snickerdoodle Platform Controller
firmware for STM32F0 platform controller
LED functions

Functions

enum sd_led_err sd_led_init (struct sd_led *led, TIM_HandleTypeDef *tim, uint32_t chan, uint32_t *pattern, uint32_t len, TIM_HandleTypeDef *up_tim)
 LED initialization Initialize an LED configuration on a timer peripheral with a pattern. More...
 
enum sd_led_err sd_led_enable (struct sd_led *led, uint8_t en)
 LED Enable.
 
enum sd_led_err sd_led_reset (struct sd_led *led)
 LED reset Reset the LED configuration and clear the pattern. More...
 
enum sd_led_err sd_led_queuehandler (struct sd_led *led)
 LED queue handler Execute the LED pattern state machine. More...
 
enum sd_led_err sd_led_set_pattern (struct sd_led *led, uint32_t *pattern, uint32_t len, uint8_t repeat)
 LED set pattern Set pattern for LED output. More...
 

Detailed Description

Function Documentation

◆ sd_led_init()

enum sd_led_err sd_led_init ( struct sd_led led,
TIM_HandleTypeDef *  tim,
uint32_t  chan,
uint32_t *  pattern,
uint32_t  len,
TIM_HandleTypeDef *  up_tim 
)

#include <Src/sd_led.c>

LED initialization Initialize an LED configuration on a timer peripheral with a pattern.

Parameters
ledLED configuration
timTimer handle associated with the LED
chanTimer channel for the LED
patternThe pattern to initialize the LED with
lenLength of the pattern
up_timUpdate timer for patter queue
Return values
SD_LED_SUCCESSon success, error status otherwise

Only reenable the update timer if it was running prior to this function being called

98 {
99  uint8_t reenable_timer;
100 
101  /* Check for NULL pointers for the config and timer handle */
102  if (led == NULL)
104 
105  if (led->tim == NULL)
106  return SD_LED_NULL_TIMER_ERROR;
107 
108  /* Check if the update timer has been initialized */
109  if ((up_tim->Instance->CR1 & (TIM_CR1_CEN)) &&
110  (up_tim->Instance->DIER & (TIM_IT_UPDATE))) {
111  reenable_timer = 1;
112  HAL_TIM_Base_Stop_IT(up_tim);
113  }
114 
115  /* Set the configuration of the LED */
116  led->tim = tim;
117  led->chan = chan;
118  led->pattern = pattern;
119  led->pattern_len = len;
120  led->pattern_idx = 0;
121  led->up_tim = up_tim;
122 
127  if (reenable_timer)
128  HAL_TIM_Base_Start_IT(up_tim);
129 
130  return SD_LED_SUCCESS;
131 }
uint32_t pattern_len
Definition: sd_led.h:106
uint32_t * pattern
Definition: sd_led.h:104
uint32_t pattern_idx
Definition: sd_led.h:107
uint32_t chan
Definition: sd_led.h:102
TIM_HandleTypeDef * tim
Definition: sd_led.h:100
Definition: sd_led.h:77
Definition: sd_led.h:79
TIM_HandleTypeDef * up_tim
Definition: sd_led.h:103
Definition: sd_led.h:80
uint32_t len
Definition: sd_buffer.h:106

◆ sd_led_queuehandler()

enum sd_led_err sd_led_queuehandler ( struct sd_led led)

#include <Src/sd_led.c>

LED queue handler Execute the LED pattern state machine.

Parameters
ledThe LED pattern handle
Return values
SD_LED_SUCCESSon success, error status otherwise
214 {
215 
216  /* Check for NULL pointers for the config and timer handle */
217  if (led == NULL)
219  if (led->tim == NULL)
221 
222  /* For uninitialized patterns, do nothing */
223  if (led->pattern == NULL)
224  return SD_LED_IDLE;
225 
226  /* Restart the pattern index if necessary */
227  if (led->pattern_idx >= led->pattern_len ) {
228  led->pattern_idx = 0;
229 
230  /* Is the pattern repeating? */
231  if (!(led->repeat)) {
232  led->pattern = NULL;
233  led->pattern_len = 0;
234  return SD_LED_SUCCESS; /* Return without configuring the PWM */
235  } else if (led->pattern_next != NULL) {
236  /* Is there a new pattern to start? */
237  led->pattern = led->pattern_next;
238  led->pattern_next = NULL;
239  }
240  }
241 
242  /* Set the pattern value in the configuration */
243  led->cfg->Pulse = led->pattern[led->pattern_idx++];
244 
245  /* Set the configuration */
246  HAL_TIM_PWM_ConfigChannel(led->tim, led->cfg, led->chan);
247 
248  /* Set the PWM Output */
249  HAL_TIM_PWM_Start(led->tim, led->chan);
250 
251  return SD_LED_SUCCESS;
252 }
Definition: sd_led.h:78
uint32_t pattern_len
Definition: sd_led.h:106
uint32_t * pattern
Definition: sd_led.h:104
uint8_t repeat
Definition: sd_led.h:108
uint32_t pattern_idx
Definition: sd_led.h:107
uint32_t chan
Definition: sd_led.h:102
TIM_HandleTypeDef * tim
Definition: sd_led.h:100
Definition: sd_led.h:77
Definition: sd_led.h:79
Definition: sd_led.h:80
TIM_OC_InitTypeDef * cfg
Definition: sd_led.h:101
uint32_t * pattern_next
Definition: sd_led.h:105

◆ sd_led_reset()

enum sd_led_err sd_led_reset ( struct sd_led led)

#include <Src/sd_led.c>

LED reset Reset the LED configuration and clear the pattern.

Parameters
ledLED configuration
Return values
SD_LED_SUCCESSon success, error status otherwise
175 {
176 
177  /* Check for NULL pointers for the config and timer handle */
178  if (led == NULL)
180  if (led->tim == NULL)
182 
183  /* Disable update timer interrupt */
184  HAL_TIM_Base_Stop_IT(led->up_tim);
185 
186  /* Set the pattern value in the configuration */
187  led->cfg->Pulse = 0;
188 
189  /* Set the configuration */
190  HAL_TIM_PWM_ConfigChannel(led->tim, led->cfg, led->chan);
191 
192  /* Remove the pattern from the LED */
193  led->pattern = NULL;
194  led->pattern_next = NULL;
195  led->pattern_idx = 0;
196  led->pattern_len = 0;
197  led->repeat = 0;
198 
199  /* Enable update timer interrupt */
200  HAL_TIM_Base_Start_IT(led->up_tim);
201 
202  return SD_LED_SUCCESS;
203 }
uint32_t pattern_len
Definition: sd_led.h:106
uint32_t * pattern
Definition: sd_led.h:104
uint8_t repeat
Definition: sd_led.h:108
uint32_t pattern_idx
Definition: sd_led.h:107
uint32_t chan
Definition: sd_led.h:102
TIM_HandleTypeDef * tim
Definition: sd_led.h:100
Definition: sd_led.h:77
Definition: sd_led.h:79
TIM_HandleTypeDef * up_tim
Definition: sd_led.h:103
Definition: sd_led.h:80
TIM_OC_InitTypeDef * cfg
Definition: sd_led.h:101
uint32_t * pattern_next
Definition: sd_led.h:105

◆ sd_led_set_pattern()

enum sd_led_err sd_led_set_pattern ( struct sd_led led,
uint32_t *  pattern,
uint32_t  len,
uint8_t  repeat 
)

#include <Src/sd_led.c>

LED set pattern Set pattern for LED output.

Parameters
ledThe LED pattern handle
patternThe pattern to use for the LED
lenThe length of the pattern
repeatSet the pattern to repeat after ending
Return values
SD_LED_SUCCESSon success, error status otherwise
269 {
270  /* Check for NULL pointers for the config and timer handle */
271  if ((led == NULL) || (led->tim == NULL))
273 
274  /* Disable the timer interrupt */
275  //HAL_TIM_Base_Stop_IT( LED->Update_HTIMx );
276 
277  led->pattern = pattern;
278  led->pattern_len = len;
279  led->pattern_idx = 0;
280  led->repeat = repeat;
281 
282  /* Reenable the timer */
283  //HAL_TIM_Base_Start_IT( LED->Update_HTIMx );
284 
285  return SD_LED_SUCCESS;
286 }
uint32_t pattern_len
Definition: sd_led.h:106
uint32_t * pattern
Definition: sd_led.h:104
uint8_t repeat
Definition: sd_led.h:108
uint32_t pattern_idx
Definition: sd_led.h:107
TIM_HandleTypeDef * tim
Definition: sd_led.h:100
Definition: sd_led.h:77
Definition: sd_led.h:79
uint32_t len
Definition: sd_buffer.h:106