]> git.donarmstrong.com Git - qmk_firmware.git/blobdiff - quantum/rgb_matrix.c
Fold install_dependencies.sh into linux_install.sh and freebsd_install.sh
[qmk_firmware.git] / quantum / rgb_matrix.c
index 5fb59af8c023d00d662b3d827d6264b22ede1d8c..26ee57f5c2c4d166e7678186200d1b7ebb5fd668 100644 (file)
 
 
 #include "rgb_matrix.h"
-#include "i2c_master.h"
 #include "progmem.h"
 #include "config.h"
 #include "eeprom.h"
+#include <string.h>
 #include <math.h>
 
 rgb_config_t rgb_matrix_config;
@@ -50,6 +50,11 @@ rgb_config_t rgb_matrix_config;
     #define RGB_MATRIX_MAXIMUM_BRIGHTNESS 255
 #endif
 
+#ifndef RGB_DIGITAL_RAIN_DROPS
+    // lower the number for denser effect/wider keyboard
+    #define RGB_DIGITAL_RAIN_DROPS 24
+#endif
+
 bool g_suspend_state = false;
 
 // Global tick at 20 Hz
@@ -111,29 +116,15 @@ void map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i, uint8_t
 }
 
 void rgb_matrix_update_pwm_buffers(void) {
-#ifdef IS31FL3731
-    IS31FL3731_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
-    IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
-#elif defined(IS31FL3733)
-    IS31FL3733_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
-    IS31FL3733_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
-#endif
+    rgb_matrix_driver.flush();
 }
 
 void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) {
-#ifdef IS31FL3731
-    IS31FL3731_set_color( index, red, green, blue );
-#elif defined(IS31FL3733)
-    IS31FL3733_set_color( index, red, green, blue );
-#endif
+    rgb_matrix_driver.set_color(index, red, green, blue);
 }
 
 void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) {
-#ifdef IS31FL3731
-    IS31FL3731_set_color_all( red, green, blue );
-#elif defined(IS31FL3733)
-    IS31FL3733_set_color_all( red, green, blue );
-#endif
+    rgb_matrix_driver.set_color_all(red, green, blue);
 }
 
 bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) {
@@ -196,47 +187,6 @@ void rgb_matrix_test(void) {
     }
 }
 
-// This tests the LEDs
-// Note that it will change the LED control registers
-// in the LED drivers, and leave them in an invalid
-// state for other backlight effects.
-// ONLY USE THIS FOR TESTING LEDS!
-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;
-
-    static uint8_t tick = 0;
-    tick++;
-
-    if ( tick > 2 )
-    {
-        tick = 0;
-        column++;
-    }
-    if ( column > MATRIX_COLS )
-    {
-        column = 0;
-        row++;
-    }
-    if ( row > MATRIX_ROWS )
-    {
-        row = 0;
-        color++;
-    }
-    if ( color > 2 )
-    {
-        color = 0;
-    }
-
-    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++) {
-        rgb_matrix_set_color_all( 40, 40, 40 );
-        rgb_matrix_test_led( led[i], color==0, color==1, color==2 );
-    }
-}
-
 // All LEDs off
 void rgb_matrix_all_off(void) {
     rgb_matrix_set_color_all( 0, 0, 0 );
@@ -521,7 +471,6 @@ void rgb_matrix_jellybean_raindrops( bool initialize ) {
 void rgb_matrix_digital_rain( const bool initialize ) {
     // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain
     const uint8_t drop_ticks           = 28;
-    const uint8_t new_drop_probability = 24;
     const uint8_t pure_green_intensity = 0xd0;
     const uint8_t max_brightness_boost = 0xc0;
     const uint8_t max_intensity        = 0xff;
@@ -536,7 +485,7 @@ void rgb_matrix_digital_rain( const bool initialize ) {
     }
     for (uint8_t col = 0; col < MATRIX_COLS; col++) {
         for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
-            if (row == 0 && drop == 0 && rand() < RAND_MAX / new_drop_probability) {
+            if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) {
                 // top row, pixels have just fallen and we're
                 // making a new rain drop in this column
                 map[col][row] = max_intensity;
@@ -671,7 +620,8 @@ void rgb_matrix_custom(void) {
 void rgb_matrix_task(void) {
     static uint8_t toggle_enable_last = 255;
        if (!rgb_matrix_config.enable) {
-       rgb_matrix_all_off();
+        rgb_matrix_all_off();
+        rgb_matrix_indicators();
         toggle_enable_last = rgb_matrix_config.enable;
        return;
     }
@@ -817,7 +767,7 @@ void rgb_matrix_indicators_user(void) {}
 // }
 
 void rgb_matrix_init(void) {
-  rgb_matrix_setup_drivers();
+  rgb_matrix_driver.init();
 
   // TODO: put the 1 second startup delay here?
 
@@ -841,33 +791,6 @@ void rgb_matrix_init(void) {
   eeconfig_debug_rgb_matrix(); // display current eeprom values
 }
 
-void rgb_matrix_setup_drivers(void) {
-  // Initialize TWI
-  i2c_init();
-#ifdef IS31FL3731
-  IS31FL3731_init( DRIVER_ADDR_1 );
-  IS31FL3731_init( DRIVER_ADDR_2 );
-#elif defined (IS31FL3733)
-  IS31FL3733_init( DRIVER_ADDR_1 );
-#endif
-
-  for ( int index = 0; index < DRIVER_LED_TOTAL; index++ ) {
-    bool enabled = true;
-    // This only caches it for later
-#ifdef IS31FL3731
-    IS31FL3731_set_led_control_register( index, enabled, enabled, enabled );
-#elif defined (IS31FL3733)
-    IS31FL3733_set_led_control_register( index, enabled, enabled, enabled );
-#endif
-  }
-  // This actually updates the LED drivers
-#ifdef IS31FL3731
-  IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
-#elif defined (IS31FL3733)
-  IS31FL3733_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
-#endif
-}
-
 // Deals with the messy details of incrementing an integer
 uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) {
     int16_t new_value = value;
@@ -910,28 +833,6 @@ uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) {
 //     }
 // }
 
-void rgb_matrix_test_led( uint8_t index, bool red, bool green, bool blue ) {
-    for ( int i=0; i<DRIVER_LED_TOTAL; i++ )
-    {
-        if ( i == index )
-        {
-#ifdef IS31FL3731
-            IS31FL3731_set_led_control_register( i, red, green, blue );
-#elif defined (IS31FL3733)
-            IS31FL3733_set_led_control_register( i, red, green, blue );
-#endif
-        }
-        else
-        {
-#ifdef IS31FL3731
-            IS31FL3731_set_led_control_register( i, false, false, false );
-#elif defined (IS31FL3733)
-            IS31FL3733_set_led_control_register( i, false, false, false );
-#endif
-        }
-    }
-}
-
 uint32_t rgb_matrix_get_tick(void) {
     return g_tick;
 }
@@ -1003,3 +904,10 @@ void rgblight_mode(uint8_t mode) {
 uint32_t rgblight_get_mode(void) {
     return rgb_matrix_config.mode;
 }
+
+void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) {
+  rgb_matrix_config.hue = hue;
+  rgb_matrix_config.sat = sat;
+  rgb_matrix_config.val = val;
+  eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
+}