SSD1306 OLED display driver 1.7.8 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
32 ssd1306_lcd_t ssd1306_lcd = { 0 };
33
34 void ssd1306_sendData(uint8_t data)
35 {
36 ssd1306_dataStart();
37 ssd1306_lcd.send_pixels1( data );
38 ssd1306_intf.stop();
39 }
40
41 void ssd1306_configureI2cDisplay(const uint8_t *config, uint8_t configSize)
42 {
43 ssd1306_commandStart();
44 for( uint8_t i=0; i<configSize; i++)
45 {
46 uint8_t data = pgm_read_byte(&config[i]);
47 ssd1306_intf.send(data);
48 }
49 ssd1306_intf.stop();
50 }
51
52 void ssd1306_configureSpiDisplay(const uint8_t *config, uint8_t configSize)
53 {
54 ssd1306_intf.start();
55 ssd1306_spiDataMode(0);
56 for( uint8_t i=0; i<configSize; i++)
57 {
58 uint8_t data = pgm_read_byte(&config[i]);
59 if (data == CMD_ARG)
60 {
61 data = pgm_read_byte(&config[++i]);
62 ssd1306_spiDataMode(1);
63 ssd1306_intf.send(data);
64 ssd1306_spiDataMode(0);
65 }
66 else
67 {
68 ssd1306_intf.send(data);
69 }
70 }
71 ssd1306_intf.stop();
72 }
73
74 void ssd1306_setMode(lcd_mode_t mode)
75 {
76 if (ssd1306_lcd.set_mode)
77 {
78 ssd1306_lcd.set_mode( mode );
79 }
80 }
81
82 void ssd1306_resetController(int8_t rstPin, uint8_t delayMs)
83 {
84 pinMode(rstPin, OUTPUT);
85 digitalWrite(rstPin, HIGH);
86 /* Wait at least 10ms after VCC is up for LCD */
87 delay(10);
88 /* Perform reset operation of LCD display */
89 digitalWrite(rstPin, LOW);
90 delay(delayMs);
91 digitalWrite(rstPin, HIGH);
92 }
93
ssd1306_setMode
void ssd1306_setMode(lcd_mode_t mode)
Sets library display mode for direct draw functions.
Definition: lcd_common.c:74
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:52
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:41
ssd1306_interface_t::stop
void(* stop)(void)
Definition: ssd1306_interface.h:65
ssd1306_dataStart
void ssd1306_dataStart(void)
Definition: ssd1306_interface.c:40
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:82
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:32
ssd1306_intf
ssd1306_interface_t ssd1306_intf
Definition: ssd1306_interface.c:29
ssd1306_interface.h
ssd1306_commandStart
void ssd1306_commandStart(void)
Definition: ssd1306_interface.c:31
ssd1306_sendData
void ssd1306_sendData(uint8_t data)
Definition: lcd_common.c:34
ssd1306_lcd_t::set_mode
void(* set_mode)(lcd_mode_t mode)
Sets library display mode for direct draw functions.
Definition: lcd_common.h:157