Use Naze hardware revision when initialising beeper. Cleanup inverted

beeper configuration.
This commit is contained in:
Dominic Clifton 2014-10-16 00:44:56 +01:00
parent 2ed09b0b2f
commit 50391f2c8e
8 changed files with 70 additions and 3808 deletions

File diff suppressed because it is too large Load Diff

View File

@ -61,21 +61,11 @@ void systemBeep(bool onoff)
#endif #endif
} }
static inline bool isBeeperOutputInverted(void) void beeperInit(beeperConfig_t *config)
{
#ifdef BEEPER_INVERTED
return true;
#else
// Naze rev5 needs inverted beeper.
return hse_value == 12000000;
#endif
}
void beeperInit(void)
{ {
#ifdef BEEPER #ifdef BEEPER
initBeeperHardware(); initBeeperHardware(config);
if (isBeeperOutputInverted()) if (config->isInverted)
systemBeepPtr = beepInverted; systemBeepPtr = beepInverted;
else else
systemBeepPtr = beepNormal; systemBeepPtr = beepNormal;

View File

@ -17,17 +17,25 @@
#pragma once #pragma once
#ifdef BEEP_GPIO #ifdef BEEPER
#define BEEP_TOGGLE digitalToggle(BEEP_GPIO, BEEP_PIN); #define BEEP_TOGGLE digitalToggle(BEEP_GPIO, BEEP_PIN)
#define BEEP_OFF systemBeep(false); #define BEEP_OFF systemBeep(false)
#define BEEP_ON systemBeep(true); #define BEEP_ON systemBeep(true)
#else #else
#define BEEP_TOGGLE ; #define BEEP_TOGGLE
#define BEEP_OFF ; #define BEEP_OFF
#define BEEP_ON ; #define BEEP_ON
#endif #endif
void systemBeep(bool onoff); typedef struct beeperConfig_s {
void beeperInit(void); uint32_t gpioPeripheral;
uint16_t gpioPin;
GPIO_TypeDef *gpioPort;
GPIO_Mode gpioMode;
bool isInverted;
} beeperConfig_t;
void initBeeperHardware(void); void systemBeep(bool onoff);
void beeperInit(beeperConfig_t *beeperConfig);
void initBeeperHardware(beeperConfig_t *config);

View File

@ -26,27 +26,17 @@
#include "sound_beeper.h" #include "sound_beeper.h"
void initBeeperHardware(void) void initBeeperHardware(beeperConfig_t *config)
{ {
#ifdef BEEPER #ifdef BEEPER
struct { gpio_config_t gpioConfig = {
GPIO_TypeDef *gpio; config->gpioPin,
gpio_config_t cfg; config->gpioMode,
} gpio_setup = { Speed_2MHz
.gpio = BEEP_GPIO,
.cfg = { BEEP_PIN, Mode_Out_OD, Speed_2MHz }
}; };
RCC_APB2PeriphClockCmd(BEEP_PERIPHERAL, ENABLE); RCC_APB2PeriphClockCmd(config->gpioPeripheral, ENABLE);
#ifdef NAZE
// Hack - naze rev4 and below used opendrain to PNP for buzzer. Rev5 and above use PP to NPN.
if (hse_value == 12000000 && gpio_setup.cfg.mode == Mode_Out_OD)
gpio_setup.cfg.mode = Mode_Out_PP;
#endif
gpioInit(gpio_setup.gpio, &gpio_setup.cfg);
gpioInit(config->gpioPort, &gpioConfig);
#endif #endif
} }

View File

@ -25,20 +25,17 @@
#include "sound_beeper.h" #include "sound_beeper.h"
void initBeeperHardware(void) void initBeeperHardware(beeperConfig_t *config)
{ {
#ifdef BEEPER #ifdef BEEPER
struct { gpio_config_t gpioConfig = {
GPIO_TypeDef *gpio; config->gpioPin,
gpio_config_t cfg; config->gpioMode,
} gpio_setup = { Speed_2MHz
.gpio = BEEP_GPIO,
.cfg = { BEEP_PIN, Mode_Out_OD, Speed_2MHz }
}; };
RCC_AHBPeriphClockCmd(BEEP_PERIPHERAL, ENABLE); RCC_AHBPeriphClockCmd(config->gpioPeripheral, ENABLE);
gpioInit(gpio_setup.gpio, &gpio_setup.cfg);
gpioInit(config->gpioPort, &gpioConfig);
#endif #endif
} }

View File

@ -26,7 +26,6 @@
#include "gpio.h" #include "gpio.h"
#include "light_led.h" #include "light_led.h"
#include "sound_beeper.h" #include "sound_beeper.h"
#include "inverter.h"
#include "system.h" #include "system.h"
@ -93,20 +92,11 @@ void systemInit(void)
AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_NO_JTAG_SW; AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_NO_JTAG_SW;
#endif #endif
ledInit();
beeperInit();
#ifdef INVERTER
initInverter();
#endif
// Init cycle counter // Init cycle counter
cycleCounterInit(); cycleCounterInit();
// SysTick // SysTick
SysTick_Config(SystemCoreClock / 1000); SysTick_Config(SystemCoreClock / 1000);
// sleep for 100ms
delay(100);
} }
#if 1 #if 1
@ -158,7 +148,7 @@ void failureMode(uint8_t mode)
LED1_TOGGLE; LED1_TOGGLE;
LED0_TOGGLE; LED0_TOGGLE;
delay(475 * mode - 2); delay(475 * mode - 2);
BEEP_ON BEEP_ON;
delay(25); delay(25);
BEEP_OFF; BEEP_OFF;
} }

View File

@ -19,6 +19,8 @@
#include "stdint.h" #include "stdint.h"
#include "platform.h" #include "platform.h"
#include "drivers/gpio.h"
#include "drivers/sound_beeper.h" #include "drivers/sound_beeper.h"
#include "drivers/system.h" #include "drivers/system.h"
#include "flight/failsafe.h" #include "flight/failsafe.h"

View File

@ -39,6 +39,10 @@
#include "drivers/adc.h" #include "drivers/adc.h"
#include "drivers/bus_i2c.h" #include "drivers/bus_i2c.h"
#include "drivers/bus_spi.h" #include "drivers/bus_spi.h"
#include "drivers/gpio.h"
#include "drivers/light_led.h"
#include "drivers/sound_beeper.h"
#include "drivers/inverter.h"
#include "flight/flight.h" #include "flight/flight.h"
#include "flight/mixer.h" #include "flight/mixer.h"
@ -169,6 +173,34 @@ void init(void)
systemInit(); systemInit();
delay(100);
ledInit();
#ifdef BEEPER
beeperConfig_t beeperConfig = {
.gpioMode = Mode_Out_OD,
.gpioPin = BEEP_PIN,
.gpioPort = BEEP_GPIO,
.gpioPeripheral = BEEP_PERIPHERAL,
.isInverted = false
};
#ifdef NAZE
if (hardwareRevision >= NAZE32_REV5) {
// naze rev4 and below used opendrain to PNP for buzzer. Rev5 and above use PP to NPN.
beeperConfig.gpioMode = Mode_Out_PP;
beeperConfig.isInverted = true;
}
#endif
beeperInit(&beeperConfig);
#endif
#ifdef INVERTER
initInverter();
#endif
#ifdef USE_SPI #ifdef USE_SPI
spiInit(SPI1); spiInit(SPI1);
spiInit(SPI2); spiInit(SPI2);