SSD1306 OLED display driver  1.8.2
This library is developed to control SSD1306/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays
composite_video.c
1 /*
2  MIT License
3 
4  Copyright (c) 2019, 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 "composite_video.h"
26 #include "vga_commands.h"
27 #include "lcd_common.h"
28 #include "intf/ssd1306_interface.h"
29 #include "ssd1306_hal/io.h"
30 #include "intf/vga/vga.h"
31 
32 static const uint8_t PROGMEM s_composite128x64_initData[] =
33 {
34 #ifdef SDL_EMULATION
35  SDL_LCD_SSD1306,
36  0x00,
37 #endif
38  VGA_SET_RESOLUTION,128,64,1,
39  VGA_DISPLAY_ON,
40 };
41 
42 static uint8_t s_column = 0;
43 static uint8_t s_page = 0;
44 
45 extern uint16_t ssd1306_color;
46 
47 static void vga_set_block1(lcduint_t x, lcduint_t y, lcduint_t w)
48 {
49  uint8_t rx = w ? (x + w - 1) : (ssd1306_lcd.width - 1);
50  s_column = x;
51  s_page = y;
53  ssd1306_intf.send(0x00);
55  ssd1306_intf.send(s_column);
56  ssd1306_intf.send(rx);
57  ssd1306_intf.send(s_page * 8);
60  ssd1306_intf.send(0x40);
61 }
62 
63 static void vga_next_page1(void)
64 {
66  vga_set_block1(s_column,s_page+1,0);
67 }
68 
69 static void vga_set_block2(lcduint_t x, lcduint_t y, lcduint_t w)
70 {
71  uint8_t rx = w ? (x + w - 1) : (ssd1306_lcd.width - 1);
73  ssd1306_intf.send(0x00);
74  ssd1306_intf.send(VGA_SET_BLOCK); // set block
75  ssd1306_intf.send(x);
76  ssd1306_intf.send(rx);
77  ssd1306_intf.send(y);
80  ssd1306_intf.send(0x40);
81 }
82 
83 static void vga_next_page2(void)
84 {
85 }
86 
87 #if 0
88 
89 static void vga_send_pixels(uint8_t data)
90 {
91  for (uint8_t i=8; i>0; i--)
92  {
93  if ( data & 0x01 )
94  {
95  ssd1306_intf.send( (uint8_t)ssd1306_color );
96  }
97  else
98  {
99  ssd1306_intf.send( 0B00000000 );
100  }
101  data >>= 1;
102  }
103 }
104 
105 #endif
106 
107 static void vga_set_mode(lcd_mode_t mode)
108 {
109  if (mode == LCD_MODE_NORMAL)
110  {
111  ssd1306_lcd.set_block = vga_set_block2;
112  ssd1306_lcd.next_page = vga_next_page2;
113  }
114  else if (mode == LCD_MODE_SSD1306_COMPAT)
115  {
116  ssd1306_lcd.set_block = vga_set_block1;
117  ssd1306_lcd.next_page = vga_next_page1;
118  }
120  ssd1306_intf.send( 0x00 );
122  ssd1306_intf.send( (uint8_t)mode );
123  ssd1306_intf.stop();
124  // empty for a while
125 }
126 
128 {
129  // init vga interface
130  ssd1306_vgaInit();
131  // init display
133  ssd1306_lcd.width = 128;
134  ssd1306_lcd.height = 64;
135  ssd1306_lcd.set_block = vga_set_block2;
136  ssd1306_lcd.next_page = vga_next_page2;
139  ssd1306_lcd.set_mode = vga_set_mode;
140  ssd1306_configureI2cDisplay( s_composite128x64_initData, sizeof(s_composite128x64_initData));
141 }
142 
void(* send)(uint8_t data)
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
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
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 ssd1306_vgaInit(void)
Definition: vga.c:37
ssd1306_interface_t ssd1306_intf
void composite_video_128x64_mono_init(void)
Inits 128x64 monochrome VGA display.
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