1.1 --- a/examples/vga-pmp/main.c Sun Oct 28 01:22:54 2018 +0200
1.2 +++ b/examples/vga-pmp/main.c Sun Oct 28 18:08:21 2018 +0100
1.3 @@ -1,155 +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 - init_pm();
1.78 -
1.79 - /* Configure parallel master mode. */
1.80 -
1.81 - pm_init(0, 0b10);
1.82 - pm_set_output(0, 1, 0);
1.83 - pm_on(0);
1.84 -
1.85 - /* Initialise VGA output with a single line channel, configuring Timer2,
1.86 - with no transfer timer and thus no initiating channel. */
1.87 -
1.88 - init_vga_with_timers(&display_config, 1, 2, 0);
1.89 -
1.90 - /* Configure VGA output transfer to the parallel mode output register, also
1.91 - configuring output compare units for horizontal and vertical sync. */
1.92 -
1.93 - vga_configure_transfer(PM_REG(0, PMxDIN));
1.94 - vga_configure_sync(1, 2);
1.95 -
1.96 - uart_init(1, FPB, 115200);
1.97 - uart_on(1);
1.98 -
1.99 - test_linedata(&display_config);
1.100 -
1.101 - interrupts_on();
1.102 -
1.103 - blink(3 << 24, PORTA, 1 << 2);
1.104 -}
1.105 -
1.106 -
1.107 -
1.108 -/* Exception and interrupt handlers. */
1.109 -
1.110 -void exception_handler(void)
1.111 -{
1.112 - blink(3 << 12, PORTA, 1 << 2);
1.113 -}
1.114 -
1.115 -void interrupt_handler(void)
1.116 -{
1.117 - uint32_t ifs;
1.118 -
1.119 - /* Check for a OC1 interrupt condition. */
1.120 -
1.121 - ifs = REG(OCIFS) & OC_INT_FLAGS(1, OCxIF);
1.122 -
1.123 - if (ifs)
1.124 - {
1.125 - vga_interrupt_handler();
1.126 - CLR_REG(OCIFS, ifs);
1.127 - }
1.128 -}
1.129 -
1.130 -
1.131 -
1.132 -/* Peripheral pin configuration. */
1.133 -
1.134 -void config_oc(void)
1.135 -{
1.136 - /* Map OC1 to RPB4. */
1.137 -
1.138 - REG(RPB4R) = 0b0101; /* RPB4R<3:0> = 0101 (OC1) */
1.139 -
1.140 - /* Map OC2 to RPB5. */
1.141 -
1.142 - REG(RPB5R) = 0b0101; /* RPB5R<3:0> = 0101 (OC2) */
1.143 -}
1.144 -
1.145 -void config_uart(void)
1.146 -{
1.147 - /* Map U1RX to RPB13. */
1.148 -
1.149 - REG(U1RXR) = 0b0011; /* U1RXR<3:0> = 0011 (RPB13) */
1.150 -
1.151 - /* Map U1TX to RPB15. */
1.152 -
1.153 - REG(RPB15R) = 0b0001; /* RPB15R<3:0> = 0001 (U1TX) */
1.154 -
1.155 - /* Set RPB13 to input. */
1.156 -
1.157 - SET_REG(TRISB, 1 << 13);
1.158 -}
1.159 +../vga/main.c
1.160 \ No newline at end of file