HW_Lib/sim/display/sim_display.h

225 lines
6.6 KiB
C
Raw Normal View History

2024-07-05 15:38:31 +00:00
//
// Created by lydxh on 24-7-5.
//
#ifndef HW_LIB_SIM_DISPLAY_H
#define HW_LIB_SIM_DISPLAY_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stdint.h"
2024-09-21 12:43:31 +00:00
//是否启用SDL3画图
#define USER_SDL3
2024-07-05 15:38:31 +00:00
/**
* @brief
*/
#define BLACK 0 // 黑色
#define BLUE 0xAA0000 // 蓝色
#define GREEN 0x00AA00 // 绿色
#define CYAN 0xAAAA00 // 青色
#define RED 0x0000AA // 红色
#define MAGENTA 0xAA00AA // 品红
#define BROWN 0x0055AA // 棕色
#define LIGHTGRAY 0xAAAAAA // 亮灰色
#define DARKGRAY 0x555555 // 暗灰色
#define LIGHTBLUE 0xFF5555 // 亮蓝色
#define LIGHTGREEN 0x55FF55 // 亮绿色
#define LIGHTCYAN 0xFFFF55 // 亮青色
#define LIGHTRED 0x5555FF // 亮红色
#define LIGHTMAGENTA 0xFF55FF // 亮品红
#define YELLOW 0x55FFFF // 黄色
#define WHITE 0xFFFFFF // 白色
2024-09-21 12:43:31 +00:00
#ifndef USER_SDL3
2024-07-05 15:38:31 +00:00
/**
* @brief
* @param width: []
* @param height: []
* @param pixcolor: []
* @param backcolor: []
* @param scale: []
* @param border: []
* @return void
* @example SIM_Display_INIT(128, 64, 0xFFFF00, 0x000000, 10, 1);
**/
void SIM_Display_INIT(int width, int height, uint32_t pixcolor, uint32_t backcolor, int scale, uint8_t border);
/**
* @brief
* @return void
* @example SIM_Display_START();
**/
void SIM_Display_START();
/**
* @brief
* @return void
* @example SIM_OLED_STOP();
**/
void SIM_Display_STOP();
/**
* @brief
* @param buf: []
* @param width: []
* @param height: []
* @return void
* @example SIM_OneColor_DrawFromBuffer(buffer, 128, 64);
**/
void SIM_OneColor_DrawFromBuffer(uint8_t *buf, uint16_t width, uint16_t height);
2024-09-21 04:48:44 +00:00
/**
* @brief
* @param color
* @param x x
* @param y y
*/
void SIM_Color_DrawPiexl(uint32_t color, uint16_t x, uint16_t y);
void SIM_Color_DrawHLineBuffer(uint32_t *buf, uint16_t x, uint16_t y, uint16_t width);
2024-07-05 15:38:31 +00:00
/**
* @brief
* @param buf: []
* @param width: []
* @param height: []
* @return void
* @example SIM_Color_DrawFromBuffer(buffer, 480, 320);
**/
void SIM_Color_DrawFromBuffer(uint32_t *buf, uint16_t width, uint16_t height);
2024-08-29 08:46:54 +00:00
/**
* @brief
* @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(uint32_t* buf, uint16_t x, uint16_t y, uint16_t width, uint16_t height);
/**
* @brief
* @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(uint32_t* buf, uint16_t xs, uint16_t ys, uint16_t xe, uint16_t ye);
2024-09-21 12:43:31 +00:00
#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);
2024-09-21 15:07:22 +00:00
/**
* @brief
* @param display
* @param buf
* @param width
* @param height
*/
2024-09-21 12:43:31 +00:00
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);
**/
2024-09-21 15:07:22 +00:00
void SIM_Color_ImgFromBuffer(SIM_Display_t *display, uint32_t *buf, uint16_t x, uint16_t y,
uint16_t width, uint16_t height);
2024-09-21 12:43:31 +00:00
/**
* @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);
2024-09-21 15:07:22 +00:00
/**
* @brief
*
* @param display
*/
void SIM_Display_Refresh(SIM_Display_t *display);
2024-09-21 12:43:31 +00:00
/**
* @brief
* @return void
* @example SIM_OLED_STOP();
**/
void SIM_Display_STOP(SIM_Display_t *display);
#endif
2024-08-29 08:46:54 +00:00
2024-09-21 15:07:22 +00:00
uint32_t RGB565_to_ARGB8888(uint16_t rgb565, bool isBGR);
2024-09-21 04:48:44 +00:00
2024-07-05 15:38:31 +00:00
#ifdef __cplusplus
}
#endif
#endif //HW_LIB_SIM_DISPLAY_H