Skip to content

Commit d6ac9e8

Browse files
Emil Dahl Juhlkartben
authored andcommitted
drivers: led: lp5569: implement write_channels api
The lp5569 has multiple pwm outputs, and thus implementing the write_channels api to set multiple values in a single call makes sense. Implement the write_channels function with a basic range check on the channel range. Since the lp5569 supports auto-increment, all of the channels can be written in one i2c transfer, starting from the pwm register of the start_channel. Signed-off-by: Emil Dahl Juhl <[email protected]>
1 parent 45744b4 commit d6ac9e8

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

doc/releases/release-notes-4.1.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ Drivers and Sensors
141141

142142
* Added a new set of devicetree based LED APIs, see :c:struct:`led_dt_spec`.
143143
* lp5569: added use of auto-increment functionality.
144+
* lp5569: implemented ``write_channels`` api.
144145

145146
* LED Strip
146147

drivers/led/lp5569.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,23 @@ static inline int lp5569_led_off(const struct device *dev, uint32_t led)
7777
return lp5569_led_set_brightness(dev, led, 0);
7878
}
7979

80+
static int lp5569_write_channels(const struct device *dev, uint32_t start_channel,
81+
uint32_t num_channels, const uint8_t *buf)
82+
{
83+
const struct lp5569_config *config = dev->config;
84+
uint32_t i2c_len = num_channels + 1;
85+
uint8_t i2c_msg[LP5569_NUM_LEDS + 1];
86+
87+
if ((uint64_t)start_channel + num_channels > LP5569_NUM_LEDS) {
88+
return -EINVAL;
89+
}
90+
91+
i2c_msg[0] = LP5569_LED0_PWM + start_channel;
92+
memcpy(&i2c_msg[1], buf, num_channels);
93+
94+
return i2c_write_dt(&config->bus, i2c_msg, i2c_len);
95+
}
96+
8097
static int lp5569_enable(const struct device *dev)
8198
{
8299
const struct lp5569_config *config = dev->config;
@@ -170,6 +187,7 @@ static const struct led_driver_api lp5569_led_api = {
170187
.set_brightness = lp5569_led_set_brightness,
171188
.on = lp5569_led_on,
172189
.off = lp5569_led_off,
190+
.write_channels = lp5569_write_channels,
173191
};
174192

175193
#define LP5569_DEFINE(id) \

0 commit comments

Comments
 (0)