From 046f1baf30f046922f0918b1957f810f1610333e Mon Sep 17 00:00:00 2001 From: jpetermans Date: Sat, 15 Apr 2017 14:37:55 -0700 Subject: more stable lock led process, added debugging code --- keyboards/infinity60/led_controller.c | 117 ++++++++++++++++++++-------------- 1 file changed, 70 insertions(+), 47 deletions(-) (limited to 'keyboards/infinity60') diff --git a/keyboards/infinity60/led_controller.c b/keyboards/infinity60/led_controller.c index cb91f9f35..d88ae14b1 100644 --- a/keyboards/infinity60/led_controller.c +++ b/keyboards/infinity60/led_controller.c @@ -70,6 +70,8 @@ along with this program. If not, see . #define BREATHE_LED_ADDRESS CAPS_LOCK_LED_ADDRESS #endif +#define DEBUG_ENABLED 1 + /* ================= * ChibiOS I2C setup * ================= */ @@ -171,11 +173,11 @@ static THD_FUNCTION(LEDthread, arg) { chRegSetThreadName("LEDthread"); uint8_t i, j, page; - uint8_t control_register_word[2] = {0};//register address - byte to write + uint8_t control_register_word[2] = {0};//2 bytes: register address, byte to write uint8_t led_control_reg[0x13] = {0};//led control register start address + 0x12 bytes //persistent status variables - uint8_t backlight_status, pwm_step_status, layer_status; + uint8_t backlight_status, pwm_step_status, page_status; //mailbox variables uint8_t temp, msg_type, msg_led; @@ -189,7 +191,7 @@ static THD_FUNCTION(LEDthread, arg) { // initialize persistent variables backlight_status = 0; //start backlight off pwm_step_status = 4; //full brightness -layer_status = 0; //start frame 0 (all off/on) +page_status = 0; //start frame 0 (all off/on) while(true) { // wait for a message (asynchronous) @@ -201,74 +203,89 @@ layer_status = 0; //start frame 0 (all off/on) xprintf("--------------------\n"); xprintf("mailbox fetch\nmsg: %X\n", msg); - xprintf("type: %X - led: %X\n", msg_type, msg_led); //test if msg_type is 1 or 2 bytes after mask + xprintf("type: %X - led: %X\n", msg_type, msg_led); switch (msg_type){ case KEY_LIGHT: //TODO: lighting key led on keypress break; - //turn on/off/toggle single led, msg_led = row/col of led case OFF_LED: + //on/off/toggle single led, msg_led = row/col of led xprintf("OFF_LED\n"); set_led_bit(7, control_register_word, msg_led, 0); is31_write_data (7, control_register_word, 0x02); - if (layer_status > 0) {//check current led page to prevent double blink + + if (page_status < 7) { is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 7); } - layer_status = 7; + page_status = 7; break; + case ON_LED: xprintf("ON_LED\n"); set_led_bit(7, control_register_word, msg_led, 1); is31_write_data (7, control_register_word, 0x02); - if (layer_status > 7) { + + if (page_status < 7) {//check current led page to prevent double blink is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 7); } - layer_status = 7; + page_status = 7; break; + case TOGGLE_LED: xprintf("TOGGLE_LED\n"); set_led_bit(7, control_register_word, msg_led, 2); is31_write_data (7, control_register_word, 0x02); - if (layer_status > 7) { + if (page_status > 7) { is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 7); } - layer_status = 7; + page_status = 7; break; case TOGGLE_ALL: xprintf("TOGGLE_ALL\n"); //msg_led = unused - is31_read_register(0, 0x00, &temp);//if first byte is on, then toggle frame 1 off + is31_read_register(0, 0x00, &temp);//if first byte is on, then toggle frame 0 off led_control_reg[0] = 0; - if (temp==0) { - xprintf("all leds on"); + if (temp==0 || page_status > 0) { + xprintf("all leds on"); __builtin_memcpy(led_control_reg+1, all_on_leds_mask, 0x12); } else { - xprintf("all leds off"); + xprintf("all leds off"); __builtin_memset(led_control_reg+1, 0, 0x12); } is31_write_data(0, led_control_reg, 0x13); - if (layer_status > 0) { + if (page_status > 0) { is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 0); } - layer_status=0; + + //maintain lock leds + if (host_keyboard_leds() & (1<0 || BACKLIGHT_OFF_LOCK_LED_OFF) ? 1 : 0; + + for(page=start; page<8; page++) { set_led_bit(page,led_control_write,led_addr,led_on); - xprintf("lock_led row: %X lock_led col%X\n", led_control_write[0], led_control_write[1]); is31_write_data(page, led_control_write, 0x02); - chThdSleepMilliseconds(10); } } @@ -458,8 +479,10 @@ void write_led_page (uint8_t page, const uint8_t *user_led_array, uint8_t led_co uint8_t row, col; uint8_t led_control_register[0x13] = {0};//led control register start address + 0x12 bytes + __builtin_memset(led_control_register,0,13); + for(i=0;i