UP 通用OLED

main
JiXieShi 2024-06-22 15:21:15 +08:00
parent 8b0426a9e0
commit a1624f0682
6 changed files with 77 additions and 9 deletions

View File

@ -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)

6
demo/oled/t_oled.h Normal file
View File

@ -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

42
demo/oled/test.c Normal file
View File

@ -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延时
}
}

View File

@ -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

View File

@ -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
View File

@ -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;
}