Skip to content

Commit 5552a80

Browse files
committed
up
1 parent 1142bfb commit 5552a80

File tree

3 files changed

+26
-103
lines changed

3 files changed

+26
-103
lines changed

OLED-0.96-inch/font/oled_font.c

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
/**
2-
* This is a simple implement for function: '_OLED_GetAsciiCode' and '_OLED_GetGbkCode'
3-
*/
4-
5-
#include <oled.h>
6-
7-
#ifdef __GNUC__
8-
#pragma GCC diagnostic ignored "-Wmissing-braces"
9-
#endif
1+
#include "ssd1306.h"
102

113
// --- ASCII Code ---
124

13-
const uint8_t ascii_8x16[][2][8] = {
5+
const uint8_t ascii_8x16[] = {
146
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0
157
0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x30, 0x00, 0x00, 0x00, //! 1
168
0x00, 0x10, 0x0C, 0x06, 0x10, 0x0C, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //" 2
@@ -108,55 +100,7 @@ const uint8_t ascii_8x16[][2][8] = {
108100
0x00, 0x06, 0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 //~ 94
109101
};
110102

111-
OLED_Data8x16 *_OLED_GetAsciiCode(char code)
103+
uint8_t *_OLED_GetAsciiCode_8x16(char code)
112104
{
113-
return (OLED_Data8x16 *)(&ascii_8x16[code - 32]);
105+
return &ascii_8x16[(code - 32) * 16];
114106
}
115-
116-
// --- GBK Code ---
117-
118-
#ifdef OLED_USE_GBK_CHAR
119-
120-
typedef struct
121-
{
122-
uint8_t index[2];
123-
uint8_t value[2][16];
124-
} GBK_Info;
125-
126-
#define GBK_Len 5
127-
128-
const GBK_Info gbkTable[GBK_Len] = {
129-
130-
"��", 0xFF, 0xFF, 0xC7, 0xCB, 0xFD, 0x7D, 0x3D, 0x83, 0xC7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
131-
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC8, 0xC8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
132-
133-
"��", 0x10, 0x60, 0x02, 0x8C, 0x00, 0x00, 0xFE, 0x92, 0x92, 0x92, 0x92, 0x92, 0xFE, 0x00, 0x00, 0x00,
134-
0x04, 0x04, 0x7E, 0x01, 0x40, 0x7E, 0x42, 0x42, 0x7E, 0x42, 0x7E, 0x42, 0x42, 0x7E, 0x40, 0x00,
135-
136-
"��", 0x00, 0x00, 0xFC, 0x24, 0x24, 0x24, 0xFC, 0x25, 0x26, 0x24, 0xFC, 0x24, 0x24, 0x24, 0x04, 0x00,
137-
0x40, 0x30, 0x8F, 0x80, 0x84, 0x4C, 0x55, 0x25, 0x25, 0x25, 0x55, 0x4C, 0x80, 0x80, 0x80, 0x00,
138-
139-
"ʪ", 0x10, 0x60, 0x02, 0x8C, 0x00, 0xFE, 0x92, 0x92, 0x92, 0x92, 0x92, 0x92, 0xFE, 0x00, 0x00, 0x00,
140-
0x04, 0x04, 0x7E, 0x01, 0x44, 0x48, 0x50, 0x7F, 0x40, 0x40, 0x7F, 0x50, 0x48, 0x44, 0x40, 0x00,
141-
142-
"��", 0x06, 0x09, 0x09, 0xE6, 0xF8, 0x0C, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x04, 0x1E, 0x00, 0x00,
143-
0x00, 0x00, 0x00, 0x07, 0x1F, 0x30, 0x20, 0x40, 0x40, 0x40, 0x40, 0x40, 0x20, 0x10, 0x00, 0x00
144-
145-
};
146-
147-
OLED_Data16x16 *_OLED_GetGbkCode(uint8_t byte1, uint8_t byte2)
148-
{
149-
uint8_t i = 0;
150-
151-
do
152-
{
153-
if (gbkTable[i].index[0] == byte1 && gbkTable[i].index[1] == byte2)
154-
{
155-
return (OLED_Data16x16 *)(&gbkTable[i].value);
156-
}
157-
} while (++i < GBK_Len);
158-
159-
return (OLED_Data16x16 *)(&gbkTable[0].value);
160-
}
161-
162-
#endif

OLED-0.96-inch/oled.c renamed to OLED-0.96-inch/ssd1306.c

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "oled.h"
1+
#include "ssd1306.h"
22

33
#define OLED_OFF 0xAE
44
#define OLED_ON 0xAF
@@ -17,7 +17,6 @@
1717
#define OLED_CALC_START_COLUMN_LOW(col) (uint8_t)(col & 0x0F)
1818

1919
#define _WriteWord(word) _OLED_WriteWord(word)
20-
#define _GetAsciiCode(c) _OLED_GetAsciiCode(c)
2120

2221
uint8_t _x, _page;
2322

@@ -79,12 +78,12 @@ void OLED_SetPage(uint8_t p)
7978
_page = p;
8079
}
8180

82-
uint8_t OLED_GetColumn()
81+
uint8_t OLED_GetColumn(void)
8382
{
8483
return _x;
8584
}
8685

87-
uint8_t OLED_GetPage()
86+
uint8_t OLED_GetPage(void)
8887
{
8988
return _page;
9089
}
@@ -106,21 +105,21 @@ void OLED_WriteCommand(uint8_t _cmd)
106105
_WriteCmd(_cmd);
107106
}
108107

109-
void OLED_WriteData_8x16(OLED_Data8x16 arr)
108+
void OLED_WriteData_8x16(uint8_t *arr)
110109
{
111110
uint8_t x = _x, page = _page;
112-
OLED_WriteDataArray(arr[0], 8);
111+
OLED_WriteDataArray(&arr[0], 8);
113112
OLED_SetColumnAndPage(x, page + 1);
114-
OLED_WriteDataArray(arr[1], 8);
113+
OLED_WriteDataArray(&arr[8], 8);
115114
OLED_SetPage(page);
116115
}
117116

118-
void OLED_WriteData_16x16(OLED_Data16x16 arr)
117+
void OLED_WriteData_16x16(uint8_t *arr)
119118
{
120119
uint8_t x = _x, page = _page;
121-
OLED_WriteDataArray(arr[0], 16);
120+
OLED_WriteDataArray(&arr[0], 16);
122121
OLED_SetColumnAndPage(x, page + 1);
123-
OLED_WriteDataArray(arr[1], 16);
122+
OLED_WriteDataArray(&arr[16], 16);
124123
OLED_SetPage(page);
125124
}
126125

@@ -172,11 +171,6 @@ void OLED_ClearAll(void)
172171
}
173172
}
174173

175-
#ifdef OLED_USE_GBK_CHAR
176-
#define _GetGbkCode(c1, c2) _OLED_GetGbkCode(c1, c2)
177-
uint8_t _firstByte;
178-
#endif
179-
180174
void OLED_putchar(char _char)
181175
{
182176
if (_char == '\n')
@@ -187,21 +181,9 @@ void OLED_putchar(char _char)
187181
return;
188182
}
189183

190-
#ifdef OLED_USE_GBK_CHAR
191-
if ((uint8_t)_char > 0x80 && _firstByte == 0)
192-
{
193-
_firstByte = (uint8_t)_char;
194-
}
195-
else if (_firstByte != 0)
196-
{
197-
OLED_WriteData_16x16(*_GetGbkCode(_firstByte, (uint8_t)_char));
198-
_firstByte = 0;
199-
}
200-
else
201-
{
202-
OLED_WriteData_8x16(*_GetAsciiCode(_char));
203-
}
184+
#ifdef OLED_USE_16x16_FONT
185+
OLED_WriteData_16x16(_OLED_GetAsciiCode_16x16(_char));
204186
#else
205-
OLED_WriteData_8x16(*_GetAsciiCode(_char));
187+
OLED_WriteData_8x16(_OLED_GetAsciiCode_8x16(_char));
206188
#endif
207-
}
189+
}

OLED-0.96-inch/oled.h renamed to OLED-0.96-inch/ssd1306.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@ extern "C" {
99

1010
#include <stdint.h>
1111

12-
typedef uint8_t OLED_Data8x16[2][8];
13-
typedef uint8_t OLED_Data16x16[2][16];
14-
1512
/* must implement this method */
1613
extern void _OLED_WriteWord(uint16_t _word);
1714

18-
/* must implement this method */
19-
extern OLED_Data8x16 *_OLED_GetAsciiCode(char c);
20-
21-
#ifdef OLED_USE_GBK_CHAR
22-
/* implement this method to support chinese char */
23-
extern OLED_Data16x16 *_OLED_GetGbkCode(uint8_t byte1, uint8_t byte2);
15+
#ifdef OLED_USE_16x16_FONT
16+
/* implement this method to support 16x16 font */
17+
extern uint8_t *_OLED_GetAsciiCode_16x16(char c);
18+
#else
19+
/* implement this method to support 8x16 font */
20+
extern uint8_t *_OLED_GetAsciiCode_8x16(char c);
2421
#endif
2522

2623
//======================================
@@ -67,8 +64,8 @@ void OLED_WriteData(uint8_t _data, uint8_t x, uint8_t page);
6764
void OLED_WriteCommand(uint8_t _cmd);
6865

6966
void OLED_WriteDataArray(uint8_t *arr, uint8_t len);
70-
void OLED_WriteData_8x16(OLED_Data8x16 arr);
71-
void OLED_WriteData_16x16(OLED_Data16x16 arr);
67+
void OLED_WriteData_8x16(uint8_t *arr);
68+
void OLED_WriteData_16x16(uint8_t *arr);
7269

7370
void OLED_ClearEndOfPage(uint8_t page);
7471
void OLED_ClearPage(uint8_t page);
@@ -83,4 +80,4 @@ void OLED_putchar(char _char);
8380
}
8481
#endif
8582

86-
#endif
83+
#endif

0 commit comments

Comments
 (0)