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
Diff: SPI_TFT.h
- Revision:
- 0:cccc5726bdf3
- Child:
- 1:aa3356b16080
diff -r 000000000000 -r cccc5726bdf3 SPI_TFT.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SPI_TFT.h Tue Jul 12 08:27:34 2011 +0000 @@ -0,0 +1,93 @@ +/* mbed library for 240*320 pixel display TFT based on HX8347D LCD Controller + * Copyright (c) 2011 Peter Drescher - DC2PD + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MBED_SPI_TFT_H +#define MBED_SPI_TFT_H + +#include "mbed.h" +#include "GraphicsDisplay.h" + +#define RGB(r,g,b) (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) //5 red | 6 green | 5 blue + +#define SPI_START (0x70) /* Start byte for SPI transfer */ +#define SPI_RD (0x01) /* WR bit 1 within start */ +#define SPI_WR (0x00) /* WR bit 0 within start */ +#define SPI_DATA (0x02) /* RS bit 1 within start byte */ +#define SPI_INDEX (0x00) /* RS bit 0 within start byte */ + + +/* some RGB color definitions */ +#define Black 0x0000 /* 0, 0, 0 */ +#define Navy 0x000F /* 0, 0, 128 */ +#define DarkGreen 0x03E0 /* 0, 128, 0 */ +#define DarkCyan 0x03EF /* 0, 128, 128 */ +#define Maroon 0x7800 /* 128, 0, 0 */ +#define Purple 0x780F /* 128, 0, 128 */ +#define Olive 0x7BE0 /* 128, 128, 0 */ +#define LightGrey 0xC618 /* 192, 192, 192 */ +#define DarkGrey 0x7BEF /* 128, 128, 128 */ +#define Blue 0x001F /* 0, 0, 255 */ +#define Green 0x07E0 /* 0, 255, 0 */ +#define Cyan 0x07FF /* 0, 255, 255 */ +#define Red 0xF800 /* 255, 0, 0 */ +#define Magenta 0xF81F /* 255, 0, 255 */ +#define Yellow 0xFFE0 /* 255, 255, 0 */ +#define White 0xFFFF /* 255, 255, 255 */ + + + +class SPI_TFT : public GraphicsDisplay { +public: + SPI_TFT(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset,const char* name ="TFT"); + virtual int width(); + virtual int height(); + virtual void pixel(int x, int y, int colour); + void circle(int x, int y, int r, int colour); + void line(int x0, int y0, int x1, int y1, int colour); + void rect(int x0, int y0, int x1, int y1, int colour); + void fillrect(int x0, int y0, int x1, int y1, int colour); + void locate(int column, int row); + virtual void cls (void); + int columns(void); + int rows(void); + int _putc(int value); + virtual void character(int col, int row, int c); + void Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap); + void set_font(unsigned char* f); + void set_orientation(unsigned int o); + + SPI _spi; + DigitalOut _cs; + DigitalOut _reset; + unsigned char* font; + +protected: + void hline(int x0, int x1, int y, int colour); + void vline(int y0, int y1, int x, int colour); + void window (unsigned int x, unsigned int y, unsigned int w, unsigned int h); + void WindowMax (void); + void tft_reset(); + void wr_dat(int value); + void wr_cmd(int value); + void wr_dat_start(); + void wr_dat_stop(); + void wr_dat_only(unsigned short dat); + unsigned short rd_dat(void); + void wr_reg (unsigned char reg, unsigned short val); + unsigned short rd_reg (unsigned char reg); + + unsigned int orientation; + unsigned int char_x; + +}; + +#endif