SSD1306 OLED display driver  1.7.12
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 
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 
88 
91 
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  }
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 
113 {
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
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);
141 }
#define CONTROLLER_NATIVE_SPI_BLOCK_8BIT_CMDS(column_cmd, row_cmd)
Definition: lcd_common.h:345
void(* send)(uint8_t data)
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
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
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
void ssd1306_spiDataMode(uint8_t mode)
Definition: ssd1306_spi.c:50
lcd_mode_t
Definition: lcd_common.h:69
void(* send_pixels_buffer1)(const uint8_t *buffer, uint16_t len)
Definition: lcd_common.h:135
void ssd1306_resetController(int8_t rstPin, uint8_t delayMs)
Does hardware reset for oled controller.
Definition: lcd_common.c:82
void(* send_pixels1)(uint8_t data)
Definition: lcd_common.h:128
void ssd1306_spiInit(int8_t cesPin, int8_t dcPin)
Definition: ssd1306_spi.c:37
ssd1306_lcd_t ssd1306_lcd
Definition: lcd_common.c:32
void ssd1325_128x64_init(void)
Inits 128x64 SSD1325 OLED display (based on SSD1325 controller).
Definition: oled_ssd1325.c:112
ssd1306_interface_t ssd1306_intf
lcduint_t height
Definition: lcd_common.h:97
#define SSD1306_COMPAT_SPI_BLOCK_8BIT_CMDS(column_cmd, row_cmd)
Definition: lcd_common.h:309
void ssd1325_setMode(lcd_mode_t mode)
Sets GDRAM autoincrement mode.
Definition: oled_ssd1325.c:92
void(* next_page)(void)
Definition: lcd_common.h:122
lcduint_t width
Definition: lcd_common.h:94
lcd_type_t type
Definition: lcd_common.h:91
void(* set_mode)(lcd_mode_t mode)
Sets library display mode for direct draw functions.
Definition: lcd_common.h:157
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