1
0

Implement ledmap and fix bugs

This commit is contained in:
Kai Ryu 2014-07-24 15:03:58 +09:00
parent b9c65be036
commit 34886dfffb
8 changed files with 46 additions and 17 deletions

View File

@ -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
} }

View File

@ -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

View File

@ -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();

View File

@ -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);

View File

@ -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];

View File

@ -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

View File

@ -50,7 +50,6 @@ TARGET_DIR = .
# project specific files # project specific files
SRC = keymap_common.c \ SRC = keymap_common.c \
matrix.c \ matrix.c \
led.c \
backlight.c \ backlight.c \
ledmap.c \ ledmap.c \
led_matrix.c led_matrix.c
@ -139,7 +138,7 @@ USB_6KRO_ENABLE = yes # USB 6key Rollover
#PS2_USE_BUSYWAIT = yes #PS2_USE_BUSYWAIT = yes
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
KEYMAP_IN_EEPROM_ENABLE = yes # Read keymap from eeprom KEYMAP_IN_EEPROM_ENABLE = yes # Read keymap from eeprom
KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor #KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor
SOFTPWM_LED_ENABLE = yes # Enable SoftPWM to drive backlight SOFTPWM_LED_ENABLE = yes # Enable SoftPWM to drive backlight
BREATHING_LED_ENABLE = yes # Enable breathing backlight BREATHING_LED_ENABLE = yes # Enable breathing backlight
LEDMAP_ENABLE = yes # Enable LED mapping LEDMAP_ENABLE = yes # Enable LED mapping

View File

@ -1,5 +1,6 @@
#include "ledmap.h"
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#include "ledmap.h"
#include "debug.h"
#ifdef LEDMAP_ENABLE #ifdef LEDMAP_ENABLE