1.1 --- a/examples/vga-timer/main.c Tue Oct 23 23:25:47 2018 +0200
1.2 +++ b/examples/vga-timer/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,9 @@
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 init_memory();
1.34 @@ -206,102 +199,57 @@
1.35
1.36 if (ifs)
1.37 {
1.38 - line += 1;
1.39 - state_handler();
1.40 + vga_interrupt_handler();
1.41 CLR_REG(OCIFS, ifs);
1.42 }
1.43 }
1.44
1.45
1.46
1.47 -/* Vertical back porch region. */
1.48 -
1.49 -void vbp_active(void)
1.50 -{
1.51 - if (line < VISIBLE_START)
1.52 - return;
1.53 -
1.54 - /* Enter the visible region. */
1.55 +/* Enable the channels for the next line. */
1.56
1.57 - state_handler = visible_active;
1.58 -
1.59 - /* Set the line address. */
1.60 -
1.61 - linedata = display_config.screen_start;
1.62 - dma_set_source(0, PHYSICAL((uint32_t) linedata), display_config.line_length / 2);
1.63 - dma_set_source(2, PHYSICAL((uint32_t) linedata + display_config.line_length / 2),
1.64 +void start_visible(vga_display_t *vga_display)
1.65 +{
1.66 + dma_set_source(0, PHYSICAL((uint32_t) vga_display->linedata),
1.67 display_config.line_length / 2);
1.68 -
1.69 - /* Enable the channels for the next line. */
1.70 -
1.71 + dma_set_source(2, PHYSICAL((uint32_t) vga_display->linedata +
1.72 + display_config.line_length / 2),
1.73 + display_config.line_length / 2);
1.74 dma_on(1);
1.75 }
1.76
1.77 -/* Visible region. */
1.78 -
1.79 -void visible_active(void)
1.80 -{
1.81 - INV_REG(PORTA, 1 << 2);
1.82 -
1.83 - if (line < VFP_START)
1.84 - {
1.85 - /* Update the line address and handle wraparound. */
1.86 +/* Update the channels for the next line. */
1.87
1.88 - if (!(line % display_config.line_multiplier))
1.89 - {
1.90 - linedata += display_config.line_length;
1.91 - if (linedata >= display_config.screen_limit)
1.92 - linedata -= display_config.screen_size;
1.93 - }
1.94 +void update_visible(vga_display_t *vga_display)
1.95 +{
1.96 + dma_set_source(0, PHYSICAL((uint32_t) vga_display->linedata),
1.97 + display_config.line_length / 2);
1.98 + dma_set_source(2, PHYSICAL((uint32_t) vga_display->linedata +
1.99 + display_config.line_length / 2),
1.100 + display_config.line_length / 2);
1.101 +}
1.102
1.103 - dma_set_source(0, PHYSICAL((uint32_t) linedata), display_config.line_length / 2);
1.104 - dma_set_source(2, PHYSICAL((uint32_t) linedata + display_config.line_length / 2),
1.105 - display_config.line_length / 2);
1.106 - return;
1.107 - }
1.108 +/* Disable the channels for the next line. */
1.109
1.110 - /* End the visible region. */
1.111 -
1.112 - state_handler = vfp_active;
1.113 -
1.114 - /* Disable the channels for the next line. */
1.115 -
1.116 +void stop_visible(vga_display_t *vga_display)
1.117 +{
1.118 dma_off(1);
1.119 }
1.120
1.121 -/* Vertical front porch region. */
1.122 -
1.123 -void vfp_active(void)
1.124 -{
1.125 - if (line < VSYNC_START)
1.126 - return;
1.127 +/* Bring vsync low (single compare, output driven low) when the next line
1.128 + starts. */
1.129
1.130 - /* Enter the vertical sync region. */
1.131 -
1.132 - state_handler = vsync_active;
1.133 -
1.134 - /* Bring vsync low (single compare, output driven low) when the next line
1.135 - starts. */
1.136 -
1.137 +void vsync_low(void)
1.138 +{
1.139 oc_init(2, 0b010, 2);
1.140 oc_on(2);
1.141 }
1.142
1.143 -/* Vertical sync region. */
1.144 -
1.145 -void vsync_active(void)
1.146 -{
1.147 - if (line < VSYNC_END)
1.148 - return;
1.149 +/* Bring vsync high (single compare, output driven high) when the next line
1.150 + starts. */
1.151
1.152 - /* Start again at the top of the display. */
1.153 -
1.154 - line = 0;
1.155 - state_handler = vbp_active;
1.156 -
1.157 - /* Bring vsync high (single compare, output driven high) when the next line
1.158 - starts. */
1.159 -
1.160 +void vsync_high(void)
1.161 +{
1.162 oc_init(2, 0b001, 2);
1.163 oc_on(2);
1.164 }