1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-25 17:25:20 +03:00

Merge pull request #5758 from jflyper/bfdev-handle-non-existent-passive-beeper-correctly

Passive beeper: Handle non-existent timer case correctly
This commit is contained in:
Michael Keller 2018-04-25 00:17:28 +12:00 committed by GitHub
commit 7ee764b569
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 19 deletions

View file

@ -469,37 +469,42 @@ void servoDevInit(const servoDevConfig_t *servoConfig)
#ifdef USE_BEEPER #ifdef USE_BEEPER
void pwmWriteBeeper(bool onoffBeep) void pwmWriteBeeper(bool onoffBeep)
{ {
if (!beeperPwm.io) if (!beeperPwm.io) {
return; return;
if (onoffBeep == true) { }
*beeperPwm.channel.ccr = (PWM_TIMER_1MHZ / freqBeep) / 2;
beeperPwm.enabled = true; if (onoffBeep == true) {
} else { *beeperPwm.channel.ccr = (PWM_TIMER_1MHZ / freqBeep) / 2;
*beeperPwm.channel.ccr = 0; beeperPwm.enabled = true;
beeperPwm.enabled = false; } else {
} *beeperPwm.channel.ccr = 0;
beeperPwm.enabled = false;
}
} }
void pwmToggleBeeper(void) void pwmToggleBeeper(void)
{ {
pwmWriteBeeper(!beeperPwm.enabled); pwmWriteBeeper(!beeperPwm.enabled);
} }
void beeperPwmInit(const ioTag_t tag, uint16_t frequency) void beeperPwmInit(const ioTag_t tag, uint16_t frequency)
{ {
beeperPwm.io = IOGetByTag(tag); const timerHardware_t *timer = timerGetByTag(tag, TIM_USE_BEEPER);
const timerHardware_t *timer = timerGetByTag(tag, TIM_USE_BEEPER); IO_t beeperIO = IOGetByTag(tag);
if (beeperPwm.io && timer) {
IOInit(beeperPwm.io, OWNER_BEEPER, RESOURCE_INDEX(0)); if (beeperIO && timer) {
beeperPwm.io = beeperIO;
IOInit(beeperPwm.io, OWNER_BEEPER, RESOURCE_INDEX(0));
#if defined(USE_HAL_DRIVER) #if defined(USE_HAL_DRIVER)
IOConfigGPIOAF(beeperPwm.io, IOCFG_AF_PP, timer->alternateFunction); IOConfigGPIOAF(beeperPwm.io, IOCFG_AF_PP, timer->alternateFunction);
#else #else
IOConfigGPIO(beeperPwm.io, IOCFG_AF_PP); IOConfigGPIO(beeperPwm.io, IOCFG_AF_PP);
#endif #endif
freqBeep = frequency; freqBeep = frequency;
pwmOutConfig(&beeperPwm.channel, timer, PWM_TIMER_1MHZ, PWM_TIMER_1MHZ / freqBeep, (PWM_TIMER_1MHZ / freqBeep) / 2, 0); pwmOutConfig(&beeperPwm.channel, timer, PWM_TIMER_1MHZ, PWM_TIMER_1MHZ / freqBeep, (PWM_TIMER_1MHZ / freqBeep) / 2, 0);
}
*beeperPwm.channel.ccr = 0; *beeperPwm.channel.ccr = 0;
beeperPwm.enabled = false; beeperPwm.enabled = false;
}
} }
#endif #endif

View file

@ -50,6 +50,7 @@
#include "io/serial.h" #include "io/serial.h"
#include "pg/beeper.h" #include "pg/beeper.h"
#include "pg/beeper_dev.h"
#include "pg/pg.h" #include "pg/pg.h"
#include "pg/pg_ids.h" #include "pg/pg_ids.h"
@ -356,6 +357,12 @@ static void validateAndFixConfig(void)
featureClear(FEATURE_RSSI_ADC); featureClear(FEATURE_RSSI_ADC);
#endif #endif
#if defined(USE_BEEPER)
if (beeperDevConfig()->frequency && !timerGetByTag(beeperDevConfig()->ioTag, TIM_USE_BEEPER)) {
beeperDevConfigMutable()->frequency = 0;
}
#endif
#if defined(TARGET_VALIDATECONFIG) #if defined(TARGET_VALIDATECONFIG)
targetValidateConfiguration(); targetValidateConfiguration();
#endif #endif