Lines Matching +full:led +full:- +full:current

4  * SPDX-License-Identifier: Apache-2.0
11 * @brief IS31FL3194 LED driver
13 * The IS31FL3194 is a 3-channel LED driver that communicates over I2C.
18 #include <zephyr/drivers/led.h>
22 #include <zephyr/dt-bindings/led/led.h>
54 uint32_t led) in is31fl3194_led_to_info() argument
56 if (led < config->num_leds) { in is31fl3194_led_to_info()
57 return &config->led_infos[led]; in is31fl3194_led_to_info()
64 uint32_t led, in is31fl3194_get_info() argument
67 const struct is31fl3194_config *config = dev->config; in is31fl3194_get_info()
68 const struct led_info *info = is31fl3194_led_to_info(config, led); in is31fl3194_get_info()
71 return -EINVAL; in is31fl3194_get_info()
78 static int is31fl3194_set_color(const struct device *dev, uint32_t led, uint8_t num_colors, in is31fl3194_set_color() argument
81 const struct is31fl3194_config *config = dev->config; in is31fl3194_set_color()
82 const struct led_info *info = is31fl3194_led_to_info(config, led); in is31fl3194_set_color()
86 return -ENODEV; in is31fl3194_set_color()
89 if (info->num_colors != 3) { in is31fl3194_set_color()
90 return -ENOTSUP; in is31fl3194_set_color()
94 return -EINVAL; in is31fl3194_set_color()
100 switch (info->color_mapping[i]) { in is31fl3194_set_color()
112 return -EINVAL; in is31fl3194_set_color()
115 ret = i2c_reg_write_byte_dt(&config->bus, led_channels[i], value); in is31fl3194_set_color()
122 ret = i2c_reg_write_byte_dt(&config->bus, in is31fl3194_set_color()
128 LOG_ERR("%s: LED write failed: %d", dev->name, ret); in is31fl3194_set_color()
134 static int is31fl3194_set_brightness(const struct device *dev, uint32_t led, uint8_t value) in is31fl3194_set_brightness() argument
136 const struct is31fl3194_config *config = dev->config; in is31fl3194_set_brightness()
137 const struct led_info *info = is31fl3194_led_to_info(config, led); in is31fl3194_set_brightness()
141 return -ENODEV; in is31fl3194_set_brightness()
144 if (info->num_colors != 1) { in is31fl3194_set_brightness()
145 return -ENOTSUP; in is31fl3194_set_brightness()
149 return -EINVAL; in is31fl3194_set_brightness()
155 ret = i2c_reg_write_byte_dt(&config->bus, led_channels[led], value); in is31fl3194_set_brightness()
157 ret = i2c_reg_write_byte_dt(&config->bus, in is31fl3194_set_brightness()
163 LOG_ERR("%s: LED write failed", dev->name); in is31fl3194_set_brightness()
169 static inline int is31fl3194_led_on(const struct device *dev, uint32_t led) in is31fl3194_led_on() argument
171 return is31fl3194_set_brightness(dev, led, 100); in is31fl3194_led_on()
174 static inline int is31fl3194_led_off(const struct device *dev, uint32_t led) in is31fl3194_led_off() argument
176 return is31fl3194_set_brightness(dev, led, 0); in is31fl3194_led_off()
202 dev->name, color_id); in is31fl3194_count_colors()
210 const struct is31fl3194_config *config = dev->config; in is31fl3194_check_config()
215 switch (config->num_leds) { in is31fl3194_check_config()
217 /* check that it is a three-channel LED */ in is31fl3194_check_config()
218 info = &config->led_infos[0]; in is31fl3194_check_config()
220 if (info->num_colors != 3) { in is31fl3194_check_config()
222 "(must be 3 for RGB LED)", in is31fl3194_check_config()
223 dev->name, info->num_colors); in is31fl3194_check_config()
224 return -EINVAL; in is31fl3194_check_config()
228 if (!is31fl3194_count_colors(dev, info->color_mapping[i], rgb_counts)) { in is31fl3194_check_config()
229 return -EINVAL; in is31fl3194_check_config()
235 /* check that each LED is single-color */ in is31fl3194_check_config()
237 info = &config->led_infos[i]; in is31fl3194_check_config()
239 if (info->num_colors != 1) { in is31fl3194_check_config()
242 dev->name, info->num_colors); in is31fl3194_check_config()
243 return -EINVAL; in is31fl3194_check_config()
246 if (!is31fl3194_count_colors(dev, info->color_mapping[0], rgb_counts)) { in is31fl3194_check_config()
247 return -EINVAL; in is31fl3194_check_config()
253 dev->name, config->num_leds); in is31fl3194_check_config()
254 return -EINVAL; in is31fl3194_check_config()
262 const struct is31fl3194_config *config = dev->config; in is31fl3194_init()
273 if (!i2c_is_ready_dt(&config->bus)) { in is31fl3194_init()
274 LOG_ERR("%s: I2C device not ready", dev->name); in is31fl3194_init()
275 return -ENODEV; in is31fl3194_init()
278 ret = i2c_reg_read_byte_dt(&config->bus, IS31FL3194_PROD_ID_REG, &prod_id); in is31fl3194_init()
280 LOG_ERR("%s: failed to read product ID", dev->name); in is31fl3194_init()
285 LOG_ERR("%s: invalid product ID 0x%02x (expected 0x%02x)", dev->name, prod_id, in is31fl3194_init()
287 return -ENODEV; in is31fl3194_init()
290 /* calc current limit register value */ in is31fl3194_init()
291 info = &config->led_infos[0]; in is31fl3194_init()
292 if (info->num_colors == IS31FL3194_CHANNEL_COUNT) { in is31fl3194_init()
293 /* one RGB LED: set all channels to the same current limit */ in is31fl3194_init()
294 band = (config->current_limits[0] / 10) - 1; in is31fl3194_init()
299 /* single-channel LEDs: independent limits */ in is31fl3194_init()
300 for (i = 0; i < config->num_leds; i++) { in is31fl3194_init()
301 band = (config->current_limits[i] / 10) - 1; in is31fl3194_init()
306 ret = i2c_reg_write_byte_dt(&config->bus, IS31FL3194_CURRENT_REG, current_reg); in is31fl3194_init()
308 LOG_ERR("%s: failed to set current limit", dev->name); in is31fl3194_init()
313 return i2c_reg_write_byte_dt(&config->bus, IS31FL3194_CONF_REG, IS31FL3194_CONF_ENABLE); in is31fl3194_init()
316 static DEVICE_API(led, is31fl3194_led_api) = {