Skip to content

Commit

Permalink
refactor(BLE): Simplifying LED interface with libphy. (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-gillespie committed Aug 26, 2024
1 parent c42d977 commit fd9d477
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 162 deletions.
7 changes: 7 additions & 0 deletions Libraries/Cordio/platform/include/pal_led.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
};

/**************************************************************************************************
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Cordio/platform/targets/maxim/build/libCordio.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
85 changes: 5 additions & 80 deletions Libraries/Cordio/platform/targets/maxim/max32655/sources/pal_led.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
**************************************************************************************************/
Expand All @@ -68,13 +52,10 @@ static struct {
Functions: Initialization
**************************************************************************************************/



/**************************************************************************************************
Functions: Status and Control
**************************************************************************************************/


/*************************************************************************************************/
/*!
* \brief Set LED on, make sure we have enough LEDs.
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
}

/*************************************************************************************************/
Expand Down Expand Up @@ -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
}
90 changes: 8 additions & 82 deletions Libraries/Cordio/platform/targets/maxim/max32690/sources/pal_led.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
**************************************************************************************************/
Expand All @@ -67,13 +52,10 @@ static struct {
Functions: Initialization
**************************************************************************************************/



/**************************************************************************************************
Functions: Status and Control
**************************************************************************************************/


/*************************************************************************************************/
/*!
* \brief Set LED on, make sure we have enough LEDs.
Expand Down Expand Up @@ -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;
}

Expand All @@ -156,28 +138,17 @@ void PalLedOn(uint8_t ledId)
#ifndef __riscv
palLedOn(1);
#else
palLedOn(0); /* D1: red */
palLedOn(0);
#endif
return;
case PAL_LED_ID_ERROR:
palLedOn(0);
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
}

/*************************************************************************************************/
Expand All @@ -200,60 +171,15 @@ void PalLedOff(uint8_t ledId)
#ifndef __riscv
palLedOff(1);
#else
palLedOff(0); /* D1: red */
palLedOff(0);
#endif
return;
case PAL_LED_ID_ERROR:
palLedOff(0);
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
}

0 comments on commit fd9d477

Please sign in to comment.