diff options
| author | skullY <skullydazed@gmail.com> | 2019-01-26 21:25:59 -0800 |
|---|---|---|
| committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-02-10 15:37:12 -0800 |
| commit | 6b74dd6de5359da18e87b2d4894e3ffc3fc89d47 (patch) | |
| tree | d4b467f032aadac477c4c2fb21d17a6c35dd30a0 | |
| parent | bf2670601d29551896bab6811b9bb64de2d0ee0e (diff) | |
| download | qmk_firmware-6b74dd6de5359da18e87b2d4894e3ffc3fc89d47.tar.gz qmk_firmware-6b74dd6de5359da18e87b2d4894e3ffc3fc89d47.zip | |
led_matrix works now
| -rw-r--r-- | common_features.mk | 5 | ||||
| -rw-r--r-- | drivers/arm/i2c_master.c | 11 | ||||
| -rw-r--r-- | drivers/arm/i2c_master.h | 10 | ||||
| -rw-r--r-- | drivers/issi/is31fl3731-simple.c | 5 | ||||
| -rw-r--r-- | quantum/led_matrix.c | 47 | ||||
| -rw-r--r-- | quantum/led_matrix.h | 3 | ||||
| -rw-r--r-- | quantum/led_matrix_drivers.c | 3 |
7 files changed, 45 insertions, 39 deletions
diff --git a/common_features.mk b/common_features.mk index 8c7043cb7..ff01ecb85 100644 --- a/common_features.mk +++ b/common_features.mk | |||
| @@ -209,7 +209,10 @@ ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) | |||
| 209 | ifeq ($(strip $(VISUALIZER_ENABLE)), yes) | 209 | ifeq ($(strip $(VISUALIZER_ENABLE)), yes) |
| 210 | CIE1931_CURVE = yes | 210 | CIE1931_CURVE = yes |
| 211 | endif | 211 | endif |
| 212 | ifeq ($(strip $(BACKLIGHT_CUSTOM_DRIVER)), yes) | 212 | ifeq ($(strip $(BACKLIGHT_CUSTOM_DRIVER)), yes) |
| 213 | OPT_DEFS += -DBACKLIGHT_CUSTOM_DRIVER | ||
| 214 | endif | ||
| 215 | ifeq ($(filter $(LED_MATRIX_ENABLE),$(VALID_MATRIX_TYPES)),) | ||
| 213 | OPT_DEFS += -DBACKLIGHT_CUSTOM_DRIVER | 216 | OPT_DEFS += -DBACKLIGHT_CUSTOM_DRIVER |
| 214 | endif | 217 | endif |
| 215 | endif | 218 | endif |
diff --git a/drivers/arm/i2c_master.c b/drivers/arm/i2c_master.c index 385bd97cb..1c3da2a1a 100644 --- a/drivers/arm/i2c_master.c +++ b/drivers/arm/i2c_master.c | |||
| @@ -46,13 +46,13 @@ __attribute__ ((weak)) | |||
| 46 | void i2c_init(void) | 46 | void i2c_init(void) |
| 47 | { | 47 | { |
| 48 | // Try releasing special pins for a short time | 48 | // Try releasing special pins for a short time |
| 49 | palSetPadMode(GPIOB, 6, PAL_MODE_INPUT); | 49 | palSetPadMode(I2C1_BANK, I2C1_SCL, PAL_MODE_INPUT); |
| 50 | palSetPadMode(GPIOB, 7, PAL_MODE_INPUT); | 50 | palSetPadMode(I2C1_BANK, I2C1_SDA, PAL_MODE_INPUT); |
| 51 | 51 | ||
| 52 | chThdSleepMilliseconds(10); | 52 | chThdSleepMilliseconds(10); |
| 53 | 53 | ||
| 54 | palSetPadMode(GPIOB, 6, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); | 54 | palSetPadMode(I2C1_BANK, I2C1_SCL, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); |
| 55 | palSetPadMode(GPIOB, 7, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); | 55 | palSetPadMode(I2C1_BANK, I2C1_SDA, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); |
| 56 | 56 | ||
| 57 | //i2cInit(); //This is invoked by halInit() so no need to redo it. | 57 | //i2cInit(); //This is invoked by halInit() so no need to redo it. |
| 58 | } | 58 | } |
| @@ -67,6 +67,7 @@ uint8_t i2c_start(uint8_t address) | |||
| 67 | 67 | ||
| 68 | uint8_t i2c_transmit(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout) | 68 | uint8_t i2c_transmit(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout) |
| 69 | { | 69 | { |
| 70 | // FIXME: Next steps: Add a print here, copy this file to your rgb_matrix firmware. Compare both. | ||
| 70 | i2c_address = address; | 71 | i2c_address = address; |
| 71 | i2cStart(&I2C_DRIVER, &i2cconfig); | 72 | i2cStart(&I2C_DRIVER, &i2cconfig); |
| 72 | return i2cMasterTransmitTimeout(&I2C_DRIVER, (i2c_address >> 1), data, length, 0, 0, MS2ST(timeout)); | 73 | return i2cMasterTransmitTimeout(&I2C_DRIVER, (i2c_address >> 1), data, length, 0, 0, MS2ST(timeout)); |
diff --git a/drivers/arm/i2c_master.h b/drivers/arm/i2c_master.h index 392760328..7a9eb32eb 100644 --- a/drivers/arm/i2c_master.h +++ b/drivers/arm/i2c_master.h | |||
| @@ -26,6 +26,16 @@ | |||
| 26 | #include "ch.h" | 26 | #include "ch.h" |
| 27 | #include <hal.h> | 27 | #include <hal.h> |
| 28 | 28 | ||
| 29 | #ifndef I2C1_BANK | ||
| 30 | #define I2C1_BANK GPIOB | ||
| 31 | #endif | ||
| 32 | #ifndef I2C1_SCL | ||
| 33 | #define I2C1_SCL 6 | ||
| 34 | #endif | ||
| 35 | #ifndef I2C1_SDA | ||
| 36 | #define I2C1_SDA 7 | ||
| 37 | #endif | ||
| 38 | |||
| 29 | #ifndef I2C_DRIVER | 39 | #ifndef I2C_DRIVER |
| 30 | #define I2C_DRIVER I2CD1 | 40 | #define I2C_DRIVER I2CD1 |
| 31 | #endif | 41 | #endif |
diff --git a/drivers/issi/is31fl3731-simple.c b/drivers/issi/is31fl3731-simple.c index 9c31df209..ff6620b72 100644 --- a/drivers/issi/is31fl3731-simple.c +++ b/drivers/issi/is31fl3731-simple.c | |||
| @@ -158,12 +158,7 @@ void IS31FL3731_init(uint8_t addr) { | |||
| 158 | // enable software shutdown | 158 | // enable software shutdown |
| 159 | IS31FL3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x00); | 159 | IS31FL3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x00); |
| 160 | // this delay was copied from other drivers, might not be needed | 160 | // this delay was copied from other drivers, might not be needed |
| 161 | // FIXME: Don't we have a wrapper for this already? | ||
| 162 | #ifdef __AVR__ | ||
| 163 | _delay_ms(10); | ||
| 164 | #else | ||
| 165 | wait_ms(10); | 161 | wait_ms(10); |
| 166 | #endif | ||
| 167 | 162 | ||
| 168 | // picture mode | 163 | // picture mode |
| 169 | IS31FL3731_write_register(addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE); | 164 | IS31FL3731_write_register(addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE); |
diff --git a/quantum/led_matrix.c b/quantum/led_matrix.c index 3b284990d..f849d478d 100644 --- a/quantum/led_matrix.c +++ b/quantum/led_matrix.c | |||
| @@ -55,6 +55,9 @@ led_config_t led_matrix_config; | |||
| 55 | 55 | ||
| 56 | bool g_suspend_state = false; | 56 | bool g_suspend_state = false; |
| 57 | 57 | ||
| 58 | // Last uniform brightness level. | ||
| 59 | uint8_t g_uniform_brightness = 0; | ||
| 60 | |||
| 58 | // Global tick at 20 Hz | 61 | // Global tick at 20 Hz |
| 59 | uint32_t g_tick = 0; | 62 | uint32_t g_tick = 0; |
| 60 | 63 | ||
| @@ -118,6 +121,7 @@ void led_matrix_set_index_value_all(uint8_t value) { | |||
| 118 | } | 121 | } |
| 119 | 122 | ||
| 120 | bool process_led_matrix(uint16_t keycode, keyrecord_t *record) { | 123 | bool process_led_matrix(uint16_t keycode, keyrecord_t *record) { |
| 124 | /* FIXME: Why you comment out skully? | ||
| 121 | if (record->event.pressed) { | 125 | if (record->event.pressed) { |
| 122 | uint8_t led[8], led_count; | 126 | uint8_t led[8], led_count; |
| 123 | map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count); | 127 | map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count); |
| @@ -141,6 +145,7 @@ bool process_led_matrix(uint16_t keycode, keyrecord_t *record) { | |||
| 141 | g_any_key_hit = 255; | 145 | g_any_key_hit = 255; |
| 142 | #endif | 146 | #endif |
| 143 | } | 147 | } |
| 148 | */ | ||
| 144 | return true; | 149 | return true; |
| 145 | } | 150 | } |
| 146 | 151 | ||
| @@ -155,22 +160,20 @@ void led_matrix_all_off(void) { | |||
| 155 | 160 | ||
| 156 | // Uniform brightness | 161 | // Uniform brightness |
| 157 | void led_matrix_uniform_brightness(void) { | 162 | void led_matrix_uniform_brightness(void) { |
| 158 | led_matrix_set_index_value_all(led_matrix_config.val); | 163 | uint8_t current_brightness = (LED_MATRIX_MAXIMUM_BRIGHTNESS / BACKLIGHT_LEVELS) * led_matrix_config.val; |
| 164 | if (current_brightness != g_uniform_brightness) { | ||
| 165 | g_uniform_brightness = current_brightness; | ||
| 166 | led_matrix_set_index_value_all(current_brightness); | ||
| 167 | } | ||
| 159 | } | 168 | } |
| 160 | 169 | ||
| 161 | void led_matrix_custom(void) {} | 170 | void led_matrix_custom(void) {} |
| 162 | 171 | ||
| 163 | void led_matrix_task(void) { | 172 | void led_matrix_task(void) { |
| 164 | #ifdef TRACK_PREVIOUS_EFFECT | 173 | if (!led_matrix_config.enable) { |
| 165 | static uint8_t toggle_enable_last = 255; | 174 | led_matrix_all_off(); |
| 166 | #endif | 175 | led_matrix_indicators(); |
| 167 | if (!led_matrix_config.enable) { | 176 | return; |
| 168 | led_matrix_all_off(); | ||
| 169 | led_matrix_indicators(); | ||
| 170 | #ifdef TRACK_PREVIOUS_EFFECT | ||
| 171 | toggle_enable_last = led_matrix_config.enable; | ||
| 172 | #endif | ||
| 173 | return; | ||
| 174 | } | 177 | } |
| 175 | 178 | ||
| 176 | // delay 1 second before driving LEDs or doing anything else | 179 | // delay 1 second before driving LEDs or doing anything else |
| @@ -187,6 +190,7 @@ void led_matrix_task(void) { | |||
| 187 | g_any_key_hit++; | 190 | g_any_key_hit++; |
| 188 | } | 191 | } |
| 189 | 192 | ||
| 193 | /* FIXME: WHY YOU COMMENT OUT?! | ||
| 190 | for (int led = 0; led < LED_DRIVER_LED_COUNT; led++) { | 194 | for (int led = 0; led < LED_DRIVER_LED_COUNT; led++) { |
| 191 | if (g_key_hit[led] < 255) { | 195 | if (g_key_hit[led] < 255) { |
| 192 | if (g_key_hit[led] == 254) | 196 | if (g_key_hit[led] == 254) |
| @@ -200,24 +204,13 @@ void led_matrix_task(void) { | |||
| 200 | led_matrix_uniform_brightness(); | 204 | led_matrix_uniform_brightness(); |
| 201 | return; | 205 | return; |
| 202 | } | 206 | } |
| 203 | 207 | */ | |
| 204 | // Ideally we would also stop sending zeros to the LED driver PWM buffers | 208 | // Ideally we would also stop sending zeros to the LED driver PWM buffers |
| 205 | // while suspended and just do a software shutdown. This is a cheap hack for now. | 209 | // while suspended and just do a software shutdown. This is a cheap hack for now. |
| 206 | bool suspend_backlight = ((g_suspend_state && LED_DISABLE_WHEN_USB_SUSPENDED) || | 210 | bool suspend_backlight = ((g_suspend_state && LED_DISABLE_WHEN_USB_SUSPENDED) || |
| 207 | (LED_DISABLE_AFTER_TIMEOUT > 0 && g_any_key_hit > LED_DISABLE_AFTER_TIMEOUT * 60 * 20)); | 211 | (LED_DISABLE_AFTER_TIMEOUT > 0 && g_any_key_hit > LED_DISABLE_AFTER_TIMEOUT * 60 * 20)); |
| 208 | uint8_t effect = suspend_backlight ? 0 : led_matrix_config.mode; | 212 | uint8_t effect = suspend_backlight ? 0 : led_matrix_config.mode; |
| 209 | 213 | ||
| 210 | #ifdef TRACK_PREVIOUS_EFFECT | ||
| 211 | // Keep track of the effect used last time, | ||
| 212 | // detect change in effect, so each effect can | ||
| 213 | // have an optional initialization. | ||
| 214 | |||
| 215 | static uint8_t effect_last = 255; | ||
| 216 | bool initialize = (effect != effect_last) || (led_matrix_config.enable != toggle_enable_last); | ||
| 217 | effect_last = effect; | ||
| 218 | toggle_enable_last = led_matrix_config.enable; | ||
| 219 | #endif | ||
| 220 | |||
| 221 | // this gets ticked at 20 Hz. | 214 | // this gets ticked at 20 Hz. |
| 222 | // each effect can opt to do calculations | 215 | // each effect can opt to do calculations |
| 223 | // and/or request PWM buffer updates. | 216 | // and/or request PWM buffer updates. |
| @@ -230,10 +223,12 @@ void led_matrix_task(void) { | |||
| 230 | break; | 223 | break; |
| 231 | } | 224 | } |
| 232 | 225 | ||
| 233 | if (! suspend_backlight) { | 226 | if (!suspend_backlight) { |
| 234 | led_matrix_indicators(); | 227 | led_matrix_indicators(); |
| 235 | } | 228 | } |
| 236 | 229 | ||
| 230 | // Tell the LED driver to update its state | ||
| 231 | led_matrix_driver.flush(); | ||
| 237 | } | 232 | } |
| 238 | 233 | ||
| 239 | void led_matrix_indicators(void) { | 234 | void led_matrix_indicators(void) { |
| @@ -404,3 +399,7 @@ void led_matrix_set_value(uint8_t val) { | |||
| 404 | led_matrix_set_value_noeeprom(val); | 399 | led_matrix_set_value_noeeprom(val); |
| 405 | eeconfig_update_led_matrix(led_matrix_config.raw); | 400 | eeconfig_update_led_matrix(led_matrix_config.raw); |
| 406 | } | 401 | } |
| 402 | |||
| 403 | void backlight_set(uint8_t val) { | ||
| 404 | led_matrix_set_value(val); | ||
| 405 | } | ||
diff --git a/quantum/led_matrix.h b/quantum/led_matrix.h index 6db162963..9bf20d044 100644 --- a/quantum/led_matrix.h +++ b/quantum/led_matrix.h | |||
| @@ -112,9 +112,6 @@ uint8_t led_matrix_get_mode(void); | |||
| 112 | void led_matrix_set_value(uint8_t mode); | 112 | void led_matrix_set_value(uint8_t mode); |
| 113 | void led_matrix_set_value_noeeprom(uint8_t mode); | 113 | void led_matrix_set_value_noeeprom(uint8_t mode); |
| 114 | 114 | ||
| 115 | // Hook into the existing backlight API | ||
| 116 | #define backlight_set(val) led_matrix_set_value(val) | ||
| 117 | |||
| 118 | typedef struct { | 115 | typedef struct { |
| 119 | /* Perform any initialisation required for the other driver functions to work. */ | 116 | /* Perform any initialisation required for the other driver functions to work. */ |
| 120 | void (*init)(void); | 117 | void (*init)(void); |
diff --git a/quantum/led_matrix_drivers.c b/quantum/led_matrix_drivers.c index e0f8b2094..21e8a14c6 100644 --- a/quantum/led_matrix_drivers.c +++ b/quantum/led_matrix_drivers.c | |||
| @@ -64,7 +64,8 @@ static void init(void) { | |||
| 64 | IS31FL3733_init(LED_DRIVER_ADDR_4); | 64 | IS31FL3733_init(LED_DRIVER_ADDR_4); |
| 65 | #endif | 65 | #endif |
| 66 | #endif | 66 | #endif |
| 67 | for (int index = 0; index < LED_DRIVER_COUNT; index++) { | 67 | |
| 68 | for (int index = 0; index < LED_DRIVER_LED_COUNT; index++) { | ||
| 68 | #ifdef IS31FL3731 | 69 | #ifdef IS31FL3731 |
| 69 | IS31FL3731_set_led_control_register(index, true); | 70 | IS31FL3731_set_led_control_register(index, true); |
| 70 | #else | 71 | #else |
