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;
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));
89 }
90 
91 static void next_page_compat(void)
92 {
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 
130 
133 
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  }
148  ssd1306_intf.send( 0xA0 );
149  ssd1306_intf.send( 0x10 | (mode == LCD_MODE_NORMAL ? 0x00 : 0x04) );
150  ssd1306_intf.stop();
151  return;
152 }
153 
155 {
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
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);
182 }
#define CONTROLLER_NATIVE_SPI_BLOCK_8BIT_CMDS(column_cmd, row_cmd)
Definition: lcd_common.h:366
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:42
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:139
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:33
void ssd1325_128x64_init(void)
Inits 128x64 SSD1325 OLED display (based on SSD1325 controller).
Definition: oled_ssd1325.c:154
ssd1306_interface_t ssd1306_intf
lcduint_t height
Definition: lcd_common.h:97
void ssd1325_setMode(lcd_mode_t mode)
Sets GDRAM autoincrement mode.
Definition: oled_ssd1325.c:134
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:164
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