1.1 --- a/examples/vga-pmp/main.c Tue Oct 23 22:11:05 2018 +0200
1.2 +++ b/examples/vga-pmp/main.c Tue Oct 23 22:14:20 2018 +0200
1.3 @@ -27,6 +27,7 @@
1.4 #include "main.h"
1.5 #include "devconfig.h"
1.6 #include "vga.h"
1.7 +#include "display.h"
1.8
1.9
1.10
1.11 @@ -35,20 +36,16 @@
1.12 static void (*state_handler)(void);
1.13 static uint32_t line;
1.14
1.15 +/* Pointers to pixel lines. */
1.16 +
1.17 +static uint8_t *linedata, *linedatalimit, *screenstart;
1.18 +
1.19 /* Pixel data. */
1.20
1.21 -static uint8_t linedata[LINE_LENGTH];
1.22 static const uint8_t zerodata[ZERO_LENGTH] = {0};
1.23 -
1.24 +static uint8_t framebuffer[SCREEN_SIZE];
1.25
1.26
1.27 -static void test_linedata(void)
1.28 -{
1.29 - int i;
1.30 -
1.31 - for (i = 0; i < LINE_LENGTH; i++)
1.32 - linedata[i] = (i % 2) ? 0xff : 0x00;
1.33 -}
1.34
1.35 /* Blink an attached LED with delays implemented using a loop. */
1.36
1.37 @@ -69,8 +66,6 @@
1.38 /* Invert outputs (LED). */
1.39
1.40 INV_REG(port, pins);
1.41 - rbits(PM_REG(0, PMxCON)); uart_write_nl();
1.42 - rhex(PM_REG(0, PMxMODE)); uart_write_nl();
1.43 }
1.44 }
1.45
1.46 @@ -82,7 +77,12 @@
1.47 {
1.48 line = 0;
1.49 state_handler = vbp_active;
1.50 - test_linedata();
1.51 + test_linedata(framebuffer);
1.52 +
1.53 + /* Initialise the current display line pointer and display limit. */
1.54 +
1.55 + linedatalimit = framebuffer + SCREEN_SIZE;
1.56 + screenstart = framebuffer;
1.57
1.58 init_memory();
1.59 init_pins();
1.60 @@ -112,16 +112,15 @@
1.61 dma_set_transfer(0, PHYSICAL((uint32_t) linedata), LINE_LENGTH,
1.62 HW_PHYSICAL(PM_REG(0, PMxDIN)), 1,
1.63 TRANSFER_CELL_SIZE);
1.64 - dma_init_interrupt(0, 0b1000, 1, 3);
1.65
1.66 - /* Enable DMA on the preceding channel's completion, with this also
1.67 - initiating transfers. This "reset" or "zero" transfer is employed to set
1.68 - the pixel level to black in a connected flip-flop. Without the flip-flop
1.69 - it is superfluous. */
1.70 + /* Enable DMA on the preceding channel's completion, with the timer event
1.71 + initiating the transfer. This "reset" or "zero" transfer is employed to
1.72 + set the pixel level to black in a connected flip-flop. Without the
1.73 + flip-flop it is superfluous. */
1.74
1.75 dma_init(1, 3);
1.76 dma_set_chaining(1, dma_chain_previous);
1.77 - dma_set_interrupt(1, DMA0, 1);
1.78 + dma_set_interrupt(1, T2, 1);
1.79 dma_set_transfer(1, PHYSICAL((uint32_t) zerodata), ZERO_LENGTH,
1.80 HW_PHYSICAL(PM_REG(0, PMxDIN)), 1,
1.81 ZERO_LENGTH);
1.82 @@ -200,7 +199,10 @@
1.83
1.84 state_handler = visible_active;
1.85
1.86 - /* NOTE: Set the line address. */
1.87 + /* Set the line address. */
1.88 +
1.89 + linedata = screenstart;
1.90 + dma_set_source(0, PHYSICAL((uint32_t) linedata), LINE_LENGTH);
1.91
1.92 /* Enable the channel for the next line. */
1.93
1.94 @@ -211,22 +213,18 @@
1.95
1.96 void visible_active(void)
1.97 {
1.98 - uint32_t ifs;
1.99 -
1.100 - /* Remove any DMA interrupt condition (CHBCIF). */
1.101 -
1.102 - ifs = REG(DMAIFS) & DMA_INT_FLAGS(0, DCHxIF);
1.103 -
1.104 - if (ifs)
1.105 - {
1.106 - CLR_REG(DMA_REG(0, DCHxINT), 0b11111111);
1.107 - CLR_REG(DMAIFS, ifs);
1.108 - }
1.109 -
1.110 if (line < VFP_START)
1.111 {
1.112 - /* NOTE: Update the line address and handle wraparound. */
1.113 + /* Update the line address and handle wraparound. */
1.114
1.115 + if (!(line % LINE_MULTIPLIER))
1.116 + {
1.117 + linedata += LINE_LENGTH;
1.118 + if (linedata >= linedatalimit)
1.119 + linedata -= SCREEN_SIZE;
1.120 + }
1.121 +
1.122 + dma_set_source(0, PHYSICAL((uint32_t) linedata), LINE_LENGTH);
1.123 return;
1.124 }
1.125