capsense 2.0.0.0
capsense.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 CAPSENSE_H
36#define CAPSENSE_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
57// -------------------------------------------------------------- PUBLIC MACROS
67#define CAPSENSE_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
71 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
72
79#define CAPSENSE_OK 0
80#define CAPSENSE_ERROR -1
87#define CAPSENSE_COMMAND_REG 0xA0
88#define CAPSENSE_CS_ENABL0 0x06
89#define CAPSENSE_CS_ENABL1 0x07
90#define CAPSENSE_GPIO_ENABLE0 0x08
91#define CAPSENSE_DM_STRONG0 0x11
92#define CAPSENSE_CS_SLID_CONFIG 0x75
93#define CAPSENSE_CS_SLID_MULM 0x77
94#define CAPSENSE_CS_SLID_MULL 0x78
95#define CAPSENSE_OUTPUT_PORT0 0x04
96#define CAPSENSE_CS_READ_RAW 0x87
97#define CAPSENSE_CS_READ_STATUS0 0x88
98#define CAPSENSE_CS_READ_STATUS1 0x89
99#define CAPSENSE_CS_READ_CEN_POSM 0x8A
100#define CAPSENSE_CS_READ_CEN_POSL 0x8B
101#define CAPSENSE_CS_READ_CEN_PEAKM 0x8C
102#define CAPSENSE_CS_READ_CEN_PEAKL 0x8D
103#define CAPSENSE_DEVICE_ID 0x7A
104#define CAPSENSE_DEVICE_STATUS 0x7B
111#define CAPSENSE_I2C_ADDRESS_0 0x00
112#define CAPSENSE_I2C_ADDRESS_1 0x4B
115 // End group macro
116// --------------------------------------------------------------- PUBLIC TYPES
125typedef struct
126{
127 // Output pins
128 digital_out_t an;
129
130 // Input pins
131 digital_in_t rst;
132
133 // Modules
134 i2c_master_t i2c;
135
136 // ctx variable
138
139} capsense_t;
140
144typedef struct
145{
146 // Communication gpio pins
147 pin_name_t scl;
148 pin_name_t sda;
149
150 // Additional gpio pins
151 pin_name_t an;
152 pin_name_t rst;
153
154 // static variable
155 uint32_t i2c_speed;
156 uint8_t i2c_address;
157
159
160 // End types group
161// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
162
168#ifdef __cplusplus
169extern "C"{
170#endif
171
181
193
220
234err_t capsense_generic_write ( capsense_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
235
249err_t capsense_generic_read ( capsense_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
250
263err_t capsense_write_data( capsense_t *ctx, uint8_t reg_address, uint8_t write_command );
264
277err_t capsense_read_data( capsense_t *ctx, uint8_t reg_address, uint8_t *read_data );
278
291err_t capsense_read_data_bytes( capsense_t *ctx, uint8_t reg_address, uint16_t *read_data );
292
305err_t capsense_get_slider_lvl( capsense_t *ctx, uint8_t *slider_lvl );
306
307#ifdef __cplusplus
308}
309#endif
310#endif // _CAPSENSE_H_
311
312 // End public_function group
314
315// ------------------------------------------------------------------------- END
err_t capsense_generic_read(capsense_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
err_t capsense_write_data(capsense_t *ctx, uint8_t reg_address, uint8_t write_command)
Generic write data function.
void capsense_cfg_setup(capsense_cfg_t *cfg)
Config Object Initialization function.
err_t capsense_read_data_bytes(capsense_t *ctx, uint8_t reg_address, uint16_t *read_data)
Read two bytes from register address.
err_t capsense_init(capsense_t *ctx, capsense_cfg_t *cfg)
Initialization function.
err_t capsense_read_data(capsense_t *ctx, uint8_t reg_address, uint8_t *read_data)
Read one byte from register address.
err_t capsense_generic_write(capsense_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
err_t capsense_default_cfg(capsense_t *ctx)
Click Default Configuration function.
err_t capsense_get_slider_lvl(capsense_t *ctx, uint8_t *slider_lvl)
Function get slider level.
Click configuration structure definition.
Definition capsense.h:145
uint32_t i2c_speed
Definition capsense.h:155
pin_name_t scl
Definition capsense.h:147
pin_name_t sda
Definition capsense.h:148
pin_name_t rst
Definition capsense.h:152
pin_name_t an
Definition capsense.h:151
uint8_t i2c_address
Definition capsense.h:156
Click ctx object definition.
Definition capsense.h:126
i2c_master_t i2c
Definition capsense.h:134
digital_in_t rst
Definition capsense.h:131
uint8_t slave_address
Definition capsense.h:137
digital_out_t an
Definition capsense.h:128