ledflash2 2.0.0.0
ledflash2.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef LEDFLASH2_H
36#define LEDFLASH2_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define LEDFLASH2_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.fi = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70 cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71 cfg.fen = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
72 cfg.ten = MIKROBUS( mikrobus, MIKROBUS_INT );
79#define LEDFLASH2_RETVAL uint8_t
80
81#define LEDFLASH2_OK 0x00
82#define LEDFLASH2_INIT_ERROR 0xFF
89#define LEDFLASH2_MODE_OFF 0x00
90#define LEDFLASH2_MODE_FLASH 0x01
91#define LEDFLASH2_MODE_TORCH 0x02
98#define LEDFLASH2_CUR_100 0x00
99#define LEDFLASH2_CUR_90 0x01
100#define LEDFLASH2_CUR_80 0x02
101#define LEDFLASH2_CUR_70 0x03
102#define LEDFLASH2_CUR_63 0x04
103#define LEDFLASH2_CUR_56 0x05
104#define LEDFLASH2_CUR_50 0x06
105#define LEDFLASH2_CUR_44 0x07
106#define LEDFLASH2_CUR_39 0x08
107#define LEDFLASH2_CUR_35 0x09
108#define LEDFLASH2_CUR_31 0x0A
109#define LEDFLASH2_CUR_28 0x0B
110#define LEDFLASH2_CUR_25 0x0C
111#define LEDFLASH2_CUR_22 0x0D
112#define LEDFLASH2_CUR_20 0x0E
113#define LEDFLASH2_CUR_18 0x0F
120#define LEDFLASH2_FTMR_1250 0xE0
121#define LEDFLASH2_FTMR_1093 0xC0
122#define LEDFLASH2_FTMR_937 0xA0
123#define LEDFLASH2_FTMR_781 0x80
124#define LEDFLASH2_FTMR_625 0x60
125#define LEDFLASH2_FTMR_468 0x40
126#define LEDFLASH2_FTMR_312 0x20
127#define LEDFLASH2_FTMR_156 0x00
130 // End group macro
131// --------------------------------------------------------------- PUBLIC TYPES
140typedef struct
141{
142 // Output pins
143
144 digital_out_t fi;
145 digital_out_t en;
146 digital_out_t fen;
147 digital_out_t ten;
148
149 // Modules
150
151 i2c_master_t i2c;
152
153 // ctx variable
154
156
158
162typedef struct
163{
164 // Communication gpio pins
165
166 pin_name_t scl;
167 pin_name_t sda;
168
169 // Additional gpio pins
170
171 pin_name_t fi;
172 pin_name_t en;
173 pin_name_t fen;
174 pin_name_t ten;
175
176 // static variable
177
178 uint32_t i2c_speed;
179 uint8_t i2c_address;
180
182
183 // End types group
184// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
185
191#ifdef __cplusplus
192extern "C"{
193#endif
194
204
213
224void ledflash2_generic_write ( ledflash2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
225
236void ledflash2_generic_read ( ledflash2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
237
246uint8_t ledflash2_read_register ( ledflash2_t *ctx, uint8_t reg_address );
247
257void ledflash2_write_register ( ledflash2_t *ctx, uint8_t reg_address, uint8_t reg_data );
258
276void ledflash2_set_mode ( ledflash2_t *ctx, uint8_t mode, uint8_t intensity, uint8_t flash_duration );
277
287void ledflash2_toggle_flash_inhibit ( ledflash2_t *ctx, uint8_t pin_state );
288
289#ifdef __cplusplus
290}
291#endif
292#endif // _LEDFLASH2_H_
293
294 // End public_function group
296
297// ------------------------------------------------------------------------- END
#define LEDFLASH2_RETVAL
Definition ledflash2.h:79
void ledflash2_toggle_flash_inhibit(ledflash2_t *ctx, uint8_t pin_state)
Toggle flash inhibit function.
void ledflash2_generic_read(ledflash2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void ledflash2_generic_write(ledflash2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void ledflash2_cfg_setup(ledflash2_cfg_t *cfg)
Config Object Initialization function.
LEDFLASH2_RETVAL ledflash2_init(ledflash2_t *ctx, ledflash2_cfg_t *cfg)
Initialization function.
void ledflash2_write_register(ledflash2_t *ctx, uint8_t reg_address, uint8_t reg_data)
Write register function.
void ledflash2_set_mode(ledflash2_t *ctx, uint8_t mode, uint8_t intensity, uint8_t flash_duration)
Set mode function.
uint8_t ledflash2_read_register(ledflash2_t *ctx, uint8_t reg_address)
Read register function.
Click configuration structure definition.
Definition ledflash2.h:163
uint32_t i2c_speed
Definition ledflash2.h:178
pin_name_t fen
Definition ledflash2.h:173
pin_name_t fi
Definition ledflash2.h:171
pin_name_t ten
Definition ledflash2.h:174
pin_name_t scl
Definition ledflash2.h:166
pin_name_t en
Definition ledflash2.h:172
pin_name_t sda
Definition ledflash2.h:167
uint8_t i2c_address
Definition ledflash2.h:179
Click ctx object definition.
Definition ledflash2.h:141
digital_out_t ten
Definition ledflash2.h:147
i2c_master_t i2c
Definition ledflash2.h:151
digital_out_t fen
Definition ledflash2.h:146
digital_out_t en
Definition ledflash2.h:145
uint8_t slave_address
Definition ledflash2.h:155
digital_out_t fi
Definition ledflash2.h:144