• 正文
  • 附件下載
  • 推薦器件
  • 相關推薦
申請入駐 產業(yè)圖譜

基于LPC55S69學習GUI-Guider軟件分享三——lvgl輸入設備模擬

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

繼上次移植了GUI-Guider生成的GUI界面后,顯示沒什么問題了。但是只有顯示,不能操作,看起來還是不完整。這次就分享如何移植輸入設備,可以點擊和移動操作。

輸入設備移植文件主要是這個。如圖,可以看到lvgl支持觸摸指針設備,鼠標,鍵盤,encoder,button。

本次是通過串口方式發(fā)送數據模擬觸摸指針設備。下面是主要修改步驟。

串口接收6個字節(jié),定義結構體變量映射6個字節(jié)。代碼如下。

主要是初始化,獲取點擊狀態(tài),獲取x,y坐標這3個函數。

extern union Indev_uart_data
{
struct
{
uint8_t flag;
uint8_t press;
uint16_t x;
uint16_t y;
}touch;
uint8_t buff[6];
}g_input;

/*------------------
* Touchpad
* -----------------*/

/*Initialize your touchpad*/
static void touchpad_init(void)
{
/*Your code comes here*/
memset(g_input.buff, 0, sizeof(g_input.buff));
}

/* Will be called by the library to read the touchpad */
static bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
static lv_coord_t last_x = 0;
static lv_coord_t last_y = 0;

/*Save the pressed coordinates and the state*/
if(touchpad_is_pressed()) {
touchpad_get_xy(&last_x, &last_y);
data->state = LV_INDEV_STATE_PR;
} else {
data->state = LV_INDEV_STATE_REL;
}

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

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

/*Return true is the touchpad is pressed*/
static bool touchpad_is_pressed(void)
{
/*Your code comes here*/
if((g_input.touch.flag == 'T')&&(g_input.touch.press))
{
return true;
}
return false;
}

/*Get the x and y coordinates if the touchpad is pressed*/
static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y)
{
/*Your code comes here*/
if(g_input.touch.flag == 'T')
{
(*x) = g_input.touch.x;
(*y) = g_input.touch.y;
}
}

然后就是主函數中調用輸入設備初始化。

主循環(huán)通過串口接收數據,模擬觸摸指針設備。注意串口接收使用非阻塞方式。

下面是通過串口助手發(fā)送數據效果,可以看到指針位置。

具體參考如下代碼:lpc55s69_lcd.rar (7.49 MB, 點擊下方附件下載)

  • lpc55s69_lcd.rar
    下載

推薦器件

更多器件
器件型號 數量 器件廠商 器件描述 數據手冊 ECAD模型 風險等級 參考價格 更多信息
S25FL512SAGMFIR10 1 Spansion Flash, 512MX1, PDSO16, 0.300 INCH, LEAD FREE, PLASTIC, MO-013EAA, SOIC-16
$11.03 查看
HFBR-1414T 1 Hewlett Packard Co Transmitter, 792nm Min, 865nm Max, 175Mbps, ST Connector, Panel Mount
$16.71 查看
DSC1001DL5-027.0000 1 Microchip Technology Inc OSC MEMS 27.000MHZ CMOS SMD
$1.92 查看

相關推薦