Modify softpwm_led to support custom callback function
This commit is contained in:
parent
85321cab29
commit
e7e58c1658
@ -12,6 +12,18 @@ static uint8_t softpwm_led_state = 0;
|
|||||||
static uint8_t softpwm_led_ocr[LED_COUNT] = {0};
|
static uint8_t softpwm_led_ocr[LED_COUNT] = {0};
|
||||||
static uint8_t softpwm_led_ocr_buff[LED_COUNT] = {0};
|
static uint8_t softpwm_led_ocr_buff[LED_COUNT] = {0};
|
||||||
|
|
||||||
|
#ifdef FADING_LED_ENABLE
|
||||||
|
static void fading_led_proc(void);
|
||||||
|
#else
|
||||||
|
#define fading_led_proc()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BREATHING_LED_ENABLE
|
||||||
|
static void breathing_led_proc(void);
|
||||||
|
#else
|
||||||
|
#define fading_led_proc()
|
||||||
|
#endif
|
||||||
|
|
||||||
void softpwm_init(void)
|
void softpwm_init(void)
|
||||||
{
|
{
|
||||||
#ifdef SOFTPWM_LED_TIMER3
|
#ifdef SOFTPWM_LED_TIMER3
|
||||||
@ -266,14 +278,24 @@ ISR(TIMER1_COMPA_vect)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(FADING_LED_ENABLE) || defined(BREATHING_LED_ENABLE) || defined(CUSTOM_LED_ENABLE)
|
||||||
|
static uint8_t counter = 0;
|
||||||
|
if (++counter >= SOFTPWM_LED_FREQ) {
|
||||||
|
counter = 0;
|
||||||
|
fading_led_proc();
|
||||||
|
breathing_led_proc();
|
||||||
|
custom_led_proc();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef FADING_LED_ENABLE
|
#ifdef FADING_LED_ENABLE
|
||||||
static uint8_t fading_led_counter = 0;
|
void fading_led_proc(void)
|
||||||
static uint8_t fading_led_step = 0;
|
{
|
||||||
|
static uint8_t step = 0;
|
||||||
if (fading_led_state) {
|
if (fading_led_state) {
|
||||||
if (++fading_led_counter > SOFTPWM_LED_FREQ) {
|
if (++step > fading_led_duration) {
|
||||||
fading_led_counter = 0;
|
step = 0;
|
||||||
if (++fading_led_step > fading_led_duration) {
|
|
||||||
fading_led_step = 0;
|
|
||||||
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
||||||
if (fading_led_state & LED_BIT(i)) {
|
if (fading_led_state & LED_BIT(i)) {
|
||||||
if (fading_led_direction) {
|
if (fading_led_direction) {
|
||||||
@ -286,43 +308,41 @@ ISR(TIMER1_COMPA_vect)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef BREATHING_LED_ENABLE
|
#ifdef BREATHING_LED_ENABLE
|
||||||
static uint8_t breathing_led_counter = 0;
|
void breathing_led_proc(void)
|
||||||
static uint8_t breathing_led_step = 0;
|
{
|
||||||
static uint8_t breathing_led_index = 0;
|
static uint8_t step = 0;
|
||||||
static uint8_t breathing_led_direction = 0;
|
static uint8_t index = 0;
|
||||||
|
static uint8_t direction = 0;
|
||||||
if (breathing_led_state) {
|
if (breathing_led_state) {
|
||||||
if (++breathing_led_counter > SOFTPWM_LED_FREQ) {
|
if (++step > breathing_led_duration) {
|
||||||
breathing_led_counter = 0;
|
step = 0;
|
||||||
if (++breathing_led_step > breathing_led_duration) {
|
uint8_t value = pgm_read_byte(&breathing_table[index]);
|
||||||
breathing_led_step = 0;
|
|
||||||
uint8_t value = pgm_read_byte(&breathing_table[breathing_led_index]);
|
|
||||||
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
||||||
if (breathing_led_state & LED_BIT(i)) {
|
if (breathing_led_state & LED_BIT(i)) {
|
||||||
softpwm_led_ocr_buff[i] = value;
|
softpwm_led_ocr_buff[i] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (breathing_led_direction) {
|
if (direction) {
|
||||||
if (breathing_led_index == 0) {
|
if (index == 0) {
|
||||||
breathing_led_direction = 0;
|
direction = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
breathing_led_index--;
|
index--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (breathing_led_index == 0x7F) {
|
if (index == 0x7F) {
|
||||||
breathing_led_direction = 1;
|
direction = 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
breathing_led_index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
@ -69,6 +69,12 @@ void breathing_led_set_duration(uint8_t dur);
|
|||||||
#define breathing_led_set_duration_all()
|
#define breathing_led_set_duration_all()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CUSTOM_LED_ENABLE
|
||||||
|
void custom_led_proc(void);
|
||||||
|
#else
|
||||||
|
#define custom_led_proc()
|
||||||
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define softpwm_init()
|
#define softpwm_init()
|
||||||
|
Reference in New Issue
Block a user