1.1 --- a/examples/vga-dual/main.c Thu Oct 25 21:11:22 2018 +0200
1.2 +++ b/examples/vga-dual/main.c Thu Oct 25 21:19:01 2018 +0200
1.3 @@ -1,148 +1,1 @@
1.4 -/*
1.5 - * Generate a VGA signal using a PIC32 microcontroller.
1.6 - *
1.7 - * Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk>
1.8 - *
1.9 - * This program is free software: you can redistribute it and/or modify
1.10 - * it under the terms of the GNU General Public License as published by
1.11 - * the Free Software Foundation, either version 3 of the License, or
1.12 - * (at your option) any later version.
1.13 - *
1.14 - * This program is distributed in the hope that it will be useful,
1.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 - * GNU General Public License for more details.
1.18 - *
1.19 - * You should have received a copy of the GNU General Public License
1.20 - * along with this program. If not, see <http://www.gnu.org/licenses/>.
1.21 - */
1.22 -
1.23 -
1.24 -#include "pic32_c.h"
1.25 -#include "init.h"
1.26 -#include "debug.h"
1.27 -
1.28 -/* Specific functionality. */
1.29 -
1.30 -#include "main.h"
1.31 -#include "devconfig.h"
1.32 -#include "vga.h"
1.33 -#include "display.h"
1.34 -#include "display_config.h"
1.35 -#include "vga_display.h"
1.36 -
1.37 -
1.38 -
1.39 -/* Blink an attached LED with delays implemented using a loop. */
1.40 -
1.41 -static void blink(uint32_t delay, uint32_t port, uint32_t pins)
1.42 -{
1.43 - uint32_t counter;
1.44 -
1.45 - /* Clear outputs (LED). */
1.46 -
1.47 - CLR_REG(port, pins);
1.48 -
1.49 - while (1)
1.50 - {
1.51 - counter = delay;
1.52 -
1.53 - while (counter--) __asm__(""); /* retain loop */
1.54 -
1.55 - /* Invert outputs (LED). */
1.56 -
1.57 - INV_REG(port, pins);
1.58 - }
1.59 -}
1.60 -
1.61 -
1.62 -
1.63 -/* Main program. */
1.64 -
1.65 -void main(void)
1.66 -{
1.67 - init_memory();
1.68 - init_pins();
1.69 - init_outputs();
1.70 -
1.71 - unlock_config();
1.72 - config_oc();
1.73 - config_uart();
1.74 - lock_config();
1.75 -
1.76 - init_dma();
1.77 -
1.78 - /* Initialise VGA output structures with two line channels and no initiating
1.79 - channel. */
1.80 -
1.81 - init_vga(&display_config, 2, -1);
1.82 -
1.83 - /* Configure VGA output transfer details along with a timer and output
1.84 - compare units for horizontal and vertical sync. */
1.85 -
1.86 - vga_configure_transfer(T2, PORTB);
1.87 - vga_configure_sync(1, 2, 2);
1.88 -
1.89 - uart_init(1, FPB, 115200);
1.90 - uart_on(1);
1.91 -
1.92 - test_linedata(&display_config);
1.93 -
1.94 - interrupts_on();
1.95 -
1.96 - blink(3 << 24, PORTA, 1 << 3);
1.97 -}
1.98 -
1.99 -
1.100 -
1.101 -/* Exception and interrupt handlers. */
1.102 -
1.103 -void exception_handler(void)
1.104 -{
1.105 - blink(3 << 12, PORTA, 1 << 3);
1.106 -}
1.107 -
1.108 -void interrupt_handler(void)
1.109 -{
1.110 - uint32_t ifs;
1.111 -
1.112 - /* Check for a OC1 interrupt condition. */
1.113 -
1.114 - ifs = REG(OCIFS) & OC_INT_FLAGS(1, OCxIF);
1.115 -
1.116 - if (ifs)
1.117 - {
1.118 - vga_interrupt_handler();
1.119 - CLR_REG(OCIFS, ifs);
1.120 - }
1.121 -}
1.122 -
1.123 -
1.124 -
1.125 -/* Peripheral pin configuration. */
1.126 -
1.127 -void config_oc(void)
1.128 -{
1.129 - /* Map OC1 to RPA0. */
1.130 -
1.131 - REG(RPA0R) = 0b0101; /* RPA0R<3:0> = 0101 (OC1) */
1.132 -
1.133 - /* Map OC2 to RPA1. */
1.134 -
1.135 - REG(RPA1R) = 0b0101; /* RPA1R<3:0> = 0101 (OC2) */
1.136 -}
1.137 -
1.138 -void config_uart(void)
1.139 -{
1.140 - /* Map U1RX to RPB13. */
1.141 -
1.142 - REG(U1RXR) = 0b0011; /* U1RXR<3:0> = 0011 (RPB13) */
1.143 -
1.144 - /* Map U1TX to RPB15. */
1.145 -
1.146 - REG(RPB15R) = 0b0001; /* RPB15R<3:0> = 0001 (U1TX) */
1.147 -
1.148 - /* Set RPB13 to input. */
1.149 -
1.150 - SET_REG(TRISB, 1 << 13);
1.151 -}
1.152 +../vga/main.c
1.153 \ No newline at end of file