commit
6b008ee971
|
@ -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
|
||||
|
|
|
@ -145,6 +145,12 @@ void pwmDigitalMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t
|
|||
void pwmCompleteDigitalMotorUpdate(uint8_t motorCount);
|
||||
#endif
|
||||
|
||||
#ifdef BEEPER
|
||||
void pwmWriteBeeper(bool onoffBeep);
|
||||
void pwmToggleBeeper(void);
|
||||
void beeperPwmInit(IO_t io, uint16_t frequency);
|
||||
#endif
|
||||
|
||||
void pwmWriteMotor(uint8_t index, uint16_t value);
|
||||
void pwmShutdownPulsesForAllMotors(uint8_t motorCount);
|
||||
void pwmCompleteMotorUpdate(uint8_t motorCount);
|
||||
|
|
|
@ -24,43 +24,56 @@
|
|||
#include "io.h"
|
||||
|
||||
#include "sound_beeper.h"
|
||||
#include "pwm_output.h"
|
||||
|
||||
|
||||
#ifdef BEEPER
|
||||
|
||||
static IO_t beeperIO = DEFIO_IO(NONE);
|
||||
static bool beeperInverted = false;
|
||||
|
||||
static uint16_t beeperFrequency = 0;
|
||||
#endif
|
||||
|
||||
void systemBeep(bool onoff)
|
||||
{
|
||||
#ifndef BEEPER
|
||||
UNUSED(onoff);
|
||||
#ifdef BEEPER
|
||||
if(beeperFrequency == 0) {
|
||||
IOWrite(beeperIO, beeperInverted ? onoff : !onoff);
|
||||
} else {
|
||||
pwmWriteBeeper(onoff);
|
||||
}
|
||||
#else
|
||||
IOWrite(beeperIO, beeperInverted ? onoff : !onoff);
|
||||
UNUSED(onoff);
|
||||
#endif
|
||||
}
|
||||
|
||||
void systemBeepToggle(void)
|
||||
{
|
||||
#ifdef BEEPER
|
||||
IOToggle(beeperIO);
|
||||
if(beeperFrequency == 0) {
|
||||
IOToggle(beeperIO);
|
||||
} else {
|
||||
pwmToggleBeeper();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void beeperInit(const beeperDevConfig_t *config)
|
||||
{
|
||||
#ifndef BEEPER
|
||||
UNUSED(config);
|
||||
#else
|
||||
beeperIO = IOGetByTag(config->ioTag);
|
||||
beeperInverted = config->isInverted;
|
||||
|
||||
if (beeperIO) {
|
||||
IOInit(beeperIO, OWNER_BEEPER, 0);
|
||||
IOConfigGPIO(beeperIO, config->isOpenDrain ? IOCFG_OUT_OD : IOCFG_OUT_PP);
|
||||
#ifdef BEEPER
|
||||
beeperFrequency = config->frequency;
|
||||
if(beeperFrequency == 0) {
|
||||
beeperIO = IOGetByTag(config->ioTag);
|
||||
beeperInverted = config->isInverted;
|
||||
if (beeperIO) {
|
||||
IOInit(beeperIO, OWNER_BEEPER, 0);
|
||||
IOConfigGPIO(beeperIO, config->isOpenDrain ? IOCFG_OUT_OD : IOCFG_OUT_PP);
|
||||
}
|
||||
systemBeep(false);
|
||||
} else {
|
||||
beeperIO = IOGetByTag(config->ioTag);
|
||||
beeperPwmInit(beeperIO, beeperFrequency);
|
||||
}
|
||||
systemBeep(false);
|
||||
#else
|
||||
UNUSED(config);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ typedef struct beeperDevConfig_s {
|
|||
ioTag_t ioTag;
|
||||
uint8_t isInverted;
|
||||
uint8_t isOpenDrain;
|
||||
uint16_t frequency;
|
||||
} beeperDevConfig_t;
|
||||
|
||||
void systemBeep(bool on);
|
||||
|
|
|
@ -67,7 +67,8 @@ typedef enum {
|
|||
TIM_USE_MOTOR = 0x4,
|
||||
TIM_USE_SERVO = 0x8,
|
||||
TIM_USE_LED = 0x10,
|
||||
TIM_USE_TRANSPONDER = 0x20
|
||||
TIM_USE_TRANSPONDER = 0x20,
|
||||
TIM_USE_BEEPER = 0x40
|
||||
} timerUsageFlag_e;
|
||||
|
||||
// use different types from capture and overflow - multiple overflow handlers are implemented as linked list
|
||||
|
|
|
@ -653,6 +653,7 @@ static const clivalue_t valueTable[] = {
|
|||
#ifdef BEEPER
|
||||
{ "beeper_inversion", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_BEEPER_DEV_CONFIG, offsetof(beeperDevConfig_t, isInverted) },
|
||||
{ "beeper_od", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_BEEPER_DEV_CONFIG, offsetof(beeperDevConfig_t, isOpenDrain) },
|
||||
{ "beeper_frequency", VAR_INT16 | MASTER_VALUE, .config.minmax = { 0, 16000 }, PG_BEEPER_DEV_CONFIG, offsetof(beeperDevConfig_t, frequency) },
|
||||
#endif
|
||||
|
||||
// PG_MIXER_CONFIG
|
||||
|
|
|
@ -53,15 +53,22 @@ PG_REGISTER_WITH_RESET_TEMPLATE(beeperDevConfig_t, beeperDevConfig, PG_BEEPER_DE
|
|||
#define IS_OPEN_DRAIN true
|
||||
#define IS_INVERTED false
|
||||
#endif
|
||||
|
||||
#ifdef BEEPER
|
||||
#define BEEPER_PIN BEEPER
|
||||
#ifndef BEEPER_PWM_HZ
|
||||
#define BEEPER_PWM_HZ 0
|
||||
#endif
|
||||
#else
|
||||
#define BEEPER_PIN NONE
|
||||
#define BEEPER_PWM_HZ 0
|
||||
#endif
|
||||
|
||||
PG_RESET_TEMPLATE(beeperDevConfig_t, beeperDevConfig,
|
||||
.isOpenDrain = IS_OPEN_DRAIN,
|
||||
.isInverted = IS_INVERTED,
|
||||
.ioTag = IO_TAG(BEEPER_PIN)
|
||||
.ioTag = IO_TAG(BEEPER_PIN),
|
||||
.frequency = BEEPER_PWM_HZ
|
||||
);
|
||||
|
||||
#if FLASH_SIZE > 64
|
||||
|
|
|
@ -34,7 +34,7 @@ const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = {
|
|||
DEF_TIM(TIM8, CH3, PC8, TIM_USE_MOTOR, 1),
|
||||
DEF_TIM(TIM3, CH4, PB1, 0, 0),
|
||||
DEF_TIM(TIM3, CH2, PA4, 0, 0),
|
||||
DEF_TIM(TIM4, CH1, PD12, 0, 0),
|
||||
DEF_TIM(TIM4, CH1, PD12, TIM_USE_BEEPER, 1),
|
||||
DEF_TIM(TIM4, CH2, PD13, 0, 0),
|
||||
DEF_TIM(TIM4, CH3, PD14, 0, 0),
|
||||
DEF_TIM(TIM4, CH4, PD15, 0, 0),
|
||||
|
|
|
@ -36,8 +36,8 @@
|
|||
#define LED1 PE10 // Orange LEDs - PE10/PE14
|
||||
#define LED1_INVERTED
|
||||
|
||||
#define BEEPER PE9 // Red LEDs - PE9/PE13
|
||||
#define BEEPER_INVERTED
|
||||
#define BEEPER PD12
|
||||
#define BEEPER_PWM_HZ 2000 // Beeper PWM frequency in Hz
|
||||
|
||||
#define USE_SPI
|
||||
#define USE_SPI_DEVICE_1
|
||||
|
|
|
@ -32,5 +32,6 @@ const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = {
|
|||
DEF_TIM(TIM2, CH4, PA3, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 1 ), // S4_OUT - DMA1_ST6
|
||||
DEF_TIM(TIM3, CH3, PB0, TIM_USE_MOTOR | TIM_USE_LED, TIMER_OUTPUT_ENABLED, 0 ), // S5_OUT - DMA1_ST7
|
||||
DEF_TIM(TIM3, CH4, PB1, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 0 ), // S6_OUT - DMA1_ST2
|
||||
DEF_TIM(TIM8, CH4, PC9, TIM_USE_BEEPER, TIMER_OUTPUT_ENABLED, 0 ), // BEEPER PWM
|
||||
};
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#define LED2 PB5
|
||||
|
||||
#define BEEPER PC9
|
||||
//#define BEEPER_INVERTED
|
||||
#define BEEPER_PWM_HZ 2200 // Beeper PWM frequency in Hz
|
||||
|
||||
#define INVERTER_PIN_UART6 PB15
|
||||
|
||||
|
@ -162,5 +162,5 @@
|
|||
#define TARGET_IO_PORTC 0xffff
|
||||
#define TARGET_IO_PORTD (BIT(2))
|
||||
|
||||
#define USABLE_TIMER_CHANNEL_COUNT 7
|
||||
#define USABLE_TIMER_CHANNEL_COUNT 8
|
||||
#define USED_TIMERS (TIM_N(2) | TIM_N(3) | TIM_N(5) | TIM_N(8))
|
||||
|
|
Loading…
Reference in New Issue