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@131 | 51 | /* Current scanline and pixel line. */ |
paul@50 | 52 | |
paul@133 | 53 | uint32_t scanline, line; |
paul@131 | 54 | uint8_t *linedata; |
paul@50 | 55 | |
paul@133 | 56 | /* Separate display windows dividing the display vertically. */ |
paul@133 | 57 | |
paul@133 | 58 | int window, windows, max_windows; |
paul@133 | 59 | |
paul@133 | 60 | /* A collection of line numbers ending each window. */ |
paul@133 | 61 | |
paul@133 | 62 | uint32_t *window_end; |
paul@133 | 63 | |
paul@131 | 64 | /* The start, limit and size of the screen are copied to this structure, |
paul@131 | 65 | allowing the display configuration to use different values such as those |
paul@131 | 66 | for a different display frame. */ |
paul@92 | 67 | |
paul@131 | 68 | /* Screen start address, frame limit. */ |
paul@131 | 69 | |
paul@133 | 70 | uint8_t **screen_start, **screen_limit; |
paul@50 | 71 | |
paul@92 | 72 | /* Screen size, used to wrap the current line pointer. */ |
paul@92 | 73 | |
paul@133 | 74 | uint32_t *screen_size; |
paul@133 | 75 | |
paul@133 | 76 | /* General display properties defined by the collection of windows. */ |
paul@133 | 77 | |
paul@133 | 78 | uint32_t line_length, line_count; |
paul@50 | 79 | |
paul@133 | 80 | /* Number of scanlines on the display. */ |
paul@133 | 81 | |
paul@133 | 82 | uint32_t scanlines; |
paul@50 | 83 | |
paul@133 | 84 | /* Number of scanlines per display line. */ |
paul@133 | 85 | |
paul@133 | 86 | int line_multiplier; /* = scanlines / line_count */ |
paul@50 | 87 | |
paul@125 | 88 | /* Display line positions. */ |
paul@125 | 89 | |
paul@125 | 90 | uint32_t hfreq_limit, hsync_start, hsync_end; |
paul@125 | 91 | |
paul@125 | 92 | /* Display region scanline positions. */ |
paul@125 | 93 | |
paul@125 | 94 | uint32_t visible_start, vfp_start, vsync_start, vsync_end; |
paul@125 | 95 | |
paul@50 | 96 | } vga_display_t; |
paul@50 | 97 | |
paul@50 | 98 | |
paul@50 | 99 | |
paul@125 | 100 | /* Initialise a VGA display object with timing and pixel transfer details. |
paul@125 | 101 | This macro depends on the VGA timing constants being defined, and they are |
paul@125 | 102 | included above. |
paul@125 | 103 | |
paul@133 | 104 | VGA_Display(<name>, int windows) |
paul@125 | 105 | */ |
paul@125 | 106 | |
paul@133 | 107 | #define VGA_Display(NAME, WINDOWS) \ |
paul@133 | 108 | uint32_t __##NAME##_window_end[WINDOWS]; \ |
paul@133 | 109 | uint8_t *__##NAME##_screen_start[WINDOWS]; \ |
paul@133 | 110 | uint8_t *__##NAME##_screen_limit[WINDOWS]; \ |
paul@133 | 111 | uint32_t __##NAME##_screen_size[WINDOWS]; \ |
paul@133 | 112 | \ |
paul@125 | 113 | vga_display_t NAME = { \ |
paul@133 | 114 | .window_end = __##NAME##_window_end, \ |
paul@133 | 115 | .screen_start = __##NAME##_screen_start, \ |
paul@133 | 116 | .screen_limit = __##NAME##_screen_limit, \ |
paul@133 | 117 | .screen_size = __##NAME##_screen_size, \ |
paul@133 | 118 | .window = 0, \ |
paul@133 | 119 | .windows = 0, \ |
paul@133 | 120 | .max_windows = WINDOWS, \ |
paul@125 | 121 | .transfer_cell_size = TRANSFER_CELL_SIZE, \ |
paul@133 | 122 | .scanlines = SCANLINES, \ |
paul@125 | 123 | .hfreq_limit = HFREQ_LIMIT, \ |
paul@125 | 124 | .hsync_start = HSYNC_START, \ |
paul@125 | 125 | .hsync_end = HSYNC_END, \ |
paul@125 | 126 | .visible_start = VISIBLE_START, \ |
paul@125 | 127 | .vfp_start = VFP_START, \ |
paul@125 | 128 | .vsync_start = VSYNC_START, \ |
paul@125 | 129 | .vsync_end = VSYNC_END}; |
paul@125 | 130 | |
paul@125 | 131 | /* Initialisation functions. */ |
paul@50 | 132 | |
paul@56 | 133 | void init_vga(display_config_t *display_config, int line_channels, |
paul@124 | 134 | int line_timer, int transfer_int_num); |
paul@59 | 135 | |
paul@59 | 136 | void init_vga_with_timers(display_config_t *display_config, int line_channels, |
paul@59 | 137 | int line_timer, int transfer_timer); |
paul@50 | 138 | |
paul@59 | 139 | void vga_configure_sync(int hsync_unit, int vsync_unit); |
paul@53 | 140 | |
paul@59 | 141 | void vga_configure_transfer(uint32_t output); |
paul@59 | 142 | |
paul@88 | 143 | void vga_configure_dma_transfer(uint32_t output); |
paul@88 | 144 | |
paul@59 | 145 | /* Initialisation helpers. */ |
paul@56 | 146 | |
paul@56 | 147 | void vga_configure_line_channel(int channel, int int_num, enum dma_chain chain, |
paul@56 | 148 | uint32_t output); |
paul@56 | 149 | |
paul@56 | 150 | void vga_configure_zero_channel(int channel, int int_num, int initiating, |
paul@56 | 151 | uint32_t output); |
paul@56 | 152 | |
paul@133 | 153 | void vga_update_properties(void); |
paul@133 | 154 | |
paul@96 | 155 | /* Access-related operations. */ |
paul@96 | 156 | |
paul@133 | 157 | void vga_add_window(display_config_t *display_config); |
paul@133 | 158 | void vga_set_frame(display_config_t *display_config, int window); |
paul@96 | 159 | void vga_wait_visible(void); |
paul@96 | 160 | |
paul@50 | 161 | /* Interrupt handlers. */ |
paul@50 | 162 | |
paul@50 | 163 | void vga_interrupt_handler(void); |
paul@88 | 164 | void vga_hsync_interrupt_handler(void); |
paul@88 | 165 | void vga_transfer_interrupt_handler(void); |
paul@50 | 166 | |
paul@50 | 167 | /* Display state handlers. */ |
paul@50 | 168 | |
paul@50 | 169 | void vbp_active(void); |
paul@50 | 170 | void visible_active(void); |
paul@50 | 171 | void vfp_active(void); |
paul@50 | 172 | void vsync_active(void); |
paul@50 | 173 | |
paul@88 | 174 | /* DMA transfer operations. */ |
paul@56 | 175 | |
paul@56 | 176 | void start_visible(void); |
paul@56 | 177 | void update_visible(void); |
paul@56 | 178 | void stop_visible(void); |
paul@56 | 179 | void update_transfers(int enable); |
paul@56 | 180 | |
paul@54 | 181 | /* Vertical sync operations. */ |
paul@54 | 182 | |
paul@54 | 183 | void vsync_high(void); |
paul@54 | 184 | void vsync_low(void); |
paul@54 | 185 | |
paul@50 | 186 | #endif /* __VGA_DISPLAY_H__ */ |