Adapted from Peter Dresche's original for Waveshare 2.8inch TFT Touch Shield Board and Mbed 6. RGB order reversed by changing reg 16 commands, spi write code adjusted as there is no reset pin but there is data command pin. Wait commands changed for new thread_sleep style, Stream class explicitly included. 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
TextDisplay.cpp
00001 /* mbed TextDisplay Display Library Base Class 00002 * Copyright (c) 2007-2009 sford 00003 * Released under the MIT License: http://mbed.org/license/mit 00004 */ 00005 00006 #include "TextDisplay.h" 00007 00008 00009 TextDisplay::TextDisplay(const char *name) : Stream(name){ 00010 _row = 0; 00011 _column = 0; 00012 if (name == NULL) { 00013 _path = NULL; 00014 } else { 00015 _path = new char[strlen(name) + 2]; 00016 sprintf(_path, "/%s", name); 00017 } 00018 } 00019 00020 int TextDisplay::_putc(int value) { 00021 if(value == '\n') { 00022 _column = 0; 00023 _row++; 00024 if(_row >= rows()) { 00025 _row = 0; 00026 } 00027 } else { 00028 character(_column, _row, value); 00029 _column++; 00030 if(_column >= columns()) { 00031 _column = 0; 00032 _row++; 00033 if(_row >= rows()) { 00034 _row = 0; 00035 } 00036 } 00037 } 00038 return value; 00039 } 00040 00041 // crude cls implementation, should generally be overwritten in derived class 00042 void TextDisplay::cls() { 00043 locate(0, 0); 00044 for(int i=0; i<columns()*rows(); i++) { 00045 putc(' '); 00046 } 00047 } 00048 00049 void TextDisplay::locate(int column, int row) { 00050 _column = column; 00051 _row = row; 00052 } 00053 00054 int TextDisplay::_getc() { 00055 return -1; 00056 } 00057 00058 void TextDisplay::foreground(uint16_t colour) { 00059 _foreground = colour; 00060 } 00061 00062 void TextDisplay::background(uint16_t colour) { 00063 _background = colour; 00064 } 00065 00066 bool TextDisplay::claim (FILE *stream) { 00067 if ( _path == NULL) { 00068 fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n"); 00069 return false; 00070 } 00071 if (freopen(_path, "w", stream) == NULL) { 00072 // Failed, should not happen 00073 return false; 00074 } 00075 // make sure we use line buffering 00076 setvbuf(stdout, NULL, _IOLBF, columns()); 00077 return true; 00078 }
Generated on Sun Jul 17 2022 11:36:08 by
1.7.2