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 | - 21 Mar. 2016
|
---|
19 | Library modified to work with Arduino Lucky Shield
|
---|
20 | by andrea[at]arduino[dot]org
|
---|
21 | *********************************************************************/
|
---|
22 |
|
---|
23 | #if ARDUINO >= 100
|
---|
24 | #include "Arduino.h"
|
---|
25 | #define WIRE_WRITE Wire.write
|
---|
26 | #else
|
---|
27 | #include "WProgram.h"
|
---|
28 | #define WIRE_WRITE Wire.send
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | #ifdef __SAM3X8E__
|
---|
32 | typedef volatile RwReg PortReg;
|
---|
33 | typedef uint32_t PortMask;
|
---|
34 | #else
|
---|
35 | typedef volatile uint8_t PortReg;
|
---|
36 | typedef uint8_t PortMask;
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | //#include <SPI.h>
|
---|
40 | #include "Adafruit_GFX.h"
|
---|
41 |
|
---|
42 | #define BLACK 0
|
---|
43 | #define WHITE 1
|
---|
44 | #define INVERSE 2
|
---|
45 |
|
---|
46 | #define SSD1306_I2C_ADDRESS 0x3C // 011110+SA0+RW - 0x3C or 0x3D
|
---|
47 | // Address for 128x32 is 0x3C
|
---|
48 | // Address for 128x64 is 0x3D (default) or 0x3C (if SA0 is grounded)
|
---|
49 |
|
---|
50 | /*=========================================================================
|
---|
51 | SSD1306 Displays
|
---|
52 | -----------------------------------------------------------------------
|
---|
53 | The driver is used in multiple displays (128x64, 128x32, etc.).
|
---|
54 | Select the appropriate display below to create an appropriately
|
---|
55 | sized framebuffer, etc.
|
---|
56 |
|
---|
57 | SSD1306_128_64 128x64 pixel display
|
---|
58 |
|
---|
59 | SSD1306_128_32 128x32 pixel display
|
---|
60 |
|
---|
61 | SSD1306_96_16
|
---|
62 |
|
---|
63 | -----------------------------------------------------------------------*/
|
---|
64 | #define SSD1306_128_64
|
---|
65 | // #define SSD1306_128_32
|
---|
66 | // #define SSD1306_96_16
|
---|
67 | /*=========================================================================*/
|
---|
68 |
|
---|
69 | #if defined SSD1306_128_64 && defined SSD1306_128_32
|
---|
70 | #error "Only one SSD1306 display can be specified at once in SSD1306.h"
|
---|
71 | #endif
|
---|
72 | #if !defined SSD1306_128_64 && !defined SSD1306_128_32 && !defined SSD1306_96_16
|
---|
73 | #error "At least one SSD1306 display must be specified in SSD1306.h"
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | #if defined SSD1306_128_64
|
---|
77 | #define SSD1306_LCDWIDTH 128
|
---|
78 | #define SSD1306_LCDHEIGHT 64
|
---|
79 | #endif
|
---|
80 | #if defined SSD1306_128_32
|
---|
81 | #define SSD1306_LCDWIDTH 128
|
---|
82 | #define SSD1306_LCDHEIGHT 32
|
---|
83 | #endif
|
---|
84 | #if defined SSD1306_96_16
|
---|
85 | #define SSD1306_LCDWIDTH 96
|
---|
86 | #define SSD1306_LCDHEIGHT 16
|
---|
87 | #endif
|
---|
88 |
|
---|
89 | #define SSD1306_SETCONTRAST 0x81
|
---|
90 | #define SSD1306_DISPLAYALLON_RESUME 0xA4
|
---|
91 | #define SSD1306_DISPLAYALLON 0xA5
|
---|
92 | #define SSD1306_NORMALDISPLAY 0xA6
|
---|
93 | #define SSD1306_INVERTDISPLAY 0xA7
|
---|
94 | #define SSD1306_DISPLAYOFF 0xAE
|
---|
95 | #define SSD1306_DISPLAYON 0xAF
|
---|
96 |
|
---|
97 | #define SSD1306_SETDISPLAYOFFSET 0xD3
|
---|
98 | #define SSD1306_SETCOMPINS 0xDA
|
---|
99 |
|
---|
100 | #define SSD1306_SETVCOMDETECT 0xDB
|
---|
101 |
|
---|
102 | #define SSD1306_SETDISPLAYCLOCKDIV 0xD5
|
---|
103 | #define SSD1306_SETPRECHARGE 0xD9
|
---|
104 |
|
---|
105 | #define SSD1306_SETMULTIPLEX 0xA8
|
---|
106 |
|
---|
107 | #define SSD1306_SETLOWCOLUMN 0x00
|
---|
108 | #define SSD1306_SETHIGHCOLUMN 0x10
|
---|
109 |
|
---|
110 | #define SSD1306_SETSTARTLINE 0x40
|
---|
111 |
|
---|
112 | #define SSD1306_MEMORYMODE 0x20
|
---|
113 | #define SSD1306_COLUMNADDR 0x21
|
---|
114 | #define SSD1306_PAGEADDR 0x22
|
---|
115 |
|
---|
116 | #define SSD1306_COMSCANINC 0xC0
|
---|
117 | #define SSD1306_COMSCANDEC 0xC8
|
---|
118 |
|
---|
119 | #define SSD1306_SEGREMAP 0xA0
|
---|
120 |
|
---|
121 | #define SSD1306_CHARGEPUMP 0x8D
|
---|
122 |
|
---|
123 | #define SSD1306_EXTERNALVCC 0x1
|
---|
124 | #define SSD1306_SWITCHCAPVCC 0x2
|
---|
125 |
|
---|
126 | // Scrolling #defines
|
---|
127 | #define SSD1306_ACTIVATE_SCROLL 0x2F
|
---|
128 | #define SSD1306_DEACTIVATE_SCROLL 0x2E
|
---|
129 | #define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3
|
---|
130 | #define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26
|
---|
131 | #define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27
|
---|
132 | #define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
|
---|
133 | #define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A
|
---|
134 |
|
---|
135 | class Adafruit_SSD1306 : public Adafruit_GFX {
|
---|
136 | public:
|
---|
137 | //Adafruit_SSD1306(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS);
|
---|
138 | //Adafruit_SSD1306(int8_t DC, int8_t RST, int8_t CS);
|
---|
139 | Adafruit_SSD1306();
|
---|
140 |
|
---|
141 | void begin();
|
---|
142 | void ssd1306_command(uint8_t c);
|
---|
143 | void ssd1306_data(uint8_t c);
|
---|
144 |
|
---|
145 | void clearDisplay(void);
|
---|
146 | void invertDisplay(uint8_t i);
|
---|
147 | void display();
|
---|
148 |
|
---|
149 | void startscrollright(uint8_t start, uint8_t stop);
|
---|
150 | void startscrollleft(uint8_t start, uint8_t stop);
|
---|
151 |
|
---|
152 | void startscrolldiagright(uint8_t start, uint8_t stop);
|
---|
153 | void startscrolldiagleft(uint8_t start, uint8_t stop);
|
---|
154 | void stopscroll(void);
|
---|
155 |
|
---|
156 | void dim(boolean dim);
|
---|
157 |
|
---|
158 | void drawPixel(int16_t x, int16_t y, uint16_t color);
|
---|
159 |
|
---|
160 | virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
|
---|
161 | virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
---|
162 |
|
---|
163 | private:
|
---|
164 | int8_t _i2caddr, _vccstate, sid, sclk, dc, rst, cs;
|
---|
165 |
|
---|
166 | //boolean hwSPI;
|
---|
167 | //PortReg *mosiport, *clkport, *csport, *dcport;
|
---|
168 | //PortMask mosipinmask, clkpinmask, cspinmask, dcpinmask;
|
---|
169 |
|
---|
170 | inline void drawFastVLineInternal(int16_t x, int16_t y, int16_t h, uint16_t color) __attribute__((always_inline));
|
---|
171 | inline void drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t color) __attribute__((always_inline));
|
---|
172 |
|
---|
173 | };
|
---|
174 |
|
---|
175 | extern Adafruit_SSD1306 ssd1306;
|
---|