diff --git a/keyboards/planck/light/light.c b/keyboards/planck/light/light.c index 67be5d111e..4ecb5f5b8d 100644 --- a/keyboards/planck/light/light.c +++ b/keyboards/planck/light/light.c @@ -19,7 +19,8 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { -/* driver +/* Refer to IS31 manual for these locations + * driver * | R location * | | G location * | | | B location @@ -140,12 +141,6 @@ const rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = { void matrix_init_kb(void) { - // Initialize LED drivers for backlight. - backlight_init_drivers(); - - backlight_timer_init(); - backlight_timer_enable(); - // Turn status LED on DDRD |= (1<<6); PORTD |= (1<<6); @@ -155,44 +150,26 @@ void matrix_init_kb(void) { bool process_record_kb(uint16_t keycode, keyrecord_t *record) { - // Record keypresses for backlight effects - if ( record->event.pressed ) { - backlight_set_key_hit( record->event.key.row, record->event.key.col ); - } else { - // backlight_unset_key_hit( record->event.key.row, record->event.key.col ); - } - return process_record_user(keycode, record); } -uint16_t backlight_task_counter = 0; - void matrix_scan_kb(void) { - - // if (backlight_task_counter == 0) - backlight_rgb_task(); - // backlight_effect_single_LED_test(); - // backlight_task_counter = ((backlight_task_counter + 1) % 5); - - // This only updates the LED driver buffers if something has changed. - backlight_update_pwm_buffers(); - matrix_scan_user(); } void led_set_kb(uint8_t usb_led) { - backlight_set_indicator_state(usb_led); - //backlight_debug_led(usb_led & (1< -#define RGB_MATRIX_EFFECT_MAX 17 - rgb_config_t rgb_matrix_config; #ifndef RGB_DISABLE_AFTER_TIMEOUT @@ -55,25 +53,25 @@ uint32_t g_any_key_hit = 0; #define PI 3.14159265 #endif -uint32_t eeconfig_read_rgblight(void) { +uint32_t eeconfig_read_rgb_matrix(void) { return eeprom_read_dword(EECONFIG_RGBLIGHT); } -void eeconfig_update_rgblight(uint32_t val) { +void eeconfig_update_rgb_matrix(uint32_t val) { eeprom_update_dword(EECONFIG_RGBLIGHT, val); } -void eeconfig_update_rgblight_default(void) { - dprintf("eeconfig_update_rgblight_default\n"); +void eeconfig_update_rgb_matrix_default(void) { + dprintf("eeconfig_update_rgb_matrix_default\n"); rgb_matrix_config.enable = 1; - rgb_matrix_config.mode = 7; + rgb_matrix_config.mode = RGB_MATRIX_CYCLE_LEFT_RIGHT; rgb_matrix_config.hue = 0; rgb_matrix_config.sat = 255; rgb_matrix_config.val = 255; - eeconfig_update_rgblight(rgb_matrix_config.raw); + eeconfig_update_rgb_matrix(rgb_matrix_config.raw); } -void eeconfig_debug_rgblight(void) { +void eeconfig_debug_rgb_matrix(void) { dprintf("rgb_matrix_config eprom\n"); dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable); - dprintf("rghlight_config.mode = %d\n", rgb_matrix_config.mode); + dprintf("rgb_matrix_config.mode = %d\n", rgb_matrix_config.mode); dprintf("rgb_matrix_config.hue = %d\n", rgb_matrix_config.hue); dprintf("rgb_matrix_config.sat = %d\n", rgb_matrix_config.sat); dprintf("rgb_matrix_config.val = %d\n", rgb_matrix_config.val); @@ -84,8 +82,7 @@ void eeconfig_debug_rgblight(void) { uint8_t g_last_led_hit[LED_HITS_TO_REMEMBER] = {255}; uint8_t g_last_led_count = 0; -void map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i, uint8_t *led_count) -{ +void map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i, uint8_t *led_count) { rgb_led led; *led_count = 0; @@ -100,120 +97,78 @@ void map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i, uint8_t } -void backlight_update_pwm_buffers(void) -{ +void rgb_matrix_update_pwm_buffers(void) { IS31FL3731_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); } -void backlight_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) -{ +void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) { IS31FL3731_set_color( index, red, green, blue ); } -void backlight_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) -{ +void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) { IS31FL3731_set_color_all( red, green, blue ); } -void backlight_set_key_hit(uint8_t row, uint8_t column) -{ - uint8_t led[8], led_count; - map_row_column_to_led(row,column,led,&led_count); - if (led_count > 0) { - for (uint8_t i = LED_HITS_TO_REMEMBER; i > 1; i--) { - g_last_led_hit[i - 1] = g_last_led_hit[i - 2]; - } - g_last_led_hit[0] = led[0]; - g_last_led_count = MIN(LED_HITS_TO_REMEMBER, g_last_led_count + 1); - } - for(uint8_t i = 0; i < led_count; i++) - g_key_hit[led[i]] = 0; - g_any_key_hit = 0; -} - -void backlight_unset_key_hit(uint8_t row, uint8_t column) -{ - uint8_t led[8], led_count; - map_row_column_to_led(row,column,led,&led_count); - for(uint8_t i = 0; i < led_count; i++) - g_key_hit[led[i]] = 255; - - g_any_key_hit = 255; -} -// This is (F_CPU/1024) / 20 Hz -// = 15625 Hz / 20 Hz -// = 781 -// #define TIMER3_TOP 781 - -void backlight_timer_init(void) -{ +bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) { + if ( record->event.pressed ) { + uint8_t led[8], led_count; + map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count); + if (led_count > 0) { + for (uint8_t i = LED_HITS_TO_REMEMBER; i > 1; i--) { + g_last_led_hit[i - 1] = g_last_led_hit[i - 2]; + } + g_last_led_hit[0] = led[0]; + g_last_led_count = MIN(LED_HITS_TO_REMEMBER, g_last_led_count + 1); + } + for(uint8_t i = 0; i < led_count; i++) + g_key_hit[led[i]] = 0; + g_any_key_hit = 0; + } else { + #ifdef RGB_MATRIX_KEYRELEASES + uint8_t led[8], led_count; + map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count); + for(uint8_t i = 0; i < led_count; i++) + g_key_hit[led[i]] = 255; - static uint8_t backlight_timer_is_init = 0; - if ( backlight_timer_is_init ) - { - return; + g_any_key_hit = 255; + #endif } - backlight_timer_is_init = 1; - - // Timer 3 setup - //TCCR3B = _BV(WGM32) | // CTC mode OCR3A as TOP - // _BV(CS32) | _BV(CS30); // prescale by /1024 - // Set TOP value - //uint8_t sreg = SREG; - //cli(); - - //OCR3AH = (TIMER3_TOP >> 8) & 0xff; - //OCR3AL = TIMER3_TOP & 0xff; - //SREG = sreg; - -} - -void backlight_timer_enable(void) -{ - //TIMSK3 |= _BV(OCIE3A); + return true; } -void backlight_timer_disable(void) -{ - //TIMSK3 &= ~_BV(OCIE3A); -} - -void backlight_set_suspend_state(bool state) -{ +void rgb_matrix_set_suspend_state(bool state) { g_suspend_state = state; } -void backlight_set_indicator_state(uint8_t state) -{ +void rgb_matrix_set_indicator_state(uint8_t state) { g_indicator_state = state; } -void backlight_effect_rgb_test(void) -{ +void rgb_matrix_test(void) { // Mask out bits 4 and 5 // This 2-bit value will stay the same for 16 ticks. switch ( (g_tick & 0x30) >> 4 ) { case 0: { - backlight_set_color_all( 20, 0, 0 ); + rgb_matrix_set_color_all( 20, 0, 0 ); break; } case 1: { - backlight_set_color_all( 0, 20, 0 ); + rgb_matrix_set_color_all( 0, 20, 0 ); break; } case 2: { - backlight_set_color_all( 0, 0, 20 ); + rgb_matrix_set_color_all( 0, 0, 20 ); break; } case 3: { - backlight_set_color_all( 20, 20, 20 ); + rgb_matrix_set_color_all( 20, 20, 20 ); break; } } @@ -224,8 +179,7 @@ void backlight_effect_rgb_test(void) // in the LED drivers, and leave them in an invalid // state for other backlight effects. // ONLY USE THIS FOR TESTING LEDS! -void backlight_effect_single_LED_test(void) -{ +void rgb_matrix_single_LED_test(void) { static uint8_t color = 0; // 0,1,2 for R,G,B static uint8_t row = 0; static uint8_t column = 0; @@ -256,27 +210,24 @@ void backlight_effect_single_LED_test(void) uint8_t led[8], led_count; map_row_column_to_led(row,column,led,&led_count); for(uint8_t i = 0; i < led_count; i++) { - backlight_set_color_all( 40, 40, 40 ); - backlight_test_led( led[i], color==0, color==1, color==2 ); + rgb_matrix_set_color_all( 40, 40, 40 ); + rgb_matrix_test_led( led[i], color==0, color==1, color==2 ); } } // All LEDs off -void backlight_effect_all_off(void) -{ - backlight_set_color_all( 0, 0, 0 ); +void rgb_matrix_all_off(void) { + rgb_matrix_set_color_all( 0, 0, 0 ); } // Solid color -void backlight_effect_solid_color(void) -{ +void rgb_matrix_solid_color(void) { HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; RGB rgb = hsv_to_rgb( hsv ); - backlight_set_color_all( rgb.r, rgb.g, rgb.b ); + rgb_matrix_set_color_all( rgb.r, rgb.g, rgb.b ); } -void backlight_effect_solid_reactive(void) -{ +void rgb_matrix_solid_reactive(void) { // Relies on hue being 8-bit and wrapping for ( int i=0; i= RGB_MATRIX_EFFECT_MAX) + rgb_matrix_config.mode = 1; + eeconfig_update_rgb_matrix(rgb_matrix_config.raw); } void rgblight_step_reverse(void) { - if (rgb_matrix_config.mode > 1) { - rgb_matrix_config.mode = (rgb_matrix_config.mode - 1) % (RGB_MATRIX_EFFECT_MAX + 1); - eeconfig_update_rgblight(rgb_matrix_config.raw); - } + rgb_matrix_config.mode--; + if (rgb_matrix_config.mode <= 1) + rgb_matrix_config.mode = (RGB_MATRIX_EFFECT_MAX - 1); + eeconfig_update_rgb_matrix(rgb_matrix_config.raw); } void rgblight_increase_hue(void) { rgb_matrix_config.hue = increment( rgb_matrix_config.hue, 8, 0, 255 ); - eeconfig_update_rgblight(rgb_matrix_config.raw); + eeconfig_update_rgb_matrix(rgb_matrix_config.raw); } void rgblight_decrease_hue(void) { rgb_matrix_config.hue = decrement( rgb_matrix_config.hue, 8, 0, 255 ); - eeconfig_update_rgblight(rgb_matrix_config.raw); + eeconfig_update_rgb_matrix(rgb_matrix_config.raw); } void rgblight_increase_sat(void) { rgb_matrix_config.sat = increment( rgb_matrix_config.sat, 8, 0, 255 ); - eeconfig_update_rgblight(rgb_matrix_config.raw); + eeconfig_update_rgb_matrix(rgb_matrix_config.raw); } void rgblight_decrease_sat(void) { rgb_matrix_config.sat = decrement( rgb_matrix_config.sat, 8, 0, 255 ); - eeconfig_update_rgblight(rgb_matrix_config.raw); + eeconfig_update_rgb_matrix(rgb_matrix_config.raw); } void rgblight_increase_val(void) { rgb_matrix_config.val = increment( rgb_matrix_config.val, 8, 0, 255 ); - eeconfig_update_rgblight(rgb_matrix_config.raw); + eeconfig_update_rgb_matrix(rgb_matrix_config.raw); } void rgblight_decrease_val(void) { rgb_matrix_config.val = decrement( rgb_matrix_config.val, 8, 0, 255 ); - eeconfig_update_rgblight(rgb_matrix_config.raw); + eeconfig_update_rgb_matrix(rgb_matrix_config.raw); } void rgblight_mode(uint8_t mode) { rgb_matrix_config.mode = mode; - eeconfig_update_rgblight(rgb_matrix_config.raw); + eeconfig_update_rgb_matrix(rgb_matrix_config.raw); } uint32_t rgblight_get_mode(void) { diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h index ec8454bd30..c9d5ebe107 100644 --- a/quantum/rgb_matrix.h +++ b/quantum/rgb_matrix.h @@ -61,48 +61,61 @@ typedef union { }; } rgb_config_t; +enum rgb_matrix_effects { + RGB_MATRIX_SOLID_COLOR = 1, + RGB_MATRIX_SOLID_REACTIVE, + RGB_MATRIX_ALPHAS_MODS, + RGB_MATRIX_DUAL_BEACON, + RGB_MATRIX_GRADIENT_UP_DOWN, + RGB_MATRIX_RAINDROPS, + RGB_MATRIX_CYCLE_ALL, + RGB_MATRIX_CYCLE_LEFT_RIGHT, + RGB_MATRIX_CYCLE_UP_DOWN, + RGB_MATRIX_RAINBOW_BEACON, + RGB_MATRIX_RAINBOW_PINWHEELS, + RGB_MATRIX_RAINBOW_MOVING_CHEVRON, + RGB_MATRIX_JELLYBEAN_RAINDROPS, +#ifdef RGB_MATRIX_KEYPRESSES + RGB_MATRIX_SPLASH, + RGB_MATRIX_MULTISPLASH, + RGB_MATRIX_SOLID_SPLASH, + RGB_MATRIX_SOLID_MULTISPLASH, +#endif + RGB_MATRIX_EFFECT_MAX +}; + // This runs after another backlight effect and replaces // colors already set __attribute__((weak)) -void backlight_effect_indicators(void) {}; - -void backlight_effect_single_LED_test(void); - -void backlight_config_set_alphas_mods( uint16_t *value ); -void backlight_config_load(void); -void backlight_config_save(void); +void rgb_matrix_indicators(void) {}; -void backlight_init_drivers(void); +void rgb_matrix_single_LED_test(void); -void backlight_timer_init(void); -void backlight_timer_enable(void); -void backlight_timer_disable(void); +void rgb_matrix_init_drivers(void); -void backlight_set_suspend_state(bool state); -void backlight_set_indicator_state(uint8_t state); +void rgb_matrix_set_suspend_state(bool state); +void rgb_matrix_set_indicator_state(uint8_t state); -void backlight_rgb_task(void); +void rgb_matrix_task(void); // This should not be called from an interrupt // (eg. from a timer interrupt). // Call this while idle (in between matrix scans). // If the buffer is dirty, it will update the driver with the buffer. -void backlight_update_pwm_buffers(void); +void rgb_matrix_update_pwm_buffers(void); -void backlight_set_key_hit(uint8_t row, uint8_t col); -void backlight_unset_key_hit(uint8_t row, uint8_t col); +bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record); -void backlight_effect_increase(void); -void backlight_effect_decrease(void); +void rgb_matrix_increase(void); +void rgb_matrix_decrease(void); -void *backlight_get_key_color_eeprom_address(uint8_t led); -void backlight_get_key_color( uint8_t led, HSV *hsv ); -void backlight_set_key_color( uint8_t row, uint8_t column, HSV hsv ); +// void *backlight_get_key_color_eeprom_address(uint8_t led); +// void backlight_get_key_color( uint8_t led, HSV *hsv ); +// void backlight_set_key_color( uint8_t row, uint8_t column, HSV hsv ); -void backlight_test_led( uint8_t index, bool red, bool green, bool blue ); -uint32_t backlight_get_tick(void); -void backlight_debug_led(bool state); +void rgb_matrix_test_led( uint8_t index, bool red, bool green, bool blue ); +uint32_t rgb_matrix_get_tick(void); void rgblight_toggle(void); void rgblight_step(void);