1.1 --- a/lib/vga_display.c Wed Oct 24 13:21:21 2018 +0200
1.2 +++ b/lib/vga_display.c Wed Oct 24 15:31:56 2018 +0200
1.3 @@ -18,6 +18,7 @@
1.4 */
1.5
1.6 #include "pic32_c.h"
1.7 +#include "init.h"
1.8 #include "vga_display.h"
1.9
1.10
1.11 @@ -58,6 +59,39 @@
1.12 vga_display.line = 0;
1.13 }
1.14
1.15 +/* Configure a timer and output compare units for horizontal and vertical
1.16 + sync. */
1.17 +
1.18 +void vga_configure_sync(int hsync_unit, int vsync_unit, int timer)
1.19 +{
1.20 + /* Configure a timer for the horizontal sync. The timer has no prescaling
1.21 + (0). */
1.22 +
1.23 + timer_init(timer, 0, vga_display.display_config->hfreq_limit);
1.24 + timer_on(timer);
1.25 +
1.26 + /* Horizontal sync. */
1.27 +
1.28 + /* Configure output compare in dual compare (continuous output) mode using
1.29 + the timer as time base. The interrupt condition drives the first DMA
1.30 + channel and is handled to drive the display state machine. */
1.31 +
1.32 + oc_init(hsync_unit, 0b101, timer);
1.33 + oc_set_pulse(hsync_unit, vga_display.display_config->hsync_end);
1.34 + oc_set_pulse_end(hsync_unit, vga_display.display_config->hsync_start);
1.35 + oc_init_interrupt(hsync_unit, 7, 3);
1.36 + oc_on(hsync_unit);
1.37 +
1.38 + /* Vertical sync. */
1.39 +
1.40 + /* Configure output compare in single compare (output driven low) mode using
1.41 + the timer as time base. The unit is enabled later. It is only really used
1.42 + to achieve precisely-timed level transitions in hardware. */
1.43 +
1.44 + oc_init(vsync_unit, 0b010, timer);
1.45 + oc_set_pulse(vsync_unit, 0);
1.46 +}
1.47 +
1.48
1.49
1.50 /* Interrupt handlers. */