jixishi 2024-06-26 15:54:30 +08:00
parent 8c8cf20056
commit 11b8128796
12 changed files with 366 additions and 181 deletions

View File

@ -1,13 +1,17 @@
#include <stdio.h>
#include "page.h"
#include "list.h"
#include "bmp.h"
uint8_t pageid = 0, cur = 1, cnt = 0, item_h = 12;
uint8_t pageid = 0, cur = 1, cnt = 0, item_h = 16, item_w = 0;
uint8_t cnt_f=1;
static List_t list;
Page_L_t mainp = {0, 3, 0, 1, 12, mainpage};
Page_L_t ap = {1, 2, 0, 1, 12, pageA};
Page_L_t bp = {2, 2, 0, 1, 12, pageB};
Page_L_t cp = {3, 2, 0, 1, 12, pageC};
Page_L_t mainp = {0, 0, 0, 0, 1, 16, 16, mainpage};
Page_L_t ap = {1, 2, 1, 0, 1, 12, 36, pageA};
Page_L_t bp = {2, 2, 1, 0, 2, 12, 36, pageB};
Page_L_t cp = {3, 2, 1, 0, 3, 12, 36, pageC};
Page_L_t ip = {4, 0, 0, 0, 4, 0, 0, pageImg};
void pageinit() {
list_init(&list);
@ -15,6 +19,7 @@ void pageinit() {
list_insert(&list, &ap);
list_insert(&list, &bp);
list_insert(&list, &cp);
list_insert(&list, &ip);
}
int compare_page(const void *s1, const void *s2) {
@ -32,17 +37,28 @@ Page_L_t pagesearch(uint8_t id) {
void pagecur(OLED_T *dev) {
if (cnt % 2) {
OLED_ShowString(dev, 26, cur * item_h, ">", item_h);
if (pagesearch(pageid).curmin != pagesearch(pageid).curmax&&pagesearch(pageid).item_h != 0) {
OLED_ShowString(dev, item_w - item_h, cur * item_h, ">", item_h);
}
}
if(cnt_f){
cnt++;
}
cnt++;
}
void mainpage(OLED_T *dev) {
OLED_CLS(dev);
OLED_ShowString(dev, 32, 0, "Main Page", 12);
OLED_ShowString(dev, 36, 12, "1.PageA", 12);
OLED_ShowString(dev, 36, 24, "2.PageB", 12);
OLED_ShowString(dev, 36, 36, "3.PageC", 12);
uint8_t fsbuf[16] = {0};
sprintf(fsbuf,"%c%c%c%c%c%c%c%c",0x4F, 0xE1 ,0x60, 0x6F,0x66, 0x3E,0x79, 0x3A);
OLED_ShowCHString(dev, 32, 0 * item_h, fsbuf);
sprintf(fsbuf,"%c%c%c%c%c%c%c%c%c",0x59, 0xD3 ,0x54, 0x0D,':',0x6B, 0x66,0x65, 0xED);
OLED_ShowCHString(dev, 12, 1 * item_h, fsbuf);
sprintf(fsbuf,"%c%c%c%c:ZB211",0x73, 0xED ,0x7E, 0xA7);
OLED_ShowCHString(dev, 12, 2 * item_h, fsbuf);
sprintf(fsbuf,"%c%c%c%c:%c%c%c%c%c%c%c%c",0x4E, 0x13 ,0x4E, 0x1A ,0x75, 0x35,0x5B, 0x50,0x4F, 0xE1 ,0x60, 0x6F);
OLED_ShowCHString(dev, 12, 3 * item_h, fsbuf);
pagecur(dev);
}
@ -69,3 +85,30 @@ void pageC(OLED_T *dev) {
OLED_ShowString(dev, 36, 24, " back", 12);
pagecur(dev);
}
void pageImg(OLED_T *dev) {
OLED_CLS(dev);
switch (cnt % 6) {
case 0:
OLED_ShowPic(dev, 0, 0, 64, 64, BMP1);
break;
case 1:
OLED_ShowPic(dev, 0, 0, 64, 64, BMP2);
break;
case 2:
OLED_ShowPic(dev, 0, 0, 64, 64, BMP3);
break;
case 3:
OLED_ShowPic(dev, 0, 0, 64, 64, BMP4);
break;
case 4:
OLED_ShowPic(dev, 0, 0, 64, 64, BMP5);
break;
case 5:
OLED_ShowPic(dev, 0, 0, 64, 64, BMP6);
break;
default:
break;
}
pagecur(dev);
}

View File

@ -5,14 +5,16 @@
typedef void (*Page_t)(OLED_T *dev);
extern uint8_t pageid, cur, cnt, item_h;
extern uint8_t pageid, cur, cnt, item_h, item_w;
extern uint8_t cnt_f;
typedef struct Page_L {
uint8_t id;
uint8_t curmax: 3;
uint8_t back;
uint8_t curmin: 3;
uint8_t item_h: 4;
uint8_t id: 4;
uint8_t curmax: 4;
uint8_t curmin: 4;
uint8_t back: 4;
uint8_t next: 4;
uint8_t item_h:6;
uint8_t item_w: 7;
Page_t page;
} Page_L_t;
@ -27,5 +29,6 @@ void pageA(OLED_T *dev);
void pageB(OLED_T *dev);
void pageC(OLED_T *dev);
void pageImg(OLED_T *dev);
#endif //HW_LIB_PAGE_H

View File

@ -8,7 +8,6 @@
#include "key.h"
#include "sim_key.h"
#include "page.h"
#include "bmp.h"
uint8_t Cmd(uint8_t *data, size_t l) {
// Buf_Print("Cmd", data, l, 16);
@ -30,13 +29,13 @@ void Key_Call_E(Key_t *key) {
switch (key->event) {
case KEY_PRESS_DOWN:
// LOGT("KEY", "ID:%d EVENT:%s", key->key_id, "PressTheEvent");
break;// 按下事件
break;// 按下事件
case KEY_PRESS_UP:
// LOGT("KEY", "ID:%d EVENT:%s", key->key_id, "BounceIncident");
break;// 弹起事件
break;// 弹起事件
case KEY_PRESS_REPEAT:
LOGT("KEY", "ID:%d EVENT:%s", key->key_id, "RepeatThePressEvent");
break;// 重复按下事件
break;// 重复按下事件
case KEY_SINGLE_CLICK:
LOGT("KEY", "ID:%d EVENT:%s", key->key_id, "ClickEvent");
if (key->key_id == SIM_KEY_UP)cur--;
@ -46,6 +45,7 @@ void Key_Call_E(Key_t *key) {
if (key->key_id == SIM_KEY_LEFT)pageid--;
if (key->key_id == SIM_KEY_RIGHT)pageid++;
if (key->key_id == SIM_KEY_RESET)pageid = pagesearch(pageid).back;
if (key->key_id == SIM_KEY_SET)pageid = pagesearch(pageid).next;
if (key->key_id == SIM_KEY_ENABLE) {
switch (pageid) {
case 0:
@ -56,18 +56,22 @@ void Key_Call_E(Key_t *key) {
case 3:
if (cur == 2)pageid = 0;
break;
case 4:
if(cnt_f==1)cnt_f=0;
else cnt_f=1;
break;
}
}
break;// 单击事件
break;// 单击事件
case KEY_DOUBLE_CLICK:
LOGT("KEY", "ID:%d EVENT:%s", key->key_id, "DoubleClickTheEvent");
break;// 双击事件
break;// 双击事件
case KEY_LONG_PRESS_START:
// LOGT("KEY", "ID:%d EVENT:%s", key->key_id, "LongPressToStartTheEvent");
break;// 长按开始事件
break;// 长按开始事件
case KEY_LONG_PRESS_HOLD:
LOGT("KEY", "ID:%d EVENT:%s", key->key_id, "LongPressToHoldTheEvent");
break;// 长按保持事件
break;// 长按保持事件
}
}
@ -90,7 +94,7 @@ void Get_Key(void *pVoid) {
key_attach(&k7, KEY_ALL_EVENT, Key_Call_E, true);
while (1) {
// 每5ms调用一次key_ticks函数
// 每5ms调用一次key_ticks函数
key_ticks();
Sleep(5);
}
@ -115,28 +119,29 @@ void Test_OLED() {
OLED_Init(&oled);
OLED_CLS(&oled);
OLED_DrawRect(&oled, 0, 0, 127, 63);
// char buf[30] = {0x5B, 0x57};
char buf[30] = {0x5B, 0x57, 0x5E, 0x93, 0x75, 0x1F, 0x62, 0x10, 0x6D, 0x4B, 0x8B, 0xD5};
uint8_t sbuf[30] = {0};
sprintf(sbuf, "%sC\0", buf);
// };//
// 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);
// Sleep(3000);
Sleep(3000);
extern lv_font_t myFont;
// OLED_DisplayString(&oled, &myFont, "你好Hello", 2, 0);
// extern lv_font_t myFont;
// OLED_DisplayString(&oled, &myFont, "班级", 2, 1);
OLED_ShowPic(&oled, 0, 0, 64, 64, BMP1);
// OLED_ShowPic(&oled, 0, 0, 64, 64, BMP1);
OLED_Refresh(&oled);
_beginthread(Get_Key, 0, NULL);
pageinit();
while (1) {
if (pageid > 3)pageid = 0;
if (pageid > 4)pageid = 0;
item_h = pagesearch(pageid).item_h;
// pagesearch(pageid).page(&oled);
item_w = pagesearch(pageid).item_w;
pagesearch(pageid).page(&oled);
// sprintf(buf, "DATA:%d", s);
// OLED_ShowString(&oled, 2, 51, buf, 12);
OLED_Refresh(&oled);

View File

@ -12,7 +12,7 @@ typedef struct List_Node_t { //节点结构
struct List_Node_t *next;
} List_Node_t;
typedef struct { //链表结构
typedef struct{ //链表结构
List_Node_t *head;
List_Node_t *tail;
long len;

View File

@ -6,11 +6,11 @@ extern "C" {
#endif
#include "stdint.h"
#include "lvgl.h"
#define REFRESH_CALL_ENABLE 1 //使用DMA或者整体刷新函数
#define HZK_FONT
//#define LVGL_FONT
/**
* @brief OLED
@ -214,6 +214,7 @@ void OLED_ShowChar(OLED_T *dev, uint8_t x, uint8_t y, uint8_t chr, uint8_t size1
* @example OLED_ShowString(&oled_dev, 0, 0, "Hello", 16);
*/
void OLED_ShowString(OLED_T *dev, uint8_t x, uint8_t y, uint8_t *chr, uint8_t size1);
#ifdef HZK_FONT
/**
* @brief OLED
@ -222,10 +223,10 @@ void OLED_ShowString(OLED_T *dev, uint8_t x, uint8_t y, uint8_t *chr, uint8_t si
* @param y: [] Y
* @param str: []
* @return void
* @example OLED_ShowCHString(&oled_device, 0, 0, chinese_str, 16);
* @example OLED_ShowCHString(&oled_device, 0, 0, chinese_str);
**/
void OLED_ShowCHString(OLED_T *dev, uint8_t x, uint8_t y, uint8_t *str);
#endif
/**
* @brief OLED
* @param dev: [] OLED
@ -279,9 +280,23 @@ void OLED_Fill(OLED_T *dev, uint8_t data);
*/
void OLED_CLS(OLED_T *dev);
#ifdef LVGL_FONT
#include "lvgl.h"
/**
* @brief OLED
* @param dev: [] OLED
* @param font: []
* @param s: []
* @param x: [] x
* @param y: [] y
* @return void
* @example OLED_DisplayString(&oled_device, &font_arial_16, "Hello World", 10, 20);
**/
void OLED_DisplayString(OLED_T *dev, const lv_font_t *font, uint8_t *s, uint16_t x, uint16_t y);
#endif
#ifdef __cplusplus
}
#endif

View File

@ -1,74 +1,161 @@
#pragma once
#ifndef HW_LIB_OLED_FONT_CHUC_H
#define HW_LIB_OLED_FONT_CHUC_H
typedef struct {
uint8_t unicode[2];
uint8_t data[32];
} Chinese_t;
uint8_t Hzk_size = 16;
uint8_t Hzk_size=16;
Chinese_t Hzk[] = {
{
// Original:
{0x5B, 0x57},
// Original:
{ 0x59, 0xD3 },
{
0x10, 0x0C, 0x04, 0x24, 0x24, 0x24, 0x25, 0x26, 0xA4, 0x64, 0x24, 0x04, 0x04, 0x14, 0x0C, 0x00,
0x02, 0x02, 0x02, 0x02, 0x02, 0x42, 0x82, 0x7F, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00,
0x10, 0x20, 0x10, 0x20, 0x11, 0x20, 0x11, 0x24, 0xFD, 0xFE, 0x25, 0x20, 0x26, 0x20, 0x24, 0x20,
0x24, 0x28, 0x45, 0xFC, 0x28, 0x20, 0x10, 0x20, 0x28, 0x20, 0x44, 0x24, 0x87, 0xFE, 0x00, 0x00,
}
},
{
// Original:
{0x5E, 0x93},
// Original:
{ 0x54, 0x0D },
{
0x00, 0x00, 0xFC, 0x24, 0x24, 0xA4, 0x64, 0x3D, 0xA6, 0x24, 0x24, 0x24, 0x24, 0x24, 0x04, 0x00,
0x40, 0x30, 0x0F, 0x10, 0x13, 0x12, 0x12, 0x12, 0xFF, 0x12, 0x12, 0x12, 0x12, 0x10, 0x10, 0x00,
0x02, 0x00, 0x02, 0x00, 0x07, 0xF0, 0x04, 0x10, 0x0C, 0x20, 0x12, 0x40, 0x01, 0x80, 0x06, 0x00,
0x18, 0x08, 0xEF, 0xFC, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0F, 0xF8, 0x08, 0x08,
}
},
{
// Original:
{0x75, 0x1F},
// Original:
{ 0x6B, 0x66 },
{
0x80, 0x40, 0x30, 0x1E, 0x10, 0x10, 0x10, 0xFF, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00,
0x40, 0x40, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7F, 0x42, 0x42, 0x42, 0x42, 0x42, 0x40, 0x40, 0x00,
0x00, 0x40, 0x02, 0x50, 0x3F, 0x48, 0x00, 0x48, 0x00, 0x40, 0xFF, 0xFE, 0x04, 0x40, 0x04, 0x40,
0x27, 0x40, 0x24, 0x40, 0x24, 0x20, 0x24, 0x20, 0x27, 0xA0, 0xF8, 0x12, 0x40, 0x0A, 0x00, 0x06,
}
},
{
// Original:
{0x62, 0x10},
// Original:
{ 0x65, 0xED },
{
0x00, 0x00, 0xF8, 0x88, 0x88, 0x88, 0x88, 0x08, 0x08, 0xFF, 0x08, 0x09, 0x0A, 0xC8, 0x08, 0x00,
0x80, 0x60, 0x1F, 0x00, 0x10, 0x20, 0x1F, 0x80, 0x40, 0x21, 0x16, 0x18, 0x26, 0x41, 0xF8, 0x00,
0x10, 0x00, 0x10, 0x08, 0x10, 0xFC, 0x10, 0x88, 0xFE, 0x88, 0x12, 0x88, 0x12, 0x88, 0x12, 0xF8,
0x12, 0x88, 0x12, 0x88, 0x12, 0x88, 0x12, 0x88, 0x22, 0xFA, 0x22, 0x02, 0x41, 0xFE, 0x80, 0x00,
}
},
{
// Original:
{0x6D, 0x4B},
// Original:
{ 0x73, 0xED },
{
0x10, 0x60, 0x02, 0x8C, 0x00, 0xFE, 0x02, 0xF2, 0x02, 0xFE, 0x00, 0xF8, 0x00, 0xFF, 0x00, 0x00,
0x04, 0x04, 0x7E, 0x01, 0x80, 0x47, 0x30, 0x0F, 0x10, 0x27, 0x00, 0x47, 0x80, 0x7F, 0x00, 0x00,
0x01, 0x00, 0x09, 0x04, 0xFD, 0x7E, 0x21, 0x10, 0x25, 0x10, 0x25, 0x10, 0x25, 0x10, 0xF5, 0x7C,
0x25, 0x10, 0x29, 0x10, 0x21, 0x10, 0x22, 0x10, 0x3A, 0x10, 0xE2, 0x14, 0x44, 0xFE, 0x08, 0x00,
}
},
{
// Original:
{0x8B, 0xD5},
// Original:
{ 0x7E, 0xA7 },
{
0x40, 0x40, 0x42, 0xCC, 0x00, 0x90, 0x90, 0x90, 0x90, 0x90, 0xFF, 0x10, 0x11, 0x16, 0x10, 0x00,
0x00, 0x00, 0x00, 0x3F, 0x10, 0x28, 0x60, 0x3F, 0x10, 0x10, 0x01, 0x0E, 0x30, 0x40, 0xF0, 0x00,
0x10, 0x08, 0x17, 0xFC, 0x21, 0x08, 0x21, 0x08, 0x49, 0x10, 0xF9, 0x10, 0x11, 0x3C, 0x21, 0x84,
0x41, 0x88, 0xF9, 0x48, 0x02, 0x50, 0x02, 0x20, 0x1A, 0x50, 0xE4, 0x88, 0x49, 0x0E, 0x02, 0x04,
}
},
{
// Original: 信
{ 0x4F, 0xE1 },
{
0x08, 0x80, 0x08, 0x44, 0x0F, 0xFE, 0x10, 0x00, 0x10, 0x08, 0x37, 0xFC, 0x50, 0x00, 0x90, 0x08,
0x17, 0xFC, 0x10, 0x00, 0x13, 0xF8, 0x12, 0x08, 0x12, 0x08, 0x12, 0x08, 0x13, 0xF8, 0x12, 0x08,
}
},
{
// Original: 息
{ 0x60, 0x6F },
{
0x02, 0x00, 0x04, 0x10, 0x1F, 0xF8, 0x10, 0x10, 0x10, 0x10, 0x1F, 0xF0, 0x10, 0x10, 0x1F, 0xF0,
0x10, 0x10, 0x10, 0x10, 0x1F, 0xF0, 0x02, 0x00, 0x51, 0x84, 0x50, 0x92, 0x90, 0x12, 0x0F, 0xF0,
}
},
{
// Original: 显
{ 0x66, 0x3E },
{
0x00, 0x10, 0x1F, 0xF8, 0x10, 0x10, 0x10, 0x10, 0x1F, 0xF0, 0x10, 0x10, 0x10, 0x10, 0x1F, 0xF0,
0x14, 0x50, 0x44, 0x44, 0x34, 0x4C, 0x14, 0x50, 0x04, 0x40, 0x04, 0x44, 0xFF, 0xFE, 0x00, 0x00,
}
},
{
// Original: 示
{ 0x79, 0x3A },
{
0x00, 0x10, 0x3F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xFF, 0xFE, 0x01, 0x00,
0x01, 0x00, 0x09, 0x20, 0x19, 0x18, 0x21, 0x0C, 0x41, 0x04, 0x01, 0x00, 0x05, 0x00, 0x02, 0x00,
}
},
{
// Original: 图
{ 0x56, 0xFE },
{
0x00, 0x04, 0x7F, 0xFE, 0x44, 0x04, 0x47, 0xE4, 0x4C, 0x44, 0x52, 0x84, 0x41, 0x04, 0x42, 0x84,
0x46, 0x44, 0x49, 0x3C, 0x70, 0x94, 0x46, 0x04, 0x41, 0x04, 0x40, 0x84, 0x7F, 0xFC, 0x40, 0x04,
}
},
{
// Original: 片
{ 0x72, 0x47 },
{
0x00, 0x80, 0x20, 0x80, 0x20, 0x80, 0x20, 0x80, 0x20, 0x84, 0x3F, 0xFE, 0x20, 0x00, 0x20, 0x00,
0x3F, 0xC0, 0x20, 0x40, 0x20, 0x40, 0x20, 0x40, 0x20, 0x40, 0x20, 0x40, 0x40, 0x40, 0x80, 0x40,
}
},
{
// Original: 视
{ 0x89, 0xC6 },
{
0x20, 0x08, 0x13, 0xFC, 0x12, 0x08, 0x02, 0x48, 0xFE, 0x48, 0x0A, 0x48, 0x12, 0x48, 0x32, 0x48,
0x5A, 0x48, 0x96, 0x68, 0x12, 0xA8, 0x10, 0xA0, 0x11, 0x22, 0x11, 0x22, 0x12, 0x1E, 0x14, 0x00,
}
},
{
// Original: 频
{ 0x98, 0x91 },
{
0x10, 0x04, 0x13, 0xFE, 0x54, 0x20, 0x5E, 0x44, 0x51, 0xFE, 0x55, 0x04, 0xFF, 0x24, 0x11, 0x24,
0x55, 0x24, 0x55, 0x24, 0x55, 0x24, 0x95, 0x24, 0x08, 0x20, 0x10, 0x50, 0x20, 0x8C, 0x43, 0x04,
}
},
{
// Original: 专
{ 0x4E, 0x13 },
{
0x01, 0x00, 0x01, 0x00, 0x01, 0x10, 0x3F, 0xF8, 0x02, 0x00, 0x02, 0x04, 0xFF, 0xFE, 0x04, 0x00,
0x04, 0x00, 0x0F, 0xF8, 0x00, 0x10, 0x00, 0x20, 0x00, 0x40, 0x06, 0x80, 0x01, 0x80, 0x00, 0x40,
}
},
{
// Original: 业
{ 0x4E, 0x1A },
{
0x04, 0x40, 0x04, 0x40, 0x04, 0x40, 0x04, 0x40, 0x44, 0x44, 0x24, 0x44, 0x24, 0x48, 0x14, 0x48,
0x14, 0x50, 0x14, 0x50, 0x14, 0x60, 0x04, 0x40, 0x04, 0x40, 0x04, 0x44, 0xFF, 0xFE, 0x00, 0x00,
}
},
{
// Original: 电
{ 0x75, 0x35 },
{
0x02, 0x00, 0x02, 0x00, 0x02, 0x10, 0x7F, 0xF8, 0x42, 0x10, 0x42, 0x10, 0x7F, 0xF0, 0x42, 0x10,
0x42, 0x10, 0x7F, 0xF0, 0x42, 0x10, 0x02, 0x00, 0x02, 0x04, 0x02, 0x04, 0x01, 0xFC, 0x00, 0x00,
}
},
{
// Original: 子
{ 0x5B, 0x50 },
{
0x00, 0x00, 0x3F, 0xF0, 0x00, 0x10, 0x00, 0x20, 0x00, 0x40, 0x01, 0x80, 0x01, 0x04, 0xFF, 0xFE,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x05, 0x00, 0x02, 0x00,
}
},
};
uint16_t find_chinese_data(uint8_t unicode_high, uint8_t unicode_low) {
for (int i = 0; i < sizeof(Hzk) / sizeof(Chinese_t); ++i) {
if (Hzk[i].unicode[0] == unicode_high && Hzk[i].unicode[1] == unicode_low) {
return i;
}
}
return NULL;
}
#endif //HW_LIB_OLED_FONT_CHUC_H

View File

@ -110,20 +110,15 @@ void draw_letter_normal(Font_f_t *fd, uint16_t pos_x, uint16_t pos_y, lv_font_gl
#if PIX_COLOR_SIZE == 16
uint16_t fd_buf[fd->dev_w / 2];
#endif
int32_t mask_p = 0;
uint32_t col_bit_max = 8 - bpp;
uint32_t col_bit_row_ofs = (box_w + col_start - col_end) * bpp;
uint16_t index = 0;
for (row = row_start; row < row_end; row++) {
int32_t mask_p_start = mask_p;
bitmask = bitmask_init >> col_bit;
for (col = col_start; col < col_end; col++) {
/*Load the pixel's opacity into the mask*/
letter_px = (*map_p & bitmask) >> (col_bit_max - col_bit);
#if PIX_COLOR_SIZE == 1
if (letter_px) {
fd_buf[index / 8] |= (1 << (index % 8));
@ -150,9 +145,6 @@ void draw_letter_normal(Font_f_t *fd, uint16_t pos_x, uint16_t pos_y, lv_font_gl
bitmask = bitmask_init;
map_p++;
}
/*Next mask byte*/
mask_p++;
}
{
@ -164,10 +156,11 @@ void draw_letter_normal(Font_f_t *fd, uint16_t pos_x, uint16_t pos_y, lv_font_gl
fd->w = box_w;
fd->h = 1;
fd->show(fd, fd_buf, box_w);
pos_y++;
index = 0;
#endif
pos_y++;
mask_p = 0;
} //避免大字体,大缓存 ,单行即刻刷入
col_bit += col_bit_row_ofs;
@ -175,13 +168,12 @@ void draw_letter_normal(Font_f_t *fd, uint16_t pos_x, uint16_t pos_y, lv_font_gl
col_bit = col_bit & 0x7;
}
#ifndef LINE_FAST_SHOW
fd->x=pos_x;
fd->y=pos_y;
fd->w=box_w;
fd->h=box_h;
fd->x = pos_x;
fd->y = pos_y;
fd->w = box_w;
fd->h = box_h;
fd->show(fd, fd_buf, box_w * box_h);
#endif
// LCD_fill_fast(pos_x, pos_y, box_w, box_h, (uint8_t *)mask_buf, box_w * box_h); // 如果 大缓存 一次刷入
}
char Font_draw_letter(const lv_font_t *font, Font_f_t *fd, uint32_t letter, int16_t pos_x, int16_t pos_y) {

View File

@ -1,7 +1,11 @@
#include "oled.h"
#include "oled_font.h"
#ifdef HZK_FONT
#include "oled_font_chuc.h"
#include "font.h"
#endif
#define BUFPOINT(x, y) (*(dev->buf + x + (y * dev->width)))
#define GET_BIT(x, bit) ((x & (1 << bit)) >> bit)
@ -107,6 +111,7 @@ void OLED_Set(OLED_T *dev, uint8_t x, uint8_t y) {
BUFPOINT(x, i) |= n;
}
// 列写入
void OLED_BSet(OLED_T *dev, uint8_t x, uint8_t y, uint8_t data) {
uint8_t i, ys = y;
for (i = 0; i < 8; i++) //写入数据
@ -117,6 +122,20 @@ void OLED_BSet(OLED_T *dev, uint8_t x, uint8_t y, uint8_t data) {
}
}
// 行写入
void OLED_HBSet(OLED_T *dev, uint8_t x, uint8_t y, uint8_t data) {
uint8_t i, ys = y;
x += 7;
for (i = 0; i < 8; i++) // 写入数据
{
if (GET_BIT(data, i))
OLED_Set(dev, x, ys);
else
OLED_RSet(dev, x, ys);
x--;
}
}
void OLED_RSet(OLED_T *dev, uint8_t x, uint8_t y) {
uint8_t i, m, n;
i = y / 8;
@ -221,54 +240,53 @@ void OLED_ShowString(OLED_T *dev, uint8_t x, uint8_t y, uint8_t *str, uint8_t si
}
}
#define GET_LOW_BYTE0(x) ((x >> 0) & 0x000000ff) /* 获取第0个字节 */
#define GET_LOW_BYTE1(x) ((x >> 8) & 0x000000ff) /* 获取第1个字节 */
#define GET_LOW_BYTE2(x) ((x >> 16) & 0x000000ff) /* 获取第2个字节 */
#define GET_LOW_BYTE3(x) ((x >> 24) & 0x000000ff) /* 获取第3个字节 */
#ifdef HZK_FONT
void OLED_ShowCHString(OLED_T *dev, uint8_t x, uint8_t y, uint8_t *str) {
uint8_t i, temp, size2, ys = y, xs = x, c = x;
uint16_t index;
// Hzk_size=12;
// size2 = Hzk_size * Hzk_size / 8; //得到字体一个字符对应点阵集所占的字节数
size2 = Hzk_size * ((Hzk_size + 7) / 8 * 8) / 8;
uint8_t test[24] = {0x00, 0x00, 0x2E, 0x18, 0xF7, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0xD0, 0xFC, 0x5F, 0x0D,
0xC6, 0x00, 0x00, 0x00};
while (*str != '\0') {
for (index = 0; index < sizeof(Hzk) / sizeof(Chinese_t); index++) {
if (Hzk[index].unicode[0] == str[0] && Hzk[index].unicode[1] == str[1])//对比汉字区码位码
{
for (i = 0; i < size2; i++) {
temp = Hzk[index].data[i];
// temp = test[i];
OLED_BSet(dev, xs, ys, temp);
xs++;
if (xs - c == Hzk_size) {
ys += 8;
xs = c;
c += Hzk_size;
}
}
ys = y;
x += Hzk_size;
str++;
str++;
} else {
OLED_ShowChar(dev, x, y, *str, 16);
x += 16 / 2;
if (x > dev->width - 16) //换行
{
x = 0;
y += 2;
}
str++;
break;
}
void OLED_ShowCHChr(OLED_T *dev, uint8_t x, uint8_t y, Chinese_t *hzk) {
uint8_t i, temp, size2 = Hzk_size * ((Hzk_size + 7) / 8 * 8) / 8;
uint16_t ziku_byte_n, ziku_bytes = ((Hzk_size + 7) / 8 * 8) / 8;
ziku_byte_n = 0;
for (i = 0; i < size2; i++) {
temp = hzk->data[i];
OLED_HBSet(dev, x + ziku_byte_n * 8, y, temp);
ziku_byte_n++;
if (ziku_byte_n >= ziku_bytes) {
ziku_byte_n = 0;
y++;
}
}
}
void OLED_ShowCHString(OLED_T *dev, uint8_t x, uint8_t y, uint8_t *str) {
uint16_t index;
while (*str != '\0') {
bool found = false;
for (index = 0; index < sizeof(Hzk) / sizeof(Chinese_t); index++) {
if (Hzk[index].unicode[0] == str[0] && Hzk[index].unicode[1] == str[1]) // 对比汉字区码位码
{
OLED_ShowCHChr(dev, x, y, &Hzk[index]);
x += Hzk_size;
str++;
str++;
found = true;
break;
}
}
if (!found) {
OLED_ShowChar(dev, x, y, *str, Hzk_size);
x += Hzk_size / 2;
str++;
}
if (x > dev->width - Hzk_size) {
x = 0;
y += Hzk_size;
}
}
}
#endif
#ifdef LGVL_FONT
#include "font.h"
void draw_rect(Font_f_t *fd, uint8_t *data, size_t len) {
size_t index;
uint16_t x = fd->x, y = fd->y;
@ -285,7 +303,6 @@ void draw_rect(Font_f_t *fd, uint8_t *data, size_t len) {
}
}
//
void OLED_DisplayString(OLED_T *dev, const lv_font_t *font, uint8_t *s, uint16_t x, uint16_t y) {
uint32_t unicode_letter;
Font_f_t fd = {.dev=dev, .dev_w=dev->width, .show=draw_rect};
@ -301,6 +318,7 @@ void OLED_DisplayString(OLED_T *dev, const lv_font_t *font, uint8_t *s, uint16_t
}
}
}
#endif
uint32_t OLED_Pow(uint8_t m, uint8_t n) {
uint32_t result = 1;

39
main.c
View File

@ -14,26 +14,27 @@
int main() {
srand((unsigned) time(NULL));
int i, j, k = 0;
unsigned char incode[3] = ""; // 要读出的汉字
unsigned char qh, wh;
long offset = 0;
// 占两个字节, 取其区位号
qh = incode[0] - 0xa0;//获得区码
wh = incode[1] - 0xa0; //获得位码
offset = (94 * (qh - 1) + (wh - 1)) * 24; /*得到偏移位置*/
// int i, j, k = 0;
// unsigned char incode[3] = "我"; // 要读出的汉字
// unsigned char qh, wh;
// long offset = 0;
//// 占两个字节, 取其区位号
// qh = incode[0] - 0xa0;//获得区码
// wh = incode[1] - 0xa0; //获得位码
// offset = (94 * (qh - 1) + (wh - 1)) * 24; /*得到偏移位置*/
//
// FILE *HZK;
// uint8_t temp, mat[24];
// if ((HZK = fopen("HZK12", "rb")) == NULL) {
// printf("Can't Open hzk16\n");
// exit(0);
// }
// fseek(HZK, offset, SEEK_SET);
// fread(mat, 24, 1, HZK);
//// Buf_Print("KZK12",mat,24,12);
// for (i = 0; i < 24; i++)
// printf("0x%02X, ", mat[i]);
FILE *HZK;
uint8_t temp, mat[24];
if ((HZK = fopen("HZK12", "rb")) == NULL) {
printf("Can't Open hzk16\n");
exit(0);
}
fseek(HZK, offset, SEEK_SET);
fread(mat, 24, 1, HZK);
// Buf_Print("KZK12",mat,24,12);
for (i = 0; i < 24; i++)
printf("0x%02X, ", mat[i]);
// for (i = 0; i < 24; i++) {
// temp = mat[i];
// for (j = 0; j < 8; j++) //写入数据

BIN
tools/HZK12 Normal file

Binary file not shown.

BIN
tools/HZK16 Normal file

Binary file not shown.

View File

@ -4,18 +4,34 @@ import PIL.Image as pilimage
import PIL.ImageDraw as pildraw
# def generate_chinese_struct(char_code, font, size):
# image = pilimage.new('L', size)
# draw = pildraw.Draw(image)
# draw.text((0, 0), char_code, font=font, fill=255)
# pixel_array = np.array(image)
# result = np.zeros(size[0] * size[1] // 8, dtype=np.uint8)
# for i in range(size[1]):
# for j in range(size[0] // 8):
# for k in range(8):
# if pixel_array[j * 8 + k, i]:
# result[j * size[1] + i] |= (1 << k)
# return result
def generate_chinese_struct(char_code, font, size):
image = pilimage.new('L', size)
draw = pildraw.Draw(image)
draw.text((0, 0), char_code, font=font, fill=255)
pixel_array = np.array(image)
result = np.zeros(size[0] * size[1] // 8, dtype=np.uint8)
for i in range(size[1]):
for j in range(size[0] // 8):
for k in range(8):
if pixel_array[j * 8 + k, i]:
result[j * size[1] + i] |= (1 << k)
return result
incode = char_code.encode('gb2312') # 要读出的汉字
qh, wh = incode[0] - 0xa0, incode[1] - 0xa0 # 占两个字节, 取其区位号
if size[0] == 12:
offset = (94 * (qh - 1) + (wh - 1)) * 24 # 得到偏移位置
with open("HZK12", "rb") as HZK:
HZK.seek(offset)
return HZK.read(24)
if size[0] == 16:
offset = (94 * (qh - 1) + (wh - 1)) * 32 # 得到偏移位置
with open("HZK16", "rb") as HZK:
HZK.seek(offset)
return HZK.read(32)
# from bitarray import bitarray
@ -72,10 +88,12 @@ def generate_chinese_array(input_str, font_str, size):
def format_chinese_array_as_text(chinese_array, size):
text_output = "#pragma pack(1)\n\n"
text_output = "#pragma once\n\n"
text_output += "#ifndef HW_LIB_OLED_FONT_CHUC_H\n"
text_output += "#define HW_LIB_OLED_FONT_CHUC_H\n\n"
text_output += f"typedef struct {{\n"
text_output += " uint8_t unicode[2];\n"
text_output += f" uint8_t data[{size[0] * size[1] // 8}];\n"
text_output += f" uint8_t data[{size[0] * ((size[1] + 7) // 8 * 8) // 8}];\n"
text_output += "} Chinese_t;\n\n"
text_output += f"uint8_t Hzk_size={size[0]};\n\n"
text_output += "Chinese_t Hzk[] = {\n"
@ -84,6 +102,7 @@ def format_chinese_array_as_text(chinese_array, size):
# line_size = 16 if line_size >= 16 else 8
for item in chinese_array:
unicode_hex = ', '.join(f"0x{ord(char) >> 8:02X}, 0x{ord(char) & 0xFF:02X}" for char in item['name'])
print(unicode_hex, end=",")
text_output += f" {{\n // Original: {item['name']}\n"
text_output += f" {{ {unicode_hex} }},\n {{\n "
bytes_str = ', '.join(f"0x{byte:02X}" for byte in item['data'])
@ -92,14 +111,15 @@ def format_chinese_array_as_text(chinese_array, size):
text_output += '\n '.join(bytes_lines)
text_output += ",\n }\n },\n"
text_output += "};\n\n"
text_output += "Chinese_t* find_chinese_data(uint8_t unicode_high, uint8_t unicode_low) {\n"
text_output += " for (int i = 0; i < sizeof(Hzk) / sizeof(Chinese_t); ++i) {\n"
text_output += " if (Hzk[i].unicode[0] == unicode_high && Hzk[i].unicode[1] == unicode_low) {\n"
text_output += " return &Hzk[i];\n"
text_output += " }\n"
text_output += " }\n"
text_output += " return NULL;\n"
text_output += "}\n"
# text_output += "Chinese_t* find_chinese_data(uint8_t unicode_high, uint8_t unicode_low) {\n"
# text_output += " for (int i = 0; i < sizeof(Hzk) / sizeof(Chinese_t); ++i) {\n"
# text_output += " if (Hzk[i].unicode[0] == unicode_high && Hzk[i].unicode[1] == unicode_low) {\n"
# text_output += " return &Hzk[i];\n"
# text_output += " }\n"
# text_output += " }\n"
# text_output += " return NULL;\n"
# text_output += "}\n"
text_output += "\n#endif //HW_LIB_OLED_FONT_CHUC_H"
return text_output
@ -110,7 +130,8 @@ def generate_and_write_chinese_array_output():
# size = (20, 20)
# size = (12, 12)
size = (16, 16)
chinese_array = generate_chinese_array("字库生成测试", 'simsun', size)
# chinese_array = generate_chinese_array("名字班级", 'simsun', size)
chinese_array = generate_chinese_array("姓名学号班级信息显示图片视频专业电子", 'simsun', size)
# 将数组格式化为文本输出并写入文件
text_output = format_chinese_array_as_text(chinese_array, size)