From fd9d4773ac39a1e86af0965e70c4868742b2b71c Mon Sep 17 00:00:00 2001 From: Kevin Gillespie Date: Mon, 26 Aug 2024 11:20:01 -0500 Subject: [PATCH] refactor(BLE): Simplifying LED interface with libphy. (#1137) --- Libraries/Cordio/platform/include/pal_led.h | 7 ++ .../platform/targets/maxim/build/libCordio.mk | 2 + .../targets/maxim/max32655/sources/pal_led.c | 85 ++---------------- .../targets/maxim/max32690/sources/pal_led.c | 90 ++----------------- 4 files changed, 22 insertions(+), 162 deletions(-) diff --git a/Libraries/Cordio/platform/include/pal_led.h b/Libraries/Cordio/platform/include/pal_led.h index 9df2db78f7d..c7bb1ff5f55 100644 --- a/Libraries/Cordio/platform/include/pal_led.h +++ b/Libraries/Cordio/platform/include/pal_led.h @@ -42,6 +42,13 @@ enum PalLedReserved_id /* System signals. */ PAL_LED_ID_CPU_ACTIVE = 0x30, /*!< CPU active LED ID. */ PAL_LED_ID_ERROR = 0x31, /*!< Error LED ID. */ + + /* Pre-built BB binary will use these definitions */ + PAL_LED_ID_BB_TX = 0x2, /*!< Baseband TX on indication. */ + PAL_LED_ID_BB_RX = 0x3, /*!< Baseband RX on indication. */ + PAL_LED_ID_BB_RX_OK = 0x4, /*!< Baseband RX success impulse. */ + PAL_LED_ID_BB_RX_TO = 0x5, /*!< Baseband RX timeout impulse. */ + PAL_LED_ID_BB_RX_CRC = 0x6, /*!< Baseband RX CRC error impulse. */ }; /************************************************************************************************** diff --git a/Libraries/Cordio/platform/targets/maxim/build/libCordio.mk b/Libraries/Cordio/platform/targets/maxim/build/libCordio.mk index 87fef2802e2..8c1341e53a8 100644 --- a/Libraries/Cordio/platform/targets/maxim/build/libCordio.mk +++ b/Libraries/Cordio/platform/targets/maxim/build/libCordio.mk @@ -80,6 +80,8 @@ IPATH += $(INC_DIRS) # Add dependencies in the Board library and the PeripheralDrivers IPATH += ${LIBS_DIR}/MiscDrivers/PushButton +IPATH += ${LIBS_DIR}/MiscDrivers/LED +IPATH += ${LIBS_DIR}/Boards/$(TARGET_UC)/$(BOARD)/Include include ${LIBS_DIR}/PeriphDrivers/periphdriver.mk # Use absolute paths if building within eclipse environment. diff --git a/Libraries/Cordio/platform/targets/maxim/max32655/sources/pal_led.c b/Libraries/Cordio/platform/targets/maxim/max32655/sources/pal_led.c index 5a23a616a2f..854918ec9ac 100644 --- a/Libraries/Cordio/platform/targets/maxim/max32655/sources/pal_led.c +++ b/Libraries/Cordio/platform/targets/maxim/max32655/sources/pal_led.c @@ -33,28 +33,12 @@ #include "pal_led.h" #include "gpio.h" +#include "led.h" /************************************************************************************************** Macros **************************************************************************************************/ -#ifndef PAL_BB_LED_ENABLED -#define PAL_BB_LED_ENABLED 1 -#endif - -#define PAL_BB_LED_TX 0x81 -#define PAL_BB_LED_RX 0x82 -#define PAL_BB_LED_RX_OK 0x84 -#define PAL_BB_LED_RX_TO 0x88 -#define PAL_BB_LED_RX_CRC 0x90 - -/* BSP LED Driver */ -extern const unsigned int num_leds; -extern int LED_Init(void); -extern void LED_On(unsigned int idx); -extern void LED_Off(unsigned int idx); -extern const mxc_gpio_cfg_t led_pin[]; - /************************************************************************************************** Local Variables **************************************************************************************************/ @@ -68,13 +52,10 @@ static struct { Functions: Initialization **************************************************************************************************/ - - /************************************************************************************************** Functions: Status and Control **************************************************************************************************/ - /*************************************************************************************************/ /*! * \brief Set LED on, make sure we have enough LEDs. @@ -131,8 +112,8 @@ void PalLedInit(void) /*************************************************************************************************/ void PalLedDeInit(void) { - palLedOff(0); - palLedOff(1); + PalLedOff(PAL_LED_ID_CPU_ACTIVE); + PalLedOff(PAL_LED_ID_ERROR); palLedCb.init = FALSE; } @@ -165,20 +146,9 @@ void PalLedOn(uint8_t ledId) return; default: + palLedOn(ledId); break; } - -#if (PAL_BB_LED_ENABLED == 1) - if(ledId & 0x80){ - /* Remap the mask for the BB LEDs */ - int i; - for(i = 0; i < 7; i++) { - if(ledId & (0x1 << i)) { - palLedOn(2+i); - } - } - } -#endif } /*************************************************************************************************/ @@ -209,52 +179,7 @@ void PalLedOff(uint8_t ledId) return; default: + palLedOff(ledId); break; } - -#if (PAL_BB_LED_ENABLED == 1) - if(ledId & 0x80){ - /* Remap the mask for the BB LEDs */ - int i; - for(i = 0; i < 7; i++) { - if(ledId & (0x1 << i)) { - palLedOff(2+i); - } - } - } -#endif -} -/*************************************************************************************************/ -/*! - * \brief Set LED On Fast as possible, by eliminating overhead. - * - * \param ledId LED ID. - * - * \return None. - */ -/*************************************************************************************************/ -void PalLedFastOn(uint8_t id) -{ - #if LED_ON == 0 - led_pin[id].port->out_clr = led_pin[id].mask; - #else - led_pin[id].port->out_set = led_pin[id].mask; - #endif } -/*************************************************************************************************/ -/*! - * \brief Set LED Off Fast as possible, by eliminating overhead. - * - * \param ledId LED ID. - * - * \return None. - */ -/*************************************************************************************************/ -void PalLedFastOff(uint8_t id) -{ - #if LED_ON == 0 - led_pin[id].port->out_set = led_pin[id].mask; - #else - led_pin[id].port->out_clr = led_pin[id].mask; - #endif -} \ No newline at end of file diff --git a/Libraries/Cordio/platform/targets/maxim/max32690/sources/pal_led.c b/Libraries/Cordio/platform/targets/maxim/max32690/sources/pal_led.c index 38beff9ec38..854918ec9ac 100644 --- a/Libraries/Cordio/platform/targets/maxim/max32690/sources/pal_led.c +++ b/Libraries/Cordio/platform/targets/maxim/max32690/sources/pal_led.c @@ -33,27 +33,12 @@ #include "pal_led.h" #include "gpio.h" +#include "led.h" + /************************************************************************************************** Macros **************************************************************************************************/ -#ifndef PAL_BB_LED_ENABLED -#define PAL_BB_LED_ENABLED 1 -#endif - -#define PAL_BB_LED_TX 0x81 -#define PAL_BB_LED_RX 0x82 -#define PAL_BB_LED_RX_OK 0x84 -#define PAL_BB_LED_RX_TO 0x88 -#define PAL_BB_LED_RX_CRC 0x90 - -/* BSP LED Driver */ -extern const unsigned int num_leds; -extern int LED_Init(void); -extern void LED_On(unsigned int idx); -extern void LED_Off(unsigned int idx); -extern const mxc_gpio_cfg_t led_pin[]; - /************************************************************************************************** Local Variables **************************************************************************************************/ @@ -67,13 +52,10 @@ static struct { Functions: Initialization **************************************************************************************************/ - - /************************************************************************************************** Functions: Status and Control **************************************************************************************************/ - /*************************************************************************************************/ /*! * \brief Set LED on, make sure we have enough LEDs. @@ -130,8 +112,8 @@ void PalLedInit(void) /*************************************************************************************************/ void PalLedDeInit(void) { - palLedOff(0); - palLedOff(1); + PalLedOff(PAL_LED_ID_CPU_ACTIVE); + PalLedOff(PAL_LED_ID_ERROR); palLedCb.init = FALSE; } @@ -156,7 +138,7 @@ void PalLedOn(uint8_t ledId) #ifndef __riscv palLedOn(1); #else - palLedOn(0); /* D1: red */ + palLedOn(0); #endif return; case PAL_LED_ID_ERROR: @@ -164,20 +146,9 @@ void PalLedOn(uint8_t ledId) return; default: + palLedOn(ledId); break; } - -#if (PAL_BB_LED_ENABLED == 1) - if(ledId & 0x80){ - /* Remap the mask for the BB LEDs */ - int i; - for(i = 0; i < 7; i++) { - if(ledId & (0x1 << i)) { - palLedOn(2+i); - } - } - } -#endif } /*************************************************************************************************/ @@ -200,7 +171,7 @@ void PalLedOff(uint8_t ledId) #ifndef __riscv palLedOff(1); #else - palLedOff(0); /* D1: red */ + palLedOff(0); #endif return; case PAL_LED_ID_ERROR: @@ -208,52 +179,7 @@ void PalLedOff(uint8_t ledId) return; default: + palLedOff(ledId); break; } - -#if (PAL_BB_LED_ENABLED == 1) - if(ledId & 0x80){ - /* Remap the mask for the BB LEDs */ - int i; - for(i = 0; i < 7; i++) { - if(ledId & (0x1 << i)) { - palLedOff(2+i); - } - } - } -#endif } -/*************************************************************************************************/ -/*! - * \brief Set LED On Fast as possible, by eliminating overhead. - * - * \param ledId LED ID. - * - * \return None. - */ -/*************************************************************************************************/ -void PalLedFastOn(uint8_t id) -{ - #if LED_ON == 0 - led_pin[id].port->out_clr = led_pin[id].mask; - #else - led_pin[id].port->out_set = led_pin[id].mask; - #endif -} -/*************************************************************************************************/ -/*! - * \brief Set LED Off Fast as possible, by eliminating overhead. - * - * \param ledId LED ID. - * - * \return None. - */ -/*************************************************************************************************/ -void PalLedFastOff(uint8_t id) -{ - #if LED_ON == 0 - led_pin[id].port->out_set = led_pin[id].mask; - #else - led_pin[id].port->out_clr = led_pin[id].mask; - #endif -} \ No newline at end of file