UP 增加OLED模拟器
This commit is contained in:
54
sim/oled/oled.cpp
Normal file
54
sim/oled/oled.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "sim_oled.h"
|
||||
#include "graphics.h"
|
||||
#include <conio.h>
|
||||
|
||||
static uint32_t pixelColor, backgroundColor;
|
||||
static int scaleFactor;
|
||||
static bool border;
|
||||
|
||||
void SIM_OLED_INIT(uint32_t pixcolor, uint32_t backcolor, int scale, bool b) {
|
||||
pixelColor = pixcolor;
|
||||
backgroundColor = backcolor;
|
||||
scaleFactor = scale;
|
||||
border = b;
|
||||
}
|
||||
|
||||
void SIM_OLED_START() {
|
||||
initgraph(WIDTH, HEIGHT);
|
||||
setbkcolor(backgroundColor); // 设置背景色为黑色
|
||||
setfillcolor(pixelColor);
|
||||
cleardevice(); // 清空屏幕
|
||||
}
|
||||
|
||||
void SIM_OLED_STOP() {
|
||||
getch();
|
||||
closegraph();
|
||||
}
|
||||
|
||||
void drawOledPixel(int oledX, int oledY, int blockSize) {
|
||||
int startX = oledX * blockSize;
|
||||
int startY = oledY * blockSize;
|
||||
if (border)
|
||||
fillrectangle(startX, startY, startX + blockSize, startY + blockSize);
|
||||
if (!border)
|
||||
solidrectangle(startX, startY, startX + blockSize, startY + blockSize);
|
||||
}
|
||||
|
||||
#define GET_BIT(x, bit) ((x & (1 << bit)) >> bit)
|
||||
|
||||
void SIM_OLED_DrawFromBuffer(uint8_t *buf, uint8_t width, uint8_t height) {
|
||||
cleardevice();
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
uint8_t byteData = buf[y * width + x];
|
||||
for (int i = 0; i < 8; i++) {
|
||||
uint8_t bit = GET_BIT(byteData, i);
|
||||
if (bit)
|
||||
drawOledPixel(x, y * 8 + (i), scaleFactor); // 这里假设 OLED 像素点大小为一个bit,对应的 EasyX 像素块大小为 10x10
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
51
sim/oled/sim_oled.h
Normal file
51
sim/oled/sim_oled.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef HW_LIB_SIM_OLED_H
|
||||
#define HW_LIB_SIM_OLED_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
#define WIDTH 1280
|
||||
#define HEIGHT 640
|
||||
|
||||
/**
|
||||
* @brief 初始化模拟 OLED 显示
|
||||
* @param pixcolor: [输入] 像素颜色
|
||||
* @param backcolor: [输入] 背景颜色
|
||||
* @param scale: [输入] 显示缩放比例
|
||||
* @param border: [输入] 是否显示边框
|
||||
* @return void
|
||||
* @example SIM_OLED_INIT(0xFFFF00, 0x000000, 2, true);
|
||||
**/
|
||||
void SIM_OLED_INIT(uint32_t pixcolor, uint32_t backcolor, int scale, bool border);
|
||||
|
||||
/**
|
||||
* @brief 开始模拟 OLED 显示
|
||||
* @return void
|
||||
* @example SIM_OLED_START();
|
||||
**/
|
||||
void SIM_OLED_START();
|
||||
|
||||
/**
|
||||
* @brief 停止模拟 OLED 显示
|
||||
* @return void
|
||||
* @example SIM_OLED_STOP();
|
||||
**/
|
||||
void SIM_OLED_STOP();
|
||||
|
||||
/**
|
||||
* @brief 从缓冲区绘制到模拟 OLED 显示
|
||||
* @param buf: [输入] 缓冲区指针
|
||||
* @param width: [输入] 图像宽度
|
||||
* @param height: [输入] 图像高度
|
||||
* @return void
|
||||
* @example SIM_OLED_DrawFromBuffer(buffer, 128, 64);
|
||||
**/
|
||||
void SIM_OLED_DrawFromBuffer(uint8_t *buf, uint8_t width, uint8_t height);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //HW_LIB_SIM_OLED_H
|
Reference in New Issue
Block a user