# HG changeset patch # User Paul Boddie # Date 1540746501 -3600 # Node ID 3981a018d7e040a755b19b0be99541f35c0ac4a3 # Parent 6c30c4c39803b547953a4cd73826dcdd7c5eca9c Incorporated the parallel mode configuration into the vga example code. diff -r 6c30c4c39803 -r 3981a018d7e0 examples/vga-pmp/Makefile --- a/examples/vga-pmp/Makefile Sun Oct 28 01:22:54 2018 +0200 +++ b/examples/vga-pmp/Makefile Sun Oct 28 18:08:21 2018 +0100 @@ -27,11 +27,11 @@ # Ordering of objects is important and cannot be left to replacement rules. -SRC = $(START_SRC) main.c $(COMMON_SRC) $(DISPLAY_SRC) -OBJ = $(START_OBJ) main.o $(COMMON_OBJ) $(DISPLAY_OBJ) +SRC = $(START_SRC) main.c $(COMMON_SRC) $(DISPLAY_SRC) screendata.S +OBJ = $(START_OBJ) main.o $(COMMON_OBJ) $(DISPLAY_OBJ) screendata.o # Application-specific adjustments. -CFLAGS += -I../vga +CFLAGS += -DPARALLEL_MODE -I../vga include ../../mk/rules.mk diff -r 6c30c4c39803 -r 3981a018d7e0 examples/vga-pmp/main.c --- a/examples/vga-pmp/main.c Sun Oct 28 01:22:54 2018 +0200 +++ b/examples/vga-pmp/main.c Sun Oct 28 18:08:21 2018 +0100 @@ -1,155 +1,1 @@ -/* - * Generate a VGA signal using a PIC32 microcontroller. - * - * Copyright (C) 2017, 2018 Paul Boddie - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -#include "pic32_c.h" -#include "init.h" -#include "debug.h" - -/* Specific functionality. */ - -#include "main.h" -#include "devconfig.h" -#include "vga.h" -#include "display.h" -#include "display_config.h" -#include "vga_display.h" - - - -/* Blink an attached LED with delays implemented using a loop. */ - -static void blink(uint32_t delay, uint32_t port, uint32_t pins) -{ - uint32_t counter; - - /* Clear outputs (LED). */ - - CLR_REG(port, pins); - - while (1) - { - counter = delay; - - while (counter--) __asm__(""); /* retain loop */ - - /* Invert outputs (LED). */ - - INV_REG(port, pins); - } -} - - - -/* Main program. */ - -void main(void) -{ - init_memory(); - init_pins(); - init_outputs(); - - unlock_config(); - config_oc(); - config_uart(); - lock_config(); - - init_dma(); - init_pm(); - - /* Configure parallel master mode. */ - - pm_init(0, 0b10); - pm_set_output(0, 1, 0); - pm_on(0); - - /* Initialise VGA output with a single line channel, configuring Timer2, - with no transfer timer and thus no initiating channel. */ - - init_vga_with_timers(&display_config, 1, 2, 0); - - /* Configure VGA output transfer to the parallel mode output register, also - configuring output compare units for horizontal and vertical sync. */ - - vga_configure_transfer(PM_REG(0, PMxDIN)); - vga_configure_sync(1, 2); - - uart_init(1, FPB, 115200); - uart_on(1); - - test_linedata(&display_config); - - interrupts_on(); - - blink(3 << 24, PORTA, 1 << 2); -} - - - -/* Exception and interrupt handlers. */ - -void exception_handler(void) -{ - blink(3 << 12, PORTA, 1 << 2); -} - -void interrupt_handler(void) -{ - uint32_t ifs; - - /* Check for a OC1 interrupt condition. */ - - ifs = REG(OCIFS) & OC_INT_FLAGS(1, OCxIF); - - if (ifs) - { - vga_interrupt_handler(); - CLR_REG(OCIFS, ifs); - } -} - - - -/* Peripheral pin configuration. */ - -void config_oc(void) -{ - /* Map OC1 to RPB4. */ - - REG(RPB4R) = 0b0101; /* RPB4R<3:0> = 0101 (OC1) */ - - /* Map OC2 to RPB5. */ - - REG(RPB5R) = 0b0101; /* RPB5R<3:0> = 0101 (OC2) */ -} - -void config_uart(void) -{ - /* Map U1RX to RPB13. */ - - REG(U1RXR) = 0b0011; /* U1RXR<3:0> = 0011 (RPB13) */ - - /* Map U1TX to RPB15. */ - - REG(RPB15R) = 0b0001; /* RPB15R<3:0> = 0001 (U1TX) */ - - /* Set RPB13 to input. */ - - SET_REG(TRISB, 1 << 13); -} +../vga/main.c \ No newline at end of file diff -r 6c30c4c39803 -r 3981a018d7e0 examples/vga/main.c --- a/examples/vga/main.c Sun Oct 28 01:22:54 2018 +0200 +++ b/examples/vga/main.c Sun Oct 28 18:08:21 2018 +0100 @@ -47,6 +47,20 @@ #define TRANSFER_TIMER 0 #endif +/* Define different output ports and pins for parallel mode. */ + +#ifndef PARALLEL_MODE +#define VGA_OUTPUT PORTB +#define OC1_PIN RPA0R +#define OC2_PIN RPA1R +#define LED_PIN (1 << 3) +#else +#define VGA_OUTPUT PM_REG(0, PMxDIN) +#define OC1_PIN RPB4R +#define OC2_PIN RPB5R +#define LED_PIN (1 << 2) +#endif + /* Bundled image data. */ @@ -95,6 +109,16 @@ init_dma(); +#ifdef PARALLEL_MODE + init_pm(); + + /* Configure parallel master mode. */ + + pm_init(0, 0b10); + pm_set_output(0, 1, 0); + pm_on(0); +#endif + /* Initialise VGA output with one or two line channels, configuring a line timer and any transfer timer, with an initiating channel being introduced if a transfer timer is specified. */ @@ -104,7 +128,7 @@ /* Configure VGA output transfer to the output register, also configuring output compare units for horizontal and vertical sync. */ - vga_configure_transfer(PORTB); + vga_configure_transfer(VGA_OUTPUT); vga_configure_sync(1, 2); uart_init(1, FPB, 115200); @@ -113,7 +137,7 @@ interrupts_on(); copy_to_framebuffer(&display_config, screendata, screendata_width, screendata_height); - blink(1 << 24, PORTA, 1 << 3); + blink(1 << 24, PORTA, LED_PIN); } @@ -122,7 +146,7 @@ void exception_handler(void) { - blink(3 << 12, PORTA, 1 << 3); + blink(3 << 12, PORTA, LED_PIN); } void interrupt_handler(void) @@ -146,13 +170,13 @@ void config_oc(void) { - /* Map OC1 to RPA0. */ + /* Map OC1. */ - REG(RPA0R) = 0b0101; /* RPA0R<3:0> = 0101 (OC1) */ + REG(OC1_PIN) = 0b0101; - /* Map OC2 to RPA1. */ + /* Map OC2. */ - REG(RPA1R) = 0b0101; /* RPA1R<3:0> = 0101 (OC2) */ + REG(OC2_PIN) = 0b0101; } void config_uart(void)