SSD1306 OLED display driver 1.7.8 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, 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 0x00,
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, 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 SSD1306_COMPAT_SPI_BLOCK_8BIT_CMDS( 0x15, 0x75 );
64
65 static void ssd1325_sendPixels(uint8_t data)
66 {
67 for (uint8_t i=4; i>0; i--)
68 {
69 uint8_t color = (data & 0x01) ? ssd1306_color : 0;
70 color |= (((data & 0x02) ? ssd1306_color: 0) << 4);
71 ssd1306_intf.send(color);
72 data >>= 2;
73 }
74 }
75
76 static void ssd1325_sendPixelsBuffer(const uint8_t *buffer, uint16_t len)
77 {
78 while(len--)
79 {
80 ssd1325_sendPixels(*buffer);
81 buffer++;
82 }
83 }
84
86
87 CONTROLLER_NATIVE_SPI_BLOCK_8BIT_CMDS( 0x15, 0x75 );
88
91
92 void ssd1325_setMode(lcd_mode_t mode)
93 {
94 if (mode == LCD_MODE_NORMAL)
95 {
96 ssd1306_lcd.set_block = set_block_native;
97 ssd1306_lcd.next_page = next_page_native;
98 }
99 else
100 {
101 ssd1306_lcd.set_block = set_block_compat;
102 ssd1306_lcd.next_page = next_page_compat;
103 }
104 ssd1306_intf.start();
105 ssd1306_spiDataMode(0);
106 ssd1306_intf.send( 0xA0 );
107 ssd1306_intf.send( 0x10 | 0x00 | 0x00 | (mode == LCD_MODE_NORMAL ? 0x00 : 0x04) );
108 ssd1306_intf.stop();
109 return;
110 }
111
112 void ssd1325_128x64_init()
113 {
114 ssd1306_lcd.type = LCD_TYPE_CUSTOM;
115 ssd1306_lcd.width = 128; // specify width
116 ssd1306_lcd.height = 64; // specify height
117 // Set functions for compatible mode
118 ssd1306_lcd.set_block = set_block_compat;
119 ssd1306_lcd.next_page = next_page_compat;
120 ssd1306_lcd.send_pixels1 = ssd1325_sendPixels;
121 ssd1306_lcd.send_pixels_buffer1 = ssd1325_sendPixelsBuffer;
122 // Set function for 8-bit mode
123 ssd1306_lcd.send_pixels8 = ssd1306_intf.send;
124 ssd1306_lcd.set_mode = ssd1325_setMode;
125 // Use one of 2 functions for initialization below
126 // Please, read help on this functions and read datasheet before you decide, which
127 // one needs to be used. For example, ssd1331 is OK with ssd1306_configureI2cDisplay(),
128 // while st7735 can be initialized only with ssd1306_configureSpiDisplay().
129 ssd1306_configureI2cDisplay(s_oled_128x64_initData, sizeof(s_oled_128x64_initData));
130 // ssd1306_configureSpiDisplay(s_oled_WxH_initData, sizeof(s_oled_WxH_initData));
131 }
132
133 void ssd1325_128x64_spi_init(int8_t rstPin, int8_t cesPin, int8_t dcPin)
134 {
135 if (rstPin >=0)
136 {
137 ssd1306_resetController( rstPin, 10 );
138 }
139 ssd1306_spiInit(cesPin, dcPin);
140 ssd1325_128x64_init();
141 }
CONTROLLER_NATIVE_SPI_BLOCK_8BIT_CMDS
#define CONTROLLER_NATIVE_SPI_BLOCK_8BIT_CMDS(column_cmd, row_cmd)
Definition: lcd_common.h:345
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:41
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:82
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:32
ssd1325_128x64_init
void ssd1325_128x64_init(void)
Inits 128x64 SSD1325 OLED display (based on SSD1325 controller).
Definition: oled_ssd1325.c:112
ssd1306_intf
ssd1306_interface_t ssd1306_intf
Definition: ssd1306_interface.c:29
ssd1306_lcd_t::height
lcduint_t height
Definition: lcd_common.h:97
SSD1306_COMPAT_SPI_BLOCK_8BIT_CMDS
#define SSD1306_COMPAT_SPI_BLOCK_8BIT_CMDS(column_cmd, row_cmd)
Definition: lcd_common.h:309
ssd1325_setMode
void ssd1325_setMode(lcd_mode_t mode)
Sets GDRAM autoincrement mode.
Definition: oled_ssd1325.c:92
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:157
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:133