Adjust led_controller.c matrix sttings and init function

This commit is contained in:
jpetermans 2017-04-06 13:46:54 -07:00
parent b73c935d36
commit da4c2d2e3e

View File

@ -23,22 +23,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "ch.h"
#include "hal.h"
#include "print.h"
#include "led_controller.h"
#include "hook.h"
#include "suspend.h"
#include "usb_main.h"
/* WF LED MAP
/* Infinity60 LED MAP
- digits mean "row" and "col", i.e. 45 means C4-5 in the IS31 datasheet, matrix A
11 12 13 14 15 16 17 18 21 22 23 24 25 26 27 28
31 32 33 34 35 36 37 38 41 42 43 44 45 46 47
48 51 52 53 54 55 56 57 58 61 62 63 64 65 66
67 68 71 72 73 74 75 76 77 78 81 82 83 84 85
86 87 88 91 92 93 (94) 95 96 97
11 12 13 14 15 16 17 18 21 22 23 24 25 26 27*
28 31 32 33 34 35 36 37 38 41 42 43 44 45
46 47 48 51 52 53 54 55 56 57 58 61 62
63 64 65 66 67 68 71 72 73 74 75 76 77*
78 81 82 83 84 85 86 87
*Unused in Alphabet Layout
*/
/*
@ -52,10 +54,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* Which LED should be used for CAPS LOCK indicator
* The usual Caps Lock position is C4-8, so the address is
* 0x24 + (4-1)*0x10 + (8-1) = 0x5B */
* The usual Caps Lock position is C4-6, so the address is
* 0x24 + (4-1)*0x10 + (8-1) = 0x59 */
#if !defined(CAPS_LOCK_LED_ADDRESS)
#define CAPS_LOCK_LED_ADDRESS 0x5B
#define CAPS_LOCK_LED_ADDRESS 0x59
#endif
/* Which LED should breathe during sleep */
@ -81,9 +83,12 @@ uint8_t rx[1] __attribute__((aligned(2)));
uint8_t full_page[0xB4+1] = {0};
// LED mask (which LEDs are present, selected by bits)
const uint8_t is31_wf_leds_mask[0x12] = {
// See page comment above, control alternates CA matrix/CB matrix
// IC60 pcb uses only CA matrix.
// Each byte is a control pin for 8 leds 8-1
const uint8_t is31_ic60_leds_mask[0x12] = {
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF,
0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x7F, 0x00
0x00, 0xFF, 0x00, 0xFF, 0x00, 0x7F, 0x00, 0x00, 0x00
};
/* ============================
@ -233,56 +238,55 @@ static THD_FUNCTION(LEDthread, arg) {
}
}
//These relate to the LED map above, row and column
//0x24 = first byte (CA1) of PWM page, 0x34 is 17th byte (CA2)
/* LED game mode */
const uint8_t led_game[83] = {
const uint8_t led_game[72] = {
0x24,
0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x34,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x44,
0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x54,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
0x64,
0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x74,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x84,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x94,
0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00,
0xA4,
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
/* ALL LEDs */
const uint8_t led_all[83] = {
const uint8_t led_all[72] = {
0x24,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x34,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0x44,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x44,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x54,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x64,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x74,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x84,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x94,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xA4,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
};
/* =============
* hook into TMK
* ============= */
void hook_early_init(void) {
void led_controller_init(void) {
uint8_t i;
xprintf("led_controller_init");
/* initialise I2C */
/* I2C pins */
palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATIVE_2); // PTB0/I2C0/SCL
@ -299,9 +303,9 @@ void hook_early_init(void) {
/* initialise IS31 chip */
is31_init();
/* enable WF LEDs on all pages */
/* enable LEDs on all pages */
full_page[0] = 0;
__builtin_memcpy(full_page+1, is31_wf_leds_mask, 0x12);
__builtin_memcpy(full_page+1, is31_ic60_leds_mask, 0x12);
for(i=0; i<8; i++) {
is31_write_data(i, full_page, 1+0x12);
}
@ -312,7 +316,7 @@ void hook_early_init(void) {
is31_write_register(IS31_FUNCTIONREG, IS31_REG_BREATHCTRL2, IS31_REG_BREATHCTRL2_ENABLE|3);
/* Write pages */
for(i=0; i<9; i++) {
for(i=0; i<8; i++) {
is31_write_data(1,(uint8_t *)(led_game+(9*i)),9);
chThdSleepMilliseconds(5);
is31_write_data(2,(uint8_t *)(led_all+(9*i)),9);
@ -329,26 +333,29 @@ void hook_early_init(void) {
chThdCreateStatic(waLEDthread, sizeof(waLEDthread), LOWPRIO, LEDthread, NULL);
}
void hook_usb_suspend_entry(void) {
#ifdef SLEEP_LED_ENABLE
chSysLockFromISR();
chMBPostI(&led_mailbox, LED_MSG_SLEEP_LED_ON);
chSysUnlockFromISR();
#endif /* SLEEP_LED_ENABLE */
}
void hook_usb_suspend_loop(void) {
chThdSleepMilliseconds(100);
/* Remote wakeup */
if((USB_DRIVER.status & 2) && suspend_wakeup_condition()) {
send_remote_wakeup(&USB_DRIVER);
}
}
void hook_usb_wakeup(void) {
#ifdef SLEEP_LED_ENABLE
chSysLockFromISR();
chMBPostI(&led_mailbox, LED_MSG_SLEEP_LED_OFF);
chSysUnlockFromISR();
#endif /* SLEEP_LED_ENABLE */
}
//TODO: Don't know equivalent QMK hooks for these
//
//void hook_usb_suspend_entry(void) {
//#ifdef SLEEP_LED_ENABLE
// chSysLockFromISR();
// chMBPostI(&led_mailbox, LED_MSG_SLEEP_LED_ON);
// chSysUnlockFromISR();
//#endif /* SLEEP_LED_ENABLE */
//}
//
//void hook_usb_suspend_loop(void) {
// chThdSleepMilliseconds(100);
// /* Remote wakeup */
// if((USB_DRIVER.status & 2) && suspend_wakeup_condition()) {
// send_remote_wakeup(&USB_DRIVER);
// }
//}
//
//void hook_usb_wakeup(void) {
//#ifdef SLEEP_LED_ENABLE
// chSysLockFromISR();
// chMBPostI(&led_mailbox, LED_MSG_SLEEP_LED_OFF);
// chSysUnlockFromISR();
//#endif /* SLEEP_LED_ENABLE */
//}
//*/