UP
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
#include <syncstream>
|
||||
#include "sim_test.h"
|
||||
|
||||
void Test_RunTime(char *name, void (*pFunction)(void *)) {
|
||||
void Test_RunTime(char *name, int (*pFunction)(void *)) {
|
||||
clock_t start, end;
|
||||
double cpu_time_used;
|
||||
|
||||
@@ -24,11 +24,7 @@ void Test_RunTime(char *name, void (*pFunction)(void *)) {
|
||||
printf("\nTime taken by %s: %f seconds\n", name, cpu_time_used);
|
||||
}
|
||||
|
||||
void Test_Run(char *name, void (*pFunction)(void *)) {
|
||||
|
||||
|
||||
SDL_Thread *Test_Run(char *name, int (*pFunction)(void *), void *arg) {
|
||||
printf("\n------< %s TEST >------\n", name);
|
||||
_beginthread(pFunction, 0, NULL);
|
||||
|
||||
|
||||
return ThreadCreat(pFunction, name, arg);
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "sim_thread.h"
|
||||
/**
|
||||
* @brief 测试函数执行时间
|
||||
* @param name: [输入] 测试名称
|
||||
@@ -15,9 +15,9 @@ extern "C" {
|
||||
* @return void
|
||||
* @example Test("FunctionName", functionName);
|
||||
**/
|
||||
void Test_RunTime(char *name, void (*pFunction)(void *));
|
||||
void Test_RunTime(char *name, int (*pFunction)(void *));
|
||||
|
||||
void Test_Run(char *name, void (*pFunction)(void *));
|
||||
SDL_Thread *Test_Run(char *name, int (*pFunction)(void *), void *arg);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
#define GET_BIT(x, bit) ((x & (1 << bit)) >> bit)
|
||||
|
||||
uint32_t RGB565_to_RGB888(uint16_t rgb565, bool isBGR) {
|
||||
uint32_t RGB565_to_ARGB8888(uint16_t rgb565, bool isBGR) {
|
||||
uint8_t r5 = (rgb565 >> 11) & 0x1F;
|
||||
uint8_t g6 = (rgb565 >> 5) & 0x3F;
|
||||
uint8_t b5 = rgb565 & 0x1F;
|
||||
@@ -14,12 +14,11 @@ uint32_t RGB565_to_RGB888(uint16_t rgb565, bool isBGR) {
|
||||
uint8_t b8 = (b5 * 527 + 23) >> 6;
|
||||
|
||||
if (isBGR) {
|
||||
return (b8 << 16) | (g8 << 8) | r8;
|
||||
return 0xFF000000 | (b8 << 16) | (g8 << 8) | r8;
|
||||
} else {
|
||||
return (r8 << 16) | (g8 << 8) | b8;
|
||||
return 0xFF000000 | (r8 << 16) | (g8 << 8) | b8;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef USER_SDL3
|
||||
static uint32_t pixelColor, backgroundColor;
|
||||
static int scaleFactor, w, h;
|
||||
@@ -211,8 +210,8 @@ void SIM_Color_ImgFromBuffer(SIM_Display_t *display, uint32_t *buf, uint16_t x,
|
||||
void
|
||||
SIM_Color_FillFromBuffer(SIM_Display_t *display, uint32_t *buf, uint16_t xs, uint16_t ys, uint16_t xe, uint16_t ye) {
|
||||
SIM_Color_t color;
|
||||
for (int y_i = ys; y_i < ye; y_i++) {
|
||||
for (int x_i = xs; x_i < xe; x_i++) {
|
||||
for (int y_i = ys; y_i <= ye; y_i++) {
|
||||
for (int x_i = xs; x_i <= xe; x_i++) {
|
||||
color.full = *buf;
|
||||
SIM_Color_DrawPiexl(display, color, x_i, y_i);
|
||||
buf++;
|
||||
@@ -221,6 +220,9 @@ SIM_Color_FillFromBuffer(SIM_Display_t *display, uint32_t *buf, uint16_t xs, uin
|
||||
SDL_RenderPresent(display->renderer);
|
||||
}
|
||||
|
||||
void SIM_Display_Refresh(SIM_Display_t *display) {
|
||||
SDL_RenderPresent(display->renderer);
|
||||
}
|
||||
|
||||
void SIM_Display_STOP(SIM_Display_t *display) {
|
||||
SDL_DestroyRenderer(display->renderer);
|
||||
|
@@ -153,7 +153,6 @@ typedef struct {
|
||||
bool SIM_Display_Init(char *name, int width, int height, uint32_t pixcolor, uint32_t backcolor, int scale,
|
||||
SIM_Display_t *display);
|
||||
|
||||
|
||||
/**
|
||||
* @brief 在指定的坐标位置绘制一个像素点
|
||||
* @param display: [输入] 输入窗口实例
|
||||
@@ -163,6 +162,13 @@ bool SIM_Display_Init(char *name, int width, int height, uint32_t pixcolor, uint
|
||||
*/
|
||||
void SIM_Color_DrawPiexl(SIM_Display_t *display, SIM_Color_t color, uint16_t x, uint16_t y);
|
||||
|
||||
/**
|
||||
* @brief 从颜色缓冲区绘制单色图像到模拟显示器
|
||||
* @param display 模拟显示器指针
|
||||
* @param buf 颜色缓冲区指针
|
||||
* @param width 绘制区域宽度
|
||||
* @param height 绘制区域高度
|
||||
*/
|
||||
void SIM_OneColor_DrawFromBuffer(SIM_Display_t *display, uint8_t *buf, uint16_t width, uint16_t height);
|
||||
|
||||
/**
|
||||
@@ -176,8 +182,8 @@ void SIM_OneColor_DrawFromBuffer(SIM_Display_t *display, uint8_t *buf, uint16_t
|
||||
* @return void
|
||||
* @example SIM_Color_ImgFromBuffer(buf, 100, 50, 320, 240);
|
||||
**/
|
||||
void
|
||||
SIM_Color_ImgFromBuffer(SIM_Display_t *display, uint32_t *buf, uint16_t x, uint16_t y, uint16_t width, uint16_t height);
|
||||
void SIM_Color_ImgFromBuffer(SIM_Display_t *display, uint32_t *buf, uint16_t x, uint16_t y,
|
||||
uint16_t width, uint16_t height);
|
||||
|
||||
/**
|
||||
* @brief 从缓冲区中填充颜色
|
||||
@@ -193,6 +199,12 @@ SIM_Color_ImgFromBuffer(SIM_Display_t *display, uint32_t *buf, uint16_t x, uint1
|
||||
void
|
||||
SIM_Color_FillFromBuffer(SIM_Display_t *display, uint32_t *buf, uint16_t xs, uint16_t ys, uint16_t xe, uint16_t ye);
|
||||
|
||||
/**
|
||||
* @brief 刷新模拟显示器
|
||||
*
|
||||
* @param display 模拟显示器指针
|
||||
*/
|
||||
void SIM_Display_Refresh(SIM_Display_t *display);
|
||||
|
||||
/**
|
||||
* @brief 停止模拟 显示
|
||||
@@ -204,7 +216,7 @@ void SIM_Display_STOP(SIM_Display_t *display);
|
||||
#endif
|
||||
|
||||
|
||||
uint32_t RGB565_to_RGB888(uint16_t rgb565, bool isBGR);
|
||||
uint32_t RGB565_to_ARGB8888(uint16_t rgb565, bool isBGR);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@
|
||||
*====================*/
|
||||
|
||||
/*Color depth: 1 (1 byte per pixel), 8 (RGB332), 16 (RGB565), 32 (ARGB8888)*/
|
||||
#define LV_COLOR_DEPTH 16
|
||||
#define LV_COLOR_DEPTH 32
|
||||
|
||||
/*Swap the 2 bytes of RGB565 color. Useful if the display has an 8-bit interface (e.g. SPI)*/
|
||||
#define LV_COLOR_16_SWAP 0
|
||||
@@ -230,7 +230,7 @@
|
||||
*-----------*/
|
||||
|
||||
/*Enable the log module*/
|
||||
#define LV_USE_LOG 1
|
||||
#define LV_USE_LOG 0
|
||||
#if LV_USE_LOG
|
||||
|
||||
/*How important log should be added:
|
||||
|
@@ -44,7 +44,7 @@ static void disp_flush(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static SIM_Display_t lvgl_display;
|
||||
SIM_Display_t lvgl_display;
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
@@ -142,7 +142,7 @@ void lv_port_disp_init(void)
|
||||
static void disp_init(void)
|
||||
{
|
||||
/*You code here*/
|
||||
SIM_Display_Init("LVGL", MY_DISP_HOR_RES, MY_DISP_VER_RES, 0xffffff, BLACK, 1, &lvgl_display);
|
||||
SIM_Display_Init("LVGL", MY_DISP_HOR_RES, MY_DISP_VER_RES, 0xffffff, BLACK, 2, &lvgl_display);
|
||||
}
|
||||
|
||||
volatile bool disp_flush_enabled = true;
|
||||
@@ -165,7 +165,7 @@ void colortorgb24(lv_color_t* color_p, uint32_t* color, size_t len)
|
||||
{
|
||||
while (len)
|
||||
{
|
||||
*color = RGB565_to_RGB888(color_p->full, false);
|
||||
*color = RGB565_to_ARGB8888(color_p->full, false);
|
||||
color_p++;
|
||||
color++;
|
||||
len--;
|
||||
@@ -180,13 +180,13 @@ static void disp_flush(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_
|
||||
if (disp_flush_enabled)
|
||||
{
|
||||
/*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
|
||||
uint32_t* color;
|
||||
size_t l = (area->x2 - area->x1) * (area->y2 - area->y1);
|
||||
color = (uint32_t*)malloc(sizeof(uint32_t) * l);
|
||||
|
||||
colortorgb24(color_p, color, l);
|
||||
SIM_Color_FillFromBuffer(&lvgl_display, color, area->x1, area->y1, area->x2, area->y2);
|
||||
free(color);
|
||||
// uint32_t* color;
|
||||
size_t l = (area->x2 - area->x1 + 1) * (area->y2 - area->y1 + 1);
|
||||
// color = (uint32_t*)malloc(sizeof(uint32_t) * l);
|
||||
//
|
||||
// colortorgb24(color_p, color, l);
|
||||
SIM_Color_FillFromBuffer(&lvgl_display, (uint32_t *) color_p, area->x1, area->y1, area->x2, area->y2);
|
||||
// free(color);
|
||||
}
|
||||
|
||||
/*IMPORTANT!!!
|
||||
|
@@ -4,10 +4,13 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*Thread_Func_t)(void *pArg);
|
||||
#include "SDL3/SDL.h"
|
||||
|
||||
void ThreadCreat(Thread_Func_t func, unsigned int stackSize, void *pArg);
|
||||
void ThreadStop();
|
||||
typedef int (*Thread_Func_t)(void *pArg);
|
||||
|
||||
SDL_Thread *ThreadCreat(Thread_Func_t func, char *name, void *pArg);
|
||||
|
||||
void ThreadStop(SDL_Thread *t);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -1,11 +1,17 @@
|
||||
#include "sim_thread.h"
|
||||
#include <windows.h>
|
||||
|
||||
#include <process.h>
|
||||
|
||||
void ThreadCreat(Thread_Func_t func, unsigned int stackSize, void *pArg) {
|
||||
_beginthread(func, stackSize, pArg);
|
||||
SDL_Thread *ThreadCreat(Thread_Func_t func, char *name, void *pArg) {
|
||||
SDL_Thread *t = SDL_CreateThread(func, name, NULL);
|
||||
if (!t) {
|
||||
SDL_Log("CreateThread: %s", SDL_GetError);
|
||||
return nullptr;
|
||||
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
void ThreadStop() {
|
||||
_endthread();
|
||||
void ThreadStop(SDL_Thread *t) {
|
||||
SDL_WaitThread(t, NULL);
|
||||
}
|
||||
|
Reference in New Issue
Block a user