1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-26 09:45:37 +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,8 +469,10 @@ 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) { if (onoffBeep == true) {
*beeperPwm.channel.ccr = (PWM_TIMER_1MHZ / freqBeep) / 2; *beeperPwm.channel.ccr = (PWM_TIMER_1MHZ / freqBeep) / 2;
beeperPwm.enabled = true; beeperPwm.enabled = true;
@ -487,9 +489,11 @@ void pwmToggleBeeper(void)
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);
if (beeperPwm.io && timer) { IO_t beeperIO = IOGetByTag(tag);
if (beeperIO && timer) {
beeperPwm.io = beeperIO;
IOInit(beeperPwm.io, OWNER_BEEPER, RESOURCE_INDEX(0)); 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);
@ -498,8 +502,9 @@ void beeperPwmInit(const ioTag_t tag, uint16_t frequency)
#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