-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSparkFunMicroOLED.h
199 lines (173 loc) · 5.87 KB
/
SparkFunMicroOLED.h
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
/*
MicroOLED Arduino Library
This program is free software: you can redistribute it and/or modify
it 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 SPARKFUN_MICRO_OLED_H
#define SPARKFUN_MICRO_OLED_H
#include <stdio.h>
#include <stdint.h>
#include "application.h"
#define swap(a, b) { uint8_t t = a; a = b; b = t; }
#define _BV(x) (1 << x)
#define pgm_read_byte(x) (*(x))
#define pgm_read_word(x) (*(x))
#define pgm_read_float(x) (*(x))
#define DC_DEFAULT D6
#define RST_DEFAULT D7
#define CS_DEFAULT A2
#define MODE_DEFAULT MODE_SPI
#define I2C_ADDRESS_SA0_0 0b0111100
#define I2C_ADDRESS_SA0_1 0b0111101
#define I2C_COMMAND 0x00
#define I2C_DATA 0x40
#define BLACK 0
#define WHITE 1
#define LCDWIDTH 64
#define LCDHEIGHT 48
#define FONTHEADERSIZE 6
#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
} micro_oled_mode;
class MicroOLED : public Print
{
public:
MicroOLED(micro_oled_mode mode = MODE_DEFAULT, uint8_t rst = RST_DEFAULT, uint8_t dc = DC_DEFAULT, uint8_t cs = CS_DEFAULT);
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(bool 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(const uint8_t * bitArray);
uint8_t getLCDWidth(void);
uint8_t getLCDHeight(void);
void setColor(uint8_t color);
void setDrawMode(uint8_t mode);
// 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(bool flip);
void flipHorizontal(bool flip);
private:
uint8_t csPin, dcPin, rstPin;
uint8_t wrPin, rdPin, dPins[8];
volatile uint8_t *wrport, *wrreg, *rdport, *rdreg;
uint8_t wrpinmask, rdpinmask;
micro_oled_mode interface;
uint8_t foreColor,drawMode,fontWidth, fontHeight, fontType, fontStartChar, fontTotalChar, cursorX, cursorY;
uint16_t fontMapWidth;
static const unsigned char *fontsPointer[];
void setup(micro_oled_mode mode, uint8_t rst, uint8_t dc, uint8_t cs);
// Communication
void spiTransfer(uint8_t data);
void spiSetup();
void i2cSetup();
void i2cWrite(uint8_t address, uint8_t control, uint8_t data);
};
#endif