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

vga_monitor.c
1 /*
2 MIT License
3
4 Copyright (c) 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 "vga_monitor.h"
26 #include "vga_commands.h"
27 #include "lcd_common.h"
28 #include "intf/ssd1306_interface.h"
29 #include "ssd1306_hal/io.h"
30
31 static uint8_t s_column = 0;
32 static uint8_t s_page = 0;
33
34 extern uint16_t ssd1306_color;
35
36 static void vga_set_block1(lcduint_t x, lcduint_t y, lcduint_t w)
37 {
38 uint8_t rx = w ? (x + w - 1) : (ssd1306_lcd.width - 1);
39 s_column = x;
40 s_page = y;
41 ssd1306_intf.start();
42 ssd1306_intf.send(0x00);
43 ssd1306_intf.send(VGA_SET_BLOCK);
44 ssd1306_intf.send(s_column);
45 ssd1306_intf.send(rx);
46 ssd1306_intf.send(s_page * 8);
47 ssd1306_intf.stop();
48 ssd1306_intf.start();
49 ssd1306_intf.send(0x40);
50 }
51
52 static void vga_next_page1(void)
53 {
54 ssd1306_intf.stop();
55 vga_set_block1(s_column,s_page+1,0);
56 }
57
58 static void vga_set_block2(lcduint_t x, lcduint_t y, lcduint_t w)
59 {
60 uint8_t rx = w ? (x + w - 1) : (ssd1306_lcd.width - 1);
61 ssd1306_intf.start();
62 ssd1306_intf.send(0x00);
63 ssd1306_intf.send(VGA_SET_BLOCK); // set block
64 ssd1306_intf.send(x);
65 ssd1306_intf.send(rx);
66 ssd1306_intf.send(y);
67 ssd1306_intf.stop();
68 ssd1306_intf.start();
69 ssd1306_intf.send(0x40);
70 }
71
72 static void vga_next_page2(void)
73 {
74 }
75
76 static void vga_send_pixels(uint8_t data)
77 {
78 for (uint8_t i=8; i>0; i--)
79 {
80 if ( data & 0x01 )
81 {
82 ssd1306_intf.send( (uint8_t)ssd1306_color );
83 }
84 else
85 {
86 ssd1306_intf.send( 0B00000000 );
87 }
88 data >>= 1;
89 }
90 }
91
92 static void vga_send_pixels_buffer(const uint8_t *buffer, uint16_t len)
93 {
94 while(len--)
95 {
96 vga_send_pixels(*buffer);
97 buffer++;
98 }
99 }
100
101 static void vga_set_mode(lcd_mode_t mode)
102 {
103 if (mode == LCD_MODE_NORMAL)
104 {
105 ssd1306_lcd.set_block = vga_set_block2;
106 ssd1306_lcd.next_page = vga_next_page2;
107 }
108 else if (mode == LCD_MODE_SSD1306_COMPAT)
109 {
110 ssd1306_lcd.set_block = vga_set_block1;
111 ssd1306_lcd.next_page = vga_next_page1;
112 }
113 ssd1306_intf.start();
114 ssd1306_intf.send( 0x00 );
115 ssd1306_intf.send( VGA_SET_MODE );
116 ssd1306_intf.send( (uint8_t)mode );
117 ssd1306_intf.stop();
118 // empty for a while
119 }
120
121 void vga_96x40_8colors_init(void)
122 {
123 ssd1306_lcd.type = LCD_TYPE_SSD1331;
124 ssd1306_lcd.width = 96;
125 ssd1306_lcd.height = 40;
126 ssd1306_lcd.set_block = vga_set_block1;
127 ssd1306_lcd.next_page = vga_next_page1;
128 ssd1306_lcd.send_pixels1 = vga_send_pixels;
129 ssd1306_lcd.send_pixels_buffer1 = vga_send_pixels_buffer;
130 ssd1306_lcd.send_pixels8 = ssd1306_intf.send;
131 ssd1306_lcd.set_mode = vga_set_mode;
132 }
133
134 void vga_128x64_mono_init(void)
135 {
136 ssd1306_lcd.type = LCD_TYPE_SSD1306;
137 ssd1306_lcd.width = 128;
138 ssd1306_lcd.height = 64;
139 ssd1306_lcd.set_block = vga_set_block2;
140 ssd1306_lcd.next_page = vga_next_page2;
141 ssd1306_lcd.send_pixels1 = ssd1306_intf.send;
142 ssd1306_lcd.send_pixels_buffer1 = ssd1306_intf.send_buffer;
143 ssd1306_lcd.set_mode = vga_set_mode;
144 }
145
vga_monitor.h
ssd1306_interface_t::send
void(* send)(uint8_t data)
Definition: ssd1306_interface.h:70
lcd_common.h
LCD_MODE_NORMAL
Definition: lcd_common.h:75
ssd1306_interface_t::stop
void(* stop)(void)
Definition: ssd1306_interface.h:65
vga_commands.h
LCD_TYPE_SSD1306
Definition: lcd_common.h:53
ssd1306_lcd_t::set_block
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
io.h
VGA_SET_MODE
Definition: vga_commands.h:59
ssd1306_lcd_t::send_pixels8
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
lcd_mode_t
lcd_mode_t
Definition: lcd_common.h:69
ssd1306_lcd_t::send_pixels_buffer1
void(* send_pixels_buffer1)(const uint8_t *buffer, uint16_t len)
Definition: lcd_common.h:135
ssd1306_lcd_t::send_pixels1
void(* send_pixels1)(uint8_t data)
Definition: lcd_common.h:128
ssd1306_interface_t::start
void(* start)(void)
Definition: ssd1306_interface.h:61
ssd1306_lcd
ssd1306_lcd_t ssd1306_lcd
Definition: lcd_common.c:32
vga_128x64_mono_init
void vga_128x64_mono_init(void)
Inits 128x64 monochrome VGA display.
Definition: vga_monitor.c:134
ssd1306_intf
ssd1306_interface_t ssd1306_intf
Definition: ssd1306_interface.c:29
LCD_MODE_SSD1306_COMPAT
Definition: lcd_common.h:82
VGA_SET_BLOCK
Definition: vga_commands.h:47
ssd1306_lcd_t::height
lcduint_t height
Definition: lcd_common.h:97
ssd1306_interface.h
ssd1306_interface_t::send_buffer
void(* send_buffer)(const uint8_t *buffer, uint16_t size)
Sends bytes to SSD1306 device.
Definition: ssd1306_interface.h:80
ssd1306_lcd_t::next_page
void(* next_page)(void)
Definition: lcd_common.h:122
ssd1306_lcd_t::width
lcduint_t width
Definition: lcd_common.h:94
ssd1306_lcd_t::type
lcd_type_t type
Definition: lcd_common.h:91
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
vga_96x40_8colors_init
void vga_96x40_8colors_init(void)
Inits 96x40 color VGA display.
Definition: vga_monitor.c:121
LCD_TYPE_SSD1331
Definition: lcd_common.h:59