SSD1306 OLED display driver  1.7.16
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 static void vga_send_pixels(uint8_t data)
88 {
89  for (uint8_t i=8; i>0; i--)
90  {
91  if ( data & 0x01 )
92  {
93  ssd1306_intf.send( (uint8_t)ssd1306_color );
94  }
95  else
96  {
97  ssd1306_intf.send( 0B00000000 );
98  }
99  data >>= 1;
100  }
101 }
102 
103 static void vga_send_pixels_buffer(const uint8_t *buffer, uint16_t len)
104 {
105  while(len--)
106  {
107  vga_send_pixels(*buffer);
108  buffer++;
109  }
110 }
111 
112 static void vga_set_mode(lcd_mode_t mode)
113 {
114  if (mode == LCD_MODE_NORMAL)
115  {
116  ssd1306_lcd.set_block = vga_set_block2;
117  ssd1306_lcd.next_page = vga_next_page2;
118  }
119  else if (mode == LCD_MODE_SSD1306_COMPAT)
120  {
121  ssd1306_lcd.set_block = vga_set_block1;
122  ssd1306_lcd.next_page = vga_next_page1;
123  }
125  ssd1306_intf.send( 0x00 );
127  ssd1306_intf.send( (uint8_t)mode );
128  ssd1306_intf.stop();
129  // empty for a while
130 }
131 
133 {
134  // init vga interface
135  ssd1306_vgaInit();
136  // init display
138  ssd1306_lcd.width = 128;
139  ssd1306_lcd.height = 64;
140  ssd1306_lcd.set_block = vga_set_block2;
141  ssd1306_lcd.next_page = vga_next_page2;
144  ssd1306_lcd.set_mode = vga_set_mode;
145  ssd1306_configureI2cDisplay( s_composite128x64_initData, sizeof(s_composite128x64_initData));
146 }
147 
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:41
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:32
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