SSD1306 OLED display driver  1.6.1
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 "spi/ssd1306_spi.h"
30 #include "ssd1306_hal/io.h"
31 
32 static const uint8_t PROGMEM s_lcd84x48_initData[] =
33 {
34  PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION, // switch to extented commands
35  PCD8544_SETVOP | 0x16, // Set vop contrast
36  PCD8544_SETTEMP,
37  PCD8544_SETBIAS | 0x04, // Set bias mode
38  PCD8544_FUNCTIONSET, // switch to basic commands
39  PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL
40 };
41 
42 static uint8_t s_column;
43 static uint8_t s_page;
44 static uint8_t s_width;
45 
46 static void pcd8544_setBlock(lcduint_t x, lcduint_t y, lcduint_t w)
47 {
48  s_width = w;
49  s_column = x;
50  s_page = y;
53  if (w == 1) ssd1306_intf.send( 0x22 ); else ssd1306_intf.send( 0x20 );
54  ssd1306_intf.send(0x80 | x);
55  ssd1306_intf.send(0x40 | y);
57 }
58 
59 static void pcd8544_nextPage(void)
60 {
61  if ( s_width != 1)
62  {
64  pcd8544_setBlock(s_column, s_page+1, s_width);
65  }
66 }
67 
68 static void pcd8544_setMode(lcd_mode_t mode)
69 {
70 }
71 
73 {
75  ssd1306_lcd.width = 84;
76  ssd1306_lcd.height = 48;
79  ssd1306_lcd.set_block = pcd8544_setBlock;
80  ssd1306_lcd.next_page = pcd8544_nextPage;
83  ssd1306_lcd.set_mode = pcd8544_setMode;
84 
85  for( uint8_t i=0; i<sizeof(s_lcd84x48_initData); i++)
86  {
87  ssd1306_intf.send(pgm_read_byte(&s_lcd84x48_initData[i]));
88  }
90 }
91 
92 void pcd8544_84x48_spi_init(int8_t rstPin, int8_t cesPin, int8_t dcPin)
93 {
94  if (rstPin >=0)
95  {
96  pinMode(rstPin, OUTPUT);
97  digitalWrite(rstPin, HIGH);
98  /* Wait at least 30ms after VCC is up for LCD */
99  delay(30);
100  /* Perform reset operation of LCD display */
101  digitalWrite(rstPin, LOW);
102  delay(1);
103  digitalWrite(rstPin, HIGH);
104  }
105  ssd1306_spiInit(cesPin, dcPin);
107 }
unsigned int lcduint_t
Definition: io.h:42
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:54
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:92
void(* send_pixels_buffer1)(const uint8_t *buffer, uint16_t len)
Definition: lcd_common.h:135
void(* send_pixels1)(uint8_t data)
Definition: lcd_common.h:128
void ssd1306_spiInit(int8_t cesPin, int8_t dcPin)
Definition: ssd1306_spi.c:39
ssd1306_lcd_t ssd1306_lcd
Definition: lcd_common.c:32
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:72
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:157