Relocate LED driver init code (#22365)

This commit is contained in:
Ryan 2023-11-01 11:53:45 +11:00 committed by GitHub
parent eac8e67888
commit b52aca0af8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
100 changed files with 795 additions and 798 deletions

View file

@ -34,7 +34,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//#define NO_ACTION_ONESHOT
#ifdef RGB_MATRIX_ENABLE
//#include "gpio.h"
// RGB Matrix Animation modes. Explicitly enabled
// For full list of effects, see:
// https://docs.qmk.fm/#/feature_rgb_matrix?id=rgb-matrix-effects
@ -106,7 +105,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# define IS31FL3733_I2C_ADDRESS_1 IS31FL3733_I2C_ADDRESS_GND_GND
# define IS31FL3733_I2C_ADDRESS_2 IS31FL3733_I2C_ADDRESS_GND_GND
# define IS31FL3733_DRIVER_COUNT 2
# define IS31FL3733_LED_COUNT (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)
# define DRIVER_1_LED_TOTAL 64
# define DRIVER_2_LED_TOTAL 55
# define RGB_MATRIX_LED_COUNT (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)
# define RGB_MATRIX_LED_COUNT IS31FL3733_LED_COUNT
#endif

View file

@ -26,6 +26,7 @@
#include <ch.h>
#include <hal.h>
#include "gpio.h"
#ifndef I2C_COUNT
# define I2C_COUNT 1

View file

@ -60,6 +60,19 @@
# define IS31FL3733_GLOBALCURRENT 0xFF
#endif
#ifndef IS31FL3733_SYNC_1
# define IS31FL3733_SYNC_1 IS31FL3733_SYNC_NONE
#endif
#ifndef IS31FL3733_SYNC_2
# define IS31FL3733_SYNC_2 IS31FL3733_SYNC_NONE
#endif
#ifndef IS31FL3733_SYNC_3
# define IS31FL3733_SYNC_3 IS31FL3733_SYNC_NONE
#endif
#ifndef IS31FL3733_SYNC_4
# define IS31FL3733_SYNC_4 IS31FL3733_SYNC_NONE
#endif
// Transfer buffer for TWITransmitData()
uint8_t g_twi_transfer_buffer[20];
@ -125,6 +138,24 @@ bool is31fl3733_write_pwm_buffer(uint8_t index, uint8_t addr, uint8_t *pwm_buffe
return true;
}
void is31fl3733_init_drivers(void) {
i2c_init(&I2CD1, I2C1_SCL_PIN, I2C1_SDA_PIN);
is31fl3733_init(0, IS31FL3733_I2C_ADDRESS_1, IS31FL3733_SYNC_1);
# ifdef USE_I2C2
i2c_init(&I2CD2, I2C2_SCL_PIN, I2C2_SDA_PIN);
is31fl3733_init(1, IS31FL3733_I2C_ADDRESS_2, IS31FL3733_SYNC_2);
# endif
for (int i = 0; i < IS31FL3733_LED_COUNT; i++) {
is31fl3733_set_led_control_register(i, true, true, true);
}
is31fl3733_update_led_control_registers(IS31FL3733_I2C_ADDRESS_1, 0);
# ifdef USE_I2C2
is31fl3733_update_led_control_registers(IS31FL3733_I2C_ADDRESS_2, 1);
# endif
}
void is31fl3733_init(uint8_t bus, uint8_t addr, uint8_t sync) {
// In order to avoid the LEDs being driven with garbage data
// in the LED driver's PWM registers, shutdown is enabled last.
@ -173,7 +204,7 @@ void is31fl3733_init(uint8_t bus, uint8_t addr, uint8_t sync) {
void is31fl3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
is31fl3733_led_t led;
if (index >= 0 && index < RGB_MATRIX_LED_COUNT) {
if (index >= 0 && index < IS31FL3733_LED_COUNT) {
memcpy_P(&led, (&g_is31fl3733_leds[index]), sizeof(led));
if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) {
@ -187,7 +218,7 @@ void is31fl3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
}
void is31fl3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
for (int i = 0; i < RGB_MATRIX_LED_COUNT; i++) {
for (int i = 0; i < IS31FL3733_LED_COUNT; i++) {
is31fl3733_set_color(i, red, green, blue);
}
}

View file

@ -46,8 +46,9 @@ typedef struct is31fl3733_led_t {
uint8_t b;
} __attribute__((packed)) is31fl3733_led_t;
extern const is31fl3733_led_t PROGMEM g_is31fl3733_leds[RGB_MATRIX_LED_COUNT];
extern const is31fl3733_led_t PROGMEM g_is31fl3733_leds[IS31FL3733_LED_COUNT];
void is31fl3733_init_drivers(void);
void is31fl3733_init(uint8_t bus, uint8_t addr, uint8_t sync);
bool is31fl3733_write_register(uint8_t index, uint8_t addr, uint8_t reg, uint8_t data);
bool is31fl3733_write_pwm_buffer(uint8_t index, uint8_t addr, uint8_t *pwm_buffer);
@ -80,6 +81,10 @@ void is31fl3733_flush(void);
#define IS31FL3733_PWM_FREQUENCY_2K1_HZ 0x03
#define IS31FL3733_PWM_FREQUENCY_1K05_HZ 0x04
#define IS31FL3733_SYNC_NONE 0b00
#define IS31FL3733_SYNC_MASTER 0b01
#define IS31FL3733_SYNC_SLAVE 0b10
#define A_1 0x00
#define A_2 0x01
#define A_3 0x02

View file

@ -16,30 +16,10 @@
#ifdef RGB_MATRIX_ENABLE
# include "rgb_matrix.h"
# include "i2c_master.h"
# include "is31fl3733-dual.h"
# include "gpio.h"
static void init(void) {
i2c_init(&I2CD1, I2C1_SCL_PIN, I2C1_SDA_PIN);
is31fl3733_init(0, IS31FL3733_I2C_ADDRESS_1, 0);
# ifdef USE_I2C2
i2c_init(&I2CD2, I2C2_SCL_PIN, I2C2_SDA_PIN);
is31fl3733_init(1, IS31FL3733_I2C_ADDRESS_2, 0);
# endif
for (int index = 0; index < RGB_MATRIX_LED_COUNT; index++) {
bool enabled = true;
// This only caches it for later
is31fl3733_set_led_control_register(index, enabled, enabled, enabled);
}
is31fl3733_update_led_control_registers(IS31FL3733_I2C_ADDRESS_1, 0);
# ifdef USE_I2C2
is31fl3733_update_led_control_registers(IS31FL3733_I2C_ADDRESS_2, 1);
# endif
}
const rgb_matrix_driver_t rgb_matrix_driver = {
.init = init,
.init = is31fl3733_init_drivers,
.flush = is31fl3733_flush,
.set_color = is31fl3733_set_color,
.set_color_all = is31fl3733_set_color_all,

View file

@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef RGB_MATRIX_ENABLE
# include "is31fl3733-dual.h"
const is31fl3733_led_t PROGMEM g_is31fl3733_leds[RGB_MATRIX_LED_COUNT] = {
const is31fl3733_led_t PROGMEM g_is31fl3733_leds[IS31FL3733_LED_COUNT] = {
{ 0, B_1, A_1, C_1 },
{ 0, B_2, A_2, C_2 },
{ 0, B_3, A_3, C_3 },

View file

@ -1,5 +1,5 @@
ifeq ($(strip $(RGB_MATRIX_ENABLE)), yes)
# Additional files for RGB lighting
SRC += k_type-rgbdriver.c
QUANTUM_LIB_SRC += i2c_master.c is31fl3733-dual.c
SRC += k_type-rgbdriver.c is31fl3733-dual.c
QUANTUM_LIB_SRC += i2c_master.c
endif