From 3d172021bef1dc5633916a188c0d66bb14f26348 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Thu, 31 Aug 2023 19:24:39 +0700 Subject: [PATCH 01/26] Added support IS31FL3729 LED Driver --- builddefs/common_features.mk | 9 +- drivers/led/issi/is31fl3729.c | 249 +++++++++++++++++ drivers/led/issi/is31fl3729.h | 340 ++++++++++++++++++++++++ quantum/rgb_matrix/rgb_matrix_drivers.c | 8 + 4 files changed, 605 insertions(+), 1 deletion(-) create mode 100644 drivers/led/issi/is31fl3729.c create mode 100644 drivers/led/issi/is31fl3729.h diff --git a/builddefs/common_features.mk b/builddefs/common_features.mk index 513a3678a947..b38db937bf6a 100644 --- a/builddefs/common_features.mk +++ b/builddefs/common_features.mk @@ -437,7 +437,7 @@ endif RGB_MATRIX_ENABLE ?= no -VALID_RGB_MATRIX_TYPES := aw20216s is31fl3218 is31fl3731 is31fl3733 is31fl3736 is31fl3737 is31fl3741 is31fl3742a is31fl3743a is31fl3745 is31fl3746a snled27351 ws2812 custom +VALID_RGB_MATRIX_TYPES := aw20216s is31fl3218 is31fl3729 is31fl3731 is31fl3733 is31fl3736 is31fl3737 is31fl3741 is31fl3742a is31fl3743a is31fl3745 is31fl3746a snled27351 ws2812 custom ifeq ($(strip $(RGB_MATRIX_ENABLE)), yes) ifeq ($(filter $(RGB_MATRIX_DRIVER),$(VALID_RGB_MATRIX_TYPES)),) $(call CATASTROPHIC_ERROR,Invalid RGB_MATRIX_DRIVER,RGB_MATRIX_DRIVER="$(RGB_MATRIX_DRIVER)" is not a valid matrix type) @@ -468,6 +468,13 @@ ifeq ($(strip $(RGB_MATRIX_ENABLE)), yes) SRC += is31fl3218.c endif + ifeq ($(strip $(RGB_MATRIX_DRIVER)), is31fl3729) + OPT_DEFS += -DIS31FL3729 -DSTM32_I2C -DHAL_USE_I2C=TRUE + COMMON_VPATH += $(DRIVER_PATH)/led/issi + SRC += is31fl3729.c + QUANTUM_LIB_SRC += i2c_master.c + endif + ifeq ($(strip $(RGB_MATRIX_DRIVER)), is31fl3731) I2C_DRIVER_REQUIRED = yes COMMON_VPATH += $(DRIVER_PATH)/led/issi diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c new file mode 100644 index 000000000000..c4115617de30 --- /dev/null +++ b/drivers/led/issi/is31fl3729.c @@ -0,0 +1,249 @@ +/* Copyright 2017 Jason Williams + * Copyright 2018 Jack Humbert + * Copyright 2018 Yiancar + * Copyright 2020 MelGeek + * Copyright 2023 HorrorTroll + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "wait.h" + +#include "is31fl3729.h" +#include +#include "i2c_master.h" +#include "progmem.h" + +// This is a 7-bit address, that gets left-shifted and bit 0 +// set to 0 for write, 1 for read (as per I2C protocol) +// The address will vary depending on your wiring: +// 00 <-> GND +// 01 <-> SCL +// 10 <-> SDA +// 11 <-> VCC +// ADDR represents A2:A1 of the 7-bit address. +// The result is: 0b01101(ADDR) +#define ISSI_ADDR_DEFAULT 0x68 + +// Registers +#define ISSI_REG_SCALING 0x90 +#define ISSI_REG_CONFIGURATION 0xA0 +#define ISSI_REG_GLOBALCURRENT 0xA1 +#define ISSI_REG_PULLDOWNUP 0xB0 +#define ISSI_REG_RESET 0xCF +#define ISSI_REG_PWM_SET 0xB2 + +// Set defaults for Timeout and Persistence +#ifndef ISSI_TIMEOUT +# define ISSI_TIMEOUT 100 +#endif +#ifndef ISSI_PERSISTENCE +# define ISSI_PERSISTENCE 0 +#endif + +// Set defaults for Registers +#ifndef ISSI_CONFIGURATION +# define ISSI_CONFIGURATION 0x01 +#endif +#ifndef ISSI_GLOBALCURRENT +# define ISSI_GLOBALCURRENT 0xFF +#endif +#ifndef ISSI_PULLDOWNUP +# define ISSI_PULLDOWNUP 0x00 +#endif +#ifndef ISSI_PWM_SET +# define ISSI_PWM_SET 0x01 +#endif + +// Set buffer sizes +#ifndef ISSI_MATRIX_16X8 +# define ISSI_MAX_LEDS 128 +# define ISSI_MAX_SCALINGS 16 +#else +# define ISSI_MAX_LEDS 135 +# define ISSI_MAX_SCALINGS 15 +#endif + +// Transfer buffer for TWITransmitData() +uint8_t g_twi_transfer_buffer[20] = {0xFF}; + +// These buffers match the PWM & scaling registers. +// Storing them like this is optimal for I2C transfers to the registers. +uint8_t g_pwm_buffer[DRIVER_COUNT][ISSI_MAX_LEDS]; +bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; + +uint8_t g_scaling_registers[DRIVER_COUNT][ISSI_MAX_SCALINGS]; +bool g_scaling_registers_update_required[DRIVER_COUNT] = {false}; + +void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { + // Set register address and register data ready to write + g_twi_transfer_buffer[0] = reg; + g_twi_transfer_buffer[1] = data; + +#if ISSI_PERSISTENCE > 0 + for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break; + } +#else + i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT); +#endif +} + +bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { + // transmit PWM registers in 15 transfers of 9 bytes + // g_twi_transfer_buffer[] is 20 bytes + + // iterate over the pwm_buffer contents at 9 byte intervals + for (int i = 0; i < 135; i += 9) { + g_twi_transfer_buffer[0] = i; + // copy the data from i to i+15 + // device will auto-increment register for data after the first byte + // thus this sets registers 0x01-0x10, 0x11-0x20, etc. in one transfer + memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 9); + +#if ISSI_PERSISTENCE > 0 + for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 10, ISSI_TIMEOUT) != 0) { + return false; + } + } +#else + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 10, ISSI_TIMEOUT) != 0) { + return false; + } +#endif + } + + return true; +} + +void is31fl3729_init(uint8_t addr) { + // In order to avoid the LEDs being driven with garbage data + // in the LED driver's PWM registers, shutdown is enabled last. + // Set up the mode and other settings, clear the PWM registers, + // then disable software shutdown. + + // Set PWM on all LEDs to 0 +#ifndef ISSI_MATRIX_16X8 + for (int i = CS1_SW1; i <= CS16_SW8; i++) { + is31fl3729_write_register(addr, i, 0x00); + } +#else + for (int i = CS1_SW1; i <= CS15_SW9; i++) { + is31fl3729_write_register(addr, i, 0x00); + } +#endif + + // Set Pull up & Down for SWx CSy + is31fl3729_write_register(addr, ISSI_REG_PULLDOWNUP, ISSI_PULLDOWNUP); + + // Set PWM Frequency Register if applicable + is31fl3729_write_register(addr, ISSI_REG_PWM_SET, ISSI_PWM_SET); + + // Set Golbal Current Control Register + is31fl3729_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); + + // Set to Normal operation + is31fl3729_write_register(addr, ISSI_REG_CONFIGURATION, ISSI_CONFIGURATION); + + // Wait 10ms to ensure the device has woken up. + wait_ms(10); +} + +void is31fl3729_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { + is31_led led; + if (index >= 0 && index < RGB_MATRIX_LED_COUNT) { + memcpy_P(&led, (&g_is31_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) { + return; + } + g_pwm_buffer_update_required[led.driver] = true; + g_pwm_buffer[led.driver][led.r] = red; + g_pwm_buffer[led.driver][led.g] = green; + g_pwm_buffer[led.driver][led.b] = blue; + } +} + +void is31fl3729_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { + for (int i = 0; i < RGB_MATRIX_LED_COUNT; i++) { + is31fl3729_set_color(i, red, green, blue); + } +} + +void is31fl3729_set_led_control_register(uint8_t index, bool red, bool green, bool blue) { + is31_led led; + memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); + + if (red) { + g_scaling_registers[led.driver][led.r] = 0xFF; + } else { + g_scaling_registers[led.driver][led.r] = 0x00; + } + + if (green) { + g_scaling_registers[led.driver][led.g] = 0xFF; + } else { + g_scaling_registers[led.driver][led.g] = 0x00; + } + + if (blue) { + g_scaling_registers[led.driver][led.b] = 0xFF; + } else { + g_scaling_registers[led.driver][led.b] = 0x00; + } + + g_scaling_registers_update_required[led.driver] = true; +} + +void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index) { + if (g_pwm_buffer_update_required[index]) { + is31fl3729_write_pwm_buffer(addr, g_pwm_buffer[index]); + } + + g_pwm_buffer_update_required[index] = false; +} + +void is31fl3729_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue) { + g_pwm_buffer[pled->driver][pled->r] = red; + g_pwm_buffer[pled->driver][pled->g] = green; + g_pwm_buffer[pled->driver][pled->b] = blue; + + g_pwm_buffer_update_required[pled->driver] = true; +} + +void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index) { + if (g_scaling_registers_update_required[index]) { +#ifndef ISSI_MATRIX_16X8 + // 0x90 to 0x9F + for (int i = 0; i < 16; i++) { + is31fl3729_write_register(addr, ISSI_REG_SCALING + i, g_scaling_registers[index][i]); + } +#else + // 0x90 to 0x9E + for (int i = 0; i < 15; i++) { + is31fl3729_write_register(addr, ISSI_REG_SCALING + i, g_scaling_registers[index][i]); + } +#endif + g_scaling_registers_update_required[index] = false; + } +} + +void is31fl3729_set_scaling_registers(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue) { + g_scaling_registers[pled->driver][pled->r] = red; + g_scaling_registers[pled->driver][pled->g] = green; + g_scaling_registers[pled->driver][pled->b] = blue; + + g_scaling_registers_update_required[pled->driver] = true; +} diff --git a/drivers/led/issi/is31fl3729.h b/drivers/led/issi/is31fl3729.h new file mode 100644 index 000000000000..7e2219f0f69b --- /dev/null +++ b/drivers/led/issi/is31fl3729.h @@ -0,0 +1,340 @@ +/* Copyright 2017 Jason Williams + * Copyright 2018 Jack Humbert + * Copyright 2018 Yiancar + * Copyright 2020 MelGeek + * Copyright 2023 HorrorTroll + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include +#include "progmem.h" + +typedef struct is31_led { + uint32_t driver : 2; + uint32_t r; + uint32_t g; + uint32_t b; +} __attribute__((packed)) is31_led; + +extern const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT]; + +void is31fl3729_init(uint8_t addr); +void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data); +bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); + +void is31fl3729_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); +void is31fl3729_set_color_all(uint8_t red, uint8_t green, uint8_t blue); + +void is31fl3729_set_led_control_register(uint8_t index, bool red, bool green, bool blue); + +// This should not be called from an interrupt +// (eg. from a timer interrupt). +// Call this while idle (in between matrix scans). +// If the buffer is dirty, it will update the driver with the buffer. +void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index); +void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index); +void is31fl3729_set_scaling_registers(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue); + +void is31fl3729_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue); + +// Map CS SW locations to order in PWM / Scaling buffers +// This matches the ORDER in the Datasheet Register not the POSITION +// It will always count from 0x01 to (ISSI_MAX_LEDS - 1) +#ifndef ISSI_MATRIX_16X8 +# define CS1_SW1 0x01 +# define CS2_SW1 0x02 +# define CS3_SW1 0x03 +# define CS4_SW1 0x04 +# define CS5_SW1 0x05 +# define CS6_SW1 0x06 +# define CS7_SW1 0x07 +# define CS8_SW1 0x08 +# define CS9_SW1 0x09 +# define CS10_SW1 0x0A +# define CS11_SW1 0x0B +# define CS12_SW1 0x0C +# define CS13_SW1 0x0D +# define CS14_SW1 0x0E +# define CS15_SW1 0x0F +# define CS16_SW1 0x10 + +# define CS1_SW2 0x11 +# define CS2_SW2 0x12 +# define CS3_SW2 0x13 +# define CS4_SW2 0x14 +# define CS5_SW2 0x15 +# define CS6_SW2 0x16 +# define CS7_SW2 0x17 +# define CS8_SW2 0x18 +# define CS9_SW2 0x19 +# define CS10_SW2 0x1A +# define CS11_SW2 0x1B +# define CS12_SW2 0x1C +# define CS13_SW2 0x1D +# define CS14_SW2 0x1E +# define CS15_SW2 0x1F +# define CS16_SW2 0x20 + +# define CS1_SW3 0x21 +# define CS2_SW3 0x22 +# define CS3_SW3 0x23 +# define CS4_SW3 0x24 +# define CS5_SW3 0x25 +# define CS6_SW3 0x26 +# define CS7_SW3 0x27 +# define CS8_SW3 0x28 +# define CS9_SW3 0x29 +# define CS10_SW3 0x2A +# define CS11_SW3 0x2B +# define CS12_SW3 0x2C +# define CS13_SW3 0x2D +# define CS14_SW3 0x2E +# define CS15_SW3 0x2F +# define CS16_SW3 0x30 + +# define CS1_SW4 0x31 +# define CS2_SW4 0x32 +# define CS3_SW4 0x33 +# define CS4_SW4 0x34 +# define CS5_SW4 0x35 +# define CS6_SW4 0x36 +# define CS7_SW4 0x37 +# define CS8_SW4 0x38 +# define CS9_SW4 0x39 +# define CS10_SW4 0x3A +# define CS11_SW4 0x3B +# define CS12_SW4 0x3C +# define CS13_SW4 0x3D +# define CS14_SW4 0x3E +# define CS15_SW4 0x3F +# define CS16_SW4 0x40 + +# define CS1_SW5 0x41 +# define CS2_SW5 0x42 +# define CS3_SW5 0x43 +# define CS4_SW5 0x44 +# define CS5_SW5 0x45 +# define CS6_SW5 0x46 +# define CS7_SW5 0x47 +# define CS8_SW5 0x48 +# define CS9_SW5 0x49 +# define CS10_SW5 0x4A +# define CS11_SW5 0x4B +# define CS12_SW5 0x4C +# define CS13_SW5 0x4D +# define CS14_SW5 0x4E +# define CS15_SW5 0x4F +# define CS16_SW5 0x50 + +# define CS1_SW6 0x51 +# define CS2_SW6 0x52 +# define CS3_SW6 0x53 +# define CS4_SW6 0x54 +# define CS5_SW6 0x55 +# define CS6_SW6 0x56 +# define CS7_SW6 0x57 +# define CS8_SW6 0x58 +# define CS9_SW6 0x59 +# define CS10_SW6 0x5A +# define CS11_SW6 0x5B +# define CS12_SW6 0x5C +# define CS13_SW6 0x5D +# define CS14_SW6 0x5E +# define CS15_SW6 0x5F +# define CS16_SW6 0x60 + +# define CS1_SW7 0x61 +# define CS2_SW7 0x62 +# define CS3_SW7 0x63 +# define CS4_SW7 0x64 +# define CS5_SW7 0x65 +# define CS6_SW7 0x66 +# define CS7_SW7 0x67 +# define CS8_SW7 0x68 +# define CS9_SW7 0x69 +# define CS10_SW7 0x6A +# define CS11_SW7 0x6B +# define CS12_SW7 0x6C +# define CS13_SW7 0x6D +# define CS14_SW7 0x6E +# define CS15_SW7 0x6F +# define CS16_SW7 0x70 + +# define CS1_SW8 0x71 +# define CS2_SW8 0x72 +# define CS3_SW8 0x73 +# define CS4_SW8 0x74 +# define CS5_SW8 0x75 +# define CS6_SW8 0x76 +# define CS7_SW8 0x77 +# define CS8_SW8 0x78 +# define CS9_SW8 0x79 +# define CS10_SW8 0x7A +# define CS11_SW8 0x7B +# define CS12_SW8 0x7C +# define CS13_SW8 0x7D +# define CS14_SW8 0x7E +# define CS15_SW8 0x7F +# define CS16_SW8 0x80 + +#else + +# define CS1_SW1 0x01 +# define CS2_SW1 0x02 +# define CS3_SW1 0x03 +# define CS4_SW1 0x04 +# define CS5_SW1 0x05 +# define CS6_SW1 0x06 +# define CS7_SW1 0x07 +# define CS8_SW1 0x08 +# define CS9_SW1 0x09 +# define CS10_SW1 0x0A +# define CS11_SW1 0x0B +# define CS12_SW1 0x0C +# define CS13_SW1 0x0D +# define CS14_SW1 0x0E +# define CS15_SW1 0x0F + +# define CS1_SW2 0x11 +# define CS2_SW2 0x12 +# define CS3_SW2 0x13 +# define CS4_SW2 0x14 +# define CS5_SW2 0x15 +# define CS6_SW2 0x16 +# define CS7_SW2 0x17 +# define CS8_SW2 0x18 +# define CS9_SW2 0x19 +# define CS10_SW2 0x1A +# define CS11_SW2 0x1B +# define CS12_SW2 0x1C +# define CS13_SW2 0x1D +# define CS14_SW2 0x1E +# define CS15_SW2 0x1F + +# define CS1_SW3 0x21 +# define CS2_SW3 0x22 +# define CS3_SW3 0x23 +# define CS4_SW3 0x24 +# define CS5_SW3 0x25 +# define CS6_SW3 0x26 +# define CS7_SW3 0x27 +# define CS8_SW3 0x28 +# define CS9_SW3 0x29 +# define CS10_SW3 0x2A +# define CS11_SW3 0x2B +# define CS12_SW3 0x2C +# define CS13_SW3 0x2D +# define CS14_SW3 0x2E +# define CS15_SW3 0x2F + +# define CS1_SW4 0x31 +# define CS2_SW4 0x32 +# define CS3_SW4 0x33 +# define CS4_SW4 0x34 +# define CS5_SW4 0x35 +# define CS6_SW4 0x36 +# define CS7_SW4 0x37 +# define CS8_SW4 0x38 +# define CS9_SW4 0x39 +# define CS10_SW4 0x3A +# define CS11_SW4 0x3B +# define CS12_SW4 0x3C +# define CS13_SW4 0x3D +# define CS14_SW4 0x3E +# define CS15_SW4 0x3F + +# define CS1_SW5 0x41 +# define CS2_SW5 0x42 +# define CS3_SW5 0x43 +# define CS4_SW5 0x44 +# define CS5_SW5 0x45 +# define CS6_SW5 0x46 +# define CS7_SW5 0x47 +# define CS8_SW5 0x48 +# define CS9_SW5 0x49 +# define CS10_SW5 0x4A +# define CS11_SW5 0x4B +# define CS12_SW5 0x4C +# define CS13_SW5 0x4D +# define CS14_SW5 0x4E +# define CS15_SW5 0x4F + +# define CS1_SW6 0x51 +# define CS2_SW6 0x52 +# define CS3_SW6 0x53 +# define CS4_SW6 0x54 +# define CS5_SW6 0x55 +# define CS6_SW6 0x56 +# define CS7_SW6 0x57 +# define CS8_SW6 0x58 +# define CS9_SW6 0x59 +# define CS10_SW6 0x5A +# define CS11_SW6 0x5B +# define CS12_SW6 0x5C +# define CS13_SW6 0x5D +# define CS14_SW6 0x5E +# define CS15_SW6 0x5F + +# define CS1_SW7 0x61 +# define CS2_SW7 0x62 +# define CS3_SW7 0x63 +# define CS4_SW7 0x64 +# define CS5_SW7 0x65 +# define CS6_SW7 0x66 +# define CS7_SW7 0x67 +# define CS8_SW7 0x68 +# define CS9_SW7 0x69 +# define CS10_SW7 0x6A +# define CS11_SW7 0x6B +# define CS12_SW7 0x6C +# define CS13_SW7 0x6D +# define CS14_SW7 0x6E +# define CS15_SW7 0x6F + +# define CS1_SW8 0x71 +# define CS2_SW8 0x72 +# define CS3_SW8 0x73 +# define CS4_SW8 0x74 +# define CS5_SW8 0x75 +# define CS6_SW8 0x76 +# define CS7_SW8 0x77 +# define CS8_SW8 0x78 +# define CS9_SW8 0x79 +# define CS10_SW8 0x7A +# define CS11_SW8 0x7B +# define CS12_SW8 0x7C +# define CS13_SW8 0x7D +# define CS14_SW8 0x7E +# define CS15_SW8 0x7F + +# define CS1_SW9 0x81 +# define CS2_SW9 0x82 +# define CS3_SW9 0x83 +# define CS4_SW9 0x84 +# define CS5_SW9 0x85 +# define CS6_SW9 0x86 +# define CS7_SW9 0x87 +# define CS8_SW9 0x88 +# define CS9_SW9 0x89 +# define CS10_SW9 0x8A +# define CS11_SW9 0x8B +# define CS12_SW9 0x8C +# define CS13_SW9 0x8D +# define CS14_SW9 0x8E +# define CS15_SW9 0x8F +#endif diff --git a/quantum/rgb_matrix/rgb_matrix_drivers.c b/quantum/rgb_matrix/rgb_matrix_drivers.c index b5e539657d58..95d1e884f09d 100644 --- a/quantum/rgb_matrix/rgb_matrix_drivers.c +++ b/quantum/rgb_matrix/rgb_matrix_drivers.c @@ -36,6 +36,14 @@ const rgb_matrix_driver_t rgb_matrix_driver = { .set_color_all = is31fl3218_set_color_all, }; +#elif defined(RGB_MATRIX_IS31FL3729) +const rgb_matrix_driver_t rgb_matrix_driver = { + .init = is31fl3729_init_drivers, + .flush = is31fl3729_flush, + .set_color = is31fl3729_set_color, + .set_color_all = is31fl3729_set_color_all, +}; + #elif defined(RGB_MATRIX_IS31FL3731) const rgb_matrix_driver_t rgb_matrix_driver = { .init = is31fl3731_init_drivers, From 771e87a4809ce6dfdd1e839e192f446133f0edd2 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Sat, 2 Sep 2023 09:28:42 +0700 Subject: [PATCH 02/26] Update driver code --- drivers/led/issi/is31fl3729.c | 41 ++++++++++++++++------------------- drivers/led/issi/is31fl3729.h | 2 +- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index c4115617de30..9ee71764b399 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -60,14 +60,14 @@ # define ISSI_GLOBALCURRENT 0xFF #endif #ifndef ISSI_PULLDOWNUP -# define ISSI_PULLDOWNUP 0x00 +# define ISSI_PULLDOWNUP 0x33 #endif #ifndef ISSI_PWM_SET # define ISSI_PWM_SET 0x01 #endif // Set buffer sizes -#ifndef ISSI_MATRIX_16X8 +#ifdef ISSI_MATRIX_16X8 # define ISSI_MAX_LEDS 128 # define ISSI_MAX_SCALINGS 16 #else @@ -81,7 +81,7 @@ uint8_t g_twi_transfer_buffer[20] = {0xFF}; // These buffers match the PWM & scaling registers. // Storing them like this is optimal for I2C transfers to the registers. uint8_t g_pwm_buffer[DRIVER_COUNT][ISSI_MAX_LEDS]; -bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; +bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; uint8_t g_scaling_registers[DRIVER_COUNT][ISSI_MAX_SCALINGS]; bool g_scaling_registers_update_required[DRIVER_COUNT] = {false}; @@ -101,28 +101,36 @@ void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { } bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { - // transmit PWM registers in 15 transfers of 9 bytes + // transmit PWM registers in 15 transfers of ISSI_MAX_SCALINGS bytes // g_twi_transfer_buffer[] is 20 bytes // iterate over the pwm_buffer contents at 9 byte intervals - for (int i = 0; i < 135; i += 9) { - g_twi_transfer_buffer[0] = i; - // copy the data from i to i+15 + + // offset due to missing parts IF using 15x9 + int offset = 0; + for (int i = 1; i <= ISSI_MAX_LEDS; i += ISSI_MAX_SCALINGS) { + g_twi_transfer_buffer[0] = i + offset; + // copy the data from i to i+ISSI_MAX_SCALINGS // device will auto-increment register for data after the first byte // thus this sets registers 0x01-0x10, 0x11-0x20, etc. in one transfer - memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 9); + memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, ISSI_MAX_SCALINGS); #if ISSI_PERSISTENCE > 0 for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 10, ISSI_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, ISSI_MAX_SCALINGS + 1, ISSI_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 10, ISSI_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, ISSI_MAX_SCALINGS + 1, ISSI_TIMEOUT) != 0) { return false; } #endif + +#ifdef ISSI_MATRIX_16X8 + // using 15x9 + offset++; +#endif } return true; @@ -134,17 +142,6 @@ void is31fl3729_init(uint8_t addr) { // Set up the mode and other settings, clear the PWM registers, // then disable software shutdown. - // Set PWM on all LEDs to 0 -#ifndef ISSI_MATRIX_16X8 - for (int i = CS1_SW1; i <= CS16_SW8; i++) { - is31fl3729_write_register(addr, i, 0x00); - } -#else - for (int i = CS1_SW1; i <= CS15_SW9; i++) { - is31fl3729_write_register(addr, i, 0x00); - } -#endif - // Set Pull up & Down for SWx CSy is31fl3729_write_register(addr, ISSI_REG_PULLDOWNUP, ISSI_PULLDOWNUP); @@ -225,7 +222,7 @@ void is31fl3729_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_scaling_registers_update_required[index]) { -#ifndef ISSI_MATRIX_16X8 +#ifdef ISSI_MATRIX_16X8 // 0x90 to 0x9F for (int i = 0; i < 16; i++) { is31fl3729_write_register(addr, ISSI_REG_SCALING + i, g_scaling_registers[index][i]); diff --git a/drivers/led/issi/is31fl3729.h b/drivers/led/issi/is31fl3729.h index 7e2219f0f69b..ec176a3d1770 100644 --- a/drivers/led/issi/is31fl3729.h +++ b/drivers/led/issi/is31fl3729.h @@ -55,7 +55,7 @@ void is31fl3729_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, // Map CS SW locations to order in PWM / Scaling buffers // This matches the ORDER in the Datasheet Register not the POSITION // It will always count from 0x01 to (ISSI_MAX_LEDS - 1) -#ifndef ISSI_MATRIX_16X8 +#ifdef ISSI_MATRIX_16X8 # define CS1_SW1 0x01 # define CS2_SW1 0x02 # define CS3_SW1 0x03 From a9ee959ef793b1a81a0a25bc1541ff0979dea207 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Sun, 3 Sep 2023 15:16:25 +0700 Subject: [PATCH 03/26] Fix up buggy PWM and delete unused functions --- drivers/led/issi/is31fl3729.c | 50 ++++++++++------------------------- drivers/led/issi/is31fl3729.h | 4 +-- 2 files changed, 16 insertions(+), 38 deletions(-) diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index 9ee71764b399..01727d585f07 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -3,6 +3,7 @@ * Copyright 2018 Yiancar * Copyright 2020 MelGeek * Copyright 2023 HorrorTroll + * Copyright 2023 Harrison Chan (Xelus) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -76,7 +77,7 @@ #endif // Transfer buffer for TWITransmitData() -uint8_t g_twi_transfer_buffer[20] = {0xFF}; +uint8_t g_twi_transfer_buffer[20]; // These buffers match the PWM & scaling registers. // Storing them like this is optimal for I2C transfers to the registers. @@ -104,12 +105,9 @@ bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // transmit PWM registers in 15 transfers of ISSI_MAX_SCALINGS bytes // g_twi_transfer_buffer[] is 20 bytes - // iterate over the pwm_buffer contents at 9 byte intervals - - // offset due to missing parts IF using 15x9 - int offset = 0; + // iterate over the pwm_buffer contents at ISSI_MAX_SCALINGS byte intervals for (int i = 1; i <= ISSI_MAX_LEDS; i += ISSI_MAX_SCALINGS) { - g_twi_transfer_buffer[0] = i + offset; + g_twi_transfer_buffer[0] = i; // copy the data from i to i+ISSI_MAX_SCALINGS // device will auto-increment register for data after the first byte // thus this sets registers 0x01-0x10, 0x11-0x20, etc. in one transfer @@ -126,11 +124,6 @@ bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { return false; } #endif - -#ifdef ISSI_MATRIX_16X8 - // using 15x9 - offset++; -#endif } return true; @@ -179,28 +172,21 @@ void is31fl3729_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { } } -void is31fl3729_set_led_control_register(uint8_t index, bool red, bool green, bool blue) { +void is31fl3729_set_led_control_register(uint8_t index) { is31_led led; memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); - if (red) { - g_scaling_registers[led.driver][led.r] = 0xFF; - } else { - g_scaling_registers[led.driver][led.r] = 0x00; - } - - if (green) { - g_scaling_registers[led.driver][led.g] = 0xFF; - } else { - g_scaling_registers[led.driver][led.g] = 0x00; +#ifdef ISSI_MATRIX_16X8 + // 0x90 to 0x9F + for (int i = 0; i < 16; i++) { + g_scaling_registers[led.driver][i] = 0xFF; } - - if (blue) { - g_scaling_registers[led.driver][led.b] = 0xFF; - } else { - g_scaling_registers[led.driver][led.b] = 0x00; +#else + // 0x90 to 0x9E + for (int i = 0; i < 15; i++) { + g_scaling_registers[led.driver][i] = 0xFF; } - +#endif g_scaling_registers_update_required[led.driver] = true; } @@ -236,11 +222,3 @@ void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index) { g_scaling_registers_update_required[index] = false; } } - -void is31fl3729_set_scaling_registers(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue) { - g_scaling_registers[pled->driver][pled->r] = red; - g_scaling_registers[pled->driver][pled->g] = green; - g_scaling_registers[pled->driver][pled->b] = blue; - - g_scaling_registers_update_required[pled->driver] = true; -} diff --git a/drivers/led/issi/is31fl3729.h b/drivers/led/issi/is31fl3729.h index ec176a3d1770..1be4a2aba886 100644 --- a/drivers/led/issi/is31fl3729.h +++ b/drivers/led/issi/is31fl3729.h @@ -3,6 +3,7 @@ * Copyright 2018 Yiancar * Copyright 2020 MelGeek * Copyright 2023 HorrorTroll + * Copyright 2023 Harrison Chan (Xelus) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,7 +41,7 @@ bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); void is31fl3729_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); void is31fl3729_set_color_all(uint8_t red, uint8_t green, uint8_t blue); -void is31fl3729_set_led_control_register(uint8_t index, bool red, bool green, bool blue); +void is31fl3729_set_led_control_register(uint8_t index); // This should not be called from an interrupt // (eg. from a timer interrupt). @@ -48,7 +49,6 @@ void is31fl3729_set_led_control_register(uint8_t index, bool red, bool green, bo // If the buffer is dirty, it will update the driver with the buffer. void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index); void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index); -void is31fl3729_set_scaling_registers(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue); void is31fl3729_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue); From e255ad0bb7b49f1800c62bfe8d066ad234cf73b4 Mon Sep 17 00:00:00 2001 From: Xelus22 Date: Mon, 4 Sep 2023 18:08:56 +0700 Subject: [PATCH 04/26] Initial IS31FL3729 cleanup --- drivers/led/issi/is31fl3729.c | 96 +++++++++++++++++++++++------------ 1 file changed, 64 insertions(+), 32 deletions(-) diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index 01727d585f07..2c460f41f482 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -55,7 +55,8 @@ // Set defaults for Registers #ifndef ISSI_CONFIGURATION -# define ISSI_CONFIGURATION 0x01 +# define ISSI_CONFIGURATION_15x9 0x01 +# define ISSI_CONFIGURATION_16x8 0x11 #endif #ifndef ISSI_GLOBALCURRENT # define ISSI_GLOBALCURRENT 0xFF @@ -68,13 +69,41 @@ #endif // Set buffer sizes -#ifdef ISSI_MATRIX_16X8 -# define ISSI_MAX_LEDS 128 -# define ISSI_MAX_SCALINGS 16 +#define ISSI_MAX_LEDS 135 +#define ISSI_MAX_SCALINGS 16 + +#ifdef DRIVER_1_15x9 +# define DRIVER_1_CONFIG_15x9 true +#else +# define DRIVER_1_CONFIG_15x9 false +#endif +#ifdef DRIVER_2_15x9 +# define DRIVER_2_CONFIG_15x9 true +#else +# define DRIVER_2_CONFIG_15x9 false +#endif +#ifdef DRIVER_3_15x9 +# define DRIVER_3_CONFIG_15x9 true +#else +# define DRIVER_3_CONFIG_15x9 false +#endif +#ifdef DRIVER_4_15x9 +# define DRIVER_4_CONFIG_15x9 true #else -# define ISSI_MAX_LEDS 135 -# define ISSI_MAX_SCALINGS 15 +# define DRIVER_4_CONFIG_15x9 false +#endif +// buffer for runtime check if it is configured as 16x8 or 15x9 +const bool g_driver_config_15x9[DRIVER_COUNT] = {DRIVER_1_CONFIG_15x9 +#ifdef DRIVER_ADDR_2 + DRIVER_2_CONFIG_15x9 +#endif +#ifdef DRIVER_ADDR_3 + DRIVER_3_CONFIG_15x9 #endif +#ifdef DRIVER_ADDR_4 + DRIVER_4_CONFIG_15x9 +#endif +} // Transfer buffer for TWITransmitData() uint8_t g_twi_transfer_buffer[20]; @@ -84,8 +113,8 @@ uint8_t g_twi_transfer_buffer[20]; uint8_t g_pwm_buffer[DRIVER_COUNT][ISSI_MAX_LEDS]; bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; -uint8_t g_scaling_registers[DRIVER_COUNT][ISSI_MAX_SCALINGS]; -bool g_scaling_registers_update_required[DRIVER_COUNT] = {false}; +uint8_t g_scaling_registers[DRIVER_COUNT][ISSI_MAX_SCALINGS] = {0}; +bool g_scaling_registers_update_required[DRIVER_COUNT] = {false}; void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { // Set register address and register data ready to write @@ -102,16 +131,15 @@ void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { } bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { - // transmit PWM registers in 15 transfers of ISSI_MAX_SCALINGS bytes - // g_twi_transfer_buffer[] is 20 bytes - // iterate over the pwm_buffer contents at ISSI_MAX_SCALINGS byte intervals + // datasheet does not mention it, but it auto-increments in 15x9 mode, and + // hence does not require us to skip any addresses for (int i = 1; i <= ISSI_MAX_LEDS; i += ISSI_MAX_SCALINGS) { g_twi_transfer_buffer[0] = i; // copy the data from i to i+ISSI_MAX_SCALINGS // device will auto-increment register for data after the first byte // thus this sets registers 0x01-0x10, 0x11-0x20, etc. in one transfer - memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, ISSI_MAX_SCALINGS); + memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i - 1, ISSI_MAX_SCALINGS); #if ISSI_PERSISTENCE > 0 for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { @@ -135,6 +163,8 @@ void is31fl3729_init(uint8_t addr) { // Set up the mode and other settings, clear the PWM registers, // then disable software shutdown. + bool config_15x9 = g_driver_config_15x9[addr]; + // Set Pull up & Down for SWx CSy is31fl3729_write_register(addr, ISSI_REG_PULLDOWNUP, ISSI_PULLDOWNUP); @@ -144,8 +174,12 @@ void is31fl3729_init(uint8_t addr) { // Set Golbal Current Control Register is31fl3729_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); - // Set to Normal operation - is31fl3729_write_register(addr, ISSI_REG_CONFIGURATION, ISSI_CONFIGURATION); + // Set to Normal 15x9 operation + if (config_15x9) { + is31fl3729_write_register(addr, ISSI_REG_CONFIGURATION, ISSI_CONFIGURATION_15x9); + } else { + is31fl3729_write_register(addr, ISSI_REG_CONFIGURATION, ISSI_CONFIGURATION_16x8); + } // Wait 10ms to ensure the device has woken up. wait_ms(10); @@ -172,21 +206,27 @@ void is31fl3729_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { } } -void is31fl3729_set_led_control_register(uint8_t index) { +void is31fl3729_set_led_control_register(uint8_t index, bool red, bool green, bool blue) { is31_led led; memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); -#ifdef ISSI_MATRIX_16X8 - // 0x90 to 0x9F - for (int i = 0; i < 16; i++) { - g_scaling_registers[led.driver][i] = 0xFF; + // need to do a bit of checking here since 3729 scaling is per CS pin. + // not the usual per RGB key as per other ISSI drivers + // only enable them, since they should be default disabled + int cs_red = (led.r & 0x0F) - 1; + int cs_green = (led.g & 0x0F) - 1; + int cs_blue = (led.b & 0x0F) - 1; + + if (red) { + g_scaling_registers[led.driver][cs_red] = 0xFF; } -#else - // 0x90 to 0x9E - for (int i = 0; i < 15; i++) { - g_scaling_registers[led.driver][i] = 0xFF; + if (green) { + g_scaling_registers[led.driver][cs_green] = 0xFF; } -#endif + if (blue) { + g_scaling_registers[led.driver][cs_blue] = 0xFF; + } + g_scaling_registers_update_required[led.driver] = true; } @@ -208,17 +248,9 @@ void is31fl3729_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_scaling_registers_update_required[index]) { -#ifdef ISSI_MATRIX_16X8 - // 0x90 to 0x9F for (int i = 0; i < 16; i++) { is31fl3729_write_register(addr, ISSI_REG_SCALING + i, g_scaling_registers[index][i]); } -#else - // 0x90 to 0x9E - for (int i = 0; i < 15; i++) { - is31fl3729_write_register(addr, ISSI_REG_SCALING + i, g_scaling_registers[index][i]); - } -#endif g_scaling_registers_update_required[index] = false; } } From 3ff017b69a062d6ef1b9503dc27be7fb38f0af32 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Tue, 5 Sep 2023 15:18:52 +0700 Subject: [PATCH 05/26] Fixed some issues --- drivers/led/issi/is31fl3729.c | 30 +++++++++++++++++++++--------- drivers/led/issi/is31fl3729.h | 2 +- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index 2c460f41f482..b99c9fc216c2 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -59,7 +59,7 @@ # define ISSI_CONFIGURATION_16x8 0x11 #endif #ifndef ISSI_GLOBALCURRENT -# define ISSI_GLOBALCURRENT 0xFF +# define ISSI_GLOBALCURRENT 0x40 #endif #ifndef ISSI_PULLDOWNUP # define ISSI_PULLDOWNUP 0x33 @@ -92,18 +92,19 @@ #else # define DRIVER_4_CONFIG_15x9 false #endif + // buffer for runtime check if it is configured as 16x8 or 15x9 -const bool g_driver_config_15x9[DRIVER_COUNT] = {DRIVER_1_CONFIG_15x9 +const bool g_driver_config_15x9[DRIVER_COUNT] = {DRIVER_1_CONFIG_15x9, #ifdef DRIVER_ADDR_2 - DRIVER_2_CONFIG_15x9 + DRIVER_2_CONFIG_15x9, #endif #ifdef DRIVER_ADDR_3 - DRIVER_3_CONFIG_15x9 + DRIVER_3_CONFIG_15x9, #endif #ifdef DRIVER_ADDR_4 DRIVER_4_CONFIG_15x9 #endif -} +}; // Transfer buffer for TWITransmitData() uint8_t g_twi_transfer_buffer[20]; @@ -134,21 +135,31 @@ bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // iterate over the pwm_buffer contents at ISSI_MAX_SCALINGS byte intervals // datasheet does not mention it, but it auto-increments in 15x9 mode, and // hence does not require us to skip any addresses - for (int i = 1; i <= ISSI_MAX_LEDS; i += ISSI_MAX_SCALINGS) { + bool config_15x9 = g_driver_config_15x9[addr]; + + int send_size; + + if (config_15x9) { + send_size = 15; + } else { + send_size = 16; + } + + for (int i = 1; i <= ISSI_MAX_LEDS; i += send_size) { g_twi_transfer_buffer[0] = i; // copy the data from i to i+ISSI_MAX_SCALINGS // device will auto-increment register for data after the first byte // thus this sets registers 0x01-0x10, 0x11-0x20, etc. in one transfer - memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i - 1, ISSI_MAX_SCALINGS); + memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, send_size); #if ISSI_PERSISTENCE > 0 for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, ISSI_MAX_SCALINGS + 1, ISSI_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, send_size + 1, ISSI_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, ISSI_MAX_SCALINGS + 1, ISSI_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, send_size + 1, ISSI_TIMEOUT) != 0) { return false; } #endif @@ -251,6 +262,7 @@ void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index) { for (int i = 0; i < 16; i++) { is31fl3729_write_register(addr, ISSI_REG_SCALING + i, g_scaling_registers[index][i]); } + g_scaling_registers_update_required[index] = false; } } diff --git a/drivers/led/issi/is31fl3729.h b/drivers/led/issi/is31fl3729.h index 1be4a2aba886..d405ad2c3c25 100644 --- a/drivers/led/issi/is31fl3729.h +++ b/drivers/led/issi/is31fl3729.h @@ -41,7 +41,7 @@ bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); void is31fl3729_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); void is31fl3729_set_color_all(uint8_t red, uint8_t green, uint8_t blue); -void is31fl3729_set_led_control_register(uint8_t index); +void is31fl3729_set_led_control_register(uint8_t index, bool red, bool green, bool blue); // This should not be called from an interrupt // (eg. from a timer interrupt). From 7434673e69ac0112aa2d3ba847a6af5f6ee47cd2 Mon Sep 17 00:00:00 2001 From: dexter93 Date: Tue, 5 Sep 2023 15:07:32 +0300 Subject: [PATCH 06/26] SImplify register declaration header for is31fl3729 --- drivers/led/issi/is31fl3729.h | 390 ++++++++++++---------------------- 1 file changed, 131 insertions(+), 259 deletions(-) diff --git a/drivers/led/issi/is31fl3729.h b/drivers/led/issi/is31fl3729.h index d405ad2c3c25..d94d2122158e 100644 --- a/drivers/led/issi/is31fl3729.h +++ b/drivers/led/issi/is31fl3729.h @@ -55,273 +55,145 @@ void is31fl3729_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, // Map CS SW locations to order in PWM / Scaling buffers // This matches the ORDER in the Datasheet Register not the POSITION // It will always count from 0x01 to (ISSI_MAX_LEDS - 1) -#ifdef ISSI_MATRIX_16X8 -# define CS1_SW1 0x01 -# define CS2_SW1 0x02 -# define CS3_SW1 0x03 -# define CS4_SW1 0x04 -# define CS5_SW1 0x05 -# define CS6_SW1 0x06 -# define CS7_SW1 0x07 -# define CS8_SW1 0x08 -# define CS9_SW1 0x09 -# define CS10_SW1 0x0A -# define CS11_SW1 0x0B -# define CS12_SW1 0x0C -# define CS13_SW1 0x0D -# define CS14_SW1 0x0E -# define CS15_SW1 0x0F +#define CS1_SW1 0x01 +#define CS2_SW1 0x02 +#define CS3_SW1 0x03 +#define CS4_SW1 0x04 +#define CS5_SW1 0x05 +#define CS6_SW1 0x06 +#define CS7_SW1 0x07 +#define CS8_SW1 0x08 +#define CS9_SW1 0x09 +#define CS10_SW1 0x0A +#define CS11_SW1 0x0B +#define CS12_SW1 0x0C +#define CS13_SW1 0x0D +#define CS14_SW1 0x0E +#define CS15_SW1 0x0F + +#define CS1_SW2 0x11 +#define CS2_SW2 0x12 +#define CS3_SW2 0x13 +#define CS4_SW2 0x14 +#define CS5_SW2 0x15 +#define CS6_SW2 0x16 +#define CS7_SW2 0x17 +#define CS8_SW2 0x18 +#define CS9_SW2 0x19 +#define CS10_SW2 0x1A +#define CS11_SW2 0x1B +#define CS12_SW2 0x1C +#define CS13_SW2 0x1D +#define CS14_SW2 0x1E +#define CS15_SW2 0x1F + +#define CS1_SW3 0x21 +#define CS2_SW3 0x22 +#define CS3_SW3 0x23 +#define CS4_SW3 0x24 +#define CS5_SW3 0x25 +#define CS6_SW3 0x26 +#define CS7_SW3 0x27 +#define CS8_SW3 0x28 +#define CS9_SW3 0x29 +#define CS10_SW3 0x2A +#define CS11_SW3 0x2B +#define CS12_SW3 0x2C +#define CS13_SW3 0x2D +#define CS14_SW3 0x2E +#define CS15_SW3 0x2F + +#define CS1_SW4 0x31 +#define CS2_SW4 0x32 +#define CS3_SW4 0x33 +#define CS4_SW4 0x34 +#define CS5_SW4 0x35 +#define CS6_SW4 0x36 +#define CS7_SW4 0x37 +#define CS8_SW4 0x38 +#define CS9_SW4 0x39 +#define CS10_SW4 0x3A +#define CS11_SW4 0x3B +#define CS12_SW4 0x3C +#define CS13_SW4 0x3D +#define CS14_SW4 0x3E +#define CS15_SW4 0x3F + +#define CS1_SW5 0x41 +#define CS2_SW5 0x42 +#define CS3_SW5 0x43 +#define CS4_SW5 0x44 +#define CS5_SW5 0x45 +#define CS6_SW5 0x46 +#define CS7_SW5 0x47 +#define CS8_SW5 0x48 +#define CS9_SW5 0x49 +#define CS10_SW5 0x4A +#define CS11_SW5 0x4B +#define CS12_SW5 0x4C +#define CS13_SW5 0x4D +#define CS14_SW5 0x4E +#define CS15_SW5 0x4F + +#define CS1_SW6 0x51 +#define CS2_SW6 0x52 +#define CS3_SW6 0x53 +#define CS4_SW6 0x54 +#define CS5_SW6 0x55 +#define CS6_SW6 0x56 +#define CS7_SW6 0x57 +#define CS8_SW6 0x58 +#define CS9_SW6 0x59 +#define CS10_SW6 0x5A +#define CS11_SW6 0x5B +#define CS12_SW6 0x5C +#define CS13_SW6 0x5D +#define CS14_SW6 0x5E +#define CS15_SW6 0x5F + +#define CS1_SW7 0x61 +#define CS2_SW7 0x62 +#define CS3_SW7 0x63 +#define CS4_SW7 0x64 +#define CS5_SW7 0x65 +#define CS6_SW7 0x66 +#define CS7_SW7 0x67 +#define CS8_SW7 0x68 +#define CS9_SW7 0x69 +#define CS10_SW7 0x6A +#define CS11_SW7 0x6B +#define CS12_SW7 0x6C +#define CS13_SW7 0x6D +#define CS14_SW7 0x6E +#define CS15_SW7 0x6F + +#define CS1_SW8 0x71 +#define CS2_SW8 0x72 +#define CS3_SW8 0x73 +#define CS4_SW8 0x74 +#define CS5_SW8 0x75 +#define CS6_SW8 0x76 +#define CS7_SW8 0x77 +#define CS8_SW8 0x78 +#define CS9_SW8 0x79 +#define CS10_SW8 0x7A +#define CS11_SW8 0x7B +#define CS12_SW8 0x7C +#define CS13_SW8 0x7D +#define CS14_SW8 0x7E +#define CS15_SW8 0x7F + +#if defined(ISSI_MATRIX_16X8) # define CS16_SW1 0x10 - -# define CS1_SW2 0x11 -# define CS2_SW2 0x12 -# define CS3_SW2 0x13 -# define CS4_SW2 0x14 -# define CS5_SW2 0x15 -# define CS6_SW2 0x16 -# define CS7_SW2 0x17 -# define CS8_SW2 0x18 -# define CS9_SW2 0x19 -# define CS10_SW2 0x1A -# define CS11_SW2 0x1B -# define CS12_SW2 0x1C -# define CS13_SW2 0x1D -# define CS14_SW2 0x1E -# define CS15_SW2 0x1F # define CS16_SW2 0x20 - -# define CS1_SW3 0x21 -# define CS2_SW3 0x22 -# define CS3_SW3 0x23 -# define CS4_SW3 0x24 -# define CS5_SW3 0x25 -# define CS6_SW3 0x26 -# define CS7_SW3 0x27 -# define CS8_SW3 0x28 -# define CS9_SW3 0x29 -# define CS10_SW3 0x2A -# define CS11_SW3 0x2B -# define CS12_SW3 0x2C -# define CS13_SW3 0x2D -# define CS14_SW3 0x2E -# define CS15_SW3 0x2F # define CS16_SW3 0x30 - -# define CS1_SW4 0x31 -# define CS2_SW4 0x32 -# define CS3_SW4 0x33 -# define CS4_SW4 0x34 -# define CS5_SW4 0x35 -# define CS6_SW4 0x36 -# define CS7_SW4 0x37 -# define CS8_SW4 0x38 -# define CS9_SW4 0x39 -# define CS10_SW4 0x3A -# define CS11_SW4 0x3B -# define CS12_SW4 0x3C -# define CS13_SW4 0x3D -# define CS14_SW4 0x3E -# define CS15_SW4 0x3F # define CS16_SW4 0x40 - -# define CS1_SW5 0x41 -# define CS2_SW5 0x42 -# define CS3_SW5 0x43 -# define CS4_SW5 0x44 -# define CS5_SW5 0x45 -# define CS6_SW5 0x46 -# define CS7_SW5 0x47 -# define CS8_SW5 0x48 -# define CS9_SW5 0x49 -# define CS10_SW5 0x4A -# define CS11_SW5 0x4B -# define CS12_SW5 0x4C -# define CS13_SW5 0x4D -# define CS14_SW5 0x4E -# define CS15_SW5 0x4F # define CS16_SW5 0x50 - -# define CS1_SW6 0x51 -# define CS2_SW6 0x52 -# define CS3_SW6 0x53 -# define CS4_SW6 0x54 -# define CS5_SW6 0x55 -# define CS6_SW6 0x56 -# define CS7_SW6 0x57 -# define CS8_SW6 0x58 -# define CS9_SW6 0x59 -# define CS10_SW6 0x5A -# define CS11_SW6 0x5B -# define CS12_SW6 0x5C -# define CS13_SW6 0x5D -# define CS14_SW6 0x5E -# define CS15_SW6 0x5F # define CS16_SW6 0x60 - -# define CS1_SW7 0x61 -# define CS2_SW7 0x62 -# define CS3_SW7 0x63 -# define CS4_SW7 0x64 -# define CS5_SW7 0x65 -# define CS6_SW7 0x66 -# define CS7_SW7 0x67 -# define CS8_SW7 0x68 -# define CS9_SW7 0x69 -# define CS10_SW7 0x6A -# define CS11_SW7 0x6B -# define CS12_SW7 0x6C -# define CS13_SW7 0x6D -# define CS14_SW7 0x6E -# define CS15_SW7 0x6F # define CS16_SW7 0x70 - -# define CS1_SW8 0x71 -# define CS2_SW8 0x72 -# define CS3_SW8 0x73 -# define CS4_SW8 0x74 -# define CS5_SW8 0x75 -# define CS6_SW8 0x76 -# define CS7_SW8 0x77 -# define CS8_SW8 0x78 -# define CS9_SW8 0x79 -# define CS10_SW8 0x7A -# define CS11_SW8 0x7B -# define CS12_SW8 0x7C -# define CS13_SW8 0x7D -# define CS14_SW8 0x7E -# define CS15_SW8 0x7F # define CS16_SW8 0x80 - -#else - -# define CS1_SW1 0x01 -# define CS2_SW1 0x02 -# define CS3_SW1 0x03 -# define CS4_SW1 0x04 -# define CS5_SW1 0x05 -# define CS6_SW1 0x06 -# define CS7_SW1 0x07 -# define CS8_SW1 0x08 -# define CS9_SW1 0x09 -# define CS10_SW1 0x0A -# define CS11_SW1 0x0B -# define CS12_SW1 0x0C -# define CS13_SW1 0x0D -# define CS14_SW1 0x0E -# define CS15_SW1 0x0F - -# define CS1_SW2 0x11 -# define CS2_SW2 0x12 -# define CS3_SW2 0x13 -# define CS4_SW2 0x14 -# define CS5_SW2 0x15 -# define CS6_SW2 0x16 -# define CS7_SW2 0x17 -# define CS8_SW2 0x18 -# define CS9_SW2 0x19 -# define CS10_SW2 0x1A -# define CS11_SW2 0x1B -# define CS12_SW2 0x1C -# define CS13_SW2 0x1D -# define CS14_SW2 0x1E -# define CS15_SW2 0x1F - -# define CS1_SW3 0x21 -# define CS2_SW3 0x22 -# define CS3_SW3 0x23 -# define CS4_SW3 0x24 -# define CS5_SW3 0x25 -# define CS6_SW3 0x26 -# define CS7_SW3 0x27 -# define CS8_SW3 0x28 -# define CS9_SW3 0x29 -# define CS10_SW3 0x2A -# define CS11_SW3 0x2B -# define CS12_SW3 0x2C -# define CS13_SW3 0x2D -# define CS14_SW3 0x2E -# define CS15_SW3 0x2F - -# define CS1_SW4 0x31 -# define CS2_SW4 0x32 -# define CS3_SW4 0x33 -# define CS4_SW4 0x34 -# define CS5_SW4 0x35 -# define CS6_SW4 0x36 -# define CS7_SW4 0x37 -# define CS8_SW4 0x38 -# define CS9_SW4 0x39 -# define CS10_SW4 0x3A -# define CS11_SW4 0x3B -# define CS12_SW4 0x3C -# define CS13_SW4 0x3D -# define CS14_SW4 0x3E -# define CS15_SW4 0x3F - -# define CS1_SW5 0x41 -# define CS2_SW5 0x42 -# define CS3_SW5 0x43 -# define CS4_SW5 0x44 -# define CS5_SW5 0x45 -# define CS6_SW5 0x46 -# define CS7_SW5 0x47 -# define CS8_SW5 0x48 -# define CS9_SW5 0x49 -# define CS10_SW5 0x4A -# define CS11_SW5 0x4B -# define CS12_SW5 0x4C -# define CS13_SW5 0x4D -# define CS14_SW5 0x4E -# define CS15_SW5 0x4F - -# define CS1_SW6 0x51 -# define CS2_SW6 0x52 -# define CS3_SW6 0x53 -# define CS4_SW6 0x54 -# define CS5_SW6 0x55 -# define CS6_SW6 0x56 -# define CS7_SW6 0x57 -# define CS8_SW6 0x58 -# define CS9_SW6 0x59 -# define CS10_SW6 0x5A -# define CS11_SW6 0x5B -# define CS12_SW6 0x5C -# define CS13_SW6 0x5D -# define CS14_SW6 0x5E -# define CS15_SW6 0x5F - -# define CS1_SW7 0x61 -# define CS2_SW7 0x62 -# define CS3_SW7 0x63 -# define CS4_SW7 0x64 -# define CS5_SW7 0x65 -# define CS6_SW7 0x66 -# define CS7_SW7 0x67 -# define CS8_SW7 0x68 -# define CS9_SW7 0x69 -# define CS10_SW7 0x6A -# define CS11_SW7 0x6B -# define CS12_SW7 0x6C -# define CS13_SW7 0x6D -# define CS14_SW7 0x6E -# define CS15_SW7 0x6F - -# define CS1_SW8 0x71 -# define CS2_SW8 0x72 -# define CS3_SW8 0x73 -# define CS4_SW8 0x74 -# define CS5_SW8 0x75 -# define CS6_SW8 0x76 -# define CS7_SW8 0x77 -# define CS8_SW8 0x78 -# define CS9_SW8 0x79 -# define CS10_SW8 0x7A -# define CS11_SW8 0x7B -# define CS12_SW8 0x7C -# define CS13_SW8 0x7D -# define CS14_SW8 0x7E -# define CS15_SW8 0x7F - +#endif +#elif defined(ISSI_MATRIX_15X9) # define CS1_SW9 0x81 # define CS2_SW9 0x82 # define CS3_SW9 0x83 From a3c2702726c34dde60d2dbac5ec74471911622fb Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Wed, 6 Sep 2023 13:34:28 +0700 Subject: [PATCH 07/26] Clean up and fixed pwm_buffer --- drivers/led/issi/is31fl3729.c | 92 +++++++---------------------------- drivers/led/issi/is31fl3729.h | 61 ++++++++++------------- 2 files changed, 43 insertions(+), 110 deletions(-) diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index b99c9fc216c2..7b277e3574b4 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -1,9 +1,6 @@ -/* Copyright 2017 Jason Williams - * Copyright 2018 Jack Humbert - * Copyright 2018 Yiancar - * Copyright 2020 MelGeek - * Copyright 2023 HorrorTroll +/* Copyright 2023 HorrorTroll * Copyright 2023 Harrison Chan (Xelus) + * Copyright 2023 Dimitris Mantzouranis * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -55,8 +52,7 @@ // Set defaults for Registers #ifndef ISSI_CONFIGURATION -# define ISSI_CONFIGURATION_15x9 0x01 -# define ISSI_CONFIGURATION_16x8 0x11 +# define ISSI_CONFIGURATION 0x01 #endif #ifndef ISSI_GLOBALCURRENT # define ISSI_GLOBALCURRENT 0x40 @@ -69,43 +65,9 @@ #endif // Set buffer sizes -#define ISSI_MAX_LEDS 135 +#define ISSI_MAX_LEDS 143 #define ISSI_MAX_SCALINGS 16 -#ifdef DRIVER_1_15x9 -# define DRIVER_1_CONFIG_15x9 true -#else -# define DRIVER_1_CONFIG_15x9 false -#endif -#ifdef DRIVER_2_15x9 -# define DRIVER_2_CONFIG_15x9 true -#else -# define DRIVER_2_CONFIG_15x9 false -#endif -#ifdef DRIVER_3_15x9 -# define DRIVER_3_CONFIG_15x9 true -#else -# define DRIVER_3_CONFIG_15x9 false -#endif -#ifdef DRIVER_4_15x9 -# define DRIVER_4_CONFIG_15x9 true -#else -# define DRIVER_4_CONFIG_15x9 false -#endif - -// buffer for runtime check if it is configured as 16x8 or 15x9 -const bool g_driver_config_15x9[DRIVER_COUNT] = {DRIVER_1_CONFIG_15x9, -#ifdef DRIVER_ADDR_2 - DRIVER_2_CONFIG_15x9, -#endif -#ifdef DRIVER_ADDR_3 - DRIVER_3_CONFIG_15x9, -#endif -#ifdef DRIVER_ADDR_4 - DRIVER_4_CONFIG_15x9 -#endif -}; - // Transfer buffer for TWITransmitData() uint8_t g_twi_transfer_buffer[20]; @@ -114,8 +76,8 @@ uint8_t g_twi_transfer_buffer[20]; uint8_t g_pwm_buffer[DRIVER_COUNT][ISSI_MAX_LEDS]; bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; -uint8_t g_scaling_registers[DRIVER_COUNT][ISSI_MAX_SCALINGS] = {0}; -bool g_scaling_registers_update_required[DRIVER_COUNT] = {false}; +uint8_t g_scaling_registers[DRIVER_COUNT][ISSI_MAX_SCALINGS]; +bool g_scaling_registers_update_required[DRIVER_COUNT] = {false}; void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { // Set register address and register data ready to write @@ -135,31 +97,22 @@ bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // iterate over the pwm_buffer contents at ISSI_MAX_SCALINGS byte intervals // datasheet does not mention it, but it auto-increments in 15x9 mode, and // hence does not require us to skip any addresses - bool config_15x9 = g_driver_config_15x9[addr]; - - int send_size; - - if (config_15x9) { - send_size = 15; - } else { - send_size = 16; - } - - for (int i = 1; i <= ISSI_MAX_LEDS; i += send_size) { + for (int i = 0; i <= ISSI_MAX_LEDS; i += ISSI_MAX_SCALINGS) { g_twi_transfer_buffer[0] = i; + // copy the data from i to i+ISSI_MAX_SCALINGS // device will auto-increment register for data after the first byte // thus this sets registers 0x01-0x10, 0x11-0x20, etc. in one transfer - memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, send_size); + memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, ISSI_MAX_SCALINGS); #if ISSI_PERSISTENCE > 0 for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, send_size + 1, ISSI_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, ISSI_MAX_SCALINGS + 1, ISSI_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, send_size + 1, ISSI_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, ISSI_MAX_SCALINGS + 1, ISSI_TIMEOUT) != 0) { return false; } #endif @@ -174,8 +127,6 @@ void is31fl3729_init(uint8_t addr) { // Set up the mode and other settings, clear the PWM registers, // then disable software shutdown. - bool config_15x9 = g_driver_config_15x9[addr]; - // Set Pull up & Down for SWx CSy is31fl3729_write_register(addr, ISSI_REG_PULLDOWNUP, ISSI_PULLDOWNUP); @@ -185,12 +136,8 @@ void is31fl3729_init(uint8_t addr) { // Set Golbal Current Control Register is31fl3729_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); - // Set to Normal 15x9 operation - if (config_15x9) { - is31fl3729_write_register(addr, ISSI_REG_CONFIGURATION, ISSI_CONFIGURATION_15x9); - } else { - is31fl3729_write_register(addr, ISSI_REG_CONFIGURATION, ISSI_CONFIGURATION_16x8); - } + // Set to Normal operation + is31fl3729_write_register(addr, ISSI_REG_CONFIGURATION, ISSI_CONFIGURATION); // Wait 10ms to ensure the device has woken up. wait_ms(10); @@ -204,6 +151,7 @@ void is31fl3729_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { 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) { return; } + g_pwm_buffer_update_required[led.driver] = true; g_pwm_buffer[led.driver][led.r] = red; g_pwm_buffer[led.driver][led.g] = green; @@ -231,9 +179,11 @@ void is31fl3729_set_led_control_register(uint8_t index, bool red, bool green, bo if (red) { g_scaling_registers[led.driver][cs_red] = 0xFF; } + if (green) { g_scaling_registers[led.driver][cs_green] = 0xFF; } + if (blue) { g_scaling_registers[led.driver][cs_blue] = 0xFF; } @@ -249,17 +199,9 @@ void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index) { g_pwm_buffer_update_required[index] = false; } -void is31fl3729_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue) { - g_pwm_buffer[pled->driver][pled->r] = red; - g_pwm_buffer[pled->driver][pled->g] = green; - g_pwm_buffer[pled->driver][pled->b] = blue; - - g_pwm_buffer_update_required[pled->driver] = true; -} - void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_scaling_registers_update_required[index]) { - for (int i = 0; i < 16; i++) { + for (int i = 0; i < ISSI_MAX_SCALINGS; i++) { is31fl3729_write_register(addr, ISSI_REG_SCALING + i, g_scaling_registers[index][i]); } diff --git a/drivers/led/issi/is31fl3729.h b/drivers/led/issi/is31fl3729.h index d94d2122158e..ed25156e10aa 100644 --- a/drivers/led/issi/is31fl3729.h +++ b/drivers/led/issi/is31fl3729.h @@ -1,9 +1,6 @@ -/* Copyright 2017 Jason Williams - * Copyright 2018 Jack Humbert - * Copyright 2018 Yiancar - * Copyright 2020 MelGeek - * Copyright 2023 HorrorTroll +/* Copyright 2023 HorrorTroll * Copyright 2023 Harrison Chan (Xelus) + * Copyright 2023 Dimitris Mantzouranis * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -50,8 +47,6 @@ void is31fl3729_set_led_control_register(uint8_t index, bool red, bool green, bo void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index); void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index); -void is31fl3729_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue); - // Map CS SW locations to order in PWM / Scaling buffers // This matches the ORDER in the Datasheet Register not the POSITION // It will always count from 0x01 to (ISSI_MAX_LEDS - 1) @@ -70,6 +65,7 @@ void is31fl3729_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, #define CS13_SW1 0x0D #define CS14_SW1 0x0E #define CS15_SW1 0x0F +#define CS16_SW1 0x10 #define CS1_SW2 0x11 #define CS2_SW2 0x12 @@ -86,6 +82,7 @@ void is31fl3729_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, #define CS13_SW2 0x1D #define CS14_SW2 0x1E #define CS15_SW2 0x1F +#define CS16_SW2 0x20 #define CS1_SW3 0x21 #define CS2_SW3 0x22 @@ -102,6 +99,7 @@ void is31fl3729_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, #define CS13_SW3 0x2D #define CS14_SW3 0x2E #define CS15_SW3 0x2F +#define CS16_SW3 0x30 #define CS1_SW4 0x31 #define CS2_SW4 0x32 @@ -118,6 +116,7 @@ void is31fl3729_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, #define CS13_SW4 0x3D #define CS14_SW4 0x3E #define CS15_SW4 0x3F +#define CS16_SW4 0x40 #define CS1_SW5 0x41 #define CS2_SW5 0x42 @@ -134,6 +133,7 @@ void is31fl3729_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, #define CS13_SW5 0x4D #define CS14_SW5 0x4E #define CS15_SW5 0x4F +#define CS16_SW5 0x50 #define CS1_SW6 0x51 #define CS2_SW6 0x52 @@ -150,6 +150,7 @@ void is31fl3729_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, #define CS13_SW6 0x5D #define CS14_SW6 0x5E #define CS15_SW6 0x5F +#define CS16_SW6 0x60 #define CS1_SW7 0x61 #define CS2_SW7 0x62 @@ -166,6 +167,7 @@ void is31fl3729_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, #define CS13_SW7 0x6D #define CS14_SW7 0x6E #define CS15_SW7 0x6F +#define CS16_SW7 0x70 #define CS1_SW8 0x71 #define CS2_SW8 0x72 @@ -182,31 +184,20 @@ void is31fl3729_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, #define CS13_SW8 0x7D #define CS14_SW8 0x7E #define CS15_SW8 0x7F - -#if defined(ISSI_MATRIX_16X8) -# define CS16_SW1 0x10 -# define CS16_SW2 0x20 -# define CS16_SW3 0x30 -# define CS16_SW4 0x40 -# define CS16_SW5 0x50 -# define CS16_SW6 0x60 -# define CS16_SW7 0x70 -# define CS16_SW8 0x80 -#endif -#elif defined(ISSI_MATRIX_15X9) -# define CS1_SW9 0x81 -# define CS2_SW9 0x82 -# define CS3_SW9 0x83 -# define CS4_SW9 0x84 -# define CS5_SW9 0x85 -# define CS6_SW9 0x86 -# define CS7_SW9 0x87 -# define CS8_SW9 0x88 -# define CS9_SW9 0x89 -# define CS10_SW9 0x8A -# define CS11_SW9 0x8B -# define CS12_SW9 0x8C -# define CS13_SW9 0x8D -# define CS14_SW9 0x8E -# define CS15_SW9 0x8F -#endif +#define CS16_SW8 0x80 + +#define CS1_SW9 0x81 +#define CS2_SW9 0x82 +#define CS3_SW9 0x83 +#define CS4_SW9 0x84 +#define CS5_SW9 0x85 +#define CS6_SW9 0x86 +#define CS7_SW9 0x87 +#define CS8_SW9 0x88 +#define CS9_SW9 0x89 +#define CS10_SW9 0x8A +#define CS11_SW9 0x8B +#define CS12_SW9 0x8C +#define CS13_SW9 0x8D +#define CS14_SW9 0x8E +#define CS15_SW9 0x8F From 719896fac31a32d5f0d591bec61c8a1968789c71 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Wed, 6 Sep 2023 21:15:38 +0700 Subject: [PATCH 08/26] Added support for LED Matrix --- builddefs/common_features.mk | 11 +- drivers/led/issi/is31fl3729-simple.c | 198 +++++++++++++++++++++++ drivers/led/issi/is31fl3729-simple.h | 201 ++++++++++++++++++++++++ quantum/led_matrix/led_matrix_drivers.c | 8 + 4 files changed, 415 insertions(+), 3 deletions(-) create mode 100644 drivers/led/issi/is31fl3729-simple.c create mode 100644 drivers/led/issi/is31fl3729-simple.h diff --git a/builddefs/common_features.mk b/builddefs/common_features.mk index b38db937bf6a..3e0d7de16259 100644 --- a/builddefs/common_features.mk +++ b/builddefs/common_features.mk @@ -340,7 +340,7 @@ LED_MATRIX_DRIVER := snled27351 endif LED_MATRIX_ENABLE ?= no -VALID_LED_MATRIX_TYPES := is31fl3218 is31fl3731 is31fl3733 is31fl3736 is31fl3737 is31fl3741 is31fl3742a is31fl3743a is31fl3745 is31fl3746a snled27351 custom +VALID_LED_MATRIX_TYPES := is31fl3218 is31fl3729 is31fl3731 is31fl3733 is31fl3736 is31fl3737 is31fl3741 is31fl3742a is31fl3743a is31fl3745 is31fl3746a snled27351 custom ifeq ($(strip $(LED_MATRIX_ENABLE)), yes) ifeq ($(filter $(LED_MATRIX_DRIVER),$(VALID_LED_MATRIX_TYPES)),) @@ -365,6 +365,12 @@ ifeq ($(strip $(LED_MATRIX_ENABLE)), yes) SRC += is31fl3218-mono.c endif + ifeq ($(strip $(LED_MATRIX_DRIVER)), is31fl3729) + I2C_DRIVER_REQUIRED = yes + COMMON_VPATH += $(DRIVER_PATH)/led/issi + SRC += is31fl3729-simple.c + endif + ifeq ($(strip $(LED_MATRIX_DRIVER)), is31fl3731) I2C_DRIVER_REQUIRED = yes COMMON_VPATH += $(DRIVER_PATH)/led/issi @@ -469,10 +475,9 @@ ifeq ($(strip $(RGB_MATRIX_ENABLE)), yes) endif ifeq ($(strip $(RGB_MATRIX_DRIVER)), is31fl3729) - OPT_DEFS += -DIS31FL3729 -DSTM32_I2C -DHAL_USE_I2C=TRUE + I2C_DRIVER_REQUIRED = yes COMMON_VPATH += $(DRIVER_PATH)/led/issi SRC += is31fl3729.c - QUANTUM_LIB_SRC += i2c_master.c endif ifeq ($(strip $(RGB_MATRIX_DRIVER)), is31fl3731) diff --git a/drivers/led/issi/is31fl3729-simple.c b/drivers/led/issi/is31fl3729-simple.c new file mode 100644 index 000000000000..022210efdbd1 --- /dev/null +++ b/drivers/led/issi/is31fl3729-simple.c @@ -0,0 +1,198 @@ +/* Copyright 2023 HorrorTroll + * Copyright 2023 Harrison Chan (Xelus) + * Copyright 2023 Dimitris Mantzouranis + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "wait.h" + +#include "is31fl3729-simple.h" +#include +#include "i2c_master.h" +#include "progmem.h" + +// This is a 7-bit address, that gets left-shifted and bit 0 +// set to 0 for write, 1 for read (as per I2C protocol) +// The address will vary depending on your wiring: +// 00 <-> GND +// 01 <-> SCL +// 10 <-> SDA +// 11 <-> VCC +// ADDR represents A2:A1 of the 7-bit address. +// The result is: 0b01101(ADDR) +#define ISSI_ADDR_DEFAULT 0x68 + +// Registers +#define ISSI_REG_SCALING 0x90 +#define ISSI_REG_CONFIGURATION 0xA0 +#define ISSI_REG_GLOBALCURRENT 0xA1 +#define ISSI_REG_PULLDOWNUP 0xB0 +#define ISSI_REG_RESET 0xCF +#define ISSI_REG_PWM_SET 0xB2 + +// Set defaults for Timeout and Persistence +#ifndef ISSI_TIMEOUT +# define ISSI_TIMEOUT 100 +#endif +#ifndef ISSI_PERSISTENCE +# define ISSI_PERSISTENCE 0 +#endif + +// Set defaults for Registers +#ifndef ISSI_CONFIGURATION +# define ISSI_CONFIGURATION 0x01 +#endif +#ifndef ISSI_GLOBALCURRENT +# define ISSI_GLOBALCURRENT 0x40 +#endif +#ifndef ISSI_PULLDOWNUP +# define ISSI_PULLDOWNUP 0x33 +#endif +#ifndef ISSI_PWM_SET +# define ISSI_PWM_SET 0x01 +#endif + +// Set buffer sizes +#define ISSI_MAX_LEDS 143 +#define ISSI_MAX_SCALINGS 16 + +// Transfer buffer for TWITransmitData() +uint8_t g_twi_transfer_buffer[20]; + +// These buffers match the PWM & scaling registers. +// Storing them like this is optimal for I2C transfers to the registers. +uint8_t g_pwm_buffer[LED_DRIVER_COUNT][ISSI_MAX_LEDS]; +bool g_pwm_buffer_update_required[LED_DRIVER_COUNT] = {false}; + +uint8_t g_scaling_registers[LED_DRIVER_COUNT][ISSI_MAX_SCALINGS]; +bool g_scaling_registers_update_required[LED_DRIVER_COUNT] = {false}; + +void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { + // Set register address and register data ready to write + g_twi_transfer_buffer[0] = reg; + g_twi_transfer_buffer[1] = data; + +#if ISSI_PERSISTENCE > 0 + for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break; + } +#else + i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT); +#endif +} + +bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { + // iterate over the pwm_buffer contents at ISSI_MAX_SCALINGS byte intervals + // datasheet does not mention it, but it auto-increments in 15x9 mode, and + // hence does not require us to skip any addresses + for (int i = 0; i <= ISSI_MAX_LEDS; i += ISSI_MAX_SCALINGS) { + g_twi_transfer_buffer[0] = i; + + // copy the data from i to i+ISSI_MAX_SCALINGS + // device will auto-increment register for data after the first byte + // thus this sets registers 0x01-0x10, 0x11-0x20, etc. in one transfer + memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, ISSI_MAX_SCALINGS); + +#if ISSI_PERSISTENCE > 0 + for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, ISSI_MAX_SCALINGS + 1, ISSI_TIMEOUT) != 0) { + return false; + } + } +#else + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, ISSI_MAX_SCALINGS + 1, ISSI_TIMEOUT) != 0) { + return false; + } +#endif + } + + return true; +} + +void is31fl3729_init(uint8_t addr) { + // In order to avoid the LEDs being driven with garbage data + // in the LED driver's PWM registers, shutdown is enabled last. + // Set up the mode and other settings, clear the PWM registers, + // then disable software shutdown. + + // Set Pull up & Down for SWx CSy + is31fl3729_write_register(addr, ISSI_REG_PULLDOWNUP, ISSI_PULLDOWNUP); + + // Set PWM Frequency Register if applicable + is31fl3729_write_register(addr, ISSI_REG_PWM_SET, ISSI_PWM_SET); + + // Set Golbal Current Control Register + is31fl3729_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); + + // Set to Normal operation + is31fl3729_write_register(addr, ISSI_REG_CONFIGURATION, ISSI_CONFIGURATION); + + // Wait 10ms to ensure the device has woken up. + wait_ms(10); +} + +void is31fl3729_set_value(int index, uint8_t value) { + is31_led led; + if (index >= 0 && index < LED_MATRIX_LED_COUNT) { + memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); + + if (g_pwm_buffer[led.driver][led.v] == value) { + return; + } + + g_pwm_buffer_update_required[led.driver] = true; + g_pwm_buffer[led.driver][led.v] = value; + } +} + +void is31fl3729_set_value_all(uint8_t value) { + for (int i = 0; i < LED_MATRIX_LED_COUNT; i++) { + is31fl3729_set_value(i, value); + } +} + +void is31fl3729_set_led_control_register(uint8_t index, bool value) { + is31_led led; + memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); + + // need to do a bit of checking here since 3729 scaling is per CS pin. + // not the usual per single LED key as per other ISSI drivers + // only enable them, since they should be default disabled + int cs_value = (led.v & 0x0F) - 1; + + if (value) { + g_scaling_registers[led.driver][cs_value] = 0xFF; + } + + g_scaling_registers_update_required[led.driver] = true; +} + +void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index) { + if (g_pwm_buffer_update_required[index]) { + is31fl3729_write_pwm_buffer(addr, g_pwm_buffer[index]); + } + + g_pwm_buffer_update_required[index] = false; +} + +void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index) { + if (g_scaling_registers_update_required[index]) { + for (int i = 0; i < ISSI_MAX_SCALINGS; i++) { + is31fl3729_write_register(addr, ISSI_REG_SCALING + i, g_scaling_registers[index][i]); + } + + g_scaling_registers_update_required[index] = false; + } +} diff --git a/drivers/led/issi/is31fl3729-simple.h b/drivers/led/issi/is31fl3729-simple.h new file mode 100644 index 000000000000..207ef0d79506 --- /dev/null +++ b/drivers/led/issi/is31fl3729-simple.h @@ -0,0 +1,201 @@ +/* Copyright 2023 HorrorTroll + * Copyright 2023 Harrison Chan (Xelus) + * Copyright 2023 Dimitris Mantzouranis + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include +#include "progmem.h" + +typedef struct is31_led { + uint32_t driver : 2; + uint8_t v; +} __attribute__((packed)) is31_led; + +extern const is31_led PROGMEM g_is31_leds[LED_MATRIX_LED_COUNT]; + +void is31fl3729_init(uint8_t addr); +void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data); +bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); + +void is31fl3729_set_value(int index, uint8_t value); +void is31fl3729_set_value_all(uint8_t value); + +void is31fl3729_set_led_control_register(uint8_t index, bool value); + +// This should not be called from an interrupt +// (eg. from a timer interrupt). +// Call this while idle (in between matrix scans). +// If the buffer is dirty, it will update the driver with the buffer. +void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index); +void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index); + +// Map CS SW locations to order in PWM / Scaling buffers +// This matches the ORDER in the Datasheet Register not the POSITION +// It will always count from 0x01 to (ISSI_MAX_LEDS - 1) +#define CS1_SW1 0x01 +#define CS2_SW1 0x02 +#define CS3_SW1 0x03 +#define CS4_SW1 0x04 +#define CS5_SW1 0x05 +#define CS6_SW1 0x06 +#define CS7_SW1 0x07 +#define CS8_SW1 0x08 +#define CS9_SW1 0x09 +#define CS10_SW1 0x0A +#define CS11_SW1 0x0B +#define CS12_SW1 0x0C +#define CS13_SW1 0x0D +#define CS14_SW1 0x0E +#define CS15_SW1 0x0F +#define CS16_SW1 0x10 + +#define CS1_SW2 0x11 +#define CS2_SW2 0x12 +#define CS3_SW2 0x13 +#define CS4_SW2 0x14 +#define CS5_SW2 0x15 +#define CS6_SW2 0x16 +#define CS7_SW2 0x17 +#define CS8_SW2 0x18 +#define CS9_SW2 0x19 +#define CS10_SW2 0x1A +#define CS11_SW2 0x1B +#define CS12_SW2 0x1C +#define CS13_SW2 0x1D +#define CS14_SW2 0x1E +#define CS15_SW2 0x1F +#define CS16_SW2 0x20 + +#define CS1_SW3 0x21 +#define CS2_SW3 0x22 +#define CS3_SW3 0x23 +#define CS4_SW3 0x24 +#define CS5_SW3 0x25 +#define CS6_SW3 0x26 +#define CS7_SW3 0x27 +#define CS8_SW3 0x28 +#define CS9_SW3 0x29 +#define CS10_SW3 0x2A +#define CS11_SW3 0x2B +#define CS12_SW3 0x2C +#define CS13_SW3 0x2D +#define CS14_SW3 0x2E +#define CS15_SW3 0x2F +#define CS16_SW3 0x30 + +#define CS1_SW4 0x31 +#define CS2_SW4 0x32 +#define CS3_SW4 0x33 +#define CS4_SW4 0x34 +#define CS5_SW4 0x35 +#define CS6_SW4 0x36 +#define CS7_SW4 0x37 +#define CS8_SW4 0x38 +#define CS9_SW4 0x39 +#define CS10_SW4 0x3A +#define CS11_SW4 0x3B +#define CS12_SW4 0x3C +#define CS13_SW4 0x3D +#define CS14_SW4 0x3E +#define CS15_SW4 0x3F +#define CS16_SW4 0x40 + +#define CS1_SW5 0x41 +#define CS2_SW5 0x42 +#define CS3_SW5 0x43 +#define CS4_SW5 0x44 +#define CS5_SW5 0x45 +#define CS6_SW5 0x46 +#define CS7_SW5 0x47 +#define CS8_SW5 0x48 +#define CS9_SW5 0x49 +#define CS10_SW5 0x4A +#define CS11_SW5 0x4B +#define CS12_SW5 0x4C +#define CS13_SW5 0x4D +#define CS14_SW5 0x4E +#define CS15_SW5 0x4F +#define CS16_SW5 0x50 + +#define CS1_SW6 0x51 +#define CS2_SW6 0x52 +#define CS3_SW6 0x53 +#define CS4_SW6 0x54 +#define CS5_SW6 0x55 +#define CS6_SW6 0x56 +#define CS7_SW6 0x57 +#define CS8_SW6 0x58 +#define CS9_SW6 0x59 +#define CS10_SW6 0x5A +#define CS11_SW6 0x5B +#define CS12_SW6 0x5C +#define CS13_SW6 0x5D +#define CS14_SW6 0x5E +#define CS15_SW6 0x5F +#define CS16_SW6 0x60 + +#define CS1_SW7 0x61 +#define CS2_SW7 0x62 +#define CS3_SW7 0x63 +#define CS4_SW7 0x64 +#define CS5_SW7 0x65 +#define CS6_SW7 0x66 +#define CS7_SW7 0x67 +#define CS8_SW7 0x68 +#define CS9_SW7 0x69 +#define CS10_SW7 0x6A +#define CS11_SW7 0x6B +#define CS12_SW7 0x6C +#define CS13_SW7 0x6D +#define CS14_SW7 0x6E +#define CS15_SW7 0x6F +#define CS16_SW7 0x70 + +#define CS1_SW8 0x71 +#define CS2_SW8 0x72 +#define CS3_SW8 0x73 +#define CS4_SW8 0x74 +#define CS5_SW8 0x75 +#define CS6_SW8 0x76 +#define CS7_SW8 0x77 +#define CS8_SW8 0x78 +#define CS9_SW8 0x79 +#define CS10_SW8 0x7A +#define CS11_SW8 0x7B +#define CS12_SW8 0x7C +#define CS13_SW8 0x7D +#define CS14_SW8 0x7E +#define CS15_SW8 0x7F +#define CS16_SW8 0x80 + +#define CS1_SW9 0x81 +#define CS2_SW9 0x82 +#define CS3_SW9 0x83 +#define CS4_SW9 0x84 +#define CS5_SW9 0x85 +#define CS6_SW9 0x86 +#define CS7_SW9 0x87 +#define CS8_SW9 0x88 +#define CS9_SW9 0x89 +#define CS10_SW9 0x8A +#define CS11_SW9 0x8B +#define CS12_SW9 0x8C +#define CS13_SW9 0x8D +#define CS14_SW9 0x8E +#define CS15_SW9 0x8F diff --git a/quantum/led_matrix/led_matrix_drivers.c b/quantum/led_matrix/led_matrix_drivers.c index b866383481ea..2e80bd03752a 100644 --- a/quantum/led_matrix/led_matrix_drivers.c +++ b/quantum/led_matrix/led_matrix_drivers.c @@ -33,6 +33,14 @@ const led_matrix_driver_t led_matrix_driver = { .set_value_all = is31fl3218_set_value_all, }; +#elif defined(LED_MATRIX_IS31FL3729) +const led_matrix_driver_t led_matrix_driver = { + .init = is31fl3729_init_drivers, + .flush = is31fl3729_flush, + .set_value = is31fl3729_set_value, + .set_value_all = is31fl3729_set_value_all, +}; + #elif defined(LED_MATRIX_IS31FL3731) const led_matrix_driver_t led_matrix_driver = { .init = is31fl3731_init_drivers, From 2e4b955a45d1d3c256594921c42907f5a2ac0b8c Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Wed, 6 Sep 2023 22:19:22 +0700 Subject: [PATCH 09/26] Added docs for RGB Matrix & LED Matrix --- docs/feature_led_matrix.md | 78 ++++++++++++++++++++++++++++++++++++++ docs/feature_rgb_matrix.md | 69 +++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) diff --git a/docs/feature_led_matrix.md b/docs/feature_led_matrix.md index 3a3a9dbf844c..ff9fa318b6e1 100644 --- a/docs/feature_led_matrix.md +++ b/docs/feature_led_matrix.md @@ -5,6 +5,84 @@ This feature allows you to use LED matrices driven by external drivers. It hooks If you want to use RGB LED's you should use the [RGB Matrix Subsystem](feature_rgb_matrix.md) instead. ## Driver configuration :id=driver-configuration +--- +### IS31FL3729 :id=is31fl3729 + +There is basic support for addressable LED matrix lighting with the I2C IS31FL3729 LED controller. To enable it, add this to your `rules.mk`: + +```make +LED_MATRIX_ENABLE = yes +LED_MATRIX_DRIVER = is31fl3729 +``` + +You can use between 1 and 4 IS31FL3729 IC's. Do not specify `LED_DRIVER_ADDR_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: + +| Variable | Description | Default | +|----------|-------------|---------| +| `ISSI_TIMEOUT` | (Optional) How long to wait for i2c messages, in milliseconds | 100 | +| `ISSI_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 | +| `LED_DRIVER_COUNT` | (Required) How many LED driver IC's are present | | +| `LED_MATRIX_LED_COUNT` | (Required) How many LED lights are present across all drivers | | +| `LED_DRIVER_ADDR_1` | (Required) Address for the first LED driver | | +| `LED_DRIVER_ADDR_2` | (Optional) Address for the second LED driver | | +| `LED_DRIVER_ADDR_3` | (Optional) Address for the third LED driver | | +| `LED_DRIVER_ADDR_4` | (Optional) Address for the fourth LED driver | | +| `ISSI_CONFIGURATION` | (Optional) Configuration for the Configuration Register | 0x01 | +| `ISSI_GLOBALCURRENT` | (Optional) Configuration for the Global Current Register | 0x40 | +| `ISSI_PULLDOWNUP` | (Optional) Configuration for the Pull Up & Pull Down Register | 0x33 | +| `ISSI_PWM_SET` | (Optional) Configuration for the PWM Setting Register | 0x01 | + +Drivers does support many matrix layout by using SWS on Configuration Register. Default is using 15 x 9 matrix layout (15 CS pin & 9 SW pin). More info [in datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3729_DS.pdf) + +| Variable | Description | Settings | +|----------|-------------|----------| +| `16 x 8` | 16 x 8 matrix layout (16 CS pin & 8 SW pin) | 0x11 | +| `16 x 7` | 16 x 7 matrix layout (16 CS pin & 7 SW pin) | 0x21 | +| `16 x 6` | 16 x 6 matrix layout (16 CS pin & 6 SW pin) | 0x31 | +| `16 x 5` | 16 x 5 matrix layout (16 CS pin & 5 SW pin) | 0x41 | +| `16 x 4` | 16 x 4 matrix layout (16 CS pin & 4 SW pin) | 0x51 | +| `16 x 3` | 16 x 3 matrix layout (16 CS pin & 3 SW pin) | 0x61 | +| `16 x 2` | 16 x 2 matrix layout (16 CS pin & 2 SW pin) | 0x71 | + +Here is an example using 2 drivers. + +```c +// This is a 7-bit address, that gets left-shifted and bit 0 +// set to 0 for write, 1 for read (as per I2C protocol) +// The address will vary depending on your wiring: +// 0b0110100 AD <-> GND +// 0b0110101 AD <-> SCL +// 0b0110110 AD <-> SDA +// 0b0110111 AD <-> VCC +#define LED_DRIVER_ADDR_1 0b0110100 +#define LED_DRIVER_ADDR_2 0b0110101 + +#define LED_DRIVER_COUNT 2 +#define LED_DRIVER_1_LED_TOTAL 39 +#define LED_DRIVER_2_LED_TOTAL 28 +#define LED_MATRIX_LED_COUNT (LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL) +``` + +!> Note the parentheses, this is so when `LED_MATRIX_LED_COUNT` is used in code and expanded, the values are added together before any additional math is applied to them. As an example, `rand() % (LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL)` will give very different results than `rand() % LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL`. + +For split keyboards using `LED_MATRIX_SPLIT` with an LED driver, you can either have the same driver address or different driver addresses. If using different addresses, use `DRIVER_ADDR_1` for one and `DRIVER_ADDR_2` for the other one. Then, in `g_is31_leds`, fill out the correct driver index (0 or 1). If using one address, use `DRIVER_ADDR_1` for both, and use index 0 for `g_is31_leds`. + +Define these arrays listing all the LEDs in your `.c`: + +```c +const is31_led PROGMEM g_is31_leds[LED_MATRIX_LED_COUNT] = { +/* Refer to IS31 manual for these locations + * driver + * | LED address + * | | */ + { 0, CS1_SW1 }, + { 0, CS1_SW8 }, + // ... +} +``` + +Where `CSx_SWy` is the location of the LED in the matrix defined by [the datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3729_DS.pdf) and the header file `drivers/led/issi/is31fl3729-simple.h`. The `driver` is the index of the driver you defined in your `config.h` (`0`, `1`, `2`, or `3` ). + --- ### IS31FL3731 :id=is31fl3731 diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md index d05d768ceb85..6f8499b69eb0 100644 --- a/docs/feature_rgb_matrix.md +++ b/docs/feature_rgb_matrix.md @@ -5,6 +5,75 @@ This feature allows you to use RGB LED matrices driven by external drivers. It h If you want to use single color LED's you should use the [LED Matrix Subsystem](feature_led_matrix.md) instead. ## Driver configuration :id=driver-configuration +--- +### IS31FL3729 :id=is31fl3729 + +There is basic support for addressable RGB matrix lighting with the I2C IS31FL3729 RGB controller. To enable it, add this to your `rules.mk`: + +```make +RGB_MATRIX_ENABLE = yes +RGB_MATRIX_DRIVER = is31fl3729 +``` + +You can use between 1 and 4 IS31FL3729 IC's. Do not specify `DRIVER_ADDR_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: + +| Variable | Description | Default | +|----------|-------------|---------| +| `ISSI_TIMEOUT` | (Optional) How long to wait for i2c messages, in milliseconds | 100 | +| `ISSI_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 | +| `DRIVER_COUNT` | (Required) How many RGB driver IC's are present | | +| `RGB_MATRIX_LED_COUNT` | (Required) How many RGB lights are present across all drivers | | +| `DRIVER_ADDR_1` | (Required) Address for the first RGB driver | | +| `DRIVER_ADDR_2` | (Optional) Address for the second RGB driver | | +| `DRIVER_ADDR_3` | (Optional) Address for the third RGB driver | | +| `DRIVER_ADDR_4` | (Optional) Address for the fourth RGB driver | | +| `ISSI_CONFIGURATION` | (Optional) Configuration for the Configuration Register | 0x01 | +| `ISSI_GLOBALCURRENT` | (Optional) Configuration for the Global Current Register | 0x40 | +| `ISSI_PULLDOWNUP` | (Optional) Configuration for the Pull Up & Pull Down Register | 0x33 | +| `ISSI_PWM_SET` | (Optional) Configuration for the PWM Setting Register | 0x01 | + +Drivers does support many matrix layout by using SWS on Configuration Register. Default for RGB Matrix is 15 x 9 matrix layout (15 CS pin & 9 SW pin). More info [in datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3729_DS.pdf) + +Here is an example using 2 drivers. + +```c +// This is a 7-bit address, that gets left-shifted and bit 0 +// set to 0 for write, 1 for read (as per I2C protocol) +// The address will vary depending on your wiring: +// 0b0110100 AD <-> GND +// 0b0110101 AD <-> SCL +// 0b0110110 AD <-> SDA +// 0b0110111 AD <-> VCC +#define DRIVER_ADDR_1 0b0110100 +#define DRIVER_ADDR_2 0b0110101 + +#define DRIVER_COUNT 2 +#define DRIVER_1_LED_TOTAL 39 +#define DRIVER_2_LED_TOTAL 28 +#define RGB_MATRIX_LED_COUNT (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL) +``` + +!> Note the parentheses, this is so when `RGB_MATRIX_LED_COUNT` is used in code and expanded, the values are added together before any additional math is applied to them. As an example, `rand() % (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)` will give very different results than `rand() % DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL`. + +For split keyboards using `RGB_MATRIX_SPLIT` with an LED driver, you can either have the same driver address or different driver addresses. If using different addresses, use `DRIVER_ADDR_1` for one and `DRIVER_ADDR_2` for the other one. Then, in `g_is31_leds`, fill out the correct driver index (0 or 1). If using one address, use `DRIVER_ADDR_1` for both, and use index 0 for `g_is31_leds`. + +Define these arrays listing all the LEDs in your `.c`: + +```c +const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT] = { +/* Refer to IS31 manual for these locations + * driver + * | R location + * | | G location + * | | | B location + * | | | | */ + {0, CS1_SW1, CS2_SW1, CS3_SW1}, + .... +} +``` + +Where `CSx_SWy` is the location of the LED in the matrix defined by [the datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3729_DS.pdf) and the header file `drivers/led/issi/is31fl3729.h`. The `driver` is the index of the driver you defined in your `config.h` (`0`, `1`, `2`, or `3`). + --- ### IS31FL3731 :id=is31fl3731 From a02bb7a306d1ddeffa350abbcbd4c6f5858d17d5 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Thu, 7 Sep 2023 14:11:56 +0700 Subject: [PATCH 10/26] Drivers name cleanup --- docs/feature_led_matrix.md | 18 +++--- docs/feature_rgb_matrix.md | 18 +++--- drivers/led/issi/is31fl3729-simple.c | 86 ++++++++++++++-------------- drivers/led/issi/is31fl3729.c | 86 ++++++++++++++-------------- 4 files changed, 104 insertions(+), 104 deletions(-) diff --git a/docs/feature_led_matrix.md b/docs/feature_led_matrix.md index ff9fa318b6e1..af07f95c62f1 100644 --- a/docs/feature_led_matrix.md +++ b/docs/feature_led_matrix.md @@ -19,20 +19,20 @@ You can use between 1 and 4 IS31FL3729 IC's. Do not specify `LED_DRIVER_ADDR_ | Variable | Description | Default | |----------|-------------|---------| -| `ISSI_TIMEOUT` | (Optional) How long to wait for i2c messages, in milliseconds | 100 | -| `ISSI_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 | -| `LED_DRIVER_COUNT` | (Required) How many LED driver IC's are present | | +| `IS31FL3729_I2C_TIMEOUT` | (Optional) How long to wait for i2c messages, in milliseconds | 100 | +| `IS31FL3729_I2C_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 | +| `IS31FL3729_CONFIGURATION` | (Optional) Configuration for the Configuration Register | 0x01 | +| `IS31FL3729_GLOBALCURRENT` | (Optional) Configuration for the Global Current Register | 0x40 | +| `IS31FL3729_PULLDOWNUP` | (Optional) Configuration for the Pull Up & Pull Down Register | 0x33 | +| `IS31FL3729_PWM_FREQUENCY` | (Optional) Configuration for the PWM Setting Register | 0x01 | +| `IS31FL3729_DRIVER_COUNT` | (Required) How many LED driver IC's are present | | | `LED_MATRIX_LED_COUNT` | (Required) How many LED lights are present across all drivers | | | `LED_DRIVER_ADDR_1` | (Required) Address for the first LED driver | | | `LED_DRIVER_ADDR_2` | (Optional) Address for the second LED driver | | | `LED_DRIVER_ADDR_3` | (Optional) Address for the third LED driver | | | `LED_DRIVER_ADDR_4` | (Optional) Address for the fourth LED driver | | -| `ISSI_CONFIGURATION` | (Optional) Configuration for the Configuration Register | 0x01 | -| `ISSI_GLOBALCURRENT` | (Optional) Configuration for the Global Current Register | 0x40 | -| `ISSI_PULLDOWNUP` | (Optional) Configuration for the Pull Up & Pull Down Register | 0x33 | -| `ISSI_PWM_SET` | (Optional) Configuration for the PWM Setting Register | 0x01 | -Drivers does support many matrix layout by using SWS on Configuration Register. Default is using 15 x 9 matrix layout (15 CS pin & 9 SW pin). More info [in datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3729_DS.pdf) +Drivers does support many matrix layout by using SWS on `IS31FL3729_CONFIGURATION`. Default is using 15 x 9 matrix layout (15 CS pin & 9 SW pin). More info [in datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3729_DS.pdf) | Variable | Description | Settings | |----------|-------------|----------| @@ -57,7 +57,7 @@ Here is an example using 2 drivers. #define LED_DRIVER_ADDR_1 0b0110100 #define LED_DRIVER_ADDR_2 0b0110101 -#define LED_DRIVER_COUNT 2 +#define IS31FL3729_DRIVER_COUNT 2 #define LED_DRIVER_1_LED_TOTAL 39 #define LED_DRIVER_2_LED_TOTAL 28 #define LED_MATRIX_LED_COUNT (LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL) diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md index 6f8499b69eb0..cbb8da444ab0 100644 --- a/docs/feature_rgb_matrix.md +++ b/docs/feature_rgb_matrix.md @@ -19,20 +19,20 @@ You can use between 1 and 4 IS31FL3729 IC's. Do not specify `DRIVER_ADDR_` de | Variable | Description | Default | |----------|-------------|---------| -| `ISSI_TIMEOUT` | (Optional) How long to wait for i2c messages, in milliseconds | 100 | -| `ISSI_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 | -| `DRIVER_COUNT` | (Required) How many RGB driver IC's are present | | +| `IS31FL3729_I2C_TIMEOUT` | (Optional) How long to wait for i2c messages, in milliseconds | 100 | +| `IS31FL3729_I2C_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 | +| `IS31FL3729_CONFIGURATION` | (Optional) Configuration for the Configuration Register | 0x01 | +| `IS31FL3729_GLOBALCURRENT` | (Optional) Configuration for the Global Current Register | 0x40 | +| `IS31FL3729_PULLDOWNUP` | (Optional) Configuration for the Pull Up & Pull Down Register | 0x33 | +| `IS31FL3729_PWM_FREQUENCY` | (Optional) Configuration for the PWM Frequency Register | 0x01 | +| `IS31FL3729_DRIVER_COUNT` | (Required) How many RGB driver IC's are present | | | `RGB_MATRIX_LED_COUNT` | (Required) How many RGB lights are present across all drivers | | | `DRIVER_ADDR_1` | (Required) Address for the first RGB driver | | | `DRIVER_ADDR_2` | (Optional) Address for the second RGB driver | | | `DRIVER_ADDR_3` | (Optional) Address for the third RGB driver | | | `DRIVER_ADDR_4` | (Optional) Address for the fourth RGB driver | | -| `ISSI_CONFIGURATION` | (Optional) Configuration for the Configuration Register | 0x01 | -| `ISSI_GLOBALCURRENT` | (Optional) Configuration for the Global Current Register | 0x40 | -| `ISSI_PULLDOWNUP` | (Optional) Configuration for the Pull Up & Pull Down Register | 0x33 | -| `ISSI_PWM_SET` | (Optional) Configuration for the PWM Setting Register | 0x01 | -Drivers does support many matrix layout by using SWS on Configuration Register. Default for RGB Matrix is 15 x 9 matrix layout (15 CS pin & 9 SW pin). More info [in datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3729_DS.pdf) +Drivers does support many matrix layout by using SWS on `IS31FL3729_CONFIGURATION`. RGB Matrix is only supported 15 x 9 matrix layout (15 CS pin & 9 SW pin). More info [in datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3729_DS.pdf) Here is an example using 2 drivers. @@ -47,7 +47,7 @@ Here is an example using 2 drivers. #define DRIVER_ADDR_1 0b0110100 #define DRIVER_ADDR_2 0b0110101 -#define DRIVER_COUNT 2 +#define IS31FL3729_DRIVER_COUNT 2 #define DRIVER_1_LED_TOTAL 39 #define DRIVER_2_LED_TOTAL 28 #define RGB_MATRIX_LED_COUNT (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL) diff --git a/drivers/led/issi/is31fl3729-simple.c b/drivers/led/issi/is31fl3729-simple.c index 022210efdbd1..14c8c5428d99 100644 --- a/drivers/led/issi/is31fl3729-simple.c +++ b/drivers/led/issi/is31fl3729-simple.c @@ -32,87 +32,87 @@ // 11 <-> VCC // ADDR represents A2:A1 of the 7-bit address. // The result is: 0b01101(ADDR) -#define ISSI_ADDR_DEFAULT 0x68 +#define IS31FL3729_I2C_ADDRESS_DEFAULT 0x68 // Registers -#define ISSI_REG_SCALING 0x90 -#define ISSI_REG_CONFIGURATION 0xA0 -#define ISSI_REG_GLOBALCURRENT 0xA1 -#define ISSI_REG_PULLDOWNUP 0xB0 -#define ISSI_REG_RESET 0xCF -#define ISSI_REG_PWM_SET 0xB2 +#define IS31FL3729_REG_SCALING 0x90 +#define IS31FL3729_REG_CONFIGURATION 0xA0 +#define IS31FL3729_REG_GLOBALCURRENT 0xA1 +#define IS31FL3729_REG_PULLDOWNUP 0xB0 +#define IS31FL3729_REG_RESET 0xCF +#define IS31FL3729_REG_PWM_FREQUENCY 0xB2 // Set defaults for Timeout and Persistence -#ifndef ISSI_TIMEOUT -# define ISSI_TIMEOUT 100 +#ifndef IS31FL3729_I2C_TIMEOUT +# define IS31FL3729_I2C_TIMEOUT 100 #endif -#ifndef ISSI_PERSISTENCE -# define ISSI_PERSISTENCE 0 +#ifndef IS31FL3729_I2C_PERSISTENCE +# define IS31FL3729_I2C_PERSISTENCE 0 #endif // Set defaults for Registers -#ifndef ISSI_CONFIGURATION -# define ISSI_CONFIGURATION 0x01 +#ifndef IS31FL3729_CONFIGURATION +# define IS31FL3729_CONFIGURATION 0x01 #endif -#ifndef ISSI_GLOBALCURRENT -# define ISSI_GLOBALCURRENT 0x40 +#ifndef IS31FL3729_GLOBALCURRENT +# define IS31FL3729_GLOBALCURRENT 0x40 #endif -#ifndef ISSI_PULLDOWNUP -# define ISSI_PULLDOWNUP 0x33 +#ifndef IS31FL3729_PULLDOWNUP +# define IS31FL3729_PULLDOWNUP 0x33 #endif -#ifndef ISSI_PWM_SET -# define ISSI_PWM_SET 0x01 +#ifndef IS31FL3729_PWM_FREQUENCY +# define IS31FL3729_PWM_FREQUENCY 0x01 #endif // Set buffer sizes -#define ISSI_MAX_LEDS 143 -#define ISSI_MAX_SCALINGS 16 +#define IS31FL3729_MAX_LEDS 143 +#define IS31FL3729_MAX_SCALINGS 16 // Transfer buffer for TWITransmitData() uint8_t g_twi_transfer_buffer[20]; // These buffers match the PWM & scaling registers. // Storing them like this is optimal for I2C transfers to the registers. -uint8_t g_pwm_buffer[LED_DRIVER_COUNT][ISSI_MAX_LEDS]; -bool g_pwm_buffer_update_required[LED_DRIVER_COUNT] = {false}; +uint8_t g_pwm_buffer[IS31FL3729_DRIVER_COUNT][IS31FL3729_MAX_LEDS]; +bool g_pwm_buffer_update_required[IS31FL3729_DRIVER_COUNT] = {false}; -uint8_t g_scaling_registers[LED_DRIVER_COUNT][ISSI_MAX_SCALINGS]; -bool g_scaling_registers_update_required[LED_DRIVER_COUNT] = {false}; +uint8_t g_scaling_registers[IS31FL3729_DRIVER_COUNT][IS31FL3729_MAX_SCALINGS]; +bool g_scaling_registers_update_required[IS31FL3729_DRIVER_COUNT] = {false}; void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { // Set register address and register data ready to write g_twi_transfer_buffer[0] = reg; g_twi_transfer_buffer[1] = data; -#if ISSI_PERSISTENCE > 0 - for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break; +#if IS31FL3729_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3729_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3729_I2C_TIMEOUT) == 0) break; } #else - i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT); + i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3729_I2C_TIMEOUT); #endif } bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { - // iterate over the pwm_buffer contents at ISSI_MAX_SCALINGS byte intervals + // iterate over the pwm_buffer contents at IS31FL3729_MAX_SCALINGS byte intervals // datasheet does not mention it, but it auto-increments in 15x9 mode, and // hence does not require us to skip any addresses - for (int i = 0; i <= ISSI_MAX_LEDS; i += ISSI_MAX_SCALINGS) { + for (int i = 0; i <= IS31FL3729_MAX_LEDS; i += IS31FL3729_MAX_SCALINGS) { g_twi_transfer_buffer[0] = i; - // copy the data from i to i+ISSI_MAX_SCALINGS + // copy the data from i to i+IS31FL3729_MAX_SCALINGS // device will auto-increment register for data after the first byte // thus this sets registers 0x01-0x10, 0x11-0x20, etc. in one transfer - memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, ISSI_MAX_SCALINGS); + memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, IS31FL3729_MAX_SCALINGS); -#if ISSI_PERSISTENCE > 0 - for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, ISSI_MAX_SCALINGS + 1, ISSI_TIMEOUT) != 0) { +#if IS31FL3729_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3729_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, IS31FL3729_MAX_SCALINGS + 1, IS31FL3729_I2C_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, ISSI_MAX_SCALINGS + 1, ISSI_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, IS31FL3729_MAX_SCALINGS + 1, IS31FL3729_I2C_TIMEOUT) != 0) { return false; } #endif @@ -128,16 +128,16 @@ void is31fl3729_init(uint8_t addr) { // then disable software shutdown. // Set Pull up & Down for SWx CSy - is31fl3729_write_register(addr, ISSI_REG_PULLDOWNUP, ISSI_PULLDOWNUP); + is31fl3729_write_register(addr, IS31FL3729_REG_PULLDOWNUP, IS31FL3729_PULLDOWNUP); // Set PWM Frequency Register if applicable - is31fl3729_write_register(addr, ISSI_REG_PWM_SET, ISSI_PWM_SET); + is31fl3729_write_register(addr, IS31FL3729_REG_PWM_FREQUENCY, IS31FL3729_PWM_FREQUENCY); // Set Golbal Current Control Register - is31fl3729_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); + is31fl3729_write_register(addr, IS31FL3729_REG_GLOBALCURRENT, IS31FL3729_GLOBALCURRENT); // Set to Normal operation - is31fl3729_write_register(addr, ISSI_REG_CONFIGURATION, ISSI_CONFIGURATION); + is31fl3729_write_register(addr, IS31FL3729_REG_CONFIGURATION, IS31FL3729_CONFIGURATION); // Wait 10ms to ensure the device has woken up. wait_ms(10); @@ -189,8 +189,8 @@ void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index) { void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_scaling_registers_update_required[index]) { - for (int i = 0; i < ISSI_MAX_SCALINGS; i++) { - is31fl3729_write_register(addr, ISSI_REG_SCALING + i, g_scaling_registers[index][i]); + for (int i = 0; i < IS31FL3729_MAX_SCALINGS; i++) { + is31fl3729_write_register(addr, IS31FL3729_REG_SCALING + i, g_scaling_registers[index][i]); } g_scaling_registers_update_required[index] = false; diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index 7b277e3574b4..1dd97bbbe805 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -32,87 +32,87 @@ // 11 <-> VCC // ADDR represents A2:A1 of the 7-bit address. // The result is: 0b01101(ADDR) -#define ISSI_ADDR_DEFAULT 0x68 +#define IS31FL3729_I2C_ADDRESS_DEFAULT 0x68 // Registers -#define ISSI_REG_SCALING 0x90 -#define ISSI_REG_CONFIGURATION 0xA0 -#define ISSI_REG_GLOBALCURRENT 0xA1 -#define ISSI_REG_PULLDOWNUP 0xB0 -#define ISSI_REG_RESET 0xCF -#define ISSI_REG_PWM_SET 0xB2 +#define IS31FL3729_REG_SCALING 0x90 +#define IS31FL3729_REG_CONFIGURATION 0xA0 +#define IS31FL3729_REG_GLOBALCURRENT 0xA1 +#define IS31FL3729_REG_PULLDOWNUP 0xB0 +#define IS31FL3729_REG_RESET 0xCF +#define IS31FL3729_REG_PWM_FREQUENCY 0xB2 // Set defaults for Timeout and Persistence -#ifndef ISSI_TIMEOUT -# define ISSI_TIMEOUT 100 +#ifndef IS31FL3729_I2C_TIMEOUT +# define IS31FL3729_I2C_TIMEOUT 100 #endif -#ifndef ISSI_PERSISTENCE -# define ISSI_PERSISTENCE 0 +#ifndef IS31FL3729_I2C_PERSISTENCE +# define IS31FL3729_I2C_PERSISTENCE 0 #endif // Set defaults for Registers -#ifndef ISSI_CONFIGURATION -# define ISSI_CONFIGURATION 0x01 +#ifndef IS31FL3729_CONFIGURATION +# define IS31FL3729_CONFIGURATION 0x01 #endif -#ifndef ISSI_GLOBALCURRENT -# define ISSI_GLOBALCURRENT 0x40 +#ifndef IS31FL3729_GLOBALCURRENT +# define IS31FL3729_GLOBALCURRENT 0x40 #endif -#ifndef ISSI_PULLDOWNUP -# define ISSI_PULLDOWNUP 0x33 +#ifndef IS31FL3729_PULLDOWNUP +# define IS31FL3729_PULLDOWNUP 0x33 #endif -#ifndef ISSI_PWM_SET -# define ISSI_PWM_SET 0x01 +#ifndef IS31FL3729_PWM_FREQUENCY +# define IS31FL3729_PWM_FREQUENCY 0x01 #endif // Set buffer sizes -#define ISSI_MAX_LEDS 143 -#define ISSI_MAX_SCALINGS 16 +#define IS31FL3729_MAX_LEDS 143 +#define IS31FL3729_MAX_SCALINGS 16 // Transfer buffer for TWITransmitData() uint8_t g_twi_transfer_buffer[20]; // These buffers match the PWM & scaling registers. // Storing them like this is optimal for I2C transfers to the registers. -uint8_t g_pwm_buffer[DRIVER_COUNT][ISSI_MAX_LEDS]; -bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; +uint8_t g_pwm_buffer[IS31FL3729_DRIVER_COUNT][IS31FL3729_MAX_LEDS]; +bool g_pwm_buffer_update_required[IS31FL3729_DRIVER_COUNT] = {false}; -uint8_t g_scaling_registers[DRIVER_COUNT][ISSI_MAX_SCALINGS]; -bool g_scaling_registers_update_required[DRIVER_COUNT] = {false}; +uint8_t g_scaling_registers[IS31FL3729_DRIVER_COUNT][IS31FL3729_MAX_SCALINGS]; +bool g_scaling_registers_update_required[IS31FL3729_DRIVER_COUNT] = {false}; void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { // Set register address and register data ready to write g_twi_transfer_buffer[0] = reg; g_twi_transfer_buffer[1] = data; -#if ISSI_PERSISTENCE > 0 - for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break; +#if IS31FL3729_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3729_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3729_I2C_TIMEOUT) == 0) break; } #else - i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT); + i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3729_I2C_TIMEOUT); #endif } bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { - // iterate over the pwm_buffer contents at ISSI_MAX_SCALINGS byte intervals + // iterate over the pwm_buffer contents at IS31FL3729_MAX_SCALINGS byte intervals // datasheet does not mention it, but it auto-increments in 15x9 mode, and // hence does not require us to skip any addresses - for (int i = 0; i <= ISSI_MAX_LEDS; i += ISSI_MAX_SCALINGS) { + for (int i = 0; i <= IS31FL3729_MAX_LEDS; i += IS31FL3729_MAX_SCALINGS) { g_twi_transfer_buffer[0] = i; - // copy the data from i to i+ISSI_MAX_SCALINGS + // copy the data from i to i+IS31FL3729_MAX_SCALINGS // device will auto-increment register for data after the first byte // thus this sets registers 0x01-0x10, 0x11-0x20, etc. in one transfer - memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, ISSI_MAX_SCALINGS); + memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, IS31FL3729_MAX_SCALINGS); -#if ISSI_PERSISTENCE > 0 - for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, ISSI_MAX_SCALINGS + 1, ISSI_TIMEOUT) != 0) { +#if IS31FL3729_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3729_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, IS31FL3729_MAX_SCALINGS + 1, IS31FL3729_I2C_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, ISSI_MAX_SCALINGS + 1, ISSI_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, IS31FL3729_MAX_SCALINGS + 1, IS31FL3729_I2C_TIMEOUT) != 0) { return false; } #endif @@ -128,16 +128,16 @@ void is31fl3729_init(uint8_t addr) { // then disable software shutdown. // Set Pull up & Down for SWx CSy - is31fl3729_write_register(addr, ISSI_REG_PULLDOWNUP, ISSI_PULLDOWNUP); + is31fl3729_write_register(addr, IS31FL3729_REG_PULLDOWNUP, IS31FL3729_PULLDOWNUP); // Set PWM Frequency Register if applicable - is31fl3729_write_register(addr, ISSI_REG_PWM_SET, ISSI_PWM_SET); + is31fl3729_write_register(addr, IS31FL3729_REG_PWM_FREQUENCY, IS31FL3729_PWM_FREQUENCY); // Set Golbal Current Control Register - is31fl3729_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); + is31fl3729_write_register(addr, IS31FL3729_REG_GLOBALCURRENT, IS31FL3729_GLOBALCURRENT); // Set to Normal operation - is31fl3729_write_register(addr, ISSI_REG_CONFIGURATION, ISSI_CONFIGURATION); + is31fl3729_write_register(addr, IS31FL3729_REG_CONFIGURATION, IS31FL3729_CONFIGURATION); // Wait 10ms to ensure the device has woken up. wait_ms(10); @@ -201,8 +201,8 @@ void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index) { void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_scaling_registers_update_required[index]) { - for (int i = 0; i < ISSI_MAX_SCALINGS; i++) { - is31fl3729_write_register(addr, ISSI_REG_SCALING + i, g_scaling_registers[index][i]); + for (int i = 0; i < IS31FL3729_MAX_SCALINGS; i++) { + is31fl3729_write_register(addr, IS31FL3729_REG_SCALING + i, g_scaling_registers[index][i]); } g_scaling_registers_update_required[index] = false; From 21ea867ce51c78a42b43200b7005a5ef1714f089 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Thu, 7 Sep 2023 19:19:18 +0700 Subject: [PATCH 11/26] Formatting lint error --- drivers/led/issi/is31fl3729-simple.h | 2 +- drivers/led/issi/is31fl3729.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/led/issi/is31fl3729-simple.h b/drivers/led/issi/is31fl3729-simple.h index 207ef0d79506..213100caa1fd 100644 --- a/drivers/led/issi/is31fl3729-simple.h +++ b/drivers/led/issi/is31fl3729-simple.h @@ -23,7 +23,7 @@ #include "progmem.h" typedef struct is31_led { - uint32_t driver : 2; + uint8_t driver : 2; uint8_t v; } __attribute__((packed)) is31_led; diff --git a/drivers/led/issi/is31fl3729.h b/drivers/led/issi/is31fl3729.h index ed25156e10aa..78ca6bcf51e3 100644 --- a/drivers/led/issi/is31fl3729.h +++ b/drivers/led/issi/is31fl3729.h @@ -23,10 +23,10 @@ #include "progmem.h" typedef struct is31_led { - uint32_t driver : 2; - uint32_t r; - uint32_t g; - uint32_t b; + uint8_t driver : 2; + uint8_t r; + uint8_t g; + uint8_t b; } __attribute__((packed)) is31_led; extern const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT]; From 3e18101c45465518422d7fd8f83c68bebea3cf5b Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Sat, 16 Sep 2023 20:02:06 +0700 Subject: [PATCH 12/26] Use define for I2C Address --- drivers/led/issi/is31fl3729-simple.c | 15 +-------------- drivers/led/issi/is31fl3729-simple.h | 5 +++++ drivers/led/issi/is31fl3729.c | 15 +-------------- drivers/led/issi/is31fl3729.h | 5 +++++ 4 files changed, 12 insertions(+), 28 deletions(-) diff --git a/drivers/led/issi/is31fl3729-simple.c b/drivers/led/issi/is31fl3729-simple.c index 14c8c5428d99..38c1815acf68 100644 --- a/drivers/led/issi/is31fl3729-simple.c +++ b/drivers/led/issi/is31fl3729-simple.c @@ -16,23 +16,10 @@ * along with this program. If not, see . */ -#include "wait.h" - #include "is31fl3729-simple.h" #include #include "i2c_master.h" -#include "progmem.h" - -// This is a 7-bit address, that gets left-shifted and bit 0 -// set to 0 for write, 1 for read (as per I2C protocol) -// The address will vary depending on your wiring: -// 00 <-> GND -// 01 <-> SCL -// 10 <-> SDA -// 11 <-> VCC -// ADDR represents A2:A1 of the 7-bit address. -// The result is: 0b01101(ADDR) -#define IS31FL3729_I2C_ADDRESS_DEFAULT 0x68 +#include "wait.h" // Registers #define IS31FL3729_REG_SCALING 0x90 diff --git a/drivers/led/issi/is31fl3729-simple.h b/drivers/led/issi/is31fl3729-simple.h index 213100caa1fd..ad6e201b05ee 100644 --- a/drivers/led/issi/is31fl3729-simple.h +++ b/drivers/led/issi/is31fl3729-simple.h @@ -22,6 +22,11 @@ #include #include "progmem.h" +#define IS31FL3729_I2C_ADDRESS_GND 0x34 +#define IS31FL3729_I2C_ADDRESS_SCL 0x35 +#define IS31FL3729_I2C_ADDRESS_SDA 0x36 +#define IS31FL3729_I2C_ADDRESS_VCC 0x37 + typedef struct is31_led { uint8_t driver : 2; uint8_t v; diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index 1dd97bbbe805..0ba119965645 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -16,23 +16,10 @@ * along with this program. If not, see . */ -#include "wait.h" - #include "is31fl3729.h" #include #include "i2c_master.h" -#include "progmem.h" - -// This is a 7-bit address, that gets left-shifted and bit 0 -// set to 0 for write, 1 for read (as per I2C protocol) -// The address will vary depending on your wiring: -// 00 <-> GND -// 01 <-> SCL -// 10 <-> SDA -// 11 <-> VCC -// ADDR represents A2:A1 of the 7-bit address. -// The result is: 0b01101(ADDR) -#define IS31FL3729_I2C_ADDRESS_DEFAULT 0x68 +#include "wait.h" // Registers #define IS31FL3729_REG_SCALING 0x90 diff --git a/drivers/led/issi/is31fl3729.h b/drivers/led/issi/is31fl3729.h index 78ca6bcf51e3..4fe71002634f 100644 --- a/drivers/led/issi/is31fl3729.h +++ b/drivers/led/issi/is31fl3729.h @@ -22,6 +22,11 @@ #include #include "progmem.h" +#define IS31FL3729_I2C_ADDRESS_GND 0x34 +#define IS31FL3729_I2C_ADDRESS_SCL 0x35 +#define IS31FL3729_I2C_ADDRESS_SDA 0x36 +#define IS31FL3729_I2C_ADDRESS_VCC 0x37 + typedef struct is31_led { uint8_t driver : 2; uint8_t r; From af82d20eff99bbb52bc7de2aa56b9cc8938037d4 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Sun, 17 Sep 2023 09:53:32 +0700 Subject: [PATCH 13/26] Added missing Spread Spectrum register for noise reduction --- drivers/led/issi/is31fl3729-simple.c | 9 ++++++++- drivers/led/issi/is31fl3729.c | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/led/issi/is31fl3729-simple.c b/drivers/led/issi/is31fl3729-simple.c index 38c1815acf68..d05667cc096b 100644 --- a/drivers/led/issi/is31fl3729-simple.c +++ b/drivers/led/issi/is31fl3729-simple.c @@ -26,8 +26,9 @@ #define IS31FL3729_REG_CONFIGURATION 0xA0 #define IS31FL3729_REG_GLOBALCURRENT 0xA1 #define IS31FL3729_REG_PULLDOWNUP 0xB0 -#define IS31FL3729_REG_RESET 0xCF +#define IS31FL3729_REG_SPREAD_SPECTRUM 0xB1 #define IS31FL3729_REG_PWM_FREQUENCY 0xB2 +#define IS31FL3729_REG_RESET 0xCF // Set defaults for Timeout and Persistence #ifndef IS31FL3729_I2C_TIMEOUT @@ -47,6 +48,9 @@ #ifndef IS31FL3729_PULLDOWNUP # define IS31FL3729_PULLDOWNUP 0x33 #endif +#ifndef IS31FL3729_SPREAD_SPECTRUM +# define IS31FL3729_SPREAD_SPECTRUM 0x00 +#endif #ifndef IS31FL3729_PWM_FREQUENCY # define IS31FL3729_PWM_FREQUENCY 0x01 #endif @@ -117,6 +121,9 @@ void is31fl3729_init(uint8_t addr) { // Set Pull up & Down for SWx CSy is31fl3729_write_register(addr, IS31FL3729_REG_PULLDOWNUP, IS31FL3729_PULLDOWNUP); + // Set Spread Spectrum Register if applicable + is31fl3729_write_register(addr, IS31FL3729_REG_SPREAD_SPECTRUM, IS31FL3729_SPREAD_SPECTRUM); + // Set PWM Frequency Register if applicable is31fl3729_write_register(addr, IS31FL3729_REG_PWM_FREQUENCY, IS31FL3729_PWM_FREQUENCY); diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index 0ba119965645..b97c2b74aef9 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -26,8 +26,9 @@ #define IS31FL3729_REG_CONFIGURATION 0xA0 #define IS31FL3729_REG_GLOBALCURRENT 0xA1 #define IS31FL3729_REG_PULLDOWNUP 0xB0 -#define IS31FL3729_REG_RESET 0xCF +#define IS31FL3729_REG_SPREAD_SPECTRUM 0xB1 #define IS31FL3729_REG_PWM_FREQUENCY 0xB2 +#define IS31FL3729_REG_RESET 0xCF // Set defaults for Timeout and Persistence #ifndef IS31FL3729_I2C_TIMEOUT @@ -47,6 +48,9 @@ #ifndef IS31FL3729_PULLDOWNUP # define IS31FL3729_PULLDOWNUP 0x33 #endif +#ifndef IS31FL3729_SPREAD_SPECTRUM +# define IS31FL3729_SPREAD_SPECTRUM 0x00 +#endif #ifndef IS31FL3729_PWM_FREQUENCY # define IS31FL3729_PWM_FREQUENCY 0x01 #endif @@ -117,6 +121,9 @@ void is31fl3729_init(uint8_t addr) { // Set Pull up & Down for SWx CSy is31fl3729_write_register(addr, IS31FL3729_REG_PULLDOWNUP, IS31FL3729_PULLDOWNUP); + // Set Spread Spectrum Register if applicable + is31fl3729_write_register(addr, IS31FL3729_REG_SPREAD_SPECTRUM, IS31FL3729_SPREAD_SPECTRUM); + // Set PWM Frequency Register if applicable is31fl3729_write_register(addr, IS31FL3729_REG_PWM_FREQUENCY, IS31FL3729_PWM_FREQUENCY); From bd8d8287a91426488e9d06a8cc06120412c9b008 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Sun, 17 Sep 2023 13:22:46 +0700 Subject: [PATCH 14/26] Add define for noise reduction --- drivers/led/issi/is31fl3729-simple.c | 4 ++-- drivers/led/issi/is31fl3729-simple.h | 29 ++++++++++++++++++++++++++++ drivers/led/issi/is31fl3729.c | 4 ++-- drivers/led/issi/is31fl3729.h | 29 ++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 4 deletions(-) diff --git a/drivers/led/issi/is31fl3729-simple.c b/drivers/led/issi/is31fl3729-simple.c index d05667cc096b..c46229b73b1b 100644 --- a/drivers/led/issi/is31fl3729-simple.c +++ b/drivers/led/issi/is31fl3729-simple.c @@ -49,10 +49,10 @@ # define IS31FL3729_PULLDOWNUP 0x33 #endif #ifndef IS31FL3729_SPREAD_SPECTRUM -# define IS31FL3729_SPREAD_SPECTRUM 0x00 +# define IS31FL3729_SPREAD_SPECTRUM SSP_DISABLE #endif #ifndef IS31FL3729_PWM_FREQUENCY -# define IS31FL3729_PWM_FREQUENCY 0x01 +# define IS31FL3729_PWM_FREQUENCY PWM_32KHZ #endif // Set buffer sizes diff --git a/drivers/led/issi/is31fl3729-simple.h b/drivers/led/issi/is31fl3729-simple.h index ad6e201b05ee..08b29dcf7ae3 100644 --- a/drivers/led/issi/is31fl3729-simple.h +++ b/drivers/led/issi/is31fl3729-simple.h @@ -50,6 +50,35 @@ void is31fl3729_set_led_control_register(uint8_t index, bool value); void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index); void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index); +// Noise reduction using Spread Spectrum register +#define SSP_DISABLE 0x00 +#define SSP_5_1980US 0x10 +#define SSP_5_1200US 0x11 +#define SSP_5_820US 0x12 +#define SSP_5_660US 0x13 +#define SSP_15_1980US 0x14 +#define SSP_15_1200US 0x15 +#define SSP_15_820US 0x16 +#define SSP_15_660US 0x17 +#define SSP_24_1980US 0x18 +#define SSP_24_1200US 0x19 +#define SSP_24_820US 0x1A +#define SSP_24_660US 0x1B +#define SSP_34_1980US 0x1C +#define SSP_34_1200US 0x1D +#define SSP_34_820US 0x1E +#define SSP_34_660US 0x1F + +// Noise reduction using PWM Frequency register +#define PWM_55KHZ 0x00 +#define PWM_32KHZ 0x01 +#define PWM_4KHZ 0x02 +#define PWM_2KHZ 0x03 +#define PWM_1KHZ 0x04 +#define PWM_500HZ 0x05 // If SWx cannot be more than 4 +#define PWM_250HZ 0x06 // If SWx cannot be more than 2 +#define PWM_80KHZ 0x07 + // Map CS SW locations to order in PWM / Scaling buffers // This matches the ORDER in the Datasheet Register not the POSITION // It will always count from 0x01 to (ISSI_MAX_LEDS - 1) diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index b97c2b74aef9..40b8b83525cf 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -49,10 +49,10 @@ # define IS31FL3729_PULLDOWNUP 0x33 #endif #ifndef IS31FL3729_SPREAD_SPECTRUM -# define IS31FL3729_SPREAD_SPECTRUM 0x00 +# define IS31FL3729_SPREAD_SPECTRUM SSP_DISABLE #endif #ifndef IS31FL3729_PWM_FREQUENCY -# define IS31FL3729_PWM_FREQUENCY 0x01 +# define IS31FL3729_PWM_FREQUENCY PWM_32KHZ #endif // Set buffer sizes diff --git a/drivers/led/issi/is31fl3729.h b/drivers/led/issi/is31fl3729.h index 4fe71002634f..7f8ce8a5e680 100644 --- a/drivers/led/issi/is31fl3729.h +++ b/drivers/led/issi/is31fl3729.h @@ -52,6 +52,35 @@ void is31fl3729_set_led_control_register(uint8_t index, bool red, bool green, bo void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index); void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index); +// Noise reduction using Spread Spectrum register +#define SSP_DISABLE 0x00 +#define SSP_5_1980US 0x10 +#define SSP_5_1200US 0x11 +#define SSP_5_820US 0x12 +#define SSP_5_660US 0x13 +#define SSP_15_1980US 0x14 +#define SSP_15_1200US 0x15 +#define SSP_15_820US 0x16 +#define SSP_15_660US 0x17 +#define SSP_24_1980US 0x18 +#define SSP_24_1200US 0x19 +#define SSP_24_820US 0x1A +#define SSP_24_660US 0x1B +#define SSP_34_1980US 0x1C +#define SSP_34_1200US 0x1D +#define SSP_34_820US 0x1E +#define SSP_34_660US 0x1F + +// Noise reduction using PWM Frequency register +#define PWM_55KHZ 0x00 +#define PWM_32KHZ 0x01 +#define PWM_4KHZ 0x02 +#define PWM_2KHZ 0x03 +#define PWM_1KHZ 0x04 +#define PWM_500HZ 0x05 // If SWx cannot be more than 4 +#define PWM_250HZ 0x06 // If SWx cannot be more than 2 +#define PWM_80KHZ 0x07 + // Map CS SW locations to order in PWM / Scaling buffers // This matches the ORDER in the Datasheet Register not the POSITION // It will always count from 0x01 to (ISSI_MAX_LEDS - 1) From 7330e31368e0037b78d517ae32ec347e968fe791 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Tue, 19 Sep 2023 14:45:46 +0700 Subject: [PATCH 15/26] Add define to change matrix mode on Configuration register --- docs/reference_info_json.md | 2 +- drivers/led/issi/is31fl3729-simple.c | 2 +- drivers/led/issi/is31fl3729-simple.h | 10 ++++++++++ drivers/led/issi/is31fl3729.c | 2 +- drivers/led/issi/is31fl3729.h | 10 ++++++++++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/docs/reference_info_json.md b/docs/reference_info_json.md index 1f73ec8faecc..796db1f24462 100644 --- a/docs/reference_info_json.md +++ b/docs/reference_info_json.md @@ -633,7 +633,7 @@ Configures the [RGB Matrix](feature_rgb_matrix.md) feature. * The default animation speed. * Default: `128` * `driver` (Required) - * The driver to use. Must be one of `aw20216s`, `custom`, `is31fl3218`, `is31fl3731`, `is31fl3733`, `is31fl3736`, `is31fl3737`, `is31fl3741`, `is31fl3742a`, `is31fl3743a`, `is31fl3745`, `is31fl3746a`, `snled27351`, `ws2812`. + * The driver to use. Must be one of `aw20216s`, `custom`, `is31fl3218`, `is31fl3729`, `is31fl3731`, `is31fl3733`, `is31fl3736`, `is31fl3737`, `is31fl3741`, `is31fl3742a`, `is31fl3743a`, `is31fl3745`, `is31fl3746a`, `snled27351`, `ws2812`. * `hue_steps` * The number of hue adjustment steps. * Default: `8` diff --git a/drivers/led/issi/is31fl3729-simple.c b/drivers/led/issi/is31fl3729-simple.c index c46229b73b1b..46d1fa676da4 100644 --- a/drivers/led/issi/is31fl3729-simple.c +++ b/drivers/led/issi/is31fl3729-simple.c @@ -40,7 +40,7 @@ // Set defaults for Registers #ifndef IS31FL3729_CONFIGURATION -# define IS31FL3729_CONFIGURATION 0x01 +# define IS31FL3729_CONFIGURATION SWS_15_9 #endif #ifndef IS31FL3729_GLOBALCURRENT # define IS31FL3729_GLOBALCURRENT 0x40 diff --git a/drivers/led/issi/is31fl3729-simple.h b/drivers/led/issi/is31fl3729-simple.h index 08b29dcf7ae3..693456163169 100644 --- a/drivers/led/issi/is31fl3729-simple.h +++ b/drivers/led/issi/is31fl3729-simple.h @@ -79,6 +79,16 @@ void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index); #define PWM_250HZ 0x06 // If SWx cannot be more than 2 #define PWM_80KHZ 0x07 +// Change SWx Setting using Configuation register +#define SWS_15_9 0x01 // 15 CS x 9 SW matrix mode +#define SWS_16_8 0x11 // 16 CS x 8 SW matrix mode +#define SWS_16_7 0x21 // 16 CS x 7 SW matrix mode +#define SWS_16_6 0x31 // 16 CS x 6 SW matrix mode +#define SWS_16_5 0x41 // 16 CS x 5 SW matrix mode +#define SWS_16_4 0x51 // 16 CS x 4 SW matrix mode +#define SWS_16_3 0x61 // 16 CS x 3 SW matrix mode +#define SWS_16_2 0x71 // 16 CS x 2 SW matrix mode + // Map CS SW locations to order in PWM / Scaling buffers // This matches the ORDER in the Datasheet Register not the POSITION // It will always count from 0x01 to (ISSI_MAX_LEDS - 1) diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index 40b8b83525cf..4c36dfcc2a8f 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -40,7 +40,7 @@ // Set defaults for Registers #ifndef IS31FL3729_CONFIGURATION -# define IS31FL3729_CONFIGURATION 0x01 +# define IS31FL3729_CONFIGURATION SWS_15_9 #endif #ifndef IS31FL3729_GLOBALCURRENT # define IS31FL3729_GLOBALCURRENT 0x40 diff --git a/drivers/led/issi/is31fl3729.h b/drivers/led/issi/is31fl3729.h index 7f8ce8a5e680..002cd01883cc 100644 --- a/drivers/led/issi/is31fl3729.h +++ b/drivers/led/issi/is31fl3729.h @@ -81,6 +81,16 @@ void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index); #define PWM_250HZ 0x06 // If SWx cannot be more than 2 #define PWM_80KHZ 0x07 +// Change SWx Setting using Configuation register +#define SWS_15_9 0x01 // 15 CS x 9 SW matrix mode +#define SWS_16_8 0x11 // 16 CS x 8 SW matrix mode +#define SWS_16_7 0x21 // 16 CS x 7 SW matrix mode +#define SWS_16_6 0x31 // 16 CS x 6 SW matrix mode +#define SWS_16_5 0x41 // 16 CS x 5 SW matrix mode +#define SWS_16_4 0x51 // 16 CS x 4 SW matrix mode +#define SWS_16_3 0x61 // 16 CS x 3 SW matrix mode +#define SWS_16_2 0x71 // 16 CS x 2 SW matrix mode + // Map CS SW locations to order in PWM / Scaling buffers // This matches the ORDER in the Datasheet Register not the POSITION // It will always count from 0x01 to (ISSI_MAX_LEDS - 1) From 071b6b94ed8fcbf666b1249124edddff3790468c Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Sat, 23 Sep 2023 22:11:11 +0700 Subject: [PATCH 16/26] Resolved fauxpark suggest changes --- drivers/led/issi/is31fl3729-simple.c | 18 +++---- drivers/led/issi/is31fl3729-simple.h | 72 ++++++++++++++-------------- drivers/led/issi/is31fl3729.c | 18 +++---- drivers/led/issi/is31fl3729.h | 72 ++++++++++++++-------------- 4 files changed, 90 insertions(+), 90 deletions(-) diff --git a/drivers/led/issi/is31fl3729-simple.c b/drivers/led/issi/is31fl3729-simple.c index 46d1fa676da4..cfdb162fe5e0 100644 --- a/drivers/led/issi/is31fl3729-simple.c +++ b/drivers/led/issi/is31fl3729-simple.c @@ -40,19 +40,19 @@ // Set defaults for Registers #ifndef IS31FL3729_CONFIGURATION -# define IS31FL3729_CONFIGURATION SWS_15_9 +# define IS31FL3729_CONFIGURATION IS31FL3729_CONFIGURATION_SWS_15_9 #endif #ifndef IS31FL3729_GLOBALCURRENT -# define IS31FL3729_GLOBALCURRENT 0x40 +# define IS31FL3729_GLOBALCURRENT 0b1000000 #endif #ifndef IS31FL3729_PULLDOWNUP -# define IS31FL3729_PULLDOWNUP 0x33 +# define IS31FL3729_PULLDOWNUP 0b110011 #endif #ifndef IS31FL3729_SPREAD_SPECTRUM -# define IS31FL3729_SPREAD_SPECTRUM SSP_DISABLE +# define IS31FL3729_SPREAD_SPECTRUM IS31FL3729_SPREAD_SPECTRUM_DISABLE #endif #ifndef IS31FL3729_PWM_FREQUENCY -# define IS31FL3729_PWM_FREQUENCY PWM_32KHZ +# define IS31FL3729_PWM_FREQUENCY IS31FL3729_PWM_FREQUENCY_32K_HZ #endif // Set buffer sizes @@ -138,9 +138,9 @@ void is31fl3729_init(uint8_t addr) { } void is31fl3729_set_value(int index, uint8_t value) { - is31_led led; + is31fl3729_led_t led; if (index >= 0 && index < LED_MATRIX_LED_COUNT) { - memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); + memcpy_P(&led, (&g_is31fl3729_leds[index]), sizeof(led)); if (g_pwm_buffer[led.driver][led.v] == value) { return; @@ -158,8 +158,8 @@ void is31fl3729_set_value_all(uint8_t value) { } void is31fl3729_set_led_control_register(uint8_t index, bool value) { - is31_led led; - memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); + is31fl3729_led_t led; + memcpy_P(&led, (&g_is31fl3729_leds[index]), sizeof(led)); // need to do a bit of checking here since 3729 scaling is per CS pin. // not the usual per single LED key as per other ISSI drivers diff --git a/drivers/led/issi/is31fl3729-simple.h b/drivers/led/issi/is31fl3729-simple.h index 693456163169..101ea0a15d95 100644 --- a/drivers/led/issi/is31fl3729-simple.h +++ b/drivers/led/issi/is31fl3729-simple.h @@ -27,12 +27,12 @@ #define IS31FL3729_I2C_ADDRESS_SDA 0x36 #define IS31FL3729_I2C_ADDRESS_VCC 0x37 -typedef struct is31_led { +typedef struct is31fl3729_led_t { uint8_t driver : 2; uint8_t v; -} __attribute__((packed)) is31_led; +} __attribute__((packed)) is31fl3729_led_t; -extern const is31_led PROGMEM g_is31_leds[LED_MATRIX_LED_COUNT]; +extern const is31fl3729_led_t PROGMEM g_is31fl3729_leds[LED_MATRIX_LED_COUNT]; void is31fl3729_init(uint8_t addr); void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data); @@ -51,43 +51,43 @@ void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index); void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index); // Noise reduction using Spread Spectrum register -#define SSP_DISABLE 0x00 -#define SSP_5_1980US 0x10 -#define SSP_5_1200US 0x11 -#define SSP_5_820US 0x12 -#define SSP_5_660US 0x13 -#define SSP_15_1980US 0x14 -#define SSP_15_1200US 0x15 -#define SSP_15_820US 0x16 -#define SSP_15_660US 0x17 -#define SSP_24_1980US 0x18 -#define SSP_24_1200US 0x19 -#define SSP_24_820US 0x1A -#define SSP_24_660US 0x1B -#define SSP_34_1980US 0x1C -#define SSP_34_1200US 0x1D -#define SSP_34_820US 0x1E -#define SSP_34_660US 0x1F +#define IS31FL3729_SPREAD_SPECTRUM_DISABLE 0b00000 +#define IS31FL3729_SPREAD_SPECTRUM_5_1980US 0b10000 +#define IS31FL3729_SPREAD_SPECTRUM_5_1200US 0b10001 +#define IS31FL3729_SPREAD_SPECTRUM_5_820US 0b10010 +#define IS31FL3729_SPREAD_SPECTRUM_5_660US 0b10011 +#define IS31FL3729_SPREAD_SPECTRUM_15_1980US 0b10100 +#define IS31FL3729_SPREAD_SPECTRUM_15_1200US 0b10101 +#define IS31FL3729_SPREAD_SPECTRUM_15_820US 0b10110 +#define IS31FL3729_SPREAD_SPECTRUM_15_660US 0b10111 +#define IS31FL3729_SPREAD_SPECTRUM_24_1980US 0b11000 +#define IS31FL3729_SPREAD_SPECTRUM_24_1200US 0b11001 +#define IS31FL3729_SPREAD_SPECTRUM_24_820US 0b11010 +#define IS31FL3729_SPREAD_SPECTRUM_24_660US 0b11011 +#define IS31FL3729_SPREAD_SPECTRUM_34_1980US 0b11100 +#define IS31FL3729_SPREAD_SPECTRUM_34_1200US 0b11101 +#define IS31FL3729_SPREAD_SPECTRUM_34_820US 0b11110 +#define IS31FL3729_SPREAD_SPECTRUM_34_660US 0b11111 // Noise reduction using PWM Frequency register -#define PWM_55KHZ 0x00 -#define PWM_32KHZ 0x01 -#define PWM_4KHZ 0x02 -#define PWM_2KHZ 0x03 -#define PWM_1KHZ 0x04 -#define PWM_500HZ 0x05 // If SWx cannot be more than 4 -#define PWM_250HZ 0x06 // If SWx cannot be more than 2 -#define PWM_80KHZ 0x07 +#define IS31FL3729_PWM_FREQUENCY_55K_HZ 0b000 +#define IS31FL3729_PWM_FREQUENCY_32K_HZ 0b001 +#define IS31FL3729_PWM_FREQUENCY_4K_HZ 0b010 +#define IS31FL3729_PWM_FREQUENCY_2K_HZ 0b011 +#define IS31FL3729_PWM_FREQUENCY_1K_HZ 0b100 +#define IS31FL3729_PWM_FREQUENCY_500_HZ 0b101 // If SWx cannot be more than 4 +#define IS31FL3729_PWM_FREQUENCY_250_HZ 0b110 // If SWx cannot be more than 2 +#define IS31FL3729_PWM_FREQUENCY_80K_HZ 0b111 // Change SWx Setting using Configuation register -#define SWS_15_9 0x01 // 15 CS x 9 SW matrix mode -#define SWS_16_8 0x11 // 16 CS x 8 SW matrix mode -#define SWS_16_7 0x21 // 16 CS x 7 SW matrix mode -#define SWS_16_6 0x31 // 16 CS x 6 SW matrix mode -#define SWS_16_5 0x41 // 16 CS x 5 SW matrix mode -#define SWS_16_4 0x51 // 16 CS x 4 SW matrix mode -#define SWS_16_3 0x61 // 16 CS x 3 SW matrix mode -#define SWS_16_2 0x71 // 16 CS x 2 SW matrix mode +#define IS31FL3729_CONFIGURATION_SWS_15_9 0b0000001 // 15 CS x 9 SW matrix mode +#define IS31FL3729_CONFIGURATION_SWS_16_8 0b0010001 // 16 CS x 8 SW matrix mode +#define IS31FL3729_CONFIGURATION_SWS_16_7 0b0100001 // 16 CS x 7 SW matrix mode +#define IS31FL3729_CONFIGURATION_SWS_16_6 0b0110001 // 16 CS x 6 SW matrix mode +#define IS31FL3729_CONFIGURATION_SWS_16_5 0b1000001 // 16 CS x 5 SW matrix mode +#define IS31FL3729_CONFIGURATION_SWS_16_4 0b1010001 // 16 CS x 4 SW matrix mode +#define IS31FL3729_CONFIGURATION_SWS_16_3 0b1100001 // 16 CS x 3 SW matrix mode +#define IS31FL3729_CONFIGURATION_SWS_16_2 0b1110001 // 16 CS x 2 SW matrix mode // Map CS SW locations to order in PWM / Scaling buffers // This matches the ORDER in the Datasheet Register not the POSITION diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index 4c36dfcc2a8f..22a76d168476 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -40,19 +40,19 @@ // Set defaults for Registers #ifndef IS31FL3729_CONFIGURATION -# define IS31FL3729_CONFIGURATION SWS_15_9 +# define IS31FL3729_CONFIGURATION IS31FL3729_CONFIGURATION_SWS_15_9 #endif #ifndef IS31FL3729_GLOBALCURRENT -# define IS31FL3729_GLOBALCURRENT 0x40 +# define IS31FL3729_GLOBALCURRENT 0b1000000 #endif #ifndef IS31FL3729_PULLDOWNUP -# define IS31FL3729_PULLDOWNUP 0x33 +# define IS31FL3729_PULLDOWNUP 0b110011 #endif #ifndef IS31FL3729_SPREAD_SPECTRUM -# define IS31FL3729_SPREAD_SPECTRUM SSP_DISABLE +# define IS31FL3729_SPREAD_SPECTRUM IS31FL3729_SPREAD_SPECTRUM_DISABLE #endif #ifndef IS31FL3729_PWM_FREQUENCY -# define IS31FL3729_PWM_FREQUENCY PWM_32KHZ +# define IS31FL3729_PWM_FREQUENCY IS31FL3729_PWM_FREQUENCY_32K_HZ #endif // Set buffer sizes @@ -138,9 +138,9 @@ void is31fl3729_init(uint8_t addr) { } void is31fl3729_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { - is31_led led; + is31fl3729_led_t led; if (index >= 0 && index < RGB_MATRIX_LED_COUNT) { - memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); + memcpy_P(&led, (&g_is31fl3729_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) { return; @@ -160,8 +160,8 @@ void is31fl3729_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { } void is31fl3729_set_led_control_register(uint8_t index, bool red, bool green, bool blue) { - is31_led led; - memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); + is31fl3729_led_t led; + memcpy_P(&led, (&g_is31fl3729_leds[index]), sizeof(led)); // need to do a bit of checking here since 3729 scaling is per CS pin. // not the usual per RGB key as per other ISSI drivers diff --git a/drivers/led/issi/is31fl3729.h b/drivers/led/issi/is31fl3729.h index 002cd01883cc..de666464927d 100644 --- a/drivers/led/issi/is31fl3729.h +++ b/drivers/led/issi/is31fl3729.h @@ -27,14 +27,14 @@ #define IS31FL3729_I2C_ADDRESS_SDA 0x36 #define IS31FL3729_I2C_ADDRESS_VCC 0x37 -typedef struct is31_led { +typedef struct is31fl3729_led_t { uint8_t driver : 2; uint8_t r; uint8_t g; uint8_t b; -} __attribute__((packed)) is31_led; +} __attribute__((packed)) is31fl3729_led_t; -extern const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT]; +extern const is31fl3729_led_t PROGMEM g_is31fl3729_leds[RGB_MATRIX_LED_COUNT]; void is31fl3729_init(uint8_t addr); void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data); @@ -53,43 +53,43 @@ void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index); void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index); // Noise reduction using Spread Spectrum register -#define SSP_DISABLE 0x00 -#define SSP_5_1980US 0x10 -#define SSP_5_1200US 0x11 -#define SSP_5_820US 0x12 -#define SSP_5_660US 0x13 -#define SSP_15_1980US 0x14 -#define SSP_15_1200US 0x15 -#define SSP_15_820US 0x16 -#define SSP_15_660US 0x17 -#define SSP_24_1980US 0x18 -#define SSP_24_1200US 0x19 -#define SSP_24_820US 0x1A -#define SSP_24_660US 0x1B -#define SSP_34_1980US 0x1C -#define SSP_34_1200US 0x1D -#define SSP_34_820US 0x1E -#define SSP_34_660US 0x1F +#define IS31FL3729_SPREAD_SPECTRUM_DISABLE 0b00000 +#define IS31FL3729_SPREAD_SPECTRUM_5_1980US 0b10000 +#define IS31FL3729_SPREAD_SPECTRUM_5_1200US 0b10001 +#define IS31FL3729_SPREAD_SPECTRUM_5_820US 0b10010 +#define IS31FL3729_SPREAD_SPECTRUM_5_660US 0b10011 +#define IS31FL3729_SPREAD_SPECTRUM_15_1980US 0b10100 +#define IS31FL3729_SPREAD_SPECTRUM_15_1200US 0b10101 +#define IS31FL3729_SPREAD_SPECTRUM_15_820US 0b10110 +#define IS31FL3729_SPREAD_SPECTRUM_15_660US 0b10111 +#define IS31FL3729_SPREAD_SPECTRUM_24_1980US 0b11000 +#define IS31FL3729_SPREAD_SPECTRUM_24_1200US 0b11001 +#define IS31FL3729_SPREAD_SPECTRUM_24_820US 0b11010 +#define IS31FL3729_SPREAD_SPECTRUM_24_660US 0b11011 +#define IS31FL3729_SPREAD_SPECTRUM_34_1980US 0b11100 +#define IS31FL3729_SPREAD_SPECTRUM_34_1200US 0b11101 +#define IS31FL3729_SPREAD_SPECTRUM_34_820US 0b11110 +#define IS31FL3729_SPREAD_SPECTRUM_34_660US 0b11111 // Noise reduction using PWM Frequency register -#define PWM_55KHZ 0x00 -#define PWM_32KHZ 0x01 -#define PWM_4KHZ 0x02 -#define PWM_2KHZ 0x03 -#define PWM_1KHZ 0x04 -#define PWM_500HZ 0x05 // If SWx cannot be more than 4 -#define PWM_250HZ 0x06 // If SWx cannot be more than 2 -#define PWM_80KHZ 0x07 +#define IS31FL3729_PWM_FREQUENCY_55K_HZ 0b000 +#define IS31FL3729_PWM_FREQUENCY_32K_HZ 0b001 +#define IS31FL3729_PWM_FREQUENCY_4K_HZ 0b010 +#define IS31FL3729_PWM_FREQUENCY_2K_HZ 0b011 +#define IS31FL3729_PWM_FREQUENCY_1K_HZ 0b100 +#define IS31FL3729_PWM_FREQUENCY_500_HZ 0b101 // If SWx cannot be more than 4 +#define IS31FL3729_PWM_FREQUENCY_250_HZ 0b110 // If SWx cannot be more than 2 +#define IS31FL3729_PWM_FREQUENCY_80K_HZ 0b111 // Change SWx Setting using Configuation register -#define SWS_15_9 0x01 // 15 CS x 9 SW matrix mode -#define SWS_16_8 0x11 // 16 CS x 8 SW matrix mode -#define SWS_16_7 0x21 // 16 CS x 7 SW matrix mode -#define SWS_16_6 0x31 // 16 CS x 6 SW matrix mode -#define SWS_16_5 0x41 // 16 CS x 5 SW matrix mode -#define SWS_16_4 0x51 // 16 CS x 4 SW matrix mode -#define SWS_16_3 0x61 // 16 CS x 3 SW matrix mode -#define SWS_16_2 0x71 // 16 CS x 2 SW matrix mode +#define IS31FL3729_CONFIGURATION_SWS_15_9 0b0000001 // 15 CS x 9 SW matrix mode +#define IS31FL3729_CONFIGURATION_SWS_16_8 0b0010001 // 16 CS x 8 SW matrix mode +#define IS31FL3729_CONFIGURATION_SWS_16_7 0b0100001 // 16 CS x 7 SW matrix mode +#define IS31FL3729_CONFIGURATION_SWS_16_6 0b0110001 // 16 CS x 6 SW matrix mode +#define IS31FL3729_CONFIGURATION_SWS_16_5 0b1000001 // 16 CS x 5 SW matrix mode +#define IS31FL3729_CONFIGURATION_SWS_16_4 0b1010001 // 16 CS x 4 SW matrix mode +#define IS31FL3729_CONFIGURATION_SWS_16_3 0b1100001 // 16 CS x 3 SW matrix mode +#define IS31FL3729_CONFIGURATION_SWS_16_2 0b1110001 // 16 CS x 2 SW matrix mode // Map CS SW locations to order in PWM / Scaling buffers // This matches the ORDER in the Datasheet Register not the POSITION From b5cf6bf06853832cae551fc98e1c57f39cd4a662 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Mon, 6 Nov 2023 22:49:21 +0700 Subject: [PATCH 17/26] Resolved conflict again --- docs/feature_led_matrix.md | 60 +++++++++++---------- docs/feature_rgb_matrix.md | 56 ++++++++++++-------- drivers/led/issi/is31fl3729-simple.c | 79 +++++++++++++++++++++------- drivers/led/issi/is31fl3729-simple.h | 79 +++++++++++++++------------- drivers/led/issi/is31fl3729.c | 79 +++++++++++++++++++++------- drivers/led/issi/is31fl3729.h | 79 +++++++++++++++------------- 6 files changed, 275 insertions(+), 157 deletions(-) diff --git a/docs/feature_led_matrix.md b/docs/feature_led_matrix.md index af07f95c62f1..10709579724d 100644 --- a/docs/feature_led_matrix.md +++ b/docs/feature_led_matrix.md @@ -15,34 +15,36 @@ LED_MATRIX_ENABLE = yes LED_MATRIX_DRIVER = is31fl3729 ``` -You can use between 1 and 4 IS31FL3729 IC's. Do not specify `LED_DRIVER_ADDR_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: +You can use between 1 and 4 IS31FL3729 IC's. Do not specify `IS31FL3729_I2C_ADDRESS_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: | Variable | Description | Default | |----------|-------------|---------| | `IS31FL3729_I2C_TIMEOUT` | (Optional) How long to wait for i2c messages, in milliseconds | 100 | | `IS31FL3729_I2C_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 | -| `IS31FL3729_CONFIGURATION` | (Optional) Configuration for the Configuration Register | 0x01 | +| `IS31FL3729_CONFIGURATION` | (Optional) Configuration for the Configuration Register | SWS_15_9 | | `IS31FL3729_GLOBALCURRENT` | (Optional) Configuration for the Global Current Register | 0x40 | | `IS31FL3729_PULLDOWNUP` | (Optional) Configuration for the Pull Up & Pull Down Register | 0x33 | -| `IS31FL3729_PWM_FREQUENCY` | (Optional) Configuration for the PWM Setting Register | 0x01 | +| `IS31FL3729_SPREAD_SPECTRUM` | (Optional) Configuration for the Spread Spectrum Register | SSP_DISABLE | +| `IS31FL3729_PWM_FREQUENCY` | (Optional) Configuration for the PWM Frequency Register | 32K_HZ | | `IS31FL3729_DRIVER_COUNT` | (Required) How many LED driver IC's are present | | | `LED_MATRIX_LED_COUNT` | (Required) How many LED lights are present across all drivers | | -| `LED_DRIVER_ADDR_1` | (Required) Address for the first LED driver | | -| `LED_DRIVER_ADDR_2` | (Optional) Address for the second LED driver | | -| `LED_DRIVER_ADDR_3` | (Optional) Address for the third LED driver | | -| `LED_DRIVER_ADDR_4` | (Optional) Address for the fourth LED driver | | - -Drivers does support many matrix layout by using SWS on `IS31FL3729_CONFIGURATION`. Default is using 15 x 9 matrix layout (15 CS pin & 9 SW pin). More info [in datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3729_DS.pdf) - -| Variable | Description | Settings | -|----------|-------------|----------| -| `16 x 8` | 16 x 8 matrix layout (16 CS pin & 8 SW pin) | 0x11 | -| `16 x 7` | 16 x 7 matrix layout (16 CS pin & 7 SW pin) | 0x21 | -| `16 x 6` | 16 x 6 matrix layout (16 CS pin & 6 SW pin) | 0x31 | -| `16 x 5` | 16 x 5 matrix layout (16 CS pin & 5 SW pin) | 0x41 | -| `16 x 4` | 16 x 4 matrix layout (16 CS pin & 4 SW pin) | 0x51 | -| `16 x 3` | 16 x 3 matrix layout (16 CS pin & 3 SW pin) | 0x61 | -| `16 x 2` | 16 x 2 matrix layout (16 CS pin & 2 SW pin) | 0x71 | +| `IS31FL3729_I2C_ADDRESS_1` | (Required) Address for the first LED driver | | +| `IS31FL3729_I2C_ADDRESS_2` | (Optional) Address for the second LED driver | | +| `IS31FL3729_I2C_ADDRESS_3` | (Optional) Address for the third LED driver | | +| `IS31FL3729_I2C_ADDRESS_4` | (Optional) Address for the fourth LED driver | | + +The IS31FL3729 IC's support multiple matrix layouts. By default 15 x 9 matrix layout is used (`IS31FL3729_CONFIGURATION` is given the value of `IS31FL3729_CONFIG_SWS_15_9`), the values that can be set to choose matrix layouts are as follows: + +| `IS31FL3729_CONFIGURATION` | Description | +|----------------------------|-------------| +| `IS31FL3729_CONFIG_SWS_15_9` | (Default) 15 CS x 9 SW matrix | +| `IS31FL3729_CONFIG_SWS_16_8` | 16 CS x 8 SW matrix | +| `IS31FL3729_CONFIG_SWS_16_7` | 16 CS x 7 SW matrix | +| `IS31FL3729_CONFIG_SWS_16_6` | 16 CS x 6 SW matrix | +| `IS31FL3729_CONFIG_SWS_16_5` | 16 CS x 5 SW matrix | +| `IS31FL3729_CONFIG_SWS_16_4` | 16 CS x 4 SW matrix | +| `IS31FL3729_CONFIG_SWS_16_3` | 16 CS x 3 SW matrix | +| `IS31FL3729_CONFIG_SWS_16_2` | 16 CS x 2 SW matrix | Here is an example using 2 drivers. @@ -50,12 +52,14 @@ Here is an example using 2 drivers. // This is a 7-bit address, that gets left-shifted and bit 0 // set to 0 for write, 1 for read (as per I2C protocol) // The address will vary depending on your wiring: -// 0b0110100 AD <-> GND -// 0b0110101 AD <-> SCL -// 0b0110110 AD <-> SDA -// 0b0110111 AD <-> VCC -#define LED_DRIVER_ADDR_1 0b0110100 -#define LED_DRIVER_ADDR_2 0b0110101 +// 00 AD <-> GND +// 01 AD <-> SCL +// 10 AD <-> SDA +// 11 AD <-> VCC +// ADDR represents A2:A1 of the 7-bit address. +// The result is: 0b01101(ADDR) +#define IS31FL3729_I2C_ADDRESS_1 IS31FL3729_I2C_ADDRESS_GND +#define IS31FL3729_I2C_ADDRESS_2 IS31FL3729_I2C_ADDRESS_SCL #define IS31FL3729_DRIVER_COUNT 2 #define LED_DRIVER_1_LED_TOTAL 39 @@ -65,12 +69,12 @@ Here is an example using 2 drivers. !> Note the parentheses, this is so when `LED_MATRIX_LED_COUNT` is used in code and expanded, the values are added together before any additional math is applied to them. As an example, `rand() % (LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL)` will give very different results than `rand() % LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL`. -For split keyboards using `LED_MATRIX_SPLIT` with an LED driver, you can either have the same driver address or different driver addresses. If using different addresses, use `DRIVER_ADDR_1` for one and `DRIVER_ADDR_2` for the other one. Then, in `g_is31_leds`, fill out the correct driver index (0 or 1). If using one address, use `DRIVER_ADDR_1` for both, and use index 0 for `g_is31_leds`. +For split keyboards using `LED_MATRIX_SPLIT` with an LED driver, you can either have the same driver address or different driver addresses. If using different addresses, use `IS31FL3729_I2C_ADDRESS_1` for one and `IS31FL3729_I2C_ADDRESS_2` for the other one. Then, in `g_is31fl3729_leds`, fill out the correct driver index (0 or 1). If using one address, use `IS31FL3729_I2C_ADDRESS_1` for both, and use index 0 for `g_is31fl3729_leds`. Define these arrays listing all the LEDs in your `.c`: ```c -const is31_led PROGMEM g_is31_leds[LED_MATRIX_LED_COUNT] = { +const is31fl3729_led_t PROGMEM g_is31fl3729_leds[LED_MATRIX_LED_COUNT] = { /* Refer to IS31 manual for these locations * driver * | LED address @@ -93,7 +97,7 @@ LED_MATRIX_ENABLE = yes LED_MATRIX_DRIVER = is31fl3731 ``` -You can use between 1 and 4 IS31FL3731 IC's. Do not specify `LED_DRIVER_ADDR_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: +You can use between 1 and 4 IS31FL3731 IC's. Do not specify `IS31FL3731_I2C_ADDRESS_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: | Variable | Description | Default | |----------|-------------|---------| diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md index cbb8da444ab0..a42b27adcdef 100644 --- a/docs/feature_rgb_matrix.md +++ b/docs/feature_rgb_matrix.md @@ -15,24 +15,36 @@ RGB_MATRIX_ENABLE = yes RGB_MATRIX_DRIVER = is31fl3729 ``` -You can use between 1 and 4 IS31FL3729 IC's. Do not specify `DRIVER_ADDR_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: +You can use between 1 and 4 IS31FL3729 IC's. Do not specify `IS31FL3729_I2C_ADDRESS_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: | Variable | Description | Default | |----------|-------------|---------| | `IS31FL3729_I2C_TIMEOUT` | (Optional) How long to wait for i2c messages, in milliseconds | 100 | | `IS31FL3729_I2C_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 | -| `IS31FL3729_CONFIGURATION` | (Optional) Configuration for the Configuration Register | 0x01 | +| `IS31FL3729_CONFIGURATION` | (Optional) Configuration for the Configuration Register | SWS_15_9 | | `IS31FL3729_GLOBALCURRENT` | (Optional) Configuration for the Global Current Register | 0x40 | | `IS31FL3729_PULLDOWNUP` | (Optional) Configuration for the Pull Up & Pull Down Register | 0x33 | -| `IS31FL3729_PWM_FREQUENCY` | (Optional) Configuration for the PWM Frequency Register | 0x01 | +| `IS31FL3729_SPREAD_SPECTRUM` | (Optional) Configuration for the Spread Spectrum Register | SSP_DISABLE | +| `IS31FL3729_PWM_FREQUENCY` | (Optional) Configuration for the PWM Frequency Register | 32K_HZ | | `IS31FL3729_DRIVER_COUNT` | (Required) How many RGB driver IC's are present | | | `RGB_MATRIX_LED_COUNT` | (Required) How many RGB lights are present across all drivers | | -| `DRIVER_ADDR_1` | (Required) Address for the first RGB driver | | -| `DRIVER_ADDR_2` | (Optional) Address for the second RGB driver | | -| `DRIVER_ADDR_3` | (Optional) Address for the third RGB driver | | -| `DRIVER_ADDR_4` | (Optional) Address for the fourth RGB driver | | - -Drivers does support many matrix layout by using SWS on `IS31FL3729_CONFIGURATION`. RGB Matrix is only supported 15 x 9 matrix layout (15 CS pin & 9 SW pin). More info [in datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3729_DS.pdf) +| `IS31FL3729_I2C_ADDRESS_1` | (Required) Address for the first RGB driver | | +| `IS31FL3729_I2C_ADDRESS_2` | (Optional) Address for the second RGB driver | | +| `IS31FL3729_I2C_ADDRESS_3` | (Optional) Address for the third RGB driver | | +| `IS31FL3729_I2C_ADDRESS_4` | (Optional) Address for the fourth RGB driver | | + +The IS31FL3729 IC's support multiple matrix layouts. By default 15 x 9 matrix layout is used (`IS31FL3729_CONFIGURATION` is given the value of `IS31FL3729_CONFIG_SWS_15_9`), the values that can be set to choose matrix layouts are as follows: + +| `IS31FL3729_CONFIGURATION` | Description | +|----------------------------|-------------| +| `IS31FL3729_CONFIG_SWS_15_9` | (Default) 15 CS x 9 SW matrix | +| `IS31FL3729_CONFIG_SWS_16_8` | 16 CS x 8 SW matrix | +| `IS31FL3729_CONFIG_SWS_16_7` | 16 CS x 7 SW matrix | +| `IS31FL3729_CONFIG_SWS_16_6` | 16 CS x 6 SW matrix | +| `IS31FL3729_CONFIG_SWS_16_5` | 16 CS x 5 SW matrix | +| `IS31FL3729_CONFIG_SWS_16_4` | 16 CS x 4 SW matrix | +| `IS31FL3729_CONFIG_SWS_16_3` | 16 CS x 3 SW matrix | +| `IS31FL3729_CONFIG_SWS_16_2` | 16 CS x 2 SW matrix | Here is an example using 2 drivers. @@ -40,12 +52,14 @@ Here is an example using 2 drivers. // This is a 7-bit address, that gets left-shifted and bit 0 // set to 0 for write, 1 for read (as per I2C protocol) // The address will vary depending on your wiring: -// 0b0110100 AD <-> GND -// 0b0110101 AD <-> SCL -// 0b0110110 AD <-> SDA -// 0b0110111 AD <-> VCC -#define DRIVER_ADDR_1 0b0110100 -#define DRIVER_ADDR_2 0b0110101 +// 00 AD <-> GND +// 01 AD <-> SCL +// 10 AD <-> SDA +// 11 AD <-> VCC +// ADDR represents A2:A1 of the 7-bit address. +// The result is: 0b01101(ADDR) +#define IS31FL3729_I2C_ADDRESS_1 IS31FL3729_I2C_ADDRESS_GND +#define IS31FL3729_I2C_ADDRESS_2 IS31FL3729_I2C_ADDRESS_SCL #define IS31FL3729_DRIVER_COUNT 2 #define DRIVER_1_LED_TOTAL 39 @@ -55,12 +69,12 @@ Here is an example using 2 drivers. !> Note the parentheses, this is so when `RGB_MATRIX_LED_COUNT` is used in code and expanded, the values are added together before any additional math is applied to them. As an example, `rand() % (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)` will give very different results than `rand() % DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL`. -For split keyboards using `RGB_MATRIX_SPLIT` with an LED driver, you can either have the same driver address or different driver addresses. If using different addresses, use `DRIVER_ADDR_1` for one and `DRIVER_ADDR_2` for the other one. Then, in `g_is31_leds`, fill out the correct driver index (0 or 1). If using one address, use `DRIVER_ADDR_1` for both, and use index 0 for `g_is31_leds`. +For split keyboards using `RGB_MATRIX_SPLIT` with an LED driver, you can either have the same driver address or different driver addresses. If using different addresses, use `IS31FL3729_I2C_ADDRESS_1` for one and `IS31FL3729_I2C_ADDRESS_2` for the other one. Then, in `g_is31fl3729_leds`, fill out the correct driver index (0 or 1). If using one address, use `IS31FL3729_I2C_ADDRESS_1` for both, and use index 0 for `g_is31fl3729_leds`. Define these arrays listing all the LEDs in your `.c`: ```c -const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT] = { +const is31fl3729_led_t PROGMEM g_is31fl3729_leds[RGB_MATRIX_LED_COUNT] = { /* Refer to IS31 manual for these locations * driver * | R location @@ -84,7 +98,7 @@ RGB_MATRIX_ENABLE = yes RGB_MATRIX_DRIVER = is31fl3731 ``` -You can use between 1 and 4 IS31FL3731 IC's. Do not specify `DRIVER_ADDR_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: +You can use between 1 and 4 IS31FL3731 IC's. Do not specify `IS31FL3731_I2C_ADDRESS_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: | Variable | Description | Default | |----------|-------------|---------| @@ -148,7 +162,7 @@ RGB_MATRIX_ENABLE = yes RGB_MATRIX_DRIVER = is31fl3733 ``` -You can use between 1 and 4 IS31FL3733 IC's. Do not specify `DRIVER_ADDR_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: +You can use between 1 and 4 IS31FL3733 IC's. Do not specify `IS31FL3733_I2C_ADDRESS_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: | Variable | Description | Default | |----------|-------------|---------| @@ -231,7 +245,7 @@ There is basic support for addressable RGB matrix lighting with the I2C IS31FL37 RGB_MATRIX_ENABLE = yes RGB_MATRIX_DRIVER = is31fl3736 ``` -You can use between 1 and 4 IS31FL3736 IC's. Do not specify `DRIVER_ADDR_` defines for IC's that are not present on your keyboard. +You can use between 1 and 4 IS31FL3736 IC's. Do not specify `IS31FL3736_I2C_ADDRESS_` defines for IC's that are not present on your keyboard. Configure the hardware via your `config.h`: @@ -306,7 +320,7 @@ There is basic support for addressable RGB matrix lighting with the I2C IS31FL37 RGB_MATRIX_ENABLE = yes RGB_MATRIX_DRIVER = is31fl3737 ``` -You can use between 1 and 4 IS31FL3737 IC's. Do not specify `DRIVER_ADDR_` defines for IC's that are not present on your keyboard. +You can use between 1 and 4 IS31FL3737 IC's. Do not specify `IS31FL3737_I2C_ADDRESS_` defines for IC's that are not present on your keyboard. Configure the hardware via your `config.h`: diff --git a/drivers/led/issi/is31fl3729-simple.c b/drivers/led/issi/is31fl3729-simple.c index cfdb162fe5e0..b13e6338cb8a 100644 --- a/drivers/led/issi/is31fl3729-simple.c +++ b/drivers/led/issi/is31fl3729-simple.c @@ -40,34 +40,34 @@ // Set defaults for Registers #ifndef IS31FL3729_CONFIGURATION -# define IS31FL3729_CONFIGURATION IS31FL3729_CONFIGURATION_SWS_15_9 +# define IS31FL3729_CONFIGURATION IS31FL3729_CONFIG_SWS_15_9 #endif #ifndef IS31FL3729_GLOBALCURRENT -# define IS31FL3729_GLOBALCURRENT 0b1000000 +# define IS31FL3729_GLOBALCURRENT 0x40 #endif #ifndef IS31FL3729_PULLDOWNUP -# define IS31FL3729_PULLDOWNUP 0b110011 +# define IS31FL3729_PULLDOWNUP 0x33 #endif #ifndef IS31FL3729_SPREAD_SPECTRUM -# define IS31FL3729_SPREAD_SPECTRUM IS31FL3729_SPREAD_SPECTRUM_DISABLE +# define IS31FL3729_SPREAD_SPECTRUM IS31FL3729_SSP_DISABLE #endif #ifndef IS31FL3729_PWM_FREQUENCY -# define IS31FL3729_PWM_FREQUENCY IS31FL3729_PWM_FREQUENCY_32K_HZ +# define IS31FL3729_PWM_FREQUENCY IS31FL3729_PWM_FREQ_32K_HZ #endif // Set buffer sizes -#define IS31FL3729_MAX_LEDS 143 -#define IS31FL3729_MAX_SCALINGS 16 +#define IS31FL3729_PWM_REGISTER_COUNT 143 +#define IS31FL3729_SCALINGS_REGISTER_COUNT 16 // Transfer buffer for TWITransmitData() uint8_t g_twi_transfer_buffer[20]; // These buffers match the PWM & scaling registers. // Storing them like this is optimal for I2C transfers to the registers. -uint8_t g_pwm_buffer[IS31FL3729_DRIVER_COUNT][IS31FL3729_MAX_LEDS]; +uint8_t g_pwm_buffer[IS31FL3729_DRIVER_COUNT][IS31FL3729_PWM_REGISTER_COUNT]; bool g_pwm_buffer_update_required[IS31FL3729_DRIVER_COUNT] = {false}; -uint8_t g_scaling_registers[IS31FL3729_DRIVER_COUNT][IS31FL3729_MAX_SCALINGS]; +uint8_t g_scaling_registers[IS31FL3729_DRIVER_COUNT][IS31FL3729_SCALINGS_REGISTER_COUNT]; bool g_scaling_registers_update_required[IS31FL3729_DRIVER_COUNT] = {false}; void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { @@ -85,25 +85,25 @@ void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { } bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { - // iterate over the pwm_buffer contents at IS31FL3729_MAX_SCALINGS byte intervals + // iterate over the pwm_buffer contents at IS31FL3729_SCALINGS_REGISTER_COUNT byte intervals // datasheet does not mention it, but it auto-increments in 15x9 mode, and // hence does not require us to skip any addresses - for (int i = 0; i <= IS31FL3729_MAX_LEDS; i += IS31FL3729_MAX_SCALINGS) { + for (int i = 0; i <= IS31FL3729_PWM_REGISTER_COUNT; i += IS31FL3729_SCALINGS_REGISTER_COUNT) { g_twi_transfer_buffer[0] = i; - // copy the data from i to i+IS31FL3729_MAX_SCALINGS + // copy the data from i to i+IS31FL3729_SCALINGS_REGISTER_COUNT // device will auto-increment register for data after the first byte // thus this sets registers 0x01-0x10, 0x11-0x20, etc. in one transfer - memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, IS31FL3729_MAX_SCALINGS); + memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, IS31FL3729_SCALINGS_REGISTER_COUNT); #if IS31FL3729_I2C_PERSISTENCE > 0 for (uint8_t i = 0; i < IS31FL3729_I2C_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, IS31FL3729_MAX_SCALINGS + 1, IS31FL3729_I2C_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, IS31FL3729_SCALINGS_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, IS31FL3729_MAX_SCALINGS + 1, IS31FL3729_I2C_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, IS31FL3729_SCALINGS_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { return false; } #endif @@ -112,6 +112,36 @@ bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { return true; } +void is31fl3729_init_drivers(void) { + i2c_init(); + + is31fl3729_init(IS31FL3729_I2C_ADDRESS_1); +#if defined(IS31FL3729_I2C_ADDRESS_2) + is31fl3729_init(IS31FL3729_I2C_ADDRESS_2); +# if defined(IS31FL3729_I2C_ADDRESS_3) + is31fl3729_init(IS31FL3729_I2C_ADDRESS_3); +# if defined(IS31FL3729_I2C_ADDRESS_4) + is31fl3729_init(IS31FL3729_I2C_ADDRESS_4); +# endif +# endif +#endif + + for (int i = 0; i < IS31FL3729_LED_COUNT; i++) { + is31fl3729_set_led_control_register(i, true); + } + + is31fl3729_update_led_control_registers(IS31FL3729_I2C_ADDRESS_1, 0); +#if defined(IS31FL3729_I2C_ADDRESS_2) + is31fl3729_update_led_control_registers(IS31FL3729_I2C_ADDRESS_2, 1); +# if defined(IS31FL3729_I2C_ADDRESS_3) + is31fl3729_update_led_control_registers(IS31FL3729_I2C_ADDRESS_3, 2); +# if defined(IS31FL3729_I2C_ADDRESS_4) + is31fl3729_update_led_control_registers(IS31FL3729_I2C_ADDRESS_4, 3); +# endif +# endif +#endif +} + void is31fl3729_init(uint8_t addr) { // In order to avoid the LEDs being driven with garbage data // in the LED driver's PWM registers, shutdown is enabled last. @@ -139,7 +169,7 @@ void is31fl3729_init(uint8_t addr) { void is31fl3729_set_value(int index, uint8_t value) { is31fl3729_led_t led; - if (index >= 0 && index < LED_MATRIX_LED_COUNT) { + if (index >= 0 && index < IS31FL3729_LED_COUNT) { memcpy_P(&led, (&g_is31fl3729_leds[index]), sizeof(led)); if (g_pwm_buffer[led.driver][led.v] == value) { @@ -152,7 +182,7 @@ void is31fl3729_set_value(int index, uint8_t value) { } void is31fl3729_set_value_all(uint8_t value) { - for (int i = 0; i < LED_MATRIX_LED_COUNT; i++) { + for (int i = 0; i < IS31FL3729_LED_COUNT; i++) { is31fl3729_set_value(i, value); } } @@ -183,10 +213,23 @@ void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index) { void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_scaling_registers_update_required[index]) { - for (int i = 0; i < IS31FL3729_MAX_SCALINGS; i++) { + for (int i = 0; i < IS31FL3729_SCALINGS_REGISTER_COUNT; i++) { is31fl3729_write_register(addr, IS31FL3729_REG_SCALING + i, g_scaling_registers[index][i]); } g_scaling_registers_update_required[index] = false; } } + +void is31fl3729_flush(void) { + is31fl3729_update_pwm_buffers(IS31FL3729_I2C_ADDRESS_1, 0); +#if defined(IS31FL3729_I2C_ADDRESS_2) + is31fl3729_update_pwm_buffers(IS31FL3729_I2C_ADDRESS_2, 1); +# if defined(IS31FL3729_I2C_ADDRESS_3) + is31fl3729_update_pwm_buffers(IS31FL3729_I2C_ADDRESS_3, 2); +# if defined(IS31FL3729_I2C_ADDRESS_4) + is31fl3729_update_pwm_buffers(IS31FL3729_I2C_ADDRESS_4, 3); +# endif +# endif +#endif +} diff --git a/drivers/led/issi/is31fl3729-simple.h b/drivers/led/issi/is31fl3729-simple.h index 101ea0a15d95..e33c4d1b3968 100644 --- a/drivers/led/issi/is31fl3729-simple.h +++ b/drivers/led/issi/is31fl3729-simple.h @@ -27,13 +27,18 @@ #define IS31FL3729_I2C_ADDRESS_SDA 0x36 #define IS31FL3729_I2C_ADDRESS_VCC 0x37 +#if defined(LED_MATRIX_IS31FL3729) +# define IS31FL3729_LED_COUNT LED_MATRIX_LED_COUNT +#endif + typedef struct is31fl3729_led_t { uint8_t driver : 2; uint8_t v; } __attribute__((packed)) is31fl3729_led_t; -extern const is31fl3729_led_t PROGMEM g_is31fl3729_leds[LED_MATRIX_LED_COUNT]; +extern const is31fl3729_led_t PROGMEM g_is31fl3729_leds[IS31FL3729_LED_COUNT]; +void is31fl3729_init_drivers(void); void is31fl3729_init(uint8_t addr); void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data); bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); @@ -50,44 +55,46 @@ void is31fl3729_set_led_control_register(uint8_t index, bool value); void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index); void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index); +void is31fl3729_flush(void); + // Noise reduction using Spread Spectrum register -#define IS31FL3729_SPREAD_SPECTRUM_DISABLE 0b00000 -#define IS31FL3729_SPREAD_SPECTRUM_5_1980US 0b10000 -#define IS31FL3729_SPREAD_SPECTRUM_5_1200US 0b10001 -#define IS31FL3729_SPREAD_SPECTRUM_5_820US 0b10010 -#define IS31FL3729_SPREAD_SPECTRUM_5_660US 0b10011 -#define IS31FL3729_SPREAD_SPECTRUM_15_1980US 0b10100 -#define IS31FL3729_SPREAD_SPECTRUM_15_1200US 0b10101 -#define IS31FL3729_SPREAD_SPECTRUM_15_820US 0b10110 -#define IS31FL3729_SPREAD_SPECTRUM_15_660US 0b10111 -#define IS31FL3729_SPREAD_SPECTRUM_24_1980US 0b11000 -#define IS31FL3729_SPREAD_SPECTRUM_24_1200US 0b11001 -#define IS31FL3729_SPREAD_SPECTRUM_24_820US 0b11010 -#define IS31FL3729_SPREAD_SPECTRUM_24_660US 0b11011 -#define IS31FL3729_SPREAD_SPECTRUM_34_1980US 0b11100 -#define IS31FL3729_SPREAD_SPECTRUM_34_1200US 0b11101 -#define IS31FL3729_SPREAD_SPECTRUM_34_820US 0b11110 -#define IS31FL3729_SPREAD_SPECTRUM_34_660US 0b11111 +#define IS31FL3729_SSP_DISABLE 0x00 +#define IS31FL3729_SSP_5_1980US 0x10 +#define IS31FL3729_SSP_5_1200US 0x11 +#define IS31FL3729_SSP_5_820US 0x12 +#define IS31FL3729_SSP_5_660US 0x13 +#define IS31FL3729_SSP_15_1980US 0x14 +#define IS31FL3729_SSP_15_1200US 0x15 +#define IS31FL3729_SSP_15_820US 0x16 +#define IS31FL3729_SSP_15_660US 0x17 +#define IS31FL3729_SSP_24_1980US 0x18 +#define IS31FL3729_SSP_24_1200US 0x19 +#define IS31FL3729_SSP_24_820US 0x1A +#define IS31FL3729_SSP_24_660US 0x1B +#define IS31FL3729_SSP_34_1980US 0x1C +#define IS31FL3729_SSP_34_1200US 0x1D +#define IS31FL3729_SSP_34_820US 0x1E +#define IS31FL3729_SSP_34_660US 0x1F // Noise reduction using PWM Frequency register -#define IS31FL3729_PWM_FREQUENCY_55K_HZ 0b000 -#define IS31FL3729_PWM_FREQUENCY_32K_HZ 0b001 -#define IS31FL3729_PWM_FREQUENCY_4K_HZ 0b010 -#define IS31FL3729_PWM_FREQUENCY_2K_HZ 0b011 -#define IS31FL3729_PWM_FREQUENCY_1K_HZ 0b100 -#define IS31FL3729_PWM_FREQUENCY_500_HZ 0b101 // If SWx cannot be more than 4 -#define IS31FL3729_PWM_FREQUENCY_250_HZ 0b110 // If SWx cannot be more than 2 -#define IS31FL3729_PWM_FREQUENCY_80K_HZ 0b111 - -// Change SWx Setting using Configuation register -#define IS31FL3729_CONFIGURATION_SWS_15_9 0b0000001 // 15 CS x 9 SW matrix mode -#define IS31FL3729_CONFIGURATION_SWS_16_8 0b0010001 // 16 CS x 8 SW matrix mode -#define IS31FL3729_CONFIGURATION_SWS_16_7 0b0100001 // 16 CS x 7 SW matrix mode -#define IS31FL3729_CONFIGURATION_SWS_16_6 0b0110001 // 16 CS x 6 SW matrix mode -#define IS31FL3729_CONFIGURATION_SWS_16_5 0b1000001 // 16 CS x 5 SW matrix mode -#define IS31FL3729_CONFIGURATION_SWS_16_4 0b1010001 // 16 CS x 4 SW matrix mode -#define IS31FL3729_CONFIGURATION_SWS_16_3 0b1100001 // 16 CS x 3 SW matrix mode -#define IS31FL3729_CONFIGURATION_SWS_16_2 0b1110001 // 16 CS x 2 SW matrix mode +#define IS31FL3729_PWM_FREQ_55K_HZ 0x00 +#define IS31FL3729_PWM_FREQ_32K_HZ 0x01 +#define IS31FL3729_PWM_FREQ_4K_HZ 0x02 +#define IS31FL3729_PWM_FREQ_2K_HZ 0x03 +#define IS31FL3729_PWM_FREQ_1K_HZ 0x04 +#define IS31FL3729_PWM_FREQ_500_HZ 0x05 // If SWx cannot be more than 4 +#define IS31FL3729_PWM_FREQ_250_HZ 0x06 // If SWx cannot be more than 2 +#define IS31FL3729_PWM_FREQ_80K_HZ 0x07 + +// Change SWx Setting using Configuration register +#define IS31FL3729_CONFIG_SWS_15_9 0x01 // 15 CS x 9 SW matrix +#define IS31FL3729_CONFIG_SWS_16_8 0x11 // 16 CS x 8 SW matrix +#define IS31FL3729_CONFIG_SWS_16_7 0x21 // 16 CS x 7 SW matrix +#define IS31FL3729_CONFIG_SWS_16_6 0x31 // 16 CS x 6 SW matrix +#define IS31FL3729_CONFIG_SWS_16_5 0x41 // 16 CS x 5 SW matrix +#define IS31FL3729_CONFIG_SWS_16_4 0x51 // 16 CS x 4 SW matrix +#define IS31FL3729_CONFIG_SWS_16_3 0x61 // 16 CS x 3 SW matrix +#define IS31FL3729_CONFIG_SWS_16_2 0x71 // 16 CS x 2 SW matrix // Map CS SW locations to order in PWM / Scaling buffers // This matches the ORDER in the Datasheet Register not the POSITION diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index 22a76d168476..534db930ea59 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -40,34 +40,34 @@ // Set defaults for Registers #ifndef IS31FL3729_CONFIGURATION -# define IS31FL3729_CONFIGURATION IS31FL3729_CONFIGURATION_SWS_15_9 +# define IS31FL3729_CONFIGURATION IS31FL3729_CONFIG_SWS_15_9 #endif #ifndef IS31FL3729_GLOBALCURRENT -# define IS31FL3729_GLOBALCURRENT 0b1000000 +# define IS31FL3729_GLOBALCURRENT 0x40 #endif #ifndef IS31FL3729_PULLDOWNUP -# define IS31FL3729_PULLDOWNUP 0b110011 +# define IS31FL3729_PULLDOWNUP 0x33 #endif #ifndef IS31FL3729_SPREAD_SPECTRUM -# define IS31FL3729_SPREAD_SPECTRUM IS31FL3729_SPREAD_SPECTRUM_DISABLE +# define IS31FL3729_SPREAD_SPECTRUM IS31FL3729_SSP_DISABLE #endif #ifndef IS31FL3729_PWM_FREQUENCY -# define IS31FL3729_PWM_FREQUENCY IS31FL3729_PWM_FREQUENCY_32K_HZ +# define IS31FL3729_PWM_FREQUENCY IS31FL3729_PWM_FREQ_32K_HZ #endif // Set buffer sizes -#define IS31FL3729_MAX_LEDS 143 -#define IS31FL3729_MAX_SCALINGS 16 +#define IS31FL3729_PWM_REGISTER_COUNT 143 +#define IS31FL3729_SCALINGS_REGISTER_COUNT 16 // Transfer buffer for TWITransmitData() uint8_t g_twi_transfer_buffer[20]; // These buffers match the PWM & scaling registers. // Storing them like this is optimal for I2C transfers to the registers. -uint8_t g_pwm_buffer[IS31FL3729_DRIVER_COUNT][IS31FL3729_MAX_LEDS]; +uint8_t g_pwm_buffer[IS31FL3729_DRIVER_COUNT][IS31FL3729_PWM_REGISTER_COUNT]; bool g_pwm_buffer_update_required[IS31FL3729_DRIVER_COUNT] = {false}; -uint8_t g_scaling_registers[IS31FL3729_DRIVER_COUNT][IS31FL3729_MAX_SCALINGS]; +uint8_t g_scaling_registers[IS31FL3729_DRIVER_COUNT][IS31FL3729_SCALINGS_REGISTER_COUNT]; bool g_scaling_registers_update_required[IS31FL3729_DRIVER_COUNT] = {false}; void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { @@ -85,25 +85,25 @@ void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { } bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { - // iterate over the pwm_buffer contents at IS31FL3729_MAX_SCALINGS byte intervals + // iterate over the pwm_buffer contents at IS31FL3729_SCALINGS_REGISTER_COUNT byte intervals // datasheet does not mention it, but it auto-increments in 15x9 mode, and // hence does not require us to skip any addresses - for (int i = 0; i <= IS31FL3729_MAX_LEDS; i += IS31FL3729_MAX_SCALINGS) { + for (int i = 0; i <= IS31FL3729_PWM_REGISTER_COUNT; i += IS31FL3729_SCALINGS_REGISTER_COUNT) { g_twi_transfer_buffer[0] = i; - // copy the data from i to i+IS31FL3729_MAX_SCALINGS + // copy the data from i to i+IS31FL3729_SCALINGS_REGISTER_COUNT // device will auto-increment register for data after the first byte // thus this sets registers 0x01-0x10, 0x11-0x20, etc. in one transfer - memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, IS31FL3729_MAX_SCALINGS); + memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, IS31FL3729_SCALINGS_REGISTER_COUNT); #if IS31FL3729_I2C_PERSISTENCE > 0 for (uint8_t i = 0; i < IS31FL3729_I2C_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, IS31FL3729_MAX_SCALINGS + 1, IS31FL3729_I2C_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, IS31FL3729_SCALINGS_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, IS31FL3729_MAX_SCALINGS + 1, IS31FL3729_I2C_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, IS31FL3729_SCALINGS_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { return false; } #endif @@ -112,6 +112,36 @@ bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { return true; } +void is31fl3729_init_drivers(void) { + i2c_init(); + + is31fl3729_init(IS31FL3729_I2C_ADDRESS_1); +#if defined(IS31FL3729_I2C_ADDRESS_2) + is31fl3729_init(IS31FL3729_I2C_ADDRESS_2); +# if defined(IS31FL3729_I2C_ADDRESS_3) + is31fl3729_init(IS31FL3729_I2C_ADDRESS_3); +# if defined(IS31FL3729_I2C_ADDRESS_4) + is31fl3729_init(IS31FL3729_I2C_ADDRESS_4); +# endif +# endif +#endif + + for (int i = 0; i < IS31FL3729_LED_COUNT; i++) { + is31fl3729_set_led_control_register(i, true, true, true); + } + + is31fl3729_update_led_control_registers(IS31FL3729_I2C_ADDRESS_1, 0); +#if defined(IS31FL3729_I2C_ADDRESS_2) + is31fl3729_update_led_control_registers(IS31FL3729_I2C_ADDRESS_2, 1); +# if defined(IS31FL3729_I2C_ADDRESS_3) + is31fl3729_update_led_control_registers(IS31FL3729_I2C_ADDRESS_3, 2); +# if defined(IS31FL3729_I2C_ADDRESS_4) + is31fl3729_update_led_control_registers(IS31FL3729_I2C_ADDRESS_4, 3); +# endif +# endif +#endif +} + void is31fl3729_init(uint8_t addr) { // In order to avoid the LEDs being driven with garbage data // in the LED driver's PWM registers, shutdown is enabled last. @@ -139,7 +169,7 @@ void is31fl3729_init(uint8_t addr) { void is31fl3729_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { is31fl3729_led_t led; - if (index >= 0 && index < RGB_MATRIX_LED_COUNT) { + if (index >= 0 && index < IS31FL3729_LED_COUNT) { memcpy_P(&led, (&g_is31fl3729_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) { @@ -154,7 +184,7 @@ void is31fl3729_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { } void is31fl3729_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 < IS31FL3729_LED_COUNT; i++) { is31fl3729_set_color(i, red, green, blue); } } @@ -195,10 +225,23 @@ void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index) { void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_scaling_registers_update_required[index]) { - for (int i = 0; i < IS31FL3729_MAX_SCALINGS; i++) { + for (int i = 0; i < IS31FL3729_SCALINGS_REGISTER_COUNT; i++) { is31fl3729_write_register(addr, IS31FL3729_REG_SCALING + i, g_scaling_registers[index][i]); } g_scaling_registers_update_required[index] = false; } } + +void is31fl3729_flush(void) { + is31fl3729_update_pwm_buffers(IS31FL3729_I2C_ADDRESS_1, 0); +#if defined(IS31FL3729_I2C_ADDRESS_2) + is31fl3729_update_pwm_buffers(IS31FL3729_I2C_ADDRESS_2, 1); +# if defined(IS31FL3729_I2C_ADDRESS_3) + is31fl3729_update_pwm_buffers(IS31FL3729_I2C_ADDRESS_3, 2); +# if defined(IS31FL3729_I2C_ADDRESS_4) + is31fl3729_update_pwm_buffers(IS31FL3729_I2C_ADDRESS_4, 3); +# endif +# endif +#endif +} diff --git a/drivers/led/issi/is31fl3729.h b/drivers/led/issi/is31fl3729.h index de666464927d..a7893fbd2fc1 100644 --- a/drivers/led/issi/is31fl3729.h +++ b/drivers/led/issi/is31fl3729.h @@ -27,6 +27,10 @@ #define IS31FL3729_I2C_ADDRESS_SDA 0x36 #define IS31FL3729_I2C_ADDRESS_VCC 0x37 +#if defined(RGB_MATRIX_IS31FL3729) +# define IS31FL3729_LED_COUNT RGB_MATRIX_LED_COUNT +#endif + typedef struct is31fl3729_led_t { uint8_t driver : 2; uint8_t r; @@ -34,8 +38,9 @@ typedef struct is31fl3729_led_t { uint8_t b; } __attribute__((packed)) is31fl3729_led_t; -extern const is31fl3729_led_t PROGMEM g_is31fl3729_leds[RGB_MATRIX_LED_COUNT]; +extern const is31fl3729_led_t PROGMEM g_is31fl3729_leds[IS31FL3729_LED_COUNT]; +void is31fl3729_init_drivers(void); void is31fl3729_init(uint8_t addr); void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data); bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); @@ -52,44 +57,46 @@ void is31fl3729_set_led_control_register(uint8_t index, bool red, bool green, bo void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index); void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index); +void is31fl3729_flush(void); + // Noise reduction using Spread Spectrum register -#define IS31FL3729_SPREAD_SPECTRUM_DISABLE 0b00000 -#define IS31FL3729_SPREAD_SPECTRUM_5_1980US 0b10000 -#define IS31FL3729_SPREAD_SPECTRUM_5_1200US 0b10001 -#define IS31FL3729_SPREAD_SPECTRUM_5_820US 0b10010 -#define IS31FL3729_SPREAD_SPECTRUM_5_660US 0b10011 -#define IS31FL3729_SPREAD_SPECTRUM_15_1980US 0b10100 -#define IS31FL3729_SPREAD_SPECTRUM_15_1200US 0b10101 -#define IS31FL3729_SPREAD_SPECTRUM_15_820US 0b10110 -#define IS31FL3729_SPREAD_SPECTRUM_15_660US 0b10111 -#define IS31FL3729_SPREAD_SPECTRUM_24_1980US 0b11000 -#define IS31FL3729_SPREAD_SPECTRUM_24_1200US 0b11001 -#define IS31FL3729_SPREAD_SPECTRUM_24_820US 0b11010 -#define IS31FL3729_SPREAD_SPECTRUM_24_660US 0b11011 -#define IS31FL3729_SPREAD_SPECTRUM_34_1980US 0b11100 -#define IS31FL3729_SPREAD_SPECTRUM_34_1200US 0b11101 -#define IS31FL3729_SPREAD_SPECTRUM_34_820US 0b11110 -#define IS31FL3729_SPREAD_SPECTRUM_34_660US 0b11111 +#define IS31FL3729_SSP_DISABLE 0x00 +#define IS31FL3729_SSP_5_1980US 0x10 +#define IS31FL3729_SSP_5_1200US 0x11 +#define IS31FL3729_SSP_5_820US 0x12 +#define IS31FL3729_SSP_5_660US 0x13 +#define IS31FL3729_SSP_15_1980US 0x14 +#define IS31FL3729_SSP_15_1200US 0x15 +#define IS31FL3729_SSP_15_820US 0x16 +#define IS31FL3729_SSP_15_660US 0x17 +#define IS31FL3729_SSP_24_1980US 0x18 +#define IS31FL3729_SSP_24_1200US 0x19 +#define IS31FL3729_SSP_24_820US 0x1A +#define IS31FL3729_SSP_24_660US 0x1B +#define IS31FL3729_SSP_34_1980US 0x1C +#define IS31FL3729_SSP_34_1200US 0x1D +#define IS31FL3729_SSP_34_820US 0x1E +#define IS31FL3729_SSP_34_660US 0x1F // Noise reduction using PWM Frequency register -#define IS31FL3729_PWM_FREQUENCY_55K_HZ 0b000 -#define IS31FL3729_PWM_FREQUENCY_32K_HZ 0b001 -#define IS31FL3729_PWM_FREQUENCY_4K_HZ 0b010 -#define IS31FL3729_PWM_FREQUENCY_2K_HZ 0b011 -#define IS31FL3729_PWM_FREQUENCY_1K_HZ 0b100 -#define IS31FL3729_PWM_FREQUENCY_500_HZ 0b101 // If SWx cannot be more than 4 -#define IS31FL3729_PWM_FREQUENCY_250_HZ 0b110 // If SWx cannot be more than 2 -#define IS31FL3729_PWM_FREQUENCY_80K_HZ 0b111 - -// Change SWx Setting using Configuation register -#define IS31FL3729_CONFIGURATION_SWS_15_9 0b0000001 // 15 CS x 9 SW matrix mode -#define IS31FL3729_CONFIGURATION_SWS_16_8 0b0010001 // 16 CS x 8 SW matrix mode -#define IS31FL3729_CONFIGURATION_SWS_16_7 0b0100001 // 16 CS x 7 SW matrix mode -#define IS31FL3729_CONFIGURATION_SWS_16_6 0b0110001 // 16 CS x 6 SW matrix mode -#define IS31FL3729_CONFIGURATION_SWS_16_5 0b1000001 // 16 CS x 5 SW matrix mode -#define IS31FL3729_CONFIGURATION_SWS_16_4 0b1010001 // 16 CS x 4 SW matrix mode -#define IS31FL3729_CONFIGURATION_SWS_16_3 0b1100001 // 16 CS x 3 SW matrix mode -#define IS31FL3729_CONFIGURATION_SWS_16_2 0b1110001 // 16 CS x 2 SW matrix mode +#define IS31FL3729_PWM_FREQ_55K_HZ 0x00 +#define IS31FL3729_PWM_FREQ_32K_HZ 0x01 +#define IS31FL3729_PWM_FREQ_4K_HZ 0x02 +#define IS31FL3729_PWM_FREQ_2K_HZ 0x03 +#define IS31FL3729_PWM_FREQ_1K_HZ 0x04 +#define IS31FL3729_PWM_FREQ_500_HZ 0x05 // If SWx cannot be more than 4 +#define IS31FL3729_PWM_FREQ_250_HZ 0x06 // If SWx cannot be more than 2 +#define IS31FL3729_PWM_FREQ_80K_HZ 0x07 + +// Change SWx Setting using Configuration register +#define IS31FL3729_CONFIG_SWS_15_9 0x01 // 15 CS x 9 SW matrix +#define IS31FL3729_CONFIG_SWS_16_8 0x11 // 16 CS x 8 SW matrix +#define IS31FL3729_CONFIG_SWS_16_7 0x21 // 16 CS x 7 SW matrix +#define IS31FL3729_CONFIG_SWS_16_6 0x31 // 16 CS x 6 SW matrix +#define IS31FL3729_CONFIG_SWS_16_5 0x41 // 16 CS x 5 SW matrix +#define IS31FL3729_CONFIG_SWS_16_4 0x51 // 16 CS x 4 SW matrix +#define IS31FL3729_CONFIG_SWS_16_3 0x61 // 16 CS x 3 SW matrix +#define IS31FL3729_CONFIG_SWS_16_2 0x71 // 16 CS x 2 SW matrix // Map CS SW locations to order in PWM / Scaling buffers // This matches the ORDER in the Datasheet Register not the POSITION From d3ab72fd2fc954be6ff21ca4ed8b836250a5c0a8 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Wed, 13 Dec 2023 19:04:35 +0700 Subject: [PATCH 18/26] Resolved changes again --- docs/feature_led_matrix.md | 2 -- docs/feature_rgb_matrix.md | 2 -- drivers/led/issi/is31fl3729-simple.c | 19 +++++++++---------- drivers/led/issi/is31fl3729-simple.h | 10 ++++++++++ drivers/led/issi/is31fl3729.c | 19 +++++++++---------- drivers/led/issi/is31fl3729.h | 10 ++++++++++ quantum/led_matrix/led_matrix_drivers.h | 2 ++ quantum/rgb_matrix/rgb_matrix_drivers.h | 2 ++ 8 files changed, 42 insertions(+), 24 deletions(-) diff --git a/docs/feature_led_matrix.md b/docs/feature_led_matrix.md index 10709579724d..97859d48709f 100644 --- a/docs/feature_led_matrix.md +++ b/docs/feature_led_matrix.md @@ -26,7 +26,6 @@ You can use between 1 and 4 IS31FL3729 IC's. Do not specify `IS31FL3729_I2C_ADDR | `IS31FL3729_PULLDOWNUP` | (Optional) Configuration for the Pull Up & Pull Down Register | 0x33 | | `IS31FL3729_SPREAD_SPECTRUM` | (Optional) Configuration for the Spread Spectrum Register | SSP_DISABLE | | `IS31FL3729_PWM_FREQUENCY` | (Optional) Configuration for the PWM Frequency Register | 32K_HZ | -| `IS31FL3729_DRIVER_COUNT` | (Required) How many LED driver IC's are present | | | `LED_MATRIX_LED_COUNT` | (Required) How many LED lights are present across all drivers | | | `IS31FL3729_I2C_ADDRESS_1` | (Required) Address for the first LED driver | | | `IS31FL3729_I2C_ADDRESS_2` | (Optional) Address for the second LED driver | | @@ -61,7 +60,6 @@ Here is an example using 2 drivers. #define IS31FL3729_I2C_ADDRESS_1 IS31FL3729_I2C_ADDRESS_GND #define IS31FL3729_I2C_ADDRESS_2 IS31FL3729_I2C_ADDRESS_SCL -#define IS31FL3729_DRIVER_COUNT 2 #define LED_DRIVER_1_LED_TOTAL 39 #define LED_DRIVER_2_LED_TOTAL 28 #define LED_MATRIX_LED_COUNT (LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL) diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md index a42b27adcdef..78a84797998d 100644 --- a/docs/feature_rgb_matrix.md +++ b/docs/feature_rgb_matrix.md @@ -26,7 +26,6 @@ You can use between 1 and 4 IS31FL3729 IC's. Do not specify `IS31FL3729_I2C_ADDR | `IS31FL3729_PULLDOWNUP` | (Optional) Configuration for the Pull Up & Pull Down Register | 0x33 | | `IS31FL3729_SPREAD_SPECTRUM` | (Optional) Configuration for the Spread Spectrum Register | SSP_DISABLE | | `IS31FL3729_PWM_FREQUENCY` | (Optional) Configuration for the PWM Frequency Register | 32K_HZ | -| `IS31FL3729_DRIVER_COUNT` | (Required) How many RGB driver IC's are present | | | `RGB_MATRIX_LED_COUNT` | (Required) How many RGB lights are present across all drivers | | | `IS31FL3729_I2C_ADDRESS_1` | (Required) Address for the first RGB driver | | | `IS31FL3729_I2C_ADDRESS_2` | (Optional) Address for the second RGB driver | | @@ -61,7 +60,6 @@ Here is an example using 2 drivers. #define IS31FL3729_I2C_ADDRESS_1 IS31FL3729_I2C_ADDRESS_GND #define IS31FL3729_I2C_ADDRESS_2 IS31FL3729_I2C_ADDRESS_SCL -#define IS31FL3729_DRIVER_COUNT 2 #define DRIVER_1_LED_TOTAL 39 #define DRIVER_2_LED_TOTAL 28 #define RGB_MATRIX_LED_COUNT (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL) diff --git a/drivers/led/issi/is31fl3729-simple.c b/drivers/led/issi/is31fl3729-simple.c index b13e6338cb8a..9125fa856cf1 100644 --- a/drivers/led/issi/is31fl3729-simple.c +++ b/drivers/led/issi/is31fl3729-simple.c @@ -59,8 +59,7 @@ #define IS31FL3729_PWM_REGISTER_COUNT 143 #define IS31FL3729_SCALINGS_REGISTER_COUNT 16 -// Transfer buffer for TWITransmitData() -uint8_t g_twi_transfer_buffer[20]; +uint8_t i2c_transfer_buffer[20]; // These buffers match the PWM & scaling registers. // Storing them like this is optimal for I2C transfers to the registers. @@ -72,15 +71,15 @@ bool g_scaling_registers_update_required[IS31FL3729_DRIVER_COUNT] = {false}; void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { // Set register address and register data ready to write - g_twi_transfer_buffer[0] = reg; - g_twi_transfer_buffer[1] = data; + i2c_transfer_buffer[0] = reg; + i2c_transfer_buffer[1] = data; #if IS31FL3729_I2C_PERSISTENCE > 0 for (uint8_t i = 0; i < IS31FL3729_I2C_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3729_I2C_TIMEOUT) == 0) break; + if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3729_I2C_TIMEOUT) == 0) break; } #else - i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3729_I2C_TIMEOUT); + i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3729_I2C_TIMEOUT); #endif } @@ -89,21 +88,21 @@ bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // datasheet does not mention it, but it auto-increments in 15x9 mode, and // hence does not require us to skip any addresses for (int i = 0; i <= IS31FL3729_PWM_REGISTER_COUNT; i += IS31FL3729_SCALINGS_REGISTER_COUNT) { - g_twi_transfer_buffer[0] = i; + i2c_transfer_buffer[0] = i; // copy the data from i to i+IS31FL3729_SCALINGS_REGISTER_COUNT // device will auto-increment register for data after the first byte // thus this sets registers 0x01-0x10, 0x11-0x20, etc. in one transfer - memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, IS31FL3729_SCALINGS_REGISTER_COUNT); + memcpy(i2c_transfer_buffer + 1, pwm_buffer + i, IS31FL3729_SCALINGS_REGISTER_COUNT); #if IS31FL3729_I2C_PERSISTENCE > 0 for (uint8_t i = 0; i < IS31FL3729_I2C_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, IS31FL3729_SCALINGS_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, i2c_transfer_buffer, IS31FL3729_SCALINGS_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, IS31FL3729_SCALINGS_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, i2c_transfer_buffer, IS31FL3729_SCALINGS_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { return false; } #endif diff --git a/drivers/led/issi/is31fl3729-simple.h b/drivers/led/issi/is31fl3729-simple.h index e33c4d1b3968..b5b73ee78295 100644 --- a/drivers/led/issi/is31fl3729-simple.h +++ b/drivers/led/issi/is31fl3729-simple.h @@ -31,6 +31,16 @@ # define IS31FL3729_LED_COUNT LED_MATRIX_LED_COUNT #endif +#if defined(IS31FL3729_I2C_ADDRESS_4) +# define IS31FL3729_DRIVER_COUNT 4 +#elif defined(IS31FL3729_I2C_ADDRESS_3) +# define IS31FL3729_DRIVER_COUNT 3 +#elif defined(IS31FL3729_I2C_ADDRESS_2) +# define IS31FL3729_DRIVER_COUNT 2 +#elif defined(IS31FL3729_I2C_ADDRESS_1) +# define IS31FL3729_DRIVER_COUNT 1 +#endif + typedef struct is31fl3729_led_t { uint8_t driver : 2; uint8_t v; diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index 534db930ea59..c22927fa6a11 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -59,8 +59,7 @@ #define IS31FL3729_PWM_REGISTER_COUNT 143 #define IS31FL3729_SCALINGS_REGISTER_COUNT 16 -// Transfer buffer for TWITransmitData() -uint8_t g_twi_transfer_buffer[20]; +uint8_t i2c_transfer_buffer[20]; // These buffers match the PWM & scaling registers. // Storing them like this is optimal for I2C transfers to the registers. @@ -72,15 +71,15 @@ bool g_scaling_registers_update_required[IS31FL3729_DRIVER_COUNT] = {false}; void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { // Set register address and register data ready to write - g_twi_transfer_buffer[0] = reg; - g_twi_transfer_buffer[1] = data; + i2c_transfer_buffer[0] = reg; + i2c_transfer_buffer[1] = data; #if IS31FL3729_I2C_PERSISTENCE > 0 for (uint8_t i = 0; i < IS31FL3729_I2C_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3729_I2C_TIMEOUT) == 0) break; + if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3729_I2C_TIMEOUT) == 0) break; } #else - i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3729_I2C_TIMEOUT); + i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3729_I2C_TIMEOUT); #endif } @@ -89,21 +88,21 @@ bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // datasheet does not mention it, but it auto-increments in 15x9 mode, and // hence does not require us to skip any addresses for (int i = 0; i <= IS31FL3729_PWM_REGISTER_COUNT; i += IS31FL3729_SCALINGS_REGISTER_COUNT) { - g_twi_transfer_buffer[0] = i; + i2c_transfer_buffer[0] = i; // copy the data from i to i+IS31FL3729_SCALINGS_REGISTER_COUNT // device will auto-increment register for data after the first byte // thus this sets registers 0x01-0x10, 0x11-0x20, etc. in one transfer - memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, IS31FL3729_SCALINGS_REGISTER_COUNT); + memcpy(i2c_transfer_buffer + 1, pwm_buffer + i, IS31FL3729_SCALINGS_REGISTER_COUNT); #if IS31FL3729_I2C_PERSISTENCE > 0 for (uint8_t i = 0; i < IS31FL3729_I2C_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, IS31FL3729_SCALINGS_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, i2c_transfer_buffer, IS31FL3729_SCALINGS_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, IS31FL3729_SCALINGS_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, i2c_transfer_buffer, IS31FL3729_SCALINGS_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { return false; } #endif diff --git a/drivers/led/issi/is31fl3729.h b/drivers/led/issi/is31fl3729.h index a7893fbd2fc1..a98ac8e1834b 100644 --- a/drivers/led/issi/is31fl3729.h +++ b/drivers/led/issi/is31fl3729.h @@ -31,6 +31,16 @@ # define IS31FL3729_LED_COUNT RGB_MATRIX_LED_COUNT #endif +#if defined(IS31FL3729_I2C_ADDRESS_4) +# define IS31FL3729_DRIVER_COUNT 4 +#elif defined(IS31FL3729_I2C_ADDRESS_3) +# define IS31FL3729_DRIVER_COUNT 3 +#elif defined(IS31FL3729_I2C_ADDRESS_2) +# define IS31FL3729_DRIVER_COUNT 2 +#elif defined(IS31FL3729_I2C_ADDRESS_1) +# define IS31FL3729_DRIVER_COUNT 1 +#endif + typedef struct is31fl3729_led_t { uint8_t driver : 2; uint8_t r; diff --git a/quantum/led_matrix/led_matrix_drivers.h b/quantum/led_matrix/led_matrix_drivers.h index d792600e1faf..a961784a62f8 100644 --- a/quantum/led_matrix/led_matrix_drivers.h +++ b/quantum/led_matrix/led_matrix_drivers.h @@ -7,6 +7,8 @@ #if defined(LED_MATRIX_IS31FL3218) # include "is31fl3218-mono.h" +#elif defined(LED_MATRIX_IS31FL3729) +# include "is31fl3729-mono.h" #elif defined(LED_MATRIX_IS31FL3731) # include "is31fl3731-mono.h" #elif defined(LED_MATRIX_IS31FL3733) diff --git a/quantum/rgb_matrix/rgb_matrix_drivers.h b/quantum/rgb_matrix/rgb_matrix_drivers.h index 8f919b1b3c7a..a24cb03a1856 100644 --- a/quantum/rgb_matrix/rgb_matrix_drivers.h +++ b/quantum/rgb_matrix/rgb_matrix_drivers.h @@ -9,6 +9,8 @@ # include "aw20216s.h" #elif defined(RGB_MATRIX_IS31FL3218) # include "is31fl3218.h" +#elif defined(RGB_MATRIX_IS31FL3729) +# include "is31fl3729.h" #elif defined(RGB_MATRIX_IS31FL3731) # include "is31fl3731.h" #elif defined(RGB_MATRIX_IS31FL3733) From 050038abfd381215c9ba37d4ef36d33a54fd02a8 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Fri, 29 Dec 2023 15:40:09 +0700 Subject: [PATCH 19/26] Another suggest change resolved --- drivers/led/issi/is31fl3729-simple.c | 45 +++++++++-------------- drivers/led/issi/is31fl3729-simple.h | 15 ++++++-- drivers/led/issi/is31fl3729.c | 55 ++++++++++------------------ drivers/led/issi/is31fl3729.h | 15 ++++++-- 4 files changed, 60 insertions(+), 70 deletions(-) diff --git a/drivers/led/issi/is31fl3729-simple.c b/drivers/led/issi/is31fl3729-simple.c index 9125fa856cf1..4f2a9bc501e8 100644 --- a/drivers/led/issi/is31fl3729-simple.c +++ b/drivers/led/issi/is31fl3729-simple.c @@ -21,15 +21,6 @@ #include "i2c_master.h" #include "wait.h" -// Registers -#define IS31FL3729_REG_SCALING 0x90 -#define IS31FL3729_REG_CONFIGURATION 0xA0 -#define IS31FL3729_REG_GLOBALCURRENT 0xA1 -#define IS31FL3729_REG_PULLDOWNUP 0xB0 -#define IS31FL3729_REG_SPREAD_SPECTRUM 0xB1 -#define IS31FL3729_REG_PWM_FREQUENCY 0xB2 -#define IS31FL3729_REG_RESET 0xCF - // Set defaults for Timeout and Persistence #ifndef IS31FL3729_I2C_TIMEOUT # define IS31FL3729_I2C_TIMEOUT 100 @@ -57,7 +48,7 @@ // Set buffer sizes #define IS31FL3729_PWM_REGISTER_COUNT 143 -#define IS31FL3729_SCALINGS_REGISTER_COUNT 16 +#define IS31FL3729_SCALING_REGISTER_COUNT 16 uint8_t i2c_transfer_buffer[20]; @@ -66,7 +57,7 @@ uint8_t i2c_transfer_buffer[20]; uint8_t g_pwm_buffer[IS31FL3729_DRIVER_COUNT][IS31FL3729_PWM_REGISTER_COUNT]; bool g_pwm_buffer_update_required[IS31FL3729_DRIVER_COUNT] = {false}; -uint8_t g_scaling_registers[IS31FL3729_DRIVER_COUNT][IS31FL3729_SCALINGS_REGISTER_COUNT]; +uint8_t g_scaling_registers[IS31FL3729_DRIVER_COUNT][IS31FL3729_SCALING_REGISTER_COUNT]; bool g_scaling_registers_update_required[IS31FL3729_DRIVER_COUNT] = {false}; void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { @@ -84,25 +75,25 @@ void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { } bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { - // iterate over the pwm_buffer contents at IS31FL3729_SCALINGS_REGISTER_COUNT byte intervals + // iterate over the pwm_buffer contents at IS31FL3729_SCALING_REGISTER_COUNT byte intervals // datasheet does not mention it, but it auto-increments in 15x9 mode, and // hence does not require us to skip any addresses - for (int i = 0; i <= IS31FL3729_PWM_REGISTER_COUNT; i += IS31FL3729_SCALINGS_REGISTER_COUNT) { + for (int i = 0; i <= IS31FL3729_PWM_REGISTER_COUNT; i += IS31FL3729_SCALING_REGISTER_COUNT) { i2c_transfer_buffer[0] = i; - // copy the data from i to i+IS31FL3729_SCALINGS_REGISTER_COUNT + // copy the data from i to i+IS31FL3729_SCALING_REGISTER_COUNT // device will auto-increment register for data after the first byte // thus this sets registers 0x01-0x10, 0x11-0x20, etc. in one transfer - memcpy(i2c_transfer_buffer + 1, pwm_buffer + i, IS31FL3729_SCALINGS_REGISTER_COUNT); + memcpy(i2c_transfer_buffer + 1, pwm_buffer + i, IS31FL3729_SCALING_REGISTER_COUNT); #if IS31FL3729_I2C_PERSISTENCE > 0 for (uint8_t i = 0; i < IS31FL3729_I2C_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, i2c_transfer_buffer, IS31FL3729_SCALINGS_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, i2c_transfer_buffer, IS31FL3729_SCALING_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, i2c_transfer_buffer, IS31FL3729_SCALINGS_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, i2c_transfer_buffer, IS31FL3729_SCALING_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { return false; } #endif @@ -126,16 +117,16 @@ void is31fl3729_init_drivers(void) { #endif for (int i = 0; i < IS31FL3729_LED_COUNT; i++) { - is31fl3729_set_led_control_register(i, true); + is31fl3729_set_scaling_register(i, 0xFF); } - is31fl3729_update_led_control_registers(IS31FL3729_I2C_ADDRESS_1, 0); + is31fl3729_update_scaling_registers(IS31FL3729_I2C_ADDRESS_1, 0); #if defined(IS31FL3729_I2C_ADDRESS_2) - is31fl3729_update_led_control_registers(IS31FL3729_I2C_ADDRESS_2, 1); + is31fl3729_update_scaling_registers(IS31FL3729_I2C_ADDRESS_2, 1); # if defined(IS31FL3729_I2C_ADDRESS_3) - is31fl3729_update_led_control_registers(IS31FL3729_I2C_ADDRESS_3, 2); + is31fl3729_update_scaling_registers(IS31FL3729_I2C_ADDRESS_3, 2); # if defined(IS31FL3729_I2C_ADDRESS_4) - is31fl3729_update_led_control_registers(IS31FL3729_I2C_ADDRESS_4, 3); + is31fl3729_update_scaling_registers(IS31FL3729_I2C_ADDRESS_4, 3); # endif # endif #endif @@ -186,7 +177,7 @@ void is31fl3729_set_value_all(uint8_t value) { } } -void is31fl3729_set_led_control_register(uint8_t index, bool value) { +void is31fl3729_set_scaling_register(uint8_t index, uint8_t value) { is31fl3729_led_t led; memcpy_P(&led, (&g_is31fl3729_leds[index]), sizeof(led)); @@ -195,9 +186,7 @@ void is31fl3729_set_led_control_register(uint8_t index, bool value) { // only enable them, since they should be default disabled int cs_value = (led.v & 0x0F) - 1; - if (value) { - g_scaling_registers[led.driver][cs_value] = 0xFF; - } + g_scaling_registers[led.driver][cs_value] = value; g_scaling_registers_update_required[led.driver] = true; } @@ -210,9 +199,9 @@ void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index) { g_pwm_buffer_update_required[index] = false; } -void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index) { +void is31fl3729_update_scaling_registers(uint8_t addr, uint8_t index) { if (g_scaling_registers_update_required[index]) { - for (int i = 0; i < IS31FL3729_SCALINGS_REGISTER_COUNT; i++) { + for (int i = 0; i < IS31FL3729_SCALING_REGISTER_COUNT; i++) { is31fl3729_write_register(addr, IS31FL3729_REG_SCALING + i, g_scaling_registers[index][i]); } diff --git a/drivers/led/issi/is31fl3729-simple.h b/drivers/led/issi/is31fl3729-simple.h index b5b73ee78295..0e686923eef5 100644 --- a/drivers/led/issi/is31fl3729-simple.h +++ b/drivers/led/issi/is31fl3729-simple.h @@ -21,6 +21,15 @@ #include #include #include "progmem.h" +#include "util.h" + +#define IS31FL3729_REG_SCALING 0x90 +#define IS31FL3729_REG_CONFIGURATION 0xA0 +#define IS31FL3729_REG_GLOBALCURRENT 0xA1 +#define IS31FL3729_REG_PULLDOWNUP 0xB0 +#define IS31FL3729_REG_SPREAD_SPECTRUM 0xB1 +#define IS31FL3729_REG_PWM_FREQUENCY 0xB2 +#define IS31FL3729_REG_RESET 0xCF #define IS31FL3729_I2C_ADDRESS_GND 0x34 #define IS31FL3729_I2C_ADDRESS_SCL 0x35 @@ -44,7 +53,7 @@ typedef struct is31fl3729_led_t { uint8_t driver : 2; uint8_t v; -} __attribute__((packed)) is31fl3729_led_t; +} PACKED is31fl3729_led_t; extern const is31fl3729_led_t PROGMEM g_is31fl3729_leds[IS31FL3729_LED_COUNT]; @@ -56,14 +65,14 @@ bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); void is31fl3729_set_value(int index, uint8_t value); void is31fl3729_set_value_all(uint8_t value); -void is31fl3729_set_led_control_register(uint8_t index, bool value); +void is31fl3729_set_scaling_register(uint8_t index, uint8_t value); // This should not be called from an interrupt // (eg. from a timer interrupt). // Call this while idle (in between matrix scans). // If the buffer is dirty, it will update the driver with the buffer. void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index); -void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index); +void is31fl3729_update_scaling_registers(uint8_t addr, uint8_t index); void is31fl3729_flush(void); diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index c22927fa6a11..a57f9f18485a 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -21,15 +21,6 @@ #include "i2c_master.h" #include "wait.h" -// Registers -#define IS31FL3729_REG_SCALING 0x90 -#define IS31FL3729_REG_CONFIGURATION 0xA0 -#define IS31FL3729_REG_GLOBALCURRENT 0xA1 -#define IS31FL3729_REG_PULLDOWNUP 0xB0 -#define IS31FL3729_REG_SPREAD_SPECTRUM 0xB1 -#define IS31FL3729_REG_PWM_FREQUENCY 0xB2 -#define IS31FL3729_REG_RESET 0xCF - // Set defaults for Timeout and Persistence #ifndef IS31FL3729_I2C_TIMEOUT # define IS31FL3729_I2C_TIMEOUT 100 @@ -57,7 +48,7 @@ // Set buffer sizes #define IS31FL3729_PWM_REGISTER_COUNT 143 -#define IS31FL3729_SCALINGS_REGISTER_COUNT 16 +#define IS31FL3729_SCALING_REGISTER_COUNT 16 uint8_t i2c_transfer_buffer[20]; @@ -66,7 +57,7 @@ uint8_t i2c_transfer_buffer[20]; uint8_t g_pwm_buffer[IS31FL3729_DRIVER_COUNT][IS31FL3729_PWM_REGISTER_COUNT]; bool g_pwm_buffer_update_required[IS31FL3729_DRIVER_COUNT] = {false}; -uint8_t g_scaling_registers[IS31FL3729_DRIVER_COUNT][IS31FL3729_SCALINGS_REGISTER_COUNT]; +uint8_t g_scaling_registers[IS31FL3729_DRIVER_COUNT][IS31FL3729_SCALING_REGISTER_COUNT]; bool g_scaling_registers_update_required[IS31FL3729_DRIVER_COUNT] = {false}; void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { @@ -84,25 +75,25 @@ void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { } bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { - // iterate over the pwm_buffer contents at IS31FL3729_SCALINGS_REGISTER_COUNT byte intervals + // iterate over the pwm_buffer contents at IS31FL3729_SCALING_REGISTER_COUNT byte intervals // datasheet does not mention it, but it auto-increments in 15x9 mode, and // hence does not require us to skip any addresses - for (int i = 0; i <= IS31FL3729_PWM_REGISTER_COUNT; i += IS31FL3729_SCALINGS_REGISTER_COUNT) { + for (int i = 0; i <= IS31FL3729_PWM_REGISTER_COUNT; i += IS31FL3729_SCALING_REGISTER_COUNT) { i2c_transfer_buffer[0] = i; - // copy the data from i to i+IS31FL3729_SCALINGS_REGISTER_COUNT + // copy the data from i to i+IS31FL3729_SCALING_REGISTER_COUNT // device will auto-increment register for data after the first byte // thus this sets registers 0x01-0x10, 0x11-0x20, etc. in one transfer - memcpy(i2c_transfer_buffer + 1, pwm_buffer + i, IS31FL3729_SCALINGS_REGISTER_COUNT); + memcpy(i2c_transfer_buffer + 1, pwm_buffer + i, IS31FL3729_SCALING_REGISTER_COUNT); #if IS31FL3729_I2C_PERSISTENCE > 0 for (uint8_t i = 0; i < IS31FL3729_I2C_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, i2c_transfer_buffer, IS31FL3729_SCALINGS_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, i2c_transfer_buffer, IS31FL3729_SCALING_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, i2c_transfer_buffer, IS31FL3729_SCALINGS_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, i2c_transfer_buffer, IS31FL3729_SCALING_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { return false; } #endif @@ -126,16 +117,16 @@ void is31fl3729_init_drivers(void) { #endif for (int i = 0; i < IS31FL3729_LED_COUNT; i++) { - is31fl3729_set_led_control_register(i, true, true, true); + is31fl3729_set_scaling_register(i, 0xFF, 0xFF, 0xFF); } - is31fl3729_update_led_control_registers(IS31FL3729_I2C_ADDRESS_1, 0); + is31fl3729_update_scaling_registers(IS31FL3729_I2C_ADDRESS_1, 0); #if defined(IS31FL3729_I2C_ADDRESS_2) - is31fl3729_update_led_control_registers(IS31FL3729_I2C_ADDRESS_2, 1); + is31fl3729_update_scaling_registers(IS31FL3729_I2C_ADDRESS_2, 1); # if defined(IS31FL3729_I2C_ADDRESS_3) - is31fl3729_update_led_control_registers(IS31FL3729_I2C_ADDRESS_3, 2); + is31fl3729_update_scaling_registers(IS31FL3729_I2C_ADDRESS_3, 2); # if defined(IS31FL3729_I2C_ADDRESS_4) - is31fl3729_update_led_control_registers(IS31FL3729_I2C_ADDRESS_4, 3); + is31fl3729_update_scaling_registers(IS31FL3729_I2C_ADDRESS_4, 3); # endif # endif #endif @@ -188,7 +179,7 @@ void is31fl3729_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { } } -void is31fl3729_set_led_control_register(uint8_t index, bool red, bool green, bool blue) { +void is31fl3729_set_scaling_register(uint8_t index, uint8_t red, uint8_t green, uint8_t blue) { is31fl3729_led_t led; memcpy_P(&led, (&g_is31fl3729_leds[index]), sizeof(led)); @@ -199,17 +190,9 @@ void is31fl3729_set_led_control_register(uint8_t index, bool red, bool green, bo int cs_green = (led.g & 0x0F) - 1; int cs_blue = (led.b & 0x0F) - 1; - if (red) { - g_scaling_registers[led.driver][cs_red] = 0xFF; - } - - if (green) { - g_scaling_registers[led.driver][cs_green] = 0xFF; - } - - if (blue) { - g_scaling_registers[led.driver][cs_blue] = 0xFF; - } + g_scaling_registers[led.driver][cs_red] = red; + g_scaling_registers[led.driver][cs_green] = green; + g_scaling_registers[led.driver][cs_blue] = blue; g_scaling_registers_update_required[led.driver] = true; } @@ -222,9 +205,9 @@ void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index) { g_pwm_buffer_update_required[index] = false; } -void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index) { +void is31fl3729_update_scaling_registers(uint8_t addr, uint8_t index) { if (g_scaling_registers_update_required[index]) { - for (int i = 0; i < IS31FL3729_SCALINGS_REGISTER_COUNT; i++) { + for (int i = 0; i < IS31FL3729_SCALING_REGISTER_COUNT; i++) { is31fl3729_write_register(addr, IS31FL3729_REG_SCALING + i, g_scaling_registers[index][i]); } diff --git a/drivers/led/issi/is31fl3729.h b/drivers/led/issi/is31fl3729.h index a98ac8e1834b..55b87a8d122b 100644 --- a/drivers/led/issi/is31fl3729.h +++ b/drivers/led/issi/is31fl3729.h @@ -21,6 +21,15 @@ #include #include #include "progmem.h" +#include "util.h" + +#define IS31FL3729_REG_SCALING 0x90 +#define IS31FL3729_REG_CONFIGURATION 0xA0 +#define IS31FL3729_REG_GLOBALCURRENT 0xA1 +#define IS31FL3729_REG_PULLDOWNUP 0xB0 +#define IS31FL3729_REG_SPREAD_SPECTRUM 0xB1 +#define IS31FL3729_REG_PWM_FREQUENCY 0xB2 +#define IS31FL3729_REG_RESET 0xCF #define IS31FL3729_I2C_ADDRESS_GND 0x34 #define IS31FL3729_I2C_ADDRESS_SCL 0x35 @@ -46,7 +55,7 @@ typedef struct is31fl3729_led_t { uint8_t r; uint8_t g; uint8_t b; -} __attribute__((packed)) is31fl3729_led_t; +} PACKED is31fl3729_led_t; extern const is31fl3729_led_t PROGMEM g_is31fl3729_leds[IS31FL3729_LED_COUNT]; @@ -58,14 +67,14 @@ bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); void is31fl3729_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); void is31fl3729_set_color_all(uint8_t red, uint8_t green, uint8_t blue); -void is31fl3729_set_led_control_register(uint8_t index, bool red, bool green, bool blue); +void is31fl3729_set_scaling_register(uint8_t index, uint8_t red, uint8_t green, uint8_t blue); // This should not be called from an interrupt // (eg. from a timer interrupt). // Call this while idle (in between matrix scans). // If the buffer is dirty, it will update the driver with the buffer. void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index); -void is31fl3729_update_led_control_registers(uint8_t addr, uint8_t index); +void is31fl3729_update_scaling_registers(uint8_t addr, uint8_t index); void is31fl3729_flush(void); From 10ae2eca98191f51d07672e73cb7fb3bc26cac70 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Fri, 29 Dec 2023 16:31:41 +0700 Subject: [PATCH 20/26] Revert docs change back to original state --- docs/feature_led_matrix.md | 82 +---------------------------------- docs/feature_rgb_matrix.md | 89 ++------------------------------------ 2 files changed, 5 insertions(+), 166 deletions(-) diff --git a/docs/feature_led_matrix.md b/docs/feature_led_matrix.md index 97859d48709f..3a3a9dbf844c 100644 --- a/docs/feature_led_matrix.md +++ b/docs/feature_led_matrix.md @@ -5,86 +5,6 @@ This feature allows you to use LED matrices driven by external drivers. It hooks If you want to use RGB LED's you should use the [RGB Matrix Subsystem](feature_rgb_matrix.md) instead. ## Driver configuration :id=driver-configuration ---- -### IS31FL3729 :id=is31fl3729 - -There is basic support for addressable LED matrix lighting with the I2C IS31FL3729 LED controller. To enable it, add this to your `rules.mk`: - -```make -LED_MATRIX_ENABLE = yes -LED_MATRIX_DRIVER = is31fl3729 -``` - -You can use between 1 and 4 IS31FL3729 IC's. Do not specify `IS31FL3729_I2C_ADDRESS_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: - -| Variable | Description | Default | -|----------|-------------|---------| -| `IS31FL3729_I2C_TIMEOUT` | (Optional) How long to wait for i2c messages, in milliseconds | 100 | -| `IS31FL3729_I2C_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 | -| `IS31FL3729_CONFIGURATION` | (Optional) Configuration for the Configuration Register | SWS_15_9 | -| `IS31FL3729_GLOBALCURRENT` | (Optional) Configuration for the Global Current Register | 0x40 | -| `IS31FL3729_PULLDOWNUP` | (Optional) Configuration for the Pull Up & Pull Down Register | 0x33 | -| `IS31FL3729_SPREAD_SPECTRUM` | (Optional) Configuration for the Spread Spectrum Register | SSP_DISABLE | -| `IS31FL3729_PWM_FREQUENCY` | (Optional) Configuration for the PWM Frequency Register | 32K_HZ | -| `LED_MATRIX_LED_COUNT` | (Required) How many LED lights are present across all drivers | | -| `IS31FL3729_I2C_ADDRESS_1` | (Required) Address for the first LED driver | | -| `IS31FL3729_I2C_ADDRESS_2` | (Optional) Address for the second LED driver | | -| `IS31FL3729_I2C_ADDRESS_3` | (Optional) Address for the third LED driver | | -| `IS31FL3729_I2C_ADDRESS_4` | (Optional) Address for the fourth LED driver | | - -The IS31FL3729 IC's support multiple matrix layouts. By default 15 x 9 matrix layout is used (`IS31FL3729_CONFIGURATION` is given the value of `IS31FL3729_CONFIG_SWS_15_9`), the values that can be set to choose matrix layouts are as follows: - -| `IS31FL3729_CONFIGURATION` | Description | -|----------------------------|-------------| -| `IS31FL3729_CONFIG_SWS_15_9` | (Default) 15 CS x 9 SW matrix | -| `IS31FL3729_CONFIG_SWS_16_8` | 16 CS x 8 SW matrix | -| `IS31FL3729_CONFIG_SWS_16_7` | 16 CS x 7 SW matrix | -| `IS31FL3729_CONFIG_SWS_16_6` | 16 CS x 6 SW matrix | -| `IS31FL3729_CONFIG_SWS_16_5` | 16 CS x 5 SW matrix | -| `IS31FL3729_CONFIG_SWS_16_4` | 16 CS x 4 SW matrix | -| `IS31FL3729_CONFIG_SWS_16_3` | 16 CS x 3 SW matrix | -| `IS31FL3729_CONFIG_SWS_16_2` | 16 CS x 2 SW matrix | - -Here is an example using 2 drivers. - -```c -// This is a 7-bit address, that gets left-shifted and bit 0 -// set to 0 for write, 1 for read (as per I2C protocol) -// The address will vary depending on your wiring: -// 00 AD <-> GND -// 01 AD <-> SCL -// 10 AD <-> SDA -// 11 AD <-> VCC -// ADDR represents A2:A1 of the 7-bit address. -// The result is: 0b01101(ADDR) -#define IS31FL3729_I2C_ADDRESS_1 IS31FL3729_I2C_ADDRESS_GND -#define IS31FL3729_I2C_ADDRESS_2 IS31FL3729_I2C_ADDRESS_SCL - -#define LED_DRIVER_1_LED_TOTAL 39 -#define LED_DRIVER_2_LED_TOTAL 28 -#define LED_MATRIX_LED_COUNT (LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL) -``` - -!> Note the parentheses, this is so when `LED_MATRIX_LED_COUNT` is used in code and expanded, the values are added together before any additional math is applied to them. As an example, `rand() % (LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL)` will give very different results than `rand() % LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL`. - -For split keyboards using `LED_MATRIX_SPLIT` with an LED driver, you can either have the same driver address or different driver addresses. If using different addresses, use `IS31FL3729_I2C_ADDRESS_1` for one and `IS31FL3729_I2C_ADDRESS_2` for the other one. Then, in `g_is31fl3729_leds`, fill out the correct driver index (0 or 1). If using one address, use `IS31FL3729_I2C_ADDRESS_1` for both, and use index 0 for `g_is31fl3729_leds`. - -Define these arrays listing all the LEDs in your `.c`: - -```c -const is31fl3729_led_t PROGMEM g_is31fl3729_leds[LED_MATRIX_LED_COUNT] = { -/* Refer to IS31 manual for these locations - * driver - * | LED address - * | | */ - { 0, CS1_SW1 }, - { 0, CS1_SW8 }, - // ... -} -``` - -Where `CSx_SWy` is the location of the LED in the matrix defined by [the datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3729_DS.pdf) and the header file `drivers/led/issi/is31fl3729-simple.h`. The `driver` is the index of the driver you defined in your `config.h` (`0`, `1`, `2`, or `3` ). - --- ### IS31FL3731 :id=is31fl3731 @@ -95,7 +15,7 @@ LED_MATRIX_ENABLE = yes LED_MATRIX_DRIVER = is31fl3731 ``` -You can use between 1 and 4 IS31FL3731 IC's. Do not specify `IS31FL3731_I2C_ADDRESS_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: +You can use between 1 and 4 IS31FL3731 IC's. Do not specify `LED_DRIVER_ADDR_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: | Variable | Description | Default | |----------|-------------|---------| diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md index 78a84797998d..d05d768ceb85 100644 --- a/docs/feature_rgb_matrix.md +++ b/docs/feature_rgb_matrix.md @@ -5,87 +5,6 @@ This feature allows you to use RGB LED matrices driven by external drivers. It h If you want to use single color LED's you should use the [LED Matrix Subsystem](feature_led_matrix.md) instead. ## Driver configuration :id=driver-configuration ---- -### IS31FL3729 :id=is31fl3729 - -There is basic support for addressable RGB matrix lighting with the I2C IS31FL3729 RGB controller. To enable it, add this to your `rules.mk`: - -```make -RGB_MATRIX_ENABLE = yes -RGB_MATRIX_DRIVER = is31fl3729 -``` - -You can use between 1 and 4 IS31FL3729 IC's. Do not specify `IS31FL3729_I2C_ADDRESS_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: - -| Variable | Description | Default | -|----------|-------------|---------| -| `IS31FL3729_I2C_TIMEOUT` | (Optional) How long to wait for i2c messages, in milliseconds | 100 | -| `IS31FL3729_I2C_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 | -| `IS31FL3729_CONFIGURATION` | (Optional) Configuration for the Configuration Register | SWS_15_9 | -| `IS31FL3729_GLOBALCURRENT` | (Optional) Configuration for the Global Current Register | 0x40 | -| `IS31FL3729_PULLDOWNUP` | (Optional) Configuration for the Pull Up & Pull Down Register | 0x33 | -| `IS31FL3729_SPREAD_SPECTRUM` | (Optional) Configuration for the Spread Spectrum Register | SSP_DISABLE | -| `IS31FL3729_PWM_FREQUENCY` | (Optional) Configuration for the PWM Frequency Register | 32K_HZ | -| `RGB_MATRIX_LED_COUNT` | (Required) How many RGB lights are present across all drivers | | -| `IS31FL3729_I2C_ADDRESS_1` | (Required) Address for the first RGB driver | | -| `IS31FL3729_I2C_ADDRESS_2` | (Optional) Address for the second RGB driver | | -| `IS31FL3729_I2C_ADDRESS_3` | (Optional) Address for the third RGB driver | | -| `IS31FL3729_I2C_ADDRESS_4` | (Optional) Address for the fourth RGB driver | | - -The IS31FL3729 IC's support multiple matrix layouts. By default 15 x 9 matrix layout is used (`IS31FL3729_CONFIGURATION` is given the value of `IS31FL3729_CONFIG_SWS_15_9`), the values that can be set to choose matrix layouts are as follows: - -| `IS31FL3729_CONFIGURATION` | Description | -|----------------------------|-------------| -| `IS31FL3729_CONFIG_SWS_15_9` | (Default) 15 CS x 9 SW matrix | -| `IS31FL3729_CONFIG_SWS_16_8` | 16 CS x 8 SW matrix | -| `IS31FL3729_CONFIG_SWS_16_7` | 16 CS x 7 SW matrix | -| `IS31FL3729_CONFIG_SWS_16_6` | 16 CS x 6 SW matrix | -| `IS31FL3729_CONFIG_SWS_16_5` | 16 CS x 5 SW matrix | -| `IS31FL3729_CONFIG_SWS_16_4` | 16 CS x 4 SW matrix | -| `IS31FL3729_CONFIG_SWS_16_3` | 16 CS x 3 SW matrix | -| `IS31FL3729_CONFIG_SWS_16_2` | 16 CS x 2 SW matrix | - -Here is an example using 2 drivers. - -```c -// This is a 7-bit address, that gets left-shifted and bit 0 -// set to 0 for write, 1 for read (as per I2C protocol) -// The address will vary depending on your wiring: -// 00 AD <-> GND -// 01 AD <-> SCL -// 10 AD <-> SDA -// 11 AD <-> VCC -// ADDR represents A2:A1 of the 7-bit address. -// The result is: 0b01101(ADDR) -#define IS31FL3729_I2C_ADDRESS_1 IS31FL3729_I2C_ADDRESS_GND -#define IS31FL3729_I2C_ADDRESS_2 IS31FL3729_I2C_ADDRESS_SCL - -#define DRIVER_1_LED_TOTAL 39 -#define DRIVER_2_LED_TOTAL 28 -#define RGB_MATRIX_LED_COUNT (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL) -``` - -!> Note the parentheses, this is so when `RGB_MATRIX_LED_COUNT` is used in code and expanded, the values are added together before any additional math is applied to them. As an example, `rand() % (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)` will give very different results than `rand() % DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL`. - -For split keyboards using `RGB_MATRIX_SPLIT` with an LED driver, you can either have the same driver address or different driver addresses. If using different addresses, use `IS31FL3729_I2C_ADDRESS_1` for one and `IS31FL3729_I2C_ADDRESS_2` for the other one. Then, in `g_is31fl3729_leds`, fill out the correct driver index (0 or 1). If using one address, use `IS31FL3729_I2C_ADDRESS_1` for both, and use index 0 for `g_is31fl3729_leds`. - -Define these arrays listing all the LEDs in your `.c`: - -```c -const is31fl3729_led_t PROGMEM g_is31fl3729_leds[RGB_MATRIX_LED_COUNT] = { -/* Refer to IS31 manual for these locations - * driver - * | R location - * | | G location - * | | | B location - * | | | | */ - {0, CS1_SW1, CS2_SW1, CS3_SW1}, - .... -} -``` - -Where `CSx_SWy` is the location of the LED in the matrix defined by [the datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3729_DS.pdf) and the header file `drivers/led/issi/is31fl3729.h`. The `driver` is the index of the driver you defined in your `config.h` (`0`, `1`, `2`, or `3`). - --- ### IS31FL3731 :id=is31fl3731 @@ -96,7 +15,7 @@ RGB_MATRIX_ENABLE = yes RGB_MATRIX_DRIVER = is31fl3731 ``` -You can use between 1 and 4 IS31FL3731 IC's. Do not specify `IS31FL3731_I2C_ADDRESS_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: +You can use between 1 and 4 IS31FL3731 IC's. Do not specify `DRIVER_ADDR_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: | Variable | Description | Default | |----------|-------------|---------| @@ -160,7 +79,7 @@ RGB_MATRIX_ENABLE = yes RGB_MATRIX_DRIVER = is31fl3733 ``` -You can use between 1 and 4 IS31FL3733 IC's. Do not specify `IS31FL3733_I2C_ADDRESS_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: +You can use between 1 and 4 IS31FL3733 IC's. Do not specify `DRIVER_ADDR_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`: | Variable | Description | Default | |----------|-------------|---------| @@ -243,7 +162,7 @@ There is basic support for addressable RGB matrix lighting with the I2C IS31FL37 RGB_MATRIX_ENABLE = yes RGB_MATRIX_DRIVER = is31fl3736 ``` -You can use between 1 and 4 IS31FL3736 IC's. Do not specify `IS31FL3736_I2C_ADDRESS_` defines for IC's that are not present on your keyboard. +You can use between 1 and 4 IS31FL3736 IC's. Do not specify `DRIVER_ADDR_` defines for IC's that are not present on your keyboard. Configure the hardware via your `config.h`: @@ -318,7 +237,7 @@ There is basic support for addressable RGB matrix lighting with the I2C IS31FL37 RGB_MATRIX_ENABLE = yes RGB_MATRIX_DRIVER = is31fl3737 ``` -You can use between 1 and 4 IS31FL3737 IC's. Do not specify `IS31FL3737_I2C_ADDRESS_` defines for IC's that are not present on your keyboard. +You can use between 1 and 4 IS31FL3737 IC's. Do not specify `DRIVER_ADDR_` defines for IC's that are not present on your keyboard. Configure the hardware via your `config.h`: From 6dd473f1c1ca842fb625bba040d7c808ff4f0ba0 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Sat, 6 Jan 2024 16:57:28 +0700 Subject: [PATCH 21/26] Resolved changes again --- builddefs/common_features.mk | 2 +- drivers/led/issi/{is31fl3729-simple.c => is31fl3729-mono.c} | 6 +++--- drivers/led/issi/{is31fl3729-simple.h => is31fl3729-mono.h} | 0 drivers/led/issi/is31fl3729.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) rename drivers/led/issi/{is31fl3729-simple.c => is31fl3729-mono.c} (98%) rename drivers/led/issi/{is31fl3729-simple.h => is31fl3729-mono.h} (100%) diff --git a/builddefs/common_features.mk b/builddefs/common_features.mk index 3e0d7de16259..c31e4551cfdc 100644 --- a/builddefs/common_features.mk +++ b/builddefs/common_features.mk @@ -368,7 +368,7 @@ ifeq ($(strip $(LED_MATRIX_ENABLE)), yes) ifeq ($(strip $(LED_MATRIX_DRIVER)), is31fl3729) I2C_DRIVER_REQUIRED = yes COMMON_VPATH += $(DRIVER_PATH)/led/issi - SRC += is31fl3729-simple.c + SRC += is31fl3729-mono.c endif ifeq ($(strip $(LED_MATRIX_DRIVER)), is31fl3731) diff --git a/drivers/led/issi/is31fl3729-simple.c b/drivers/led/issi/is31fl3729-mono.c similarity index 98% rename from drivers/led/issi/is31fl3729-simple.c rename to drivers/led/issi/is31fl3729-mono.c index 4f2a9bc501e8..b0e132772be0 100644 --- a/drivers/led/issi/is31fl3729-simple.c +++ b/drivers/led/issi/is31fl3729-mono.c @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -#include "is31fl3729-simple.h" +#include "is31fl3729-mono.h" #include #include "i2c_master.h" #include "wait.h" @@ -194,9 +194,9 @@ void is31fl3729_set_scaling_register(uint8_t index, uint8_t value) { void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { is31fl3729_write_pwm_buffer(addr, g_pwm_buffer[index]); - } - g_pwm_buffer_update_required[index] = false; + g_pwm_buffer_update_required[index] = false; + } } void is31fl3729_update_scaling_registers(uint8_t addr, uint8_t index) { diff --git a/drivers/led/issi/is31fl3729-simple.h b/drivers/led/issi/is31fl3729-mono.h similarity index 100% rename from drivers/led/issi/is31fl3729-simple.h rename to drivers/led/issi/is31fl3729-mono.h diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index a57f9f18485a..4b15d52c73e0 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -200,9 +200,9 @@ void is31fl3729_set_scaling_register(uint8_t index, uint8_t red, uint8_t green, void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { is31fl3729_write_pwm_buffer(addr, g_pwm_buffer[index]); - } - g_pwm_buffer_update_required[index] = false; + g_pwm_buffer_update_required[index] = false; + } } void is31fl3729_update_scaling_registers(uint8_t addr, uint8_t index) { From 2f5e08e63675a19ec395666b761630c2a1c5c531 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Thu, 25 Jan 2024 17:08:03 +0700 Subject: [PATCH 22/26] Resolve changes --- drivers/led/issi/is31fl3729-mono.c | 8 ++-- drivers/led/issi/is31fl3729-mono.h | 74 +++++++++++++++++++----------- drivers/led/issi/is31fl3729.c | 8 ++-- drivers/led/issi/is31fl3729.h | 74 +++++++++++++++++++----------- 4 files changed, 104 insertions(+), 60 deletions(-) diff --git a/drivers/led/issi/is31fl3729-mono.c b/drivers/led/issi/is31fl3729-mono.c index b0e132772be0..fd6aedcc070a 100644 --- a/drivers/led/issi/is31fl3729-mono.c +++ b/drivers/led/issi/is31fl3729-mono.c @@ -33,8 +33,8 @@ #ifndef IS31FL3729_CONFIGURATION # define IS31FL3729_CONFIGURATION IS31FL3729_CONFIG_SWS_15_9 #endif -#ifndef IS31FL3729_GLOBALCURRENT -# define IS31FL3729_GLOBALCURRENT 0x40 +#ifndef IS31FL3729_GLOBAL_CURRENT +# define IS31FL3729_GLOBAL_CURRENT 0x40 #endif #ifndef IS31FL3729_PULLDOWNUP # define IS31FL3729_PULLDOWNUP 0x33 @@ -43,7 +43,7 @@ # define IS31FL3729_SPREAD_SPECTRUM IS31FL3729_SSP_DISABLE #endif #ifndef IS31FL3729_PWM_FREQUENCY -# define IS31FL3729_PWM_FREQUENCY IS31FL3729_PWM_FREQ_32K_HZ +# define IS31FL3729_PWM_FREQUENCY IS31FL3729_PWM_FREQUENCY_32K_HZ #endif // Set buffer sizes @@ -148,7 +148,7 @@ void is31fl3729_init(uint8_t addr) { is31fl3729_write_register(addr, IS31FL3729_REG_PWM_FREQUENCY, IS31FL3729_PWM_FREQUENCY); // Set Golbal Current Control Register - is31fl3729_write_register(addr, IS31FL3729_REG_GLOBALCURRENT, IS31FL3729_GLOBALCURRENT); + is31fl3729_write_register(addr, IS31FL3729_REG_GLOBAL_CURRENT, IS31FL3729_GLOBAL_CURRENT); // Set to Normal operation is31fl3729_write_register(addr, IS31FL3729_REG_CONFIGURATION, IS31FL3729_CONFIGURATION); diff --git a/drivers/led/issi/is31fl3729-mono.h b/drivers/led/issi/is31fl3729-mono.h index 0e686923eef5..af151c198236 100644 --- a/drivers/led/issi/is31fl3729-mono.h +++ b/drivers/led/issi/is31fl3729-mono.h @@ -25,7 +25,7 @@ #define IS31FL3729_REG_SCALING 0x90 #define IS31FL3729_REG_CONFIGURATION 0xA0 -#define IS31FL3729_REG_GLOBALCURRENT 0xA1 +#define IS31FL3729_REG_GLOBAL_CURRENT 0xA1 #define IS31FL3729_REG_PULLDOWNUP 0xB0 #define IS31FL3729_REG_SPREAD_SPECTRUM 0xB1 #define IS31FL3729_REG_PWM_FREQUENCY 0xB2 @@ -77,33 +77,55 @@ void is31fl3729_update_scaling_registers(uint8_t addr, uint8_t index); void is31fl3729_flush(void); // Noise reduction using Spread Spectrum register -#define IS31FL3729_SSP_DISABLE 0x00 -#define IS31FL3729_SSP_5_1980US 0x10 -#define IS31FL3729_SSP_5_1200US 0x11 -#define IS31FL3729_SSP_5_820US 0x12 -#define IS31FL3729_SSP_5_660US 0x13 -#define IS31FL3729_SSP_15_1980US 0x14 -#define IS31FL3729_SSP_15_1200US 0x15 -#define IS31FL3729_SSP_15_820US 0x16 -#define IS31FL3729_SSP_15_660US 0x17 -#define IS31FL3729_SSP_24_1980US 0x18 -#define IS31FL3729_SSP_24_1200US 0x19 -#define IS31FL3729_SSP_24_820US 0x1A -#define IS31FL3729_SSP_24_660US 0x1B -#define IS31FL3729_SSP_34_1980US 0x1C -#define IS31FL3729_SSP_34_1200US 0x1D -#define IS31FL3729_SSP_34_820US 0x1E -#define IS31FL3729_SSP_34_660US 0x1F +#define SSP_DISABLE (0b0 << 4) +#define SSP_ENABLE (0b1 << 4) + +#define RNG_5 (0b00 << 2) +#define RNG_15 (0b01 << 2) +#define RNG_24 (0b10 << 2) +#define RNG_34 (0b11 << 2) + +#define CLT_1980 0b00 +#define CLT_1200 0b01 +#define CLT_820 0b10 +#define CLT_660 0b11 + +/* Disabled SSP */ +#define IS31FL3729_SSP_DISABLE SSP_DISABLE + +/* SSP 5 percent range */ +#define IS31FL3729_SSP_5_1980US (SSP_ENABLE | RNG_5 | CLT_1980) +#define IS31FL3729_SSP_5_1200US (SSP_ENABLE | RNG_5 | CLT_1200) +#define IS31FL3729_SSP_5_820US (SSP_ENABLE | RNG_5 | CLT_820) +#define IS31FL3729_SSP_5_660US (SSP_ENABLE | RNG_5 | CLT_660) + +/* SSP 15 percent range */ +#define IS31FL3729_SSP_15_1980US (SSP_ENABLE | RNG_15 | CLT_1980) +#define IS31FL3729_SSP_15_1200US (SSP_ENABLE | RNG_15 | CLT_1200) +#define IS31FL3729_SSP_15_820US (SSP_ENABLE | RNG_15 | CLT_820) +#define IS31FL3729_SSP_15_660US (SSP_ENABLE | RNG_15 | CLT_660) + +/* SSP 24 percent range */ +#define IS31FL3729_SSP_24_1980US (SSP_ENABLE | RNG_24 | CLT_1980) +#define IS31FL3729_SSP_24_1200US (SSP_ENABLE | RNG_24 | CLT_1200) +#define IS31FL3729_SSP_24_820US (SSP_ENABLE | RNG_24 | CLT_820) +#define IS31FL3729_SSP_24_660US (SSP_ENABLE | RNG_24 | CLT_660) + +/* SSP 34 percent range */ +#define IS31FL3729_SSP_34_1980US (SSP_ENABLE | RNG_34 | CLT_1980) +#define IS31FL3729_SSP_34_1200US (SSP_ENABLE | RNG_34 | CLT_1200) +#define IS31FL3729_SSP_34_820US (SSP_ENABLE | RNG_34 | CLT_820) +#define IS31FL3729_SSP_34_660US (SSP_ENABLE | RNG_34 | CLT_660) // Noise reduction using PWM Frequency register -#define IS31FL3729_PWM_FREQ_55K_HZ 0x00 -#define IS31FL3729_PWM_FREQ_32K_HZ 0x01 -#define IS31FL3729_PWM_FREQ_4K_HZ 0x02 -#define IS31FL3729_PWM_FREQ_2K_HZ 0x03 -#define IS31FL3729_PWM_FREQ_1K_HZ 0x04 -#define IS31FL3729_PWM_FREQ_500_HZ 0x05 // If SWx cannot be more than 4 -#define IS31FL3729_PWM_FREQ_250_HZ 0x06 // If SWx cannot be more than 2 -#define IS31FL3729_PWM_FREQ_80K_HZ 0x07 +#define IS31FL3729_PWM_FREQUENCY_55K_HZ 0b000 +#define IS31FL3729_PWM_FREQUENCY_32K_HZ 0b001 +#define IS31FL3729_PWM_FREQUENCY_4K_HZ 0b010 +#define IS31FL3729_PWM_FREQUENCY_2K_HZ 0b011 +#define IS31FL3729_PWM_FREQUENCY_1K_HZ 0b100 +#define IS31FL3729_PWM_FREQUENCY_500_HZ 0b101 +#define IS31FL3729_PWM_FREQUENCY_250_HZ 0b110 +#define IS31FL3729_PWM_FREQUENCY_80K_HZ 0b111 // Change SWx Setting using Configuration register #define IS31FL3729_CONFIG_SWS_15_9 0x01 // 15 CS x 9 SW matrix diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index 4b15d52c73e0..d1de04ffe3df 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -33,8 +33,8 @@ #ifndef IS31FL3729_CONFIGURATION # define IS31FL3729_CONFIGURATION IS31FL3729_CONFIG_SWS_15_9 #endif -#ifndef IS31FL3729_GLOBALCURRENT -# define IS31FL3729_GLOBALCURRENT 0x40 +#ifndef IS31FL3729_GLOBAL_CURRENT +# define IS31FL3729_GLOBAL_CURRENT 0x40 #endif #ifndef IS31FL3729_PULLDOWNUP # define IS31FL3729_PULLDOWNUP 0x33 @@ -43,7 +43,7 @@ # define IS31FL3729_SPREAD_SPECTRUM IS31FL3729_SSP_DISABLE #endif #ifndef IS31FL3729_PWM_FREQUENCY -# define IS31FL3729_PWM_FREQUENCY IS31FL3729_PWM_FREQ_32K_HZ +# define IS31FL3729_PWM_FREQUENCY IS31FL3729_PWM_FREQUENCY_32K_HZ #endif // Set buffer sizes @@ -148,7 +148,7 @@ void is31fl3729_init(uint8_t addr) { is31fl3729_write_register(addr, IS31FL3729_REG_PWM_FREQUENCY, IS31FL3729_PWM_FREQUENCY); // Set Golbal Current Control Register - is31fl3729_write_register(addr, IS31FL3729_REG_GLOBALCURRENT, IS31FL3729_GLOBALCURRENT); + is31fl3729_write_register(addr, IS31FL3729_REG_GLOBAL_CURRENT, IS31FL3729_GLOBAL_CURRENT); // Set to Normal operation is31fl3729_write_register(addr, IS31FL3729_REG_CONFIGURATION, IS31FL3729_CONFIGURATION); diff --git a/drivers/led/issi/is31fl3729.h b/drivers/led/issi/is31fl3729.h index 55b87a8d122b..bec625075e7c 100644 --- a/drivers/led/issi/is31fl3729.h +++ b/drivers/led/issi/is31fl3729.h @@ -25,7 +25,7 @@ #define IS31FL3729_REG_SCALING 0x90 #define IS31FL3729_REG_CONFIGURATION 0xA0 -#define IS31FL3729_REG_GLOBALCURRENT 0xA1 +#define IS31FL3729_REG_GLOBAL_CURRENT 0xA1 #define IS31FL3729_REG_PULLDOWNUP 0xB0 #define IS31FL3729_REG_SPREAD_SPECTRUM 0xB1 #define IS31FL3729_REG_PWM_FREQUENCY 0xB2 @@ -79,33 +79,55 @@ void is31fl3729_update_scaling_registers(uint8_t addr, uint8_t index); void is31fl3729_flush(void); // Noise reduction using Spread Spectrum register -#define IS31FL3729_SSP_DISABLE 0x00 -#define IS31FL3729_SSP_5_1980US 0x10 -#define IS31FL3729_SSP_5_1200US 0x11 -#define IS31FL3729_SSP_5_820US 0x12 -#define IS31FL3729_SSP_5_660US 0x13 -#define IS31FL3729_SSP_15_1980US 0x14 -#define IS31FL3729_SSP_15_1200US 0x15 -#define IS31FL3729_SSP_15_820US 0x16 -#define IS31FL3729_SSP_15_660US 0x17 -#define IS31FL3729_SSP_24_1980US 0x18 -#define IS31FL3729_SSP_24_1200US 0x19 -#define IS31FL3729_SSP_24_820US 0x1A -#define IS31FL3729_SSP_24_660US 0x1B -#define IS31FL3729_SSP_34_1980US 0x1C -#define IS31FL3729_SSP_34_1200US 0x1D -#define IS31FL3729_SSP_34_820US 0x1E -#define IS31FL3729_SSP_34_660US 0x1F +#define SSP_DISABLE (0b0 << 4) +#define SSP_ENABLE (0b1 << 4) + +#define RNG_5 (0b00 << 2) +#define RNG_15 (0b01 << 2) +#define RNG_24 (0b10 << 2) +#define RNG_34 (0b11 << 2) + +#define CLT_1980 0b00 +#define CLT_1200 0b01 +#define CLT_820 0b10 +#define CLT_660 0b11 + +/* Disabled SSP */ +#define IS31FL3729_SSP_DISABLE SSP_DISABLE + +/* SSP 5 percent range */ +#define IS31FL3729_SSP_5_1980US (SSP_ENABLE | RNG_5 | CLT_1980) +#define IS31FL3729_SSP_5_1200US (SSP_ENABLE | RNG_5 | CLT_1200) +#define IS31FL3729_SSP_5_820US (SSP_ENABLE | RNG_5 | CLT_820) +#define IS31FL3729_SSP_5_660US (SSP_ENABLE | RNG_5 | CLT_660) + +/* SSP 15 percent range */ +#define IS31FL3729_SSP_15_1980US (SSP_ENABLE | RNG_15 | CLT_1980) +#define IS31FL3729_SSP_15_1200US (SSP_ENABLE | RNG_15 | CLT_1200) +#define IS31FL3729_SSP_15_820US (SSP_ENABLE | RNG_15 | CLT_820) +#define IS31FL3729_SSP_15_660US (SSP_ENABLE | RNG_15 | CLT_660) + +/* SSP 24 percent range */ +#define IS31FL3729_SSP_24_1980US (SSP_ENABLE | RNG_24 | CLT_1980) +#define IS31FL3729_SSP_24_1200US (SSP_ENABLE | RNG_24 | CLT_1200) +#define IS31FL3729_SSP_24_820US (SSP_ENABLE | RNG_24 | CLT_820) +#define IS31FL3729_SSP_24_660US (SSP_ENABLE | RNG_24 | CLT_660) + +/* SSP 34 percent range */ +#define IS31FL3729_SSP_34_1980US (SSP_ENABLE | RNG_34 | CLT_1980) +#define IS31FL3729_SSP_34_1200US (SSP_ENABLE | RNG_34 | CLT_1200) +#define IS31FL3729_SSP_34_820US (SSP_ENABLE | RNG_34 | CLT_820) +#define IS31FL3729_SSP_34_660US (SSP_ENABLE | RNG_34 | CLT_660) // Noise reduction using PWM Frequency register -#define IS31FL3729_PWM_FREQ_55K_HZ 0x00 -#define IS31FL3729_PWM_FREQ_32K_HZ 0x01 -#define IS31FL3729_PWM_FREQ_4K_HZ 0x02 -#define IS31FL3729_PWM_FREQ_2K_HZ 0x03 -#define IS31FL3729_PWM_FREQ_1K_HZ 0x04 -#define IS31FL3729_PWM_FREQ_500_HZ 0x05 // If SWx cannot be more than 4 -#define IS31FL3729_PWM_FREQ_250_HZ 0x06 // If SWx cannot be more than 2 -#define IS31FL3729_PWM_FREQ_80K_HZ 0x07 +#define IS31FL3729_PWM_FREQUENCY_55K_HZ 0b000 +#define IS31FL3729_PWM_FREQUENCY_32K_HZ 0b001 +#define IS31FL3729_PWM_FREQUENCY_4K_HZ 0b010 +#define IS31FL3729_PWM_FREQUENCY_2K_HZ 0b011 +#define IS31FL3729_PWM_FREQUENCY_1K_HZ 0b100 +#define IS31FL3729_PWM_FREQUENCY_500_HZ 0b101 +#define IS31FL3729_PWM_FREQUENCY_250_HZ 0b110 +#define IS31FL3729_PWM_FREQUENCY_80K_HZ 0b111 // Change SWx Setting using Configuration register #define IS31FL3729_CONFIG_SWS_15_9 0x01 // 15 CS x 9 SW matrix From bfd8c4d27b0173336b49104ba480e3940fceaf95 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Thu, 8 Feb 2024 15:30:49 +0700 Subject: [PATCH 23/26] Resolved --- drivers/led/issi/is31fl3729-mono.c | 62 +++++++++++------------------- drivers/led/issi/is31fl3729-mono.h | 7 ++-- drivers/led/issi/is31fl3729.c | 62 +++++++++++------------------- drivers/led/issi/is31fl3729.h | 7 ++-- 4 files changed, 50 insertions(+), 88 deletions(-) diff --git a/drivers/led/issi/is31fl3729-mono.c b/drivers/led/issi/is31fl3729-mono.c index fd6aedcc070a..4ba3633894d0 100644 --- a/drivers/led/issi/is31fl3729-mono.c +++ b/drivers/led/issi/is31fl3729-mono.c @@ -1,6 +1,6 @@ -/* Copyright 2023 HorrorTroll - * Copyright 2023 Harrison Chan (Xelus) - * Copyright 2023 Dimitris Mantzouranis +/* Copyright 2024 HorrorTroll + * Copyright 2024 Harrison Chan (Xelus) + * Copyright 2024 Dimitris Mantzouranis * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,41 +17,40 @@ */ #include "is31fl3729-mono.h" -#include #include "i2c_master.h" #include "wait.h" -// Set defaults for Timeout and Persistence +#define IS31FL3729_PWM_REGISTER_COUNT 143 +#define IS31FL3729_SCALING_REGISTER_COUNT 16 + #ifndef IS31FL3729_I2C_TIMEOUT # define IS31FL3729_I2C_TIMEOUT 100 #endif + #ifndef IS31FL3729_I2C_PERSISTENCE # define IS31FL3729_I2C_PERSISTENCE 0 #endif -// Set defaults for Registers #ifndef IS31FL3729_CONFIGURATION # define IS31FL3729_CONFIGURATION IS31FL3729_CONFIG_SWS_15_9 #endif + #ifndef IS31FL3729_GLOBAL_CURRENT # define IS31FL3729_GLOBAL_CURRENT 0x40 #endif + #ifndef IS31FL3729_PULLDOWNUP # define IS31FL3729_PULLDOWNUP 0x33 #endif + #ifndef IS31FL3729_SPREAD_SPECTRUM # define IS31FL3729_SPREAD_SPECTRUM IS31FL3729_SSP_DISABLE #endif + #ifndef IS31FL3729_PWM_FREQUENCY # define IS31FL3729_PWM_FREQUENCY IS31FL3729_PWM_FREQUENCY_32K_HZ #endif -// Set buffer sizes -#define IS31FL3729_PWM_REGISTER_COUNT 143 -#define IS31FL3729_SCALING_REGISTER_COUNT 16 - -uint8_t i2c_transfer_buffer[20]; - // These buffers match the PWM & scaling registers. // Storing them like this is optimal for I2C transfers to the registers. uint8_t g_pwm_buffer[IS31FL3729_DRIVER_COUNT][IS31FL3729_PWM_REGISTER_COUNT]; @@ -61,45 +60,28 @@ uint8_t g_scaling_registers[IS31FL3729_DRIVER_COUNT][IS31FL3729_SCALING_REGISTER bool g_scaling_registers_update_required[IS31FL3729_DRIVER_COUNT] = {false}; void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { - // Set register address and register data ready to write - i2c_transfer_buffer[0] = reg; - i2c_transfer_buffer[1] = data; - #if IS31FL3729_I2C_PERSISTENCE > 0 for (uint8_t i = 0; i < IS31FL3729_I2C_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3729_I2C_TIMEOUT) == 0) break; + if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3729_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break; } #else - i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3729_I2C_TIMEOUT); + i2c_write_register(addr << 1, reg, &data, 1, IS31FL3729_I2C_TIMEOUT); #endif } -bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { - // iterate over the pwm_buffer contents at IS31FL3729_SCALING_REGISTER_COUNT byte intervals - // datasheet does not mention it, but it auto-increments in 15x9 mode, and - // hence does not require us to skip any addresses - for (int i = 0; i <= IS31FL3729_PWM_REGISTER_COUNT; i += IS31FL3729_SCALING_REGISTER_COUNT) { - i2c_transfer_buffer[0] = i; - - // copy the data from i to i+IS31FL3729_SCALING_REGISTER_COUNT - // device will auto-increment register for data after the first byte - // thus this sets registers 0x01-0x10, 0x11-0x20, etc. in one transfer - memcpy(i2c_transfer_buffer + 1, pwm_buffer + i, IS31FL3729_SCALING_REGISTER_COUNT); +void is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t index) { + // Transmit PWM registers in 9 transfers of 16 bytes. + // Iterate over the pwm_buffer contents at 16 byte intervals. + for (uint8_t i = 0; i <= IS31FL3729_PWM_REGISTER_COUNT; i += 16) { #if IS31FL3729_I2C_PERSISTENCE > 0 - for (uint8_t i = 0; i < IS31FL3729_I2C_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, i2c_transfer_buffer, IS31FL3729_SCALING_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { - return false; - } + for (uint8_t j = 0; j < IS31FL3729_I2C_PERSISTENCE; j++) { + if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3729_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break; } #else - if (i2c_transmit(addr << 1, i2c_transfer_buffer, IS31FL3729_SCALING_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { - return false; - } + i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3729_I2C_TIMEOUT); #endif } - - return true; } void is31fl3729_init_drivers(void) { @@ -193,7 +175,7 @@ void is31fl3729_set_scaling_register(uint8_t index, uint8_t value) { void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { - is31fl3729_write_pwm_buffer(addr, g_pwm_buffer[index]); + is31fl3729_write_pwm_buffer(addr, index); g_pwm_buffer_update_required[index] = false; } @@ -201,7 +183,7 @@ void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index) { void is31fl3729_update_scaling_registers(uint8_t addr, uint8_t index) { if (g_scaling_registers_update_required[index]) { - for (int i = 0; i < IS31FL3729_SCALING_REGISTER_COUNT; i++) { + for (uint8_t i = 0; i < IS31FL3729_SCALING_REGISTER_COUNT; i++) { is31fl3729_write_register(addr, IS31FL3729_REG_SCALING + i, g_scaling_registers[index][i]); } diff --git a/drivers/led/issi/is31fl3729-mono.h b/drivers/led/issi/is31fl3729-mono.h index af151c198236..0f4226e04461 100644 --- a/drivers/led/issi/is31fl3729-mono.h +++ b/drivers/led/issi/is31fl3729-mono.h @@ -1,6 +1,6 @@ -/* Copyright 2023 HorrorTroll - * Copyright 2023 Harrison Chan (Xelus) - * Copyright 2023 Dimitris Mantzouranis +/* Copyright 2024 HorrorTroll + * Copyright 2024 Harrison Chan (Xelus) + * Copyright 2024 Dimitris Mantzouranis * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -60,7 +60,6 @@ extern const is31fl3729_led_t PROGMEM g_is31fl3729_leds[IS31FL3729_LED_COUNT]; void is31fl3729_init_drivers(void); void is31fl3729_init(uint8_t addr); void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data); -bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); void is31fl3729_set_value(int index, uint8_t value); void is31fl3729_set_value_all(uint8_t value); diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index d1de04ffe3df..1954d33cc3aa 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -1,6 +1,6 @@ -/* Copyright 2023 HorrorTroll - * Copyright 2023 Harrison Chan (Xelus) - * Copyright 2023 Dimitris Mantzouranis +/* Copyright 2024 HorrorTroll + * Copyright 2024 Harrison Chan (Xelus) + * Copyright 2024 Dimitris Mantzouranis * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,41 +17,40 @@ */ #include "is31fl3729.h" -#include #include "i2c_master.h" #include "wait.h" -// Set defaults for Timeout and Persistence +#define IS31FL3729_PWM_REGISTER_COUNT 143 +#define IS31FL3729_SCALING_REGISTER_COUNT 16 + #ifndef IS31FL3729_I2C_TIMEOUT # define IS31FL3729_I2C_TIMEOUT 100 #endif + #ifndef IS31FL3729_I2C_PERSISTENCE # define IS31FL3729_I2C_PERSISTENCE 0 #endif -// Set defaults for Registers #ifndef IS31FL3729_CONFIGURATION # define IS31FL3729_CONFIGURATION IS31FL3729_CONFIG_SWS_15_9 #endif + #ifndef IS31FL3729_GLOBAL_CURRENT # define IS31FL3729_GLOBAL_CURRENT 0x40 #endif + #ifndef IS31FL3729_PULLDOWNUP # define IS31FL3729_PULLDOWNUP 0x33 #endif + #ifndef IS31FL3729_SPREAD_SPECTRUM # define IS31FL3729_SPREAD_SPECTRUM IS31FL3729_SSP_DISABLE #endif + #ifndef IS31FL3729_PWM_FREQUENCY # define IS31FL3729_PWM_FREQUENCY IS31FL3729_PWM_FREQUENCY_32K_HZ #endif -// Set buffer sizes -#define IS31FL3729_PWM_REGISTER_COUNT 143 -#define IS31FL3729_SCALING_REGISTER_COUNT 16 - -uint8_t i2c_transfer_buffer[20]; - // These buffers match the PWM & scaling registers. // Storing them like this is optimal for I2C transfers to the registers. uint8_t g_pwm_buffer[IS31FL3729_DRIVER_COUNT][IS31FL3729_PWM_REGISTER_COUNT]; @@ -61,45 +60,28 @@ uint8_t g_scaling_registers[IS31FL3729_DRIVER_COUNT][IS31FL3729_SCALING_REGISTER bool g_scaling_registers_update_required[IS31FL3729_DRIVER_COUNT] = {false}; void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { - // Set register address and register data ready to write - i2c_transfer_buffer[0] = reg; - i2c_transfer_buffer[1] = data; - #if IS31FL3729_I2C_PERSISTENCE > 0 for (uint8_t i = 0; i < IS31FL3729_I2C_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3729_I2C_TIMEOUT) == 0) break; + if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3729_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break; } #else - i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3729_I2C_TIMEOUT); + i2c_write_register(addr << 1, reg, &data, 1, IS31FL3729_I2C_TIMEOUT); #endif } -bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { - // iterate over the pwm_buffer contents at IS31FL3729_SCALING_REGISTER_COUNT byte intervals - // datasheet does not mention it, but it auto-increments in 15x9 mode, and - // hence does not require us to skip any addresses - for (int i = 0; i <= IS31FL3729_PWM_REGISTER_COUNT; i += IS31FL3729_SCALING_REGISTER_COUNT) { - i2c_transfer_buffer[0] = i; - - // copy the data from i to i+IS31FL3729_SCALING_REGISTER_COUNT - // device will auto-increment register for data after the first byte - // thus this sets registers 0x01-0x10, 0x11-0x20, etc. in one transfer - memcpy(i2c_transfer_buffer + 1, pwm_buffer + i, IS31FL3729_SCALING_REGISTER_COUNT); +void is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t index) { + // Transmit PWM registers in 9 transfers of 16 bytes. + // Iterate over the pwm_buffer contents at 16 byte intervals. + for (uint8_t i = 0; i <= IS31FL3729_PWM_REGISTER_COUNT; i += 16) { #if IS31FL3729_I2C_PERSISTENCE > 0 - for (uint8_t i = 0; i < IS31FL3729_I2C_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, i2c_transfer_buffer, IS31FL3729_SCALING_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { - return false; - } + for (uint8_t j = 0; j < IS31FL3729_I2C_PERSISTENCE; j++) { + if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3729_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break; } #else - if (i2c_transmit(addr << 1, i2c_transfer_buffer, IS31FL3729_SCALING_REGISTER_COUNT + 1, IS31FL3729_I2C_TIMEOUT) != 0) { - return false; - } + i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3729_I2C_TIMEOUT); #endif } - - return true; } void is31fl3729_init_drivers(void) { @@ -199,7 +181,7 @@ void is31fl3729_set_scaling_register(uint8_t index, uint8_t red, uint8_t green, void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { - is31fl3729_write_pwm_buffer(addr, g_pwm_buffer[index]); + is31fl3729_write_pwm_buffer(addr, index); g_pwm_buffer_update_required[index] = false; } @@ -207,7 +189,7 @@ void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index) { void is31fl3729_update_scaling_registers(uint8_t addr, uint8_t index) { if (g_scaling_registers_update_required[index]) { - for (int i = 0; i < IS31FL3729_SCALING_REGISTER_COUNT; i++) { + for (uint8_t i = 0; i < IS31FL3729_SCALING_REGISTER_COUNT; i++) { is31fl3729_write_register(addr, IS31FL3729_REG_SCALING + i, g_scaling_registers[index][i]); } diff --git a/drivers/led/issi/is31fl3729.h b/drivers/led/issi/is31fl3729.h index bec625075e7c..284c7c35769f 100644 --- a/drivers/led/issi/is31fl3729.h +++ b/drivers/led/issi/is31fl3729.h @@ -1,6 +1,6 @@ -/* Copyright 2023 HorrorTroll - * Copyright 2023 Harrison Chan (Xelus) - * Copyright 2023 Dimitris Mantzouranis +/* Copyright 2024 HorrorTroll + * Copyright 2024 Harrison Chan (Xelus) + * Copyright 2024 Dimitris Mantzouranis * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -62,7 +62,6 @@ extern const is31fl3729_led_t PROGMEM g_is31fl3729_leds[IS31FL3729_LED_COUNT]; void is31fl3729_init_drivers(void); void is31fl3729_init(uint8_t addr); void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data); -bool is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); void is31fl3729_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); void is31fl3729_set_color_all(uint8_t red, uint8_t green, uint8_t blue); From 96ce46d87c836486943c3b21d099c6d0149d0fa9 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Tue, 13 Feb 2024 14:56:15 +0700 Subject: [PATCH 24/26] Resolved --- drivers/led/issi/is31fl3729-mono.c | 10 +++++- drivers/led/issi/is31fl3729-mono.h | 51 +++++++----------------------- drivers/led/issi/is31fl3729.c | 10 +++++- drivers/led/issi/is31fl3729.h | 51 +++++++----------------------- 4 files changed, 42 insertions(+), 80 deletions(-) diff --git a/drivers/led/issi/is31fl3729-mono.c b/drivers/led/issi/is31fl3729-mono.c index 4ba3633894d0..5de5c414a744 100644 --- a/drivers/led/issi/is31fl3729-mono.c +++ b/drivers/led/issi/is31fl3729-mono.c @@ -47,6 +47,14 @@ # define IS31FL3729_SPREAD_SPECTRUM IS31FL3729_SSP_DISABLE #endif +#ifndef IS31FL3729_SPREAD_SPECTRUM_RANGE +# define IS31FL3729_SPREAD_SPECTRUM_RANGE IS31FL3729_RNG_5_PERCENT +#endif + +#ifndef IS31FL3729_SPREAD_SPECTRUM_CYCLE_TIME +# define IS31FL3729_SPREAD_SPECTRUM_CYCLE_TIME IS31FL3729_CLT_1980_US +#endif + #ifndef IS31FL3729_PWM_FREQUENCY # define IS31FL3729_PWM_FREQUENCY IS31FL3729_PWM_FREQUENCY_32K_HZ #endif @@ -124,7 +132,7 @@ void is31fl3729_init(uint8_t addr) { is31fl3729_write_register(addr, IS31FL3729_REG_PULLDOWNUP, IS31FL3729_PULLDOWNUP); // Set Spread Spectrum Register if applicable - is31fl3729_write_register(addr, IS31FL3729_REG_SPREAD_SPECTRUM, IS31FL3729_SPREAD_SPECTRUM); + is31fl3729_write_register(addr, IS31FL3729_REG_SPREAD_SPECTRUM, ((IS31FL3729_SPREAD_SPECTRUM & 0b1) << 4) | ((IS31FL3729_SPREAD_SPECTRUM_RANGE & 0b11) << 2) | (IS31FL3729_SPREAD_SPECTRUM_CYCLE_TIME & 0b11)); // Set PWM Frequency Register if applicable is31fl3729_write_register(addr, IS31FL3729_REG_PWM_FREQUENCY, IS31FL3729_PWM_FREQUENCY); diff --git a/drivers/led/issi/is31fl3729-mono.h b/drivers/led/issi/is31fl3729-mono.h index 0f4226e04461..dc5be767f229 100644 --- a/drivers/led/issi/is31fl3729-mono.h +++ b/drivers/led/issi/is31fl3729-mono.h @@ -76,45 +76,18 @@ void is31fl3729_update_scaling_registers(uint8_t addr, uint8_t index); void is31fl3729_flush(void); // Noise reduction using Spread Spectrum register -#define SSP_DISABLE (0b0 << 4) -#define SSP_ENABLE (0b1 << 4) - -#define RNG_5 (0b00 << 2) -#define RNG_15 (0b01 << 2) -#define RNG_24 (0b10 << 2) -#define RNG_34 (0b11 << 2) - -#define CLT_1980 0b00 -#define CLT_1200 0b01 -#define CLT_820 0b10 -#define CLT_660 0b11 - -/* Disabled SSP */ -#define IS31FL3729_SSP_DISABLE SSP_DISABLE - -/* SSP 5 percent range */ -#define IS31FL3729_SSP_5_1980US (SSP_ENABLE | RNG_5 | CLT_1980) -#define IS31FL3729_SSP_5_1200US (SSP_ENABLE | RNG_5 | CLT_1200) -#define IS31FL3729_SSP_5_820US (SSP_ENABLE | RNG_5 | CLT_820) -#define IS31FL3729_SSP_5_660US (SSP_ENABLE | RNG_5 | CLT_660) - -/* SSP 15 percent range */ -#define IS31FL3729_SSP_15_1980US (SSP_ENABLE | RNG_15 | CLT_1980) -#define IS31FL3729_SSP_15_1200US (SSP_ENABLE | RNG_15 | CLT_1200) -#define IS31FL3729_SSP_15_820US (SSP_ENABLE | RNG_15 | CLT_820) -#define IS31FL3729_SSP_15_660US (SSP_ENABLE | RNG_15 | CLT_660) - -/* SSP 24 percent range */ -#define IS31FL3729_SSP_24_1980US (SSP_ENABLE | RNG_24 | CLT_1980) -#define IS31FL3729_SSP_24_1200US (SSP_ENABLE | RNG_24 | CLT_1200) -#define IS31FL3729_SSP_24_820US (SSP_ENABLE | RNG_24 | CLT_820) -#define IS31FL3729_SSP_24_660US (SSP_ENABLE | RNG_24 | CLT_660) - -/* SSP 34 percent range */ -#define IS31FL3729_SSP_34_1980US (SSP_ENABLE | RNG_34 | CLT_1980) -#define IS31FL3729_SSP_34_1200US (SSP_ENABLE | RNG_34 | CLT_1200) -#define IS31FL3729_SSP_34_820US (SSP_ENABLE | RNG_34 | CLT_820) -#define IS31FL3729_SSP_34_660US (SSP_ENABLE | RNG_34 | CLT_660) +#define IS31FL3729_SSP_DISABLE 0b0 +#define IS31FL3729_SSP_ENABLE 0b1 + +#define IS31FL3729_RNG_5_PERCENT 0b00 +#define IS31FL3729_RNG_15_PERCENT 0b01 +#define IS31FL3729_RNG_24_PERCENT 0b10 +#define IS31FL3729_RNG_34_PERCENT 0b11 + +#define IS31FL3729_CLT_1980_US 0b00 +#define IS31FL3729_CLT_1200_US 0b01 +#define IS31FL3729_CLT_820_US 0b10 +#define IS31FL3729_CLT_660_US 0b11 // Noise reduction using PWM Frequency register #define IS31FL3729_PWM_FREQUENCY_55K_HZ 0b000 diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index 1954d33cc3aa..0610dcf98fcc 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -47,6 +47,14 @@ # define IS31FL3729_SPREAD_SPECTRUM IS31FL3729_SSP_DISABLE #endif +#ifndef IS31FL3729_SPREAD_SPECTRUM_RANGE +# define IS31FL3729_SPREAD_SPECTRUM_RANGE IS31FL3729_RNG_5_PERCENT +#endif + +#ifndef IS31FL3729_SPREAD_SPECTRUM_CYCLE_TIME +# define IS31FL3729_SPREAD_SPECTRUM_CYCLE_TIME IS31FL3729_CLT_1980_US +#endif + #ifndef IS31FL3729_PWM_FREQUENCY # define IS31FL3729_PWM_FREQUENCY IS31FL3729_PWM_FREQUENCY_32K_HZ #endif @@ -124,7 +132,7 @@ void is31fl3729_init(uint8_t addr) { is31fl3729_write_register(addr, IS31FL3729_REG_PULLDOWNUP, IS31FL3729_PULLDOWNUP); // Set Spread Spectrum Register if applicable - is31fl3729_write_register(addr, IS31FL3729_REG_SPREAD_SPECTRUM, IS31FL3729_SPREAD_SPECTRUM); + is31fl3729_write_register(addr, IS31FL3729_REG_SPREAD_SPECTRUM, ((IS31FL3729_SPREAD_SPECTRUM & 0b1) << 4) | ((IS31FL3729_SPREAD_SPECTRUM_RANGE & 0b11) << 2) | (IS31FL3729_SPREAD_SPECTRUM_CYCLE_TIME & 0b11)); // Set PWM Frequency Register if applicable is31fl3729_write_register(addr, IS31FL3729_REG_PWM_FREQUENCY, IS31FL3729_PWM_FREQUENCY); diff --git a/drivers/led/issi/is31fl3729.h b/drivers/led/issi/is31fl3729.h index 284c7c35769f..66755f008e88 100644 --- a/drivers/led/issi/is31fl3729.h +++ b/drivers/led/issi/is31fl3729.h @@ -78,45 +78,18 @@ void is31fl3729_update_scaling_registers(uint8_t addr, uint8_t index); void is31fl3729_flush(void); // Noise reduction using Spread Spectrum register -#define SSP_DISABLE (0b0 << 4) -#define SSP_ENABLE (0b1 << 4) - -#define RNG_5 (0b00 << 2) -#define RNG_15 (0b01 << 2) -#define RNG_24 (0b10 << 2) -#define RNG_34 (0b11 << 2) - -#define CLT_1980 0b00 -#define CLT_1200 0b01 -#define CLT_820 0b10 -#define CLT_660 0b11 - -/* Disabled SSP */ -#define IS31FL3729_SSP_DISABLE SSP_DISABLE - -/* SSP 5 percent range */ -#define IS31FL3729_SSP_5_1980US (SSP_ENABLE | RNG_5 | CLT_1980) -#define IS31FL3729_SSP_5_1200US (SSP_ENABLE | RNG_5 | CLT_1200) -#define IS31FL3729_SSP_5_820US (SSP_ENABLE | RNG_5 | CLT_820) -#define IS31FL3729_SSP_5_660US (SSP_ENABLE | RNG_5 | CLT_660) - -/* SSP 15 percent range */ -#define IS31FL3729_SSP_15_1980US (SSP_ENABLE | RNG_15 | CLT_1980) -#define IS31FL3729_SSP_15_1200US (SSP_ENABLE | RNG_15 | CLT_1200) -#define IS31FL3729_SSP_15_820US (SSP_ENABLE | RNG_15 | CLT_820) -#define IS31FL3729_SSP_15_660US (SSP_ENABLE | RNG_15 | CLT_660) - -/* SSP 24 percent range */ -#define IS31FL3729_SSP_24_1980US (SSP_ENABLE | RNG_24 | CLT_1980) -#define IS31FL3729_SSP_24_1200US (SSP_ENABLE | RNG_24 | CLT_1200) -#define IS31FL3729_SSP_24_820US (SSP_ENABLE | RNG_24 | CLT_820) -#define IS31FL3729_SSP_24_660US (SSP_ENABLE | RNG_24 | CLT_660) - -/* SSP 34 percent range */ -#define IS31FL3729_SSP_34_1980US (SSP_ENABLE | RNG_34 | CLT_1980) -#define IS31FL3729_SSP_34_1200US (SSP_ENABLE | RNG_34 | CLT_1200) -#define IS31FL3729_SSP_34_820US (SSP_ENABLE | RNG_34 | CLT_820) -#define IS31FL3729_SSP_34_660US (SSP_ENABLE | RNG_34 | CLT_660) +#define IS31FL3729_SSP_DISABLE 0b0 +#define IS31FL3729_SSP_ENABLE 0b1 + +#define IS31FL3729_RNG_5_PERCENT 0b00 +#define IS31FL3729_RNG_15_PERCENT 0b01 +#define IS31FL3729_RNG_24_PERCENT 0b10 +#define IS31FL3729_RNG_34_PERCENT 0b11 + +#define IS31FL3729_CLT_1980_US 0b00 +#define IS31FL3729_CLT_1200_US 0b01 +#define IS31FL3729_CLT_820_US 0b10 +#define IS31FL3729_CLT_660_US 0b11 // Noise reduction using PWM Frequency register #define IS31FL3729_PWM_FREQUENCY_55K_HZ 0b000 From 52394b2590cfb1aa68f6aab2e51ddc12ceb3793d Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Tue, 13 Feb 2024 16:01:43 +0700 Subject: [PATCH 25/26] update PWM register defines --- drivers/led/issi/is31fl3729-mono.h | 286 ++++++++++++++--------------- drivers/led/issi/is31fl3729.h | 286 ++++++++++++++--------------- 2 files changed, 286 insertions(+), 286 deletions(-) diff --git a/drivers/led/issi/is31fl3729-mono.h b/drivers/led/issi/is31fl3729-mono.h index dc5be767f229..815c200fd932 100644 --- a/drivers/led/issi/is31fl3729-mono.h +++ b/drivers/led/issi/is31fl3729-mono.h @@ -112,154 +112,154 @@ void is31fl3729_flush(void); // Map CS SW locations to order in PWM / Scaling buffers // This matches the ORDER in the Datasheet Register not the POSITION // It will always count from 0x01 to (ISSI_MAX_LEDS - 1) -#define CS1_SW1 0x01 -#define CS2_SW1 0x02 -#define CS3_SW1 0x03 -#define CS4_SW1 0x04 -#define CS5_SW1 0x05 -#define CS6_SW1 0x06 -#define CS7_SW1 0x07 -#define CS8_SW1 0x08 -#define CS9_SW1 0x09 -#define CS10_SW1 0x0A -#define CS11_SW1 0x0B -#define CS12_SW1 0x0C -#define CS13_SW1 0x0D -#define CS14_SW1 0x0E -#define CS15_SW1 0x0F -#define CS16_SW1 0x10 +#define SW1_CS1 0x01 +#define SW1_CS2 0x02 +#define SW1_CS3 0x03 +#define SW1_CS4 0x04 +#define SW1_CS5 0x05 +#define SW1_CS6 0x06 +#define SW1_CS7 0x07 +#define SW1_CS8 0x08 +#define SW1_CS9 0x09 +#define SW1_CS10 0x0A +#define SW1_CS11 0x0B +#define SW1_CS12 0x0C +#define SW1_CS13 0x0D +#define SW1_CS14 0x0E +#define SW1_CS15 0x0F +#define SW1_CS16 0x10 -#define CS1_SW2 0x11 -#define CS2_SW2 0x12 -#define CS3_SW2 0x13 -#define CS4_SW2 0x14 -#define CS5_SW2 0x15 -#define CS6_SW2 0x16 -#define CS7_SW2 0x17 -#define CS8_SW2 0x18 -#define CS9_SW2 0x19 -#define CS10_SW2 0x1A -#define CS11_SW2 0x1B -#define CS12_SW2 0x1C -#define CS13_SW2 0x1D -#define CS14_SW2 0x1E -#define CS15_SW2 0x1F -#define CS16_SW2 0x20 +#define SW2_CS1 0x11 +#define SW2_CS2 0x12 +#define SW2_CS3 0x13 +#define SW2_CS4 0x14 +#define SW2_CS5 0x15 +#define SW2_CS6 0x16 +#define SW2_CS7 0x17 +#define SW2_CS8 0x18 +#define SW2_CS9 0x19 +#define SW2_CS10 0x1A +#define SW2_CS11 0x1B +#define SW2_CS12 0x1C +#define SW2_CS13 0x1D +#define SW2_CS14 0x1E +#define SW2_CS15 0x1F +#define SW2_CS16 0x20 -#define CS1_SW3 0x21 -#define CS2_SW3 0x22 -#define CS3_SW3 0x23 -#define CS4_SW3 0x24 -#define CS5_SW3 0x25 -#define CS6_SW3 0x26 -#define CS7_SW3 0x27 -#define CS8_SW3 0x28 -#define CS9_SW3 0x29 -#define CS10_SW3 0x2A -#define CS11_SW3 0x2B -#define CS12_SW3 0x2C -#define CS13_SW3 0x2D -#define CS14_SW3 0x2E -#define CS15_SW3 0x2F -#define CS16_SW3 0x30 +#define SW3_CS1 0x21 +#define SW3_CS2 0x22 +#define SW3_CS3 0x23 +#define SW3_CS4 0x24 +#define SW3_CS5 0x25 +#define SW3_CS6 0x26 +#define SW3_CS7 0x27 +#define SW3_CS8 0x28 +#define SW3_CS9 0x29 +#define SW3_CS10 0x2A +#define SW3_CS11 0x2B +#define SW3_CS12 0x2C +#define SW3_CS13 0x2D +#define SW3_CS14 0x2E +#define SW3_CS15 0x2F +#define SW3_CS16 0x30 -#define CS1_SW4 0x31 -#define CS2_SW4 0x32 -#define CS3_SW4 0x33 -#define CS4_SW4 0x34 -#define CS5_SW4 0x35 -#define CS6_SW4 0x36 -#define CS7_SW4 0x37 -#define CS8_SW4 0x38 -#define CS9_SW4 0x39 -#define CS10_SW4 0x3A -#define CS11_SW4 0x3B -#define CS12_SW4 0x3C -#define CS13_SW4 0x3D -#define CS14_SW4 0x3E -#define CS15_SW4 0x3F -#define CS16_SW4 0x40 +#define SW4_CS1 0x31 +#define SW4_CS2 0x32 +#define SW4_CS3 0x33 +#define SW4_CS4 0x34 +#define SW4_CS5 0x35 +#define SW4_CS6 0x36 +#define SW4_CS7 0x37 +#define SW4_CS8 0x38 +#define SW4_CS9 0x39 +#define SW4_CS10 0x3A +#define SW4_CS11 0x3B +#define SW4_CS12 0x3C +#define SW4_CS13 0x3D +#define SW4_CS14 0x3E +#define SW4_CS15 0x3F +#define SW4_CS16 0x40 -#define CS1_SW5 0x41 -#define CS2_SW5 0x42 -#define CS3_SW5 0x43 -#define CS4_SW5 0x44 -#define CS5_SW5 0x45 -#define CS6_SW5 0x46 -#define CS7_SW5 0x47 -#define CS8_SW5 0x48 -#define CS9_SW5 0x49 -#define CS10_SW5 0x4A -#define CS11_SW5 0x4B -#define CS12_SW5 0x4C -#define CS13_SW5 0x4D -#define CS14_SW5 0x4E -#define CS15_SW5 0x4F -#define CS16_SW5 0x50 +#define SW5_CS1 0x41 +#define SW5_CS2 0x42 +#define SW5_CS3 0x43 +#define SW5_CS4 0x44 +#define SW5_CS5 0x45 +#define SW5_CS6 0x46 +#define SW5_CS7 0x47 +#define SW5_CS8 0x48 +#define SW5_CS9 0x49 +#define SW5_CS10 0x4A +#define SW5_CS11 0x4B +#define SW5_CS12 0x4C +#define SW5_CS13 0x4D +#define SW5_CS14 0x4E +#define SW5_CS15 0x4F +#define SW5_CS16 0x50 -#define CS1_SW6 0x51 -#define CS2_SW6 0x52 -#define CS3_SW6 0x53 -#define CS4_SW6 0x54 -#define CS5_SW6 0x55 -#define CS6_SW6 0x56 -#define CS7_SW6 0x57 -#define CS8_SW6 0x58 -#define CS9_SW6 0x59 -#define CS10_SW6 0x5A -#define CS11_SW6 0x5B -#define CS12_SW6 0x5C -#define CS13_SW6 0x5D -#define CS14_SW6 0x5E -#define CS15_SW6 0x5F -#define CS16_SW6 0x60 +#define SW6_CS1 0x51 +#define SW6_CS2 0x52 +#define SW6_CS3 0x53 +#define SW6_CS4 0x54 +#define SW6_CS5 0x55 +#define SW6_CS6 0x56 +#define SW6_CS7 0x57 +#define SW6_CS8 0x58 +#define SW6_CS9 0x59 +#define SW6_CS10 0x5A +#define SW6_CS11 0x5B +#define SW6_CS12 0x5C +#define SW6_CS13 0x5D +#define SW6_CS14 0x5E +#define SW6_CS15 0x5F +#define SW6_CS16 0x60 -#define CS1_SW7 0x61 -#define CS2_SW7 0x62 -#define CS3_SW7 0x63 -#define CS4_SW7 0x64 -#define CS5_SW7 0x65 -#define CS6_SW7 0x66 -#define CS7_SW7 0x67 -#define CS8_SW7 0x68 -#define CS9_SW7 0x69 -#define CS10_SW7 0x6A -#define CS11_SW7 0x6B -#define CS12_SW7 0x6C -#define CS13_SW7 0x6D -#define CS14_SW7 0x6E -#define CS15_SW7 0x6F -#define CS16_SW7 0x70 +#define SW7_CS1 0x61 +#define SW7_CS2 0x62 +#define SW7_CS3 0x63 +#define SW7_CS4 0x64 +#define SW7_CS5 0x65 +#define SW7_CS6 0x66 +#define SW7_CS7 0x67 +#define SW7_CS8 0x68 +#define SW7_CS9 0x69 +#define SW7_CS10 0x6A +#define SW7_CS11 0x6B +#define SW7_CS12 0x6C +#define SW7_CS13 0x6D +#define SW7_CS14 0x6E +#define SW7_CS15 0x6F +#define SW7_CS16 0x70 -#define CS1_SW8 0x71 -#define CS2_SW8 0x72 -#define CS3_SW8 0x73 -#define CS4_SW8 0x74 -#define CS5_SW8 0x75 -#define CS6_SW8 0x76 -#define CS7_SW8 0x77 -#define CS8_SW8 0x78 -#define CS9_SW8 0x79 -#define CS10_SW8 0x7A -#define CS11_SW8 0x7B -#define CS12_SW8 0x7C -#define CS13_SW8 0x7D -#define CS14_SW8 0x7E -#define CS15_SW8 0x7F -#define CS16_SW8 0x80 +#define SW8_CS1 0x71 +#define SW8_CS2 0x72 +#define SW8_CS3 0x73 +#define SW8_CS4 0x74 +#define SW8_CS5 0x75 +#define SW8_CS6 0x76 +#define SW8_CS7 0x77 +#define SW8_CS8 0x78 +#define SW8_CS9 0x79 +#define SW8_CS10 0x7A +#define SW8_CS11 0x7B +#define SW8_CS12 0x7C +#define SW8_CS13 0x7D +#define SW8_CS14 0x7E +#define SW8_CS15 0x7F +#define SW8_CS16 0x80 -#define CS1_SW9 0x81 -#define CS2_SW9 0x82 -#define CS3_SW9 0x83 -#define CS4_SW9 0x84 -#define CS5_SW9 0x85 -#define CS6_SW9 0x86 -#define CS7_SW9 0x87 -#define CS8_SW9 0x88 -#define CS9_SW9 0x89 -#define CS10_SW9 0x8A -#define CS11_SW9 0x8B -#define CS12_SW9 0x8C -#define CS13_SW9 0x8D -#define CS14_SW9 0x8E -#define CS15_SW9 0x8F +#define SW9_CS1 0x81 +#define SW9_CS2 0x82 +#define SW9_CS3 0x83 +#define SW9_CS4 0x84 +#define SW9_CS5 0x85 +#define SW9_CS6 0x86 +#define SW9_CS7 0x87 +#define SW9_CS8 0x88 +#define SW9_CS9 0x89 +#define SW9_CS10 0x8A +#define SW9_CS11 0x8B +#define SW9_CS12 0x8C +#define SW9_CS13 0x8D +#define SW9_CS14 0x8E +#define SW9_CS15 0x8F diff --git a/drivers/led/issi/is31fl3729.h b/drivers/led/issi/is31fl3729.h index 66755f008e88..6f2672b6a323 100644 --- a/drivers/led/issi/is31fl3729.h +++ b/drivers/led/issi/is31fl3729.h @@ -114,154 +114,154 @@ void is31fl3729_flush(void); // Map CS SW locations to order in PWM / Scaling buffers // This matches the ORDER in the Datasheet Register not the POSITION // It will always count from 0x01 to (ISSI_MAX_LEDS - 1) -#define CS1_SW1 0x01 -#define CS2_SW1 0x02 -#define CS3_SW1 0x03 -#define CS4_SW1 0x04 -#define CS5_SW1 0x05 -#define CS6_SW1 0x06 -#define CS7_SW1 0x07 -#define CS8_SW1 0x08 -#define CS9_SW1 0x09 -#define CS10_SW1 0x0A -#define CS11_SW1 0x0B -#define CS12_SW1 0x0C -#define CS13_SW1 0x0D -#define CS14_SW1 0x0E -#define CS15_SW1 0x0F -#define CS16_SW1 0x10 +#define SW1_CS1 0x01 +#define SW1_CS2 0x02 +#define SW1_CS3 0x03 +#define SW1_CS4 0x04 +#define SW1_CS5 0x05 +#define SW1_CS6 0x06 +#define SW1_CS7 0x07 +#define SW1_CS8 0x08 +#define SW1_CS9 0x09 +#define SW1_CS10 0x0A +#define SW1_CS11 0x0B +#define SW1_CS12 0x0C +#define SW1_CS13 0x0D +#define SW1_CS14 0x0E +#define SW1_CS15 0x0F +#define SW1_CS16 0x10 -#define CS1_SW2 0x11 -#define CS2_SW2 0x12 -#define CS3_SW2 0x13 -#define CS4_SW2 0x14 -#define CS5_SW2 0x15 -#define CS6_SW2 0x16 -#define CS7_SW2 0x17 -#define CS8_SW2 0x18 -#define CS9_SW2 0x19 -#define CS10_SW2 0x1A -#define CS11_SW2 0x1B -#define CS12_SW2 0x1C -#define CS13_SW2 0x1D -#define CS14_SW2 0x1E -#define CS15_SW2 0x1F -#define CS16_SW2 0x20 +#define SW2_CS1 0x11 +#define SW2_CS2 0x12 +#define SW2_CS3 0x13 +#define SW2_CS4 0x14 +#define SW2_CS5 0x15 +#define SW2_CS6 0x16 +#define SW2_CS7 0x17 +#define SW2_CS8 0x18 +#define SW2_CS9 0x19 +#define SW2_CS10 0x1A +#define SW2_CS11 0x1B +#define SW2_CS12 0x1C +#define SW2_CS13 0x1D +#define SW2_CS14 0x1E +#define SW2_CS15 0x1F +#define SW2_CS16 0x20 -#define CS1_SW3 0x21 -#define CS2_SW3 0x22 -#define CS3_SW3 0x23 -#define CS4_SW3 0x24 -#define CS5_SW3 0x25 -#define CS6_SW3 0x26 -#define CS7_SW3 0x27 -#define CS8_SW3 0x28 -#define CS9_SW3 0x29 -#define CS10_SW3 0x2A -#define CS11_SW3 0x2B -#define CS12_SW3 0x2C -#define CS13_SW3 0x2D -#define CS14_SW3 0x2E -#define CS15_SW3 0x2F -#define CS16_SW3 0x30 +#define SW3_CS1 0x21 +#define SW3_CS2 0x22 +#define SW3_CS3 0x23 +#define SW3_CS4 0x24 +#define SW3_CS5 0x25 +#define SW3_CS6 0x26 +#define SW3_CS7 0x27 +#define SW3_CS8 0x28 +#define SW3_CS9 0x29 +#define SW3_CS10 0x2A +#define SW3_CS11 0x2B +#define SW3_CS12 0x2C +#define SW3_CS13 0x2D +#define SW3_CS14 0x2E +#define SW3_CS15 0x2F +#define SW3_CS16 0x30 -#define CS1_SW4 0x31 -#define CS2_SW4 0x32 -#define CS3_SW4 0x33 -#define CS4_SW4 0x34 -#define CS5_SW4 0x35 -#define CS6_SW4 0x36 -#define CS7_SW4 0x37 -#define CS8_SW4 0x38 -#define CS9_SW4 0x39 -#define CS10_SW4 0x3A -#define CS11_SW4 0x3B -#define CS12_SW4 0x3C -#define CS13_SW4 0x3D -#define CS14_SW4 0x3E -#define CS15_SW4 0x3F -#define CS16_SW4 0x40 +#define SW4_CS1 0x31 +#define SW4_CS2 0x32 +#define SW4_CS3 0x33 +#define SW4_CS4 0x34 +#define SW4_CS5 0x35 +#define SW4_CS6 0x36 +#define SW4_CS7 0x37 +#define SW4_CS8 0x38 +#define SW4_CS9 0x39 +#define SW4_CS10 0x3A +#define SW4_CS11 0x3B +#define SW4_CS12 0x3C +#define SW4_CS13 0x3D +#define SW4_CS14 0x3E +#define SW4_CS15 0x3F +#define SW4_CS16 0x40 -#define CS1_SW5 0x41 -#define CS2_SW5 0x42 -#define CS3_SW5 0x43 -#define CS4_SW5 0x44 -#define CS5_SW5 0x45 -#define CS6_SW5 0x46 -#define CS7_SW5 0x47 -#define CS8_SW5 0x48 -#define CS9_SW5 0x49 -#define CS10_SW5 0x4A -#define CS11_SW5 0x4B -#define CS12_SW5 0x4C -#define CS13_SW5 0x4D -#define CS14_SW5 0x4E -#define CS15_SW5 0x4F -#define CS16_SW5 0x50 +#define SW5_CS1 0x41 +#define SW5_CS2 0x42 +#define SW5_CS3 0x43 +#define SW5_CS4 0x44 +#define SW5_CS5 0x45 +#define SW5_CS6 0x46 +#define SW5_CS7 0x47 +#define SW5_CS8 0x48 +#define SW5_CS9 0x49 +#define SW5_CS10 0x4A +#define SW5_CS11 0x4B +#define SW5_CS12 0x4C +#define SW5_CS13 0x4D +#define SW5_CS14 0x4E +#define SW5_CS15 0x4F +#define SW5_CS16 0x50 -#define CS1_SW6 0x51 -#define CS2_SW6 0x52 -#define CS3_SW6 0x53 -#define CS4_SW6 0x54 -#define CS5_SW6 0x55 -#define CS6_SW6 0x56 -#define CS7_SW6 0x57 -#define CS8_SW6 0x58 -#define CS9_SW6 0x59 -#define CS10_SW6 0x5A -#define CS11_SW6 0x5B -#define CS12_SW6 0x5C -#define CS13_SW6 0x5D -#define CS14_SW6 0x5E -#define CS15_SW6 0x5F -#define CS16_SW6 0x60 +#define SW6_CS1 0x51 +#define SW6_CS2 0x52 +#define SW6_CS3 0x53 +#define SW6_CS4 0x54 +#define SW6_CS5 0x55 +#define SW6_CS6 0x56 +#define SW6_CS7 0x57 +#define SW6_CS8 0x58 +#define SW6_CS9 0x59 +#define SW6_CS10 0x5A +#define SW6_CS11 0x5B +#define SW6_CS12 0x5C +#define SW6_CS13 0x5D +#define SW6_CS14 0x5E +#define SW6_CS15 0x5F +#define SW6_CS16 0x60 -#define CS1_SW7 0x61 -#define CS2_SW7 0x62 -#define CS3_SW7 0x63 -#define CS4_SW7 0x64 -#define CS5_SW7 0x65 -#define CS6_SW7 0x66 -#define CS7_SW7 0x67 -#define CS8_SW7 0x68 -#define CS9_SW7 0x69 -#define CS10_SW7 0x6A -#define CS11_SW7 0x6B -#define CS12_SW7 0x6C -#define CS13_SW7 0x6D -#define CS14_SW7 0x6E -#define CS15_SW7 0x6F -#define CS16_SW7 0x70 +#define SW7_CS1 0x61 +#define SW7_CS2 0x62 +#define SW7_CS3 0x63 +#define SW7_CS4 0x64 +#define SW7_CS5 0x65 +#define SW7_CS6 0x66 +#define SW7_CS7 0x67 +#define SW7_CS8 0x68 +#define SW7_CS9 0x69 +#define SW7_CS10 0x6A +#define SW7_CS11 0x6B +#define SW7_CS12 0x6C +#define SW7_CS13 0x6D +#define SW7_CS14 0x6E +#define SW7_CS15 0x6F +#define SW7_CS16 0x70 -#define CS1_SW8 0x71 -#define CS2_SW8 0x72 -#define CS3_SW8 0x73 -#define CS4_SW8 0x74 -#define CS5_SW8 0x75 -#define CS6_SW8 0x76 -#define CS7_SW8 0x77 -#define CS8_SW8 0x78 -#define CS9_SW8 0x79 -#define CS10_SW8 0x7A -#define CS11_SW8 0x7B -#define CS12_SW8 0x7C -#define CS13_SW8 0x7D -#define CS14_SW8 0x7E -#define CS15_SW8 0x7F -#define CS16_SW8 0x80 +#define SW8_CS1 0x71 +#define SW8_CS2 0x72 +#define SW8_CS3 0x73 +#define SW8_CS4 0x74 +#define SW8_CS5 0x75 +#define SW8_CS6 0x76 +#define SW8_CS7 0x77 +#define SW8_CS8 0x78 +#define SW8_CS9 0x79 +#define SW8_CS10 0x7A +#define SW8_CS11 0x7B +#define SW8_CS12 0x7C +#define SW8_CS13 0x7D +#define SW8_CS14 0x7E +#define SW8_CS15 0x7F +#define SW8_CS16 0x80 -#define CS1_SW9 0x81 -#define CS2_SW9 0x82 -#define CS3_SW9 0x83 -#define CS4_SW9 0x84 -#define CS5_SW9 0x85 -#define CS6_SW9 0x86 -#define CS7_SW9 0x87 -#define CS8_SW9 0x88 -#define CS9_SW9 0x89 -#define CS10_SW9 0x8A -#define CS11_SW9 0x8B -#define CS12_SW9 0x8C -#define CS13_SW9 0x8D -#define CS14_SW9 0x8E -#define CS15_SW9 0x8F +#define SW9_CS1 0x81 +#define SW9_CS2 0x82 +#define SW9_CS3 0x83 +#define SW9_CS4 0x84 +#define SW9_CS5 0x85 +#define SW9_CS6 0x86 +#define SW9_CS7 0x87 +#define SW9_CS8 0x88 +#define SW9_CS9 0x89 +#define SW9_CS10 0x8A +#define SW9_CS11 0x8B +#define SW9_CS12 0x8C +#define SW9_CS13 0x8D +#define SW9_CS14 0x8E +#define SW9_CS15 0x8F From b2c9fa5439d8de9388241cbc14cc12cf39d0f0eb Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Wed, 14 Feb 2024 13:36:52 +0700 Subject: [PATCH 26/26] Resolved --- drivers/led/issi/is31fl3729-mono.c | 43 ++++++++++++++----------- drivers/led/issi/is31fl3729.c | 51 +++++++++++++++++------------- 2 files changed, 54 insertions(+), 40 deletions(-) diff --git a/drivers/led/issi/is31fl3729-mono.c b/drivers/led/issi/is31fl3729-mono.c index 5de5c414a744..1617dd40a7a1 100644 --- a/drivers/led/issi/is31fl3729-mono.c +++ b/drivers/led/issi/is31fl3729-mono.c @@ -61,11 +61,19 @@ // These buffers match the PWM & scaling registers. // Storing them like this is optimal for I2C transfers to the registers. -uint8_t g_pwm_buffer[IS31FL3729_DRIVER_COUNT][IS31FL3729_PWM_REGISTER_COUNT]; -bool g_pwm_buffer_update_required[IS31FL3729_DRIVER_COUNT] = {false}; - -uint8_t g_scaling_registers[IS31FL3729_DRIVER_COUNT][IS31FL3729_SCALING_REGISTER_COUNT]; -bool g_scaling_registers_update_required[IS31FL3729_DRIVER_COUNT] = {false}; +typedef struct is31fl3729_driver_t { + uint8_t pwm_buffer[IS31FL3729_PWM_REGISTER_COUNT]; + bool pwm_buffer_dirty; + uint8_t scaling_buffer[IS31FL3729_SCALING_REGISTER_COUNT]; + bool scaling_buffer_dirty; +} PACKED is31fl3729_driver_t; + +is31fl3729_driver_t driver_buffers[IS31FL3729_DRIVER_COUNT] = {{ + .pwm_buffer = {0}, + .pwm_buffer_dirty = false, + .scaling_buffer = {0}, + .scaling_buffer_dirty = false, +}}; void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { #if IS31FL3729_I2C_PERSISTENCE > 0 @@ -84,10 +92,10 @@ void is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t index) { for (uint8_t i = 0; i <= IS31FL3729_PWM_REGISTER_COUNT; i += 16) { #if IS31FL3729_I2C_PERSISTENCE > 0 for (uint8_t j = 0; j < IS31FL3729_I2C_PERSISTENCE; j++) { - if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3729_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break; + if (i2c_write_register(addr << 1, i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3729_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break; } #else - i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3729_I2C_TIMEOUT); + i2c_write_register(addr << 1, i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3729_I2C_TIMEOUT); #endif } } @@ -152,12 +160,12 @@ void is31fl3729_set_value(int index, uint8_t value) { if (index >= 0 && index < IS31FL3729_LED_COUNT) { memcpy_P(&led, (&g_is31fl3729_leds[index]), sizeof(led)); - if (g_pwm_buffer[led.driver][led.v] == value) { + if (driver_buffers[led.driver].pwm_buffer[led.v] == value) { return; } - g_pwm_buffer_update_required[led.driver] = true; - g_pwm_buffer[led.driver][led.v] = value; + driver_buffers[led.driver].pwm_buffer[led.v] = value; + driver_buffers[led.driver].pwm_buffer_dirty = true; } } @@ -176,26 +184,25 @@ void is31fl3729_set_scaling_register(uint8_t index, uint8_t value) { // only enable them, since they should be default disabled int cs_value = (led.v & 0x0F) - 1; - g_scaling_registers[led.driver][cs_value] = value; - - g_scaling_registers_update_required[led.driver] = true; + driver_buffers[led.driver].scaling_buffer[cs_value] = value; + driver_buffers[led.driver].scaling_buffer_dirty = true; } void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index) { - if (g_pwm_buffer_update_required[index]) { + if (driver_buffers[index].pwm_buffer_dirty) { is31fl3729_write_pwm_buffer(addr, index); - g_pwm_buffer_update_required[index] = false; + driver_buffers[index].pwm_buffer_dirty = false; } } void is31fl3729_update_scaling_registers(uint8_t addr, uint8_t index) { - if (g_scaling_registers_update_required[index]) { + if (driver_buffers[index].scaling_buffer_dirty) { for (uint8_t i = 0; i < IS31FL3729_SCALING_REGISTER_COUNT; i++) { - is31fl3729_write_register(addr, IS31FL3729_REG_SCALING + i, g_scaling_registers[index][i]); + is31fl3729_write_register(addr, IS31FL3729_REG_SCALING + i, driver_buffers[index].scaling_buffer[i]); } - g_scaling_registers_update_required[index] = false; + driver_buffers[index].scaling_buffer_dirty = false; } } diff --git a/drivers/led/issi/is31fl3729.c b/drivers/led/issi/is31fl3729.c index 0610dcf98fcc..06f2d168d0b0 100644 --- a/drivers/led/issi/is31fl3729.c +++ b/drivers/led/issi/is31fl3729.c @@ -61,11 +61,19 @@ // These buffers match the PWM & scaling registers. // Storing them like this is optimal for I2C transfers to the registers. -uint8_t g_pwm_buffer[IS31FL3729_DRIVER_COUNT][IS31FL3729_PWM_REGISTER_COUNT]; -bool g_pwm_buffer_update_required[IS31FL3729_DRIVER_COUNT] = {false}; - -uint8_t g_scaling_registers[IS31FL3729_DRIVER_COUNT][IS31FL3729_SCALING_REGISTER_COUNT]; -bool g_scaling_registers_update_required[IS31FL3729_DRIVER_COUNT] = {false}; +typedef struct is31fl3729_driver_t { + uint8_t pwm_buffer[IS31FL3729_PWM_REGISTER_COUNT]; + bool pwm_buffer_dirty; + uint8_t scaling_buffer[IS31FL3729_SCALING_REGISTER_COUNT]; + bool scaling_buffer_dirty; +} PACKED is31fl3729_driver_t; + +is31fl3729_driver_t driver_buffers[IS31FL3729_DRIVER_COUNT] = {{ + .pwm_buffer = {0}, + .pwm_buffer_dirty = false, + .scaling_buffer = {0}, + .scaling_buffer_dirty = false, +}}; void is31fl3729_write_register(uint8_t addr, uint8_t reg, uint8_t data) { #if IS31FL3729_I2C_PERSISTENCE > 0 @@ -84,10 +92,10 @@ void is31fl3729_write_pwm_buffer(uint8_t addr, uint8_t index) { for (uint8_t i = 0; i <= IS31FL3729_PWM_REGISTER_COUNT; i += 16) { #if IS31FL3729_I2C_PERSISTENCE > 0 for (uint8_t j = 0; j < IS31FL3729_I2C_PERSISTENCE; j++) { - if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3729_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break; + if (i2c_write_register(addr << 1, i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3729_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break; } #else - i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3729_I2C_TIMEOUT); + i2c_write_register(addr << 1, i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3729_I2C_TIMEOUT); #endif } } @@ -152,14 +160,14 @@ void is31fl3729_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { if (index >= 0 && index < IS31FL3729_LED_COUNT) { memcpy_P(&led, (&g_is31fl3729_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) { + if (driver_buffers[led.driver].pwm_buffer[led.r] == red && driver_buffers[led.driver].pwm_buffer[led.g] == green && driver_buffers[led.driver].pwm_buffer[led.b] == blue) { return; } - g_pwm_buffer_update_required[led.driver] = true; - g_pwm_buffer[led.driver][led.r] = red; - g_pwm_buffer[led.driver][led.g] = green; - g_pwm_buffer[led.driver][led.b] = blue; + driver_buffers[led.driver].pwm_buffer[led.r] = red; + driver_buffers[led.driver].pwm_buffer[led.g] = green; + driver_buffers[led.driver].pwm_buffer[led.b] = blue; + driver_buffers[led.driver].pwm_buffer_dirty = true; } } @@ -180,28 +188,27 @@ void is31fl3729_set_scaling_register(uint8_t index, uint8_t red, uint8_t green, int cs_green = (led.g & 0x0F) - 1; int cs_blue = (led.b & 0x0F) - 1; - g_scaling_registers[led.driver][cs_red] = red; - g_scaling_registers[led.driver][cs_green] = green; - g_scaling_registers[led.driver][cs_blue] = blue; - - g_scaling_registers_update_required[led.driver] = true; + driver_buffers[led.driver].scaling_buffer[cs_red] = red; + driver_buffers[led.driver].scaling_buffer[cs_green] = green; + driver_buffers[led.driver].scaling_buffer[cs_blue] = blue; + driver_buffers[led.driver].scaling_buffer_dirty = true; } void is31fl3729_update_pwm_buffers(uint8_t addr, uint8_t index) { - if (g_pwm_buffer_update_required[index]) { + if (driver_buffers[index].pwm_buffer_dirty) { is31fl3729_write_pwm_buffer(addr, index); - g_pwm_buffer_update_required[index] = false; + driver_buffers[index].pwm_buffer_dirty = false; } } void is31fl3729_update_scaling_registers(uint8_t addr, uint8_t index) { - if (g_scaling_registers_update_required[index]) { + if (driver_buffers[index].scaling_buffer_dirty) { for (uint8_t i = 0; i < IS31FL3729_SCALING_REGISTER_COUNT; i++) { - is31fl3729_write_register(addr, IS31FL3729_REG_SCALING + i, g_scaling_registers[index][i]); + is31fl3729_write_register(addr, IS31FL3729_REG_SCALING + i, driver_buffers[index].scaling_buffer[i]); } - g_scaling_registers_update_required[index] = false; + driver_buffers[index].scaling_buffer_dirty = false; } }