SSD1306 OLED display driver  1.3.2
This library is developed to control SSD1306 i2c/spi OLED display
sh1106_128x64.c
1 /*
2  Copyright (C) 2017 Alexey Dynda
3 
4  This file is part of SSD1306 library.
5 
6  This program 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.
10 
11  This program 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.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "sh1106_128x64.h"
21 #include "lcd_common.h"
22 #include "ssd1306_commands.h"
23 #include "intf/ssd1306_interface.h"
24 #include "i2c/ssd1306_i2c.h"
25 #include "spi/ssd1306_spi.h"
26 
27 static const uint8_t PROGMEM s_oled128x64_initData[] =
28 {
29  SSD1306_DISPLAYOFF, // display off
30  SSD1306_COMSCANDEC, // Scan from 127 to 0 (Reverse scan)
31  SSD1306_SETSTARTLINE | 0x00, // First line to start scanning from
32  SSD1306_SETCONTRAST, 0x7F, // contast value to 0x7F according to datasheet
33  SSD1306_SEGREMAP | 0x01, // Use reverse mapping. 0x00 - is normal mapping
34  SSD1306_NORMALDISPLAY,
35  SSD1306_SETMULTIPLEX, 63, // Reset to default MUX. See datasheet
36  SSD1306_SETDISPLAYOFFSET, 0x00, // no offset
37  SSD1306_SETDISPLAYCLOCKDIV, 0x80,// set to default ratio/osc frequency
38  SSD1306_SETPRECHARGE, 0x22, // switch precharge to 0x22 // 0xF1
39  SSD1306_SETCOMPINS, 0x12, // set divide ratio
40  SSD1306_SETVCOMDETECT, 0x20, // vcom deselect to 0x20 // 0x40
41  SSD1306_CHARGEPUMP, 0x14, // Enable charge pump
42  SSD1306_DISPLAYALLON_RESUME,
43  SSD1306_DISPLAYON
44 };
45 
46 static uint8_t s_column;
47 static uint8_t s_page;
48 
49 static void sh1106_setBlock(uint8_t x, uint8_t y, uint8_t w)
50 {
51  s_column = x;
52  s_page = y;
54  ssd1306_sendByte(SSD1306_SETPAGE | y);
55  ssd1306_sendByte((x>>4) | SSD1306_SETHIGHCOLUMN);
56  ssd1306_sendByte((x & 0x0f) | SSD1306_SETLOWCOLUMN);
58 }
59 
60 static void sh1106_nextPage()
61 {
63  sh1106_setBlock(s_column,s_page+1,0);
65 }
66 
67 static void sh1106_setPos(uint8_t x, uint8_t y)
68 {
70  ssd1306_sendByte(SSD1306_SETPAGE | y);
71  ssd1306_sendByte((x>>4) | SSD1306_SETHIGHCOLUMN);
72  ssd1306_sendByte((x & 0x0f) | SSD1306_SETLOWCOLUMN);
74 }
75 
77 {
79  s_displayHeight = 64;
80  s_displayWidth = 128;
81  ssd1306_setRamBlock = sh1106_setBlock;
82  ssd1306_nextRamPage = sh1106_nextPage;
83  ssd1306_setRamPos = sh1106_setPos;
84  for( uint8_t i=0; i<sizeof(s_oled128x64_initData); i++)
85  {
86  ssd1306_sendCommand(pgm_read_byte(&s_oled128x64_initData[i]));
87  }
88 }
89 
91 {
94 }
95 
96 void sh1106_128x64_spi_init(int8_t rstPin, int8_t cesPin, int8_t dcPin)
97 {
98  if (rstPin >=0)
99  {
100  pinMode(rstPin, OUTPUT);
101  digitalWrite(rstPin, HIGH);
102  /* Wait at least 1ms after VCC is up for LCD */
103  delay(1);
104  /* Perform reset operation of LCD display */
105  digitalWrite(rstPin, LOW);
106  delay(10);
107  digitalWrite(rstPin, HIGH);
108  }
109  ssd1306_spiInit(cesPin, dcPin);
111 }
void sh1106_128x64_i2c_init()
Inits 128x64 OLED display over i2c (based on SH1106 controller).
Definition: sh1106_128x64.c:90
void sh1106_128x64_init()
Inits 128x64 OLED display (based on SH1106 controller).
Definition: sh1106_128x64.c:76
void(* ssd1306_sendByte)(uint8_t data)
void sh1106_128x64_spi_init(int8_t rstPin, int8_t cesPin, int8_t dcPin)
Inits 128x64 OLED display over spi (based on SH1106 controller).
Definition: sh1106_128x64.c:96
void(* ssd1306_dataStart)()
void(* ssd1306_endTransmission)()
void(* ssd1306_nextRamPage)()
void ssd1306_sendCommand(uint8_t command)
void ssd1306_i2cInit()
void(* ssd1306_commandStart)()
uint8_t g_lcd_type
Definition: ssd1306.cpp:32
uint8_t s_displayHeight
Definition: ssd1306.cpp:30
void(* ssd1306_setRamBlock)(uint8_t x, uint8_t y, uint8_t w)
void(* ssd1306_setRamPos)(uint8_t x, uint8_t y)
void ssd1306_spiInit(int8_t cesPin, int8_t dcPin)
Definition: ssd1306_spi.cpp:30
uint8_t s_displayWidth
Definition: ssd1306.cpp:31