mikroSDK Reference Manual
tsc2003.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2023 MikroElektronika d.o.o.
4 ** Contact: https://www.mikroe.com/contact
5 **
6 ** This file is part of the mikroSDK package
7 **
8 ** Commercial License Usage
9 **
10 ** Licensees holding valid commercial NECTO compilers AI licenses may use this
11 ** file in accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The MikroElektronika Company.
14 ** For licensing terms and conditions see
15 ** https://www.mikroe.com/legal/software-license-agreement.
16 ** For further information use the contact form at
17 ** https://www.mikroe.com/contact.
18 **
19 **
20 ** GNU Lesser General Public License Usage
21 **
22 ** Alternatively, this file may be used for
23 ** non-commercial projects under the terms of the GNU Lesser
24 ** General Public License version 3 as published by the Free Software
25 ** Foundation: https://www.gnu.org/licenses/lgpl-3.0.html.
26 **
27 ** The above copyright notice and this permission notice shall be
28 ** included in all copies or substantial portions of the Software.
29 **
30 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31 ** OF MERCHANTABILITY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
32 ** TO THE WARRANTIES FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
34 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
35 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
36 ** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 **
38 ****************************************************************************/
58 #ifndef _TSC2003_H_
59 #define _TSC2003_H_
60 
61 #ifdef __cplusplus
62 extern "C"{
63 #endif
64 
65 #include "drv_digital_out.h"
66 #include "drv_i2c_master.h"
67 #include "drv_digital_in.h"
68 #include "drv_name.h"
69 #include "tp.h"
70 
75 #define configureData(c,pd,m) ((c<<4)|(pd<<2)|(m<<1))
76 
86 typedef enum {
101 
110 typedef enum {
116 
125 typedef enum {
129 
134 typedef struct {
135 
136  uint16_t min_x;
137  uint16_t max_x;
138  uint16_t min_y;
139  uint16_t max_y;
141 
145 typedef struct {
146  uint16_t tsc2003_pressure_threshold_lower;
147  uint16_t tsc2003_pressure_threshold_upper;
149 
156 
161 typedef struct {
162  pin_name_t int_pin;
164  i2c_master_config_t i2c_cfg;
166  uint16_t width;
167  uint16_t height;
169  uint8_t addr_sel;
171  tsc2003_bits_m resolution;
172  tsc2003_bits_pd power_down;
174  tsc2003_pressure_threshold_t pressure_threshold_level;
175 } tsc2003_cfg_t;
176 
184 typedef struct {
185  digital_in_t int_pin;
187  i2c_master_t i2c;
189  uint16_t width;
190  uint16_t height;
192  tp_event_t press_det;
194  tp_event_t gesture;
196  bool pen_down;
198  tsc2003_bits_m resolution;
199  tsc2003_bits_pd power_down;
201  tsc2003_pressure_threshold_t pressure_threshold_level;
203  tsc2003_calibration_data_t calibration_data;
204 } tsc2003_t;
205 
232 #define TSC2003_I2C_SLAVE_ADDR_FIXED (0x48)
233 
238 #define TSC2003_I2C_SLAVE_ADDR_A0 (0x1)
239 
244 #define TSC2003_I2C_SLAVE_ADDR_A1 (0x2)
245 
250 #define TSC2003_I2C_SLAVE_ADDR_0 (TSC2003_I2C_SLAVE_ADDR_FIXED)
251 
256 #define TSC2003_I2C_SLAVE_ADDR_1 (TSC2003_I2C_SLAVE_ADDR_FIXED | \
257  TSC2003_I2C_SLAVE_ADDR_A0)
258 
263 #define TSC2003_I2C_SLAVE_ADDR_2 (TSC2003_I2C_SLAVE_ADDR_FIXED | \
264  TSC2003_I2C_SLAVE_ADDR_A1)
265 
270 #define TSC2003_I2C_SLAVE_ADDR_3 (TSC2003_I2C_SLAVE_ADDR_FIXED | \
271  TSC2003_I2C_SLAVE_ADDR_A0 | \
272  TSC2003_I2C_SLAVE_ADDR_A1)
273 
278 #define TSC2003_I2C_SLAVE_ADDR_DEFAULT (TSC2003_I2C_SLAVE_ADDR_3)
279  // tsc2003_slave_addreses
280 
290 #define TSC2003_MAP_PINS( cfg ) \
291  cfg.i2c_cfg.scl = CTP_SCL; \
292  cfg.i2c_cfg.sda = CTP_SDA; \
293  cfg.int_pin = CTP_INT
294 
306 void tsc2003_cfg_setup( tsc2003_cfg_t * cfg );
307 
328 tp_err_t tsc2003_init( tsc2003_t * ctx, tsc2003_cfg_t * cfg, tp_drv_t * drv );
329 
337 void tsc2003_default_cfg( tsc2003_t* ctx );
338 
348 void tsc2003_press_coordinates( tsc2003_t* ctx, tp_touch_item_t * touch_item );
349 
362 
374 
387 void tsc2003_gesture( tsc2003_t* ctx, tp_event_t * event );
388 
406 void tsc2003_write_cmd( tsc2003_t * ctx, uint8_t reg_addr );
407 
427 void tsc2003_generic_read( tsc2003_t * ctx, uint8_t reg_addr, uint8_t *data_buff, uint8_t len );
428 
440 void tsc2003_calibrate( tsc2003_t* ctx );
441 
451 
462 
473  // middlewaregroup // tsc2003
476 
477 #ifdef __cplusplus
478 }
479 #endif
480 
481 #endif // _TSC2003_H_
482 
483 // ------------------------------------------------------------------------ END
tsc2003_bits_cfg_measure_activate_drivers_x_y
Definition: tsc2003.h:94
tsc2003_bits_cfg_measure_activate_drivers_x
Definition: tsc2003.h:92
drv_name.h
Pin and port name type definitions.
tsc2003_bits_cfg_measure_in2
Definition: tsc2003.h:91
tsc2003_press_coordinates
void tsc2003_press_coordinates(tsc2003_t *ctx, tp_touch_item_t *touch_item)
Copies touch information from context object to touch item object.
i2c_master_t
I2C Master driver context structure, consisted of the following fields :
Definition: drv_i2c_master.h:119
tsc2003_bits_cfg_measure_position_z2
Definition: tsc2003.h:98
tsc2003_bits_pd_power_down_between_conversion
Definition: tsc2003.h:110
tp.h
Touch Panel API Library.
tsc2003_bits_cfg_measure_in1
Definition: tsc2003.h:88
tsc2003_set_pressure_threshold_level
void tsc2003_set_pressure_threshold_level(tsc2003_cfg_t *cfg, tsc2003_pressure_threshold_t pressure)
Utility funciton used for setting threshold levels.
tsc2003_bits_pd_int_ref_off_adc_on
Definition: tsc2003.h:111
tsc2003_gesture
void tsc2003_gesture(tsc2003_t *ctx, tp_event_t *event)
Read gesture information.
tsc2003_cfg_setup
void tsc2003_cfg_setup(tsc2003_cfg_t *cfg)
TSC2003 configuration object setup function.
tsc2003_calibrate
void tsc2003_calibrate(tsc2003_t *ctx)
Calibrates variables used for converting raw TSC2003 ADC values to pixel coordinates.
tsc2003_bits_cfg_measure_temp1
Definition: tsc2003.h:89
drv_digital_in.h
API for Digital input driver.
tp_event_t
tp_event_t
Touch Panel Event Code Definition.
Definition: tp.h:79
tsc2003_press_detect
tp_event_t tsc2003_press_detect(tsc2003_t *ctx)
Press detection function.
tsc2003_default_cfg
void tsc2003_default_cfg(tsc2003_t *ctx)
TSC2003 Default Configuration Function.
digital_in_t
Digital input driver context structure, consisted of the following fields :
Definition: drv_digital_in.h:71
tp_touch_item_t
Touch Item Definition.
Definition: tp.h:149
tsc2003_init
tp_err_t tsc2003_init(tsc2003_t *ctx, tsc2003_cfg_t *cfg, tp_drv_t *drv)
TSC2003 Initialization Function.
tsc2003_process
tp_err_t tsc2003_process(tsc2003_t *ctx)
Function processing events.
tsc2003_bits_cfg_measure_activate_drivers_y
Definition: tsc2003.h:93
tsc2003_bits_cfg_measure_position_y
Definition: tsc2003.h:96
tsc2003_bits_pd_int_ref_on_adc_on
Definition: tsc2003.h:113
tsc2003_bits_m
tsc2003_bits_m
TSC2003 Mode.
Definition: tsc2003.h:124
tsc2003_pressure_threshold_t
Press intensity needed to register touch event.
Definition: tsc2003.h:144
tsc2003_get_calibration_data
void tsc2003_get_calibration_data(tsc2003_t *ctx, tsc2003_calibration_data_t *cdata)
Utility funciton used for getting a copy of current calibration data.
tsc2003_set_calibration_data
void tsc2003_set_calibration_data(tsc2003_t *ctx, const tsc2003_calibration_data_t *cdata)
Utility funciton used for setting calibration data.
tsc2003_bits_cfg
tsc2003_bits_cfg
TSC2003 Configuration.
Definition: tsc2003.h:85
tsc2003_bits_cfg_measure_temp0
Definition: tsc2003.h:86
tsc2003_bits_cfg_measure_vbat2
Definition: tsc2003.h:90
tp_err_t
tp_err_t
Touch Panel Error Code Definition.
Definition: tp.h:63
drv_i2c_master.h
API for I2C master driver.
tsc2003_calibration_data_t
Calibration data structure.
Definition: tsc2003.h:133
tsc2003_bits_pd_int_ref_on_adc_off
Definition: tsc2003.h:112
pin_name_t
hal_pin_name_t pin_name_t
Definition: drv_name.h:73
drv_digital_out.h
API for Digital output driver.
tsc2003_generic_read
void tsc2003_generic_read(tsc2003_t *ctx, uint8_t reg_addr, uint8_t *data_buff, uint8_t len)
Reads a number of bytes from a register.
tsc2003_bits_cfg_measure_position_z1
Definition: tsc2003.h:97
tsc2003_bits_cfg_measure_vbat1
Definition: tsc2003.h:87
tsc2003_bits_m_8bit
Definition: tsc2003.h:126
tsc2003_t
TSC2003 Context Object.
Definition: tsc2003.h:183
tp_drv_t
Touch Panel Driver Interface Items.
Definition: tp.h:197
tsc2003_write_cmd
void tsc2003_write_cmd(tsc2003_t *ctx, uint8_t reg_addr)
Writes a generic command to the IC.
tsc2003_bits_cfg_measure_position_x
Definition: tsc2003.h:95
tsc2003_cfg_t
TSC2003 Configuration Object.
Definition: tsc2003.h:160
tsc2003_bits_pd
tsc2003_bits_pd
TSC2003 Power Down Setting.
Definition: tsc2003.h:109
TSC2003_CALIBRATION_DATA_DEFAULT
const tsc2003_calibration_data_t TSC2003_CALIBRATION_DATA_DEFAULT
Default calibration data specific for MikroE resistive tft boards.
i2c_master_config_t
I2C Master initialization configuration structure, consisted of the following fields :
Definition: drv_i2c_master.h:95
tsc2003_bits_m_12bit
Definition: tsc2003.h:125