• 方案介紹
  • 推薦器件
  • 相關推薦
申請入駐 產業(yè)圖譜

基于RT1062的lvgl綜合界面-界面配置、驅動代碼

2024/05/17
2459
加入交流群
掃碼加入
獲取工程師必備禮包
參與熱點資訊討論

最近確實有點懶,摸了太久的魚,在日天兄的再三催促下,勉勉強強趕上了這個主題月的尾巴。

演示視頻:https://player.youku.com/embed/XNTg3Mjc4MjQ0MA==

這次用的板子是騰訊IOT的一塊卡,主控是RT1062,帶一塊800*480的RGB屏。

配界面的時候,使用了GUI-Guider,不得不說,雀食好用,簡單界面拖一拖就能完成,字庫圖庫也是一鍵完成,比官網網頁那個好用多了,就算不用它設計界面,拿來搞個中文小字庫,也是超級方便。

直接拷貝出來的代碼,編譯會報錯,要把guider_fonts.h文件里面 lv_font.h 修改成 lvgl/lvgl.h。

板子的官方沒有把觸摸屏的驅動放出來,這里就把我寫的放下面,有需要的可以看看。

#include "fsl_common.h"
#include "fsl_lpi2c.h"
#include "fsl_gt911_rt.h"

#include "pin_mux.h"
#include "fsl_gpio.h"
#include "fsl_debug_console.h"
#include "FreeRTOS.h"
#include "task.h"

typedef struct _ft5406_rt_touch_point
{
    uint8_t XH;
    uint8_t XL;
    uint8_t YH;
    uint8_t YL;
    uint8_t RESERVED[2];
} ft5406_rt_touch_point_t;

typedef struct _ft5406_rt_touch_data
{
    uint8_t GEST_ID;
    uint8_t TD_STATUS;
    ft5406_rt_touch_point_t TOUCH[FT5406_RT_MAX_TOUCHES];
} ft5406_rt_touch_data_t;

#define TOUCH_POINT_GET_EVENT(T) ((touch_event_t)((T).XH >> 6))
#define TOUCH_POINT_GET_ID(T)    ((T).YH >> 4)
#define TOUCH_POINT_GET_X(T)     ((((T).XH & 0x0f) << 8) | (T).XL)
#define TOUCH_POINT_GET_Y(T)     ((((T).YH & 0x0f) << 8) | (T).YL)

status_t FT5406_RT_Init(ft5406_rt_handle_t *handle, LPI2C_Type *base)
{
    lpi2c_master_transfer_t *xfer = &(handle->xfer);
    status_t status;
    uint8_t mode;

    assert(handle);
    assert(base);

    if (!handle || !base)
    {
        return kStatus_InvalidArgument;
    }

    GPIO_PinWrite(GPIO5, 0U, 1); //復位
    vTaskDelay(10);
    
    GPIO_PinWrite(GPIO5, 0U, 0); //復位
    vTaskDelay(100);
    GPIO_PinWrite(GPIO5, 0U, 0); //INT
    vTaskDelay(100);
    GPIO_PinWrite(GPIO5, 0U, 1); //復位
    vTaskDelay(200);
    
  gpio_pin_config_t PMIC_ON_REQ_config = {
      .direction = kGPIO_DigitalInput,
      .outputLogic = 0U,
      .interruptMode = kGPIO_NoIntmode
  };
  GPIO_PinInit(GPIO5, 1U, &PMIC_ON_REQ_config);
    
    handle->base = base;

    /* clear transfer structure and buffer */
    memset(xfer, 0, sizeof(*xfer));
    memset(handle->touch_buf, 0, FT5406_RT_TOUCH_DATA_LEN);

    /* set device mode to normal operation */
    uint8_t id[4] = {0};
    
    xfer->slaveAddress   = FT5406_RT_I2C_ADDRESS;
    xfer->direction      = kLPI2C_Read;
    xfer->subaddress     = 0X8140;
    xfer->subaddressSize = 2;
    xfer->data           = id;
    xfer->dataSize       = 4;
    xfer->flags          = kLPI2C_TransferDefaultFlag;
    status = LPI2C_MasterTransferBlocking(handle->base, &handle->xfer);
    PRINTF("%c%c%c%crn",id[0],id[1],id[2],id[3]);

    return status;
}

status_t FT5406_RT_Denit(ft5406_rt_handle_t *handle)
{
    assert(handle);

    if (!handle)
    {
        return kStatus_InvalidArgument;
    }

    handle->base = NULL;
    return kStatus_Success;
}

status_t FT5406_RT_GetSingleTouch(ft5406_rt_handle_t *handle, touch_event_t *touch_event, int *touch_x, int *touch_y)
{
    status_t status;
    touch_event_t touch_event_local;
    uint8_t Clearbuf = 0; 
    *touch_event = kTouch_Reserved;
    if(GPIO_PinRead(GPIO5, 0U) == 0)
        return kStatus_Success;
        
    handle->xfer.slaveAddress   = FT5406_RT_I2C_ADDRESS;
    handle->xfer.direction      = kLPI2C_Read;
    handle->xfer.subaddress     = 0x814E;
    handle->xfer.subaddressSize = 2;
    handle->xfer.data           = handle->touch_buf;
    handle->xfer.dataSize       = FT5406_RT_TOUCH_DATA_LEN;
    handle->xfer.flags          = kLPI2C_TransferDefaultFlag;

    status = LPI2C_MasterTransferBlocking(handle->base, &handle->xfer);

    if (status == kStatus_Success)
    {
        if(handle->touch_buf[0] != 0x00)
        {
            handle->xfer.slaveAddress   = FT5406_RT_I2C_ADDRESS;
            handle->xfer.direction      = kLPI2C_Write;
            handle->xfer.subaddress     = 0x814E;
            handle->xfer.subaddressSize = 2;
            handle->xfer.data           = &Clearbuf;
            handle->xfer.dataSize       = 1;
            handle->xfer.flags          = kLPI2C_TransferDefaultFlag;
            status = LPI2C_MasterTransferBlocking(handle->base, &handle->xfer);
            
            if((handle->touch_buf[0] & 0x0f) != 0)
            {
                *touch_event = kTouch_Down;
                *touch_y = ((uint16_t)handle->touch_buf[3]<<8) + handle->touch_buf[2];
                *touch_x = ((uint16_t)handle->touch_buf[5]<<8) + handle->touch_buf[4];
            }
            //PRINTF("%x %x %xrn",handle->touch_buf[0],handle->touch_buf[1],handle->touch_buf[2]);
        }
        
    }

    return status;
}

 

推薦器件

更多器件
器件型號 數(shù)量 器件廠商 器件描述 數(shù)據(jù)手冊 ECAD模型 風險等級 參考價格 更多信息
LTST-C191KGKT 1 Lite-On Semiconductor Corporation Single Color LED, Green, Water Clear, 1.1mm, GREEN, PLASTIC, THIN, 2 PIN

ECAD模型

下載ECAD模型
$0.02 查看
S29AL016J70TFI020 1 Spansion Flash, 1MX16, 70ns, PDSO48, LEAD FREE, MO-142DDD, TSOP-48
$5.08 查看
MO-9200AE-D3E-HE87M3515420 1 Microchip Technology Inc LVDS Output Clock Oscillator, 87.351542MHz Nom
暫無數(shù)據(jù) 查看

相關推薦