leddriver19  2.1.0.0
leddriver19.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 LEDDRIVER19_H
29 #define LEDDRIVER19_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_i2c_master.h"
52 
73 #define LEDDRIVER19_REG_DEVICE_ID 0x00
74 #define LEDDRIVER19_REG_DEVICE_EN 0x01
75 #define LEDDRIVER19_REG_CH_EN_LOW 0x02
76 #define LEDDRIVER19_REG_CH_EN_HIGH 0x03
77 #define LEDDRIVER19_REG_CONFIG 0x04
78 #define LEDDRIVER19_REG_FAULT_MASK 0x05
79 #define LEDDRIVER19_REG_FAULT_INT 0x06
80 #define LEDDRIVER19_REG_OPEN_LED_LOW 0x07
81 #define LEDDRIVER19_REG_OPEN_LED_HIGH 0x08
82 #define LEDDRIVER19_REG_CUR_LED_CS0 0x09
83 #define LEDDRIVER19_REG_CUR_LED_CS1 0x0A
84 #define LEDDRIVER19_REG_CUR_LED_CS2 0x0B
85 #define LEDDRIVER19_REG_CUR_LED_CS3 0x0C
86 #define LEDDRIVER19_REG_CUR_LED_CS4 0x0D
87 #define LEDDRIVER19_REG_CUR_LED_CS5 0x0E
88 #define LEDDRIVER19_REG_CUR_LED_CS6 0x0F
89 #define LEDDRIVER19_REG_CUR_LED_CS7 0x10
90 #define LEDDRIVER19_REG_CUR_LED_CS8 0x11
91 #define LEDDRIVER19_REG_CUR_LED_CS9 0x12
92 #define LEDDRIVER19_REG_CUR_LED_CS10 0x13
93 #define LEDDRIVER19_REG_CUR_LED_CS11 0x14
94 #define LEDDRIVER19_REG_PATTERN_SEQ_REP 0x15
95 #define LEDDRIVER19_REG_PATTERN_0_DUR 0x16
96 #define LEDDRIVER19_REG_PATTERN_1_DUR 0x17
97 #define LEDDRIVER19_REG_PATTERN_2_DUR 0x18
98 #define LEDDRIVER19_REG_PATTERN_3_DUR 0x19
99 #define LEDDRIVER19_REG_PATTERN_4_DUR 0x1A
100 #define LEDDRIVER19_REG_PATTERN_5_DUR 0x1B
101 #define LEDDRIVER19_REG_PATTERN_6_DUR 0x1C
102 #define LEDDRIVER19_REG_PATTERN_7_DUR 0x1D
103 #define LEDDRIVER19_REG_PWMREG_OFFSET 0x1E
104 #define LEDDRIVER19_REG_CLOCK_CONFIG 0xE0
105 
106  // leddriver19_reg
108 
123 #define LEDDRIVER19_DEVICE_ID 0x12
124 
130 #define LEDDRIVER19_PIN_STATE_HIGH 0x01
131 #define LEDDRIVER19_PIN_STATE_LOW 0x00
132 
138 #define LEDDRIVER19_SW_RESET 0x80
139 #define LEDDRIVER19_ENABLE 0x01
140 
146 #define LEDDRIVER19_PATSEL_0 0x00
147 #define LEDDRIVER19_PATSEL_1 0x01
148 #define LEDDRIVER19_PATSEL_2 0x02
149 #define LEDDRIVER19_PATSEL_3 0x03
150 #define LEDDRIVER19_PATSEL_4 0x04
151 #define LEDDRIVER19_PATSEL_5 0x05
152 #define LEDDRIVER19_PATSEL_6 0x06
153 #define LEDDRIVER19_PATSEL_7 0x07
154 
160 #define LEDDRIVER19_CH_SEL_0 0x00
161 #define LEDDRIVER19_CH_SEL_1 0x01
162 #define LEDDRIVER19_CH_SEL_2 0x02
163 #define LEDDRIVER19_CH_SEL_3 0x03
164 #define LEDDRIVER19_CH_SEL_4 0x04
165 #define LEDDRIVER19_CH_SEL_5 0x05
166 #define LEDDRIVER19_CH_SEL_6 0x06
167 #define LEDDRIVER19_CH_SEL_7 0x07
168 #define LEDDRIVER19_CH_SEL_8 0x08
169 #define LEDDRIVER19_CH_SEL_9 0x09
170 #define LEDDRIVER19_CH_SEL_10 0x0A
171 #define LEDDRIVER19_CH_SEL_11 0x0B
172 
178 #define LEDDRIVER19_SHFT_EN 0x08
179 #define LEDDRIVER19_SHFT_DIS 0x00
180 #define LEDDRIVER19_GCTRL_EN 0x01
181 #define LEDDRIVER19_GCTRL_DIS 0x00
182 #define LEDDRIVER19_PATSR_RUNING 0x01
183 #define LEDDRIVER19_PATSR_DONE 0x00
184 #define LEDDRIVER19_PATS_EN 0x01
185 #define LEDDRIVER19_PATS_DIS 0x00
186 
192 #define LEDDRIVER19_OVTP_MASK 0x01
193 #define LEDDRIVER19_OPEN_MASK 0x02
194 #define LEDDRIVER19_PAT_MASK 0x04
195 #define LEDDRIVER19_SOF_MASK 0x08
196 
202 #define LEDDRIVER19_OVTP 0x01
203 #define LEDDRIVER19_OPEN 0x02
204 #define LEDDRIVER19_PAT 0x04
205 #define LEDDRIVER19_SOF 0x08
206 
212 #define LEDDRIVER19_PATTERN_SEL_OFFSET 0x18
213 
219 #define LEDDRIVER19_PWM_MASK 0x0FFFu
220 
226 #define LEDDRIVER19_CS0_OPEN 0x0001u
227 #define LEDDRIVER19_CS1_OPEN 0x0002u
228 #define LEDDRIVER19_CS2_OPEN 0x0004u
229 #define LEDDRIVER19_CS3_OPEN 0x0008u
230 #define LEDDRIVER19_CS4_OPEN 0x0010u
231 #define LEDDRIVER19_CS5_OPEN 0x0020u
232 #define LEDDRIVER19_CS6_OPEN 0x0040u
233 #define LEDDRIVER19_CS7_OPEN 0x0080u
234 #define LEDDRIVER19_CS8_OPEN 0x0100u
235 #define LEDDRIVER19_CS9_OPEN 0x0200u
236 #define LEDDRIVER19_CS10_OPEN 0x0400u
237 #define LEDDRIVER19_CS11_OPEN 0x0800u
238 
244 #define LEDDRIVER19_CS0_ENABLE 0x0001u
245 #define LEDDRIVER19_CS1_ENABLE 0x0002u
246 #define LEDDRIVER19_CS2_ENABLE 0x0004u
247 #define LEDDRIVER19_CS3_ENABLE 0x0008u
248 #define LEDDRIVER19_CS4_ENABLE 0x0010u
249 #define LEDDRIVER19_CS5_ENABLE 0x0020u
250 #define LEDDRIVER19_CS6_ENABLE 0x0040u
251 #define LEDDRIVER19_CS7_ENABLE 0x0080u
252 #define LEDDRIVER19_CS8_ENABLE 0x0100u
253 #define LEDDRIVER19_CS9_ENABLE 0x0200u
254 #define LEDDRIVER19_CS10_ENABLE 0x0400u
255 #define LEDDRIVER19_CS11_ENABLE 0x0800u
256 #define LEDDRIVER19_CS_ENABLE_ALL 0x0FFFu
257 
263 #define LEDDRIVER19_PWM_VAL_CONVERSION 40.95f
264 #define LEDDRIVER19_CURRENT_STEP_TO_MA 0.07843f
265 #define LEDDRIVER19_CURRENT_STEP_TO_HEX 12.75f
266 
272 #define LEDDRIVER19_DEVICE_ADDRESS_0 0x58
273 #define LEDDRIVER19_DEVICE_ADDRESS_1 0x59
274 #define LEDDRIVER19_DEVICE_ADDRESS_2 0x5A
275 #define LEDDRIVER19_DEVICE_ADDRESS_3 0x5B
276  // leddriver19_set
278 
293 #define LEDDRIVER19_MAP_MIKROBUS( cfg, mikrobus ) \
294  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
295  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
296  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
297  // leddriver19_map // leddriver19
300 
305 typedef struct
306 {
307  // Input pins
308  digital_in_t int_pin;
310  // Modules
311  i2c_master_t i2c;
313  // I2C slave address
314  uint8_t slave_address;
316 } leddriver19_t;
317 
322 typedef struct
323 {
324  pin_name_t scl;
325  pin_name_t sda;
327  pin_name_t int_pin;
329  uint32_t i2c_speed;
330  uint8_t i2c_address;
333 
338 typedef enum
339 {
341  LEDDRIVER19_ERROR = -1
342 
344 
361 
376 
390 
405 err_t leddriver19_generic_write ( leddriver19_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
406 
421 err_t leddriver19_generic_read ( leddriver19_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
422 
432 
446 err_t leddriver19_write_reg ( leddriver19_t *ctx, uint8_t reg, uint8_t data_in );
447 
461 err_t leddriver19_read_reg ( leddriver19_t *ctx, uint8_t reg, uint8_t *data_out );
462 
474 
486 err_t leddriver19_enable_channels ( leddriver19_t *ctx, uint16_t channels_en );
487 
499 err_t leddriver19_disable_channels ( leddriver19_t *ctx, uint16_t channels_dis );
500 
501 
515 err_t leddriver19_set_pattern_pwm ( leddriver19_t *ctx, uint8_t pattern_sel, uint8_t channel_sel,
516  float pwm_value );
517 
530 err_t leddriver19_get_ch_current ( leddriver19_t *ctx, uint8_t channel_sel, float *current_val );
531 
544 err_t leddriver19_set_ch_current ( leddriver19_t *ctx, uint8_t channel_sel, float current_val );
545 
557 err_t leddriver19_get_int_data ( leddriver19_t *ctx, uint8_t *int_data );
558 
570 err_t leddriver19_get_nc_led ( leddriver19_t *ctx, uint16_t *led_data );
571 
572 #ifdef __cplusplus
573 }
574 #endif
575 #endif // LEDDRIVER19_H
576  // leddriver19
578 
579 // ------------------------------------------------------------------------ END
leddriver19_cfg_setup
void leddriver19_cfg_setup(leddriver19_cfg_t *cfg)
LED Driver 19 configuration object setup function.
leddriver19_disable_channels
err_t leddriver19_disable_channels(leddriver19_t *ctx, uint16_t channels_dis)
LED Driver 19 disable channels function.
leddriver19_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: leddriver19.h:329
leddriver19_init
err_t leddriver19_init(leddriver19_t *ctx, leddriver19_cfg_t *cfg)
LED Driver 19 initialization function.
leddriver19_t
LED Driver 19 Click context object.
Definition: leddriver19.h:306
leddriver19_get_nc_led
err_t leddriver19_get_nc_led(leddriver19_t *ctx, uint16_t *led_data)
LED Driver 19 get LED open ( NC channels ) data function.
leddriver19_t::slave_address
uint8_t slave_address
Definition: leddriver19.h:314
leddriver19_t::int_pin
digital_in_t int_pin
Definition: leddriver19.h:308
LEDDRIVER19_ERROR
@ LEDDRIVER19_ERROR
Definition: leddriver19.h:341
leddriver19_cfg_t::scl
pin_name_t scl
Definition: leddriver19.h:324
leddriver19_default_cfg
err_t leddriver19_default_cfg(leddriver19_t *ctx)
LED Driver 19 default configuration function.
leddriver19_get_ch_current
err_t leddriver19_get_ch_current(leddriver19_t *ctx, uint8_t channel_sel, float *current_val)
LED Driver 19 get channel current value function.
leddriver19_get_int_data
err_t leddriver19_get_int_data(leddriver19_t *ctx, uint8_t *int_data)
LED Driver 19 get interrupt register data function.
leddriver19_cfg_t::i2c_address
uint8_t i2c_address
Definition: leddriver19.h:330
leddriver19_sw_reset
err_t leddriver19_sw_reset(leddriver19_t *ctx)
LED Driver 19 software reset function.
leddriver19_generic_read
err_t leddriver19_generic_read(leddriver19_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
LED Driver 19 I2C reading function.
leddriver19_generic_write
err_t leddriver19_generic_write(leddriver19_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
LED Driver 19 I2C writing function.
LEDDRIVER19_OK
@ LEDDRIVER19_OK
Definition: leddriver19.h:340
leddriver19_set_ch_current
err_t leddriver19_set_ch_current(leddriver19_t *ctx, uint8_t channel_sel, float current_val)
LED Driver 19 set channel current value function.
leddriver19_set_pattern_pwm
err_t leddriver19_set_pattern_pwm(leddriver19_t *ctx, uint8_t pattern_sel, uint8_t channel_sel, float pwm_value)
LED Driver 19 set pattern PWM value function.
leddriver19_read_reg
err_t leddriver19_read_reg(leddriver19_t *ctx, uint8_t reg, uint8_t *data_out)
LED Driver 19 I2C register reading function.
leddriver19_write_reg
err_t leddriver19_write_reg(leddriver19_t *ctx, uint8_t reg, uint8_t data_in)
LED Driver 19 I2C register writing function.
leddriver19_enable_channels
err_t leddriver19_enable_channels(leddriver19_t *ctx, uint16_t channels_en)
LED Driver 19 enables channels function.
leddriver19_cfg_t::sda
pin_name_t sda
Definition: leddriver19.h:325
leddriver19_t::i2c
i2c_master_t i2c
Definition: leddriver19.h:311
leddriver19_cfg_t
LED Driver 19 Click configuration object.
Definition: leddriver19.h:323
leddriver19_return_value_t
leddriver19_return_value_t
LED Driver 19 Click return value data.
Definition: leddriver19.h:339
leddriver19_cfg_t::int_pin
pin_name_t int_pin
Definition: leddriver19.h:327
leddriver19_get_int_pin
uint8_t leddriver19_get_int_pin(leddriver19_t *ctx)
LED Driver 19 get interrupt pin state function.