paul@24 | 1 | /* |
paul@24 | 2 | * Generate a VGA signal using a PIC32 microcontroller. |
paul@24 | 3 | * |
paul@24 | 4 | * Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk> |
paul@24 | 5 | * |
paul@24 | 6 | * This program is free software: you can redistribute it and/or modify |
paul@24 | 7 | * it under the terms of the GNU General Public License as published by |
paul@24 | 8 | * the Free Software Foundation, either version 3 of the License, or |
paul@24 | 9 | * (at your option) any later version. |
paul@24 | 10 | * |
paul@24 | 11 | * This program is distributed in the hope that it will be useful, |
paul@24 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@24 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@24 | 14 | * GNU General Public License for more details. |
paul@24 | 15 | * |
paul@24 | 16 | * You should have received a copy of the GNU General Public License |
paul@24 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@24 | 18 | */ |
paul@24 | 19 | |
paul@24 | 20 | |
paul@24 | 21 | #include "pic32_c.h" |
paul@24 | 22 | #include "init.h" |
paul@24 | 23 | #include "debug.h" |
paul@41 | 24 | |
paul@41 | 25 | /* Specific functionality. */ |
paul@41 | 26 | |
paul@47 | 27 | #include "devconfig.h" |
paul@41 | 28 | #include "display.h" |
paul@49 | 29 | #include "display_config.h" |
paul@78 | 30 | #include "font.h" |
paul@78 | 31 | #include "main.h" |
paul@78 | 32 | #include "vga.h" |
paul@88 | 33 | #include "vga_display.h" |
paul@87 | 34 | |
paul@88 | 35 | |
paul@88 | 36 | |
paul@88 | 37 | /* Define DMA channels if not indicated in the build configuration. */ |
paul@88 | 38 | |
paul@88 | 39 | /* CPU-based transfers: no channels. */ |
paul@88 | 40 | |
paul@88 | 41 | #ifdef TRANSFER_CPU |
paul@88 | 42 | #define SCROLL_XSTEP 1 |
paul@88 | 43 | |
paul@88 | 44 | /* DMA-based transfers: single channel by default. */ |
paul@88 | 45 | |
paul@87 | 46 | #else |
paul@88 | 47 | #define SCROLL_XSTEP LINE_CHANNELS |
paul@87 | 48 | #endif |
paul@24 | 49 | |
paul@24 | 50 | |
paul@41 | 51 | |
paul@59 | 52 | /* Define timers if not indicated in the build configuration. */ |
paul@59 | 53 | |
paul@59 | 54 | #ifndef LINE_TIMER |
paul@59 | 55 | #define LINE_TIMER 2 |
paul@59 | 56 | #endif |
paul@59 | 57 | |
paul@59 | 58 | #ifndef TRANSFER_TIMER |
paul@59 | 59 | #define TRANSFER_TIMER 0 |
paul@59 | 60 | #endif |
paul@59 | 61 | |
paul@72 | 62 | /* Define different output ports and pins for parallel mode. */ |
paul@72 | 63 | |
paul@72 | 64 | #ifndef PARALLEL_MODE |
paul@72 | 65 | #define VGA_OUTPUT PORTB |
paul@72 | 66 | #define OC1_PIN RPA0R |
paul@72 | 67 | #define OC2_PIN RPA1R |
paul@72 | 68 | #define LED_PIN (1 << 3) |
paul@72 | 69 | #else |
paul@72 | 70 | #define VGA_OUTPUT PM_REG(0, PMxDIN) |
paul@72 | 71 | #define OC1_PIN RPB4R |
paul@72 | 72 | #define OC2_PIN RPB5R |
paul@72 | 73 | #define LED_PIN (1 << 2) |
paul@72 | 74 | #endif |
paul@72 | 75 | |
paul@59 | 76 | |
paul@59 | 77 | |
paul@101 | 78 | /* Define the relationship between source images and the screen. */ |
paul@101 | 79 | |
paul@101 | 80 | #ifndef SOURCE_HEIGHT |
paul@101 | 81 | #define SOURCE_HEIGHT 256 |
paul@101 | 82 | #endif |
paul@101 | 83 | |
paul@101 | 84 | #define SOURCE_YSTEP (SOURCE_HEIGHT / LINE_COUNT) |
paul@101 | 85 | |
paul@101 | 86 | |
paul@101 | 87 | |
paul@93 | 88 | /* Framebuffer memory. */ |
paul@93 | 89 | |
paul@93 | 90 | static uint8_t framebuffer[FRAME_SIZE * FRAME_COUNT]; |
paul@93 | 91 | |
paul@93 | 92 | |
paul@93 | 93 | |
paul@78 | 94 | /* Bundled image and font data. */ |
paul@69 | 95 | |
paul@69 | 96 | extern uint8_t screendata[]; |
paul@69 | 97 | extern uint32_t screendata_width, screendata_height; |
paul@74 | 98 | extern uint8_t sprite[]; |
paul@74 | 99 | extern uint32_t sprite_width, sprite_height; |
paul@74 | 100 | |
paul@78 | 101 | extern uint8_t fontchars[]; |
paul@78 | 102 | extern uint32_t fonttable[]; |
paul@78 | 103 | extern uint32_t fontbase, fontlimit; |
paul@78 | 104 | |
paul@78 | 105 | static font_config_t font_config; |
paul@78 | 106 | |
paul@69 | 107 | |
paul@69 | 108 | |
paul@74 | 109 | /* Busy wait. */ |
paul@74 | 110 | |
paul@74 | 111 | static void wait(uint32_t delay) |
paul@74 | 112 | { |
paul@74 | 113 | uint32_t counter = delay; |
paul@74 | 114 | |
paul@74 | 115 | if (!delay) return; |
paul@74 | 116 | while (counter--) __asm__(""); /* retain loop */ |
paul@74 | 117 | } |
paul@69 | 118 | |
paul@24 | 119 | /* Blink an attached LED with delays implemented using a loop. */ |
paul@24 | 120 | |
paul@24 | 121 | static void blink(uint32_t delay, uint32_t port, uint32_t pins) |
paul@24 | 122 | { |
paul@24 | 123 | /* Clear outputs (LED). */ |
paul@24 | 124 | |
paul@24 | 125 | CLR_REG(port, pins); |
paul@24 | 126 | |
paul@24 | 127 | while (1) |
paul@24 | 128 | { |
paul@74 | 129 | wait(delay); |
paul@24 | 130 | |
paul@24 | 131 | /* Invert outputs (LED). */ |
paul@24 | 132 | |
paul@24 | 133 | INV_REG(port, pins); |
paul@24 | 134 | } |
paul@24 | 135 | } |
paul@24 | 136 | |
paul@94 | 137 | /* Copy to the store from the display, then blit the image. */ |
paul@94 | 138 | |
paul@94 | 139 | static void plot_sprite(uint8_t *background, int x, int y) |
paul@94 | 140 | { |
paul@94 | 141 | copy_display(&display_config, background, |
paul@101 | 142 | sprite_width, sprite_height / SOURCE_YSTEP, 1, |
paul@94 | 143 | x, y, -1, 0); |
paul@94 | 144 | copy_display(&display_config, sprite, |
paul@101 | 145 | sprite_width, sprite_height, SOURCE_YSTEP, |
paul@94 | 146 | x, y, 0x8c, 1); |
paul@94 | 147 | } |
paul@94 | 148 | |
paul@94 | 149 | /* Copy to the display from the store, restoring the original background. */ |
paul@94 | 150 | |
paul@94 | 151 | static void unplot_sprite(uint8_t *background, int x, int y) |
paul@94 | 152 | { |
paul@94 | 153 | copy_display(&display_config, background, |
paul@101 | 154 | sprite_width, sprite_height / SOURCE_YSTEP, 1, |
paul@94 | 155 | x, y, -1, 1); |
paul@94 | 156 | } |
paul@94 | 157 | |
paul@103 | 158 | /* Wrap a value within the bounds [0, limit). */ |
paul@103 | 159 | |
paul@103 | 160 | static int wrap_value(int value, int limit) |
paul@103 | 161 | { |
paul@103 | 162 | if (value < 0) |
paul@103 | 163 | return limit - (-value % limit); |
paul@103 | 164 | else if (value >= limit) |
paul@103 | 165 | return (value - limit) % limit; |
paul@103 | 166 | else |
paul@103 | 167 | return value; |
paul@103 | 168 | } |
paul@103 | 169 | |
paul@94 | 170 | /* Plot the revealed region at the edge of the screen after scrolling. */ |
paul@94 | 171 | |
paul@94 | 172 | static void plot_screen_edge(int xorigin, int yorigin, int xstep) |
paul@94 | 173 | { |
paul@103 | 174 | /* Determine positions within the image. */ |
paul@103 | 175 | |
paul@103 | 176 | int xpos = wrap_value(xorigin, screendata_width); |
paul@103 | 177 | int ypos = wrap_value(yorigin, screendata_height); |
paul@103 | 178 | |
paul@94 | 179 | /* The display region is either the left or right edge. */ |
paul@94 | 180 | |
paul@94 | 181 | int xdisplay = xstep < 0 ? 0 : screendata_width - xstep; |
paul@94 | 182 | |
paul@94 | 183 | /* The source region depends on the origin within the background image. */ |
paul@94 | 184 | |
paul@103 | 185 | int xsource = wrap_value(xdisplay + xpos, screendata_width); |
paul@94 | 186 | |
paul@94 | 187 | /* The column width is the absolute increment. */ |
paul@94 | 188 | |
paul@94 | 189 | int width = xstep < 0 ? -xstep : xstep; |
paul@94 | 190 | |
paul@103 | 191 | /* Not all of the column may be available if close to the edge of the |
paul@103 | 192 | image, requiring multiple slices. */ |
paul@103 | 193 | |
paul@103 | 194 | int available = screendata_width - xsource; |
paul@94 | 195 | |
paul@103 | 196 | while (width) |
paul@103 | 197 | { |
paul@103 | 198 | /* Plot a column in two pieces if the vertical origin is |
paul@103 | 199 | non-zero. The first piece is at (xdisplay, 0) and |
paul@103 | 200 | provides the lower part of the background image displaced |
paul@103 | 201 | upwards (or downwards having wrapped around) on the |
paul@103 | 202 | screen. */ |
paul@94 | 203 | |
paul@94 | 204 | copy_display_section(&display_config, screendata, |
paul@94 | 205 | screendata_width, screendata_height, |
paul@103 | 206 | xsource, ypos, |
paul@103 | 207 | width, screendata_height - ypos, |
paul@101 | 208 | SOURCE_YSTEP, |
paul@103 | 209 | xdisplay, 0, |
paul@94 | 210 | -1, 1); |
paul@103 | 211 | |
paul@103 | 212 | /* The second column is at (xdisplay, h - ypos) and |
paul@103 | 213 | provides the upper part of the background image displaced |
paul@103 | 214 | downwards (or upwards having wrapped around) on the |
paul@103 | 215 | screen. */ |
paul@94 | 216 | |
paul@103 | 217 | if (ypos) |
paul@103 | 218 | copy_display_section(&display_config, screendata, |
paul@103 | 219 | screendata_width, screendata_height, |
paul@103 | 220 | xsource, 0, |
paul@103 | 221 | width, ypos, |
paul@103 | 222 | SOURCE_YSTEP, |
paul@103 | 223 | xdisplay, (screendata_height - ypos) / SOURCE_YSTEP, |
paul@103 | 224 | -1, 1); |
paul@103 | 225 | |
paul@103 | 226 | /* Get the next slice of the column. */ |
paul@94 | 227 | |
paul@103 | 228 | if (available < width) |
paul@103 | 229 | { |
paul@103 | 230 | width -= available; |
paul@103 | 231 | xsource = 0; |
paul@103 | 232 | xdisplay = wrap_value(xdisplay + available, screendata_width); |
paul@103 | 233 | available = screendata_width; |
paul@103 | 234 | } |
paul@103 | 235 | else |
paul@103 | 236 | width = 0; |
paul@103 | 237 | } |
paul@94 | 238 | } |
paul@94 | 239 | |
paul@74 | 240 | /* Move a sprite around on the framebuffer. */ |
paul@74 | 241 | |
paul@74 | 242 | static void animate(uint32_t delay) |
paul@74 | 243 | { |
paul@88 | 244 | /* Stored region behind the sprite. */ |
paul@88 | 245 | |
paul@102 | 246 | uint8_t background[FRAME_COUNT][(sprite_width * sprite_height) / SOURCE_YSTEP]; |
paul@102 | 247 | |
paul@102 | 248 | /* Positions of the stored regions for each frame. */ |
paul@102 | 249 | |
paul@102 | 250 | int background_x[FRAME_COUNT], background_y[FRAME_COUNT]; |
paul@102 | 251 | int background_stored[FRAME_COUNT]; |
paul@102 | 252 | |
paul@102 | 253 | /* Screen start values for each frame. */ |
paul@102 | 254 | |
paul@102 | 255 | uint32_t frame_offset[FRAME_COUNT]; |
paul@88 | 256 | |
paul@88 | 257 | /* Sprite position. */ |
paul@88 | 258 | |
paul@74 | 259 | int x, y; |
paul@88 | 260 | |
paul@88 | 261 | /* Scrolling directions. */ |
paul@88 | 262 | |
paul@94 | 263 | int dir[] = {1, 0, -1, 0, 1}; |
paul@94 | 264 | int dirindex = 0; |
paul@88 | 265 | |
paul@88 | 266 | /* Scrolling position. */ |
paul@88 | 267 | |
paul@88 | 268 | int xorigin = 0, yorigin = 0; |
paul@88 | 269 | |
paul@102 | 270 | /* Scrolling positions for each frame. */ |
paul@102 | 271 | |
paul@102 | 272 | int xorigins[FRAME_COUNT], yorigins[FRAME_COUNT]; |
paul@102 | 273 | |
paul@94 | 274 | /* Scroll increments and replotted column details. */ |
paul@88 | 275 | |
paul@102 | 276 | int xdir, ydir, xstep, ystep; |
paul@102 | 277 | |
paul@102 | 278 | /* Current frame being accessed. */ |
paul@102 | 279 | |
paul@102 | 280 | int frame; |
paul@102 | 281 | |
paul@102 | 282 | for (frame = 0; frame < display_config.frames; frame++) |
paul@102 | 283 | { |
paul@102 | 284 | background_stored[frame] = 0; |
paul@102 | 285 | frame_offset[frame] = 0; |
paul@102 | 286 | xorigins[frame] = xorigin; |
paul@102 | 287 | yorigins[frame] = yorigin; |
paul@102 | 288 | } |
paul@102 | 289 | |
paul@102 | 290 | frame = display_config.frame; |
paul@102 | 291 | |
paul@102 | 292 | /* Animation loop. */ |
paul@74 | 293 | |
paul@74 | 294 | while (1) |
paul@83 | 295 | { |
paul@102 | 296 | for (y = 0; y < display_config.line_count - sprite_height; y++) |
paul@83 | 297 | { |
paul@102 | 298 | for (x = 0; x < display_config.line_length - sprite_width; x++) |
paul@74 | 299 | { |
paul@102 | 300 | plot_sprite(background[frame], x, y); |
paul@102 | 301 | |
paul@102 | 302 | /* Record the stored background. */ |
paul@102 | 303 | |
paul@102 | 304 | background_x[frame] = x; |
paul@102 | 305 | background_y[frame] = y; |
paul@102 | 306 | background_stored[frame] = 1; |
paul@74 | 307 | |
paul@92 | 308 | /* Update the display with the frame details. */ |
paul@74 | 309 | |
paul@92 | 310 | vga_set_frame(&display_config); |
paul@74 | 311 | wait(delay); |
paul@74 | 312 | |
paul@102 | 313 | /* Select the next frame to plot to. */ |
paul@102 | 314 | |
paul@102 | 315 | frame = wrap_value(frame + 1, display_config.frames); |
paul@102 | 316 | select_frame(&display_config, frame, frame_offset[frame]); |
paul@102 | 317 | |
paul@102 | 318 | /* Prepare the frame for updates. */ |
paul@102 | 319 | |
paul@102 | 320 | if (background_stored[frame]) |
paul@102 | 321 | unplot_sprite(background[frame], background_x[frame], background_y[frame]); |
paul@83 | 322 | |
paul@83 | 323 | /* Scroll in the indicated direction. */ |
paul@83 | 324 | |
paul@94 | 325 | xdir = dir[dirindex]; |
paul@94 | 326 | ydir = dir[dirindex + 1]; |
paul@94 | 327 | |
paul@102 | 328 | /* Update the origin if appropriate. */ |
paul@83 | 329 | |
paul@102 | 330 | /* Due to the effect of a simple screen start increment in the |
paul@102 | 331 | dual channel configuration, horizontal scrolling involves two |
paul@102 | 332 | pixel increments and thus requires a two-pixel column to be |
paul@103 | 333 | plotted per scrolling increment. */ |
paul@102 | 334 | |
paul@102 | 335 | if (xdir) |
paul@102 | 336 | xorigin += xdir * SCROLL_XSTEP; |
paul@84 | 337 | |
paul@103 | 338 | /* For vertically-scaled backgrounds, the full resolution image |
paul@103 | 339 | is traversed by multiples of the scrolling increment. */ |
paul@103 | 340 | |
paul@94 | 341 | if (ydir) |
paul@102 | 342 | yorigin += ydir * SOURCE_YSTEP; |
paul@102 | 343 | |
paul@102 | 344 | /* Determine the magnitude of the scrolling required from this |
paul@102 | 345 | frame to the current origin. */ |
paul@102 | 346 | |
paul@102 | 347 | xstep = xorigin - xorigins[frame]; |
paul@102 | 348 | ystep = yorigin - yorigins[frame]; |
paul@102 | 349 | |
paul@102 | 350 | /* Scroll the frame. */ |
paul@102 | 351 | |
paul@102 | 352 | scroll_display(&display_config, xstep / SCROLL_XSTEP, |
paul@102 | 353 | ystep / SOURCE_YSTEP); |
paul@102 | 354 | |
paul@102 | 355 | /* Record the new screen start offset. */ |
paul@102 | 356 | |
paul@102 | 357 | frame_offset[frame] = get_start_offset(&display_config); |
paul@102 | 358 | |
paul@83 | 359 | /* For horizontal scrolling, plot the exposed column at the left |
paul@83 | 360 | (if scrolling left) or at the right (if scrolling right). */ |
paul@83 | 361 | |
paul@102 | 362 | if (xstep) |
paul@102 | 363 | plot_screen_edge(xorigin, yorigin, xstep); |
paul@83 | 364 | |
paul@102 | 365 | /* Record the origin for this frame. */ |
paul@84 | 366 | |
paul@102 | 367 | xorigins[frame] = xorigin; |
paul@102 | 368 | yorigins[frame] = yorigin; |
paul@74 | 369 | } |
paul@83 | 370 | |
paul@83 | 371 | /* Switch direction periodically. */ |
paul@83 | 372 | |
paul@94 | 373 | dirindex = wrap_value(dirindex + 1, 4); |
paul@83 | 374 | } |
paul@83 | 375 | } |
paul@74 | 376 | } |
paul@74 | 377 | |
paul@78 | 378 | /* Fill the screen with characters. */ |
paul@78 | 379 | |
paul@78 | 380 | static void write_chars(void) |
paul@78 | 381 | { |
paul@78 | 382 | int x = 0, y = 0; |
paul@78 | 383 | char c; |
paul@78 | 384 | |
paul@78 | 385 | font_config.chars = (char_definition_t *) fontchars; |
paul@78 | 386 | font_config.table = fonttable; |
paul@78 | 387 | font_config.base = fontbase; |
paul@78 | 388 | font_config.limit = fontlimit; |
paul@78 | 389 | |
paul@78 | 390 | while (y < display_config.line_count) |
paul@78 | 391 | for (c = (char) font_config.base; c < (char) font_config.limit; c++) |
paul@78 | 392 | { |
paul@78 | 393 | x = write_char(&display_config, &font_config, c, x, y, 0xff); |
paul@78 | 394 | |
paul@78 | 395 | if (x > display_config.line_length) |
paul@78 | 396 | { |
paul@78 | 397 | x = 0; y += 9; |
paul@78 | 398 | } |
paul@78 | 399 | } |
paul@78 | 400 | } |
paul@78 | 401 | |
paul@98 | 402 | /* Set up a background. */ |
paul@98 | 403 | |
paul@98 | 404 | static void setup(void) |
paul@98 | 405 | { |
paul@98 | 406 | int frame; |
paul@98 | 407 | |
paul@98 | 408 | for (frame = 0; frame < display_config.frames; frame++) |
paul@98 | 409 | { |
paul@98 | 410 | /* Obtain the frame. */ |
paul@98 | 411 | |
paul@98 | 412 | select_frame(&display_config, frame, 0); |
paul@98 | 413 | |
paul@98 | 414 | /* Plot the image centred on the screen. */ |
paul@98 | 415 | |
paul@101 | 416 | copy_display(&display_config, screendata, |
paul@101 | 417 | screendata_width, screendata_height, |
paul@101 | 418 | SOURCE_YSTEP, |
paul@98 | 419 | (display_config.line_length - screendata_width) / 2, |
paul@101 | 420 | (display_config.line_count - (screendata_height / SOURCE_YSTEP)) / 2, |
paul@101 | 421 | -1, 1); |
paul@98 | 422 | |
paul@98 | 423 | /* Write a sequence of characters. */ |
paul@98 | 424 | |
paul@98 | 425 | write_chars(); |
paul@98 | 426 | } |
paul@98 | 427 | |
paul@98 | 428 | select_frame(&display_config, 0, 0); |
paul@98 | 429 | } |
paul@98 | 430 | |
paul@24 | 431 | |
paul@24 | 432 | |
paul@24 | 433 | /* Main program. */ |
paul@24 | 434 | |
paul@24 | 435 | void main(void) |
paul@24 | 436 | { |
paul@24 | 437 | init_memory(); |
paul@24 | 438 | init_pins(); |
paul@24 | 439 | init_outputs(); |
paul@24 | 440 | |
paul@24 | 441 | unlock_config(); |
paul@24 | 442 | config_oc(); |
paul@24 | 443 | config_uart(); |
paul@24 | 444 | lock_config(); |
paul@24 | 445 | |
paul@87 | 446 | #ifndef TRANSFER_CPU |
paul@24 | 447 | init_dma(); |
paul@87 | 448 | #endif |
paul@57 | 449 | |
paul@72 | 450 | #ifdef PARALLEL_MODE |
paul@72 | 451 | init_pm(); |
paul@72 | 452 | |
paul@72 | 453 | /* Configure parallel master mode. */ |
paul@72 | 454 | |
paul@72 | 455 | pm_init(0, 0b10); |
paul@72 | 456 | pm_set_output(0, 1, 0); |
paul@72 | 457 | pm_on(0); |
paul@72 | 458 | #endif |
paul@72 | 459 | |
paul@93 | 460 | uart_init(1, FPB, 115200); |
paul@93 | 461 | uart_on(1); |
paul@93 | 462 | |
paul@93 | 463 | /* Initialise memory for a double-buffered display. */ |
paul@93 | 464 | |
paul@93 | 465 | init_display(&display_config, framebuffer, LINE_LENGTH, LINE_COUNT, FRAME_COUNT); |
paul@93 | 466 | |
paul@59 | 467 | /* Initialise VGA output with one or two line channels, configuring a line |
paul@59 | 468 | timer and any transfer timer, with an initiating channel being introduced |
paul@59 | 469 | if a transfer timer is specified. */ |
paul@57 | 470 | |
paul@59 | 471 | init_vga_with_timers(&display_config, LINE_CHANNELS, LINE_TIMER, TRANSFER_TIMER); |
paul@24 | 472 | |
paul@59 | 473 | /* Configure VGA output transfer to the output register, also configuring |
paul@59 | 474 | output compare units for horizontal and vertical sync. */ |
paul@24 | 475 | |
paul@72 | 476 | vga_configure_transfer(VGA_OUTPUT); |
paul@59 | 477 | vga_configure_sync(1, 2); |
paul@24 | 478 | |
paul@24 | 479 | interrupts_on(); |
paul@24 | 480 | |
paul@74 | 481 | /* Move a sprite around on the screen with a delay between each movement. */ |
paul@74 | 482 | |
paul@98 | 483 | setup(); |
paul@96 | 484 | animate(1 << 18); |
paul@24 | 485 | } |
paul@24 | 486 | |
paul@24 | 487 | |
paul@24 | 488 | |
paul@24 | 489 | /* Exception and interrupt handlers. */ |
paul@24 | 490 | |
paul@24 | 491 | void exception_handler(void) |
paul@24 | 492 | { |
paul@79 | 493 | blink(1 << 22, PORTA, LED_PIN); |
paul@24 | 494 | } |
paul@24 | 495 | |
paul@24 | 496 | void interrupt_handler(void) |
paul@24 | 497 | { |
paul@88 | 498 | vga_interrupt_handler(); |
paul@24 | 499 | } |
paul@24 | 500 | |
paul@24 | 501 | |
paul@24 | 502 | |
paul@24 | 503 | /* Peripheral pin configuration. */ |
paul@24 | 504 | |
paul@24 | 505 | void config_oc(void) |
paul@24 | 506 | { |
paul@72 | 507 | /* Map OC1. */ |
paul@24 | 508 | |
paul@72 | 509 | REG(OC1_PIN) = 0b0101; |
paul@24 | 510 | |
paul@72 | 511 | /* Map OC2. */ |
paul@24 | 512 | |
paul@72 | 513 | REG(OC2_PIN) = 0b0101; |
paul@24 | 514 | } |
paul@24 | 515 | |
paul@24 | 516 | void config_uart(void) |
paul@24 | 517 | { |
paul@24 | 518 | /* Map U1RX to RPB13. */ |
paul@24 | 519 | |
paul@24 | 520 | REG(U1RXR) = 0b0011; /* U1RXR<3:0> = 0011 (RPB13) */ |
paul@24 | 521 | |
paul@24 | 522 | /* Map U1TX to RPB15. */ |
paul@24 | 523 | |
paul@24 | 524 | REG(RPB15R) = 0b0001; /* RPB15R<3:0> = 0001 (U1TX) */ |
paul@24 | 525 | |
paul@24 | 526 | /* Set RPB13 to input. */ |
paul@24 | 527 | |
paul@24 | 528 | SET_REG(TRISB, 1 << 13); |
paul@24 | 529 | } |