#ifndef __VGA_H__ #define __VGA_H__ #include "System.h" #include "stm32f4xx.h" #include typedef void HBlankInterruptFunction(void); extern volatile uint32_t VGALine; extern volatile uint32_t VGAFrame; void InitializeVGA(); void InitializeVGAFor800x600(); void InitializeVGAFor1024x768(); void InitializeVGAWithTimings(uint32_t hsynccycles,uint32_t pulselength,uint32_t pulseandbackporchlength); void SetBlankVGAScreenMode480(); void SetBlankVGAScreenMode400(); void SetBlankVGAScreenMode350(); void SetBlankVGAScreenMode600(); void SetBlankVGAScreenMode768(); void SetVGAScreenMode240At480(uint8_t *framebuffer,int pixelsperrow,int pixelticks); void SetVGAScreenMode200At480(uint8_t *framebuffer,int pixelsperrow,int pixelticks); void SetVGAScreenMode200At400(uint8_t *framebuffer,int pixelsperrow,int pixelticks); void SetVGAScreenMode175At350(uint8_t *framebuffer,int pixelsperrow,int pixelticks); void SetVGAScreenMode160At480(uint8_t *framebuffer,int pixelsperrow,int pixelticks); void SetVGAScreenMode133At480(uint8_t *framebuffer,int pixelsperrow,int pixelticks); void SetVGAScreenMode133At400(uint8_t *framebuffer,int pixelsperrow,int pixelticks); void SetVGAScreenMode117At350(uint8_t *framebuffer,int pixelsperrow,int pixelticks); void SetVGAScreenMode128At768(uint8_t *framebuffer,int pixelsperrow,int pixelticks); void SetFrameBuffer(uint8_t *framebuffer); #ifdef EnableOverclocking // Pixel ticks = 176 MHz / Pixel clock * Pixel multiplier static inline void SetVGAScreenMode320x240(uint8_t *framebuffer) { SetVGAScreenMode240At480(framebuffer,320,14); } static inline void SetVGAScreenMode320x200_60Hz(uint8_t *framebuffer) { SetVGAScreenMode200At480(framebuffer,320,14); } static inline void SetVGAScreenMode320x200(uint8_t *framebuffer) { SetVGAScreenMode200At400(framebuffer,320,14); } static inline void SetVGAScreenMode320x175(uint8_t *framebuffer) { SetVGAScreenMode175At350(framebuffer,320,14); } static inline void SetVGAScreenMode212x160(uint8_t *framebuffer) { SetVGAScreenMode160At480(framebuffer,212,21); } static inline void SetVGAScreenMode212x133_60Hz(uint8_t *framebuffer) { SetVGAScreenMode133At480(framebuffer,212,21); } static inline void SetVGAScreenMode212x133(uint8_t *framebuffer) { SetVGAScreenMode133At400(framebuffer,212,21); } static inline void SetVGAScreenMode212x175(uint8_t *framebuffer) { SetVGAScreenMode117At350(framebuffer,212,21); } static inline void SetVGAScreenMode170x128(uint8_t *framebuffer) { SetVGAScreenMode128At768(framebuffer,170,16); } #else // Pixel ticks = 168 MHz / Pixel clock * Pixel multiplier static inline void SetVGAScreenMode320x240(uint8_t *framebuffer) { SetVGAScreenMode240At480(framebuffer,320,13); } static inline void SetVGAScreenMode320x200_60Hz(uint8_t *framebuffer) { SetVGAScreenMode200At480(framebuffer,320,13); } static inline void SetVGAScreenMode320x200(uint8_t *framebuffer) { SetVGAScreenMode200At400(framebuffer,320,13); } static inline void SetVGAScreenMode320x175(uint8_t *framebuffer) { SetVGAScreenMode175At350(framebuffer,320,13); } static inline void SetVGAScreenMode212x160(uint8_t *framebuffer) { SetVGAScreenMode160At480(framebuffer,212,19); } static inline void SetVGAScreenMode212x133_60Hz(uint8_t *framebuffer) { SetVGAScreenMode133At480(framebuffer,212,19); } static inline void SetVGAScreenMode212x133(uint8_t *framebuffer) { SetVGAScreenMode133At400(framebuffer,212,19); } static inline void SetVGAScreenMode212x117(uint8_t *framebuffer) { SetVGAScreenMode117At350(framebuffer,212,19); } static inline void SetVGAScreenMode170x128(uint8_t *framebuffer) { SetVGAScreenMode128At768(framebuffer,170,15); } #endif static inline void WaitVBL() { uint32_t currframe=VGAFrame; while(VGAFrame==currframe); } static inline uint32_t VGAFrameCounter() { return VGAFrame; } // Functions for implementing your own video driving code. void SetVGAHorizontalSync(InterruptHandler *handler); void SetVGAHorizontalSyncActiveHigh(InterruptHandler *handler); void SetVGAHorizontalSyncWithEarlyStart(InterruptHandler *handler,int offset); void SetVGAHorizontalSyncActiveHighWithEarlyStart(InterruptHandler *handler,int offset); void SetVGAHorizontalSyncForDMA(InterruptHandler *handler); void SetVGAHorizontalSyncActiveHighForDMA(InterruptHandler *handler); static inline void RaiseVGAVSyncLine() { GPIOB->BSRRL=(1<<12); } static inline void LowerVGAVSyncLine() { GPIOB->BSRRH=(1<<12); } static inline void SetVGASignalToBlack() { GPIOE->BSRRH=0xff00; } static inline void SetVGASignal(uint8_t pixel) { ((uint8_t *)&GPIOE->ODR)[1]=pixel; } static inline int HandleVGAHSync480() { // TIM2->SR=0; __asm__ volatile( " mov.w r1,#0x40000000\n" " movs r0,#0\n" " strh r0,[r1,#0x10]\n" :::"r0","r1"); VGALine++; if(VGALine<480) { return VGALine; } else if(VGALine==480) { VGAFrame++; } else if(VGALine==490) { LowerVGAVSyncLine(); } else if(VGALine==492) { RaiseVGAVSyncLine(); } else if(VGALine==524) { VGALine=-1; } return -1; } static inline int HandleVGAHSync400At480() { // TIM2->SR=0; __asm__ volatile( " mov.w r1,#0x40000000\n" " movs r0,#0\n" " strh r0,[r1,#0x10]\n" :::"r0","r1"); VGALine++; if(VGALine<40) { return -1; } else if(VGALine<440) { return VGALine-40; } else if(VGALine==440) { VGAFrame++; } else if(VGALine==490) { LowerVGAVSyncLine(); } else if(VGALine==492) { RaiseVGAVSyncLine(); } else if(VGALine==524) { VGALine=-1; } return -1; } static inline int HandleVGAHSync400() { // TIM2->SR=0; __asm__ volatile( " mov.w r1,#0x40000000\n" " movs r0,#0\n" " strh r0,[r1,#0x10]\n" :::"r0","r1"); VGALine++; if(VGALine<400) { return VGALine; } else if(VGALine==400) { VGAFrame++; } else if(VGALine==412) { RaiseVGAVSyncLine(); } else if(VGALine==414) { LowerVGAVSyncLine(); } else if(VGALine==448) { VGALine=-1; } return -1; } static inline int HandleVGAHSync350() { // TIM2->SR=0; __asm__ volatile( " mov.w r1,#0x40000000\n" " movs r0,#0\n" " strh r0,[r1,#0x10]\n" :::"r0","r1"); VGALine++; if(VGALine<350) { return VGALine; } else if(VGALine==350) { VGAFrame++; } else if(VGALine==387) { LowerVGAVSyncLine(); } else if(VGALine==389) { RaiseVGAVSyncLine(); } else if(VGALine==448) { VGALine=-1; } return -1; } static inline int HandleVGAHSync600() { // TIM2->SR=0; __asm__ volatile( " mov.w r1,#0x40000000\n" " movs r0,#0\n" " strh r0,[r1,#0x10]\n" :::"r0","r1"); VGALine++; if(VGALine<600) { return VGALine; } else if(VGALine==600) { VGAFrame++; } else if(VGALine==601) { RaiseVGAVSyncLine(); } else if(VGALine==605) { LowerVGAVSyncLine(); } else if(VGALine==627) { VGALine=-1; } return -1; } static inline int HandleVGAHSync768() { // TIM2->SR=0; __asm__ volatile( " mov.w r1,#0x40000000\n" " movs r0,#0\n" " strh r0,[r1,#0x10]\n" :::"r0","r1"); VGALine++; if(VGALine<768) { return VGALine; } else if(VGALine==768) { VGAFrame++; } else if(VGALine==768+3) { LowerVGAVSyncLine(); } else if(VGALine==768+3+6) { RaiseVGAVSyncLine(); } else if(VGALine==768+3+6+29-1) { VGALine=-1; } return -1; } // Deprecated old names. static inline void SetVGAHorizontalSync31kHz(InterruptHandler *handler) { SetVGAHorizontalSync(handler); } static inline void SetVGAHorizontalSync31kHzActiveHigh(InterruptHandler *handler) { SetVGAHorizontalSyncActiveHigh(handler); } static inline void SetVGAHorizontalSync31kHzWithEarlyStart(InterruptHandler *handler,int offset) { SetVGAHorizontalSyncWithEarlyStart(handler,offset); } static inline void SetVGAHorizontalSync31kHzActiveHighWithEarlyStart(InterruptHandler *handler,int offset) { SetVGAHorizontalSyncActiveHighWithEarlyStart(handler,offset); } static inline void SetVGAScreenMode240(uint8_t *framebuffer,int pixelsperrow,int pixelticks) { SetVGAScreenMode240At480(framebuffer,pixelsperrow,pixelticks); } static inline void SetVGAScreenMode200_60Hz(uint8_t *framebuffer,int pixelsperrow,int pixelticks) { SetVGAScreenMode200At480(framebuffer,pixelsperrow,pixelticks); } static inline void SetVGAScreenMode200(uint8_t *framebuffer,int pixelsperrow,int pixelticks) { SetVGAScreenMode200At400(framebuffer,pixelsperrow,pixelticks); } static inline void SetVGAScreenMode175(uint8_t *framebuffer,int pixelsperrow,int pixelticks) { SetVGAScreenMode175At350(framebuffer,pixelsperrow,pixelticks); } static inline void SetVGAScreenMode160(uint8_t *framebuffer,int pixelsperrow,int pixelticks) { SetVGAScreenMode160At480(framebuffer,pixelsperrow,pixelticks); } static inline void SetVGAScreenMode133_60Hz(uint8_t *framebuffer,int pixelsperrow,int pixelticks) { SetVGAScreenMode133At480(framebuffer,pixelsperrow,pixelticks); } static inline void SetVGAScreenMode133(uint8_t *framebuffer,int pixelsperrow,int pixelticks) { SetVGAScreenMode133At400(framebuffer,pixelsperrow,pixelticks); } static inline void SetVGAScreenMode117(uint8_t *framebuffer,int pixelsperrow,int pixelticks) { SetVGAScreenMode117At350(framebuffer,pixelsperrow,pixelticks); } #endif