Skip to content

Conversation

@DavidMenting
Copy link
Member

Summary

Replaces hardware auto-detect with direct MFP3 pin reading and time-based software debouncing for headphone jack detection. This provides better control over detection behavior and centralizes policy logic in the AudioOutput HAL layer.

Driver Layer Changes (Aic3204)

  • Read MFP3 pin state directly from GPIO control register (Page 0, Reg 0x36) instead of hardware auto-detect result register
  • Remove hardware auto-detect initialization from init() (Page 0, Reg 0x43 setup)
  • Remove update_headphone_detection() method that embedded policy logic in the driver
  • Remove _headphone_inserted_state member variable

HAL Layer Changes (AudioOutput)

  • Implement time-based software debouncing (20ms poll interval, 75ms debounce duration)
  • Add debounce state machine with SDK time functions (get_absolute_time(), absolute_time_diff_us())
  • Cache debounced state and notify listeners only on confirmed state changes
  • Add new public API:
    • headphones_inserted() - Returns cached debounced state
    • set_headphone_listener() - Register callback for state changes
    • clear_headphone_listener() - Clear callback
    • enable_auto_speaker_mute() - Toggle automatic amp control policy

Architecture Benefits

  • Clean separation: driver provides semantic read API, HAL orchestrates polling and policy
  • Codec-agnostic: application layer accesses headphone state through AudioOutput
  • Configurable: poll interval and debounce duration via build-time constants
  • Testable: policy and debouncing logic isolated from hardware I/O

Test Plan

  • Verify headphone insertion/removal detected on hardware within ~75-95ms
  • Confirm no false triggers from contact bounce
  • Test auto-mute policy correctly toggles external amp
  • Verify listener callbacks invoked on debounced state changes only
  • Check no audible artifacts during amp toggling

Replace codec hardware auto-detect with direct MFP3 pin reading and
time-based software debouncing (20ms poll, 75ms debounce). Move
policy and debounce logic from driver to AudioOutput HAL layer.
Add listener API for headphone state change notifications.
@DavidMenting DavidMenting force-pushed the feature/headphone-detection-polling branch from 9318bc4 to 7ba337b Compare October 14, 2025 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants