硬汉嵌入式论坛

 找回密码
 立即注册
查看: 966|回复: 2
收起左侧

[ThreadX全家桶] 完成LVGL, ThreadX GUIX,emWin6.x和裸机触摸触方案统一(2023-07-16)

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107128
QQ
发表于 2023-7-16 09:45:25 | 显示全部楼层 |阅读模式
现在V5,V6和V7都已经统一,而且都是修改同样的函数实现,  包括电阻触摸和电容触摸。

1、裸机无需任何修改,emWin仅需对bsp_ts_touch.c文件函数TOUCH_PutKey做个修改:

[C] 纯文本查看 复制代码
GUI_PID_STATE State;
void TOUCH_PutKey(uint8_t _ucEvent, uint16_t _usX, uint16_t _usY)
{
#if 1
        uint16_t xx, yy;


        if (g_tTP.Enable == 1)        /* 电阻屏。 形参是ADC值 */
        {
                xx = TOUCH_TransX(_usX, _usY);
                yy = TOUCH_TransY(_usX, _usY);
        }
        else        /* GT811,FTX06,GT911 电容触摸走此分之 */
        {
                /* 无需转换, 直接是坐标值 */
                xx = _usX;
                yy = _usY;               
        }
        
        /* 按下, 移动和松手事件 */
        switch (_ucEvent)
        {
                case TOUCH_DOWN:
            State.x = xx;
            State.y = yy;
            State.Pressed = 1;
            GUI_PID_StoreState(&State);
                        break;

                case TOUCH_MOVE:
            State.x = xx;
            State.y = yy;
            State.Pressed = 1;
            GUI_PID_StoreState(&State);
                        break;

                case TOUCH_RELEASE:
                        State.Pressed = 0;
                        GUI_PID_StoreState(&State);
                        break;

                default:
                        break;
        }
#else
        uint16_t xx, yy;
        uint16_t x = 0, y = 0;

        g_tTP.Event[g_tTP.Write] = _ucEvent;

        if (g_tTP.Enable == 1)        /* 电阻屏。 形参是ADC值 */
        {
                xx = TOUCH_TransX(_usX, _usY);
                yy = TOUCH_TransY(_usX, _usY);
        }
        else        /* GT811,FTX06,GT911 电容触摸走此分之 */
        {
                /* 无需转换, 直接是坐标值 */
                xx = _usX;
                yy = _usY;               
        }
        
        /* 横屏和竖屏方向识别 */
        switch (g_tTPParam.TouchDirection)
        {
                case 0:        /* 校准触摸时,屏幕方向为0 */
                        if (g_LcdDirection == 0)                /* 横屏 */
                        {
                                x = xx;
                                y = yy;
                        }
                        else if (g_LcdDirection == 1)        /* 横屏180°*/
                        {
                                x = g_LcdWidth - xx - 1;
                                y = g_LcdHeight - yy - 1;
                        }
                        else if (g_LcdDirection == 2)        /* 竖屏 */
                        {
                                y = xx;
                                x = g_LcdWidth - yy - 1;
                        }
                        else if (g_LcdDirection == 3)        /* 竖屏180° */
                        {
                                y = g_LcdHeight - xx - 1;
                                x = yy;
                        }
                        break;

                case 1:        /* 校准触摸时,屏幕方向为1 */
                        if (g_LcdDirection == 0)                /* 横屏 */
                        {
                                x = g_LcdWidth - xx - 1;
                                y = g_LcdHeight - yy - 1;
                        }
                        else if (g_LcdDirection == 1)        /* 横屏180°*/
                        {
                                x = xx;
                                y = yy;
                        }
                        else if (g_LcdDirection == 2)        /* 竖屏 */
                        {
                                y = g_LcdHeight - xx - 1;
                                x = yy;
                        }
                        else if (g_LcdDirection == 3)        /* 竖屏180° */
                        {
                                y = xx;
                                x = g_LcdWidth - yy - 1;
                        }
                        break;

                case 2:        /* 校准触摸时,屏幕方向为2 */
                        if (g_LcdDirection == 0)                /* 横屏 */
                        {
                                y = xx;
                                x = g_LcdWidth - yy - 1;
                        }
                        else if (g_LcdDirection == 1)        /* 横屏180°*/
                        {
                                y = g_LcdHeight - xx - 1;
                                x = yy;
                        }
                        else if (g_LcdDirection == 2)        /* 竖屏 */
                        {
                                x = xx;
                                y = yy;
                        }
                        else if (g_LcdDirection == 3)        /* 竖屏180° */
                        {
                                x = g_LcdWidth - xx - 1;
                                y = g_LcdHeight - yy - 1;
                        }
                        break;

                case 3:        /* 校准触摸时,屏幕方向为3 */
                        if (g_LcdDirection == 0)                /* 横屏 */
                        {
                                y = xx;
                                x = g_LcdWidth - yy - 1;
                        }
                        else if (g_LcdDirection == 1)        /* 横屏180°*/
                        {
                                y = g_LcdHeight - xx - 1;
                                x = yy;
                        }
                        else if (g_LcdDirection == 2)        /* 竖屏 */
                        {
                                x = g_LcdWidth - xx - 1;
                                y = g_LcdHeight - yy - 1;
                        }
                        else if (g_LcdDirection == 3)        /* 竖屏180° */
                        {
                                x = xx;
                                y = yy;
                        }
                        break;

                default:
                        g_tTPParam.TouchDirection = 0;        /* 方向参数无效时,纠正为缺省的横屏 */
                        break;
        }

        g_tTP.XBuf[g_tTP.Write] = x;
        g_tTP.YBuf[g_tTP.Write] = y;

        if (++g_tTP.Write  >= TOUCH_FIFO_SIZE)
        {
                g_tTP.Write = 0;
        }
        
        /* 调试语句,打印adc和坐标 */
        touch_printf("%d - (%d, %d) adcX=%d,adcY=%d\r\n", _ucEvent, x, y, g_tTP.usAdcNowX, g_tTP.usAdcNowY);
#endif
}


2、同样,ThreadX GUIX也仅需对bsp_ts_touch.c文件函数TOUCH_PutKey做个修改:

[C] 纯文本查看 复制代码
#include   "gx_api.h"
void TOUCH_PutKey(uint8_t _ucEvent, uint16_t _usX, uint16_t _usY)
{
#if 1
        uint16_t xx, yy;
        GX_EVENT event;

        if (g_tTP.Enable == 1)        /* 电阻屏。 形参是ADC值 */
        {
                xx = TOUCH_TransX(_usX, _usY);
                yy = TOUCH_TransY(_usX, _usY);
        }
        else        /* GT811,FTX06,GT911 电容触摸走此分之 */
        {
                /* 无需转换, 直接是坐标值 */
                xx = _usX;
                yy = _usY;               
        }
        
        /* 按下, 移动和松手事件 */
        switch (_ucEvent)
        {
                case TOUCH_DOWN:
                        event.gx_event_type = GX_EVENT_PEN_DOWN;
                        event.gx_event_payload.gx_event_pointdata.gx_point_x = xx;
                        event.gx_event_payload.gx_event_pointdata.gx_point_y = yy;
                        event.gx_event_sender = 0;
                        event.gx_event_target = 0;
                        event.gx_event_display_handle = 0xC0000000;
                        gx_system_event_send(&event);
                        break;

                case TOUCH_MOVE:
                        event.gx_event_type = GX_EVENT_PEN_DRAG;
                        event.gx_event_payload.gx_event_pointdata.gx_point_x = xx;
                        event.gx_event_payload.gx_event_pointdata.gx_point_y = yy;
                        event.gx_event_sender = 0;
                        event.gx_event_target = 0;
                        event.gx_event_display_handle = 0xC0000000;
                        gx_system_event_fold(&event);
                        break;

                case TOUCH_RELEASE:
                        event.gx_event_type = GX_EVENT_PEN_UP;
                        event.gx_event_payload.gx_event_pointdata.gx_point_x = xx;
                        event.gx_event_payload.gx_event_pointdata.gx_point_y = yy;
                        event.gx_event_sender = 0;
                        event.gx_event_target = 0;
                        event.gx_event_display_handle = 0xC0000000;
                        gx_system_event_send(&event);
                        break;

                default:
                        break;
        }
#else
        uint16_t xx, yy;
        uint16_t x = 0, y = 0;

        g_tTP.Event[g_tTP.Write] = _ucEvent;

        if (g_tTP.Enable == 1)        /* 电阻屏。 形参是ADC值 */
        {
                xx = TOUCH_TransX(_usX, _usY);
                yy = TOUCH_TransY(_usX, _usY);
        }
        else        /* GT811,FTX06,GT911 电容触摸走此分之 */
        {
                /* 无需转换, 直接是坐标值 */
                xx = _usX;
                yy = _usY;               
        }
        
        /* 横屏和竖屏方向识别 */
        switch (g_tTPParam.TouchDirection)
        {
                case 0:        /* 校准触摸时,屏幕方向为0 */
                        if (g_LcdDirection == 0)                /* 横屏 */
                        {
                                x = xx;
                                y = yy;
                        }
                        else if (g_LcdDirection == 1)        /* 横屏180°*/
                        {
                                x = g_LcdWidth - xx - 1;
                                y = g_LcdHeight - yy - 1;
                        }
                        else if (g_LcdDirection == 2)        /* 竖屏 */
                        {
                                y = xx;
                                x = g_LcdWidth - yy - 1;
                        }
                        else if (g_LcdDirection == 3)        /* 竖屏180° */
                        {
                                y = g_LcdHeight - xx - 1;
                                x = yy;
                        }
                        break;

                case 1:        /* 校准触摸时,屏幕方向为1 */
                        if (g_LcdDirection == 0)                /* 横屏 */
                        {
                                x = g_LcdWidth - xx - 1;
                                y = g_LcdHeight - yy - 1;
                        }
                        else if (g_LcdDirection == 1)        /* 横屏180°*/
                        {
                                x = xx;
                                y = yy;
                        }
                        else if (g_LcdDirection == 2)        /* 竖屏 */
                        {
                                y = g_LcdHeight - xx - 1;
                                x = yy;
                        }
                        else if (g_LcdDirection == 3)        /* 竖屏180° */
                        {
                                y = xx;
                                x = g_LcdWidth - yy - 1;
                        }
                        break;

                case 2:        /* 校准触摸时,屏幕方向为2 */
                        if (g_LcdDirection == 0)                /* 横屏 */
                        {
                                y = xx;
                                x = g_LcdWidth - yy - 1;
                        }
                        else if (g_LcdDirection == 1)        /* 横屏180°*/
                        {
                                y = g_LcdHeight - xx - 1;
                                x = yy;
                        }
                        else if (g_LcdDirection == 2)        /* 竖屏 */
                        {
                                x = xx;
                                y = yy;
                        }
                        else if (g_LcdDirection == 3)        /* 竖屏180° */
                        {
                                x = g_LcdWidth - xx - 1;
                                y = g_LcdHeight - yy - 1;
                        }
                        break;

                case 3:        /* 校准触摸时,屏幕方向为3 */
                        if (g_LcdDirection == 0)                /* 横屏 */
                        {
                                y = xx;
                                x = g_LcdWidth - yy - 1;
                        }
                        else if (g_LcdDirection == 1)        /* 横屏180°*/
                        {
                                y = g_LcdHeight - xx - 1;
                                x = yy;
                        }
                        else if (g_LcdDirection == 2)        /* 竖屏 */
                        {
                                x = g_LcdWidth - xx - 1;
                                y = g_LcdHeight - yy - 1;
                        }
                        else if (g_LcdDirection == 3)        /* 竖屏180° */
                        {
                                x = xx;
                                y = yy;
                        }
                        break;

                default:
                        g_tTPParam.TouchDirection = 0;        /* 方向参数无效时,纠正为缺省的横屏 */
                        break;
        }

        g_tTP.XBuf[g_tTP.Write] = x;
        g_tTP.YBuf[g_tTP.Write] = y;

        if (++g_tTP.Write  >= TOUCH_FIFO_SIZE)
        {
                g_tTP.Write = 0;
        }
        
        /* 调试语句,打印adc和坐标 */
        touch_printf("%d - (%d, %d) adcX=%d,adcY=%d\r\n", _ucEvent, x, y, g_tTP.usAdcNowX, g_tTP.usAdcNowY);
#endif
}


3、LVGL无需任何修改,仅需给接口函数touchpad_read提供反馈

[C] 纯文本查看 复制代码
/*Will be called by the library to read the touchpad*/
static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
        static lv_coord_t last_x = 0;
        static lv_coord_t last_y = 0;

        uint8_t ret;
        int16_t x,y;
        
        ret = TOUCH_GetKey(&x, &y);
        
        /*Save the pressed coordinates and the state*/
    if((ret == TOUCH_MOVE)||(ret == TOUCH_DOWN))
        {
                last_x = x;
                last_y = y;
                data->state = LV_INDEV_STATE_PR;
        }
        else //if(ret == TOUCH_RELEASE)
        {
                data->state = LV_INDEV_STATE_REL;
        }
        
        /*Set the last pressed coordinates*/
        data->point.x = last_x;
        data->point.y = last_y;
}


回复

使用道具 举报

610

主题

3063

回帖

4913

积分

至尊会员

积分
4913
发表于 2023-7-28 11:17:01 | 显示全部楼层
牛劈 了,我的神

据说 lvgl 比较好用,不过貌似有版本兼容的问题,不知道大神会不会这个方面的教程呀 ?

回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107128
QQ
 楼主| 发表于 2023-7-28 14:58:03 | 显示全部楼层
hpdell 发表于 2023-7-28 11:17
牛劈 了,我的神

据说 lvgl 比较好用,不过貌似有版本兼容的问题,不知道大神会不会这个方面的教程呀 ? ...

官方文档,整的不错,上手足够。
https://docs.lvgl.io/8.3/index.html
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-19 22:30 , Processed in 0.256209 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表