Browse Source

kimera: Some minor fixes for RGB LED

master
Kai Ryu 7 years ago
parent
commit
c9b71e25fb

+ 1
- 0
keyboard/kimera/Makefile View File

ifdef DEFS ifdef DEFS
OPT_DEFS += $(foreach DEF,$(DEFS),-D$(DEF)) OPT_DEFS += $(foreach DEF,$(DEFS),-D$(DEF))
endif endif
OPT_DEFS += -DRGB_LED_ENABLE


# Build Options # Build Options
# comment out to disable the options. # comment out to disable the options.

+ 0
- 1
keyboard/kimera/config.h View File

/* enable customized backlight logic */ /* enable customized backlight logic */
#define BACKLIGHT_CUSTOM #define BACKLIGHT_CUSTOM
#define CUSTOM_LED_ENABLE #define CUSTOM_LED_ENABLE
#define RGB_LED_ENABLE


/* number of leds */ /* number of leds */
#define LED_COUNT 4 #define LED_COUNT 4

+ 2
- 0
keyboard/kimera/keymap_default.c View File



void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
{ {
#ifdef RGB_LED_ENABLE
if (record->event.pressed) { if (record->event.pressed) {
switch (id) { switch (id) {
case AF_RGB_TOGGLE: case AF_RGB_TOGGLE:
break; break;
} }
} }
#endif
} }
#endif #endif

+ 31
- 0
keyboard/kimera/keymap_two_headed.c View File

return sizeof(fn_actions) / sizeof(fn_actions[0]); return sizeof(fn_actions) / sizeof(fn_actions[0]);
} }
#endif #endif

#ifndef NO_ACTION_FUNCTION
enum function_id {
AF_RGB_TOGGLE = 0,
AF_RGB_DECREASE,
AF_RGB_INCREASE,
AF_RGB_STEP
};

void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
{
#ifdef RGB_LED_ENABLE
if (record->event.pressed) {
switch (id) {
case AF_RGB_TOGGLE:
rgb_toggle();
break;
case AF_RGB_DECREASE:
rgb_decrease();
break;
case AF_RGB_INCREASE:
rgb_increase();
break;
case AF_RGB_STEP:
rgb_step();
break;
}
}
#endif
}
#endif

+ 2
- 0
keyboard/kimera/matrix.c View File

kimera_init(); kimera_init();
kimera_scan_timestamp = timer_read(); kimera_scan_timestamp = timer_read();


rgb_init();

// initialize row and col // initialize row and col
kimera_unselect_rows(); kimera_unselect_rows();



+ 18
- 5
keyboard/kimera/rgb.c View File

static void rgb_read_config(void); static void rgb_read_config(void);
static void rgb_set_level(uint8_t level); static void rgb_set_level(uint8_t level);
static void rgb_refresh(void); static void rgb_refresh(void);
#if 0
static void hue_to_rgb(uint16_t hue, struct cRGB *rgb); static void hue_to_rgb(uint16_t hue, struct cRGB *rgb);
#endif
static void hsb_to_rgb(uint16_t hue, uint8_t saturation, uint8_t brightness, struct cRGB *rgb); static void hsb_to_rgb(uint16_t hue, uint8_t saturation, uint8_t brightness, struct cRGB *rgb);


void rgb_init(void) void rgb_init(void)


void rgb_write_config(void) void rgb_write_config(void)
{ {
eeprom_write_byte(EECONFIG_RGB, rgb_config.raw);
eeprom_update_byte(EECONFIG_RGB, rgb_config.raw);
} }


void rgb_toggle(void) void rgb_toggle(void)
rgb_config.level = 0; rgb_config.level = 0;
} }
rgb_config.enable = (rgb_config.level != 0); rgb_config.enable = (rgb_config.level != 0);
rgb_write_config();
rgb_set_level(rgb_config.level); rgb_set_level(rgb_config.level);
} }


void rgb_set_level(uint8_t level) void rgb_set_level(uint8_t level)
{ {
dprintf("RGB Level: %d\n", level); dprintf("RGB Level: %d\n", level);
if (level == RGB_OFF) {
rgb_brightness = 0;
}
else if (backlight_config.enable) {
if (backlight_config.level >= 1 && backlight_config.level <= 3) {
rgb_brightness = backlight_brightness;
}
}
else {
rgb_brightness = 16;
}
if (level <= RGB_WHITE) { if (level <= RGB_WHITE) {
rgb_fading_enable = 0; rgb_fading_enable = 0;
rgb_rainbow = 0; rgb_rainbow = 0;
if (level == RGB_OFF) {
rgb_brightness = 0;
}
else {
if (level != RGB_OFF) {
if (level == RGB_WHITE) { if (level == RGB_WHITE) {
rgb_saturation = 0; rgb_saturation = 0;
} }
ws2812_setleds(rgb_color, RGB_LED_COUNT); ws2812_setleds(rgb_color, RGB_LED_COUNT);
} }


#if 0
void hue_to_rgb(uint16_t hue, struct cRGB *rgb) void hue_to_rgb(uint16_t hue, struct cRGB *rgb)
{ {
uint8_t hi = hue / 60; uint8_t hi = hue / 60;
case 5: rgb->r = 255; rgb->g = 0; rgb->b = q; break; case 5: rgb->r = 255; rgb->g = 0; rgb->b = q; break;
} }
} }
#endif


/* /*
* original code: https://blog.adafruit.com/2012/03/14/constant-brightness-hsb-to-rgb-algorithm/ * original code: https://blog.adafruit.com/2012/03/14/constant-brightness-hsb-to-rgb-algorithm/