From c784f3ca9699e997ce5d1a749c18dc55f508bd76 Mon Sep 17 00:00:00 2001 From: JiXieShi Date: Sat, 22 Jun 2024 16:41:48 +0800 Subject: [PATCH] =?UTF-8?q?UP=20=E9=80=9A=E7=94=A8OLED?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/oled/test.c | 24 +++++++++--------------- lib/inc/oled/oled.h | 6 +++--- lib/src/oled/oled.cpp | 3 +-- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/demo/oled/test.c b/demo/oled/test.c index 6948eb4..31b9862 100644 --- a/demo/oled/test.c +++ b/demo/oled/test.c @@ -3,40 +3,34 @@ #include "log.h" #include "tool.h" #include "t_oled.h" -#include -uint8_t Cmd(uint8_t *data, size_t l) { +void Cmd(uint8_t *data, size_t l) { Buf_Print("Cmd", data, l, 16); } -uint8_t Data(uint8_t *data, size_t l) { +void 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); + BufPrint("Buf", dev->buf, T_U8, dev->width * (dev->height / 8), 16); } -uint8_t oledbuf[8][128]; +uint8_t oledbuf[8][128] = {0}; void Test_OLED() { OLED_T oled = { - .height=64, + .height=(uint8_t) 64, .width=128, .state=IDLE, .buf=oledbuf, - .call=Refresh_Call, .cmd=Cmd, - .data=Data + .data=Data, + .call=Refresh_Call, }; 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延时 - } + OLED_ShowString(&oled, 0, 0, "Hello", 12); + OLED_Refresh(&oled); } \ No newline at end of file diff --git a/lib/inc/oled/oled.h b/lib/inc/oled/oled.h index 37c0b75..b346dd2 100644 --- a/lib/inc/oled/oled.h +++ b/lib/inc/oled/oled.h @@ -52,9 +52,9 @@ typedef enum { */ struct OLED_Dev { uint8_t *buf; /**< 显示缓冲区指针 */ - uint8_t width: 3; /**< 显示宽度 */ - uint8_t height: 3; /**< 显示高度 */ - OLED_STATE_T state: 2; /**< OLED状态 */ + uint8_t width; /**< 显示宽度 */ + uint8_t height; /**< 显示高度 */ + OLED_STATE_T state; /**< OLED状态 */ OLED_CMD_t cmd; /**< OLED命令处理函数指针 */ OLED_DATA_t data; /**< OLED数据处理函数指针 */ #if REFRESH_CALL_ENABLE diff --git a/lib/src/oled/oled.cpp b/lib/src/oled/oled.cpp index 7bbc77f..1b1edf0 100644 --- a/lib/src/oled/oled.cpp +++ b/lib/src/oled/oled.cpp @@ -44,7 +44,6 @@ void OLED_Turn(OLED_T *dev, bool e) { } void OLED_Refresh(OLED_T *dev) { - #if REFRESH_CALL_ENABLE dev->call(dev); #else @@ -56,7 +55,7 @@ void OLED_Refresh(OLED_T *dev) { dev->cmd(cmd, 3); dev->data(dev->buf + (i * dev->width), dev->width); } - dev->state=IDLE; + dev->state = IDLE; } #endif }