aboutsummaryrefslogtreecommitdiff
path: root/keyboards/infinity60/led_controller.c
diff options
context:
space:
mode:
authorjpetermans <tibcmhhm@gmail.com>2017-04-06 13:46:54 -0700
committerjpetermans <tibcmhhm@gmail.com>2017-04-06 13:46:54 -0700
commitda4c2d2e3e4cd566ccf0c5a468f1a544c4b2be55 (patch)
treea3421782e1b7a2cfdba81bca0c2480c0ecd26df0 /keyboards/infinity60/led_controller.c
parentb73c935d3652df58fc573c83986424ab47a2ba14 (diff)
downloadqmk_firmware-da4c2d2e3e4cd566ccf0c5a468f1a544c4b2be55.tar.gz
qmk_firmware-da4c2d2e3e4cd566ccf0c5a468f1a544c4b2be55.zip
Adjust led_controller.c matrix sttings and init function
Diffstat (limited to 'keyboards/infinity60/led_controller.c')
-rw-r--r--keyboards/infinity60/led_controller.c123
1 files changed, 65 insertions, 58 deletions
diff --git a/keyboards/infinity60/led_controller.c b/keyboards/infinity60/led_controller.c
index bc501d9f2..c5303a3e7 100644
--- a/keyboards/infinity60/led_controller.c
+++ b/keyboards/infinity60/led_controller.c
@@ -23,22 +23,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
23 23
24#include "ch.h" 24#include "ch.h"
25#include "hal.h" 25#include "hal.h"
26#include "print.h"
26 27
27#include "led_controller.h" 28#include "led_controller.h"
28 29
29#include "hook.h"
30#include "suspend.h" 30#include "suspend.h"
31 31
32#include "usb_main.h" 32#include "usb_main.h"
33 33
34/* WF LED MAP 34/* Infinity60 LED MAP
35 - digits mean "row" and "col", i.e. 45 means C4-5 in the IS31 datasheet, matrix A 35 - digits mean "row" and "col", i.e. 45 means C4-5 in the IS31 datasheet, matrix A
36 36
37 11 12 13 14 15 16 17 18 21 22 23 24 25 26 27 28 37 11 12 13 14 15 16 17 18 21 22 23 24 25 26 27*
38 31 32 33 34 35 36 37 38 41 42 43 44 45 46 47 38 28 31 32 33 34 35 36 37 38 41 42 43 44 45
39 48 51 52 53 54 55 56 57 58 61 62 63 64 65 66 39 46 47 48 51 52 53 54 55 56 57 58 61 62
40 67 68 71 72 73 74 75 76 77 78 81 82 83 84 85 40 63 64 65 66 67 68 71 72 73 74 75 76 77*
41 86 87 88 91 92 93 (94) 95 96 97 41 78 81 82 83 84 85 86 87
42
43*Unused in Alphabet Layout
42*/ 44*/
43 45
44/* 46/*
@@ -52,10 +54,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
52*/ 54*/
53 55
54/* Which LED should be used for CAPS LOCK indicator 56/* Which LED should be used for CAPS LOCK indicator
55 * The usual Caps Lock position is C4-8, so the address is 57 * The usual Caps Lock position is C4-6, so the address is
56 * 0x24 + (4-1)*0x10 + (8-1) = 0x5B */ 58 * 0x24 + (4-1)*0x10 + (8-1) = 0x59 */
57#if !defined(CAPS_LOCK_LED_ADDRESS) 59#if !defined(CAPS_LOCK_LED_ADDRESS)
58#define CAPS_LOCK_LED_ADDRESS 0x5B 60#define CAPS_LOCK_LED_ADDRESS 0x59
59#endif 61#endif
60 62
61/* Which LED should breathe during sleep */ 63/* Which LED should breathe during sleep */
@@ -81,9 +83,12 @@ uint8_t rx[1] __attribute__((aligned(2)));
81uint8_t full_page[0xB4+1] = {0}; 83uint8_t full_page[0xB4+1] = {0};
82 84
83// LED mask (which LEDs are present, selected by bits) 85// LED mask (which LEDs are present, selected by bits)
84const uint8_t is31_wf_leds_mask[0x12] = { 86// See page comment above, control alternates CA matrix/CB matrix
87// IC60 pcb uses only CA matrix.
88// Each byte is a control pin for 8 leds 8-1
89const uint8_t is31_ic60_leds_mask[0x12] = {
85 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 90 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF,
86 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x7F, 0x00 91 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x7F, 0x00, 0x00, 0x00
87}; 92};
88 93
89/* ============================ 94/* ============================
@@ -233,56 +238,55 @@ static THD_FUNCTION(LEDthread, arg) {
233 } 238 }
234} 239}
235 240
241//These relate to the LED map above, row and column
242//0x24 = first byte (CA1) of PWM page, 0x34 is 17th byte (CA2)
236/* LED game mode */ 243/* LED game mode */
237const uint8_t led_game[83] = { 244const uint8_t led_game[72] = {
238 0x24, 245 0x24,
239 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 246 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
240 0x34, 247 0x34,
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
242 0x44, 249 0x44,
243 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 250 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
244 0x54, 251 0x54,
245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
246 0x64, 253 0x64,
247 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 254 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
248 0x74, 255 0x74,
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
250 0x84, 257 0x84,
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252 0x94, 259 0x94,
253 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
254 0xA4,
255 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00,
256}; 261};
257 262
258/* ALL LEDs */ 263/* ALL LEDs */
259const uint8_t led_all[83] = { 264const uint8_t led_all[72] = {
260 0x24, 265 0x24,
261 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 266 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
262 0x34, 267 0x34,
263 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 268 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
264 0x44, 2690x44,
265 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 270 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
266 0x54, 271 0x54,
267 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 272 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
268 0x64, 273 0x64,
269 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 274 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
270 0x74, 275 0x74,
271 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 276 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
272 0x84, 277 0x84,
273 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 278 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
274 0x94, 279 0x94,
275 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 280 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
276 0xA4,
277 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
278}; 281};
279 282
280/* ============= 283/* =============
281 * hook into TMK 284 * hook into TMK
282 * ============= */ 285 * ============= */
283void hook_early_init(void) { 286void led_controller_init(void) {
284 uint8_t i; 287 uint8_t i;
285 288
289 xprintf("led_controller_init");
286 /* initialise I2C */ 290 /* initialise I2C */
287 /* I2C pins */ 291 /* I2C pins */
288 palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATIVE_2); // PTB0/I2C0/SCL 292 palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATIVE_2); // PTB0/I2C0/SCL
@@ -299,9 +303,9 @@ void hook_early_init(void) {
299 /* initialise IS31 chip */ 303 /* initialise IS31 chip */
300 is31_init(); 304 is31_init();
301 305
302 /* enable WF LEDs on all pages */ 306 /* enable LEDs on all pages */
303 full_page[0] = 0; 307 full_page[0] = 0;
304 __builtin_memcpy(full_page+1, is31_wf_leds_mask, 0x12); 308 __builtin_memcpy(full_page+1, is31_ic60_leds_mask, 0x12);
305 for(i=0; i<8; i++) { 309 for(i=0; i<8; i++) {
306 is31_write_data(i, full_page, 1+0x12); 310 is31_write_data(i, full_page, 1+0x12);
307 } 311 }
@@ -312,7 +316,7 @@ void hook_early_init(void) {
312 is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL2, IS31_REG_BREATHCTRL2_ENABLE|3); 316 is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL2, IS31_REG_BREATHCTRL2_ENABLE|3);
313 317
314 /* Write pages */ 318 /* Write pages */
315 for(i=0; i<9; i++) { 319 for(i=0; i<8; i++) {
316 is31_write_data(1,(uint8_t *)(led_game+(9*i)),9); 320 is31_write_data(1,(uint8_t *)(led_game+(9*i)),9);
317 chThdSleepMilliseconds(5); 321 chThdSleepMilliseconds(5);
318 is31_write_data(2,(uint8_t *)(led_all+(9*i)),9); 322 is31_write_data(2,(uint8_t *)(led_all+(9*i)),9);
@@ -329,26 +333,29 @@ void hook_early_init(void) {
329 chThdCreateStatic(waLEDthread, sizeof(waLEDthread), LOWPRIO, LEDthread, NULL); 333 chThdCreateStatic(waLEDthread, sizeof(waLEDthread), LOWPRIO, LEDthread, NULL);
330} 334}
331 335
332void hook_usb_suspend_entry(void) { 336//TODO: Don't know equivalent QMK hooks for these
333#ifdef SLEEP_LED_ENABLE 337//
334 chSysLockFromISR(); 338//void hook_usb_suspend_entry(void) {
335 chMBPostI(&led_mailbox, LED_MSG_SLEEP_LED_ON); 339//#ifdef SLEEP_LED_ENABLE
336 chSysUnlockFromISR(); 340// chSysLockFromISR();
337#endif /* SLEEP_LED_ENABLE */ 341// chMBPostI(&led_mailbox, LED_MSG_SLEEP_LED_ON);
338} 342// chSysUnlockFromISR();
339 343//#endif /* SLEEP_LED_ENABLE */
340void hook_usb_suspend_loop(void) { 344//}
341 chThdSleepMilliseconds(100); 345//
342 /* Remote wakeup */ 346//void hook_usb_suspend_loop(void) {
343 if((USB_DRIVER.status & 2) && suspend_wakeup_condition()) { 347// chThdSleepMilliseconds(100);
344 send_remote_wakeup(&USB_DRIVER); 348// /* Remote wakeup */
345 } 349// if((USB_DRIVER.status & 2) && suspend_wakeup_condition()) {
346} 350// send_remote_wakeup(&USB_DRIVER);
347 351// }
348void hook_usb_wakeup(void) { 352//}
349#ifdef SLEEP_LED_ENABLE 353//
350 chSysLockFromISR(); 354//void hook_usb_wakeup(void) {
351 chMBPostI(&led_mailbox, LED_MSG_SLEEP_LED_OFF); 355//#ifdef SLEEP_LED_ENABLE
352 chSysUnlockFromISR(); 356// chSysLockFromISR();
353#endif /* SLEEP_LED_ENABLE */ 357// chMBPostI(&led_mailbox, LED_MSG_SLEEP_LED_OFF);
354} 358// chSysUnlockFromISR();
359//#endif /* SLEEP_LED_ENABLE */
360//}
361//*/