ADD FLASH(flash.h flash.cpp flash_def.h flash_cfg.h flash_sfdp.cpp)

ADD RunTimer(log.h ticks.h ticks.cpp)
ADD sim_key form sdl
This commit is contained in:
JiXieShi
2024-11-27 13:49:34 +08:00
parent 8f7f72712c
commit a1176112ce
29 changed files with 3993 additions and 179 deletions

View File

@@ -170,11 +170,14 @@ 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) {
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_);
}
}
SDL_FRect rect1 = {(x * display->scale) * 1.0f, (y * display->scale) * 1.0f, display->scale * 1.0f,
display->scale * 1.0f};
SDL_RenderFillRect(display->renderer, &rect1);
// 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) {

View File

@@ -1,6 +1,7 @@
#include "sim_key.h"
#include "log.h"
#ifndef USER_SDL3
#include<easyx.h>
#include<conio.h>
@@ -80,4 +81,31 @@ uint8_t SIM_Key_SET(uint8_t) {
uint8_t SIM_Key_RESET(uint8_t) {
return GetAsyncKeyState(VK_END);
}
}
#else
#include "SDL3/SDL.h"
uint8_t SIM_Key_Scan() {
SDL_Event event;
uint8_t key = 0;
SDL_PollEvent(&event);
switch (event.type) {
case SDL_EVENT_QUIT:
return 0;
case SDL_EVENT_KEY_DOWN:
if (event.key.key == SDLK_Q)key = SIM_KEY_SET;
if (event.key.key == SDLK_UP || event.key.key == SDLK_W)key = SIM_KEY_UP;
if (event.key.key == SDLK_DOWN || event.key.key == SDLK_S)key = SIM_KEY_DOWN;
if (event.key.key == SDLK_LEFT || event.key.key == SDLK_A)key = SIM_KEY_LEFT;
if (event.key.key == SDLK_RIGHT || event.key.key == SDLK_D)key = SIM_KEY_RIGHT;
if (event.key.key == SDLK_R)key = SIM_KEY_RESET;
if (event.key.key == SDLK_KP_ENTER || event.key.key == SDLK_E)key = SIM_KEY_ENABLE;
break;
default:
break;
}
return key;
}
#endif

View File

@@ -5,6 +5,9 @@ extern "C" {
#endif
#include "stdint.h"
//是否启用SDL3获取按键事件
#define USER_SDL3
typedef enum Key_map {
SIM_KEY_UP = 1,
SIM_KEY_DOWN,

View File

@@ -736,7 +736,7 @@
====================*/
/*Show some widget. It might be required to increase `LV_MEM_SIZE` */
#define LV_USE_DEMO_WIDGETS 0
#define LV_USE_DEMO_WIDGETS 1
#if LV_USE_DEMO_WIDGETS
#define LV_DEMO_WIDGETS_SLIDESHOW 0
#endif

View File

@@ -91,17 +91,17 @@ void lv_port_disp_init(void)
// lv_disp_draw_buf_init(&draw_buf_dsc_1, buf_1, NULL, MY_DISP_HOR_RES * 10); /*Initialize the display buffer*/
// /* Example for 2) */
// static lv_disp_draw_buf_t draw_buf_dsc_2;
// static lv_color_t buf_2_1[MY_DISP_HOR_RES * 10]; /*A buffer for 10 rows*/
// static lv_color_t buf_2_2[MY_DISP_HOR_RES * 10]; /*An other buffer for 10 rows*/
// lv_disp_draw_buf_init(&draw_buf_dsc_2, buf_2_1, buf_2_2, MY_DISP_HOR_RES * 10); /*Initialize the display buffer*/
static lv_disp_draw_buf_t draw_buf_dsc_2;
static lv_color_t buf_2_1[MY_DISP_HOR_RES * 10]; /*A buffer for 10 rows*/
static lv_color_t buf_2_2[MY_DISP_HOR_RES * 10]; /*An other buffer for 10 rows*/
lv_disp_draw_buf_init(&draw_buf_dsc_2, buf_2_1, buf_2_2, MY_DISP_HOR_RES * 10); /*Initialize the display buffer*/
/* Example for 3) also set disp_drv.full_refresh = 1 below*/
static lv_disp_draw_buf_t draw_buf_dsc_3;
static lv_color_t buf_3_1[MY_DISP_HOR_RES * MY_DISP_VER_RES]; /*A screen sized buffer*/
static lv_color_t buf_3_2[MY_DISP_HOR_RES * MY_DISP_VER_RES]; /*Another screen sized buffer*/
lv_disp_draw_buf_init(&draw_buf_dsc_3, buf_3_1, buf_3_2,
MY_DISP_VER_RES * MY_DISP_HOR_RES); /*Initialize the display buffer*/
// static lv_disp_draw_buf_t draw_buf_dsc_3;
// static lv_color_t buf_3_1[MY_DISP_HOR_RES * MY_DISP_VER_RES]; /*A screen sized buffer*/
// static lv_color_t buf_3_2[MY_DISP_HOR_RES * MY_DISP_VER_RES]; /*Another screen sized buffer*/
// lv_disp_draw_buf_init(&draw_buf_dsc_3, buf_3_1, buf_3_2,
// MY_DISP_VER_RES * MY_DISP_HOR_RES); /*Initialize the display buffer*/
/*-----------------------------------
* Register the display in LVGL
@@ -120,7 +120,7 @@ void lv_port_disp_init(void)
disp_drv.flush_cb = disp_flush;
/*Set a display buffer*/
disp_drv.draw_buf = &draw_buf_dsc_3;
disp_drv.draw_buf = &draw_buf_dsc_2;
/*Required for Example 3)*/
//disp_drv.full_refresh = 1;

View File

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

View File

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