Add BUZZER as a runtime-assignable timer output mode#11675
Conversation
Extends the unified PWM/PINIO output system so any timer-capable pad can be assigned as a PWM buzzer at runtime via the output assignment UI, instead of being fixed to the compile-time BEEPER pin in target.h. - Add OUTPUT_MODE_BEEPER to outputMode_e enum (mixer.h) - timerHardwareOverride(): set TIM_USE_BEEPER and clear conflicting flags when OUTPUT_MODE_BEEPER is assigned, preventing double-allocation - beeperInit(): scan timerOverrides for OUTPUT_MODE_BEEPER first; if found, call beeperPwmInit() on that pad and return — falls back to compile-time BEEPER pin when no runtime assignment is present - MSP2_INAV_OUTPUT_ASSIGNMENT / MSP2_INAV_QUERY_OUTPUT_ASSIGNMENT: report the runtime-assigned buzzer pad as OUTPUT_ASSIGNMENT_TYPE_BUZZER (3) - CLI timer_output_mode: add BEEPER as a valid mode name
…NT type byte Replace the separate OUTPUT_ASSIGNMENT_TYPE_* numbering system with __builtin_ctz(TIM_USE_*) so the type byte in the 3-tuple response matches the TIM_USE_* bit-index constants already defined in the JS configurator. This aligns firmware and configurator on one consistent system rather than two parallel sets of constants.
Remove the early-return guard that permanently locked TIM_USE_BEEPER pads out of timerHardwareOverride(). Add TIM_USE_BEEPER to the clear masks of all non-beeper cases so a reassigned pad cannot carry both flags at once. In beeperInit(), skip the compile-time fallback when the pad's post-override usageFlags no longer have TIM_USE_BEEPER set. Compile-time beeper pads now default to beeper (AUTO mode = no-op) but can be overridden to motor/servo/etc. like any other timer-capable pad.
PR Summary by QodoAdd BUZZER as a runtime-assignable timer output mode
AI Description
Diagram
High-Level Assessment
Files changed (6)
|
Code Review by Qodo
Context used 1. Wrong beeper pad chosen
|
|
Test firmware build ready — commit Download firmware for PR #11675 238 targets built. Find your board's
|
beeperPwmInit() now returns bool. beeperInit() checks it on both the runtime-assigned pad and the compile-time fallback pad, logging an error via LOG_ERROR(PWM, ...) on failure. The runtime path does not fall through to the compile-time pin on failure, since that pin may have been reassigned to another function. Addresses Qodo review finding on PR iNavFlight#11675.
5713429
into
iNavFlight:maintenance-10.x
Summary
Extends the unified PWM/PINIO output system (#11375, #11564) so any timer-capable pad can be assigned as a PWM buzzer at runtime via the output assignment UI, instead of being fixed to the compile-time
BEEPERpin intarget.h. Companion firmware PR to inav-configurator#2654.Changes
flight/mixer.h— addOUTPUT_MODE_BEEPERtooutputMode_edrivers/pwm_mapping.c/pwm_mapping.h—timerHardwareOverride()setsTIM_USE_BEEPERand clears conflicting flags whenOUTPUT_MODE_BEEPERis assigned, preventing double-allocation; also removes the guard that permanently locked compile-timeTIM_USE_BEEPERpads out of reassignment (clearingTIM_USE_BEEPERfrom all non-beeper cases so a reassigned pad can't carry both flags)drivers/sound_beeper.c—beeperInit()scanstimerOverridesforOUTPUT_MODE_BEEPERfirst; if found, initializes that pad as PWM beeper and returns. Falls back to compile-time#define BEEPER+ existing behavior when no runtime assignment is present. Skips the compile-time fallback when a compile-time beeper pad has been reassigned away fromTIM_USE_BEEPER.fc/fc_msp.c—MSP2_INAV_OUTPUT_ASSIGNMENT/MSP2_INAV_QUERY_OUTPUT_ASSIGNMENT: replace the literalOUTPUT_ASSIGNMENT_TYPE_MOTOR/SERVOnumbering with__builtin_ctz(TIM_USE_*)bit-index values, and extend the handler to also report LED/BEEPER/PINIO direct assignments (previously motor/servo only). This aligns the wire type byte with theTIM_USE_*bit-index constants already used in the JS configurator.fc/cli.c—timer_output_modeCLI command: addBEEPERas a valid mode nameBackward compatibility
Targets with existing
#define BEEPER+ old-style compile-time PWM beeper config continue to work unchanged when no runtime BUZZER assignment exists — runtime assignment only takes precedence when explicitly set.Note on the MSP type-byte change
This changes the type byte encoding for the existing MOTOR/SERVO entries too (from literal
1/2to bit-index2/3), not just adding new types. inav-configurator#2654 was written against this new encoding. Both targetmaintenance-10.x/INAV 10.0 (unreleased), so there's no production population affected — but the two PRs should land close together to avoid a stale Output Mapping table for anyone testingmaintenance-10.xconfigurator againstmaintenance-10.xfirmware in the gap between merges.Testing
test-engineerthen verified live MSP/DOM state against the running FC — Output Mapping table correctly reports the buzzer pad asS14/Buzzer, timer dropdown pre-selectsBEEPER, function row showsBuzzer, and Motor 1–4 assignments are unaffected. This confirms the runtime assignment mechanism and MSP reporting are correct end-to-end on real hardware.Related
claude/projects/active/feature-buzzer-unified-output/