forked from jg-storey/ded
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pather_oled.cpp
More file actions
216 lines (193 loc) · 5.37 KB
/
er_oled.cpp
File metadata and controls
216 lines (193 loc) · 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/***************************************************
//Web: http://www.buydisplay.com
EastRising Technology Co.,LTD
****************************************************/
//May 2022. Contains modifications by James Storey to imitate F-16 Data Entry Display.
#include <SPI.h>
#include "er_oled.h"
void command(uint8_t cmd)
{
digitalWrite(OLED_DC, LOW);
digitalWrite(OLED_CS, LOW);
SPI.transfer(cmd);
digitalWrite(OLED_CS, HIGH);
}
void data(uint8_t dat)
{
digitalWrite(OLED_DC, HIGH);
digitalWrite(OLED_CS, LOW );
SPI.transfer(dat);
digitalWrite(OLED_CS, HIGH);
}
void er_oled_begin()
{
pinMode(OLED_RST, OUTPUT);
pinMode(OLED_DC, OUTPUT);
pinMode(OLED_CS, OUTPUT);
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV128);
digitalWrite(OLED_CS, LOW);
digitalWrite(OLED_RST, HIGH);
delay(10);
digitalWrite(OLED_RST, LOW);
delay(10);
digitalWrite(OLED_RST, HIGH);
command(0xFD); /*SET COMMAND LOCK*/
data(0x12); /* UNLOCK */
command(0xAE); /*DISPLAY OFF*/
command(0xB3);/*DISPLAYDIVIDE CLOCKRADIO/OSCILLATAR FREQUANCY*/
data(0x91); command(0xCA); /*multiplex ratio*/
data(0x3F); /*duty = 1/64*/
command(0xA2); /*set offset*/
data(0x00);
command(0xA1); /*start line*/
data(0x00);
command(0xA0); /*set remap*/
data(0x14);
data(0x11);
command(0xAB); /*funtion selection*/
data(0x01); /* selection external vdd */
command(0xB4); /* */
data(0xA0);
data(0xfd);
command(0xC1); /*set contrast current */
data(0x80);
command(0xC7); /*master contrast current control*/
data(0x0f);
command(0xB1); /*SET PHASE LENGTH*/
data(0xE2);
command(0xD1); /**/
data(0x82);
data(0x20);
command(0xBB); /*SET PRE-CHANGE VOLTAGE*/
data(0x1F);
command(0xB6); /*SET SECOND PRE-CHARGE PERIOD*/
data(0x08);
command(0xBE); /* SET VCOMH */
data(0x07);
command(0xA6); /*normal display*/
command(0xAF); /*display ON*/
}
void er_oled_SetWindow(uint8_t Xstart, uint8_t Ystart, uint8_t Xend, uint8_t Yend)
{
command(0x15);
data(Xstart+0x1c);
data(Xend+0x1c);
command(0x75);
data(Ystart);
data(Yend);
command(0x5c);//write ram command
}
void er_oled_clear()
{int i,row;
command(0x15);
data(0x00); //col start
data(0x77); //col end
command(0x75);
data(0x00); //row start
data(0x7f); //row end
command(0x5c);
for (row = 0; row < 128; row++) {
for(i = 0; i< 240; i++ ) {
data(0x00);// write data
}
}
}
// Modified by James Storey for characters with 11 rows of pixels (instead of 16 rows).
void er_oled_char(uint8_t x, uint8_t y, const char *acsii, uint8_t mode)
{ uint8_t i,str;uint16_t OffSet;
x=x/4;
OffSet = (*acsii - 32)*11;
er_oled_SetWindow(x, y, x+1, y+11);
for (i=0;i<11;i++)
{ str =pgm_read_byte(&AsciiLib[OffSet + i]);
if(mode) str=~str;
Data_processing (str);
}
}
void er_oled_string(uint8_t x, uint8_t y, const char *pString, uint8_t Mode)
{
while(1)
{
if (*pString == 0)
{
return;
}
er_oled_char(x, y, pString,Mode);
x += 8;
pString += 1;
}
}
//Created by James Storey. Similar to er_oled_string but changes asterisk color and only prints first 24 characters
//because sometimes the DCS bios string contains extra characters.
void er_oled_dedstring(uint8_t x, uint8_t y, const char *pString, uint8_t Mode)
{
while(1)
{
if (*pString == 0)
{
return;
}
if(*pString==42){
//character is an asterisk so make it dark on light background.
er_oled_char(x,y,pString,1);
}else{
er_oled_char(x,y,pString,Mode);
}
x += 8;
if(x>24*8){
return;
}
pString += 1;
}
}
void Data_processing(uint8_t temp) //turns 1byte B/W data to 4 bye gray data with 8 Pixel
{uint8_t temp1,temp2;
if(temp&0x80)temp1=0xf0;
else temp1=0x00;
if(temp&0x40)temp2=0x0f;
else temp2=0x00;
temp1=temp1|temp2;
data(temp1); //Pixel1,Pixel2
if(temp&0x20)temp1=0xf0;
else temp1=0x00;
if(temp&0x10)temp2=0x0f;
else temp2=0x00;
temp1=temp1|temp2;
data(temp1); //Pixel3,Pixel4
if(temp&0x08)temp1=0xf0;
else temp1=0x00;
if(temp&0x04)temp2=0x0f;
else temp2=0x00;
temp1=temp1|temp2;
data(temp1); //Pixel5,Pixel6
if(temp&0x02)temp1=0xf0;
else temp1=0x00;
if(temp&0x01)temp2=0x0f;
else temp2=0x00;
temp1=temp1|temp2;
data(temp1); //Pixel7,Pixel8
}
/*
void er_oled_bitmap_mono(const uint8_t * pBuf)
{ uint8_t row,col,dat;
er_oled_SetWindow(0, 0, 255/4, 63);
for (row = 0; row < 64; row++) {
for(col = 0;col<256/8; col++ ) {
dat=(pgm_read_byte(pBuf));
*pBuf++;
Data_processing(dat);
}
}
}
void er_oled_bitmap_gray(const uint8_t * pBuf)
{ uint8_t row,col;
er_oled_SetWindow(0, 0, 255/4, 63);
for (row = 0; row < 64; row++) {
for(col = 0;col<128; col++ ) {
data(pgm_read_byte(pBuf));
* pBuf++;
}
}
}
*/