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 and pixel line. */ 52 53 uint32_t line; 54 uint8_t *linedata; 55 56 /* The start, limit and size of the screen are copied to this structure, 57 allowing the display configuration to use different values such as those 58 for a different display frame. */ 59 60 /* Screen start address, frame limit. */ 61 62 uint8_t *screen_start, *screen_limit; 63 64 /* Screen size, used to wrap the current line pointer. */ 65 66 uint32_t screen_size; 67 68 /* General display configuration. */ 69 70 display_config_t *display_config; 71 72 /* Display line positions. */ 73 74 uint32_t hfreq_limit, hsync_start, hsync_end; 75 76 /* Display region scanline positions. */ 77 78 uint32_t visible_start, vfp_start, vsync_start, vsync_end; 79 80 } vga_display_t; 81 82 83 84 /* Initialise a VGA display object with timing and pixel transfer details. 85 This macro depends on the VGA timing constants being defined, and they are 86 included above. 87 88 VGA_Display(<name>) 89 */ 90 91 #define VGA_Display(NAME) \ 92 vga_display_t NAME = { \ 93 .transfer_cell_size = TRANSFER_CELL_SIZE, \ 94 .hfreq_limit = HFREQ_LIMIT, \ 95 .hsync_start = HSYNC_START, \ 96 .hsync_end = HSYNC_END, \ 97 .visible_start = VISIBLE_START, \ 98 .vfp_start = VFP_START, \ 99 .vsync_start = VSYNC_START, \ 100 .vsync_end = VSYNC_END}; 101 102 /* Initialisation functions. */ 103 104 void init_vga(display_config_t *display_config, int line_channels, 105 int line_timer, int transfer_int_num); 106 107 void init_vga_with_timers(display_config_t *display_config, int line_channels, 108 int line_timer, int transfer_timer); 109 110 void vga_configure_sync(int hsync_unit, int vsync_unit); 111 112 void vga_configure_transfer(uint32_t output); 113 114 void vga_configure_dma_transfer(uint32_t output); 115 116 /* Initialisation helpers. */ 117 118 void vga_configure_line_channel(int channel, int int_num, enum dma_chain chain, 119 uint32_t output); 120 121 void vga_configure_zero_channel(int channel, int int_num, int initiating, 122 uint32_t output); 123 124 /* Access-related operations. */ 125 126 void vga_set_frame(display_config_t *display_config); 127 void vga_wait_visible(void); 128 129 /* Interrupt handlers. */ 130 131 void vga_interrupt_handler(void); 132 void vga_hsync_interrupt_handler(void); 133 void vga_transfer_interrupt_handler(void); 134 135 /* Display state handlers. */ 136 137 void vbp_active(void); 138 void visible_active(void); 139 void vfp_active(void); 140 void vsync_active(void); 141 142 /* DMA transfer operations. */ 143 144 void start_visible(void); 145 void update_visible(void); 146 void stop_visible(void); 147 void update_transfers(int enable); 148 149 /* Vertical sync operations. */ 150 151 void vsync_high(void); 152 void vsync_low(void); 153 154 #endif /* __VGA_DISPLAY_H__ */