1.1 --- a/examples/vga-timer/Makefile Tue Oct 23 00:36:31 2018 +0200
1.2 +++ b/examples/vga-timer/Makefile Tue Oct 23 00:38:01 2018 +0200
1.3 @@ -27,7 +27,7 @@
1.4
1.5 # Ordering of objects is important and cannot be left to replacement rules.
1.6
1.7 -SRC = $(START_SRC) main.c $(COMMON_SRC)
1.8 -OBJ = $(START_OBJ) main.o $(COMMON_OBJ)
1.9 +SRC = $(START_SRC) main.c $(COMMON_SRC) $(DISPLAY_SRC)
1.10 +OBJ = $(START_OBJ) main.o $(COMMON_OBJ) $(DISPLAY_OBJ)
1.11
1.12 include ../../mk/rules.mk
2.1 --- a/examples/vga-timer/main.c Tue Oct 23 00:36:31 2018 +0200
2.2 +++ b/examples/vga-timer/main.c Tue Oct 23 00:38:01 2018 +0200
2.3 @@ -21,8 +21,12 @@
2.4 #include "pic32_c.h"
2.5 #include "init.h"
2.6 #include "debug.h"
2.7 +
2.8 +/* Specific functionality. */
2.9 +
2.10 #include "main.h"
2.11 #include "vga.h"
2.12 +#include "display.h"
2.13
2.14
2.15
2.16 @@ -31,20 +35,16 @@
2.17 static void (*state_handler)(void);
2.18 static uint32_t line;
2.19
2.20 +/* Pointers to pixel lines. */
2.21 +
2.22 +static uint8_t *linedata, *linedatalimit, *screenstart;
2.23 +
2.24 /* Pixel data. */
2.25
2.26 -static uint8_t linedata[LINE_LENGTH];
2.27 static const uint8_t zerodata[ZERO_LENGTH] = {0};
2.28 -
2.29 +static uint8_t framebuffer[SCREEN_SIZE];
2.30
2.31
2.32 -static void test_linedata(void)
2.33 -{
2.34 - int i;
2.35 -
2.36 - for (i = 0; i < LINE_LENGTH; i++)
2.37 - linedata[i] = (i % 2) ? 0xff : 0x00;
2.38 -}
2.39
2.40 /* Blink an attached LED with delays implemented using a loop. */
2.41
2.42 @@ -76,7 +76,12 @@
2.43 {
2.44 line = 0;
2.45 state_handler = vbp_active;
2.46 - test_linedata();
2.47 + test_linedata(framebuffer);
2.48 +
2.49 + /* Initialise the current display line pointer and display limit. */
2.50 +
2.51 + linedatalimit = framebuffer + SCREEN_SIZE;
2.52 + screenstart = framebuffer;
2.53
2.54 init_memory();
2.55 init_pins();
2.56 @@ -117,7 +122,7 @@
2.57 dma_init(1, 3);
2.58 dma_set_chaining(1, dma_chain_previous);
2.59 dma_set_interrupt(1, T3, 1);
2.60 - dma_set_transfer(1, PHYSICAL((uint32_t) linedata), LINE_LENGTH,
2.61 + dma_set_transfer(1, PHYSICAL((uint32_t) screenstart), LINE_LENGTH,
2.62 HW_PHYSICAL(PORTB), 1,
2.63 1);
2.64 dma_init_interrupt(1, 0b00001000, 1, 3);
2.65 @@ -211,7 +216,10 @@
2.66
2.67 state_handler = visible_active;
2.68
2.69 - /* NOTE: Set the line address. */
2.70 + /* Set the line address. */
2.71 +
2.72 + linedata = screenstart;
2.73 + dma_set_source(1, PHYSICAL((uint32_t) linedata), LINE_LENGTH);
2.74
2.75 /* Enable the channel for the next line. */
2.76
2.77 @@ -237,8 +245,16 @@
2.78
2.79 if (line < VFP_START)
2.80 {
2.81 - /* NOTE: Update the line address and handle wraparound. */
2.82 + /* Update the line address and handle wraparound. */
2.83
2.84 + if (!(line % LINE_MULTIPLIER))
2.85 + {
2.86 + linedata += LINE_LENGTH;
2.87 + if (linedata >= linedatalimit)
2.88 + linedata -= SCREEN_SIZE;
2.89 + }
2.90 +
2.91 + dma_set_source(1, PHYSICAL((uint32_t) linedata), LINE_LENGTH);
2.92 return;
2.93 }
2.94
3.1 --- a/examples/vga-timer/vga.h Tue Oct 23 00:36:31 2018 +0200
3.2 +++ b/examples/vga-timer/vga.h Tue Oct 23 00:38:01 2018 +0200
3.3 @@ -20,7 +20,7 @@
3.4 #ifndef __VGA_H__
3.5 #define __VGA_H__
3.6
3.7 -#define LINE_LENGTH 80 /* pixels */
3.8 +#define LINE_LENGTH 80 /* pixels */
3.9 #define LINE_COUNT 256 /* distinct display lines */
3.10
3.11 #define ZERO_LENGTH 1 /* pixels */
3.12 @@ -45,11 +45,9 @@
3.13
3.14 #define VSYNC_END 622
3.15
3.16 -#define SCREEN_BASE 256
3.17 -#define SCREEN_SIZE (40 * 1024)
3.18 -#define SCREEN_LIMIT (SCREEN_BASE + SCREEN_SIZE)
3.19 +/* Framebuffer properties. */
3.20
3.21 -#define SCREEN_BASE_KSEG0 (KSEG0_BASE + SCREEN_BASE)
3.22 -#define SCREEN_LIMIT_KSEG0 (KSEG0_BASE + SCREEN_LIMIT)
3.23 +#define SCREEN_SIZE (LINE_LENGTH * LINE_COUNT)
3.24 +#define LINE_MULTIPLIER 2
3.25
3.26 #endif /* __VGA_H__ */
4.1 --- a/examples/vga/Makefile Tue Oct 23 00:36:31 2018 +0200
4.2 +++ b/examples/vga/Makefile Tue Oct 23 00:38:01 2018 +0200
4.3 @@ -27,7 +27,7 @@
4.4
4.5 # Ordering of objects is important and cannot be left to replacement rules.
4.6
4.7 -SRC = $(START_SRC) main.c $(COMMON_SRC)
4.8 -OBJ = $(START_OBJ) main.o $(COMMON_OBJ)
4.9 +SRC = $(START_SRC) main.c $(COMMON_SRC) $(DISPLAY_SRC)
4.10 +OBJ = $(START_OBJ) main.o $(COMMON_OBJ) $(DISPLAY_OBJ)
4.11
4.12 include ../../mk/rules.mk
5.1 --- a/examples/vga/main.c Tue Oct 23 00:36:31 2018 +0200
5.2 +++ b/examples/vga/main.c Tue Oct 23 00:38:01 2018 +0200
5.3 @@ -21,8 +21,12 @@
5.4 #include "pic32_c.h"
5.5 #include "init.h"
5.6 #include "debug.h"
5.7 +
5.8 +/* Specific functionality. */
5.9 +
5.10 #include "main.h"
5.11 #include "vga.h"
5.12 +#include "display.h"
5.13
5.14
5.15
5.16 @@ -31,20 +35,16 @@
5.17 static void (*state_handler)(void);
5.18 static uint32_t line;
5.19
5.20 +/* Pointers to pixel lines. */
5.21 +
5.22 +static uint8_t *linedata, *linedatalimit, *screenstart;
5.23 +
5.24 /* Pixel data. */
5.25
5.26 -static uint8_t linedata[LINE_LENGTH];
5.27 static const uint8_t zerodata[ZERO_LENGTH] = {0};
5.28 -
5.29 +static uint8_t framebuffer[SCREEN_SIZE];
5.30
5.31
5.32 -static void test_linedata(void)
5.33 -{
5.34 - int i;
5.35 -
5.36 - for (i = 0; i < LINE_LENGTH; i++)
5.37 - linedata[i] = (i % 2) ? 0xff : 0x00;
5.38 -}
5.39
5.40 /* Blink an attached LED with delays implemented using a loop. */
5.41
5.42 @@ -76,7 +76,12 @@
5.43 {
5.44 line = 0;
5.45 state_handler = vbp_active;
5.46 - test_linedata();
5.47 + test_linedata(framebuffer);
5.48 +
5.49 + /* Initialise the current display line pointer and display limit. */
5.50 +
5.51 + linedatalimit = framebuffer + SCREEN_SIZE;
5.52 + screenstart = framebuffer;
5.53
5.54 init_memory();
5.55 init_pins();
5.56 @@ -96,7 +101,7 @@
5.57 dma_init(0, 3);
5.58 dma_set_auto_enable(0, 1);
5.59 dma_set_interrupt(0, T2, 1);
5.60 - dma_set_transfer(0, PHYSICAL((uint32_t) linedata), LINE_LENGTH,
5.61 + dma_set_transfer(0, PHYSICAL((uint32_t) screenstart), LINE_LENGTH,
5.62 HW_PHYSICAL(PORTB), 1,
5.63 LINE_LENGTH);
5.64 dma_init_interrupt(0, 0b00001000, 1, 3);
5.65 @@ -185,7 +190,10 @@
5.66
5.67 state_handler = visible_active;
5.68
5.69 - /* NOTE: Set the line address. */
5.70 + /* Set the line address. */
5.71 +
5.72 + linedata = screenstart;
5.73 + dma_set_source(0, PHYSICAL((uint32_t) linedata), LINE_LENGTH);
5.74
5.75 /* Enable the channel for the next line. */
5.76
5.77 @@ -211,8 +219,16 @@
5.78
5.79 if (line < VFP_START)
5.80 {
5.81 - /* NOTE: Update the line address and handle wraparound. */
5.82 + /* Update the line address and handle wraparound. */
5.83
5.84 + if (!(line % LINE_MULTIPLIER))
5.85 + {
5.86 + linedata += LINE_LENGTH;
5.87 + if (linedata >= linedatalimit)
5.88 + linedata -= SCREEN_SIZE;
5.89 + }
5.90 +
5.91 + dma_set_source(0, PHYSICAL((uint32_t) linedata), LINE_LENGTH);
5.92 return;
5.93 }
5.94
6.1 --- a/examples/vga/vga.h Tue Oct 23 00:36:31 2018 +0200
6.2 +++ b/examples/vga/vga.h Tue Oct 23 00:38:01 2018 +0200
6.3 @@ -45,11 +45,9 @@
6.4
6.5 #define VSYNC_END 622
6.6
6.7 -#define SCREEN_BASE 256
6.8 -#define SCREEN_SIZE (40 * 1024)
6.9 -#define SCREEN_LIMIT (SCREEN_BASE + SCREEN_SIZE)
6.10 +/* Framebuffer properties. */
6.11
6.12 -#define SCREEN_BASE_KSEG0 (KSEG0_BASE + SCREEN_BASE)
6.13 -#define SCREEN_LIMIT_KSEG0 (KSEG0_BASE + SCREEN_LIMIT)
6.14 +#define SCREEN_SIZE (LINE_LENGTH * LINE_COUNT)
6.15 +#define LINE_MULTIPLIER 2
6.16
6.17 #endif /* __VGA_H__ */
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/include/display.h Tue Oct 23 00:38:01 2018 +0200
7.3 @@ -0,0 +1,27 @@
7.4 +/*
7.5 + * Common display-related functions.
7.6 + *
7.7 + * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
7.8 + *
7.9 + * This program is free software: you can redistribute it and/or modify
7.10 + * it under the terms of the GNU General Public License as published by
7.11 + * the Free Software Foundation, either version 3 of the License, or
7.12 + * (at your option) any later version.
7.13 + *
7.14 + * This program is distributed in the hope that it will be useful,
7.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.17 + * GNU General Public License for more details.
7.18 + *
7.19 + * You should have received a copy of the GNU General Public License
7.20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7.21 + */
7.22 +
7.23 +#ifndef __DISPLAY_H__
7.24 +#define __DISPLAY_H__
7.25 +
7.26 +#include <stdint.h>
7.27 +
7.28 +void test_linedata(uint8_t *framebuffer);
7.29 +
7.30 +#endif /* __DISPLAY_H__ */
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/lib/display.c Tue Oct 23 00:38:01 2018 +0200
8.3 @@ -0,0 +1,50 @@
8.4 +/*
8.5 + * Common display-related functions.
8.6 + *
8.7 + * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
8.8 + *
8.9 + * This program is free software: you can redistribute it and/or modify
8.10 + * it under the terms of the GNU General Public License as published by
8.11 + * the Free Software Foundation, either version 3 of the License, or
8.12 + * (at your option) any later version.
8.13 + *
8.14 + * This program is distributed in the hope that it will be useful,
8.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8.17 + * GNU General Public License for more details.
8.18 + *
8.19 + * You should have received a copy of the GNU General Public License
8.20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8.21 + */
8.22 +
8.23 +#include "display.h"
8.24 +
8.25 +/* Provided by the application. */
8.26 +
8.27 +#include "vga.h"
8.28 +
8.29 +
8.30 +
8.31 +/* Provide a pattern to test the line data. */
8.32 +
8.33 +void test_linedata(uint8_t *framebuffer)
8.34 +{
8.35 + int x, y;
8.36 + uint8_t *linedata = framebuffer;
8.37 +
8.38 + for (y = 0; y < LINE_COUNT; y++)
8.39 + {
8.40 + for (x = 0; x < LINE_LENGTH; x++)
8.41 + {
8.42 + /* Pixel: I0RRGGBB = Y0YYYYXX */
8.43 +
8.44 + linedata[x] = (x % 2) ?
8.45 + (((y / (LINE_COUNT / 32)) & 0b1) << 7) |
8.46 + (((y / (LINE_COUNT / 16)) & 0b1111) << 2) |
8.47 + ((x / (LINE_LENGTH / 4)) & 0b11) :
8.48 + 0x00;
8.49 + }
8.50 +
8.51 + linedata += LINE_LENGTH;
8.52 + }
8.53 +}
9.1 --- a/mk/common.mk Tue Oct 23 00:36:31 2018 +0200
9.2 +++ b/mk/common.mk Tue Oct 23 00:38:01 2018 +0200
9.3 @@ -48,8 +48,11 @@
9.4 # Application-specific files appear after the above but before those below in
9.5 # the application Makefiles.
9.6
9.7 -COMMON_SRC = $(LIBDIR)/init.c $(LIBDIR)/debug.c $(LIBDIR)/cpu.S
9.8 -COMMON_OBJ = $(LIBDIR)/init.o $(LIBDIR)/debug.o $(LIBDIR)/cpu.o
9.9 +COMMON_SRC = $(LIBDIR)/init.c $(LIBDIR)/debug.c $(LIBDIR)/cpu.S
9.10 +COMMON_OBJ = $(LIBDIR)/init.o $(LIBDIR)/debug.o $(LIBDIR)/cpu.o
9.11 +
9.12 +DISPLAY_SRC = $(LIBDIR)/display.c
9.13 +DISPLAY_OBJ = $(LIBDIR)/display.o
9.14
9.15 # Common linker script.
9.16