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