SSD1306 OLED display driver 1.8.2 This library is developed to control SSD1306/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays

lcd_common.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/lcd_common.h"
26 #include "intf/ssd1306_interface.h"
27 #include "intf/spi/ssd1306_spi.h"
28 #include <stddef.h>
29
30 #define CMD_ARG 0xFF
31 #define CMD_DELAY 0xFF
32
33 ssd1306_lcd_t ssd1306_lcd = { 0 };
34
35 void ssd1306_sendData(uint8_t data)
36 {
37 ssd1306_dataStart();
38 ssd1306_lcd.send_pixels1( data );
39 ssd1306_intf.stop();
40 }
41
42 void ssd1306_configureI2cDisplay(const uint8_t *config, uint8_t configSize)
43 {
44 ssd1306_commandStart();
45 for( uint8_t i=0; i<configSize; i++)
46 {
47 uint8_t data = pgm_read_byte(&config[i]);
48 ssd1306_intf.send(data);
49 }
50 ssd1306_intf.stop();
51 }
52
53 void ssd1306_configureSpiDisplay(const uint8_t *config, uint8_t configSize)
54 {
55 ssd1306_intf.start();
56 ssd1306_spiDataMode(0);
57 for( uint8_t i=0; i<configSize; i++)
58 {
59 uint8_t data = pgm_read_byte(&config[i]);
60 if (data == CMD_ARG)
61 {
62 data = pgm_read_byte(&config[++i]);
63 ssd1306_spiDataMode(1);
64 ssd1306_intf.send(data);
65 ssd1306_spiDataMode(0);
66 }
67 else
68 {
69 ssd1306_intf.send(data);
70 }
71 }
72 ssd1306_intf.stop();
73 }
74
75 void ssd1306_configureSpiDisplay2(const uint8_t *config, uint8_t configSize)
76 {
77 uint8_t command = 1;
78 int8_t args;
79 ssd1306_intf.start();
80 ssd1306_spiDataMode(0);
81 for( uint8_t i=0; i<configSize; i++)
82 {
83 uint8_t data = pgm_read_byte(&config[i]);
84 if ( command )
85 {
86 if ( command == CMD_DELAY )
87 {
88 command = 1;
89 delay( data == 0xFF ? 500: data );
90 }
91 else
92 {
93 ssd1306_intf.send(data);
94 command = 0;
95 args = -1;
96 }
97 }
98 else
99 {
100 if (args < 0)
101 {
102 if ( data >= 128 )
103 {
104 command = data;
105 }
106 else if ( data > 0 )
107 {
108 args = data;
109 ssd1306_spiDataMode(1);
110 }
111 else
112 {
113 command = 1;
114 }
115 }
116 else
117 {
118 args--;
119 ssd1306_intf.send(data);
120 if ( !args )
121 {
122 command = 1;
123 ssd1306_spiDataMode(0);
124 }
125 }
126 }
127 }
128 ssd1306_intf.stop();
129 }
130
131 void ssd1306_setMode(lcd_mode_t mode)
132 {
133 if (ssd1306_lcd.set_mode)
134 {
135 ssd1306_lcd.set_mode( mode );
136 }
137 }
138
139 void ssd1306_resetController(int8_t rstPin, uint8_t delayMs)
140 {
141 pinMode(rstPin, OUTPUT);
142 digitalWrite(rstPin, HIGH);
143 /* Wait at least 10ms after VCC is up for LCD */
144 delay(10);
145 /* Perform reset operation of LCD display */
146 digitalWrite(rstPin, LOW);
147 delay(delayMs);
148 digitalWrite(rstPin, HIGH);
149 }
150
ssd1306_configureSpiDisplay2
void ssd1306_configureSpiDisplay2(const uint8_t *config, uint8_t configSize)
Sends configuration being passed to lcd display spi controller.
Definition: lcd_common.c:75
ssd1306_setMode
void ssd1306_setMode(lcd_mode_t mode)
Sets library display mode for direct draw functions.
Definition: lcd_common.c:131
ssd1306_configureSpiDisplay
void ssd1306_configureSpiDisplay(const uint8_t *config, uint8_t configSize)
Sends configuration being passed to lcd display spi controller.
Definition: lcd_common.c:53
ssd1306_lcd_t
Definition: lcd_common.h:88
ssd1306_interface_t::send
void(* send)(uint8_t data)
Definition: ssd1306_interface.h:70
lcd_common.h
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:42
ssd1306_interface_t::stop
void(* stop)(void)
Definition: ssd1306_interface.h:65
ssd1306_dataStart
void ssd1306_dataStart(void)
Definition: ssd1306_interface.c:45
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_resetController
void ssd1306_resetController(int8_t rstPin, uint8_t delayMs)
Does hardware reset for oled controller.
Definition: lcd_common.c:139
ssd1306_lcd_t::send_pixels1
void(* send_pixels1)(uint8_t data)
Definition: lcd_common.h:128
ssd1306_spi.h
ssd1306_interface_t::start
void(* start)(void)
Definition: ssd1306_interface.h:61
ssd1306_lcd
ssd1306_lcd_t ssd1306_lcd
Definition: lcd_common.c:33
ssd1306_intf
ssd1306_interface_t ssd1306_intf
Definition: ssd1306_interface.c:31
ssd1306_interface.h
ssd1306_commandStart
void ssd1306_commandStart(void)
Definition: ssd1306_interface.c:36
ssd1306_sendData
void ssd1306_sendData(uint8_t data)
Definition: lcd_common.c:35
ssd1306_lcd_t::set_mode
void(* set_mode)(lcd_mode_t mode)
Sets library display mode for direct draw functions.
Definition: lcd_common.h:164