mikroSDK Reference Manual
tp_mikroe.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 ****************************************************************************/
44 #ifndef _TP_MIKROE_H_
45 #define _TP_MIKROE_H_
46 
47 #ifdef __cplusplus
48 extern "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 
58 
59 
64 #define VREF_VALUE 3.3f
65 
66 #ifndef TP_MIKROE_CALIBRATION_XMIN
67 
71 #define TP_MIKROE_CALIBRATION_XMIN 0
72 #endif
73 #ifndef TP_MIKROE_CALIBRATION_XMAX
74 
78 #define TP_MIKROE_CALIBRATION_XMAX 0
79 #endif
80 
81 #ifndef TP_MIKROE_CALIBRATION_YMIN
82 
86 #define TP_MIKROE_CALIBRATION_YMIN 0
87 #endif
88 #ifndef TP_MIKROE_CALIBRATION_YMAX
89 
93 #define TP_MIKROE_CALIBRATION_YMAX 0
94 #endif
95 
96 #ifndef TP_MIKROE_PRESSURE_THRESHOLD_LOWER
97 
101 #define TP_MIKROE_PRESSURE_THRESHOLD_LOWER 0
102 #endif
103 #ifndef TP_MIKROE_PRESSURE_THRESHOLD_UPPER
104 
108 #define TP_MIKROE_PRESSURE_THRESHOLD_UPPER 0
109 #endif
110 
114 #define TP_MIKROE_MAP_PINS( tp_mikroe_cfg ) \
115  tp_mikroe_cfg.left = TP_MIKROE_XL;\
116  tp_mikroe_cfg.right = TP_MIKROE_XR;\
117  tp_mikroe_cfg.up = TP_MIKROE_YU;\
118  tp_mikroe_cfg.down = TP_MIKROE_YD;
119 
124 typedef struct {
125  uint16_t min_x;
126  uint16_t max_x;
127  uint16_t min_y;
128  uint16_t max_y;
130 
135 typedef struct {
136  uint16_t tp_mikroe_pressure_threshold_lower;
137  uint16_t tp_mikroe_pressure_threshold_upper;
139 
144 typedef struct {
145  pin_name_t left;
146  pin_name_t right;
148  pin_name_t down;
150  analog_in_config_t analog_in_cfg_read_x;
151  analog_in_config_t analog_in_cfg_read_y;
154  tp_mikroe_pressure_threshold_t pressure_threshold_level;
156  uint16_t width;
157  uint16_t height;
159 
164 #define TP_MIKROE_ADC_CONFIG( cfg ) \
165  cfg->analog_in_cfg_read_x.resolution = ANALOG_IN_RESOLUTION_CMAKE; \
166  cfg->analog_in_cfg_read_y.resolution = ANALOG_IN_RESOLUTION_CMAKE; \
167  cfg->analog_in_cfg_read_x.input_pin = TP_READ_X_CMAKE; \
168  cfg->analog_in_cfg_read_y.input_pin = TP_READ_Y_CMAKE; \
169  cfg->analog_in_cfg_read_x.vref_input = ANALOG_IN_VREF_CMAKE; \
170  cfg->analog_in_cfg_read_y.vref_input = ANALOG_IN_VREF_CMAKE; \
171  cfg->analog_in_cfg_read_x.vref_value = VREF_VALUE; \
172  cfg->analog_in_cfg_read_y.vref_value = VREF_VALUE;
173 
178 typedef struct {
179  pin_name_t left;
180  pin_name_t right;
182  pin_name_t down;
184  analog_in_t analog_in_x;
185  analog_in_t analog_in_y;
187  tp_event_t press_det;
189  tp_event_t gesture;
190  tp_rotate_t rotate;
192  bool pen_down;
194  tp_mikroe_pressure_threshold_t pressure_threshold_level;
196  tp_mikroe_calibration_data_t calibration_data;
198  uint16_t width;
199  uint16_t height;
200 } tp_mikroe_t;
201 
206 #define SET_PEN() \
207  gl_set_pen( GL_WHITE, 4 );
208 
213 #define DRAW_ARROW_TOP_LEFT() \
214  gl_clear( GL_BLACK ); \
215  gl_draw_line( 0, 0, 10, 0 ); \
216  gl_draw_line( 0, 0, 0, 10 ); \
217  gl_draw_line( 0, 0, 15, 15 );
218 
223 #define DRAW_ARROW_TOP_RIGHT() \
224  gl_clear( GL_BLACK ); \
225  gl_draw_line( 320, 0, 320, 10 ); \
226  gl_draw_line( 320, 0, 310, 0 ); \
227  gl_draw_line( 320, 0, 305, 15 );
228 
233 #define DRAW_ARROW_BOTTOM_LEFT() \
234  gl_clear( GL_BLACK ); \
235  gl_draw_line( 0, 240, 0, 230 ); \
236  gl_draw_line( 0, 240, 10, 240 ); \
237  gl_draw_line( 0, 240, 15, 225 );
238 
243 #define DRAW_ARROW_BOTTOM_RIGHT() \
244  gl_clear( GL_BLACK ); \
245  gl_draw_line( 320, 240, 320, 230 ); \
246  gl_draw_line( 320, 240, 310, 240 ); \
247  gl_draw_line( 320, 240, 305, 225 );
248 
272 
285 void tp_mikroe_gesture ( tp_mikroe_t *ctx, tp_event_t *event );
286 
299 
309 void tp_mikroe_press_coordinates ( tp_mikroe_t *ctx, tp_touch_coord_t *touch_item );
310 
318 void tp_mikroe_calibrate( tp_t *tp_instance );
319 
329 
340 
352 
363 bool tp_mikroe_check_pressure ( tp_mikroe_t *ctx, uint16_t *x_pos, uint16_t *y_pos );
364 
373 void tp_mikroe_set_threshold ( tp_mikroe_t *ctx, uint16_t threshold_upper, uint16_t threshold_lower );
374 
384 void tp_mikroe_update_ctx_coords( tp_mikroe_t *ctx, uint16_t x_pos, uint16_t y_pos );
385 
397 void tp_mikroe_calibrate_point ( tp_mikroe_t *ctx, bool calibration_points_uninitialized );
398 
406 
415 
435 
444  // tp_mikroe // mwgroup
447 
448 #ifdef __cplusplus
449 }
450 #endif
451 
452 #endif // _TP_MIKROE_H_
453 
454 // ------------------------------------------------------------------------ END
tp_mikroe_calibrate_point
void tp_mikroe_calibrate_point(tp_mikroe_t *ctx, bool calibration_points_uninitialized)
Utility function used for calibration.
tp_t
Touch Panel Context Object.
Definition: tp.h:222
tp_mikroe_update_ctx_coords
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...
tp_mikroe_set_pressure_threshold_level
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.
tp.h
Touch Panel API Library.
analog_in_config_t
Analog input driver configuration structure.
Definition: drv_analog_in.h:106
drv_analog_in.h
API for Analog input driver.
tp_mikroe_press_detect
tp_event_t tp_mikroe_press_detect(tp_mikroe_t *ctx)
Press detection function.
analog_in_t
Analog input driver context structure, consisted of the following fields :
Definition: drv_analog_in.h:126
drv_digital_in.h
API for Digital input driver.
tp_event_t
tp_event_t
Touch Panel Event Code Definition.
Definition: tp.h:79
tp_mikroe_init_tp
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...
tp_mikroe_press_coordinates
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.
tp_mikroe_gesture
void tp_mikroe_gesture(tp_mikroe_t *ctx, tp_event_t *event)
Read gesture information.
tp_mikroe_set_threshold
void tp_mikroe_set_threshold(tp_mikroe_t *ctx, uint16_t threshold_upper, uint16_t threshold_lower)
Utility function used for setting threshold levels.
tp_mikroe_pressure_level_detect
char tp_mikroe_pressure_level_detect(tp_mikroe_t *ctx)
Function used for checking pressure levels.
tp_err_t
tp_err_t
Touch Panel Error Code Definition.
Definition: tp.h:63
tp_touch_coord_t
Touch Point Object Definition.
Definition: tp.h:135
tp_rotate_t
tp_rotate_t
Touch Panel Placement (Orientation) Definition.
Definition: tp.h:115
tp_mikroe_pressure_threshold_t
Pressure threshold data structure.
Definition: tp_mikroe.h:134
tp_mikroe_process
tp_err_t tp_mikroe_process(tp_mikroe_t *ctx)
Function processing events.
tp_mikroe_default_cfg_adc
void tp_mikroe_default_cfg_adc(tp_mikroe_t *ctx)
TP_MIKROE ADC pin configuration function.
pin_name_t
hal_pin_name_t pin_name_t
Definition: drv_name.h:73
tp_mikroe_t
TP_MIKROE Context Object.
Definition: tp_mikroe.h:177
drv_digital_out.h
API for Digital output driver.
tp_mikroe_calibrate
void tp_mikroe_calibrate(tp_t *tp_instance)
Calibrates variables used for converting raw TP_MIKROE ADC values to pixel coordinates.
gl.h
Graphics Library.
tp_mikroe_calibration_data_t
Calibration data structure.
Definition: tp_mikroe.h:123
tp_mikroe_set_calibration_data
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_mikroe_cfg_t
TP_MIKROE Configuration Object.
Definition: tp_mikroe.h:143
tp_mikroe_cfg_setup
void tp_mikroe_cfg_setup(tp_mikroe_cfg_t *cfg)
TP_MIKROE Configuration setup Function.
tp_drv_t
Touch Panel Driver Interface Items.
Definition: tp.h:197
tp_mikroe_get_calibration_data
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_mikroe_check_pressure
bool tp_mikroe_check_pressure(tp_mikroe_t *ctx, uint16_t *x_pos, uint16_t *y_pos)
Function for reading raw ADC data.