summaryrefslogtreecommitdiff
path: root/bsp/renesas/ra2l1-cpk/QE-Touch/qe_sample_rtthread.c
blob: 8342466bcfa90b693cd8e03e07df2aff02b50300 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "qe_touch_config.h"
#include <rtthread.h>
#include <rtdevice.h>
#define TOUCH_SCAN_INTERVAL_EXAMPLE (20)    /* milliseconds */

uint64_t button_status;
#if (TOUCH_CFG_NUM_SLIDERS != 0)
    uint16_t slider_position[TOUCH_CFG_NUM_SLIDERS];
#endif
#if (TOUCH_CFG_NUM_WHEELS != 0)
    uint16_t wheel_position[TOUCH_CFG_NUM_WHEELS];
#endif

void qe_touch_main(void *parameter)
{
    fsp_err_t err;
    rt_uint32_t led_blu = rt_pin_get("P501");

    /* Open Touch middleware */
    rt_kprintf("TOUCH Open\n");
    err = RM_TOUCH_Open(g_qe_touch_instance_config01.p_ctrl, g_qe_touch_instance_config01.p_cfg);
    if (FSP_SUCCESS != err)
    {
        rt_kprintf("RM_TOUCH_Open fail\n");
        return;
    }

    rt_kprintf("TOUCH ScanStart\n");
    /* Main loop */
    while (true)
    {
        /* for [CONFIG01] configuration */
        err = RM_TOUCH_ScanStart(g_qe_touch_instance_config01.p_ctrl);
        if (FSP_SUCCESS != err)
        {
            rt_kprintf("RM_TOUCH_Open fail\n");
            return;
        }
        while (0 == g_qe_touch_flag) {}
        g_qe_touch_flag = 0;

        err = RM_TOUCH_DataGet(g_qe_touch_instance_config01.p_ctrl, &button_status, NULL, NULL);
        if (FSP_SUCCESS == err)
        {
            if (button_status)
            {
                rt_pin_write(led_blu, PIN_HIGH);
            }
            else
            {
                rt_pin_write(led_blu, PIN_LOW);
            }
        }

        /* FIXME: Since this is a temporary process, so re-create a waiting process yourself. */
        rt_thread_mdelay(TOUCH_SCAN_INTERVAL_EXAMPLE);
    }
}

int touch_init(void)
{
    rt_thread_t tid = rt_thread_create("touch", qe_touch_main, RT_NULL, 512, 10, 50);
    if (tid)
    {
        rt_thread_startup(tid);
    }
    return 0;
}
INIT_APP_EXPORT(touch_init);
//MSH_CMD_EXPORT(touch_init, touch_init);