Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
Adafruit_SSD1306.h
1 /*********************************************************************
2 This is a library for our Monochrome OLEDs based on SSD1306 drivers
3 
4  Pick one up today in the adafruit shop!
5  ------> http://www.adafruit.com/category/63_98
6 
7 These displays use SPI to communicate, 4 or 5 pins are required to
8 interface
9 
10 Adafruit invests time and resources providing this open source code,
11 please support Adafruit and open-source hardware by purchasing
12 products from Adafruit!
13 
14 Written by Limor Fried/Ladyada for Adafruit Industries.
15 BSD license, check license.txt for more information
16 All text above, and the splash screen must be included in any redistribution
17 *********************************************************************/
18 #ifndef _Adafruit_SSD1306_H_
19 #define _Adafruit_SSD1306_H_
20 
21 #if ARDUINO >= 100
22  #include "Arduino.h"
23  #define WIRE_WRITE Wire.write
24 #else
25  #include "WProgram.h"
26  #define WIRE_WRITE Wire.send
27 #endif
28 
29 #if defined(__SAM3X8E__)
30  typedef volatile RwReg PortReg;
31  typedef uint32_t PortMask;
32  #define HAVE_PORTREG
33 #elif defined(ARDUINO_ARCH_SAMD)
34 // not supported
35 #elif defined(ESP8266) || defined(ESP32) || defined(ARDUINO_STM32_FEATHER) || defined(__arc__)
36  typedef volatile uint32_t PortReg;
37  typedef uint32_t PortMask;
38 #elif defined(__AVR__)
39  typedef volatile uint8_t PortReg;
40  typedef uint8_t PortMask;
41  #define HAVE_PORTREG
42 #else
43  // chances are its 32 bit so assume that
44  typedef volatile uint32_t PortReg;
45  typedef uint32_t PortMask;
46 #endif
47 
48 #include <SPI.h>
49 #include <Adafruit_GFX.h>
50 
51 #define BLACK 0
52 #define WHITE 1
53 #define INVERSE 2
54 
55 #define SSD1306_I2C_ADDRESS 0x3C // 011110+SA0+RW - 0x3C or 0x3D
56 // Address for 128x32 is 0x3C
57 // Address for 128x64 is 0x3D (default) or 0x3C (if SA0 is grounded)
58 
59 /*=========================================================================
60  SSD1306 Displays
61  -----------------------------------------------------------------------
62  The driver is used in multiple displays (128x64, 128x32, etc.).
63  Select the appropriate display below to create an appropriately
64  sized framebuffer, etc.
65 
66  SSD1306_128_64 128x64 pixel display
67 
68  SSD1306_128_32 128x32 pixel display
69 
70  SSD1306_96_16
71 
72  SH1106_128_64 - 1.3" OLED display version
73 
74  -----------------------------------------------------------------------*/
75 // #define SH1106_128_64
76  #define SSD1306_128_64
77 // #define SSD1306_128_32
78 // #define SSD1306_96_16
79 // #define SSD1306_64_48
80 /*=========================================================================*/
81 
82 #if defined SSD1306_128_64 && defined SH1106_128_64
83  #error "Select either SH1106 or SSD1306 display type in SSD1306.h"
84 #endif
85 
86 
87 #if defined SSD1306_128_64 && defined SSD1306_128_32
88  #error "Only one SSD1306 display can be specified at once in SSD1306.h"
89 #endif
90 #if !defined SSD1306_128_64 && !defined SSD1306_128_32 && !defined SSD1306_96_16 && !defined SSD1306_64_48 && !defined SH1106_128_64
91  #error "At least one SSD1306 display must be specified in SSD1306.h"
92 #endif
93 
94 #if defined SSD1306_128_64 || defined SH1106_128_64
95  #define SSD1306_LCDWIDTH 128
96  #define SSD1306_LCDHEIGHT 64
97 #endif
98 #if defined SSD1306_128_32
99  #define SSD1306_LCDWIDTH 128
100  #define SSD1306_LCDHEIGHT 32
101 #endif
102 #if defined SSD1306_96_16
103  #define SSD1306_LCDWIDTH 96
104  #define SSD1306_LCDHEIGHT 16
105 #elif defined SSD1306_64_48
106  #define SSD1306_LCDWIDTH 64
107  #define SSD1306_LCDHEIGHT 48
108 #endif
109 
110 #define SSD1306_SETCONTRAST 0x81
111 #define SSD1306_DISPLAYALLON_RESUME 0xA4
112 #define SSD1306_DISPLAYALLON 0xA5
113 #define SSD1306_NORMALDISPLAY 0xA6
114 #define SSD1306_INVERTDISPLAY 0xA7
115 #define SSD1306_DISPLAYOFF 0xAE
116 #define SSD1306_DISPLAYON 0xAF
117 
118 #define SSD1306_SETDISPLAYOFFSET 0xD3
119 #define SSD1306_SETCOMPINS 0xDA
120 
121 #define SSD1306_SETVCOMDETECT 0xDB
122 
123 #define SSD1306_SETDISPLAYCLOCKDIV 0xD5
124 #define SSD1306_SETPRECHARGE 0xD9
125 
126 #define SSD1306_SETMULTIPLEX 0xA8
127 
128 #define SSD1306_SETLOWCOLUMN 0x00
129 #define SSD1306_SETHIGHCOLUMN 0x10
130 
131 #define SSD1306_SETSTARTLINE 0x40
132 
133 #define SSD1306_MEMORYMODE 0x20
134 #define SSD1306_COLUMNADDR 0x21
135 #define SSD1306_PAGEADDR 0x22
136 
137 #define SSD1306_COMSCANINC 0xC0
138 #define SSD1306_COMSCANDEC 0xC8
139 
140 #define SSD1306_SEGREMAP 0xA0
141 
142 #define SSD1306_CHARGEPUMP 0x8D
143 
144 #define SSD1306_EXTERNALVCC 0x1
145 #define SSD1306_SWITCHCAPVCC 0x2
146 
147 #define SH1106_SETSTARTPAGE 0xB0
148 
149 // Scrolling #defines
150 #define SSD1306_ACTIVATE_SCROLL 0x2F
151 #define SSD1306_DEACTIVATE_SCROLL 0x2E
152 #define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3
153 #define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26
154 #define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27
155 #define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
156 #define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A
157 
159  public:
160  Adafruit_SSD1306(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS);
161  Adafruit_SSD1306(int8_t DC, int8_t RST, int8_t CS);
162  Adafruit_SSD1306(int8_t RST = -1);
163 
164  void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC, uint8_t i2caddr = SSD1306_I2C_ADDRESS, bool reset=true);
165  void ssd1306_command(uint8_t c);
166 
167  void clearDisplay(void);
168  void invertDisplay(uint8_t i);
169  void display();
170 
171  void startscrollright(uint8_t start, uint8_t stop);
172  void startscrollleft(uint8_t start, uint8_t stop);
173 
174  void startscrolldiagright(uint8_t start, uint8_t stop);
175  void startscrolldiagleft(uint8_t start, uint8_t stop);
176  void stopscroll(void);
177 
178  void dim(boolean dim);
179 
180  void drawPixel(int16_t x, int16_t y, uint16_t color);
181 
182  virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
183  virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
184 
185  private:
186  int8_t _i2caddr, _vccstate, sid, sclk, dc, rst, cs;
187  void fastSPIwrite(uint8_t c);
188 
189  boolean hwSPI;
190 #ifdef HAVE_PORTREG
191  PortReg *mosiport, *clkport, *csport, *dcport;
192  PortMask mosipinmask, clkpinmask, cspinmask, dcpinmask;
193 #endif
194 
195  inline void drawFastVLineInternal(int16_t x, int16_t y, int16_t h, uint16_t color) __attribute__((always_inline));
196  inline void drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t color) __attribute__((always_inline));
197 
198 };
199 
200 #endif /* _Adafruit_SSD1306_H_ */
Definition: Adafruit_GFX.h:13
Definition: Adafruit_SSD1306.h:158