1
0
This repo is archived. You can view files and clone it, but cannot push or open issues or pull requests.
tmk_keyboard_custom/common/ledmap.c

110 lines
3.1 KiB
C
Raw Normal View History

2014-07-19 02:27:00 +00:00
#include "ledmap.h"
2014-07-23 01:02:14 +00:00
#include "ledmap_in_eeprom.h"
2014-07-20 03:52:56 +00:00
#include "led.h"
#include "softpwm_led.h"
#include "action_layer.h"
2014-07-24 06:03:58 +00:00
#include "debug.h"
2014-07-20 03:52:56 +00:00
static led_state_t led_state = 0;
static led_state_t led_state_last = 0;
static void update_led_state(void);
void led_set(uint8_t usb_led)
{
for (uint8_t i = 0; i < LED_COUNT; i++) {
uint8_t code = ledmap_get_code(i);
2014-07-24 06:03:58 +00:00
/*
2014-07-20 03:52:56 +00:00
switch (code) {
case LEDMAP_NUM_LOCK:
2014-07-24 06:03:58 +00:00
(usb_led & (1 << USB_LED_NUM_LOCK)) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
2014-07-20 03:52:56 +00:00
break;
case LEDMAP_CAPS_LOCK:
2014-07-24 06:03:58 +00:00
(usb_led & (1 << USB_LED_CAPS_LOCK)) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
2014-07-20 03:52:56 +00:00
break;
case LEDMAP_SCROLL_LOCK:
2014-07-24 06:03:58 +00:00
(usb_led & (1 << USB_LED_SCROLL_LOCK)) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
2014-07-20 03:52:56 +00:00
break;
case LEDMAP_COMPOSE:
2014-07-24 06:03:58 +00:00
(usb_led & (1 << USB_LED_COMPOSE)) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
2014-07-20 03:52:56 +00:00
break;
case LEDMAP_KANA:
2014-07-24 06:03:58 +00:00
(usb_led & (1 << USB_LED_KANA)) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
2014-07-20 03:52:56 +00:00
break;
default:
break;
}
2014-07-24 06:03:58 +00:00
*/
for (uint8_t j = USB_LED_NUM_LOCK; j <= USB_LED_KANA; j++) {
if (code - LEDMAP_NUM_LOCK == j) {
(usb_led & (1 << j)) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
}
}
2014-07-20 03:52:56 +00:00
}
update_led_state();
}
#ifndef NO_ACTION_LAYER
void default_layer_state_change(uint32_t state)
{
for (uint8_t i = 0; i < LED_COUNT; i++) {
uint8_t code = ledmap_get_code(i);
if (code >= LEDMAP_DEFAULT_LAYER_0 && code < LEDMAP_DEFAULT_LAYER_31) {
2014-07-24 06:03:58 +00:00
(state & (1UL << (code - LEDMAP_DEFAULT_LAYER_0))) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
2014-07-20 03:52:56 +00:00
}
}
update_led_state();
}
void layer_state_change(uint32_t state)
{
for (uint8_t i = 0; i < LED_COUNT; i++) {
uint8_t code = ledmap_get_code(i);
if (code >= LEDMAP_LAYER_0 && code < LEDMAP_LAYER_31) {
2014-07-24 06:03:58 +00:00
(state & (1UL << (code - LEDMAP_LAYER_0))) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
2014-07-20 03:52:56 +00:00
}
}
update_led_state();
}
#endif
#ifdef SOFTPWM_LED_ENABLE
void softpwm_led_on()
{
for (uint8_t i = 0; i < LED_COUNT; i++) {
uint8_t code = ledmap_get_code(i);
if (code == LEDMAP_BACKLIGHT) {
ledmap_led_on(i);
}
}
}
void softpwm_led_off()
{
for (uint8_t i = 0; i < LED_COUNT; i++) {
uint8_t code = ledmap_get_code(i);
if (code == LEDMAP_BACKLIGHT) {
ledmap_led_off(i);
}
}
}
#endif
void update_led_state(void)
{
uint8_t diff = led_state_last ^ led_state;
if (diff) {
for (uint8_t i = 0; i < LED_COUNT; i++) {
if (diff & LED_BIT(i)) {
if (led_state & LED_BIT(i)) {
ledmap_led_on(i);
}
else {
ledmap_led_off(i);
}
}
}
led_state_last = led_state;
}
}