UP 通用OLED
parent
8b0426a9e0
commit
a1624f0682
|
@ -20,4 +20,4 @@ add_executable(HW_Lib main.c ${SOURCES})
|
|||
|
||||
#导入库
|
||||
add_subdirectory(lib)
|
||||
target_link_libraries(HW_Lib HW_LIB_List HW_LIB_Task HW_LIB_Printf HW_LIB_Utils HW_LIB_Iic HW_LIB_Spi HW_LIB_Key)
|
||||
target_link_libraries(HW_Lib HW_LIB_List HW_LIB_Task HW_LIB_Printf HW_LIB_Utils HW_LIB_Iic HW_LIB_Spi HW_LIB_Key HW_LIB_Oled)
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef HW_LIB_T_OLED_H
|
||||
#define HW_LIB_T_OLED_H
|
||||
|
||||
void Test_OLED();
|
||||
|
||||
#endif //HW_LIB_T_OLED_H
|
|
@ -0,0 +1,42 @@
|
|||
#include <stdio.h>
|
||||
#include "oled.h"
|
||||
#include "log.h"
|
||||
#include "tool.h"
|
||||
#include "t_oled.h"
|
||||
#include <windows.h>
|
||||
|
||||
uint8_t Cmd(uint8_t *data, size_t l) {
|
||||
Buf_Print("Cmd", data, l, 16);
|
||||
}
|
||||
|
||||
uint8_t Data(uint8_t *data, size_t l) {
|
||||
Buf_Print("Data", data, l, 16);
|
||||
}
|
||||
|
||||
void Refresh_Call(OLED_T *dev) {
|
||||
LOGT("OLED", "CALL");
|
||||
Buf_Print("Buf", dev->buf, dev->width * (dev->height / 8), 16);
|
||||
}
|
||||
|
||||
uint8_t oledbuf[8][128];
|
||||
|
||||
void Test_OLED() {
|
||||
OLED_T oled = {
|
||||
.height=64,
|
||||
.width=128,
|
||||
.state=IDLE,
|
||||
.buf=oledbuf,
|
||||
.call=Refresh_Call,
|
||||
.cmd=Cmd,
|
||||
.data=Data
|
||||
};
|
||||
OLED_Init(&oled);
|
||||
Sleep(150);
|
||||
OLED_CLS(&oled);
|
||||
OLED_ShowString(&oled, 0, 0, "sss", 4);
|
||||
while (1) {
|
||||
// 每5ms调用一次key_ticks函数
|
||||
OLED_Refresh(&oled);
|
||||
Sleep(5); // 使用Windows平台的Sleep函数进行5ms延时
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ extern "C" {
|
|||
#include "stdint.h"
|
||||
|
||||
|
||||
#define REFRESH_CALL_ENABLE 1 //使用DMA或者需要收到刷新完毕通知的回调函数
|
||||
#define REFRESH_CALL_ENABLE 1 //使用DMA或者整体刷新函数
|
||||
|
||||
|
||||
/**
|
||||
|
@ -33,9 +33,9 @@ typedef uint8_t (*OLED_DATA_t)(uint8_t *data, size_t len);
|
|||
|
||||
#if REFRESH_CALL_ENABLE
|
||||
/**
|
||||
* @brief OLED刷新完毕回调指针类型
|
||||
* @brief OLED刷新函数指针类型
|
||||
*/
|
||||
typedef void (*OLED_REFRESH_t)();
|
||||
typedef void (*OLED_REFRESH_t)(OLED_T *dev);
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -58,7 +58,7 @@ struct OLED_Dev {
|
|||
OLED_CMD_t cmd; /**< OLED命令处理函数指针 */
|
||||
OLED_DATA_t data; /**< OLED数据处理函数指针 */
|
||||
#if REFRESH_CALL_ENABLE
|
||||
OLED_REFRESH_t call; /**< OLED刷新完毕回调函数指针 */
|
||||
OLED_REFRESH_t call; /**< OLED刷新函数指针 */
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -76,7 +76,7 @@ const uint8_t initCmd[] = {
|
|||
2, 0xDA, 0x12, // 设置COM引脚硬件配置
|
||||
2, 0x81, 0xCF, // 设置对比度控制
|
||||
2, 0xD9, 0xF1, // 设置预充电周期
|
||||
2, 0xDB, 0x40, // 设置VCOMH取消电平
|
||||
2, 0xDB, 0x20, // 设置VCOMH取消电平
|
||||
2, 0xA4, 0xA6, // 整个显示打开
|
||||
1, 0xAF // 打开显示
|
||||
};
|
||||
|
@ -208,6 +208,23 @@ void OLED_ShowString(OLED_T *dev, uint8_t x, uint8_t y, uint8_t *chr, uint8_t si
|
|||
*/
|
||||
void OLED_SPos(OLED_T *dev, uint8_t x, uint8_t y);
|
||||
|
||||
/**
|
||||
* @brief 填充OLED显示缓冲区
|
||||
* @param dev: [输入] OLED设备指针
|
||||
* @param data: [输入] 填充数据
|
||||
* @return void
|
||||
* @example OLED_Fill(&oled_dev, 0xFF);
|
||||
*/
|
||||
void OLED_Fill(OLED_T *dev, uint8_t data);
|
||||
|
||||
/**
|
||||
* @brief 清空OLED显示缓冲区
|
||||
* @param dev: [输入] OLED设备指针
|
||||
* @return void
|
||||
* @example OLED_CLS(&oled_dev);
|
||||
*/
|
||||
void OLED_CLS(OLED_T *dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -44,10 +44,11 @@ void OLED_Turn(OLED_T *dev, bool e) {
|
|||
}
|
||||
|
||||
void OLED_Refresh(OLED_T *dev) {
|
||||
uint8_t i, cmd[3] = {0xb0, 0x00, 0x10};
|
||||
|
||||
#if REFRESH_CALL_ENABLE
|
||||
dev->call();
|
||||
dev->call(dev);
|
||||
#else
|
||||
uint8_t i, cmd[3] = {0xb0, 0x00, 0x10};
|
||||
if (dev->state == IDLE) {
|
||||
dev->state = REFRESH;
|
||||
for (i = 0; i < (dev->height >> 3); i++) {
|
||||
|
|
4
main.c
4
main.c
|
@ -7,6 +7,7 @@
|
|||
#include "t_arg.h"
|
||||
#include "t_list.h"
|
||||
#include "t_key.h"
|
||||
#include "t_oled.h"
|
||||
#include "tool.h"
|
||||
#include <time.h>
|
||||
|
||||
|
@ -25,6 +26,7 @@ int main() {
|
|||
Test_RunTime("List", Test_List);
|
||||
Test_RunTime("Queue", Test_Queue);
|
||||
// Test_RunTime("Task", Test_task);
|
||||
Test_RunTime("Key", Test_Key);
|
||||
Test_RunTime("OLED", Test_OLED);
|
||||
// Test_RunTime("Key", Test_Key);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue