c1x4rgb  2.1.0.0
c1x4rgb.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef C1X4RGB_H
29 #define C1X4RGB_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define C1X4RGB_REG_CHIP_EN 0x0000u
70 #define C1X4RGB_REG_DEV_CFG_0 0x0001u
71 #define C1X4RGB_REG_DEV_CFG_1 0x0002u
72 #define C1X4RGB_REG_DEV_CFG_2 0x0003u
73 #define C1X4RGB_REG_DEV_CFG_3 0x0004u
74 #define C1X4RGB_REG_DEV_CFG_4 0x0005u
75 #define C1X4RGB_REG_DEV_CFG_5 0x0006u
76 #define C1X4RGB_REG_DEV_CFG_6 0x0007u
77 #define C1X4RGB_REG_DEV_CFG_7 0x0008u
78 #define C1X4RGB_REG_DEV_CFG_8 0x0009u
79 #define C1X4RGB_REG_DEV_CFG_9 0x000Au
80 #define C1X4RGB_REG_DEV_CFG_10 0x000Bu
81 #define C1X4RGB_REG_DEV_CFG_11 0x000Cu
82 #define C1X4RGB_REG_DEV_CFG_12 0x000Du
83 #define C1X4RGB_REG_CMD_UPDATE 0x0010u
84 #define C1X4RGB_REG_CMD_START 0x0011u
85 #define C1X4RGB_REG_CMD_STOP 0x0012u
86 #define C1X4RGB_REG_CMD_PAUSE 0x0013u
87 #define C1X4RGB_REG_CMD_CONTINUE 0x0014u
88 #define C1X4RGB_REG_LED_EN_1 0x0020u
89 #define C1X4RGB_REG_LED_EN_2 0x0021u
90 #define C1X4RGB_REG_FAULT_CLR 0x0022u
91 #define C1X4RGB_REG_RESET 0x0023u
92 #define C1X4RGB_REG_MANUAL_DC_0 0x0030u
93 #define C1X4RGB_REG_MANUAL_DC_1 0x0031u
94 #define C1X4RGB_REG_MANUAL_DC_2 0x0032u
95 #define C1X4RGB_REG_MANUAL_DC_3 0x0033u
96 #define C1X4RGB_REG_MANUAL_L0_G 0x0034u
97 #define C1X4RGB_REG_MANUAL_L0_R 0x0035u
98 #define C1X4RGB_REG_MANUAL_L0_B 0x0036u
99 #define C1X4RGB_REG_MANUAL_L1_G 0x0037u
100 #define C1X4RGB_REG_MANUAL_L1_R 0x0038u
101 #define C1X4RGB_REG_MANUAL_L1_B 0x0039u
102 #define C1X4RGB_REG_MANUAL_L2_G 0x003Au
103 #define C1X4RGB_REG_MANUAL_L2_R 0x003Bu
104 #define C1X4RGB_REG_MANUAL_L2_B 0x003Cu
105 #define C1X4RGB_REG_MANUAL_L3_G 0x003Du
106 #define C1X4RGB_REG_MANUAL_L3_R 0x003Eu
107 #define C1X4RGB_REG_MANUAL_L3_B 0x003Fu
108 #define C1X4RGB_REG_MANUAL_PWM_0 0x0040u
109 #define C1X4RGB_REG_MANUAL_PWM_1 0x0041u
110 #define C1X4RGB_REG_MANUAL_PWM_2 0x0042u
111 #define C1X4RGB_REG_MANUAL_PWM_3 0x0043u
112 #define C1X4RGB_REG_MANUAL_PWM_L0_G 0x0044u
113 #define C1X4RGB_REG_MANUAL_PWM_L0_R 0x0045u
114 #define C1X4RGB_REG_MANUAL_PWM_L0_B 0x0046u
115 #define C1X4RGB_REG_MANUAL_PWM_L1_G 0x0047u
116 #define C1X4RGB_REG_MANUAL_PWM_L1_R 0x0048u
117 #define C1X4RGB_REG_MANUAL_PWM_L1_B 0x0049u
118 #define C1X4RGB_REG_MANUAL_PWM_L2_G 0x004Au
119 #define C1X4RGB_REG_MANUAL_PWM_L2_R 0x004Bu
120 #define C1X4RGB_REG_MANUAL_PWM_L2_B 0x004Cu
121 #define C1X4RGB_REG_MANUAL_PWM_L3_G 0x004Du
122 #define C1X4RGB_REG_MANUAL_PWM_L3_R 0x004Eu
123 #define C1X4RGB_REG_MANUAL_PWM_L3_B 0x004Fu
124 #define C1X4RGB_REG_AUTO_DC_0 0x0050u
125 #define C1X4RGB_REG_AUTO_DC_1 0x0051u
126 #define C1X4RGB_REG_AUTO_DC_2 0x0052u
127 #define C1X4RGB_REG_AUTO_DC_3 0x0053u
128 #define C1X4RGB_REG_AUTO_L0_G 0x0054u
129 #define C1X4RGB_REG_AUTO_L0_R 0x0055u
130 #define C1X4RGB_REG_AUTO_L0_B 0x0056u
131 #define C1X4RGB_REG_AUTO_L1_G 0x0057u
132 #define C1X4RGB_REG_AUTO_L1_R 0x0058u
133 #define C1X4RGB_REG_AUTO_L1_B 0x0059u
134 #define C1X4RGB_REG_AUTO_L2_G 0x005Au
135 #define C1X4RGB_REG_AUTO_L2_R 0x005Bu
136 #define C1X4RGB_REG_AUTO_L2_B 0x005Cu
137 #define C1X4RGB_REG_AUTO_L3_G 0x005Du
138 #define C1X4RGB_REG_AUTO_L3_R 0x005Eu
139 #define C1X4RGB_REG_AUTO_L3_B 0x005Fu
140 #define C1X4RGB_REG_LED0_AEP_START 0x0080u
141 #define C1X4RGB_REG_LED0_AEP_END 0x0099u
142 #define C1X4RGB_REG_LED1_AEP_START 0x009Au
143 #define C1X4RGB_REG_LED1_AEP_END 0x00B3u
144 #define C1X4RGB_REG_LED2_AEP_START 0x00B4u
145 #define C1X4RGB_REG_LED2_AEP_END 0x00CDu
146 #define C1X4RGB_REG_LED3_AEP_START 0x00CEu
147 #define C1X4RGB_REG_LED4_AEP_END 0x00E7u
148 #define C1X4RGB_REG_LED_A0_AEP_START 0x00E8u
149 #define C1X4RGB_REG_LED_A0_AEP_END 0x0101u
150 #define C1X4RGB_REG_LED_A1_AEP_START 0x0102u
151 #define C1X4RGB_REG_LED_A1_AEP_END 0x011Bu
152 #define C1X4RGB_REG_LED_A2_AEP_START 0x011Cu
153 #define C1X4RGB_REG_LED_A2_AEP_END 0x0135u
154 #define C1X4RGB_REG_LED_B0_AEP_START 0x0136u
155 #define C1X4RGB_REG_LED_B0_AEP_END 0x014Fu
156 #define C1X4RGB_REG_LED_B1_AEP_START 0x0150u
157 #define C1X4RGB_REG_LED_B1_AEP_END 0x0169u
158 #define C1X4RGB_REG_LED_B2_AEP_START 0x016Au
159 #define C1X4RGB_REG_LED_B2_AEP_END 0x0183u
160 #define C1X4RGB_REG_LED_C0_AEP_START 0x0184u
161 #define C1X4RGB_REG_LED_C0_AEP_END 0x019Du
162 #define C1X4RGB_REG_LED_C1_AEP_START 0x019Eu
163 #define C1X4RGB_REG_LED_C1_AEP_END 0x01B7u
164 #define C1X4RGB_REG_LED_C2_AEP_START 0x01B8u
165 #define C1X4RGB_REG_LED_C2_AEP_END 0x01D1u
166 #define C1X4RGB_REG_LED_D0_AEP_START 0x01D2u
167 #define C1X4RGB_REG_LED_D0_AEP_END 0x01EBu
168 #define C1X4RGB_REG_LED_D1_AEP_START 0x01ECu
169 #define C1X4RGB_REG_LED_D1_AEP_END 0x0205u
170 #define C1X4RGB_REG_LED_D2_AEP_START 0x0206u
171 #define C1X4RGB_REG_LED_D2_AEP_END 0x021Fu
172 #define C1X4RGB_REG_STATUS_TSD 0x0300u
173 #define C1X4RGB_REG_STATUS_LDO_1 0x0301u
174 #define C1X4RGB_REG_STATUS_LDO_2 0x0302u
175 #define C1X4RGB_REG_STATUS_LSD_1 0x0303u
176 #define C1X4RGB_REG_STATUS_PWM_INT_0 0x0305u
177 #define C1X4RGB_REG_STATUS_PWM_INT_1 0x0306u
178 #define C1X4RGB_REG_STATUS_PWM_INT_2 0x0307u
179 #define C1X4RGB_REG_STATUS_PWM_INT_3 0x0308u
180 #define C1X4RGB_REG_STATUS_PWM_INT_D0 0x0309u
181 #define C1X4RGB_REG_STATUS_PWM_INT_D1 0x030Au
182 #define C1X4RGB_REG_STATUS_PWM_INT_D2 0x030Bu
183 #define C1X4RGB_REG_STATUS_PWM_INT_D3 0x030Cu
184 #define C1X4RGB_REG_STATUS_PWM_INT_D4 0x030Du
185 #define C1X4RGB_REG_STATUS_PWM_INT_D5 0x030Eu
186 #define C1X4RGB_REG_STATUS_PWM_INT_D6 0x030Fu
187 #define C1X4RGB_REG_STATUS_PWM_INT_D7 0x0310u
188 #define C1X4RGB_REG_STATUS_PWM_INT_D8 0x0311u
189 #define C1X4RGB_REG_STATUS_PWM_INT_D9 0x0312u
190 #define C1X4RGB_REG_STATUS_PWM_INT_D10 0x0313u
191 #define C1X4RGB_REG_STATUS_PWM_INT_D11 0x0314u
192 #define C1X4RGB_REG_STATUS_PATTERN_1 0x0315u
193 #define C1X4RGB_REG_STATUS_PATTERN_2 0x0316u
194 #define C1X4RGB_REG_STATUS_PATTERN_3 0x0317u
195 #define C1X4RGB_REG_STATUS_PATTERN_4 0x0318u
196 #define C1X4RGB_REG_STATUS_PATTERN_5 0x0319u
197 #define C1X4RGB_REG_STATUS_PATTERN_6 0x031Au
198 #define C1X4RGB_REG_STATUS_PATTERN_7 0x031Bu
199 #define C1X4RGB_REG_STATUS_PATTERN_8 0x031Cu
200 
201  // c1x4rgb_reg
203 
218 #define C1X4RGB_CHIP_ENABLE 0x01
219 
224 #define C1X4RGB_TCM_MODE_SCAN_1 0x10
225 #define C1X4RGB_TCM_MODE_SCAN_2 0x20
226 #define C1X4RGB_TCM_MODE_SCAN_3 0x30
227 #define C1X4RGB_TCM_MODE_SCAN_4 0x40
228 
233 #define C1X4RGB_SET_CMD_UPDATE 0x00
234 #define C1X4RGB_SET_CMD_START 0x01
235 #define C1X4RGB_SET_CMD_STOP 0x02
236 #define C1X4RGB_SET_CMD_PAUSE 0x03
237 #define C1X4RGB_CMD_ENABLE 0x55
238 
243 #define C1X4RGB_DUTY_CYCLE_CALC_FACT 2.55f
244 #define C1X4RGB_DUTY_CYCLE_10 10.0f
245 #define C1X4RGB_DUTY_CYCLE_50 50.0f
246 #define C1X4RGB_DUTY_CYCLE_100 100.0f
247 
252 #define C1X4RGB_LSD_DET_DEFAULT 0x0B
253 
258 #define C1X4RGB_NUM_LED_0 0
259 #define C1X4RGB_NUM_LED_1 1
260 #define C1X4RGB_NUM_LED_2 2
261 #define C1X4RGB_NUM_LED_3 3
262 #define C1X4RGB_NUM_LED_4 4
263 #define C1X4RGB_NUM_LED_5 5
264 #define C1X4RGB_NUM_LED_6 6
265 #define C1X4RGB_NUM_LED_7 7
266 #define C1X4RGB_NUM_LED_8 8
267 #define C1X4RGB_NUM_LED_9 9
268 #define C1X4RGB_NUM_LED_10 10
269 #define C1X4RGB_NUM_LED_11 11
270 
275 #define C1X4RGB_ENABLE_ALL_LEDS 0x0FFFu
276 
281 #define C1X4RGB_LED_POS_LD1 0
282 #define C1X4RGB_LED_POS_LD2 1
283 #define C1X4RGB_LED_POS_LD3 2
284 #define C1X4RGB_LED_POS_LD4 3
285 
290 #define C1X4RGB_LED_ENABLE_BITMASK 0x0F00U
291 
296 #define C1X4RGB_SYC_STATE_LOW 0x00
297 #define C1X4RGB_SYC_STATE_HIGH 0x01
298 
304 #define C1X4RGB_DEVICE_ADDRESS_IND 0x50
305 #define C1X4RGB_DEVICE_ADDRESS_BCST 0x6C
306  // c1x4rgb_set
308 
323 #define C1X4RGB_MAP_MIKROBUS( cfg, mikrobus ) \
324  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
325  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
326  cfg.syc = MIKROBUS( mikrobus, MIKROBUS_PWM )
327  // c1x4rgb_map // c1x4rgb
330 
335 typedef struct
336 {
337  // Output pins
338  digital_out_t syc;
340  // Modules
341  i2c_master_t i2c;
343  // I2C slave address
344  uint8_t slave_address;
346 } c1x4rgb_t;
347 
352 typedef struct
353 {
354  pin_name_t scl;
355  pin_name_t sda;
357  pin_name_t syc;
359  uint32_t i2c_speed;
360  uint8_t i2c_address;
362 } c1x4rgb_cfg_t;
363 
368 typedef struct
369 {
370  uint8_t red;
371  uint8_t green;
372  uint8_t blue;
373 
375 
380 typedef struct
381 {
386 
387 } c1x4rgb_led_t;
388 
389 
394 typedef enum
395 {
397  C1X4RGB_ERROR = -1
398 
400 
417 
431 err_t c1x4rgb_init ( c1x4rgb_t *ctx, c1x4rgb_cfg_t *cfg );
432 
446 
461 err_t c1x4rgb_generic_write ( c1x4rgb_t *ctx, uint16_t reg, uint8_t *data_in, uint8_t len );
462 
477 err_t c1x4rgb_generic_read ( c1x4rgb_t *ctx, uint16_t reg, uint8_t *data_out, uint8_t len );
478 
492 err_t c1x4rgb_reg_write ( c1x4rgb_t *ctx, uint16_t reg, uint8_t data_in );
493 
507 err_t c1x4rgb_reg_read ( c1x4rgb_t *ctx, uint16_t reg, uint8_t *data_out );
508 
520 
534 err_t c1x4rgb_set_tmc_mode ( c1x4rgb_t *ctx, uint8_t dev_cfg, uint8_t mode );
535 
548 err_t c1x4rgb_set_lsd_thold ( c1x4rgb_t *ctx, uint8_t lsd_thold );
549 
562 err_t c1x4rgb_set_command ( c1x4rgb_t *ctx, uint8_t command );
563 
576 err_t c1x4rgb_get_tsd_cfg_status ( c1x4rgb_t *ctx, uint8_t *status );
577 
590 err_t c1x4rgb_enable_leds ( c1x4rgb_t *ctx, uint16_t led_bitmask );
591 
604 err_t c1x4rgb_set_leds_illuminate ( c1x4rgb_t *ctx, float duty_cycle );
605 
619 err_t c1x4rgb_set_led_illuminate ( c1x4rgb_t *ctx, uint8_t n_led, float duty_cycle );
620 
636 err_t c1x4rgb_set_rgb_color ( c1x4rgb_t *ctx, uint8_t led_pos, uint8_t red, uint8_t green, uint8_t blue );
637 
652 
662 void c1x4rgb_set_sync ( c1x4rgb_t *ctx, uint8_t sync );
663 
664 #ifdef __cplusplus
665 }
666 #endif
667 #endif // C1X4RGB_H
668  // c1x4rgb
670 
671 // ------------------------------------------------------------------------ END
c1x4rgb_led_t::led_3
c1x4rgb_led_color_t led_3
Definition: c1x4rgb.h:385
c1x4rgb_default_cfg
err_t c1x4rgb_default_cfg(c1x4rgb_t *ctx)
1x4 RGB default configuration function.
c1x4rgb_cfg_t::syc
pin_name_t syc
Definition: c1x4rgb.h:357
c1x4rgb_cfg_rgb_color
err_t c1x4rgb_cfg_rgb_color(c1x4rgb_t *ctx, c1x4rgb_led_t led_cfg)
1x4 RGB configure RGB colors function.
c1x4rgb_generic_write
err_t c1x4rgb_generic_write(c1x4rgb_t *ctx, uint16_t reg, uint8_t *data_in, uint8_t len)
1x4 RGB I2C writing function.
c1x4rgb_cfg_t::i2c_address
uint8_t i2c_address
Definition: c1x4rgb.h:360
c1x4rgb_set_tmc_mode
err_t c1x4rgb_set_tmc_mode(c1x4rgb_t *ctx, uint8_t dev_cfg, uint8_t mode)
1x4 RGB set TCM mode function.
c1x4rgb_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c1x4rgb.h:359
c1x4rgb_t::slave_address
uint8_t slave_address
Definition: c1x4rgb.h:344
c1x4rgb_set_lsd_thold
err_t c1x4rgb_set_lsd_thold(c1x4rgb_t *ctx, uint8_t lsd_thold)
1x4 RGB set LSD threshold function.
c1x4rgb_enable_leds
err_t c1x4rgb_enable_leds(c1x4rgb_t *ctx, uint16_t led_bitmask)
1x4 RGB enable LEDs function.
c1x4rgb_return_value_t
c1x4rgb_return_value_t
1x4 RGB Click return value data.
Definition: c1x4rgb.h:395
c1x4rgb_cfg_t
1x4 RGB Click configuration object.
Definition: c1x4rgb.h:353
c1x4rgb_get_tsd_cfg_status
err_t c1x4rgb_get_tsd_cfg_status(c1x4rgb_t *ctx, uint8_t *status)
1x4 RGB get TSD status function.
c1x4rgb_led_t
1x4 RGB Click LED position configuration object.
Definition: c1x4rgb.h:381
c1x4rgb_set_command
err_t c1x4rgb_set_command(c1x4rgb_t *ctx, uint8_t command)
1x4 RGB set command function.
c1x4rgb_reg_write
err_t c1x4rgb_reg_write(c1x4rgb_t *ctx, uint16_t reg, uint8_t data_in)
1x4 RGB register writing function.
c1x4rgb_led_t::led_1
c1x4rgb_led_color_t led_1
Definition: c1x4rgb.h:383
c1x4rgb_set_rgb_color
err_t c1x4rgb_set_rgb_color(c1x4rgb_t *ctx, uint8_t led_pos, uint8_t red, uint8_t green, uint8_t blue)
1x4 RGB set colors function.
c1x4rgb_set_led_illuminate
err_t c1x4rgb_set_led_illuminate(c1x4rgb_t *ctx, uint8_t n_led, float duty_cycle)
1x4 RGB set illuminate function.
c1x4rgb_led_t::led_0
c1x4rgb_led_color_t led_0
Definition: c1x4rgb.h:382
c1x4rgb_generic_read
err_t c1x4rgb_generic_read(c1x4rgb_t *ctx, uint16_t reg, uint8_t *data_out, uint8_t len)
1x4 RGB I2C reading function.
C1X4RGB_OK
@ C1X4RGB_OK
Definition: c1x4rgb.h:396
c1x4rgb_cfg_t::sda
pin_name_t sda
Definition: c1x4rgb.h:355
c1x4rgb_led_color_t
1x4 RGB Click LED color configuration object.
Definition: c1x4rgb.h:369
c1x4rgb_set_sync
void c1x4rgb_set_sync(c1x4rgb_t *ctx, uint8_t sync)
1x4 RGB set SYNC function.
c1x4rgb_init
err_t c1x4rgb_init(c1x4rgb_t *ctx, c1x4rgb_cfg_t *cfg)
1x4 RGB initialization function.
c1x4rgb_cfg_t::scl
pin_name_t scl
Definition: c1x4rgb.h:354
c1x4rgb_t::syc
digital_out_t syc
Definition: c1x4rgb.h:338
c1x4rgb_reg_read
err_t c1x4rgb_reg_read(c1x4rgb_t *ctx, uint16_t reg, uint8_t *data_out)
1x4 RGB register reading function.
c1x4rgb_t
1x4 RGB Click context object.
Definition: c1x4rgb.h:336
c1x4rgb_t::i2c
i2c_master_t i2c
Definition: c1x4rgb.h:341
c1x4rgb_led_color_t::red
uint8_t red
Definition: c1x4rgb.h:370
C1X4RGB_ERROR
@ C1X4RGB_ERROR
Definition: c1x4rgb.h:397
c1x4rgb_led_color_t::blue
uint8_t blue
Definition: c1x4rgb.h:372
c1x4rgb_led_t::led_2
c1x4rgb_led_color_t led_2
Definition: c1x4rgb.h:384
c1x4rgb_set_leds_illuminate
err_t c1x4rgb_set_leds_illuminate(c1x4rgb_t *ctx, float duty_cycle)
1x4 RGB set LEDs illuminate function.
c1x4rgb_cfg_setup
void c1x4rgb_cfg_setup(c1x4rgb_cfg_t *cfg)
1x4 RGB configuration object setup function.
c1x4rgb_chip_enable
err_t c1x4rgb_chip_enable(c1x4rgb_t *ctx)
1x4 RGB chip enable function.
c1x4rgb_led_color_t::green
uint8_t green
Definition: c1x4rgb.h:371