mikroSDK Reference Manual
tp_mikroe.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** Copyright (C) 2024 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****************************************************************************/
44#ifndef _TP_MIKROE_H_
45#define _TP_MIKROE_H_
46
47#ifdef __cplusplus
48extern "C"{
49#endif
50
51#include "drv_analog_in.h"
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "tp.h"
55#include "gl.h"
56#include "board.h"
57
73#define VREF_VALUE 3.3f
74
75#ifndef TP_MIKROE_CALIBRATION_XMIN
76#define TP_MIKROE_CALIBRATION_XMIN 0
77#endif
78#ifndef TP_MIKROE_CALIBRATION_XMAX
79#define TP_MIKROE_CALIBRATION_XMAX 0
80#endif
81
82#ifndef TP_MIKROE_CALIBRATION_YMIN
83#define TP_MIKROE_CALIBRATION_YMIN 0
84#endif
85#ifndef TP_MIKROE_CALIBRATION_YMAX
86#define TP_MIKROE_CALIBRATION_YMAX 0
87#endif
88
89#ifndef TP_MIKROE_PRESSURE_THRESHOLD_LOWER
90#define TP_MIKROE_PRESSURE_THRESHOLD_LOWER 0
91#endif
92#ifndef TP_MIKROE_PRESSURE_THRESHOLD_UPPER
93#define TP_MIKROE_PRESSURE_THRESHOLD_UPPER 0
94#endif
95
99#define TP_MIKROE_MAP_PINS( tp_mikroe_cfg ) \
100 tp_mikroe_cfg.left = TP_MIKROE_XL;\
101 tp_mikroe_cfg.right = TP_MIKROE_XR;\
102 tp_mikroe_cfg.up = TP_MIKROE_YU;\
103 tp_mikroe_cfg.down = TP_MIKROE_YD;
104
109typedef struct {
111 uint16_t min_x;
113 uint16_t max_x;
115 uint16_t min_y;
117 uint16_t max_y;
119
128
148
149#define TP_MIKROE_ADC_CONFIG( cfg ) \
150 cfg->analog_in_cfg_read_x.resolution = ANALOG_IN_RESOLUTION_CMAKE; \
151 cfg->analog_in_cfg_read_y.resolution = ANALOG_IN_RESOLUTION_CMAKE; \
152 cfg->analog_in_cfg_read_x.input_pin = TP_READ_X_CMAKE; \
153 cfg->analog_in_cfg_read_y.input_pin = TP_READ_Y_CMAKE; \
154 cfg->analog_in_cfg_read_x.vref_input = ANALOG_IN_VREF_CMAKE; \
155 cfg->analog_in_cfg_read_y.vref_input = ANALOG_IN_VREF_CMAKE; \
156 cfg->analog_in_cfg_read_x.vref_value = VREF_VALUE; \
157 cfg->analog_in_cfg_read_y.vref_value = VREF_VALUE;
158
188
192#define SET_PEN() \
193 gl_set_pen( GL_WHITE, 4 );
194
195#define DRAW_ARROW_TOP_LEFT() \
196 gl_clear( GL_BLACK ); \
197 gl_draw_line( 0, 0, 10, 0 ); \
198 gl_draw_line( 0, 0, 0, 10 ); \
199 gl_draw_line( 0, 0, 15, 15 );
200
201#define DRAW_ARROW_TOP_RIGHT() \
202 gl_clear( GL_BLACK ); \
203 gl_draw_line( 320, 0, 320, 10 ); \
204 gl_draw_line( 320, 0, 310, 0 ); \
205 gl_draw_line( 320, 0, 305, 15 );
206
207#define DRAW_ARROW_BOTTOM_LEFT() \
208 gl_clear( GL_BLACK ); \
209 gl_draw_line( 0, 240, 0, 230 ); \
210 gl_draw_line( 0, 240, 10, 240 ); \
211 gl_draw_line( 0, 240, 15, 225 );
212
213#define DRAW_ARROW_BOTTOM_RIGHT() \
214 gl_clear( GL_BLACK ); \
215 gl_draw_line( 320, 240, 320, 230 ); \
216 gl_draw_line( 320, 240, 310, 240 ); \
217 gl_draw_line( 320, 240, 305, 225 );
218
230
244
257
267
275void tp_mikroe_calibrate( tp_t *tp_instance );
276
286
297
309
320bool tp_mikroe_check_pressure ( tp_mikroe_t *ctx, uint16_t *x_pos, uint16_t *y_pos );
321
330void tp_mikroe_set_threshold ( tp_mikroe_t *ctx, uint16_t threshold_upper, uint16_t threshold_lower );
331
341void tp_mikroe_update_ctx_coords( tp_mikroe_t *ctx, uint16_t x_pos, uint16_t y_pos );
342
354void tp_mikroe_calibrate_point ( tp_mikroe_t *ctx, bool calibration_points_uninitialized );
355
363
372
392
401
402 // tp_mikroe
403 // mwgroup
404
405#ifdef __cplusplus
406}
407#endif
408
409#endif // _TP_MIKROE_H_
410
411// ------------------------------------------------------------------------ END
API for Analog input driver.
API for Digital input driver.
API for Digital output driver.
hal_pin_name_t pin_name_t
Definition drv_name.h:74
mikroSDK Graphic Library API.
void tp_mikroe_gesture(tp_mikroe_t *ctx, tp_event_t *event)
Read gesture information.
tp_err_t tp_mikroe_process(tp_mikroe_t *ctx)
Function processing events.
void tp_mikroe_set_pressure_threshold_level(tp_mikroe_cfg_t *cfg, tp_mikroe_pressure_threshold_t pressure)
Utility function used for setting threshold levels.
void tp_mikroe_update_ctx_coords(tp_mikroe_t *ctx, uint16_t x_pos, uint16_t y_pos)
Converts x_pos & y_pos raw ADC values to coordinate values and stores them in 'touch point 0' ctx mem...
void tp_mikroe_set_calibration_data(tp_mikroe_t *ctx, const tp_mikroe_calibration_data_t *cdata)
Utility function used for setting calibration data.
tp_event_t tp_mikroe_press_detect(tp_mikroe_t *ctx)
Press detection function.
void tp_mikroe_default_cfg_adc(tp_mikroe_t *ctx)
TP_MIKROE ADC pin configuration function.
char tp_mikroe_pressure_level_detect(tp_mikroe_t *ctx)
Function used for checking pressure levels.
void tp_mikroe_set_threshold(tp_mikroe_t *ctx, uint16_t threshold_upper, uint16_t threshold_lower)
Utility function used for setting threshold levels.
void tp_mikroe_calibrate(tp_t *tp_instance)
Calibrates variables used for converting raw TP_MIKROE ADC values to pixel coordinates.
bool tp_mikroe_check_pressure(tp_mikroe_t *ctx, uint16_t *x_pos, uint16_t *y_pos)
Function for reading raw ADC data.
void tp_mikroe_cfg_setup(tp_mikroe_cfg_t *cfg)
TP_MIKROE Configuration setup Function.
void tp_mikroe_press_coordinates(tp_mikroe_t *ctx, tp_touch_coord_t *touch_item)
Copies touch information from context object to touch item object.
void tp_mikroe_get_calibration_data(tp_mikroe_t *ctx, tp_mikroe_calibration_data_t *cdata)
Utility function used for getting a copy of current calibration data.
tp_err_t tp_mikroe_init_tp(tp_mikroe_t *ctx, tp_mikroe_cfg_t *cfg, tp_drv_t *drv)
TP_MIKROE Touch Panel initialization. This function initializes TP_MIKROE context object using config...
void tp_mikroe_calibrate_point(tp_mikroe_t *ctx, bool calibration_points_uninitialized)
Utility function used for calibration.
Analog input driver configuration structure.
Definition drv_analog_in.h:108
Analog input driver context structure, consisted of the following fields :
Definition drv_analog_in.h:128
Touch Panel Driver Interface Items.
Definition tp.h:199
Calibration data structure.
Definition tp_mikroe.h:109
uint16_t max_x
Definition tp_mikroe.h:113
uint16_t min_x
Definition tp_mikroe.h:111
uint16_t min_y
Definition tp_mikroe.h:115
TP_MIKROE Configuration Object.
Definition tp_mikroe.h:133
pin_name_t down
Definition tp_mikroe.h:137
analog_in_config_t analog_in_cfg_read_x
Definition tp_mikroe.h:139
pin_name_t right
Definition tp_mikroe.h:135
pin_name_t left
Definition tp_mikroe.h:134
pin_name_t up
Definition tp_mikroe.h:136
uint16_t height
Definition tp_mikroe.h:146
analog_in_config_t analog_in_cfg_read_y
Definition tp_mikroe.h:140
uint16_t width
Definition tp_mikroe.h:145
Pressure threshold data structure.
Definition tp_mikroe.h:124
uint16_t tp_mikroe_pressure_threshold_upper
Definition tp_mikroe.h:126
uint16_t tp_mikroe_pressure_threshold_lower
Definition tp_mikroe.h:125
TP_MIKROE Context Object.
Definition tp_mikroe.h:163
analog_in_t analog_in_x
Definition tp_mikroe.h:169
tp_event_t gesture
Definition tp_mikroe.h:174
pin_name_t up
Definition tp_mikroe.h:166
pin_name_t left
Definition tp_mikroe.h:164
tp_touch_coord_t touch
Definition tp_mikroe.h:173
uint16_t width
Definition tp_mikroe.h:185
bool pen_down
Definition tp_mikroe.h:177
tp_mikroe_pressure_threshold_t pressure_threshold_level
Definition tp_mikroe.h:180
pin_name_t down
Definition tp_mikroe.h:167
analog_in_t analog_in_y
Definition tp_mikroe.h:170
tp_rotate_t rotate
Definition tp_mikroe.h:175
pin_name_t right
Definition tp_mikroe.h:165
tp_event_t press_det
Definition tp_mikroe.h:172
uint16_t height
Definition tp_mikroe.h:186
Touch Panel Context Object.
Definition tp.h:224
Touch Point Object Definition.
Definition tp.h:137
tp_event_t
Touch Panel Event Code Definition.
Definition tp.h:81
tp_err_t
Touch Panel Error Code Definition.
Definition tp.h:65
tp_rotate_t
Touch Panel Placement (Orientation) Definition.
Definition tp.h:117