Implement ledmap and fix bugs
This commit is contained in:
parent
c402923529
commit
0c5e2e8f22
@ -8,6 +8,7 @@
|
|||||||
#include "action_layer.h"
|
#include "action_layer.h"
|
||||||
#include "eeconfig.h"
|
#include "eeconfig.h"
|
||||||
#include "keymap_in_eeprom.h"
|
#include "keymap_in_eeprom.h"
|
||||||
|
#include "ledmap_in_eeprom.h"
|
||||||
#include "bootmagic.h"
|
#include "bootmagic.h"
|
||||||
|
|
||||||
|
|
||||||
@ -35,6 +36,9 @@ void bootmagic(void)
|
|||||||
eeconfig_init();
|
eeconfig_init();
|
||||||
#ifdef KEYMAP_IN_EEPROM_ENABLE
|
#ifdef KEYMAP_IN_EEPROM_ENABLE
|
||||||
write_keymap_to_eeprom();
|
write_keymap_to_eeprom();
|
||||||
|
#endif
|
||||||
|
#ifdef LEDMAP_IN_EEPROM_ENABLE
|
||||||
|
write_ledmap_to_eeprom();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#else
|
#else
|
||||||
#include "breathing_led.h"
|
#include "breathing_led.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include "ledmap.h"
|
||||||
|
#include "ledmap_in_eeprom.h"
|
||||||
#include "keymap_in_eeprom.h"
|
#include "keymap_in_eeprom.h"
|
||||||
#ifdef MOUSEKEY_ENABLE
|
#ifdef MOUSEKEY_ENABLE
|
||||||
# include "mousekey.h"
|
# include "mousekey.h"
|
||||||
@ -82,6 +84,13 @@ void keyboard_init(void)
|
|||||||
bootmagic();
|
bootmagic();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef LEDMAP_ENABLE
|
||||||
|
ledmap_led_init();
|
||||||
|
#ifdef LEDMAP_IN_EEPROM_ENABLE
|
||||||
|
ledmap_in_eeprom_init();
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef BACKLIGHT_ENABLE
|
#ifdef BACKLIGHT_ENABLE
|
||||||
backlight_init();
|
backlight_init();
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "softpwm_led.h"
|
#include "softpwm_led.h"
|
||||||
#include "action_layer.h"
|
#include "action_layer.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
static led_state_t led_state = 0;
|
static led_state_t led_state = 0;
|
||||||
static led_state_t led_state_last = 0;
|
static led_state_t led_state_last = 0;
|
||||||
@ -13,25 +14,32 @@ void led_set(uint8_t usb_led)
|
|||||||
{
|
{
|
||||||
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
||||||
uint8_t code = ledmap_get_code(i);
|
uint8_t code = ledmap_get_code(i);
|
||||||
|
/*
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case LEDMAP_NUM_LOCK:
|
case LEDMAP_NUM_LOCK:
|
||||||
usb_led & (1 << USB_LED_NUM_LOCK) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
|
(usb_led & (1 << USB_LED_NUM_LOCK)) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
|
||||||
break;
|
break;
|
||||||
case LEDMAP_CAPS_LOCK:
|
case LEDMAP_CAPS_LOCK:
|
||||||
usb_led & (1 << USB_LED_CAPS_LOCK) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
|
(usb_led & (1 << USB_LED_CAPS_LOCK)) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
|
||||||
break;
|
break;
|
||||||
case LEDMAP_SCROLL_LOCK:
|
case LEDMAP_SCROLL_LOCK:
|
||||||
usb_led & (1 << USB_LED_SCROLL_LOCK) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
|
(usb_led & (1 << USB_LED_SCROLL_LOCK)) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
|
||||||
break;
|
break;
|
||||||
case LEDMAP_COMPOSE:
|
case LEDMAP_COMPOSE:
|
||||||
usb_led & (1 << USB_LED_COMPOSE) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
|
(usb_led & (1 << USB_LED_COMPOSE)) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
|
||||||
break;
|
break;
|
||||||
case LEDMAP_KANA:
|
case LEDMAP_KANA:
|
||||||
usb_led & (1 << USB_LED_KANA) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
|
(usb_led & (1 << USB_LED_KANA)) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
update_led_state();
|
update_led_state();
|
||||||
}
|
}
|
||||||
@ -42,7 +50,7 @@ void default_layer_state_change(uint32_t state)
|
|||||||
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
||||||
uint8_t code = ledmap_get_code(i);
|
uint8_t code = ledmap_get_code(i);
|
||||||
if (code >= LEDMAP_DEFAULT_LAYER_0 && code < LEDMAP_DEFAULT_LAYER_31) {
|
if (code >= LEDMAP_DEFAULT_LAYER_0 && code < LEDMAP_DEFAULT_LAYER_31) {
|
||||||
state & (1UL << (code - LEDMAP_DEFAULT_LAYER_0)) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
|
(state & (1UL << (code - LEDMAP_DEFAULT_LAYER_0))) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update_led_state();
|
update_led_state();
|
||||||
@ -53,7 +61,7 @@ void layer_state_change(uint32_t state)
|
|||||||
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
||||||
uint8_t code = ledmap_get_code(i);
|
uint8_t code = ledmap_get_code(i);
|
||||||
if (code >= LEDMAP_LAYER_0 && code < LEDMAP_LAYER_31) {
|
if (code >= LEDMAP_LAYER_0 && code < LEDMAP_LAYER_31) {
|
||||||
state & (1UL << (code - LEDMAP_LAYER_0)) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
|
(state & (1UL << (code - LEDMAP_LAYER_0))) ? LED_BIT_ON(led_state, i) : LED_BIT_OFF(led_state, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update_led_state();
|
update_led_state();
|
||||||
|
@ -40,10 +40,8 @@ typedef enum {
|
|||||||
LEDMAP_UNCONFIGURED = 0xFF
|
LEDMAP_UNCONFIGURED = 0xFF
|
||||||
} ledmap_code_t;
|
} ledmap_code_t;
|
||||||
|
|
||||||
#define LEDMAP_LAYER(x) (x)
|
#define LEDMAP_DEFAULT_LAYER(x) (LEDMAP_DEFAULT_LAYER_0 + x)
|
||||||
#define LEDMAP_DEFAULT_LAYER(x) (32 + x)
|
#define LEDMAP_LAYER(x) (LEDMAP_LAYER_0 + x)
|
||||||
|
|
||||||
void ledmap_init(void);
|
|
||||||
|
|
||||||
#ifdef LEDMAP_ENABLE
|
#ifdef LEDMAP_ENABLE
|
||||||
uint8_t ledmap_get_code(uint8_t index);
|
uint8_t ledmap_get_code(uint8_t index);
|
||||||
|
@ -9,17 +9,25 @@
|
|||||||
|
|
||||||
static uint8_t ledmap[LED_COUNT];
|
static uint8_t ledmap[LED_COUNT];
|
||||||
|
|
||||||
void ledmap_in_eeprom_init(void) {
|
void ledmap_in_eeprom_init(void)
|
||||||
// read and check ledmap in eeprom
|
{
|
||||||
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
||||||
ledmap[i] = eeprom_read_byte(EECONFIG_LEDMAP + i);
|
ledmap[i] = eeprom_read_byte(EECONFIG_LEDMAP + i);
|
||||||
|
ledmap[i] = LEDMAP_UNCONFIGURED;
|
||||||
if (ledmap[i] == LEDMAP_UNCONFIGURED) {
|
if (ledmap[i] == LEDMAP_UNCONFIGURED) {
|
||||||
ledmap[i] = lemap_get_code(i);
|
ledmap[i] = ledmap_get_code(i);
|
||||||
eeprom_write_byte(EECONFIG_LEDMAP + i, ledmap[i]);
|
eeprom_write_byte(EECONFIG_LEDMAP + i, ledmap[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void write_ledmap_to_eeprom(void)
|
||||||
|
{
|
||||||
|
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
||||||
|
eeprom_write_byte(EECONFIG_LEDMAP + i, ledmap_get_code(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t ledmap_in_eeprom_get_code(uint8_t i)
|
uint8_t ledmap_in_eeprom_get_code(uint8_t i)
|
||||||
{
|
{
|
||||||
return ledmap[i];
|
return ledmap[i];
|
||||||
|
@ -11,9 +11,11 @@
|
|||||||
#ifdef LEDMAP_IN_EEPROM_ENABLE
|
#ifdef LEDMAP_IN_EEPROM_ENABLE
|
||||||
#define ledmap_get_code ledmap_in_eeprom_get_code
|
#define ledmap_get_code ledmap_in_eeprom_get_code
|
||||||
void ledmap_in_eeprom_init(void);
|
void ledmap_in_eeprom_init(void);
|
||||||
|
void write_ledmap_to_eeprom(void);
|
||||||
uint8_t ledmap_in_eeprom_get_code(uint8_t index);
|
uint8_t ledmap_in_eeprom_get_code(uint8_t index);
|
||||||
#else
|
#else
|
||||||
#define ledmap_in_eeprom_init()
|
#define ledmap_in_eeprom_init()
|
||||||
|
#define write_ledmap_to_eeprom()
|
||||||
#define ledmap_in_eeprom_get_code()
|
#define ledmap_in_eeprom_get_code()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user