From d2e5789476f6c977e16a17e948cab66bd3cd0a7c Mon Sep 17 00:00:00 2001 From: JiXieShi Date: Sat, 21 Sep 2024 16:07:31 +0800 Subject: [PATCH] SDL2 --- .gitmodules | 4 ++++ SDL2 | 1 + demo/arg/t_arg.h | 2 +- demo/arg/test.c | 4 ++-- demo/iic/t_iic.h | 2 +- demo/iic/test.c | 4 ++-- demo/key/t_key.h | 2 +- demo/key/test.c | 4 ++-- demo/list/t_list.h | 4 ++-- demo/list/test.c | 6 +++--- demo/lvgl/t_lvgl.h | 2 +- demo/lvgl/test.c | 37 +++++++++++++++++++++++++++++++------ demo/oled/t_oled.h | 2 +- demo/oled/test.c | 4 ++-- demo/spi/t_spi.h | 3 ++- demo/spi/test.c | 4 ++-- demo/task/t_task.h | 2 +- demo/task/test.c | 4 ++-- demo/tft/t_tft.h | 2 +- demo/tft/test.c | 2 +- lib/utils/inc/tool.h | 8 -------- lib/utils/tool.cpp | 18 +----------------- main.c | 18 ++++++++++-------- sim/Test/sim_test.cpp | 34 ++++++++++++++++++++++++++++++++++ sim/Test/sim_test.h | 19 +++++++++++++++++++ sim/lvgl/lv_conf.h | 2 +- sim/lvgl/lv_port_disp.cpp | 2 +- 27 files changed, 129 insertions(+), 67 deletions(-) create mode 100644 .gitmodules create mode 160000 SDL2 create mode 100644 sim/Test/sim_test.cpp create mode 100644 sim/Test/sim_test.h diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..74474c3 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "SDL2"] + path = SDL2 + url = https://github.com/libsdl-org/SDL.git + branch = release-2.30.x diff --git a/SDL2 b/SDL2 new file mode 160000 index 0000000..5669b97 --- /dev/null +++ b/SDL2 @@ -0,0 +1 @@ +Subproject commit 5669b97fd78642b9068d4efa3eeab84098ce8527 diff --git a/demo/arg/t_arg.h b/demo/arg/t_arg.h index 078bdd9..2abdbb1 100644 --- a/demo/arg/t_arg.h +++ b/demo/arg/t_arg.h @@ -5,6 +5,6 @@ #ifndef HW_LIB_T_ARG_H #define HW_LIB_T_ARG_H -void Test_argpase(); +void Test_argpase(void *pVoid); #endif //HW_LIB_T_ARG_H diff --git a/demo/arg/test.c b/demo/arg/test.c index e6a833d..d8a0cc6 100644 --- a/demo/arg/test.c +++ b/demo/arg/test.c @@ -11,7 +11,7 @@ Option Opts[6] = {{"T0", T0}, {"T4", T4}, {"T5", T5}}; -void Test_argpase() { +void Test_argpase(void *pVoid) { OptList *Head = Options_Creat("Head", -1); OptList *t; int i; @@ -46,4 +46,4 @@ void Test_argpase() { break; } } -} \ No newline at end of file +} diff --git a/demo/iic/t_iic.h b/demo/iic/t_iic.h index 0d2f42d..05608cf 100644 --- a/demo/iic/t_iic.h +++ b/demo/iic/t_iic.h @@ -5,6 +5,6 @@ #ifndef HW_LIB_T_IIC_H #define HW_LIB_T_IIC_H -void Test_iic(); +void Test_iic(void *pVoid); #endif //HW_LIB_T_IIC_H diff --git a/demo/iic/test.c b/demo/iic/test.c index 5b56717..4feb0f1 100644 --- a/demo/iic/test.c +++ b/demo/iic/test.c @@ -28,7 +28,7 @@ uint8_t SDA_Read() { return l; } -void Test_iic() { +void Test_iic(void *pVoid) { SW_Dev_IIC dev = { .CLK_SET = CLK_Pin, .SDA_SET = SDA_Set, @@ -57,4 +57,4 @@ void Test_iic() { SW_IIC_WL(dev, internalAddress, writeData, len); SW_IIC_RL(dev, internalAddress, readData, len, 1); BufPrint(" RX", readData, TYPE_T(readData), len, 16); -} \ No newline at end of file +} diff --git a/demo/key/t_key.h b/demo/key/t_key.h index c2e7825..aad7698 100644 --- a/demo/key/t_key.h +++ b/demo/key/t_key.h @@ -1,6 +1,6 @@ #ifndef HW_LIB_T_KEY_H #define HW_LIB_T_KEY_H -void Test_Key(); +void Test_Key(void *pVoid); #endif //HW_LIB_T_KEY_H diff --git a/demo/key/test.c b/demo/key/test.c index 8ef53de..c61d981 100644 --- a/demo/key/test.c +++ b/demo/key/test.c @@ -38,7 +38,7 @@ void Key_Call(Key_t *key) { } } -void Test_Key() { +void Test_Key(void *pVoid) { Key_t k1, k2, k3, k4, k5, k6, ks; key_init(&k1, SIM_KEY_UP, 1, SIM_Key_UP); key_init(&k2, SIM_KEY_DOWN, 1, SIM_Key_DOWN); @@ -61,4 +61,4 @@ void Test_Key() { key_ticks(); Sleep(5); } -} \ No newline at end of file +} diff --git a/demo/list/t_list.h b/demo/list/t_list.h index 5be3b71..ce29f58 100644 --- a/demo/list/t_list.h +++ b/demo/list/t_list.h @@ -5,7 +5,7 @@ #ifndef HW_LIB_T_LIST_H #define HW_LIB_T_LIST_H -extern void Test_List(); +extern void Test_List(void *pVoid); -extern void Test_Queue(); +extern void Test_Queue(void *pVoid1); #endif //HW_LIB_T_LIST_H diff --git a/demo/list/test.c b/demo/list/test.c index 6215c98..690ab10 100644 --- a/demo/list/test.c +++ b/demo/list/test.c @@ -38,7 +38,7 @@ void print(List_t *list) { } } -void Test_List() { +void Test_List(void *pVoid) { List_t list; list_init(&list); // 初始化链表 @@ -102,7 +102,7 @@ void Test_List() { list_destroy(&list, NULL); // 销毁链表 } -void Test_Queue() { +void Test_Queue(void *pVoid) { Queue_List_t *deque = newQueue_List(sizeof(int)); // 创建一个int类型的双端队列 // 测试入队操作 @@ -141,4 +141,4 @@ void Test_Queue() { printf("Pop value from front: %d\n", *popVal); } delQueue_List(deque); -} \ No newline at end of file +} diff --git a/demo/lvgl/t_lvgl.h b/demo/lvgl/t_lvgl.h index ab6f397..c067322 100644 --- a/demo/lvgl/t_lvgl.h +++ b/demo/lvgl/t_lvgl.h @@ -5,6 +5,6 @@ #ifndef HW_LIB_T_LVGL_H #define HW_LIB_T_LVGL_H -void Test_lvgl(); +void Test_lvgl(void *pVoid); #endif //HW_LIB_T_LVGL_H diff --git a/demo/lvgl/test.c b/demo/lvgl/test.c index 6ecabcc..301caa7 100644 --- a/demo/lvgl/test.c +++ b/demo/lvgl/test.c @@ -6,17 +6,42 @@ #include #include "t_lvgl.h" -void Test_lvgl() { + +static void btn_event_cb(lv_event_t *e) { + lv_event_code_t code = lv_event_get_code(e); + lv_obj_t *btn = lv_event_get_target(e); + if (code == LV_EVENT_CLICKED) { + static uint8_t cnt = 0; + cnt++; + + /*Get the first child of the button which is the label and change its text*/ + lv_obj_t *label = lv_obj_get_child(btn, 0); + lv_label_set_text_fmt(label, "Button: %d", cnt); + } +} + +/** + * Create a button with a label and react on click event. + */ +void lv_example_get_started_1(void) { + lv_obj_t *btn = lv_btn_create(lv_scr_act()); /*Add a button the current screen*/ + lv_obj_set_pos(btn, 10, 10); /*Set its position*/ + lv_obj_set_size(btn, 120, 50); /*Set its size*/ + lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL); /*Assign a callback to the button*/ + + lv_obj_t *label = lv_label_create(btn); /*Add a label to the button*/ + lv_label_set_text(label, "Button"); /*Set the labels text*/ + lv_obj_center(label); +} + +void Test_lvgl(void *pVoid) { 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_example_get_started_1(); // lv_demo_widgets(); -// printf("\nTEST Widgets\n"); + printf("\nTEST Widgets\n"); while (1) { /* Periodically call the lv_task handler. diff --git a/demo/oled/t_oled.h b/demo/oled/t_oled.h index 25844a8..f1609cb 100644 --- a/demo/oled/t_oled.h +++ b/demo/oled/t_oled.h @@ -1,6 +1,6 @@ #ifndef HW_LIB_T_OLED_H #define HW_LIB_T_OLED_H -void Test_OLED(); +void Test_OLED(void *pVoid); #endif //HW_LIB_T_OLED_H diff --git a/demo/oled/test.c b/demo/oled/test.c index 9ce6d6a..0a4c23b 100644 --- a/demo/oled/test.c +++ b/demo/oled/test.c @@ -111,7 +111,7 @@ OLED_T oled = { .call=Refresh_Call, }; -void Test_OLED() { +void Test_OLED(void *pVoid) { SIM_OLED_INIT(128, 64, CYAN, 0x0, 5, 0); SIM_OLED_START(); @@ -145,4 +145,4 @@ void Test_OLED() { Sleep(200); } SIM_OLED_STOP(); -} \ No newline at end of file +} diff --git a/demo/spi/t_spi.h b/demo/spi/t_spi.h index 78d0b75..438eb40 100644 --- a/demo/spi/t_spi.h +++ b/demo/spi/t_spi.h @@ -4,5 +4,6 @@ #ifndef HW_LIB_T_SPI_H #define HW_LIB_T_SPI_H -void Test_spi(); + +void Test_spi(void *pVoid); #endif //HW_LIB_T_SPI_H diff --git a/demo/spi/test.c b/demo/spi/test.c index e94b217..f830af8 100644 --- a/demo/spi/test.c +++ b/demo/spi/test.c @@ -32,7 +32,7 @@ uint8_t Miso_Pin() { return l; } -void Test_spi() { +void Test_spi(void *pVoid) { SW_Dev_Spi ltl = { .MOSI_SET=Mosi_Pin, .SCK_SET=Sck_Pin, @@ -59,4 +59,4 @@ void Test_spi() { SW_SPI_RWL16(ltl, rbuf16, tbuf16, 64); BufPrint(" TX[16]", tbuf16, TYPE_T(tbuf16), 64, 16); BufPrint(" RX[16]", rbuf16, TYPE_T(rbuf16), 64, 16); -} \ No newline at end of file +} diff --git a/demo/task/t_task.h b/demo/task/t_task.h index 2cbc5c6..13c1f09 100644 --- a/demo/task/t_task.h +++ b/demo/task/t_task.h @@ -5,6 +5,6 @@ #ifndef HW_LIB_T_TASK_H #define HW_LIB_T_TASK_H -_Noreturn void Test_task(); +_Noreturn void Test_task(void *pVoid); #endif //HW_LIB_T_TASK_H diff --git a/demo/task/test.c b/demo/task/test.c index 073dd8a..fd440d9 100644 --- a/demo/task/test.c +++ b/demo/task/test.c @@ -40,7 +40,7 @@ void exampleTimer4Callback(Task_t *task, void *userData) { } } -void Test_task() { +void Test_task(void *pVoid) { TaskInit(GetTick); TaskCreat(task1, 1000, -1, exampleTimer1Callback, "1000ms CYCLE task"); TaskCreat(task2, 5000, -1, exampleTimer2Callback, "5000ms ONCE task"); @@ -53,4 +53,4 @@ void Test_task() { while (1) { TaskRun(); } -} \ No newline at end of file +} diff --git a/demo/tft/t_tft.h b/demo/tft/t_tft.h index 789a8e9..f6cc25b 100644 --- a/demo/tft/t_tft.h +++ b/demo/tft/t_tft.h @@ -1,6 +1,6 @@ #ifndef HW_LIB_T_TFT_H #define HW_LIB_T_TFT_H -void Test_tft(); +void Test_tft(void *); #endif //HW_LIB_T_TFT_H diff --git a/demo/tft/test.c b/demo/tft/test.c index 36cb2df..9660eeb 100644 --- a/demo/tft/test.c +++ b/demo/tft/test.c @@ -103,7 +103,7 @@ uint8_t tft_senddata(uint8_t *data, size_t len) { return result; } -void Test_tft() { +void Test_tft(void *) { //设备信息预填充 demo_tft.width = 480;//实际如有支持不用填(如ST7735/7796) diff --git a/lib/utils/inc/tool.h b/lib/utils/inc/tool.h index d96778c..a1a5cf8 100644 --- a/lib/utils/inc/tool.h +++ b/lib/utils/inc/tool.h @@ -134,14 +134,6 @@ float Str2Float(char *str); printf(fmt " ", arr[i]); }\ printf("\n"); } while (0) -/** - * @brief 测试函数执行时间 - * @param name: [输入] 测试名称 - * @param pFunction: [输入] 指向待测试函数的指针 - * @return void - * @example Test("FunctionName", functionName); -**/ -void Test_RunTime(char *name, void (*pFunction)()); #define END "\n" #define TYPE_F(v) _Generic((v), \ diff --git a/lib/utils/tool.cpp b/lib/utils/tool.cpp index 7678527..bd32d38 100644 --- a/lib/utils/tool.cpp +++ b/lib/utils/tool.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "tool.h" float Mapping(float val, float I_Min, float I_Max, float O_Min, float O_Max) { @@ -74,20 +75,3 @@ float Str2Float(char *str) { decimal /= decimalWeight; return float(sign * (integer + decimal)); } - -void Test_RunTime(char *name, void (*pFunction)()) { - clock_t start, end; - double cpu_time_used; - - printf("\n------< %s TEST >------\n", name); - - start = clock(); - pFunction(); - end = clock(); - - cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; - - printf("\n------< %s END >------\n", name); - - printf("\nTime taken by %s: %f seconds\n", name, cpu_time_used); -} \ No newline at end of file diff --git a/main.c b/main.c index 36ba763..8a4bc06 100644 --- a/main.c +++ b/main.c @@ -11,6 +11,7 @@ #include "t_lvgl.h" #include "t_tft.h" #include "tool.h" +#include "sim_test.h" #include #include @@ -22,14 +23,15 @@ int main() { // char str[] = "123.456"; // float result = Str2Float(str); // printf("Result: %.3f\n", result); -// Test_RunTime("SPI", Test_spi); -// Test_RunTime("IIC", Test_iic); -// Test_RunTime("ArgPase", Test_argpase); -// Test_RunTime("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("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; } diff --git a/sim/Test/sim_test.cpp b/sim/Test/sim_test.cpp new file mode 100644 index 0000000..a371e9b --- /dev/null +++ b/sim/Test/sim_test.cpp @@ -0,0 +1,34 @@ +// +// Created by lydxh on 24-9-21. +// + +#include +#include +#include +#include "sim_test.h" + +void Test_RunTime(char *name, void (*pFunction)(void *)) { + clock_t start, end; + double cpu_time_used; + + printf("\n------< %s TEST >------\n", name); + + start = clock(); + pFunction(NULL); + end = clock(); + + cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; + + printf("\n------< %s END >------\n", name); + + printf("\nTime taken by %s: %f seconds\n", name, cpu_time_used); +} + +void Test_Run(char *name, void (*pFunction)(void *)) { + + + printf("\n------< %s TEST >------\n", name); + _beginthread(pFunction, 0, NULL); + + +} diff --git a/sim/Test/sim_test.h b/sim/Test/sim_test.h new file mode 100644 index 0000000..8b56ac0 --- /dev/null +++ b/sim/Test/sim_test.h @@ -0,0 +1,19 @@ +// +// Created by lydxh on 24-9-21. +// + +#ifndef HW_LIB_SIM_TEST_H +#define HW_LIB_SIM_TEST_H + +/** + * @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 *)); + +#endif //HW_LIB_SIM_TEST_H diff --git a/sim/lvgl/lv_conf.h b/sim/lvgl/lv_conf.h index 0c83a7f..8f1b1e3 100644 --- a/sim/lvgl/lv_conf.h +++ b/sim/lvgl/lv_conf.h @@ -24,7 +24,7 @@ *====================*/ /*Color depth: 1 (1 byte per pixel), 8 (RGB332), 16 (RGB565), 32 (ARGB8888)*/ -#define LV_COLOR_DEPTH 32 +#define LV_COLOR_DEPTH 16 /*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 diff --git a/sim/lvgl/lv_port_disp.cpp b/sim/lvgl/lv_port_disp.cpp index 1a91cff..4815507 100644 --- a/sim/lvgl/lv_port_disp.cpp +++ b/sim/lvgl/lv_port_disp.cpp @@ -166,7 +166,7 @@ void colortorgb24(lv_color_t* color_p, uint32_t* color, size_t len) { while (len) { - *color = (uint32_t)RGB(color_p->ch.red, color_p->ch.green, color_p->ch.blue) | (color_p->ch.alpha << 24); + *color = RGB565_to_RGB888(color_p->full, false); color_p++; color++; len--;