aboutsummaryrefslogtreecommitdiff
path: root/keyboards/infinity60/led_controller.c
diff options
context:
space:
mode:
authorjpetermans <tibcmhhm@gmail.com>2017-04-11 23:33:48 -0700
committerjpetermans <tibcmhhm@gmail.com>2017-04-11 23:33:48 -0700
commit0881f2dbfa6887347afad577def01c246050df61 (patch)
treecc8163a5e0cd5f82ceff348c8534802e8b008a21 /keyboards/infinity60/led_controller.c
parentd8e9c183bef146bc4b42c7f15d5c44c7abd5118f (diff)
downloadqmk_firmware-0881f2dbfa6887347afad577def01c246050df61.tar.gz
qmk_firmware-0881f2dbfa6887347afad577def01c246050df61.zip
fixed write_led_page col shift, added option for lock led display
Diffstat (limited to 'keyboards/infinity60/led_controller.c')
-rw-r--r--keyboards/infinity60/led_controller.c109
1 files changed, 33 insertions, 76 deletions
diff --git a/keyboards/infinity60/led_controller.c b/keyboards/infinity60/led_controller.c
index 2a7431a4c..89c477ee7 100644
--- a/keyboards/infinity60/led_controller.c
+++ b/keyboards/infinity60/led_controller.c
@@ -101,7 +101,7 @@ const uint8_t pwm_levels[5] = {
101}; 101};
102 102
103// array to write to pwm register 103// array to write to pwm register
104uint8_t pwm_reg_array[9] = {0}; 104uint8_t pwm_register_array[9] = {0};
105 105
106 106
107/* ============================ 107/* ============================
@@ -147,10 +147,6 @@ void is31_init(void) {
147 // software shutdown 147 // software shutdown
148 is31_write_register(IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, 0); 148 is31_write_register(IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, 0);
149 chThdSleepMilliseconds(10); 149 chThdSleepMilliseconds(10);
150 // TODO: This already done above, remove?
151 // zero function page, all registers
152 is31_write_data(IS31_FUNCTIONREG, full_page, 0xD + 1);
153 chThdSleepMilliseconds(10);
154 // software shutdown disable (i.e. turn stuff on) 150 // software shutdown disable (i.e. turn stuff on)
155 is31_write_register(IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_ON); 151 is31_write_register(IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_ON);
156 chThdSleepMilliseconds(10); 152 chThdSleepMilliseconds(10);
@@ -176,7 +172,7 @@ static THD_FUNCTION(LEDthread, arg) {
176 uint8_t i, page; 172 uint8_t i, page;
177 173
178 //persistent status variables 174 //persistent status variables
179 uint8_t backlight_status, lock_status, led_step, active_layer; 175 uint8_t backlight_status, lock_status, led_step_status, layer_status;
180 uint8_t led_control_reg[0x13] = {0};//led control register start address + 0x12 bytes 176 uint8_t led_control_reg[0x13] = {0};//led control register start address + 0x12 bytes
181 177
182 //mailbox variables 178 //mailbox variables
@@ -191,8 +187,8 @@ static THD_FUNCTION(LEDthread, arg) {
191// initialize persistent variables 187// initialize persistent variables
192backlight_status = 0; 188backlight_status = 0;
193lock_status = 0;//TODO: does keyboard remember locks? 189lock_status = 0;//TODO: does keyboard remember locks?
194led_step = 4; //full brightness 190led_step_status = 4; //full brightness
195active_layer = 0; 191layer_status = 0;
196 192
197 while(true) { 193 while(true) {
198 // wait for a message (asynchronous) 194 // wait for a message (asynchronous)
@@ -213,13 +209,13 @@ active_layer = 0;
213 case TOGGLE_LED: 209 case TOGGLE_LED:
214 //TODO: toggle existing indicator off, or let user do this, but write frame 7 for every led change 210 //TODO: toggle existing indicator off, or let user do this, but write frame 7 for every led change
215 //turn on single led, msg_led = row/col of led 211 //turn on single led, msg_led = row/col of led
212 xprintf("TOGGLE_LED\n");
216 set_led_bit(led_control_reg, msg_led, 1); 213 set_led_bit(led_control_reg, msg_led, 1);
217 214
218 is31_write_data (7, led_control_reg, 0x12+1); 215 is31_write_data (7, led_control_reg, 0x12+1);
219 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 7); 216 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 7);
220 active_layer = 7; 217 layer_status = 7;
221 is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &temp); 218 is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &temp);
222 xprintf("page display: %X\n", temp);
223 break; 219 break;
224 220
225 case TOGGLE_ALL: 221 case TOGGLE_ALL:
@@ -227,40 +223,39 @@ active_layer = 0;
227 //msg_led = unused, TODO: consider using msg_led to toggle layer display 223 //msg_led = unused, TODO: consider using msg_led to toggle layer display
228 is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &temp); 224 is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &temp);
229 225
230 xprintf("temp: %X\n", temp);
231 //if LED_ALL is on then toggle off, any other layer, turn on LED_ALL 226 //if LED_ALL is on then toggle off, any other layer, turn on LED_ALL
232 if(temp == 1) { 227 if(temp == 1) {
233 xprintf("page display true: %X\n", temp);
234 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 0); 228 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 0);
235 } else { 229 } else {
236 xprintf("page display false: %X\n", temp);
237 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 1); 230 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 1);
238 } 231 }
239 is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &temp); 232 is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &temp);
240 xprintf("page display: %X\n", temp);
241 break; 233 break;
242 234
243 case TOGGLE_BACKLIGHT: 235 case TOGGLE_BACKLIGHT:
244 //msg_led = unused 236 //msg_led = unused
237 //TODO: consider Frame 0 as on/off layer and toggle led control register here
238 xprintf("TOGGLE_BACKLIGHT\n");
245 backlight_status ^= 1; 239 backlight_status ^= 1;
246 is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &temp); 240 is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &temp);
247 active_layer = temp; 241 layer_status = temp;
248 242
249 page = backlight_status == 0 ? 0 : active_layer; 243 page = backlight_status == 0 ? 0 : layer_status;
250 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, page); 244 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, page);
251 break; 245 break;
252 246
253 case TOGGLE_LAYER_LEDS://show layer indicator or full map of layer keys. 247 case TOGGLE_LAYER_LEDS://show layer indicator or full map of layer keys.
254 //TODO: change so user can flag which they want, indiv or full map in fn_actions 248 //TODO: change so user can flag which they want, indiv or full map in fn_actions
255 //msg_led = layer to toggle on 249 //msg_led = layer to toggle on
250 xprintf("TOGGLE_LAYER_LEDS\n");
256 is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &temp); 251 is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &temp);
257 252
258 if(temp == msg_led) { 253 if(temp == msg_led) {
259 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 7); 254 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 7);
260 active_layer = 7; 255 layer_status = 7;
261 } else { 256 } else {
262 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, msg_led); 257 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, msg_led);
263 active_layer = msg_led; 258 layer_status = msg_led;
264 } 259 }
265 break; 260 break;
266 261
@@ -275,29 +270,27 @@ active_layer = 0;
275 case STEP_BRIGHTNESS: 270 case STEP_BRIGHTNESS:
276 //pwm_levels[] bounds checking, loop through array 271 //pwm_levels[] bounds checking, loop through array
277 //TODO: find a cleaner way to walk through this logic 272 //TODO: find a cleaner way to walk through this logic
278 if (msg_led == 0) { 273 if (msg_led == 0 && led_step_status == 0) {
279 if (led_step == 0) { 274 led_step_status = 4;
280 led_step = 4;
281 } else {
282 led_step--;
283 }
284 } else { 275 } else {
285 if (led_step == 4) { 276 led_step_status--;
286 led_step = 0; 277 }
287 } else { 278
288 led_step++; 279 if (msg_led == 1 && led_step_status == 4) {
289 } 280 led_step_status = 0;
281 } else {
282 led_step_status++;
290 } 283 }
291 284
292 //TODO: this seems a messy way to populate the pwm register 285 //TODO: this seems a messy way to populate the pwm register
286 //mimic whitefox init which uses memcpy
293 //populate the 9 byte rows to be written to each pin, first byte is register (pin) address 287 //populate the 9 byte rows to be written to each pin, first byte is register (pin) address
294 for(i=1; i<9; i++) { 288 for(i=1; i<9; i++) {
295 pwm_reg_array[i]=pwm_levels[led_step]; 289 pwm_register_array[i]=pwm_levels[led_step_status];
296 } 290 }
297 for(i=0; i<8; i++) { 291 for(i=0; i<8; i++) {
298 pwm_reg_array[0] = 0x24 + (i * 0x10);//first byte of 9 bytes must be register address 292 pwm_register_array[0] = 0x24 + (i * 0x10);//first byte of 9 bytes must be register address
299 is31_write_data(0, pwm_reg_array, 9); 293 is31_write_data(0, pwm_register_array, 9);//first page controls pwm in all pages (init Display Option register)
300 chThdSleepMilliseconds(5);
301 } 294 }
302 break; 295 break;
303 296
@@ -330,36 +323,6 @@ active_layer = 0;
330 case LED_MSG_SLEEP_LED_OFF: 323 case LED_MSG_SLEEP_LED_OFF:
331 // should not get here; wakeup should be received in the branch above break; 324 // should not get here; wakeup should be received in the branch above break;
332 break; 325 break;
333 default:
334 //TODO: individual led state unchanged if page arrays are selected in code above
335 //avoidable if full pages are written on the fly
336 //or use pg8 for individual leds, have pointer to currently on led address for toggling
337 if (msg == 0x59 || msg == 0x84) {
338 //toggle lock keys on all layers
339 for (i=0,i<8,i++) {
340 is31_read_register(0, msg, &temp);
341 pwm = (temp > 0x00 ? 0x00 : 0xFF);
342 is31_write_register(i,msg,pwm);
343 }
344
345 } else if(msg >= 0x24) {
346 xprintf("Power pre-read\ntemp: %X - msg: %X - pwm: %X\n", temp, msg, pwm);
347 is31_read_register(7, msg, &temp);
348 xprintf("Post-read\ntemp: %X - msg: %X - pwm: %X\n", temp, msg, pwm);
349 if (msg == active_led) {
350 //toggle led power
351 pwm = (temp > 0x00 ? 0x00 : 0xFF);
352
353 //Use 8th led page for individual led indicators
354 is31_write_register(7, msg, pwm);
355 } else {
356 is31_write_register(7, active_led, 0x00);
357 is31_write_register(7, msg, 0xFF);
358 }
359 xprintf("Power post-change\ntemp: %X - msg: %X - pwm: %X\n", temp, msg, pwm);
360 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 7);
361 }
362 break;
363*/ 326*/
364 } 327 }
365 xprintf("--------------------\n"); 328 xprintf("--------------------\n");
@@ -378,8 +341,6 @@ void set_led_bit (uint8_t *led_control_reg, uint8_t msg_led, uint8_t toggle_on)
378 ////first byte is register address 0x00 341 ////first byte is register address 0x00
379 row_byte = ((msg_led / 10) % 10 - 1 ) * 2 + 1; 342 row_byte = ((msg_led / 10) % 10 - 1 ) * 2 + 1;
380 column_bit = 1<<(msg_led % 10 - 1); 343 column_bit = 1<<(msg_led % 10 - 1);
381 xprintf("row %X\n", row_byte);
382 xprintf("col %X\n", column_bit);
383 344
384 if (toggle_on) { 345 if (toggle_on) {
385 led_control_reg[row_byte] |= 1<<(column_bit); 346 led_control_reg[row_byte] |= 1<<(column_bit);
@@ -393,7 +354,7 @@ void set_lock_leds(uint8_t *led_control_reg, uint8_t lock_status) {
393 354
394 switch (lock_status) { 355 switch (lock_status) {
395 case 1: 356 case 1:
396 set_led_bit(led_control_reg, CAPS_LOCK_LED_ADDRESS, 1);//TODO: define lock addresses by matrix#, and loop for all frames 357 set_led_bit(led_control_reg, CAPS_LOCK_LED_ADDRESS, 1);
397 set_led_bit(led_control_reg, NUM_LOCK_LED_ADDRESS, 0); 358 set_led_bit(led_control_reg, NUM_LOCK_LED_ADDRESS, 0);
398 break; 359 break;
399 case 2: 360 case 2:
@@ -406,9 +367,8 @@ void set_lock_leds(uint8_t *led_control_reg, uint8_t lock_status) {
406 break; 367 break;
407 } 368 }
408 369
409 for(i=1; i<8; i++) { //keep LED_OFF layer all off, including locks 370 for(i=BACKLIGHT_OFF_LOCK_LED_OFF; i<8; i++) { //set in led_controller.h
410 is31_write_data (i, led_control_reg, 0x12+1); 371 is31_write_data (i, led_control_reg, 0x12+1);
411 chThdSleepMilliseconds(5);
412 } 372 }
413} 373}
414 374
@@ -417,18 +377,15 @@ void write_led_page (uint8_t page, const uint8_t *led_array, uint8_t led_count)
417 uint8_t i; 377 uint8_t i;
418 uint8_t row, col; 378 uint8_t row, col;
419 uint8_t temp_control_reg[0x13] = {0};//led control register start address + 0x12 bytes 379 uint8_t temp_control_reg[0x13] = {0};//led control register start address + 0x12 bytes
420 xprintf("-------------\n");
421 xprintf("write page %X\n", page);
422 380
423 for(i=0;i<led_count;i++){ 381 for(i=0;i<led_count;i++){
424 row = ((led_array[i] / 10) % 10 - 1 ) * 2 + 1;//includes 1 byte shift for 0x00 address 382 row = ((led_array[i] / 10) % 10 - 1 ) * 2 + 1;//includes 1 byte shift for led register 0x00 address
425 col = 1<<(led_array[i] % 10 - 1); 383 col = led_array[i] % 10 - 1;
426 384
427 temp_control_reg[row] |= 1<<(col); 385 temp_control_reg[row] |= 1<<(col);
428 } 386 }
429 387
430 is31_write_data(page, temp_control_reg, 0x13); 388 is31_write_data(page, temp_control_reg, 0x13);
431 xprintf("-------------\n");
432} 389}
433/* ===================== 390/* =====================
434 * hook into user keymap 391 * hook into user keymap
@@ -457,11 +414,11 @@ void led_controller_init(void) {
457 414
458 /* set full pwm on Frame 1 */ 415 /* set full pwm on Frame 1 */
459 for(i=1; i<9; i++) { 416 for(i=1; i<9; i++) {
460 pwm_reg_array[i]=0xFF; 417 pwm_register_array[i]=0xFF;
461 } 418 }
462 for(i=0; i<8; i++) { 419 for(i=0; i<8; i++) {
463 pwm_reg_array[0] = 0x24 + (i * 0x10);//first byte of 9 bytes must be register address 420 pwm_register_array[0] = 0x24 + (i * 0x10);//first byte of 9 bytes must be register address
464 is31_write_data(0, pwm_reg_array, 9); 421 is31_write_data(0, pwm_register_array, 9);
465 chThdSleepMilliseconds(5); 422 chThdSleepMilliseconds(5);
466 } 423 }
467 424