ART-Pi在rt-thread studio中使用touchgfx与触摸屏GT1151的适配

首先感谢大佬手把手操作,我们做下来,不出意外的话编译没有错误,我们也需要根据大佬的文章进行操作,但是有一个问题就是ART-Pi中Touchgfx默认的是GT9147触摸屏,如果使用其它的触摸屏就需要在在这里插入图片描述
中适配,由于时间原因长话短说,完成大佬的操作后,可以看到显示屏上显示demo但是并不能进行触摸操作,我们需要在在这里插入图片描述
这个文件中适配修改,比方说我使用的GT1151,先把GT1151的示例在工程中注释掉,然后根据GT1151的示例进行修改。
直接上代码:使用其它的触摸屏应该也是一样的方法。

/**
  ******************************************************************************
  * File Name          : STM32TouchController.cpp
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under Ultimate Liberty license
  * SLA0044, the "License"; You may not use this file except in compliance with
  * the License. You may obtain a copy of the License at:
  *                             www.st.com/SLA0044
  *
  ******************************************************************************
  */

/* USER CODE BEGIN STM32TouchController */

#include <STM32TouchController.hpp>
#include <rtthread.h>

#include "gt1151.h"
#include <touch.h>
#include <rtdevice.h>

#define DBG_TAG "gt1151_sample"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>



#ifdef PKG_USING_GT1151


int gt1151_init(void)
{
    rt_thread_mdelay(1000);

       rt_device_t touch_dev = rt_device_find("gt1151");
       RT_ASSERT(touch_dev != RT_NULL);
       rt_device_open(touch_dev, RT_DEVICE_FLAG_RDONLY);

        /* 璇� ID */
        rt_uint8_t read_id[4];
        rt_device_control(touch_dev, RT_TOUCH_CTRL_GET_ID, read_id);
        LOG_I("id = %d %d %d %d \n", read_id[0] - '0', read_id[1] - '0', read_id[2] - '0', read_id[3] - '0');

        /* 鑾峰彇璁惧淇℃伅 */
        struct rt_touch_info info;
        rt_device_control(touch_dev, RT_TOUCH_CTRL_GET_INFO, &info);
        LOG_I("type       :%d", info.type);                       /* 绫诲瀷锛氱數瀹瑰瀷/鐢甸樆鍨�*/
        LOG_I("vendor     :%d", info.vendor);                     /* 鍘傚晢 */
        LOG_I("point_num  :%d", info.point_num);                  /* 鏀寔鐨勮Е鐐逛釜鏁� */
        LOG_I("range_x    :%d", info.range_x);                    /* X 杞村垎杈ㄧ巼 */
        LOG_I("range_y    :%d\n", info.range_y);                  /* Y 杞村垎杈ㄧ巼*/

        /* 璁剧疆宸ヤ綔妯″紡涓轰腑鏂ā寮� */
        rt_device_control(touch_dev, RT_TOUCH_CTRL_SET_MODE, (void *)RT_DEVICE_FLAG_INT_RX);
        /* 璁剧疆宸ヤ綔妯″紡涓鸿疆璇㈡ā寮� */
        rt_device_control(touch_dev, RT_TOUCH_CTRL_SET_MODE, (void *)RT_DEVICE_FLAG_RDONLY);

       /* 浜ゆ崲 X銆乊 杞村潗鏍� */
   //    rt_device_control(touch_dev, RT_TOUCH_CTRL_SET_X_TO_Y, RT_NULL);

       struct rt_touch_data data;
       rt_memset(&data, 0, sizeof(data));

    return 0;
}
#endif

void STM32TouchController::init()
{
    /**
     * Initialize touch controller and driver
     *
     */
#ifdef PKG_USING_GT1151
    gt1151_init();
#endif
}

bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y)
{
    /**
     * By default sampleTouch returns false,
     * return true if a touch has been detected, otherwise false.
     *
     * Coordinates are passed to the caller by reference by x and y.
     *
     * This function is called by the TouchGFX framework.
     * By default sampleTouch is called every tick, this can be adjusted by HAL::setTouchSampleRate(int8_t);
     *
     */
    rt_thread_mdelay(20);


    #ifdef PKG_USING_GT1151
    struct rt_touch_data data;
    rt_device_t touch_dev = rt_device_find("gt1151");
    rt_device_read(touch_dev, 0, &data, 1);
    if ((data.x_coordinate > 0&&data.x_coordinate<=800) || (data.y_coordinate > 0&&data.y_coordinate <=480))
    {
        if (data.event == RT_TOUCH_EVENT_DOWN || data.event == RT_TOUCH_EVENT_MOVE)
        {
            x =data.x_coordinate;
            y =data.y_coordinate;
            LOG_I("\t x: %d, y: %d", x, y);
            rt_memset(&data, 0, sizeof(data));

        }
        return true;
    }
    else
    #endif
    {
        return false;
    }
}

/* USER CODE END STM32TouchController */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值