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

2  * Copyright (c) 2018 Savoir-Faire Linux.
4 * SPDX-License-Identifier: Apache-2.0
11 * @brief LED driver for the PCA9633 I2C LED driver (7-bit slave address 0x62)
15 #include <zephyr/drivers/led.h>
25 /* PCA9633 select registers determine the source that drives LED outputs */
26 #define PCA9633_LED_OFF 0x0 /* LED driver off */
27 #define PCA9633_LED_ON 0x1 /* LED driver on */
34 #define PCA9633_PWM_BASE 0x02 /* Reg 0x02-0x05 for brightness control LED01-04 */
56 static int pca9633_led_blink(const struct device *dev, uint32_t led, in pca9633_led_blink() argument
59 struct pca9633_data *data = dev->data; in pca9633_led_blink()
60 const struct pca9633_config *config = dev->config; in pca9633_led_blink()
61 struct led_data *dev_data = &data->dev_data; in pca9633_led_blink()
67 if (period < dev_data->min_period || period > dev_data->max_period) { in pca9633_led_blink()
68 return -EINVAL; in pca9633_led_blink()
73 * duty cycle = (GDC / 256) -> in pca9633_led_blink()
74 * (time_on / period) = (GDC / 256) -> in pca9633_led_blink()
78 if (i2c_reg_write_byte_dt(&config->i2c, in pca9633_led_blink()
81 LOG_ERR("LED reg write failed"); in pca9633_led_blink()
82 return -EIO; in pca9633_led_blink()
88 * So, period (in ms) = (((GFRQ + 1) / 24) * 1000) -> in pca9633_led_blink()
89 * GFRQ = ((period * 24 / 1000) - 1) in pca9633_led_blink()
91 gfrq = (period * 24U / 1000) - 1; in pca9633_led_blink()
92 if (i2c_reg_write_byte_dt(&config->i2c, in pca9633_led_blink()
95 LOG_ERR("LED reg write failed"); in pca9633_led_blink()
96 return -EIO; in pca9633_led_blink()
100 if (i2c_reg_update_byte_dt(&config->i2c, in pca9633_led_blink()
104 LOG_ERR("LED reg update failed"); in pca9633_led_blink()
105 return -EIO; in pca9633_led_blink()
108 /* Select the GRPPWM source to drive the LED output */ in pca9633_led_blink()
109 if (i2c_reg_update_byte_dt(&config->i2c, in pca9633_led_blink()
111 PCA9633_MASK << (led << 1), in pca9633_led_blink()
112 PCA9633_LED_GRP_PWM << (led << 1))) { in pca9633_led_blink()
113 LOG_ERR("LED reg update failed"); in pca9633_led_blink()
114 return -EIO; in pca9633_led_blink()
120 static int pca9633_led_set_brightness(const struct device *dev, uint32_t led, in pca9633_led_set_brightness() argument
123 const struct pca9633_config *config = dev->config; in pca9633_led_set_brightness()
124 struct pca9633_data *data = dev->data; in pca9633_led_set_brightness()
125 struct led_data *dev_data = &data->dev_data; in pca9633_led_set_brightness()
128 if (value < dev_data->min_brightness || in pca9633_led_set_brightness()
129 value > dev_data->max_brightness) { in pca9633_led_set_brightness()
130 return -EINVAL; in pca9633_led_set_brightness()
133 /* Set the LED brightness value */ in pca9633_led_set_brightness()
134 val = (value * 255U) / dev_data->max_brightness; in pca9633_led_set_brightness()
135 if (i2c_reg_write_byte_dt(&config->i2c, in pca9633_led_set_brightness()
136 PCA9633_PWM_BASE + led, in pca9633_led_set_brightness()
138 LOG_ERR("LED reg write failed"); in pca9633_led_set_brightness()
139 return -EIO; in pca9633_led_set_brightness()
142 /* Set the LED driver to be controlled through its PWMx register. */ in pca9633_led_set_brightness()
143 if (i2c_reg_update_byte_dt(&config->i2c, in pca9633_led_set_brightness()
145 PCA9633_MASK << (led << 1), in pca9633_led_set_brightness()
146 PCA9633_LED_PWM << (led << 1))) { in pca9633_led_set_brightness()
147 LOG_ERR("LED reg update failed"); in pca9633_led_set_brightness()
148 return -EIO; in pca9633_led_set_brightness()
154 static inline int pca9633_led_on(const struct device *dev, uint32_t led) in pca9633_led_on() argument
156 const struct pca9633_config *config = dev->config; in pca9633_led_on()
158 /* Set LED state to ON */ in pca9633_led_on()
159 if (i2c_reg_update_byte_dt(&config->i2c, in pca9633_led_on()
161 PCA9633_MASK << (led << 1), in pca9633_led_on()
162 PCA9633_LED_ON << (led << 1))) { in pca9633_led_on()
163 LOG_ERR("LED reg update failed"); in pca9633_led_on()
164 return -EIO; in pca9633_led_on()
170 static inline int pca9633_led_off(const struct device *dev, uint32_t led) in pca9633_led_off() argument
172 const struct pca9633_config *config = dev->config; in pca9633_led_off()
174 /* Set LED state to OFF */ in pca9633_led_off()
175 if (i2c_reg_update_byte_dt(&config->i2c, in pca9633_led_off()
177 PCA9633_MASK << (led << 1), in pca9633_led_off()
179 LOG_ERR("LED reg update failed"); in pca9633_led_off()
180 return -EIO; in pca9633_led_off()
188 const struct pca9633_config *config = dev->config; in pca9633_led_init()
189 struct pca9633_data *data = dev->data; in pca9633_led_init()
190 struct led_data *dev_data = &data->dev_data; in pca9633_led_init()
192 if (!device_is_ready(config->i2c.bus)) { in pca9633_led_init()
194 return -ENODEV; in pca9633_led_init()
198 * Take the LED driver out from Sleep mode and disable All Call Address in pca9633_led_init()
202 &config->i2c, PCA9633_MODE1, in pca9633_led_init()
203 config->disable_allcall ? PCA9633_MODE1_SLEEP | PCA9633_MODE1_ALLCAL in pca9633_led_init()
205 config->disable_allcall ? ~(PCA9633_MODE1_SLEEP | PCA9633_MODE1_ALLCAL) in pca9633_led_init()
207 LOG_ERR("LED reg update failed"); in pca9633_led_init()
208 return -EIO; in pca9633_led_init()
211 dev_data->min_period = 41U; in pca9633_led_init()
212 dev_data->max_period = 10667U; in pca9633_led_init()
213 dev_data->min_brightness = 0U; in pca9633_led_init()
214 dev_data->max_brightness = 100U; in pca9633_led_init()