aboutsummaryrefslogtreecommitdiff
path: root/keyboards/infinity60/led_controller.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/infinity60/led_controller.c')
-rw-r--r--keyboards/infinity60/led_controller.c385
1 files changed, 201 insertions, 184 deletions
diff --git a/keyboards/infinity60/led_controller.c b/keyboards/infinity60/led_controller.c
index 59ca833b6..c162e9a8f 100644
--- a/keyboards/infinity60/led_controller.c
+++ b/keyboards/infinity60/led_controller.c
@@ -72,8 +72,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
72#define BREATHE_LED_ADDRESS CAPS_LOCK_LED_ADDRESS 72#define BREATHE_LED_ADDRESS CAPS_LOCK_LED_ADDRESS
73#endif 73#endif
74 74
75#define DEBUG_ENABLED 1
76
77/* ================= 75/* =================
78 * ChibiOS I2C setup 76 * ChibiOS I2C setup
79 * ================= */ 77 * ================= */
@@ -145,7 +143,6 @@ void is31_init(void) {
145 __builtin_memset(full_page,0,0xB4+1); 143 __builtin_memset(full_page,0,0xB4+1);
146 // zero function page, all registers (assuming full_page is all zeroes) 144 // zero function page, all registers (assuming full_page is all zeroes)
147 is31_write_data(IS31_FUNCTIONREG, full_page, 0xD + 1); 145 is31_write_data(IS31_FUNCTIONREG, full_page, 0xD + 1);
148 // disable hardware shutdown
149 palSetPadMode(GPIOB, 16, PAL_MODE_OUTPUT_PUSHPULL); 146 palSetPadMode(GPIOB, 16, PAL_MODE_OUTPUT_PUSHPULL);
150 palSetPad(GPIOB, 16); 147 palSetPad(GPIOB, 16);
151 chThdSleepMilliseconds(10); 148 chThdSleepMilliseconds(10);
@@ -182,7 +179,7 @@ static THD_FUNCTION(LEDthread, arg) {
182 uint8_t pwm_step_status, page_status; 179 uint8_t pwm_step_status, page_status;
183 180
184 //mailbox variables 181 //mailbox variables
185 uint8_t temp, msg_type, msg_led; 182 uint8_t temp, msg_type, msg_pin, msg_col, msg_led;
186 msg_t msg; 183 msg_t msg;
187 184
188/* //control register variables 185/* //control register variables
@@ -199,14 +196,17 @@ page_status = 0; //start frame 0 (all off/on)
199 // (messages are queued (up to LED_MAILBOX_NUM_MSGS) if they can't 196 // (messages are queued (up to LED_MAILBOX_NUM_MSGS) if they can't
200 // be processed right away) 197 // be processed right away)
201 chMBFetch(&led_mailbox, &msg, TIME_INFINITE); 198 chMBFetch(&led_mailbox, &msg, TIME_INFINITE);
202 msg_type = (msg >> 8) & 0xFF; //first byte is msg type 199 msg_col = (msg >> 24) & 0xFF;//if needed
203 msg_led = (msg) & 0xFF; //second byte is action information 200 msg_pin = (msg >> 16) & 0XFF;//if needed (SET_FULL_ROW)
201 msg_type = (msg >> 8) & 0xFF; //second byte is msg type
202 msg_led = (msg) & 0xFF; //first byte is action information
204 203
205 xprintf("--------------------\n"); 204 xprintf("--------------------\n");
206 chThdSleepMilliseconds(10);
207 xprintf("mailbox fetch\nmsg: %X\n", msg); 205 xprintf("mailbox fetch\nmsg: %X\n", msg);
208 chThdSleepMilliseconds(10); 206 chThdSleepMilliseconds(20);
209 xprintf("type: %X - led: %X\n", msg_type, msg_led); 207 xprintf("type: %X - pin: %X\n", msg_type, msg_pin);
208 chThdSleepMilliseconds(20);
209 xprintf("col: %X - led: %X\n", msg_col, msg_led);
210 chThdSleepMilliseconds(10); 210 chThdSleepMilliseconds(10);
211 211
212 switch (msg_type){ 212 switch (msg_type){
@@ -214,8 +214,12 @@ page_status = 0; //start frame 0 (all off/on)
214 //TODO: lighting key led on keypress 214 //TODO: lighting key led on keypress
215 break; 215 break;
216 216
217 //TODO: BLINK_ON/OFF_LED 217 case SET_FULL_ROW:
218 break; 218 //write full byte to pin address, msg_pin = pin #, msg_led = byte to write
219 //writes only to current page
220 xprintf("SET_FULL_ROW\n");
221 write_led_byte(page_status,msg_pin,msg_led);
222 break;
219 223
220 case OFF_LED: 224 case OFF_LED:
221 //on/off/toggle single led, msg_led = row/col of led 225 //on/off/toggle single led, msg_led = row/col of led
@@ -255,6 +259,7 @@ page_status = 0; //start frame 0 (all off/on)
255 chThdSleepMilliseconds(10); 259 chThdSleepMilliseconds(10);
256 set_led_bit(7, control_register_word, msg_led, 6); 260 set_led_bit(7, control_register_word, msg_led, 6);
257 is31_write_data (7, control_register_word, 0x02); 261 is31_write_data (7, control_register_word, 0x02);
262 break;
258 263
259 case TOGGLE_ALL: 264 case TOGGLE_ALL:
260 xprintf("TOGGLE_ALL: %d\n", msg_led); 265 xprintf("TOGGLE_ALL: %d\n", msg_led);
@@ -272,17 +277,12 @@ page_status = 0; //start frame 0 (all off/on)
272 277
273 if (page_status > 0) { 278 if (page_status > 0) {
274 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 0); 279 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 0);
275 }
276 280
277 //maintain lock leds 281 page_status=0;
278 if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) {
279 set_lock_leds(USB_LED_NUM_LOCK, 1);
280 }
281 if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) {
282 set_lock_leds(USB_LED_CAPS_LOCK, 1);
283 }
284 282
285 page_status=0; 283 //maintain lock leds
284 led_set(host_keyboard_leds());
285 }
286 break; 286 break;
287 287
288 case TOGGLE_BACKLIGHT: 288 case TOGGLE_BACKLIGHT:
@@ -306,81 +306,75 @@ page_status = 0; //start frame 0 (all off/on)
306 306
307 case DISPLAY_PAGE://show single layer indicator or full map of layer 307 case DISPLAY_PAGE://show single layer indicator or full map of layer
308 //msg_led = page to toggle on 308 //msg_led = page to toggle on
309 xprintf("DISPLAY_PAGE"); 309 xprintf("DISPLAY_PAGE\n");
310 chThdSleepMilliseconds(10); 310 chThdSleepMilliseconds(10);
311 if (page_status != msg_led) { 311 if (page_status != msg_led) {
312 xprintf(" - new page\n"); 312 xprintf(" - new page\n");
313 chThdSleepMilliseconds(10); 313 chThdSleepMilliseconds(10);
314 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, msg_led); 314 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, msg_led);
315 page_status = msg_led;
316
317 //maintain lock leds
318 led_set(host_keyboard_leds());
315 } 319 }
316 page_status = msg_led;
317 break; 320 break;
318 321
319 case RESET_PAGE: 322 case RESET_PAGE:
323 //led_msg = page to reset
320 xprintf("RESET_PAGE\n"); 324 xprintf("RESET_PAGE\n");
321 chThdSleepMilliseconds(10); 325 chThdSleepMilliseconds(10);
322 //led_msg = page to reset
323 led_control_reg[0] = 0; 326 led_control_reg[0] = 0;
324 __builtin_memset(led_control_reg+1, 0, 0x12); 327 __builtin_memset(led_control_reg+1, 0, 0x12);
325 is31_write_data(msg_led, led_control_reg, 0x13); 328 is31_write_data(msg_led, led_control_reg, 0x13);
326
327 //maintain lock leds
328 if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) {
329 set_lock_leds(USB_LED_NUM_LOCK, 1);
330 }
331 if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) {
332 set_lock_leds(USB_LED_CAPS_LOCK, 1);
333 }
334 break; 329 break;
335 330
336 case TOGGLE_NUM_LOCK: 331 case TOGGLE_NUM_LOCK:
337 //msg_led = 0 or 1, off/on 332 //msg_led = 0 or 1, off/on
338 xprintf("NUMLOCK: %d\n", msg_led); 333 xprintf("NUMLOCK: %d\n", msg_led);
339 chThdSleepMilliseconds(10); 334 chThdSleepMilliseconds(10);
340 set_lock_leds(NUM_LOCK_LED_ADDRESS, msg_led); 335 set_lock_leds(NUM_LOCK_LED_ADDRESS, msg_led, page_status);
341 break; 336 break;
342 337
343 case TOGGLE_CAPS_LOCK: 338 case TOGGLE_CAPS_LOCK:
344 xprintf("CAPSLOCK: %d\n", msg_led); 339 xprintf("CAPSLOCK: %d\n", msg_led);
345 chThdSleepMilliseconds(10); 340 chThdSleepMilliseconds(10);
346 //msg_led = 0 or 1, off/on 341 //msg_led = 0 or 1, off/on
347 set_lock_leds(CAPS_LOCK_LED_ADDRESS, msg_led); 342 set_lock_leds(CAPS_LOCK_LED_ADDRESS, msg_led, page_status);
348 break; 343 break;
349 344
350 //TODO: MODE_BREATH 345 //TODO: MODE_BREATH
351 case MODE_BREATH: 346
352 break;
353 case STEP_BRIGHTNESS: 347 case STEP_BRIGHTNESS:
354 xprintf("STEP_BACKLIGHT\n"); 348 xprintf("STEP_BACKLIGHT\n");
355 chThdSleepMilliseconds(10); 349 chThdSleepMilliseconds(10);
356 //led_msg = step pwm up or down 350 //led_msg = step pwm up or down
357 switch (msg_led) { 351 switch (msg_led) {
358 case 0: 352 case 0:
359 if (pwm_step_status == 0) { 353 if (pwm_step_status == 0) {
360 pwm_step_status = 4; 354 pwm_step_status = 4;
361 } else { 355 } else {
362 pwm_step_status--; 356 pwm_step_status--;
363 } 357 }
364 break; 358 break;
365 359
366 case 1: 360 case 1:
367 if (pwm_step_status == 4) { 361 if (pwm_step_status == 4) {
368 pwm_step_status = 0; 362 pwm_step_status = 0;
369 } else { 363 } else {
370 pwm_step_status++; 364 pwm_step_status++;
371 } 365 }
372 break; 366 break;
373 } 367 }
374 368
375 //populate 8 byte rows to write on each pin 369 //populate 8 byte rows to write on each pin
376 //first byte is register address, every 0x10 9 bytes are A-register pwm pins 370 //first byte is register address, every 0x10 9 bytes are A-register pwm pins
377 __builtin_memset(pwm_register_array+1, pwm_levels[pwm_step_status], 8); 371 __builtin_memset(pwm_register_array+1, pwm_levels[pwm_step_status], 8);
378 372
379 for(i=0; i<8; i++) { 373 for(i=0; i<8; i++) {
380 pwm_register_array[0] = 0x24 + (i * 0x10); 374 pwm_register_array[0] = 0x24 + (i * 0x10);
381 is31_write_data(0,pwm_register_array,9); 375 is31_write_data(0,pwm_register_array,9);
382 } 376 }
383 break; 377 break;
384 378
385/* case LED_MSG_SLEEP_LED_ON: 379/* case LED_MSG_SLEEP_LED_ON:
386 // save current settings 380 // save current settings
@@ -415,103 +409,104 @@ page_status = 0; //start frame 0 (all off/on)
415 xprintf("--------------------\n"); 409 xprintf("--------------------\n");
416 chThdSleepMilliseconds(10); 410 chThdSleepMilliseconds(10);
417 } 411 }
418#if DEBUG_ENABLED 412 }
419 uint8_t j; 413}
420 uint8_t pages[3]={0x00, 0x07};
421 //debugging code - print full led/blink/pwm registers on each frame
422 xprintf("----layer state----: %X\n", layer_state);
423 for(i=0;i<2;i++) {
424 xprintf("page: %d\n", pages[i]);
425 chThdSleepMilliseconds(2);
426 for(j=0;j<0x24;j++){
427 if(j > 0 && j % 9 == 0){
428 xprintf("\n");
429 }
430 switch (j) {
431 case 0:
432 xprintf("\n--on-off--\n");
433 chThdSleepMilliseconds(2);
434 break;
435 case 0x12:
436 xprintf("\n--blink--\n");
437 chThdSleepMilliseconds(2);
438 break;
439 }
440 is31_read_register(pages[i],j,&temp);
441 xprintf("%02X, ", temp);
442 chThdSleepMilliseconds(2);
443 }
444 414
445 xprintf("\n--pwm--\n"); 415/* ==============================
446 chThdSleepMilliseconds(2); 416 * debug function
447 for(j=0x24;j<0xB4;j++) { 417 * ============================== */
448 is31_read_register(pages[i],j,&temp); 418void print_debug(uint8_t page) {
449 xprintf("%02X, ", temp); 419 uint8_t j, debug_temp;
450 chThdSleepMilliseconds(2); 420 //debugging code - print full led/blink/pwm registers on each frame
451 if(j > 0x24 && (j-4) % 8 == 0){ 421 xprintf("----layer state----: %X\n", layer_state);
452 xprintf("\n"); 422 xprintf("page: %d\n", page);
453 } 423 chThdSleepMilliseconds(10);
454 } 424 for(j=0;j<0x24;j++){
455 xprintf("\n"); 425 if(j > 0 && j % 9 == 0){
426 xprintf("\n");
427 }
428 switch (j) {
429 case 0:
430 xprintf("\n--on-off--\n");
431 chThdSleepMilliseconds(10);
432 break;
433 case 0x12:
434 xprintf("\n--blink--\n");
435 chThdSleepMilliseconds(10);
436 break;
456 } 437 }
438 is31_read_register(page,j,&debug_temp);
439 xprintf("%02X, ", debug_temp);
440 chThdSleepMilliseconds(10);
441 }
457 442
458 //Function Register 443 xprintf("\n--pwm--\n");
459 xprintf("\n--FUNCTION--\n"); 444 chThdSleepMilliseconds(10);
460 chThdSleepMilliseconds(2); 445 for(j=0x24;j<0xB4;j++) {
461 for(j=0;j<0x0D;j++) { 446 is31_read_register(page,j,&debug_temp);
462 is31_read_register(0x0B,j,&temp); 447 xprintf("%02X, ", debug_temp);
463 switch(j) { 448 chThdSleepMilliseconds(10);
464 case 0: 449 if(j > 0x24 && (j-3) % 8 == 0){
465 xprintf("Config %02X", temp); 450 xprintf("\n");
466 chThdSleepMilliseconds(2); 451 }
467 break; 452 }
468 case 1: 453 xprintf("\n");
469 xprintf(" - Pict %02X\n", temp); 454
470 chThdSleepMilliseconds(2); 455 //Function Register
471 break; 456 xprintf("\n--FUNCTION--\n");
472 case 2: 457 chThdSleepMilliseconds(10);
473 xprintf("Auto1 %02X", temp); 458 for(j=0;j<0x0D;j++) {
474 chThdSleepMilliseconds(2); 459 is31_read_register(0x0B,j,&debug_temp);
475 break; 460 switch(j) {
476 case 3: 461 case 0:
477 xprintf(" - Auto2 %02X\n", temp); 462 xprintf("Config %02X", debug_temp);
478 chThdSleepMilliseconds(2); 463 chThdSleepMilliseconds(2);
479 break; 464 break;
480 case 5: 465 case 1:
481 xprintf("Disp %02X", temp); 466 xprintf(" - Pict %02X\n", debug_temp);
482 chThdSleepMilliseconds(2); 467 chThdSleepMilliseconds(2);
483 break; 468 break;
484 case 6: 469 case 2:
485 xprintf(" - Audio %02X\n", temp); 470 xprintf("Auto1 %02X", debug_temp);
486 chThdSleepMilliseconds(2); 471 chThdSleepMilliseconds(2);
487 break; 472 break;
488 case 7: 473 case 3:
489 xprintf("Frame %02X", temp); 474 xprintf(" - Auto2 %02X\n", debug_temp);
490 chThdSleepMilliseconds(2); 475 chThdSleepMilliseconds(2);
491 break; 476 break;
492 case 8: 477 case 5:
493 xprintf(" - Breath1 %02X\n", temp); 478 xprintf("Disp %02X", debug_temp);
494 chThdSleepMilliseconds(2); 479 chThdSleepMilliseconds(2);
495 break; 480 break;
496 case 9: 481 case 6:
497 xprintf("Breath2 %02X - ", temp); 482 xprintf(" - Audio %02X\n", debug_temp);
498 chThdSleepMilliseconds(2); 483 chThdSleepMilliseconds(2);
499 break; 484 break;
500 case 10: 485 case 7:
501 xprintf(" - Shut %02X\n", temp); 486 xprintf("Frame %02X", debug_temp);
502 chThdSleepMilliseconds(2); 487 chThdSleepMilliseconds(2);
503 break; 488 break;
504 case 11: 489 case 8:
505 xprintf("AGC %02X", temp); 490 xprintf(" - Breath1 %02X\n", debug_temp);
506 chThdSleepMilliseconds(2); 491 chThdSleepMilliseconds(2);
507 break; 492 break;
508 case 12: 493 case 9:
509 xprintf(" - ADC %02X\n", temp); 494 xprintf("Breath2 %02X - ", debug_temp);
510 chThdSleepMilliseconds(2); 495 chThdSleepMilliseconds(2);
511 break; 496 break;
512 } 497 case 10:
498 xprintf(" - Shut %02X\n", debug_temp);
499 chThdSleepMilliseconds(2);
500 break;
501 case 11:
502 xprintf("AGC %02X", debug_temp);
503 chThdSleepMilliseconds(2);
504 break;
505 case 12:
506 xprintf(" - ADC %02X\n", debug_temp);
507 chThdSleepMilliseconds(2);
508 break;
513 } 509 }
514#endif
515 } 510 }
516} 511}
517 512
@@ -523,7 +518,7 @@ void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint
523 //returns 2 bytes led control register address and byte to write 518 //returns 2 bytes led control register address and byte to write
524 //0 - bit off, 1 - bit on, 2 - toggle bit 519 //0 - bit off, 1 - bit on, 2 - toggle bit
525 520
526 uint8_t control_reg_addr, column_bit, column_byte, temp, blink_on; 521 uint8_t control_reg_addr, column_bit, column_byte, bit_temp, blink_on;
527 522
528 //check for valid led address 523 //check for valid led address
529 if (led_addr < 0 || led_addr > 87 || led_addr % 10 > 8) { 524 if (led_addr < 0 || led_addr > 87 || led_addr % 10 > 8) {
@@ -541,18 +536,28 @@ void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint
541 //first byte is led control register address 0x00 536 //first byte is led control register address 0x00
542 //msg_led tens column is pin#, ones column is bit position in 8-bit mask 537 //msg_led tens column is pin#, ones column is bit position in 8-bit mask
543 control_reg_addr = ((led_addr / 10) % 10 - 1 ) * 0x02;// A-register is every other byte 538 control_reg_addr = ((led_addr / 10) % 10 - 1 ) * 0x02;// A-register is every other byte
544 xprintf("pre-reg_addr: %X\n", control_reg_addr); 539 xprintf("pre-reg_addr: %2X\n", control_reg_addr);
545 chThdSleepMilliseconds(10); 540 chThdSleepMilliseconds(10);
546 control_reg_addr += blink_on == 1 ? 0x12 : 0x00;//shift 12 bytes to blink register 541 control_reg_addr += blink_on == 1 ? 0x12 : 0x00;//shift 12 bytes to blink register
547 xprintf("blink-reg_addr: %X\n", control_reg_addr); 542 xprintf("blink-reg_addr: %2X\n", control_reg_addr);
543 chThdSleepMilliseconds(10);
544 xprintf("page: %2X\n", page);
548 chThdSleepMilliseconds(10); 545 chThdSleepMilliseconds(10);
549 546
550 column_bit = 1<<(led_addr % 10 - 1);
551 547
552 is31_read_register(page, control_reg_addr, &temp);//maintain status of leds on this byte 548 is31_read_register(page, 0x06, &bit_temp);//maintain status of leds on this byte
553 column_byte = temp; 549 xprintf("reg 06: %2X\n", bit_temp);
550 is31_read_register(page, 0x17, &bit_temp);//maintain status of leds on this byte
551 xprintf("reg 17: %2X\n", bit_temp);
552 is31_read_register(page, 0x18, &bit_temp);//maintain status of leds on this byte
553 xprintf("reg 18: %2X\n", bit_temp);
554 is31_read_register(page, 0x19, &bit_temp);//maintain status of leds on this byte
555 xprintf("reg 19: %2X\n", bit_temp);
556 is31_read_register(page, control_reg_addr, &bit_temp);//maintain status of leds on this byte
557 column_bit = 1<<(led_addr % 10 - 1);
558 column_byte = bit_temp;
554 559
555 xprintf("column_byte read: %X\n", column_byte); 560 xprintf("column_byte read: %2X\n", column_byte);
556 chThdSleepMilliseconds(10); 561 chThdSleepMilliseconds(10);
557 switch(action) { 562 switch(action) {
558 case 0: 563 case 0:
@@ -565,7 +570,7 @@ void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint
565 column_byte ^= column_bit; 570 column_byte ^= column_bit;
566 break; 571 break;
567 } 572 }
568 xprintf("column_byte write: %X\n", column_byte); 573 xprintf("column_byte write: %2X\n", column_byte);
569 chThdSleepMilliseconds(10); 574 chThdSleepMilliseconds(10);
570 575
571 //return word to be written in register 576 //return word to be written in register
@@ -574,47 +579,59 @@ void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint
574} 579}
575 580
576void write_led_byte (uint8_t page, uint8_t row, uint8_t led_byte) { 581void write_led_byte (uint8_t page, uint8_t row, uint8_t led_byte) {
577 uint8_t led_control_word[2] = {0};//register address and led on/off mask 582 uint8_t led_control_word[2] = {0};//register address and on/off byte
578 583
579 led_control_word[0] = (row - 1 ) * 0x02;// A-register is every other byte 584 led_control_word[0] = (row - 1 ) * 0x02;// A-register is every other byte
580 led_control_word[1] = led_byte;// A-register is every other byte 585 led_control_word[1] = led_byte;
581 is31_write_data(page, led_control_word, 0x13); 586 is31_write_data(page, led_control_word, 0x02);
582} 587}
583 588
584void write_led_page (uint8_t page, uint8_t *user_led_array, uint8_t led_count) { 589void write_led_page (uint8_t page, uint8_t *user_led_array, uint8_t led_count) {
585 uint8_t i; 590 uint8_t i;
586 uint8_t pin, col; 591 uint8_t pin, col;
587 uint8_t led_control_register[0x13] = {0};//led control register start address + 0x12 bytes 592 uint8_t led_control_register[0x13] = {0};//control register start address + 0x12 bytes
588 593
589 __builtin_memset(led_control_register,0,13); 594 __builtin_memset(led_control_register,0,13);
590 595
591 for(i=0;i<led_count;i++){ 596 for(i=0;i<led_count;i++){
592 pin = ((user_led_array[i] / 10) % 10 - 1 ) * 2 + 1;// 1 byte shift for led register 0x00 address 597 // 1 byte shift for led register 0x00 address
598 pin = ((user_led_array[i] / 10) % 10 - 1 ) * 2 + 1;
593 col = user_led_array[i] % 10 - 1; 599 col = user_led_array[i] % 10 - 1;
594
595 led_control_register[pin] |= 1<<(col); 600 led_control_register[pin] |= 1<<(col);
596 } 601 }
597 602
598 is31_write_data(page, led_control_register, 0x13); 603 is31_write_data(page, led_control_register, 0x13);
599} 604}
600 605
601void set_lock_leds(uint8_t led_addr, uint8_t led_action) { 606void set_lock_leds(uint8_t led_addr, uint8_t led_action, uint8_t page) {
602 uint8_t page, temp; 607 uint8_t lock_temp;
603 uint8_t led_control_word[2] = {0}; 608 uint8_t led_control_word[2] = {0};
604 609
610 xprintf("---set lock---\n");
611 chThdSleepMilliseconds(10);
612
605 //blink if all leds are on 613 //blink if all leds are on
606 //is31_read_register(0, 0x00, &temp); 614 if (page == 0) {
607 //if (temp != 0x00) { 615 is31_read_register(0, 0x00, &lock_temp);
608 // set_led_bit(0,led_control_word,led_addr,(led_action | (1<<2))); //set blink bit 616 xprintf("AllOnReg: %2X\n", lock_temp);
609 //} else { 617 chThdSleepMilliseconds(10);
610 // set_led_bit(0,led_control_word,led_addr,led_action); 618 if (lock_temp == 0xFF) {
611 //} 619 xprintf("AllOntrue\n");
612 //is31_write_data(0, led_control_word, 0x02); 620 chThdSleepMilliseconds(10);
613 621 led_action |= (1<<2); //set blink bit
614 for(page=1; page<8; page++) { 622 } else {
615 set_led_bit(page,led_control_word,led_addr,led_action); 623 xprintf("AllOnfalse\n");
616 is31_write_data(page, led_control_word, 0x02); 624 chThdSleepMilliseconds(10);
625 }
617 } 626 }
627
628 set_led_bit(page,led_control_word,led_addr,led_action);
629
630 xprintf("led_word: %2X", led_control_word[0]);
631 xprintf("%X\n", led_control_word[1]);
632 chThdSleepMilliseconds(10);
633
634 is31_write_data(page, led_control_word, 0x02);
618} 635}
619 636
620/* ===================== 637/* =====================
@@ -639,11 +656,11 @@ void led_controller_init(void) {
639 /* initialise IS31 chip */ 656 /* initialise IS31 chip */
640 is31_init(); 657 is31_init();
641 658
642 //set Display Option Register so all pwm intensity is controlled from Frame 0 659 //set Display Option Register so all pwm intensity is controlled from page 0
643 //enable blink and set blink period to 0.27s x rate 660 //enable blink and set blink period to 0.27s x rate
644 is31_write_register(IS31_FUNCTIONREG, IS31_REG_DISPLAYOPT, IS31_REG_DISPLAYOPT_INTENSITY_SAME + S31_REG_DISPLAYOPT_BLINK_ENABLE + 5); 661 is31_write_register(IS31_FUNCTIONREG, IS31_REG_DISPLAYOPT, IS31_REG_DISPLAYOPT_INTENSITY_SAME + IS31_REG_DISPLAYOPT_BLINK_ENABLE + 4);
645 662
646 /* set full pwm on Frame 1 */ 663 /* set full pwm on page 1 */
647 pwm_register_array[0] = 0; 664 pwm_register_array[0] = 0;
648 __builtin_memset(pwm_register_array+1, 0xFF, 8); 665 __builtin_memset(pwm_register_array+1, 0xFF, 8);
649 for(i=0; i<8; i++) { 666 for(i=0; i<8; i++) {