Solar panel
Loading...
Searching...
No Matches
ft5xx6.c
Go to the documentation of this file.
1/****************************************************************************
2**
3** Copyright (C) 2020 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****************************************************************************/
39
45#include "ft5xx6.h"
46#include "drv_digital_out.h"
47#include "drv_digital_in.h"
48
54{
55 {
56 { 0x00, TP_EVENT_GEST_NONE },
57 { 0x10, TP_EVENT_GEST_LEFT },
58 { 0x18, TP_EVENT_GEST_RIGHT },
59 { 0x1C, TP_EVENT_GEST_UP },
60 { 0x14, TP_EVENT_GEST_DOWN },
61 { 0x48, TP_EVENT_GEST_ZOOM_IN },
62 { 0x49, TP_EVENT_GEST_ZOOM_OUT }
63 }
64};
65
67{
68 {
69 { 0x00, TP_EVENT_GEST_NONE },
70 { 0x10, TP_EVENT_GEST_LEFT },
71 { 0x18, TP_EVENT_GEST_RIGHT },
72 { 0x1C, TP_EVENT_GEST_UP },
73 { 0x14, TP_EVENT_GEST_DOWN },
74 { 0x48, TP_EVENT_GEST_ZOOM_IN },
75 { 0x49, TP_EVENT_GEST_ZOOM_OUT }
76 }
77};
78
80{
81 {
82 { 0x00, TP_EVENT_GEST_NONE },
83 { 0x1C, TP_EVENT_GEST_LEFT },
84 { 0x14, TP_EVENT_GEST_RIGHT },
85 { 0x10, TP_EVENT_GEST_UP },
86 { 0x18, TP_EVENT_GEST_DOWN },
87 { 0x48, TP_EVENT_GEST_ZOOM_IN },
88 { 0x49, TP_EVENT_GEST_ZOOM_OUT }
89 }
90};
91
93{
94 {
95 { 0x00, TP_EVENT_GEST_NONE },
96 { 0x1C, TP_EVENT_GEST_LEFT },
97 { 0x14, TP_EVENT_GEST_RIGHT },
98 { 0x10, TP_EVENT_GEST_UP },
99 { 0x18, TP_EVENT_GEST_DOWN },
100 { 0x48, TP_EVENT_GEST_ZOOM_IN },
101 { 0x49, TP_EVENT_GEST_ZOOM_OUT }
102 }
103};
104
114static tp_err_t
115ft5xx6_read_press_coordinates( ft5xx6_t * ctx );
116
125static void
126ft5xx6_read_gesture( ft5xx6_t * ctx );
127
128void
130{
131 i2c_master_configure_default( &cfg->i2c_cfg );
132
133 cfg->int_pin = HAL_PIN_NC;
134 cfg->controller = controller;
135}
136
137tp_err_t
138ft5xx6_init( ft5xx6_t * ctx, ft5xx6_cfg_t * cfg, tp_drv_t * drv )
139{
140// digital_out_t scl_pin;
141// digital_in_t sda_pin;
142
143 // ** Linking problem for functions with different types of arguments.
144 tp_event_t ( * tmp_ptr1 )( ft5xx6_t * );
145 void ( * tmp_ptr2 )( ft5xx6_t *, tp_touch_item_t * );
146 void ( * tmp_ptr3 )( ft5xx6_t *, tp_event_t * );
147 tp_err_t ( * tmp_ptr4 )( ft5xx6_t * );
148
149 /*digital_out_init( &scl_pin, cfg->i2c_cfg.scl );
150 digital_in_init( &sda_pin, cfg->i2c_cfg.sda );
151 digital_out_high( &scl_pin );
152
153 while ( 0 == digital_in_read( &sda_pin ) )
154 {
155 digital_out_low( &scl_pin );
156 Delay_10us( );
157 digital_out_high( &scl_pin );
158 Delay_10us( );
159 }*/
160
161 if ( i2c_master_open( &ctx->i2c, &cfg->i2c_cfg ) == I2C_MASTER_ERROR )
162 {
163 return TP_ERR_INIT_DRV;
164 }
165
166 i2c_master_set_slave_address( &ctx->i2c, FT5XX6_I2C_ADDR );
167 i2c_master_set_speed( &ctx->i2c, I2C_MASTER_SPEED_STANDARD );
168 i2c_master_set_timeout( &ctx->i2c, 0 );
169
170 if ( digital_in_init( &ctx->int_pin, cfg->int_pin ) == DIGITAL_IN_UNSUPPORTED_PIN )
171 {
172 return TP_ERR_UNSUPPORTED_PIN;
173 }
174
175 ctx->controller = cfg->controller;
176
177 drv->tp_press_detect_f = ft5xx6_press_detect;
178 drv->tp_press_coordinates_f = ft5xx6_press_coordinates;
179 drv->tp_gesture_f = ft5xx6_gesture;
180 drv->tp_process_f = ft5xx6_process;
181
182 return TP_OK;
183
184 // **
185 tmp_ptr1( NULL );
186 tmp_ptr2( NULL, NULL );
187 tmp_ptr3( NULL, NULL );
188 tmp_ptr4( NULL );
189}
190
191void
193{
198}
199
200void
201ft5xx6_generic_write( ft5xx6_t * ctx, uint8_t reg_addr, uint8_t data_in )
202{
203 uint8_t tmp_data[ 2 ];
204
205 tmp_data[ 0 ] = reg_addr;
206 tmp_data[ 1 ] = data_in;
207
208 i2c_master_write( &ctx->i2c, tmp_data, 2 );
209}
210
211uint8_t
212ft5xx6_generic_read_single( ft5xx6_t * ctx, uint8_t reg_addr )
213{
214 uint8_t tmp_data;
215
216 tmp_data = reg_addr;
217
218 i2c_master_write_then_read( &ctx->i2c, &tmp_data, 1, &tmp_data, 1 );
219
220 return tmp_data;
221}
222
223tp_err_t
224ft5xx6_generic_read_multiple( ft5xx6_t * ctx, uint8_t reg_addr,
225 uint8_t * data_out, uint16_t n_bytes )
226{
227 uint8_t tmp_data;
228
229 if ( ( n_bytes < FT5XX6_N_DATA_TRANSFER_MIN ) ||
230 ( n_bytes > FT5XX6_N_DATA_TRANSFER_MAX ) )
231 {
232 return TP_ERR_N_DATA;
233 }
234
235 tmp_data = reg_addr;
236
237 i2c_master_write_then_read( &ctx->i2c, &tmp_data, 1, data_out, n_bytes );
238
239 return TP_OK;
240}
241
242void
244{
246}
247
248void
250{
252}
253
254tp_event_t
256{
257 return ctx->press_det;
258}
259
260void
261ft5xx6_press_coordinates( ft5xx6_t * ctx, tp_touch_item_t * touch_item )
262{
263 touch_item->n_touches = ctx->touch.n_touches;
264
265 for ( uint8_t idx = 0; idx < ctx->touch.n_touches; idx++ )
266 {
267 touch_item->point[ idx ].coord_x = ctx->touch.point[ idx ].coord_x;
268 touch_item->point[ idx ].coord_y = ctx->touch.point[ idx ].coord_y;
269
270 touch_item->point[ idx ].event = ctx->touch.point[ idx ].event;
271 touch_item->point[ idx ].id = ctx->touch.point[ idx ].id;
272 }
273}
274
275void
276ft5xx6_gesture( ft5xx6_t * ctx, tp_event_t * event )
277{
278 *event = ctx->gesture;
279}
280
281tp_err_t
283{
284 tp_err_t status;
285
286 status = ft5xx6_read_press_coordinates( ctx );
287
288 if ( ( status == TP_OK ) && ( ctx->press_det == TP_EVENT_PRESS_DET ) )
289 {
290 ft5xx6_read_gesture( ctx );
291 }
292
293 return status;
294}
295
296static tp_err_t
297ft5xx6_read_press_coordinates( ft5xx6_t * ctx )
298{
299 if ( !digital_in_read( &ctx->int_pin ) )
300 {
302
303 if ( ctx->touch.n_touches > TP_N_TOUCHES_MAX )
304 {
305 return TP_ERR_N_TOUCHES;
306 }
307 else
308 {
309 uint8_t read_data[ 4 ];
310 uint8_t touch_addr = FT5XX6_REG_TOUCH1_XH;
311
312 for ( uint8_t idx = 0; idx < ctx->touch.n_touches; idx++ )
313 {
314 ft5xx6_generic_read_multiple( ctx, touch_addr, read_data, 4 );
315
316 ctx->touch.point[ idx ].coord_x = read_data[ 0 ];
317 ctx->touch.point[ idx ].coord_x <<= 8;
318 ctx->touch.point[ idx ].coord_x |= read_data[ 1 ];
319 ctx->touch.point[ idx ].coord_x &= FT5XX6_MASK_PRESS_COORD;
320
321 ctx->touch.point[ idx ].coord_y = read_data[ 2 ];
322 ctx->touch.point[ idx ].coord_y <<= 8;
323 ctx->touch.point[ idx ].coord_y |= read_data[ 3 ];
324 ctx->touch.point[ idx ].coord_y &= FT5XX6_MASK_PRESS_COORD;
325
326 ctx->touch.point[ idx ].event = read_data[ 0 ] >> FT5XX6_OFFSET_PRESS_EVENT;
327 ctx->touch.point[ idx ].id = read_data[ 2 ] >> FT5XX6_OFFSET_PRESS_ID;
328
329 touch_addr += FT5XX6_OFFSET_TOUCH_READING;
330 }
331
332 ctx->press_det = TP_EVENT_PRESS_DET;
333 }
334 }
335 else
336 {
337 ctx->press_det = TP_EVENT_PRESS_NOT_DET;
338 }
339
340 return TP_OK;
341}
342
343static void
344ft5xx6_read_gesture( ft5xx6_t * ctx )
345{
346 uint8_t read_data;
347
349
350 for ( uint8_t idx = 0; idx < FT5XX6_GESTURE_ITEMS_MAX; idx++ )
351 {
352 if ( read_data == ctx->controller->gest_items[ idx ].key )
353 {
354 ctx->gesture = ctx->controller->gest_items[ idx ].value;
355
356 return;
357 }
358 }
359}
360
361// ------------------------------------------------------------------------ END
const ft5xx6_controller_t FT5X26_CONTROLLER
FT5x26 Touch Controllers Descriptor.
Definition: ft5xx6.c:79
const ft5xx6_controller_t FT5X16_CONTROLLER
FT5x16 Touch Controllers Descriptor.
Definition: ft5xx6.c:66
const ft5xx6_controller_t FT5X46_CONTROLLER
FT5x46 Touch Controllers Descriptor.
Definition: ft5xx6.c:92
const ft5xx6_controller_t FT5X06_CONTROLLER
FT5xx6 Events Definition.
Definition: ft5xx6.c:53
FT5xx6 Touch Controller Driver.
ft5xx6_run_mode_t
FT5xx6 Run Mode Settings.
Definition: ft5xx6.h:536
@ FT5XX6_RUN_MODE_WORK
Definition: ft5xx6.h:538
@ FT5XX6_RUN_MODE_CFG
Definition: ft5xx6.h:537
ft5xx6_dev_mode_t
FT5xx6 Device Mode Settings.
Definition: ft5xx6.h:524
@ FT5XX6_DEV_MODE_NORMAL
Definition: ft5xx6.h:525
#define FT5XX6_MASK_PRESS_COORD
FT5xx6 Touch Coordinates Mask.
Definition: ft5xx6.h:447
#define FT5XX6_OFFSET_TOUCH_READING
FT5xx6 Touch Reading Offset.
Definition: ft5xx6.h:502
#define FT5XX6_OFFSET_DEV_MODE
FT5xx6 Device Mode Offset.
Definition: ft5xx6.h:496
#define FT5XX6_OFFSET_PRESS_ID
FT5xx6 Touch ID Offset.
Definition: ft5xx6.h:490
#define FT5XX6_OFFSET_PRESS_EVENT
FT5xx6 Touch Event Offset.
Definition: ft5xx6.h:484
#define FT5XX6_REG_TD_STATUS
FT5xx6 Status Register.
Definition: ft5xx6.h:94
#define FT5XX6_REG_GEST_ID
FT5xx6 Gesture ID Register.
Definition: ft5xx6.h:88
#define FT5XX6_REG_DEVICE_MODE
FT5xx6 Device Mode Register.
Definition: ft5xx6.h:81
#define FT5XX6_REG_RUNNING_STATE
FT5xx6 Running State Register.
Definition: ft5xx6.h:353
#define FT5XX6_REG_IVT_TO_HOST_STATUS
FT5xx6 IVT To Host Status Register.
Definition: ft5xx6.h:332
#define FT5XX6_REG_TOUCH1_XH
FT5xx6 Touch1 X-coord MSB Register.
Definition: ft5xx6.h:101
#define FT5XX6_N_DATA_TRANSFER_MAX
Definition: ft5xx6.h:418
#define FT5XX6_INT_MODE_POLLING
FT5xx6 Interrupt Polling Mode Setting.
Definition: ft5xx6.h:399
#define FT5XX6_I2C_ADDR
FT5xx6 Slave Address Setting.
Definition: ft5xx6.h:411
#define FT5XX6_N_DATA_TRANSFER_MIN
FT5xx6 Data Transfer Limits Setting.
Definition: ft5xx6.h:417
#define FT5XX6_GESTURE_ITEMS_MAX
FT5xx6 Gesture Items Limit Setting.
Definition: ft5xx6.h:424
void ft5xx6_run_mode_setup(ft5xx6_t *ctx, ft5xx6_run_mode_t mode)
FT5xx6 Run Mode Setup Function.
Definition: ft5xx6.c:249
uint8_t ft5xx6_generic_read_single(ft5xx6_t *ctx, uint8_t reg_addr)
FT5xx6 Generic Single Read Function.
Definition: ft5xx6.c:212
void ft5xx6_press_coordinates(ft5xx6_t *ctx, tp_touch_item_t *touch_item)
FT5xx6 Pressure Coordinates Check Function.
Definition: ft5xx6.c:261
tp_err_t ft5xx6_init(ft5xx6_t *ctx, ft5xx6_cfg_t *cfg, tp_drv_t *drv)
FT5xx6 Initialization Function.
Definition: ft5xx6.c:138
void ft5xx6_cfg_setup(ft5xx6_cfg_t *cfg, const ft5xx6_controller_t *controller)
FT5xx6 Configuration Object Setup Function.
Definition: ft5xx6.c:129
tp_event_t ft5xx6_press_detect(ft5xx6_t *ctx)
FT5xx6 Touch Pressure Detect Function.
Definition: ft5xx6.c:255
void ft5xx6_dev_mode_setup(ft5xx6_t *ctx, ft5xx6_dev_mode_t mode)
FT5xx6 Device Mode Setup Function.
Definition: ft5xx6.c:243
void ft5xx6_gesture(ft5xx6_t *ctx, tp_event_t *event)
FT5xx6 Gesture Check Function.
Definition: ft5xx6.c:276
void ft5xx6_generic_write(ft5xx6_t *ctx, uint8_t reg_addr, uint8_t data_in)
FT5xx6 Generic Write Function.
Definition: ft5xx6.c:201
void ft5xx6_default_cfg(ft5xx6_t *ctx)
FT5xx6 Default Configuration Function.
Definition: ft5xx6.c:192
tp_err_t ft5xx6_process(ft5xx6_t *ctx)
FT5xx6 Process Function.
Definition: ft5xx6.c:282
tp_err_t ft5xx6_generic_read_multiple(ft5xx6_t *ctx, uint8_t reg_addr, uint8_t *data_out, uint16_t n_bytes)
FT5xx6 Generic Multiple Read Function.
Definition: ft5xx6.c:224
FT5xx6 Configuration Object.
Definition: ft5xx6.h:571
const ft5xx6_controller_t * controller
Definition: ft5xx6.h:576
i2c_master_config_t i2c_cfg
Definition: ft5xx6.h:574
pin_name_t int_pin
Definition: ft5xx6.h:572
FT5xx6 Gesture Items.
Definition: ft5xx6.h:561
ft5xx6_gest_item_t gest_items[FT5XX6_GESTURE_ITEMS_MAX]
Definition: ft5xx6.h:562
tp_event_t value
Definition: ft5xx6.h:552
FT5xx6 Context Object.
Definition: ft5xx6.h:585
i2c_master_t i2c
Definition: ft5xx6.h:586
tp_event_t gesture
Definition: ft5xx6.h:594
tp_touch_item_t touch
Definition: ft5xx6.h:593
const ft5xx6_controller_t * controller
Definition: ft5xx6.h:590
tp_event_t press_det
Definition: ft5xx6.h:592
digital_in_t int_pin
Definition: ft5xx6.h:588