Compare commits
No commits in common. "6c9a999c712dea7afbb2a9f731df210916309538" and "d2e5789476f6c977e16a17e948cab66bd3cd0a7c" have entirely different histories.
6c9a999c71
...
d2e5789476
|
@ -1,3 +1,4 @@
|
|||
[submodule "SDL3"]
|
||||
path = SDL3
|
||||
[submodule "SDL2"]
|
||||
path = SDL2
|
||||
url = https://github.com/libsdl-org/SDL.git
|
||||
branch = release-2.30.x
|
||||
|
|
|
@ -18,17 +18,16 @@ foreach (SIM_SUBDIR ${SIM_SUBDIRS})
|
|||
include_directories(${SIM_SUBDIR})
|
||||
endforeach ()
|
||||
|
||||
set(LVGL_ROOT_DIR lvgl)
|
||||
include(lvgl/env_support/cmake/custom.cmake)
|
||||
file(GLOB LVGL_SUBDIRS "lvgl/demos/*" "lvgl/*" "lvgl/src/*")
|
||||
foreach (LVGL_SUBDIR ${LVGL_SUBDIRS})
|
||||
include_directories(${LVGL_SUBDIR})
|
||||
endforeach ()
|
||||
|
||||
include_directories(easyx/include)
|
||||
link_directories(easyx/lib64)
|
||||
|
||||
|
||||
file(GLOB_RECURSE SOURCES "demo/*/*.*" "sim/*/*.*")
|
||||
message(${SOURCES})
|
||||
add_subdirectory(SDL3 EXCLUDE_FROM_ALL)
|
||||
link_libraries(SDL3::SDL3)
|
||||
file(GLOB_RECURSE SOURCES "demo/*/*.*" "sim/*/*.*" "lvgl/src/*/*.*" "lvgl/demos/*/*.*")
|
||||
#file(GLOB_RECURSE SOURCES "demo/tft/*.*" "sim/*/*.*" "lvgl/src/*/*.*")
|
||||
|
||||
link_libraries(libeasyx.a libgdi32.a libole32.a)
|
||||
add_executable(HW_Lib main.c ${SOURCES})
|
||||
|
@ -36,11 +35,5 @@ add_executable(HW_Lib main.c ${SOURCES})
|
|||
#导入库
|
||||
add_subdirectory(lib)
|
||||
target_link_libraries(HW_Lib HW_LIB_List HW_LIB_Task HW_LIB_Printf HW_LIB_Utils HW_LIB_Iic
|
||||
HW_LIB_Spi HW_LIB_Key HW_LIB_Oled HW_LIB_Font HW_LIB_Tft lvgl::lvgl
|
||||
)
|
||||
|
||||
add_custom_command(TARGET HW_Lib POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
$<TARGET_FILE:SDL3::SDL3>
|
||||
$<TARGET_FILE_DIR:HW_Lib>
|
||||
HW_LIB_Spi HW_LIB_Key HW_LIB_Oled HW_LIB_Font HW_LIB_Tft
|
||||
)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 5669b97fd78642b9068d4efa3eeab84098ce8527
|
1
SDL3
1
SDL3
|
@ -1 +0,0 @@
|
|||
Subproject commit 89c6bc5f5022e71433a9e4eb1a2edc6d79be71f2
|
|
@ -2,6 +2,7 @@
|
|||
#include "lv_port_disp.h"
|
||||
#include "lv_port_indev.h"
|
||||
#include "lvgl.h"
|
||||
#include "lv_demo_widgets.h"
|
||||
#include <windows.h>
|
||||
#include "t_lvgl.h"
|
||||
|
||||
|
|
|
@ -114,10 +114,12 @@ OLED_T oled = {
|
|||
void Test_OLED(void *pVoid) {
|
||||
SIM_OLED_INIT(128, 64, CYAN, 0x0, 5, 0);
|
||||
|
||||
SIM_OLED_START();
|
||||
|
||||
OLED_Init(&oled);
|
||||
OLED_CLS(&oled);
|
||||
|
||||
OLED_ShowCHString(&oled, 1, 24, "星海科技机械师");
|
||||
OLED_ShowCHString(&oled, 1, 24, "姓名学号:2233");
|
||||
|
||||
OLED_DrawRect(&oled, 0, 0, 127, 63);
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
TFT_T demo_tft;
|
||||
uint16_t xs = 0, ys = 0, xe = 0, ye = 0;
|
||||
bool fill;
|
||||
static SIM_Display_t tft_display;
|
||||
|
||||
//屏幕指令
|
||||
#define WGRAM_CMD 0x5C
|
||||
#define SETXCMD 0x2A
|
||||
|
@ -79,7 +79,7 @@ uint8_t tft_senddata(uint8_t *data, size_t len) {
|
|||
if (len == 2) {
|
||||
color_u.u8[1] = *data;
|
||||
color_u.u8[0] = *data++;
|
||||
SIM_Color_DrawPiexl(&tft_display, (SIM_Color_t) RGB565_to_RGB888(color_u.u16, true), xs, ys);
|
||||
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 {
|
||||
|
@ -88,10 +88,10 @@ uint8_t tft_senddata(uint8_t *data, size_t len) {
|
|||
data++;
|
||||
color_u.u8[0] = *data;
|
||||
data++;
|
||||
color[i] = RGB565_to_RGB888(color_u.u16, true) | 0xFF000000;
|
||||
color[i] = RGB565_to_RGB888(color_u.u16, true);
|
||||
}
|
||||
SIM_Color_ImgFromBuffer(&tft_display, color, xs, ys, len / 2 - 1, 1);
|
||||
// SIM_Color_DrawHLineBuffer(color, xs, ys, len / 2);
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
@ -116,8 +116,8 @@ void Test_tft(void *) {
|
|||
demo_tft.dir = HORIZONTAL;//必填
|
||||
|
||||
//模拟初始化
|
||||
SIM_Display_Init("TFT", demo_tft.width, demo_tft.height, 0xFFFF, 0x0000, 2, &tft_display);
|
||||
|
||||
SIM_Display_INIT(demo_tft.width, demo_tft.height, 0xFFFF, 0x0000, 2, 0);
|
||||
SIM_Display_START();
|
||||
|
||||
TFT_Init(&demo_tft);//初始化
|
||||
TFT_Color_t t;
|
||||
|
|
|
@ -10,7 +10,7 @@ extern "C" {
|
|||
|
||||
#define REFRESH_CALL_ENABLE 1 //使用DMA或者整体刷新函数
|
||||
#define HZK_FONT //使用HZK 12/16 字体 tools下可自由生成
|
||||
#define UTF8_TO_UNICODE //启用UTF8转换显示
|
||||
//#define UTF8_TO_UNICODE //启用UTF8转换显示
|
||||
//#define LVGL_FONT //启用LVGL字体
|
||||
|
||||
/**
|
||||
|
|
157
main.c
157
main.c
|
@ -12,163 +12,26 @@
|
|||
#include "t_tft.h"
|
||||
#include "tool.h"
|
||||
#include "sim_test.h"
|
||||
#include "sim_sdl.h"
|
||||
#include <windows.h>
|
||||
#include <stdint.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
|
||||
|
||||
#define POINTS_COUNT 4
|
||||
|
||||
static SDL_Point points[POINTS_COUNT] = {
|
||||
{320, 200},
|
||||
{300, 240},
|
||||
{340, 240},
|
||||
{320, 200}
|
||||
};
|
||||
|
||||
static SDL_Rect bigrect = {0, 0, 540, 380};
|
||||
|
||||
static SIM_SDL3_t sdl1;
|
||||
static SIM_SDL3_t sdl2;
|
||||
static SIM_SDL3_t sdl3;
|
||||
|
||||
static SIM_SDL3_t sdls[3];
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main() {
|
||||
srand((unsigned) time(NULL));
|
||||
|
||||
|
||||
// SDL_Log("Hello, SDL3!");
|
||||
// int count = SDL_GetNumRenderDrivers();
|
||||
// for (int i = 0; i < count; ++i) {
|
||||
// const char* name = SDL_GetRenderDriver(i);
|
||||
// SDL_Log("Render driver[%d]: %s", i, name);
|
||||
// }
|
||||
// if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
// SDL_Log("SDL_Init failed: %s", SDL_GetError());
|
||||
// return -1;
|
||||
// }
|
||||
// SDL_Window* window = SDL_CreateWindow("Hello, SDL3!", 800, 600, SDL_WINDOW_RESIZABLE);
|
||||
// if (!window) {
|
||||
// SDL_Log("Could not create a window: %s", SDL_GetError());
|
||||
// return -1;
|
||||
// }
|
||||
//
|
||||
// SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
//
|
||||
// SDL_Renderer* renderer = SDL_CreateRenderer(window, nullptr);
|
||||
// if (!renderer) {
|
||||
// SDL_Log("Create renderer failed: %s", SDL_GetError());
|
||||
// return -1;
|
||||
// }
|
||||
//
|
||||
// SDL_SetRenderDrawColor(renderer, 16, 0, 16, 255);
|
||||
// SDL_RenderClear(renderer);
|
||||
// SDL_Delay(2000);
|
||||
// SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
|
||||
// for (int i = 0; i < 100; ++i) {
|
||||
// SDL_RenderPoint(renderer,i,i);
|
||||
// }
|
||||
// if(!SDL_RenderPoints(renderer,points,POINTS_COUNT)){
|
||||
// SDL_Log("Draw Renderer failed: %s", SDL_GetError());
|
||||
// return -1;
|
||||
// }
|
||||
// SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
|
||||
// SDL_Rect rect1 = { 1, 1, 500, 500 };
|
||||
// SDL_RenderFillRect(renderer, &rect1);
|
||||
//
|
||||
// SDL_SetRenderDrawColor(renderer, 255, 0, 0, SDL_ALPHA_OPAQUE);
|
||||
//
|
||||
// SDL_RenderLines(renderer, points, POINTS_COUNT);
|
||||
//
|
||||
// SDL_Rect rect = { 200, 300, 100, 100 };
|
||||
// SDL_RenderRect(renderer, &rect);
|
||||
//
|
||||
// SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255);
|
||||
// SDL_RenderFillRect(renderer, &rect);
|
||||
//
|
||||
// SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
|
||||
// SDL_RenderFillRect(renderer, &bigrect);
|
||||
//
|
||||
//
|
||||
// SDL_RenderPresent(renderer);
|
||||
// SDL_Delay(5000);
|
||||
// SDL_Event event;
|
||||
// bool keep_going = true;
|
||||
//
|
||||
// while (keep_going) {
|
||||
// while (SDL_PollEvent(&event)) {
|
||||
// switch (event.type) {
|
||||
// case SDL_EVENT_QUIT: {
|
||||
// keep_going = false;
|
||||
// break;
|
||||
// }
|
||||
// case SDL_EVENT_KEY_DOWN: {
|
||||
// keep_going = keep_going && (event.key.key != SDLK_ESCAPE);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//// SDL_Log("Event: %d", event.type);
|
||||
// }
|
||||
// SDL_RenderClear(renderer);
|
||||
// SDL_RenderPresent(renderer);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// SDL_DestroyRenderer(renderer);
|
||||
// SDL_DestroyWindow(window);
|
||||
// SDL_Quit();
|
||||
|
||||
|
||||
|
||||
// SIM_SDLInit("TEST1",480,320,2,&sdls[0]);
|
||||
// SIM_SDLInit("TEST2",480,320,1,&sdls[1]);
|
||||
// SIM_SDLInit("TEST3",320,320,1,&sdls[2]);
|
||||
// SIM_Color_t color;
|
||||
// color.full=0xffff0000;
|
||||
// for (int i = 0; i < 3; ++i) {
|
||||
// for (int j = 0; j < 100; ++j) {
|
||||
// SIM_SDL_Color_DrawPiexl(&sdls[i],j,j,color);
|
||||
// }
|
||||
// }
|
||||
// SDL_Event event;
|
||||
// bool keep_going = true;
|
||||
// while (keep_going) {
|
||||
// while (SDL_PollEvent(&event)) {
|
||||
// switch (event.type) {
|
||||
// case SDL_EVENT_QUIT: {
|
||||
// keep_going = false;
|
||||
// break;
|
||||
// }
|
||||
// case SDL_EVENT_KEY_DOWN: {
|
||||
// keep_going = keep_going && (event.key.key != SDLK_ESCAPE);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//// SDL_Log("Event: %d", event.type);
|
||||
// }
|
||||
// }
|
||||
// SIM_SDL_Stop(&sdls[0]);
|
||||
// SIM_SDL_Stop(&sdls[1]);
|
||||
// SIM_SDL_Stop(&sdls[2]);
|
||||
|
||||
// int i = 1;
|
||||
// POUT((++i) + (++i));
|
||||
//
|
||||
// char str[] = "123.456";
|
||||
// float result = Str2Float(str);
|
||||
// printf("Result: %.3f\n", result);
|
||||
// Test_Run("SPI", Test_spi);
|
||||
// Test_Run("IIC", Test_iic);
|
||||
// Test_Run("ArgPase", Test_argpase);
|
||||
// Test_Run("List", Test_List);
|
||||
// Test_RunTime("Key", Test_Key);
|
||||
// Test_RunTime("Queue", Test_Queue);
|
||||
// Test_RunTime("Task", Test_task);
|
||||
// Test_Run("OLED", Test_OLED);
|
||||
// Test_Run("LVGL", Test_lvgl);
|
||||
Test_Run("SPI", Test_spi);
|
||||
Test_Run("IIC", Test_iic);
|
||||
Test_Run("ArgPase", Test_argpase);
|
||||
Test_Run("List", Test_List);
|
||||
Test_RunTime("Key", Test_Key);
|
||||
Test_RunTime("Queue", Test_Queue);
|
||||
Test_RunTime("Task", Test_task);
|
||||
Test_RunTime("OLED", Test_OLED);
|
||||
Test_Run("LVGL", Test_lvgl);
|
||||
Test_RunTime("TFT", Test_tft);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -4,24 +4,16 @@
|
|||
|
||||
#ifndef HW_LIB_SIM_TEST_H
|
||||
#define HW_LIB_SIM_TEST_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief 测试函数执行时间
|
||||
* @param name: [输入] 测试名称
|
||||
* @param pFunction: [输入] 指向待测试函数的指针
|
||||
* @return void
|
||||
* @example Test("FunctionName", functionName);
|
||||
* @brief 测试函数执行时间
|
||||
* @param name: [输入] 测试名称
|
||||
* @param pFunction: [输入] 指向待测试函数的指针
|
||||
* @return void
|
||||
* @example Test("FunctionName", functionName);
|
||||
**/
|
||||
void Test_RunTime(char *name, void (*pFunction)(void *));
|
||||
|
||||
void Test_Run(char *name, void (*pFunction)(void *));
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //HW_LIB_SIM_TEST_H
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
#include "graphics.h"
|
||||
#include <conio.h>
|
||||
|
||||
|
||||
static uint32_t pixelColor, backgroundColor;
|
||||
static int scaleFactor, w, h;
|
||||
uint8_t border;
|
||||
|
||||
#define GET_BIT(x, bit) ((x & (1 << bit)) >> bit)
|
||||
|
||||
uint32_t RGB565_to_RGB888(uint16_t rgb565, bool isBGR) {
|
||||
|
@ -20,10 +25,6 @@ uint32_t RGB565_to_RGB888(uint16_t rgb565, bool isBGR) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef USER_SDL3
|
||||
static uint32_t pixelColor, backgroundColor;
|
||||
static int scaleFactor, w, h;
|
||||
uint8_t border;
|
||||
|
||||
void SIM_Display_INIT(int width, int height, uint32_t pixcolor, uint32_t backcolor, int scale, uint8_t b)
|
||||
{
|
||||
|
@ -142,90 +143,3 @@ void SIM_Color_FillFromBuffer(uint32_t* buf, uint16_t xs, uint16_t ys, uint16_t
|
|||
}
|
||||
EndBatchDraw();
|
||||
}
|
||||
#else
|
||||
|
||||
bool SIM_Display_Init(char *name, int width, int height, uint32_t pixcolor, uint32_t backcolor, int scale,
|
||||
SIM_Display_t *display) {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
SDL_Log("SDL_Init failed: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
display->scale = scale;
|
||||
display->pixelcolor.full = pixcolor;
|
||||
display->backcolor.full = backcolor;
|
||||
display->window = SDL_CreateWindow(name, width * scale, height * scale, SDL_WINDOW_RESIZABLE);
|
||||
if (!display->window) {
|
||||
SDL_Log("Could not create a window: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
SDL_SetWindowPosition(display->window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
display->renderer = SDL_CreateRenderer(display->window, nullptr);
|
||||
if (!display->renderer) {
|
||||
SDL_Log("Create renderer failed: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
SDL_SetRenderDrawColor(display->renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(display->renderer);
|
||||
return true;
|
||||
}
|
||||
|
||||
void SIM_Color_DrawPiexl(SIM_Display_t *display, SIM_Color_t color, uint16_t x, uint16_t y) {
|
||||
SDL_SetRenderDrawColor(display->renderer, color.ch.red, color.ch.green, color.ch.blue, color.ch.alpha);
|
||||
for (int y_ = y * display->scale; y_ < (y * display->scale) + display->scale; ++y_) {
|
||||
for (int x_ = x * display->scale; x_ < (x * display->scale) + display->scale; ++x_) {
|
||||
SDL_RenderPoint(display->renderer, x_, y_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SIM_OneColor_DrawFromBuffer(SIM_Display_t *display, uint8_t *buf, uint16_t width, uint16_t height) {
|
||||
SIM_Color_t color;
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
uint8_t byteData = buf[y * width + x];
|
||||
for (int i = 0; i < 8; i++) {
|
||||
uint8_t bit = GET_BIT(byteData, i);
|
||||
if (bit)color = display->pixelcolor;
|
||||
else color = display->backcolor;
|
||||
SIM_Color_DrawPiexl(display, color, x, y * 8 + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_RenderPresent(display->renderer);
|
||||
}
|
||||
|
||||
|
||||
void SIM_Color_ImgFromBuffer(SIM_Display_t *display, uint32_t *buf, uint16_t x, uint16_t y, uint16_t width,
|
||||
uint16_t height) {
|
||||
SIM_Color_t color;
|
||||
for (int y_i = 0; y_i < height; y_i++) {
|
||||
for (int x_i = 0; x_i < width; x_i++) {
|
||||
color.full = *buf;
|
||||
SIM_Color_DrawPiexl(display, color, x + x_i, y + y_i);
|
||||
buf++;
|
||||
}
|
||||
}
|
||||
SDL_RenderPresent(display->renderer);
|
||||
}
|
||||
|
||||
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++) {
|
||||
color.full = *buf;
|
||||
SIM_Color_DrawPiexl(display, color, x_i, y_i);
|
||||
buf++;
|
||||
}
|
||||
}
|
||||
SDL_RenderPresent(display->renderer);
|
||||
}
|
||||
|
||||
|
||||
void SIM_Display_STOP(SIM_Display_t *display) {
|
||||
SDL_DestroyRenderer(display->renderer);
|
||||
SDL_DestroyWindow(display->window);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -9,10 +9,6 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "stdint.h"
|
||||
//是否启用SDL3画图
|
||||
#define USER_SDL3
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 定义颜色常量值,用于模拟显示
|
||||
|
@ -34,7 +30,7 @@ extern "C" {
|
|||
#define YELLOW 0x55FFFF // 黄色
|
||||
#define WHITE 0xFFFFFF // 白色
|
||||
|
||||
#ifndef USER_SDL3
|
||||
|
||||
/**
|
||||
* @brief 初始化模拟 显示
|
||||
* @param width: [输入] 显示宽度
|
||||
|
@ -115,94 +111,6 @@ void SIM_Color_ImgFromBuffer(uint32_t* buf, uint16_t x, uint16_t y, uint16_t wid
|
|||
* @example SIM_Color_FillFromBuffer(buf, 50, 30, 150, 100);
|
||||
**/
|
||||
void SIM_Color_FillFromBuffer(uint32_t* buf, uint16_t xs, uint16_t ys, uint16_t xe, uint16_t ye);
|
||||
#else
|
||||
#include "SDL3/SDL.h"
|
||||
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t blue;
|
||||
uint8_t green;
|
||||
uint8_t red;
|
||||
uint8_t alpha;
|
||||
} ch;
|
||||
uint32_t full;
|
||||
} SIM_Color_t;
|
||||
|
||||
typedef struct {
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Event *event;
|
||||
int scale;
|
||||
SIM_Color_t pixelcolor;
|
||||
SIM_Color_t backcolor;
|
||||
} SIM_Display_t;
|
||||
|
||||
/**
|
||||
* @brief 初始化模拟 显示
|
||||
* @param name: [输入] 窗口名称
|
||||
* @param width: [输入] 显示宽度
|
||||
* @param height: [输入] 显示高度
|
||||
* @param pixcolor: [输入] 像素颜色
|
||||
* @param backcolor: [输入] 背景颜色
|
||||
* @param scale: [输入] 显示缩放比例
|
||||
* @param display: [输入] 输入窗口实例
|
||||
* @return bool: true[成功] false[失败]
|
||||
* @example SIM_Display_Init(128, 64, 0xFFFF00, 0x000000, 10, 1);
|
||||
**/
|
||||
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: [输入] 输入窗口实例
|
||||
* @param color 颜色
|
||||
* @param x x坐标
|
||||
* @param y y坐标
|
||||
*/
|
||||
void SIM_Color_DrawPiexl(SIM_Display_t *display, SIM_Color_t color, uint16_t x, uint16_t y);
|
||||
|
||||
void SIM_OneColor_DrawFromBuffer(SIM_Display_t *display, uint8_t *buf, uint16_t width, uint16_t height);
|
||||
|
||||
/**
|
||||
* @brief 从缓冲区中填充图像
|
||||
* @param display: [输入] 输入窗口实例
|
||||
* @param buf: [输入] 缓冲区指针
|
||||
* @param x: [输入] 图像起始横坐标
|
||||
* @param y: [输入] 图像起始纵坐标
|
||||
* @param width: [输入] 图像宽度
|
||||
* @param height: [输入] 图像高度
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @brief 从缓冲区中填充颜色
|
||||
* @param display: [输入] 输入窗口实例
|
||||
* @param buf: [输入] 缓冲区指针
|
||||
* @param xs: [输入] 填充区域起始横坐标
|
||||
* @param ys: [输入] 填充区域起始纵坐标
|
||||
* @param xe: [输入] 填充区域结束横坐标
|
||||
* @param ye: [输入] 填充区域结束纵坐标
|
||||
* @return void
|
||||
* @example SIM_Color_FillFromBuffer(buf, 50, 30, 150, 100);
|
||||
**/
|
||||
void
|
||||
SIM_Color_FillFromBuffer(SIM_Display_t *display, uint32_t *buf, uint16_t xs, uint16_t ys, uint16_t xe, uint16_t ye);
|
||||
|
||||
|
||||
/**
|
||||
* @brief 停止模拟 显示
|
||||
* @return void
|
||||
* @example SIM_OLED_STOP();
|
||||
**/
|
||||
void SIM_Display_STOP(SIM_Display_t *display);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
uint32_t RGB565_to_RGB888(uint16_t rgb565, bool isBGR);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
@ -142,7 +142,8 @@ 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(MY_DISP_HOR_RES,MY_DISP_VER_RES, 0xffffff, BLACK, 1, false);
|
||||
SIM_Display_START();
|
||||
}
|
||||
|
||||
volatile bool disp_flush_enabled = true;
|
||||
|
@ -185,7 +186,7 @@ static void disp_flush(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_
|
|||
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);
|
||||
SIM_Color_FillFromBuffer(color, area->x1, area->y1, area->x2, area->y2);
|
||||
free(color);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,16 +2,21 @@
|
|||
#include "graphics.h"
|
||||
#include <conio.h>
|
||||
|
||||
static SIM_Display_t oled_display;
|
||||
void SIM_OLED_INIT(int width, int height, uint32_t pixcolor, uint32_t backcolor, int scale, uint8_t b) {
|
||||
SIM_Display_Init("OLED", width, height, pixcolor, backcolor, scale, &oled_display);
|
||||
SIM_Display_INIT(width,height,pixcolor,backcolor,scale,b);
|
||||
}
|
||||
|
||||
void SIM_OLED_START() {
|
||||
SIM_Display_START();
|
||||
}
|
||||
|
||||
void SIM_OLED_STOP() {
|
||||
SIM_Display_STOP(&oled_display);
|
||||
SIM_Display_STOP();
|
||||
}
|
||||
|
||||
void SIM_OLED_DrawFromBuffer(uint8_t *buf, uint8_t width, uint8_t height) {
|
||||
SIM_OneColor_DrawFromBuffer(&oled_display, buf, width, height);
|
||||
SIM_OneColor_DrawFromBuffer(buf,width,height);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -19,6 +19,13 @@ extern "C" {
|
|||
**/
|
||||
void SIM_OLED_INIT(int width, int height, uint32_t pixcolor, uint32_t backcolor, int scale, uint8_t border);
|
||||
|
||||
/**
|
||||
* @brief 开始模拟 OLED 显示
|
||||
* @return void
|
||||
* @example SIM_OLED_START();
|
||||
**/
|
||||
void SIM_OLED_START();
|
||||
|
||||
/**
|
||||
* @brief 停止模拟 OLED 显示
|
||||
* @return void
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
#include "sim_sdl.h"
|
||||
|
||||
|
||||
bool SIM_SDLInit(char *name, int width, int height, int scale, SIM_SDL3_t *sdl3) {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
SDL_Log("SDL_Init failed: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
sdl3->scale = scale;
|
||||
sdl3->window = SDL_CreateWindow(name, width * scale, height * scale, SDL_WINDOW_RESIZABLE);
|
||||
if (!sdl3->window) {
|
||||
SDL_Log("Could not create a window: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
SDL_SetWindowPosition(sdl3->window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
sdl3->renderer = SDL_CreateRenderer(sdl3->window, nullptr);
|
||||
if (!sdl3->renderer) {
|
||||
SDL_Log("Create renderer failed: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SIM_SDL_Color_DrawPiexl(SIM_SDL3_t *sdl3, uint16_t x, uint16_t y, SIM_Color_t color) {
|
||||
SDL_SetRenderDrawColor(sdl3->renderer, color.ch.red, color.ch.green, color.ch.blue, color.ch.alpha);
|
||||
for (int y_ = y * sdl3->scale; y_ < (y * sdl3->scale) + sdl3->scale; ++y_) {
|
||||
for (int x_ = x * sdl3->scale; x_ < (x * sdl3->scale) + sdl3->scale; ++x_) {
|
||||
SDL_RenderPoint(sdl3->renderer, x_, y_);
|
||||
}
|
||||
}
|
||||
SDL_RenderPresent(sdl3->renderer);
|
||||
}
|
||||
|
||||
void SIM_SDL_Stop(SIM_SDL3_t *sdl3) {
|
||||
SDL_DestroyRenderer(sdl3->renderer);
|
||||
SDL_DestroyWindow(sdl3->window);
|
||||
SDL_Quit();
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
#ifndef HW_LIB_SIM_SDL_H
|
||||
#define HW_LIB_SIM_SDL_H
|
||||
|
||||
#include "SDL3/SDL.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
typedef struct {
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Event *event;
|
||||
int scale;
|
||||
} SIM_SDL3_t;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t blue;
|
||||
uint8_t green;
|
||||
uint8_t red;
|
||||
uint8_t alpha;
|
||||
} ch;
|
||||
uint32_t full;
|
||||
} SIM_Color_t;
|
||||
|
||||
|
||||
bool SIM_SDLInit(char *name, int width, int height, int scale, SIM_SDL3_t *sdl3);
|
||||
|
||||
void SIM_SDL_Color_DrawPiexl(SIM_SDL3_t *sdl3, uint16_t x, uint16_t y, SIM_Color_t color);
|
||||
|
||||
void SIM_SDL_Stop(SIM_SDL3_t *sdl3);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif //HW_LIB_SIM_SDL_H
|
Loading…
Reference in New Issue