SSD1306 OLED display driver 1.8.2 This library is developed to control SSD1306/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays

oled_ssd1325.c
1 /*
2 MIT License
3
4 Copyright (c) 2018-2019, 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_ssd1325.h"
26 #include "lcd_common.h"
27 #include "intf/ssd1306_interface.h"
28 #include "intf/spi/ssd1306_spi.h"
29 #include "ssd1306_hal/io.h"
30 #ifdef SDL_EMULATION
31 #include "sdl_core.h"
32 #endif
33
34 extern uint16_t ssd1306_color;
35
36 static const PROGMEM uint8_t s_oled_128x64_initData[] =
37 {
38 #ifdef SDL_EMULATION
39 SDL_LCD_SSD1325,
40 SDL_LCD_SSD1325_GENERIC,
41 #endif
42 0xAE, // OFF /* display off */
43 0xB3, 0x91, // CLK
44 0xA8, 0x3F, // multiplex 64
45 0xA2, 0x00, // Display offset
46 0xA1, 0x00, // Start line
47 0xAD, 0x02, // VCOMH
48 0xA0, 0x40 | 0x10 | 0x04 | 0x02 | 0x01, // REMAP: vertical increment mode
49 0x86, // CURRENT
50 0x81, 0x70, // CONTRAST
51 0xB2, 0x51, // FREQ
52 0xB1, 0x55, // PHASE
53 0xBC, 0x10, // PRECHARGE
54 0xBE, 0x1C, // VCOMH voltage
55 0xA4, // NORMAL
56 };
57
60
62
63 static uint8_t __s_column;
64 static uint8_t __s_w;
65 static uint8_t __s_w2;
66 static uint8_t __s_page;
67 static uint8_t __s_leftPixel;
68 static uint8_t __s_pos;
69
70 static void set_block_compat(lcduint_t x, lcduint_t y, lcduint_t w)
71 {
72 uint8_t rx = w ? (x + w - 1) : (ssd1306_lcd.width - 1);
73 rx = rx < ssd1306_lcd.width ? rx : (ssd1306_lcd.width - 1);
74 __s_column = x;
75 __s_page = y;
76 __s_w = w;
77 __s_w2 = rx - x + 1;
78 __s_leftPixel = 0;
79 __s_pos = __s_column;
80 ssd1306_intf.start();
81 ssd1306_spiDataMode(0);
82 ssd1306_intf.send(0x15);
83 ssd1306_intf.send(x / 2);
84 ssd1306_intf.send(rx / 2);
85 ssd1306_intf.send(0x75);
86 ssd1306_intf.send(y<<3);
87 ssd1306_intf.send(((y<<3) + 7) < ssd1306_lcd.height ? ((y<<3) + 7) : (ssd1306_lcd.height - 1));
88 ssd1306_spiDataMode(1);
89 }
90
91 static void next_page_compat(void)
92 {
93 ssd1306_intf.stop();
94 set_block_compat(__s_column,__s_page + 1, __s_w);
95 }
96
97 static void ssd1325_sendPixels(uint8_t data)
98 {
99 if (!(__s_pos & 0x01))
100 {
101 __s_leftPixel = data;
102 data = 0x00;
103 }
104 if ((__s_pos & 0x01) || (__s_pos == __s_column + __s_w2 - 1))
105 {
106 for (uint8_t i=8; i>0; i--)
107 {
108 uint8_t color = (__s_leftPixel & 0x01) ? (ssd1306_color & 0x0F) : 0;
109 color |= (((data & 0x01) ? (ssd1306_color & 0x0F): 0) << 4);
110 ssd1306_intf.send(color);
111 data >>= 1;
112 __s_leftPixel >>= 1;
113 }
114 }
115 __s_pos++;
116 }
117
118 static void ssd1325_sendPixelsBuffer(const uint8_t *buffer, uint16_t len)
119 {
120 while (len--)
121 {
122 ssd1325_sendPixels(*buffer);
123 buffer++;
124 }
125 }
126
128
129 CONTROLLER_NATIVE_SPI_BLOCK_8BIT_CMDS( 0x15, 0x75 );
130
133
134 void ssd1325_setMode(lcd_mode_t mode)
135 {
136 if (mode == LCD_MODE_NORMAL)
137 {
138 ssd1306_lcd.set_block = set_block_native;
139 ssd1306_lcd.next_page = next_page_native;
140 }
141 else if (mode == LCD_MODE_SSD1306_COMPAT )
142 {
143 ssd1306_lcd.set_block = set_block_compat;
144 ssd1306_lcd.next_page = next_page_compat;
145 }
146 ssd1306_intf.start();
147 ssd1306_spiDataMode(0);
148 ssd1306_intf.send( 0xA0 );
149 ssd1306_intf.send( 0x10 | (mode == LCD_MODE_NORMAL ? 0x00 : 0x04) );
150 ssd1306_intf.stop();
151 return;
152 }
153
154 void ssd1325_128x64_init()
155 {
156 ssd1306_lcd.type = LCD_TYPE_CUSTOM;
157 ssd1306_lcd.width = 128; // specify width
158 ssd1306_lcd.height = 64; // specify height
159 // Set functions for compatible mode
160 ssd1306_lcd.set_block = set_block_compat;
161 ssd1306_lcd.next_page = next_page_compat;
162 ssd1306_lcd.send_pixels1 = ssd1325_sendPixels;
163 ssd1306_lcd.send_pixels_buffer1 = ssd1325_sendPixelsBuffer;
164 // Set function for 8-bit mode
165 ssd1306_lcd.send_pixels8 = ssd1306_intf.send;
166 ssd1306_lcd.set_mode = ssd1325_setMode;
167 // Use one of 2 functions for initialization below
168 // Please, read help on this functions and read datasheet before you decide, which
169 // one needs to be used. For example, ssd1331 is OK with ssd1306_configureI2cDisplay(),
170 // while st7735 can be initialized only with ssd1306_configureSpiDisplay().
171 ssd1306_configureI2cDisplay(s_oled_128x64_initData, sizeof(s_oled_128x64_initData));
172 }
173
174 void ssd1325_128x64_spi_init(int8_t rstPin, int8_t cesPin, int8_t dcPin)
175 {
176 if (rstPin >=0)
177 {
178 ssd1306_resetController( rstPin, 10 );
179 }
180 ssd1306_spiInit(cesPin, dcPin);
181 ssd1325_128x64_init();
182 }
CONTROLLER_NATIVE_SPI_BLOCK_8BIT_CMDS
#define CONTROLLER_NATIVE_SPI_BLOCK_8BIT_CMDS(column_cmd, row_cmd)
Definition: lcd_common.h:366
ssd1306_interface_t::send
void(* send)(uint8_t data)
Definition: ssd1306_interface.h:70
lcd_common.h
LCD_MODE_NORMAL
Definition: lcd_common.h:75
ssd1306_configureI2cDisplay
void ssd1306_configureI2cDisplay(const uint8_t *config, uint8_t configSize)
Sends configuration being passed to lcd display i2c/spi controller.
Definition: lcd_common.c:42
ssd1306_interface_t::stop
void(* stop)(void)
Definition: ssd1306_interface.h:65
ssd1306_lcd_t::set_block
void(* set_block)(lcduint_t x, lcduint_t y, lcduint_t w)
Sets block in RAM of lcd display controller to write data to.
Definition: lcd_common.h:114
io.h
ssd1306_lcd_t::send_pixels8
void(* send_pixels8)(uint8_t data)
Sends RGB pixel encoded in 3-3-2 format to OLED driver. Sends RGB pixel encoded in 3-3-2 format to OL...
Definition: lcd_common.h:142
ssd1306_spiDataMode
void ssd1306_spiDataMode(uint8_t mode)
Definition: ssd1306_spi.c:50
lcd_mode_t
lcd_mode_t
Definition: lcd_common.h:69
ssd1306_lcd_t::send_pixels_buffer1
void(* send_pixels_buffer1)(const uint8_t *buffer, uint16_t len)
Definition: lcd_common.h:135
ssd1306_resetController
void ssd1306_resetController(int8_t rstPin, uint8_t delayMs)
Does hardware reset for oled controller.
Definition: lcd_common.c:139
ssd1306_lcd_t::send_pixels1
void(* send_pixels1)(uint8_t data)
Definition: lcd_common.h:128
oled_ssd1325.h
ssd1306_spi.h
ssd1306_interface_t::start
void(* start)(void)
Definition: ssd1306_interface.h:61
ssd1306_spiInit
void ssd1306_spiInit(int8_t cesPin, int8_t dcPin)
Definition: ssd1306_spi.c:37
ssd1306_lcd
ssd1306_lcd_t ssd1306_lcd
Definition: lcd_common.c:33
ssd1325_128x64_init
void ssd1325_128x64_init(void)
Inits 128x64 SSD1325 OLED display (based on SSD1325 controller).
Definition: oled_ssd1325.c:154
ssd1306_intf
ssd1306_interface_t ssd1306_intf
Definition: ssd1306_interface.c:31
LCD_MODE_SSD1306_COMPAT
Definition: lcd_common.h:82
ssd1306_lcd_t::height
lcduint_t height
Definition: lcd_common.h:97
ssd1325_setMode
void ssd1325_setMode(lcd_mode_t mode)
Sets GDRAM autoincrement mode.
Definition: oled_ssd1325.c:134
ssd1306_interface.h
ssd1306_lcd_t::next_page
void(* next_page)(void)
Definition: lcd_common.h:122
LCD_TYPE_CUSTOM
Definition: lcd_common.h:61
ssd1306_lcd_t::width
lcduint_t width
Definition: lcd_common.h:94
ssd1306_lcd_t::type
lcd_type_t type
Definition: lcd_common.h:91
ssd1306_lcd_t::set_mode
void(* set_mode)(lcd_mode_t mode)
Sets library display mode for direct draw functions.
Definition: lcd_common.h:164
ssd1325_128x64_spi_init
void ssd1325_128x64_spi_init(int8_t rstPin, int8_t cesPin, int8_t dcPin)
Inits 128x64 SSD1325 OLED display over spi (based on SSD1325 controller).
Definition: oled_ssd1325.c:174