LED Part Drivers PWM API Documentation

This page documents the API of the LED Part Drivers PWM.

An overview of the driver is also available here: main_doc .

Functions

Functions

led_pwm_status_t led_pwm_init ( led_pwm_t * pled , uint32_t id )

Initializes the LED PWM object.

Parameters :
  • pled – pointer to the LED PWM object

  • id – configuration ID

Return values :

error – status

int32_t led_pwm_io_init ( led_pwm_t * pled )

Assigns resources to the LED PWM object.

Note

This function must be overridden in codegen or otherwise with a proper implementation.

Parameters :

pled – pointer to the LED PWM object

Return values :

error – status: 0=success, -1=error

led_pwm_status_t led_pwm_on ( led_pwm_t * pled )

Turns the LED on.

Parameters :

pled – pointer to the LED PWM object

Return values :

error – status

led_pwm_status_t led_pwm_off ( led_pwm_t * pled )

Turns the LED off.

Parameters :

pled – pointer to the LED PWM object

Return values :

error – status

led_pwm_status_t led_pwm_toggle ( led_pwm_t * pled )

Toggles the LED. If the LED is fully off, it is turned on. In all other cases, it is turned off.

Parameters :

pled – pointer to the LED PWM object

Return values :

error – status

led_pwm_status_t led_pwm_set_brightness ( led_pwm_t * pled , uint32_t brightness )

Sets the brightness of the LED.

Parameters :
Return values :

error – status

led_pwm_status_t led_pwm_blink ( led_pwm_t * pled , led_speed_t speed )

Starts a blinking pattern.

Parameters :
  • pled – pointer to the LED PWM object

  • speed – speed selection

Return values :

error – status

Starts a blinking pattern.

Parameters :
  • pled – pointer to the LED PWM object

  • period_ms – duration for the full pattern in ms

Return values :

error – status

led_pwm_status_t led_pwm_fade ( led_pwm_t * pled , led_speed_t speed )

Starts a fading pattern.

Parameters :
  • pled – pointer to the LED PWM object

  • speed – speed selection

Return values :

error – status

led_pwm_status_t led_pwm_fade_alt ( led_pwm_t * pled , uint16_t period_ms )

Starts a fading pattern.

Parameters :
  • pled – pointer to the LED PWM object

  • period_ms – duration for the full pattern in ms

Return values :

error – status

led_pwm_status_t led_pwm_play_pattern ( led_pwm_t * pled , const uint16_t * pattern , uint16_t period_ms )

Starts a custom pattern.

Parameters :
  • pled – pointer to the LED PWM object

  • pattern – pointer to a buffer of pulse values to feed to the TIM channel. The timer has a period of LED_PWM_PATTERN_MAX_VALUE; a buffer value of 0 turns the LED off, and a value of LED_PWM_PATTERN_MAX_VALUE turns it fully on. The pattern must have a length of LED_PWM_PATTERN_SIZE elements.

  • period_ms – duration for the full pattern in ms

Return values :

error – status

Types

Enums

enum led_pwm_status_t

Status enum for LED PWM operations.

Values:

enumerator LED_PWM_OK
enumerator LED_PWM_ERROR
enum led_speed_t

Enumeration defining 3 possible speeds for the LED dynamic features, such as fading and blinking.

Values:

enumerator LED_SPEED_FAST

pattern speed: fast (500 ms / buffer)

enumerator LED_SPEED_MEDIUM

pattern speed: medium (1000 ms / buffer)

enumerator LED_SPEED_SLOW

pattern speed: slow (2000 ms / buffer)

struct led_pwm_t

Structure defining the properties for a LED PWM object.

Public Members

uint32_t id

device ID to ensure correct initialization

hal_tim_handle_t * htim

handle of the timer used to drive the LED

hal_tim_channel_t pwm_channel

Timer PWM CHANNEL used to drive the LED

const uint16_t * ppattern

pointer to the pattern buffer for DMA usage

uint8_t is_running

boolean: DMA operation ongoing on the channel

Constants and macros

Defines

LED_PWM_PATTERN_SIZE 128UL

Length of a pattern buffer

LED_PWM_PATTERN_MAX_VALUE 2048U

maximum value for a pattern element