HW_Lib/demo/tft/test.c

168 lines
4.5 KiB
C
Raw Normal View History

2024-08-29 08:46:54 +00:00
#include "stdio.h"
2024-09-21 04:48:44 +00:00
#include "tft.h"
2024-08-29 08:46:54 +00:00
#include <windows.h>
#include "t_tft.h"
2024-09-21 04:48:44 +00:00
#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;
2024-09-21 12:43:31 +00:00
static SIM_Display_t tft_display;
2024-09-21 04:48:44 +00:00
//屏幕指令
#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++;
2024-09-21 12:43:31 +00:00
SIM_Color_DrawPiexl(&tft_display, (SIM_Color_t) RGB565_to_RGB888(color_u.u16, true), xs, ys);
2024-09-21 04:48:44 +00:00
// 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++;
2024-09-21 12:43:31 +00:00
color[i] = RGB565_to_RGB888(color_u.u16, true) | 0xFF000000;
2024-09-21 04:48:44 +00:00
}
2024-09-21 12:43:31 +00:00
SIM_Color_ImgFromBuffer(&tft_display, color, xs, ys, len / 2 - 1, 1);
// SIM_Color_DrawHLineBuffer(color, xs, ys, len / 2);
2024-09-21 04:48:44 +00:00
// LOGT("Img","x:%d,y:%d,len:%d",xs,ys,len);
}
if (result > 0) {
result = -1;
} else {
result = 0;
}
return result;
}
2024-08-29 08:46:54 +00:00
2024-09-21 08:07:31 +00:00
void Test_tft(void *) {
2024-09-21 04:48:44 +00:00
2024-09-21 05:18:06 +00:00
//设备信息预填充
demo_tft.width = 480;//实际如有支持不用填(如ST7735/7796)
demo_tft.height = 320;//实际如有支持不用填(如ST7735/7796)
demo_tft.wgramcmd = WGRAM_CMD;//实际如有支持不用填(如ST7735/7796)
demo_tft.setycmd = SETYCMD;//实际如有支持不用填(如ST7735/7796)
demo_tft.setxcmd = SETXCMD;//实际如有支持不用填(如ST7735/7796)
demo_tft.writeReg = tft_writereg;//必须实现
demo_tft.sendData = tft_senddata;//必须实现
demo_tft.dir = HORIZONTAL;//必填
//模拟初始化
2024-09-21 12:43:31 +00:00
SIM_Display_Init("TFT", demo_tft.width, demo_tft.height, 0xFFFF, 0x0000, 2, &tft_display);
2024-09-21 04:48:44 +00:00
2024-09-21 05:18:06 +00:00
TFT_Init(&demo_tft);//初始化
2024-09-21 04:48:44 +00:00
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);
2024-09-21 05:18:06 +00:00
for (float p = 0; p < 1; p += 0.001) {
2024-09-21 04:48:44 +00:00
TFT_ShowBar(&demo_tft, 0, 100, demo_tft.width, 24, p);
2024-09-21 05:18:06 +00:00
TFT_ShowBar(&demo_tft, 0, 125, demo_tft.width, 16, p);
TFT_ShowBar(&demo_tft, 0, 142, demo_tft.width, 12, p);
TFT_ShowBar(&demo_tft, 0, 155, demo_tft.width, 3, p);
2024-09-21 04:48:44 +00:00
}
while (1) {
2024-08-29 08:46:54 +00:00
Sleep(5);
}
}