Browse Source

Implement ledmap and fix bugs

core
Kai Ryu 10 years ago
parent
commit
0c5e2e8f22
6 changed files with 43 additions and 14 deletions
  1. 4
    0
      common/bootmagic.c
  2. 9
    0
      common/keyboard.c
  3. 15
    7
      common/ledmap.c
  4. 2
    4
      common/ledmap.h
  5. 11
    3
      common/ledmap_in_eeprom.c
  6. 2
    0
      common/ledmap_in_eeprom.h

+ 4
- 0
common/bootmagic.c View File

#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"




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



+ 9
- 0
common/keyboard.c View File

#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"
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

+ 15
- 7
common/ledmap.c View File

#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;
{ {
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();
} }
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();
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();

+ 2
- 4
common/ledmap.h View File

LEDMAP_UNCONFIGURED = 0xFF LEDMAP_UNCONFIGURED = 0xFF
} ledmap_code_t; } 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 #ifdef LEDMAP_ENABLE
uint8_t ledmap_get_code(uint8_t index); uint8_t ledmap_get_code(uint8_t index);

+ 11
- 3
common/ledmap_in_eeprom.c View File



static uint8_t ledmap[LED_COUNT]; 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++) { 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];

+ 2
- 0
common/ledmap_in_eeprom.h View File

#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