forked from jonesman/ArduiPi_OLED
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ArduiPi_OLED.h
220 lines (166 loc) · 7.31 KB
/
ArduiPi_OLED.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*********************************************************************
This is a library for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98
These displays use SPI to communicate, 4 or 5 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
02/18/2013 Charles-Henri Hallard (http://hallard.me)
Modified for compiling and use on Raspberry ArduiPi Board
LCD size and connection are now passed as arguments on
the command line (no more #define on compilation needed)
ArduiPi project documentation http://hallard.me/arduipi
07/26/2013 Charles-Henri Hallard (http://hallard.me)
modified name for generic library using different OLED type
--- European time format ---
23/12/2018 Destroyedlolo (http://destroyedlolo.info)
I2C device is passed as argument
30/12/2018 Destroyedlolo (http://destroyedlolo.info)
Add Flip()
03/01/2019 Destroyedlolo (http://destroyedlolo.info)
Add SaveToPBM()
*********************************************************************/
#ifndef _ArduiPi_OLED_H
#define _ArduiPi_OLED_H
#include "Adafruit_GFX.h"
#define BLACK 0
#define WHITE 1
/*=========================================================================
SSDxxxx Common Displays
-----------------------------------------------------------------------
Common values to all displays
=========================================================================*/
//#define SSD_Command_Mode 0x80 /* DC bit is 0 */ Seeed set C0 to 1 why ?
#define SSD_Command_Mode 0x00 /* C0 and DC bit are 0 */
#define SSD_Data_Mode 0x40 /* C0 bit is 0 and DC bit is 1 */
#define SSD_Set_Segment_Remap 0xA0
#define SSD_Inverse_Display 0xA7
#define SSD_Set_Muliplex_Ratio 0xA8
#define SSD_Display_Off 0xAE
#define SSD_Display_On 0xAF
#define SSD_Set_ContrastLevel 0x81
#define SSD_External_Vcc 0x01
#define SSD_Internal_Vcc 0x02
#define SSD_Set_Column_Address 0x21
#define SSD_Set_Page_Address 0x22
#define SSD_Activate_Scroll 0x2F
#define SSD_Deactivate_Scroll 0x2E
#define SSD_Right_Horizontal_Scroll 0x26
#define SSD_Left_Horizontal_Scroll 0x27
#define Scroll_Left 0x00
#define Scroll_Right 0x01
#define Scroll_2Frames 0x07
#define Scroll_3Frames 0x04
#define Scroll_4Frames 0x05
#define Scroll_5Frames 0x00
#define Scroll_25Frames 0x06
#define Scroll_64Frames 0x01
#define Scroll_128Frames 0x02
#define Scroll_256Frames 0x03
#define VERTICAL_MODE 01
#define PAGE_MODE 01
#define HORIZONTAL_MODE 02
/*=========================================================================
SSD1306 Displays
-----------------------------------------------------------------------
The driver is used in multiple displays (128x64, 128x32, etc.).
=========================================================================*/
#define SSD1306_Entire_Display_Resume 0xA4
#define SSD1306_Entire_Display_On 0xA5
#define SSD1306_Normal_Display 0xA6
#define SSD1306_Set_Display_Offset 0xD3
#define SSD1306_Set_Com_Pins 0xDA
#define SSD1306_Set_Vcomh_Deselect_Level 0xDB
#define SSD1306_Set_Display_Clock_Div 0xD5
#define SSD1306_Set_Precharge_Period 0xD9
#define SSD1306_Set_Lower_Column_Start_Address 0x00
#define SSD1306_Set_Higher_Column_Start_Address 0x10
#define SSD1306_Set_Start_Line 0x40
#define SSD1306_Set_Memory_Mode 0x20
#define SSD1306_Set_Seg_Direction_Nomal 0xA0
#define SSD1306_Set_Seg_Direction_Rever 0xA1
#define SSD1306_Set_Com_Output_Scan_Direction_Normal 0xC0
#define SSD1306_Set_Com_Output_Scan_Direction_Remap 0xC8
#define SSD1306_Charge_Pump_Setting 0x8D
// Scrolling #defines
#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3
#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A
/*=========================================================================
SSD1308 Displays
-----------------------------------------------------------------------
The driver is used in multiple displays (128x64, 128x32, etc.).
=========================================================================*/
#define SSD1308_Normal_Display 0xA6
/*=========================================================================
SSD1327 Displays
-----------------------------------------------------------------------
The driver is used in Seeed 96x96 display
=========================================================================*/
#define SSD1327_Set_Display_Start_Line 0xA1
#define SSD1327_Set_Display_Offset 0xA2
#define SSD1327_Normal_Display 0xA4
#define SSD1327_Set_Display_Clock_Div 0xB3
#define SSD1327_Set_Command_Lock 0xFD
#define SSD1327_Set_Column_Address 0x15
#define SSD1327_Set_Row_Address 0x75
#define SSD1327_Set_Row_Address 0x75
/*=========================================================================
SH1106 Displays
-----------------------------------------------------------------------
The driver is used in multiple displays (128x64, 128x32, etc.).
=========================================================================*/
#define SH1106_Set_Page_Address 0xB0
class ArduiPi_OLED : public Adafruit_GFX
{
public:
ArduiPi_OLED();
boolean init(uint8_t OLED_TYPE, const char *device);
boolean oled_is_spi_proto(uint8_t OLED_TYPE); /* to know protocol before init */
boolean select_oled(uint8_t OLED_TYPE, const char *device);
void begin(void);
void close(void);
void sendCommand(uint8_t c);
void sendCommand(uint8_t c0, uint8_t c1);
void sendCommand(uint8_t c0, uint8_t c1, uint8_t c2);
void sendData(uint8_t c);
void clearDisplay(void);
void setGrayLevel(uint8_t grayLevel);
void setBrightness(uint8_t Brightness);
void invertDisplay(uint8_t i);
void display();
void OnOff( boolean );
void Flip( boolean );
boolean SaveToPBM(const char *);
void setSeedTextXY(unsigned char Row, unsigned char Column);
void putSeedChar(char C);
void putSeedString(const char *String);
int16_t getOledWidth(void);
int16_t getOledHeight(void);
void startscrollright(uint8_t start, uint8_t stop);
void startscrollleft(uint8_t start, uint8_t stop);
void startscrolldiagright(uint8_t start, uint8_t stop);
void startscrolldiagleft(uint8_t start, uint8_t stop);
void setHorizontalScrollProperties(bool direction,uint8_t startRow, uint8_t endRow,uint8_t startColumn, uint8_t endColumn, uint8_t scrollSpeed);
void stopscroll(void);
void drawPixel(int16_t x, int16_t y, uint16_t color);
uint16_t getPixel(int16_t x, int16_t y);
private:
uint8_t *poledbuff; // Pointer to OLED data buffer in memory
int8_t _i2c_addr, dc, rst, spi;
int16_t oled_width, oled_height;
int16_t oled_buff_size;
uint8_t vcc_type;
uint8_t oled_type;
uint8_t grayH, grayL;
inline boolean isI2C(void);
inline boolean isSPI(void);
//volatile uint8_t *dcport;
//uint8_t dcpinmask;
};
#endif