Library to control a QVGA TFT connected to SPI. You can use printf to print text The lib can handle different fonts, draw lines, circles, rect and bmp

Committer:
dreschpe
Date:
Tue Sep 11 20:44:49 2012 +0000
Revision:
13:d525819cb601
Parent:
0:cccc5726bdf3
Switch back to io mode CS. The automatic spi cs can cause problems with interrupts or RTOS.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreschpe 0:cccc5726bdf3 1 /* mbed TextDisplay Display Library Base Class
dreschpe 0:cccc5726bdf3 2 * Copyright (c) 2007-2009 sford
dreschpe 0:cccc5726bdf3 3 * Released under the MIT License: http://mbed.org/license/mit
dreschpe 0:cccc5726bdf3 4 */
dreschpe 0:cccc5726bdf3 5
dreschpe 0:cccc5726bdf3 6 #include "TextDisplay.h"
dreschpe 0:cccc5726bdf3 7
dreschpe 0:cccc5726bdf3 8 TextDisplay::TextDisplay(const char *name) : Stream(name){
dreschpe 0:cccc5726bdf3 9 _row = 0;
dreschpe 0:cccc5726bdf3 10 _column = 0;
dreschpe 0:cccc5726bdf3 11 if (name == NULL) {
dreschpe 0:cccc5726bdf3 12 _path = NULL;
dreschpe 0:cccc5726bdf3 13 } else {
dreschpe 0:cccc5726bdf3 14 _path = new char[strlen(name) + 2];
dreschpe 0:cccc5726bdf3 15 sprintf(_path, "/%s", name);
dreschpe 0:cccc5726bdf3 16 }
dreschpe 0:cccc5726bdf3 17 }
dreschpe 0:cccc5726bdf3 18
dreschpe 0:cccc5726bdf3 19 int TextDisplay::_putc(int value) {
dreschpe 0:cccc5726bdf3 20 if(value == '\n') {
dreschpe 0:cccc5726bdf3 21 _column = 0;
dreschpe 0:cccc5726bdf3 22 _row++;
dreschpe 0:cccc5726bdf3 23 if(_row >= rows()) {
dreschpe 0:cccc5726bdf3 24 _row = 0;
dreschpe 0:cccc5726bdf3 25 }
dreschpe 0:cccc5726bdf3 26 } else {
dreschpe 0:cccc5726bdf3 27 character(_column, _row, value);
dreschpe 0:cccc5726bdf3 28 _column++;
dreschpe 0:cccc5726bdf3 29 if(_column >= columns()) {
dreschpe 0:cccc5726bdf3 30 _column = 0;
dreschpe 0:cccc5726bdf3 31 _row++;
dreschpe 0:cccc5726bdf3 32 if(_row >= rows()) {
dreschpe 0:cccc5726bdf3 33 _row = 0;
dreschpe 0:cccc5726bdf3 34 }
dreschpe 0:cccc5726bdf3 35 }
dreschpe 0:cccc5726bdf3 36 }
dreschpe 0:cccc5726bdf3 37 return value;
dreschpe 0:cccc5726bdf3 38 }
dreschpe 0:cccc5726bdf3 39
dreschpe 0:cccc5726bdf3 40 // crude cls implementation, should generally be overwritten in derived class
dreschpe 0:cccc5726bdf3 41 void TextDisplay::cls() {
dreschpe 0:cccc5726bdf3 42 locate(0, 0);
dreschpe 0:cccc5726bdf3 43 for(int i=0; i<columns()*rows(); i++) {
dreschpe 0:cccc5726bdf3 44 putc(' ');
dreschpe 0:cccc5726bdf3 45 }
dreschpe 0:cccc5726bdf3 46 }
dreschpe 0:cccc5726bdf3 47
dreschpe 0:cccc5726bdf3 48 void TextDisplay::locate(int column, int row) {
dreschpe 0:cccc5726bdf3 49 _column = column;
dreschpe 0:cccc5726bdf3 50 _row = row;
dreschpe 0:cccc5726bdf3 51 }
dreschpe 0:cccc5726bdf3 52
dreschpe 0:cccc5726bdf3 53 int TextDisplay::_getc() {
dreschpe 0:cccc5726bdf3 54 return -1;
dreschpe 0:cccc5726bdf3 55 }
dreschpe 0:cccc5726bdf3 56
dreschpe 0:cccc5726bdf3 57 void TextDisplay::foreground(uint16_t colour) {
dreschpe 0:cccc5726bdf3 58 _foreground = colour;
dreschpe 0:cccc5726bdf3 59 }
dreschpe 0:cccc5726bdf3 60
dreschpe 0:cccc5726bdf3 61 void TextDisplay::background(uint16_t colour) {
dreschpe 0:cccc5726bdf3 62 _background = colour;
dreschpe 0:cccc5726bdf3 63 }
dreschpe 0:cccc5726bdf3 64
dreschpe 0:cccc5726bdf3 65 bool TextDisplay::claim (FILE *stream) {
dreschpe 0:cccc5726bdf3 66 if ( _path == NULL) {
dreschpe 0:cccc5726bdf3 67 fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n");
dreschpe 0:cccc5726bdf3 68 return false;
dreschpe 0:cccc5726bdf3 69 }
dreschpe 0:cccc5726bdf3 70 if (freopen(_path, "w", stream) == NULL) {
dreschpe 0:cccc5726bdf3 71 // Failed, should not happen
dreschpe 0:cccc5726bdf3 72 return false;
dreschpe 0:cccc5726bdf3 73 }
dreschpe 0:cccc5726bdf3 74 // make sure we use line buffering
dreschpe 0:cccc5726bdf3 75 setvbuf(stdout, NULL, _IOLBF, columns());
dreschpe 0:cccc5726bdf3 76 return true;
dreschpe 0:cccc5726bdf3 77 }