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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define LEDFLASH2_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.fi = MIKROBUS( mikrobus, MIKROBUS_AN ); \
66  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
67  cfg.fen = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
68  cfg.ten = MIKROBUS( mikrobus, MIKROBUS_INT );
69 
75 #define LEDFLASH2_RETVAL uint8_t
76 
77 #define LEDFLASH2_OK 0x00
78 #define LEDFLASH2_INIT_ERROR 0xFF
79 
85 #define LEDFLASH2_MODE_OFF 0x00
86 #define LEDFLASH2_MODE_FLASH 0x01
87 #define LEDFLASH2_MODE_TORCH 0x02
88 
94 #define LEDFLASH2_CUR_100 0x00
95 #define LEDFLASH2_CUR_90 0x01
96 #define LEDFLASH2_CUR_80 0x02
97 #define LEDFLASH2_CUR_70 0x03
98 #define LEDFLASH2_CUR_63 0x04
99 #define LEDFLASH2_CUR_56 0x05
100 #define LEDFLASH2_CUR_50 0x06
101 #define LEDFLASH2_CUR_44 0x07
102 #define LEDFLASH2_CUR_39 0x08
103 #define LEDFLASH2_CUR_35 0x09
104 #define LEDFLASH2_CUR_31 0x0A
105 #define LEDFLASH2_CUR_28 0x0B
106 #define LEDFLASH2_CUR_25 0x0C
107 #define LEDFLASH2_CUR_22 0x0D
108 #define LEDFLASH2_CUR_20 0x0E
109 #define LEDFLASH2_CUR_18 0x0F
110 
116 #define LEDFLASH2_FTMR_1250 0xE0
117 #define LEDFLASH2_FTMR_1093 0xC0
118 #define LEDFLASH2_FTMR_937 0xA0
119 #define LEDFLASH2_FTMR_781 0x80
120 #define LEDFLASH2_FTMR_625 0x60
121 #define LEDFLASH2_FTMR_468 0x40
122 #define LEDFLASH2_FTMR_312 0x20
123 #define LEDFLASH2_FTMR_156 0x00
124  // End group macro
127 // --------------------------------------------------------------- PUBLIC TYPES
136 typedef struct
137 {
138  // Output pins
139 
140  digital_out_t fi;
141  digital_out_t en;
142  digital_out_t fen;
143  digital_out_t ten;
144 
145  // Modules
146 
147  i2c_master_t i2c;
148 
149  // ctx variable
150 
151  uint8_t slave_address;
152 
153 } ledflash2_t;
154 
158 typedef struct
159 {
160  // Communication gpio pins
161 
162  pin_name_t scl;
163  pin_name_t sda;
164 
165  // Additional gpio pins
166 
167  pin_name_t fi;
168  pin_name_t en;
169  pin_name_t fen;
170  pin_name_t ten;
171 
172  // static variable
173 
174  uint32_t i2c_speed;
175  uint8_t i2c_address;
176 
178  // End types group
180 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
181 
187 #ifdef __cplusplus
188 extern "C"{
189 #endif
190 
200 
209 
220 void ledflash2_generic_write ( ledflash2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
221 
232 void ledflash2_generic_read ( ledflash2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
233 
242 uint8_t ledflash2_read_register ( ledflash2_t *ctx, uint8_t reg_address );
243 
253 void ledflash2_write_register ( ledflash2_t *ctx, uint8_t reg_address, uint8_t reg_data );
254 
272 void ledflash2_set_mode ( ledflash2_t *ctx, uint8_t mode, uint8_t intensity, uint8_t flash_duration );
273 
283 void ledflash2_toggle_flash_inhibit ( ledflash2_t *ctx, uint8_t pin_state );
284 
285 #ifdef __cplusplus
286 }
287 #endif
288 #endif // _LEDFLASH2_H_
289  // End public_function group
292 
293 // ------------------------------------------------------------------------- END
ledflash2_t
Click ctx object definition.
Definition: ledflash2.h:137
LEDFLASH2_RETVAL
#define LEDFLASH2_RETVAL
Definition: ledflash2.h:75
ledflash2_cfg_t::en
pin_name_t en
Definition: ledflash2.h:168
ledflash2_t::i2c
i2c_master_t i2c
Definition: ledflash2.h:147
ledflash2_cfg_t
Click configuration structure definition.
Definition: ledflash2.h:159
ledflash2_t::slave_address
uint8_t slave_address
Definition: ledflash2.h:151
ledflash2_t::fi
digital_out_t fi
Definition: ledflash2.h:140
ledflash2_cfg_t::fi
pin_name_t fi
Definition: ledflash2.h:167
ledflash2_t::ten
digital_out_t ten
Definition: ledflash2.h:143
ledflash2_t::en
digital_out_t en
Definition: ledflash2.h:141
ledflash2_t::fen
digital_out_t fen
Definition: ledflash2.h:142
ledflash2_init
LEDFLASH2_RETVAL ledflash2_init(ledflash2_t *ctx, ledflash2_cfg_t *cfg)
Initialization function.
ledflash2_generic_read
void ledflash2_generic_read(ledflash2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
ledflash2_write_register
void ledflash2_write_register(ledflash2_t *ctx, uint8_t reg_address, uint8_t reg_data)
Write register function.
ledflash2_read_register
uint8_t ledflash2_read_register(ledflash2_t *ctx, uint8_t reg_address)
Read register function.
ledflash2_cfg_t::fen
pin_name_t fen
Definition: ledflash2.h:169
ledflash2_generic_write
void ledflash2_generic_write(ledflash2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
ledflash2_cfg_setup
void ledflash2_cfg_setup(ledflash2_cfg_t *cfg)
Config Object Initialization function.
ledflash2_cfg_t::scl
pin_name_t scl
Definition: ledflash2.h:162
ledflash2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ledflash2.h:174
ledflash2_cfg_t::sda
pin_name_t sda
Definition: ledflash2.h:163
ledflash2_toggle_flash_inhibit
void ledflash2_toggle_flash_inhibit(ledflash2_t *ctx, uint8_t pin_state)
Toggle flash inhibit function.
ledflash2_cfg_t::ten
pin_name_t ten
Definition: ledflash2.h:170
ledflash2_set_mode
void ledflash2_set_mode(ledflash2_t *ctx, uint8_t mode, uint8_t intensity, uint8_t flash_duration)
Set mode function.
ledflash2_cfg_t::i2c_address
uint8_t i2c_address
Definition: ledflash2.h:175