Formatting
This commit is contained in:
parent
6e6858b399
commit
0f86643d26
2 changed files with 131 additions and 133 deletions
|
@ -5,8 +5,8 @@
|
||||||
#define DT_DRV_COMPAT issi_is31fl3733
|
#define DT_DRV_COMPAT issi_is31fl3733
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "SUMMARY"
|
* "SUMMARY"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <drivers/i2c.h>
|
#include <drivers/i2c.h>
|
||||||
#include <drivers/led.h>
|
#include <drivers/led.h>
|
||||||
|
@ -16,11 +16,11 @@
|
||||||
#define LOG_LEVEL CONFIG_LED_LOG_LEVEL
|
#define LOG_LEVEL CONFIG_LED_LOG_LEVEL
|
||||||
#include <logging/log.h>
|
#include <logging/log.h>
|
||||||
LOG_MODULE_REGISTER(is31fl3733);
|
LOG_MODULE_REGISTER(is31fl3733);
|
||||||
/** Number of CS lines. */
|
/** Number of CS lines. */
|
||||||
#define IS31FL3733_CS (16)
|
#define IS31FL3733_CS (16)
|
||||||
/** Number of SW lines. */
|
/** Number of SW lines. */
|
||||||
#define IS31FL3733_SW (12)
|
#define IS31FL3733_SW (12)
|
||||||
/** IS31FL3733 common registers. */
|
/** IS31FL3733 common registers. */
|
||||||
#define IS31FL3733_PSR (0xFD) ///< Page select register. Write only.
|
#define IS31FL3733_PSR (0xFD) ///< Page select register. Write only.
|
||||||
#define IS31FL3733_PSWL (0xFE) ///< Page select register write lock. Read/Write.
|
#define IS31FL3733_PSWL (0xFE) ///< Page select register write lock. Read/Write.
|
||||||
/** Registers in Page 0. */
|
/** Registers in Page 0. */
|
||||||
|
@ -46,29 +46,29 @@ struct is31fl3733_data {
|
||||||
};
|
};
|
||||||
uint8_t leds[IS31FL3733_SW * IS31FL3733_CS / 8];
|
uint8_t leds[IS31FL3733_SW * IS31FL3733_CS / 8];
|
||||||
|
|
||||||
static int is31fl3733_set_page(const struct device *dev, uint16_t addr){
|
static int is31fl3733_set_page(const struct device *dev, uint16_t addr) {
|
||||||
const struct is31fl3733_data *dev_data = dev->data;
|
const struct is31fl3733_data *dev_data = dev->data;
|
||||||
const struct is31fl3733_config *dev_cfg = dev->config;
|
const struct is31fl3733_config *dev_cfg = dev->config;
|
||||||
if (i2c_reg_write_byte(dev_data->i2c, dev_cfg->reg, IS31FL3733_PSWL, IS31FL3733_PSWL_ENABLE)){
|
if (i2c_reg_write_byte(dev_data->i2c, dev_cfg->reg, IS31FL3733_PSWL, IS31FL3733_PSWL_ENABLE)) {
|
||||||
LOG_ERR("Enable write to Page select register failed");
|
LOG_ERR("Enable write to Page select register failed");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
if (i2c_reg_write_byte(dev_data->i2c, dev_cfg->reg, IS31FL3733_PSR, addr)){
|
if (i2c_reg_write_byte(dev_data->i2c, dev_cfg->reg, IS31FL3733_PSR, addr)) {
|
||||||
LOG_ERR("Writing to Page select register failed");
|
LOG_ERR("Writing to Page select register failed");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static int is31fl3733_write_page_reg(const struct device *dev, uint8_t reg, uint8_t buffer){
|
static int is31fl3733_write_page_reg(const struct device *dev, uint8_t reg, uint8_t buffer) {
|
||||||
const struct is31fl3733_data *dev_data = dev->data;
|
const struct is31fl3733_data *dev_data = dev->data;
|
||||||
const struct is31fl3733_config *dev_cfg = dev->config;
|
const struct is31fl3733_config *dev_cfg = dev->config;
|
||||||
if (i2c_reg_write_byte(dev_data->i2c, dev_cfg->reg, reg, buffer)){
|
if (i2c_reg_write_byte(dev_data->i2c, dev_cfg->reg, reg, buffer)) {
|
||||||
LOG_ERR("Writing Page Failed");
|
LOG_ERR("Writing Page Failed");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static int is31fl3733_led_set_brightness(const struct device *dev, uint32_t led, uint8_t value){
|
static int is31fl3733_led_set_brightness(const struct device *dev, uint32_t led, uint8_t value) {
|
||||||
uint8_t cs = led - ((led / 16) * 16);
|
uint8_t cs = led - ((led / 16) * 16);
|
||||||
uint8_t sw = led / 16;
|
uint8_t sw = led / 16;
|
||||||
uint8_t offset = sw * IS31FL3733_CS + cs;
|
uint8_t offset = sw * IS31FL3733_CS + cs;
|
||||||
|
@ -77,7 +77,7 @@ static int is31fl3733_led_set_brightness(const struct device *dev, uint32_t led,
|
||||||
is31fl3733_write_page_reg(dev, offset, value);
|
is31fl3733_write_page_reg(dev, offset, value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static inline int is31fl3733_led_on(const struct device *dev, uint32_t led){
|
static inline int is31fl3733_led_on(const struct device *dev, uint32_t led) {
|
||||||
uint8_t cs = led - ((led / 16) * 16);
|
uint8_t cs = led - ((led / 16) * 16);
|
||||||
uint8_t sw = led / 16;
|
uint8_t sw = led / 16;
|
||||||
uint8_t offset = (sw << 1) + (cs / 8);
|
uint8_t offset = (sw << 1) + (cs / 8);
|
||||||
|
@ -87,7 +87,7 @@ static inline int is31fl3733_led_on(const struct device *dev, uint32_t led){
|
||||||
is31fl3733_write_page_reg(dev, offset, leds[offset]);
|
is31fl3733_write_page_reg(dev, offset, leds[offset]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static inline int is31fl3733_led_off(const struct device *dev, uint32_t led){
|
static inline int is31fl3733_led_off(const struct device *dev, uint32_t led) {
|
||||||
uint8_t cs = led - ((led / 16) * 16);
|
uint8_t cs = led - ((led / 16) * 16);
|
||||||
uint8_t sw = led / 16;
|
uint8_t sw = led / 16;
|
||||||
uint8_t offset = (sw << 1) + (cs / 8);
|
uint8_t offset = (sw << 1) + (cs / 8);
|
||||||
|
@ -97,7 +97,8 @@ static inline int is31fl3733_led_off(const struct device *dev, uint32_t led){
|
||||||
is31fl3733_write_page_reg(dev, offset, leds[offset]);
|
is31fl3733_write_page_reg(dev, offset, leds[offset]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static int is31fl3733_led_set_color(const struct device *dev,uint32_t led, uint8_t num_of_colors, const uint8_t *colors){
|
static int is31fl3733_led_set_color(const struct device *dev, uint32_t led, uint8_t num_of_colors,
|
||||||
|
const uint8_t *colors) {
|
||||||
uint8_t cs = led - ((led / 16) * 16);
|
uint8_t cs = led - ((led / 16) * 16);
|
||||||
uint8_t sw = (led / 16) * 3;
|
uint8_t sw = (led / 16) * 3;
|
||||||
uint8_t offset_red = sw * IS31FL3733_CS + cs;
|
uint8_t offset_red = sw * IS31FL3733_CS + cs;
|
||||||
|
@ -110,10 +111,10 @@ static int is31fl3733_led_set_color(const struct device *dev,uint32_t led, uint8
|
||||||
is31fl3733_write_page_reg(dev, offset_blue, colors[2]);
|
is31fl3733_write_page_reg(dev, offset_blue, colors[2]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static int is31fl3733_led_reset(const struct device *dev){
|
static int is31fl3733_led_reset(const struct device *dev) {
|
||||||
const struct is31fl3733_data *data = dev->data;
|
const struct is31fl3733_data *data = dev->data;
|
||||||
const struct is31fl3733_config *dev_cfg = dev->config;
|
const struct is31fl3733_config *dev_cfg = dev->config;
|
||||||
if (i2c_reg_write_byte(data->i2c, dev_cfg->reg, IS31FL3733_PSWL, IS31FL3733_PSWL_ENABLE)){
|
if (i2c_reg_write_byte(data->i2c, dev_cfg->reg, IS31FL3733_PSWL, IS31FL3733_PSWL_ENABLE)) {
|
||||||
LOG_ERR("Enable write to Page select register failed");
|
LOG_ERR("Enable write to Page select register failed");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
@ -121,16 +122,16 @@ static int is31fl3733_led_reset(const struct device *dev){
|
||||||
uint8_t partB = (uint8_t)(IS31FL3733_RESET & 0x00FF);
|
uint8_t partB = (uint8_t)(IS31FL3733_RESET & 0x00FF);
|
||||||
uint8_t tx_buf[2] = {IS31FL3733_PSR, partA};
|
uint8_t tx_buf[2] = {IS31FL3733_PSR, partA};
|
||||||
// Sequence to reset the IC
|
// Sequence to reset the IC
|
||||||
if (i2c_write(data->i2c,tx_buf, 2, dev_cfg->reg)){
|
if (i2c_write(data->i2c, tx_buf, 2, dev_cfg->reg)) {
|
||||||
LOG_ERR("Reseting Device Failed");
|
LOG_ERR("Reseting Device Failed");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
uint8_t tx_buf2[1] = {partB};
|
uint8_t tx_buf2[1] = {partB};
|
||||||
if (i2c_write(data->i2c, tx_buf2, 1, dev_cfg->reg)){
|
if (i2c_write(data->i2c, tx_buf2, 1, dev_cfg->reg)) {
|
||||||
LOG_ERR("Reseting Device Failed");
|
LOG_ERR("Reseting Device Failed");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
if (i2c_read(data->i2c, NULL, 1, dev_cfg->reg)){
|
if (i2c_read(data->i2c, NULL, 1, dev_cfg->reg)) {
|
||||||
LOG_ERR("Reseting Device Failed");
|
LOG_ERR("Reseting Device Failed");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
@ -144,7 +145,7 @@ static int is31fl3733_led_reset(const struct device *dev){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is31fl3733_led_init(const struct device *dev){
|
static int is31fl3733_led_init(const struct device *dev) {
|
||||||
const struct is31fl3733_config *dev_cfg = dev->config;
|
const struct is31fl3733_config *dev_cfg = dev->config;
|
||||||
struct is31fl3733_data *dev_data = dev->data;
|
struct is31fl3733_data *dev_data = dev->data;
|
||||||
dev_data->i2c = device_get_binding(dev_cfg->bus_name);
|
dev_data->i2c = device_get_binding(dev_cfg->bus_name);
|
||||||
|
@ -168,16 +169,13 @@ static const struct led_driver_api is31fl3733_led_api = {
|
||||||
.set_color = is31fl3733_led_set_color,
|
.set_color = is31fl3733_led_set_color,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define IS31FL3733_INIT(inst) \
|
#define IS31FL3733_INIT(inst) \
|
||||||
static struct is31fl3733_data is31fl3733_led_data_##inst; \
|
static struct is31fl3733_data is31fl3733_led_data_##inst; \
|
||||||
static const struct is31fl3733_config is31fl3733_config_##inst = { \
|
static const struct is31fl3733_config is31fl3733_config_##inst = { \
|
||||||
.bus_name = DT_INST_BUS_LABEL(inst), \
|
.bus_name = DT_INST_BUS_LABEL(inst), \
|
||||||
.reg = DT_INST_REG_ADDR(inst), \
|
.reg = DT_INST_REG_ADDR(inst), \
|
||||||
}; \
|
}; \
|
||||||
DEVICE_AND_API_INIT(is31fl3733_led##inst, DT_INST_LABEL(inst), \
|
DEVICE_AND_API_INIT(is31fl3733_led##inst, DT_INST_LABEL(inst), &is31fl3733_led_init, \
|
||||||
&is31fl3733_led_init, &is31fl3733_led_data_##inst, \
|
&is31fl3733_led_data_##inst, &is31fl3733_config_##inst, POST_KERNEL, \
|
||||||
&is31fl3733_config_##inst, POST_KERNEL, CONFIG_LED_INIT_PRIORITY, \
|
CONFIG_LED_INIT_PRIORITY, &is31fl3733_led_api);
|
||||||
&is31fl3733_led_api);
|
|
||||||
DT_INST_FOREACH_STATUS_OKAY(IS31FL3733_INIT)
|
DT_INST_FOREACH_STATUS_OKAY(IS31FL3733_INIT)
|
||||||
|
|
Loading…
Add table
Reference in a new issue