From cd07b642637872bc71fcadf0743a0b5475ab42e2 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Tue, 24 Apr 2018 15:37:37 -0400 Subject: [PATCH] betterize register handling --- drivers/avr/is31fl3731.c | 135 +++------------- drivers/avr/is31fl3731.h | 169 +++++++++++++++++++- keyboards/planck/light/light.c | 283 ++++++++++++++++++++------------- quantum/rgb_matrix.c | 21 ++- quantum/rgb_matrix.h | 3 +- 5 files changed, 376 insertions(+), 235 deletions(-) diff --git a/drivers/avr/is31fl3731.c b/drivers/avr/is31fl3731.c index 5edcdefd..8c0fe525 100644 --- a/drivers/avr/is31fl3731.c +++ b/drivers/avr/is31fl3731.c @@ -87,71 +87,6 @@ typedef struct // 0x0E - R17,G15,G14,G13,G12,G11,G10,G09 // 0x10 - R16,R15,R14,R13,R12,R11,R10,R09 -const led_control_bitmask g_led_control_bitmask[18] = -{ - { 0x02, 0, 0x04, 0, 0x06, 0 }, // R00,G00,B00 - { 0x00, 0, 0x04, 1, 0x06, 1 }, // R01,G01,B01 - { 0x00, 1, 0x02, 1, 0x06, 2 }, // R02,G02,B02 - { 0x00, 2, 0x02, 2, 0x04, 2 }, // R03,G03,B03 - { 0x00, 3, 0x02, 3, 0x04, 3 }, // R04,G04,B04 - { 0x00, 4, 0x02, 4, 0x04, 4 }, // R05,G05,B05 - { 0x00, 5, 0x02, 5, 0x04, 5 }, // R06,G06,B06 - { 0x00, 6, 0x02, 6, 0x04, 6 }, // R07,G07,B07 - { 0x00, 7, 0x02, 7, 0x04, 7 }, // R08,G08,B08 - - { 0x10, 0, 0x0E, 0, 0x0C, 0 }, // R09,G09,B09 - { 0x10, 1, 0x0E, 1, 0x0C, 1 }, // R10,G10,B10 - { 0x10, 2, 0x0E, 2, 0x0C, 2 }, // R11,G11,B11 - { 0x10, 3, 0x0E, 3, 0x0C, 3 }, // R12,G12,B12 - { 0x10, 4, 0x0E, 4, 0x0C, 4 }, // R13,G13,B13 - { 0x10, 5, 0x0E, 5, 0x0C, 5 }, // R14,G14,B14 - { 0x10, 6, 0x0E, 6, 0x0A, 5 }, // R15,G15,B15 - { 0x10, 7, 0x0C, 6, 0x0A, 6 }, // R16,G16,B16 - { 0x0E, 7, 0x0C, 7, 0x0A, 7 }, // R17,G17,B17 -}; - -const uint8_t g_map_control_index_to_register[2][18][3] PROGMEM = { - { - {0x34, 0x44, 0x54}, // 00 - {0x24, 0x45, 0x55}, // 01 - {0x25, 0x35, 0x56}, // 02 - {0x26, 0x36, 0x46}, // 03 - {0x27, 0x37, 0x47}, // 04 - {0x28, 0x38, 0x48}, // 05 - {0x29, 0x39, 0x49}, // 06 - {0x2a, 0x3a, 0x4a}, // 07 - {0x2b, 0x3b, 0x4b}, // 08 - - {0xa4, 0x94, 0x84}, // 09 - {0xa5, 0x95, 0x85}, // 10 - {0xa6, 0x96, 0x86}, // 11 - {0xa7, 0x97, 0x87}, // 12 - {0xa8, 0x98, 0x88}, // 13 - {0xa9, 0x99, 0x89}, // 14 - {0xaa, 0x9a, 0x79}, // 15 - {0xab, 0x8a, 0x7a}, // 16 - {0x9b, 0x8b, 0x7b} // 17 - }, { - {0x34 + 8, 0x44 + 8, 0x54 + 8}, // 00 - {0x24 + 8, 0x45 + 8, 0x55 + 8}, // 01 - {0x25 + 8, 0x35 + 8, 0x56 + 8}, // 02 - {0x26 + 8, 0x36 + 8, 0x46 + 8}, // 03 - {0x27 + 8, 0x37 + 8, 0x47 + 8}, // 04 - {0x28 + 8, 0x38 + 8, 0x48 + 8}, // 05 - {0x29 + 8, 0x39 + 8, 0x49 + 8}, // 06 - {0x2a + 8, 0x3a + 8, 0x4a + 8}, // 07 - {0x2b + 8, 0x3b + 8, 0x4b + 8}, // 08 - - {0xa4 + 8, 0x94 + 8, 0x84 + 8}, // 09 - {0xa5 + 8, 0x95 + 8, 0x85 + 8}, // 10 - {0xa6 + 8, 0x96 + 8, 0x86 + 8}, // 11 - {0xa7 + 8, 0x97 + 8, 0x87 + 8}, // 12 - {0xa8 + 8, 0x98 + 8, 0x88 + 8}, // 13 - {0xa9 + 8, 0x99 + 8, 0x89 + 8}, // 14 - {0xaa + 8, 0x9a + 8, 0x79 + 8}, // 15 - {0xab + 8, 0x8a + 8, 0x7a + 8}, // 16 - {0x9b + 8, 0x8b + 8, 0x7b + 8} // 17 -}}; void IS31FL3731_write_register( uint8_t addr, uint8_t reg, uint8_t data ) { @@ -256,32 +191,15 @@ void IS31FL3731_init( uint8_t addr ) IS31FL3731_write_register( addr, ISSI_COMMANDREGISTER, 0 ); } - -void map_index_to_led( uint8_t index, is31_led *led ) { - //led = , sizeof(struct is31_led)); - // led->driver = addr->driver; - // led->matrix = addr->matrix; - // led->modifier = addr->modifier; - // led->control_index = addr->control_index; - // led->matrix_co.raw = addr->matrix_co.raw; - // led->driver = (pgm_read_byte(addr) >> 6) && 0b11; - // led->matrix = (pgm_read_byte(addr) >> 4) && 0b1; - // led->modifier = (pgm_read_byte(addr) >> 3) && 0b1; - // led->control_index = pgm_read_byte(addr+1); - // led->matrix_co.raw = pgm_read_byte(addr+2); -} - void IS31FL3731_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) { - if ( index >= 0 && index < DRIVER_LED_TOTAL ) - { + if ( index >= 0 && index < DRIVER_LED_TOTAL ) { is31_led led = g_is31_leds[index]; - //map_index_to_led(index, &led); // Subtract 0x24 to get the second index of g_pwm_buffer - g_pwm_buffer[led.driver][ pgm_read_byte(&g_map_control_index_to_register[led.matrix][led.control_index][0]) - 0x24] = red; - g_pwm_buffer[led.driver][ pgm_read_byte(&g_map_control_index_to_register[led.matrix][led.control_index][1]) - 0x24] = green; - g_pwm_buffer[led.driver][ pgm_read_byte(&g_map_control_index_to_register[led.matrix][led.control_index][2]) - 0x24] = blue; + g_pwm_buffer[led.driver][led.r - 0x24] = red; + g_pwm_buffer[led.driver][led.g - 0x24] = green; + g_pwm_buffer[led.driver][led.b - 0x24] = blue; g_pwm_buffer_update_required = true; } } @@ -297,35 +215,28 @@ void IS31FL3731_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) void IS31FL3731_set_led_control_register( uint8_t index, bool red, bool green, bool blue ) { is31_led led = g_is31_leds[index]; - // map_index_to_led(index, &led); - - led_control_bitmask bitmask = g_led_control_bitmask[led.control_index]; - // Matrix A and B registers are interleaved. - // Add 1 to Matrix A register to get Matrix B register - if ( red ) - { - g_led_control_registers[led.driver][bitmask.red_register+led.matrix] |= (1<event.key.row, record->event.key.col ); } - + return process_record_user(keycode, record); } diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index b31430b3..eee10306 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c @@ -39,7 +39,7 @@ rgb_matrix_config g_config = { .layer_1_indicator = { .color = { .h = 0, .s = 0, .v = 255 }, .index = 255 }, .layer_2_indicator = { .color = { .h = 0, .s = 0, .v = 255 }, .index = 255 }, .layer_3_indicator = { .color = { .h = 0, .s = 0, .v = 255 }, .index = 255 }, -}; +}; bool g_suspend_state = false; uint8_t g_indicator_state = 0; @@ -128,7 +128,7 @@ void backlight_unset_key_hit(uint8_t row, uint8_t column) void backlight_timer_init(void) { - + static uint8_t backlight_timer_is_init = 0; if ( backlight_timer_is_init ) { @@ -146,7 +146,7 @@ void backlight_timer_init(void) //OCR3AH = (TIMER3_TOP >> 8) & 0xff; //OCR3AL = TIMER3_TOP & 0xff; //SREG = sreg; - + } void backlight_timer_enable(void) @@ -273,7 +273,7 @@ void backlight_effect_alphas_mods(void) { RGB rgb1 = hsv_to_rgb( (HSV){ .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness } ); RGB rgb2 = hsv_to_rgb( (HSV){ .h = g_config.color_2.h, .s = g_config.color_2.s, .v = g_config.brightness } ); - + rgb_led led; for (int i = 0; i < DRIVER_LED_TOTAL; i++) { led = g_rgb_leds[i]; @@ -523,7 +523,7 @@ void backlight_effect_jellybean_raindrops( bool initialize ) } void backlight_effect_multisplash(void) { - // if (g_any_key_hit < 0xFF) { + // if (g_any_key_hit < 0xFF) { HSV hsv = { .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness }; RGB rgb; rgb_led led; @@ -554,13 +554,13 @@ void backlight_effect_multisplash(void) { void backlight_effect_splash(void) { - g_last_led_count = MIN(g_last_led_count, 1); + g_last_led_count = MIN(g_last_led_count, 1); backlight_effect_multisplash(); } void backlight_effect_solid_multisplash(void) { - // if (g_any_key_hit < 0xFF) { + // if (g_any_key_hit < 0xFF) { HSV hsv = { .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness }; RGB rgb; rgb_led led; @@ -589,7 +589,7 @@ void backlight_effect_solid_multisplash(void) { void backlight_effect_solid_splash(void) { - g_last_led_count = MIN(g_last_led_count, 1); + g_last_led_count = MIN(g_last_led_count, 1); backlight_effect_solid_multisplash(); } @@ -1015,6 +1015,11 @@ void rgblight_step(void) { backlight_config_save(); } +void rgblight_step_reverse(void) { + g_config.effect = (g_config.effect - 1) % (BACKLIGHT_EFFECT_MAX + 1); + backlight_config_save(); +} + void rgblight_increase_hue(void) { backlight_color_1_hue_increase(); backlight_color_2_hue_increase(); diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h index 2d3a08a8..e97f2b93 100644 --- a/quantum/rgb_matrix.h +++ b/quantum/rgb_matrix.h @@ -130,6 +130,7 @@ void backlight_debug_led(bool state); void rgblight_toggle(void); void rgblight_step(void); +void rgblight_step_reverse(void); void rgblight_increase_hue(void); void rgblight_decrease_hue(void); void rgblight_increase_sat(void); @@ -139,4 +140,4 @@ void rgblight_decrease_val(void); void rgblight_mode(uint8_t mode); uint32_t rgblight_get_mode(void); -#endif \ No newline at end of file +#endif