paul@50 | 1 | /* |
paul@50 | 2 | * VGA display-related functions. |
paul@50 | 3 | * |
paul@50 | 4 | * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk> |
paul@50 | 5 | * |
paul@50 | 6 | * This program is free software: you can redistribute it and/or modify |
paul@50 | 7 | * it under the terms of the GNU General Public License as published by |
paul@50 | 8 | * the Free Software Foundation, either version 3 of the License, or |
paul@50 | 9 | * (at your option) any later version. |
paul@50 | 10 | * |
paul@50 | 11 | * This program is distributed in the hope that it will be useful, |
paul@50 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@50 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@50 | 14 | * GNU General Public License for more details. |
paul@50 | 15 | * |
paul@50 | 16 | * You should have received a copy of the GNU General Public License |
paul@50 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@50 | 18 | */ |
paul@50 | 19 | |
paul@50 | 20 | #ifndef __VGA_DISPLAY_H__ |
paul@50 | 21 | #define __VGA_DISPLAY_H__ |
paul@50 | 22 | |
paul@125 | 23 | #include "display.h" |
paul@56 | 24 | #include "pic32_c.h" |
paul@125 | 25 | #include "vga.h" |
paul@50 | 26 | |
paul@50 | 27 | |
paul@50 | 28 | |
paul@50 | 29 | /* Display configuration type. */ |
paul@50 | 30 | |
paul@50 | 31 | typedef struct |
paul@50 | 32 | { |
paul@50 | 33 | /* Current display state handler. */ |
paul@50 | 34 | |
paul@50 | 35 | void (*state_handler)(); |
paul@50 | 36 | |
paul@88 | 37 | /* Common transfer properties. */ |
paul@88 | 38 | |
paul@88 | 39 | int line_timer; |
paul@88 | 40 | uint32_t output; |
paul@88 | 41 | |
paul@56 | 42 | /* DMA transfer properties. */ |
paul@50 | 43 | |
paul@88 | 44 | int line_channels, transfer_int_num; |
paul@125 | 45 | uint32_t transfer_cell_size; |
paul@50 | 46 | |
paul@54 | 47 | /* Horizontal and vertical sync peripherals. */ |
paul@50 | 48 | |
paul@59 | 49 | int hsync_unit, vsync_unit; |
paul@50 | 50 | |
paul@50 | 51 | /* Current scanline. */ |
paul@50 | 52 | |
paul@50 | 53 | uint32_t line; |
paul@50 | 54 | |
paul@92 | 55 | /* Screen start address, frame limit, current pixel line. */ |
paul@92 | 56 | |
paul@92 | 57 | uint8_t *screen_start, *screen_limit, *linedata; |
paul@50 | 58 | |
paul@92 | 59 | /* Screen size, used to wrap the current line pointer. */ |
paul@92 | 60 | |
paul@92 | 61 | uint32_t screen_size; |
paul@50 | 62 | |
paul@50 | 63 | /* General display configuration. */ |
paul@50 | 64 | |
paul@50 | 65 | display_config_t *display_config; |
paul@50 | 66 | |
paul@125 | 67 | /* Display line positions. */ |
paul@125 | 68 | |
paul@125 | 69 | uint32_t hfreq_limit, hsync_start, hsync_end; |
paul@125 | 70 | |
paul@125 | 71 | /* Display region scanline positions. */ |
paul@125 | 72 | |
paul@125 | 73 | uint32_t visible_start, vfp_start, vsync_start, vsync_end; |
paul@125 | 74 | |
paul@50 | 75 | } vga_display_t; |
paul@50 | 76 | |
paul@50 | 77 | |
paul@50 | 78 | |
paul@125 | 79 | /* Initialise a VGA display object with timing and pixel transfer details. |
paul@125 | 80 | This macro depends on the VGA timing constants being defined, and they are |
paul@125 | 81 | included above. |
paul@125 | 82 | |
paul@125 | 83 | VGA_Display(<name>) |
paul@125 | 84 | */ |
paul@125 | 85 | |
paul@125 | 86 | #define VGA_Display(NAME) \ |
paul@125 | 87 | vga_display_t NAME = { \ |
paul@125 | 88 | .transfer_cell_size = TRANSFER_CELL_SIZE, \ |
paul@125 | 89 | .hfreq_limit = HFREQ_LIMIT, \ |
paul@125 | 90 | .hsync_start = HSYNC_START, \ |
paul@125 | 91 | .hsync_end = HSYNC_END, \ |
paul@125 | 92 | .visible_start = VISIBLE_START, \ |
paul@125 | 93 | .vfp_start = VFP_START, \ |
paul@125 | 94 | .vsync_start = VSYNC_START, \ |
paul@125 | 95 | .vsync_end = VSYNC_END}; |
paul@125 | 96 | |
paul@125 | 97 | /* Initialisation functions. */ |
paul@50 | 98 | |
paul@56 | 99 | void init_vga(display_config_t *display_config, int line_channels, |
paul@124 | 100 | int line_timer, int transfer_int_num); |
paul@59 | 101 | |
paul@59 | 102 | void init_vga_with_timers(display_config_t *display_config, int line_channels, |
paul@59 | 103 | int line_timer, int transfer_timer); |
paul@50 | 104 | |
paul@59 | 105 | void vga_configure_sync(int hsync_unit, int vsync_unit); |
paul@53 | 106 | |
paul@59 | 107 | void vga_configure_transfer(uint32_t output); |
paul@59 | 108 | |
paul@88 | 109 | void vga_configure_dma_transfer(uint32_t output); |
paul@88 | 110 | |
paul@59 | 111 | /* Initialisation helpers. */ |
paul@56 | 112 | |
paul@56 | 113 | void vga_configure_line_channel(int channel, int int_num, enum dma_chain chain, |
paul@56 | 114 | uint32_t output); |
paul@56 | 115 | |
paul@56 | 116 | void vga_configure_zero_channel(int channel, int int_num, int initiating, |
paul@56 | 117 | uint32_t output); |
paul@56 | 118 | |
paul@96 | 119 | /* Access-related operations. */ |
paul@96 | 120 | |
paul@92 | 121 | void vga_set_frame(display_config_t *display_config); |
paul@96 | 122 | void vga_wait_visible(void); |
paul@96 | 123 | |
paul@50 | 124 | /* Interrupt handlers. */ |
paul@50 | 125 | |
paul@50 | 126 | void vga_interrupt_handler(void); |
paul@88 | 127 | void vga_hsync_interrupt_handler(void); |
paul@88 | 128 | void vga_transfer_interrupt_handler(void); |
paul@50 | 129 | |
paul@50 | 130 | /* Display state handlers. */ |
paul@50 | 131 | |
paul@50 | 132 | void vbp_active(void); |
paul@50 | 133 | void visible_active(void); |
paul@50 | 134 | void vfp_active(void); |
paul@50 | 135 | void vsync_active(void); |
paul@50 | 136 | |
paul@88 | 137 | /* DMA transfer operations. */ |
paul@56 | 138 | |
paul@56 | 139 | void start_visible(void); |
paul@56 | 140 | void update_visible(void); |
paul@56 | 141 | void stop_visible(void); |
paul@56 | 142 | void update_transfers(int enable); |
paul@56 | 143 | |
paul@54 | 144 | /* Vertical sync operations. */ |
paul@54 | 145 | |
paul@54 | 146 | void vsync_high(void); |
paul@54 | 147 | void vsync_low(void); |
paul@54 | 148 | |
paul@50 | 149 | #endif /* __VGA_DISPLAY_H__ */ |