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