ledflash4  2.1.0.0
ledflash4.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 LEDFLASH4_H
29 #define LEDFLASH4_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 LEDFLASH4_REG_CHIP_ID 0x00
74 #define LEDFLASH4_REG_CURRENT_SET_LED1 0x01
75 #define LEDFLASH4_REG_CURRENT_SET_LED2 0x02
76 #define LEDFLASH4_REG_LOW_VOLTAGE 0x04
77 #define LEDFLASH4_REG_FLASH_TIMER 0x05
78 #define LEDFLASH4_REG_CONTROL 0x06
79 #define LEDFLASH4_REG_STROBE_SIGNALING 0x07
80 #define LEDFLASH4_REG_FAULT 0x08
81 #define LEDFLASH4_REG_PWM_AND_INDICATOR 0x09
82 #define LEDFLASH4_REG_MINIMUM_LED_CURRENT 0x0E
83 #define LEDFLASH4_REG_ACTUAL_LED_CURRENT 0x0F
84 #define LEDFLASH4_REG_PASSWORD 0x80
85 #define LEDFLASH4_REG_CURRENT_BOOST 0x81
86  // ledflash4_reg
88 
103 #define LEDFLASH4_DEVICE_ID 0xB0
104 #define LEDFLASH4_DEVICE_ID_MASK 0xF8
105 
110 #define LEDFLASH4_LED_CURRENT_MIN 0
111 #define LEDFLASH4_LED_CURRENT_MAX 900
112 #define LEDFLASH4_LED_CURRENT_DEFAULT 50
113 #define LEDFLASH4_LED_CURRENT_REG_MASK 0xFF
114 #define LEDFLASH4_LED_CURRENT_ROUND_INT 0.5f
115 
120 #define LEDFLASH4_VIN_LOW_V_RUN_DIS 0x00
121 #define LEDFLASH4_VIN_LOW_V_RUN_3V 0x01
122 #define LEDFLASH4_VIN_LOW_V_RUN_3_07V 0x02
123 #define LEDFLASH4_VIN_LOW_V_RUN_3_14V 0x03
124 #define LEDFLASH4_VIN_LOW_V_RUN_3_22V 0x04
125 #define LEDFLASH4_VIN_LOW_V_RUN_3_3V 0x05
126 #define LEDFLASH4_VIN_LOW_V_RUN_3_38V 0x06
127 #define LEDFLASH4_VIN_LOW_V_RUN_3_47V 0x07
128 #define LEDFLASH4_VIN_LOW_V_RUN_MASK 0x07
129 #define LEDFLASH4_VIN_LOW_V_DIS 0x00
130 #define LEDFLASH4_VIN_LOW_V_3V 0x08
131 #define LEDFLASH4_VIN_LOW_V_3_07V 0x10
132 #define LEDFLASH4_VIN_LOW_V_3_14V 0x18
133 #define LEDFLASH4_VIN_LOW_V_3_22V 0x20
134 #define LEDFLASH4_VIN_LOW_V_3_3V 0x28
135 #define LEDFLASH4_VIN_LOW_V_3_38V 0x30
136 #define LEDFLASH4_VIN_LOW_V_3_47V 0x38
137 #define LEDFLASH4_VIN_LOW_V_MASK 0x38
138 #define LEDFLASH4_VIN_LOW_V_SHUTDOWN_MASK 0x40
139 #define LEDFLASH4_CONST_V_MODE_MASK 0x80
140 
145 #define LEDFLASH4_FLASH_TIMER_36MS 0x23
146 
151 #define LEDFLASH4_CONTROL_MODE_SHUTDOWN 0x00
152 #define LEDFLASH4_CONTROL_MODE_INDICATOR 0x01
153 #define LEDFLASH4_CONTROL_MODE_ASSIST_LIGHT 0x02
154 #define LEDFLASH4_CONTROL_MODE_FLASH 0x03
155 #define LEDFLASH4_CONTROL_MODE_MASK 0x03
156 #define LEDFLASH4_CONTROL_OUT_OFF 0x00
157 #define LEDFLASH4_CONTROL_OUT_ON 0x08
158 #define LEDFLASH4_CONTROL_OUT_MASK 0x08
159 #define LEDFLASH4_CONTROL_AUTO_STROBE_OFF 0x00
160 #define LEDFLASH4_CONTROL_AUTO_STROBE_ON 0x10
161 #define LEDFLASH4_CONTROL_AUTO_STROBE_MASK 0x10
162 #define LEDFLASH4_CONTROL_STROBE_TYPE_EDGE 0x00
163 #define LEDFLASH4_CONTROL_STROBE_TYPE_LEVEL 0x40
164 #define LEDFLASH4_CONTROL_STROBE_TYPE_MASK 0x40
165 #define LEDFLASH4_CONTROL_STROBE_INPUT_OFF 0x00
166 #define LEDFLASH4_CONTROL_STROBE_INPUT_ON 0x80
167 #define LEDFLASH4_CONTROL_STROBE_INPUT_MASK 0x80
168 
173 #define LEDFLASH4_FAULT_UVLO 0x01
174 #define LEDFLASH4_FAULT_TIMEOUT 0x10
175 #define LEDFLASH4_FAULT_OVERTEMP 0x20
176 #define LEDFLASH4_FAULT_LED_SHORT 0x40
177 #define LEDFLASH4_FAULT_OVP 0x80
178 
183 #define LEDFLASH4_PWM_INCT_1_OF_16_DC 0x00
184 #define LEDFLASH4_PWM_INCT_2_OF_16_DC 0x01
185 #define LEDFLASH4_PWM_INCT_3_OF_16_DC 0x02
186 #define LEDFLASH4_PWM_INCT_4_OF_16_DC 0x03
187 #define LEDFLASH4_PWM_INCT_MASK 0x03
188 #define LEDFLASH4_PWM_FREQ_SWITCH_ON_MASK 0x04
189 #define LEDFLASH4_PWM_LED_OUT1ABOVE2_MASK 0x08
190 #define LEDFLASH4_PWM_LED_OUT2ABOVE1_MASK 0x10
191 #define LEDFLASH4_PWM_LOAD_BALANCE_ON_MASK 0x20
192 
197 #define LEDFLASH4_STROBE_PIN_LOW 0
198 #define LEDFLASH4_STROBE_PIN_HIGH 1
199 
205 #define LEDFLASH4_DEVICE_ADDRESS_0 0x30
206 #define LEDFLASH4_DEVICE_ADDRESS_1 0x32
207  // ledflash4_set
209 
224 #define LEDFLASH4_MAP_MIKROBUS( cfg, mikrobus ) \
225  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
226  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
227  cfg.stb = MIKROBUS( mikrobus, MIKROBUS_PWM );
228  // ledflash4_map // ledflash4
231 
236 typedef struct
237 {
238  // Output pins
239  digital_out_t stb;
241  // Modules
242  i2c_master_t i2c;
244  // I2C slave address
245  uint8_t slave_address;
247 } ledflash4_t;
248 
253 typedef struct
254 {
255  pin_name_t scl;
256  pin_name_t sda;
258  pin_name_t stb;
260  uint32_t i2c_speed;
261  uint8_t i2c_address;
264 
269 typedef enum
270 {
272  LEDFLASH4_ERROR = -1
273 
275 
292 
307 
321 
336 err_t ledflash4_generic_write ( ledflash4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
337 
352 err_t ledflash4_generic_read ( ledflash4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
353 
366 err_t ledflash4_write_reg ( ledflash4_t *ctx, uint8_t reg, uint8_t data_in );
367 
380 err_t ledflash4_read_reg ( ledflash4_t *ctx, uint8_t reg, uint8_t *data_out );
381 
391 void ledflash4_set_stb_pin ( ledflash4_t *ctx, uint8_t state );
392 
404 
416 err_t ledflash4_set_led1_current ( ledflash4_t *ctx, uint16_t led_current );
417 
429 err_t ledflash4_set_led2_current ( ledflash4_t *ctx, uint16_t led_current );
430 
431 #ifdef __cplusplus
432 }
433 #endif
434 #endif // LEDFLASH4_H
435  // ledflash4
437 
438 // ------------------------------------------------------------------------ END
ledflash4_return_value_t
ledflash4_return_value_t
LED Flash 4 Click return value data.
Definition: ledflash4.h:270
ledflash4_t::slave_address
uint8_t slave_address
Definition: ledflash4.h:245
ledflash4_cfg_t
LED Flash 4 Click configuration object.
Definition: ledflash4.h:254
ledflash4_cfg_setup
void ledflash4_cfg_setup(ledflash4_cfg_t *cfg)
LED Flash 4 configuration object setup function.
ledflash4_read_reg
err_t ledflash4_read_reg(ledflash4_t *ctx, uint8_t reg, uint8_t *data_out)
LED Flash 4 read reg function.
ledflash4_t::stb
digital_out_t stb
Definition: ledflash4.h:239
ledflash4_write_reg
err_t ledflash4_write_reg(ledflash4_t *ctx, uint8_t reg, uint8_t data_in)
LED Flash 4 write reg function.
ledflash4_cfg_t::sda
pin_name_t sda
Definition: ledflash4.h:256
ledflash4_cfg_t::stb
pin_name_t stb
Definition: ledflash4.h:258
ledflash4_cfg_t::i2c_address
uint8_t i2c_address
Definition: ledflash4.h:261
LEDFLASH4_OK
@ LEDFLASH4_OK
Definition: ledflash4.h:271
ledflash4_init
err_t ledflash4_init(ledflash4_t *ctx, ledflash4_cfg_t *cfg)
LED Flash 4 initialization function.
ledflash4_t
LED Flash 4 Click context object.
Definition: ledflash4.h:237
ledflash4_set_led1_current
err_t ledflash4_set_led1_current(ledflash4_t *ctx, uint16_t led_current)
LED Flash 4 set LED1 current function.
LEDFLASH4_ERROR
@ LEDFLASH4_ERROR
Definition: ledflash4.h:272
ledflash4_check_communication
err_t ledflash4_check_communication(ledflash4_t *ctx)
LED Flash 4 check communication function.
ledflash4_generic_read
err_t ledflash4_generic_read(ledflash4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
LED Flash 4 I2C reading function.
ledflash4_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ledflash4.h:260
ledflash4_default_cfg
err_t ledflash4_default_cfg(ledflash4_t *ctx)
LED Flash 4 default configuration function.
ledflash4_cfg_t::scl
pin_name_t scl
Definition: ledflash4.h:255
ledflash4_t::i2c
i2c_master_t i2c
Definition: ledflash4.h:242
ledflash4_set_led2_current
err_t ledflash4_set_led2_current(ledflash4_t *ctx, uint16_t led_current)
LED Flash 4 set LED2 current function.
ledflash4_set_stb_pin
void ledflash4_set_stb_pin(ledflash4_t *ctx, uint8_t state)
LED Flash 4 set STB pin function.
ledflash4_generic_write
err_t ledflash4_generic_write(ledflash4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
LED Flash 4 I2C writing function.