Improve ledmap feature
- Change date type of ledmap from byte to word - New reverse bit, reversing binding stats - Fix minor bugs
This commit is contained in:
parent
15d9c0a692
commit
f6643a082c
@ -10,28 +10,34 @@ 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;
|
||||
static led_binding_t reverse_binding = 0;
|
||||
|
||||
static void update_led_state(led_state_t state);
|
||||
static void update_led_state(led_state_t state, uint8_t force);
|
||||
|
||||
void ledmap_init(void)
|
||||
{
|
||||
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
||||
uint8_t code = ledmap_get_code(i);
|
||||
if (code & LEDMAP_BACKLIGHT) {
|
||||
ledmap_t ledmap = ledmap_get_code(i);
|
||||
if (ledmap.reverse) {
|
||||
LED_BIT_SET(reverse_binding, i);
|
||||
}
|
||||
if (ledmap.backlight) {
|
||||
LED_BIT_SET(backlight_binding, i);
|
||||
}
|
||||
code &= LEDMAP_MASK;
|
||||
if (code >= LEDMAP_DEFAULT_LAYER_0 && code <= LEDMAP_DEFAULT_LAYER_31) {
|
||||
switch (ledmap.binding) {
|
||||
case LEDMAP_BINDING_DEFAULT_LAYER:
|
||||
LED_BIT_SET(default_layer_binding, i);
|
||||
}
|
||||
else if (code >= LEDMAP_LAYER_0 && code <= LEDMAP_LAYER_31) {
|
||||
break;
|
||||
case LEDMAP_BINDING_LAYER:
|
||||
LED_BIT_SET(layer_binding, i);
|
||||
}
|
||||
else if (code >= LEDMAP_NUM_LOCK && code <= LEDMAP_KANA) {
|
||||
break;
|
||||
case LEDMAP_BINDING_USB_LED:
|
||||
LED_BIT_SET(usb_led_binding, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ledmap_led_init();
|
||||
update_led_state(0, 1);
|
||||
}
|
||||
|
||||
void led_set(uint8_t usb_led)
|
||||
@ -40,15 +46,11 @@ void led_set(uint8_t usb_led)
|
||||
led_state_t led_state = led_state_last;
|
||||
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
||||
if (usb_led_binding & LED_BIT(i)) {
|
||||
uint8_t code = ledmap_get_code(i) & LEDMAP_MASK;
|
||||
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_SET(led_state, i) : LED_BIT_CLEAR(led_state, i);
|
||||
uint8_t param = ledmap_get_code(i).param;
|
||||
(usb_led & (1 << param)) ? LED_BIT_SET(led_state, i) : LED_BIT_CLEAR(led_state, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
update_led_state(led_state);
|
||||
update_led_state(led_state, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,11 +61,11 @@ void default_layer_state_change(uint32_t state)
|
||||
led_state_t led_state = led_state_last;
|
||||
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
||||
if (default_layer_binding & LED_BIT(i)) {
|
||||
uint8_t code = ledmap_get_code(i) & LEDMAP_MASK;
|
||||
(state & (1UL << (code - LEDMAP_DEFAULT_LAYER_0))) ? LED_BIT_SET(led_state, i) : LED_BIT_CLEAR(led_state, i);
|
||||
uint8_t param = ledmap_get_code(i).param;
|
||||
(state & (1UL << param)) ? LED_BIT_SET(led_state, i) : LED_BIT_CLEAR(led_state, i);
|
||||
}
|
||||
}
|
||||
update_led_state(led_state);
|
||||
update_led_state(led_state, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,11 +75,11 @@ void layer_state_change(uint32_t state)
|
||||
led_state_t led_state = led_state_last;
|
||||
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
||||
if (layer_binding & LED_BIT(i)) {
|
||||
uint8_t code = ledmap_get_code(i) & LEDMAP_MASK;
|
||||
(state & (1UL << (code - LEDMAP_LAYER_0))) ? LED_BIT_SET(led_state, i) : LED_BIT_CLEAR(led_state, i);
|
||||
uint8_t param = ledmap_get_code(i).param;
|
||||
(state & (1UL << param)) ? LED_BIT_SET(led_state, i) : LED_BIT_CLEAR(led_state, i);
|
||||
}
|
||||
}
|
||||
update_led_state(led_state);
|
||||
update_led_state(led_state, 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -106,23 +108,21 @@ void softpwm_led_state_change(uint8_t state)
|
||||
if (state) {
|
||||
}
|
||||
else {
|
||||
led_state_t led_state = led_state_last;
|
||||
led_state_last &= ~(backlight_binding);
|
||||
update_led_state(led_state);
|
||||
update_led_state(led_state_last, 1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void update_led_state(led_state_t state)
|
||||
void update_led_state(led_state_t state, uint8_t force)
|
||||
{
|
||||
uint8_t diff = led_state_last ^ state;
|
||||
if (diff) {
|
||||
led_state_t diff = led_state_last ^ state;
|
||||
if (force || diff) {
|
||||
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
||||
if (softpwm_led_get_state() && (backlight_binding & LED_BIT(i))) {
|
||||
continue;
|
||||
}
|
||||
if (diff & LED_BIT(i)) {
|
||||
if (state & LED_BIT(i)) {
|
||||
if (force || diff & LED_BIT(i)) {
|
||||
if ((state ^ reverse_binding) & LED_BIT(i)) {
|
||||
ledmap_led_on(i);
|
||||
}
|
||||
else {
|
||||
|
@ -8,43 +8,49 @@
|
||||
typedef led_pack_t led_state_t;
|
||||
typedef led_pack_t led_binding_t;
|
||||
|
||||
typedef enum {
|
||||
LEDMAP_NO = 0,
|
||||
LEDMAP_DEFAULT_LAYER_0,
|
||||
LEDMAP_DEFAULT_LAYER_31 = LEDMAP_DEFAULT_LAYER_0 + 31,
|
||||
LEDMAP_LAYER_0,
|
||||
LEDMAP_LAYER_31 = LEDMAP_LAYER_0 + 31,
|
||||
LEDMAP_NUM_LOCK,
|
||||
LEDMAP_CAPS_LOCK,
|
||||
LEDMAP_SCROLL_LOCK,
|
||||
LEDMAP_COMPOSE,
|
||||
LEDMAP_KANA,
|
||||
LEDMAP_BACKLIGHT = 0x80
|
||||
} ledmap_code_t;
|
||||
enum ledmap_binding {
|
||||
LEDMAP_BINDING_NO = 0,
|
||||
LEDMAP_BINDING_DEFAULT_LAYER,
|
||||
LEDMAP_BINDING_LAYER,
|
||||
LEDMAP_BINDING_USB_LED
|
||||
};
|
||||
|
||||
#define LEDMAP_MASK 0x7F
|
||||
enum ledmap_usb_led {
|
||||
LEDMAP_USB_LED_NUM_LOCK = 0,
|
||||
LEDMAP_USB_LED_CAPS_LOCK,
|
||||
LEDMAP_USB_LED_SCROLL_LOCK,
|
||||
LEDMAP_USB_LED_COMPOSE,
|
||||
LEDMAP_USB_LED_KANA,
|
||||
};
|
||||
|
||||
typedef union {
|
||||
uint8_t raw;
|
||||
uint16_t code;
|
||||
struct {
|
||||
uint8_t binding : 7;
|
||||
uint8_t param: 8;
|
||||
uint8_t binding: 4;
|
||||
bool reverse: 1;
|
||||
bool backlight: 1;
|
||||
uint8_t reserved: 2;
|
||||
};
|
||||
} ledmap_t;
|
||||
|
||||
#define LEDMAP_DEFAULT_LAYER(x) (LEDMAP_DEFAULT_LAYER_0 + x)
|
||||
#define LEDMAP_LAYER(x) (LEDMAP_LAYER_0 + x)
|
||||
#define LEDMAP_DEFAULT_LAYER(layer) (LEDMAP_BINDING_DEFAULT_LAYER<<8 | layer)
|
||||
#define LEDMAP_LAYER(layer) (LEDMAP_BINDING_LAYER<<8 | layer )
|
||||
#define LEDMAP_NUM_LOCK (LEDMAP_BINDING_USB_LED<<8 | LEDMAP_USB_LED_NUM_LOCK)
|
||||
#define LEDMAP_CAPS_LOCK (LEDMAP_BINDING_USB_LED<<8 | LEDMAP_USB_LED_CAPS_LOCK)
|
||||
#define LEDMAP_SCROLL_LOCK (LEDMAP_BINDING_USB_LED<<8 | LEDMAP_USB_LED_SCROLL_LOCK)
|
||||
#define LEDMAP_REVERSE (1<<12)
|
||||
#define LEDMAP_BACKLIGHT (1<<13)
|
||||
|
||||
void ledmap_init(void);
|
||||
|
||||
#ifdef LEDMAP_ENABLE
|
||||
uint8_t ledmap_get_code(uint8_t index);
|
||||
ledmap_t ledmap_get_code(uint8_t index);
|
||||
void ledmap_led_init(void);
|
||||
void ledmap_led_on(uint8_t index);
|
||||
void ledmap_led_off(uint8_t index);
|
||||
#else
|
||||
#define ledmaps
|
||||
#define ledmap_get()
|
||||
#define ledmap_get_code()
|
||||
#define ledmap_led_init()
|
||||
#define ledmap_led_on()
|
||||
#define ledmap_led_off()
|
||||
|
@ -1,22 +1,21 @@
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/eeprom.h>
|
||||
#include "ledmap.h"
|
||||
#include "ledmap_in_eeprom.h"
|
||||
|
||||
#ifdef LEDMAP_IN_EEPROM_ENABLE
|
||||
|
||||
#undef ledmap_get_code
|
||||
|
||||
static uint8_t ledmap[LED_COUNT];
|
||||
static ledmap_t ledmap[LED_COUNT];
|
||||
|
||||
void ledmap_in_eeprom_init(void)
|
||||
{
|
||||
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
||||
ledmap[i] = eeprom_read_byte(EECONFIG_LEDMAP + i);
|
||||
//ledmap[i] = LEDMAP_UNCONFIGURED;
|
||||
if (ledmap[i] == LEDMAP_UNCONFIGURED) {
|
||||
ledmap[i].code = eeprom_read_word(EECONFIG_LEDMAP + i);
|
||||
/* ledmap[i].code = LEDMAP_UNCONFIGURED; */
|
||||
if (ledmap[i].code == LEDMAP_UNCONFIGURED) {
|
||||
ledmap[i] = ledmap_get_code(i);
|
||||
eeprom_write_byte(EECONFIG_LEDMAP + i, ledmap[i]);
|
||||
eeprom_write_word(EECONFIG_LEDMAP + i, ledmap[i].code);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -24,11 +23,11 @@ void ledmap_in_eeprom_init(void)
|
||||
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));
|
||||
eeprom_write_word(EECONFIG_LEDMAP + i, ledmap_get_code(i).code);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ledmap_in_eeprom_get_code(uint8_t i)
|
||||
ledmap_t ledmap_in_eeprom_get_code(uint8_t i)
|
||||
{
|
||||
return ledmap[i];
|
||||
}
|
||||
|
@ -1,20 +1,22 @@
|
||||
#ifndef LEDMAP_IN_EEPROM_H
|
||||
#define LEDMAP_IN_EEPROM_H
|
||||
|
||||
#include "ledmap.h"
|
||||
|
||||
#ifndef EECONFIG_LEDMAP_IN_EEPROM
|
||||
#define EECONFIG_LEDMAP_IN_EEPROM 7
|
||||
#endif
|
||||
|
||||
#define EECONFIG_LEDMAP (uint8_t*)EECONFIG_LEDMAP_IN_EEPROM
|
||||
#define LEDMAP_SIZE (sizeof(uint8_t) * LED_COUNT)
|
||||
#define EECONFIG_LEDMAP (uint16_t*)EECONFIG_LEDMAP_IN_EEPROM
|
||||
#define LEDMAP_SIZE (sizeof(uint16_t) * LED_COUNT)
|
||||
|
||||
#define LEDMAP_UNCONFIGURED 0xFF
|
||||
#define LEDMAP_UNCONFIGURED 0xFFFF
|
||||
|
||||
#ifdef LEDMAP_IN_EEPROM_ENABLE
|
||||
#define ledmap_get_code ledmap_in_eeprom_get_code
|
||||
void ledmap_in_eeprom_init(void);
|
||||
void write_ledmap_to_eeprom(void);
|
||||
uint8_t ledmap_in_eeprom_get_code(uint8_t index);
|
||||
ledmap_t ledmap_in_eeprom_get_code(uint8_t index);
|
||||
#else
|
||||
#define ledmap_in_eeprom_init()
|
||||
#define write_ledmap_to_eeprom()
|
||||
|
@ -50,9 +50,9 @@ TARGET_DIR = .
|
||||
# project specific files
|
||||
SRC = keymap_common.c \
|
||||
matrix.c \
|
||||
led.c \
|
||||
backlight.c \
|
||||
ledmap.c \
|
||||
led_matrix.c
|
||||
ledmap.c
|
||||
|
||||
ifdef KEYMAP
|
||||
SRC := keymap_$(KEYMAP).c $(SRC)
|
||||
|
@ -51,7 +51,8 @@ TARGET_DIR = .
|
||||
SRC = keymap_common.c \
|
||||
matrix.c \
|
||||
led.c \
|
||||
backlight.c
|
||||
backlight.c \
|
||||
ledmap.c
|
||||
|
||||
ifdef KEYMAP
|
||||
SRC := keymap_$(KEYMAP).c $(SRC)
|
||||
@ -102,10 +103,17 @@ CONSOLE_ENABLE = yes # Console for debug(+400)
|
||||
COMMAND_ENABLE = yes # Commands for debug and configuration
|
||||
#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
|
||||
NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA
|
||||
USB_6KRO_ENABLE = yes # USB 6key Rollover
|
||||
#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
|
||||
#PS2_USE_BUSYWAIT = yes
|
||||
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
|
||||
KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor
|
||||
KEYMAP_IN_EEPROM_ENABLE = yes # Read keymap from eeprom
|
||||
#KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor
|
||||
SOFTPWM_LED_ENABLE = yes # Enable SoftPWM to drive backlight
|
||||
FADING_LED_ENABLE = yes # Enable fading backlight
|
||||
BREATHING_LED_ENABLE = yes # Enable breathing backlight
|
||||
LEDMAP_ENABLE = yes # Enable LED mapping
|
||||
LEDMAP_IN_EEPROM_ENABLE = yes # Read LED mapping from eeprom
|
||||
|
||||
|
||||
# Search Path
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#ifdef LEDMAP_ENABLE
|
||||
|
||||
static const uint8_t ledmaps[LED_COUNT] PROGMEM = {
|
||||
static const uint16_t ledmaps[LED_COUNT] PROGMEM = {
|
||||
#if defined(GH60_REV_CHN)
|
||||
[0] = LEDMAP_CAPS_LOCK | LEDMAP_BACKLIGHT, // CapsLock - PB2
|
||||
[1] = LEDMAP_BACKLIGHT, // PWM - PB6
|
||||
@ -18,9 +18,9 @@ static const uint8_t ledmaps[LED_COUNT] PROGMEM = {
|
||||
#endif
|
||||
};
|
||||
|
||||
uint8_t ledmap_get_code(uint8_t index)
|
||||
ledmap_t ledmap_get_code(uint8_t index)
|
||||
{
|
||||
return pgm_read_byte(&ledmaps[index]);
|
||||
return (ledmap_t) { .code = pgm_read_word(&ledmaps[index]) };
|
||||
}
|
||||
|
||||
void ledmap_led_init(void)
|
||||
|
Reference in New Issue
Block a user