Anuj Patel
/
uVGAII_with_printf
Wrappper for VGAII demo by Jim Hamblem that includes a printf function that can print infinitely.
main.cpp@0:10b753bd635e, 2011-10-13 (annotated)
- Committer:
- apatel43
- Date:
- Thu Oct 13 19:21:27 2011 +0000
- Revision:
- 0:10b753bd635e
Version 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
apatel43 | 0:10b753bd635e | 1 | // |
apatel43 | 0:10b753bd635e | 2 | // TFT_4DGL is a class to drive 4D Systems TFT touch screens |
apatel43 | 0:10b753bd635e | 3 | // |
apatel43 | 0:10b753bd635e | 4 | // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> |
apatel43 | 0:10b753bd635e | 5 | // |
apatel43 | 0:10b753bd635e | 6 | // TFT_4DGL is free software: you can redistribute it and/or modify |
apatel43 | 0:10b753bd635e | 7 | // it under the terms of the GNU General Public License as published by |
apatel43 | 0:10b753bd635e | 8 | // the Free Software Foundation, either version 3 of the License, or |
apatel43 | 0:10b753bd635e | 9 | // (at your option) any later version. |
apatel43 | 0:10b753bd635e | 10 | // |
apatel43 | 0:10b753bd635e | 11 | // TFT_4DGL is distributed in the hope that it will be useful, |
apatel43 | 0:10b753bd635e | 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
apatel43 | 0:10b753bd635e | 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
apatel43 | 0:10b753bd635e | 14 | // GNU General Public License for more details. |
apatel43 | 0:10b753bd635e | 15 | // |
apatel43 | 0:10b753bd635e | 16 | // You should have received a copy of the GNU General Public License |
apatel43 | 0:10b753bd635e | 17 | // along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. |
apatel43 | 0:10b753bd635e | 18 | |
apatel43 | 0:10b753bd635e | 19 | #include "mbed.h" |
apatel43 | 0:10b753bd635e | 20 | #include "TFT_4DGL.h" |
apatel43 | 0:10b753bd635e | 21 | #include <stdarg.h> |
apatel43 | 0:10b753bd635e | 22 | #include <stdio.h> |
apatel43 | 0:10b753bd635e | 23 | |
apatel43 | 0:10b753bd635e | 24 | // overwrite 4DGL library screen size settings in TFT_4DGL.h |
apatel43 | 0:10b753bd635e | 25 | #define SIZE_X 479 |
apatel43 | 0:10b753bd635e | 26 | #define SIZE_Y 639 |
apatel43 | 0:10b753bd635e | 27 | // |
apatel43 | 0:10b753bd635e | 28 | |
apatel43 | 0:10b753bd635e | 29 | TFT_4DGL ecran(p9,p10,p11); // serial tx, serial rx, reset pin; |
apatel43 | 0:10b753bd635e | 30 | |
apatel43 | 0:10b753bd635e | 31 | |
apatel43 | 0:10b753bd635e | 32 | int outputrow = 1; |
apatel43 | 0:10b753bd635e | 33 | int j = 0; |
apatel43 | 0:10b753bd635e | 34 | char buffer[20480]; //working at 4608 |
apatel43 | 0:10b753bd635e | 35 | char printbuf[256]; |
apatel43 | 0:10b753bd635e | 36 | int linenum=1; |
apatel43 | 0:10b753bd635e | 37 | |
apatel43 | 0:10b753bd635e | 38 | void myprintf(const char* format, ...) { |
apatel43 | 0:10b753bd635e | 39 | char dest[256]; |
apatel43 | 0:10b753bd635e | 40 | if(j>80){ |
apatel43 | 0:10b753bd635e | 41 | j=0; |
apatel43 | 0:10b753bd635e | 42 | } |
apatel43 | 0:10b753bd635e | 43 | va_list argptr; |
apatel43 | 0:10b753bd635e | 44 | va_start(argptr, format); |
apatel43 | 0:10b753bd635e | 45 | vsprintf(dest, format, argptr); |
apatel43 | 0:10b753bd635e | 46 | va_end(argptr); |
apatel43 | 0:10b753bd635e | 47 | for ( int i = 0; i < 256; i++) { |
apatel43 | 0:10b753bd635e | 48 | buffer[256*j+i]= dest[i]; |
apatel43 | 0:10b753bd635e | 49 | } |
apatel43 | 0:10b753bd635e | 50 | j++; |
apatel43 | 0:10b753bd635e | 51 | int linenum = j; |
apatel43 | 0:10b753bd635e | 52 | |
apatel43 | 0:10b753bd635e | 53 | for (int k = 0; k <256; k++) { |
apatel43 | 0:10b753bd635e | 54 | printbuf[k] = buffer[256*(linenum-1)+k]; |
apatel43 | 0:10b753bd635e | 55 | } |
apatel43 | 0:10b753bd635e | 56 | ecran.rectangle(0, 8*outputrow, 639, 8*outputrow+31, BLACK); |
apatel43 | 0:10b753bd635e | 57 | ecran.text_string( dest, 0 , outputrow , FONT_8X8, WHITE); |
apatel43 | 0:10b753bd635e | 58 | outputrow+= 4; |
apatel43 | 0:10b753bd635e | 59 | if(outputrow>58){ |
apatel43 | 0:10b753bd635e | 60 | outputrow =1; |
apatel43 | 0:10b753bd635e | 61 | } |
apatel43 | 0:10b753bd635e | 62 | } |
apatel43 | 0:10b753bd635e | 63 | |
apatel43 | 0:10b753bd635e | 64 | |
apatel43 | 0:10b753bd635e | 65 | |
apatel43 | 0:10b753bd635e | 66 | int main() { |
apatel43 | 0:10b753bd635e | 67 | // char s[500]; |
apatel43 | 0:10b753bd635e | 68 | // int x = 0, y = 0, status, xc = 0, yc = 0; |
apatel43 | 0:10b753bd635e | 69 | |
apatel43 | 0:10b753bd635e | 70 | ecran.baudrate(115200); |
apatel43 | 0:10b753bd635e | 71 | // added - Set Display to 640 by 480 mode |
apatel43 | 0:10b753bd635e | 72 | ecran.display_control(0x0c, 0x01); |
apatel43 | 0:10b753bd635e | 73 | for(int i=0; i < 300; i++){ |
apatel43 | 0:10b753bd635e | 74 | myprintf("This is line %i.Because printing to through the vga is slow, any prints off the screen will wrap around to the top of the screen and override the the existing text on the screen 1 line at a time. Therefore, the user has the ability to print infinitely.", i); |
apatel43 | 0:10b753bd635e | 75 | } |
apatel43 | 0:10b753bd635e | 76 | } |
apatel43 | 0:10b753bd635e | 77 | |
apatel43 | 0:10b753bd635e | 78 | /* |
apatel43 | 0:10b753bd635e | 79 | DigitalIn up(p22); |
apatel43 | 0:10b753bd635e | 80 | DigitalIn down(p21); |
apatel43 | 0:10b753bd635e | 81 | DigitalOut led1(LED1); |
apatel43 | 0:10b753bd635e | 82 | DigitalOut led2(LED2); |
apatel43 | 0:10b753bd635e | 83 | DigitalOut led3(LED3); |
apatel43 | 0:10b753bd635e | 84 | DigitalOut led4(LED4); |
apatel43 | 0:10b753bd635e | 85 | |
apatel43 | 0:10b753bd635e | 86 | void cursor() { |
apatel43 | 0:10b753bd635e | 87 | DigitalIn up(p22); |
apatel43 | 0:10b753bd635e | 88 | DigitalIn down(p21); |
apatel43 | 0:10b753bd635e | 89 | DigitalOut led1(LED1); |
apatel43 | 0:10b753bd635e | 90 | DigitalOut led2(LED2); |
apatel43 | 0:10b753bd635e | 91 | DigitalOut led3(LED3); |
apatel43 | 0:10b753bd635e | 92 | DigitalOut led4(LED4); |
apatel43 | 0:10b753bd635e | 93 | while (1) { |
apatel43 | 0:10b753bd635e | 94 | up.mode(PullUp); |
apatel43 | 0:10b753bd635e | 95 | down.mode(PullUp); |
apatel43 | 0:10b753bd635e | 96 | if (!up) { |
apatel43 | 0:10b753bd635e | 97 | led1 = 1; |
apatel43 | 0:10b753bd635e | 98 | if (linenum>0) { |
apatel43 | 0:10b753bd635e | 99 | linenum--; |
apatel43 | 0:10b753bd635e | 100 | for (int k = 0; k <256; k++) { |
apatel43 | 0:10b753bd635e | 101 | printbuf[k] = buffer[256*(linenum-1)+k]; |
apatel43 | 0:10b753bd635e | 102 | } |
apatel43 | 0:10b753bd635e | 103 | ecran.rectangle(0, 0, 639, 59, BLACK); |
apatel43 | 0:10b753bd635e | 104 | ecran.text_string( printbuf, 0 , 1 , FONT_8X8, WHITE); |
apatel43 | 0:10b753bd635e | 105 | } |
apatel43 | 0:10b753bd635e | 106 | } |
apatel43 | 0:10b753bd635e | 107 | if (up) { |
apatel43 | 0:10b753bd635e | 108 | led3 = 1; |
apatel43 | 0:10b753bd635e | 109 | led1=0; |
apatel43 | 0:10b753bd635e | 110 | } |
apatel43 | 0:10b753bd635e | 111 | if (!down) { |
apatel43 | 0:10b753bd635e | 112 | led2 = 1; |
apatel43 | 0:10b753bd635e | 113 | if (linenum<j) { |
apatel43 | 0:10b753bd635e | 114 | linenum++; |
apatel43 | 0:10b753bd635e | 115 | for (int k = 0; k <256; k++) { |
apatel43 | 0:10b753bd635e | 116 | printbuf[k] = buffer[256*(linenum-1)+k]; |
apatel43 | 0:10b753bd635e | 117 | } |
apatel43 | 0:10b753bd635e | 118 | ecran.rectangle(0, 0, 639, 59, BLACK); |
apatel43 | 0:10b753bd635e | 119 | ecran.text_string( printbuf, 0 , 1 , FONT_8X8, WHITE); |
apatel43 | 0:10b753bd635e | 120 | } |
apatel43 | 0:10b753bd635e | 121 | } |
apatel43 | 0:10b753bd635e | 122 | if (down) { |
apatel43 | 0:10b753bd635e | 123 | led4 = 1; |
apatel43 | 0:10b753bd635e | 124 | led2=0; |
apatel43 | 0:10b753bd635e | 125 | } |
apatel43 | 0:10b753bd635e | 126 | } |
apatel43 | 0:10b753bd635e | 127 | } |
apatel43 | 0:10b753bd635e | 128 | */ |