aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjpetermans <tibcmhhm@gmail.com>2017-04-12 23:32:38 -0700
committerjpetermans <tibcmhhm@gmail.com>2017-04-12 23:32:38 -0700
commit15635817b5ae6068c5c79a9b67a0d97839893a7e (patch)
treece832a0937b8ffa92000afe146b8d46b35ebae33
parent0881f2dbfa6887347afad577def01c246050df61 (diff)
downloadqmk_firmware-15635817b5ae6068c5c79a9b67a0d97839893a7e.tar.gz
qmk_firmware-15635817b5ae6068c5c79a9b67a0d97839893a7e.zip
Updated lock led init
-rw-r--r--keyboards/infinity60/led.c26
-rw-r--r--keyboards/infinity60/led_controller.c104
-rw-r--r--keyboards/infinity60/led_controller.h11
3 files changed, 96 insertions, 45 deletions
diff --git a/keyboards/infinity60/led.c b/keyboards/infinity60/led.c
index d2f554549..c78e2d119 100644
--- a/keyboards/infinity60/led.c
+++ b/keyboards/infinity60/led.c
@@ -16,6 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17 17
18#include "hal.h" 18#include "hal.h"
19#include "print.h"
19 20
20#include "led.h" 21#include "led.h"
21 22
@@ -26,6 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
26 * In particular, I2C functions (interrupt-driven) should NOT be called from here. 27 * In particular, I2C functions (interrupt-driven) should NOT be called from here.
27 */ 28 */
28void led_set(uint8_t usb_led) { 29void led_set(uint8_t usb_led) {
30 msg_t msg;
29/* 31/*
30 // PTA5: LED (1:on/0:off) 32 // PTA5: LED (1:on/0:off)
31 GPIOA->PDDR |= (1<<1); 33 GPIOA->PDDR |= (1<<1);
@@ -36,18 +38,32 @@ void led_set(uint8_t usb_led) {
36 GPIOA->PCOR |= (1<<5); 38 GPIOA->PCOR |= (1<<5);
37 } 39 }
38 */ 40 */
39//TODO: How does this test if led is set 41 if (usb_led & (1<<USB_LED_NUM_LOCK)) {
40//usb_led --> led_set(usb_led) <-- chibios/host_keyboard_leds <-- keyboard_leds from usbSetupTransfer 42 // signal the LED control thread
41//keyboard_leds is enum'd in chibios/main.c 43 chSysUnconditionalLock();
44 msg=(TOGGLE_NUM_LOCK << 8) | 1;
45 chMBPostI(&led_mailbox, msg);
46 chSysUnconditionalUnlock();
47 } else {
48 // signal the LED control thread
49 xprintf("NUMLOCK OFF\n");
50 chSysUnconditionalLock();
51 msg=(TOGGLE_NUM_LOCK << 8) | 0;
52 chMBPostI(&led_mailbox, msg);
53 chSysUnconditionalUnlock();
54 }
42 if (usb_led & (1<<USB_LED_CAPS_LOCK)) { 55 if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
43 // signal the LED control thread 56 // signal the LED control thread
57 xprintf("CAPSLOCK ON\n");
44 chSysUnconditionalLock(); 58 chSysUnconditionalLock();
45 chMBPostI(&led_mailbox, 0x59); 59 msg=(TOGGLE_CAPS_LOCK << 8) | 1;
60 chMBPostI(&led_mailbox, msg);
46 chSysUnconditionalUnlock(); 61 chSysUnconditionalUnlock();
47 } else { 62 } else {
48 // signal the LED control thread 63 // signal the LED control thread
49 chSysUnconditionalLock(); 64 chSysUnconditionalLock();
50 chMBPostI(&led_mailbox, 0x59); 65 msg=(TOGGLE_CAPS_LOCK << 8) | 0;
66 chMBPostI(&led_mailbox, msg);
51 chSysUnconditionalUnlock(); 67 chSysUnconditionalUnlock();
52 } 68 }
53} 69}
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 * ======================== */
336void set_led_bit (uint8_t *led_control_reg, uint8_t msg_led, uint8_t toggle_on) { 342void 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
352void 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 359void 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
375void write_led_page (uint8_t page, const uint8_t *led_array, uint8_t led_count) { 411void 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. */
diff --git a/keyboards/infinity60/led_controller.h b/keyboards/infinity60/led_controller.h
index e9d897303..740862018 100644
--- a/keyboards/infinity60/led_controller.h
+++ b/keyboards/infinity60/led_controller.h
@@ -32,9 +32,9 @@ msg_t is31_read_register(uint8_t page, uint8_t reg, uint8_t *result);
32 32
33void led_controller_init(void); 33void led_controller_init(void);
34 34
35#define CAPS_LOCK_LED_ADDRESS 0x46 35#define CAPS_LOCK_LED_ADDRESS 46
36#define NUM_LOCK_LED_ADDRESS 0x85 36#define NUM_LOCK_LED_ADDRESS 85
37#define BACKLIGHT_OFF_LOCK_LED_OFF 1 //set to 0 to show lock leds even if backlight off 37#define BACKLIGHT_OFF_LOCK_LED_OFF 0 //set to 0 to show lock leds even if backlight off
38 38
39/* ============================= 39/* =============================
40 * IS31 chip related definitions 40 * IS31 chip related definitions
@@ -93,7 +93,7 @@ void led_controller_init(void);
93extern mailbox_t led_mailbox; 93extern mailbox_t led_mailbox;
94 94
95void set_led_bit (uint8_t *led_control_reg, uint8_t led_msg, uint8_t toggle_on); 95void set_led_bit (uint8_t *led_control_reg, uint8_t led_msg, uint8_t toggle_on);
96void set_lock_leds (uint8_t *led_control_reg, uint8_t lock_status); 96void set_lock_leds (uint8_t lock_type, uint8_t lock_status);
97void write_led_page (uint8_t page, const uint8_t *led_array, uint8_t led_count); 97void write_led_page (uint8_t page, const 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
@@ -103,7 +103,8 @@ enum led_msg_t {
103 TOGGLE_ALL, 103 TOGGLE_ALL,
104 TOGGLE_BACKLIGHT, 104 TOGGLE_BACKLIGHT,
105 TOGGLE_LAYER_LEDS, 105 TOGGLE_LAYER_LEDS,
106 TOGGLE_LOCK_LED, 106 TOGGLE_NUM_LOCK,
107 TOGGLE_CAPS_LOCK,
107 MODE_BREATH, 108 MODE_BREATH,
108 STEP_BRIGHTNESS 109 STEP_BRIGHTNESS
109}; 110};