UP tft SIM
This commit is contained in:
@@ -1,7 +1,3 @@
|
||||
//
|
||||
// Created by lydxh on 2024/5/10.
|
||||
//
|
||||
|
||||
#ifndef HW_LIB_T_TFT_H
|
||||
#define HW_LIB_T_TFT_H
|
||||
|
||||
|
170
demo/tft/test.c
170
demo/tft/test.c
@@ -1,28 +1,162 @@
|
||||
#include "stdio.h"
|
||||
#include "lv_port_disp.h"
|
||||
#include "lv_port_indev.h"
|
||||
#include "lvgl.h"
|
||||
#include "lv_demo_widgets.h"
|
||||
#include "tft.h"
|
||||
#include <windows.h>
|
||||
#include "t_tft.h"
|
||||
#include "sim_display.h"
|
||||
#include "tool.h"
|
||||
#include "log.h"
|
||||
|
||||
TFT_T demo_tft;
|
||||
uint16_t xs = 0, ys = 0, xe = 0, ye = 0;
|
||||
bool fill;
|
||||
|
||||
//屏幕指令
|
||||
#define WGRAM_CMD 0x5C
|
||||
#define SETXCMD 0x2A
|
||||
#define SETYCMD 0x2B
|
||||
|
||||
//硬件实现区
|
||||
uint8_t tft_writereg(uint8_t reg, uint8_t *pdata, size_t ldata) {
|
||||
uint8_t result;
|
||||
fill = false;
|
||||
Data16_t data16;
|
||||
if (reg == SETXCMD) {
|
||||
if (ldata >= 4) {
|
||||
data16.u8[1] = *pdata;
|
||||
pdata++;
|
||||
data16.u8[0] = *pdata;
|
||||
pdata++;
|
||||
xs = data16.u16;
|
||||
data16.u8[1] = *pdata;
|
||||
pdata++;
|
||||
data16.u8[0] = *pdata;
|
||||
xe = data16.u16;
|
||||
} else if (ldata >= 2) {
|
||||
data16.u8[1] = *pdata;
|
||||
pdata++;
|
||||
data16.u8[0] = *pdata;
|
||||
xs = data16.u16;
|
||||
}
|
||||
// LOGT("SETX","X_S:%d,X_E:%d,len:%d",xs,xe,ldata);
|
||||
} else if (reg == SETYCMD) {
|
||||
if (ldata >= 4) {
|
||||
data16.u8[1] = *pdata;
|
||||
pdata++;
|
||||
data16.u8[0] = *pdata;
|
||||
pdata++;
|
||||
ys = data16.u16;
|
||||
|
||||
|
||||
data16.u8[1] = *pdata;
|
||||
pdata++;
|
||||
data16.u8[0] = *pdata;
|
||||
ye = data16.u16;
|
||||
} else if (ldata >= 2) {
|
||||
data16.u8[1] = *pdata;
|
||||
pdata++;
|
||||
data16.u8[0] = *pdata;
|
||||
ys = data16.u16;
|
||||
}
|
||||
// LOGT("SETY","Y_S:%d,Y_E:%d,len:%d",ys,ye,ldata);
|
||||
} else if (reg == WGRAM_CMD) {
|
||||
fill = true;
|
||||
}
|
||||
if (result > 0) {
|
||||
result = -1;
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//硬件实现
|
||||
uint8_t tft_senddata(uint8_t *data, size_t len) {
|
||||
uint8_t result;
|
||||
uint32_t color[len / 2];
|
||||
TFT_Color_t color_u;
|
||||
if (!fill || len == 0)return -1;
|
||||
if (len == 2) {
|
||||
color_u.u8[1] = *data;
|
||||
color_u.u8[0] = *data++;
|
||||
SIM_Color_DrawPiexl(RGB565_to_RGB888(color_u.u16, true), xs, ys);
|
||||
// LOGT("Piexl","color:%x,x:%d,y:%d,len:%d",color_u.u16,xs,ys,len);
|
||||
// SIM_Color_ImgFromBuffer(color,xs, ys, uint16_t width, 1)
|
||||
} else {
|
||||
for (int i = 0; i < len / 2; i++) {
|
||||
color_u.u8[1] = *data;
|
||||
data++;
|
||||
color_u.u8[0] = *data;
|
||||
data++;
|
||||
color[i] = RGB565_to_RGB888(color_u.u16, true);
|
||||
}
|
||||
// SIM_Color_ImgFromBuffer(color, xs, ys, len / 2 - 1, 1);
|
||||
SIM_Color_DrawHLineBuffer(color, xs, ys, len / 2);
|
||||
// LOGT("Img","x:%d,y:%d,len:%d",xs,ys,len);
|
||||
}
|
||||
|
||||
if (result > 0) {
|
||||
result = -1;
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Test_tft() {
|
||||
lv_init();
|
||||
lv_port_disp_init();
|
||||
lv_port_indev_init();
|
||||
|
||||
// lv_obj_t * bar1 = lv_bar_create(lv_scr_act());
|
||||
// lv_obj_set_size(bar1, 200, 20);
|
||||
// lv_obj_center(bar1);
|
||||
// lv_bar_set_value(bar1, 70, LV_ANIM_OFF);
|
||||
// lv_demo_widgets();
|
||||
// printf("\nTEST Widgets\n");
|
||||
demo_tft.width = 480;
|
||||
demo_tft.height = 320;
|
||||
demo_tft.wgramcmd = WGRAM_CMD;
|
||||
demo_tft.setycmd = SETYCMD;
|
||||
demo_tft.setxcmd = SETXCMD;
|
||||
demo_tft.writeReg = tft_writereg;
|
||||
demo_tft.sendData = tft_senddata;
|
||||
demo_tft.dir = HORIZONTAL;
|
||||
SIM_Display_INIT(demo_tft.width, demo_tft.height, 0xFFFF, 0x0000, 2, 0);
|
||||
SIM_Display_START();
|
||||
|
||||
// SIM_Color_DrawPiexl(RGB565_to_RGB888(0xFFFFF),0,0);
|
||||
Sleep(2000);
|
||||
TFT_Init(&demo_tft);
|
||||
TFT_Color_t t;
|
||||
t.color = 0XFFFF;
|
||||
TFT_Fill(&demo_tft, 0, 0, demo_tft.width, demo_tft.height, t);
|
||||
|
||||
t.color = 0XFFFF;
|
||||
TFT_SetColor(0xFFFF, 0x0000);
|
||||
|
||||
TFT_Fill(&demo_tft, 0, 0, demo_tft.width, demo_tft.height, t);
|
||||
|
||||
|
||||
TFT_SetColor(0x7D7C, 0x0000);
|
||||
TFT_DrawRect(&demo_tft, 0, 0, 50, 50);
|
||||
|
||||
|
||||
t.color = 0X01CF;
|
||||
TFT_Fill(&demo_tft, 1, 1, 49, 49, t);
|
||||
|
||||
|
||||
TFT_SetColor(0x7D7C, 0x0000);
|
||||
TFT_ShowCHString(&demo_tft, 0, 60, "星海科技机械师", 1);
|
||||
|
||||
|
||||
TFT_DrawCircle(&demo_tft, 25, 25, 10);
|
||||
|
||||
|
||||
TFT_DrawCross(&demo_tft, 25, 25, 10);
|
||||
|
||||
|
||||
TFT_ShowString(&demo_tft, 60, 20, "JiXieShi", 16, 1);
|
||||
|
||||
|
||||
TFT_ShowString(&demo_tft, 0, 160,
|
||||
"abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>(){}[]\\/?.,;:'\"!@#$%^&*-=_+~|", 16, 1);
|
||||
for (float p = 0; p < 1; p += 0.0001) {
|
||||
TFT_ShowBar(&demo_tft, 0, 100, demo_tft.width, 24, p);
|
||||
}
|
||||
while (1) {
|
||||
|
||||
while(1) {
|
||||
/* Periodically call the lv_task handler.
|
||||
* It could be done in a timer interrupt or an OS task too.*/
|
||||
lv_timer_handler();
|
||||
lv_tick_inc(5);
|
||||
Sleep(5);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user