Skip to content

Commit

Permalink
drivers: led: lp5569: implement write_channels api
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Emil-Juhl committed Nov 17, 2024
1 parent 8a78596 commit e59c459
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions drivers/led/lp5569.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

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[i2c_len];

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)
{
const struct lp5569_config *config = dev->config;
Expand Down Expand Up @@ -170,6 +187,7 @@ static const struct led_driver_api lp5569_led_api = {
.set_brightness = lp5569_led_set_brightness,
.on = lp5569_led_on,
.off = lp5569_led_off,
.write_channels = lp5569_write_channels,
};

#define LP5569_DEFINE(id) \
Expand Down

0 comments on commit e59c459

Please sign in to comment.