summaryrefslogtreecommitdiff
path: root/bsp/nxp/lpc/lpc55sxx/libraries/drivers/sample/touch_sample.c
blob: 1c649ad7539b4b0a346a71d184289ae54ec9c7de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * Copyright (c) 2006-2023, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2023-05-26     Chushicheng  the first version
 */
/*
 * Program listing: This is a touch device usage routine
 * The routine exports touch_sample commands to the control terminal
 * Command invocation format: touch_sample
 * Program function: The terminal prints the coordinates of the touch point
*/
#include <rtdevice.h>
#include "drv_gt911.h"

static int touch_sample(void)
{
    gt911_input_t ctp_input;

    rt_device_t dev = rt_device_find("capt");

    RT_ASSERT(dev != RT_NULL);

    capt_t *capt = (capt_t*)dev->user_data;
    while(1)
    {
        gt911_ctp_read(&capt->gt911, &ctp_input);

        for (rt_uint8_t  i = 0; i < ctp_input.num_pos; i++)
        {
            /* Found track ID #0 */
            if (ctp_input.pos[i].id == 0)
            {
                rt_kprintf("x:%d, y:%d\r\n", capt->gt911.pos_y_max - ctp_input.pos[i].pos_y, ctp_input.pos[i].pos_x);
            }
        }

        rt_thread_mdelay(16);
    }

    return RT_EOK;
}

MSH_CMD_EXPORT(touch_sample, the capt touch test);