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 <emdj@bang-olufsen.dk>
This commit is contained in:
Emil Dahl Juhl 2024-11-17 21:32:20 +01:00 committed by Benjamin Cabé
commit d6ac9e8424
2 changed files with 19 additions and 0 deletions

View file

@ -141,6 +141,7 @@ Drivers and Sensors
* Added a new set of devicetree based LED APIs, see :c:struct:`led_dt_spec`. * Added a new set of devicetree based LED APIs, see :c:struct:`led_dt_spec`.
* lp5569: added use of auto-increment functionality. * lp5569: added use of auto-increment functionality.
* lp5569: implemented ``write_channels`` api.
* LED Strip * LED Strip

View file

@ -77,6 +77,23 @@ static inline int lp5569_led_off(const struct device *dev, uint32_t led)
return lp5569_led_set_brightness(dev, led, 0); return lp5569_led_set_brightness(dev, led, 0);
} }
static int lp5569_write_channels(const struct device *dev, uint32_t start_channel,
uint32_t num_channels, const uint8_t *buf)
{
const struct lp5569_config *config = dev->config;
uint32_t i2c_len = num_channels + 1;
uint8_t i2c_msg[LP5569_NUM_LEDS + 1];
if ((uint64_t)start_channel + num_channels > LP5569_NUM_LEDS) {
return -EINVAL;
}
i2c_msg[0] = LP5569_LED0_PWM + start_channel;
memcpy(&i2c_msg[1], buf, num_channels);
return i2c_write_dt(&config->bus, i2c_msg, i2c_len);
}
static int lp5569_enable(const struct device *dev) static int lp5569_enable(const struct device *dev)
{ {
const struct lp5569_config *config = dev->config; const struct lp5569_config *config = dev->config;
@ -170,6 +187,7 @@ static const struct led_driver_api lp5569_led_api = {
.set_brightness = lp5569_led_set_brightness, .set_brightness = lp5569_led_set_brightness,
.on = lp5569_led_on, .on = lp5569_led_on,
.off = lp5569_led_off, .off = lp5569_led_off,
.write_channels = lp5569_write_channels,
}; };
#define LP5569_DEFINE(id) \ #define LP5569_DEFINE(id) \