capextend  2.0.0.0
capextend.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 CAPEXTEND_H
36 #define CAPEXTEND_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 CAPEXTEND_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
71 
77 #define CAPEXTEND_RETVAL uint8_t
78 
79 #define CAPEXTEND_OK 0x00
80 #define CAPEXTEND_INIT_ERROR 0xFF
81 
87 #define CAPEXTEND_SPM_CFG 0x0D
88 #define CAPEXTEND_SPM_BASE_ADDR 0x0E
89 #define CAPEXTEND_SPM_KEY_MSB 0xAC
90 #define CAPEXTEND_SPM_KEY_LSB 0xAD
91 
97 #define CAPEXTEND_BLOCK_1 0x00
98 #define CAPEXTEND_BLOCK_2 0x08
99 #define CAPEXTEND_BLOCK_3 0x10
100 #define CAPEXTEND_BLOCK_4 0x20
101 #define CAPEXTEND_BLOCK_5 0x28
102 #define CAPEXTEND_BLOCK_6 0x30
103 #define CAPEXTEND_BLOCK_7 0x38
104 #define CAPEXTEND_BLOCK_8 0x40
105 #define CAPEXTEND_BLOCK_9 0x48
106 #define CAPEXTEND_BLOCK_10 0x50
107 #define CAPEXTEND_BLOCK_11 0x58
108 #define CAPEXTEND_BLOCK_12 0x60
109 #define CAPEXTEND_BLOCK_13 0x68
110 #define CAPEXTEND_BLOCK_14 0x70
111 #define CAPEXTEND_BLOCK_15 0x78
112 
118 #define CAPEXTEND_IRQ_SRC 0x00
119 #define CAPEXTEND_CAP_STAT_MSB 0x01
120 #define CAPEXTEND_CAP_STAT_LSB 0x02
121 #define CAPEXTEND_GPI_STAT 0x07
122 #define CAPEXTEND_SPM_STAT 0x08
123 #define CAPEXTEND_COMP_OP_MODE 0x09
124 #define CAPEXTEND_GPO_CTRL 0x0A
125 #define CAPEXTEND_GPP_PIN_ID 0x0B
126 #define CAPEXTEND_GPP_INTENSITY 0x0C
127 #define CAPEXTEND_SOFT_RESET 0xB1
128 #define CAPEXTEND_MON_SCAN_PER 0xF9
129 #define CAPEXTEND_SLAVE_ADDRESS 0x2B
130 
136 #define CAPEXTEND_CAP_DIFF_BA 0xB4
137 #define CAPEXTEND_CAP_RAW_BA 0x80
138 #define CAPEXTEND_CAP_AVG_BA 0x9A
139 
145 #define CAPEXTEND_CAP_DIFF_BLK_1 0xB4
146 #define CAPEXTEND_CAP_DIFF_BLK_2 0xBC
147 #define CAPEXTEND_CAP_DIFF_BLK_3 0xC4
148 #define CAPEXTEND_CAP_AVG_BLK_1 0x80
149 #define CAPEXTEND_CAP_AVG_BLK_2 0x88
150 #define CAPEXTEND_CAP_AVG_BLK_3 0x90
151 #define CAPEXTEND_CAP_RAW_BLK_1 0x9A
152 #define CAPEXTEND_CAP_RAW_BLK_2 0xA2
153 #define CAPEXTEND_CAP_RAW_BLK_3 0xAA
154 #define CAPEXTEND_GPIO_0 0x00
155 #define CAPEXTEND_GPIO_1 0x01
156 #define CAPEXTEND_GPIO_2 0x02
157 #define CAPEXTEND_GPIO_3 0x03
158 #define CAPEXTEND_GPIO_4 0x04
159 #define CAPEXTEND_GPIO_5 0x05
160 #define CAPEXTEND_GPIO_6 0x06
161 #define CAPEXTEND_GPIO_7 0x07
162 #define CAPEXTEND_GPIO_ALL 0x08
163 #define CAPEXTEND_COMMON_SETTINGS 0x01
164 #define CAPEXTEND_INDIVIDUAL_SETTINGS 0x04
165 #define CAPEXTEND_DISABLED 0x00
166 #define CAPEXTEND_BUTTON 0x01
167 #define CAPEXTEND_MULTI_TOUCH 0x00
168 #define CAPEXTEND_SINGLE_TOUCH 0x01
169 #define CAPEXTEND_INT_MASKED 0x00
170 #define CAPEXTEND_INT_TOUCH 0x01
171 #define CAPEXTEND_INT_RELEASE 0x02
172 #define CAPEXTEND_INT_BOTH_TR 0x03
173 #define CAPEXTEND_SMPL_0 0x00
174 #define CAPEXTEND_SMPL_2 0x01
175 #define CAPEXTEND_SMPL_3 0x02
176 #define CAPEXTEND_SMPL_4 0x03
177 #define CAPEXTEND_BTN_0 0x00
178 #define CAPEXTEND_BTN_1 0x01
179 #define CAPEXTEND_BTN_2 0x02
180 #define CAPEXTEND_BTN_3 0x03
181 #define CAPEXTEND_BTN_4 0x04
182 #define CAPEXTEND_BTN_5 0x05
183 #define CAPEXTEND_BTN_6 0x06
184 #define CAPEXTEND_BTN_7 0x07
185 #define CAPEXTEND_BTN_8 0x08
186 #define CAPEXTEND_BTN_9 0x09
187 #define CAPEXTEND_BTN_10 0x0A
188 #define CAPEXTEND_BTN_11 0x0B
189 #define CAPEXTEND_GROUP_0 0x0C
190 #define CAPEXTEND_GROUP_1 0x0D
191 #define CAPEXTEND_GPO 0x00
192 #define CAPEXTEND_GPP 0x01
193 #define CAPEXTEND_GPI 0x02
194 #define CAPEXTEND_LOG 0x00
195 #define CAPEXTEND_LIN 0x01
196 #define CAPEXTEND_EVERY_TIME 0x00
197 #define CAPEXTEND_EVERY_16 0x01
198 #define CAPEXTEND_NONE 0x00
199 #define CAPEXTEND_PULLUP 0x01
200 #define CAPEXTEND_PULLDOWN 0x02
201 #define CAPEXTEND_NO_INT 0x00
202 #define CAPEXTEND_RISING 0x01
203 #define CAPEXTEND_FALLING 0x02
204 #define CAPEXTEND_BOTH 0x03
205 #define CAPEXTEND_OP_MODE_INT 0x01
206 #define CAPEXTEND_COMP_INT 0x02
207 #define CAPEXTEND_BUTTON_INT 0x04
208 #define CAPEXTEND_GPI_INT 0x10
209 #define CAPEXTEND_SPM_INT 0x20
210 #define CAPEXTEND_NVM_INT 0x40
211 #define CAPEXTEND_ACTIVE_MODE 0x00
212 #define CAPEXTEND_DOZE_MODE 0x01
213 #define CAPEXTEND_SLEEP_MODE 0x02
214 #define CAPEXTEND_RAW 0x00
215 #define CAPEXTEND_AVG 0x01
216 #define CAPEXTEND_DIFF 0x02
217 #define CAPEXTEND_MSB_BUTTONS_ADDR 0x01
218 #define CAPEXTEND_LSB_BUTTONS_ADDR 0x02
219  // End group macro
222 // --------------------------------------------------------------- PUBLIC TYPES
231 typedef struct
232 {
233  // Output pins
234 
235  digital_out_t rst;
236 
237  // Input pins
238 
239  digital_in_t int_pin;
240 
241  // Modules
242 
243  i2c_master_t i2c;
244 
245  // ctx variable
246 
247  uint8_t slave_address;
248 
249 } capextend_t;
250 
254 typedef struct
255 {
256  // Communication gpio pins
257 
258  pin_name_t scl;
259  pin_name_t sda;
260 
261  // Additional gpio pins
262 
263  pin_name_t rst;
264  pin_name_t int_pin;
265 
266  // static variable
267 
268  uint32_t i2c_speed;
269  uint8_t i2c_address;
270 
272  // End types group
274 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
275 
281 #ifdef __cplusplus
282 extern "C"{
283 #endif
284 
294 
303 
314 void capextend_generic_write ( capextend_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
315 
326 void capextend_generic_read ( capextend_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
327 
336 
345 
356 
365 
374 
383 
392 
393 #ifdef __cplusplus
394 }
395 #endif
396 #endif // _CAPEXTEND_H_
397  // End public_function group
400 
401 // ------------------------------------------------------------------------- END
capextend_cfg_setup
void capextend_cfg_setup(capextend_cfg_t *cfg)
Config Object Initialization function.
capextend_cfg_t
Click configuration structure definition.
Definition: capextend.h:255
capextend_generic_write
void capextend_generic_write(capextend_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
capextend_get_int_input
uint8_t capextend_get_int_input(capextend_t *ctx)
Get interrupt input function.
capextend_t::int_pin
digital_in_t int_pin
Definition: capextend.h:239
capextend_cfg_t::scl
pin_name_t scl
Definition: capextend.h:258
capextend_cfg_t::rst
pin_name_t rst
Definition: capextend.h:263
capextend_t::i2c
i2c_master_t i2c
Definition: capextend.h:243
capextend_cfg_t::sda
pin_name_t sda
Definition: capextend.h:259
capextend_t::slave_address
uint8_t slave_address
Definition: capextend.h:247
capextend_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: capextend.h:268
capextend_set_rst_high
void capextend_set_rst_high(capextend_t *ctx)
Set reset high function.
capextend_t
Click ctx object definition.
Definition: capextend.h:232
capextend_init
CAPEXTEND_RETVAL capextend_init(capextend_t *ctx, capextend_cfg_t *cfg)
Initialization function.
capextend_cfg_t::int_pin
pin_name_t int_pin
Definition: capextend.h:264
capextend_t::rst
digital_out_t rst
Definition: capextend.h:235
capextend_read_lsb_buttons
int8_t capextend_read_lsb_buttons(capextend_t *ctx)
Read LSB buttons function.
CAPEXTEND_RETVAL
#define CAPEXTEND_RETVAL
Definition: capextend.h:77
capextend_generic_read
void capextend_generic_read(capextend_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
capextend_set_rst_low
void capextend_set_rst_low(capextend_t *ctx)
Set reset low function.
capextend_read_msb_buttons
int8_t capextend_read_msb_buttons(capextend_t *ctx)
Read MSB buttons function.
capextend_read_buttons
uint16_t capextend_read_buttons(capextend_t *ctx)
Read buttons function.
capextend_cfg_t::i2c_address
uint8_t i2c_address
Definition: capextend.h:269
capextend_reset
void capextend_reset(capextend_t *ctx)
Reset function.