SSD1306 OLED display driver  1.8.2
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;
42  ssd1306_intf.send(0x00);
44  ssd1306_intf.send(s_column);
45  ssd1306_intf.send(rx);
46  ssd1306_intf.send(s_page * 8);
49  ssd1306_intf.send(0x40);
50 }
51 
52 static void vga_next_page1(void)
53 {
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);
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);
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  }
114  ssd1306_intf.send( 0x00 );
116  ssd1306_intf.send( (uint8_t)mode );
117  ssd1306_intf.stop();
118  // empty for a while
119 }
120 
122 {
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;
131  ssd1306_lcd.set_mode = vga_set_mode;
132 }
133 
135 {
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;
143  ssd1306_lcd.set_mode = vga_set_mode;
144 }
145 
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(* 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
Definition: lcd_common.h:69
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
ssd1306_lcd_t ssd1306_lcd
Definition: lcd_common.c:33
void vga_128x64_mono_init(void)
Inits 128x64 monochrome VGA display.
Definition: vga_monitor.c:134
ssd1306_interface_t ssd1306_intf
lcduint_t height
Definition: lcd_common.h:97
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
void vga_96x40_8colors_init(void)
Inits 96x40 color VGA display.
Definition: vga_monitor.c:121