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
#define HW_LIB_T_ARG_H
void Test_argpase();
void Test_argpase(void *pVoid);
#endif //HW_LIB_T_ARG_H

View File

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

View File

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

View File

@ -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("<IIC> RX", readData, TYPE_T(readData), len, 16);
}
}

View File

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

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_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);
}
}
}

View File

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

View File

@ -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);
}
}

View File

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

View File

@ -6,17 +6,42 @@
#include <windows.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_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.

View File

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

View File

@ -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();
}
}

View File

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

View File

@ -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("<SPI> TX[16]", tbuf16, TYPE_T(tbuf16), 64, 16);
BufPrint("<SPI> RX[16]", rbuf16, TYPE_T(rbuf16), 64, 16);
}
}

View File

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

View File

@ -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();
}
}
}

View File

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

View File

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

View File

@ -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), \

View File

@ -5,6 +5,7 @@
#include <ctime>
#include <stdint.h>
#include <cstdlib>
#include <syncstream>
#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);
}

18
main.c
View File

@ -11,6 +11,7 @@
#include "t_lvgl.h"
#include "t_tft.h"
#include "tool.h"
#include "sim_test.h"
#include <windows.h>
#include <stdint.h>
@ -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;
}

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)*/
#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

View File

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