ledring2  2.1.0.0
ledring2.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 LEDRING2_H
29 #define LEDRING2_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 
70 #define LEDRING2_REG_CHIP_EN 0x0000
71 #define LEDRING2_REG_DEV_INITIAL 0x0001
72 #define LEDRING2_REG_DEV_CONFIG1 0x0002
73 #define LEDRING2_REG_DEV_CONFIG2 0x0003
74 #define LEDRING2_REG_DEV_CONFIG3 0x0004
75 #define LEDRING2_REG_GLOBAL_BRI 0x0005
76 #define LEDRING2_REG_GROUP0_BRI 0x0006
77 #define LEDRING2_REG_GROUP1_BRI 0x0007
78 #define LEDRING2_REG_GROUP2_BRI 0x0008
79 #define LEDRING2_REG_R_CURRENT_SET 0x0009
80 #define LEDRING2_REG_G_CURRENT_SET 0x000A
81 #define LEDRING2_REG_B_CURRENT_SET 0x000B
82 #define LEDRING2_REG_DOT_GRP_SEL0 0x000C
83 #define LEDRING2_REG_DOT_GRP_SEL1 0x000D
84 #define LEDRING2_REG_DOT_GRP_SEL2 0x000E
85 #define LEDRING2_REG_DOT_GRP_SEL3 0x000F
86 #define LEDRING2_REG_DOT_GRP_SEL4 0x0010
87 #define LEDRING2_REG_DOT_GRP_SEL5 0x0011
88 #define LEDRING2_REG_DOT_GRP_SEL6 0x0012
89 #define LEDRING2_REG_DOT_GRP_SEL7 0x0013
90 #define LEDRING2_REG_DOT_GRP_SEL8 0x0014
91 #define LEDRING2_REG_DOT_GRP_SEL9 0x0015
92 #define LEDRING2_REG_DOT_ONOFF0 0x0043
93 #define LEDRING2_REG_DOT_ONOFF1 0x0044
94 #define LEDRING2_REG_DOT_ONOFF2 0x0045
95 #define LEDRING2_REG_DOT_ONOFF3 0x0046
96 #define LEDRING2_REG_DOT_ONOFF4 0x0047
97 #define LEDRING2_REG_DOT_ONOFF5 0x0048
98 #define LEDRING2_REG_FAULT_STATE 0x0064
99 #define LEDRING2_REG_DOT_LOD0 0x0065
100 #define LEDRING2_REG_DOT_LOD1 0x0066
101 #define LEDRING2_REG_DOT_LOD2 0x0067
102 #define LEDRING2_REG_DOT_LOD3 0x0068
103 #define LEDRING2_REG_DOT_LOD4 0x0069
104 #define LEDRING2_REG_DOT_LOD5 0x006A
105 #define LEDRING2_REG_DOT_LSD0 0x0086
106 #define LEDRING2_REG_DOT_LSD1 0x0087
107 #define LEDRING2_REG_DOT_LSD2 0x0088
108 #define LEDRING2_REG_DOT_LSD3 0x0089
109 #define LEDRING2_REG_DOT_LSD4 0x008A
110 #define LEDRING2_REG_DOT_LSD5 0x008B
111 #define LEDRING2_REG_LOD_CLEAR 0x00A7
112 #define LEDRING2_REG_LSD_CLEAR 0x00A8
113 #define LEDRING2_REG_RESET 0x00A9
114 #define LEDRING2_REG_DC0 0x0100
115 #define LEDRING2_REG_DC1 0x0101
116 #define LEDRING2_REG_DC2 0x0102
117 #define LEDRING2_REG_DC3 0x0103
118 #define LEDRING2_REG_DC4 0x0104
119 #define LEDRING2_REG_DC5 0x0105
120 #define LEDRING2_REG_DC6 0x0106
121 #define LEDRING2_REG_DC7 0x0107
122 #define LEDRING2_REG_DC8 0x0108
123 #define LEDRING2_REG_DC9 0x0109
124 #define LEDRING2_REG_DC10 0x010A
125 #define LEDRING2_REG_DC11 0x010B
126 #define LEDRING2_REG_DC12 0x010C
127 #define LEDRING2_REG_DC13 0x010D
128 #define LEDRING2_REG_DC14 0x010E
129 #define LEDRING2_REG_DC15 0x010F
130 #define LEDRING2_REG_DC16 0x0110
131 #define LEDRING2_REG_DC17 0x0111
132 #define LEDRING2_REG_DC18 0x0112
133 #define LEDRING2_REG_DC19 0x0113
134 #define LEDRING2_REG_DC20 0x0114
135 #define LEDRING2_REG_DC21 0x0115
136 #define LEDRING2_REG_DC22 0x0116
137 #define LEDRING2_REG_DC23 0x0117
138 #define LEDRING2_REG_DC24 0x0118
139 #define LEDRING2_REG_DC25 0x0119
140 #define LEDRING2_REG_DC26 0x011A
141 #define LEDRING2_REG_DC27 0x011B
142 #define LEDRING2_REG_DC28 0x011C
143 #define LEDRING2_REG_DC29 0x011D
144 #define LEDRING2_REG_DC30 0x011E
145 #define LEDRING2_REG_DC31 0x011F
146 #define LEDRING2_REG_DC32 0x0120
147 #define LEDRING2_REG_DC33 0x0121
148 #define LEDRING2_REG_DC34 0x0122
149 #define LEDRING2_REG_DC35 0x0123
150 #define LEDRING2_REG_PWM_BRI0 0x0200
151 #define LEDRING2_REG_PWM_BRI1 0x0201
152 #define LEDRING2_REG_PWM_BRI2 0x0202
153 #define LEDRING2_REG_PWM_BRI3 0x0203
154 #define LEDRING2_REG_PWM_BRI4 0x0204
155 #define LEDRING2_REG_PWM_BRI5 0x0205
156 #define LEDRING2_REG_PWM_BRI6 0x0206
157 #define LEDRING2_REG_PWM_BRI7 0x0207
158 #define LEDRING2_REG_PWM_BRI8 0x0208
159 #define LEDRING2_REG_PWM_BRI9 0x0209
160 #define LEDRING2_REG_PWM_BRI10 0x020A
161 #define LEDRING2_REG_PWM_BRI11 0x020B
162 #define LEDRING2_REG_PWM_BRI12 0x020C
163 #define LEDRING2_REG_PWM_BRI13 0x020D
164 #define LEDRING2_REG_PWM_BRI14 0x020E
165 #define LEDRING2_REG_PWM_BRI15 0x020F
166 #define LEDRING2_REG_PWM_BRI16 0x0210
167 #define LEDRING2_REG_PWM_BRI17 0x0211
168 #define LEDRING2_REG_PWM_BRI18 0x0212
169 #define LEDRING2_REG_PWM_BRI19 0x0213
170 #define LEDRING2_REG_PWM_BRI20 0x0214
171 #define LEDRING2_REG_PWM_BRI21 0x0215
172 #define LEDRING2_REG_PWM_BRI22 0x0216
173 #define LEDRING2_REG_PWM_BRI23 0x0217
174 #define LEDRING2_REG_PWM_BRI24 0x0218
175 #define LEDRING2_REG_PWM_BRI25 0x0219
176 #define LEDRING2_REG_PWM_BRI26 0x021A
177 #define LEDRING2_REG_PWM_BRI27 0x021B
178 #define LEDRING2_REG_PWM_BRI28 0x021C
179 #define LEDRING2_REG_PWM_BRI29 0x021D
180 #define LEDRING2_REG_PWM_BRI30 0x021E
181 #define LEDRING2_REG_PWM_BRI31 0x021F
182 #define LEDRING2_REG_PWM_BRI32 0x0220
183 #define LEDRING2_REG_PWM_BRI33 0x0221
184 #define LEDRING2_REG_PWM_BRI34 0x0222
185 #define LEDRING2_REG_PWM_BRI35 0x0223
186 #define LEDRING2_REG_PWM_BRI36 0x0224
187 #define LEDRING2_REG_PWM_BRI37 0x0225
188 #define LEDRING2_REG_PWM_BRI38 0x0226
189 #define LEDRING2_REG_PWM_BRI39 0x0227
190 #define LEDRING2_REG_PWM_BRI40 0x0228
191 #define LEDRING2_REG_PWM_BRI41 0x0229
192 #define LEDRING2_REG_PWM_BRI42 0x022A
193 #define LEDRING2_REG_PWM_BRI43 0x022B
194 #define LEDRING2_REG_PWM_BRI44 0x022C
195 #define LEDRING2_REG_PWM_BRI45 0x022D
196 #define LEDRING2_REG_PWM_BRI46 0x022E
197 #define LEDRING2_REG_PWM_BRI47 0x022F
198 #define LEDRING2_REG_PWM_BRI48 0x0230
199 #define LEDRING2_REG_PWM_BRI49 0x0231
200 #define LEDRING2_REG_PWM_BRI50 0x0232
201 #define LEDRING2_REG_PWM_BRI51 0x0233
202 #define LEDRING2_REG_PWM_BRI52 0x0234
203 #define LEDRING2_REG_PWM_BRI53 0x0235
204 #define LEDRING2_REG_PWM_BRI54 0x0236
205 #define LEDRING2_REG_PWM_BRI55 0x0237
206 #define LEDRING2_REG_PWM_BRI56 0x0238
207 #define LEDRING2_REG_PWM_BRI57 0x0239
208 #define LEDRING2_REG_PWM_BRI58 0x023A
209 #define LEDRING2_REG_PWM_BRI59 0x023B
210 #define LEDRING2_REG_PWM_BRI60 0x023C
211 #define LEDRING2_REG_PWM_BRI61 0x023D
212 #define LEDRING2_REG_PWM_BRI62 0x023E
213 #define LEDRING2_REG_PWM_BRI63 0x023F
214 #define LEDRING2_REG_PWM_BRI64 0x0240
215 #define LEDRING2_REG_PWM_BRI65 0x0241
216 #define LEDRING2_REG_PWM_BRI66 0x0242
217 #define LEDRING2_REG_PWM_BRI67 0x0243
218 #define LEDRING2_REG_PWM_BRI68 0x0244
219 #define LEDRING2_REG_PWM_BRI69 0x0245
220 #define LEDRING2_REG_PWM_BRI70 0x0246
221 #define LEDRING2_REG_PWM_BRI71 0x0247
222  // ledring2_reg
224 
239 #define LEDRING2_8_9_BIT_MASK 0x00003
240 
241 #define LEDRING2_LED_DISABLE 0x00
242 #define LEDRING2_LED_ENABLE 0x01
243 
244 #define LEDRING2_OP_MODE_1 0x01
245 #define LEDRING2_OP_MODE_2 0x02
246 #define LEDRING2_OP_MODE_3 0x03
247 
253 #define LEDRING2_LED_GROUP_U1_LED_1_18 0x40
254 #define LEDRING2_LED_GROUP_U2_LED_19_36 0x44
255 #define LEDRING2_LED_GROUP_U3_LED_37_54 0x48
256  // ledring2_set
258 
273 #define LEDRING2_MAP_MIKROBUS( cfg, mikrobus ) \
274  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
275  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
276  cfg.vsy = MIKROBUS( mikrobus, MIKROBUS_PWM )
277  // ledring2_map // ledring2
280 
285 typedef struct
286 {
287  // Output pins
288  digital_out_t vsy;
290  // Modules
291  i2c_master_t i2c;
293  // I2C slave address
294  uint8_t slave_address;
296 } ledring2_t;
297 
302 typedef struct
303 {
304  pin_name_t scl;
305  pin_name_t sda;
307  pin_name_t vsy;
309  uint32_t i2c_speed;
310  uint8_t i2c_address;
313 
318 typedef enum
319 {
321  LEDRING2_ERROR = -1
322 
324 
329 typedef enum
330 {
333 
335 
352 
367 
381 
397 err_t ledring2_set_slave_address ( ledring2_t *ctx, uint8_t slave_address );
398 
419 err_t ledring2_write_reg ( ledring2_t *ctx, uint8_t led_group, uint16_t reg, uint8_t *data_in, uint8_t len );
420 
441 err_t ledring2_read_reg ( ledring2_t *ctx, uint8_t led_group, uint16_t reg, uint8_t *data_out, uint8_t len );
442 
454 
468 
482 
498 
514 err_t ledring2_set_led_pos_state ( ledring2_t *ctx, uint8_t led_pos, ledring2_led_state_t led_state );
515 
531 err_t ledring2_set_led_brightness ( ledring2_t *ctx, uint8_t led_pos, uint16_t led_brightness );
532 
533 #ifdef __cplusplus
534 }
535 #endif
536 #endif // LEDRING2_H
537  // ledring2
539 
540 // ------------------------------------------------------------------------ END
ledring2_set_slave_address
err_t ledring2_set_slave_address(ledring2_t *ctx, uint8_t slave_address)
Set I2C Slave address.
LEDRING2_ERROR
@ LEDRING2_ERROR
Definition: ledring2.h:321
ledring2_t::slave_address
uint8_t slave_address
Definition: ledring2.h:294
ledring2_return_value_t
ledring2_return_value_t
LED Ring 2 Click return value data.
Definition: ledring2.h:319
ledring2_default_cfg
err_t ledring2_default_cfg(ledring2_t *ctx)
LED Ring 2 default configuration function.
ledring2_write_reg
err_t ledring2_write_reg(ledring2_t *ctx, uint8_t led_group, uint16_t reg, uint8_t *data_in, uint8_t len)
LED Ring 2 write register function.
ledring2_t
LED Ring 2 Click context object.
Definition: ledring2.h:286
ledring2_disable
err_t ledring2_disable(ledring2_t *ctx)
LED Ring 2 disable function.
ledring2_cfg_t
LED Ring 2 Click configuration object.
Definition: ledring2.h:303
ledring2_cfg_setup
void ledring2_cfg_setup(ledring2_cfg_t *cfg)
LED Ring 2 configuration object setup function.
ledring2_read_reg
err_t ledring2_read_reg(ledring2_t *ctx, uint8_t led_group, uint16_t reg, uint8_t *data_out, uint8_t len)
LED Ring 2 read registe function.
ledring2_t::i2c
i2c_master_t i2c
Definition: ledring2.h:291
ledring2_led_state_t
ledring2_led_state_t
LED Ring 2 Click LED state data.
Definition: ledring2.h:330
ledring2_init
err_t ledring2_init(ledring2_t *ctx, ledring2_cfg_t *cfg)
LED Ring 2 initialization function.
ledring2_set_all_led_state
err_t ledring2_set_all_led_state(ledring2_t *ctx, ledring2_led_state_t led_state)
LED Ring 2 set all LED state function.
ledring2_enable
err_t ledring2_enable(ledring2_t *ctx)
LED Ring 2 enable function.
ledring2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ledring2.h:309
LEDRING2_OK
@ LEDRING2_OK
Definition: ledring2.h:320
ledring2_set_vsync
void ledring2_set_vsync(ledring2_t *ctx)
LED Ring 2 read registe function.
ledring2_cfg_t::i2c_address
uint8_t i2c_address
Definition: ledring2.h:310
ledring2_set_led_brightness
err_t ledring2_set_led_brightness(ledring2_t *ctx, uint8_t led_pos, uint16_t led_brightness)
LED Ring 2 set LED brightness function.
LEDRING2_LED_OFF
@ LEDRING2_LED_OFF
Definition: ledring2.h:331
ledring2_t::vsy
digital_out_t vsy
Definition: ledring2.h:288
ledring2_cfg_t::scl
pin_name_t scl
Definition: ledring2.h:304
ledring2_set_led_pos_state
err_t ledring2_set_led_pos_state(ledring2_t *ctx, uint8_t led_pos, ledring2_led_state_t led_state)
LED Ring 2 set LED state function.
LEDRING2_LED_ON
@ LEDRING2_LED_ON
Definition: ledring2.h:332
ledring2_cfg_t::sda
pin_name_t sda
Definition: ledring2.h:305
ledring2_cfg_t::vsy
pin_name_t vsy
Definition: ledring2.h:307