最近確實(shí)有點(diǎn)懶,摸了太久的魚(yú),在日天兄的再三催促下,勉勉強(qiáng)強(qiáng)趕上了這個(gè)主題月的尾巴。
演示視頻:https://player.youku.com/embed/XNTg3Mjc4MjQ0MA==
這次用的板子是騰訊IOT的一塊卡,主控是RT1062,帶一塊800*480的RGB屏。
配界面的時(shí)候,使用了GUI-Guider,不得不說(shuō),雀食好用,簡(jiǎn)單界面拖一拖就能完成,字庫(kù)圖庫(kù)也是一鍵完成,比官網(wǎng)網(wǎng)頁(yè)那個(gè)好用多了,就算不用它設(shè)計(jì)界面,拿來(lái)搞個(gè)中文小字庫(kù),也是超級(jí)方便。
直接拷貝出來(lái)的代碼,編譯會(huì)報(bào)錯(cuò),要把guider_fonts.h文件里面 lv_font.h 修改成 lvgl/lvgl.h。
板子的官方?jīng)]有把觸摸屏的驅(qū)動(dòng)放出來(lái),這里就把我寫的放下面,有需要的可以看看。
#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); //復(fù)位
vTaskDelay(10);
GPIO_PinWrite(GPIO5, 0U, 0); //復(fù)位
vTaskDelay(100);
GPIO_PinWrite(GPIO5, 0U, 0); //INT
vTaskDelay(100);
GPIO_PinWrite(GPIO5, 0U, 1); //復(fù)位
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;
}