new file 100644
/*
* led.h
*
* Created on: Mar 30, 2017
* Author: Matthew Reed
*/
#ifndef INC_LED_H_
#define INC_LED_H_
#include "stm32f0xx_hal.h"
#include <stdbool.h>
#include <string.h>
typedef enum {
LED_STATUS = 0,
LED_CAN,
LED_ERROR,
} led_name_t;
void led_init(void);
void led_start(led_name_t led);
void led_start_time(led_name_t led, uint16_t time);
void led_update(led_name_t led);
void led_update_all(void);
void led_set(led_name_t led, bool value);
void led_toggle(led_name_t led);
__weak bool gpio_set_led(led_name_t led, bool value);
__weak bool gpio_toggle_led(led_name_t led);
#endif /* INC_LED_H_ */
* led.c
#include "led.h"
#define LED_CYCLE_STATUS 2000
#define LED_CYCLE_CAN 0
#define LED_CYCLE_ERROR 0
uint16_t led_timers[3];
uint16_t led_thresholds[3];
uint16_t led_cycles[3];
void led_init(void)
{
memset(led_timers, 0, sizeof led_timers);
memset(led_thresholds, 0, sizeof led_thresholds);
memset(led_cycles, 0, sizeof led_cycles);
led_cycles[LED_STATUS] = LED_CYCLE_STATUS;
led_cycles[LED_CAN] = LED_CYCLE_CAN;
led_cycles[LED_ERROR] = LED_CYCLE_ERROR;
}
void led_start(led_name_t led)
led_timers[led] = led_cycles[led];
led_thresholds[led] = led_cycles[led]/2;
void led_start_time(led_name_t led, uint16_t time)
if (led_timers[led] == 0)
led_timers[led] = time;
led_thresholds[led] = time/2;
void led_update(led_name_t led)
if (led_timers[led] > led_thresholds[led])
led_set(led, 1);
led_timers[led]--;
else if (led_timers[led] > 0)
led_set(led, 0);
else {
void led_update_all(void)
led_update(LED_STATUS);
led_update(LED_CAN);
led_update(LED_ERROR);
void led_set(led_name_t led, bool value)
gpio_set_led(led, value);
void led_toggle(led_name_t led)
gpio_toggle_led(led);
__weak bool gpio_set_led(led_name_t led, bool value)
return false;
__weak bool gpio_toggle_led(led_name_t led)
Status change: