touchkey3 2.0.0.0
touchkey3.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 TOUCHKEY3_H
36#define TOUCHKEY3_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_spi_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define TOUCHKEY3_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
73 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
80#define TOUCHKEY3_RETVAL uint8_t
81
82#define TOUCHKEY3_OK 0x00
83#define TOUCHKEY3_INIT_ERROR 0xFF
90#define TOUCHKEY3_CMD_SENDSETUP 0x01
91#define TOUCHKEY3_CMD_RESET 0x04
92#define TOUCHKEY3_CMD_SLEEP 0x05
93#define TOUCHKEY3_CMD_EEPROM_STORE 0x0A
94#define TOUCHKEY3_CMD_EEPROM_RESTORE 0x0B
95#define TOUCHKEY3_CMD_EEPROM_ERASE 0x0C
96#define TOUCHKEY3_CMD_EEPROM_RECOVER 0x0D
103#define TOUCHKEY3_CMD_CALLIBRATE_ALL 0x03
104#define TOUCHKEY3_CMD_CALLIBRATE_0 0x10
105#define TOUCHKEY3_CMD_CALLIBRATE_1 0x11
106#define TOUCHKEY3_CMD_CALLIBRATE_2 0x12
107#define TOUCHKEY3_CMD_CALLIBRATE_3 0x13
108#define TOUCHKEY3_CMD_CALLIBRATE_4 0x14
109#define TOUCHKEY3_CMD_CALLIBRATE_5 0x15
110#define TOUCHKEY3_CMD_CALLIBRATE_6 0x16
117#define TOUCHKEY3_REQ_FIRST_KEY 0xC0
118#define TOUCHKEY3_REQ_ALL_KEYS 0xC1
119#define TOUCHKEY3_REQ_DEVICE_STATUS 0xC2
120#define TOUCHKEY3_REQ_EEPROM_CRC 0xC3
121#define TOUCHKEY3_REQ_RAM_CRC 0xC4
122#define TOUCHKEY3_REQ_ERROR_KEYS 0xC5
129#define TOUCHKEY3_REQ_LAST_COMMAND 0xC7
130#define TOUCHKEY3_REQ_SETUP_DATA 0xC8
131#define TOUCHKEY3_REQ_DEVICE_ID 0xC9
132#define TOUCHKEY3_REQ_FIRMWARE_VERSION 0xCA
135 // End group macro
136// --------------------------------------------------------------- PUBLIC TYPES
145typedef struct
146{
147 // Output pins
148
149 digital_out_t rst;
150 digital_out_t cs;
151
152 // Input pins
153
154 digital_in_t int_pin;
155
156 // Modules
157
158 spi_master_t spi;
159 pin_name_t chip_select;
160
162
166typedef struct
167{
168 // Communication gpio pins
169
170 pin_name_t miso;
171 pin_name_t mosi;
172 pin_name_t sck;
173 pin_name_t cs;
174
175 // Additional gpio pins
176
177 pin_name_t rst;
178 pin_name_t int_pin;
179
180 // static variable
181
182 uint32_t spi_speed;
183 spi_master_mode_t spi_mode;
184 spi_master_chip_select_polarity_t cs_polarity;
185
187
188 // End types group
189// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
190
195#ifdef __cplusplus
196extern "C"{
197#endif
198
208
218
227
240(
241 touchkey3_t *ctx,
242 uint8_t *wr_buf,
243 uint16_t wr_len,
244 uint8_t *rd_buf,
245 uint16_t rd_len
246);
247
256void touchkey3_send_command ( touchkey3_t *ctx, uint8_t command );
257
266void touchkey3_send_setup ( touchkey3_t *ctx, uint8_t *p_setup_data );
267
277void touchkey3_send_request ( touchkey3_t *ctx, uint8_t request, uint8_t *p_response );
278
288void touchkey3_set_data ( touchkey3_t *ctx, uint8_t data_address, uint8_t write_data );
289
299void touchkey3_get_data ( touchkey3_t *ctx, uint8_t data_address, uint8_t *read_data );
300
301#ifdef __cplusplus
302}
303#endif
304#endif // _TOUCHKEY3_H_
305
306 // End public_function group
308
309// ------------------------------------------------------------------------- END
#define TOUCHKEY3_RETVAL
Definition touchkey3.h:80
void touchkey3_cfg_setup(touchkey3_cfg_t *cfg)
Config Object Initialization function.
void touchkey3_send_request(touchkey3_t *ctx, uint8_t request, uint8_t *p_response)
Send request.
void touchkey3_set_data(touchkey3_t *ctx, uint8_t data_address, uint8_t write_data)
Set configuration data.
TOUCHKEY3_RETVAL touchkey3_init(touchkey3_t *ctx, touchkey3_cfg_t *cfg)
Initialization function.
void touchkey3_send_setup(touchkey3_t *ctx, uint8_t *p_setup_data)
Send setup data.
void touchkey3_send_command(touchkey3_t *ctx, uint8_t command)
Send command.
void touchkey3_generic_transfer(touchkey3_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
void touchkey3_reset(touchkey3_t *ctx)
Reset function.
void touchkey3_get_data(touchkey3_t *ctx, uint8_t data_address, uint8_t *read_data)
Read configuration data.
Click configuration structure definition.
Definition touchkey3.h:167
spi_master_chip_select_polarity_t cs_polarity
Definition touchkey3.h:184
pin_name_t sck
Definition touchkey3.h:172
spi_master_mode_t spi_mode
Definition touchkey3.h:183
pin_name_t mosi
Definition touchkey3.h:171
uint32_t spi_speed
Definition touchkey3.h:182
pin_name_t int_pin
Definition touchkey3.h:178
pin_name_t miso
Definition touchkey3.h:170
pin_name_t rst
Definition touchkey3.h:177
pin_name_t cs
Definition touchkey3.h:173
Click ctx object definition.
Definition touchkey3.h:146
digital_out_t cs
Definition touchkey3.h:150
spi_master_t spi
Definition touchkey3.h:158
digital_in_t int_pin
Definition touchkey3.h:154
digital_out_t rst
Definition touchkey3.h:149
pin_name_t chip_select
Definition touchkey3.h:159