diff options
| author | jpetermans <tibcmhhm@gmail.com> | 2017-04-12 23:32:38 -0700 |
|---|---|---|
| committer | jpetermans <tibcmhhm@gmail.com> | 2017-04-12 23:32:38 -0700 |
| commit | 15635817b5ae6068c5c79a9b67a0d97839893a7e (patch) | |
| tree | ce832a0937b8ffa92000afe146b8d46b35ebae33 /keyboards/infinity60/led_controller.c | |
| parent | 0881f2dbfa6887347afad577def01c246050df61 (diff) | |
| download | qmk_firmware-15635817b5ae6068c5c79a9b67a0d97839893a7e.tar.gz qmk_firmware-15635817b5ae6068c5c79a9b67a0d97839893a7e.zip | |
Updated lock led init
Diffstat (limited to 'keyboards/infinity60/led_controller.c')
| -rw-r--r-- | keyboards/infinity60/led_controller.c | 104 |
1 files changed, 69 insertions, 35 deletions
diff --git a/keyboards/infinity60/led_controller.c b/keyboards/infinity60/led_controller.c index 89c477ee7..ea1449d76 100644 --- a/keyboards/infinity60/led_controller.c +++ b/keyboards/infinity60/led_controller.c | |||
| @@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 24 | #include "ch.h" | 24 | #include "ch.h" |
| 25 | #include "hal.h" | 25 | #include "hal.h" |
| 26 | #include "print.h" | 26 | #include "print.h" |
| 27 | #include "led.h" | ||
| 27 | 28 | ||
| 28 | #include "led_controller.h" | 29 | #include "led_controller.h" |
| 29 | 30 | ||
| @@ -57,11 +58,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 57 | * The usual Caps Lock position is C4-6, so the address is | 58 | * The usual Caps Lock position is C4-6, so the address is |
| 58 | * 0x24 + (4-1)*0x10 + (8-1) = 0x59 */ | 59 | * 0x24 + (4-1)*0x10 + (8-1) = 0x59 */ |
| 59 | #if !defined(CAPS_LOCK_LED_ADDRESS) | 60 | #if !defined(CAPS_LOCK_LED_ADDRESS) |
| 60 | #define CAPS_LOCK_LED_ADDRESS 0x46 | 61 | #define CAPS_LOCK_LED_ADDRESS 46 |
| 61 | #endif | 62 | #endif |
| 62 | 63 | ||
| 63 | #if !defined(NUM_LOCK_LED_ADDRESS) | 64 | #if !defined(NUM_LOCK_LED_ADDRESS) |
| 64 | #define NUM_LOCK_LED_ADDRESS 0x85 | 65 | #define NUM_LOCK_LED_ADDRESS 85 |
| 65 | #endif | 66 | #endif |
| 66 | 67 | ||
| 67 | /* Which LED should breathe during sleep */ | 68 | /* Which LED should breathe during sleep */ |
| @@ -215,7 +216,6 @@ layer_status = 0; | |||
| 215 | is31_write_data (7, led_control_reg, 0x12+1); | 216 | is31_write_data (7, led_control_reg, 0x12+1); |
| 216 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 7); | 217 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 7); |
| 217 | layer_status = 7; | 218 | layer_status = 7; |
| 218 | is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &temp); | ||
| 219 | break; | 219 | break; |
| 220 | 220 | ||
| 221 | case TOGGLE_ALL: | 221 | case TOGGLE_ALL: |
| @@ -259,12 +259,18 @@ layer_status = 0; | |||
| 259 | } | 259 | } |
| 260 | break; | 260 | break; |
| 261 | 261 | ||
| 262 | case TOGGLE_LOCK_LED: | 262 | case TOGGLE_NUM_LOCK: |
| 263 | //msg_led = 0-3 for lock flags | 263 | //msg_led = 0 or 1, off/on |
| 264 | lock_status ^= msg_led; //TODO: confirm toggling works and doesn't get out of sync | 264 | //TODO: confirm toggling works and doesn't get out of sync |
| 265 | set_lock_leds(led_control_reg, lock_status); | 265 | set_lock_leds(USB_LED_NUM_LOCK, msg_led); |
| 266 | break; | 266 | break; |
| 267 | 267 | ||
| 268 | case TOGGLE_CAPS_LOCK: | ||
| 269 | //msg_led = 0 or 1, off/on | ||
| 270 | //TODO: confirm toggling works and doesn't get out of sync | ||
| 271 | set_lock_leds(USB_LED_CAPS_LOCK, msg_led); | ||
| 272 | break; | ||
| 273 | |||
| 268 | case MODE_BREATH: | 274 | case MODE_BREATH: |
| 269 | break; | 275 | break; |
| 270 | case STEP_BRIGHTNESS: | 276 | case STEP_BRIGHTNESS: |
| @@ -335,11 +341,10 @@ layer_status = 0; | |||
| 335 | * ======================== */ | 341 | * ======================== */ |
| 336 | void set_led_bit (uint8_t *led_control_reg, uint8_t msg_led, uint8_t toggle_on) { | 342 | void set_led_bit (uint8_t *led_control_reg, uint8_t msg_led, uint8_t toggle_on) { |
| 337 | uint8_t row_byte, column_bit; | 343 | uint8_t row_byte, column_bit; |
| 338 | //msg_led tens column is pin#, A-control register is every other 8 bits | 344 | //msg_led tens column is pin# |
| 339 | //ones column is bit position in 8-bit mask | 345 | //ones column is bit position in 8-bit mask |
| 340 | //control register will be one bit shifted into position along register's full 0x12 bytes | 346 | //first byte is register address 0x00 |
| 341 | ////first byte is register address 0x00 | 347 | row_byte = ((msg_led / 10) % 10 - 1 ) * 2 + 1;// A register is every other 8 bits |
| 342 | row_byte = ((msg_led / 10) % 10 - 1 ) * 2 + 1; | ||
| 343 | column_bit = 1<<(msg_led % 10 - 1); | 348 | column_bit = 1<<(msg_led % 10 - 1); |
| 344 | 349 | ||
| 345 | if (toggle_on) { | 350 | if (toggle_on) { |
| @@ -349,31 +354,61 @@ void set_led_bit (uint8_t *led_control_reg, uint8_t msg_led, uint8_t toggle_on) | |||
| 349 | } | 354 | } |
| 350 | } | 355 | } |
| 351 | 356 | ||
| 352 | void set_lock_leds(uint8_t *led_control_reg, uint8_t lock_status) { | 357 | //TODO: not toggling off correctly |
| 353 | uint8_t i; | 358 | //TODO: confirm led_off page still has FF pwm for all |
| 354 | 359 | void set_lock_leds(uint8_t lock_type, uint8_t lock_status) { | |
| 355 | switch (lock_status) { | 360 | uint8_t page; |
| 356 | case 1: | 361 | uint8_t led_addr, temp; |
| 357 | set_led_bit(led_control_reg, CAPS_LOCK_LED_ADDRESS, 1); | 362 | uint8_t control_reg[2] = {0};//register address and led bits |
| 358 | set_led_bit(led_control_reg, NUM_LOCK_LED_ADDRESS, 0); | 363 | |
| 359 | break; | 364 | switch(lock_type) { |
| 360 | case 2: | 365 | case USB_LED_NUM_LOCK: |
| 361 | set_led_bit(led_control_reg, CAPS_LOCK_LED_ADDRESS, 0); | 366 | led_addr = NUM_LOCK_LED_ADDRESS; |
| 362 | set_led_bit(led_control_reg, NUM_LOCK_LED_ADDRESS, 1); | 367 | break; |
| 363 | break; | 368 | case USB_LED_CAPS_LOCK: |
| 364 | case 3: | 369 | led_addr = CAPS_LOCK_LED_ADDRESS; |
| 365 | set_led_bit(led_control_reg, NUM_LOCK_LED_ADDRESS, 1); | 370 | break; |
| 366 | set_led_bit(led_control_reg, CAPS_LOCK_LED_ADDRESS, 1); | 371 | #ifdef SCROLL_LOCK_LED_ADDRESS |
| 367 | break; | 372 | case USB_LED_SCROLL_LOCK: |
| 368 | } | 373 | led_addr = SCROLL_LOCK_LED_ADDRESS; |
| 369 | 374 | break; | |
| 370 | for(i=BACKLIGHT_OFF_LOCK_LED_OFF; i<8; i++) { //set in led_controller.h | 375 | #endif |
| 371 | is31_write_data (i, led_control_reg, 0x12+1); | 376 | #ifdef COMPOSE_LED_ADDRESS |
| 377 | case USB_LED_COMPOSE: | ||
| 378 | led_addr = COMPOSE_LED_ADDRESS; | ||
| 379 | break; | ||
| 380 | #endif | ||
| 381 | #ifdef SCROLL_LOCK_LED_ADDRESS | ||
| 382 | case USB_LED_KANA: | ||
| 383 | led_addr = KANA_LED_ADDRESS; | ||
| 384 | break; | ||
| 385 | #endif | ||
| 386 | } | ||
| 387 | xprintf("led_addr: %X\n", led_addr); | ||
| 388 | chThdSleepMilliseconds(30); | ||
| 389 | control_reg[0] = ((led_addr / 10) % 10 - 1 ) * 0x02;// A-register is every other byte | ||
| 390 | xprintf("control_reg: %X\n", control_reg[0]); | ||
| 391 | chThdSleepMilliseconds(30); | ||
| 392 | |||
| 393 | for(page=BACKLIGHT_OFF_LOCK_LED_OFF; page<8; page++) { //set in led_controller.h | ||
| 394 | is31_read_register(page,control_reg[0],&temp);//need to maintain status of leds in this row (1 byte) | ||
| 395 | chThdSleepMilliseconds(30); | ||
| 396 | xprintf("1lock byte: %X\n", temp); | ||
| 397 | chThdSleepMilliseconds(30); | ||
| 398 | if (lock_status) { | ||
| 399 | temp |= 1<<(led_addr % 10 - 1); | ||
| 400 | } else { | ||
| 401 | temp &= ~1<<(led_addr % 10 - 1); | ||
| 402 | } | ||
| 403 | chThdSleepMilliseconds(30); | ||
| 404 | xprintf("2lock byte: %X\n", temp); | ||
| 405 | chThdSleepMilliseconds(30); | ||
| 406 | control_reg[1] = temp; | ||
| 407 | is31_write_data (page, control_reg, 0x02); | ||
| 372 | } | 408 | } |
| 373 | } | 409 | } |
| 374 | 410 | ||
| 375 | void write_led_page (uint8_t page, const uint8_t *led_array, uint8_t led_count) { | 411 | void write_led_page (uint8_t page, const uint8_t *led_array, uint8_t led_count) { |
| 376 | //TODO: init function that accepts array of led addresses and sets them by row | ||
| 377 | uint8_t i; | 412 | uint8_t i; |
| 378 | uint8_t row, col; | 413 | uint8_t row, col; |
| 379 | uint8_t temp_control_reg[0x13] = {0};//led control register start address + 0x12 bytes | 414 | uint8_t temp_control_reg[0x13] = {0};//led control register start address + 0x12 bytes |
| @@ -433,9 +468,8 @@ void led_controller_init(void) { | |||
| 433 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL2, IS31_REG_BREATHCTRL2_ENABLE|3); | 468 | is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL2, IS31_REG_BREATHCTRL2_ENABLE|3); |
| 434 | 469 | ||
| 435 | // clean up the lock LEDs | 470 | // clean up the lock LEDs |
| 436 | //TODO: adjust for new addressing and additional frames | 471 | set_lock_leds(USB_LED_NUM_LOCK, 0); |
| 437 | //is31_write_register(1, CAPS_LOCK_LED_ADDRESS, 0); | 472 | set_lock_leds(USB_LED_CAPS_LOCK, 0); |
| 438 | //is31_write_register(2, CAPS_LOCK_LED_ADDRESS, 0); | ||
| 439 | 473 | ||
| 440 | /* more time consuming LED processing should be offloaded into | 474 | /* more time consuming LED processing should be offloaded into |
| 441 | * a thread, with asynchronous messaging. */ | 475 | * a thread, with asynchronous messaging. */ |
