From 8ddd8a029efdffc4b6393a2e11e2ac3915150c9d Mon Sep 17 00:00:00 2001 From: Vladimir Zidar Date: Thu, 1 Jun 2017 18:10:08 +0200 Subject: [PATCH] LP-512 Cleaned up buzzer configuration and usage for boards with dedicated buzzer port. --- flight/libraries/notification.c | 33 ++++++++++++++++--- flight/pios/stm32f0x/pios_sys.c | 13 +++++--- flight/pios/stm32f10x/pios_sys.c | 13 +++++--- flight/pios/stm32f30x/pios_sys.c | 14 +++++--- flight/pios/stm32f4xx/pios_sys.c | 13 +++++--- flight/targets/boards/pikoblx/board_hw_defs.c | 2 +- flight/targets/boards/pikoblx/pios_board.h | 2 +- .../targets/boards/spracingf3/board_hw_defs.c | 14 +++++++- flight/targets/boards/spracingf3/pios_board.h | 1 + .../boards/spracingf3evo/board_hw_defs.c | 2 +- .../targets/boards/spracingf3evo/pios_board.h | 2 +- .../targets/boards/tinyfish/board_hw_defs.c | 2 +- .../boards/tinyfish/firmware/pios_board.c | 2 +- flight/targets/boards/tinyfish/pios_board.h | 2 +- 14 files changed, 85 insertions(+), 30 deletions(-) diff --git a/flight/libraries/notification.c b/flight/libraries/notification.c index f68504048..b60fd4d8d 100644 --- a/flight/libraries/notification.c +++ b/flight/libraries/notification.c @@ -42,6 +42,18 @@ #define ALARM_LED_OFF() #endif +#ifdef PIOS_BUZZER_ALARM +#define ALARM_BUZZER_ON() \ + { if (buzzer_enabled) { PIOS_LED_On(PIOS_BUZZER_ALARM); } \ + } +#define ALARM_BUZZER_OFF() \ + { if (buzzer_enabled) { PIOS_LED_Off(PIOS_BUZZER_ALARM); } \ + } +#else +#define ALARM_BUZZER_ON() +#define ALARM_BUZZER_OFF() +#endif + #ifdef PIOS_LED_HEARTBEAT #define HEARTBEAT_LED_ON() PIOS_LED_On(PIOS_LED_HEARTBEAT) #define HEARTBEAT_LED_OFF() PIOS_LED_Off(PIOS_LED_HEARTBEAT) @@ -135,9 +147,10 @@ static volatile FlightStatusData currentFlightStatus; static volatile bool started = false; static volatile pios_notify_notification nextNotification = NOTIFY_NONE; -#ifdef PIOS_LED_ALARM + +#if defined(PIOS_LED_ALARM) || defined(PIOS_BUZZER_ALARM) static bool handleAlarms(uint16_t *r_pattern, uint16_t *b_pattern); -#endif // PIOS_LED_ALARM +#endif // PIOS_LED_ALARM || PIOS_BUZZER_ALARM static bool handleNotifications(pios_notify_notification runningNotification, uint16_t *r_pattern, uint16_t *b_pattern); static void handleFlightMode(uint16_t *r_pattern, uint16_t *b_pattern); static void handleHeartbeat(uint16_t *r_pattern, uint16_t *b_pattern); @@ -163,6 +176,10 @@ void NotificationOnboardLedsRun() static uint8_t lastFlightMode = -1; static bool forceShowFlightMode = false; static pios_notify_notification runningNotification = NOTIFY_NONE; + +#ifdef PIOS_BUZZER_ALARM + static bool buzzer_enabled = false; +#endif static enum { STATUS_NOTIFY, STATUS_ALARM, @@ -206,6 +223,7 @@ void NotificationOnboardLedsRun() if (cycleCount & 0x10) { HEARTBEAT_LED_OFF(); ALARM_LED_OFF(); + ALARM_BUZZER_OFF(); cycleCount = 0x0; forceShowFlightMode = false; // Notification has been just shown, cleanup @@ -213,6 +231,9 @@ void NotificationOnboardLedsRun() runningNotification = NOTIFY_NONE; } status = (status + 1) % STATUS_LENGHT; +#ifdef PIOS_BUZZER_ALARM + buzzer_enabled = true; /* This is the place where we update buzzer_enabled status based on (not yet implemented) NotificationSettings.Buzzer config */ +#endif } if (status == STATUS_NOTIFY) { @@ -224,7 +245,7 @@ void NotificationOnboardLedsRun() // Handles Alarm display if (status == STATUS_ALARM) { -#ifdef PIOS_LED_ALARM +#if defined(PIOS_LED_ALARM) || defined(PIOS_BUZZER_ALARM) if (!cycleCount && !handleAlarms(&r_pattern, &b_pattern)) { // no alarms, advance status++; @@ -252,14 +273,16 @@ void NotificationOnboardLedsRun() } if (r_pattern & 0x1) { ALARM_LED_ON(); + ALARM_BUZZER_ON(); } else { ALARM_LED_OFF(); + ALARM_BUZZER_OFF(); } r_pattern >>= 1; b_pattern >>= 1; } -#if defined(PIOS_LED_ALARM) +#if defined(PIOS_LED_ALARM) || defined(PIOS_BUZZER_ALARM) static bool handleAlarms(uint16_t *r_pattern, uint16_t *b_pattern) { if (currentAlarmLevel == SYSTEMALARMS_ALARM_OK) { @@ -269,7 +292,7 @@ static bool handleAlarms(uint16_t *r_pattern, uint16_t *b_pattern) *r_pattern = BLINK_R_ALARM_PATTERN(currentAlarmLevel); return true; } -#endif /* PIOS_LED_ALARM */ +#endif /* PIOS_LED_ALARM || PIOS_BUZZER_ALARM */ static bool handleNotifications(pios_notify_notification runningNotification, uint16_t *r_pattern, uint16_t *b_pattern) diff --git a/flight/pios/stm32f0x/pios_sys.c b/flight/pios/stm32f0x/pios_sys.c index ab2aef92f..aae142302 100644 --- a/flight/pios/stm32f0x/pios_sys.c +++ b/flight/pios/stm32f0x/pios_sys.c @@ -124,12 +124,17 @@ int32_t PIOS_SYS_Reset(void) PIOS_IRQ_Disable(); // turn off all board LEDs -#if defined(PIOS_LED_HEARTBEAT) +#ifdef PIOS_INCLUDE_LED +# ifdef PIOS_LED_HEARTBEAT PIOS_LED_Off(PIOS_LED_HEARTBEAT); -#endif /* PIOS_LED_HEARTBEAT */ -#if defined(PIOS_LED_ALARM) +# endif /* PIOS_LED_HEARTBEAT */ +# ifdef PIOS_LED_ALARM PIOS_LED_Off(PIOS_LED_ALARM); -#endif /* PIOS_LED_ALARM */ +# endif /* PIOS_LED_ALARM */ +# ifdef PIOS_BUZZER_ALARM + PIOS_LED_Off(PIOS_BUZZER_ALARM); +# endif /* PIOS_BUZZER_ALARM */ +#endif /* PIOS_INCLUDE_LED */ /* Reset STM32 */ NVIC_SystemReset(); diff --git a/flight/pios/stm32f10x/pios_sys.c b/flight/pios/stm32f10x/pios_sys.c index 849bb83cd..288fc0775 100644 --- a/flight/pios/stm32f10x/pios_sys.c +++ b/flight/pios/stm32f10x/pios_sys.c @@ -97,12 +97,17 @@ int32_t PIOS_SYS_Reset(void) PIOS_IRQ_Disable(); // turn off all board LEDs -#if defined(PIOS_LED_HEARTBEAT) +#ifdef PIOS_INCLUDE_LED +# ifdef PIOS_LED_HEARTBEAT PIOS_LED_Off(PIOS_LED_HEARTBEAT); -#endif /* PIOS_LED_HEARTBEAT */ -#if defined(PIOS_LED_ALARM) +# endif /* PIOS_LED_HEARTBEAT */ +# ifdef PIOS_LED_ALARM PIOS_LED_Off(PIOS_LED_ALARM); -#endif /* PIOS_LED_ALARM */ +# endif /* PIOS_LED_ALARM */ +# ifdef PIOS_BUZZER_ALARM + PIOS_LED_Off(PIOS_BUZZER_ALARM); +# endif /* PIOS_BUZZER_ALARM */ +#endif /* PIOS_INCLUDE_LED */ RCC_APB2PeriphResetCmd(0xffffffff, DISABLE); RCC_APB1PeriphResetCmd(0xffffffff, DISABLE); diff --git a/flight/pios/stm32f30x/pios_sys.c b/flight/pios/stm32f30x/pios_sys.c index 45640400e..6d849bc14 100644 --- a/flight/pios/stm32f30x/pios_sys.c +++ b/flight/pios/stm32f30x/pios_sys.c @@ -155,13 +155,17 @@ int32_t PIOS_SYS_Reset(void) PIOS_IRQ_Disable(); // turn off all board LEDs -#if defined(PIOS_INCLUDE_LED) && defined(PIOS_LED_HEARTBEAT) +#ifdef PIOS_INCLUDE_LED +# ifdef PIOS_LED_HEARTBEAT PIOS_LED_Off(PIOS_LED_HEARTBEAT); -#endif /* PIOS_LED_HEARTBEAT */ -#if defined(PIOS_INCLUDE_LED) && defined(PIOS_LED_ALARM) +# endif /* PIOS_LED_HEARTBEAT */ +# ifdef PIOS_LED_ALARM PIOS_LED_Off(PIOS_LED_ALARM); -#endif /* PIOS_LED_ALARM */ - +# endif /* PIOS_LED_ALARM */ +# ifdef PIOS_BUZZER_ALARM + PIOS_LED_Off(PIOS_BUZZER_ALARM); +# endif /* PIOS_BUZZER_ALARM */ +#endif /* PIOS_INCLUDE_LED */ /* XXX F10x port resets most (but not all) peripherals ... do we care? */ /* Reset STM32 */ diff --git a/flight/pios/stm32f4xx/pios_sys.c b/flight/pios/stm32f4xx/pios_sys.c index ab6759fe9..c03297871 100644 --- a/flight/pios/stm32f4xx/pios_sys.c +++ b/flight/pios/stm32f4xx/pios_sys.c @@ -204,12 +204,17 @@ int32_t PIOS_SYS_Reset(void) PIOS_IRQ_Disable(); // turn off all board LEDs -#if defined(PIOS_LED_HEARTBEAT) +#ifdef PIOS_INCLUDE_LED +# ifdef PIOS_LED_HEARTBEAT PIOS_LED_Off(PIOS_LED_HEARTBEAT); -#endif /* PIOS_LED_HEARTBEAT */ -#if defined(PIOS_LED_ALARM) +# endif /* PIOS_LED_HEARTBEAT */ +# ifdef PIOS_LED_ALARM PIOS_LED_Off(PIOS_LED_ALARM); -#endif /* PIOS_LED_ALARM */ +# endif /* PIOS_LED_ALARM */ +# ifdef PIOS_BUZZER_ALARM + PIOS_LED_Off(PIOS_BUZZER_ALARM); +# endif /* PIOS_BUZZER_ALARM */ +#endif /* PIOS_INCLUDE_LED */ /* XXX F10x port resets most (but not all) peripherals ... do we care? */ diff --git a/flight/targets/boards/pikoblx/board_hw_defs.c b/flight/targets/boards/pikoblx/board_hw_defs.c index 1330070fd..159c93034 100644 --- a/flight/targets/boards/pikoblx/board_hw_defs.c +++ b/flight/targets/boards/pikoblx/board_hw_defs.c @@ -53,7 +53,7 @@ static const struct pios_gpio pios_leds[] = { }, .active_low = true }, - [PIOS_LED_BUZZER] = { /* not really LED, but buzzer! */ + [PIOS_BUZZER_ALARM] = { .pin = { .gpio = GPIOA, .init = { diff --git a/flight/targets/boards/pikoblx/pios_board.h b/flight/targets/boards/pikoblx/pios_board.h index dcc6a06a4..f3654b0b0 100644 --- a/flight/targets/boards/pikoblx/pios_board.h +++ b/flight/targets/boards/pikoblx/pios_board.h @@ -86,7 +86,7 @@ // ------------------------ #define PIOS_LED_HEARTBEAT 0 #define PIOS_LED_ALARM 1 -#define PIOS_LED_BUZZER 2 +#define PIOS_BUZZER_ALARM 2 // ------------------------- // System Settings diff --git a/flight/targets/boards/spracingf3/board_hw_defs.c b/flight/targets/boards/spracingf3/board_hw_defs.c index b6d1fd39a..5febf939d 100644 --- a/flight/targets/boards/spracingf3/board_hw_defs.c +++ b/flight/targets/boards/spracingf3/board_hw_defs.c @@ -44,7 +44,19 @@ static const struct pios_gpio pios_leds[] = { .GPIO_PuPd = GPIO_PuPd_NOPULL, }, }, -// .remap = GPIO_Remap_SWJ_JTAGDisable, + .active_low = false + }, + [PIOS_BUZZER_ALARM] = { + .pin = { + .gpio = GPIOC, + .init = { + .GPIO_Pin = GPIO_Pin_15, + .GPIO_Mode = GPIO_Mode_OUT, + .GPIO_OType = GPIO_OType_PP, + .GPIO_Speed = GPIO_Speed_50MHz, + .GPIO_PuPd = GPIO_PuPd_NOPULL, + }, + }, .active_low = false }, }; diff --git a/flight/targets/boards/spracingf3/pios_board.h b/flight/targets/boards/spracingf3/pios_board.h index 2e9102778..9f3fb6253 100644 --- a/flight/targets/boards/spracingf3/pios_board.h +++ b/flight/targets/boards/spracingf3/pios_board.h @@ -84,6 +84,7 @@ // PIOS_LED // ------------------------ #define PIOS_LED_HEARTBEAT 0 +#define PIOS_BUZZER_ALARM 1 // ------------------------- // System Settings diff --git a/flight/targets/boards/spracingf3evo/board_hw_defs.c b/flight/targets/boards/spracingf3evo/board_hw_defs.c index 1a3166518..2e4d75b4a 100644 --- a/flight/targets/boards/spracingf3evo/board_hw_defs.c +++ b/flight/targets/boards/spracingf3evo/board_hw_defs.c @@ -44,7 +44,7 @@ static const struct pios_gpio pios_leds[] = { }, .active_low = true }, - [PIOS_LED_ALARM] = { /* not really LED, but buzzer! */ + [PIOS_BUZZER_ALARM] = { .pin = { .gpio = GPIOC, .init = { diff --git a/flight/targets/boards/spracingf3evo/pios_board.h b/flight/targets/boards/spracingf3evo/pios_board.h index 887ed2073..629b33783 100644 --- a/flight/targets/boards/spracingf3evo/pios_board.h +++ b/flight/targets/boards/spracingf3evo/pios_board.h @@ -85,7 +85,7 @@ // PIOS_LED // ------------------------ #define PIOS_LED_HEARTBEAT 0 -#define PIOS_LED_ALARM 1 +#define PIOS_BUZZER_ALARM 1 // ------------------------- // System Settings diff --git a/flight/targets/boards/tinyfish/board_hw_defs.c b/flight/targets/boards/tinyfish/board_hw_defs.c index 197b153a9..6f1ef5467 100644 --- a/flight/targets/boards/tinyfish/board_hw_defs.c +++ b/flight/targets/boards/tinyfish/board_hw_defs.c @@ -53,7 +53,7 @@ static const struct pios_gpio pios_leds[] = { }, .active_low = false }, - [PIOS_LED_BUZZER] = { /* not really LED, but buzzer! (or PB2 ??) */ + [PIOS_BUZZER_ALARM] = { /* (or PB2 ??) */ .pin = { .gpio = GPIOC, .init = { diff --git a/flight/targets/boards/tinyfish/firmware/pios_board.c b/flight/targets/boards/tinyfish/firmware/pios_board.c index b6fbd02e7..7ced0a9c1 100644 --- a/flight/targets/boards/tinyfish/firmware/pios_board.c +++ b/flight/targets/boards/tinyfish/firmware/pios_board.c @@ -63,7 +63,7 @@ uintptr_t pios_user_fs_id = 0; uint32_t pios_ws2811_id; #endif -void FlightBatterySettingsDataOverrideDefaults(FlightBatterySettingsData * data) +void FlightBatterySettingsDataOverrideDefaults(FlightBatterySettingsData *data) { data->SensorCalibrations.VoltageFactor = 8.8f; data->SensorCalibrations.CurrentFactor = 0.07f; diff --git a/flight/targets/boards/tinyfish/pios_board.h b/flight/targets/boards/tinyfish/pios_board.h index 2fe545f26..45e4f69e4 100644 --- a/flight/targets/boards/tinyfish/pios_board.h +++ b/flight/targets/boards/tinyfish/pios_board.h @@ -58,7 +58,7 @@ // ------------------------ #define PIOS_LED_HEARTBEAT 0 #define PIOS_LED_ALARM 1 -#define PIOS_LED_BUZZER 2 +#define PIOS_BUZZER_ALARM 2 // ------------------------- // System Settings