UP 增加OLED模拟器
This commit is contained in:
@@ -32,10 +32,12 @@ typedef uint8_t (*OLED_CMD_t)(uint8_t *data, size_t len);
|
||||
typedef uint8_t (*OLED_DATA_t)(uint8_t *data, size_t len);
|
||||
|
||||
#if REFRESH_CALL_ENABLE
|
||||
|
||||
/**
|
||||
* @brief OLED刷新函数指针类型
|
||||
*/
|
||||
typedef void (*OLED_REFRESH_t)(OLED_T *dev);
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -63,22 +65,39 @@ struct OLED_Dev {
|
||||
};
|
||||
|
||||
// OLED初始化指令数组
|
||||
//const uint8_t initCmd[] = {
|
||||
// 1, 0xAE, // 关闭显示
|
||||
// 2, 0xD5, 0x80, // 设置显示时钟分频比/振荡器频率
|
||||
// 2, 0xA8, 0x3F, // 设置多路复用比率
|
||||
// 2, 0xD3, 0x00, // 设置显示偏移
|
||||
// 2, 0x40, 0x00, // 设置显示起始行
|
||||
// 2, 0x8D, 0x14, // 电荷泵设置
|
||||
// 2, 0x20, 0x00, // 设置内存寻址模式
|
||||
// 1, 0xA0, // 设置段重映射
|
||||
// 1, 0xC0, // 设置COM输出扫描方向
|
||||
// 2, 0xDA, 0x12, // 设置COM引脚硬件配置
|
||||
// 2, 0x81, 0xCF, // 设置对比度控制
|
||||
// 2, 0xD9, 0xF1, // 设置预充电周期
|
||||
// 2, 0xDB, 0x20, // 设置VCOMH取消电平
|
||||
// 2, 0xA4, 0xA6, // 整个显示打开
|
||||
// 1, 0xAF // 打开显示
|
||||
//};
|
||||
const uint8_t initCmd[] = {
|
||||
1, 0xAE, // 关闭显示
|
||||
2, 0xD5, 0x80, // 设置显示时钟分频比/振荡器频率
|
||||
2, 0xA8, 0x3F, // 设置多路复用比率
|
||||
2, 0xD3, 0x00, // 设置显示偏移
|
||||
2, 0x40, 0x00, // 设置显示起始行
|
||||
2, 0x8D, 0x14, // 电荷泵设置
|
||||
2, 0x20, 0x00, // 设置内存寻址模式
|
||||
1, 0xA0, // 设置段重映射
|
||||
1, 0xC0, // 设置COM输出扫描方向
|
||||
2, 0xDA, 0x12, // 设置COM引脚硬件配置
|
||||
2, 0x81, 0xCF, // 设置对比度控制
|
||||
2, 0xD9, 0xF1, // 设置预充电周期
|
||||
2, 0xDB, 0x20, // 设置VCOMH取消电平
|
||||
2, 0xA4, 0xA6, // 整个显示打开
|
||||
1, 0xAF // 打开显示
|
||||
0xAE, // 关闭显示
|
||||
0xD5, 0x80, // 设置显示时钟分频比/振荡器频率
|
||||
0xA8, 0x3F, // 设置多路复用比率
|
||||
0xD3, 0x00, // 设置显示偏移
|
||||
0x40, 0x00, // 设置显示起始行
|
||||
0x8D, 0x14, // 电荷泵设置
|
||||
0x20, 0x00, // 设置内存寻址模式
|
||||
0xA0, // 设置段重映射
|
||||
0xC0, // 设置COM输出扫描方向
|
||||
0xDA, 0x12, // 设置COM引脚硬件配置
|
||||
0x81, 0xCF, // 设置对比度控制
|
||||
0xD9, 0xF1, // 设置预充电周期
|
||||
0xDB, 0x20, // 设置VCOMH取消电平
|
||||
0xA4, 0xA6, // 整个显示打开
|
||||
0xAF // 打开显示
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -163,6 +182,18 @@ void OLED_RSet(OLED_T *dev, uint8_t x, uint8_t y);
|
||||
*/
|
||||
void OLED_DrawLine(OLED_T *dev, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
|
||||
|
||||
/**
|
||||
* @brief 在 OLED 上绘制矩形
|
||||
* @param dev: [输入] OLED 设备指针
|
||||
* @param x1: [输入] 矩形左上角 x 坐标
|
||||
* @param y1: [输入] 矩形左上角 y 坐标
|
||||
* @param x2: [输入] 矩形右下角 x 坐标
|
||||
* @param y2: [输入] 矩形右下角 y 坐标
|
||||
* @return void
|
||||
* @example OLED_DrawRect(&oledDevice, 10, 10, 50, 30);
|
||||
**/
|
||||
void OLED_DrawRect(OLED_T *dev, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
|
||||
|
||||
/**
|
||||
* @brief 绘制圆
|
||||
* @param dev: [输入] OLED设备指针
|
||||
|
@@ -1,18 +1,19 @@
|
||||
#include "oled.h"
|
||||
#include "oled_font.h"
|
||||
|
||||
#define BUFPOINT(x, i) (*(dev->buf + x + (i * dev->width)))
|
||||
#define BUFPOINT(x, y) (*(dev->buf + x + (y * dev->width)))
|
||||
|
||||
void OLED_Init(OLED_T *dev) {
|
||||
uint8_t *cmdIndex = (uint8_t *) initCmd;
|
||||
uint8_t count, temp;
|
||||
while (*cmdIndex) {
|
||||
temp = *cmdIndex++;
|
||||
count = temp & 0x7F;
|
||||
|
||||
dev->cmd(cmdIndex, count);
|
||||
cmdIndex += count;
|
||||
}
|
||||
// uint8_t count, temp;
|
||||
// while (*cmdIndex) {
|
||||
// temp = *cmdIndex++;
|
||||
// count = temp & 0x7F;
|
||||
//
|
||||
// dev->cmd(cmdIndex, count);
|
||||
// cmdIndex += count;
|
||||
// }
|
||||
dev->cmd(cmdIndex, sizeof(initCmd));
|
||||
dev->state = IDLE;
|
||||
}
|
||||
|
||||
@@ -119,6 +120,13 @@ void OLED_DrawLine(OLED_T *dev, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2)
|
||||
}
|
||||
}
|
||||
|
||||
void OLED_DrawRect(OLED_T *dev, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) {
|
||||
OLED_DrawLine(dev, x1, y1, x2, y1); // Top side
|
||||
OLED_DrawLine(dev, x1, y1, x1, y2); // Left side
|
||||
OLED_DrawLine(dev, x2, y1, x2, y2); // Right side
|
||||
OLED_DrawLine(dev, x1, y2, x2, y2); // Bottom side
|
||||
}
|
||||
|
||||
void OLED_DrawCircle(OLED_T *dev, uint8_t x, uint8_t y, uint8_t r) {
|
||||
int a, b, num;
|
||||
a = 0;
|
||||
|
Reference in New Issue
Block a user