# HG changeset patch # User Paul Boddie # Date 1540388802 -7200 # Node ID 908bd0dbb6b2755acded7fa52391fb4a712d2583 # Parent 43cfde9693e2fa180306cc7a211352a580c57cd4 Moved horizontal/vertical sync configuration and functions into library code. diff -r 43cfde9693e2 -r 908bd0dbb6b2 examples/vga-dual/main.c --- a/examples/vga-dual/main.c Wed Oct 24 15:31:56 2018 +0200 +++ b/examples/vga-dual/main.c Wed Oct 24 15:46:42 2018 +0200 @@ -67,8 +67,7 @@ void main(void) { - init_vga(&display_config, start_visible, update_visible, stop_visible, - vsync_high, vsync_low); + init_vga(&display_config, start_visible, update_visible, stop_visible); test_linedata(&display_config); @@ -189,24 +188,6 @@ dma_off(1); } -/* Bring vsync low (single compare, output driven low) when the next line - starts. */ - -void vsync_low(void) -{ - oc_init(2, 0b010, 2); - oc_on(2); -} - -/* Bring vsync high (single compare, output driven high) when the next line - starts. */ - -void vsync_high(void) -{ - oc_init(2, 0b001, 2); - oc_on(2); -} - /* Peripheral pin configuration. */ diff -r 43cfde9693e2 -r 908bd0dbb6b2 examples/vga-dual/main.h --- a/examples/vga-dual/main.h Wed Oct 24 15:31:56 2018 +0200 +++ b/examples/vga-dual/main.h Wed Oct 24 15:46:42 2018 +0200 @@ -33,9 +33,4 @@ void update_visible(vga_display_t *vga_display); void stop_visible(vga_display_t *vga_display); -/* Vertical sync operations. */ - -void vsync_high(void); -void vsync_low(void); - #endif /* __MAIN_H__ */ diff -r 43cfde9693e2 -r 908bd0dbb6b2 examples/vga-pmp/main.c --- a/examples/vga-pmp/main.c Wed Oct 24 15:31:56 2018 +0200 +++ b/examples/vga-pmp/main.c Wed Oct 24 15:46:42 2018 +0200 @@ -67,8 +67,7 @@ void main(void) { - init_vga(&display_config, start_visible, update_visible, stop_visible, - vsync_high, vsync_low); + init_vga(&display_config, start_visible, update_visible, stop_visible); test_linedata(&display_config); @@ -178,24 +177,6 @@ dma_off(0); } -/* Bring vsync low (single compare, output driven low) when the next line - starts. */ - -void vsync_low(void) -{ - oc_init(2, 0b010, 2); - oc_on(2); -} - -/* Bring vsync high (single compare, output driven high) when the next line - starts. */ - -void vsync_high(void) -{ - oc_init(2, 0b001, 2); - oc_on(2); -} - /* Peripheral pin configuration. */ diff -r 43cfde9693e2 -r 908bd0dbb6b2 examples/vga-pmp/main.h --- a/examples/vga-pmp/main.h Wed Oct 24 15:31:56 2018 +0200 +++ b/examples/vga-pmp/main.h Wed Oct 24 15:46:42 2018 +0200 @@ -33,9 +33,4 @@ void update_visible(vga_display_t *vga_display); void stop_visible(vga_display_t *vga_display); -/* Vertical sync operations. */ - -void vsync_high(void); -void vsync_low(void); - #endif /* __MAIN_H__ */ diff -r 43cfde9693e2 -r 908bd0dbb6b2 examples/vga-timer/main.c --- a/examples/vga-timer/main.c Wed Oct 24 15:31:56 2018 +0200 +++ b/examples/vga-timer/main.c Wed Oct 24 15:46:42 2018 +0200 @@ -67,8 +67,7 @@ void main(void) { - init_vga(&display_config, start_visible, update_visible, stop_visible, - vsync_high, vsync_low); + init_vga(&display_config, start_visible, update_visible, stop_visible); test_linedata(&display_config); @@ -214,24 +213,6 @@ dma_off(1); } -/* Bring vsync low (single compare, output driven low) when the next line - starts. */ - -void vsync_low(void) -{ - oc_init(2, 0b010, 2); - oc_on(2); -} - -/* Bring vsync high (single compare, output driven high) when the next line - starts. */ - -void vsync_high(void) -{ - oc_init(2, 0b001, 2); - oc_on(2); -} - /* Peripheral pin configuration. */ diff -r 43cfde9693e2 -r 908bd0dbb6b2 examples/vga-timer/main.h --- a/examples/vga-timer/main.h Wed Oct 24 15:31:56 2018 +0200 +++ b/examples/vga-timer/main.h Wed Oct 24 15:46:42 2018 +0200 @@ -33,9 +33,4 @@ void update_visible(vga_display_t *vga_display); void stop_visible(vga_display_t *vga_display); -/* Vertical sync operations. */ - -void vsync_high(void); -void vsync_low(void); - #endif /* __MAIN_H__ */ diff -r 43cfde9693e2 -r 908bd0dbb6b2 examples/vga/main.c --- a/examples/vga/main.c Wed Oct 24 15:31:56 2018 +0200 +++ b/examples/vga/main.c Wed Oct 24 15:46:42 2018 +0200 @@ -67,8 +67,7 @@ void main(void) { - init_vga(&display_config, start_visible, update_visible, stop_visible, - vsync_high, vsync_low); + init_vga(&display_config, start_visible, update_visible, stop_visible); test_linedata(&display_config); @@ -169,24 +168,6 @@ dma_off(0); } -/* Bring vsync low (single compare, output driven low) when the next line - starts. */ - -void vsync_low(void) -{ - oc_init(2, 0b010, 2); - oc_on(2); -} - -/* Bring vsync high (single compare, output driven high) when the next line - starts. */ - -void vsync_high(void) -{ - oc_init(2, 0b001, 2); - oc_on(2); -} - /* Peripheral pin configuration. */ diff -r 43cfde9693e2 -r 908bd0dbb6b2 examples/vga/main.h --- a/examples/vga/main.h Wed Oct 24 15:31:56 2018 +0200 +++ b/examples/vga/main.h Wed Oct 24 15:46:42 2018 +0200 @@ -33,9 +33,4 @@ void update_visible(vga_display_t *vga_display); void stop_visible(vga_display_t *vga_display); -/* Vertical sync operations. */ - -void vsync_high(void); -void vsync_low(void); - #endif /* __MAIN_H__ */ diff -r 43cfde9693e2 -r 908bd0dbb6b2 include/vga_display.h --- a/include/vga_display.h Wed Oct 24 15:31:56 2018 +0200 +++ b/include/vga_display.h Wed Oct 24 15:46:42 2018 +0200 @@ -38,10 +38,9 @@ void (*update_visible)(); void (*stop_visible)(); - /* Vertical sync operations. */ + /* Horizontal and vertical sync peripherals. */ - void (*vsync_high)(); - void (*vsync_low)(); + int timer, hsync_unit, vsync_unit; /* Current scanline. */ @@ -64,9 +63,7 @@ void init_vga(display_config_t *display_config, void (*start_visible)(), void (*update_visible)(), - void (*stop_visible)(), - void (*vsync_high)(), - void (*vsync_low)()); + void (*stop_visible)()); void vga_configure_sync(int hsync_unit, int vsync_unit, int timer); @@ -81,4 +78,9 @@ void vfp_active(void); void vsync_active(void); +/* Vertical sync operations. */ + +void vsync_high(void); +void vsync_low(void); + #endif /* __VGA_DISPLAY_H__ */ diff -r 43cfde9693e2 -r 908bd0dbb6b2 lib/vga_display.c --- a/lib/vga_display.c Wed Oct 24 15:31:56 2018 +0200 +++ b/lib/vga_display.c Wed Oct 24 15:46:42 2018 +0200 @@ -34,9 +34,7 @@ void init_vga(display_config_t *display_config, void (*start_visible)(), void (*update_visible)(), - void (*stop_visible)(), - void (*vsync_high)(), - void (*vsync_low)()) + void (*stop_visible)()) { /* Display parameters. */ @@ -48,11 +46,6 @@ vga_display.update_visible = update_visible; vga_display.stop_visible = stop_visible; - /* Vertical sync operations. */ - - vga_display.vsync_high = vsync_high; - vga_display.vsync_low = vsync_low; - /* Initial state. */ vga_display.state_handler = vbp_active; @@ -64,6 +57,12 @@ void vga_configure_sync(int hsync_unit, int vsync_unit, int timer) { + /* Record the peripherals in use. */ + + vga_display.hsync_unit = hsync_unit; + vga_display.vsync_unit = vsync_unit; + vga_display.timer = timer; + /* Configure a timer for the horizontal sync. The timer has no prescaling (0). */ @@ -163,7 +162,7 @@ /* Bring vsync low when the next line starts. */ - vga_display.vsync_low(); + vsync_low(); } /* Vertical sync region. */ @@ -180,5 +179,25 @@ /* Bring vsync high when the next line starts. */ - vga_display.vsync_high(); + vsync_high(); } + + + +/* Bring vsync low (single compare, output driven low) when the next line + starts. */ + +void vsync_low(void) +{ + oc_init(vga_display.vsync_unit, 0b010, vga_display.timer); + oc_on(vga_display.vsync_unit); +} + +/* Bring vsync high (single compare, output driven high) when the next line + starts. */ + +void vsync_high(void) +{ + oc_init(vga_display.vsync_unit, 0b001, vga_display.timer); + oc_on(vga_display.vsync_unit); +}