3648|2

111

帖子

0

TA的资源

一粒金砂(中级)

楼主
 

【GD32450I-EVAL】移植触摸到LittleVGL [复制链接]

上一篇帖子进行了触摸驱动测试:SPI收发与触摸芯片XPT2046驱动及笔中断

接下来就是移植到 LittleVGL 。

上次移植完 LittleVGL 的显示时留下了一个:

static bool DEMO_ReadTouch(lv_indev_drv_t * indev_drv, lv_indev_data_t *data)

这个函数里面没有进行什么操作,这时候只需要添加触摸位置点进去即可。

static bool DEMO_ReadTouch(lv_indev_drv_t * indev_drv, lv_indev_data_t *data)
{
    static int touch_x = 0;
    static int touch_y = 0;
    uint16_t t_xx = 0, t_yy = 0;

    data->state = LV_INDEV_STATE_REL;


    if(gpio_input_bit_get(GPIOI, GPIO_PIN_3)==RESET)
    {
        ReadTPXYOver(&t_xx, &t_yy);
		t_yy = 4096-t_yy;
        touch_x = 480 * t_xx / 4096;
        touch_y = 272 * t_yy / 4096;
        touch_x -= 20;
        touch_y -= 30;
        if (touch_x<0 || touch_x > LCD_WIDTH){
			touch_x =0;
			touch_y =0;
		}
        else if (touch_y<0 || touch_y > LCD_HEIGHT){
			touch_x =0;
			touch_y =0;
		}
		else
			data->state = LV_INDEV_STATE_PR;
    }

    /*Set the last pressed coordinates*/
    data->point.x = touch_x;
    data->point.y = touch_y;

    /*Return `false` because we are not buffering and no more data to read*/
    return false;
}

因为RAM容量的原因,只能支持270*180宽度显示,因此必须换算实际触摸点与 LittleVGL 内的位置,因此程序里加入了:

        touch_x -= 20;
        touch_y -= 30;

其中X显示的时候向左偏移了20像素,Y偏移了30像素,具体可以看显示部分的移植

 

ReadTPXYOver 函数是进行多次读取,经过冒泡排序后取中位数:


void ReadTPXY(uint16_t *t_x, uint16_t *t_y)
{
    char t_char[30] = "";
    gpio_bit_reset(GPIOF, GPIO_PIN_6);
    //X
    while (RESET == spi_i2s_flag_get(SPI3, SPI_FLAG_TBE));
    spi_i2s_data_transmit(SPI4, 0xD0);
    while (RESET == spi_i2s_flag_get(SPI4, SPI_FLAG_RBNE));
    spi_i2s_data_receive(SPI4);

	// delay_us(100);
    //read 1
    while (RESET == spi_i2s_flag_get(SPI3, SPI_FLAG_TBE));
    spi_i2s_data_transmit(SPI4, 0x00);
    while (RESET == spi_i2s_flag_get(SPI4, SPI_FLAG_RBNE));
    *t_x = spi_i2s_data_receive(SPI4);
    *t_x = (*t_x& 0x7F)<<8 ;
    //read2
    while (RESET == spi_i2s_flag_get(SPI3, SPI_FLAG_TBE));
    spi_i2s_data_transmit(SPI4, 0x90);
    while (RESET == spi_i2s_flag_get(SPI4, SPI_FLAG_RBNE));
    *t_x = *t_x|spi_i2s_data_receive(SPI4);

    // sprintf(t_char, "x:%x\t", *t_x);
    // PRINTF_UART0(t_char);

    *t_x = *t_x>>3;

	// delay_us(100);
    
    while (RESET == spi_i2s_flag_get(SPI3, SPI_FLAG_TBE));
    spi_i2s_data_transmit(SPI4, 0x00);
    while (RESET == spi_i2s_flag_get(SPI4, SPI_FLAG_RBNE));
    *t_y = spi_i2s_data_receive(SPI4);
    *t_y = (*t_y& 0x7F) <<8;

    while (RESET == spi_i2s_flag_get(SPI3, SPI_FLAG_TBE));
    spi_i2s_data_transmit(SPI4, 0x00);
    while (RESET == spi_i2s_flag_get(SPI4, SPI_FLAG_RBNE));
    *t_y = *t_y|spi_i2s_data_receive(SPI4);

    // sprintf(t_char, "y:%x\t", *t_y);
    // PRINTF_UART0(t_char);

    *t_y = *t_y>>3;
}

void ReadTPXYOver(uint16_t *t_x, uint16_t *t_y)

 

效果:

此帖出自GD32 MCU论坛

最新回复

这个好,给力!   详情 回复 发表于 2020-10-11 21:41
点赞 关注
 

回复
举报

1万

帖子

203

TA的资源

管理员

沙发
 

兆易GD32450I-EVAL

汇总贴:https://bbs.eeworld.com.cn/thread-1140981-1-1.html

此帖出自GD32 MCU论坛
加EE小助手好友,
入技术交流群
EE服务号
精彩活动e手掌握
EE订阅号
热门资讯e网打尽
聚焦汽车电子软硬件开发
认真关注技术本身
 
个人签名玩板看这里:
https://bbs.eeworld.com.cn/elecplay.html
EEWorld测评频道众多好板等你来玩,还可以来频道许愿树许愿说说你想要玩的板子,我们都在努力为大家实现!
 
 

回复

7671

帖子

2

TA的资源

五彩晶圆(高级)

板凳
 

这个好,给力!

此帖出自GD32 MCU论坛
 
个人签名

默认摸鱼,再摸鱼。2022、9、28

 
 

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

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/6 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表