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.h
00001 /* mbed TextDisplay Library Base Class 00002 * Copyright (c) 2007-2009 sford 00003 * Released under the MIT License: http://mbed.org/license/mit 00004 * 00005 * A common base class for Text displays 00006 * To port a new display, derive from this class and implement 00007 * the constructor (setup the display), character (put a character 00008 * at a location), rows and columns (number of rows/cols) functions. 00009 * Everything else (locate, printf, putc, cls) will come for free 00010 * 00011 * The model is the display will wrap at the right and bottom, so you can 00012 * keep writing and will always get valid characters. The location is 00013 * maintained internally to the class to make this easy 00014 */ 00015 00016 #ifndef MBED_TEXTDISPLAY_H 00017 #define MBED_TEXTDISPLAY_H 00018 00019 #include "mbed.h" 00020 #include <Stream.h> 00021 00022 00023 class TextDisplay : public Stream { 00024 public: 00025 00026 // functions needing implementation in derived implementation class 00027 /** Create a TextDisplay interface 00028 * 00029 * @param name The name used in the path to access the strean through the filesystem 00030 */ 00031 TextDisplay(const char *name = NULL); 00032 00033 /** output a character at the given position 00034 * 00035 * @param column column where charater must be written 00036 * @param row where character must be written 00037 * @param c the character to be written to the TextDisplay 00038 */ 00039 virtual void character(int column, int row, int c) = 0; 00040 00041 /** return number if rows on TextDisplay 00042 * @result number of rows 00043 */ 00044 virtual int rows() = 0; 00045 00046 /** return number if columns on TextDisplay 00047 * @result number of rows 00048 */ 00049 virtual int columns() = 0; 00050 00051 // functions that come for free, but can be overwritten 00052 00053 /** redirect output from a stream (stoud, sterr) to display 00054 * @param stream stream that shall be redirected to the TextDisplay 00055 */ 00056 virtual bool claim (FILE *stream); 00057 00058 /** clear screen 00059 */ 00060 virtual void cls(); 00061 virtual void locate(int column, int row); 00062 virtual void foreground(uint16_t colour); 00063 virtual void background(uint16_t colour); 00064 // putc (from Stream) 00065 // printf (from Stream) 00066 00067 protected: 00068 00069 virtual int _putc(int value); 00070 virtual int _getc(); 00071 00072 // character location 00073 uint16_t _column; 00074 uint16_t _row; 00075 00076 // colours 00077 uint16_t _foreground; 00078 uint16_t _background; 00079 char *_path; 00080 }; 00081 00082 #endif
Generated on Sun Jul 17 2022 11:36:08 by
1.7.2