硬汉嵌入式论坛

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

[LTDC] V7的裸机触摸,emWin触摸和ThreadX GUIX触发方案已经完全统一

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107028
QQ
发表于 2021-2-9 08:14:33 | 显示全部楼层 |阅读模式
现在V5,V6和V7都已经统一,而且都是修改同样的函数实现。

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

  1. GUI_PID_STATE State;
  2. void TOUCH_PutKey(uint8_t _ucEvent, uint16_t _usX, uint16_t _usY)
  3. {
  4. #if 1
  5.         uint16_t xx, yy;


  6.         if (g_tTP.Enable == 1)        /* 电阻屏。 形参是ADC值 */
  7.         {
  8.                 xx = TOUCH_TransX(_usX, _usY);
  9.                 yy = TOUCH_TransY(_usX, _usY);
  10.         }
  11.         else        /* GT811,FTX06,GT911 电容触摸走此分之 */
  12.         {
  13.                 /* 无需转换, 直接是坐标值 */
  14.                 xx = _usX;
  15.                 yy = _usY;               
  16.         }
  17.         
  18.         /* 按下, 移动和松手事件 */
  19.         switch (_ucEvent)
  20.         {
  21.                 case TOUCH_DOWN:
  22.             State.x = xx;
  23.             State.y = yy;
  24.             State.Pressed = 1;
  25.             GUI_PID_StoreState(&State);
  26.                         break;

  27.                 case TOUCH_MOVE:
  28.             State.x = xx;
  29.             State.y = yy;
  30.             State.Pressed = 1;
  31.             GUI_PID_StoreState(&State);
  32.                         break;

  33.                 case TOUCH_RELEASE:
  34.                         State.Pressed = 0;
  35.                         GUI_PID_StoreState(&State);
  36.                         break;

  37.                 default:
  38.                         break;
  39.         }
  40. #else
  41.         uint16_t xx, yy;
  42.         uint16_t x = 0, y = 0;

  43.         g_tTP.Event[g_tTP.Write] = _ucEvent;

  44.         if (g_tTP.Enable == 1)        /* 电阻屏。 形参是ADC值 */
  45.         {
  46.                 xx = TOUCH_TransX(_usX, _usY);
  47.                 yy = TOUCH_TransY(_usX, _usY);
  48.         }
  49.         else        /* GT811,FTX06,GT911 电容触摸走此分之 */
  50.         {
  51.                 /* 无需转换, 直接是坐标值 */
  52.                 xx = _usX;
  53.                 yy = _usY;               
  54.         }
  55.         
  56.         /* 横屏和竖屏方向识别 */
  57.         switch (g_tTPParam.TouchDirection)
  58.         {
  59.                 case 0:        /* 校准触摸时,屏幕方向为0 */
  60.                         if (g_LcdDirection == 0)                /* 横屏 */
  61.                         {
  62.                                 x = xx;
  63.                                 y = yy;
  64.                         }
  65.                         else if (g_LcdDirection == 1)        /* 横屏180°*/
  66.                         {
  67.                                 x = g_LcdWidth - xx - 1;
  68.                                 y = g_LcdHeight - yy - 1;
  69.                         }
  70.                         else if (g_LcdDirection == 2)        /* 竖屏 */
  71.                         {
  72.                                 y = xx;
  73.                                 x = g_LcdWidth - yy - 1;
  74.                         }
  75.                         else if (g_LcdDirection == 3)        /* 竖屏180° */
  76.                         {
  77.                                 y = g_LcdHeight - xx - 1;
  78.                                 x = yy;
  79.                         }
  80.                         break;

  81.                 case 1:        /* 校准触摸时,屏幕方向为1 */
  82.                         if (g_LcdDirection == 0)                /* 横屏 */
  83.                         {
  84.                                 x = g_LcdWidth - xx - 1;
  85.                                 y = g_LcdHeight - yy - 1;
  86.                         }
  87.                         else if (g_LcdDirection == 1)        /* 横屏180°*/
  88.                         {
  89.                                 x = xx;
  90.                                 y = yy;
  91.                         }
  92.                         else if (g_LcdDirection == 2)        /* 竖屏 */
  93.                         {
  94.                                 y = g_LcdHeight - xx - 1;
  95.                                 x = yy;
  96.                         }
  97.                         else if (g_LcdDirection == 3)        /* 竖屏180° */
  98.                         {
  99.                                 y = xx;
  100.                                 x = g_LcdWidth - yy - 1;
  101.                         }
  102.                         break;

  103.                 case 2:        /* 校准触摸时,屏幕方向为2 */
  104.                         if (g_LcdDirection == 0)                /* 横屏 */
  105.                         {
  106.                                 y = xx;
  107.                                 x = g_LcdWidth - yy - 1;
  108.                         }
  109.                         else if (g_LcdDirection == 1)        /* 横屏180°*/
  110.                         {
  111.                                 y = g_LcdHeight - xx - 1;
  112.                                 x = yy;
  113.                         }
  114.                         else if (g_LcdDirection == 2)        /* 竖屏 */
  115.                         {
  116.                                 x = xx;
  117.                                 y = yy;
  118.                         }
  119.                         else if (g_LcdDirection == 3)        /* 竖屏180° */
  120.                         {
  121.                                 x = g_LcdWidth - xx - 1;
  122.                                 y = g_LcdHeight - yy - 1;
  123.                         }
  124.                         break;

  125.                 case 3:        /* 校准触摸时,屏幕方向为3 */
  126.                         if (g_LcdDirection == 0)                /* 横屏 */
  127.                         {
  128.                                 y = xx;
  129.                                 x = g_LcdWidth - yy - 1;
  130.                         }
  131.                         else if (g_LcdDirection == 1)        /* 横屏180°*/
  132.                         {
  133.                                 y = g_LcdHeight - xx - 1;
  134.                                 x = yy;
  135.                         }
  136.                         else if (g_LcdDirection == 2)        /* 竖屏 */
  137.                         {
  138.                                 x = g_LcdWidth - xx - 1;
  139.                                 y = g_LcdHeight - yy - 1;
  140.                         }
  141.                         else if (g_LcdDirection == 3)        /* 竖屏180° */
  142.                         {
  143.                                 x = xx;
  144.                                 y = yy;
  145.                         }
  146.                         break;

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

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

  153.         if (++g_tTP.Write  >= TOUCH_FIFO_SIZE)
  154.         {
  155.                 g_tTP.Write = 0;
  156.         }
  157.         
  158.         /* 调试语句,打印adc和坐标 */
  159.         touch_printf("%d - (%d, %d) adcX=%d,adcY=%d\r\n", _ucEvent, x, y, g_tTP.usAdcNowX, g_tTP.usAdcNowY);
  160. #endif
  161. }
复制代码



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

  1. #include   "gx_api.h"
  2. void TOUCH_PutKey(uint8_t _ucEvent, uint16_t _usX, uint16_t _usY)
  3. {
  4. #if 1
  5.         uint16_t xx, yy;
  6.         GX_EVENT event;

  7.         if (g_tTP.Enable == 1)        /* 电阻屏。 形参是ADC值 */
  8.         {
  9.                 xx = TOUCH_TransX(_usX, _usY);
  10.                 yy = TOUCH_TransY(_usX, _usY);
  11.         }
  12.         else        /* GT811,FTX06,GT911 电容触摸走此分之 */
  13.         {
  14.                 /* 无需转换, 直接是坐标值 */
  15.                 xx = _usX;
  16.                 yy = _usY;               
  17.         }
  18.         
  19.         /* 按下, 移动和松手事件 */
  20.         switch (_ucEvent)
  21.         {
  22.                 case TOUCH_DOWN:
  23.                         event.gx_event_type = GX_EVENT_PEN_DOWN;
  24.                         event.gx_event_payload.gx_event_pointdata.gx_point_x = xx;
  25.                         event.gx_event_payload.gx_event_pointdata.gx_point_y = yy;
  26.                         event.gx_event_sender = 0;
  27.                         event.gx_event_target = 0;
  28.                         event.gx_event_display_handle = 0xC0000000;
  29.                         gx_system_event_send(&event);
  30.                         break;

  31.                 case TOUCH_MOVE:
  32.                         event.gx_event_type = GX_EVENT_PEN_DRAG;
  33.                         event.gx_event_payload.gx_event_pointdata.gx_point_x = xx;
  34.                         event.gx_event_payload.gx_event_pointdata.gx_point_y = yy;
  35.                         event.gx_event_sender = 0;
  36.                         event.gx_event_target = 0;
  37.                         event.gx_event_display_handle = 0xC0000000;
  38.                         gx_system_event_fold(&event);
  39.                         break;

  40.                 case TOUCH_RELEASE:
  41.                         event.gx_event_type = GX_EVENT_PEN_UP;
  42.                         event.gx_event_payload.gx_event_pointdata.gx_point_x = xx;
  43.                         event.gx_event_payload.gx_event_pointdata.gx_point_y = yy;
  44.                         event.gx_event_sender = 0;
  45.                         event.gx_event_target = 0;
  46.                         event.gx_event_display_handle = 0xC0000000;
  47.                         gx_system_event_send(&event);
  48.                         break;

  49.                 default:
  50.                         break;
  51.         }
  52. #else
  53.         uint16_t xx, yy;
  54.         uint16_t x = 0, y = 0;

  55.         g_tTP.Event[g_tTP.Write] = _ucEvent;

  56.         if (g_tTP.Enable == 1)        /* 电阻屏。 形参是ADC值 */
  57.         {
  58.                 xx = TOUCH_TransX(_usX, _usY);
  59.                 yy = TOUCH_TransY(_usX, _usY);
  60.         }
  61.         else        /* GT811,FTX06,GT911 电容触摸走此分之 */
  62.         {
  63.                 /* 无需转换, 直接是坐标值 */
  64.                 xx = _usX;
  65.                 yy = _usY;               
  66.         }
  67.         
  68.         /* 横屏和竖屏方向识别 */
  69.         switch (g_tTPParam.TouchDirection)
  70.         {
  71.                 case 0:        /* 校准触摸时,屏幕方向为0 */
  72.                         if (g_LcdDirection == 0)                /* 横屏 */
  73.                         {
  74.                                 x = xx;
  75.                                 y = yy;
  76.                         }
  77.                         else if (g_LcdDirection == 1)        /* 横屏180°*/
  78.                         {
  79.                                 x = g_LcdWidth - xx - 1;
  80.                                 y = g_LcdHeight - yy - 1;
  81.                         }
  82.                         else if (g_LcdDirection == 2)        /* 竖屏 */
  83.                         {
  84.                                 y = xx;
  85.                                 x = g_LcdWidth - yy - 1;
  86.                         }
  87.                         else if (g_LcdDirection == 3)        /* 竖屏180° */
  88.                         {
  89.                                 y = g_LcdHeight - xx - 1;
  90.                                 x = yy;
  91.                         }
  92.                         break;

  93.                 case 1:        /* 校准触摸时,屏幕方向为1 */
  94.                         if (g_LcdDirection == 0)                /* 横屏 */
  95.                         {
  96.                                 x = g_LcdWidth - xx - 1;
  97.                                 y = g_LcdHeight - yy - 1;
  98.                         }
  99.                         else if (g_LcdDirection == 1)        /* 横屏180°*/
  100.                         {
  101.                                 x = xx;
  102.                                 y = yy;
  103.                         }
  104.                         else if (g_LcdDirection == 2)        /* 竖屏 */
  105.                         {
  106.                                 y = g_LcdHeight - xx - 1;
  107.                                 x = yy;
  108.                         }
  109.                         else if (g_LcdDirection == 3)        /* 竖屏180° */
  110.                         {
  111.                                 y = xx;
  112.                                 x = g_LcdWidth - yy - 1;
  113.                         }
  114.                         break;

  115.                 case 2:        /* 校准触摸时,屏幕方向为2 */
  116.                         if (g_LcdDirection == 0)                /* 横屏 */
  117.                         {
  118.                                 y = xx;
  119.                                 x = g_LcdWidth - yy - 1;
  120.                         }
  121.                         else if (g_LcdDirection == 1)        /* 横屏180°*/
  122.                         {
  123.                                 y = g_LcdHeight - xx - 1;
  124.                                 x = yy;
  125.                         }
  126.                         else if (g_LcdDirection == 2)        /* 竖屏 */
  127.                         {
  128.                                 x = xx;
  129.                                 y = yy;
  130.                         }
  131.                         else if (g_LcdDirection == 3)        /* 竖屏180° */
  132.                         {
  133.                                 x = g_LcdWidth - xx - 1;
  134.                                 y = g_LcdHeight - yy - 1;
  135.                         }
  136.                         break;

  137.                 case 3:        /* 校准触摸时,屏幕方向为3 */
  138.                         if (g_LcdDirection == 0)                /* 横屏 */
  139.                         {
  140.                                 y = xx;
  141.                                 x = g_LcdWidth - yy - 1;
  142.                         }
  143.                         else if (g_LcdDirection == 1)        /* 横屏180°*/
  144.                         {
  145.                                 y = g_LcdHeight - xx - 1;
  146.                                 x = yy;
  147.                         }
  148.                         else if (g_LcdDirection == 2)        /* 竖屏 */
  149.                         {
  150.                                 x = g_LcdWidth - xx - 1;
  151.                                 y = g_LcdHeight - yy - 1;
  152.                         }
  153.                         else if (g_LcdDirection == 3)        /* 竖屏180° */
  154.                         {
  155.                                 x = xx;
  156.                                 y = yy;
  157.                         }
  158.                         break;

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

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

  165.         if (++g_tTP.Write  >= TOUCH_FIFO_SIZE)
  166.         {
  167.                 g_tTP.Write = 0;
  168.         }
  169.         
  170.         /* 调试语句,打印adc和坐标 */
  171.         touch_printf("%d - (%d, %d) adcX=%d,adcY=%d\r\n", _ucEvent, x, y, g_tTP.usAdcNowX, g_tTP.usAdcNowY);
  172. #endif
  173. }
复制代码




回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107028
QQ
 楼主| 发表于 2021-2-9 08:19:10 | 显示全部楼层
后期GUI类工程维护就会方便很多。
回复

使用道具 举报

23

主题

1406

回帖

1475

积分

至尊会员

积分
1475
发表于 2021-2-9 09:20:53 | 显示全部楼层
放假了,改休息了下了
代码不规范,亲人两行泪!
回复

使用道具 举报

1

主题

10

回帖

13

积分

新手上路

积分
13
发表于 2021-2-9 23:42:13 | 显示全部楼层
精益求精的精神
回复

使用道具 举报

1

主题

10

回帖

13

积分

新手上路

积分
13
发表于 2021-2-9 23:43:02 | 显示全部楼层
精益求精的敬业精神
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-14 15:20 , Processed in 0.160355 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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