Demo of low res colour vga video for stm32f3 discovery board
Dependencies: STM32F3-Discovery-minimal
Fork of Space_Invaders_Demo by
demo.c@17:833f1b69e11d, 2019-04-03 (annotated)
- Committer:
- MartinJohnson
- Date:
- Wed Apr 03 22:05:56 2019 +0000
- Revision:
- 17:833f1b69e11d
- Parent:
- 14:3035b3271395
update library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MartinJohnson | 0:404dae88af71 | 1 | /*************************************************************************** |
MartinJohnson | 0:404dae88af71 | 2 | * STM32 VGA demo |
MartinJohnson | 0:404dae88af71 | 3 | |
MartinJohnson | 0:404dae88af71 | 4 | ### demo.c |
MartinJohnson | 0:404dae88af71 | 5 | |
MartinJohnson | 0:404dae88af71 | 6 | # This program is free software; you can redistribute it and/or modify |
MartinJohnson | 0:404dae88af71 | 7 | # it under the terms of the GNU General Public License as published by |
MartinJohnson | 0:404dae88af71 | 8 | # the Free Software Foundation; either version 2 of the License, or |
MartinJohnson | 0:404dae88af71 | 9 | # (at your option) any later version. |
MartinJohnson | 0:404dae88af71 | 10 | # |
MartinJohnson | 0:404dae88af71 | 11 | # This program is distributed in the hope that it will be useful, |
MartinJohnson | 0:404dae88af71 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
MartinJohnson | 0:404dae88af71 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MartinJohnson | 0:404dae88af71 | 14 | # GNU General Public License for more details. |
MartinJohnson | 0:404dae88af71 | 15 | # |
MartinJohnson | 0:404dae88af71 | 16 | # You should have received a copy of the GNU General Public License |
MartinJohnson | 0:404dae88af71 | 17 | # along with this program; if not, write to the Free Software |
MartinJohnson | 0:404dae88af71 | 18 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
MartinJohnson | 0:404dae88af71 | 19 | |
MartinJohnson | 0:404dae88af71 | 20 | ***************************************************************************/ |
MartinJohnson | 0:404dae88af71 | 21 | |
MartinJohnson | 0:404dae88af71 | 22 | #include "stm32f30x.h" |
MartinJohnson | 0:404dae88af71 | 23 | #include "sys.h" |
MartinJohnson | 0:404dae88af71 | 24 | #include "video.h" |
MartinJohnson | 0:404dae88af71 | 25 | #include "gdi.h" |
MartinJohnson | 0:404dae88af71 | 26 | #include "string.h" |
MartinJohnson | 0:404dae88af71 | 27 | //#include <stdlib.h> |
MartinJohnson | 0:404dae88af71 | 28 | |
MartinJohnson | 0:404dae88af71 | 29 | extern volatile u32 sysTicks; |
MartinJohnson | 0:404dae88af71 | 30 | int rndseed=0; |
MartinJohnson | 0:404dae88af71 | 31 | |
MartinJohnson | 0:404dae88af71 | 32 | void srand(int i) { |
MartinJohnson | 0:404dae88af71 | 33 | rndseed=i; |
MartinJohnson | 0:404dae88af71 | 34 | } |
MartinJohnson | 0:404dae88af71 | 35 | |
MartinJohnson | 0:404dae88af71 | 36 | |
MartinJohnson | 0:404dae88af71 | 37 | int rand() { |
MartinJohnson | 0:404dae88af71 | 38 | return( ((rndseed = rndseed * 214013L + 2531011L) >> 16) & |
MartinJohnson | 0:404dae88af71 | 39 | 0x7fff ); |
MartinJohnson | 0:404dae88af71 | 40 | } |
MartinJohnson | 0:404dae88af71 | 41 | |
MartinJohnson | 0:404dae88af71 | 42 | const u8 deBadBoys1[] = { 0x00, 0x00, |
MartinJohnson | 0:404dae88af71 | 43 | 0x00, 0x00, |
MartinJohnson | 0:404dae88af71 | 44 | 0x07, 0xc0, |
MartinJohnson | 0:404dae88af71 | 45 | 0x1f, 0xf0, |
MartinJohnson | 0:404dae88af71 | 46 | 0x3f, 0xf8, |
MartinJohnson | 0:404dae88af71 | 47 | 0x33, 0x98, |
MartinJohnson | 0:404dae88af71 | 48 | 0x3f, 0xf8, |
MartinJohnson | 0:404dae88af71 | 49 | 0x0c, 0x60, |
MartinJohnson | 0:404dae88af71 | 50 | 0x1b, 0xb0, |
MartinJohnson | 0:404dae88af71 | 51 | 0x30, 0x18, |
MartinJohnson | 0:404dae88af71 | 52 | 0x00, 0x00, |
MartinJohnson | 0:404dae88af71 | 53 | 0x00, 0x00 }; |
MartinJohnson | 0:404dae88af71 | 54 | |
MartinJohnson | 0:404dae88af71 | 55 | const u8 deBadBoys2[] = { 0x00, 0x00, |
MartinJohnson | 0:404dae88af71 | 56 | 0x00, 0x00, |
MartinJohnson | 0:404dae88af71 | 57 | 0x07, 0xc0, |
MartinJohnson | 0:404dae88af71 | 58 | 0x1f, 0xf0, |
MartinJohnson | 0:404dae88af71 | 59 | 0x3f, 0xf8, |
MartinJohnson | 0:404dae88af71 | 60 | 0x33, 0x98, |
MartinJohnson | 0:404dae88af71 | 61 | 0x3f, 0xf8, |
MartinJohnson | 0:404dae88af71 | 62 | 0x0c, 0x60, |
MartinJohnson | 0:404dae88af71 | 63 | 0x1b, 0xb0, |
MartinJohnson | 0:404dae88af71 | 64 | 0x0c, 0x60, |
MartinJohnson | 0:404dae88af71 | 65 | 0x00, 0x00, |
MartinJohnson | 0:404dae88af71 | 66 | 0x00, 0x00 }; |
MartinJohnson | 0:404dae88af71 | 67 | void conway_demo(void); |
MartinJohnson | 0:404dae88af71 | 68 | void demoInit(void) { |
MartinJohnson | 0:404dae88af71 | 69 | |
MartinJohnson | 0:404dae88af71 | 70 | i32 x, y, x1, y1, i, flip; |
MartinJohnson | 0:404dae88af71 | 71 | |
MartinJohnson | 0:404dae88af71 | 72 | |
MartinJohnson | 0:404dae88af71 | 73 | // Demo Point |
MartinJohnson | 14:3035b3271395 | 74 | //while(1) { |
MartinJohnson | 3:93e488fbb8a2 | 75 | GPIOE->ODR|=0x100; |
MartinJohnson | 0:404dae88af71 | 76 | vidClearScreen(); |
MartinJohnson | 3:93e488fbb8a2 | 77 | GPIOE->ODR|=0x200; |
MartinJohnson | 0:404dae88af71 | 78 | gdiRectangle(0,0,(VID_PIXELS_X - 1),VID_VSIZE - 1,0); |
MartinJohnson | 3:93e488fbb8a2 | 79 | GPIOE->ODR|=0x300; |
MartinJohnson | 3:93e488fbb8a2 | 80 | GPIOE->ODR|=0x400; |
MartinJohnson | 14:3035b3271395 | 81 | gdiDrawTextEx(40, 55, "STM32F3 Discovery", GDI_ROP_COPY); |
MartinJohnson | 14:3035b3271395 | 82 | gdiDrawTextEx(40, 70, "Point Demo", GDI_ROP_COPY); |
MartinJohnson | 3:93e488fbb8a2 | 83 | GPIOE->ODR|=0x500; |
MartinJohnson | 3:93e488fbb8a2 | 84 | vidNextBuffer(); |
MartinJohnson | 3:93e488fbb8a2 | 85 | sysDelayMs(2000); |
MartinJohnson | 3:93e488fbb8a2 | 86 | GPIOE->ODR|=0x600; |
MartinJohnson | 0:404dae88af71 | 87 | srand(sysTicks); |
MartinJohnson | 0:404dae88af71 | 88 | for (i = 0; i < 950000; i++) { |
MartinJohnson | 0:404dae88af71 | 89 | // sysDelayMs(1); |
MartinJohnson | 0:404dae88af71 | 90 | x = rand(); x = x % (VID_PIXELS_X - 1); |
MartinJohnson | 0:404dae88af71 | 91 | y = rand(); y = y % VID_VSIZE - 1; |
MartinJohnson | 3:93e488fbb8a2 | 92 | gdiSetColour(rand()%7+1); |
MartinJohnson | 0:404dae88af71 | 93 | gdiPoint(NULL,x,y,GDI_ROP_XOR); |
MartinJohnson | 3:93e488fbb8a2 | 94 | if(i%20000==0) |
MartinJohnson | 3:93e488fbb8a2 | 95 | vidNextBuffer(); |
MartinJohnson | 0:404dae88af71 | 96 | } |
MartinJohnson | 3:93e488fbb8a2 | 97 | vidNextBuffer(); |
MartinJohnson | 0:404dae88af71 | 98 | sysDelayMs(300); |
MartinJohnson | 0:404dae88af71 | 99 | GPIOE->ODR=0x700; |
MartinJohnson | 0:404dae88af71 | 100 | |
MartinJohnson | 3:93e488fbb8a2 | 101 | // conway_demo(); |
MartinJohnson | 3:93e488fbb8a2 | 102 | |
MartinJohnson | 14:3035b3271395 | 103 | // if(GPIOA->IDR&1) bubble_demo(); |
MartinJohnson | 0:404dae88af71 | 104 | |
MartinJohnson | 0:404dae88af71 | 105 | // Demo Line |
MartinJohnson | 0:404dae88af71 | 106 | |
MartinJohnson | 0:404dae88af71 | 107 | vidClearScreen(); |
MartinJohnson | 0:404dae88af71 | 108 | gdiRectangle(0,0,(VID_PIXELS_X - 1),VID_VSIZE - 1,0); |
MartinJohnson | 14:3035b3271395 | 109 | gdiDrawTextEx(40, 55, "STM32F3 Discovery", GDI_ROP_COPY); |
MartinJohnson | 14:3035b3271395 | 110 | gdiDrawTextEx(40, 70, "Line Demo", GDI_ROP_COPY); |
MartinJohnson | 3:93e488fbb8a2 | 111 | vidNextBuffer(); |
MartinJohnson | 0:404dae88af71 | 112 | sysDelayMs(300); |
MartinJohnson | 0:404dae88af71 | 113 | srand(sysTicks); |
MartinJohnson | 0:404dae88af71 | 114 | for (i = 0; i < 10000; i++) { |
MartinJohnson | 0:404dae88af71 | 115 | // sysDelayMs(50); |
MartinJohnson | 0:404dae88af71 | 116 | x = rand(); x = x % (VID_PIXELS_X - 1); |
MartinJohnson | 0:404dae88af71 | 117 | y = rand(); y = y % VID_VSIZE - 1; |
MartinJohnson | 0:404dae88af71 | 118 | x1 = rand(); x1 = x1 % (VID_PIXELS_X - 1); |
MartinJohnson | 0:404dae88af71 | 119 | y1 = rand(); y1 = y1 % VID_VSIZE - 1; |
MartinJohnson | 3:93e488fbb8a2 | 120 | gdiSetColour(rand()%7+1); |
MartinJohnson | 0:404dae88af71 | 121 | gdiLine(NULL,x,y,x1,y1,GDI_ROP_XOR); |
MartinJohnson | 3:93e488fbb8a2 | 122 | if(i%500==0) |
MartinJohnson | 3:93e488fbb8a2 | 123 | vidNextBuffer(); |
MartinJohnson | 0:404dae88af71 | 124 | } |
MartinJohnson | 0:404dae88af71 | 125 | sysDelayMs(300); |
MartinJohnson | 0:404dae88af71 | 126 | |
MartinJohnson | 0:404dae88af71 | 127 | // Demo Square |
MartinJohnson | 0:404dae88af71 | 128 | |
MartinJohnson | 0:404dae88af71 | 129 | vidClearScreen(); |
MartinJohnson | 0:404dae88af71 | 130 | gdiRectangle(0,0,(VID_PIXELS_X - 1),VID_VSIZE - 1,0); |
MartinJohnson | 14:3035b3271395 | 131 | gdiDrawTextEx(40, 55, "STM32F3 Discovery", GDI_ROP_COPY); |
MartinJohnson | 14:3035b3271395 | 132 | gdiDrawTextEx(40, 70, "Rectangle Demo", GDI_ROP_COPY); |
MartinJohnson | 3:93e488fbb8a2 | 133 | vidNextBuffer(); |
MartinJohnson | 0:404dae88af71 | 134 | sysDelayMs(300); |
MartinJohnson | 0:404dae88af71 | 135 | srand(sysTicks); |
MartinJohnson | 14:3035b3271395 | 136 | for (i = 0; i < 8000; i++) { |
MartinJohnson | 0:404dae88af71 | 137 | // sysDelayMs(50); |
MartinJohnson | 0:404dae88af71 | 138 | x = rand(); x = x % (VID_PIXELS_X - 1); |
MartinJohnson | 0:404dae88af71 | 139 | y = rand(); y = y % VID_VSIZE - 1; |
MartinJohnson | 0:404dae88af71 | 140 | x1 = rand(); x1 = x1 % 100; |
MartinJohnson | 0:404dae88af71 | 141 | y1 = rand(); y1 = y1 % 100; |
MartinJohnson | 3:93e488fbb8a2 | 142 | gdiSetColour(rand()%7+1); |
MartinJohnson | 0:404dae88af71 | 143 | gdiRectangle(x,y,x1,y1,GDI_ROP_COPY); |
MartinJohnson | 3:93e488fbb8a2 | 144 | if(i%50==0) |
MartinJohnson | 3:93e488fbb8a2 | 145 | vidNextBuffer(); |
MartinJohnson | 3:93e488fbb8a2 | 146 | |
MartinJohnson | 0:404dae88af71 | 147 | } |
MartinJohnson | 0:404dae88af71 | 148 | sysDelayMs(300); |
MartinJohnson | 0:404dae88af71 | 149 | |
MartinJohnson | 0:404dae88af71 | 150 | // Demo Circle |
MartinJohnson | 0:404dae88af71 | 151 | |
MartinJohnson | 0:404dae88af71 | 152 | vidClearScreen(); |
MartinJohnson | 0:404dae88af71 | 153 | gdiRectangle(0,0,(VID_PIXELS_X - 1),VID_VSIZE - 1,0); |
MartinJohnson | 14:3035b3271395 | 154 | gdiDrawTextEx(40, 55, "STM32F3 Discovery", GDI_ROP_COPY); |
MartinJohnson | 14:3035b3271395 | 155 | gdiDrawTextEx(40, 70, "Circle Demo", GDI_ROP_COPY); |
MartinJohnson | 3:93e488fbb8a2 | 156 | vidNextBuffer(); |
MartinJohnson | 0:404dae88af71 | 157 | sysDelayMs(300); |
MartinJohnson | 0:404dae88af71 | 158 | srand(sysTicks); |
MartinJohnson | 3:93e488fbb8a2 | 159 | for (i = 0; i < 2000; i++) { |
MartinJohnson | 0:404dae88af71 | 160 | // sysDelayMs(20); |
MartinJohnson | 0:404dae88af71 | 161 | x = rand(); x = x % (VID_PIXELS_X - 1); |
MartinJohnson | 0:404dae88af71 | 162 | y = rand(); y = y % VID_VSIZE - 1; |
MartinJohnson | 0:404dae88af71 | 163 | x1 = rand(); x1 = x1 % 80; |
MartinJohnson | 3:93e488fbb8a2 | 164 | gdiSetColour(rand()%7+1); |
MartinJohnson | 3:93e488fbb8a2 | 165 | gdiCircle(x,y,x1,0); |
MartinJohnson | 3:93e488fbb8a2 | 166 | if(i%10==0) |
MartinJohnson | 3:93e488fbb8a2 | 167 | vidNextBuffer(); |
MartinJohnson | 0:404dae88af71 | 168 | } |
MartinJohnson | 0:404dae88af71 | 169 | sysDelayMs(300); |
MartinJohnson | 0:404dae88af71 | 170 | |
MartinJohnson | 0:404dae88af71 | 171 | // Demo Bitmap |
MartinJohnson | 0:404dae88af71 | 172 | |
MartinJohnson | 0:404dae88af71 | 173 | vidClearScreen(); |
MartinJohnson | 0:404dae88af71 | 174 | gdiRectangle(0,0,(VID_PIXELS_X - 1),VID_VSIZE - 1,0); |
MartinJohnson | 14:3035b3271395 | 175 | gdiDrawTextEx(40, 55, "STM32F3 Discovery", GDI_ROP_COPY); |
MartinJohnson | 14:3035b3271395 | 176 | gdiDrawTextEx(40, 70, "Bitmap Demo", GDI_ROP_COPY); |
MartinJohnson | 3:93e488fbb8a2 | 177 | vidNextBuffer(); |
MartinJohnson | 0:404dae88af71 | 178 | sysDelayMs(300); |
MartinJohnson | 0:404dae88af71 | 179 | |
MartinJohnson | 0:404dae88af71 | 180 | x = 100; |
MartinJohnson | 0:404dae88af71 | 181 | y = 130; |
MartinJohnson | 0:404dae88af71 | 182 | flip = 0; |
MartinJohnson | 3:93e488fbb8a2 | 183 | for (i = 0; i < 10000; i++) { |
MartinJohnson | 0:404dae88af71 | 184 | // sysDelayMs(150); |
MartinJohnson | 0:404dae88af71 | 185 | x = rand(); x = x % (VID_PIXELS_X - 20); |
MartinJohnson | 0:404dae88af71 | 186 | y = rand(); y = y % (VID_VSIZE - 20); |
MartinJohnson | 0:404dae88af71 | 187 | |
MartinJohnson | 3:93e488fbb8a2 | 188 | gdiSetColour(rand()%7+1); |
MartinJohnson | 0:404dae88af71 | 189 | if (flip) { |
MartinJohnson | 0:404dae88af71 | 190 | flip = 0; |
MartinJohnson | 0:404dae88af71 | 191 | gdiBitBlt(NULL,x,y,15,12,(pu8) deBadBoys1,GDI_ROP_COPY); |
MartinJohnson | 0:404dae88af71 | 192 | } else { |
MartinJohnson | 0:404dae88af71 | 193 | flip = 1; |
MartinJohnson | 0:404dae88af71 | 194 | gdiBitBlt(NULL,x,y,15,12,(pu8) deBadBoys2,GDI_ROP_COPY); |
MartinJohnson | 0:404dae88af71 | 195 | } |
MartinJohnson | 0:404dae88af71 | 196 | x += 2; |
MartinJohnson | 3:93e488fbb8a2 | 197 | if(i%500==0) |
MartinJohnson | 3:93e488fbb8a2 | 198 | vidNextBuffer(); |
MartinJohnson | 0:404dae88af71 | 199 | } |
MartinJohnson | 0:404dae88af71 | 200 | sysDelayMs(300); |
MartinJohnson | 0:404dae88af71 | 201 | vidClearScreen(); |
MartinJohnson | 3:93e488fbb8a2 | 202 | for (i = 0; i < 10000; i++) { |
MartinJohnson | 0:404dae88af71 | 203 | // sysDelayMs(150); |
MartinJohnson | 0:404dae88af71 | 204 | x = rand(); x = x % (VID_PIXELS_X - 20); |
MartinJohnson | 0:404dae88af71 | 205 | y = rand(); y = y % (VID_VSIZE - 20); |
MartinJohnson | 3:93e488fbb8a2 | 206 | gdiSetColour(rand()%7+1); |
MartinJohnson | 0:404dae88af71 | 207 | if (flip) { |
MartinJohnson | 0:404dae88af71 | 208 | flip = 0; |
MartinJohnson | 0:404dae88af71 | 209 | gdiBitBlt(NULL,x,y,15,12,(pu8) deBadBoys1,GDI_ROP_XOR); |
MartinJohnson | 0:404dae88af71 | 210 | } else { |
MartinJohnson | 0:404dae88af71 | 211 | flip = 1; |
MartinJohnson | 0:404dae88af71 | 212 | gdiBitBlt(NULL,x,y,15,12,(pu8) deBadBoys2,GDI_ROP_XOR); |
MartinJohnson | 0:404dae88af71 | 213 | } |
MartinJohnson | 0:404dae88af71 | 214 | x += 2; |
MartinJohnson | 3:93e488fbb8a2 | 215 | if(i%500==0) |
MartinJohnson | 3:93e488fbb8a2 | 216 | vidNextBuffer(); |
MartinJohnson | 0:404dae88af71 | 217 | } |
MartinJohnson | 3:93e488fbb8a2 | 218 | sysDelayMs(300); |
MartinJohnson | 0:404dae88af71 | 219 | |
MartinJohnson | 14:3035b3271395 | 220 | //conway_demo(); |
MartinJohnson | 14:3035b3271395 | 221 | //} |
MartinJohnson | 0:404dae88af71 | 222 | |
MartinJohnson | 0:404dae88af71 | 223 | |
MartinJohnson | 0:404dae88af71 | 224 | } |
MartinJohnson | 0:404dae88af71 | 225 |