1
0

kimera: Some minor fixes for RGB LED

This commit is contained in:
Kai Ryu 2016-12-14 21:00:37 +09:00
parent e7d4a1c2e6
commit c9b71e25fb
6 changed files with 54 additions and 6 deletions

View File

@ -129,6 +129,7 @@ endif
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.

View File

@ -57,7 +57,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* 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

View File

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

View File

@ -60,3 +60,34 @@ uint16_t fn_actions_count(void) {
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

View File

@ -77,6 +77,8 @@ void matrix_init(void)
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();

View File

@ -40,7 +40,9 @@ static void rgb_write_config(void);
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)
@ -63,7 +65,7 @@ void rgb_read_config(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)
@ -118,19 +120,28 @@ void rgb_step(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_WHITE) {
rgb_fading_enable = 0;
rgb_rainbow = 0;
if (level == RGB_OFF) { if (level == RGB_OFF) {
rgb_brightness = 0; rgb_brightness = 0;
} }
else if (backlight_config.enable) {
if (backlight_config.level >= 1 && backlight_config.level <= 3) {
rgb_brightness = backlight_brightness;
}
}
else { else {
rgb_brightness = 16;
}
if (level <= RGB_WHITE) {
rgb_fading_enable = 0;
rgb_rainbow = 0;
if (level != RGB_OFF) {
if (level == RGB_WHITE) { if (level == RGB_WHITE) {
rgb_saturation = 0; rgb_saturation = 0;
} }
@ -186,6 +197,7 @@ void rgb_refresh(void)
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;
@ -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; 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/