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