main
JiXieShi 2024-09-21 16:07:31 +08:00
parent 4e53f936d8
commit d2e5789476
27 changed files with 129 additions and 67 deletions

4
.gitmodules vendored Normal file
View File

@ -0,0 +1,4 @@
[submodule "SDL2"]
path = SDL2
url = https://github.com/libsdl-org/SDL.git
branch = release-2.30.x

1
SDL2 Submodule

@ -0,0 +1 @@
Subproject commit 5669b97fd78642b9068d4efa3eeab84098ce8527

View File

@ -5,6 +5,6 @@
#ifndef HW_LIB_T_ARG_H #ifndef HW_LIB_T_ARG_H
#define 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 #endif //HW_LIB_T_ARG_H

View File

@ -11,7 +11,7 @@ Option Opts[6] = {{"T0", T0},
{"T4", T4}, {"T4", T4},
{"T5", T5}}; {"T5", T5}};
void Test_argpase() { void Test_argpase(void *pVoid) {
OptList *Head = Options_Creat("Head", -1); OptList *Head = Options_Creat("Head", -1);
OptList *t; OptList *t;
int i; int i;

View File

@ -5,6 +5,6 @@
#ifndef HW_LIB_T_IIC_H #ifndef HW_LIB_T_IIC_H
#define 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 #endif //HW_LIB_T_IIC_H

View File

@ -28,7 +28,7 @@ uint8_t SDA_Read() {
return l; return l;
} }
void Test_iic() { void Test_iic(void *pVoid) {
SW_Dev_IIC dev = { SW_Dev_IIC dev = {
.CLK_SET = CLK_Pin, .CLK_SET = CLK_Pin,
.SDA_SET = SDA_Set, .SDA_SET = SDA_Set,

View File

@ -1,6 +1,6 @@
#ifndef HW_LIB_T_KEY_H #ifndef HW_LIB_T_KEY_H
#define 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 #endif //HW_LIB_T_KEY_H

View File

@ -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_t k1, k2, k3, k4, k5, k6, ks;
key_init(&k1, SIM_KEY_UP, 1, SIM_Key_UP); key_init(&k1, SIM_KEY_UP, 1, SIM_Key_UP);
key_init(&k2, SIM_KEY_DOWN, 1, SIM_Key_DOWN); key_init(&k2, SIM_KEY_DOWN, 1, SIM_Key_DOWN);

View File

@ -5,7 +5,7 @@
#ifndef HW_LIB_T_LIST_H #ifndef HW_LIB_T_LIST_H
#define 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 #endif //HW_LIB_T_LIST_H

View File

@ -38,7 +38,7 @@ void print(List_t *list) {
} }
} }
void Test_List() { void Test_List(void *pVoid) {
List_t list; List_t list;
list_init(&list); // 初始化链表 list_init(&list); // 初始化链表
@ -102,7 +102,7 @@ void Test_List() {
list_destroy(&list, NULL); // 销毁链表 list_destroy(&list, NULL); // 销毁链表
} }
void Test_Queue() { void Test_Queue(void *pVoid) {
Queue_List_t *deque = newQueue_List(sizeof(int)); // 创建一个int类型的双端队列 Queue_List_t *deque = newQueue_List(sizeof(int)); // 创建一个int类型的双端队列
// 测试入队操作 // 测试入队操作

View File

@ -5,6 +5,6 @@
#ifndef HW_LIB_T_LVGL_H #ifndef HW_LIB_T_LVGL_H
#define 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 #endif //HW_LIB_T_LVGL_H

View File

@ -6,17 +6,42 @@
#include <windows.h> #include <windows.h>
#include "t_lvgl.h" #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_init();
lv_port_disp_init(); lv_port_disp_init();
lv_port_indev_init(); lv_port_indev_init();
// lv_obj_t * bar1 = lv_bar_create(lv_scr_act()); lv_example_get_started_1();
// lv_obj_set_size(bar1, 200, 20);
// lv_obj_center(bar1);
// lv_bar_set_value(bar1, 70, LV_ANIM_OFF);
// lv_demo_widgets(); // lv_demo_widgets();
// printf("\nTEST Widgets\n"); printf("\nTEST Widgets\n");
while (1) { while (1) {
/* Periodically call the lv_task handler. /* Periodically call the lv_task handler.

View File

@ -1,6 +1,6 @@
#ifndef HW_LIB_T_OLED_H #ifndef HW_LIB_T_OLED_H
#define 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 #endif //HW_LIB_T_OLED_H

View File

@ -111,7 +111,7 @@ OLED_T oled = {
.call=Refresh_Call, .call=Refresh_Call,
}; };
void Test_OLED() { void Test_OLED(void *pVoid) {
SIM_OLED_INIT(128, 64, CYAN, 0x0, 5, 0); SIM_OLED_INIT(128, 64, CYAN, 0x0, 5, 0);
SIM_OLED_START(); SIM_OLED_START();

View File

@ -4,5 +4,6 @@
#ifndef HW_LIB_T_SPI_H #ifndef HW_LIB_T_SPI_H
#define 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 #endif //HW_LIB_T_SPI_H

View File

@ -32,7 +32,7 @@ uint8_t Miso_Pin() {
return l; return l;
} }
void Test_spi() { void Test_spi(void *pVoid) {
SW_Dev_Spi ltl = { SW_Dev_Spi ltl = {
.MOSI_SET=Mosi_Pin, .MOSI_SET=Mosi_Pin,
.SCK_SET=Sck_Pin, .SCK_SET=Sck_Pin,

View File

@ -5,6 +5,6 @@
#ifndef HW_LIB_T_TASK_H #ifndef HW_LIB_T_TASK_H
#define 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 #endif //HW_LIB_T_TASK_H

View File

@ -40,7 +40,7 @@ void exampleTimer4Callback(Task_t *task, void *userData) {
} }
} }
void Test_task() { void Test_task(void *pVoid) {
TaskInit(GetTick); TaskInit(GetTick);
TaskCreat(task1, 1000, -1, exampleTimer1Callback, "1000ms CYCLE task"); TaskCreat(task1, 1000, -1, exampleTimer1Callback, "1000ms CYCLE task");
TaskCreat(task2, 5000, -1, exampleTimer2Callback, "5000ms ONCE task"); TaskCreat(task2, 5000, -1, exampleTimer2Callback, "5000ms ONCE task");

View File

@ -1,6 +1,6 @@
#ifndef HW_LIB_T_TFT_H #ifndef HW_LIB_T_TFT_H
#define HW_LIB_T_TFT_H #define HW_LIB_T_TFT_H
void Test_tft(); void Test_tft(void *);
#endif //HW_LIB_T_TFT_H #endif //HW_LIB_T_TFT_H

View File

@ -103,7 +103,7 @@ uint8_t tft_senddata(uint8_t *data, size_t len) {
return result; return result;
} }
void Test_tft() { void Test_tft(void *) {
//设备信息预填充 //设备信息预填充
demo_tft.width = 480;//实际如有支持不用填(如ST7735/7796) demo_tft.width = 480;//实际如有支持不用填(如ST7735/7796)

View File

@ -134,14 +134,6 @@ float Str2Float(char *str);
printf(fmt " ", arr[i]); }\ printf(fmt " ", arr[i]); }\
printf("\n"); } while (0) 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 END "\n"
#define TYPE_F(v) _Generic((v), \ #define TYPE_F(v) _Generic((v), \

View File

@ -5,6 +5,7 @@
#include <ctime> #include <ctime>
#include <stdint.h> #include <stdint.h>
#include <cstdlib> #include <cstdlib>
#include <syncstream>
#include "tool.h" #include "tool.h"
float Mapping(float val, float I_Min, float I_Max, float O_Min, float O_Max) { 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; decimal /= decimalWeight;
return float(sign * (integer + decimal)); 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);
}

18
main.c
View File

@ -11,6 +11,7 @@
#include "t_lvgl.h" #include "t_lvgl.h"
#include "t_tft.h" #include "t_tft.h"
#include "tool.h" #include "tool.h"
#include "sim_test.h"
#include <windows.h> #include <windows.h>
#include <stdint.h> #include <stdint.h>
@ -22,14 +23,15 @@ int main() {
// char str[] = "123.456"; // char str[] = "123.456";
// float result = Str2Float(str); // float result = Str2Float(str);
// printf("Result: %.3f\n", result); // printf("Result: %.3f\n", result);
// Test_RunTime("SPI", Test_spi); Test_Run("SPI", Test_spi);
// Test_RunTime("IIC", Test_iic); Test_Run("IIC", Test_iic);
// Test_RunTime("ArgPase", Test_argpase); Test_Run("ArgPase", Test_argpase);
// Test_RunTime("List", Test_List); Test_Run("List", Test_List);
// Test_RunTime("Key", Test_Key); Test_RunTime("Key", Test_Key);
// Test_RunTime("Queue", Test_Queue); Test_RunTime("Queue", Test_Queue);
// Test_RunTime("Task", Test_task); Test_RunTime("Task", Test_task);
// Test_RunTime("OLED", Test_OLED); Test_RunTime("OLED", Test_OLED);
Test_Run("LVGL", Test_lvgl);
Test_RunTime("TFT", Test_tft); Test_RunTime("TFT", Test_tft);
return 0; return 0;
} }

34
sim/Test/sim_test.cpp Normal file
View File

@ -0,0 +1,34 @@
//
// Created by lydxh on 24-9-21.
//
#include <ctime>
#include <cstdio>
#include <syncstream>
#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);
}

19
sim/Test/sim_test.h Normal file
View File

@ -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

View File

@ -24,7 +24,7 @@
*====================*/ *====================*/
/*Color depth: 1 (1 byte per pixel), 8 (RGB332), 16 (RGB565), 32 (ARGB8888)*/ /*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)*/ /*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 #define LV_COLOR_16_SWAP 0

View File

@ -166,7 +166,7 @@ void colortorgb24(lv_color_t* color_p, uint32_t* color, size_t len)
{ {
while (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_p++;
color++; color++;
len--; len--;