Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LED drivers: register naming cleanups #22436

Merged
merged 12 commits into from
Nov 20, 2023
47 changes: 12 additions & 35 deletions drivers/led/aw20216s.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,16 @@
#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_CONFIGURATION
# define AW20216S_CONFIGURATION (AW20216S_CONFIGURATION_SWSEL_1_12 | AW20216S_CONFIGURATION_CHIPEN)
#endif

#ifndef AW20216S_MIX_FUNCTION
# define AW20216S_MIX_FUNCTION (AW20216S_MIX_FUNCTION_LPEN)
#endif

#ifndef AW20216S_SCALING_MAX
# define AW20216S_SCALING_MAX 150
#endif
Expand Down Expand Up @@ -102,7 +79,7 @@ static inline bool aw20216s_write_register(pin_t cs_pin, uint8_t page, uint8_t r
}

void aw20216s_soft_reset(pin_t cs_pin) {
aw20216s_write_register(cs_pin, AW20216S_PAGE_FUNCTION, AW20216S_REG_RESET, AW20216S_RESET_CMD);
aw20216s_write_register(cs_pin, AW20216S_PAGE_FUNCTION, AW20216S_FUNCTION_REG_RESET, AW20216S_RESET_MAGIC);
}

static void aw20216s_init_scaling(pin_t cs_pin) {
Expand All @@ -114,16 +91,16 @@ static void aw20216s_init_scaling(pin_t cs_pin) {

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);
aw20216s_write_register(cs_pin, AW20216S_PAGE_FUNCTION, AW20216S_FUNCTION_REG_GLOBAL_CURRENT, 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);
aw20216s_write_register(cs_pin, AW20216S_PAGE_FUNCTION, AW20216S_FUNCTION_REG_CONFIGURATION, AW20216S_CONFIGURATION);
}

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);
aw20216s_write_register(cs_pin, AW20216S_PAGE_FUNCTION, AW20216S_FUNCTION_REG_MIX_FUNCTION, AW20216S_MIX_FUNCTION);
}

void aw20216s_init_drivers(void) {
Expand Down
22 changes: 22 additions & 0 deletions drivers/led/aw20216s.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@
#define g_aw_leds g_aw20216s_leds
// ========

#define AW20216S_ID (0b1010 << 4)
#define AW20216S_WRITE 0
#define AW20216S_READ 1

#define AW20216S_PAGE_FUNCTION (0x00 << 1)
#define AW20216S_PAGE_PWM (0x01 << 1)
#define AW20216S_PAGE_SCALING (0x02 << 1)
#define AW20216S_PAGE_PATTERN_CHOICE (0x03 << 1)
#define AW20216S_PAGE_PWM_SCALING (0x04 << 1)

#define AW20216S_FUNCTION_REG_CONFIGURATION 0x00
#define AW20216S_CONFIGURATION_SWSEL_1_12 (0b1011 << 4)
#define AW20216S_CONFIGURATION_CHIPEN (0b1 << 0)

#define AW20216S_FUNCTION_REG_GLOBAL_CURRENT 0x01

#define AW20216S_FUNCTION_REG_RESET 0x2F
#define AW20216S_RESET_MAGIC 0xAE

#define AW20216S_FUNCTION_REG_MIX_FUNCTION 0x46
#define AW20216S_MIX_FUNCTION_LPEN (0b1 << 1)

#if defined(RGB_MATRIX_AW20216S)
# define AW20216S_LED_COUNT RGB_MATRIX_LED_COUNT
#endif
Expand Down
11 changes: 2 additions & 9 deletions drivers/led/issi/is31fl3218-simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@
#include <string.h>
#include "i2c_master.h"

// These are the register addresses
#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

#define IS31FL3218_PWM_REGISTER_COUNT 18
#define IS31FL3218_LED_CONTROL_REGISTER_COUNT 3

Expand Down Expand Up @@ -86,7 +79,7 @@ void is31fl3218_init(void) {

// turn off all LEDs in the LED control register
for (uint8_t i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3218_write_register(IS31FL3218_REG_CONTROL + i, 0x00);
is31fl3218_write_register(IS31FL3218_REG_LED_CONTROL_1 + i, 0x00);
}

// Load PWM registers and LED Control register data
Expand Down Expand Up @@ -146,7 +139,7 @@ void is31fl3218_update_pwm_buffers(void) {
void is31fl3218_update_led_control_registers(void) {
if (g_led_control_registers_update_required) {
for (int i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3218_write_register(IS31FL3218_REG_CONTROL + i, g_led_control_registers[i]);
is31fl3218_write_register(IS31FL3218_REG_LED_CONTROL_1 + i, g_led_control_registers[i]);
}

g_led_control_registers_update_required = false;
Expand Down
8 changes: 8 additions & 0 deletions drivers/led/issi/is31fl3218-simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
#include "progmem.h"
#include "util.h"

#define IS31FL3218_REG_SHUTDOWN 0x00
#define IS31FL3218_REG_PWM 0x01
#define IS31FL3218_REG_LED_CONTROL_1 0x13
#define IS31FL3218_REG_LED_CONTROL_2 0x14
#define IS31FL3218_REG_LED_CONTROL_3 0x15
#define IS31FL3218_REG_UPDATE 0x16
#define IS31FL3218_REG_RESET 0x17

#define IS31FL3218_I2C_ADDRESS 0x54

#if defined(LED_MATRIX_IS31FL3218)
Expand Down
11 changes: 2 additions & 9 deletions drivers/led/issi/is31fl3218.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@
#include <string.h>
#include "i2c_master.h"

// These are the register addresses
#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

#define IS31FL3218_PWM_REGISTER_COUNT 18
#define IS31FL3218_LED_CONTROL_REGISTER_COUNT 3

Expand Down Expand Up @@ -86,7 +79,7 @@ void is31fl3218_init(void) {

// turn off all LEDs in the LED control register
for (uint8_t i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3218_write_register(IS31FL3218_REG_CONTROL + i, 0x00);
is31fl3218_write_register(IS31FL3218_REG_LED_CONTROL_1 + i, 0x00);
}

// Load PWM registers and LED Control register data
Expand Down Expand Up @@ -162,7 +155,7 @@ void is31fl3218_update_pwm_buffers(void) {
void is31fl3218_update_led_control_registers(void) {
if (g_led_control_registers_update_required) {
for (int i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3218_write_register(IS31FL3218_REG_CONTROL + i, g_led_control_registers[i]);
is31fl3218_write_register(IS31FL3218_REG_LED_CONTROL_1 + i, g_led_control_registers[i]);
}

g_led_control_registers_update_required = false;
Expand Down
8 changes: 8 additions & 0 deletions drivers/led/issi/is31fl3218.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
#include "progmem.h"
#include "util.h"

#define IS31FL3218_REG_SHUTDOWN 0x00
#define IS31FL3218_REG_PWM 0x01
#define IS31FL3218_REG_LED_CONTROL_1 0x13
#define IS31FL3218_REG_LED_CONTROL_2 0x14
#define IS31FL3218_REG_LED_CONTROL_3 0x15
#define IS31FL3218_REG_UPDATE 0x16
#define IS31FL3218_REG_RESET 0x17

#define IS31FL3218_I2C_ADDRESS 0x54

#if defined(RGB_MATRIX_IS31FL3218)
Expand Down
40 changes: 10 additions & 30 deletions drivers/led/issi/is31fl3731-simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,6 @@
#include "i2c_master.h"
#include "wait.h"

#define IS31FL3731_REG_CONFIG 0x00
#define IS31FL3731_REG_CONFIG_PICTUREMODE 0x00
#define IS31FL3731_REG_CONFIG_AUTOPLAYMODE 0x08
#define IS31FL3731_REG_CONFIG_AUDIOPLAYMODE 0x18

#define IS31FL3731_CONF_PICTUREMODE 0x00
#define IS31FL3731_CONF_AUTOFRAMEMODE 0x04
#define IS31FL3731_CONF_AUDIOMODE 0x08

#define IS31FL3731_REG_PICTUREFRAME 0x01

// Not defined in the datasheet -- See AN for IC
#define IS31FL3731_REG_GHOST_IMAGE_PREVENTION 0xC2 // Set bit 4 to enable de-ghosting

#define IS31FL3731_REG_SHUTDOWN 0x0A
#define IS31FL3731_REG_AUDIOSYNC 0x06

#define IS31FL3731_COMMANDREGISTER 0xFD
#define IS31FL3731_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine'

#define IS31FL3731_PWM_REGISTER_COUNT 144
#define IS31FL3731_LED_CONTROL_REGISTER_COUNT 18

Expand Down Expand Up @@ -144,26 +124,26 @@ void is31fl3731_init(uint8_t addr) {
// then disable software shutdown.

// select "function register" bank
is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, IS31FL3731_BANK_FUNCTIONREG);
is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, IS31FL3731_COMMAND_FUNCTION);

// enable software shutdown
is31fl3731_write_register(addr, IS31FL3731_REG_SHUTDOWN, 0x00);
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_SHUTDOWN, 0x00);
#ifdef IS31FL3731_DEGHOST // set to enable de-ghosting of the array
is31fl3731_write_register(addr, IS31FL3731_REG_GHOST_IMAGE_PREVENTION, 0x10);
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_GHOST_IMAGE_PREVENTION, IS31FL3731_GHOST_IMAGE_PREVENTION_GEN);
#endif

// this delay was copied from other drivers, might not be needed
wait_ms(10);

// picture mode
is31fl3731_write_register(addr, IS31FL3731_REG_CONFIG, IS31FL3731_REG_CONFIG_PICTUREMODE);
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_CONFIG, IS31FL3731_CONFIG_MODE_PICTURE);
// display frame 0
is31fl3731_write_register(addr, IS31FL3731_REG_PICTUREFRAME, 0x00);
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_PICTURE_DISPLAY, 0x00);
// audio sync off
is31fl3731_write_register(addr, IS31FL3731_REG_AUDIOSYNC, 0x00);
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_AUDIO_SYNC, 0x00);

// select bank 0
is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, 0);
is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, IS31FL3731_COMMAND_FRAME_1);

// turn off all LEDs in the LED control register
for (int i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
Expand All @@ -181,15 +161,15 @@ void is31fl3731_init(uint8_t addr) {
}

// select "function register" bank
is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, IS31FL3731_BANK_FUNCTIONREG);
is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, IS31FL3731_COMMAND_FUNCTION);

// disable software shutdown
is31fl3731_write_register(addr, IS31FL3731_REG_SHUTDOWN, 0x01);
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_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, IS31FL3731_COMMANDREGISTER, 0);
is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, IS31FL3731_COMMAND_FRAME_1);
}

void is31fl3731_set_value(int index, uint8_t value) {
Expand Down
24 changes: 24 additions & 0 deletions drivers/led/issi/is31fl3731-simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@
#define g_is31_leds g_is31fl3731_leds
// ========

#define IS31FL3731_REG_COMMAND 0xFD
#define IS31FL3731_COMMAND_FRAME_1 0x00
#define IS31FL3731_COMMAND_FRAME_2 0x01
#define IS31FL3731_COMMAND_FRAME_3 0x02
#define IS31FL3731_COMMAND_FRAME_4 0x03
#define IS31FL3731_COMMAND_FRAME_5 0x04
#define IS31FL3731_COMMAND_FRAME_6 0x05
#define IS31FL3731_COMMAND_FRAME_7 0x06
#define IS31FL3731_COMMAND_FRAME_8 0x07
#define IS31FL3731_COMMAND_FUNCTION 0x0B

#define IS31FL3731_FUNCTION_REG_CONFIG 0x00
#define IS31FL3731_CONFIG_MODE_PICTURE 0x00
#define IS31FL3731_CONFIG_MODE_AUTO_PLAY 0x08
#define IS31FL3731_CONFIG_MODE_AUDIO_PLAY 0x18

#define IS31FL3731_FUNCTION_REG_PICTURE_DISPLAY 0x01
#define IS31FL3731_FUNCTION_REG_AUDIO_SYNC 0x06
#define IS31FL3731_FUNCTION_REG_SHUTDOWN 0x0A

// Not defined in the datasheet -- See AN for IC
#define IS31FL3731_FUNCTION_REG_GHOST_IMAGE_PREVENTION 0xC2
#define IS31FL3731_GHOST_IMAGE_PREVENTION_GEN 0x10

#define IS31FL3731_I2C_ADDRESS_GND 0x74
#define IS31FL3731_I2C_ADDRESS_SCL 0x75
#define IS31FL3731_I2C_ADDRESS_SDA 0x76
Expand Down
40 changes: 10 additions & 30 deletions drivers/led/issi/is31fl3731.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,6 @@
#include "i2c_master.h"
#include "wait.h"

#define IS31FL3731_REG_CONFIG 0x00
#define IS31FL3731_REG_CONFIG_PICTUREMODE 0x00
#define IS31FL3731_REG_CONFIG_AUTOPLAYMODE 0x08
#define IS31FL3731_REG_CONFIG_AUDIOPLAYMODE 0x18

#define IS31FL3731_CONF_PICTUREMODE 0x00
#define IS31FL3731_CONF_AUTOFRAMEMODE 0x04
#define IS31FL3731_CONF_AUDIOMODE 0x08

#define IS31FL3731_REG_PICTUREFRAME 0x01

// Not defined in the datasheet -- See AN for IC
#define IS31FL3731_REG_GHOST_IMAGE_PREVENTION 0xC2 // Set bit 4 to enable de-ghosting

#define IS31FL3731_REG_SHUTDOWN 0x0A
#define IS31FL3731_REG_AUDIOSYNC 0x06

#define IS31FL3731_COMMANDREGISTER 0xFD
#define IS31FL3731_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine'

#define IS31FL3731_PWM_REGISTER_COUNT 144
#define IS31FL3731_LED_CONTROL_REGISTER_COUNT 18

Expand Down Expand Up @@ -141,26 +121,26 @@ void is31fl3731_init(uint8_t addr) {
// then disable software shutdown.

// select "function register" bank
is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, IS31FL3731_BANK_FUNCTIONREG);
is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, IS31FL3731_COMMAND_FUNCTION);

// enable software shutdown
is31fl3731_write_register(addr, IS31FL3731_REG_SHUTDOWN, 0x00);
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_SHUTDOWN, 0x00);
#ifdef IS31FL3731_DEGHOST // set to enable de-ghosting of the array
is31fl3731_write_register(addr, IS31FL3731_REG_GHOST_IMAGE_PREVENTION, 0x10);
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_GHOST_IMAGE_PREVENTION, IS31FL3731_GHOST_IMAGE_PREVENTION_GEN);
#endif

// this delay was copied from other drivers, might not be needed
wait_ms(10);

// picture mode
is31fl3731_write_register(addr, IS31FL3731_REG_CONFIG, IS31FL3731_REG_CONFIG_PICTUREMODE);
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_CONFIG, IS31FL3731_CONFIG_MODE_PICTURE);
// display frame 0
is31fl3731_write_register(addr, IS31FL3731_REG_PICTUREFRAME, 0x00);
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_PICTURE_DISPLAY, 0x00);
// audio sync off
is31fl3731_write_register(addr, IS31FL3731_REG_AUDIOSYNC, 0x00);
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_AUDIO_SYNC, 0x00);

// select bank 0
is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, 0);
is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, IS31FL3731_COMMAND_FRAME_1);

// turn off all LEDs in the LED control register
for (int i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
Expand All @@ -178,15 +158,15 @@ void is31fl3731_init(uint8_t addr) {
}

// select "function register" bank
is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, IS31FL3731_BANK_FUNCTIONREG);
is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, IS31FL3731_COMMAND_FUNCTION);

// disable software shutdown
is31fl3731_write_register(addr, IS31FL3731_REG_SHUTDOWN, 0x01);
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_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, IS31FL3731_COMMANDREGISTER, 0);
is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, IS31FL3731_COMMAND_FRAME_1);
}

void is31fl3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
Expand Down
Loading