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