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_last = 0;
|
2014-07-25 05:24:57 +00:00
|
|
|
static led_binding_t usb_led_binding = 0;
|
|
|
|
static led_binding_t default_layer_binding = 0;
|
|
|
|
static led_binding_t layer_binding = 0;
|
|
|
|
static led_binding_t backlight_binding = 0;
|
2014-11-25 09:23:16 +00:00
|
|
|
static led_binding_t reverse_binding = 0;
|
2014-07-20 03:52:56 +00:00
|
|
|
|
2014-11-25 09:23:16 +00:00
|
|
|
static void update_led_state(led_state_t state, uint8_t force);
|
2014-07-20 03:52:56 +00:00
|
|
|
|
2014-07-25 05:24:57 +00:00
|
|
|
void ledmap_init(void)
|
2014-07-20 03:52:56 +00:00
|
|
|
{
|
|
|
|
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
2014-11-25 09:23:16 +00:00
|
|
|
ledmap_t ledmap = ledmap_get_code(i);
|
|
|
|
if (ledmap.reverse) {
|
|
|
|
LED_BIT_SET(reverse_binding, i);
|
2014-07-25 05:24:57 +00:00
|
|
|
}
|
2014-11-25 09:23:16 +00:00
|
|
|
if (ledmap.backlight) {
|
|
|
|
LED_BIT_SET(backlight_binding, i);
|
2014-07-25 05:24:57 +00:00
|
|
|
}
|
2014-11-25 09:23:16 +00:00
|
|
|
switch (ledmap.binding) {
|
|
|
|
case LEDMAP_BINDING_DEFAULT_LAYER:
|
|
|
|
LED_BIT_SET(default_layer_binding, i);
|
|
|
|
break;
|
|
|
|
case LEDMAP_BINDING_LAYER:
|
|
|
|
LED_BIT_SET(layer_binding, i);
|
|
|
|
break;
|
|
|
|
case LEDMAP_BINDING_USB_LED:
|
|
|
|
LED_BIT_SET(usb_led_binding, i);
|
|
|
|
break;
|
2014-07-20 03:52:56 +00:00
|
|
|
}
|
2014-07-25 05:24:57 +00:00
|
|
|
}
|
|
|
|
ledmap_led_init();
|
2014-11-25 09:23:16 +00:00
|
|
|
update_led_state(0, 1);
|
2014-07-25 05:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void led_set(uint8_t usb_led)
|
|
|
|
{
|
|
|
|
if (usb_led_binding) {
|
|
|
|
led_state_t led_state = led_state_last;
|
|
|
|
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
|
|
|
if (usb_led_binding & LED_BIT(i)) {
|
2014-11-25 09:23:16 +00:00
|
|
|
uint8_t param = ledmap_get_code(i).param;
|
|
|
|
(usb_led & (1 << param)) ? LED_BIT_SET(led_state, i) : LED_BIT_CLEAR(led_state, i);
|
2014-07-24 06:03:58 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-25 09:23:16 +00:00
|
|
|
update_led_state(led_state, 0);
|
2014-07-20 03:52:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NO_ACTION_LAYER
|
|
|
|
void default_layer_state_change(uint32_t state)
|
|
|
|
{
|
2014-07-25 05:24:57 +00:00
|
|
|
if (default_layer_binding) {
|
|
|
|
led_state_t led_state = led_state_last;
|
|
|
|
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
|
|
|
if (default_layer_binding & LED_BIT(i)) {
|
2014-11-25 09:23:16 +00:00
|
|
|
uint8_t param = ledmap_get_code(i).param;
|
|
|
|
(state & (1UL << param)) ? LED_BIT_SET(led_state, i) : LED_BIT_CLEAR(led_state, i);
|
2014-07-25 05:24:57 +00:00
|
|
|
}
|
2014-07-20 03:52:56 +00:00
|
|
|
}
|
2014-11-25 09:23:16 +00:00
|
|
|
update_led_state(led_state, 0);
|
2014-07-20 03:52:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void layer_state_change(uint32_t state)
|
|
|
|
{
|
2014-07-25 05:24:57 +00:00
|
|
|
if (layer_binding) {
|
|
|
|
led_state_t led_state = led_state_last;
|
|
|
|
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
|
|
|
if (layer_binding & LED_BIT(i)) {
|
2014-11-25 09:23:16 +00:00
|
|
|
uint8_t param = ledmap_get_code(i).param;
|
|
|
|
(state & (1UL << param)) ? LED_BIT_SET(led_state, i) : LED_BIT_CLEAR(led_state, i);
|
2014-07-25 05:24:57 +00:00
|
|
|
}
|
2014-07-20 03:52:56 +00:00
|
|
|
}
|
2014-11-25 09:23:16 +00:00
|
|
|
update_led_state(led_state, 0);
|
2014-07-20 03:52:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SOFTPWM_LED_ENABLE
|
2014-08-03 03:00:18 +00:00
|
|
|
void softpwm_led_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-08-02 01:15:57 +00:00
|
|
|
void softpwm_led_on(uint8_t index)
|
2014-07-20 03:52:56 +00:00
|
|
|
{
|
2014-08-02 01:15:57 +00:00
|
|
|
if (backlight_binding & LED_BIT(index)) {
|
|
|
|
ledmap_led_on(index);
|
2014-07-20 03:52:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-02 01:15:57 +00:00
|
|
|
void softpwm_led_off(uint8_t index)
|
2014-07-20 03:52:56 +00:00
|
|
|
{
|
2014-08-02 01:15:57 +00:00
|
|
|
if (backlight_binding & LED_BIT(index)) {
|
|
|
|
ledmap_led_off(index);
|
2014-07-20 03:52:56 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-25 05:24:57 +00:00
|
|
|
|
|
|
|
void softpwm_led_state_change(uint8_t state)
|
|
|
|
{
|
|
|
|
if (state) {
|
|
|
|
}
|
|
|
|
else {
|
2014-11-25 09:23:16 +00:00
|
|
|
update_led_state(led_state_last, 1);
|
2014-07-25 05:24:57 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-20 03:52:56 +00:00
|
|
|
#endif
|
|
|
|
|
2014-11-25 09:23:16 +00:00
|
|
|
void update_led_state(led_state_t state, uint8_t force)
|
2014-07-20 03:52:56 +00:00
|
|
|
{
|
2014-11-25 09:23:16 +00:00
|
|
|
led_state_t diff = led_state_last ^ state;
|
|
|
|
if (force || diff) {
|
2014-07-20 03:52:56 +00:00
|
|
|
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
2014-07-25 05:24:57 +00:00
|
|
|
if (softpwm_led_get_state() && (backlight_binding & LED_BIT(i))) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-11-25 09:23:16 +00:00
|
|
|
if (force || diff & LED_BIT(i)) {
|
|
|
|
if ((state ^ reverse_binding) & LED_BIT(i)) {
|
2014-07-20 03:52:56 +00:00
|
|
|
ledmap_led_on(i);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ledmap_led_off(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-25 05:24:57 +00:00
|
|
|
led_state_last = state;
|
2014-07-20 03:52:56 +00:00
|
|
|
}
|
|
|
|
}
|