31 #if defined(CONFIG_VGA_AVAILABLE) && defined(CONFIG_VGA_ENABLE) && defined(__AVR_ATmega328P__) 33 extern uint16_t ssd1306_color;
46 static uint8_t s_mode = 0x01;
47 static uint8_t s_vga_command = 0xFF;
48 static uint8_t s_vga_arg = 0;
49 static uint8_t s_column = 0;
50 static uint8_t s_column_end = 0;
51 static uint8_t s_cursor_x = 0;
52 static uint8_t s_cursor_y = 0;
53 volatile uint8_t s_vga_frames;
55 static void vga_controller_init(
void)
60 static void vga_controller_stop(
void)
65 static void vga_controller_close(
void)
78 static inline void vga_controller_put_pixel3(uint8_t x, uint8_t y, uint8_t color)
80 uint16_t addr = (x >> 3)*3 + (uint16_t)y*36;
81 uint8_t offset = x & 0x07;
90 __vga_buffer[addr + (offset>>1)] &= 0x8F;
91 __vga_buffer[addr + (offset>>1)] |= (color<<4);
95 __vga_buffer[addr + (offset>>1)] &= 0xF8;
96 __vga_buffer[addr + (offset>>1)] |= color;
101 __vga_buffer[addr+0] &= 0x7F;
102 __vga_buffer[addr+0] |= ((color & 0x01) << 7);
103 __vga_buffer[addr+1] &= 0x7F;
104 __vga_buffer[addr+1] |= ((color & 0x02) << 6);
105 __vga_buffer[addr+2] &= 0x7F;
106 __vga_buffer[addr+2] |= ((color & 0x04) << 5);
110 __vga_buffer[addr+0] &= 0xF7;
111 __vga_buffer[addr+0] |= ((color & 0x01) << 3);
112 __vga_buffer[addr+1] &= 0xF7;
113 __vga_buffer[addr+1] |= ((color & 0x02) << 2);
114 __vga_buffer[addr+2] &= 0xF7;
115 __vga_buffer[addr+2] |= ((color & 0x04) << 1);
119 static void vga_controller_send_byte4(uint8_t data)
121 if (s_vga_command == 0xFF)
123 s_vga_command = data;
126 if (s_vga_command == 0x40)
128 uint8_t color = ((data & 0x80) >> 5) | ((data & 0x10) >> 3) | ((data & 0x02)>>1);
129 vga_controller_put_pixel3(s_cursor_x, s_cursor_y, color);
133 if (s_cursor_x > s_column_end)
135 s_cursor_x = s_column;
142 if ((s_cursor_y & 0x07) == 0)
153 s_vga_command = data;
159 if (s_vga_arg == 1) { s_column = data; s_cursor_x = data; }
160 if (s_vga_arg == 2) { s_column_end = data; }
161 if (s_vga_arg == 3) { s_cursor_y = data; }
162 if (s_vga_arg == 4) { s_vga_command = 0; }
166 if (s_vga_arg == 1) { s_mode = data; s_vga_command = 0; }
171 static void vga_controller_send_bytes(
const uint8_t *buffer, uint16_t len)
180 static inline void init_vga_crt_driver(uint8_t enable_jitter_fix)
183 if (enable_jitter_fix)
196 TIMSK0 &= ~(1<<TOIE0);
200 pinMode (V_SYNC_PIN, OUTPUT);
201 TCCR1A=(1<<WGM10) | (1<<WGM11) | (1<<COM1B1);
202 TCCR1B=(1<<WGM12) | (1<<WGM13) | (1<<CS12) | (1<<CS10);
209 pinMode (H_SYNC_PIN, OUTPUT);
210 TCCR2A=(1<<WGM20) | (1<<WGM21) | (1<<COM2B1);
211 TCCR2B=(1<<WGM22) | (1<<CS21);
217 TIMSK2 = (1<<OCIE2B);
235 void ssd1306_vga_controller_96x40_init_no_output(
void)
245 void ssd1306_vga_controller_96x40_init_enable_output(
void)
247 ssd1306_vga_controller_96x40_init_no_output();
248 init_vga_crt_driver(1);
251 void ssd1306_vga_controller_96x40_init_enable_output_no_jitter_fix(
void)
253 ssd1306_vga_controller_96x40_init_no_output();
254 init_vga_crt_driver(0);
258 void ssd1306_debug_print_vga_buffer_96x40(
void (*func)(uint8_t))
264 uint8_t color = (__vga_buffer[(y*
ssd1306_lcd.
width + x)/2] >> ((x&1)<<2)) & 0x0F;
281 void ssd1306_vga_delay(uint32_t ms)
286 vga_frames = s_vga_frames;
287 while (vga_frames == s_vga_frames);
void(* send)(uint8_t data)
void(* close)(void)
deinitializes internal resources, allocated for interface.
ssd1306_lcd_t ssd1306_lcd
ssd1306_interface_t ssd1306_intf
void(* send_buffer)(const uint8_t *buffer, uint16_t size)
Sends bytes to SSD1306 device.