SSD1306 OLED display driver  1.4.4
This library is developed to control SSD1306/SSD1331 RGB i2c/spi OLED displays and spi PCD8544 LED display
ssd1306_128x32.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 "ssd1306_128x32.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 "hal/io.h"
31 
32 #include <stdlib.h>
33 
34 static const uint8_t PROGMEM s_oled128x32_initData[] =
35 {
36  SSD1306_DISPLAYOFF, // display off
37  SSD1306_SETDISPLAYCLOCKDIV, 0x80,
38  SSD1306_SETMULTIPLEX, 31,
39  SSD1306_SETDISPLAYOFFSET, 0x00, // --no offset
40  SSD1306_SETSTARTLINE,
41  SSD1306_CHARGEPUMP, 0x14, // 0x10
42  SSD1306_SEGREMAP | 0x01, // Reverse mapping
43  SSD1306_COMSCANDEC,
44  SSD1306_SETCOMPINS, 0x02,
45  SSD1306_SETCONTRAST, 0x7F, // contast value
46  SSD1306_SETPRECHARGE, 0x22, // 0x1F
47  SSD1306_SETVCOMDETECT, 0x40,
48  SSD1306_MEMORYMODE, HORIZONTAL_ADDRESSING_MODE,
49  SSD1306_DISPLAYALLON_RESUME,
50  SSD1306_NORMALDISPLAY,
51  SSD1306_DISPLAYON
52 };
53 
54 static void ssd1306_setBlock(uint8_t x, uint8_t y, uint8_t w)
55 {
57  ssd1306_sendByte(SSD1306_COLUMNADDR);
59  ssd1306_sendByte(x + w - 1);
60  ssd1306_sendByte(SSD1306_PAGEADDR);
64 }
65 
66 static void ssd1306_nextPage()
67 {
68 }
69 
70 
71 /*
72 // We do not need this function, since ssd1306 library works in Horizontal Addressing mode
73 static void ssd1306_setPos(uint8_t x, uint8_t y)
74 {
75  ssd1306_setBlock(0,0,s_displayWidth);
76  ssd1306_commandStart();
77  ssd1306_sendByte(SSD1306_SETPAGE | y);
78  ssd1306_sendByte((x>>4) | SSD1306_SETHIGHCOLUMN);
79  ssd1306_sendByte((x & 0x0f) | SSD1306_SETLOWCOLUMN);
80  ssd1306_endTransmission();
81 }
82 */
83 
85 {
87  s_displayHeight = 32;
88  s_displayWidth = 128;
89  ssd1306_setRamBlock = ssd1306_setBlock;
90  ssd1306_nextRamPage = ssd1306_nextPage;
92  for( uint8_t i=0; i < sizeof(s_oled128x32_initData); i++)
93  {
94  ssd1306_sendCommand(pgm_read_byte(&s_oled128x32_initData[i]));
95  }
96 }
97 
98 
100 {
101  ssd1306_i2cInit();
103 }
void(* ssd1306_sendByte)(uint8_t data)
void ssd1306_128x32_init()
Inits 128x32 OLED display (based on ssd1306 controller).
void(* ssd1306_endTransmission)()
void ssd1306_128x32_i2c_init()
Inits 128x32 OLED display over i2c (based on SSD1306 controller).
void(* ssd1306_nextRamPage)()
void ssd1306_sendCommand(uint8_t command)
void ssd1306_i2cInit()
void(* ssd1306_commandStart)()
uint8_t g_lcd_type
Definition: ssd1306.c:38
uint8_t s_displayHeight
Definition: ssd1306.c:36
void(* ssd1306_setRamBlock)(uint8_t x, uint8_t y, uint8_t w)
void(* ssd1306_sendPixels)(uint8_t data)
uint8_t s_displayWidth
Definition: ssd1306.c:37