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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define CAPEXTEND_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define CAPEXTEND_RETVAL uint8_t
64 
65 #define CAPEXTEND_OK 0x00
66 #define CAPEXTEND_INIT_ERROR 0xFF
67 
73 #define CAPEXTEND_SPM_CFG 0x0D
74 #define CAPEXTEND_SPM_BASE_ADDR 0x0E
75 #define CAPEXTEND_SPM_KEY_MSB 0xAC
76 #define CAPEXTEND_SPM_KEY_LSB 0xAD
77 
83 #define CAPEXTEND_BLOCK_1 0x00
84 #define CAPEXTEND_BLOCK_2 0x08
85 #define CAPEXTEND_BLOCK_3 0x10
86 #define CAPEXTEND_BLOCK_4 0x20
87 #define CAPEXTEND_BLOCK_5 0x28
88 #define CAPEXTEND_BLOCK_6 0x30
89 #define CAPEXTEND_BLOCK_7 0x38
90 #define CAPEXTEND_BLOCK_8 0x40
91 #define CAPEXTEND_BLOCK_9 0x48
92 #define CAPEXTEND_BLOCK_10 0x50
93 #define CAPEXTEND_BLOCK_11 0x58
94 #define CAPEXTEND_BLOCK_12 0x60
95 #define CAPEXTEND_BLOCK_13 0x68
96 #define CAPEXTEND_BLOCK_14 0x70
97 #define CAPEXTEND_BLOCK_15 0x78
98 
104 #define CAPEXTEND_IRQ_SRC 0x00
105 #define CAPEXTEND_CAP_STAT_MSB 0x01
106 #define CAPEXTEND_CAP_STAT_LSB 0x02
107 #define CAPEXTEND_GPI_STAT 0x07
108 #define CAPEXTEND_SPM_STAT 0x08
109 #define CAPEXTEND_COMP_OP_MODE 0x09
110 #define CAPEXTEND_GPO_CTRL 0x0A
111 #define CAPEXTEND_GPP_PIN_ID 0x0B
112 #define CAPEXTEND_GPP_INTENSITY 0x0C
113 #define CAPEXTEND_SOFT_RESET 0xB1
114 #define CAPEXTEND_MON_SCAN_PER 0xF9
115 #define CAPEXTEND_SLAVE_ADDRESS 0x2B
116 
122 #define CAPEXTEND_CAP_DIFF_BA 0xB4
123 #define CAPEXTEND_CAP_RAW_BA 0x80
124 #define CAPEXTEND_CAP_AVG_BA 0x9A
125 
131 #define CAPEXTEND_CAP_DIFF_BLK_1 0xB4
132 #define CAPEXTEND_CAP_DIFF_BLK_2 0xBC
133 #define CAPEXTEND_CAP_DIFF_BLK_3 0xC4
134 #define CAPEXTEND_CAP_AVG_BLK_1 0x80
135 #define CAPEXTEND_CAP_AVG_BLK_2 0x88
136 #define CAPEXTEND_CAP_AVG_BLK_3 0x90
137 #define CAPEXTEND_CAP_RAW_BLK_1 0x9A
138 #define CAPEXTEND_CAP_RAW_BLK_2 0xA2
139 #define CAPEXTEND_CAP_RAW_BLK_3 0xAA
140 #define CAPEXTEND_GPIO_0 0x00
141 #define CAPEXTEND_GPIO_1 0x01
142 #define CAPEXTEND_GPIO_2 0x02
143 #define CAPEXTEND_GPIO_3 0x03
144 #define CAPEXTEND_GPIO_4 0x04
145 #define CAPEXTEND_GPIO_5 0x05
146 #define CAPEXTEND_GPIO_6 0x06
147 #define CAPEXTEND_GPIO_7 0x07
148 #define CAPEXTEND_GPIO_ALL 0x08
149 #define CAPEXTEND_COMMON_SETTINGS 0x01
150 #define CAPEXTEND_INDIVIDUAL_SETTINGS 0x04
151 #define CAPEXTEND_DISABLED 0x00
152 #define CAPEXTEND_BUTTON 0x01
153 #define CAPEXTEND_MULTI_TOUCH 0x00
154 #define CAPEXTEND_SINGLE_TOUCH 0x01
155 #define CAPEXTEND_INT_MASKED 0x00
156 #define CAPEXTEND_INT_TOUCH 0x01
157 #define CAPEXTEND_INT_RELEASE 0x02
158 #define CAPEXTEND_INT_BOTH_TR 0x03
159 #define CAPEXTEND_SMPL_0 0x00
160 #define CAPEXTEND_SMPL_2 0x01
161 #define CAPEXTEND_SMPL_3 0x02
162 #define CAPEXTEND_SMPL_4 0x03
163 #define CAPEXTEND_BTN_0 0x00
164 #define CAPEXTEND_BTN_1 0x01
165 #define CAPEXTEND_BTN_2 0x02
166 #define CAPEXTEND_BTN_3 0x03
167 #define CAPEXTEND_BTN_4 0x04
168 #define CAPEXTEND_BTN_5 0x05
169 #define CAPEXTEND_BTN_6 0x06
170 #define CAPEXTEND_BTN_7 0x07
171 #define CAPEXTEND_BTN_8 0x08
172 #define CAPEXTEND_BTN_9 0x09
173 #define CAPEXTEND_BTN_10 0x0A
174 #define CAPEXTEND_BTN_11 0x0B
175 #define CAPEXTEND_GROUP_0 0x0C
176 #define CAPEXTEND_GROUP_1 0x0D
177 #define CAPEXTEND_GPO 0x00
178 #define CAPEXTEND_GPP 0x01
179 #define CAPEXTEND_GPI 0x02
180 #define CAPEXTEND_LOG 0x00
181 #define CAPEXTEND_LIN 0x01
182 #define CAPEXTEND_EVERY_TIME 0x00
183 #define CAPEXTEND_EVERY_16 0x01
184 #define CAPEXTEND_NONE 0x00
185 #define CAPEXTEND_PULLUP 0x01
186 #define CAPEXTEND_PULLDOWN 0x02
187 #define CAPEXTEND_NO_INT 0x00
188 #define CAPEXTEND_RISING 0x01
189 #define CAPEXTEND_FALLING 0x02
190 #define CAPEXTEND_BOTH 0x03
191 #define CAPEXTEND_OP_MODE_INT 0x01
192 #define CAPEXTEND_COMP_INT 0x02
193 #define CAPEXTEND_BUTTON_INT 0x04
194 #define CAPEXTEND_GPI_INT 0x10
195 #define CAPEXTEND_SPM_INT 0x20
196 #define CAPEXTEND_NVM_INT 0x40
197 #define CAPEXTEND_ACTIVE_MODE 0x00
198 #define CAPEXTEND_DOZE_MODE 0x01
199 #define CAPEXTEND_SLEEP_MODE 0x02
200 #define CAPEXTEND_RAW 0x00
201 #define CAPEXTEND_AVG 0x01
202 #define CAPEXTEND_DIFF 0x02
203 #define CAPEXTEND_MSB_BUTTONS_ADDR 0x01
204 #define CAPEXTEND_LSB_BUTTONS_ADDR 0x02
205  // End group macro
208 // --------------------------------------------------------------- PUBLIC TYPES
217 typedef struct
218 {
219  // Output pins
220 
221  digital_out_t rst;
222 
223  // Input pins
224 
225  digital_in_t int_pin;
226 
227  // Modules
228 
229  i2c_master_t i2c;
230 
231  // ctx variable
232 
233  uint8_t slave_address;
234 
235 } capextend_t;
236 
240 typedef struct
241 {
242  // Communication gpio pins
243 
244  pin_name_t scl;
245  pin_name_t sda;
246 
247  // Additional gpio pins
248 
249  pin_name_t rst;
250  pin_name_t int_pin;
251 
252  // static variable
253 
254  uint32_t i2c_speed;
255  uint8_t i2c_address;
256 
258  // End types group
260 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
261 
267 #ifdef __cplusplus
268 extern "C"{
269 #endif
270 
280 
289 
300 void capextend_generic_write ( capextend_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
301 
312 void capextend_generic_read ( capextend_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
313 
322 
331 
342 
351 
360 
369 
378 
379 #ifdef __cplusplus
380 }
381 #endif
382 #endif // _CAPEXTEND_H_
383  // End public_function group
386 
387 // ------------------------------------------------------------------------- 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:241
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:225
capextend_cfg_t::scl
pin_name_t scl
Definition: capextend.h:244
capextend_cfg_t::rst
pin_name_t rst
Definition: capextend.h:249
capextend_t::i2c
i2c_master_t i2c
Definition: capextend.h:229
capextend_cfg_t::sda
pin_name_t sda
Definition: capextend.h:245
capextend_t::slave_address
uint8_t slave_address
Definition: capextend.h:233
capextend_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: capextend.h:254
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:218
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:250
capextend_t::rst
digital_out_t rst
Definition: capextend.h:221
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:63
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:255
capextend_reset
void capextend_reset(capextend_t *ctx)
Reset function.