mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 12:55:19 +03:00
Beeper PWM support
Beeper PWM frequency set limited to positive values Removal of all the defined(BEEPER_PWM) tabs and spaces cleanup in beeper functions Add IOGetByTag and timerGetByTag check to Beeper Pwm Init Add IO check before every Beeper Pwm functions in pwm_output Update pwm_output.c after comments from Mikeller
This commit is contained in:
parent
3408d9d613
commit
458cf6601d
11 changed files with 98 additions and 23 deletions
|
@ -26,6 +26,7 @@
|
|||
#include "io.h"
|
||||
#include "pwm_output.h"
|
||||
#include "timer.h"
|
||||
#include "drivers/pwm_output.h"
|
||||
|
||||
#define MULTISHOT_5US_PW (MULTISHOT_TIMER_MHZ * 5)
|
||||
#define MULTISHOT_20US_MULT (MULTISHOT_TIMER_MHZ * 20 / 1000.0f)
|
||||
|
@ -40,6 +41,11 @@ static pwmCompleteWriteFuncPtr pwmCompleteWritePtr = NULL;
|
|||
static pwmOutputPort_t servos[MAX_SUPPORTED_SERVOS];
|
||||
#endif
|
||||
|
||||
#ifdef BEEPER
|
||||
static pwmOutputPort_t beeperPwm;
|
||||
static uint16_t freqBeep=0;
|
||||
#endif
|
||||
|
||||
bool pwmMotorsEnabled = false;
|
||||
|
||||
static void pwmOCConfig(TIM_TypeDef *tim, uint8_t channel, uint16_t value, uint8_t output)
|
||||
|
@ -380,3 +386,42 @@ void servoDevInit(const servoDevConfig_t *servoConfig)
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef BEEPER
|
||||
void pwmWriteBeeper(bool onoffBeep)
|
||||
{
|
||||
if(!beeperPwm.io)
|
||||
return;
|
||||
if(onoffBeep == true) {
|
||||
*beeperPwm.ccr = (1000000/freqBeep)/2;
|
||||
beeperPwm.enabled = true;
|
||||
} else {
|
||||
*beeperPwm.ccr = 0;
|
||||
beeperPwm.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
void pwmToggleBeeper(void)
|
||||
{
|
||||
pwmWriteBeeper(!beeperPwm.enabled);
|
||||
}
|
||||
|
||||
void beeperPwmInit(IO_t io, uint16_t frequency)
|
||||
{
|
||||
const ioTag_t tag=IO_TAG(BEEPER);
|
||||
beeperPwm.io = io;
|
||||
const timerHardware_t *timer = timerGetByTag(tag, TIM_USE_BEEPER);
|
||||
if (beeperPwm.io && timer) {
|
||||
IOInit(beeperPwm.io, OWNER_BEEPER, RESOURCE_INDEX(0));
|
||||
#if defined(USE_HAL_DRIVER)
|
||||
IOConfigGPIOAF(beeperPwm.io, IOCFG_AF_PP, timer->alternateFunction);
|
||||
#else
|
||||
IOConfigGPIO(beeperPwm.io, IOCFG_AF_PP);
|
||||
#endif
|
||||
freqBeep = frequency;
|
||||
pwmOutConfig(&beeperPwm, timer, PWM_TIMER_MHZ, 1000000/freqBeep, (1000000/freqBeep)/2,0);
|
||||
}
|
||||
*beeperPwm.ccr = 0;
|
||||
beeperPwm.enabled = false;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue