SSD1306 OLED display driver  1.8.2
This library is developed to control SSD1306/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays
lcd_pcd8544.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 "lcd_pcd8544.h"
26 #include "lcd_common.h"
27 #include "pcd8544_commands.h"
28 #include "intf/ssd1306_interface.h"
29 #include "intf/spi/ssd1306_spi.h"
30 #include "ssd1306_hal/io.h"
31 #ifdef SDL_EMULATION
32 #include "sdl_core.h"
33 #endif
34 
35 
36 static const uint8_t PROGMEM s_lcd84x48_initData[] =
37 {
38 #ifdef SDL_EMULATION
39  SDL_LCD_PCD8544,
40  0x00,
41 #endif
42  PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION, // switch to extented commands
43  PCD8544_SETVOP | 0x16, // Set vop contrast
44  PCD8544_SETTEMP,
45  PCD8544_SETBIAS | 0x04, // Set bias mode
46  PCD8544_FUNCTIONSET, // switch to basic commands
47  PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL
48 };
49 
50 static uint8_t s_column;
51 static uint8_t s_page;
52 static uint8_t s_width;
53 
54 static void pcd8544_setBlock(lcduint_t x, lcduint_t y, lcduint_t w)
55 {
56  s_width = w;
57  s_column = x;
58  s_page = y;
61  if (w == 1) ssd1306_intf.send( 0x22 ); else ssd1306_intf.send( 0x20 );
62  ssd1306_intf.send(0x80 | x);
63  ssd1306_intf.send(0x40 | y);
65 }
66 
67 static void pcd8544_nextPage(void)
68 {
69  if ( s_width != 1)
70  {
72  pcd8544_setBlock(s_column, s_page+1, s_width);
73  }
74 }
75 
76 static void pcd8544_setMode(lcd_mode_t mode)
77 {
78 }
79 
81 {
83  ssd1306_lcd.width = 84;
84  ssd1306_lcd.height = 48;
87  ssd1306_lcd.set_block = pcd8544_setBlock;
88  ssd1306_lcd.next_page = pcd8544_nextPage;
91  ssd1306_lcd.set_mode = pcd8544_setMode;
92 
93  for( uint8_t i=0; i<sizeof(s_lcd84x48_initData); i++)
94  {
95  ssd1306_intf.send(pgm_read_byte(&s_lcd84x48_initData[i]));
96  }
98 }
99 
100 void pcd8544_84x48_spi_init(int8_t rstPin, int8_t cesPin, int8_t dcPin)
101 {
102  if (rstPin >=0)
103  {
104  ssd1306_resetController( rstPin, 1 );
105  }
106  ssd1306_spiInit(cesPin, dcPin);
108 }
void(* send)(uint8_t data)
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 ssd1306_spiDataMode(uint8_t mode)
Definition: ssd1306_spi.c:50
lcd_mode_t
Definition: lcd_common.h:69
void pcd8544_84x48_spi_init(int8_t rstPin, int8_t cesPin, int8_t dcPin)
Definition: lcd_pcd8544.c:100
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
ssd1306_interface_t ssd1306_intf
lcduint_t height
Definition: lcd_common.h:97
void pcd8544_84x48_init()
Inits 84x48 LED display (based on PCD8544 controller).
Definition: lcd_pcd8544.c:80
void(* send_buffer)(const uint8_t *buffer, uint16_t size)
Sends bytes to SSD1306 device.
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