Bring the driver up to date
This commit is contained in:
parent
01a93c70c8
commit
206f9da7af
12 changed files with 455 additions and 165 deletions
|
@ -1,4 +0,0 @@
|
|||
# Copyright (c) 2020 The ZMK Contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
add_subdirectory_ifdef(CONFIG_IS31FL3743A is31fl3743a)
|
|
@ -1,10 +0,0 @@
|
|||
# Copyright (c) 2020 The ZMK Contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
rsource "is31fl3743a/Kconfig"
|
||||
|
||||
config LEG_STRIP_INIT_PRIORITY
|
||||
int "LED strip initialization priority"
|
||||
default 90
|
||||
help
|
||||
System initialization priority for LED strip drivers.
|
|
@ -1,6 +0,0 @@
|
|||
# Copyright (c) 2020 The ZMK Contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
zephyr_library()
|
||||
|
||||
zephyr_library_sources(is31fl3743a.c)
|
|
@ -1,20 +0,0 @@
|
|||
# Copyright (c) 2020 The ZMK Contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
config IS31FL3743A
|
||||
bool "IS31FL3743A LED Matrix driver"
|
||||
depends on I2C
|
||||
help
|
||||
Enable an IS31FL3743A LED Matrix driver.
|
||||
|
||||
The IS31FL3743A is a general purpose 18xn(n=1-11) LED Matrix
|
||||
programmed via 1MHz I2C compatible interface. Each LED can be
|
||||
dimmed individually with 8-bit PWM data and 8-bit DC scaling data
|
||||
which allows 256 steps of linear PWM dimming and 256 steps of DC
|
||||
current adjustable levels.
|
||||
|
||||
config LED_STRIP_INIT_PRIORITY
|
||||
int "LED strip initialization priority"
|
||||
default 90
|
||||
help
|
||||
System initialization priority for LED strip drivers.
|
|
@ -28,24 +28,21 @@ properties:
|
|||
SW setting used to control the matrix size by turning off SWx pins
|
||||
as described in the datasheet.
|
||||
|
||||
cs-order:
|
||||
type: uint8-array
|
||||
required: false
|
||||
default: [0x02, 0x01, 0x00, 0x05, 0x04, 0x03, 0x08, 0x07, 0x06, 0x0B, 0x0A, 0x09, 0x0E, 0x0D, 0x0C, 0x11, 0x10, 0x0F]
|
||||
map:
|
||||
type: array
|
||||
required: true
|
||||
description: |
|
||||
Stores the configuration of CS* pins.
|
||||
Each 3 consecutive numbers must be R, G and B pins for a single LED.
|
||||
Matches the reference design from the datasheet by default.
|
||||
Configure how RGB pixels are mapped to individual pixel registers.
|
||||
|
||||
riset:
|
||||
r-ext:
|
||||
type: int
|
||||
required: true
|
||||
description: Riset resistor value in kiloohms.
|
||||
description: Rext resistor value in kiloohms.
|
||||
|
||||
led-max-current:
|
||||
type: int
|
||||
required: true
|
||||
description: Maximum allowed LED current in mAh. The maximum allowed by the chip is 34.
|
||||
description: Maximum current for each LED in mA. The chip supports up to 34mA.
|
||||
|
||||
sync:
|
||||
type: int
|
||||
|
@ -56,10 +53,311 @@ properties:
|
|||
required: false
|
||||
default: 0x00
|
||||
description: |
|
||||
Controls the SYNC function. Set to 0x11 to set the device as main or 0x10 for secondary.
|
||||
Controls the SYNC function. Set to 0x11 to set the device as main or 0x10 for secondary. 0x00 for 'off'.
|
||||
|
||||
sdb-gpios:
|
||||
type: phandle-array
|
||||
required: true
|
||||
required: false
|
||||
description: |
|
||||
GPIO pin for hardware shutdown functionality.
|
||||
|
||||
chain-length:
|
||||
type: int
|
||||
required: true
|
||||
description: |
|
||||
How many RGB LEDs are driven by the IC.
|
||||
|
||||
scaling-red:
|
||||
type: int
|
||||
required: false
|
||||
default: 255
|
||||
description: |
|
||||
Current scaling factor for red channel LEDs on a scale of 0-255.
|
||||
This setting adjusts the brightness of red pixels relative to other channels by scaling
|
||||
the amount of current flowing through them. 255 equals led-max-current.
|
||||
|
||||
scaling-green:
|
||||
type: int
|
||||
required: false
|
||||
default: 255
|
||||
description: |
|
||||
Current scaling factor for green channel LEDs on a scale of 0-255.
|
||||
This setting adjusts the brightness of green pixels relative to other channels by scaling
|
||||
the amount of current flowing through them. 255 equals led-max-current.
|
||||
|
||||
scaling-blue:
|
||||
type: int
|
||||
required: false
|
||||
default: 255
|
||||
description: |
|
||||
Current scaling factor for blue channel LEDs on a scale of 0-255.
|
||||
This setting adjusts the brightness of blue pixels relative to other channels by scaling
|
||||
the amount of current flowing through them. 255 equals led-max-current.
|
||||
|
||||
gamma:
|
||||
type: array
|
||||
required: false
|
||||
description: |
|
||||
Gamma correction lookup values.
|
||||
The gamma values make the LED brightness seem more linear to human eyes.
|
||||
Default values match the recommendation from the IC datasheet but note that this may
|
||||
or may not apply for your particular LEDs.
|
||||
default:
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
3,
|
||||
3,
|
||||
3,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
5,
|
||||
5,
|
||||
5,
|
||||
6,
|
||||
6,
|
||||
6,
|
||||
6,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
8,
|
||||
8,
|
||||
8,
|
||||
8,
|
||||
10,
|
||||
10,
|
||||
10,
|
||||
10,
|
||||
12,
|
||||
12,
|
||||
12,
|
||||
12,
|
||||
14,
|
||||
14,
|
||||
14,
|
||||
14,
|
||||
16,
|
||||
16,
|
||||
16,
|
||||
16,
|
||||
18,
|
||||
18,
|
||||
18,
|
||||
18,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
26,
|
||||
26,
|
||||
26,
|
||||
26,
|
||||
29,
|
||||
29,
|
||||
29,
|
||||
29,
|
||||
32,
|
||||
32,
|
||||
32,
|
||||
32,
|
||||
35,
|
||||
35,
|
||||
35,
|
||||
35,
|
||||
38,
|
||||
38,
|
||||
38,
|
||||
38,
|
||||
41,
|
||||
41,
|
||||
41,
|
||||
41,
|
||||
44,
|
||||
44,
|
||||
44,
|
||||
44,
|
||||
47,
|
||||
47,
|
||||
47,
|
||||
47,
|
||||
50,
|
||||
50,
|
||||
50,
|
||||
50,
|
||||
53,
|
||||
53,
|
||||
53,
|
||||
53,
|
||||
57,
|
||||
57,
|
||||
57,
|
||||
57,
|
||||
61,
|
||||
61,
|
||||
61,
|
||||
61,
|
||||
65,
|
||||
65,
|
||||
65,
|
||||
65,
|
||||
69,
|
||||
69,
|
||||
69,
|
||||
69,
|
||||
73,
|
||||
73,
|
||||
73,
|
||||
73,
|
||||
77,
|
||||
77,
|
||||
77,
|
||||
77,
|
||||
81,
|
||||
81,
|
||||
81,
|
||||
81,
|
||||
85,
|
||||
85,
|
||||
85,
|
||||
85,
|
||||
89,
|
||||
89,
|
||||
89,
|
||||
89,
|
||||
94,
|
||||
94,
|
||||
94,
|
||||
94,
|
||||
99,
|
||||
99,
|
||||
99,
|
||||
99,
|
||||
104,
|
||||
104,
|
||||
104,
|
||||
104,
|
||||
109,
|
||||
109,
|
||||
109,
|
||||
109,
|
||||
114,
|
||||
114,
|
||||
114,
|
||||
114,
|
||||
119,
|
||||
119,
|
||||
119,
|
||||
119,
|
||||
124,
|
||||
124,
|
||||
124,
|
||||
124,
|
||||
129,
|
||||
129,
|
||||
129,
|
||||
129,
|
||||
134,
|
||||
134,
|
||||
134,
|
||||
134,
|
||||
140,
|
||||
140,
|
||||
140,
|
||||
140,
|
||||
146,
|
||||
146,
|
||||
146,
|
||||
146,
|
||||
152,
|
||||
152,
|
||||
152,
|
||||
152,
|
||||
158,
|
||||
158,
|
||||
158,
|
||||
158,
|
||||
164,
|
||||
164,
|
||||
164,
|
||||
164,
|
||||
170,
|
||||
170,
|
||||
170,
|
||||
170,
|
||||
176,
|
||||
176,
|
||||
176,
|
||||
176,
|
||||
182,
|
||||
182,
|
||||
182,
|
||||
182,
|
||||
188,
|
||||
188,
|
||||
188,
|
||||
188,
|
||||
195,
|
||||
195,
|
||||
195,
|
||||
195,
|
||||
202,
|
||||
202,
|
||||
202,
|
||||
202,
|
||||
209,
|
||||
209,
|
||||
209,
|
||||
209,
|
||||
216,
|
||||
216,
|
||||
216,
|
||||
216,
|
||||
223,
|
||||
223,
|
||||
223,
|
||||
223,
|
||||
230,
|
||||
230,
|
||||
230,
|
||||
230,
|
||||
237,
|
||||
237,
|
||||
237,
|
||||
237,
|
||||
244,
|
||||
244,
|
||||
244,
|
||||
244,
|
||||
251,
|
||||
251,
|
||||
251,
|
||||
251,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
]
|
||||
|
|
10
app/include/dt-bindings/zmk/is31fl3743_transform.h
Normal file
10
app/include/dt-bindings/zmk/is31fl3743_transform.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* Copyright (c) 2024 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#define RGB(com, r, g, b) (com + r)(com + g)(com + b)
|
||||
|
||||
#define SW(n) ((n - 1) * 18)
|
||||
#define CS(n) (n - 1)
|
|
@ -5,3 +5,4 @@ add_subdirectory_ifdef(CONFIG_GPIO gpio)
|
|||
add_subdirectory_ifdef(CONFIG_KSCAN kscan)
|
||||
add_subdirectory_ifdef(CONFIG_SENSOR sensor)
|
||||
add_subdirectory_ifdef(CONFIG_DISPLAY display)
|
||||
add_subdirectory_ifdef(CONFIG_LED_STRIP led_strip)
|
||||
|
|
6
app/module/drivers/led_strip/CMakeLists.txt
Normal file
6
app/module/drivers/led_strip/CMakeLists.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
# Copyright (c) 2020 The ZMK Contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
zephyr_library_amend()
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_IS31FL3743A is31fl3743a.c)
|
8
app/module/drivers/led_strip/Kconfig
Normal file
8
app/module/drivers/led_strip/Kconfig
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Copyright (c) 2021 The ZMK Contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
if LED_STRIP
|
||||
|
||||
rsource "Kconfig.is31fl3743a"
|
||||
|
||||
endif # LED_STRIP
|
15
app/module/drivers/led_strip/Kconfig.is31fl3743a
Normal file
15
app/module/drivers/led_strip/Kconfig.is31fl3743a
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Copyright (c) 2020 The ZMK Contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
config IS31FL3743A
|
||||
bool "IS31FL3743A LED matrix driver"
|
||||
depends on I2C
|
||||
depends on LED_STRIP
|
||||
help
|
||||
Enable an IS31FL3743A LED matrix driver.
|
||||
|
||||
The IS31FL3743A is a general purpose 18xn(n=1-11) LED matrix
|
||||
programmed via 1MHz I2C compatible interface. Each LED can be
|
||||
dimmed individually with 8-bit PWM data and 8-bit DC scaling data
|
||||
which allows 256 steps of linear PWM dimming and 256 steps of DC
|
||||
current adjustable levels.
|
|
@ -6,22 +6,20 @@
|
|||
|
||||
#define DT_DRV_COMPAT issi_is31fl3743a
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <device.h>
|
||||
#include <drivers/gpio.h>
|
||||
#include <drivers/i2c.h>
|
||||
#include <drivers/led_strip.h>
|
||||
#include <logging/log.h>
|
||||
#include <sys/math_extras.h>
|
||||
#include <sys/util.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/drivers/i2c.h>
|
||||
#include <zephyr/drivers/led_strip.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/sys/math_extras.h>
|
||||
#include <zephyr/sys/util.h>
|
||||
|
||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
|
||||
#define IS31FL3743A_CS_PINS 18
|
||||
#define IS31FL3743A_SW_PINS 11
|
||||
#define IS31FL3743A_REG_PS (0xfd)
|
||||
#define IS31FL3743A_REG_PSWL (0xfe)
|
||||
|
||||
#define IS31FL3743A_PSR (0xfd)
|
||||
#define IS31FL3743A_PSWL (0xfe)
|
||||
#define IS31FL3743A_PSWL_ENABLE (0xc5)
|
||||
#define IS31FL3743A_PSWL_DISABLE (0x00)
|
||||
|
||||
|
@ -30,32 +28,30 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
|||
#define IS31FL3743A_PAGE_FUNCTION (0x02)
|
||||
|
||||
struct is31fl3743a_config {
|
||||
char *bus;
|
||||
int reg;
|
||||
char *label;
|
||||
char *sdb_port;
|
||||
gpio_pin_t sdb_pin;
|
||||
gpio_dt_flags_t sdb_flags;
|
||||
uint8_t *px_buffer;
|
||||
struct i2c_dt_spec i2c;
|
||||
struct gpio_dt_spec gpio;
|
||||
size_t px_buffer_size;
|
||||
uint8_t gcc;
|
||||
uint8_t sws;
|
||||
uint8_t sync;
|
||||
uint8_t *cs_map;
|
||||
uint8_t *rgb_map;
|
||||
uint8_t *gamma;
|
||||
uint8_t scaling_red;
|
||||
uint8_t scaling_green;
|
||||
uint8_t scaling_blue;
|
||||
};
|
||||
|
||||
struct is31fl3743a_data {
|
||||
const struct device *i2c;
|
||||
const struct device *gpio;
|
||||
uint8_t *px_buffer;
|
||||
};
|
||||
|
||||
static int is31fl3743a_reg_write(const struct device *dev, uint8_t addr, uint8_t value) {
|
||||
const struct is31fl3743a_data *data = dev->data;
|
||||
const struct is31fl3743a_config *config = dev->config;
|
||||
|
||||
if (i2c_reg_write_byte(data->i2c, config->reg, addr, value)) {
|
||||
if (i2c_reg_write_byte_dt(&config->i2c, addr, value)) {
|
||||
LOG_ERR("Failed writing value %x to register address %x on device %x.", value, addr,
|
||||
config->reg);
|
||||
config->i2c.addr);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
@ -64,11 +60,10 @@ static int is31fl3743a_reg_write(const struct device *dev, uint8_t addr, uint8_t
|
|||
|
||||
static int is31fl3743a_reg_burst_write(const struct device *dev, uint8_t start_addr,
|
||||
const uint8_t *buffer, size_t num_bytes) {
|
||||
const struct is31fl3743a_data *data = dev->data;
|
||||
const struct is31fl3743a_config *config = dev->config;
|
||||
|
||||
if (i2c_burst_write(data->i2c, config->reg, start_addr, buffer, num_bytes)) {
|
||||
LOG_ERR("Failed burst write with starting address %x", start_addr);
|
||||
if (i2c_burst_write_dt(&config->i2c, start_addr, buffer, num_bytes)) {
|
||||
LOG_ERR("Failed burst write with starting address %x.", start_addr);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
@ -76,11 +71,11 @@ static int is31fl3743a_reg_burst_write(const struct device *dev, uint8_t start_a
|
|||
}
|
||||
|
||||
static int is31fl3743a_set_page(const struct device *dev, uint8_t page_addr) {
|
||||
if (is31fl3743a_reg_write(dev, IS31FL3743A_PSWL, IS31FL3743A_PSWL_ENABLE)) {
|
||||
if (is31fl3743a_reg_write(dev, IS31FL3743A_REG_PSWL, IS31FL3743A_PSWL_ENABLE)) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
if (is31fl3743a_reg_write(dev, IS31FL3743A_PSR, page_addr)) {
|
||||
if (is31fl3743a_reg_write(dev, IS31FL3743A_REG_PS, page_addr)) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
@ -95,43 +90,6 @@ static inline bool num_pixels_ok(const struct is31fl3743a_config *config, size_t
|
|||
return !overflow && (num_bytes <= config->px_buffer_size);
|
||||
}
|
||||
|
||||
/*
|
||||
* Updates the RGB LED matrix using cs-order devicetree property
|
||||
* to assign correct R,G,B channels.
|
||||
*/
|
||||
static int is31fl3743a_strip_update_rgb(const struct device *dev, struct led_rgb *pixels,
|
||||
size_t num_pixels) {
|
||||
const struct is31fl3743a_config *config = dev->config;
|
||||
|
||||
uint8_t *px_buffer = config->px_buffer;
|
||||
uint8_t *cs_map = config->cs_map;
|
||||
|
||||
size_t sw_offset = 0;
|
||||
size_t cs = 0;
|
||||
|
||||
if (!num_pixels_ok(config, num_pixels)) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < num_pixels; ++i) {
|
||||
px_buffer[sw_offset + cs_map[cs++]] = pixels[i].r;
|
||||
px_buffer[sw_offset + cs_map[cs++]] = pixels[i].g;
|
||||
px_buffer[sw_offset + cs_map[cs++]] = pixels[i].b;
|
||||
|
||||
if (IS31FL3743A_CS_PINS <= cs) {
|
||||
cs = 0;
|
||||
sw_offset += IS31FL3743A_CS_PINS;
|
||||
}
|
||||
}
|
||||
|
||||
if (is31fl3743a_set_page(dev, IS31FL3743A_PAGE_PWM)) {
|
||||
LOG_ERR("Failed to set PWM page on %s", config->label);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return is31fl3743a_reg_burst_write(dev, 0x01, px_buffer, config->px_buffer_size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates individual LED channels without an RGB interpretation.
|
||||
*/
|
||||
|
@ -143,68 +101,97 @@ static int is31fl3743a_strip_update_channels(const struct device *dev, uint8_t *
|
|||
return -ENOMEM;
|
||||
}
|
||||
|
||||
is31fl3743a_set_page(dev, IS31FL3743A_PAGE_PWM);
|
||||
|
||||
return is31fl3743a_reg_burst_write(dev, 0x01, channels, num_channels);
|
||||
}
|
||||
|
||||
/*
|
||||
* Updates the RGB LED matrix according to devicetree's map property.
|
||||
*/
|
||||
static int is31fl3743a_strip_update_rgb(const struct device *dev, struct led_rgb *pixels,
|
||||
size_t num_pixels) {
|
||||
const struct is31fl3743a_config *config = dev->config;
|
||||
const struct is31fl3743a_data *data = dev->data;
|
||||
|
||||
size_t pixel_idx = 0;
|
||||
size_t led_idx = 0;
|
||||
|
||||
if (!num_pixels_ok(config, num_pixels)) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
while (pixel_idx < num_pixels) {
|
||||
data->px_buffer[config->rgb_map[led_idx++]] = config->gamma[pixels[pixel_idx].r];
|
||||
data->px_buffer[config->rgb_map[led_idx++]] = config->gamma[pixels[pixel_idx].g];
|
||||
data->px_buffer[config->rgb_map[led_idx++]] = config->gamma[pixels[pixel_idx].b];
|
||||
|
||||
++pixel_idx;
|
||||
}
|
||||
|
||||
return is31fl3743a_strip_update_channels(dev, data->px_buffer, config->px_buffer_size);
|
||||
}
|
||||
|
||||
/*
|
||||
* Initiates a driver instance for IS31FL3743A.
|
||||
*
|
||||
* SDB is pulled high to enable chip operation followed
|
||||
* by a reset to clear out all previous values.
|
||||
* If available, SDB is pulled high to enable chip operation,
|
||||
* followed by a reset to clear out all previous values.
|
||||
*
|
||||
* Function and scaling registers are then pre-configured based on devicetree settings.
|
||||
*/
|
||||
int static is31fl3743a_init(const struct device *dev) {
|
||||
struct is31fl3743a_data *data = dev->data;
|
||||
const struct is31fl3743a_config *config = dev->config;
|
||||
const struct is31fl3743a_data *data = dev->data;
|
||||
|
||||
data->i2c = device_get_binding(config->bus);
|
||||
|
||||
if (data->i2c == NULL) {
|
||||
LOG_ERR("I2C device %s not found", config->bus);
|
||||
if (!device_is_ready(config->i2c.bus)) {
|
||||
LOG_ERR("I2C device %s is not ready", config->i2c.bus->name);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
data->gpio = device_get_binding(config->sdb_port);
|
||||
|
||||
if (data->gpio == NULL) {
|
||||
LOG_ERR("GPIO device %s not found", config->sdb_port);
|
||||
if (!device_is_ready(config->gpio.port)) {
|
||||
LOG_ERR("GPIO device for %s is not ready", config->label);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
gpio_pin_configure(data->gpio, config->sdb_pin, (GPIO_OUTPUT | config->sdb_flags));
|
||||
if (gpio_pin_configure_dt(&config->gpio, GPIO_OUTPUT)) {
|
||||
LOG_ERR("SDB pin for %s cannot be configured", config->label);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
if (gpio_pin_set(data->gpio, config->sdb_pin, 1)) {
|
||||
if (gpio_pin_set_dt(&config->gpio, 1)) {
|
||||
LOG_ERR("SDB pin for %s cannot be pulled high", config->label);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
// Set configuration registers
|
||||
if (is31fl3743a_set_page(dev, IS31FL3743A_PAGE_FUNCTION)) {
|
||||
LOG_ERR("Couldn't switch to function registers on %s", config->label);
|
||||
return -EIO;
|
||||
// Reset settings
|
||||
is31fl3743a_set_page(dev, IS31FL3743A_PAGE_FUNCTION);
|
||||
is31fl3743a_reg_write(dev, 0x2f, 0xae);
|
||||
|
||||
// Set configuration & GCC registers
|
||||
is31fl3743a_set_page(dev, IS31FL3743A_PAGE_FUNCTION);
|
||||
is31fl3743a_reg_write(dev, 0x00, (config->sws << 4) | (0x01 << 3) | 0x01); // Configuration
|
||||
is31fl3743a_reg_write(dev, 0x01, config->gcc); // GCC
|
||||
|
||||
// Set scaling registers
|
||||
uint8_t *px_buffer = data->px_buffer;
|
||||
uint8_t *rgb_map = config->rgb_map;
|
||||
|
||||
for (size_t i = 0; i < config->px_buffer_size; i += 3) {
|
||||
px_buffer[rgb_map[i]] = config->scaling_red;
|
||||
px_buffer[rgb_map[i + 1]] = config->scaling_green;
|
||||
px_buffer[rgb_map[i + 2]] = config->scaling_blue;
|
||||
}
|
||||
|
||||
is31fl3743a_reg_write(dev, 0x2f, 0xae); // Reset
|
||||
is31fl3743a_reg_write(
|
||||
dev, 0x00, (config->sws << 4) | (0x01 << 3) | 0x01); // SWS, H logic, Normal operation
|
||||
is31fl3743a_reg_write(dev, 0x01, config->gcc); // Set GCC
|
||||
is31fl3743a_reg_write(dev, 0x24, 0x08); // Thermal shutoff at 100*C, put into DT
|
||||
is31fl3743a_reg_write(dev, 0x25, (config->sync << 6)); // Set SYNC setting
|
||||
|
||||
// Set scaling registers, default to 0xff
|
||||
if (is31fl3743a_set_page(dev, IS31FL3743A_PAGE_SCALING)) {
|
||||
LOG_ERR("Couldn't switch to scaling registers on %s", config->label);
|
||||
}
|
||||
|
||||
uint8_t scaling_buffer[config->px_buffer_size];
|
||||
is31fl3743a_set_page(dev, IS31FL3743A_PAGE_SCALING);
|
||||
is31fl3743a_reg_burst_write(dev, 0x01, px_buffer, num_pixels);
|
||||
|
||||
// Re-initialize px_buffer to prevent any scaling values from sticking around
|
||||
// when updating PWN registers during normal operation.
|
||||
for (size_t i = 0; i < config->px_buffer_size; ++i) {
|
||||
px_buffer[i] = 0xff;
|
||||
px_buffer[i] = 0;
|
||||
}
|
||||
|
||||
is31fl3743a_reg_burst_write(dev, 0x01, scaling_buffer, config->px_buffer_size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -217,33 +204,38 @@ static const struct led_strip_driver_api is31fl3743a_api = {
|
|||
IS31FL3743A_CS_PINS *(IS31FL3743A_SW_PINS - DT_INST_PROP(idx, sw_setting))
|
||||
|
||||
#define IS31FL3743A_GCC(idx) \
|
||||
(DT_INST_PROP(idx, riset) * DT_INST_PROP(idx, led_max_current) * 256 * 256) / (343 * 255)
|
||||
(DT_INST_PROP(idx, r_ext) * DT_INST_PROP(idx, led_max_current) * 256 * 256) / (343 * 255)
|
||||
|
||||
#define IS31FL3743A_DEVICE(idx) \
|
||||
\
|
||||
static struct is31fl3743a_data is31fl3743a_##idx##_data; \
|
||||
\
|
||||
static uint8_t is31fl3743a_##idx##_px_buffer[IS31FL3743A_BUFFER_SIZE(idx)]; \
|
||||
\
|
||||
static uint8_t is31fl3743a_##idx##_cs_map[] = DT_INST_PROP(idx, cs_order); \
|
||||
static struct is31fl3743a_data is31fl3743a_##idx##_data = { \
|
||||
.px_buffer = is31fl3743a_##idx##_px_buffer, \
|
||||
}; \
|
||||
\
|
||||
static uint8_t is31fl3743a_##idx##_rgb_map[IS31FL3743A_BUFFER_SIZE(idx)] = \
|
||||
DT_INST_PROP(idx, map); \
|
||||
\
|
||||
static uint8_t is31fl3743a_##idx##_gamma[] = DT_INST_PROP(idx, gamma); \
|
||||
\
|
||||
static const struct is31fl3743a_config is31fl3743a_##idx##_config = { \
|
||||
.bus = DT_INST_BUS_LABEL(idx), \
|
||||
.reg = DT_INST_REG_ADDR(idx), \
|
||||
.label = DT_INST_LABEL(idx), \
|
||||
.sdb_port = DT_INST_GPIO_LABEL(idx, sdb_gpios), \
|
||||
.sdb_pin = DT_INST_GPIO_PIN(idx, sdb_gpios), \
|
||||
.sdb_flags = DT_INST_GPIO_FLAGS(idx, sdb_gpios), \
|
||||
.px_buffer = is31fl3743a_##idx##_px_buffer, \
|
||||
.i2c = I2C_DT_SPEC_INST_GET(idx), \
|
||||
.gpio = GPIO_DT_SPEC_INST_GET(idx, sdb_gpios), \
|
||||
.px_buffer_size = IS31FL3743A_BUFFER_SIZE(idx), \
|
||||
.gcc = IS31FL3743A_GCC(idx), \
|
||||
.sws = DT_INST_PROP(idx, sw_setting), \
|
||||
.sync = DT_INST_PROP(idx, sync), \
|
||||
.cs_map = is31fl3743a_##idx##_cs_map, \
|
||||
.rgb_map = is31fl3743a_##idx##_rgb_map, \
|
||||
.gamma = is31fl3743a_##idx##_gamma, \
|
||||
.scaling_red = DT_INST_PROP(idx, scaling_red), \
|
||||
.scaling_green = DT_INST_PROP(idx, scaling_green), \
|
||||
.scaling_blue = DT_INST_PROP(idx, scaling_blue), \
|
||||
}; \
|
||||
\
|
||||
DEVICE_AND_API_INIT(is31fl3743a_##idx, DT_INST_LABEL(idx), &is31fl3743a_init, \
|
||||
&is31fl3743a_##idx##_data, &is31fl3743a_##idx##_config, POST_KERNEL, \
|
||||
DEVICE_DT_INST_DEFINE(idx, &is31fl3743a_init, NULL, &is31fl3743a_##idx##_data, \
|
||||
&is31fl3743a_##idx##_config, POST_KERNEL, \
|
||||
CONFIG_LED_STRIP_INIT_PRIORITY, &is31fl3743a_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(IS31FL3743A_DEVICE);
|
Loading…
Add table
Reference in a new issue