diff options
author | Jack Humbert <jack.humb@gmail.com> | 2018-06-12 23:37:06 -0400 |
---|---|---|
committer | Jack Humbert <jack.humb@gmail.com> | 2018-06-12 23:37:06 -0400 |
commit | bad56a4f2b91fc8591f6d33a1710ea0050abcfbf (patch) | |
tree | ce6400e681028237464ac2f869249a17b00ab1e4 /quantum/rgb_matrix.c | |
parent | b8564f5dd08f49ee0fc6d28957a376132bd7038d (diff) | |
download | qmk_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.c | 87 |
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 | |||
105 | void rgb_matrix_update_pwm_buffers(void) { | 104 | void 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 | ||
110 | void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) { | 114 | void 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 | |||
119 | bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) { | 122 | bool 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 |
221 | void rgb_matrix_all_off(void) { | 224 | void 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 |
246 | void rgb_matrix_alphas_mods(void) { | 249 | void 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 | ||
725 | void rgb_matrix_init_drivers(void) { | 728 | void 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(); | 753 | void 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 |