1.1 --- a/examples/vga/main.c Tue Oct 23 23:25:47 2018 +0200
1.2 +++ b/examples/vga/main.c Wed Oct 24 00:50:48 2018 +0200
1.3 @@ -29,17 +29,9 @@
1.4 #include "vga.h"
1.5 #include "display.h"
1.6 #include "display_config.h"
1.7 -
1.8 +#include "vga_display.h"
1.9
1.10
1.11 -/* Display state. */
1.12 -
1.13 -static void (*state_handler)(void);
1.14 -static uint32_t line;
1.15 -
1.16 -/* Pointers to pixel lines. */
1.17 -
1.18 -static uint8_t *linedata;
1.19
1.20 /* Pixel data. */
1.21
1.22 @@ -75,8 +67,8 @@
1.23
1.24 void main(void)
1.25 {
1.26 - line = 0;
1.27 - state_handler = vbp_active;
1.28 + init_vga(&display_config, start_visible, update_visible, stop_visible,
1.29 + vsync_high, vsync_low);
1.30
1.31 test_linedata(&display_config);
1.32
1.33 @@ -168,98 +160,51 @@
1.34
1.35 if (ifs)
1.36 {
1.37 - line += 1;
1.38 - state_handler();
1.39 + vga_interrupt_handler();
1.40 CLR_REG(OCIFS, ifs);
1.41 }
1.42 }
1.43
1.44
1.45
1.46 -/* Vertical back porch region. */
1.47 -
1.48 -void vbp_active(void)
1.49 -{
1.50 - if (line < VISIBLE_START)
1.51 - return;
1.52 -
1.53 - /* Enter the visible region. */
1.54 +/* Enable the channel for the next line. */
1.55
1.56 - state_handler = visible_active;
1.57 -
1.58 - /* Set the line address. */
1.59 -
1.60 - linedata = display_config.screen_start;
1.61 - dma_set_source(0, PHYSICAL((uint32_t) linedata), display_config.line_length);
1.62 -
1.63 - /* Enable the channel for the next line. */
1.64 -
1.65 +void start_visible(vga_display_t *vga_display)
1.66 +{
1.67 + dma_set_source(0, PHYSICAL((uint32_t) vga_display->linedata),
1.68 + display_config.line_length);
1.69 dma_on(0);
1.70 }
1.71
1.72 -/* Visible region. */
1.73 -
1.74 -void visible_active(void)
1.75 -{
1.76 - INV_REG(PORTA, 1 << 2);
1.77 -
1.78 - if (line < VFP_START)
1.79 - {
1.80 - /* Update the line address and handle wraparound. */
1.81 +/* Update the channel for the next line. */
1.82
1.83 - if (!(line % display_config.line_multiplier))
1.84 - {
1.85 - linedata += display_config.line_length;
1.86 - if (linedata >= display_config.screen_limit)
1.87 - linedata -= display_config.screen_size;
1.88 - }
1.89 +void update_visible(vga_display_t *vga_display)
1.90 +{
1.91 + dma_set_source(0, PHYSICAL((uint32_t) vga_display->linedata),
1.92 + display_config.line_length);
1.93 +}
1.94
1.95 - dma_set_source(0, PHYSICAL((uint32_t) linedata), display_config.line_length);
1.96 - return;
1.97 - }
1.98 +/* Disable the channel for the next line. */
1.99
1.100 - /* End the visible region. */
1.101 -
1.102 - state_handler = vfp_active;
1.103 -
1.104 - /* Disable the channel for the next line. */
1.105 -
1.106 +void stop_visible(vga_display_t *vga_display)
1.107 +{
1.108 dma_off(0);
1.109 }
1.110
1.111 -/* Vertical front porch region. */
1.112 -
1.113 -void vfp_active(void)
1.114 -{
1.115 - if (line < VSYNC_START)
1.116 - return;
1.117 +/* Bring vsync low (single compare, output driven low) when the next line
1.118 + starts. */
1.119
1.120 - /* Enter the vertical sync region. */
1.121 -
1.122 - state_handler = vsync_active;
1.123 -
1.124 - /* Bring vsync low (single compare, output driven low) when the next line
1.125 - starts. */
1.126 -
1.127 +void vsync_low(void)
1.128 +{
1.129 oc_init(2, 0b010, 2);
1.130 oc_on(2);
1.131 }
1.132
1.133 -/* Vertical sync region. */
1.134 -
1.135 -void vsync_active(void)
1.136 -{
1.137 - if (line < VSYNC_END)
1.138 - return;
1.139 +/* Bring vsync high (single compare, output driven high) when the next line
1.140 + starts. */
1.141
1.142 - /* Start again at the top of the display. */
1.143 -
1.144 - line = 0;
1.145 - state_handler = vbp_active;
1.146 -
1.147 - /* Bring vsync high (single compare, output driven high) when the next line
1.148 - starts. */
1.149 -
1.150 +void vsync_high(void)
1.151 +{
1.152 oc_init(2, 0b001, 2);
1.153 oc_on(2);
1.154 }