From 5e4286571f4d2de2e1ee314ebe40ffeb4f724aff Mon Sep 17 00:00:00 2001 From: Till Harbaum Date: Wed, 12 Apr 2017 13:30:32 +0200 Subject: [PATCH] Make LED animation on mist 1.3+ optional --- mist_cfg.c | 4 +++- mist_cfg.h | 1 + usb/max3421e.c | 39 ++++++++++++++++++++++----------------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/mist_cfg.c b/mist_cfg.c index 78af3a3..27c0229 100644 --- a/mist_cfg.c +++ b/mist_cfg.c @@ -34,7 +34,8 @@ mist_cfg_t mist_cfg = { .keyrah_mode = 0, .reset_combo = 0, .ypbpr = 0, - .keep_video_mode = 0 + .keep_video_mode = 0, + .led_animation = 0 }; // mist ini sections @@ -44,6 +45,7 @@ const ini_section_t mist_ini_sections[] = { // mist ini vars const ini_var_t mist_ini_vars[] = { + {"LED_ANIMATION", (void*)(&(mist_cfg.led_animation)), UINT8, 0, 1, 1}, {"YPBPR", (void*)(&(mist_cfg.ypbpr)), UINT8, 0, 1, 1}, {"KEEP_VIDEO_MODE", (void*)(&(mist_cfg.keep_video_mode)), UINT8, 0, 1, 1}, {"KEYRAH_MODE", (void*)(&(mist_cfg.keyrah_mode)), UINT32, 0, 0xFFFFFFFF, 1}, diff --git a/mist_cfg.h b/mist_cfg.h index 86c1ca1..e835171 100644 --- a/mist_cfg.h +++ b/mist_cfg.h @@ -23,6 +23,7 @@ typedef struct { uint8_t reset_combo; uint8_t ypbpr; uint8_t keep_video_mode; + uint8_t led_animation; } mist_cfg_t; diff --git a/usb/max3421e.c b/usb/max3421e.c index 94f999a..ef06e7e 100644 --- a/usb/max3421e.c +++ b/usb/max3421e.c @@ -3,6 +3,7 @@ #include "max3421e.h" #include "timer.h" #include "spi.h" +#include "mist_cfg.h" void max3421e_write_u08(uint8_t reg, uint8_t data) { // iprintf("write %x %x\n", reg, data); @@ -150,26 +151,30 @@ void max3421e_init() { uint8_t max3421e_poll() { uint8_t hirq = max3421e_read_u08( MAX3421E_HIRQ ); - static msec_t next = 0; - if(timer_get_msec() > next) { - static uint8_t led_pattern = 0x01; - - // iprintf("irq src=%x, bus state %x\n", hirq, vbusState); - // iprintf("host result %x\n", max3421e_read_u08( MAX3421E_HRSL)); + // do LED animation on V1.3+ boards if enabled via cfg file + if(mist_cfg.led_animation) { + static msec_t next = 0; - max3421e_write_u08(MAX3421E_IOPINS2, ~(led_pattern & 0x0f)); + if(timer_get_msec() > next) { + static uint8_t led_pattern = 0x01; - if(!(led_pattern & 0x10)) { - // knight rider left - led_pattern <<= 1; - if(!(led_pattern & 0x0f)) led_pattern = 0x18; - } else { - // knight rider right - led_pattern = ((led_pattern & 0x0f) >> 1) | 0x10; - if(!(led_pattern & 0x0f)) led_pattern = 0x01; - } + // iprintf("irq src=%x, bus state %x\n", hirq, vbusState); + // iprintf("host result %x\n", max3421e_read_u08( MAX3421E_HRSL)); + + max3421e_write_u08(MAX3421E_IOPINS2, ~(led_pattern & 0x0f)); + + if(!(led_pattern & 0x10)) { + // knight rider left + led_pattern <<= 1; + if(!(led_pattern & 0x0f)) led_pattern = 0x18; + } else { + // knight rider right + led_pattern = ((led_pattern & 0x0f) >> 1) | 0x10; + if(!(led_pattern & 0x0f)) led_pattern = 0x01; + } - next = timer_get_msec() + 100; + next = timer_get_msec() + 100; + } } if( hirq & MAX3421E_CONDETIRQ ) {