11#include "oled.h"
22
3+ #define OLED_OFF 0xAE
4+ #define OLED_ON 0xAF
5+
6+ #define OLED_SET_DISPLAY_ROW_OFFSET 0xD3
7+
8+ #define OLED_CALC_START_ROW (row ) (uint8_t)(0x40U | (row & 0x3FU))
9+ #define OLED_CALC_START_PAGE (page ) (uint8_t)(0xB0U | (page & 0x07U))
10+
11+ #define OLED_CALC_START_COLUMN_HIGH (col ) (uint8_t)(((col & 0xF0U) >> 4) | 0x10)
12+ #define OLED_CALC_START_COLUMN_LOW (col ) (uint8_t)(col & 0x0F)
13+
314WriteWordCallBack _WriteWord ;
415
516uint8_t _x , _page ;
617
7- void _AddPosition (uint32_t n )
18+ void _AddPosition (uint8_t n )
819{
9- uint32_t i = 0 ;
20+ uint8_t i = 0 ;
1021 while (i < n )
1122 {
1223 if (++ _x > 127U )
@@ -16,10 +27,10 @@ void _AddPosition(uint32_t n)
1627}
1728
1829#define _WriteData (_data ) \
19- _WriteWord(0x4000 | (_data)); \
30+ _WriteWord(0x4000 | ((uint16_t) _data)); \
2031 _AddPosition(1)
2132
22- #define _WriteCmd (_cmd ) _WriteWord(0x00FF & _cmd)
33+ #define _WriteCmd (_cmd ) _WriteWord(0x00FF & ((uint16_t) _cmd) )
2334
2435void OLED_Init (WriteWordCallBack writeWordCallBk )
2536{
@@ -47,14 +58,14 @@ void OLED_Init(WriteWordCallBack writeWordCallBk)
4758 _WriteCmd (OLED_ON );
4859}
4960
50- void OLED_SetColumn (uint32_t col )
61+ void OLED_SetColumn (uint8_t col )
5162{
5263 _WriteCmd (OLED_CALC_START_COLUMN_LOW (col ));
5364 _WriteCmd (OLED_CALC_START_COLUMN_HIGH (col ));
5465 _x = col ;
5566}
5667
57- void OLED_SetPage (uint32_t p )
68+ void OLED_SetPage (uint8_t p )
5869{
5970 _WriteCmd (OLED_CALC_START_PAGE (p ));
6071 _page = p ;
@@ -70,13 +81,13 @@ uint8_t OLED_GetPage()
7081 return _page ;
7182}
7283
73- void OLED_SetColumnAndPage (uint32_t col , uint32_t p )
84+ void OLED_SetColumnAndPage (uint8_t col , uint8_t p )
7485{
7586 OLED_SetColumn (col );
7687 OLED_SetPage (p );
7788}
7889
79- void OLED_WriteData (uint8_t _data , uint32_t x , uint32_t page )
90+ void OLED_WriteData (uint8_t _data , uint8_t x , uint8_t page )
8091{
8192 OLED_SetColumnAndPage (x , page );
8293 _WriteData (_data );
@@ -87,45 +98,45 @@ void OLED_WriteCommand(uint8_t _cmd)
8798 _WriteCmd (_cmd );
8899}
89100
90- void OLED_WritePoint (uint32_t x , uint32_t y , bool val )
101+ void OLED_WritePoint (uint8_t x , uint8_t y , uint8_t val )
91102{
92103 uint8_t page = y / 8 , pos = 0x01 << (y % 8 ), _data ;
93104 OLED_SetColumnAndPage (x , page );
94105 _data = val ? (_data | pos ) : (_data & ~pos );
95106 _WriteData (_data );
96107}
97108
98- void OLED_WriteData_8x16 (uint8_t ( * arr )[ 2 ][ 8 ] )
109+ void OLED_WriteData_8x16 (OLED_Data8x16 arr )
99110{
100- uint32_t x = _x , page = _page ;
101- OLED_WriteDataArray (( * arr ) [0 ], 8 );
111+ uint8_t x = _x , page = _page ;
112+ OLED_WriteDataArray (arr [0 ], 8 );
102113 OLED_SetColumnAndPage (x , page + 1 );
103- OLED_WriteDataArray (( * arr ) [1 ], 8 );
114+ OLED_WriteDataArray (arr [1 ], 8 );
104115 OLED_SetPage (page );
105116}
106117
107- void OLED_WriteData_16x16 (uint8_t ( * arr )[ 2 ][ 16 ] )
118+ void OLED_WriteData_16x16 (OLED_Data16x16 arr )
108119{
109- uint32_t x = _x , page = _page ;
110- OLED_WriteDataArray (( * arr ) [0 ], 16 );
120+ uint8_t x = _x , page = _page ;
121+ OLED_WriteDataArray (arr [0 ], 16 );
111122 OLED_SetColumnAndPage (x , page + 1 );
112- OLED_WriteDataArray (( * arr ) [1 ], 16 );
123+ OLED_WriteDataArray (arr [1 ], 16 );
113124 OLED_SetPage (page );
114125}
115126
116127void OLED_WriteDataArray (uint8_t * arr , uint8_t len )
117128{
118- uint32_t i = 0 ;
129+ uint8_t i = 0 ;
119130 while (i < len )
120131 {
121- _WriteWord (0x4000 | arr [i ++ ]);
132+ _WriteWord (0x4000 | ( uint16_t ) arr [i ++ ]);
122133 }
123134 _AddPosition (len );
124135}
125136
126137void OLED_ClearEndOfPage (uint8_t page )
127138{
128- int x = _x ;
139+ int8_t x = _x ;
129140
130141 OLED_SetPage (page );
131142
@@ -161,7 +172,7 @@ void OLED_ClearAll(void)
161172
162173#ifdef OLED_USE_8x16_CHAR_TABLE
163174
164- const unsigned char _ascii_8x16 [][ 2 ][ 8 ] = {
175+ CONST OLED_Data8x16 CODE _ascii_8x16 [] = {
165176 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , // 0
166177 0x00 , 0x00 , 0x00 , 0xF8 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x33 , 0x30 , 0x00 , 0x00 , 0x00 , //! 1
167178 0x00 , 0x10 , 0x0C , 0x06 , 0x10 , 0x0C , 0x06 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , //" 2
@@ -259,11 +270,11 @@ const unsigned char _ascii_8x16[][2][8] = {
259270 0x00 , 0x06 , 0x01 , 0x01 , 0x02 , 0x02 , 0x04 , 0x04 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 //~ 94
260271};
261272
262- #define CHAR_8X16 (_code ) ((uint8_t(*)[2][8]) & _ascii_8x16[(_code)-32])
273+ #define CHAR_8X16 (_code ) _ascii_8x16[(_code)-32]
263274
264- void OLED_WriteString_8x16 (char * _str )
275+ void OLED_WriteString_8x16 (const char * _str )
265276{
266- unsigned int index = 0 ;
277+ uint16_t index = 0 ;
267278
268279 while (_str [index ] != 0 )
269280 {
0 commit comments