aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keyboards/infinity60/keymaps/jpetermans/keymap.c28
-rw-r--r--keyboards/infinity60/keymaps/jpetermans/readme.md38
-rw-r--r--keyboards/infinity60/led.c8
-rw-r--r--keyboards/infinity60/led_controller.c138
4 files changed, 101 insertions, 111 deletions
diff --git a/keyboards/infinity60/keymaps/jpetermans/keymap.c b/keyboards/infinity60/keymaps/jpetermans/keymap.c
index 630105017..8d19834b2 100644
--- a/keyboards/infinity60/keymaps/jpetermans/keymap.c
+++ b/keyboards/infinity60/keymaps/jpetermans/keymap.c
@@ -12,7 +12,7 @@
12#define _TILDE 4 12#define _TILDE 4
13 13
14//IS31 chip has 8 available led pages, using 0 for all leds and 7 for single toggles 14//IS31 chip has 8 available led pages, using 0 for all leds and 7 for single toggles
15#define max_pages 6 15#define max_pages 6
16 16
17enum ic60_keycodes { 17enum ic60_keycodes {
18 NUMPAD, 18 NUMPAD,
@@ -75,7 +75,7 @@ const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
75 [_FNAV] = KEYMAP( \ 75 [_FNAV] = KEYMAP( \
76 KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______,KC_NO,\ 76 KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______,KC_NO,\
77 KC_CAPS,_______,_______,_______,_______,_______,_______,KC_PGUP,KC_UP,KC_PGDN,KC_PSCR,_______,_______,KC_DEL, \ 77 KC_CAPS,_______,_______,_______,_______,_______,_______,KC_PGUP,KC_UP,KC_PGDN,KC_PSCR,_______,_______,KC_DEL, \
78 _______,M(0),KC_BTN2,_______,_______,_______,KC_HOME,KC_LEFT,KC_DOWN,KC_RGHT,KC_INS,_______,_______, \ 78 _______,_______,KC_BTN2,_______,_______,_______,KC_HOME,KC_LEFT,KC_DOWN,KC_RGHT,KC_INS,_______,_______, \
79 _______,KC_APP,KC_BTN1,KC_CALC,_______,_______,KC_END,_______,_______,_______,_______,_______,KC_NO, \ 79 _______,KC_APP,KC_BTN1,KC_CALC,_______,_______,KC_END,_______,_______,_______,_______,_______,KC_NO, \
80 _______,_______,_______, _______, F(CTLALTDEL),KC_NLCK,_______,_______ \ 80 _______,_______,_______, _______, F(CTLALTDEL),KC_NLCK,_______,_______ \
81 ), 81 ),
@@ -119,7 +119,7 @@ enum macro_id {
119 ACTION_LEDS_DIM, 119 ACTION_LEDS_DIM,
120 ACTION_LEDS_SINGLE, 120 ACTION_LEDS_SINGLE,
121 ACTION_LEDS_PAGE, 121 ACTION_LEDS_PAGE,
122 ACTION_LEDS_FLASH, 122 ACTION_LEDS_FLASH
123}; 123};
124 124
125/* ================================== 125/* ==================================
@@ -137,9 +137,8 @@ enum macro_id {
137*/ 137*/
138 138
139//======== full page arrays ========= 139//======== full page arrays =========
140//LED Page 1 - _Numpad
141//any change in array size needs to be mirrored in matrix_init_user 140//any change in array size needs to be mirrored in matrix_init_user
142uint8_t led_numpad[16] = { 141uint8_t led_numpad[16] = {
143 18,21,22,23, 142 18,21,22,23,
144 37,38,41,42, 143 37,38,41,42,
145 55,56,57,58, 144 55,56,57,58,
@@ -186,7 +185,7 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {
186 case ACTION_LEDS_ALL: 185 case ACTION_LEDS_ALL:
187 if(record->event.pressed) { 186 if(record->event.pressed) {
188 led_mode_global = led_mode_global == ALL ? MODE_SINGLE : ALL; 187 led_mode_global = led_mode_global == ALL ? MODE_SINGLE : ALL;
189 msg=(TOGGLE_ALL << 8) | 0; 188 msg=TOGGLE_ALL;
190 chMBPost(&led_mailbox, msg, TIME_IMMEDIATE); 189 chMBPost(&led_mailbox, msg, TIME_IMMEDIATE);
191 } 190 }
192 break; 191 break;
@@ -194,7 +193,7 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {
194 case ACTION_LEDS_BACKLIGHT: 193 case ACTION_LEDS_BACKLIGHT:
195 if(record->event.pressed) { 194 if(record->event.pressed) {
196 backlight_status_global ^= 1; 195 backlight_status_global ^= 1;
197 msg=(TOGGLE_BACKLIGHT << 8) | (backlight_status_global); 196 msg=(backlight_status_global << 8) | TOGGLE_BACKLIGHT;
198 chMBPost(&led_mailbox, msg, TIME_IMMEDIATE); 197 chMBPost(&led_mailbox, msg, TIME_IMMEDIATE);
199 } 198 }
200 break; 199 break;
@@ -203,21 +202,21 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {
203 if(record->event.pressed) { 202 if(record->event.pressed) {
204 led_mode_global = led_mode_global == GAME ? MODE_SINGLE : GAME; 203 led_mode_global = led_mode_global == GAME ? MODE_SINGLE : GAME;
205 204
206 msg=(DISPLAY_PAGE << 8) | 4; 205 msg=(4 << 8) | DISPLAY_PAGE;
207 chMBPost(&led_mailbox, msg, TIME_IMMEDIATE); 206 chMBPost(&led_mailbox, msg, TIME_IMMEDIATE);
208 } 207 }
209 break; 208 break;
210 209
211 case ACTION_LEDS_BRIGHT: 210 case ACTION_LEDS_BRIGHT:
212 if(record->event.pressed) { 211 if(record->event.pressed) {
213 msg=(STEP_BRIGHTNESS << 8) | 1; 212 msg=(1 << 8) | STEP_BRIGHTNESS;
214 chMBPost(&led_mailbox, msg, TIME_IMMEDIATE); 213 chMBPost(&led_mailbox, msg, TIME_IMMEDIATE);
215 } 214 }
216 break; 215 break;
217 216
218 case ACTION_LEDS_DIM: 217 case ACTION_LEDS_DIM:
219 if(record->event.pressed) { 218 if(record->event.pressed) {
220 msg=(STEP_BRIGHTNESS << 8) | 0; 219 msg=(0 << 8) | STEP_BRIGHTNESS;
221 chMBPost(&led_mailbox, msg, TIME_IMMEDIATE); 220 chMBPost(&led_mailbox, msg, TIME_IMMEDIATE);
222 } 221 }
223 break; 222 break;
@@ -282,26 +281,25 @@ void matrix_scan_user(void) {
282 switch(led_mode_global) { 281 switch(led_mode_global) {
283 case MODE_FLASH: //flash preset page leds then single indicator 282 case MODE_FLASH: //flash preset page leds then single indicator
284 page = biton32(layer_state) > max_pages ? 7 : biton32(layer_state); 283 page = biton32(layer_state) > max_pages ? 7 : biton32(layer_state);
285 msg=(DISPLAY_PAGE << 8) | (page); 284 msg=(page << 8) | DISPLAY_PAGE;
286 chMBPost(&led_mailbox, msg, TIME_IMMEDIATE); 285 chMBPost(&led_mailbox, msg, TIME_IMMEDIATE);
287 chThdSleepMilliseconds(500); 286 chThdSleepMilliseconds(500);
288 //flow to display single layer leds 287 //flow to display single layer leds
289 288
290 case MODE_SINGLE: //light layer indicators for all active layers 289 case MODE_SINGLE: //light layer indicators for all active layers
291 led_pin_byte = layer_state & 0xFF; 290 led_pin_byte = layer_state & 0xFF;
292 msg=(DISPLAY_PAGE << 8) | 7; 291 msg=(7 << 8) | DISPLAY_PAGE;
293 chMBPost(&led_mailbox, msg, TIME_IMMEDIATE); 292 chMBPost(&led_mailbox, msg, TIME_IMMEDIATE);
294 msg=(1<<16) | (SET_FULL_ROW << 8) | (led_pin_byte); 293 msg=(1<<16) | (led_pin_byte << 8) | SET_FULL_ROW;
295 chMBPost(&led_mailbox, msg, TIME_IMMEDIATE); 294 chMBPost(&led_mailbox, msg, TIME_IMMEDIATE);
296 break; 295 break;
297 296
298 case MODE_PAGE: //display pre-defined led page 297 case MODE_PAGE: //display pre-defined led page
299 page = biton32(layer_state) > max_pages ? 7 : biton32(layer_state); 298 page = biton32(layer_state) > max_pages ? 7 : biton32(layer_state);
300 msg=(DISPLAY_PAGE << 8) | (page); 299 msg=(page << 8) | DISPLAY_PAGE;
301 chMBPost(&led_mailbox, msg, TIME_IMMEDIATE); 300 chMBPost(&led_mailbox, msg, TIME_IMMEDIATE);
302 break; 301 break;
303 } 302 }
304 led_layer_state = layer_state; 303 led_layer_state = layer_state;
305 } 304 }
306} 305}
307
diff --git a/keyboards/infinity60/keymaps/jpetermans/readme.md b/keyboards/infinity60/keymaps/jpetermans/readme.md
index f50bee617..63fd88ec2 100644
--- a/keyboards/infinity60/keymaps/jpetermans/readme.md
+++ b/keyboards/infinity60/keymaps/jpetermans/readme.md
@@ -16,26 +16,24 @@ digits mean "row" and "col", i.e. 45 means pin 4, column 5 in the IS31 datasheet
16``` 16```
17*Unused in Alphabet Layout 17*Unused in Alphabet Layout
18 18
19The IS31 includes 8 pages (or frames) 0-7 and each page consists of 0xB4 (144) bytes 19The IS31 includes 8 pages (or frames) 0-7 and each page consists of 144 bytes
20- **0 - 17** 20- **bytes 0 - 17** - LED control (on/off).
21 * LED control (on/off). 21 * 18 pins which alternate between A and B matrices (CA1, CB1, CA2, CB2, ..).
22 * 18 pins which alternate between A and B matrices (CA1, CB1, CA2, CB2, ..).
23 * Each byte controls the 8 leds on that pin with bits (8 to 1). 22 * Each byte controls the 8 leds on that pin with bits (8 to 1).
24- **18 - 35** 23- **bytes 8 - 35** - Blink control.
25 * Blink control.
26 * Same as LED control above, but sets blink on/off. 24 * Same as LED control above, but sets blink on/off.
27- **36 - 143** 25- **bytes 36 - 143** - PWM control.
28 * PWM control. One byte per LED, sets PWM from 0 to 255. 26 * One byte per LED, sets PWM from 0 to 255.
29 * Same as above, the register alternates, every 8 *bytes* (not bits) between the A & B matrices. 27 * Same as above, the register alternates, every 8 *bytes* (not bits) between the A & B matrices.
30 28
31## Led Controller Code 29## Led Controller Code
32In the Infinity60 project folder, led_controller.c sets up ability to write led layers at startup or control leds on demand as part of fn_actions. By default led_controller.c assumes page 0 will be used for full on/off and page 7 for controlling individual leds. The remaining 6 pages (1-6) are free to preset led maps at init or on demand. Communication with the IS31 is primarily done through the led_mailbox using chMBPost described further below under "Sending messages in Keymap.c" 30In the Infinity60 project folder, led_controller.c sets up ability to write led layers at startup or control leds on demand as part of fn_actions. By default led_controller.c assumes page 0 will be used for full on/off. The remaining 7 pages (1-7) are free for preset led maps or single led actions at init or on demand. Communication with the IS31 is primarily done through the led_mailbox using chMBPost described further below under "Sending messages in Keymap.c". This code is based on work matt3o and flabbergast did for tmk firmware on the [whitefox](https://github.com/tmk/whitefox).
33 31
34One function is available to directly set leds without the mailbox: 32One function is available to directly set leds without the mailbox:
35``` 33```
36write_led_page(page#, array of leds by address, # of leds in array) 34write_led_page(page#, array of leds by address, # of leds in array)
37``` 35```
38This function saves a full page using a supplied array of led locations such as: 36This function saves a full page to the controller using a supplied array of led locations such as:
39```c 37```c
40uint8_t led_numpad[16] = { 38uint8_t led_numpad[16] = {
41 18,21,22,23, 39 18,21,22,23,
@@ -48,13 +46,9 @@ write_led_page(5, led_numpad, 16);
48 46
49Remaining led control is done through the led mailbox using these message types: 47Remaining led control is done through the led mailbox using these message types:
50- **SET_FULL_ROW** (3 bytes) - row#, message type, 8-bit mask. Sets all leds on one pin per the bit mask. 48- **SET_FULL_ROW** (3 bytes) - row#, message type, 8-bit mask. Sets all leds on one pin per the bit mask.
51- **OFF_LED** (2 bytes) - message type, led address. Turn off specific led. 49- **OFF_LED, ON_LED, TOGGLE_LED** (3 bytes) - message type, led address, and page#. Off/on/toggle specific led.
52- **ON_LED** (2 bytes) - message type, led address. Turn on specific led. 50- **BLINK_OFF_LED, BLINK_ON_LED, BLINK_OFF_LED** (3 bytes) - message type, led address, and page#. Set blink Off/on/toggle for specific led.
53- **TOGGLE_LED** (2 bytes) - message type, led address. Toggle specific led on/off. 51- **TOGGLE_ALL** (1 byte) - Turn on/off full backlight.
54- **BLINK_OFF_LED** (2 bytes) - message type, led address. Set blink off for specific led.
55- **BLINK_ON_LED** (2 bytes) - message type, led address. Set blink on for specific led.
56- **BLINK_TOGGLE_LED** (2 bytes) - message type, led address. Toggle blink for specific led.
57- **TOGGLE_ALL** (2 bytes) - message type, not used. Turn on/off full backlight.
58- **TOGGLE_BACKLIGHT** (2 bytes) - message type, on/off. Sets backlight completely off, no leds will display. 52- **TOGGLE_BACKLIGHT** (2 bytes) - message type, on/off. Sets backlight completely off, no leds will display.
59- **DISPLAY_PAGE** (2 bytes) - message type, page to display. Switch to specific pre-set page. 53- **DISPLAY_PAGE** (2 bytes) - message type, page to display. Switch to specific pre-set page.
60- **RESET_PAGE** (2 bytes) - message type, page to reset. Reset/erase specific page. 54- **RESET_PAGE** (2 bytes) - message type, page to reset. Reset/erase specific page.
@@ -68,13 +62,13 @@ Sending an action to the led mailbox is done using chMBPost:
68chMBPost(&led_mailbox, message, timeout); 62chMBPost(&led_mailbox, message, timeout);
69``` 63```
70- &led_mailbox - pointer to led mailbox 64- &led_mailbox - pointer to led mailbox
71- message - up to 4 bytes but most messages use only 2. First byte (LSB) is the message to process, the second byte is type. The third is only used to pass row information in SET_FULL_ROW. The fourth byte is currently unused. 65- message - up to 4 bytes but most messages use only 2. First byte (LSB) is the message type, the remaining three bytes are the message to process.
72-timeout is usually TIME_IMMEDIATE 66- timeout is TIME_IMMEDIATE
73 67
74An example: 68An example:
75```c 69```c
76//set the message to be sent. First byte (LSB) is the led address, and second is the message type 70//set the message to be sent. First byte (LSB) is the led address, and second is the message type
77msg=(ON_LED << 8) | 42; 71msg=(42 << 8) | ON_LED
78 72
79//send msg to the led mailbox 73//send msg to the led mailbox
80chMBPost(&led_mailbox, msg, TIME_IMMEDIATE); 74chMBPost(&led_mailbox, msg, TIME_IMMEDIATE);
@@ -82,12 +76,12 @@ chMBPost(&led_mailbox, msg, TIME_IMMEDIATE);
82 76
83Another: 77Another:
84```c 78```c
85msg=(BLINK_TOGGLE_LED << 8) | 46; 79msg=(46 << 8) | BLINK_TOGGLE_LED
86chMBPost(&led_mailbox, msg, TIME_IMMEDIATE); 80chMBPost(&led_mailbox, msg, TIME_IMMEDIATE);
87``` 81```
88 82
89Finally, SET_FULL_ROW requires an extra byte with row information in the message so sending this message looks like: 83Finally, SET_FULL_ROW requires an extra byte with row information in the message so sending this message looks like:
90```c 84```c
91msg=(row<<16) | (SET_FULL_ROW << 8) | (led_pin_byte); 85msg=(row<<16) | (led_pin_byte << 8) | SET_FULL_ROW;
92chMBPost(&led_mailbox, msg, TIME_IMMEDIATE); 86chMBPost(&led_mailbox, msg, TIME_IMMEDIATE);
93``` 87```
diff --git a/keyboards/infinity60/led.c b/keyboards/infinity60/led.c
index d60c76fd8..53147a78a 100644
--- a/keyboards/infinity60/led.c
+++ b/keyboards/infinity60/led.c
@@ -30,23 +30,23 @@ void led_set(uint8_t usb_led) {
30 30
31 if (usb_led & (1<<USB_LED_NUM_LOCK)) { 31 if (usb_led & (1<<USB_LED_NUM_LOCK)) {
32 chSysUnconditionalLock(); 32 chSysUnconditionalLock();
33 msg=(TOGGLE_NUM_LOCK << 8) | 1; 33 msg=(1 << 8) | TOGGLE_NUM_LOCK;
34 chMBPostI(&led_mailbox, msg); 34 chMBPostI(&led_mailbox, msg);
35 chSysUnconditionalUnlock(); 35 chSysUnconditionalUnlock();
36 } else { 36 } else {
37 chSysUnconditionalLock(); 37 chSysUnconditionalLock();
38 msg=(TOGGLE_NUM_LOCK << 8) | 0; 38 msg=(0 << 8) | TOGGLE_NUM_LOCK;
39 chMBPostI(&led_mailbox, msg); 39 chMBPostI(&led_mailbox, msg);
40 chSysUnconditionalUnlock(); 40 chSysUnconditionalUnlock();
41 } 41 }
42 if (usb_led & (1<<USB_LED_CAPS_LOCK)) { 42 if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
43 chSysUnconditionalLock(); 43 chSysUnconditionalLock();
44 msg=(TOGGLE_CAPS_LOCK << 8) | 1; 44 msg=(1 << 8) | TOGGLE_CAPS_LOCK;
45 chMBPostI(&led_mailbox, msg); 45 chMBPostI(&led_mailbox, msg);
46 chSysUnconditionalUnlock(); 46 chSysUnconditionalUnlock();
47 } else { 47 } else {
48 chSysUnconditionalLock(); 48 chSysUnconditionalLock();
49 msg=(TOGGLE_CAPS_LOCK << 8) | 0; 49 msg=(0 << 8) | TOGGLE_CAPS_LOCK;
50 chMBPostI(&led_mailbox, msg); 50 chMBPostI(&led_mailbox, msg);
51 chSysUnconditionalUnlock(); 51 chSysUnconditionalUnlock();
52 } 52 }
diff --git a/keyboards/infinity60/led_controller.c b/keyboards/infinity60/led_controller.c
index d776b4fcf..a66edb927 100644
--- a/keyboards/infinity60/led_controller.c
+++ b/keyboards/infinity60/led_controller.c
@@ -143,9 +143,6 @@ void is31_init(void) {
143 palSetPadMode(GPIOB, 16, PAL_MODE_OUTPUT_PUSHPULL); 143 palSetPadMode(GPIOB, 16, PAL_MODE_OUTPUT_PUSHPULL);
144 palSetPad(GPIOB, 16); 144 palSetPad(GPIOB, 16);
145 chThdSleepMilliseconds(10); 145 chThdSleepMilliseconds(10);
146 // software shutdown
147 is31_write_register(IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, 0);
148 chThdSleepMilliseconds(10);
149 // software shutdown disable (i.e. turn stuff on) 146 // software shutdown disable (i.e. turn stuff on)
150 is31_write_register(IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_ON); 147 is31_write_register(IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_ON);
151 chThdSleepMilliseconds(10); 148 chThdSleepMilliseconds(10);
@@ -153,7 +150,7 @@ void is31_init(void) {
153 uint8_t i; 150 uint8_t i;
154 for(i=0; i<8; i++) { 151 for(i=0; i<8; i++) {
155 is31_write_data(i, full_page, 0xB4 + 1); 152 is31_write_data(i, full_page, 0xB4 + 1);
156 chThdSleepMilliseconds(1); 153 chThdSleepMilliseconds(5);
157 } 154 }
158} 155}
159 156
@@ -176,64 +173,65 @@ static THD_FUNCTION(LEDthread, arg) {
176 uint8_t pwm_step_status, page_status; 173 uint8_t pwm_step_status, page_status;
177 174
178 //mailbox variables 175 //mailbox variables
179 uint8_t temp, msg_type, msg_pin, msg_col, msg_led; 176 uint8_t temp, msg_type;
177 uint8_t msg_args[3];
180 msg_t msg; 178 msg_t msg;
181 179
182// initialize persistent variables 180 // initialize persistent variables
183pwm_step_status = 4; //full brightness 181 pwm_step_status = 4; //full brightness
184page_status = 0; //start frame 0 (all off/on) 182 page_status = 0; //start frame 0 (all off/on)
185 183
186 while(true) { 184 while(true) {
187 // wait for a message (asynchronous) 185 // wait for a message (asynchronous)
188 // (messages are queued (up to LED_MAILBOX_NUM_MSGS) if they can't 186 // (messages are queued (up to LED_MAILBOX_NUM_MSGS) if they can't
189 // be processed right away 187 // be processed right away
190 chMBFetch(&led_mailbox, &msg, TIME_INFINITE); 188 chMBFetch(&led_mailbox, &msg, TIME_INFINITE);
191 msg_col = (msg >> 24) & 0xFF;//if needed 189 msg_type = msg & 0xFF; //first byte is action information
192 msg_pin = (msg >> 16) & 0XFF;//if needed (e.g. SET_FULL_ROW) 190 msg_args[0] = (msg >> 8) & 0xFF;
193 msg_type = (msg >> 8) & 0xFF; //second byte is msg type 191 msg_args[1] = (msg >> 16) & 0XFF;
194 msg_led = (msg) & 0xFF; //first byte is action information 192 msg_args[2] = (msg >> 24) & 0xFF;
195 193
196 switch (msg_type){ 194 switch (msg_type){
197 case SET_FULL_ROW: 195 case SET_FULL_ROW:
198 //write full byte to pin address, msg_pin = pin #, msg_led = byte to write 196 //write full byte to pin address, msg_args[1] = pin #, msg_args[0] = 8 bits to write
199 //writes only to current page 197 //writes only to currently displayed page
200 write_led_byte(page_status,msg_pin,msg_led); 198 write_led_byte(page_status, msg_args[1], msg_args[0]);
201 break; 199 break;
202 200
203 case OFF_LED: 201 case OFF_LED:
204 //on/off/toggle single led, msg_led = row/col of led 202 //on/off/toggle single led, msg_args[0] = row/col of led
205 set_led_bit(7, control_register_word, msg_led, 0); 203 set_led_bit(msg_args[1], control_register_word, msg_args[0], 0);
206 is31_write_data (7, control_register_word, 0x02); 204 is31_write_data (msg_args[1], control_register_word, 0x02);
207 break; 205 break;
208 case ON_LED: 206 case ON_LED:
209 set_led_bit(7, control_register_word, msg_led, 1); 207 set_led_bit(msg_args[1], control_register_word, msg_args[0], 1);
210 is31_write_data (7, control_register_word, 0x02); 208 is31_write_data (msg_args[1], control_register_word, 0x02);
211 break; 209 break;
212 case TOGGLE_LED: 210 case TOGGLE_LED:
213 set_led_bit(7, control_register_word, msg_led, 2); 211 set_led_bit(msg_args[1], control_register_word, msg_args[0], 2);
214 is31_write_data (7, control_register_word, 0x02); 212 is31_write_data (msg_args[1], control_register_word, 0x02);
215 break; 213 break;
216 214
217 case BLINK_OFF_LED: 215 case BLINK_OFF_LED:
218 //on/off/toggle single led, msg_led = row/col of led 216 //on/off/toggle single led, msg_args[0] = row/col of led
219 set_led_bit(7, control_register_word, msg_led, 4); 217 set_led_bit(msg_args[1], control_register_word, msg_args[0], 4);
220 is31_write_data (7, control_register_word, 0x02); 218 is31_write_data (msg_args[1], control_register_word, 0x02);
221 break; 219 break;
222 case BLINK_ON_LED: 220 case BLINK_ON_LED:
223 set_led_bit(7, control_register_word, msg_led, 5); 221 set_led_bit(msg_args[1], control_register_word, msg_args[0], 5);
224 is31_write_data (7, control_register_word, 0x02); 222 is31_write_data (msg_args[1], control_register_word, 0x02);
225 break; 223 break;
226 case BLINK_TOGGLE_LED: 224 case BLINK_TOGGLE_LED:
227 set_led_bit(7, control_register_word, msg_led, 6); 225 set_led_bit(msg_args[1], control_register_word, msg_args[0], 6);
228 is31_write_data (7, control_register_word, 0x02); 226 is31_write_data (msg_args[1], control_register_word, 0x02);
229 break; 227 break;
230 228
231 case TOGGLE_ALL: 229 case TOGGLE_ALL:
232 //msg_led = unused 230 //turn on/off all leds, msg_args = unused
233 is31_read_register(0, 0x00, &temp); 231 is31_read_register(0, 0x00, &temp);
234 led_control_reg[0] = 0; 232 led_control_reg[0] = 0;
235 233
236 //if first byte is on, then toggle frame 0 off 234 //if first leds are already on, toggle frame 0 off
237 if (temp==0 || page_status > 0) { 235 if (temp==0 || page_status > 0) {
238 __builtin_memcpy(led_control_reg+1, all_on_leds_mask, 0x12); 236 __builtin_memcpy(led_control_reg+1, all_on_leds_mask, 0x12);
239 } else { 237 } else {
@@ -252,27 +250,27 @@ page_status = 0; //start frame 0 (all off/on)
252 break; 250 break;
253 251
254 case TOGGLE_BACKLIGHT: 252 case TOGGLE_BACKLIGHT:
255 //msg_led = on/off 253 //msg_args[0] = on/off
256 254
257 //populate the 9 byte rows to be written to each pin, first byte is register (pin) address 255 //populate 9 byte rows to be written to each pin, first byte is register (pin) address
258 if (msg_led == 1) { 256 if (msg_args[0] == 1) {
259 __builtin_memset(pwm_register_array+1, pwm_levels[pwm_step_status], 8); 257 __builtin_memset(pwm_register_array+1, pwm_levels[pwm_step_status], 8);
260 } else { 258 } else {
261 __builtin_memset(pwm_register_array+1, 0, 8); 259 __builtin_memset(pwm_register_array+1, 0, 8);
262 } 260 }
263 261
264 for(i=0; i<8; i++) { 262 for(i=0; i<8; i++) {
265 //first byte is register address, every 0x10 9 bytes is A-register pwm pins 263 //first byte is register address, every 0x10 9 bytes is A-matrix pwm pins
266 pwm_register_array[0] = 0x24 + (i * 0x10); 264 pwm_register_array[0] = 0x24 + (i * 0x10);
267 is31_write_data(0,pwm_register_array,9); 265 is31_write_data(0,pwm_register_array,9);
268 } 266 }
269 break; 267 break;
270 268
271 case DISPLAY_PAGE: 269 case DISPLAY_PAGE:
272 //msg_led = page to toggle on 270 //msg_args[0] = page to toggle on
273 if (page_status != msg_led) { 271 if (page_status != msg_args[0]) {
274 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, msg_led); 272 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, msg_args[0]);
275 page_status = msg_led; 273 page_status = msg_args[0];
276 274
277 //maintain lock leds 275 //maintain lock leds
278 led_set(host_keyboard_leds()); 276 led_set(host_keyboard_leds());
@@ -280,24 +278,24 @@ page_status = 0; //start frame 0 (all off/on)
280 break; 278 break;
281 279
282 case RESET_PAGE: 280 case RESET_PAGE:
283 //led_msg = page to reset 281 //led_args[0] = page to reset
284 led_control_reg[0] = 0; 282 led_control_reg[0] = 0;
285 __builtin_memset(led_control_reg+1, 0, 0x12); 283 __builtin_memset(led_control_reg+1, 0, 0x12);
286 is31_write_data(msg_led, led_control_reg, 0x13); 284 is31_write_data(msg_args[0], led_control_reg, 0x13);
287 break; 285 break;
288 286
289 case TOGGLE_NUM_LOCK: 287 case TOGGLE_NUM_LOCK:
290 //msg_led = 0 or 1, off/on 288 //msg_args[0] = 0 or 1, off/on
291 set_lock_leds(NUM_LOCK_LED_ADDRESS, msg_led, page_status); 289 set_lock_leds(NUM_LOCK_LED_ADDRESS, msg_args[0], page_status);
292 break; 290 break;
293 case TOGGLE_CAPS_LOCK: 291 case TOGGLE_CAPS_LOCK:
294 //msg_led = 0 or 1, off/on 292 //msg_args[0] = 0 or 1, off/on
295 set_lock_leds(CAPS_LOCK_LED_ADDRESS, msg_led, page_status); 293 set_lock_leds(CAPS_LOCK_LED_ADDRESS, msg_args[0], page_status);
296 break; 294 break;
297 295
298 case STEP_BRIGHTNESS: 296 case STEP_BRIGHTNESS:
299 //led_msg = step pwm up or down 297 //led_args[0] = step up (1) or down (0)
300 switch (msg_led) { 298 switch (msg_args[0]) {
301 case 0: 299 case 0:
302 if (pwm_step_status == 0) { 300 if (pwm_step_status == 0) {
303 pwm_step_status = 4; 301 pwm_step_status = 4;
@@ -305,7 +303,7 @@ page_status = 0; //start frame 0 (all off/on)
305 pwm_step_status--; 303 pwm_step_status--;
306 } 304 }
307 break; 305 break;
308 306
309 case 1: 307 case 1:
310 if (pwm_step_status == 4) { 308 if (pwm_step_status == 4) {
311 pwm_step_status = 0; 309 pwm_step_status = 0;
@@ -316,7 +314,7 @@ page_status = 0; //start frame 0 (all off/on)
316 } 314 }
317 315
318 //populate 8 byte arrays to write on each pin 316 //populate 8 byte arrays to write on each pin
319 //first byte is register address, every 0x10 9 bytes are A-register pwm pins 317 //first byte is register address, every 0x10 9 bytes are A-matrix pwm pins
320 __builtin_memset(pwm_register_array+1, pwm_levels[pwm_step_status], 8); 318 __builtin_memset(pwm_register_array+1, pwm_levels[pwm_step_status], 8);
321 319
322 for(i=0; i<8; i++) { 320 for(i=0; i<8; i++) {
@@ -334,9 +332,9 @@ page_status = 0; //start frame 0 (all off/on)
334 332
335void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint8_t action) { 333void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint8_t action) {
336 //returns 2 bytes: led control register address and byte to write 334 //returns 2 bytes: led control register address and byte to write
337 //0 - bit off, 1 - bit on, 2 - toggle bit 335 //action: 0 - off, 1 - on, 2 - toggle, 4 - blink on, 5 - blink off, 6 - toggle blink
338 336
339 uint8_t control_reg_addr, column_bit, column_byte, bit_temp, blink_on; 337 uint8_t control_reg_addr, column_bit, column_byte, temp, blink_bit;
340 338
341 //check for valid led address 339 //check for valid led address
342 if (led_addr < 0 || led_addr > 87 || led_addr % 10 > 8) { 340 if (led_addr < 0 || led_addr > 87 || led_addr % 10 > 8) {
@@ -344,17 +342,17 @@ void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint
344 } 342 }
345 343
346 //check for blink bit 344 //check for blink bit
347 blink_on = action>>2; 345 blink_bit = action>>2;
348 action &= ~(1<<2); //strip blink bit 346 action &= ~(1<<2); //strip blink bit
349 347
350 //first byte is led control register address 0x00 348 //first byte is led control register address 0x00
351 //msg_led tens column is pin#, ones column is bit position in 8-bit mask 349 //led_addr tens column is pin#, ones column is bit position in 8-bit mask
352 control_reg_addr = ((led_addr / 10) % 10 - 1 ) * 0x02;// A-register is every other byte 350 control_reg_addr = ((led_addr / 10) % 10 - 1 ) * 0x02;// A-matrix is every other byte
353 control_reg_addr += blink_on == 1 ? 0x12 : 0x00;//shift 12 bytes to blink register 351 control_reg_addr += blink_bit == 1 ? 0x12 : 0x00;//if blink_bit, shift 12 bytes to blink register
354 352
355 is31_read_register(page, control_reg_addr, &bit_temp);//maintain status of leds on this byte 353 is31_read_register(page, control_reg_addr, &temp);//maintain status of leds on this byte
356 column_bit = 1<<(led_addr % 10 - 1); 354 column_bit = 1<<(led_addr % 10 - 1);
357 column_byte = bit_temp; 355 column_byte = temp;
358 356
359 switch(action) { 357 switch(action) {
360 case 0: 358 case 0:
@@ -376,7 +374,7 @@ void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint
376void write_led_byte (uint8_t page, uint8_t row, uint8_t led_byte) { 374void write_led_byte (uint8_t page, uint8_t row, uint8_t led_byte) {
377 uint8_t led_control_word[2] = {0};//register address and on/off byte 375 uint8_t led_control_word[2] = {0};//register address and on/off byte
378 376
379 led_control_word[0] = (row - 1 ) * 0x02;// A-register is every other byte 377 led_control_word[0] = (row - 1 ) * 0x02;// A-matrix is every other byte
380 led_control_word[1] = led_byte; 378 led_control_word[1] = led_byte;
381 is31_write_data(page, led_control_word, 0x02); 379 is31_write_data(page, led_control_word, 0x02);
382} 380}
@@ -389,7 +387,7 @@ void write_led_page (uint8_t page, uint8_t *user_led_array, uint8_t led_count) {
389 __builtin_memset(led_control_register,0,13); 387 __builtin_memset(led_control_register,0,13);
390 388
391 for(i=0;i<led_count;i++){ 389 for(i=0;i<led_count;i++){
392 // 1 byte shift for led register 0x00 address 390 //shift pin by 1 for led register 0x00 address
393 pin = ((user_led_array[i] / 10) % 10 - 1 ) * 2 + 1; 391 pin = ((user_led_array[i] / 10) % 10 - 1 ) * 2 + 1;
394 col = user_led_array[i] % 10 - 1; 392 col = user_led_array[i] % 10 - 1;
395 led_control_register[pin] |= 1<<(col); 393 led_control_register[pin] |= 1<<(col);
@@ -399,13 +397,13 @@ void write_led_page (uint8_t page, uint8_t *user_led_array, uint8_t led_count) {
399} 397}
400 398
401void set_lock_leds(uint8_t led_addr, uint8_t led_action, uint8_t page) { 399void set_lock_leds(uint8_t led_addr, uint8_t led_action, uint8_t page) {
402 uint8_t lock_temp; 400 uint8_t temp;
403 uint8_t led_control_word[2] = {0}; 401 uint8_t led_control_word[2] = {0};
404 402
405 //blink if all leds are on 403 //blink if all leds are on
406 if (page == 0) { 404 if (page == 0) {
407 is31_read_register(0, 0x00, &lock_temp); 405 is31_read_register(0, 0x00, &temp);
408 if (lock_temp == 0xFF) { 406 if (temp == 0xFF) {
409 led_action |= (1<<2); //set blink bit 407 led_action |= (1<<2); //set blink bit
410 } 408 }
411 } 409 }