SSD1306 OLED display driver  1.3.1
This library is developed to control SSD1306 i2c/spi OLED display
ssd1306_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 "ssd1306_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_MEMORYMODE, HORIZONTAL_ADDRESSING_MODE, // Page Addressing mode
31  SSD1306_COMSCANDEC, // Scan from 127 to 0 (Reverse scan)
32  SSD1306_SETSTARTLINE | 0x00, // First line to start scanning from
33  SSD1306_SETCONTRAST, 0x7F, // contast value to 0x7F according to datasheet
34  SSD1306_SEGREMAP | 0x01, // Use reverse mapping. 0x00 - is normal mapping
35  SSD1306_NORMALDISPLAY,
36  SSD1306_SETMULTIPLEX, 63, // Reset to default MUX. See datasheet
37  SSD1306_SETDISPLAYOFFSET, 0x00, // no offset
38  SSD1306_SETDISPLAYCLOCKDIV, 0x80,// set to default ratio/osc frequency
39  SSD1306_SETPRECHARGE, 0x22, // switch precharge to 0x22 // 0xF1
40  SSD1306_SETCOMPINS, 0x12, // set divide ratio
41  SSD1306_SETVCOMDETECT, 0x20, // vcom deselect to 0x20 // 0x40
42  SSD1306_CHARGEPUMP, 0x14, // Enable charge pump
43  SSD1306_DISPLAYALLON_RESUME,
44  SSD1306_DISPLAYON
45 };
46 
47 static void ssd1306_setBlock(uint8_t x, uint8_t y, uint8_t w)
48 {
50  ssd1306_sendByte(SSD1306_COLUMNADDR);
52  ssd1306_sendByte(w ? (x + w - 1) : (s_displayWidth - 1));
53  ssd1306_sendByte(SSD1306_PAGEADDR);
57 }
58 
59 static void ssd1306_nextPage()
60 {
61 }
62 
63 /*
64 // We do not need this function, since ssd1306 library works in Horizontal Addressing mode
65 static void ssd1306_setPos(uint8_t x, uint8_t y)
66 {
67  ssd1306_setBlock(0,0,s_displayWidth);
68  ssd1306_commandStart();
69  ssd1306_sendByte(SSD1306_SETPAGE | y);
70  ssd1306_sendByte((x>>4) | SSD1306_SETHIGHCOLUMN);
71  ssd1306_sendByte((x & 0x0f) | SSD1306_SETLOWCOLUMN);
72  ssd1306_endTransmission();
73 }
74 */
75 
77 {
79 }
80 
81 
83 {
85  s_displayHeight = 64;
86  s_displayWidth = 128;
87  ssd1306_setRamBlock = ssd1306_setBlock;
88  ssd1306_nextRamPage = ssd1306_nextPage;
89  // ssd1306 library doesn't use setRamPos intended for Page Addressing mode
90  ssd1306_setRamPos = NULL; //ssd1306_setPos;
91  for( uint8_t i=0; i<sizeof(s_oled128x64_initData); i++)
92  {
93  ssd1306_sendCommand(pgm_read_byte(&s_oled128x64_initData[i]));
94  }
95 }
96 
98 {
101 }
102 
103 void ssd1306_128x64_spi_init(int8_t rstPin, int8_t cesPin, int8_t dcPin)
104 {
105  if (rstPin >=0)
106  {
107  pinMode(rstPin, OUTPUT);
108  digitalWrite(rstPin, HIGH);
109  /* Wait at least 1ms after VCC is up for LCD */
110  delay(1);
111  /* Perform reset operation of LCD display */
112  digitalWrite(rstPin, LOW);
113  delay(10);
114  digitalWrite(rstPin, HIGH);
115  }
116  ssd1306_spiInit(cesPin, dcPin);
118 }
void ssd1306_128x64_spi_init(int8_t rstPin, int8_t cesPin, int8_t dcPin)
Inits 128x64 OLED display over spi (based on SSD1306 controller).
void(* ssd1306_sendByte)(uint8_t data)
void(* ssd1306_endTransmission)()
uint8_t ssd1306_displayHeight()
Definition: ssd1306.cpp:36
void(* ssd1306_nextRamPage)()
void ssd1306_128x64_init()
Inits 128x64 OLED display (based on SSD1306 controller).
void ssd1306_128x64_i2c_init()
Inits 128x64 OLED display over i2c (based on SSD1306 controller).
void ssd1306_sendCommand(uint8_t command)
void ssd1306_init()
Inits 128x64 OLED display over i2c (based on SSD1306 controller).
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