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 
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_spi_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define TOUCHKEY3_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
68  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
69  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
70 
76 #define TOUCHKEY3_RETVAL uint8_t
77 
78 #define TOUCHKEY3_OK 0x00
79 #define TOUCHKEY3_INIT_ERROR 0xFF
80 
86 #define TOUCHKEY3_CMD_SENDSETUP 0x01
87 #define TOUCHKEY3_CMD_RESET 0x04
88 #define TOUCHKEY3_CMD_SLEEP 0x05
89 #define TOUCHKEY3_CMD_EEPROM_STORE 0x0A
90 #define TOUCHKEY3_CMD_EEPROM_RESTORE 0x0B
91 #define TOUCHKEY3_CMD_EEPROM_ERASE 0x0C
92 #define TOUCHKEY3_CMD_EEPROM_RECOVER 0x0D
93 
99 #define TOUCHKEY3_CMD_CALLIBRATE_ALL 0x03
100 #define TOUCHKEY3_CMD_CALLIBRATE_0 0x10
101 #define TOUCHKEY3_CMD_CALLIBRATE_1 0x11
102 #define TOUCHKEY3_CMD_CALLIBRATE_2 0x12
103 #define TOUCHKEY3_CMD_CALLIBRATE_3 0x13
104 #define TOUCHKEY3_CMD_CALLIBRATE_4 0x14
105 #define TOUCHKEY3_CMD_CALLIBRATE_5 0x15
106 #define TOUCHKEY3_CMD_CALLIBRATE_6 0x16
107 
113 #define TOUCHKEY3_REQ_FIRST_KEY 0xC0
114 #define TOUCHKEY3_REQ_ALL_KEYS 0xC1
115 #define TOUCHKEY3_REQ_DEVICE_STATUS 0xC2
116 #define TOUCHKEY3_REQ_EEPROM_CRC 0xC3
117 #define TOUCHKEY3_REQ_RAM_CRC 0xC4
118 #define TOUCHKEY3_REQ_ERROR_KEYS 0xC5
119 
125 #define TOUCHKEY3_REQ_LAST_COMMAND 0xC7
126 #define TOUCHKEY3_REQ_SETUP_DATA 0xC8
127 #define TOUCHKEY3_REQ_DEVICE_ID 0xC9
128 #define TOUCHKEY3_REQ_FIRMWARE_VERSION 0xCA
129  // End group macro
132 // --------------------------------------------------------------- PUBLIC TYPES
141 typedef struct
142 {
143  // Output pins
144 
145  digital_out_t rst;
146  digital_out_t cs;
147 
148  // Input pins
149 
150  digital_in_t int_pin;
151 
152  // Modules
153 
154  spi_master_t spi;
155  pin_name_t chip_select;
156 
157 } touchkey3_t;
158 
162 typedef struct
163 {
164  // Communication gpio pins
165 
166  pin_name_t miso;
167  pin_name_t mosi;
168  pin_name_t sck;
169  pin_name_t cs;
170 
171  // Additional gpio pins
172 
173  pin_name_t rst;
174  pin_name_t int_pin;
175 
176  // static variable
177 
178  uint32_t spi_speed;
179  spi_master_mode_t spi_mode;
180  spi_master_chip_select_polarity_t cs_polarity;
181 
183  // End types group
185 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
186 
191 #ifdef __cplusplus
192 extern "C"{
193 #endif
194 
204 
214 
223 
236 (
237  touchkey3_t *ctx,
238  uint8_t *wr_buf,
239  uint16_t wr_len,
240  uint8_t *rd_buf,
241  uint16_t rd_len
242 );
243 
252 void touchkey3_send_command ( touchkey3_t *ctx, uint8_t command );
253 
262 void touchkey3_send_setup ( touchkey3_t *ctx, uint8_t *p_setup_data );
263 
273 void touchkey3_send_request ( touchkey3_t *ctx, uint8_t request, uint8_t *p_response );
274 
284 void touchkey3_set_data ( touchkey3_t *ctx, uint8_t data_address, uint8_t write_data );
285 
295 void touchkey3_get_data ( touchkey3_t *ctx, uint8_t data_address, uint8_t *read_data );
296 
297 #ifdef __cplusplus
298 }
299 #endif
300 #endif // _TOUCHKEY3_H_
301  // End public_function group
304 
305 // ------------------------------------------------------------------------- END
touchkey3_cfg_t::spi_speed
uint32_t spi_speed
Definition: touchkey3.h:178
touchkey3_t::cs
digital_out_t cs
Definition: touchkey3.h:146
touchkey3_cfg_t::sck
pin_name_t sck
Definition: touchkey3.h:168
touchkey3_t::chip_select
pin_name_t chip_select
Definition: touchkey3.h:155
touchkey3_cfg_t::miso
pin_name_t miso
Definition: touchkey3.h:166
touchkey3_cfg_t::mosi
pin_name_t mosi
Definition: touchkey3.h:167
touchkey3_t
Click ctx object definition.
Definition: touchkey3.h:142
touchkey3_t::int_pin
digital_in_t int_pin
Definition: touchkey3.h:150
touchkey3_cfg_t::rst
pin_name_t rst
Definition: touchkey3.h:173
touchkey3_init
TOUCHKEY3_RETVAL touchkey3_init(touchkey3_t *ctx, touchkey3_cfg_t *cfg)
Initialization function.
touchkey3_t::spi
spi_master_t spi
Definition: touchkey3.h:154
touchkey3_send_request
void touchkey3_send_request(touchkey3_t *ctx, uint8_t request, uint8_t *p_response)
Send request.
touchkey3_t::rst
digital_out_t rst
Definition: touchkey3.h:145
touchkey3_cfg_t::cs
pin_name_t cs
Definition: touchkey3.h:169
touchkey3_generic_transfer
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.
touchkey3_set_data
void touchkey3_set_data(touchkey3_t *ctx, uint8_t data_address, uint8_t write_data)
Set configuration data.
touchkey3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: touchkey3.h:179
touchkey3_cfg_t::int_pin
pin_name_t int_pin
Definition: touchkey3.h:174
touchkey3_cfg_t
Click configuration structure definition.
Definition: touchkey3.h:163
touchkey3_send_setup
void touchkey3_send_setup(touchkey3_t *ctx, uint8_t *p_setup_data)
Send setup data.
touchkey3_send_command
void touchkey3_send_command(touchkey3_t *ctx, uint8_t command)
Send command.
touchkey3_cfg_setup
void touchkey3_cfg_setup(touchkey3_cfg_t *cfg)
Config Object Initialization function.
touchkey3_reset
void touchkey3_reset(touchkey3_t *ctx)
Reset function.
touchkey3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: touchkey3.h:180
touchkey3_get_data
void touchkey3_get_data(touchkey3_t *ctx, uint8_t data_address, uint8_t *read_data)
Read configuration data.
TOUCHKEY3_RETVAL
#define TOUCHKEY3_RETVAL
Definition: touchkey3.h:76