Lines Matching +full:led +full:- +full:duty +full:- +full:cycle

5  * SPDX-License-Identifier: Apache-2.0
12 * @brief LED driver for the TLC59108 I2C LED driver
16 #include <zephyr/drivers/led.h>
25 /* TLC59108 max supported LED id */
28 /* TLC59108 select registers determine the source that drives LED outputs */
29 #define TLC59108_LED_OFF 0x0 /* LED driver off */
30 #define TLC59108_LED_ON 0x1 /* LED driver on */
60 static int tlc59108_set_ledout(const struct device *dev, uint32_t led, in tlc59108_set_ledout() argument
63 const struct tlc59108_cfg *config = dev->config; in tlc59108_set_ledout()
65 if (led < 4) { in tlc59108_set_ledout()
66 if (i2c_reg_update_byte_dt(&config->i2c, TLC59108_LEDOUT0, in tlc59108_set_ledout()
67 TLC59108_MASK << (led << 1), val << (led << 1))) { in tlc59108_set_ledout()
68 LOG_ERR("LED reg 0x%x update failed", TLC59108_LEDOUT0); in tlc59108_set_ledout()
69 return -EIO; in tlc59108_set_ledout()
72 if (i2c_reg_update_byte_dt(&config->i2c, TLC59108_LEDOUT1, in tlc59108_set_ledout()
73 TLC59108_MASK << ((led - 4) << 1), in tlc59108_set_ledout()
74 val << ((led - 4) << 1))) { in tlc59108_set_ledout()
75 LOG_ERR("LED reg 0x%x update failed", TLC59108_LEDOUT1); in tlc59108_set_ledout()
76 return -EIO; in tlc59108_set_ledout()
83 static int tlc59108_led_blink(const struct device *dev, uint32_t led, in tlc59108_led_blink() argument
86 const struct tlc59108_cfg *config = dev->config; in tlc59108_led_blink()
87 struct tlc59108_data *data = dev->data; in tlc59108_led_blink()
88 struct led_data *dev_data = &data->dev_data; in tlc59108_led_blink()
94 if (led > TLC59108_MAX_LED) { in tlc59108_led_blink()
95 return -EINVAL; in tlc59108_led_blink()
98 if (period < dev_data->min_period || period > dev_data->max_period) { in tlc59108_led_blink()
99 return -EINVAL; in tlc59108_led_blink()
104 * duty cycle = (GDC / 256) -> in tlc59108_led_blink()
105 * (time_on / period) = (GDC / 256) -> in tlc59108_led_blink()
109 if (i2c_reg_write_byte_dt(&config->i2c, TLC59108_GRPPWM, gdc)) { in tlc59108_led_blink()
110 LOG_ERR("LED reg 0x%x write failed", TLC59108_GRPPWM); in tlc59108_led_blink()
111 return -EIO; in tlc59108_led_blink()
117 * So, period (in ms) = (((GFRQ + 1) / 24) * 1000) -> in tlc59108_led_blink()
118 * GFRQ = ((period * 24 / 1000) - 1) in tlc59108_led_blink()
120 gfrq = (period * 24U / 1000) - 1; in tlc59108_led_blink()
121 if (i2c_reg_write_byte_dt(&config->i2c, TLC59108_GRPFREQ, gfrq)) { in tlc59108_led_blink()
122 LOG_ERR("LED reg 0x%x write failed", TLC59108_GRPFREQ); in tlc59108_led_blink()
123 return -EIO; in tlc59108_led_blink()
127 if (i2c_reg_update_byte_dt(&config->i2c, TLC59108_MODE2, TLC59108_MODE2_DMBLNK, in tlc59108_led_blink()
129 LOG_ERR("LED reg 0x%x update failed", TLC59108_MODE2); in tlc59108_led_blink()
130 return -EIO; in tlc59108_led_blink()
133 /* Select the GRPPWM source to drive the LED output */ in tlc59108_led_blink()
134 return tlc59108_set_ledout(dev, led, TLC59108_LED_GRP_PWM); in tlc59108_led_blink()
137 static int tlc59108_led_set_brightness(const struct device *dev, uint32_t led, in tlc59108_led_set_brightness() argument
140 const struct tlc59108_cfg *config = dev->config; in tlc59108_led_set_brightness()
141 struct tlc59108_data *data = dev->data; in tlc59108_led_set_brightness()
142 struct led_data *dev_data = &data->dev_data; in tlc59108_led_set_brightness()
145 if (led > TLC59108_MAX_LED) { in tlc59108_led_set_brightness()
146 return -EINVAL; in tlc59108_led_set_brightness()
149 if (value < dev_data->min_brightness || in tlc59108_led_set_brightness()
150 value > dev_data->max_brightness) { in tlc59108_led_set_brightness()
151 return -EINVAL; in tlc59108_led_set_brightness()
154 /* Set the LED brightness value */ in tlc59108_led_set_brightness()
155 val = (value * 255U) / dev_data->max_brightness; in tlc59108_led_set_brightness()
156 if (i2c_reg_write_byte_dt(&config->i2c, TLC59108_PWM_BASE + led, val)) { in tlc59108_led_set_brightness()
157 LOG_ERR("LED 0x%x reg write failed", TLC59108_PWM_BASE + led); in tlc59108_led_set_brightness()
158 return -EIO; in tlc59108_led_set_brightness()
161 /* Set the LED driver to be controlled through its PWMx register. */ in tlc59108_led_set_brightness()
162 return tlc59108_set_ledout(dev, led, TLC59108_LED_PWM); in tlc59108_led_set_brightness()
165 static inline int tlc59108_led_on(const struct device *dev, uint32_t led) in tlc59108_led_on() argument
167 if (led > TLC59108_MAX_LED) { in tlc59108_led_on()
168 return -EINVAL; in tlc59108_led_on()
171 /* Set LED state to ON */ in tlc59108_led_on()
172 return tlc59108_set_ledout(dev, led, TLC59108_LED_ON); in tlc59108_led_on()
175 static inline int tlc59108_led_off(const struct device *dev, uint32_t led) in tlc59108_led_off() argument
177 if (led > TLC59108_MAX_LED) { in tlc59108_led_off()
178 return -EINVAL; in tlc59108_led_off()
181 /* Set LED state to OFF */ in tlc59108_led_off()
182 return tlc59108_set_ledout(dev, led, TLC59108_LED_OFF); in tlc59108_led_off()
187 const struct tlc59108_cfg *config = dev->config; in tlc59108_led_init()
188 struct tlc59108_data *data = dev->data; in tlc59108_led_init()
189 struct led_data *dev_data = &data->dev_data; in tlc59108_led_init()
191 if (!device_is_ready(config->i2c.bus)) { in tlc59108_led_init()
192 LOG_ERR("I2C bus device %s is not ready", config->i2c.bus->name); in tlc59108_led_init()
193 return -ENODEV; in tlc59108_led_init()
197 if (i2c_reg_update_byte_dt(&config->i2c, TLC59108_MODE1, TLC59108_MODE1_OSC, 0)) { in tlc59108_led_init()
198 LOG_ERR("LED reg 0x%x update failed", TLC59108_MODE1); in tlc59108_led_init()
199 return -EIO; in tlc59108_led_init()
203 dev_data->min_period = 41U; in tlc59108_led_init()
204 dev_data->max_period = 10730U; in tlc59108_led_init()
205 dev_data->min_brightness = 0U; in tlc59108_led_init()
206 dev_data->max_brightness = 100U; in tlc59108_led_init()
211 static DEVICE_API(led, tlc59108_led_api) = {