add ability to toggle individual led by address
parent
af13e9a12d
commit
a2ac883779
|
@ -12,6 +12,10 @@
|
||||||
#define _MEDIA 3
|
#define _MEDIA 3
|
||||||
#define _TILDE 4
|
#define _TILDE 4
|
||||||
|
|
||||||
|
/* ==================================
|
||||||
|
* KEYMAPS
|
||||||
|
* ==================================*/
|
||||||
|
|
||||||
const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
/* Layer 0: Default Layer
|
/* Layer 0: Default Layer
|
||||||
* ,-----------------------------------------------------------.
|
* ,-----------------------------------------------------------.
|
||||||
|
@ -58,7 +62,7 @@ const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
_______,_______,_______,_______,_______,_______,_______, _______, _______, _______,KC_MUTE, KC_VOLD, KC_VOLU,_______,KC_NO,\
|
_______,_______,_______,_______,_______,_______,_______, _______, _______, _______,KC_MUTE, KC_VOLD, KC_VOLU,_______,KC_NO,\
|
||||||
_______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______,_______,\
|
_______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______,_______,\
|
||||||
_______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______, \
|
_______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______, \
|
||||||
_______,_______,F(2),F(3),_______,_______,_______, _______, KC_MPRV, KC_MNXT,KC_MSTP, _______,KC_NO, \
|
_______,_______,F(2),F(3),F(4),_______,_______, _______, KC_MPRV, KC_MNXT,KC_MSTP, _______,KC_NO, \
|
||||||
_______,_______,_______, KC_MPLY, _______,_______, _______,_______ \
|
_______,_______,_______, KC_MPLY, _______,_______, _______,_______ \
|
||||||
),
|
),
|
||||||
/* ~ */
|
/* ~ */
|
||||||
|
@ -86,20 +90,20 @@ enum function_id {
|
||||||
|
|
||||||
enum macro_id {
|
enum macro_id {
|
||||||
ACTION_LEDS_ALL,
|
ACTION_LEDS_ALL,
|
||||||
ACTION_LEDS_GAME
|
ACTION_LEDS_GAME,
|
||||||
//TODO: ACTION_LED_LAYER which reads current layer and turns on appropriate LED
|
ACTION_LED_1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* ==================================
|
||||||
|
* LED MAPPING
|
||||||
|
* ==================================*/
|
||||||
|
|
||||||
|
//TODO: ACTION_LED_LAYER which reads current layer and turns on appropriate LED
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Configuring led control can be done
|
Configuring led control can be done as
|
||||||
1. full keyboard at a time - define led array, or
|
1. full keyboard at a time - define led array, or
|
||||||
2. individual - send specific led address (defined in keymap.h)
|
2. individual led - send specific led address (defined in keymap.h)
|
||||||
|
|
||||||
The arrays relate to the mcu's LED pages (8 available) desribed in led_controller.c
|
|
||||||
0x24 (pcb row 1) is first byte of PWM portion of LED page
|
|
||||||
0x34 (pcb row 2) is 17th byte of PWM portion of LED page
|
|
||||||
array translates to row and column positions
|
|
||||||
|
|
||||||
|
|
||||||
Infinity60 LED MAP
|
Infinity60 LED MAP
|
||||||
11 12 13 14 15 16 17 18 21 22 23 24 25 26 27*
|
11 12 13 14 15 16 17 18 21 22 23 24 25 26 27*
|
||||||
|
@ -108,6 +112,13 @@ enum macro_id {
|
||||||
63 64 65 66 67 68 71 72 73 74 75 76 77*
|
63 64 65 66 67 68 71 72 73 74 75 76 77*
|
||||||
78 81 82 83 84 85 86 87
|
78 81 82 83 84 85 86 87
|
||||||
*Unused in Alphabet Layout
|
*Unused in Alphabet Layout
|
||||||
|
|
||||||
|
The full keyboard arrays map to the mcu's LED pages
|
||||||
|
(8 available) desribed in led_controller.c
|
||||||
|
|
||||||
|
0x24 (pcb row 1) is first byte of PWM portion of LED page
|
||||||
|
0x34 (pcb row 2) is 17th byte of PWM portion of LED page
|
||||||
|
array translates to row and column positions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//"WASD"
|
//"WASD"
|
||||||
|
@ -153,7 +164,8 @@ const uint16_t fn_actions[] = {
|
||||||
[0] = ACTION_KEY(LALT(LCTL(KC_DEL))),
|
[0] = ACTION_KEY(LALT(LCTL(KC_DEL))),
|
||||||
[1] = ACTION_LAYER_MODS(_TILDE, MOD_LSFT),
|
[1] = ACTION_LAYER_MODS(_TILDE, MOD_LSFT),
|
||||||
[2] = ACTION_FUNCTION(ACTION_LEDS_ALL),
|
[2] = ACTION_FUNCTION(ACTION_LEDS_ALL),
|
||||||
[3] = ACTION_FUNCTION(ACTION_LEDS_GAME)
|
[3] = ACTION_FUNCTION(ACTION_LEDS_GAME),
|
||||||
|
[4] = ACTION_FUNCTION(ACTION_LED_1)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -164,13 +176,19 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {
|
||||||
case ACTION_LEDS_ALL:
|
case ACTION_LEDS_ALL:
|
||||||
if(record->event.pressed) {
|
if(record->event.pressed) {
|
||||||
// signal the LED controller thread
|
// signal the LED controller thread
|
||||||
chMBPost(&led_mailbox, LED_MSG_GAME_TOGGLE, TIME_IMMEDIATE);
|
chMBPost(&led_mailbox, 1, TIME_IMMEDIATE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ACTION_LEDS_GAME:
|
case ACTION_LEDS_GAME:
|
||||||
if(record->event.pressed) {
|
if(record->event.pressed) {
|
||||||
// signal the LED controller thread
|
// signal the LED controller thread
|
||||||
chMBPost(&led_mailbox, LED_MSG_ALL_TOGGLE, TIME_IMMEDIATE);
|
chMBPost(&led_mailbox, 2, TIME_IMMEDIATE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ACTION_LED_1:
|
||||||
|
if(record->event.pressed) {
|
||||||
|
// signal the LED controller thread
|
||||||
|
chMBPost(&led_mailbox, ADDR_LED_1, TIME_IMMEDIATE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,9 @@ void led_set(uint8_t usb_led) {
|
||||||
GPIOA->PCOR |= (1<<5);
|
GPIOA->PCOR |= (1<<5);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
//TODO: How does this test if led is set
|
||||||
|
//usb_led --> led_set(usb_led) <-- chibios/host_keyboard_leds <-- keyboard_leds from usbSetupTransfer
|
||||||
|
//keyboard_leds is enum'd in chibios/main.c
|
||||||
if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
|
if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
|
||||||
// signal the LED control thread
|
// signal the LED control thread
|
||||||
chSysUnconditionalLock();
|
chSysUnconditionalLock();
|
||||||
|
|
|
@ -112,8 +112,8 @@ msg_t is31_write_register(uint8_t page, uint8_t reg, uint8_t data) {
|
||||||
return i2cMasterTransmitTimeout(&I2CD1, IS31_ADDR_DEFAULT, tx, 2, NULL, 0, US2ST(IS31_TIMEOUT));
|
return i2cMasterTransmitTimeout(&I2CD1, IS31_ADDR_DEFAULT, tx, 2, NULL, 0, US2ST(IS31_TIMEOUT));
|
||||||
}
|
}
|
||||||
|
|
||||||
msg_t is31_read_register(uint8_t b, uint8_t reg, uint8_t *result) {
|
msg_t is31_read_register(uint8_t page, uint8_t reg, uint8_t *result) {
|
||||||
is31_select_page(b);
|
is31_select_page(page);
|
||||||
|
|
||||||
tx[0] = reg;
|
tx[0] = reg;
|
||||||
return i2cMasterTransmitTimeout(&I2CD1, IS31_ADDR_DEFAULT, tx, 1, result, 1, US2ST(IS31_TIMEOUT));
|
return i2cMasterTransmitTimeout(&I2CD1, IS31_ADDR_DEFAULT, tx, 1, result, 1, US2ST(IS31_TIMEOUT));
|
||||||
|
@ -134,6 +134,7 @@ void is31_init(void) {
|
||||||
// software shutdown
|
// software shutdown
|
||||||
is31_write_register(IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, 0);
|
is31_write_register(IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, 0);
|
||||||
chThdSleepMilliseconds(10);
|
chThdSleepMilliseconds(10);
|
||||||
|
// TODO: This already done above, remove?
|
||||||
// zero function page, all registers
|
// zero function page, all registers
|
||||||
is31_write_data(IS31_FUNCTIONREG, full_page, 0xD + 1);
|
is31_write_data(IS31_FUNCTIONREG, full_page, 0xD + 1);
|
||||||
chThdSleepMilliseconds(10);
|
chThdSleepMilliseconds(10);
|
||||||
|
@ -159,7 +160,8 @@ static THD_FUNCTION(LEDthread, arg) {
|
||||||
(void)arg;
|
(void)arg;
|
||||||
chRegSetThreadName("LEDthread");
|
chRegSetThreadName("LEDthread");
|
||||||
|
|
||||||
uint8_t temp;
|
uint8_t i;
|
||||||
|
uint8_t temp, pwm;
|
||||||
uint8_t save_page, save_breath1, save_breath2;
|
uint8_t save_page, save_breath1, save_breath2;
|
||||||
msg_t msg, retval;
|
msg_t msg, retval;
|
||||||
|
|
||||||
|
@ -170,20 +172,28 @@ static THD_FUNCTION(LEDthread, arg) {
|
||||||
chMBFetch(&led_mailbox, &msg, TIME_INFINITE);
|
chMBFetch(&led_mailbox, &msg, TIME_INFINITE);
|
||||||
|
|
||||||
// process 'msg' here
|
// process 'msg' here
|
||||||
|
// if msg between 0-7, then process as page#, otherwise a specific LED address
|
||||||
|
xprintf("--------------------\n");
|
||||||
|
xprintf("mailbox fetch\ntemp: %X - msg: %X\n", temp, msg);
|
||||||
|
if (msg < 8) {
|
||||||
|
|
||||||
|
// read current page into 'temp'
|
||||||
|
is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &temp);
|
||||||
|
chThdSleepMilliseconds(1);
|
||||||
|
// If page is already in layer, switch off (layer 0)
|
||||||
|
xprintf("Layer: post-read\ntemp: %X\n", temp);
|
||||||
|
if(temp == msg) {
|
||||||
|
is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 0);
|
||||||
|
} else {
|
||||||
|
is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, msg);
|
||||||
|
}
|
||||||
|
xprintf("Layer: post-change\ntemp: %X\n", temp);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
switch(msg) {
|
switch(msg) {
|
||||||
//TODO: make this generic and able to turn on/off any address and loop through all(or current) pages
|
//TODO: make this generic and able to turn on/off any address and loop through all(or current) pages
|
||||||
case LED_MSG_CAPS_ON:
|
//TODO: set number of layers somewhere and loop through all when setting specific led
|
||||||
// turn caps on on pages 1 and 2
|
|
||||||
is31_write_register(0, CAPS_LOCK_LED_ADDRESS, 0xFF);
|
|
||||||
is31_write_register(1, CAPS_LOCK_LED_ADDRESS, 0xFF);
|
|
||||||
is31_write_register(2, CAPS_LOCK_LED_ADDRESS, 0xFF);
|
|
||||||
break;
|
|
||||||
case LED_MSG_CAPS_OFF:
|
|
||||||
// turn caps off on pages 1 and 2
|
|
||||||
is31_write_register(0, CAPS_LOCK_LED_ADDRESS, 0);
|
|
||||||
is31_write_register(1, CAPS_LOCK_LED_ADDRESS, 0);
|
|
||||||
is31_write_register(2, CAPS_LOCK_LED_ADDRESS, 0);
|
|
||||||
break;
|
|
||||||
case LED_MSG_SLEEP_LED_ON:
|
case LED_MSG_SLEEP_LED_ON:
|
||||||
// save current settings
|
// save current settings
|
||||||
is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &save_page);
|
is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &save_page);
|
||||||
|
@ -211,37 +221,33 @@ static THD_FUNCTION(LEDthread, arg) {
|
||||||
is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, save_page);
|
is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, save_page);
|
||||||
break;
|
break;
|
||||||
case LED_MSG_SLEEP_LED_OFF:
|
case LED_MSG_SLEEP_LED_OFF:
|
||||||
// should not get here; wakeup should be received in the branch above
|
// should not get here; wakeup should be received in the branch above break;
|
||||||
break;
|
break;
|
||||||
case LED_MSG_ALL_TOGGLE:
|
default:
|
||||||
// read current page into 'temp'
|
if(msg >= 0x24) {
|
||||||
is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &temp);
|
xprintf("Power pre-read\ntemp: %X - msg: %X - pwm: %X\n", temp, msg, pwm);
|
||||||
chThdSleepMilliseconds(1);
|
is31_read_register(0, msg, &temp);
|
||||||
// switch to 'the other' page
|
chThdSleepMilliseconds(10);
|
||||||
if(temp==2) {
|
xprintf("Post-read\ntemp: %X - msg: %X - pwm: %X\n", temp, msg, pwm);
|
||||||
is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 0);
|
chThdSleepMilliseconds(10);
|
||||||
} else {
|
pwm = (temp > 0x00 ? 0x00 : 0xFF);
|
||||||
is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 2);
|
xprintf("pwm after: %X\n", pwm);
|
||||||
|
chThdSleepMilliseconds(10);
|
||||||
|
for(i=0; i<8; i++) {
|
||||||
|
is31_write_register(i, msg, pwm);
|
||||||
}
|
}
|
||||||
break;
|
xprintf("Power post-change\ntemp: %X - msg: %X - pwm: %X\n", temp, msg, pwm);
|
||||||
case LED_MSG_GAME_TOGGLE:
|
chThdSleepMilliseconds(10);
|
||||||
// read current page into 'temp'
|
|
||||||
is31_read_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, &temp);
|
|
||||||
chThdSleepMilliseconds(1);
|
|
||||||
// switch to 'the other' page
|
|
||||||
if(temp==1) {
|
|
||||||
is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 0);
|
|
||||||
} else {
|
|
||||||
is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
xprintf("--------------------\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* =============
|
/* =====================
|
||||||
* hook into TMK
|
* hook into user keymap
|
||||||
* ============= */
|
* ===================== */
|
||||||
void led_controller_init(void) {
|
void led_controller_init(void) {
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue