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

@@ -129,6 +129,7 @@ endif
ifdef DEFS
OPT_DEFS += $(foreach DEF,$(DEFS),-D$(DEF))
endif
OPT_DEFS += -DRGB_LED_ENABLE

# Build Options
# comment out to disable the options.

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

@@ -57,7 +57,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* enable customized backlight logic */
#define BACKLIGHT_CUSTOM
#define CUSTOM_LED_ENABLE
#define RGB_LED_ENABLE

/* number of leds */
#define LED_COUNT 4

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

@@ -61,6 +61,7 @@ enum function_id {

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:
@@ -77,5 +78,6 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
break;
}
}
#endif
}
#endif

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

@@ -60,3 +60,34 @@ uint16_t fn_actions_count(void) {
return sizeof(fn_actions) / sizeof(fn_actions[0]);
}
#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

@@ -77,6 +77,8 @@ void matrix_init(void)
kimera_init();
kimera_scan_timestamp = timer_read();

rgb_init();

// initialize row and col
kimera_unselect_rows();


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

@@ -40,7 +40,9 @@ static void rgb_write_config(void);
static void rgb_read_config(void);
static void rgb_set_level(uint8_t level);
static void rgb_refresh(void);
#if 0
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);

void rgb_init(void)
@@ -63,7 +65,7 @@ void rgb_read_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)
@@ -118,19 +120,28 @@ void rgb_step(void)
rgb_config.level = 0;
}
rgb_config.enable = (rgb_config.level != 0);
rgb_write_config();
rgb_set_level(rgb_config.level);
}

void rgb_set_level(uint8_t 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) {
rgb_fading_enable = 0;
rgb_rainbow = 0;
if (level == RGB_OFF) {
rgb_brightness = 0;
}
else {
if (level != RGB_OFF) {
if (level == RGB_WHITE) {
rgb_saturation = 0;
}
@@ -186,6 +197,7 @@ void rgb_refresh(void)
ws2812_setleds(rgb_color, RGB_LED_COUNT);
}

#if 0
void hue_to_rgb(uint16_t hue, struct cRGB *rgb)
{
uint8_t hi = hue / 60;
@@ -200,6 +212,7 @@ void hue_to_rgb(uint16_t hue, struct cRGB *rgb)
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/