1.1 --- a/examples/vga-timer/main.c Thu Oct 25 21:11:22 2018 +0200
1.2 +++ b/examples/vga-timer/main.c Thu Oct 25 21:19:01 2018 +0200
1.3 @@ -1,165 +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 an initiating
1.79 - channel. */
1.80 -
1.81 - init_vga(&display_config, 2, T2);
1.82 -
1.83 - /* Peripheral relationships:
1.84 -
1.85 - Timer2 -> OC1
1.86 - -> OC2 (vertical sync region)
1.87 - -> DMA1: zerodata -> PORTB (visible region)
1.88 - |
1.89 - Timer3 -> DMA0: linedata -> PORTB
1.90 - Timer3 -> DMA2: linedata -> PORTB
1.91 - |
1.92 - Timer3 -> DMA3: zerodata -> PORTB
1.93 - */
1.94 -
1.95 - /* Configure VGA output transfer details along with a timer and output
1.96 - compare units for horizontal and vertical sync. */
1.97 -
1.98 - vga_configure_transfer(T3, PORTB);
1.99 - vga_configure_sync(1, 2, 2);
1.100 -
1.101 - /* Configure a timer for line data transfers. */
1.102 -
1.103 - timer_init(3, 0, 1);
1.104 - timer_on(3);
1.105 -
1.106 - uart_init(1, FPB, 115200);
1.107 - uart_on(1);
1.108 -
1.109 - test_linedata(&display_config);
1.110 -
1.111 - interrupts_on();
1.112 -
1.113 - blink(3 << 24, PORTA, 1 << 3);
1.114 -}
1.115 -
1.116 -
1.117 -
1.118 -/* Exception and interrupt handlers. */
1.119 -
1.120 -void exception_handler(void)
1.121 -{
1.122 - blink(3 << 12, PORTA, 1 << 3);
1.123 -}
1.124 -
1.125 -void interrupt_handler(void)
1.126 -{
1.127 - uint32_t ifs;
1.128 -
1.129 - /* Check for a OC1 interrupt condition. */
1.130 -
1.131 - ifs = REG(OCIFS) & OC_INT_FLAGS(1, OCxIF);
1.132 -
1.133 - if (ifs)
1.134 - {
1.135 - vga_interrupt_handler();
1.136 - CLR_REG(OCIFS, ifs);
1.137 - }
1.138 -}
1.139 -
1.140 -
1.141 -
1.142 -/* Peripheral pin configuration. */
1.143 -
1.144 -void config_oc(void)
1.145 -{
1.146 - /* Map OC1 to RPA0. */
1.147 -
1.148 - REG(RPA0R) = 0b0101; /* RPA0R<3:0> = 0101 (OC1) */
1.149 -
1.150 - /* Map OC2 to RPA1. */
1.151 -
1.152 - REG(RPA1R) = 0b0101; /* RPA1R<3:0> = 0101 (OC2) */
1.153 -}
1.154 -
1.155 -void config_uart(void)
1.156 -{
1.157 - /* Map U1RX to RPB13. */
1.158 -
1.159 - REG(U1RXR) = 0b0011; /* U1RXR<3:0> = 0011 (RPB13) */
1.160 -
1.161 - /* Map U1TX to RPB15. */
1.162 -
1.163 - REG(RPB15R) = 0b0001; /* RPB15R<3:0> = 0001 (U1TX) */
1.164 -
1.165 - /* Set RPB13 to input. */
1.166 -
1.167 - SET_REG(TRISB, 1 << 13);
1.168 -}
1.169 +../vga/main.c
1.170 \ No newline at end of file