SSD1306 OLED display driver  1.5.0
This library is developed to control SSD1306/SSD1331 RGB i2c/spi OLED displays and spi PCD8544 LED display
oled_sh1106.c
1 /*
2  MIT License
3 
4  Copyright (c) 2017-2018, Alexey Dynda
5 
6  Permission is hereby granted, free of charge, to any person obtaining a copy
7  of this software and associated documentation files (the "Software"), to deal
8  in the Software without restriction, including without limitation the rights
9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  copies of the Software, and to permit persons to whom the Software is
11  furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in all
14  copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  SOFTWARE.
23 */
24 
25 #include "oled_sh1106.h"
26 #include "lcd_common.h"
27 #include "ssd1306_commands.h"
28 #include "intf/ssd1306_interface.h"
29 #include "i2c/ssd1306_i2c.h"
30 #include "spi/ssd1306_spi.h"
31 #include "hal/io.h"
32 
33 
34 static const uint8_t PROGMEM s_oled128x64_initData[] =
35 {
36  SSD1306_DISPLAYOFF, // display off
37  SSD1306_COMSCANDEC, // Scan from 127 to 0 (Reverse scan)
38  SSD1306_SETSTARTLINE | 0x00, // First line to start scanning from
39  SSD1306_SETCONTRAST, 0x7F, // contast value to 0x7F according to datasheet
40  SSD1306_SEGREMAP | 0x01, // Use reverse mapping. 0x00 - is normal mapping
41  SSD1306_NORMALDISPLAY,
42  SSD1306_SETMULTIPLEX, 63, // Reset to default MUX. See datasheet
43  SSD1306_SETDISPLAYOFFSET, 0x00, // no offset
44  SSD1306_SETDISPLAYCLOCKDIV, 0x80,// set to default ratio/osc frequency
45  SSD1306_SETPRECHARGE, 0x22, // switch precharge to 0x22 // 0xF1
46  SSD1306_SETCOMPINS, 0x12, // set divide ratio
47  SSD1306_SETVCOMDETECT, 0x20, // vcom deselect to 0x20 // 0x40
48  SSD1306_CHARGEPUMP, 0x14, // Enable charge pump
49  SSD1306_DISPLAYALLON_RESUME,
50  SSD1306_DISPLAYON
51 };
52 
53 static uint8_t s_column;
54 static uint8_t s_page;
55 
56 static void sh1106_setBlock(uint8_t x, uint8_t y, uint8_t w)
57 {
58  s_column = x;
59  s_page = y;
61  ssd1306_sendByte(SSD1306_SETPAGE | y);
62  ssd1306_sendByte((x>>4) | SSD1306_SETHIGHCOLUMN);
63  ssd1306_sendByte((x & 0x0f) | SSD1306_SETLOWCOLUMN);
65  {
67  }
68  else
69  {
72  }
73 }
74 
75 static void sh1106_nextPage(void)
76 {
78  sh1106_setBlock(s_column,s_page+1,0);
79 }
80 
82 {
84  s_displayHeight = 64;
85  s_displayWidth = 128;
86  ssd1306_setRamBlock = sh1106_setBlock;
87  ssd1306_nextRamPage = sh1106_nextPage;
89  for( uint8_t i=0; i<sizeof(s_oled128x64_initData); i++)
90  {
91  ssd1306_sendCommand(pgm_read_byte(&s_oled128x64_initData[i]));
92  }
93 }
94 
96 {
99 }
100 
101 void sh1106_128x64_spi_init(int8_t rstPin, int8_t cesPin, int8_t dcPin)
102 {
103  if (rstPin >=0)
104  {
105  pinMode(rstPin, OUTPUT);
106  digitalWrite(rstPin, HIGH);
107  /* Wait at least 1ms after VCC is up for LCD */
108  delay(1);
109  /* Perform reset operation of LCD display */
110  digitalWrite(rstPin, LOW);
111  delay(10);
112  digitalWrite(rstPin, HIGH);
113  }
114  ssd1306_spiInit(cesPin, dcPin);
116 }
uint8_t ssd1306_dcQuickSwitch
void ssd1306_i2cInit(void)
void sh1106_128x64_init()
Inits 128x64 OLED display (based on SH1106 controller).
Definition: oled_sh1106.c:81
uint8_t s_displayWidth
void(* ssd1306_dataStart)(void)
void ssd1306_spiDataMode(uint8_t mode)
Definition: ssd1306_spi.c:65
void ssd1306_spiInit(int8_t cesPin, int8_t dcPin)
Definition: ssd1306_spi.c:39
void(* ssd1306_endTransmission)(void)
uint8_t g_lcd_type
void(* ssd1306_sendByte)(uint8_t data)
void ssd1306_sendCommand(uint8_t command)
void(* ssd1306_commandStart)(void)
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: oled_sh1106.c:101
void(* ssd1306_setRamBlock)(uint8_t x, uint8_t y, uint8_t w)
Definition: lcd_common.c:29
void sh1106_128x64_i2c_init(void)
Inits 128x64 OLED display over i2c (based on SH1106 controller).
Definition: oled_sh1106.c:95
uint8_t s_displayHeight
void(* ssd1306_nextRamPage)(void)
Definition: lcd_common.c:30
void(* ssd1306_sendPixels)(uint8_t data)
Definition: lcd_common.c:31