diff options
Diffstat (limited to 'drivers')
27 files changed, 1193 insertions, 885 deletions
diff --git a/drivers/led/apa102.c b/drivers/led/apa102.c index 766d8cd2eb..527519eb8a 100644 --- a/drivers/led/apa102.c +++ b/drivers/led/apa102.c @@ -24,7 +24,7 @@ # elif defined(PROTOCOL_CHIBIOS) # include "hal.h" # include "chibios_config.h" -# if defined(STM32F0XX) || defined(STM32F1XX) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32L0XX) || defined(GD32VF103) +# if defined(STM32F0XX) || defined(STM32F1XX) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32L0XX) || defined(GD32VF103) || defined(MCU_RP) # define APA102_NOPS (100 / (1000000000L / (CPU_CLOCK / 4))) // This calculates how many loops of 4 nops to run to delay 100 ns # else # error APA102_NOPS configuration required @@ -61,18 +61,18 @@ void static apa102_end_frame(uint16_t num_leds); void static apa102_send_frame(uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness); void static apa102_send_byte(uint8_t byte); -void apa102_setleds(LED_TYPE *start_led, uint16_t num_leds) { - LED_TYPE *end = start_led + num_leds; +void apa102_setleds(rgb_led_t *start_led, uint16_t num_leds) { + rgb_led_t *end = start_led + num_leds; apa102_start_frame(); - for (LED_TYPE *led = start_led; led < end; led++) { + for (rgb_led_t *led = start_led; led < end; led++) { apa102_send_frame(led->r, led->g, led->b, apa102_led_brightness); } apa102_end_frame(num_leds); } // Overwrite the default rgblight_call_driver to use apa102 driver -void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { +void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds) { apa102_setleds(start_led, num_leds); } diff --git a/drivers/led/apa102.h b/drivers/led/apa102.h index 58cf020c1e..cd0a19d445 100644 --- a/drivers/led/apa102.h +++ b/drivers/led/apa102.h @@ -37,5 +37,5 @@ extern uint8_t apa102_led_brightness; * - Set the data-out pin as output * - Send out the LED data */ -void apa102_setleds(LED_TYPE *start_led, uint16_t num_leds); +void apa102_setleds(rgb_led_t *start_led, uint16_t num_leds); void apa102_set_brightness(uint8_t brightness); diff --git a/drivers/led/aw20216.c b/drivers/led/aw20216.c deleted file mode 100644 index 479643add4..0000000000 --- a/drivers/led/aw20216.c +++ /dev/null @@ -1,168 +0,0 @@ -/* Copyright 2021 Jasper Chan - * 2023 Huckies <https://github.com/Huckies> - * - * 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 <http://www.gnu.org/licenses/>. - */ - -#include "aw20216.h" -#include "wait.h" -#include "spi_master.h" - -/* The AW20216 appears to be somewhat similar to the IS31FL743, although quite - * a few things are different, such as the command byte format and page ordering. - * The LED addresses start from 0x00 instead of 0x01. - */ -#define AWINIC_ID 0b1010 << 4 - -#define AW_PAGE_FUNCTION 0x00 << 1 // PG0, Function registers -#define AW_PAGE_PWM 0x01 << 1 // PG1, LED PWM control -#define AW_PAGE_SCALING 0x02 << 1 // PG2, LED current scaling control -#define AW_PAGE_PATCHOICE 0x03 << 1 // PG3, Pattern choice? -#define AW_PAGE_PWMSCALING 0x04 << 1 // PG4, LED PWM + Scaling control? - -#define AW_WRITE 0 -#define AW_READ 1 - -#define AW_REG_CONFIGURATION 0x00 // PG0 -#define AW_REG_GLOBALCURRENT 0x01 // PG0 -#define AW_REG_RESET 0x2F // PG0 -#define AW_REG_MIXFUNCTION 0x46 // PG0 - -// Default value of AW_REG_CONFIGURATION -// D7:D4 = 1011, SWSEL (SW1~SW12 active) -// D3 = 0?, reserved (apparently this should be 1 but it doesn't seem to matter) -// D2:D1 = 00, OSDE (open/short detection enable) -// D0 = 0, CHIPEN (write 1 to enable LEDs when hardware enable pulled high) -#define AW_CONFIG_DEFAULT 0b10110000 -#define AW_MIXCR_DEFAULT 0b00000000 -#define AW_RESET_CMD 0xAE -#define AW_CHIPEN 1 -#define AW_LPEN (0x01 << 1) - -#define AW_PWM_REGISTER_COUNT 216 - -#ifndef AW_SCALING_MAX -# define AW_SCALING_MAX 150 -#endif - -#ifndef AW_GLOBAL_CURRENT_MAX -# define AW_GLOBAL_CURRENT_MAX 150 -#endif - -#ifndef AW_SPI_MODE -# define AW_SPI_MODE 0 -#endif - -#ifndef AW_SPI_DIVISOR -# define AW_SPI_DIVISOR 4 -#endif - -uint8_t g_pwm_buffer[DRIVER_COUNT][AW_PWM_REGISTER_COUNT]; -bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; - -bool aw20216_write(pin_t cs_pin, uint8_t page, uint8_t reg, uint8_t* data, uint8_t len) { - static uint8_t s_spi_transfer_buffer[2] = {0}; - - if (!spi_start(cs_pin, false, AW_SPI_MODE, AW_SPI_DIVISOR)) { - spi_stop(); - return false; - } - - s_spi_transfer_buffer[0] = (AWINIC_ID | page | AW_WRITE); - s_spi_transfer_buffer[1] = reg; - - if (spi_transmit(s_spi_transfer_buffer, 2) != SPI_STATUS_SUCCESS) { - spi_stop(); - return false; - } - - if (spi_transmit(data, len) != SPI_STATUS_SUCCESS) { - spi_stop(); - return false; - } - - spi_stop(); - return true; -} - -static inline bool aw20216_write_register(pin_t cs_pin, uint8_t page, uint8_t reg, uint8_t value) { - // Little wrapper so callers need not care about sending a buffer - return aw20216_write(cs_pin, page, reg, &value, 1); -} - -void aw20216_soft_reset(pin_t cs_pin) { - aw20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_RESET, AW_RESET_CMD); -} - -static void aw20216_init_scaling(pin_t cs_pin) { - // Set constant current to the max, control brightness with PWM - for (uint8_t i = 0; i < AW_PWM_REGISTER_COUNT; i++) { - aw20216_write_register(cs_pin, AW_PAGE_SCALING, i, AW_SCALING_MAX); - } -} - -static inline void aw20216_init_current_limit(pin_t cs_pin) { - // Push config - aw20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_GLOBALCURRENT, AW_GLOBAL_CURRENT_MAX); -} - -static inline void aw20216_soft_enable(pin_t cs_pin) { - // Push config - aw20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_CONFIGURATION, AW_CONFIG_DEFAULT | AW_CHIPEN); -} - -static inline void aw20216_auto_lowpower(pin_t cs_pin) { - aw20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_MIXFUNCTION, AW_MIXCR_DEFAULT | AW_LPEN); -} - -void aw20216_init(pin_t cs_pin, pin_t en_pin) { - setPinOutput(en_pin); - writePinHigh(en_pin); - - aw20216_soft_reset(cs_pin); - wait_ms(2); - - // Drivers should start with all scaling and PWM registers as off - aw20216_init_current_limit(cs_pin); - aw20216_init_scaling(cs_pin); - - aw20216_soft_enable(cs_pin); - aw20216_auto_lowpower(cs_pin); -} - -void aw20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { - aw_led led; - memcpy_P(&led, (&g_aw_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[led.driver][led.r] = red; - g_pwm_buffer[led.driver][led.g] = green; - g_pwm_buffer[led.driver][led.b] = blue; - g_pwm_buffer_update_required[led.driver] = true; -} - -void aw20216_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { - for (uint8_t i = 0; i < RGB_MATRIX_LED_COUNT; i++) { - aw20216_set_color(i, red, green, blue); - } -} - -void aw20216_update_pwm_buffers(pin_t cs_pin, uint8_t index) { - if (g_pwm_buffer_update_required[index]) { - aw20216_write(cs_pin, AW_PAGE_PWM, 0, g_pwm_buffer[index], AW_PWM_REGISTER_COUNT); - } - g_pwm_buffer_update_required[index] = false; -} diff --git a/drivers/led/aw20216s.c b/drivers/led/aw20216s.c new file mode 100644 index 0000000000..1b7861a1ec --- /dev/null +++ b/drivers/led/aw20216s.c @@ -0,0 +1,168 @@ +/* Copyright 2021 Jasper Chan + * 2023 Huckies <https://github.com/Huckies> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#include "aw20216s.h" +#include "wait.h" +#include "spi_master.h" + +/* The AW20216S appears to be somewhat similar to the IS31FL743, although quite + * a few things are different, such as the command byte format and page ordering. + * The LED addresses start from 0x00 instead of 0x01. + */ +#define AW20216S_ID 0b1010 << 4 + +#define AW20216S_PAGE_FUNCTION 0x00 << 1 // PG0, Function registers +#define AW20216S_PAGE_PWM 0x01 << 1 // PG1, LED PWM control +#define AW20216S_PAGE_SCALING 0x02 << 1 // PG2, LED current scaling control +#define AW20216S_PAGE_PATCHOICE 0x03 << 1 // PG3, Pattern choice? +#define AW20216S_PAGE_PWMSCALING 0x04 << 1 // PG4, LED PWM + Scaling control? + +#define AW20216S_WRITE 0 +#define AW20216S_READ 1 + +#define AW20216S_REG_CONFIGURATION 0x00 // PG0 +#define AW20216S_REG_GLOBALCURRENT 0x01 // PG0 +#define AW20216S_REG_RESET 0x2F // PG0 +#define AW20216S_REG_MIXFUNCTION 0x46 // PG0 + +// Default value of AW20216S_REG_CONFIGURATION +// D7:D4 = 1011, SWSEL (SW1~SW12 active) +// D3 = 0?, reserved (apparently this should be 1 but it doesn't seem to matter) +// D2:D1 = 00, OSDE (open/short detection enable) +// D0 = 0, CHIPEN (write 1 to enable LEDs when hardware enable pulled high) +#define AW20216S_CONFIG_DEFAULT 0b10110000 +#define AW20216S_MIXCR_DEFAULT 0b00000000 +#define AW20216S_RESET_CMD 0xAE +#define AW20216S_CHIPEN 1 +#define AW20216S_LPEN (0x01 << 1) + +#define AW20216S_PWM_REGISTER_COUNT 216 + +#ifndef AW20216S_SCALING_MAX +# define AW20216S_SCALING_MAX 150 +#endif + +#ifndef AW20216S_GLOBAL_CURRENT_MAX +# define AW20216S_GLOBAL_CURRENT_MAX 150 +#endif + +#ifndef AW20216S_SPI_MODE +# define AW20216S_SPI_MODE 0 +#endif + +#ifndef AW20216S_SPI_DIVISOR +# define AW20216S_SPI_DIVISOR 4 +#endif + +uint8_t g_pwm_buffer[AW20216S_DRIVER_COUNT][AW20216S_PWM_REGISTER_COUNT]; +bool g_pwm_buffer_update_required[AW20216S_DRIVER_COUNT] = {false}; + +bool aw20216s_write(pin_t cs_pin, uint8_t page, uint8_t reg, uint8_t* data, uint8_t len) { + static uint8_t s_spi_transfer_buffer[2] = {0}; + + if (!spi_start(cs_pin, false, AW20216S_SPI_MODE, AW20216S_SPI_DIVISOR)) { + spi_stop(); + return false; + } + + s_spi_transfer_buffer[0] = (AW20216S_ID | page | AW20216S_WRITE); + s_spi_transfer_buffer[1] = reg; + + if (spi_transmit(s_spi_transfer_buffer, 2) != SPI_STATUS_SUCCESS) { + spi_stop(); + return false; + } + + if (spi_transmit(data, len) != SPI_STATUS_SUCCESS) { + spi_stop(); + return false; + } + + spi_stop(); + return true; +} + +static inline bool aw20216s_write_register(pin_t cs_pin, uint8_t page, uint8_t reg, uint8_t value) { + // Little wrapper so callers need not care about sending a buffer + return aw20216s_write(cs_pin, page, reg, &value, 1); +} + +void aw20216s_soft_reset(pin_t cs_pin) { + aw20216s_write_register(cs_pin, AW20216S_PAGE_FUNCTION, AW20216S_REG_RESET, AW20216S_RESET_CMD); +} + +static void aw20216s_init_scaling(pin_t cs_pin) { + // Set constant current to the max, control brightness with PWM + for (uint8_t i = 0; i < AW20216S_PWM_REGISTER_COUNT; i++) { + aw20216s_write_register(cs_pin, AW20216S_PAGE_SCALING, i, AW20216S_SCALING_MAX); + } +} + +static inline void aw20216s_init_current_limit(pin_t cs_pin) { + // Push config + aw20216s_write_register(cs_pin, AW20216S_PAGE_FUNCTION, AW20216S_REG_GLOBALCURRENT, AW20216S_GLOBAL_CURRENT_MAX); +} + +static inline void aw20216s_soft_enable(pin_t cs_pin) { + // Push config + aw20216s_write_register(cs_pin, AW20216S_PAGE_FUNCTION, AW20216S_REG_CONFIGURATION, AW20216S_CONFIG_DEFAULT | AW20216S_CHIPEN); +} + +static inline void aw20216s_auto_lowpower(pin_t cs_pin) { + aw20216s_write_register(cs_pin, AW20216S_PAGE_FUNCTION, AW20216S_REG_MIXFUNCTION, AW20216S_MIXCR_DEFAULT | AW20216S_LPEN); +} + +void aw20216s_init(pin_t cs_pin, pin_t en_pin) { + setPinOutput(en_pin); + writePinHigh(en_pin); + + aw20216s_soft_reset(cs_pin); + wait_ms(2); + + // Drivers should start with all scaling and PWM registers as off + aw20216s_init_current_limit(cs_pin); + aw20216s_init_scaling(cs_pin); + + aw20216s_soft_enable(cs_pin); + aw20216s_auto_lowpower(cs_pin); +} + +void aw20216s_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { + aw20216s_led led; + memcpy_P(&led, (&g_aw20216s_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[led.driver][led.r] = red; + g_pwm_buffer[led.driver][led.g] = green; + g_pwm_buffer[led.driver][led.b] = blue; + g_pwm_buffer_update_required[led.driver] = true; +} + +void aw20216s_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { + for (uint8_t i = 0; i < RGB_MATRIX_LED_COUNT; i++) { + aw20216s_set_color(i, red, green, blue); + } +} + +void aw20216s_update_pwm_buffers(pin_t cs_pin, uint8_t index) { + if (g_pwm_buffer_update_required[index]) { + aw20216s_write(cs_pin, AW20216S_PAGE_PWM, 0, g_pwm_buffer[index], AW20216S_PWM_REGISTER_COUNT); + } + g_pwm_buffer_update_required[index] = false; +} diff --git a/drivers/led/aw20216.h b/drivers/led/aw20216s.h index e342cb6bac..49b0a8e0ad 100644 --- a/drivers/led/aw20216.h +++ b/drivers/led/aw20216s.h @@ -21,19 +21,49 @@ #include "progmem.h" #include "gpio.h" -typedef struct aw_led { +// ======== DEPRECATED DEFINES - DO NOT USE ======== +#ifdef DRIVER_COUNT +# define AW20216S_DRIVER_COUNT DRIVER_COUNT +#endif +#ifdef AW_SCALING_MAX +# define AW20216S_SCALING_MAX AW_SCALING_MAX +#endif +#ifdef AW_GLOBAL_CURRENT_MAX +# define AW20216S_GLOBAL_CURRENT_MAX AW_GLOBAL_CURRENT_MAX +#endif +#ifdef AW_SPI_MODE +# define AW20216S_SPI_MODE AW_SPI_MODE +#endif +#ifdef AW_SPI_DIVISOR +# define AW20216S_SPI_DIVISOR AW_SPI_DIVISOR +#endif +#ifdef DRIVER_1_CS +# define AW20216S_DRIVER_1_CS DRIVER_1_CS +#endif +#ifdef DRIVER_2_CS +# define AW20216S_DRIVER_2_CS DRIVER_2_CS +#endif +#ifdef DRIVER_1_EN +# define AW20216S_DRIVER_1_EN DRIVER_1_EN +#endif +#ifdef DRIVER_2_EN +# define AW20216S_DRIVER_2_EN DRIVER_2_EN +#endif +// ======== + +typedef struct aw20216s_led { uint8_t driver : 2; uint8_t r; uint8_t g; uint8_t b; -} aw_led; +} aw20216s_led; -extern const aw_led PROGMEM g_aw_leds[RGB_MATRIX_LED_COUNT]; +extern const aw20216s_led PROGMEM g_aw20216s_leds[RGB_MATRIX_LED_COUNT]; -void aw20216_init(pin_t cs_pin, pin_t en_pin); -void aw20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); -void aw20216_set_color_all(uint8_t red, uint8_t green, uint8_t blue); -void aw20216_update_pwm_buffers(pin_t cs_pin, uint8_t index); +void aw20216s_init(pin_t cs_pin, pin_t en_pin); +void aw20216s_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); +void aw20216s_set_color_all(uint8_t red, uint8_t green, uint8_t blue); +void aw20216s_update_pwm_buffers(pin_t cs_pin, uint8_t index); #define CS1_SW1 0x00 #define CS2_SW1 0x01 diff --git a/drivers/led/ckled2001-simple.c b/drivers/led/ckled2001-simple.c index c4d4c0a4cc..936b915af8 100644 --- a/drivers/led/ckled2001-simple.c +++ b/drivers/led/ckled2001-simple.c @@ -16,18 +16,17 @@ #include "ckled2001-simple.h" #include "i2c_master.h" -#include "wait.h" -#ifndef CKLED2001_TIMEOUT -# define CKLED2001_TIMEOUT 100 +#ifndef CKLED2001_I2C_TIMEOUT +# define CKLED2001_I2C_TIMEOUT 100 #endif -#ifndef CKLED2001_PERSISTENCE -# define CKLED2001_PERSISTENCE 0 +#ifndef CKLED2001_I2C_PERSISTENCE +# define CKLED2001_I2C_PERSISTENCE 0 #endif -#ifndef PHASE_CHANNEL -# define PHASE_CHANNEL MSKPHASE_12CHANNEL +#ifndef CKLED2001_PHASE_CHANNEL +# define CKLED2001_PHASE_CHANNEL CKLED2001_MSKPHASE_12CHANNEL #endif #ifndef CKLED2001_CURRENT_TUNE @@ -44,25 +43,25 @@ uint8_t g_twi_transfer_buffer[20]; // We could optimize this and take out the unused registers from these // buffers and the transfers in ckled2001_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[DRIVER_COUNT][192]; -bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; +uint8_t g_pwm_buffer[CKLED2001_DRIVER_COUNT][192]; +bool g_pwm_buffer_update_required[CKLED2001_DRIVER_COUNT] = {false}; -uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0}; -bool g_led_control_registers_update_required[DRIVER_COUNT] = {false}; +uint8_t g_led_control_registers[CKLED2001_DRIVER_COUNT][24] = {0}; +bool g_led_control_registers_update_required[CKLED2001_DRIVER_COUNT] = {false}; bool ckled2001_write_register(uint8_t addr, uint8_t reg, uint8_t data) { // If the transaction fails function returns false. g_twi_transfer_buffer[0] = reg; g_twi_transfer_buffer[1] = data; -#if CKLED2001_PERSISTENCE > 0 - for (uint8_t i = 0; i < CKLED2001_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, CKLED2001_TIMEOUT) != 0) { +#if CKLED2001_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < CKLED2001_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, CKLED2001_I2C_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, CKLED2001_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, CKLED2001_I2C_TIMEOUT) != 0) { return false; } #endif @@ -85,14 +84,14 @@ bool ckled2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j]; } -#if CKLED2001_PERSISTENCE > 0 - for (uint8_t i = 0; i < CKLED2001_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, CKLED2001_TIMEOUT) != 0) { +#if CKLED2001_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < CKLED2001_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, CKLED2001_I2C_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, CKLED2001_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, CKLED2001_I2C_TIMEOUT) != 0) { return false; } #endif @@ -102,48 +101,48 @@ bool ckled2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { void ckled2001_init(uint8_t addr) { // Select to function page - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_FUNCTION_PAGE); // Setting LED driver to shutdown mode - ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_SHUT_DOWN_MODE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURATION, CKLED2001_MSKSW_SHUT_DOWN_MODE); // Setting internal channel pulldown/pullup - ckled2001_write_register(addr, PDU_REG, MSKSET_CA_CB_CHANNEL); + ckled2001_write_register(addr, CKLED2001_REG_PDU, CKLED2001_MSKSET_CA_CB_CHANNEL); // Select number of scan phase - ckled2001_write_register(addr, SCAN_PHASE_REG, PHASE_CHANNEL); + ckled2001_write_register(addr, CKLED2001_REG_SCAN_PHASE, CKLED2001_PHASE_CHANNEL); // Setting PWM Delay Phase - ckled2001_write_register(addr, SLEW_RATE_CONTROL_MODE1_REG, MSKPWM_DELAY_PHASE_ENABLE); + ckled2001_write_register(addr, CKLED2001_REG_SLEW_RATE_CONTROL_MODE1, CKLED2001_MSKPWM_DELAY_PHASE_ENABLE); // Setting Driving/Sinking Channel Slew Rate - ckled2001_write_register(addr, SLEW_RATE_CONTROL_MODE2_REG, MSKDRIVING_SINKING_CHHANNEL_SLEWRATE_ENABLE); + ckled2001_write_register(addr, CKLED2001_REG_SLEW_RATE_CONTROL_MODE2, CKLED2001_MSKDRIVING_SINKING_CHANNEL_SLEWRATE_ENABLE); // Setting Iref - ckled2001_write_register(addr, SOFTWARE_SLEEP_REG, MSKSLEEP_DISABLE); + ckled2001_write_register(addr, CKLED2001_REG_SOFTWARE_SLEEP, CKLED2001_MSKSLEEP_DISABLE); // Set LED CONTROL PAGE (Page 0) - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE); - for (int i = 0; i < LED_CONTROL_ON_OFF_LENGTH; i++) { + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_LED_CONTROL_PAGE); + for (int i = 0; i < CKLED2001_LED_CONTROL_ON_OFF_LENGTH; i++) { ckled2001_write_register(addr, i, 0x00); } // Set PWM PAGE (Page 1) - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_PWM_PAGE); - for (int i = 0; i < LED_CURRENT_TUNE_LENGTH; i++) { + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_LED_PWM_PAGE); + for (int i = 0; i < CKLED2001_LED_CURRENT_TUNE_LENGTH; i++) { ckled2001_write_register(addr, i, 0x00); } // Set CURRENT PAGE (Page 4) - uint8_t current_tuen_reg_list[LED_CURRENT_TUNE_LENGTH] = CKLED2001_CURRENT_TUNE; - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, CURRENT_TUNE_PAGE); - for (int i = 0; i < LED_CURRENT_TUNE_LENGTH; i++) { - ckled2001_write_register(addr, i, current_tuen_reg_list[i]); + uint8_t current_tune_reg_list[CKLED2001_LED_CURRENT_TUNE_LENGTH] = CKLED2001_CURRENT_TUNE; + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_CURRENT_TUNE_PAGE); + for (int i = 0; i < CKLED2001_LED_CURRENT_TUNE_LENGTH; i++) { + ckled2001_write_register(addr, i, current_tune_reg_list[i]); } // Enable LEDs ON/OFF - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE); - for (int i = 0; i < LED_CONTROL_ON_OFF_LENGTH; i++) { + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_LED_CONTROL_PAGE); + for (int i = 0; i < CKLED2001_LED_CONTROL_ON_OFF_LENGTH; i++) { ckled2001_write_register(addr, i, 0xFF); } // Select to function page - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_FUNCTION_PAGE); // Setting LED driver to normal mode - ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_NORMAL_MODE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURATION, CKLED2001_MSKSW_NORMAL_MODE); } void ckled2001_set_value(int index, uint8_t value) { @@ -183,7 +182,7 @@ void ckled2001_set_led_control_register(uint8_t index, bool value) { void ckled2001_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_PWM_PAGE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_LED_PWM_PAGE); // If any of the transactions fail we risk writing dirty PG0, // refresh page 0 just in case. @@ -196,7 +195,7 @@ void ckled2001_update_pwm_buffers(uint8_t addr, uint8_t index) { void ckled2001_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_led_control_registers_update_required[index]) { - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_LED_CONTROL_PAGE); for (int i = 0; i < 24; i++) { ckled2001_write_register(addr, i, g_led_control_registers[index][i]); } @@ -206,16 +205,16 @@ void ckled2001_update_led_control_registers(uint8_t addr, uint8_t index) { void ckled2001_sw_return_normal(uint8_t addr) { // Select to function page - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_FUNCTION_PAGE); // Setting LED driver to normal mode - ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_NORMAL_MODE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURATION, CKLED2001_MSKSW_NORMAL_MODE); } void ckled2001_sw_shutdown(uint8_t addr) { // Select to function page - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_FUNCTION_PAGE); // Setting LED driver to shutdown mode - ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_SHUT_DOWN_MODE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURATION, CKLED2001_MSKSW_SHUT_DOWN_MODE); // Write SW Sleep Register - ckled2001_write_register(addr, SOFTWARE_SLEEP_REG, MSKSLEEP_ENABLE); + ckled2001_write_register(addr, CKLED2001_REG_SOFTWARE_SLEEP, CKLED2001_MSKSLEEP_ENABLE); } diff --git a/drivers/led/ckled2001-simple.h b/drivers/led/ckled2001-simple.h index c94df62dd2..d1765b912b 100644 --- a/drivers/led/ckled2001-simple.h +++ b/drivers/led/ckled2001-simple.h @@ -20,6 +20,34 @@ #include <stdbool.h> #include "progmem.h" +// ======== DEPRECATED DEFINES - DO NOT USE ======== +#ifdef DRIVER_COUNT +# define CKLED2001_DRIVER_COUNT DRIVER_COUNT +#endif +#ifdef CKLED2001_TIMEOUT +# define CKLED2001_I2C_TIMEOUT CKLED2001_TIMEOUT +#endif +#ifdef CKLED2001_PERSISTENCE +# define CKLED2001_I2C_PERSISTENCE CKLED2001_PERSISTENCE +#endif +#ifdef PHASE_CHANNEL +# define CKLED2001_PHASE_CHANNEL PHASE_CHANNEL +#endif + +#define MSKPHASE_12CHANNEL CKLED2001_MSKPHASE_12CHANNEL +#define MSKPHASE_11CHANNEL CKLED2001_MSKPHASE_11CHANNEL +#define MSKPHASE_10CHANNEL CKLED2001_MSKPHASE_10CHANNEL +#define MSKPHASE_9CHANNEL CKLED2001_MSKPHASE_9CHANNEL +#define MSKPHASE_8CHANNEL CKLED2001_MSKPHASE_8CHANNEL +#define MSKPHASE_7CHANNEL CKLED2001_MSKPHASE_7CHANNEL +#define MSKPHASE_6CHANNEL CKLED2001_MSKPHASE_6CHANNEL +#define MSKPHASE_5CHANNEL CKLED2001_MSKPHASE_5CHANNEL +#define MSKPHASE_4CHANNEL CKLED2001_MSKPHASE_4CHANNEL +#define MSKPHASE_3CHANNEL CKLED2001_MSKPHASE_3CHANNEL +#define MSKPHASE_2CHANNEL CKLED2001_MSKPHASE_2CHANNEL +#define MSKPHASE_1CHANNEL CKLED2001_MSKPHASE_1CHANNEL +// ======== + typedef struct ckled2001_led { uint8_t driver : 2; uint8_t v; @@ -47,90 +75,90 @@ void ckled2001_sw_return_normal(uint8_t addr); void ckled2001_sw_shutdown(uint8_t addr); // Registers Page Define -#define CONFIGURE_CMD_PAGE 0xFD -#define LED_CONTROL_PAGE 0x00 -#define LED_PWM_PAGE 0x01 -#define FUNCTION_PAGE 0x03 -#define CURRENT_TUNE_PAGE 0x04 +#define CKLED2001_REG_CONFIGURE_CMD_PAGE 0xFD +#define CKLED2001_LED_CONTROL_PAGE 0x00 +#define CKLED2001_LED_PWM_PAGE 0x01 +#define CKLED2001_FUNCTION_PAGE 0x03 +#define CKLED2001_CURRENT_TUNE_PAGE 0x04 // Function Register: address 0x00 -#define CONFIGURATION_REG 0x00 -#define MSKSW_SHUT_DOWN_MODE (0x0 << 0) -#define MSKSW_NORMAL_MODE (0x1 << 0) - -#define DRIVER_ID_REG 0x11 -#define CKLED2001_ID 0x8A - -#define PDU_REG 0x13 -#define MSKSET_CA_CB_CHANNEL 0xAA -#define MSKCLR_CA_CB_CHANNEL 0x00 - -#define SCAN_PHASE_REG 0x14 -#define MSKPHASE_12CHANNEL 0x00 -#define MSKPHASE_11CHANNEL 0x01 -#define MSKPHASE_10CHANNEL 0x02 -#define MSKPHASE_9CHANNEL 0x03 -#define MSKPHASE_8CHANNEL 0x04 -#define MSKPHASE_7CHANNEL 0x05 -#define MSKPHASE_6CHANNEL 0x06 -#define MSKPHASE_5CHANNEL 0x07 -#define MSKPHASE_4CHANNEL 0x08 -#define MSKPHASE_3CHANNEL 0x09 -#define MSKPHASE_2CHANNEL 0x0A -#define MSKPHASE_1CHANNEL 0x0B - -#define SLEW_RATE_CONTROL_MODE1_REG 0x15 -#define MSKPWM_DELAY_PHASE_ENABLE 0x04 -#define MSKPWM_DELAY_PHASE_DISABLE 0x00 - -#define SLEW_RATE_CONTROL_MODE2_REG 0x16 -#define MSKDRIVING_SINKING_CHHANNEL_SLEWRATE_ENABLE 0xC0 -#define MSKDRIVING_SINKING_CHHANNEL_SLEWRATE_DISABLE 0x00 - -#define OPEN_SHORT_ENABLE_REG 0x17 -#define MSKOPEN_DETECTION_ENABLE (0x01 << 7) -#define MSKOPEN_DETECTION_DISABLE (0x00) - -#define MSKSHORT_DETECTION_ENABLE (0x01 << 6) -#define MSKSHORT_DETECTION_DISABLE (0x00) - -#define OPEN_SHORT_DUTY_REG 0x18 -#define OPEN_SHORT_FLAG_REG 0x19 - -#define MSKOPEN_DETECTION_INTERRUPT_ENABLE (0x01 << 7) -#define MSKOPEN_DETECTION_INTERRUPT_DISABLE (0x00) - -#define MSKSHORT_DETECTION_INTERRUPT_ENABLE (0x01 << 6) -#define MSKSHORT_DETECTION_INTERRUPT_DISABLE (0x00) - -#define SOFTWARE_SLEEP_REG 0x1A -#define MSKSLEEP_ENABLE 0x02 -#define MSKSLEEP_DISABLE 0x00 +#define CKLED2001_REG_CONFIGURATION 0x00 +#define CKLED2001_MSKSW_SHUT_DOWN_MODE (0x0 << 0) +#define CKLED2001_MSKSW_NORMAL_MODE (0x1 << 0) + +#define CKLED2001_REG_DRIVER_ID 0x11 +#define CKLED2001_DRIVER_ID 0x8A + +#define CKLED2001_REG_PDU 0x13 +#define CKLED2001_MSKSET_CA_CB_CHANNEL 0xAA +#define CKLED2001_MSKCLR_CA_CB_CHANNEL 0x00 + +#define CKLED2001_REG_SCAN_PHASE 0x14 +#define CKLED2001_MSKPHASE_12CHANNEL 0x00 +#define CKLED2001_MSKPHASE_11CHANNEL 0x01 +#define CKLED2001_MSKPHASE_10CHANNEL 0x02 +#define CKLED2001_MSKPHASE_9CHANNEL 0x03 +#define CKLED2001_MSKPHASE_8CHANNEL 0x04 +#define CKLED2001_MSKPHASE_7CHANNEL 0x05 +#define CKLED2001_MSKPHASE_6CHANNEL 0x06 +#define CKLED2001_MSKPHASE_5CHANNEL 0x07 +#define CKLED2001_MSKPHASE_4CHANNEL 0x08 +#define CKLED2001_MSKPHASE_3CHANNEL 0x09 +#define CKLED2001_MSKPHASE_2CHANNEL 0x0A +#define CKLED2001_MSKPHASE_1CHANNEL 0x0B + +#define CKLED2001_REG_SLEW_RATE_CONTROL_MODE1 0x15 +#define CKLED2001_MSKPWM_DELAY_PHASE_ENABLE 0x04 +#define CKLED2001_MSKPWM_DELAY_PHASE_DISABLE 0x00 + +#define CKLED2001_REG_SLEW_RATE_CONTROL_MODE2 0x16 +#define CKLED2001_MSKDRIVING_SINKING_CHANNEL_SLEWRATE_ENABLE 0xC0 +#define CKLED2001_MSKDRIVING_SINKING_CHANNEL_SLEWRATE_DISABLE 0x00 + +#define CKLED2001_REG_OPEN_SHORT_ENABLE 0x17 +#define CKLED2001_MSKOPEN_DETECTION_ENABLE (0x01 << 7) +#define CKLED2001_MSKOPEN_DETECTION_DISABLE (0x00) + +#define CKLED2001_MSKSHORT_DETECTION_ENABLE (0x01 << 6) +#define CKLED2001_MSKSHORT_DETECTION_DISABLE (0x00) + +#define CKLED2001_REG_OPEN_SHORT_DUTY 0x18 +#define CKLED2001_REG_OPEN_SHORT_FLAG 0x19 + +#define CKLED2001_MSKOPEN_DETECTION_INTERRUPT_ENABLE (0x01 << 7) +#define CKLED2001_MSKOPEN_DETECTION_INTERRUPT_DISABLE (0x00) + +#define CKLED2001_MSKSHORT_DETECTION_INTERRUPT_ENABLE (0x01 << 6) +#define CKLED2001_MSKSHORT_DETECTION_INTERRUPT_DISABLE (0x00) + +#define CKLED2001_REG_SOFTWARE_SLEEP 0x1A +#define CKLED2001_MSKSLEEP_ENABLE 0x02 +#define CKLED2001_MSKSLEEP_DISABLE 0x00 // LED Control Registers -#define LED_CONTROL_ON_OFF_FIRST_ADDR 0x0 -#define LED_CONTROL_ON_OFF_LAST_ADDR 0x17 -#define LED_CONTROL_ON_OFF_LENGTH ((LED_CONTROL_ON_OFF_LAST_ADDR - LED_CONTROL_ON_OFF_FIRST_ADDR) + 1) +#define CKLED2001_LED_CONTROL_ON_OFF_FIRST_ADDR 0x0 +#define CKLED2001_LED_CONTROL_ON_OFF_LAST_ADDR 0x17 +#define CKLED2001_LED_CONTROL_ON_OFF_LENGTH ((CKLED2001_LED_CONTROL_ON_OFF_LAST_ADDR - CKLED2001_LED_CONTROL_ON_OFF_FIRST_ADDR) + 1) -#define LED_CONTROL_OPEN_FIRST_ADDR 0x18 -#define LED_CONTROL_OPEN_LAST_ADDR 0x2F -#define LED_CONTROL_OPEN_LENGTH ((LED_CONTROL_OPEN_LAST_ADDR - LED_CONTROL_OPEN_FIRST_ADDR) + 1) +#define CKLED2001_LED_CONTROL_OPEN_FIRST_ADDR 0x18 +#define CKLED2001_LED_CONTROL_OPEN_LAST_ADDR 0x2F +#define CKLED2001_LED_CONTROL_OPEN_LENGTH ((CKLED2001_LED_CONTROL_OPEN_LAST_ADDR - CKLED2001_LED_CONTROL_OPEN_FIRST_ADDR) + 1) -#define LED_CONTROL_SHORT_FIRST_ADDR 0x30 -#define LED_CONTROL_SHORT_LAST_ADDR 0x47 -#define LED_CONTROL_SHORT_LENGTH ((LED_CONTROL_SHORT_LAST_ADDR - LED_CONTROL_SHORT_FIRST_ADDR) + 1) +#define CKLED2001_LED_CONTROL_SHORT_FIRST_ADDR 0x30 +#define CKLED2001_LED_CONTROL_SHORT_LAST_ADDR 0x47 +#define CKLED2001_LED_CONTROL_SHORT_LENGTH ((CKLED2001_LED_CONTROL_SHORT_LAST_ADDR - CKLED2001_LED_CONTROL_SHORT_FIRST_ADDR) + 1) -#define LED_CONTROL_PAGE_LENGTH 0x48 +#define CKLED2001_LED_CONTROL_PAGE_LENGTH 0x48 // LED Control Registers -#define LED_PWM_FIRST_ADDR 0x00 -#define LED_PWM_LAST_ADDR 0xBF -#define LED_PWM_LENGTH 0xC0 +#define CKLED2001_LED_PWM_FIRST_ADDR 0x00 +#define CKLED2001_LED_PWM_LAST_ADDR 0xBF +#define CKLED2001_LED_PWM_LENGTH 0xC0 // Current Tune Registers -#define LED_CURRENT_TUNE_FIRST_ADDR 0x00 -#define LED_CURRENT_TUNE_LAST_ADDR 0x0B -#define LED_CURRENT_TUNE_LENGTH 0x0C +#define CKLED2001_LED_CURRENT_TUNE_FIRST_ADDR 0x00 +#define CKLED2001_LED_CURRENT_TUNE_LAST_ADDR 0x0B +#define CKLED2001_LED_CURRENT_TUNE_LENGTH 0x0C #define A_1 0x00 #define A_2 0x01 @@ -334,4 +362,4 @@ void ckled2001_sw_shutdown(uint8_t addr); #define L_13 0xBC #define L_14 0xBD #define L_15 0xBE -#define L_16 0xBF
\ No newline at end of file +#define L_16 0xBF diff --git a/drivers/led/ckled2001.c b/drivers/led/ckled2001.c index 6ababf55e9..8340aae823 100644 --- a/drivers/led/ckled2001.c +++ b/drivers/led/ckled2001.c @@ -16,18 +16,17 @@ #include "ckled2001.h" #include "i2c_master.h" -#include "wait.h" -#ifndef CKLED2001_TIMEOUT -# define CKLED2001_TIMEOUT 100 +#ifndef CKLED2001_I2C_TIMEOUT +# define CKLED2001_I2C_TIMEOUT 100 #endif -#ifndef CKLED2001_PERSISTENCE -# define CKLED2001_PERSISTENCE 0 +#ifndef CKLED2001_I2C_PERSISTENCE +# define CKLED2001_I2C_PERSISTENCE 0 #endif -#ifndef PHASE_CHANNEL -# define PHASE_CHANNEL MSKPHASE_12CHANNEL +#ifndef CKLED2001_PHASE_CHANNEL +# define CKLED2001_PHASE_CHANNEL CKLED2001_MSKPHASE_12CHANNEL #endif #ifndef CKLED2001_CURRENT_TUNE @@ -44,25 +43,25 @@ uint8_t g_twi_transfer_buffer[65]; // We could optimize this and take out the unused registers from these // buffers and the transfers in ckled2001_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[DRIVER_COUNT][192]; -bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; +uint8_t g_pwm_buffer[CKLED2001_DRIVER_COUNT][192]; +bool g_pwm_buffer_update_required[CKLED2001_DRIVER_COUNT] = {false}; -uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0}; -bool g_led_control_registers_update_required[DRIVER_COUNT] = {false}; +uint8_t g_led_control_registers[CKLED2001_DRIVER_COUNT][24] = {0}; +bool g_led_control_registers_update_required[CKLED2001_DRIVER_COUNT] = {false}; bool ckled2001_write_register(uint8_t addr, uint8_t reg, uint8_t data) { // If the transaction fails function returns false. g_twi_transfer_buffer[0] = reg; g_twi_transfer_buffer[1] = data; -#if CKLED2001_PERSISTENCE > 0 - for (uint8_t i = 0; i < CKLED2001_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, CKLED2001_TIMEOUT) != 0) { +#if CKLED2001_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < CKLED2001_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, CKLED2001_I2C_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, CKLED2001_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, CKLED2001_I2C_TIMEOUT) != 0) { return false; } #endif @@ -84,14 +83,14 @@ bool ckled2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j]; } -#if CKLED2001_PERSISTENCE > 0 - for (uint8_t i = 0; i < CKLED2001_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 65, CKLED2001_TIMEOUT) != 0) { +#if CKLED2001_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < CKLED2001_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 65, CKLED2001_I2C_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 65, CKLED2001_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 65, CKLED2001_I2C_TIMEOUT) != 0) { return false; } #endif @@ -101,48 +100,48 @@ bool ckled2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { void ckled2001_init(uint8_t addr) { // Select to function page - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_FUNCTION_PAGE); // Setting LED driver to shutdown mode - ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_SHUT_DOWN_MODE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURATION, CKLED2001_MSKSW_SHUT_DOWN_MODE); // Setting internal channel pulldown/pullup - ckled2001_write_register(addr, PDU_REG, MSKSET_CA_CB_CHANNEL); + ckled2001_write_register(addr, CKLED2001_REG_PDU, CKLED2001_MSKSET_CA_CB_CHANNEL); // Select number of scan phase - ckled2001_write_register(addr, SCAN_PHASE_REG, PHASE_CHANNEL); + ckled2001_write_register(addr, CKLED2001_REG_SCAN_PHASE, CKLED2001_PHASE_CHANNEL); // Setting PWM Delay Phase - ckled2001_write_register(addr, SLEW_RATE_CONTROL_MODE1_REG, MSKPWM_DELAY_PHASE_ENABLE); + ckled2001_write_register(addr, CKLED2001_REG_SLEW_RATE_CONTROL_MODE1, CKLED2001_MSKPWM_DELAY_PHASE_ENABLE); // Setting Driving/Sinking Channel Slew Rate - ckled2001_write_register(addr, SLEW_RATE_CONTROL_MODE2_REG, MSKDRIVING_SINKING_CHHANNEL_SLEWRATE_ENABLE); + ckled2001_write_register(addr, CKLED2001_REG_SLEW_RATE_CONTROL_MODE2, CKLED2001_MSKDRIVING_SINKING_CHANNEL_SLEWRATE_ENABLE); // Setting Iref - ckled2001_write_register(addr, SOFTWARE_SLEEP_REG, MSKSLEEP_DISABLE); + ckled2001_write_register(addr, CKLED2001_REG_SOFTWARE_SLEEP, CKLED2001_MSKSLEEP_DISABLE); // Set LED CONTROL PAGE (Page 0) - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE); - for (int i = 0; i < LED_CONTROL_ON_OFF_LENGTH; i++) { + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_LED_CONTROL_PAGE); + for (int i = 0; i < CKLED2001_LED_CONTROL_ON_OFF_LENGTH; i++) { ckled2001_write_register(addr, i, 0x00); } // Set PWM PAGE (Page 1) - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_PWM_PAGE); - for (int i = 0; i < LED_CURRENT_TUNE_LENGTH; i++) { + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_LED_PWM_PAGE); + for (int i = 0; i < CKLED2001_LED_CURRENT_TUNE_LENGTH; i++) { ckled2001_write_register(addr, i, 0x00); } // Set CURRENT PAGE (Page 4) - uint8_t current_tuen_reg_list[LED_CURRENT_TUNE_LENGTH] = CKLED2001_CURRENT_TUNE; - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, CURRENT_TUNE_PAGE); - for (int i = 0; i < LED_CURRENT_TUNE_LENGTH; i++) { - ckled2001_write_register(addr, i, current_tuen_reg_list[i]); + uint8_t current_tune_reg_list[CKLED2001_LED_CURRENT_TUNE_LENGTH] = CKLED2001_CURRENT_TUNE; + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_CURRENT_TUNE_PAGE); + for (int i = 0; i < CKLED2001_LED_CURRENT_TUNE_LENGTH; i++) { + ckled2001_write_register(addr, i, current_tune_reg_list[i]); } // Enable LEDs ON/OFF - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE); - for (int i = 0; i < LED_CONTROL_ON_OFF_LENGTH; i++) { + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_LED_CONTROL_PAGE); + for (int i = 0; i < CKLED2001_LED_CONTROL_ON_OFF_LENGTH; i++) { ckled2001_write_register(addr, i, 0xFF); } // Select to function page - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_FUNCTION_PAGE); // Setting LED driver to normal mode - ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_NORMAL_MODE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURATION, CKLED2001_MSKSW_NORMAL_MODE); } void ckled2001_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { @@ -198,7 +197,7 @@ void ckled2001_set_led_control_register(uint8_t index, bool red, bool green, boo void ckled2001_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_PWM_PAGE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_LED_PWM_PAGE); // If any of the transactions fail we risk writing dirty PG0, // refresh page 0 just in case. @@ -211,7 +210,7 @@ void ckled2001_update_pwm_buffers(uint8_t addr, uint8_t index) { void ckled2001_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_led_control_registers_update_required[index]) { - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_LED_CONTROL_PAGE); for (int i = 0; i < 24; i++) { ckled2001_write_register(addr, i, g_led_control_registers[index][i]); } @@ -221,16 +220,16 @@ void ckled2001_update_led_control_registers(uint8_t addr, uint8_t index) { void ckled2001_sw_return_normal(uint8_t addr) { // Select to function page - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_FUNCTION_PAGE); // Setting LED driver to normal mode - ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_NORMAL_MODE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURATION, CKLED2001_MSKSW_NORMAL_MODE); } void ckled2001_sw_shutdown(uint8_t addr) { // Select to function page - ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_FUNCTION_PAGE); // Setting LED driver to shutdown mode - ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_SHUT_DOWN_MODE); + ckled2001_write_register(addr, CKLED2001_REG_CONFIGURATION, CKLED2001_MSKSW_SHUT_DOWN_MODE); // Write SW Sleep Register - ckled2001_write_register(addr, SOFTWARE_SLEEP_REG, MSKSLEEP_ENABLE); + ckled2001_write_register(addr, CKLED2001_REG_SOFTWARE_SLEEP, CKLED2001_MSKSLEEP_ENABLE); } diff --git a/drivers/led/ckled2001.h b/drivers/led/ckled2001.h index 32da137fb7..bfd70f7173 100644 --- a/drivers/led/ckled2001.h +++ b/drivers/led/ckled2001.h @@ -20,6 +20,34 @@ #include <stdbool.h> #include "progmem.h" +// ======== DEPRECATED DEFINES - DO NOT USE ======== +#ifdef DRIVER_COUNT +# define CKLED2001_DRIVER_COUNT DRIVER_COUNT +#endif +#ifdef CKLED2001_TIMEOUT +# define CKLED2001_I2C_TIMEOUT CKLED2001_TIMEOUT +#endif +#ifdef CKLED2001_PERSISTENCE +# define CKLED2001_I2C_PERSISTENCE CKLED2001_PERSISTENCE +#endif +#ifdef PHASE_CHANNEL +# define CKLED2001_PHASE_CHANNEL PHASE_CHANNEL +#endif + +#define MSKPHASE_12CHANNEL CKLED2001_MSKPHASE_12CHANNEL +#define MSKPHASE_11CHANNEL CKLED2001_MSKPHASE_11CHANNEL +#define MSKPHASE_10CHANNEL CKLED2001_MSKPHASE_10CHANNEL +#define MSKPHASE_9CHANNEL CKLED2001_MSKPHASE_9CHANNEL +#define MSKPHASE_8CHANNEL CKLED2001_MSKPHASE_8CHANNEL +#define MSKPHASE_7CHANNEL CKLED2001_MSKPHASE_7CHANNEL +#define MSKPHASE_6CHANNEL CKLED2001_MSKPHASE_6CHANNEL +#define MSKPHASE_5CHANNEL CKLED2001_MSKPHASE_5CHANNEL +#define MSKPHASE_4CHANNEL CKLED2001_MSKPHASE_4CHANNEL +#define MSKPHASE_3CHANNEL CKLED2001_MSKPHASE_3CHANNEL +#define MSKPHASE_2CHANNEL CKLED2001_MSKPHASE_2CHANNEL +#define MSKPHASE_1CHANNEL CKLED2001_MSKPHASE_1CHANNEL +// ======== + typedef struct ckled2001_led { uint8_t driver : 2; uint8_t r; @@ -49,90 +77,90 @@ void ckled2001_sw_return_normal(uint8_t addr); void ckled2001_sw_shutdown(uint8_t addr); // Registers Page Define -#define CONFIGURE_CMD_PAGE 0xFD -#define LED_CONTROL_PAGE 0x00 -#define LED_PWM_PAGE 0x01 -#define FUNCTION_PAGE 0x03 -#define CURRENT_TUNE_PAGE 0x04 +#define CKLED2001_REG_CONFIGURE_CMD_PAGE 0xFD +#define CKLED2001_LED_CONTROL_PAGE 0x00 +#define CKLED2001_LED_PWM_PAGE 0x01 +#define CKLED2001_FUNCTION_PAGE 0x03 +#define CKLED2001_CURRENT_TUNE_PAGE 0x04 // Function Register: address 0x00 -#define CONFIGURATION_REG 0x00 -#define MSKSW_SHUT_DOWN_MODE (0x0 << 0) -#define MSKSW_NORMAL_MODE (0x1 << 0) - -#define DRIVER_ID_REG 0x11 -#define CKLED2001_ID 0x8A - -#define PDU_REG 0x13 -#define MSKSET_CA_CB_CHANNEL 0xAA -#define MSKCLR_CA_CB_CHANNEL 0x00 - -#define SCAN_PHASE_REG 0x14 -#define MSKPHASE_12CHANNEL 0x00 -#define MSKPHASE_11CHANNEL 0x01 -#define MSKPHASE_10CHANNEL 0x02 -#define MSKPHASE_9CHANNEL 0x03 -#define MSKPHASE_8CHANNEL 0x04 -#define MSKPHASE_7CHANNEL 0x05 -#define MSKPHASE_6CHANNEL 0x06 -#define MSKPHASE_5CHANNEL 0x07 -#define MSKPHASE_4CHANNEL 0x08 -#define MSKPHASE_3CHANNEL 0x09 -#define MSKPHASE_2CHANNEL 0x0A -#define MSKPHASE_1CHANNEL 0x0B - -#define SLEW_RATE_CONTROL_MODE1_REG 0x15 -#define MSKPWM_DELAY_PHASE_ENABLE 0x04 -#define MSKPWM_DELAY_PHASE_DISABLE 0x00 - -#define SLEW_RATE_CONTROL_MODE2_REG 0x16 -#define MSKDRIVING_SINKING_CHHANNEL_SLEWRATE_ENABLE 0xC0 -#define MSKDRIVING_SINKING_CHHANNEL_SLEWRATE_DISABLE 0x00 - -#define OPEN_SHORT_ENABLE_REG 0x17 -#define MSKOPEN_DETECTION_ENABLE (0x01 << 7) -#define MSKOPEN_DETECTION_DISABLE (0x00) - -#define MSKSHORT_DETECTION_ENABLE (0x01 << 6) -#define MSKSHORT_DETECTION_DISABLE (0x00) - -#define OPEN_SHORT_DUTY_REG 0x18 -#define OPEN_SHORT_FLAG_REG 0x19 - -#define MSKOPEN_DETECTION_INTERRUPT_ENABLE (0x01 << 7) -#define MSKOPEN_DETECTION_INTERRUPT_DISABLE (0x00) - -#define MSKSHORT_DETECTION_INTERRUPT_ENABLE (0x01 << 6) -#define MSKSHORT_DETECTION_INTERRUPT_DISABLE (0x00) - -#define SOFTWARE_SLEEP_REG 0x1A -#define MSKSLEEP_ENABLE 0x02 -#define MSKSLEEP_DISABLE 0x00 +#define CKLED2001_REG_CONFIGURATION 0x00 +#define CKLED2001_MSKSW_SHUT_DOWN_MODE (0x0 << 0) +#define CKLED2001_MSKSW_NORMAL_MODE (0x1 << 0) + +#define CKLED2001_REG_DRIVER_ID 0x11 +#define CKLED2001_DRIVER_ID 0x8A + +#define CKLED2001_REG_PDU 0x13 +#define CKLED2001_MSKSET_CA_CB_CHANNEL 0xAA +#define CKLED2001_MSKCLR_CA_CB_CHANNEL 0x00 + +#define CKLED2001_REG_SCAN_PHASE 0x14 +#define CKLED2001_MSKPHASE_12CHANNEL 0x00 +#define CKLED2001_MSKPHASE_11CHANNEL 0x01 +#define CKLED2001_MSKPHASE_10CHANNEL 0x02 +#define CKLED2001_MSKPHASE_9CHANNEL 0x03 +#define CKLED2001_MSKPHASE_8CHANNEL 0x04 +#define CKLED2001_MSKPHASE_7CHANNEL 0x05 +#define CKLED2001_MSKPHASE_6CHANNEL 0x06 +#define CKLED2001_MSKPHASE_5CHANNEL 0x07 +#define CKLED2001_MSKPHASE_4CHANNEL 0x08 +#define CKLED2001_MSKPHASE_3CHANNEL 0x09 +#define CKLED2001_MSKPHASE_2CHANNEL 0x0A +#define CKLED2001_MSKPHASE_1CHANNEL 0x0B + +#define CKLED2001_REG_SLEW_RATE_CONTROL_MODE1 0x15 +#define CKLED2001_MSKPWM_DELAY_PHASE_ENABLE 0x04 +#define CKLED2001_MSKPWM_DELAY_PHASE_DISABLE 0x00 + +#define CKLED2001_REG_SLEW_RATE_CONTROL_MODE2 0x16 +#define CKLED2001_MSKDRIVING_SINKING_CHANNEL_SLEWRATE_ENABLE 0xC0 +#define CKLED2001_MSKDRIVING_SINKING_CHANNEL_SLEWRATE_DISABLE 0x00 + +#define CKLED2001_REG_OPEN_SHORT_ENABLE 0x17 +#define CKLED2001_MSKOPEN_DETECTION_ENABLE (0x01 << 7) +#define CKLED2001_MSKOPEN_DETECTION_DISABLE (0x00) + +#define CKLED2001_MSKSHORT_DETECTION_ENABLE (0x01 << 6) +#define CKLED2001_MSKSHORT_DETECTION_DISABLE (0x00) + +#define CKLED2001_REG_OPEN_SHORT_DUTY 0x18 +#define CKLED2001_REG_OPEN_SHORT_FLAG 0x19 + +#define CKLED2001_MSKOPEN_DETECTION_INTERRUPT_ENABLE (0x01 << 7) +#define CKLED2001_MSKOPEN_DETECTION_INTERRUPT_DISABLE (0x00) + +#define CKLED2001_MSKSHORT_DETECTION_INTERRUPT_ENABLE (0x01 << 6) +#define CKLED2001_MSKSHORT_DETECTION_INTERRUPT_DISABLE (0x00) + +#define CKLED2001_REG_SOFTWARE_SLEEP 0x1A +#define CKLED2001_MSKSLEEP_ENABLE 0x02 +#define CKLED2001_MSKSLEEP_DISABLE 0x00 // LED Control Registers -#define LED_CONTROL_ON_OFF_FIRST_ADDR 0x0 -#define LED_CONTROL_ON_OFF_LAST_ADDR 0x17 -#define LED_CONTROL_ON_OFF_LENGTH ((LED_CONTROL_ON_OFF_LAST_ADDR - LED_CONTROL_ON_OFF_FIRST_ADDR) + 1) +#define CKLED2001_LED_CONTROL_ON_OFF_FIRST_ADDR 0x0 +#define CKLED2001_LED_CONTROL_ON_OFF_LAST_ADDR 0x17 +#define CKLED2001_LED_CONTROL_ON_OFF_LENGTH ((CKLED2001_LED_CONTROL_ON_OFF_LAST_ADDR - CKLED2001_LED_CONTROL_ON_OFF_FIRST_ADDR) + 1) -#define LED_CONTROL_OPEN_FIRST_ADDR 0x18 -#define LED_CONTROL_OPEN_LAST_ADDR 0x2F -#define LED_CONTROL_OPEN_LENGTH ((LED_CONTROL_OPEN_LAST_ADDR - LED_CONTROL_OPEN_FIRST_ADDR) + 1) +#define CKLED2001_LED_CONTROL_OPEN_FIRST_ADDR 0x18 +#define CKLED2001_LED_CONTROL_OPEN_LAST_ADDR 0x2F +#define CKLED2001_LED_CONTROL_OPEN_LENGTH ((CKLED2001_LED_CONTROL_OPEN_LAST_ADDR - CKLED2001_LED_CONTROL_OPEN_FIRST_ADDR) + 1) -#define LED_CONTROL_SHORT_FIRST_ADDR 0x30 -#define LED_CONTROL_SHORT_LAST_ADDR 0x47 -#define LED_CONTROL_SHORT_LENGTH ((LED_CONTROL_SHORT_LAST_ADDR - LED_CONTROL_SHORT_FIRST_ADDR) + 1) +#define CKLED2001_LED_CONTROL_SHORT_FIRST_ADDR 0x30 +#define CKLED2001_LED_CONTROL_SHORT_LAST_ADDR 0x47 +#define CKLED2001_LED_CONTROL_SHORT_LENGTH ((CKLED2001_LED_CONTROL_SHORT_LAST_ADDR - CKLED2001_LED_CONTROL_SHORT_FIRST_ADDR) + 1) -#define LED_CONTROL_PAGE_LENGTH 0x48 +#define CKLED2001_LED_CONTROL_PAGE_LENGTH 0x48 // LED Control Registers -#define LED_PWM_FIRST_ADDR 0x00 -#define LED_PWM_LAST_ADDR 0xBF -#define LED_PWM_LENGTH 0xC0 +#define CKLED2001_LED_PWM_FIRST_ADDR 0x00 +#define CKLED2001_LED_PWM_LAST_ADDR 0xBF +#define CKLED2001_LED_PWM_LENGTH 0xC0 // Current Tune Registers -#define LED_CURRENT_TUNE_FIRST_ADDR 0x00 -#define LED_CURRENT_TUNE_LAST_ADDR 0x0B -#define LED_CURRENT_TUNE_LENGTH 0x0C +#define CKLED2001_LED_CURRENT_TUNE_FIRST_ADDR 0x00 +#define CKLED2001_LED_CURRENT_TUNE_LAST_ADDR 0x0B +#define CKLED2001_LED_CURRENT_TUNE_LENGTH 0x0C #define A_1 0x00 #define A_2 0x01 @@ -336,4 +364,4 @@ void ckled2001_sw_shutdown(uint8_t addr); #define L_13 0xBC #define L_14 0xBD #define L_15 0xBE -#define L_16 0xBF
\ No newline at end of file +#define L_16 0xBF diff --git a/drivers/led/issi/is31fl3218.c b/drivers/led/issi/is31fl3218.c index 970e9a0be9..6072f6cecd 100644 --- a/drivers/led/issi/is31fl3218.c +++ b/drivers/led/issi/is31fl3218.c @@ -17,17 +17,17 @@ #include "i2c_master.h" // This is the full 8-bit address -#define ISSI_ADDRESS 0b10101000 +#define IS31FL3218_I2C_ADDRESS 0xA8 // These are the register addresses -#define ISSI_REG_SHUTDOWN 0x00 -#define ISSI_REG_PWM 0x01 -#define ISSI_REG_CONTROL 0x13 -#define ISSI_REG_UPDATE 0x16 -#define ISSI_REG_RESET 0x17 +#define IS31FL3218_REG_SHUTDOWN 0x00 +#define IS31FL3218_REG_PWM 0x01 +#define IS31FL3218_REG_CONTROL 0x13 +#define IS31FL3218_REG_UPDATE 0x16 +#define IS31FL3218_REG_RESET 0x17 // Default timeout if no I2C response -#define ISSI_TIMEOUT 100 +#define IS31FL3218_I2C_TIMEOUT 100 // Reusable buffer for transfers uint8_t g_twi_transfer_buffer[20]; @@ -40,35 +40,35 @@ bool g_pwm_buffer_update_required = false; void is31fl3218_write_register(uint8_t reg, uint8_t data) { g_twi_transfer_buffer[0] = reg; g_twi_transfer_buffer[1] = data; - i2c_transmit(ISSI_ADDRESS, g_twi_transfer_buffer, 2, ISSI_TIMEOUT); + i2c_transmit(IS31FL3218_I2C_ADDRESS, g_twi_transfer_buffer, 2, IS31FL3218_I2C_TIMEOUT); } void is31fl3218_write_pwm_buffer(uint8_t *pwm_buffer) { - g_twi_transfer_buffer[0] = ISSI_REG_PWM; + g_twi_transfer_buffer[0] = IS31FL3218_REG_PWM; memcpy(g_twi_transfer_buffer + 1, pwm_buffer, 18); - i2c_transmit(ISSI_ADDRESS, g_twi_transfer_buffer, 19, ISSI_TIMEOUT); + i2c_transmit(IS31FL3218_I2C_ADDRESS, g_twi_transfer_buffer, 19, IS31FL3218_I2C_TIMEOUT); } void is31fl3218_init(void) { // In case we ever want to reinitialize (?) - is31fl3218_write_register(ISSI_REG_RESET, 0x00); + is31fl3218_write_register(IS31FL3218_REG_RESET, 0x00); // Turn off software shutdown - is31fl3218_write_register(ISSI_REG_SHUTDOWN, 0x01); + is31fl3218_write_register(IS31FL3218_REG_SHUTDOWN, 0x01); // Set all PWM values to zero for (uint8_t i = 0; i < 18; i++) { - is31fl3218_write_register(ISSI_REG_PWM + i, 0x00); + is31fl3218_write_register(IS31FL3218_REG_PWM + i, 0x00); } // Enable all channels for (uint8_t i = 0; i < 3; i++) { - is31fl3218_write_register(ISSI_REG_CONTROL + i, 0b00111111); + is31fl3218_write_register(IS31FL3218_REG_CONTROL + i, 0b00111111); } // Load PWM registers and LED Control register data - is31fl3218_write_register(ISSI_REG_UPDATE, 0x01); + is31fl3218_write_register(IS31FL3218_REG_UPDATE, 0x01); } void is31fl3218_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { @@ -91,7 +91,7 @@ void is31fl3218_update_pwm_buffers(void) { if (g_pwm_buffer_update_required) { is31fl3218_write_pwm_buffer(g_pwm_buffer); // Load PWM registers and LED Control register data - is31fl3218_write_register(ISSI_REG_UPDATE, 0x01); + is31fl3218_write_register(IS31FL3218_REG_UPDATE, 0x01); } g_pwm_buffer_update_required = false; } diff --git a/drivers/led/issi/is31fl3731-simple.c b/drivers/led/issi/is31fl3731-simple.c index f7f6980a3b..6b463d3092 100644 --- a/drivers/led/issi/is31fl3731-simple.c +++ b/drivers/led/issi/is31fl3731-simple.c @@ -18,6 +18,7 @@ */ #include "is31fl3731-simple.h" +#include <string.h> #include "i2c_master.h" #include "wait.h" @@ -28,34 +29,34 @@ // 0b1110111 AD <-> VCC // 0b1110101 AD <-> SCL // 0b1110110 AD <-> SDA -#define ISSI_ADDR_DEFAULT 0x74 +#define IS31FL3731_I2C_ADDRESS_DEFAULT 0x74 -#define ISSI_REG_CONFIG 0x00 -#define ISSI_REG_CONFIG_PICTUREMODE 0x00 -#define ISSI_REG_CONFIG_AUTOPLAYMODE 0x08 -#define ISSI_REG_CONFIG_AUDIOPLAYMODE 0x18 +#define IS31FL3731_REG_CONFIG 0x00 +#define IS31FL3731_REG_CONFIG_PICTUREMODE 0x00 +#define IS31FL3731_REG_CONFIG_AUTOPLAYMODE 0x08 +#define IS31FL3731_REG_CONFIG_AUDIOPLAYMODE 0x18 -#define ISSI_CONF_PICTUREMODE 0x00 -#define ISSI_CONF_AUTOFRAMEMODE 0x04 -#define ISSI_CONF_AUDIOMODE 0x08 +#define IS31FL3731_CONF_PICTUREMODE 0x00 +#define IS31FL3731_CONF_AUTOFRAMEMODE 0x04 +#define IS31FL3731_CONF_AUDIOMODE 0x08 -#define ISSI_REG_PICTUREFRAME 0x01 +#define IS31FL3731_REG_PICTUREFRAME 0x01 // Not defined in the datasheet -- See AN for IC -#define ISSI_REG_GHOST_IMAGE_PREVENTION 0xC2 // Set bit 4 to enable de-ghosting +#define IS31FL3731_REG_GHOST_IMAGE_PREVENTION 0xC2 // Set bit 4 to enable de-ghosting -#define ISSI_REG_SHUTDOWN 0x0A -#define ISSI_REG_AUDIOSYNC 0x06 +#define IS31FL3731_REG_SHUTDOWN 0x0A +#define IS31FL3731_REG_AUDIOSYNC 0x06 -#define ISSI_COMMANDREGISTER 0xFD -#define ISSI_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine' +#define IS31FL3731_COMMANDREGISTER 0xFD +#define IS31FL3731_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine' -#ifndef ISSI_TIMEOUT -# define ISSI_TIMEOUT 100 +#ifndef IS31FL3731_I2C_TIMEOUT +# define IS31FL3731_I2C_TIMEOUT 100 #endif -#ifndef ISSI_PERSISTENCE -# define ISSI_PERSISTENCE 0 +#ifndef IS31FL3731_I2C_PERSISTENCE +# define IS31FL3731_I2C_PERSISTENCE 0 #endif // Transfer buffer for TWITransmitData() @@ -66,20 +67,20 @@ uint8_t g_twi_transfer_buffer[20]; // We could optimize this and take out the unused registers from these // buffers and the transfers in is31fl3731_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[LED_DRIVER_COUNT][144]; -bool g_pwm_buffer_update_required[LED_DRIVER_COUNT] = {false}; +uint8_t g_pwm_buffer[IS31FL3731_DRIVER_COUNT][144]; +bool g_pwm_buffer_update_required[IS31FL3731_DRIVER_COUNT] = {false}; /* There's probably a better way to init this... */ -#if LED_DRIVER_COUNT == 1 -uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}}; -#elif LED_DRIVER_COUNT == 2 -uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}, {0}}; -#elif LED_DRIVER_COUNT == 3 -uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}, {0}, {0}}; -#elif LED_DRIVER_COUNT == 4 -uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}, {0}, {0}, {0}}; +#if IS31FL3731_DRIVER_COUNT == 1 +uint8_t g_led_control_registers[IS31FL3731_DRIVER_COUNT][18] = {{0}}; +#elif IS31FL3731_DRIVER_COUNT == 2 +uint8_t g_led_control_registers[IS31FL3731_DRIVER_COUNT][18] = {{0}, {0}}; +#elif IS31FL3731_DRIVER_COUNT == 3 +uint8_t g_led_control_registers[IS31FL3731_DRIVER_COUNT][18] = {{0}, {0}, {0}}; +#elif IS31FL3731_DRIVER_COUNT == 4 +uint8_t g_led_control_registers[IS31FL3731_DRIVER_COUNT][18] = {{0}, {0}, {0}, {0}}; #endif -bool g_led_control_registers_update_required[LED_DRIVER_COUNT] = {false}; +bool g_led_control_registers_update_required[IS31FL3731_DRIVER_COUNT] = {false}; // This is the bit pattern in the LED control registers // (for matrix A, add one to register for matrix B) @@ -99,14 +100,14 @@ void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) { 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) { +#if IS31FL3731_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3731_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3731_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, IS31FL3731_I2C_TIMEOUT); #endif } @@ -125,12 +126,12 @@ void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // thus this sets registers 0x24-0x33, 0x34-0x43, etc. in one transfer memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16); -#if ISSI_PERSISTENCE > 0 - for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0) break; +#if IS31FL3731_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3731_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3731_I2C_TIMEOUT) == 0) break; } #else - i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT); + i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3731_I2C_TIMEOUT); #endif } } @@ -142,26 +143,26 @@ void is31fl3731_init(uint8_t addr) { // then disable software shutdown. // select "function register" bank - is31fl3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG); + is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, IS31FL3731_BANK_FUNCTIONREG); // enable software shutdown - is31fl3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x00); -#ifdef ISSI_3731_DEGHOST // set to enable de-ghosting of the array - is31fl3731_write_register(addr, ISSI_REG_GHOST_IMAGE_PREVENTION, 0x10); + is31fl3731_write_register(addr, IS31FL3731_REG_SHUTDOWN, 0x00); +#ifdef IS31FL3731_DEGHOST // set to enable de-ghosting of the array + is31fl3731_write_register(addr, IS31FL3731_REG_GHOST_IMAGE_PREVENTION, 0x10); #endif // this delay was copied from other drivers, might not be needed wait_ms(10); // picture mode - is31fl3731_write_register(addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE); + is31fl3731_write_register(addr, IS31FL3731_REG_CONFIG, IS31FL3731_REG_CONFIG_PICTUREMODE); // display frame 0 - is31fl3731_write_register(addr, ISSI_REG_PICTUREFRAME, 0x00); + is31fl3731_write_register(addr, IS31FL3731_REG_PICTUREFRAME, 0x00); // audio sync off - is31fl3731_write_register(addr, ISSI_REG_AUDIOSYNC, 0x00); + is31fl3731_write_register(addr, IS31FL3731_REG_AUDIOSYNC, 0x00); // select bank 0 - is31fl3731_write_register(addr, ISSI_COMMANDREGISTER, 0); + is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, 0); // turn off all LEDs in the LED control register for (int i = 0x00; i <= 0x11; i++) { @@ -179,15 +180,15 @@ void is31fl3731_init(uint8_t addr) { } // select "function register" bank - is31fl3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG); + is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, IS31FL3731_BANK_FUNCTIONREG); // disable software shutdown - is31fl3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x01); + is31fl3731_write_register(addr, IS31FL3731_REG_SHUTDOWN, 0x01); // select bank 0 and leave it selected. // most usage after initialization is just writing PWM buffers in bank 0 // as there's not much point in double-buffering - is31fl3731_write_register(addr, ISSI_COMMANDREGISTER, 0); + is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, 0); } void is31fl3731_set_value(int index, uint8_t value) { diff --git a/drivers/led/issi/is31fl3731-simple.h b/drivers/led/issi/is31fl3731-simple.h index 69fba14a0b..ee830faca8 100644 --- a/drivers/led/issi/is31fl3731-simple.h +++ b/drivers/led/issi/is31fl3731-simple.h @@ -20,9 +20,23 @@ #include <stdint.h> #include <stdbool.h> -#include <string.h> #include "progmem.h" +// ======== DEPRECATED DEFINES - DO NOT USE ======== +#ifdef LED_DRIVER_COUNT +# define IS31FL3731_DRIVER_COUNT LED_DRIVER_COUNT +#endif +#ifdef ISSI_TIMEOUT +# define IS31FL3731_I2C_TIMEOUT ISSI_TIMEOUT +#endif +#ifdef ISSI_PERSISTENCE +# define IS31FL3731_I2C_PERSISTENCE ISSI_PERSISTENCE +#endif +#ifdef ISSI_3731_DEGHOST +# define IS31FL3731_DEGHOST ISSI_3731_DEGHOST +#endif +// ======== + typedef struct is31_led { uint8_t driver : 2; uint8_t v; diff --git a/drivers/led/issi/is31fl3731.c b/drivers/led/issi/is31fl3731.c index 15a01b6d75..9e2d39c692 100644 --- a/drivers/led/issi/is31fl3731.c +++ b/drivers/led/issi/is31fl3731.c @@ -17,6 +17,7 @@ */ #include "is31fl3731.h" +#include <string.h> #include "i2c_master.h" #include "wait.h" @@ -27,34 +28,34 @@ // 0b1110111 AD <-> VCC // 0b1110101 AD <-> SCL // 0b1110110 AD <-> SDA -#define ISSI_ADDR_DEFAULT 0x74 +#define IS31FL3731_I2C_ADDRESS_DEFAULT 0x74 -#define ISSI_REG_CONFIG 0x00 -#define ISSI_REG_CONFIG_PICTUREMODE 0x00 -#define ISSI_REG_CONFIG_AUTOPLAYMODE 0x08 -#define ISSI_REG_CONFIG_AUDIOPLAYMODE 0x18 +#define IS31FL3731_REG_CONFIG 0x00 +#define IS31FL3731_REG_CONFIG_PICTUREMODE 0x00 +#define IS31FL3731_REG_CONFIG_AUTOPLAYMODE 0x08 +#define IS31FL3731_REG_CONFIG_AUDIOPLAYMODE 0x18 -#define ISSI_CONF_PICTUREMODE 0x00 -#define ISSI_CONF_AUTOFRAMEMODE 0x04 -#define ISSI_CONF_AUDIOMODE 0x08 +#define IS31FL3731_CONF_PICTUREMODE 0x00 +#define IS31FL3731_CONF_AUTOFRAMEMODE 0x04 +#define IS31FL3731_CONF_AUDIOMODE 0x08 -#define ISSI_REG_PICTUREFRAME 0x01 +#define IS31FL3731_REG_PICTUREFRAME 0x01 // Not defined in the datasheet -- See AN for IC -#define ISSI_REG_GHOST_IMAGE_PREVENTION 0xC2 // Set bit 4 to enable de-ghosting +#define IS31FL3731_REG_GHOST_IMAGE_PREVENTION 0xC2 // Set bit 4 to enable de-ghosting -#define ISSI_REG_SHUTDOWN 0x0A -#define ISSI_REG_AUDIOSYNC 0x06 +#define IS31FL3731_REG_SHUTDOWN 0x0A +#define IS31FL3731_REG_AUDIOSYNC 0x06 -#define ISSI_COMMANDREGISTER 0xFD -#define ISSI_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine' +#define IS31FL3731_COMMANDREGISTER 0xFD +#define IS31FL3731_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine' -#ifndef ISSI_TIMEOUT -# define ISSI_TIMEOUT 100 +#ifndef IS31FL3731_I2C_TIMEOUT +# define IS31FL3731_I2C_TIMEOUT 100 #endif -#ifndef ISSI_PERSISTENCE -# define ISSI_PERSISTENCE 0 +#ifndef IS31FL3731_I2C_PERSISTENCE +# define IS31FL3731_I2C_PERSISTENCE 0 #endif // Transfer buffer for TWITransmitData() @@ -65,11 +66,11 @@ uint8_t g_twi_transfer_buffer[20]; // We could optimize this and take out the unused registers from these // buffers and the transfers in is31fl3731_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[DRIVER_COUNT][144]; -bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; +uint8_t g_pwm_buffer[IS31FL3731_DRIVER_COUNT][144]; +bool g_pwm_buffer_update_required[IS31FL3731_DRIVER_COUNT] = {false}; -uint8_t g_led_control_registers[DRIVER_COUNT][18] = {{0}}; -bool g_led_control_registers_update_required[DRIVER_COUNT] = {false}; +uint8_t g_led_control_registers[IS31FL3731_DRIVER_COUNT][18] = {{0}}; +bool g_led_control_registers_update_required[IS31FL3731_DRIVER_COUNT] = {false}; // This is the bit pattern in the LED control registers // (for matrix A, add one to register for matrix B) @@ -89,12 +90,12 @@ void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) { 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 IS31FL3731_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3731_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3731_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, IS31FL3731_I2C_TIMEOUT); #endif } @@ -113,12 +114,12 @@ void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // thus this sets registers 0x24-0x33, 0x34-0x43, etc. in one transfer memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16); -#if ISSI_PERSISTENCE > 0 - for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0) break; +#if IS31FL3731_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3731_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3731_I2C_TIMEOUT) == 0) break; } #else - i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT); + i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3731_I2C_TIMEOUT); #endif } } @@ -130,26 +131,26 @@ void is31fl3731_init(uint8_t addr) { // then disable software shutdown. // select "function register" bank - is31fl3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG); + is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, IS31FL3731_BANK_FUNCTIONREG); // enable software shutdown - is31fl3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x00); -#ifdef ISSI_3731_DEGHOST // set to enable de-ghosting of the array - is31fl3731_write_register(addr, ISSI_REG_GHOST_IMAGE_PREVENTION, 0x10); + is31fl3731_write_register(addr, IS31FL3731_REG_SHUTDOWN, 0x00); +#ifdef IS31FL3731_DEGHOST // set to enable de-ghosting of the array + is31fl3731_write_register(addr, IS31FL3731_REG_GHOST_IMAGE_PREVENTION, 0x10); #endif // this delay was copied from other drivers, might not be needed wait_ms(10); // picture mode - is31fl3731_write_register(addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE); + is31fl3731_write_register(addr, IS31FL3731_REG_CONFIG, IS31FL3731_REG_CONFIG_PICTUREMODE); // display frame 0 - is31fl3731_write_register(addr, ISSI_REG_PICTUREFRAME, 0x00); + is31fl3731_write_register(addr, IS31FL3731_REG_PICTUREFRAME, 0x00); // audio sync off - is31fl3731_write_register(addr, ISSI_REG_AUDIOSYNC, 0x00); + is31fl3731_write_register(addr, IS31FL3731_REG_AUDIOSYNC, 0x00); // select bank 0 - is31fl3731_write_register(addr, ISSI_COMMANDREGISTER, 0); + is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, 0); // turn off all LEDs in the LED control register for (int i = 0x00; i <= 0x11; i++) { @@ -167,15 +168,15 @@ void is31fl3731_init(uint8_t addr) { } // select "function register" bank - is31fl3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG); + is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, IS31FL3731_BANK_FUNCTIONREG); // disable software shutdown - is31fl3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x01); + is31fl3731_write_register(addr, IS31FL3731_REG_SHUTDOWN, 0x01); // select bank 0 and leave it selected. // most usage after initialization is just writing PWM buffers in bank 0 // as there's not much point in double-buffering - is31fl3731_write_register(addr, ISSI_COMMANDREGISTER, 0); + is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, 0); } void is31fl3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { diff --git a/drivers/led/issi/is31fl3731.h b/drivers/led/issi/is31fl3731.h index bdf03de1ee..97e3f454df 100644 --- a/drivers/led/issi/is31fl3731.h +++ b/drivers/led/issi/is31fl3731.h @@ -19,9 +19,23 @@ #include <stdint.h> #include <stdbool.h> -#include <string.h> #include "progmem.h" +// ======== DEPRECATED DEFINES - DO NOT USE ======== +#ifdef DRIVER_COUNT +# define IS31FL3731_DRIVER_COUNT DRIVER_COUNT +#endif +#ifdef ISSI_TIMEOUT +# define IS31FL3731_I2C_TIMEOUT ISSI_TIMEOUT +#endif +#ifdef ISSI_PERSISTENCE +# define IS31FL3731_I2C_PERSISTENCE ISSI_PERSISTENCE +#endif +#ifdef ISSI_3731_DEGHOST +# define IS31FL3731_DEGHOST ISSI_3731_DEGHOST +#endif +// ======== + typedef struct is31_led { uint8_t driver : 2; uint8_t r; diff --git a/drivers/led/issi/is31fl3733-simple.c b/drivers/led/issi/is31fl3733-simple.c index f9a0a271a8..c52e1ff9f1 100644 --- a/drivers/led/issi/is31fl3733-simple.c +++ b/drivers/led/issi/is31fl3733-simple.c @@ -19,6 +19,7 @@ */ #include "is31fl3733-simple.h" +#include <string.h> #include "i2c_master.h" #include "wait.h" @@ -32,46 +33,46 @@ // ADDR1 represents A1:A0 of the 7-bit address. // ADDR2 represents A3:A2 of the 7-bit address. // The result is: 0b101(ADDR2)(ADDR1) -#define ISSI_ADDR_DEFAULT 0x50 - -#define ISSI_COMMANDREGISTER 0xFD -#define ISSI_COMMANDREGISTER_WRITELOCK 0xFE -#define ISSI_INTERRUPTMASKREGISTER 0xF0 -#define ISSI_INTERRUPTSTATUSREGISTER 0xF1 - -#define ISSI_PAGE_LEDCONTROL 0x00 // PG0 -#define ISSI_PAGE_PWM 0x01 // PG1 -#define ISSI_PAGE_AUTOBREATH 0x02 // PG2 -#define ISSI_PAGE_FUNCTION 0x03 // PG3 - -#define ISSI_REG_CONFIGURATION 0x00 // PG3 -#define ISSI_REG_GLOBALCURRENT 0x01 // PG3 -#define ISSI_REG_RESET 0x11 // PG3 -#define ISSI_REG_SWPULLUP 0x0F // PG3 -#define ISSI_REG_CSPULLUP 0x10 // PG3 - -#ifndef ISSI_TIMEOUT -# define ISSI_TIMEOUT 100 +#define IS31FL3733_I2C_ADDRESS_DEFAULT 0x50 + +#define IS31FL3733_COMMANDREGISTER 0xFD +#define IS31FL3733_COMMANDREGISTER_WRITELOCK 0xFE +#define IS31FL3733_INTERRUPTMASKREGISTER 0xF0 +#define IS31FL3733_INTERRUPTSTATUSREGISTER 0xF1 + +#define IS31FL3733_PAGE_LEDCONTROL 0x00 // PG0 +#define IS31FL3733_PAGE_PWM 0x01 // PG1 +#define IS31FL3733_PAGE_AUTOBREATH 0x02 // PG2 +#define IS31FL3733_PAGE_FUNCTION 0x03 // PG3 + +#define IS31FL3733_REG_CONFIGURATION 0x00 // PG3 +#define IS31FL3733_REG_GLOBALCURRENT 0x01 // PG3 +#define IS31FL3733_REG_RESET 0x11 // PG3 +#define IS31FL3733_REG_SWPULLUP 0x0F // PG3 +#define IS31FL3733_REG_CSPULLUP 0x10 // PG3 + +#ifndef IS31FL3733_I2C_TIMEOUT +# define IS31FL3733_I2C_TIMEOUT 100 #endif -#ifndef ISSI_PERSISTENCE -# define ISSI_PERSISTENCE 0 +#ifndef IS31FL3733_I2C_PERSISTENCE +# define IS31FL3733_I2C_PERSISTENCE 0 #endif -#ifndef ISSI_PWM_FREQUENCY -# define ISSI_PWM_FREQUENCY 0b000 // PFS - IS31FL3733B only +#ifndef IS31FL3733_PWM_FREQUENCY +# define IS31FL3733_PWM_FREQUENCY IS31FL3733_PWM_FREQUENCY_8K4_HZ // PFS - IS31FL3733B only #endif -#ifndef ISSI_SWPULLUP -# define ISSI_SWPULLUP PUR_0R +#ifndef IS31FL3733_SWPULLUP +# define IS31FL3733_SWPULLUP IS31FL3733_PUR_0R #endif -#ifndef ISSI_CSPULLUP -# define ISSI_CSPULLUP PUR_0R +#ifndef IS31FL3733_CSPULLUP +# define IS31FL3733_CSPULLUP IS31FL3733_PUR_0R #endif -#ifndef ISSI_GLOBALCURRENT -# define ISSI_GLOBALCURRENT 0xFF +#ifndef IS31FL3733_GLOBALCURRENT +# define IS31FL3733_GLOBALCURRENT 0xFF #endif // Transfer buffer for TWITransmitData() @@ -83,34 +84,34 @@ uint8_t g_twi_transfer_buffer[20]; // We could optimize this and take out the unused registers from these // buffers and the transfers in is31fl3733_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[LED_DRIVER_COUNT][192]; -bool g_pwm_buffer_update_required[LED_DRIVER_COUNT] = {false}; +uint8_t g_pwm_buffer[IS31FL3733_DRIVER_COUNT][192]; +bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false}; /* There's probably a better way to init this... */ -#if LED_DRIVER_COUNT == 1 -uint8_t g_led_control_registers[LED_DRIVER_COUNT][24] = {{0}}; -#elif LED_DRIVER_COUNT == 2 -uint8_t g_led_control_registers[LED_DRIVER_COUNT][24] = {{0}, {0}}; -#elif LED_DRIVER_COUNT == 3 -uint8_t g_led_control_registers[LED_DRIVER_COUNT][24] = {{0}, {0}, {0}}; -#elif LED_DRIVER_COUNT == 4 -uint8_t g_led_control_registers[LED_DRIVER_COUNT][24] = {{0}, {0}, {0}, {0}}; +#if IS31FL3733_DRIVER_COUNT == 1 +uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][24] = {{0}}; +#elif IS31FL3733_DRIVER_COUNT == 2 +uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][24] = {{0}, {0}}; +#elif IS31FL3733_DRIVER_COUNT == 3 +uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][24] = {{0}, {0}, {0}}; +#elif IS31FL3733_DRIVER_COUNT == 4 +uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][24] = {{0}, {0}, {0}, {0}}; #endif -bool g_led_control_registers_update_required[LED_DRIVER_COUNT] = {false}; +bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT] = {false}; bool is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) { // If the transaction fails function returns false. 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) { +#if IS31FL3733_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) { return false; } #endif @@ -131,14 +132,14 @@ bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // Thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer. memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16); -#if ISSI_PERSISTENCE > 0 - for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) != 0) { +#if IS31FL3733_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) { return false; } #endif @@ -154,20 +155,20 @@ void is31fl3733_init(uint8_t addr, uint8_t sync) { // Sync is passed so set it according to the datasheet. // Unlock the command register. - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG0 - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL); // Turn off all LEDs. for (int i = 0x00; i <= 0x17; i++) { is31fl3733_write_register(addr, i, 0x00); } // Unlock the command register. - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG1 - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_PWM); // Set PWM on all LEDs to 0 // No need to setup Breath registers to PWM as that is the default. for (int i = 0x00; i <= 0xBF; i++) { @@ -175,18 +176,18 @@ void is31fl3733_init(uint8_t addr, uint8_t sync) { } // Unlock the command register. - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG3 - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_FUNCTION); // Set de-ghost pull-up resistors (SWx) - is31fl3733_write_register(addr, ISSI_REG_SWPULLUP, ISSI_SWPULLUP); + is31fl3733_write_register(addr, IS31FL3733_REG_SWPULLUP, IS31FL3733_SWPULLUP); // Set de-ghost pull-down resistors (CSx) - is31fl3733_write_register(addr, ISSI_REG_CSPULLUP, ISSI_CSPULLUP); + is31fl3733_write_register(addr, IS31FL3733_REG_CSPULLUP, IS31FL3733_CSPULLUP); // Set global current to maximum. - is31fl3733_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); + is31fl3733_write_register(addr, IS31FL3733_REG_GLOBALCURRENT, IS31FL3733_GLOBALCURRENT); // Disable software shutdown. - is31fl3733_write_register(addr, ISSI_REG_CONFIGURATION, ((sync & 0b11) << 6) | ((ISSI_PWM_FREQUENCY & 0b111) << 3) | 0x01); + is31fl3733_write_register(addr, IS31FL3733_REG_CONFIGURATION, ((sync & 0b11) << 6) | ((IS31FL3733_PWM_FREQUENCY & 0b111) << 3) | 0x01); // Wait 10ms to ensure the device has woken up. wait_ms(10); @@ -230,8 +231,8 @@ void is31fl3733_set_led_control_register(uint8_t index, bool value) { void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { // Firstly we need to unlock the command register and select PG1. - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_PWM); // If any of the transactions fail we risk writing dirty PG0, // refresh page 0 just in case. @@ -245,8 +246,8 @@ void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index) { void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_led_control_registers_update_required[index]) { // Firstly we need to unlock the command register and select PG0 - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL); for (int i = 0; i < 24; i++) { is31fl3733_write_register(addr, i, g_led_control_registers[index][i]); } diff --git a/drivers/led/issi/is31fl3733-simple.h b/drivers/led/issi/is31fl3733-simple.h index 1458f7ac8d..7e06e2af02 100644 --- a/drivers/led/issi/is31fl3733-simple.h +++ b/drivers/led/issi/is31fl3733-simple.h @@ -22,9 +22,40 @@ #include <stdint.h> #include <stdbool.h> -#include <string.h> #include "progmem.h" +// ======== DEPRECATED DEFINES - DO NOT USE ======== +#ifdef LED_DRIVER_COUNT +# define IS31FL3733_DRIVER_COUNT LED_DRIVER_COUNT +#endif +#ifdef ISSI_TIMEOUT +# define IS31FL3733_I2C_TIMEOUT ISSI_TIMEOUT +#endif +#ifdef ISSI_PERSISTENCE +# define IS31FL3733_I2C_PERSISTENCE ISSI_PERSISTENCE +#endif +#ifdef ISSI_PWM_FREQUENCY +# define IS31FL3733_PWM_FREQUENCY ISSI_PWM_FREQUENCY +#endif +#ifdef ISSI_SWPULLUP +# define IS31FL3733_SWPULLUP ISSI_SWPULLUP +#endif +#ifdef ISSI_CSPULLUP +# define IS31FL3733_CSPULLUP ISSI_CSPULLUP +#endif +#ifdef ISSI_GLOBALCURRENT +# define IS31FL3733_GLOBALCURRENT ISSI_GLOBALCURRENT +#endif + +#define PUR_0R IS31FL3733_PUR_0R +#define PUR_05KR IS31FL3733_PUR_05KR +#define PUR_3KR IS31FL3733_PUR_3KR +#define PUR_4KR IS31FL3733_PUR_4KR +#define PUR_8KR IS31FL3733_PUR_8KR +#define PUR_16KR IS31FL3733_PUR_16KR +#define PUR_32KR IS31FL3733_PUR_32KR +// ======== + typedef struct is31_led { uint8_t driver : 2; uint8_t v; @@ -48,13 +79,19 @@ void is31fl3733_set_led_control_register(uint8_t index, bool value); void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index); void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index); -#define PUR_0R 0x00 // No PUR resistor -#define PUR_05KR 0x02 // 0.5k Ohm resistor in t_NOL -#define PUR_3KR 0x03 // 3.0k Ohm resistor on all the time -#define PUR_4KR 0x04 // 4.0k Ohm resistor on all the time -#define PUR_8KR 0x05 // 8.0k Ohm resistor on all the time -#define PUR_16KR 0x06 // 16k Ohm resistor on all the time -#define PUR_32KR 0x07 // 32k Ohm resistor in t_NOL +#define IS31FL3733_PUR_0R 0x00 // No PUR resistor +#define IS31FL3733_PUR_05KR 0x02 // 0.5k Ohm resistor in t_NOL +#define IS31FL3733_PUR_3KR 0x03 // 3.0k Ohm resistor on all the time +#define IS31FL3733_PUR_4KR 0x04 // 4.0k Ohm resistor on all the time +#define IS31FL3733_PUR_8KR 0x05 // 8.0k Ohm resistor on all the time +#define IS31FL3733_PUR_16KR 0x06 // 16k Ohm resistor on all the time +#define IS31FL3733_PUR_32KR 0x07 // 32k Ohm resistor in t_NOL + +#define IS31FL3733_PWM_FREQUENCY_8K4_HZ 0b000 +#define IS31FL3733_PWM_FREQUENCY_4K2_HZ 0b001 +#define IS31FL3733_PWM_FREQUENCY_26K7_HZ 0b010 +#define IS31FL3733_PWM_FREQUENCY_2K1_HZ 0b011 +#define IS31FL3733_PWM_FREQUENCY_1K05_HZ 0b100 #define A_1 0x00 #define A_2 0x01 diff --git a/drivers/led/issi/is31fl3733.c b/drivers/led/issi/is31fl3733.c index ca431838ef..3ee9b14c81 100644 --- a/drivers/led/issi/is31fl3733.c +++ b/drivers/led/issi/is31fl3733.c @@ -18,6 +18,7 @@ */ #include "is31fl3733.h" +#include <string.h> #include "i2c_master.h" #include "wait.h" @@ -31,46 +32,46 @@ // ADDR1 represents A1:A0 of the 7-bit address. // ADDR2 represents A3:A2 of the 7-bit address. // The result is: 0b101(ADDR2)(ADDR1) -#define ISSI_ADDR_DEFAULT 0x50 - -#define ISSI_COMMANDREGISTER 0xFD -#define ISSI_COMMANDREGISTER_WRITELOCK 0xFE -#define ISSI_INTERRUPTMASKREGISTER 0xF0 -#define ISSI_INTERRUPTSTATUSREGISTER 0xF1 - -#define ISSI_PAGE_LEDCONTROL 0x00 // PG0 -#define ISSI_PAGE_PWM 0x01 // PG1 -#define ISSI_PAGE_AUTOBREATH 0x02 // PG2 -#define ISSI_PAGE_FUNCTION 0x03 // PG3 - -#define ISSI_REG_CONFIGURATION 0x00 // PG3 -#define ISSI_REG_GLOBALCURRENT 0x01 // PG3 -#define ISSI_REG_RESET 0x11 // PG3 -#define ISSI_REG_SWPULLUP 0x0F // PG3 -#define ISSI_REG_CSPULLUP 0x10 // PG3 - -#ifndef ISSI_TIMEOUT -# define ISSI_TIMEOUT 100 +#define IS31FL3733_I2C_ADDRESS_DEFAULT 0x50 + +#define IS31FL3733_COMMANDREGISTER 0xFD +#define IS31FL3733_COMMANDREGISTER_WRITELOCK 0xFE +#define IS31FL3733_INTERRUPTMASKREGISTER 0xF0 +#define IS31FL3733_INTERRUPTSTATUSREGISTER 0xF1 + +#define IS31FL3733_PAGE_LEDCONTROL 0x00 // PG0 +#define IS31FL3733_PAGE_PWM 0x01 // PG1 +#define IS31FL3733_PAGE_AUTOBREATH 0x02 // PG2 +#define IS31FL3733_PAGE_FUNCTION 0x03 // PG3 + +#define IS31FL3733_REG_CONFIGURATION 0x00 // PG3 +#define IS31FL3733_REG_GLOBALCURRENT 0x01 // PG3 +#define IS31FL3733_REG_RESET 0x11 // PG3 +#define IS31FL3733_REG_SWPULLUP 0x0F // PG3 +#define IS31FL3733_REG_CSPULLUP 0x10 // PG3 + +#ifndef IS31FL3733_I2C_TIMEOUT +# define IS31FL3733_I2C_TIMEOUT 100 #endif -#ifndef ISSI_PERSISTENCE -# define ISSI_PERSISTENCE 0 +#ifndef IS31FL3733_I2C_PERSISTENCE +# define IS31FL3733_I2C_PERSISTENCE 0 #endif -#ifndef ISSI_PWM_FREQUENCY -# define ISSI_PWM_FREQUENCY 0b000 // PFS - IS31FL3733B only +#ifndef IS31FL3733_PWM_FREQUENCY +# define IS31FL3733_PWM_FREQUENCY IS31FL3733_PWM_FREQUENCY_8K4_HZ // PFS - IS31FL3733B only #endif -#ifndef ISSI_SWPULLUP -# define ISSI_SWPULLUP PUR_0R +#ifndef IS31FL3733_SWPULLUP +# define IS31FL3733_SWPULLUP IS31FL3733_PUR_0R #endif -#ifndef ISSI_CSPULLUP -# define ISSI_CSPULLUP PUR_0R +#ifndef IS31FL3733_CSPULLUP +# define IS31FL3733_CSPULLUP IS31FL3733_PUR_0R #endif -#ifndef ISSI_GLOBALCURRENT -# define ISSI_GLOBALCURRENT 0xFF +#ifndef IS31FL3733_GLOBALCURRENT +# define IS31FL3733_GLOBALCURRENT 0xFF #endif // Transfer buffer for TWITransmitData() @@ -82,25 +83,25 @@ uint8_t g_twi_transfer_buffer[20]; // We could optimize this and take out the unused registers from these // buffers and the transfers in is31fl3733_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[DRIVER_COUNT][192]; -bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; +uint8_t g_pwm_buffer[IS31FL3733_DRIVER_COUNT][192]; +bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false}; -uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0}; -bool g_led_control_registers_update_required[DRIVER_COUNT] = {false}; +uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][24] = {0}; +bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT] = {false}; bool is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) { // If the transaction fails function returns false. 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) { +#if IS31FL3733_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) { return false; } #endif @@ -119,18 +120,16 @@ bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // Copy the data from i to i+15. // Device will auto-increment register for data after the first byte // Thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer. - for (int j = 0; j < 16; j++) { - g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j]; - } + memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16); -#if ISSI_PERSISTENCE > 0 - for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) != 0) { +#if IS31FL3733_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) { return false; } #endif @@ -146,20 +145,20 @@ void is31fl3733_init(uint8_t addr, uint8_t sync) { // Sync is passed so set it according to the datasheet. // Unlock the command register. - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG0 - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL); // Turn off all LEDs. for (int i = 0x00; i <= 0x17; i++) { is31fl3733_write_register(addr, i, 0x00); } // Unlock the command register. - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG1 - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_PWM); // Set PWM on all LEDs to 0 // No need to setup Breath registers to PWM as that is the default. for (int i = 0x00; i <= 0xBF; i++) { @@ -167,18 +166,18 @@ void is31fl3733_init(uint8_t addr, uint8_t sync) { } // Unlock the command register. - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG3 - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_FUNCTION); // Set de-ghost pull-up resistors (SWx) - is31fl3733_write_register(addr, ISSI_REG_SWPULLUP, ISSI_SWPULLUP); + is31fl3733_write_register(addr, IS31FL3733_REG_SWPULLUP, IS31FL3733_SWPULLUP); // Set de-ghost pull-down resistors (CSx) - is31fl3733_write_register(addr, ISSI_REG_CSPULLUP, ISSI_CSPULLUP); + is31fl3733_write_register(addr, IS31FL3733_REG_CSPULLUP, IS31FL3733_CSPULLUP); // Set global current to maximum. - is31fl3733_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); + is31fl3733_write_register(addr, IS31FL3733_REG_GLOBALCURRENT, IS31FL3733_GLOBALCURRENT); // Disable software shutdown. - is31fl3733_write_register(addr, ISSI_REG_CONFIGURATION, ((sync & 0b11) << 6) | ((ISSI_PWM_FREQUENCY & 0b111) << 3) | 0x01); + is31fl3733_write_register(addr, IS31FL3733_REG_CONFIGURATION, ((sync & 0b11) << 6) | ((IS31FL3733_PWM_FREQUENCY & 0b111) << 3) | 0x01); // Wait 10ms to ensure the device has woken up. wait_ms(10); @@ -238,26 +237,26 @@ void is31fl3733_set_led_control_register(uint8_t index, bool red, bool green, bo void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { // Firstly we need to unlock the command register and select PG1. - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_PWM); // If any of the transactions fail we risk writing dirty PG0, // refresh page 0 just in case. if (!is31fl3733_write_pwm_buffer(addr, g_pwm_buffer[index])) { g_led_control_registers_update_required[index] = true; } + g_pwm_buffer_update_required[index] = false; } - g_pwm_buffer_update_required[index] = false; } void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_led_control_registers_update_required[index]) { // Firstly we need to unlock the command register and select PG0 - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL); for (int i = 0; i < 24; i++) { is31fl3733_write_register(addr, i, g_led_control_registers[index][i]); } + g_led_control_registers_update_required[index] = false; } - g_led_control_registers_update_required[index] = false; } diff --git a/drivers/led/issi/is31fl3733.h b/drivers/led/issi/is31fl3733.h index f37a58de0f..3c17723f92 100644 --- a/drivers/led/issi/is31fl3733.h +++ b/drivers/led/issi/is31fl3733.h @@ -23,6 +23,38 @@ #include <stdbool.h> #include "progmem.h" +// ======== DEPRECATED DEFINES - DO NOT USE ======== +#ifdef DRIVER_COUNT +# define IS31FL3733_DRIVER_COUNT DRIVER_COUNT +#endif +#ifdef ISSI_TIMEOUT +# define IS31FL3733_I2C_TIMEOUT ISSI_TIMEOUT +#endif +#ifdef ISSI_PERSISTENCE +# define IS31FL3733_I2C_PERSISTENCE ISSI_PERSISTENCE +#endif +#ifdef ISSI_PWM_FREQUENCY +# define IS31FL3733_PWM_FREQUENCY ISSI_PWM_FREQUENCY +#endif +#ifdef ISSI_SWPULLUP +# define IS31FL3733_SWPULLUP ISSI_SWPULLUP +#endif +#ifdef ISSI_CSPULLUP +# define IS31FL3733_CSPULLUP ISSI_CSPULLUP +#endif +#ifdef ISSI_GLOBALCURRENT +# define IS31FL3733_GLOBALCURRENT ISSI_GLOBALCURRENT +#endif + +#define PUR_0R IS31FL3733_PUR_0R +#define PUR_05KR IS31FL3733_PUR_05KR +#define PUR_3KR IS31FL3733_PUR_3KR +#define PUR_4KR IS31FL3733_PUR_4KR +#define PUR_8KR IS31FL3733_PUR_8KR +#define PUR_16KR IS31FL3733_PUR_16KR +#define PUR_32KR IS31FL3733_PUR_32KR +// ======== + typedef struct is31_led { uint8_t driver : 2; uint8_t r; @@ -48,13 +80,19 @@ void is31fl3733_set_led_control_register(uint8_t index, bool red, bool green, bo void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index); void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index); -#define PUR_0R 0x00 // No PUR resistor -#define PUR_05KR 0x02 // 0.5k Ohm resistor in t_NOL -#define PUR_3KR 0x03 // 3.0k Ohm resistor on all the time -#define PUR_4KR 0x04 // 4.0k Ohm resistor on all the time -#define PUR_8KR 0x05 // 8.0k Ohm resistor on all the time -#define PUR_16KR 0x06 // 16k Ohm resistor on all the time -#define PUR_32KR 0x07 // 32k Ohm resistor in t_NOL +#define IS31FL3733_PUR_0R 0x00 // No PUR resistor +#define IS31FL3733_PUR_05KR 0x02 // 0.5k Ohm resistor in t_NOL +#define IS31FL3733_PUR_3KR 0x03 // 3.0k Ohm resistor on all the time +#define IS31FL3733_PUR_4KR 0x04 // 4.0k Ohm resistor on all the time +#define IS31FL3733_PUR_8KR 0x05 // 8.0k Ohm resistor on all the time +#define IS31FL3733_PUR_16KR 0x06 // 16k Ohm resistor on all the time +#define IS31FL3733_PUR_32KR 0x07 // 32k Ohm resistor in t_NOL + +#define IS31FL3733_PWM_FREQUENCY_8K4_HZ 0b000 +#define IS31FL3733_PWM_FREQUENCY_4K2_HZ 0b001 +#define IS31FL3733_PWM_FREQUENCY_26K7_HZ 0b010 +#define IS31FL3733_PWM_FREQUENCY_2K1_HZ 0b011 +#define IS31FL3733_PWM_FREQUENCY_1K05_HZ 0b100 #define A_1 0x00 #define A_2 0x01 diff --git a/drivers/led/issi/is31fl3736.c b/drivers/led/issi/is31fl3736.c index 0de8b3bbae..c8c035854f 100644 --- a/drivers/led/issi/is31fl3736.c +++ b/drivers/led/issi/is31fl3736.c @@ -16,6 +16,7 @@ */ #include "is31fl3736.h" +#include <string.h> #include "i2c_master.h" #include "wait.h" @@ -29,42 +30,46 @@ // ADDR1 represents A1:A0 of the 7-bit address. // ADDR2 represents A3:A2 of the 7-bit address. // The result is: 0b101(ADDR2)(ADDR1) -#define ISSI_ADDR_DEFAULT 0x50 - -#define ISSI_COMMANDREGISTER 0xFD -#define ISSI_COMMANDREGISTER_WRITELOCK 0xFE -#define ISSI_INTERRUPTMASKREGISTER 0xF0 -#define ISSI_INTERRUPTSTATUSREGISTER 0xF1 - -#define ISSI_PAGE_LEDCONTROL 0x00 // PG0 -#define ISSI_PAGE_PWM 0x01 // PG1 -#define ISSI_PAGE_AUTOBREATH 0x02 // PG2 -#define ISSI_PAGE_FUNCTION 0x03 // PG3 - -#define ISSI_REG_CONFIGURATION 0x00 // PG3 -#define ISSI_REG_GLOBALCURRENT 0x01 // PG3 -#define ISSI_REG_RESET 0x11 // PG3 -#define ISSI_REG_SWPULLUP 0x0F // PG3 -#define ISSI_REG_CSPULLUP 0x10 // PG3 - -#ifndef ISSI_TIMEOUT -# define ISSI_TIMEOUT 100 +#define IS31FL3736_I2C_ADDRESS_DEFAULT 0x50 + +#define IS31FL3736_COMMANDREGISTER 0xFD +#define IS31FL3736_COMMANDREGISTER_WRITELOCK 0xFE +#define IS31FL3736_INTERRUPTMASKREGISTER 0xF0 +#define IS31FL3736_INTERRUPTSTATUSREGISTER 0xF1 + +#define IS31FL3736_PAGE_LEDCONTROL 0x00 // PG0 +#define IS31FL3736_PAGE_PWM 0x01 // PG1 +#define IS31FL3736_PAGE_AUTOBREATH 0x02 // PG2 +#define IS31FL3736_PAGE_FUNCTION 0x03 // PG3 + +#define IS31FL3736_REG_CONFIGURATION 0x00 // PG3 +#define IS31FL3736_REG_GLOBALCURRENT 0x01 // PG3 +#define IS31FL3736_REG_RESET 0x11 // PG3 +#define IS31FL3736_REG_SWPULLUP 0x0F // PG3 +#define IS31FL3736_REG_CSPULLUP 0x10 // PG3 + +#ifndef IS31FL3736_I2C_TIMEOUT +# define IS31FL3736_I2C_TIMEOUT 100 #endif -#ifndef ISSI_PERSISTENCE -# define ISSI_PERSISTENCE 0 +#ifndef IS31FL3736_I2C_PERSISTENCE +# define IS31FL3736_I2C_PERSISTENCE 0 #endif -#ifndef ISSI_SWPULLUP -# define ISSI_SWPULLUP PUR_0R +#ifndef IS31FL3736_PWM_FREQUENCY +# define IS31FL3736_PWM_FREQUENCY IS31FL3736_PWM_FREQUENCY_8K4_HZ // PFS - IS31FL3736B only #endif -#ifndef ISSI_CSPULLUP -# define ISSI_CSPULLUP PUR_0R +#ifndef IS31FL3736_SWPULLUP +# define IS31FL3736_SWPULLUP IS31FL3736_PUR_0R #endif -#ifndef ISSI_GLOBALCURRENT -# define ISSI_GLOBALCURRENT 0xFF +#ifndef IS31FL3736_CSPULLUP +# define IS31FL3736_CSPULLUP IS31FL3736_PUR_0R +#endif + +#ifndef IS31FL3736_GLOBALCURRENT +# define IS31FL3736_GLOBALCURRENT 0xFF #endif // Transfer buffer for TWITransmitData() @@ -76,22 +81,22 @@ uint8_t g_twi_transfer_buffer[20]; // We could optimize this and take out the unused registers from these // buffers and the transfers in is31fl3736_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[DRIVER_COUNT][192]; -bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; +uint8_t g_pwm_buffer[IS31FL3736_DRIVER_COUNT][192]; +bool g_pwm_buffer_update_required[IS31FL3736_DRIVER_COUNT] = {false}; -uint8_t g_led_control_registers[DRIVER_COUNT][24] = {{0}, {0}}; -bool g_led_control_registers_update_required = false; +uint8_t g_led_control_registers[IS31FL3736_DRIVER_COUNT][24] = {{0}, {0}}; +bool g_led_control_registers_update_required = false; void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) { 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 IS31FL3736_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3736_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3736_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, IS31FL3736_I2C_TIMEOUT); #endif } @@ -109,12 +114,12 @@ void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16); -#if ISSI_PERSISTENCE > 0 - for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0) break; +#if IS31FL3736_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3736_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3736_I2C_TIMEOUT) == 0) break; } #else - i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT); + i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3736_I2C_TIMEOUT); #endif } } @@ -126,20 +131,20 @@ void is31fl3736_init(uint8_t addr) { // then disable software shutdown. // Unlock the command register. - is31fl3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG0 - is31fl3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); + is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_LEDCONTROL); // Turn off all LEDs. for (int i = 0x00; i <= 0x17; i++) { is31fl3736_write_register(addr, i, 0x00); } // Unlock the command register. - is31fl3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG1 - is31fl3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); + is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_PWM); // Set PWM on all LEDs to 0 // No need to setup Breath registers to PWM as that is the default. for (int i = 0x00; i <= 0xBF; i++) { @@ -147,18 +152,18 @@ void is31fl3736_init(uint8_t addr) { } // Unlock the command register. - is31fl3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG3 - is31fl3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION); + is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_FUNCTION); // Set de-ghost pull-up resistors (SWx) - is31fl3736_write_register(addr, ISSI_REG_SWPULLUP, ISSI_SWPULLUP); + is31fl3736_write_register(addr, IS31FL3736_REG_SWPULLUP, IS31FL3736_SWPULLUP); // Set de-ghost pull-down resistors (CSx) - is31fl3736_write_register(addr, ISSI_REG_CSPULLUP, ISSI_CSPULLUP); + is31fl3736_write_register(addr, IS31FL3736_REG_CSPULLUP, IS31FL3736_CSPULLUP); // Set global current to maximum. - is31fl3736_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); + is31fl3736_write_register(addr, IS31FL3736_REG_GLOBALCURRENT, IS31FL3736_GLOBALCURRENT); // Disable software shutdown. - is31fl3736_write_register(addr, ISSI_REG_CONFIGURATION, 0x01); + is31fl3736_write_register(addr, IS31FL3736_REG_CONFIGURATION, ((IS31FL3736_PWM_FREQUENCY & 0b111) << 3) | 0x01); // Wait 10ms to ensure the device has woken up. wait_ms(10); @@ -266,19 +271,19 @@ void is31fl3736_mono_set_led_control_register(uint8_t index, bool enabled) { void is31fl3736_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { // Firstly we need to unlock the command register and select PG1 - is31fl3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - is31fl3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); + is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_PWM); is31fl3736_write_pwm_buffer(addr, g_pwm_buffer[index]); + g_pwm_buffer_update_required[index] = false; } - g_pwm_buffer_update_required[index] = false; } void is31fl3736_update_led_control_registers(uint8_t addr1, uint8_t addr2) { if (g_led_control_registers_update_required) { // Firstly we need to unlock the command register and select PG0 - is31fl3736_write_register(addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - is31fl3736_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); + is31fl3736_write_register(addr1, IS31FL3736_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3736_write_register(addr1, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_LEDCONTROL); for (int i = 0; i < 24; i++) { is31fl3736_write_register(addr1, i, g_led_control_registers[0][i]); // is31fl3736_write_register(addr2, i, g_led_control_registers[1][i]); diff --git a/drivers/led/issi/is31fl3736.h b/drivers/led/issi/is31fl3736.h index 32bdef4a80..5cc1262633 100644 --- a/drivers/led/issi/is31fl3736.h +++ b/drivers/led/issi/is31fl3736.h @@ -19,19 +19,37 @@ #include <stdint.h> #include <stdbool.h> -#include <string.h> #include "progmem.h" -// Simple interface option. -// If these aren't defined, just define them to make it compile - -#ifndef DRIVER_COUNT -# define DRIVER_COUNT 2 +// ======== DEPRECATED DEFINES - DO NOT USE ======== +#ifdef DRIVER_COUNT +# define IS31FL3736_DRIVER_COUNT DRIVER_COUNT #endif - -#ifndef RGB_MATRIX_LED_COUNT -# define RGB_MATRIX_LED_COUNT 96 +#ifdef ISSI_TIMEOUT +# define IS31FL3736_I2C_TIMEOUT ISSI_TIMEOUT +#endif +#ifdef ISSI_PERSISTENCE +# define IS31FL3736_I2C_PERSISTENCE ISSI_PERSISTENCE +#endif +#ifdef ISSI_SWPULLUP +# define IS31FL3736_SWPULLUP ISSI_SWPULLUP #endif +#ifdef ISSI_CSPULLUP +# define IS31FL3736_CSPULLUP ISSI_CSPULLUP +#endif +#ifdef ISSI_GLOBALCURRENT +# define IS31FL3736_GLOBALCURRENT ISSI_GLOBALCURRENT +#endif + +#define PUR_0R IS31FL3736_PUR_0R +#define PUR_05KR IS31FL3736_PUR_05KR +#define PUR_1KR IS31FL3736_PUR_1KR +#define PUR_2KR IS31FL3736_PUR_2KR +#define PUR_4KR IS31FL3736_PUR_4KR +#define PUR_8KR IS31FL3736_PUR_8KR +#define PUR_16KR IS31FL3736_PUR_16KR +#define PUR_32KR IS31FL3736_PUR_32KR +// ======== typedef struct is31_led { uint8_t driver : 2; @@ -62,14 +80,20 @@ void is31fl3736_mono_set_led_control_register(uint8_t index, bool enabled); void is31fl3736_update_pwm_buffers(uint8_t addr, uint8_t index); void is31fl3736_update_led_control_registers(uint8_t addr, uint8_t index); -#define PUR_0R 0x00 // No PUR resistor -#define PUR_05KR 0x01 // 0.5k Ohm resistor -#define PUR_1KR 0x02 // 1.0k Ohm resistor -#define PUR_2KR 0x03 // 2.0k Ohm resistor -#define PUR_4KR 0x04 // 4.0k Ohm resistor -#define PUR_8KR 0x05 // 8.0k Ohm resistor -#define PUR_16KR 0x06 // 16k Ohm resistor -#define PUR_32KR 0x07 // 32k Ohm resistor +#define IS31FL3736_PUR_0R 0x00 // No PUR resistor +#define IS31FL3736_PUR_05KR 0x01 // 0.5k Ohm resistor +#define IS31FL3736_PUR_1KR 0x02 // 1.0k Ohm resistor +#define IS31FL3736_PUR_2KR 0x03 // 2.0k Ohm resistor +#define IS31FL3736_PUR_4KR 0x04 // 4.0k Ohm resistor +#define IS31FL3736_PUR_8KR 0x05 // 8.0k Ohm resistor +#define IS31FL3736_PUR_16KR 0x06 // 16k Ohm resistor +#define IS31FL3736_PUR_32KR 0x07 // 32k Ohm resistor + +#define IS31FL3736_PWM_FREQUENCY_8K4_HZ 0b000 +#define IS31FL3736_PWM_FREQUENCY_4K2_HZ 0b001 +#define IS31FL3736_PWM_FREQUENCY_26K7_HZ 0b010 +#define IS31FL3736_PWM_FREQUENCY_2K1_HZ 0b011 +#define IS31FL3736_PWM_FREQUENCY_1K05_HZ 0b100 #define A_1 0x00 #define A_2 0x02 diff --git a/drivers/led/issi/is31fl3737.c b/drivers/led/issi/is31fl3737.c index 947c0a1d1a..550d26da8d 100644 --- a/drivers/led/issi/is31fl3737.c +++ b/drivers/led/issi/is31fl3737.c @@ -18,6 +18,7 @@ */ #include "is31fl3737.h" +#include <string.h> #include "i2c_master.h" #include "wait.h" @@ -31,46 +32,46 @@ // ADDR1 represents A1:A0 of the 7-bit address. // ADDR2 represents A3:A2 of the 7-bit address. // The result is: 0b101(ADDR2)(ADDR1) -#define ISSI_ADDR_DEFAULT 0x50 - -#define ISSI_COMMANDREGISTER 0xFD -#define ISSI_COMMANDREGISTER_WRITELOCK 0xFE -#define ISSI_INTERRUPTMASKREGISTER 0xF0 -#define ISSI_INTERRUPTSTATUSREGISTER 0xF1 - -#define ISSI_PAGE_LEDCONTROL 0x00 // PG0 -#define ISSI_PAGE_PWM 0x01 // PG1 -#define ISSI_PAGE_AUTOBREATH 0x02 // PG2 -#define ISSI_PAGE_FUNCTION 0x03 // PG3 - -#define ISSI_REG_CONFIGURATION 0x00 // PG3 -#define ISSI_REG_GLOBALCURRENT 0x01 // PG3 -#define ISSI_REG_RESET 0x11 // PG3 -#define ISSI_REG_SWPULLUP 0x0F // PG3 -#define ISSI_REG_CSPULLUP 0x10 // PG3 - -#ifndef ISSI_TIMEOUT -# define ISSI_TIMEOUT 100 +#define IS31FL3737_I2C_ADDRESS_DEFAULT 0x50 + +#define IS31FL3737_COMMANDREGISTER 0xFD +#define IS31FL3737_COMMANDREGISTER_WRITELOCK 0xFE +#define IS31FL3737_INTERRUPTMASKREGISTER 0xF0 +#define IS31FL3737_INTERRUPTSTATUSREGISTER 0xF1 + +#define IS31FL3737_PAGE_LEDCONTROL 0x00 // PG0 +#define IS31FL3737_PAGE_PWM 0x01 // PG1 +#define IS31FL3737_PAGE_AUTOBREATH 0x02 // PG2 +#define IS31FL3737_PAGE_FUNCTION 0x03 // PG3 + +#define IS31FL3737_REG_CONFIGURATION 0x00 // PG3 +#define IS31FL3737_REG_GLOBALCURRENT 0x01 // PG3 +#define IS31FL3737_REG_RESET 0x11 // PG3 +#define IS31FL3737_REG_SWPULLUP 0x0F // PG3 +#define IS31FL3737_REG_CSPULLUP 0x10 // PG3 + +#ifndef IS31FL3737_I2C_TIMEOUT +# define IS31FL3737_I2C_TIMEOUT 100 #endif -#ifndef ISSI_PERSISTENCE -# define ISSI_PERSISTENCE 0 +#ifndef IS31FL3737_I2C_PERSISTENCE +# define IS31FL3737_I2C_PERSISTENCE 0 #endif -#ifndef ISSI_PWM_FREQUENCY -# define ISSI_PWM_FREQUENCY 0b000 // PFS - IS31FL3737B only +#ifndef IS31FL3737_PWM_FREQUENCY +# define IS31FL3737_PWM_FREQUENCY IS31FL3737_PWM_FREQUENCY_8K4_HZ // PFS - IS31FL3737B only #endif -#ifndef ISSI_SWPULLUP -# define ISSI_SWPULLUP PUR_0R +#ifndef IS31FL3737_SWPULLUP +# define IS31FL3737_SWPULLUP IS31FL3737_PUR_0R #endif -#ifndef ISSI_CSPULLUP -# define ISSI_CSPULLUP PUR_0R +#ifndef IS31FL3737_CSPULLUP +# define IS31FL3737_CSPULLUP IS31FL3737_PUR_0R #endif -#ifndef ISSI_GLOBALCURRENT -# define ISSI_GLOBALCURRENT 0xFF +#ifndef IS31FL3737_GLOBALCURRENT +# define IS31FL3737_GLOBALCURRENT 0xFF #endif // Transfer buffer for TWITransmitData() @@ -83,22 +84,22 @@ uint8_t g_twi_transfer_buffer[20]; // buffers and the transfers in is31fl3737_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[DRIVER_COUNT][192]; -bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; +uint8_t g_pwm_buffer[IS31FL3737_DRIVER_COUNT][192]; +bool g_pwm_buffer_update_required[IS31FL3737_DRIVER_COUNT] = {false}; -uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0}; -bool g_led_control_registers_update_required[DRIVER_COUNT] = {false}; +uint8_t g_led_control_registers[IS31FL3737_DRIVER_COUNT][24] = {0}; +bool g_led_control_registers_update_required[IS31FL3737_DRIVER_COUNT] = {false}; void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) { 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 IS31FL3737_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3737_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3737_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, IS31FL3737_I2C_TIMEOUT); #endif } @@ -116,12 +117,12 @@ void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16); -#if ISSI_PERSISTENCE > 0 - for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0) break; +#if IS31FL3737_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3737_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3737_I2C_TIMEOUT) == 0) break; } #else - i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT); + i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3737_I2C_TIMEOUT); #endif } } @@ -133,20 +134,20 @@ void is31fl3737_init(uint8_t addr) { // then disable software shutdown. // Unlock the command register. - is31fl3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG0 - is31fl3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); + is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_LEDCONTROL); // Turn off all LEDs. for (int i = 0x00; i <= 0x17; i++) { is31fl3737_write_register(addr, i, 0x00); } // Unlock the command register. - is31fl3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG1 - is31fl3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); + is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_PWM); // Set PWM on all LEDs to 0 // No need to setup Breath registers to PWM as that is the default. for (int i = 0x00; i <= 0xBF; i++) { @@ -154,18 +155,18 @@ void is31fl3737_init(uint8_t addr) { } // Unlock the command register. - is31fl3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG3 - is31fl3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION); + is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_FUNCTION); // Set de-ghost pull-up resistors (SWx) - is31fl3737_write_register(addr, ISSI_REG_SWPULLUP, ISSI_SWPULLUP); + is31fl3737_write_register(addr, IS31FL3737_REG_SWPULLUP, IS31FL3737_SWPULLUP); // Set de-ghost pull-down resistors (CSx) - is31fl3737_write_register(addr, ISSI_REG_CSPULLUP, ISSI_CSPULLUP); + is31fl3737_write_register(addr, IS31FL3737_REG_CSPULLUP, IS31FL3737_CSPULLUP); // Set global current to maximum. - is31fl3737_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); + is31fl3737_write_register(addr, IS31FL3737_REG_GLOBALCURRENT, IS31FL3737_GLOBALCURRENT); // Disable software shutdown. - is31fl3737_write_register(addr, ISSI_REG_CONFIGURATION, ((ISSI_PWM_FREQUENCY & 0b111) << 3) | 0x01); + is31fl3737_write_register(addr, IS31FL3737_REG_CONFIGURATION, ((IS31FL3737_PWM_FREQUENCY & 0b111) << 3) | 0x01); // Wait 10ms to ensure the device has woken up. wait_ms(10); @@ -225,22 +226,22 @@ void is31fl3737_set_led_control_register(uint8_t index, bool red, bool green, bo void is31fl3737_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { // Firstly we need to unlock the command register and select PG1 - is31fl3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - is31fl3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); + is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_PWM); is31fl3737_write_pwm_buffer(addr, g_pwm_buffer[index]); + g_pwm_buffer_update_required[index] = false; } - g_pwm_buffer_update_required[index] = false; } void is31fl3737_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_led_control_registers_update_required[index]) { // Firstly we need to unlock the command register and select PG0 - is31fl3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - is31fl3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); + is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_LEDCONTROL); for (int i = 0; i < 24; i++) { is31fl3737_write_register(addr, i, g_led_control_registers[index][i]); } + g_led_control_registers_update_required[index] = false; } - g_led_control_registers_update_required[index] = false; } diff --git a/drivers/led/issi/is31fl3737.h b/drivers/led/issi/is31fl3737.h index e7fc97872c..e382602e9a 100644 --- a/drivers/led/issi/is31fl3737.h +++ b/drivers/led/issi/is31fl3737.h @@ -19,9 +19,41 @@ #pragma once +// ======== DEPRECATED DEFINES - DO NOT USE ======== +#ifdef DRIVER_COUNT +# define IS31FL3737_DRIVER_COUNT DRIVER_COUNT +#endif +#ifdef ISSI_TIMEOUT +# define IS31FL3737_I2C_TIMEOUT ISSI_TIMEOUT +#endif +#ifdef ISSI_PERSISTENCE +# define IS31FL3737_I2C_PERSISTENCE ISSI_PERSISTENCE +#endif +#ifdef ISSI_PWM_FREQUENCY +# define IS31FL3737_PWM_FREQUENCY ISSI_PWM_FREQUENCY +#endif +#ifdef ISSI_SWPULLUP +# define IS31FL3737_SWPULLUP ISSI_SWPULLUP +#endif +#ifdef ISSI_CSPULLUP +# define IS31FL3737_CSPULLUP ISSI_CSPULLUP +#endif +#ifdef ISSI_GLOBALCURRENT +# define IS31FL3737_GLOBALCURRENT ISSI_GLOBALCURRENT +#endif + +#define PUR_0R IS31FL3737_PUR_0R +#define PUR_05KR IS31FL3737_PUR_05KR +#define PUR_1KR IS31FL3737_PUR_1KR +#define PUR_2KR IS31FL3737_PUR_2KR +#define PUR_4KR IS31FL3737_PUR_4KR +#define PUR_8KR IS31FL3737_PUR_8KR +#define PUR_16KR IS31FL3737_PUR_16KR +#define PUR_32KR IS31FL3737_PUR_32KR +// ======== + #include <stdint.h> #include <stdbool.h> -#include <string.h> #include "progmem.h" typedef struct is31_led { @@ -49,14 +81,20 @@ void is31fl3737_set_led_control_register(uint8_t index, bool red, bool green, bo void is31fl3737_update_pwm_buffers(uint8_t addr, uint8_t index); void is31fl3737_update_led_control_registers(uint8_t addr, uint8_t index); -#define PUR_0R 0x00 // No PUR resistor -#define PUR_05KR 0x01 // 0.5k Ohm resistor in t_NOL -#define PUR_1KR 0x02 // 1.0k Ohm resistor in t_NOL -#define PUR_2KR 0x03 // 2.0k Ohm resistor in t_NOL -#define PUR_4KR 0x04 // 4.0k Ohm resistor in t_NOL -#define PUR_8KR 0x05 // 8.0k Ohm resistor in t_NOL -#define PUR_16KR 0x06 // 16k Ohm resistor in t_NOL -#define PUR_32KR 0x07 // 32k Ohm resistor in t_NOL +#define IS31FL3737_PUR_0R 0x00 // No PUR resistor +#define IS31FL3737_PUR_05KR 0x01 // 0.5k Ohm resistor in t_NOL +#define IS31FL3737_PUR_1KR 0x02 // 1.0k Ohm resistor in t_NOL +#define IS31FL3737_PUR_2KR 0x03 // 2.0k Ohm resistor in t_NOL +#define IS31FL3737_PUR_4KR 0x04 // 4.0k Ohm resistor in t_NOL +#define IS31FL3737_PUR_8KR 0x05 // 8.0k Ohm resistor in t_NOL +#define IS31FL3737_PUR_16KR 0x06 // 16k Ohm resistor in t_NOL +#define IS31FL3737_PUR_32KR 0x07 // 32k Ohm resistor in t_NOL + +#define IS31FL3737_PWM_FREQUENCY_8K4_HZ 0b000 +#define IS31FL3737_PWM_FREQUENCY_4K2_HZ 0b001 +#define IS31FL3737_PWM_FREQUENCY_26K7_HZ 0b010 +#define IS31FL3737_PWM_FREQUENCY_2K1_HZ 0b011 +#define IS31FL3737_PWM_FREQUENCY_1K05_HZ 0b100 #define A_1 0x00 #define A_2 0x01 diff --git a/drivers/led/issi/is31fl3741.c b/drivers/led/issi/is31fl3741.c index 70671c2a40..2db1f021b1 100644 --- a/drivers/led/issi/is31fl3741.c +++ b/drivers/led/issi/is31fl3741.c @@ -17,12 +17,10 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "wait.h" - #include "is31fl3741.h" #include <string.h> #include "i2c_master.h" -#include "progmem.h" +#include "wait.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) @@ -34,46 +32,55 @@ // ADDR1 represents A1:A0 of the 7-bit address. // ADDR2 represents A3:A2 of the 7-bit address. // The result is: 0b101(ADDR2)(ADDR1) -#define ISSI_ADDR_DEFAULT 0x60 - -#define ISSI_COMMANDREGISTER 0xFD -#define ISSI_COMMANDREGISTER_WRITELOCK 0xFE -#define ISSI_INTERRUPTMASKREGISTER 0xF0 -#define ISSI_INTERRUPTSTATUSREGISTER 0xF1 -#define ISSI_IDREGISTER 0xFC - -#define ISSI_PAGE_PWM0 0x00 // PG0 -#define ISSI_PAGE_PWM1 0x01 // PG1 -#define ISSI_PAGE_SCALING_0 0x02 // PG2 -#define ISSI_PAGE_SCALING_1 0x03 // PG3 -#define ISSI_PAGE_FUNCTION 0x04 // PG4 - -#define ISSI_REG_CONFIGURATION 0x00 // PG4 -#define ISSI_REG_GLOBALCURRENT 0x01 // PG4 -#define ISSI_REG_PULLDOWNUP 0x02 // PG4 -#define ISSI_REG_RESET 0x3F // PG4 - -#ifndef ISSI_TIMEOUT -# define ISSI_TIMEOUT 100 +#define IS31FL3741_I2C_ADDRESS_DEFAULT 0x60 + +#define IS31FL3741_COMMANDREGISTER 0xFD +#define IS31FL3741_COMMANDREGISTER_WRITELOCK 0xFE +#define IS31FL3741_INTERRUPTMASKREGISTER 0xF0 +#define IS31FL3741_INTERRUPTSTATUSREGISTER 0xF1 +#define IS31FL3741_IDREGISTER 0xFC + +#define IS31FL3741_PAGE_PWM0 0x00 // PG0 +#define IS31FL3741_PAGE_PWM1 0x01 // PG1 +#define IS31FL3741_PAGE_SCALING_0 0x02 // PG2 +#define IS31FL3741_PAGE_SCALING_1 0x03 // PG3 +#define IS31FL3741_PAGE_FUNCTION 0x04 // PG4 + +#define IS31FL3741_REG_CONFIGURATION 0x00 // PG4 +#define IS31FL3741_REG_GLOBALCURRENT 0x01 // PG4 +#define IS31FL3741_REG_PULLDOWNUP 0x02 // PG4 +#define IS31FL3741_REG_PWM_FREQUENCY 0x36 // PG4 +#define IS31FL3741_REG_RESET 0x3F // PG4 + +#ifndef IS31FL3741_I2C_TIMEOUT +# define IS31FL3741_I2C_TIMEOUT 100 +#endif + +#ifndef IS31FL3741_I2C_PERSISTENCE +# define IS31FL3741_I2C_PERSISTENCE 0 +#endif + +#ifndef IS31FL3741_CONFIGURATION +# define IS31FL3741_CONFIGURATION 0x01 #endif -#ifndef ISSI_PERSISTENCE -# define ISSI_PERSISTENCE 0 +#ifndef IS31FL3741_PWM_FREQUENCY +# define IS31FL3741_PWM_FREQUENCY IS31FL3741_PWM_FREQUENCY_29K_HZ #endif -#ifndef ISSI_SWPULLUP -# define ISSI_SWPULLUP PUR_32KR +#ifndef IS31FL3741_SWPULLUP +# define IS31FL3741_SWPULLUP IS31FL3741_PUR_32KR #endif -#ifndef ISSI_CSPULLUP -# define ISSI_CSPULLUP PUR_32KR +#ifndef IS31FL3741_CSPULLUP +# define IS31FL3741_CSPULLUP IS31FL3741_PUR_32KR #endif -#ifndef ISSI_GLOBALCURRENT -# define ISSI_GLOBALCURRENT 0xFF +#ifndef IS31FL3741_GLOBALCURRENT +# define IS31FL3741_GLOBALCURRENT 0xFF #endif -#define ISSI_MAX_LEDS 351 +#define IS31FL3741_MAX_LEDS 351 // Transfer buffer for TWITransmitData() uint8_t g_twi_transfer_buffer[20] = {0xFF}; @@ -84,22 +91,22 @@ uint8_t g_twi_transfer_buffer[20] = {0xFF}; // We could optimize this and take out the unused registers from these // buffers and the transfers in is31fl3741_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[DRIVER_COUNT][ISSI_MAX_LEDS]; -bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; -bool g_scaling_registers_update_required[DRIVER_COUNT] = {false}; +uint8_t g_pwm_buffer[IS31FL3741_DRIVER_COUNT][IS31FL3741_MAX_LEDS]; +bool g_pwm_buffer_update_required[IS31FL3741_DRIVER_COUNT] = {false}; +bool g_scaling_registers_update_required[IS31FL3741_DRIVER_COUNT] = {false}; -uint8_t g_scaling_registers[DRIVER_COUNT][ISSI_MAX_LEDS]; +uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_MAX_LEDS]; void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) { 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 IS31FL3741_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3741_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, IS31FL3741_I2C_TIMEOUT); #endif } @@ -109,21 +116,21 @@ bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { for (int i = 0; i < 342; i += 18) { if (i == 180) { // unlock the command register and select PG1 - is31fl3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - is31fl3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM1); + is31fl3741_write_register(addr, IS31FL3741_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3741_write_register(addr, IS31FL3741_COMMANDREGISTER, IS31FL3741_PAGE_PWM1); } g_twi_transfer_buffer[0] = i % 180; memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 18); -#if ISSI_PERSISTENCE > 0 - for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 19, ISSI_TIMEOUT) != 0) { +#if IS31FL3741_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) != 0) { return false; } } #else - if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 19, ISSI_TIMEOUT) != 0) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) != 0) { return false; } #endif @@ -133,14 +140,14 @@ bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { g_twi_transfer_buffer[0] = 162; memcpy(g_twi_transfer_buffer + 1, pwm_buffer + 342, 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) { +#if IS31FL3741_I2C_PERSISTENCE > 0 + for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) { + if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 10, IS31FL3741_I2C_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, 10, IS31FL3741_I2C_TIMEOUT) != 0) { return false; } #endif @@ -156,18 +163,20 @@ void is31fl3741_init(uint8_t addr) { // Unlock the command register. // Unlock the command register. - is31fl3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3741_write_register(addr, IS31FL3741_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG4 - is31fl3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION); + is31fl3741_write_register(addr, IS31FL3741_COMMANDREGISTER, IS31FL3741_PAGE_FUNCTION); // Set to Normal operation - is31fl3741_write_register(addr, ISSI_REG_CONFIGURATION, 0x01); + is31fl3741_write_register(addr, IS31FL3741_REG_CONFIGURATION, IS31FL3741_CONFIGURATION); // Set Golbal Current Control Register - is31fl3741_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); + is31fl3741_write_register(addr, IS31FL3741_REG_GLOBALCURRENT, IS31FL3741_GLOBALCURRENT); // Set Pull up & Down for SWx CSy - is31fl3741_write_register(addr, ISSI_REG_PULLDOWNUP, ((ISSI_CSPULLUP << 4) | ISSI_SWPULLUP)); + is31fl3741_write_register(addr, IS31FL3741_REG_PULLDOWNUP, ((IS31FL3741_CSPULLUP << 4) | IS31FL3741_SWPULLUP)); + // Set PWM frequency + is31fl3741_write_register(addr, IS31FL3741_REG_PWM_FREQUENCY, (IS31FL3741_PWM_FREQUENCY & 0b1111)); // is31fl3741_update_led_scaling_registers(addr, 0xFF, 0xFF, 0xFF); @@ -224,8 +233,8 @@ void is31fl3741_set_led_control_register(uint8_t index, bool red, bool green, bo void is31fl3741_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { // unlock the command register and select PG2 - is31fl3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - is31fl3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM0); + is31fl3741_write_register(addr, IS31FL3741_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3741_write_register(addr, IS31FL3741_COMMANDREGISTER, IS31FL3741_PAGE_PWM0); is31fl3741_write_pwm_buffer(addr, g_pwm_buffer[index]); } @@ -244,8 +253,8 @@ void is31fl3741_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, void is31fl3741_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_scaling_registers_update_required[index]) { // unlock the command register and select PG2 - is31fl3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - is31fl3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_SCALING_0); + is31fl3741_write_register(addr, IS31FL3741_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3741_write_register(addr, IS31FL3741_COMMANDREGISTER, IS31FL3741_PAGE_SCALING_0); // CS1_SW1 to CS30_SW6 are on PG2 for (int i = CS1_SW1; i <= CS30_SW6; ++i) { @@ -253,8 +262,8 @@ void is31fl3741_update_led_control_registers(uint8_t addr, uint8_t index) { } // unlock the command register and select PG3 - is31fl3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - is31fl3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_SCALING_1); + is31fl3741_write_register(addr, IS31FL3741_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3741_write_register(addr, IS31FL3741_COMMANDREGISTER, IS31FL3741_PAGE_SCALING_1); // CS1_SW7 to CS39_SW9 are on PG3 for (int i = CS1_SW7; i <= CS39_SW9; ++i) { diff --git a/drivers/led/issi/is31fl3741.h b/drivers/led/issi/is31fl3741.h index 4ae84dc3c6..b7317bdab6 100644 --- a/drivers/led/issi/is31fl3741.h +++ b/drivers/led/issi/is31fl3741.h @@ -23,6 +23,39 @@ #include <stdbool.h> #include "progmem.h" +// ======== DEPRECATED DEFINES - DO NOT USE ======== +#ifdef DRIVER_COUNT +# define IS31FL3741_DRIVER_COUNT DRIVER_COUNT +#endif +#ifdef ISSI_TIMEOUT +# define IS31FL3741_I2C_TIMEOUT ISSI_TIMEOUT +#endif +#ifdef ISSI_PERSISTENCE +# define IS31FL3741_I2C_PERSISTENCE ISSI_PERSISTENCE +#endif +#ifdef ISSI_CONFIGURATION +# define IS31FL3741_CONFIGURATION ISSI_CONFIGURATION +#endif +#ifdef ISSI_SWPULLUP +# define IS31FL3741_SWPULLUP ISSI_SWPULLUP +#endif +#ifdef ISSI_CSPULLUP +# define IS31FL3741_CSPULLUP ISSI_CSPULLUP +#endif +#ifdef ISSI_GLOBALCURRENT +# define IS31FL3741_GLOBALCURRENT ISSI_GLOBALCURRENT +#endif + +#define PUR_0R IS31FL3741_PUR_0R +#define PUR_05KR IS31FL3741_PUR_05KR +#define PUR_1KR IS31FL3741_PUR_1KR +#define PUR_2KR IS31FL3741_PUR_2KR +#define PUR_4KR IS31FL3741_PUR_4KR +#define PUR_8KR IS31FL3741_PUR_8KR +#define PUR_16KR IS31FL3741_PUR_16KR +#define PUR_32KR IS31FL3741_PUR_32KR +// ======== + typedef struct is31_led { uint32_t driver : 2; uint32_t r : 10; @@ -51,14 +84,19 @@ void is31fl3741_set_scaling_registers(const is31_led *pled, uint8_t red, uint8_t void is31fl3741_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue); -#define PUR_0R 0x00 // No PUR resistor -#define PUR_05KR 0x01 // 0.5k Ohm resistor -#define PUR_1KR 0x02 // 1.0k Ohm resistor -#define PUR_2KR 0x03 // 2.0k Ohm resistor -#define PUR_4KR 0x04 // 4.0k Ohm resistor -#define PUR_8KR 0x05 // 8.0k Ohm resistor -#define PUR_16KR 0x06 // 16k Ohm resistor -#define PUR_32KR 0x07 // 32k Ohm resistor +#define IS31FL3741_PUR_0R 0x00 // No PUR resistor +#define IS31FL3741_PUR_05KR 0x01 // 0.5k Ohm resistor +#define IS31FL3741_PUR_1KR 0x02 // 1.0k Ohm resistor +#define IS31FL3741_PUR_2KR 0x03 // 2.0k Ohm resistor +#define IS31FL3741_PUR_4KR 0x04 // 4.0k Ohm resistor +#define IS31FL3741_PUR_8KR 0x05 // 8.0k Ohm resistor +#define IS31FL3741_PUR_16KR 0x06 // 16k Ohm resistor +#define IS31FL3741_PUR_32KR 0x07 // 32k Ohm resistor + +#define IS31FL3741_PWM_FREQUENCY_29K_HZ 0b0000 +#define IS31FL3741_PWM_FREQUENCY_3K6_HZ 0b0011 +#define IS31FL3741_PWM_FREQUENCY_1K8_HZ 0b0111 +#define IS31FL3741_PWM_FREQUENCY_900_HZ 0b1011 #define CS1_SW1 0x00 #define CS2_SW1 0x01 diff --git a/drivers/oled/oled_driver.c b/drivers/oled/oled_driver.c index 8ff6e0426c..ab04ff3d40 100644 --- a/drivers/oled/oled_driver.c +++ b/drivers/oled/oled_driver.c @@ -448,7 +448,7 @@ static void rotate_90(const uint8_t *src, uint8_t *dest) { } } -void oled_render(void) { +void oled_render_dirty(bool all) { // Do we have work to do? oled_dirty &= OLED_ALL_BLOCKS_MASK; if (!oled_dirty || !oled_initialized || oled_scrolling) { @@ -460,7 +460,7 @@ void oled_render(void) { uint8_t update_start = 0; uint8_t num_processed = 0; - while (oled_dirty && num_processed++ < OLED_UPDATE_PROCESS_LIMIT) { // render all dirty blocks (up to the configured limit) + while (oled_dirty && (num_processed++ < OLED_UPDATE_PROCESS_LIMIT || all)) { // render all dirty blocks (up to the configured limit) // Find next dirty block while (!(oled_dirty & ((OLED_BLOCK_TYPE)1 << update_start))) { ++update_start; diff --git a/drivers/oled/oled_driver.h b/drivers/oled/oled_driver.h index 627a3da0ba..fba6633176 100644 --- a/drivers/oled/oled_driver.h +++ b/drivers/oled/oled_driver.h @@ -353,20 +353,24 @@ oled_rotation_t oled_init_user(oled_rotation_t rotation); // Clears the display buffer, resets cursor position to 0, and sets the buffer to dirty for rendering void oled_clear(void); -// Renders the dirty chunks of the buffer to oled display -void oled_render(void); +// Alias to oled_render_dirty to avoid a change in api. +#define oled_render() oled_render_dirty(false) + +// Renders all dirty blocks to the display at one time or a subset depending on the value of +// all. +void oled_render_dirty(bool all); // Moves cursor to character position indicated by column and line, wraps if out of bounds // Max column denoted by 'oled_max_chars()' and max lines by 'oled_max_lines()' functions void oled_set_cursor(uint8_t col, uint8_t line); // Advances the cursor to the next page, writing ' ' if true -// Wraps to the begining when out of bounds +// Wraps to the beginning when out of bounds void oled_advance_page(bool clearPageRemainder); // Moves the cursor forward 1 character length // Advance page if there is not enough room for the next character -// Wraps to the begining when out of bounds +// Wraps to the beginning when out of bounds void oled_advance_char(void); // Writes a single character to the buffer at current cursor position @@ -433,10 +437,10 @@ bool oled_off(void); // not bool is_oled_on(void); -// Sets the brightness of the display +// Sets the brightness level of the display uint8_t oled_set_brightness(uint8_t level); -// Gets the current brightness of the display +// Gets the current brightness level of the display uint8_t oled_get_brightness(void); // Basically it's oled_render, but with timeout management and oled_task_user calling! @@ -458,12 +462,12 @@ void oled_scroll_set_area(uint8_t start_line, uint8_t end_line); // 0=2, 1=3, 2=4, 3=5, 4=25, 5=64, 6=128, 7=256 void oled_scroll_set_speed(uint8_t speed); -// Scrolls the entire display right +// Begin scrolling the entire display right // Returns true if the screen was scrolling or starts scrolling // NOTE: display contents cannot be changed while scrolling bool oled_scroll_right(void); -// Scrolls the entire display left +// Begin scrolling the entire display left // Returns true if the screen was scrolling or starts scrolling // NOTE: display contents cannot be changed while scrolling bool oled_scroll_left(void); diff --git a/drivers/ws2812.h b/drivers/ws2812.h index 8750b0110e..1527df23d3 100644 --- a/drivers/ws2812.h +++ b/drivers/ws2812.h @@ -73,4 +73,4 @@ * - Send out the LED data * - Wait 50us to reset the LEDs */ -void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds); +void ws2812_setleds(rgb_led_t *ledarray, uint16_t number_of_leds); |