1 /* Arduino SSD1306Ascii Library
2 * Copyright (C) 2015 by William Greiman
4 * This file is part of the Arduino SSD1306Ascii Library
6 * This Library is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This Library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with the Arduino SSD1306Ascii Library. If not, see
18 * <http://www.gnu.org/licenses/>.
22 * @brief Display controller initialization commands.
26 //------------------------------------------------------------------------------
28 /** Handle AVR flash addressing. */
31 #define MEM_TYPE __attribute__ ((progmem))
33 //------------------------------------------------------------------------------
34 /** Set Lower Column Start Address for Page Addressing Mode. */
35 #define SSD1306_SETLOWCOLUMN 0x00
36 /** Set Higher Column Start Address for Page Addressing Mode. */
37 #define SSD1306_SETHIGHCOLUMN 0x10
38 /** Set Memory Addressing Mode. */
39 #define SSD1306_MEMORYMODE 0x20
40 /** Set display RAM display start line register from 0 - 63. */
41 #define SSD1306_SETSTARTLINE 0x40
42 /** Set Display Contrast to one of 256 steps. */
43 #define SSD1306_SETCONTRAST 0x81
44 /** Enable or disable charge pump. Follow with 0X14 enable, 0X10 disable. */
45 #define SSD1306_CHARGEPUMP 0x8D
46 /** Set Segment Re-map between data column and the segment driver. */
47 #define SSD1306_SEGREMAP 0xA0
48 /** Resume display from GRAM content. */
49 #define SSD1306_DISPLAYALLON_RESUME 0xA4
50 /** Force display on regardless of GRAM content. */
51 #define SSD1306_DISPLAYALLON 0xA5
52 /** Set Normal Display. */
53 #define SSD1306_NORMALDISPLAY 0xA6
54 /** Set Inverse Display. */
55 #define SSD1306_INVERTDISPLAY 0xA7
56 /** Set Multiplex Ratio from 16 to 63. */
57 #define SSD1306_SETMULTIPLEX 0xA8
58 /** Set Display off. */
59 #define SSD1306_DISPLAYOFF 0xAE
60 /** Set Display on. */
61 #define SSD1306_DISPLAYON 0xAF
62 /**Set GDDRAM Page Start Address. */
63 #define SSD1306_SETSTARTPAGE 0XB0
64 /** Set COM output scan direction normal. */
65 #define SSD1306_COMSCANINC 0xC0
66 /** Set COM output scan direction reversed. */
67 #define SSD1306_COMSCANDEC 0xC8
68 /** Set Display Offset. */
69 #define SSD1306_SETDISPLAYOFFSET 0xD3
70 /** Sets COM signals pin configuration to match the OLED panel layout. */
71 #define SSD1306_SETCOMPINS 0xDA
72 /** This command adjusts the VCOMH regulator output. */
73 #define SSD1306_SETVCOMDETECT 0xDB
74 /** Set Display Clock Divide Ratio/ Oscillator Frequency. */
75 #define SSD1306_SETDISPLAYCLOCKDIV 0xD5
76 /** Set Pre-charge Period */
77 #define SSD1306_SETPRECHARGE 0xD9
78 /** Deactivate scroll */
79 #define SSD1306_DEACTIVATE_SCROLL 0x2E
80 /** No Operation Command. */
81 #define SSD1306_NOP 0XE3
82 //------------------------------------------------------------------------------
83 /** Set Pump voltage value: (30H~33H) 6.4, 7.4, 8.0 (POR), 9.0. */
84 #define SH1106_SET_PUMP_VOLTAGE 0X30
85 /** First byte of set charge pump mode */
86 #define SH1106_SET_PUMP_MODE 0XAD
87 /** Second byte charge pump on. */
88 #define SH1106_PUMP_ON 0X8B
89 /** Second byte charge pump off. */
90 #define SH1106_PUMP_OFF 0X8A
91 //------------------------------------------------------------------------------
94 * @brief Device initialization structure.
98 * Pointer to initialization command bytes.
100 const uint8_t* initcmds
;
102 * Number of initialization bytes.
104 const uint8_t initSize
;
106 * Width of the diaplay in pixels.
108 const uint8_t lcdWidth
;
110 * Height of the display in pixels.
112 const uint8_t lcdHeight
;
114 * Column offset RAM to display. Used to pick start column of SH1106.
116 const uint8_t colOffset
;
118 //------------------------------------------------------------------------------
119 /** Initialization commands for a 64x48 Micro OLED display (by r7) */
120 static const uint8_t MEM_TYPE MicroOLED64x48init
[] = {
121 // Init sequence for 64x48 Micro OLED module
123 SSD1306_SETDISPLAYCLOCKDIV
, 0x80, // the suggested ratio 0x80
124 SSD1306_SETMULTIPLEX
, 0x2F, //
125 SSD1306_SETDISPLAYOFFSET
, 0x0, // no offset
126 SSD1306_SETSTARTLINE
| 0x0, // line #0
127 SSD1306_CHARGEPUMP
, 0x14, // internal vcc
128 SSD1306_NORMALDISPLAY
,
129 SSD1306_DISPLAYALLON_RESUME
,
130 SSD1306_SEGREMAP
| 0x1, // column 127 mapped to SEG0
131 SSD1306_COMSCANDEC
, // column scan direction reversed
132 SSD1306_SETCOMPINS
, 0x12, // 0x12 if height > 32 else 0x02
133 SSD1306_SETCONTRAST
, 0x7F, // contrast level 127
134 SSD1306_SETPRECHARGE
, 0xF1, // pre-charge period (1, 15)
135 SSD1306_SETVCOMDETECT
, 0x40, // vcomh regulator level
138 /** Initialize a 64x48 Micro OLED display. */
139 static const DevType MEM_TYPE MicroOLED64x48
= {
141 sizeof(MicroOLED64x48init
),
146 //------------------------------------------------------------------------------
147 // this section is based on
148 // https://github.com/olikraus/u8g2/blob/master/csrc/u8x8_d_ssd1306_96x16.c
149 /** Initialization commands for a 96x16 SSD1306 oled display. */
150 static const uint8_t MEM_TYPE SSD1306_96x16init
[] = {
151 // Init sequence for Generic 96x16 OLED module
153 SSD1306_SETDISPLAYCLOCKDIV
, 0x80, // clock divide ratio and osc frequency
154 SSD1306_SETMULTIPLEX
, 0x0F, // multiplex ratio
155 SSD1306_SETDISPLAYOFFSET
, 0x0, // display offset zero
156 SSD1306_SETSTARTLINE
| 0x0, // set display start line to 0
157 SSD1306_CHARGEPUMP
, 0x14, // charge pump setting enable
158 SSD1306_MEMORYMODE
, 0x00, // page addressing mode
159 SSD1306_SEGREMAP
| 0xA1, // segment remap
160 SSD1306_COMSCANDEC
, // scan dir reverse
161 SSD1306_SETCOMPINS
, 0x02, // com pin HW config
162 SSD1306_SETCONTRAST
, 0xAF, // set contrast level 0xaf
163 SSD1306_SETPRECHARGE
, 0xF1, // pre-charge period 0x0f1
164 SSD1306_SETVCOMDETECT
, 0x20, // vcomh deselect level
165 SSD1306_DEACTIVATE_SCROLL
, // Deactivate scroll
166 SSD1306_DISPLAYALLON_RESUME
,
167 SSD1306_NORMALDISPLAY
,
170 /* Initialize a 96x16 SSD1306 oled display. */
171 static const DevType MEM_TYPE SSD1306_96x16
= {
173 sizeof(SSD1306_96x16init
),
178 //------------------------------------------------------------------------------
179 // this section is based on https://github.com/adafruit/Adafruit_SSD1306
180 /** Initialization commands for a 128x32 SSD1306 oled display. */
181 static const uint8_t MEM_TYPE Adafruit128x32init
[] = {
182 // Init sequence for Adafruit 128x32 OLED module
184 SSD1306_SETDISPLAYCLOCKDIV
, 0x80, // the suggested ratio 0x80
185 SSD1306_SETMULTIPLEX
, 0x1F, // ratio 32
186 SSD1306_SETDISPLAYOFFSET
, 0x0, // no offset
187 SSD1306_SETSTARTLINE
| 0x0, // line #0
188 SSD1306_CHARGEPUMP
, 0x14, // internal vcc
189 SSD1306_MEMORYMODE
, 0x02, // page mode
190 SSD1306_SEGREMAP
| 0x1, // column 127 mapped to SEG0
191 SSD1306_COMSCANDEC
, // column scan direction reversed
192 SSD1306_SETCOMPINS
, 0x02, // sequential COM pins, disable remap
193 SSD1306_SETCONTRAST
, 0x7F, // contrast level 127
194 SSD1306_SETPRECHARGE
, 0xF1, // pre-charge period (1, 15)
195 SSD1306_SETVCOMDETECT
, 0x40, // vcomh regulator level
196 SSD1306_DISPLAYALLON_RESUME
,
197 SSD1306_NORMALDISPLAY
,
200 /** Initialize a 128x32 SSD1306 oled display. */
201 static const DevType MEM_TYPE Adafruit128x32
= {
203 sizeof(Adafruit128x32init
),
208 //------------------------------------------------------------------------------
209 // This section is based on https://github.com/adafruit/Adafruit_SSD1306
210 /** Initialization commands for a 128x64 SSD1306 oled display. */
211 static const uint8_t MEM_TYPE Adafruit128x64init
[] = {
212 // Init sequence for Adafruit 128x64 OLED module
214 SSD1306_SETDISPLAYCLOCKDIV
, 0x80, // the suggested ratio 0x80
215 SSD1306_SETMULTIPLEX
, 0x3F, // ratio 64
216 SSD1306_SETDISPLAYOFFSET
, 0x0, // no offset
217 SSD1306_SETSTARTLINE
| 0x0, // line #0
218 SSD1306_CHARGEPUMP
, 0x14, // internal vcc
219 SSD1306_MEMORYMODE
, 0x02, // page mode
220 SSD1306_SEGREMAP
| 0x1, // column 127 mapped to SEG0
221 SSD1306_COMSCANDEC
, // column scan direction reversed
222 SSD1306_SETCOMPINS
, 0x12, // alt COM pins, disable remap
223 SSD1306_SETCONTRAST
, 0x7F, // contrast level 127
224 SSD1306_SETPRECHARGE
, 0xF1, // pre-charge period (1, 15)
225 SSD1306_SETVCOMDETECT
, 0x40, // vcomh regulator level
226 SSD1306_DISPLAYALLON_RESUME
,
227 SSD1306_NORMALDISPLAY
,
230 /** Initialize a 128x64 oled display. */
231 static const DevType MEM_TYPE Adafruit128x64
= {
233 sizeof(Adafruit128x64init
),
238 //------------------------------------------------------------------------------
239 // This section is based on https://github.com/stanleyhuangyc/MultiLCD
240 /** Initialization commands for a 128x64 SH1106 oled display. */
241 static const uint8_t MEM_TYPE SH1106_128x64init
[] = {
243 SSD1306_SETSTARTPAGE
| 0X0, // set page address
244 SSD1306_SETCONTRAST
, 0x80, // 128
245 SSD1306_SEGREMAP
| 0X1, // set segment remap
246 SSD1306_NORMALDISPLAY
, // normal / reverse
247 SSD1306_SETMULTIPLEX
, 0x3F, // ratio 64
248 SH1106_SET_PUMP_MODE
, SH1106_PUMP_ON
, // set charge pump enable
249 SH1106_SET_PUMP_VOLTAGE
| 0X2, // 8.0 volts
250 SSD1306_COMSCANDEC
, // Com scan direction
251 SSD1306_SETDISPLAYOFFSET
, 0X00, // set display offset
252 SSD1306_SETDISPLAYCLOCKDIV
, 0X80, // set osc division
253 SSD1306_SETPRECHARGE
, 0X1F, // set pre-charge period
254 SSD1306_SETCOMPINS
, 0X12, // set COM pins
255 SSD1306_SETVCOMDETECT
, 0x40, // set vcomh
258 /** Initialize a 128x64 oled SH1106 display. */
259 static const DevType MEM_TYPE SH1106_128x64
= {
261 sizeof(SH1106_128x64init
),
264 2 // SH1106 is a 132x64 controller. Use middle 128 columns.
266 #endif // SSD1306init_h