Lines Matching +full:4 +full:- +full:byte
4 * SPDX-License-Identifier: Apache-2.0
13 #include <zephyr/dt-bindings/led/led.h>
43 * The TLC5971 has 4x RGB outputs per device, where each RGB group constitues a pixel from this
46 #define TLC5971_PIXELS_PER_DEVICE 4
57 /** GS reference clock edge select bit for OUTXn on-off timing control in FC data */
60 /** Constant-current output enable bit in FC data (0 = output control enabled, 1 = blank). */
69 /** Bit mask for write cmd in data byte 27 */
72 /** Bit mask for control bits in data byte 27 */
75 /** Bit mask for control bits in data byte 26 */
78 /** Bit mask for global brightness control for color 1 in data byte 26, upper 5 bits of GBC */
79 #define TLC5971_BYTE26_GBC1_MASK GENMASK(4, 0)
81 /** Bit mask for global brightness control for color 1 in data byte 25, lower 2 bits of GBC */
84 /** Bit mask for global brightness control for color 2 in data byte 25, upper 6 bits of GBC */
87 /** Bit mask for global brightness control for color 2 in data byte 24, lower 1 bits of GBC */
90 /** Bit mask for global brightness control for color 3 in data byte 24, all 7 bits of GBC */
94 * @brief create data byte 27 from control data
97 * @return uint8_t the serialized data byte 27
106 * @brief create data byte 26 from control data and color 1 GBC
110 * @return uint8_t the serialized data byte 26
119 * @brief create data byte 25 from color 1 and 2 GBC
123 * @return uint8_t the serialized data byte 25
132 * @brief create data byte 24 from color 2 and 3 GBC
136 * @return uint8_t the serialized data byte 24
157 temp = pixel_data->r; in tlc5971_map_color()
160 temp = pixel_data->g; in tlc5971_map_color()
163 temp = pixel_data->b; in tlc5971_map_color()
177 * to be mounted with all 4 LEDs.
186 const struct tlc5971_config *cfg = dev->config; in tlc5971_fill_data_buffer()
187 struct tlc5971_data *data = dev->data; in tlc5971_fill_data_buffer()
188 uint8_t *data_buffer = data->data_buffer; in tlc5971_fill_data_buffer()
195 for (int device = (num_pixels / TLC5971_PIXELS_PER_DEVICE) - 1; device >= 0; device--) { in tlc5971_fill_data_buffer()
201 data_buffer[count++] = tlc5971_data_byte27(data->control_data); in tlc5971_fill_data_buffer()
202 data_buffer[count++] = tlc5971_data_byte26(data->control_data, data->gbc_color_1); in tlc5971_fill_data_buffer()
203 data_buffer[count++] = tlc5971_data_byte25(data->gbc_color_1, data->gbc_color_2); in tlc5971_fill_data_buffer()
204 data_buffer[count++] = tlc5971_data_byte24(data->gbc_color_2, data->gbc_color_3); in tlc5971_fill_data_buffer()
206 for (int pixel = (TLC5971_PIXELS_PER_DEVICE - 1); pixel >= 0; pixel--) { in tlc5971_fill_data_buffer()
207 /* data is "reversed" so RGB0 comes last, i.e at byte 0 */ in tlc5971_fill_data_buffer()
215 for (int color = 0; color < cfg->num_colors; color++) { in tlc5971_fill_data_buffer()
217 tlc5971_map_color(cfg->color_mapping[color], pixel_data); in tlc5971_fill_data_buffer()
233 const struct tlc5971_config *cfg = dev->config; in tlc5971_transmit_data()
234 struct tlc5971_data *data = dev->data; in tlc5971_transmit_data()
237 .buf = data->data_buffer, in tlc5971_transmit_data()
246 return spi_write_dt(&cfg->bus, &tx); in tlc5971_transmit_data()
258 const struct tlc5971_config *cfg = dev->config; in tlc5971_length()
260 return (size_t)cfg->num_pixels; in tlc5971_length()
265 const struct tlc5971_config *cfg = dev->config; in tlc5971_set_global_brightness()
266 struct tlc5971_data *data = dev->data; in tlc5971_set_global_brightness()
267 int res = -EINVAL; in tlc5971_set_global_brightness()
272 data->gbc_color_1 = tlc5971_map_color(cfg->color_mapping[0], &pixel); in tlc5971_set_global_brightness()
273 data->gbc_color_2 = tlc5971_map_color(cfg->color_mapping[1], &pixel); in tlc5971_set_global_brightness()
274 data->gbc_color_3 = tlc5971_map_color(cfg->color_mapping[2], &pixel); in tlc5971_set_global_brightness()
283 const struct tlc5971_config *cfg = dev->config; in tlc5971_init()
284 struct tlc5971_data *data = dev->data; in tlc5971_init()
286 if (!spi_is_ready_dt(&cfg->bus)) { in tlc5971_init()
287 LOG_ERR("%s: SPI device %s not ready", dev->name, cfg->bus.bus->name); in tlc5971_init()
288 return -ENODEV; in tlc5971_init()
291 if ((cfg->num_pixels % TLC5971_PIXELS_PER_DEVICE) != 0) { in tlc5971_init()
292 LOG_ERR("%s: chain length must be multiple of 4", dev->name); in tlc5971_init()
293 return -EINVAL; in tlc5971_init()
296 if (cfg->num_colors != TLC5971_NUMBER_OF_COLORS) { in tlc5971_init()
297 LOG_ERR("%s: the tlc5971 only supports %i colors", dev->name, in tlc5971_init()
299 return -EINVAL; in tlc5971_init()
302 for (int i = 0; i < cfg->num_colors; i++) { in tlc5971_init()
303 switch (cfg->color_mapping[i]) { in tlc5971_init()
309 LOG_ERR("%s: invalid color mapping", dev->name); in tlc5971_init()
310 return -EINVAL; in tlc5971_init()
319 data->control_data = TLC5971_BYTE27_CTRL_BIT_OUTTMG | TLC5971_BYTE26_CTRL_BIT_DSPRPT | in tlc5971_init()