ledflash3  2.1.0.0
ledflash3.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 LEDFLASH3_H
29 #define LEDFLASH3_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 LEDFLASH3_REG_ENABLE 0x01
74 #define LEDFLASH3_REG_CONFIGURATION 0x02
75 #define LEDFLASH3_REG_FLASH_CURRENT 0x03
76 #define LEDFLASH3_REG_TOUCH_CURRENT 0x04
77 #define LEDFLASH3_REG_FAULT_FLAG 0x05
78 #define LEDFLASH3_REG_DEVICE_ID 0x06
79  // ledflash3_reg
81 
96 #define LEDFLASH3_LVP_ENABLE 0x10
97 #define LEDFLASH3_STROBE_LEVEL 0x00
98 #define LEDFLASH3_STROBE_EDGE 0x08
99 #define LEDFLASH3_STROBE_PIN_ENABLE 0x04
100 #define LEDFLASH3_MODE_FLASH 0x03
101 #define LEDFLASH3_MODE_TORCH 0x02
102 #define LEDFLASH3_MODE_IR 0x01
103 #define LEDFLASH3_MODE_STANDBY 0x00
104 
109 #define LEDFLASH3_LVP_THRESHOLD_2V9 0x00
110 #define LEDFLASH3_LVP_THRESHOLD_3V 0x02
111 #define LEDFLASH3_LVP_THRESHOLD_3V1 0x04
112 #define LEDFLASH3_LVP_THRESHOLD_3V2 0x06
113 #define LEDFLASH3_LVP_THRESHOLD_3V3 0x08
114 #define LEDFLASH3_LVP_THRESHOLD_3V4 0x0A
115 #define LEDFLASH3_LVP_THRESHOLD_3V5 0x0C
116 #define LEDFLASH3_LVP_THRESHOLD_3V6 0x0E
117 #define LEDFLASH3_TIME_OUT_40MS 0x00
118 #define LEDFLASH3_TIME_OUT_80MS 0x02
119 #define LEDFLASH3_TIME_OUT_120MS 0x04
120 #define LEDFLASH3_TIME_OUT_160MS 0x06
121 #define LEDFLASH3_TIME_OUT_200MS 0x08
122 #define LEDFLASH3_TIME_OUT_240MS 0x0A
123 #define LEDFLASH3_TIME_OUT_280MS 0x0C
124 #define LEDFLASH3_TIME_OUT_320MS 0x0E
125 #define LEDFLASH3_TIME_OUT_360MS 0x10
126 #define LEDFLASH3_TIME_OUT_400MS 0x12
127 #define LEDFLASH3_TIME_OUT_600MS 0x14
128 #define LEDFLASH3_TIME_OUT_800MS 0x16
129 #define LEDFLASH3_TIME_OUT_1000MS 0x18
130 #define LEDFLASH3_TIME_OUT_1200MS 0x1A
131 #define LEDFLASH3_TIME_OUT_1400MS 0x1C
132 #define LEDFLASH3_TIME_OUT_1600MS 0x1E
133 #define LEDFLASH3_TORCH_RAMP_TIME_1MS 0x01
134 
139 #define LEDFLASH3_LVP_FAULT_MASK 0x40
140 #define LEDFLASH3_LED_SHORT_FAULT_MASK 0x20
141 #define LEDFLASH3_THERMAL_SHDN_MASK 0x04
142 #define LEDFLASH3_THERMAL_SHDN_MASK 0x04
143 #define LEDFLASH3_OVLO_FAULT_MASK 0x02
144 #define LEDFLASH3_FLASH_TIMEOUT_MASK 0x01
145 
150 #define LEDFLASH3_SW_RESET_MASK 0x80
151 
156 #define LEDFLASH3_TORCH_CURRENT_MAX 376.0f
157 #define LEDFLASH3_TORCH_CURRENT_MIN 2.94f
158 #define LEDFLASH3_FLASH_CURRENT_MAX 1500.0f
159 #define LEDFLASH3_FLASH_CURRENT_MIN 11.72f
160 #define LEDFLASH3_ROUND_TO_NEAR_INT 0.5f
161 
167 #define LEDFLASH3_DEVICE_ADDRESS 0x64
168  // ledflash3_set
170 
185 #define LEDFLASH3_MAP_MIKROBUS( cfg, mikrobus ) \
186  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
187  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
188  cfg.stb = MIKROBUS( mikrobus, MIKROBUS_PWM )
189  // ledflash3_map // ledflash3
192 
197 typedef struct
198 {
199  // Output pins
200  digital_out_t stb;
202  // Modules
203  i2c_master_t i2c;
205  // I2C slave address
206  uint8_t slave_address;
208 } ledflash3_t;
209 
214 typedef struct
215 {
216  pin_name_t scl;
217  pin_name_t sda;
219  pin_name_t stb;
221  uint32_t i2c_speed;
222  uint8_t i2c_address;
225 
230 typedef enum
231 {
233  LEDFLASH3_ERROR = -1
234 
236 
253 
268 
282 
297 err_t ledflash3_generic_write ( ledflash3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
298 
313 err_t ledflash3_generic_read ( ledflash3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
314 
328 err_t ledflash3_write_reg ( ledflash3_t *ctx, uint8_t reg, uint8_t data_in );
329 
343 err_t ledflash3_read_reg ( ledflash3_t *ctx, uint8_t reg, uint8_t *data_out );
344 
354 
366 err_t ledflash3_set_flash_current ( ledflash3_t *ctx, float flash_current );
367 
379 err_t ledflash3_set_torch_current ( ledflash3_t *ctx, float torch_current );
380 
381 #ifdef __cplusplus
382 }
383 #endif
384 #endif // LEDFLASH3_H
385  // ledflash3
387 
388 // ------------------------------------------------------------------------ END
ledflash3_generic_write
err_t ledflash3_generic_write(ledflash3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
LED Flash 3 I2C writing function.
ledflash3_strobe_pin
void ledflash3_strobe_pin(ledflash3_t *ctx)
LED Flash 3 strobe function.
ledflash3_cfg_t
LED Flash 3 Click configuration object.
Definition: ledflash3.h:215
ledflash3_return_value_t
ledflash3_return_value_t
LED Flash 3 Click return value data.
Definition: ledflash3.h:231
ledflash3_read_reg
err_t ledflash3_read_reg(ledflash3_t *ctx, uint8_t reg, uint8_t *data_out)
LED Flash 3 regiister reading function.
ledflash3_set_torch_current
err_t ledflash3_set_torch_current(ledflash3_t *ctx, float torch_current)
LED Flash 3 set torch current function.
ledflash3_cfg_t::sda
pin_name_t sda
Definition: ledflash3.h:217
LEDFLASH3_OK
@ LEDFLASH3_OK
Definition: ledflash3.h:232
ledflash3_generic_read
err_t ledflash3_generic_read(ledflash3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
LED Flash 3 I2C reading function.
ledflash3_write_reg
err_t ledflash3_write_reg(ledflash3_t *ctx, uint8_t reg, uint8_t data_in)
LED Flash 3 register writing function.
ledflash3_t::slave_address
uint8_t slave_address
Definition: ledflash3.h:206
ledflash3_cfg_t::i2c_address
uint8_t i2c_address
Definition: ledflash3.h:222
LEDFLASH3_ERROR
@ LEDFLASH3_ERROR
Definition: ledflash3.h:233
ledflash3_t::i2c
i2c_master_t i2c
Definition: ledflash3.h:203
ledflash3_default_cfg
err_t ledflash3_default_cfg(ledflash3_t *ctx)
LED Flash 3 default configuration function.
ledflash3_init
err_t ledflash3_init(ledflash3_t *ctx, ledflash3_cfg_t *cfg)
LED Flash 3 initialization function.
ledflash3_cfg_t::scl
pin_name_t scl
Definition: ledflash3.h:216
ledflash3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ledflash3.h:221
ledflash3_t
LED Flash 3 Click context object.
Definition: ledflash3.h:198
ledflash3_cfg_t::stb
pin_name_t stb
Definition: ledflash3.h:219
ledflash3_set_flash_current
err_t ledflash3_set_flash_current(ledflash3_t *ctx, float flash_current)
LED Flash 3 set flash current function.
ledflash3_t::stb
digital_out_t stb
Definition: ledflash3.h:200
ledflash3_cfg_setup
void ledflash3_cfg_setup(ledflash3_cfg_t *cfg)
LED Flash 3 configuration object setup function.