-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholed.h
153 lines (116 loc) · 4.52 KB
/
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
#include "./gfx.h"
#include "i2cdev.h"
#include "ofxGPIO.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_Inverse_Display 0xA7
#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_Activate_Scroll 0x2F
#define SSD_Deactivate_Scroll 0x2E
#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_DISPLAYALLON_RESUME 0xA4
#define SSD1306_DISPLAYALLON 0xA5
#define SSD1306_Normal_Display 0xA6
#define SSD1306_SETDISPLAYOFFSET 0xD3
#define SSD1306_SETCOMPINS 0xDA
#define SSD1306_SETVCOMDETECT 0xDB
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
#define SSD1306_SETPRECHARGE 0xD9
#define SSD1306_SETMULTIPLEX 0xA8
#define SSD1306_SETLOWCOLUMN 0x00
#define SSD1306_SETHIGHCOLUMN 0x10
#define SSD1306_SETSTARTLINE 0x40
#define SSD1306_MEMORYMODE 0x20
#define SSD1306_COMSCANINC 0xC0
#define SSD1306_COMSCANDEC 0xC8
#define SSD1306_SEGREMAP 0xA0
#define SSD1306_CHARGEPUMP 0x8D
// Scrolling #defines
#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3
#define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26
#define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27
#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_Normal_Display 0xA4
class oled : public gfx
{
public:
GPIO* rstPin;
I2Cdev * bus;
oled();
// SPI Init
boolean init(int8_t DC, int8_t RST, int8_t CS, uint8_t OLED_TYPE);
// I2C Init
boolean init(int8_t RST, uint8_t OLED_TYPE);
boolean oled_is_spi_proto(uint8_t OLED_TYPE); /* to know protocol before init */
boolean select_oled(uint8_t OLED_TYPE) ;
void begin(void);
void close(void);
void ssd1306_command(uint8_t c);
void ssd1306_command(uint8_t c0, uint8_t c1);
void ssd1306_command(uint8_t c0, uint8_t c1, uint8_t c2);
void ssd1306_data(uint8_t c);
void clearDisplay(void);
void invertDisplay(uint8_t i);
void display();
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 stopscroll(void);
void drawPixel(int16_t x, int16_t y, uint16_t color);
private:
uint8_t *poledbuff; // Pointer to OLED data buffer in memory
int8_t _i2c_addr, dc, rst, cs;
int16_t ssd1306_lcdwidth, ssd1306_lcdheight;
uint8_t vcc_type;
inline boolean isI2C(void);
inline boolean isSPI(void);
void fastSPIwrite(uint8_t c);
void fastSPIwrite(char* tbuf, uint32_t len);
void fastI2Cwrite(uint8_t c);
void fastI2Cwrite(char* tbuf, uint32_t len);
void slowSPIwrite(uint8_t c);
//volatile uint8_t *dcport;
//uint8_t dcpinmask;
};