1.1 --- a/examples/vga-pmp/Makefile Sun Oct 28 01:22:54 2018 +0200
1.2 +++ b/examples/vga-pmp/Makefile Sun Oct 28 18:08:21 2018 +0100
1.3 @@ -27,11 +27,11 @@
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) $(DISPLAY_SRC)
1.8 -OBJ = $(START_OBJ) main.o $(COMMON_OBJ) $(DISPLAY_OBJ)
1.9 +SRC = $(START_SRC) main.c $(COMMON_SRC) $(DISPLAY_SRC) screendata.S
1.10 +OBJ = $(START_OBJ) main.o $(COMMON_OBJ) $(DISPLAY_OBJ) screendata.o
1.11
1.12 # Application-specific adjustments.
1.13
1.14 -CFLAGS += -I../vga
1.15 +CFLAGS += -DPARALLEL_MODE -I../vga
1.16
1.17 include ../../mk/rules.mk
2.1 --- a/examples/vga-pmp/main.c Sun Oct 28 01:22:54 2018 +0200
2.2 +++ b/examples/vga-pmp/main.c Sun Oct 28 18:08:21 2018 +0100
2.3 @@ -1,155 +1,1 @@
2.4 -/*
2.5 - * Generate a VGA signal using a PIC32 microcontroller.
2.6 - *
2.7 - * Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk>
2.8 - *
2.9 - * This program is free software: you can redistribute it and/or modify
2.10 - * it under the terms of the GNU General Public License as published by
2.11 - * the Free Software Foundation, either version 3 of the License, or
2.12 - * (at your option) any later version.
2.13 - *
2.14 - * This program is distributed in the hope that it will be useful,
2.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.17 - * GNU General Public License for more details.
2.18 - *
2.19 - * You should have received a copy of the GNU General Public License
2.20 - * along with this program. If not, see <http://www.gnu.org/licenses/>.
2.21 - */
2.22 -
2.23 -
2.24 -#include "pic32_c.h"
2.25 -#include "init.h"
2.26 -#include "debug.h"
2.27 -
2.28 -/* Specific functionality. */
2.29 -
2.30 -#include "main.h"
2.31 -#include "devconfig.h"
2.32 -#include "vga.h"
2.33 -#include "display.h"
2.34 -#include "display_config.h"
2.35 -#include "vga_display.h"
2.36 -
2.37 -
2.38 -
2.39 -/* Blink an attached LED with delays implemented using a loop. */
2.40 -
2.41 -static void blink(uint32_t delay, uint32_t port, uint32_t pins)
2.42 -{
2.43 - uint32_t counter;
2.44 -
2.45 - /* Clear outputs (LED). */
2.46 -
2.47 - CLR_REG(port, pins);
2.48 -
2.49 - while (1)
2.50 - {
2.51 - counter = delay;
2.52 -
2.53 - while (counter--) __asm__(""); /* retain loop */
2.54 -
2.55 - /* Invert outputs (LED). */
2.56 -
2.57 - INV_REG(port, pins);
2.58 - }
2.59 -}
2.60 -
2.61 -
2.62 -
2.63 -/* Main program. */
2.64 -
2.65 -void main(void)
2.66 -{
2.67 - init_memory();
2.68 - init_pins();
2.69 - init_outputs();
2.70 -
2.71 - unlock_config();
2.72 - config_oc();
2.73 - config_uart();
2.74 - lock_config();
2.75 -
2.76 - init_dma();
2.77 - init_pm();
2.78 -
2.79 - /* Configure parallel master mode. */
2.80 -
2.81 - pm_init(0, 0b10);
2.82 - pm_set_output(0, 1, 0);
2.83 - pm_on(0);
2.84 -
2.85 - /* Initialise VGA output with a single line channel, configuring Timer2,
2.86 - with no transfer timer and thus no initiating channel. */
2.87 -
2.88 - init_vga_with_timers(&display_config, 1, 2, 0);
2.89 -
2.90 - /* Configure VGA output transfer to the parallel mode output register, also
2.91 - configuring output compare units for horizontal and vertical sync. */
2.92 -
2.93 - vga_configure_transfer(PM_REG(0, PMxDIN));
2.94 - vga_configure_sync(1, 2);
2.95 -
2.96 - uart_init(1, FPB, 115200);
2.97 - uart_on(1);
2.98 -
2.99 - test_linedata(&display_config);
2.100 -
2.101 - interrupts_on();
2.102 -
2.103 - blink(3 << 24, PORTA, 1 << 2);
2.104 -}
2.105 -
2.106 -
2.107 -
2.108 -/* Exception and interrupt handlers. */
2.109 -
2.110 -void exception_handler(void)
2.111 -{
2.112 - blink(3 << 12, PORTA, 1 << 2);
2.113 -}
2.114 -
2.115 -void interrupt_handler(void)
2.116 -{
2.117 - uint32_t ifs;
2.118 -
2.119 - /* Check for a OC1 interrupt condition. */
2.120 -
2.121 - ifs = REG(OCIFS) & OC_INT_FLAGS(1, OCxIF);
2.122 -
2.123 - if (ifs)
2.124 - {
2.125 - vga_interrupt_handler();
2.126 - CLR_REG(OCIFS, ifs);
2.127 - }
2.128 -}
2.129 -
2.130 -
2.131 -
2.132 -/* Peripheral pin configuration. */
2.133 -
2.134 -void config_oc(void)
2.135 -{
2.136 - /* Map OC1 to RPB4. */
2.137 -
2.138 - REG(RPB4R) = 0b0101; /* RPB4R<3:0> = 0101 (OC1) */
2.139 -
2.140 - /* Map OC2 to RPB5. */
2.141 -
2.142 - REG(RPB5R) = 0b0101; /* RPB5R<3:0> = 0101 (OC2) */
2.143 -}
2.144 -
2.145 -void config_uart(void)
2.146 -{
2.147 - /* Map U1RX to RPB13. */
2.148 -
2.149 - REG(U1RXR) = 0b0011; /* U1RXR<3:0> = 0011 (RPB13) */
2.150 -
2.151 - /* Map U1TX to RPB15. */
2.152 -
2.153 - REG(RPB15R) = 0b0001; /* RPB15R<3:0> = 0001 (U1TX) */
2.154 -
2.155 - /* Set RPB13 to input. */
2.156 -
2.157 - SET_REG(TRISB, 1 << 13);
2.158 -}
2.159 +../vga/main.c
2.160 \ No newline at end of file
3.1 --- a/examples/vga/main.c Sun Oct 28 01:22:54 2018 +0200
3.2 +++ b/examples/vga/main.c Sun Oct 28 18:08:21 2018 +0100
3.3 @@ -47,6 +47,20 @@
3.4 #define TRANSFER_TIMER 0
3.5 #endif
3.6
3.7 +/* Define different output ports and pins for parallel mode. */
3.8 +
3.9 +#ifndef PARALLEL_MODE
3.10 +#define VGA_OUTPUT PORTB
3.11 +#define OC1_PIN RPA0R
3.12 +#define OC2_PIN RPA1R
3.13 +#define LED_PIN (1 << 3)
3.14 +#else
3.15 +#define VGA_OUTPUT PM_REG(0, PMxDIN)
3.16 +#define OC1_PIN RPB4R
3.17 +#define OC2_PIN RPB5R
3.18 +#define LED_PIN (1 << 2)
3.19 +#endif
3.20 +
3.21
3.22
3.23 /* Bundled image data. */
3.24 @@ -95,6 +109,16 @@
3.25
3.26 init_dma();
3.27
3.28 +#ifdef PARALLEL_MODE
3.29 + init_pm();
3.30 +
3.31 + /* Configure parallel master mode. */
3.32 +
3.33 + pm_init(0, 0b10);
3.34 + pm_set_output(0, 1, 0);
3.35 + pm_on(0);
3.36 +#endif
3.37 +
3.38 /* Initialise VGA output with one or two line channels, configuring a line
3.39 timer and any transfer timer, with an initiating channel being introduced
3.40 if a transfer timer is specified. */
3.41 @@ -104,7 +128,7 @@
3.42 /* Configure VGA output transfer to the output register, also configuring
3.43 output compare units for horizontal and vertical sync. */
3.44
3.45 - vga_configure_transfer(PORTB);
3.46 + vga_configure_transfer(VGA_OUTPUT);
3.47 vga_configure_sync(1, 2);
3.48
3.49 uart_init(1, FPB, 115200);
3.50 @@ -113,7 +137,7 @@
3.51 interrupts_on();
3.52
3.53 copy_to_framebuffer(&display_config, screendata, screendata_width, screendata_height);
3.54 - blink(1 << 24, PORTA, 1 << 3);
3.55 + blink(1 << 24, PORTA, LED_PIN);
3.56 }
3.57
3.58
3.59 @@ -122,7 +146,7 @@
3.60
3.61 void exception_handler(void)
3.62 {
3.63 - blink(3 << 12, PORTA, 1 << 3);
3.64 + blink(3 << 12, PORTA, LED_PIN);
3.65 }
3.66
3.67 void interrupt_handler(void)
3.68 @@ -146,13 +170,13 @@
3.69
3.70 void config_oc(void)
3.71 {
3.72 - /* Map OC1 to RPA0. */
3.73 + /* Map OC1. */
3.74
3.75 - REG(RPA0R) = 0b0101; /* RPA0R<3:0> = 0101 (OC1) */
3.76 + REG(OC1_PIN) = 0b0101;
3.77
3.78 - /* Map OC2 to RPA1. */
3.79 + /* Map OC2. */
3.80
3.81 - REG(RPA1R) = 0b0101; /* RPA1R<3:0> = 0101 (OC2) */
3.82 + REG(OC2_PIN) = 0b0101;
3.83 }
3.84
3.85 void config_uart(void)