forked from sparkfun/SparkFun_Micro_OLED_Arduino_Library
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOpenHAK_MicroOLED.h
More file actions
230 lines (198 loc) · 6.82 KB
/
OpenHAK_MicroOLED.h
File metadata and controls
230 lines (198 loc) · 6.82 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/******************************************************************************
OpenHAK_MicroOLED.h
Header file for the MicroOLED Arduino Library
Jim Lindblom @ SparkFun Electronics
October 26, 2014
https://github.com/sparkfun/Micro_OLED_Breakout/tree/master/Firmware/Arduino/libraries/SFE_MicroOLED
Modified by:
Emil Varughese @ Edwin Robotics Pvt. Ltd.
July 27, 2015
https://github.com/emil01/SparkFun_Micro_OLED_Arduino_Library/
*
* >>>> Modified to work with OpenHAK by Joel Murphy/Biomurph Summer 2017 <<<<
* >>>> https://github.com/OpenHAK/OpenHAK_64x48_Micro_OLED_Library <<<<
*
This file defines the hardware interface(s) for the Micro OLED Breakout. Those
interfaces include SPI, I2C and a parallel bus.
Development environment specifics:
Arduino 1.0.5
Arduino Pro 3.3V
Micro OLED Breakout v1.0
This code was heavily based around the MicroView library, written by GeekAmmo
(https://github.com/geekammo/MicroView-Arduino-Library), and released under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#ifndef OPENHAK_MICROOLED_H
#define OPENHAK_MICROOLED_H
#include <stdio.h>
#include <Arduino.h>
#if defined(__AVR__) || defined(__arm__)
#include <avr/pgmspace.h>
#else
#include <pgmspace.h>
#endif
#define swap(a, b) { uint8_t t = a; a = b; b = t; }
#define I2C_ADDRESS_SA0_0 0b0111100
#define I2C_ADDRESS_SA0_1 0b0111101
#define I2C_COMMAND 0x00
#define I2C_DATA 0x40
#define OLED_SCL 2
#define OLED_SDA 3
#define OLED_RESET 25
#define DC 1
#define BLACK 0
#define WHITE 1
#define LCDWIDTH 64
#define LCDHEIGHT 48
#define FONTHEADERSIZE 6
#define FONT_5x7 0
#define FONT_8x16 1
#define SEVEN_SEGMENT 2
#define FONT_NUMBER_12x48 3
#define FONT_LETTER_31x48 4 // if included will use up flash
#define NORM 0
#define XOR 1
#define PAGE 0
#define ALL 1
#define WIDGETSTYLE0 0
#define WIDGETSTYLE1 1
#define WIDGETSTYLE2 2
#define SETCONTRAST 0x81
#define DISPLAYALLONRESUME 0xA4
#define DISPLAYALLON 0xA5
#define NORMALDISPLAY 0xA6
#define INVERTDISPLAY 0xA7
#define DISPLAYOFF 0xAE
#define DISPLAYON 0xAF
#define SETDISPLAYOFFSET 0xD3
#define SETCOMPINS 0xDA
#define SETVCOMDESELECT 0xDB
#define SETDISPLAYCLOCKDIV 0xD5
#define SETPRECHARGE 0xD9
#define SETMULTIPLEX 0xA8
#define SETLOWCOLUMN 0x00
#define SETHIGHCOLUMN 0x10
#define SETSTARTLINE 0x40
#define MEMORYMODE 0x20
#define COMSCANINC 0xC0
#define COMSCANDEC 0xC8
#define SEGREMAP 0xA0
#define CHARGEPUMP 0x8D
#define EXTERNALVCC 0x01
#define SWITCHCAPVCC 0x02
// Scroll
#define ACTIVATESCROLL 0x2F
#define DEACTIVATESCROLL 0x2E
#define SETVERTICALSCROLLAREA 0xA3
#define RIGHTHORIZONTALSCROLL 0x26
#define LEFT_HORIZONTALSCROLL 0x27
#define VERTICALRIGHTHORIZONTALSCROLL 0x29
#define VERTICALLEFTHORIZONTALSCROLL 0x2A
typedef enum CMD {
CMD_CLEAR, //0
CMD_INVERT, //1
CMD_CONTRAST, //2
CMD_DISPLAY, //3
CMD_SETCURSOR, //4
CMD_PIXEL, //5
CMD_LINE, //6
CMD_LINEH, //7
CMD_LINEV, //8
CMD_RECT, //9
CMD_RECTFILL, //10
CMD_CIRCLE, //11
CMD_CIRCLEFILL, //12
CMD_DRAWCHAR, //13
CMD_DRAWBITMAP, //14
CMD_GETLCDWIDTH, //15
CMD_GETLCDHEIGHT, //16
CMD_SETCOLOR, //17
CMD_SETDRAWMODE //18
} commCommand_t;
typedef enum COMM_MODE{
MODE_SPI,
MODE_I2C,
MODE_PARALLEL
} micro_oled_mode;
class MicroOLED : public Print{
public:
// Constructor(s)
MicroOLED(uint8_t rst, uint8_t dc);
void begin(void);
virtual size_t write(uint8_t);
// RAW LCD functions
void command(uint8_t c);
void data(uint8_t c);
void setColumnAddress(uint8_t add);
void setPageAddress(uint8_t add);
// LCD Draw functions
void clear(uint8_t mode);
void clear(uint8_t mode, uint8_t c);
void invert(boolean inv);
void contrast(uint8_t contrast);
void display(void);
void setCursor(uint8_t x, uint8_t y);
void pixel(uint8_t x, uint8_t y);
void pixel(uint8_t x, uint8_t y, uint8_t color, uint8_t mode);
void line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);
void line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color, uint8_t mode);
void lineH(uint8_t x, uint8_t y, uint8_t width);
void lineH(uint8_t x, uint8_t y, uint8_t width, uint8_t color, uint8_t mode);
void lineV(uint8_t x, uint8_t y, uint8_t height);
void lineV(uint8_t x, uint8_t y, uint8_t height, uint8_t color, uint8_t mode);
void rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height);
void rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode);
void rectFill(uint8_t x, uint8_t y, uint8_t width, uint8_t height);
void rectFill(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode);
void circle(uint8_t x, uint8_t y, uint8_t radius);
void circle(uint8_t x, uint8_t y, uint8_t radius, uint8_t color, uint8_t mode);
void circleFill(uint8_t x0, uint8_t y0, uint8_t radius);
void circleFill(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, uint8_t mode);
void drawChar(uint8_t x, uint8_t y, uint8_t c);
void drawChar(uint8_t x, uint8_t y, uint8_t c, uint8_t color, uint8_t mode);
void drawBitmap(uint8_t * bitArray);
uint8_t getLCDWidth(void);
uint8_t getLCDHeight(void);
void setColor(uint8_t color);
void setDrawMode(uint8_t mode);
uint8_t *getScreenBuffer(void);
// Font functions
uint8_t getFontWidth(void);
uint8_t getFontHeight(void);
uint8_t getTotalFonts(void);
uint8_t getFontType(void);
uint8_t setFontType(uint8_t type);
uint8_t getFontStartChar(void);
uint8_t getFontTotalChar(void);
// LCD Rotate Scroll functions
void scrollRight(uint8_t start, uint8_t stop);
void scrollLeft(uint8_t start, uint8_t stop);
void scrollVertRight(uint8_t start, uint8_t stop);
void scrollVertLeft(uint8_t start, uint8_t stop);
void scrollStop(void);
void flipVertical(boolean flip);
void flipHorizontal(boolean flip);
private:
uint8_t dcPin, rstPin;
volatile uint8_t *wrport, *wrreg, *rdport, *rdreg;
uint8_t wrpinmask, rdpinmask;
micro_oled_mode interface;
byte i2c_address;
volatile uint8_t *ssport, *dcport, *ssreg, *dcreg; // use volatile because these are fixed location port address
// uint8_t mosipinmask, sckpinmask, sspinmask, dcpinmask;
uint8_t foreColor,drawMode,fontWidth, fontHeight, fontType, fontStartChar, fontTotalChar, cursorX, cursorY;
uint16_t fontMapWidth;
static const unsigned char *fontsPointer[];
// Communication
void i2cSetup();
void i2cWrite(byte address, byte control, byte data);
};
#endif