1
0

Implement ledmap and fix bugs

This commit is contained in:
Kai Ryu 2014-07-24 15:03:58 +09:00
parent c402923529
commit 0c5e2e8f22
6 changed files with 43 additions and 14 deletions

View File

@ -8,6 +8,7 @@
#include "action_layer.h"
#include "eeconfig.h"
#include "keymap_in_eeprom.h"
#include "ledmap_in_eeprom.h"
#include "bootmagic.h"
@ -35,6 +36,9 @@ void bootmagic(void)
eeconfig_init();
#ifdef KEYMAP_IN_EEPROM_ENABLE
write_keymap_to_eeprom();
#endif
#ifdef LEDMAP_IN_EEPROM_ENABLE
write_ledmap_to_eeprom();
#endif
}

View File

@ -36,6 +36,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#else
#include "breathing_led.h"
#endif
#include "ledmap.h"
#include "ledmap_in_eeprom.h"
#include "keymap_in_eeprom.h"
#ifdef MOUSEKEY_ENABLE
# include "mousekey.h"
@ -82,6 +84,13 @@ void keyboard_init(void)
bootmagic();
#endif
#ifdef LEDMAP_ENABLE
ledmap_led_init();
#ifdef LEDMAP_IN_EEPROM_ENABLE
ledmap_in_eeprom_init();
#endif
#endif
#ifdef BACKLIGHT_ENABLE
backlight_init();
#endif

View File

@ -3,6 +3,7 @@
#include "led.h"
#include "softpwm_led.h"
#include "action_layer.h"
#include "debug.h"
static led_state_t led_state = 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++) {
uint8_t code = ledmap_get_code(i);
/*
switch (code) {
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;
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;
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;
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;
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;
default:
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();
}
@ -42,7 +50,7 @@ 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) {
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();
@ -53,7 +61,7 @@ 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) {
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();

View File

@ -40,10 +40,8 @@ typedef enum {
LEDMAP_UNCONFIGURED = 0xFF
} ledmap_code_t;
#define LEDMAP_LAYER(x) (x)
#define LEDMAP_DEFAULT_LAYER(x) (32 + x)
void ledmap_init(void);
#define LEDMAP_DEFAULT_LAYER(x) (LEDMAP_DEFAULT_LAYER_0 + x)
#define LEDMAP_LAYER(x) (LEDMAP_LAYER_0 + x)
#ifdef LEDMAP_ENABLE
uint8_t ledmap_get_code(uint8_t index);

View File

@ -9,17 +9,25 @@
static uint8_t ledmap[LED_COUNT];
void ledmap_in_eeprom_init(void) {
// read and check ledmap in eeprom
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] = lemap_get_code(i);
ledmap[i] = ledmap_get_code(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)
{
return ledmap[i];

View File

@ -11,9 +11,11 @@
#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);
#else
#define ledmap_in_eeprom_init()
#define write_ledmap_to_eeprom()
#define ledmap_in_eeprom_get_code()
#endif