Nordic Thingy:52 v2.2.0
GPIO extender LED driver

GPIO extender LED driver API. More...

Data Structures

struct  drv_ext_light_conf_t
 Struct that defines the type of light (monochrome or RGB) and the corresponding connected pins. All lights are per definition sinked (The IO extender provides ground to the lights). More...
 
struct  drv_ext_light_data_t
 App timer and internal light timing struct. More...
 
struct  drv_ext_light_init_t
 Struct for initializing the light driver. More...
 
struct  drv_ext_light_rgb_intensity_t
 Simplified struct for setting RGB intensity directly. More...
 
struct  drv_ext_light_rgb_sequence_t
 The color mix and sequence variables if a sequence (e.g. breathe) is used. More...
 
struct  drv_ext_light_status_t
 Struct used by the app_timer handler, mainly for power saving. More...
 

Macros

#define DRV_EXT_LIGHT_DEF(light_id)
 Define to create timers associated with each light source.
 
#define DRV_EXT_LIGHT_INTENSITY_MAX   ((uint8_t)(0xFF))
 Maximum light intensity value.
 
#define DRV_EXT_LIGHT_INTENSITY_OFF   (0)
 Minimum light intensity value (off).
 
#define DRV_EXT_LIGHT_INVALID_RESYNC_PIN   255
 If IO extender resync pin is unused.
 
#define DRV_EXT_LIGHT_IOEXT_CLKX_DIV_MAX   (DRV_SX1509_MISC_CLKX_Msk >> DRV_SX1509_MISC_CLKX_Pos)
 Maximum ClkX divider.
 
#define DRV_EXT_LIGHT_MAX_PIN_ID_ALLOWED   16
 Highest I/O extender pin ID possible for a connected light. Dependent on driver implementation.
 
#define DRV_EXT_LIGHT_NUM_LIGHTS_MAX
 Maximum number of lights, depends on the IO extender and maximum of current implementation (16).
 
#define DRV_EXT_LIGHT_STATUS_INIT
 Default initial value configuration for each light.
 
#define SEQUENCE_REAL_VAL_INIT(PARAM)   drv_ext_light_sequence_t PARAM = SEQUENCE_DEFAULT_VAL
 Macro for initializing the sequence struct with default values.
 

Enumerations

enum  {
  DRV_EXT_LIGHT_STATUS_CODE_SUCCESS, DRV_EXT_LIGHT_STATUS_CODE_INVALID_PARAM, DRV_EXT_LIGHT_STATUS_CODE_NOT_SUPPORTED, DRV_EXT_LIGHT_STATUS_CODE_INVALID_LIGHT_TYPE,
  DRV_EXT_LIGHT_STATUS_CODE_INVALID_TIMER_VALUE
}
 The GPIO extender LED driver status codes. More...
 
enum  drv_ext_light_clkx_div_t
 Defines the frequency of the LED driver clock (ClkX) of the SX1509 according to ClkX = fOSC/2^(DRV_EXT_LIGHT_CLKX_DIV_n-1). See SX1509 datasheet for details.
 
enum  drv_ext_light_color_mix_t
 The following color combinations are possible when using drv_ext_light_rgb_sequence_t.
 
enum  drv_ext_light_ioext_osc_status_t {
  EXTENDER_OSC_UNUSED, EXTENDER_OSC_USED_RUNNING, EXTENDER_OSC_USED_PAUSED, EXTENDER_OSC_USED_PERM,
  IOEXT_OSC_STATUS_T_SIZE
}
 The state of the IO extender oscillator for each light. More...
 
enum  drv_ext_light_reg_type_t { DRV_EXT_LIGHT_TYPE_MONO, DRV_EXT_LIGHT_TYPE_RGB }
 Monochrome (single) or RGB light. More...
 

Functions

ret_code_t drv_ext_light_init (drv_ext_light_init_t const *p_init, bool on_init_reset)
 Function for initializing the drv_ext_light driver. More...
 
ret_code_t drv_ext_light_intensity_set (uint32_t id, uint8_t intensity)
 Function for setting intensity of monochrome light. More...
 
ret_code_t drv_ext_light_off (uint32_t id)
 Function for turning a given light off. More...
 
ret_code_t drv_ext_light_on (uint32_t id)
 Function for turning a given light on. More...
 
ret_code_t drv_ext_light_reset (void)
 Function for resetting all the registers of the IO extender to their default values. More...
 
ret_code_t drv_ext_light_rgb_intensity_set (uint32_t id, drv_ext_light_rgb_intensity_t const *const p_intensity)
 Function for setting color for RGB LEDs. More...
 
ret_code_t drv_ext_light_rgb_sequence (uint32_t id, drv_ext_light_rgb_sequence_t *const p_sequence)
 Function for setting color for a given light through the GPIO extender. More...
 
ret_code_t drv_ext_light_sequence (uint32_t id, drv_ext_light_sequence_t *const p_sequence)
 Function for setting color for a given light through the GPIO extender. More...
 

Detailed Description

GPIO extender LED driver API.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

The GPIO extender LED driver status codes.

Enumerator
DRV_EXT_LIGHT_STATUS_CODE_SUCCESS 

Successful.

DRV_EXT_LIGHT_STATUS_CODE_INVALID_PARAM 

Invalid parameters.

DRV_EXT_LIGHT_STATUS_CODE_NOT_SUPPORTED 

Not supported.

DRV_EXT_LIGHT_STATUS_CODE_INVALID_LIGHT_TYPE 

The type of light is not supported.

DRV_EXT_LIGHT_STATUS_CODE_INVALID_TIMER_VALUE 

The desired time is too long. Increase the ClkX divider.

◆ drv_ext_light_ioext_osc_status_t

The state of the IO extender oscillator for each light.

Enumerator
EXTENDER_OSC_UNUSED 

Ext osc not used for this light.

EXTENDER_OSC_USED_RUNNING 

Ext osc running (Light currently on).

EXTENDER_OSC_USED_PAUSED 

Ext osc paused (Light currently off).

EXTENDER_OSC_USED_PERM 

Ext osc used on a permanent basis (light dimmed).

IOEXT_OSC_STATUS_T_SIZE 

Number of different possible IO extender oscillator statuses.

◆ drv_ext_light_reg_type_t

Monochrome (single) or RGB light.

Enumerator
DRV_EXT_LIGHT_TYPE_MONO 

Monochrome (single) LED.

DRV_EXT_LIGHT_TYPE_RGB 

RGB LED (three IOs used).

Function Documentation

◆ drv_ext_light_init()

ret_code_t drv_ext_light_init ( drv_ext_light_init_t const *  p_init,
bool  on_init_reset 
)

Function for initializing the drv_ext_light driver.

Parameters
[in]p_initContains the full configuration struct sent to drv_ext_light_init drv_ext_light_init_t.
[in]on_init_resetIf true, the io extender will be reset on init. This will put the io extender in a known state, but will delete any previous configurations, even from other drivers.
Note
Make sure that APP_SCHED_INIT and APP_TIMER_APPSH_INIT have been run prior to this function call. Also note that this driver will take full control of the IO extender oscillator. This may influence other HW connected to the extender on other pins. p_init->p_light_conf->p_data must reside in RAM.
Returns
Status codes from this function. (Return codes may originate from other underlying modules/drivers as well which are not listed below).
Return values
DRV_EXT_LIGHT_STATUS_CODE_SUCCESS
DRV_EXT_LIGHT_STATUS_CODE_INVALID_PARAM

◆ drv_ext_light_intensity_set()

ret_code_t drv_ext_light_intensity_set ( uint32_t  id,
uint8_t  intensity 
)

Function for setting intensity of monochrome light.

Parameters
[in]idSpecifies the ID of the given light. (Has to be in the range [0, num_lights-1]).
[in]intensity(0-255).
Returns
Status codes from this function. (Return codes may originate from other underlying modules/drivers as well which are not listed below).
Return values
DRV_EXT_LIGHT_STATUS_CODE_SUCCESS
DRV_EXT_LIGHT_STATUS_CODE_INVALID_PARAM

◆ drv_ext_light_off()

ret_code_t drv_ext_light_off ( uint32_t  id)

Function for turning a given light off.

Parameters
[in]idValid light ID (Has to be in the range [0, num_lights-1]).
Note
In case the given LED ID corresponds to a RGB light, all colors will be set to 0 intensity.
Returns
Status codes from this function. (Return codes may originate from other underlying modules/drivers as well which are not listed below).
Return values
DRV_EXT_LIGHT_STATUS_CODE_SUCCESS
DRV_EXT_LIGHT_STATUS_CODE_INVALID_PARAM

◆ drv_ext_light_on()

ret_code_t drv_ext_light_on ( uint32_t  id)

Function for turning a given light on.

Parameters
[in]idValid light ID.
Note
In case the given LED ID corresponds to an RGB light, all colors will be set to max intensity.
Returns
Status codes from this function. (Return codes may originate from other underlying modules/drivers as well which are not listed below).
Return values
DRV_EXT_LIGHT_STATUS_CODE_SUCCESS
DRV_EXT_LIGHT_STATUS_CODE_INVALID_PARAM

◆ drv_ext_light_reset()

ret_code_t drv_ext_light_reset ( void  )

Function for resetting all the registers of the IO extender to their default values.

Warning
This reset applies to all registers, regardless if they were set by another driver outside of drv_ext_light.
Returns
Status codes from this function. (Return codes may originate from other underlying modules/drivers as well which are not listed below).
Return values
DRV_EXT_LIGHT_STATUS_CODE_SUCCESS

◆ drv_ext_light_rgb_intensity_set()

ret_code_t drv_ext_light_rgb_intensity_set ( uint32_t  id,
drv_ext_light_rgb_intensity_t const *const  p_intensity 
)

Function for setting color for RGB LEDs.

Parameters
[in]idSpecifies the ID of the given light. (Has to be in the range [0, num_lights-1]).
[in]p_intensity(0-255).
Returns
Status codes from this function. (Return codes may originate from other underlying modules/drivers as well which are not listed below).
Return values
DRV_EXT_LIGHT_STATUS_CODE_SUCCESS
DRV_EXT_LIGHT_STATUS_CODE_INVALID_PARAM

◆ drv_ext_light_rgb_sequence()

ret_code_t drv_ext_light_rgb_sequence ( uint32_t  id,
drv_ext_light_rgb_sequence_t *const  p_sequence 
)

Function for setting color for a given light through the GPIO extender.

Parameters
[in]idSpecifies the ID of the given light. (Has to be in the range [0, num_lights-1]).
[in,out]p_sequenceRGB sequence struct. s
Note
The actual timings in milliseconds will not necessarily correspond to the supplied times. The underlying functionality will choose register values to obtain timings as close as possible. Adjusting drv_ext_light_clkx_div_t::clkx_div supplied to drv_ext_light_init will influence the accuracy of this function. Also note that for the remaining intensity and fade parameters, values will be set as close as possible to the desired values. The user may read back p_sequence, which will be populated with the actual values.
If the resync_pin is used, calling this function will resync all counters on the IO extender.
Returns
Status codes from this function. (Return codes may originate from other underlying modules/drivers as well which are not listed below).
Return values
DRV_EXT_LIGHT_STATUS_CODE_SUCCESS
DRV_EXT_LIGHT_STATUS_CODE_INVALID_PARAM

◆ drv_ext_light_sequence()

ret_code_t drv_ext_light_sequence ( uint32_t  id,
drv_ext_light_sequence_t *const  p_sequence 
)

Function for setting color for a given light through the GPIO extender.

Parameters
[in]idSpecifies the ID of the given light. (Has to be in the range [0, num_lights-1]).
[in,out]p_sequenceSequence struct.
Note
The actual timings in milliseconds will not necessarily correspond to the supplied times. The underlying functionality will choose register values to obtain timings as close as possible. Adjusting DRV_EXT_LIGHT_CLKX_DIV will influence the accuracy of this function. Also note that for the remaining intensity and fade parameters, values will be set as close as possible to the desired values. The user may read back p_sequence, which will be populated with the actual values.
If the resync_pin is used, calling this function will resync all counters on the IO extender.
Returns
Status codes from this function. (Return codes may originate from other underlying modules/drivers as well which are not listed below).
Return values
DRV_EXT_LIGHT_STATUS_CODE_SUCCESS
DRV_EXT_LIGHT_STATUS_CODE_INVALID_PARAM