diff options
| author | jpetermans <tibcmhhm@gmail.com> | 2017-04-26 23:12:25 -0700 |
|---|---|---|
| committer | jpetermans <tibcmhhm@gmail.com> | 2017-04-26 23:12:25 -0700 |
| commit | b3945c103cfa4c8f30a656d626dba75ad7f0af85 (patch) | |
| tree | e4d4a36ac0f550c2487d6135fca2f374b4d14eb9 | |
| parent | 046f1baf30f046922f0918b1957f810f1610333e (diff) | |
| download | qmk_firmware-b3945c103cfa4c8f30a656d626dba75ad7f0af85.tar.gz qmk_firmware-b3945c103cfa4c8f30a656d626dba75ad7f0af85.zip | |
Simplified processing in led_controller; more control at user level.
| -rw-r--r-- | keyboards/infinity60/led_controller.c | 214 | ||||
| -rw-r--r-- | keyboards/infinity60/led_controller.h | 5 |
2 files changed, 123 insertions, 96 deletions
diff --git a/keyboards/infinity60/led_controller.c b/keyboards/infinity60/led_controller.c index d88ae14b1..4dc9b9234 100644 --- a/keyboards/infinity60/led_controller.c +++ b/keyboards/infinity60/led_controller.c | |||
| @@ -25,6 +25,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 25 | #include "hal.h" | 25 | #include "hal.h" |
| 26 | #include "print.h" | 26 | #include "print.h" |
| 27 | #include "led.h" | 27 | #include "led.h" |
| 28 | #include "action_layer.h" | ||
| 29 | #include "host.h" | ||
| 28 | 30 | ||
| 29 | #include "led_controller.h" | 31 | #include "led_controller.h" |
| 30 | 32 | ||
| @@ -70,7 +72,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 70 | #define BREATHE_LED_ADDRESS CAPS_LOCK_LED_ADDRESS | 72 | #define BREATHE_LED_ADDRESS CAPS_LOCK_LED_ADDRESS |
| 71 | #endif | 73 | #endif |
| 72 | 74 | ||
| 73 | #define DEBUG_ENABLED 1 | 75 | #define DEBUG_ENABLED 0 |
| 74 | 76 | ||
| 75 | /* ================= | 77 | /* ================= |
| 76 | * ChibiOS I2C setup | 78 | * ChibiOS I2C setup |
| @@ -172,12 +174,12 @@ static THD_FUNCTION(LEDthread, arg) { | |||
| 172 | (void)arg; | 174 | (void)arg; |
| 173 | chRegSetThreadName("LEDthread"); | 175 | chRegSetThreadName("LEDthread"); |
| 174 | 176 | ||
| 175 | uint8_t i, j, page; | 177 | uint8_t i; |
| 176 | uint8_t control_register_word[2] = {0};//2 bytes: register address, byte to write | 178 | uint8_t control_register_word[2] = {0};//2 bytes: register address, byte to write |
| 177 | uint8_t led_control_reg[0x13] = {0};//led control register start address + 0x12 bytes | 179 | uint8_t led_control_reg[0x13] = {0};//led control register start address + 0x12 bytes |
| 178 | 180 | ||
| 179 | //persistent status variables | 181 | //persistent status variables |
| 180 | uint8_t backlight_status, pwm_step_status, page_status; | 182 | uint8_t pwm_step_status, page_status; |
| 181 | 183 | ||
| 182 | //mailbox variables | 184 | //mailbox variables |
| 183 | uint8_t temp, msg_type, msg_led; | 185 | uint8_t temp, msg_type, msg_led; |
| @@ -189,7 +191,6 @@ static THD_FUNCTION(LEDthread, arg) { | |||
| 189 | */ | 191 | */ |
| 190 | 192 | ||
| 191 | // initialize persistent variables | 193 | // initialize persistent variables |
| 192 | backlight_status = 0; //start backlight off | ||
| 193 | pwm_step_status = 4; //full brightness | 194 | pwm_step_status = 4; //full brightness |
| 194 | page_status = 0; //start frame 0 (all off/on) | 195 | page_status = 0; //start frame 0 (all off/on) |
| 195 | 196 | ||
| @@ -202,68 +203,63 @@ page_status = 0; //start frame 0 (all off/on) | |||
| 202 | msg_led = (msg) & 0xFF; //second byte is action information | 203 | msg_led = (msg) & 0xFF; //second byte is action information |
| 203 | 204 | ||
| 204 | xprintf("--------------------\n"); | 205 | xprintf("--------------------\n"); |
| 206 | chThdSleepMilliseconds(10); | ||
| 205 | xprintf("mailbox fetch\nmsg: %X\n", msg); | 207 | xprintf("mailbox fetch\nmsg: %X\n", msg); |
| 208 | chThdSleepMilliseconds(10); | ||
| 206 | xprintf("type: %X - led: %X\n", msg_type, msg_led); | 209 | xprintf("type: %X - led: %X\n", msg_type, msg_led); |
| 210 | chThdSleepMilliseconds(10); | ||
| 207 | 211 | ||
| 208 | switch (msg_type){ | 212 | switch (msg_type){ |
| 209 | case KEY_LIGHT: | 213 | case KEY_LIGHT: |
| 210 | //TODO: lighting key led on keypress | 214 | //TODO: lighting key led on keypress |
| 211 | break; | 215 | break; |
| 212 | 216 | ||
| 217 | //TODO: custom page that is written using keypresses | ||
| 218 | //TODO: BLINK_ON/OFF_LED | ||
| 219 | |||
| 213 | case OFF_LED: | 220 | case OFF_LED: |
| 214 | //on/off/toggle single led, msg_led = row/col of led | 221 | //on/off/toggle single led, msg_led = row/col of led |
| 215 | xprintf("OFF_LED\n"); | 222 | xprintf("OFF_LED\n"); |
| 223 | chThdSleepMilliseconds(10); | ||
| 216 | set_led_bit(7, control_register_word, msg_led, 0); | 224 | set_led_bit(7, control_register_word, msg_led, 0); |
| 217 | is31_write_data (7, control_register_word, 0x02); | 225 | is31_write_data (7, control_register_word, 0x02); |
| 218 | |||
| 219 | if (page_status < 7) { | ||
| 220 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 7); | ||
| 221 | } | ||
| 222 | page_status = 7; | ||
| 223 | break; | 226 | break; |
| 224 | 227 | ||
| 225 | case ON_LED: | 228 | case ON_LED: |
| 226 | xprintf("ON_LED\n"); | 229 | xprintf("ON_LED\n"); |
| 230 | chThdSleepMilliseconds(10); | ||
| 227 | set_led_bit(7, control_register_word, msg_led, 1); | 231 | set_led_bit(7, control_register_word, msg_led, 1); |
| 228 | is31_write_data (7, control_register_word, 0x02); | 232 | is31_write_data (7, control_register_word, 0x02); |
| 229 | |||
| 230 | if (page_status < 7) {//check current led page to prevent double blink | ||
| 231 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 7); | ||
| 232 | } | ||
| 233 | page_status = 7; | ||
| 234 | break; | 233 | break; |
| 235 | 234 | ||
| 236 | case TOGGLE_LED: | 235 | case TOGGLE_LED: |
| 237 | xprintf("TOGGLE_LED\n"); | 236 | xprintf("TOGGLE_LED\n"); |
| 237 | chThdSleepMilliseconds(10); | ||
| 238 | set_led_bit(7, control_register_word, msg_led, 2); | 238 | set_led_bit(7, control_register_word, msg_led, 2); |
| 239 | |||
| 240 | is31_write_data (7, control_register_word, 0x02); | 239 | is31_write_data (7, control_register_word, 0x02); |
| 241 | if (page_status > 7) { | ||
| 242 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 7); | ||
| 243 | } | ||
| 244 | page_status = 7; | ||
| 245 | break; | 240 | break; |
| 246 | 241 | ||
| 247 | case TOGGLE_ALL: | 242 | case TOGGLE_ALL: |
| 248 | xprintf("TOGGLE_ALL\n"); | 243 | xprintf("TOGGLE_ALL\n"); |
| 244 | chThdSleepMilliseconds(10); | ||
| 249 | //msg_led = unused | 245 | //msg_led = unused |
| 250 | |||
| 251 | is31_read_register(0, 0x00, &temp);//if first byte is on, then toggle frame 0 off | 246 | is31_read_register(0, 0x00, &temp);//if first byte is on, then toggle frame 0 off |
| 252 | |||
| 253 | led_control_reg[0] = 0; | 247 | led_control_reg[0] = 0; |
| 254 | if (temp==0 || page_status > 0) { | 248 | if (temp==0 || page_status > 0) { |
| 255 | xprintf("all leds on"); | 249 | xprintf("all leds on"); |
| 250 | chThdSleepMilliseconds(10); | ||
| 256 | __builtin_memcpy(led_control_reg+1, all_on_leds_mask, 0x12); | 251 | __builtin_memcpy(led_control_reg+1, all_on_leds_mask, 0x12); |
| 257 | } else { | 252 | } else { |
| 258 | xprintf("all leds off"); | 253 | xprintf("all leds off"); |
| 254 | chThdSleepMilliseconds(10); | ||
| 259 | __builtin_memset(led_control_reg+1, 0, 0x12); | 255 | __builtin_memset(led_control_reg+1, 0, 0x12); |
| 260 | } | 256 | } |
| 261 | |||
| 262 | is31_write_data(0, led_control_reg, 0x13); | 257 | is31_write_data(0, led_control_reg, 0x13); |
| 258 | |||
| 263 | if (page_status > 0) { | 259 | if (page_status > 0) { |
| 264 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 0); | 260 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 0); |
| 265 | } | 261 | } |
| 266 | 262 | ||
| 267 | //maintain lock leds | 263 | //maintain lock leds |
| 268 | if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) { | 264 | if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) { |
| 269 | set_lock_leds(USB_LED_NUM_LOCK, 1); | 265 | set_lock_leds(USB_LED_NUM_LOCK, 1); |
| @@ -276,30 +272,46 @@ page_status = 0; //start frame 0 (all off/on) | |||
| 276 | break; | 272 | break; |
| 277 | 273 | ||
| 278 | case TOGGLE_BACKLIGHT: | 274 | case TOGGLE_BACKLIGHT: |
| 279 | //msg_led = unused | 275 | //msg_led = on/off |
| 280 | //TODO: need to test tracking of active layer with layer_state from qmk | ||
| 281 | //TODO: this code still assumes on/off frame 0/1, combine this with | ||
| 282 | //toggle_all with 0,1,2 msg_leds for off/on/toggle-current? | ||
| 283 | xprintf("TOGGLE_BACKLIGHT\n"); | 276 | xprintf("TOGGLE_BACKLIGHT\n"); |
| 284 | backlight_status ^= 1; | 277 | chThdSleepMilliseconds(10); |
| 285 | is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &temp); | ||
| 286 | page_status = temp; | ||
| 287 | 278 | ||
| 288 | page = backlight_status == 0 ? 0 : page_status; | 279 | //populate the 9 byte rows to be written to each pin, first byte is register (pin) address |
| 289 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, page); | 280 | if (msg_led == 1) { |
| 281 | __builtin_memset(pwm_register_array+1, pwm_levels[pwm_step_status], 8); | ||
| 282 | } else { | ||
| 283 | __builtin_memset(pwm_register_array+1, 0, 8); | ||
| 284 | } | ||
| 285 | |||
| 286 | for(i=0; i<8; i++) { | ||
| 287 | //first byte is register address, every 0x10 9 bytes is A-register pwm pins | ||
| 288 | pwm_register_array[0] = 0x24 + (i * 0x10); | ||
| 289 | is31_write_data(0,pwm_register_array,9); | ||
| 290 | } | ||
| 290 | break; | 291 | break; |
| 291 | 292 | ||
| 292 | case TOGGLE_PAGE_LEDS://show single layer indicator or full map of layer | 293 | case DISPLAY_PAGE://show single layer indicator or full map of layer |
| 293 | //msg_led = page to toggle on | 294 | //msg_led = page to toggle on |
| 294 | xprintf("TOGGLE_LAYER_LEDS\n"); | 295 | xprintf("DISPLAY_PAGE\n"); |
| 295 | is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &temp); | 296 | chThdSleepMilliseconds(10); |
| 296 | 297 | if (page_status != msg_led) { | |
| 297 | if(temp == msg_led) { | ||
| 298 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 7); | ||
| 299 | page_status = 7; | ||
| 300 | } else { | ||
| 301 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, msg_led); | 298 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, msg_led); |
| 302 | page_status = msg_led; | 299 | } |
| 300 | page_status = msg_led; | ||
| 301 | break; | ||
| 302 | |||
| 303 | case RESET_PAGE: | ||
| 304 | //led_msg = page to reset | ||
| 305 | led_control_reg[0] = 0; | ||
| 306 | __builtin_memset(led_control_reg+1, 0, 0x12); | ||
| 307 | is31_write_data(msg_led, led_control_reg, 0x13); | ||
| 308 | |||
| 309 | //maintain lock leds | ||
| 310 | if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) { | ||
| 311 | set_lock_leds(USB_LED_NUM_LOCK, 1); | ||
| 312 | } | ||
| 313 | if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) { | ||
| 314 | set_lock_leds(USB_LED_CAPS_LOCK, 1); | ||
| 303 | } | 315 | } |
| 304 | break; | 316 | break; |
| 305 | 317 | ||
| @@ -313,10 +325,12 @@ page_status = 0; //start frame 0 (all off/on) | |||
| 313 | set_lock_leds(USB_LED_CAPS_LOCK, msg_led); | 325 | set_lock_leds(USB_LED_CAPS_LOCK, msg_led); |
| 314 | break; | 326 | break; |
| 315 | 327 | ||
| 328 | //TODO: MODE_BREATH | ||
| 316 | case MODE_BREATH: | 329 | case MODE_BREATH: |
| 317 | break; | 330 | break; |
| 318 | case STEP_BRIGHTNESS: | 331 | case STEP_BRIGHTNESS: |
| 319 | xprintf("TOGGLE_BACKLIGHT\n"); | 332 | xprintf("TOGGLE_BACKLIGHT\n"); |
| 333 | chThdSleepMilliseconds(10); | ||
| 320 | //led_msg = step pwm up or down | 334 | //led_msg = step pwm up or down |
| 321 | switch (msg_led) { | 335 | switch (msg_led) { |
| 322 | case 0: | 336 | case 0: |
| @@ -336,66 +350,70 @@ page_status = 0; //start frame 0 (all off/on) | |||
| 336 | break; | 350 | break; |
| 337 | } | 351 | } |
| 338 | 352 | ||
| 339 | //populate the 9 byte rows to be written to each pin, first byte is register (pin) address | 353 | //populate 8 byte rows to write on each pin |
| 340 | __builtin_memset(pwm_register_array+1, pwm_levels[pwm_step_status], 8); | 354 | //first byte is register address, every 0x10 9 bytes are A-register pwm pins |
| 355 | __builtin_memset(pwm_register_array+1, pwm_levels[pwm_step_status], 8); | ||
| 341 | 356 | ||
| 342 | for(i=0; i<8; i++) { | 357 | for(i=0; i<8; i++) { |
| 343 | //first byte is register address, every 0x10 9 bytes is A-register pwm pins | 358 | pwm_register_array[0] = 0x24 + (i * 0x10); |
| 344 | pwm_register_array[0] = 0x24 + (i * 0x10); | 359 | is31_write_data(0,pwm_register_array,9); |
| 345 | is31_write_data(0,pwm_register_array,9); | 360 | } |
| 346 | } | ||
| 347 | break; | 361 | break; |
| 348 | 362 | ||
| 349 | /* case LED_MSG_SLEEP_LED_ON: | 363 | /* case LED_MSG_SLEEP_LED_ON: |
| 350 | // save current settings | 364 | // save current settings |
| 351 | is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &save_page); | 365 | is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &save_page); |
| 352 | is31_read_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL1, &save_breath1); | 366 | is31_read_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL1, &save_breath1); |
| 353 | is31_read_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL2, &save_breath2); | 367 | is31_read_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL2, &save_breath2); |
| 354 | // use pages 7 and 8 for (hardware) breathing (assuming they're empty) | 368 | // use pages 7 and 8 for (hardware) breathing (assuming they're empty) |
| 355 | is31_write_register(6, BREATHE_LED_ADDRESS, 0xFF); | 369 | is31_write_register(6, BREATHE_LED_ADDRESS, 0xFF); |
| 356 | is31_write_register(7, BREATHE_LED_ADDRESS, 0x00); | 370 | is31_write_register(7, BREATHE_LED_ADDRESS, 0x00); |
| 357 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL1, (6<<4)|6); | 371 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL1, (6<<4)|6); |
| 358 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL2, IS31_REG_BREATHCTRL2_ENABLE|3); | 372 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL2, IS31_REG_BREATHCTRL2_ENABLE|3); |
| 359 | retval = MSG_TIMEOUT; | 373 | retval = MSG_TIMEOUT; |
| 360 | temp = 6; | 374 | temp = 6; |
| 361 | while(retval == MSG_TIMEOUT) { | 375 | while(retval == MSG_TIMEOUT) { |
| 362 | // switch to the other page | 376 | // switch to the other page |
| 363 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, temp); | 377 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, temp); |
| 364 | temp = (temp == 6 ? 7 : 6); | 378 | temp = (temp == 6 ? 7 : 6); |
| 365 | // the times should be sufficiently long for IS31 to finish switching pages | 379 | // the times should be sufficiently long for IS31 to finish switching pages |
| 366 | retval = chMBFetch(&led_mailbox, &msg, MS2ST(temp == 6 ? 4000 : 6000)); | 380 | retval = chMBFetch(&led_mailbox, &msg, MS2ST(temp == 6 ? 4000 : 6000)); |
| 367 | } | 381 | } |
| 368 | // received a message (should be a wakeup), so restore previous state | 382 | // received a message (should be a wakeup), so restore previous state |
| 369 | chThdSleepMilliseconds(3000); // need to wait until the page change finishes | 383 | chThdSleepMilliseconds(3000); // need to wait until the page change finishes |
| 370 | // note: any other messages are queued | 384 | // note: any other messages are queued |
| 371 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL1, save_breath1); | 385 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL1, save_breath1); |
| 372 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL2, save_breath2); | 386 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL2, save_breath2); |
| 373 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, save_page); | 387 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, save_page); |
| 374 | break; | 388 | break; |
| 375 | case LED_MSG_SLEEP_LED_OFF: | 389 | case LED_MSG_SLEEP_LED_OFF: |
| 376 | // should not get here; wakeup should be received in the branch above break; | 390 | // should not get here; wakeup should be received in the branch above break; |
| 377 | break; | 391 | break; |
| 378 | */ | 392 | */ |
| 379 | xprintf("--------------------\n"); | 393 | xprintf("--------------------\n"); |
| 394 | chThdSleepMilliseconds(10); | ||
| 380 | } | 395 | } |
| 381 | #ifdef DEBUG_ENABLED | 396 | #if DEBUG_ENABLED |
| 397 | uint8_t j, page; | ||
| 382 | //debugging code - print full led/blink/pwm registers on each frame | 398 | //debugging code - print full led/blink/pwm registers on each frame |
| 399 | xprintf("----layer state----: %X\n", layer_state); | ||
| 383 | for(i=0;i<8;i++) { | 400 | for(i=0;i<8;i++) { |
| 384 | xprintf("page: %d", i); | 401 | xprintf("page: %d", i); |
| 402 | chThdSleepMilliseconds(2); | ||
| 385 | for(j=0;j<0xB4;j++){ | 403 | for(j=0;j<0xB4;j++){ |
| 386 | is31_read_register(i,j,&temp); | 404 | is31_read_register(i,j,&temp); |
| 387 | chThdSleepMilliseconds(1); | 405 | chThdSleepMilliseconds(2); |
| 388 | xprintf("%02X, ", temp); | 406 | xprintf("%02X, ", temp); |
| 389 | if(j % 9 == 0){ | 407 | if(j % 9 == 0){ |
| 390 | xprintf("\n", temp); | 408 | xprintf("\n"); |
| 391 | if(j % 18 ==0){ | 409 | if(j % 18 ==0){ |
| 392 | xprintf("register", temp); | 410 | xprintf("register"); |
| 393 | xprintf("\n", temp); | 411 | xprintf("\n"); |
| 394 | } | 412 | } |
| 395 | } | 413 | } |
| 396 | chThdSleepMilliseconds(1); | 414 | chThdSleepMilliseconds(1); |
| 397 | } | 415 | } |
| 398 | xprintf("\n", temp); | 416 | xprintf("\n"); |
| 399 | } | 417 | } |
| 400 | #endif | 418 | #endif |
| 401 | } | 419 | } |
| @@ -406,16 +424,21 @@ page_status = 0; //start frame 0 (all off/on) | |||
| 406 | * ============================== */ | 424 | * ============================== */ |
| 407 | 425 | ||
| 408 | void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint8_t action) { | 426 | void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint8_t action) { |
| 409 | //returns 2 bytes led control register address and byte mask to write | 427 | //returns 2 bytes led control register address and byte to write |
| 410 | 428 | ||
| 411 | uint8_t control_reg_addr, column_bit, column_byte, temp; | 429 | uint8_t control_reg_addr, column_bit, column_byte, temp; |
| 412 | // | 430 | //check for valid led address |
| 431 | if (led_addr < 0 || led_addr > 90 || led_addr % 10 > 8) { | ||
| 432 | xprintf("Invalid address: %d\n", led_addr); | ||
| 433 | return; | ||
| 434 | } | ||
| 435 | |||
| 413 | //first byte is led control register address 0x00 | 436 | //first byte is led control register address 0x00 |
| 414 | //msg_led tens column is pin#, ones column is bit position in 8-bit mask | 437 | //msg_led tens column is pin#, ones column is bit position in 8-bit mask |
| 415 | control_reg_addr = ((led_addr / 10) % 10 - 1 ) * 0x02;// A-register is every other byte | 438 | control_reg_addr = ((led_addr / 10) % 10 - 1 ) * 0x02;// A-register is every other byte |
| 416 | column_bit = 1<<(led_addr % 10 - 1); | 439 | column_bit = 1<<(led_addr % 10 - 1); |
| 417 | 440 | ||
| 418 | is31_read_register(page,control_reg_addr,&temp);//need to maintain status of leds in this row (1 byte) | 441 | is31_read_register(page, control_reg_addr, &temp);//maintain status of leds on this byte |
| 419 | column_byte = temp; | 442 | column_byte = temp; |
| 420 | 443 | ||
| 421 | switch(action) { | 444 | switch(action) { |
| @@ -437,9 +460,11 @@ void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint | |||
| 437 | 460 | ||
| 438 | void set_lock_leds(uint8_t lock_type, uint8_t led_on) { | 461 | void set_lock_leds(uint8_t lock_type, uint8_t led_on) { |
| 439 | uint8_t page, led_addr, start, temp; | 462 | uint8_t page, led_addr, start, temp; |
| 440 | uint8_t led_control_write[2] = {0}; | 463 | uint8_t led_control_word[2] = {0}; |
| 441 | //TODO: consolidate control register to top level array vs. three scattered around | 464 | //TODO: this function call could send led address vs lock_type. |
| 465 | //however, the switch/case allows for additional steps, like audio, depending on type | ||
| 442 | 466 | ||
| 467 | led_addr = 0; | ||
| 443 | switch(lock_type) { | 468 | switch(lock_type) { |
| 444 | case USB_LED_NUM_LOCK: | 469 | case USB_LED_NUM_LOCK: |
| 445 | led_addr = NUM_LOCK_LED_ADDRESS; | 470 | led_addr = NUM_LOCK_LED_ADDRESS; |
| @@ -465,16 +490,18 @@ void set_lock_leds(uint8_t lock_type, uint8_t led_on) { | |||
| 465 | } | 490 | } |
| 466 | 491 | ||
| 467 | //ignore frame0 if all leds are on or if option set in led_controller.h | 492 | //ignore frame0 if all leds are on or if option set in led_controller.h |
| 493 | //TODO: blink of all leds are on, clear blink register if not | ||
| 468 | is31_read_register(0, 0x00, &temp); | 494 | is31_read_register(0, 0x00, &temp); |
| 469 | start = (temp>0 || BACKLIGHT_OFF_LOCK_LED_OFF) ? 1 : 0; | 495 | led_addr += temp == 0 ? 0 : 0x12;//send bit to blink register instead |
| 496 | start = BACKLIGHT_OFF_LOCK_LED_OFF ? 1 : 0; | ||
| 470 | 497 | ||
| 471 | for(page=start; page<8; page++) { | 498 | for(page=start; page<8; page++) { |
| 472 | set_led_bit(page,led_control_write,led_addr,led_on); | 499 | set_led_bit(page,led_control_word,led_addr,led_on); |
| 473 | is31_write_data(page, led_control_write, 0x02); | 500 | is31_write_data(page, led_control_word, 0x02); |
| 474 | } | 501 | } |
| 475 | } | 502 | } |
| 476 | 503 | ||
| 477 | void write_led_page (uint8_t page, const uint8_t *user_led_array, uint8_t led_count) { | 504 | void write_led_page (uint8_t page, uint8_t *user_led_array, uint8_t led_count) { |
| 478 | uint8_t i; | 505 | uint8_t i; |
| 479 | uint8_t row, col; | 506 | uint8_t row, col; |
| 480 | uint8_t led_control_register[0x13] = {0};//led control register start address + 0x12 bytes | 507 | uint8_t led_control_register[0x13] = {0};//led control register start address + 0x12 bytes |
| @@ -516,7 +543,6 @@ void led_controller_init(void) { | |||
| 516 | //set Display Option Register so all pwm intensity is controlled from Frame 0 | 543 | //set Display Option Register so all pwm intensity is controlled from Frame 0 |
| 517 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_DISPLAYOPT, IS31_REG_DISPLAYOPT_INTENSITY_SAME); | 544 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_DISPLAYOPT, IS31_REG_DISPLAYOPT_INTENSITY_SAME); |
| 518 | 545 | ||
| 519 | //TODO: test new init pwm loop | ||
| 520 | /* set full pwm on Frame 1 */ | 546 | /* set full pwm on Frame 1 */ |
| 521 | pwm_register_array[0] = 0; | 547 | pwm_register_array[0] = 0; |
| 522 | __builtin_memset(pwm_register_array+1, 0xFF, 8); | 548 | __builtin_memset(pwm_register_array+1, 0xFF, 8); |
diff --git a/keyboards/infinity60/led_controller.h b/keyboards/infinity60/led_controller.h index 151100471..b06113b07 100644 --- a/keyboards/infinity60/led_controller.h +++ b/keyboards/infinity60/led_controller.h | |||
| @@ -94,7 +94,7 @@ extern mailbox_t led_mailbox; | |||
| 94 | 94 | ||
| 95 | void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint8_t action); | 95 | void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint8_t action); |
| 96 | void set_lock_leds (uint8_t lock_type, uint8_t led_on); | 96 | void set_lock_leds (uint8_t lock_type, uint8_t led_on); |
| 97 | void write_led_page (uint8_t page, const uint8_t *led_array, uint8_t led_count); | 97 | void write_led_page (uint8_t page, uint8_t *led_array, uint8_t led_count); |
| 98 | 98 | ||
| 99 | // constants for signaling the LED controller thread | 99 | // constants for signaling the LED controller thread |
| 100 | enum led_msg_t { | 100 | enum led_msg_t { |
| @@ -104,7 +104,8 @@ enum led_msg_t { | |||
| 104 | TOGGLE_LED, | 104 | TOGGLE_LED, |
| 105 | TOGGLE_ALL, | 105 | TOGGLE_ALL, |
| 106 | TOGGLE_BACKLIGHT, | 106 | TOGGLE_BACKLIGHT, |
| 107 | TOGGLE_PAGE_LEDS, | 107 | DISPLAY_PAGE, |
| 108 | RESET_PAGE, | ||
| 108 | TOGGLE_NUM_LOCK, | 109 | TOGGLE_NUM_LOCK, |
| 109 | TOGGLE_CAPS_LOCK, | 110 | TOGGLE_CAPS_LOCK, |
| 110 | MODE_BREATH, | 111 | MODE_BREATH, |
