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
SPI_TFT.h@0:cccc5726bdf3, 2011-07-12 (annotated)
- Committer:
- dreschpe
- Date:
- Tue Jul 12 08:27:34 2011 +0000
- Revision:
- 0:cccc5726bdf3
- Child:
- 1:aa3356b16080
0.8
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 0:cccc5726bdf3 | 1 | /* mbed library for 240*320 pixel display TFT based on HX8347D LCD Controller |
dreschpe | 0:cccc5726bdf3 | 2 | * Copyright (c) 2011 Peter Drescher - DC2PD |
dreschpe | 0:cccc5726bdf3 | 3 | * |
dreschpe | 0:cccc5726bdf3 | 4 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
dreschpe | 0:cccc5726bdf3 | 5 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
dreschpe | 0:cccc5726bdf3 | 6 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
dreschpe | 0:cccc5726bdf3 | 7 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
dreschpe | 0:cccc5726bdf3 | 8 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
dreschpe | 0:cccc5726bdf3 | 9 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
dreschpe | 0:cccc5726bdf3 | 10 | * THE SOFTWARE. |
dreschpe | 0:cccc5726bdf3 | 11 | */ |
dreschpe | 0:cccc5726bdf3 | 12 | |
dreschpe | 0:cccc5726bdf3 | 13 | #ifndef MBED_SPI_TFT_H |
dreschpe | 0:cccc5726bdf3 | 14 | #define MBED_SPI_TFT_H |
dreschpe | 0:cccc5726bdf3 | 15 | |
dreschpe | 0:cccc5726bdf3 | 16 | #include "mbed.h" |
dreschpe | 0:cccc5726bdf3 | 17 | #include "GraphicsDisplay.h" |
dreschpe | 0:cccc5726bdf3 | 18 | |
dreschpe | 0:cccc5726bdf3 | 19 | #define RGB(r,g,b) (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) //5 red | 6 green | 5 blue |
dreschpe | 0:cccc5726bdf3 | 20 | |
dreschpe | 0:cccc5726bdf3 | 21 | #define SPI_START (0x70) /* Start byte for SPI transfer */ |
dreschpe | 0:cccc5726bdf3 | 22 | #define SPI_RD (0x01) /* WR bit 1 within start */ |
dreschpe | 0:cccc5726bdf3 | 23 | #define SPI_WR (0x00) /* WR bit 0 within start */ |
dreschpe | 0:cccc5726bdf3 | 24 | #define SPI_DATA (0x02) /* RS bit 1 within start byte */ |
dreschpe | 0:cccc5726bdf3 | 25 | #define SPI_INDEX (0x00) /* RS bit 0 within start byte */ |
dreschpe | 0:cccc5726bdf3 | 26 | |
dreschpe | 0:cccc5726bdf3 | 27 | |
dreschpe | 0:cccc5726bdf3 | 28 | /* some RGB color definitions */ |
dreschpe | 0:cccc5726bdf3 | 29 | #define Black 0x0000 /* 0, 0, 0 */ |
dreschpe | 0:cccc5726bdf3 | 30 | #define Navy 0x000F /* 0, 0, 128 */ |
dreschpe | 0:cccc5726bdf3 | 31 | #define DarkGreen 0x03E0 /* 0, 128, 0 */ |
dreschpe | 0:cccc5726bdf3 | 32 | #define DarkCyan 0x03EF /* 0, 128, 128 */ |
dreschpe | 0:cccc5726bdf3 | 33 | #define Maroon 0x7800 /* 128, 0, 0 */ |
dreschpe | 0:cccc5726bdf3 | 34 | #define Purple 0x780F /* 128, 0, 128 */ |
dreschpe | 0:cccc5726bdf3 | 35 | #define Olive 0x7BE0 /* 128, 128, 0 */ |
dreschpe | 0:cccc5726bdf3 | 36 | #define LightGrey 0xC618 /* 192, 192, 192 */ |
dreschpe | 0:cccc5726bdf3 | 37 | #define DarkGrey 0x7BEF /* 128, 128, 128 */ |
dreschpe | 0:cccc5726bdf3 | 38 | #define Blue 0x001F /* 0, 0, 255 */ |
dreschpe | 0:cccc5726bdf3 | 39 | #define Green 0x07E0 /* 0, 255, 0 */ |
dreschpe | 0:cccc5726bdf3 | 40 | #define Cyan 0x07FF /* 0, 255, 255 */ |
dreschpe | 0:cccc5726bdf3 | 41 | #define Red 0xF800 /* 255, 0, 0 */ |
dreschpe | 0:cccc5726bdf3 | 42 | #define Magenta 0xF81F /* 255, 0, 255 */ |
dreschpe | 0:cccc5726bdf3 | 43 | #define Yellow 0xFFE0 /* 255, 255, 0 */ |
dreschpe | 0:cccc5726bdf3 | 44 | #define White 0xFFFF /* 255, 255, 255 */ |
dreschpe | 0:cccc5726bdf3 | 45 | |
dreschpe | 0:cccc5726bdf3 | 46 | |
dreschpe | 0:cccc5726bdf3 | 47 | |
dreschpe | 0:cccc5726bdf3 | 48 | class SPI_TFT : public GraphicsDisplay { |
dreschpe | 0:cccc5726bdf3 | 49 | public: |
dreschpe | 0:cccc5726bdf3 | 50 | SPI_TFT(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset,const char* name ="TFT"); |
dreschpe | 0:cccc5726bdf3 | 51 | virtual int width(); |
dreschpe | 0:cccc5726bdf3 | 52 | virtual int height(); |
dreschpe | 0:cccc5726bdf3 | 53 | virtual void pixel(int x, int y, int colour); |
dreschpe | 0:cccc5726bdf3 | 54 | void circle(int x, int y, int r, int colour); |
dreschpe | 0:cccc5726bdf3 | 55 | void line(int x0, int y0, int x1, int y1, int colour); |
dreschpe | 0:cccc5726bdf3 | 56 | void rect(int x0, int y0, int x1, int y1, int colour); |
dreschpe | 0:cccc5726bdf3 | 57 | void fillrect(int x0, int y0, int x1, int y1, int colour); |
dreschpe | 0:cccc5726bdf3 | 58 | void locate(int column, int row); |
dreschpe | 0:cccc5726bdf3 | 59 | virtual void cls (void); |
dreschpe | 0:cccc5726bdf3 | 60 | int columns(void); |
dreschpe | 0:cccc5726bdf3 | 61 | int rows(void); |
dreschpe | 0:cccc5726bdf3 | 62 | int _putc(int value); |
dreschpe | 0:cccc5726bdf3 | 63 | virtual void character(int col, int row, int c); |
dreschpe | 0:cccc5726bdf3 | 64 | void Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap); |
dreschpe | 0:cccc5726bdf3 | 65 | void set_font(unsigned char* f); |
dreschpe | 0:cccc5726bdf3 | 66 | void set_orientation(unsigned int o); |
dreschpe | 0:cccc5726bdf3 | 67 | |
dreschpe | 0:cccc5726bdf3 | 68 | SPI _spi; |
dreschpe | 0:cccc5726bdf3 | 69 | DigitalOut _cs; |
dreschpe | 0:cccc5726bdf3 | 70 | DigitalOut _reset; |
dreschpe | 0:cccc5726bdf3 | 71 | unsigned char* font; |
dreschpe | 0:cccc5726bdf3 | 72 | |
dreschpe | 0:cccc5726bdf3 | 73 | protected: |
dreschpe | 0:cccc5726bdf3 | 74 | void hline(int x0, int x1, int y, int colour); |
dreschpe | 0:cccc5726bdf3 | 75 | void vline(int y0, int y1, int x, int colour); |
dreschpe | 0:cccc5726bdf3 | 76 | void window (unsigned int x, unsigned int y, unsigned int w, unsigned int h); |
dreschpe | 0:cccc5726bdf3 | 77 | void WindowMax (void); |
dreschpe | 0:cccc5726bdf3 | 78 | void tft_reset(); |
dreschpe | 0:cccc5726bdf3 | 79 | void wr_dat(int value); |
dreschpe | 0:cccc5726bdf3 | 80 | void wr_cmd(int value); |
dreschpe | 0:cccc5726bdf3 | 81 | void wr_dat_start(); |
dreschpe | 0:cccc5726bdf3 | 82 | void wr_dat_stop(); |
dreschpe | 0:cccc5726bdf3 | 83 | void wr_dat_only(unsigned short dat); |
dreschpe | 0:cccc5726bdf3 | 84 | unsigned short rd_dat(void); |
dreschpe | 0:cccc5726bdf3 | 85 | void wr_reg (unsigned char reg, unsigned short val); |
dreschpe | 0:cccc5726bdf3 | 86 | unsigned short rd_reg (unsigned char reg); |
dreschpe | 0:cccc5726bdf3 | 87 | |
dreschpe | 0:cccc5726bdf3 | 88 | unsigned int orientation; |
dreschpe | 0:cccc5726bdf3 | 89 | unsigned int char_x; |
dreschpe | 0:cccc5726bdf3 | 90 | |
dreschpe | 0:cccc5726bdf3 | 91 | }; |
dreschpe | 0:cccc5726bdf3 | 92 | |
dreschpe | 0:cccc5726bdf3 | 93 | #endif |