Lines Matching +full:led +full:- +full:current
2 * Copyright 2022-2023 Daniel DeGrasse <daniel@degrasse.com>
4 * SPDX-License-Identifier: Apache-2.0
10 #include <zephyr/drivers/led.h>
13 #include <zephyr/drivers/led/is31fl3733.h>
20 #define CMD_SEL_LED 0x0 /* LED configuration page */
36 #define GLOBAL_CURRENT_CTRL_REG 0x1 /* global current control register */
60 /* LED config reg state, IS31FL3733 conf reg is write only */
70 const struct is31fl3733_config *config = dev->config; in is31fl3733_select_page()
71 struct is31fl3733_data *data = dev->data; in is31fl3733_select_page()
74 if (data->selected_page == page) { in is31fl3733_select_page()
80 ret = i2c_reg_write_byte_dt(&config->bus, CMD_LOCK_REG, CMD_LOCK_UNLOCK); in is31fl3733_select_page()
87 ret = i2c_reg_write_byte_dt(&config->bus, CMD_SEL_REG, page); in is31fl3733_select_page()
92 data->selected_page = page; in is31fl3733_select_page()
97 static int is31fl3733_led_set_brightness(const struct device *dev, uint32_t led, uint8_t value) in is31fl3733_led_set_brightness() argument
99 const struct is31fl3733_config *config = dev->config; in is31fl3733_led_set_brightness()
103 if (led >= IS31FL3733_MAX_LED) { in is31fl3733_led_set_brightness()
104 return -EINVAL; in is31fl3733_led_set_brightness()
113 return i2c_reg_write_byte_dt(&config->bus, led, led_brightness); in is31fl3733_led_set_brightness()
116 static int is31fl3733_led_on(const struct device *dev, uint32_t led) in is31fl3733_led_on() argument
118 return is31fl3733_led_set_brightness(dev, led, IS31FL3733_MAX_BRIGHTNESS); in is31fl3733_led_on()
121 static int is31fl3733_led_off(const struct device *dev, uint32_t led) in is31fl3733_led_off() argument
123 return is31fl3733_led_set_brightness(dev, led, 0); in is31fl3733_led_off()
129 const struct is31fl3733_config *config = dev->config; in is31fl3733_led_write_channels()
130 struct is31fl3733_data *data = dev->data; in is31fl3733_led_write_channels()
135 return -EINVAL; in is31fl3733_led_write_channels()
137 pwm_start = data->scratch_buf + start_channel; in is31fl3733_led_write_channels()
138 /* Set PWM and LED target registers as first byte of each transfer */ in is31fl3733_led_write_channels()
142 /* Write LED PWM states */ in is31fl3733_led_write_channels()
149 return i2c_write_dt(&config->bus, pwm_start, num_channels + 1); in is31fl3733_led_write_channels()
154 const struct is31fl3733_config *config = dev->config; in is31fl3733_init()
155 struct is31fl3733_data *data = dev->data; in is31fl3733_init()
159 if (!i2c_is_ready_dt(&config->bus)) { in is31fl3733_init()
161 return -ENODEV; in is31fl3733_init()
163 if (config->sdb.port != NULL) { in is31fl3733_init()
164 if (!gpio_is_ready_dt(&config->sdb)) { in is31fl3733_init()
166 return -ENODEV; in is31fl3733_init()
169 ret = gpio_pin_configure_dt(&config->sdb, GPIO_OUTPUT_ACTIVE); in is31fl3733_init()
183 ret = i2c_reg_read_byte_dt(&config->bus, RESET_REG, &dummy); in is31fl3733_init()
188 /* Select function page after LED controller reset */ in is31fl3733_init()
193 /* Set global current control register based off devicetree value */ in is31fl3733_init()
194 ret = i2c_reg_write_byte_dt(&config->bus, GLOBAL_CURRENT_CTRL_REG, in is31fl3733_init()
195 config->current_limit); in is31fl3733_init()
200 * blanking. We also set the LED controller sync mode here. in is31fl3733_init()
202 data->conf_reg = (config->sync << CONF_REG_SYNC_SHIFT) | CONF_REG_SSD_MASK; in is31fl3733_init()
203 ret = i2c_reg_write_byte_dt(&config->bus, CONF_REG, data->conf_reg); in is31fl3733_init()
208 /* Enable all LEDs. We only control LED brightness in this driver. */ in is31fl3733_init()
209 data->scratch_buf[0] = 0x0; in is31fl3733_init()
210 memset(data->scratch_buf + 1, 0xFF, (IS31FL3733_MAX_LED / 8)); in is31fl3733_init()
216 return i2c_write_dt(&config->bus, data->scratch_buf, in is31fl3733_init()
223 * @brief Blanks IS31FL3733 LED display.
225 * When blank_en is set, the LED display will be disabled. This can be used for
226 * flicker-free display updates, or power saving.
228 * @param dev: LED device structure
234 const struct is31fl3733_config *config = dev->config; in is31fl3733_blank()
235 struct is31fl3733_data *data = dev->data; in is31fl3733_blank()
244 data->conf_reg &= ~CONF_REG_SSD_MASK; in is31fl3733_blank()
246 data->conf_reg |= CONF_REG_SSD_MASK; in is31fl3733_blank()
249 return i2c_reg_write_byte_dt(&config->bus, CONF_REG, data->conf_reg); in is31fl3733_blank()
253 * @brief Sets led current limit
255 * Sets the current limit for the LED driver. This is a separate value
256 * from per-led brightness, and applies to all LEDs.
257 * This value sets the output current limit according
260 * @param dev: LED device structure
261 * @param limit: current limit to apply
266 const struct is31fl3733_config *config = dev->config; in is31fl3733_current_limit()
274 /* Set global current control register */ in is31fl3733_current_limit()
275 return i2c_reg_write_byte_dt(&config->bus, GLOBAL_CURRENT_CTRL_REG, limit); in is31fl3733_current_limit()
278 static DEVICE_API(led, is31fl3733_api) = {