aboutsummaryrefslogtreecommitdiff
path: root/quantum/rgb_matrix.c
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2018-06-12 23:37:06 -0400
committerJack Humbert <jack.humb@gmail.com>2018-06-12 23:37:06 -0400
commitbad56a4f2b91fc8591f6d33a1710ea0050abcfbf (patch)
treece6400e681028237464ac2f869249a17b00ab1e4 /quantum/rgb_matrix.c
parentb8564f5dd08f49ee0fc6d28957a376132bd7038d (diff)
downloadqmk_firmware-bad56a4f2b91fc8591f6d33a1710ea0050abcfbf.tar.gz
qmk_firmware-bad56a4f2b91fc8591f6d33a1710ea0050abcfbf.zip
adds timeout to avr i2c
Diffstat (limited to 'quantum/rgb_matrix.c')
-rw-r--r--quantum/rgb_matrix.c87
1 files changed, 47 insertions, 40 deletions
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c
index 8c41fc54d..d71283f7c 100644
--- a/quantum/rgb_matrix.c
+++ b/quantum/rgb_matrix.c
@@ -101,10 +101,14 @@ void map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i, uint8_t
101 } 101 }
102} 102}
103 103
104
105void rgb_matrix_update_pwm_buffers(void) { 104void rgb_matrix_update_pwm_buffers(void) {
106 IS31FL3731_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); 105 uint8_t ret = IS31FL3731_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
107 IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); 106 ret |= IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
107 if (ret == 2) {
108 wait_ms(1000);
109 i2c_stop();
110 rgb_matrix_setup_drivers();
111 }
108} 112}
109 113
110void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) { 114void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) {
@@ -115,7 +119,6 @@ void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) {
115 IS31FL3731_set_color_all( red, green, blue ); 119 IS31FL3731_set_color_all( red, green, blue );
116} 120}
117 121
118
119bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) { 122bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) {
120 if ( record->event.pressed ) { 123 if ( record->event.pressed ) {
121 uint8_t led[8], led_count; 124 uint8_t led[8], led_count;
@@ -218,7 +221,7 @@ void rgb_matrix_single_LED_test(void) {
218} 221}
219 222
220// All LEDs off 223// All LEDs off
221void rgb_matrix_all_off(void) { 224void rgb_matrix_all_off(void) {
222 rgb_matrix_set_color_all( 0, 0, 0 ); 225 rgb_matrix_set_color_all( 0, 0, 0 );
223} 226}
224 227
@@ -244,7 +247,7 @@ void rgb_matrix_solid_reactive(void) {
244 247
245// alphas = color1, mods = color2 248// alphas = color1, mods = color2
246void rgb_matrix_alphas_mods(void) { 249void rgb_matrix_alphas_mods(void) {
247 250
248 RGB rgb1 = hsv_to_rgb( (HSV){ .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val } ); 251 RGB rgb1 = hsv_to_rgb( (HSV){ .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val } );
249 RGB rgb2 = hsv_to_rgb( (HSV){ .h = (rgb_matrix_config.hue + 180) % 360, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val } ); 252 RGB rgb2 = hsv_to_rgb( (HSV){ .h = (rgb_matrix_config.hue + 180) % 360, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val } );
250 253
@@ -722,40 +725,44 @@ void rgb_matrix_indicators_user(void) {}
722// } 725// }
723// } 726// }
724 727
725void rgb_matrix_init_drivers(void) { 728void rgb_matrix_init(void) {
726 // Initialize TWI 729 rgb_matrix_setup_drivers();
727 i2c_init(); 730
728 IS31FL3731_init( DRIVER_ADDR_1 ); 731 // TODO: put the 1 second startup delay here?
729 IS31FL3731_init( DRIVER_ADDR_2 ); 732
730 733 // clear the key hits
731 for ( int index = 0; index < DRIVER_LED_TOTAL; index++ ) { 734 for ( int led=0; led<DRIVER_LED_TOTAL; led++ ) {
732 bool enabled = true; 735 g_key_hit[led] = 255;
733 // This only caches it for later 736 }
734 IS31FL3731_set_led_control_register( index, enabled, enabled, enabled ); 737
735 } 738
736 // This actually updates the LED drivers 739 if (!eeconfig_is_enabled()) {
737 IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); 740 dprintf("rgb_matrix_init_drivers eeconfig is not enabled.\n");
738 741 eeconfig_init();
739 // TODO: put the 1 second startup delay here? 742 eeconfig_update_rgb_matrix_default();
740 743 }
741 // clear the key hits 744 rgb_matrix_config.raw = eeconfig_read_rgb_matrix();
742 for ( int led=0; led<DRIVER_LED_TOTAL; led++ ) { 745 if (!rgb_matrix_config.mode) {
743 g_key_hit[led] = 255; 746 dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n");
744 } 747 eeconfig_update_rgb_matrix_default();
745 748 rgb_matrix_config.raw = eeconfig_read_rgb_matrix();
746 749 }
747 if (!eeconfig_is_enabled()) { 750 eeconfig_debug_rgb_matrix(); // display current eeprom values
748 dprintf("rgb_matrix_init_drivers eeconfig is not enabled.\n"); 751}
749 eeconfig_init(); 752
750 eeconfig_update_rgb_matrix_default(); 753void rgb_matrix_setup_drivers(void) {
751 } 754 // Initialize TWI
752 rgb_matrix_config.raw = eeconfig_read_rgb_matrix(); 755 i2c_init();
753 if (!rgb_matrix_config.mode) { 756 IS31FL3731_init( DRIVER_ADDR_1 );
754 dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n"); 757 IS31FL3731_init( DRIVER_ADDR_2 );
755 eeconfig_update_rgb_matrix_default(); 758
756 rgb_matrix_config.raw = eeconfig_read_rgb_matrix(); 759 for ( int index = 0; index < DRIVER_LED_TOTAL; index++ ) {
757 } 760 bool enabled = true;
758 eeconfig_debug_rgb_matrix(); // display current eeprom values 761 // This only caches it for later
762 IS31FL3731_set_led_control_register( index, enabled, enabled, enabled );
763 }
764 // This actually updates the LED drivers
765 IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
759} 766}
760 767
761// Deals with the messy details of incrementing an integer 768// Deals with the messy details of incrementing an integer