LED
The LED driver provides API to control I2C/GPIO based LED present in the board. The driver supports multiple LED control for the LEDs connected to the same I2C controller using a single API which can be used to set LED ON/OFF for multiple LED at the same time.
Features Supported
API to turn ON/OFF LED
Set LED mask using single API to set the LED state of multiple LEDs connected to same controller at one go
SysConfig Features
Note
It is strongly recommend to use SysConfig where it is available instead of using direct SW API calls. This will help simplify the SW application and also catch common mistakes early in the development cycle.
Option to select LED type based on board
Supported LED
GPIO
TPIC2810 (I2C based)
IO Expander: TCA6424 (I2C based)
Based on the type of LED controller selected, the GPIO or I2C driver can be configured
In case of IO Expander based LED control, provides option to select the pin to which the LED is connected
In case of I2C based LED controller, ability to provide the I2C slave address of the controller
Features NOT Supported
Set mask API is not supported for GPIO based LED as typically only one LED is connected to a single instance of GPIO pin
Important Usage Guidelines
None
Example Usage
Include the below file to access the APIs
//! [include]
#include <board/led.h>
//! [include]
LED ON API
//! [on]
status = LED_on(ledHandle, 0U);
DebugP_assert(SystemP_SUCCESS == status);
//! [on]
LED OFF API
//! [off]
status = LED_off(ledHandle, 0U);
DebugP_assert(SystemP_SUCCESS == status);
//! [off]
API Reference
LED driver implementation callbacks
-
typedef int32_t (*LED_OpenFxn)(LED_Config *config, const LED_Params *params)
Driver implementation to open a specific LED driver.
Typically this callback is hidden from the end application and is implemented when a new type of LED device needs to be implemented.
- Param config:
[IN] LED configuration for the specific LED device
- Param params:
[IN] User controllable parameters when opening the LED device
- Return:
SystemP_SUCCESS on success, else failure
-
typedef void (*LED_CloseFxn)(LED_Config *config)
Driver implementation to close a specific LED driver.
Typically this callback is hidden from the end application and is implemented when a new type of LED device needs to be implemented.
- Param config:
[IN] LED configuration for the specific LED device
- Return:
SystemP_SUCCESS on success, else failure
-
typedef int32_t (*LED_OnFxn)(LED_Config *config, uint32_t index)
Driver implementation to power on an LED using a specific LED driver.
Typically this callback is hidden from the end application and is implemented when a new type of LED device needs to be implemented.
- Param config:
[IN] LED configuration for the specific LED device
- Param index:
[IN] Index to the LED group which needs to be turned on
- Return:
SystemP_SUCCESS on success, else failure
-
typedef int32_t (*LED_OffFxn)(LED_Config *config, uint32_t index)
Driver implementation to power off an LED using a specific LED driver.
Typically this callback is hidden from the end application and is implemented when a new type of LED device needs to be implemented.
- Param config:
[IN] LED configuration for the specific LED device
- Param index:
[IN] Index to the LED group which needs to be turned off
- Return:
SystemP_SUCCESS on success, else failure
-
typedef int32_t (*LED_SetMaskFxn)(LED_Config *config, uint32_t mask)
Driver implementation to set group mask using a specific LED driver.
Typically this callback is hidden from the end application and is implemented when a new type of LED device needs to be implemented.
- Param config:
[IN] LED configuration for the specific LED device
- Param mask:
[IN] Bit Mask to set at one go
- Return:
SystemP_SUCCESS on success, else failure
Typedefs
-
typedef void *LED_Handle
Handle to the LED driver returned by LED_open()
Functions
-
void LED_Params_init(LED_Params *params)
Set default parameters in the LED_Params_s structure.
Call this API to set defaults and then override the fields as needed before calling LED_open.
- Parameters:
params – [OUT] Initialized parameters
-
LED_Handle LED_open(uint32_t instanceId, const LED_Params *params)
Open LED driver.
Make sure the SOC peripheral driver is open’ed before calling this API. Drivers_open function generated by SysCfg opens the underlying SOC peripheral driver, e.g I2C.
Global variables
LED_Config gLedConfig[]anduint32_t gLedConfigNumis instantiated by SysCfg to describe the LED configuration based on user selection in SysCfg.- Parameters:
instanceId – [IN] Index within
LED_Config gLedConfig[]denoting the LED driver to openparams – [IN] Open parameters
- Returns:
Handle to LED driver which should be used in subsequent API call Else returns NULL in case of failure
-
void LED_close(LED_Handle handle)
Open LED driver.
- Parameters:
handle – [IN] LED driver handle from LED_open
-
int32_t LED_on(LED_Handle handle, uint32_t index)
API to power on the LED.
- Parameters:
handle – [IN] LED driver handle from LED_open
index – [IN] Index to the LED group which needs to be turned on. In case of GPIO controlled LED, set this to 0.
- Returns:
SystemP_SUCCESS on success, else failure
-
int32_t LED_off(LED_Handle handle, uint32_t index)
API to power off the LED.
- Parameters:
handle – [IN] LED driver handle from LED_open
index – [IN] Index to the LED group which needs to be turned off. In case of GPIO controlled LED, set this to 0.
- Returns:
SystemP_SUCCESS on success, else failure
-
int32_t LED_setMask(LED_Handle handle, uint32_t mask)
API to set the group mask incase of I2C controlled LED having more than one LED connected to the controller.
- Parameters:
handle – [IN] LED driver handle from LED_open
mask – [IN] Bit Mask to set at one go. Only bits upto the number of LED present in a group will be used by this function. Set bit to 0 for OFF. Set bit to 1 for ON.
- Returns:
SystemP_SUCCESS on success, else failure
-
struct LED_Params_s
- #include <led.h>
Parameters passed during LED_open()
Forward declaration of LED_Params_s.
Public Members
-
uint32_t gpioBaseAddr
Underlying GPIO instance that is used by the LED driver incase of GPIO controlled LED
-
uint32_t gpioPinNum
GPIO pin to be used
-
uint32_t i2cInstance
Underlying peripheral driver instance that is used by the LED driver incase of I2C controlled LED
-
uint32_t i2cAddress
I2C address for IO expander or external LED driver
-
uint32_t ioIndex
Index to the IO expander which needs to be set/reset. Applicable only for IO expander based LED.
-
uint32_t gpioBaseAddr
-
struct LED_Fxns
- #include <led.h>
Driver implementation callbacks.
Public Members
-
LED_OpenFxn openFxn
LED driver implementation specific callback
-
LED_CloseFxn closeFxn
LED driver implementation specific callback
-
LED_OffFxn offFxn
LED driver implementation specific callback
-
LED_SetMaskFxn setMaskFxn
LED driver implementation specific callback
-
LED_OpenFxn openFxn
-
struct LED_Attrs
- #include <led.h>
LED device attributes, these are filled by SysCfg based on the device that is selected.
Public Members
-
uint32_t numLedPerGroup
Number of LED in a group
-
uint32_t numLedPerGroup
-
struct LED_Config_s
- #include <led.h>
LED driver configuration, these are filled by SysCfg based on the device that is selected.
Forward declaration of LED_Config_s.
-
struct LED_Object
- #include <led.h>
LED driver object - not to be used by application.
Public Members
-
I2C_Handle i2cHandle
I2C driver handle
-
uint32_t gpioBaseAddr
Underlying GPIO instance that is used by the LED driver incase of GPIO controlled LED
-
uint32_t gpioPinNum
GPIO pin to be used
-
uint32_t i2cInstance
Underlying I2C driver instance that is used by the LED driver incase of I2C controlled LED
-
uint32_t i2cAddress
I2C address for IO expander or external LED driver
-
uint32_t ioIndex
Index to the IO expander which needs to be set/reset. Applicable only for IO expander based LED.
-
I2C_Handle i2cHandle