UP 准备加入彩屏支持

main
jixishi 2024-07-05 23:38:31 +08:00
parent 7719984a6e
commit 899dcdd294
6 changed files with 158 additions and 74 deletions

View File

@ -119,22 +119,9 @@ void Test_OLED() {
OLED_Init(&oled); OLED_Init(&oled);
OLED_CLS(&oled); OLED_CLS(&oled);
uint8_t buft[13] = {0x6C, 0x14, 0x6C, 0xE1, 0x5F, 0x0F, 0x6D, 0xB2, 0x4F, 0x4D, 0x8B, 0xA1, 0x00};
// OLED_ShowCHString(&oled, 16, 1, buft);
uint8_t sbuf[30] = {0};
uint8_t bufx[8] = {0x5F, 0x53, 0x52, 0x4D, 0x6D, 0xB2, 0x4F, 0x4D};
sprintf(sbuf, "%s: 13.4271m\0", bufx);
// OLED_ShowCHString(&oled, 1, 24, sbuf);
OLED_ShowCHString(&oled, 1, 24, "姓名学号:2233"); OLED_ShowCHString(&oled, 1, 24, "姓名学号:2233");
OLED_DrawRect(&oled, 0, 0, 127, 63); OLED_DrawRect(&oled, 0, 0, 127, 63);
// };//
// char buf[30] = {0x60,0x6F,0x59, 0xD3,0x54, 0x0D,0x6B, 0x66,0x65, 0xED,0x73, 0xED,0x7E, 0xA7,0x4F, 0xE1,0x60, 0x6F,0x66, 0x3E,0x79, 0x3A,0x56, 0xFE,0x72, 0x47,0x89, 0xC6,0x98, 0x91,0x4E, 0x13,0x4E, 0x1A,0x75, 0x35,0x5B, 0x50,};
//
// uint8_t sbuf[30] = {0};
// sprintf(sbuf, "%sC\0", buf);
// OLED_ShowCHString(&oled, 1, 16, sbuf);
OLED_Refresh(&oled); OLED_Refresh(&oled);

View File

@ -9,9 +9,9 @@ extern "C" {
#define REFRESH_CALL_ENABLE 1 //使用DMA或者整体刷新函数 #define REFRESH_CALL_ENABLE 1 //使用DMA或者整体刷新函数
#define HZK_FONT #define HZK_FONT //使用HZK 12/16 字体 tools下可自由生成
#define UTF8_TO_UNICODE #define UTF8_TO_UNICODE //启用UTF8转换显示
//#define LVGL_FONT //#define LVGL_FONT //启用LVGL字体
/** /**
* @brief OLED * @brief OLED

View File

@ -0,0 +1,66 @@
#include "sim_display.h"
#include "graphics.h"
#include <conio.h>
static uint32_t pixelColor, backgroundColor;
static int scaleFactor, w, h;
uint8_t border;
#define GET_BIT(x, bit) ((x & (1 << bit)) >> bit)
void SIM_Display_INIT(int width, int height, uint32_t pixcolor, uint32_t backcolor, int scale, uint8_t b) {
w = width * scale;
h = height * scale;
pixelColor = pixcolor;
backgroundColor = backcolor;
scaleFactor = scale;
border = b;
}
void SIM_Display_START() {
initgraph(w, h);
setbkcolor(backgroundColor);
setfillcolor(pixelColor);
cleardevice();
}
void SIM_Display_STOP() {
closegraph();
}
void drawPixel(int oledX, int oledY) {
int startX = oledX * scaleFactor;
int startY = oledY * scaleFactor;
if (border) fillrectangle(startX + 1, startY + 1, startX + scaleFactor - 1, startY + scaleFactor - 1);
else solidrectangle(startX, startY, startX + scaleFactor, startY + scaleFactor);
}
void SIM_OneColor_DrawFromBuffer(uint8_t *buf, uint16_t width, uint16_t height) {
BeginBatchDraw();
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)drawPixel(x, y * 8 + i);
}
}
}
EndBatchDraw();
}
void SIM_Color_DrawFromBuffer(uint32_t *buf, uint16_t width, uint16_t height){
BeginBatchDraw();
cleardevice();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
setfillcolor(*buf);
drawPixel(x, y);
buf++;
}
}
EndBatchDraw();
}

84
sim/display/sim_display.h Normal file
View File

@ -0,0 +1,84 @@
//
// 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"
/**
* @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 // 白色
/**
* @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);
/**
* @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);
#ifdef __cplusplus
}
#endif
#endif //HW_LIB_SIM_DISPLAY_H

View File

@ -2,53 +2,20 @@
#include "graphics.h" #include "graphics.h"
#include <conio.h> #include <conio.h>
static uint32_t pixelColor, backgroundColor;
static int scaleFactor, w, h;
uint8_t border;
#define GET_BIT(x, bit) ((x & (1 << bit)) >> bit)
void SIM_OLED_INIT(int width, int height, uint32_t pixcolor, uint32_t backcolor, int scale, uint8_t b) { void SIM_OLED_INIT(int width, int height, uint32_t pixcolor, uint32_t backcolor, int scale, uint8_t b) {
w = width * scale; SIM_Display_INIT(width,height,pixcolor,backcolor,scale,b);
h = height * scale;
pixelColor = pixcolor;
backgroundColor = backcolor;
scaleFactor = scale;
border = b;
} }
void SIM_OLED_START() { void SIM_OLED_START() {
initgraph(w, h); SIM_Display_START();
setbkcolor(backgroundColor);
setfillcolor(pixelColor);
cleardevice();
} }
void SIM_OLED_STOP() { void SIM_OLED_STOP() {
closegraph(); SIM_Display_STOP();
} }
void drawOledPixel(int oledX, int oledY) {
int startX = oledX * scaleFactor;
int startY = oledY * scaleFactor;
if (border) fillrectangle(startX + 1, startY + 1, startX + scaleFactor - 1, startY + scaleFactor - 1);
else solidrectangle(startX, startY, startX + scaleFactor, startY + scaleFactor);
}
void SIM_OLED_DrawFromBuffer(uint8_t *buf, uint8_t width, uint8_t height) { void SIM_OLED_DrawFromBuffer(uint8_t *buf, uint8_t width, uint8_t height) {
BeginBatchDraw(); SIM_OneColor_DrawFromBuffer(buf,width,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);
}
}
}
EndBatchDraw();
} }

View File

@ -4,27 +4,7 @@
extern "C" { extern "C" {
#endif #endif
#include "stdint.h" #include "sim_display.h"
/**
* @brief OLED
*/
#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 // 白色
/** /**
* @brief OLED * @brief OLED