1.1 --- a/examples/vga/main.c Tue Oct 23 00:36:31 2018 +0200
1.2 +++ b/examples/vga/main.c Tue Oct 23 00:38:01 2018 +0200
1.3 @@ -21,8 +21,12 @@
1.4 #include "pic32_c.h"
1.5 #include "init.h"
1.6 #include "debug.h"
1.7 +
1.8 +/* Specific functionality. */
1.9 +
1.10 #include "main.h"
1.11 #include "vga.h"
1.12 +#include "display.h"
1.13
1.14
1.15
1.16 @@ -31,20 +35,16 @@
1.17 static void (*state_handler)(void);
1.18 static uint32_t line;
1.19
1.20 +/* Pointers to pixel lines. */
1.21 +
1.22 +static uint8_t *linedata, *linedatalimit, *screenstart;
1.23 +
1.24 /* Pixel data. */
1.25
1.26 -static uint8_t linedata[LINE_LENGTH];
1.27 static const uint8_t zerodata[ZERO_LENGTH] = {0};
1.28 -
1.29 +static uint8_t framebuffer[SCREEN_SIZE];
1.30
1.31
1.32 -static void test_linedata(void)
1.33 -{
1.34 - int i;
1.35 -
1.36 - for (i = 0; i < LINE_LENGTH; i++)
1.37 - linedata[i] = (i % 2) ? 0xff : 0x00;
1.38 -}
1.39
1.40 /* Blink an attached LED with delays implemented using a loop. */
1.41
1.42 @@ -76,7 +76,12 @@
1.43 {
1.44 line = 0;
1.45 state_handler = vbp_active;
1.46 - test_linedata();
1.47 + test_linedata(framebuffer);
1.48 +
1.49 + /* Initialise the current display line pointer and display limit. */
1.50 +
1.51 + linedatalimit = framebuffer + SCREEN_SIZE;
1.52 + screenstart = framebuffer;
1.53
1.54 init_memory();
1.55 init_pins();
1.56 @@ -96,7 +101,7 @@
1.57 dma_init(0, 3);
1.58 dma_set_auto_enable(0, 1);
1.59 dma_set_interrupt(0, T2, 1);
1.60 - dma_set_transfer(0, PHYSICAL((uint32_t) linedata), LINE_LENGTH,
1.61 + dma_set_transfer(0, PHYSICAL((uint32_t) screenstart), LINE_LENGTH,
1.62 HW_PHYSICAL(PORTB), 1,
1.63 LINE_LENGTH);
1.64 dma_init_interrupt(0, 0b00001000, 1, 3);
1.65 @@ -185,7 +190,10 @@
1.66
1.67 state_handler = visible_active;
1.68
1.69 - /* NOTE: Set the line address. */
1.70 + /* Set the line address. */
1.71 +
1.72 + linedata = screenstart;
1.73 + dma_set_source(0, PHYSICAL((uint32_t) linedata), LINE_LENGTH);
1.74
1.75 /* Enable the channel for the next line. */
1.76
1.77 @@ -211,8 +219,16 @@
1.78
1.79 if (line < VFP_START)
1.80 {
1.81 - /* NOTE: Update the line address and handle wraparound. */
1.82 + /* Update the line address and handle wraparound. */
1.83
1.84 + if (!(line % LINE_MULTIPLIER))
1.85 + {
1.86 + linedata += LINE_LENGTH;
1.87 + if (linedata >= linedatalimit)
1.88 + linedata -= SCREEN_SIZE;
1.89 + }
1.90 +
1.91 + dma_set_source(0, PHYSICAL((uint32_t) linedata), LINE_LENGTH);
1.92 return;
1.93 }
1.94