3554 views|2 replies

111

Posts

0

Resources
The OP
 

【GD32450I-EVAL】Transplant touch to LittleVGL [Copy link]

The previous post tested the touch driver: SPI transceiver and touch chip XPT2046 driver and pen interrupt

The next step is to port to LittleVGL.

Last time when I ported LittleVGL's display, I left behind this:

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

There is no operation in this function. At this time, you just need to add the touch position and click it.

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;
}

Due to RAM capacity, only 270*180 width display can be supported, so the actual touch point and the position in LittleVGL must be converted, so the program adds:

        touch_x -= 20;
        touch_y -= 30;

When X is displayed, it is offset to the left by 20 pixels, and Y is offset by 30 pixels. For details, see the transplantation of the display part .

The ReadTPXYOver function performs multiple reads and takes the median after bubble sorting:


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)

Effect:

This post is from GD32 MCU

Latest reply

This is good, awesome!   Details Published on 2020-10-11 21:41
 

1w

Posts

204

Resources
2
 

GigaDevice GD32450I-EVAL

Summary post: https://bbs.eeworld.com.cn/thread-1140981-1-1.html

This post is from GD32 MCU
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
 
Personal signature

玩板看这里:

https://bbs.eeworld.com.cn/elecplay.html

EEWorld测评频道众多好板等你来玩,还可以来频道许愿树许愿说说你想要玩的板子,我们都在努力为大家实现!

 
 

7462

Posts

2

Resources
3
 

This is good, awesome!

This post is from GD32 MCU
 
Personal signature

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

 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list