LEDDRV - LED Pre-Driver#
Example#
This example shows how to configure and use the LEDDRV peripheral for driving LED lights using both single and dual drive modes.
#include "sl_hal_leddrv.h"
#include "sl_clock_manager.h"
// Example function showing how to initialize and use the LEDDRV for LED control
void leddrv_example(void)
{
// Enable clock to the LEDDRV peripheral
sl_clock_manager_enable_bus_clock(SL_BUS_CLOCK_LEDDRV0);
sl_clock_manager_enable_bus_clock(SL_BUS_CLOCK_GPIO);
// Configure LEDDRV peripheral
sl_hal_leddrv_init_t init = {
.dual_drive_mode_enable = true, // Enable dual drive mode
.direct_drive_mode_enable = false, // Disable direct drive mode
.peak_current_foldback_enable = true, // Enable peak current foldback
.disable_ocflag_hardware_control = false, // Enable overcurrent flag hardware control
.enable_forced_calibration = false, // Don't force enable (use internal enable)
.time_on_max = SL_HAL_LEDDRV_TIME_MAX_12P8US, // Set max on time to 12.8us
.time_off_max = SL_HAL_LEDDRV_TIME_MAX_38P4US, // Set max off time to 38.4us
.ipeak_detect_ref_adjust = SL_HAL_LEDDRV_IPEAK_DETECT_REF_ADJUST_300MV,
.overcurrent_ref_adjust = SL_HAL_LEDDRV_IPEAK_OVERCURRENT_REF_ADJUST_800MV,
.ton_cal_mode = SL_HAL_LEDDRV_TON_CAL_MODE_BOTH_CHANNELS,
.fixed_ton_sel_lsb = SL_HAL_LEDDRV_FIXED_TON_SEL_LSB_5MV,
// Configure GPIO pins for LEDDRV - only Port C or D can be used
.vac_gpio_select = { SL_HAL_LEDDRV_PORT_SELECT_PORT_C, 0 },
.current_sense0_gpio_select = { SL_HAL_LEDDRV_PORT_SELECT_PORT_C, 1 },
.drain_sense0_gpio_select = { SL_HAL_LEDDRV_PORT_SELECT_PORT_C, 2 },
.current_sense1_gpio_select = { SL_HAL_LEDDRV_PORT_SELECT_PORT_C, 3 },
.drain_sense1_gpio_select = { SL_HAL_LEDDRV_PORT_SELECT_PORT_C, 4 }
};
// Initialize the LEDDRV with the configuration
sl_hal_leddrv_init(LEDDRV0, &init);
// Enable the LEDDRV peripheral
sl_hal_leddrv_enable(LEDDRV0);
// Configure interrupts if needed
sl_hal_leddrv_clear_interrupts(LEDDRV0, _LEDDRV_IEN_MASK);
sl_hal_leddrv_enable_interrupts(LEDDRV0, LEDDRV_IEN_OCDET0); // Enable overcurrent detection interrupt
// Wait for a while to let the LEDDRV operate
// In a real application, this would be replaced with application code
// or you would respond to interrupts
for (volatile int i = 0; i < 1000; i++) {}
// Check for any overcurrent conditions
uint32_t status = sl_hal_leddrv_get_status(LEDDRV0);
if (status & LEDDRV_STATUS_OCFLAG0) {
// Handle overcurrent condition on channel 0
sl_hal_leddrv_clear_ocflag_channel0(LEDDRV0);
}
// Clean up and disable LEDDRV when done
sl_hal_leddrv_disable_interrupts(LEDDRV0, _LEDDRV_IEN_MASK);
sl_hal_leddrv_disable(LEDDRV0);
sl_hal_leddrv_wait_ready(LEDDRV0);
// Disable clocks to save power
sl_clock_manager_disable_bus_clock(SL_BUS_CLOCK_LEDDRV0);
sl_clock_manager_disable_bus_clock(SL_BUS_CLOCK_GPIO);
}
Modules#
Enumerations#
Used for Max On time and max Off time of LEDDRV.
Time On calibration channel mode.
Peak current detect reference adjust value.
Over current reference adjust.
Fixed Ton Select LSBs.
Port selection for LEDDRV gpio selection (only ports C/D allowed).
Functions#
Initialize LEDDRV.
Wait for disabling to finish.
Enable LEDDRV.
Disable LEDDRV.
Enable LEDDRV dual drive mode.
Disable LEDDRV dual drive mode.
Enable LEDDRV peak current foldback mode.
Disable LEDDRV peak current foldback mode.
Enable LEDDRV direct drive mode.
Disable LEDDRV direct drive mode.
Enable LEDDRV Hardware overcurrent control.
Disable LEDDRV Hardware overcurrent control.
Set LEDDRV Ton calibration trigger.
Clear LEDDRV Ton calibration trigger.
Clear LEDDRV Overcurrent Flag on channel 0.
Clear LEDDRV Overcurrent Flag on channel 1.
Reset the LEDDRV.
Gets LEDDRV STATUS register value.
Clear one or more pending LEDDRV interrupts.
Set one or more pending LEDDRV interrupts from SW.
Disable one or more LEDDRV interrupts.
Enable one or more LEDDRV interrupts.
Get pending LEDDRV interrupt flags.
Get enabled LEDDRV interrupt flags.
Get enabled and pending LEDDRV interrupt flags.
Macros#
Check if LEDDRV instance is valid.
Default configuration for LEDDRV port/pin structure.
Default configuration for LEDDRV initialization structure.
Enumeration Documentation#
sl_hal_leddrv_time_max_t#
sl_hal_leddrv_time_max_t
Used for Max On time and max Off time of LEDDRV.
Enumerator | |
---|---|
SL_HAL_LEDDRV_TIME_MAX_DISABLE | Max On/Off time is disabled. |
SL_HAL_LEDDRV_TIME_MAX_6P4US | Max On/Off time is 6.4 us. |
SL_HAL_LEDDRV_TIME_MAX_12P8US | Max On/Off time is 12.8 us. |
SL_HAL_LEDDRV_TIME_MAX_19P2US | Max On/Off time is 19.2 us. |
SL_HAL_LEDDRV_TIME_MAX_25P6US | Max On/Off time is 25.6 us. |
SL_HAL_LEDDRV_TIME_MAX_32P0US | Max On/Off time is 32.0 us. |
SL_HAL_LEDDRV_TIME_MAX_38P4US | Max On/Off time is 38.4 us. |
SL_HAL_LEDDRV_TIME_MAX_44P8US | Max On/Off time is 44.8 us. |
sl_hal_leddrv_ton_cal_mode_t#
sl_hal_leddrv_ton_cal_mode_t
Time On calibration channel mode.
Enumerator | |
---|---|
SL_HAL_LEDDRV_TON_CAL_MODE_CURRENT_CHANNEL_ONLY | Current channel only. |
SL_HAL_LEDDRV_TON_CAL_MODE_BOTH_CHANNELS | Both channels. |
SL_HAL_LEDDRV_TON_CAL_MODE_ON_FORCE | Calibration On force. |
SL_HAL_LEDDRV_TON_CAL_MODE_FIXED | Calibration is Fixed. |
sl_hal_leddrv_ipeak_detect_ref_adjust_t#
sl_hal_leddrv_ipeak_detect_ref_adjust_t
Peak current detect reference adjust value.
Enumerator | |
---|---|
SL_HAL_LEDDRV_IPEAK_DETECT_REF_ADJUST_200MV | ipeak detect reference adjust 200 mV. |
SL_HAL_LEDDRV_IPEAK_DETECT_REF_ADJUST_300MV | ipeak detect reference adjust 300 mV. |
SL_HAL_LEDDRV_IPEAK_DETECT_REF_ADJUST_400MV | ipeak detect reference adjust 400 mV. |
SL_HAL_LEDDRV_IPEAK_DETECT_REF_ADJUST_500MV | ipeak detect reference adjust 500 mV. |
sl_hal_leddrv_overcurrent_ref_adjust_t#
sl_hal_leddrv_overcurrent_ref_adjust_t
Over current reference adjust.
Enumerator | |
---|---|
SL_HAL_LEDDRV_IPEAK_OVERCURRENT_REF_ADJUST_400MV | Overcurrent reference adjust 400 mV. |
SL_HAL_LEDDRV_IPEAK_OVERCURRENT_REF_ADJUST_600MV | Overcurrent reference adjust 600 mV. |
SL_HAL_LEDDRV_IPEAK_OVERCURRENT_REF_ADJUST_800MV | Overcurrent reference adjust 800 mV. |
SL_HAL_LEDDRV_IPEAK_OVERCURRENT_REF_ADJUST_1000MV | Overcurrent reference adjust 1000 mV. |
sl_hal_leddrv_fixed_ton_sel_lsb_t#
sl_hal_leddrv_fixed_ton_sel_lsb_t
Fixed Ton Select LSBs.
Enumerator | |
---|---|
SL_HAL_LEDDRV_FIXED_TON_SEL_LSB_0MV | LSB is 0 mV. |
SL_HAL_LEDDRV_FIXED_TON_SEL_LSB_1MV | LSB is 1 mV. |
SL_HAL_LEDDRV_FIXED_TON_SEL_LSB_2MV | LSB is 2 mV. |
SL_HAL_LEDDRV_FIXED_TON_SEL_LSB_3MV | LSB is 3 mV. |
SL_HAL_LEDDRV_FIXED_TON_SEL_LSB_4MV | LSB is 4 mV. |
SL_HAL_LEDDRV_FIXED_TON_SEL_LSB_5MV | LSB is 5 mV. |
SL_HAL_LEDDRV_FIXED_TON_SEL_LSB_6MV | LSB is 6 mV. |
SL_HAL_LEDDRV_FIXED_TON_SEL_LSB_7MV | LSB is 7 mV. |
SL_HAL_LEDDRV_FIXED_TON_SEL_LSB_8MV | LSB is 8 mV. |
SL_HAL_LEDDRV_FIXED_TON_SEL_LSB_9MV | LSB is 9 mV. |
SL_HAL_LEDDRV_FIXED_TON_SEL_LSB_10MV | LSB is 10 mV. |
SL_HAL_LEDDRV_FIXED_TON_SEL_LSB_11MV | LSB is 11 mV. |
SL_HAL_LEDDRV_FIXED_TON_SEL_LSB_12MV | LSB is 12 mV. |
SL_HAL_LEDDRV_FIXED_TON_SEL_LSB_13MV | LSB is 13 mV. |
SL_HAL_LEDDRV_FIXED_TON_SEL_LSB_14MV | LSB is 14 mV. |
SL_HAL_LEDDRV_FIXED_TON_SEL_LSB_15MV | LSB is 15 mV. |
sl_hal_leddrv_port_select_t#
sl_hal_leddrv_port_select_t
Port selection for LEDDRV gpio selection (only ports C/D allowed).
Enumerator | |
---|---|
SL_HAL_LEDDRV_PORT_SELECT_NONE | Select no Port. |
SL_HAL_LEDDRV_PORT_SELECT_PORT_C | Select Port C. |
SL_HAL_LEDDRV_PORT_SELECT_PORT_D | Select Port D. |
Function Documentation#
sl_hal_leddrv_init#
void sl_hal_leddrv_init (LEDDRV_TypeDef * leddrv, const sl_hal_leddrv_init_t * init)
Initialize LEDDRV.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | A pointer to the LEDDRV peripheral register block. |
const sl_hal_leddrv_init_t * | [in] | init | A pointer to the LEDDRV initialization structure. |
This function will allocate GPIO CD bus to LEDDRV. Make sure to set port/pin to C/D ports and pins in the init structure.
sl_hal_leddrv_wait_ready#
void sl_hal_leddrv_wait_ready (LEDDRV_TypeDef * leddrv)
Wait for disabling to finish.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
sl_hal_leddrv_enable#
void sl_hal_leddrv_enable (LEDDRV_TypeDef * leddrv)
Enable LEDDRV.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
sl_hal_leddrv_disable#
void sl_hal_leddrv_disable (LEDDRV_TypeDef * leddrv)
Disable LEDDRV.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
sl_hal_leddrv_enable_dual_drive_mode#
void sl_hal_leddrv_enable_dual_drive_mode (LEDDRV_TypeDef * leddrv)
Enable LEDDRV dual drive mode.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
sl_hal_leddrv_disable_dual_drive_mode#
void sl_hal_leddrv_disable_dual_drive_mode (LEDDRV_TypeDef * leddrv)
Disable LEDDRV dual drive mode.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
sl_hal_leddrv_enable_peak_current_foldback#
void sl_hal_leddrv_enable_peak_current_foldback (LEDDRV_TypeDef * leddrv)
Enable LEDDRV peak current foldback mode.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
sl_hal_leddrv_disable_peak_current_foldback#
void sl_hal_leddrv_disable_peak_current_foldback (LEDDRV_TypeDef * leddrv)
Disable LEDDRV peak current foldback mode.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
sl_hal_leddrv_enable_direct_drive_mode#
void sl_hal_leddrv_enable_direct_drive_mode (LEDDRV_TypeDef * leddrv)
Enable LEDDRV direct drive mode.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
sl_hal_leddrv_disable_direct_drive_mode#
void sl_hal_leddrv_disable_direct_drive_mode (LEDDRV_TypeDef * leddrv)
Disable LEDDRV direct drive mode.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
sl_hal_leddrv_enable_ocflag_hardware_control#
void sl_hal_leddrv_enable_ocflag_hardware_control (LEDDRV_TypeDef * leddrv)
Enable LEDDRV Hardware overcurrent control.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
sl_hal_leddrv_disable_ocflag_hardware_control#
void sl_hal_leddrv_disable_ocflag_hardware_control (LEDDRV_TypeDef * leddrv)
Disable LEDDRV Hardware overcurrent control.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
sl_hal_leddrv_set_ton_forced_calibration#
void sl_hal_leddrv_set_ton_forced_calibration (LEDDRV_TypeDef * leddrv)
Set LEDDRV Ton calibration trigger.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
sl_hal_leddrv_clear_ton_forced_calibration#
void sl_hal_leddrv_clear_ton_forced_calibration (LEDDRV_TypeDef * leddrv)
Clear LEDDRV Ton calibration trigger.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
sl_hal_leddrv_clear_ocflag_channel0#
void sl_hal_leddrv_clear_ocflag_channel0 (LEDDRV_TypeDef * leddrv)
Clear LEDDRV Overcurrent Flag on channel 0.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
sl_hal_leddrv_clear_ocflag_channel1#
void sl_hal_leddrv_clear_ocflag_channel1 (LEDDRV_TypeDef * leddrv)
Clear LEDDRV Overcurrent Flag on channel 1.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
sl_hal_leddrv_reset#
void sl_hal_leddrv_reset (LEDDRV_TypeDef * leddrv)
Reset the LEDDRV.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | A leddrv peripheral module. |
sl_hal_leddrv_get_status#
uint32_t sl_hal_leddrv_get_status (LEDDRV_TypeDef * leddrv)
Gets LEDDRV STATUS register value.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | A LEDDRV peripheral module. |
Returns
Current STATUS register value.
sl_hal_leddrv_clear_interrupts#
void sl_hal_leddrv_clear_interrupts (LEDDRV_TypeDef * leddrv, uint32_t flags)
Clear one or more pending LEDDRV interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
uint32_t | [in] | flags | Pending LEDDRV interrupt source(s) to clear. Use one or more valid interrupt flags for the LEDDRV module (LEDDRV_IF_nnn) OR'ed together. |
sl_hal_leddrv_set_interrupts#
void sl_hal_leddrv_set_interrupts (LEDDRV_TypeDef * leddrv, uint32_t flags)
Set one or more pending LEDDRV interrupts from SW.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
uint32_t | [in] | flags | LEDDRV interrupt source(s) to set to pending. Use one or more valid interrupt flags for the LEDDRV module (LEDDRV_IF_nnn) OR'ed together. |
sl_hal_leddrv_disable_interrupts#
void sl_hal_leddrv_disable_interrupts (LEDDRV_TypeDef * leddrv, uint32_t flags)
Disable one or more LEDDRV interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
uint32_t | [in] | flags | LEDDRV interrupt source(s) to disable. Use one or more valid interrupt flags for the LEDDRV module (LEDDRV_IEN_nnn) OR'ed together. |
sl_hal_leddrv_enable_interrupts#
void sl_hal_leddrv_enable_interrupts (LEDDRV_TypeDef * leddrv, uint32_t flags)
Enable one or more LEDDRV interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
uint32_t | [in] | flags | LEDDRV interrupt source(s) to enable. Use one or more valid interrupt flags for the LEDDRV module (LEDDRV_IEN_nnn) OR'ed together. |
Note
Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. To ignore a pending interrupt, consider using sl_hal_leddrv_clear_interrupts() prior to enabling the interrupt.
sl_hal_leddrv_get_pending_interrupts#
uint32_t sl_hal_leddrv_get_pending_interrupts (LEDDRV_TypeDef * leddrv)
Get pending LEDDRV interrupt flags.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
Note
Event bits are not cleared by this function.
Returns
LEDDRV interrupt source(s) pending. Returns one or more valid interrupt flags for the LEDDRV module (LEDDRV_IF_nnn) OR'ed together.
sl_hal_leddrv_get_enabled_interrupts#
uint32_t sl_hal_leddrv_get_enabled_interrupts (LEDDRV_TypeDef * leddrv)
Get enabled LEDDRV interrupt flags.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
Note
Event bits are not cleared by this function.
Returns
LEDDRV interrupt source(s) enabled. Returns one or more valid enabled interrupt sources in LEDDRVx_IEN_nnn.
sl_hal_leddrv_get_enabled_pending_interrupts#
uint32_t sl_hal_leddrv_get_enabled_pending_interrupts (LEDDRV_TypeDef * leddrv)
Get enabled and pending LEDDRV interrupt flags.
Type | Direction | Argument Name | Description |
---|---|---|---|
LEDDRV_TypeDef * | [in] | leddrv | Pointer to the LEDDRV peripheral register block. |
Useful for handling more interrupt sources in the same interrupt handler.
Note
Interrupt flags are not cleared by this function.
Returns
Pending and enabled LEDDRV interrupt sources. The return value is the bitwise AND combination of
the OR combination of enabled interrupt sources in LEDDRVx_IEN_nnn register (LEDDRVx_IEN_nnn) and
the OR combination of valid interrupt flags of the LEDDRV module (LEDDRVx_IF_nnn).