Update system/beeper drivers so they do not include "board.h". It is now

clear what all system/beeper drivers need to compile and what was
unnecessarily included before.

Extracted system beeper code to a separate file.
This commit is contained in:
Dominic Clifton 2014-04-17 14:41:17 +01:00
parent 1e9186d3a1
commit 2f07f52cf7
5 changed files with 86 additions and 54 deletions

View File

@ -62,6 +62,7 @@ COMMON_SRC = startup_stm32f10x_md_gcc.S \
drivers/gpio_common.c \
drivers/serial_common.c \
drivers/serial_uart.c \
drivers/sound_beeper.c \
drivers/system_common.c \
flight_imu.c \
flight_mixer.c \

View File

@ -120,17 +120,7 @@ typedef void (* pidControllerFuncPtr)(void); // pid controller fu
#include "platform.h"
#include "drivers/light_led.h"
#ifdef BEEP_GPIO
#define BEEP_TOGGLE digitalToggle(BEEP_GPIO, BEEP_PIN);
#define BEEP_OFF systemBeep(false);
#define BEEP_ON systemBeep(true);
#else
#define BEEP_TOGGLE ;
#define BEEP_OFF ;
#define BEEP_ON ;
#endif
#include "drivers/sound_beeper.h"
#include "boardalignment.h"
#include "battery.h"
#include "math.h"

View File

@ -0,0 +1,55 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include "platform.h"
#include "system_common.h"
#include "gpio_common.h"
#include "sound_beeper.h"
#ifdef BUZZER
void (* systemBeepPtr)(bool onoff) = NULL;
static void beepRev4(bool onoff)
{
if (onoff) {
digitalLo(BEEP_GPIO, BEEP_PIN);
} else {
digitalHi(BEEP_GPIO, BEEP_PIN);
}
}
static void beepRev5(bool onoff)
{
if (onoff) {
digitalHi(BEEP_GPIO, BEEP_PIN);
} else {
digitalLo(BEEP_GPIO, BEEP_PIN);
}
}
#endif
void systemBeep(bool onoff)
{
#ifdef BUZZER
systemBeepPtr(onoff);
#endif
}
void beeperInit(void)
{
#ifdef BUZZER
// Configure gpio
// rev5 needs inverted beeper. oops.
if (hse_value == 12000000)
systemBeepPtr = beepRev5;
else
systemBeepPtr = beepRev4;
BEEP_OFF;
#endif
}

View File

@ -0,0 +1,14 @@
#pragma once
#ifdef BEEP_GPIO
#define BEEP_TOGGLE digitalToggle(BEEP_GPIO, BEEP_PIN);
#define BEEP_OFF systemBeep(false);
#define BEEP_ON systemBeep(true);
#else
#define BEEP_TOGGLE ;
#define BEEP_OFF ;
#define BEEP_ON ;
#endif
void systemBeep(bool onoff);
void beeperInit(void);

View File

@ -1,4 +1,17 @@
#include "board.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include "platform.h"
#include "gpio_common.h"
#include "light_led.h"
#include "sound_beeper.h"
#include "bus_i2c.h"
#include "bus_spi.h"
#include "system_common.h"
// cycles per microsecond
static volatile uint32_t usTicks = 0;
@ -6,12 +19,6 @@ static volatile uint32_t usTicks = 0;
static volatile uint32_t sysTickUptime = 0;
// from system_stm32f10x.c
void SetSysClock(void);
#ifdef BUZZER
void systemBeep(bool onoff);
static void beepRev4(bool onoff);
static void beepRev5(bool onoff);
void (* systemBeepPtr)(bool onoff) = NULL;
#endif
static void cycleCounterInit(void)
{
@ -94,15 +101,7 @@ void systemInit(void)
#define AFIO_MAPR_SWJ_CFG_NO_JTAG_SW (0x2 << 24)
AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_NO_JTAG_SW;
#ifdef BUZZER
// Configure gpio
// rev5 needs inverted beeper. oops.
if (hse_value == 12000000)
systemBeepPtr = beepRev5;
else
systemBeepPtr = beepRev4;
BEEP_OFF;
#endif
beeperInit();
LED0_OFF;
LED1_OFF;
@ -196,30 +195,3 @@ void systemReset(bool toBootloader)
SCB->AIRCR = AIRCR_VECTKEY_MASK | (uint32_t)0x04;
}
#ifdef BUZZER
static void beepRev4(bool onoff)
{
if (onoff) {
digitalLo(BEEP_GPIO, BEEP_PIN);
} else {
digitalHi(BEEP_GPIO, BEEP_PIN);
}
}
static void beepRev5(bool onoff)
{
if (onoff) {
digitalHi(BEEP_GPIO, BEEP_PIN);
} else {
digitalLo(BEEP_GPIO, BEEP_PIN);
}
}
#endif
void systemBeep(bool onoff)
{
#ifdef BUZZER
systemBeepPtr(onoff);
#endif
}