This library can be used to control a low-cost Adafruit 358 TFT display. It has basic functionality but is a starting point for others trying to control this type of display using the FRDM-K64F.
Adafruit_358.h@1:cd3c7c2e2746, 2014-08-07 (annotated)
- Committer:
- bmazzeo
- Date:
- Thu Aug 07 03:17:21 2014 +0000
- Revision:
- 1:cd3c7c2e2746
- Parent:
- 0:7cb96171f886
A few updates to clean up the code before publishing.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bmazzeo | 0:7cb96171f886 | 1 | /* Display library for Adafruit 358 TFT display written for the FRDM-K64F |
bmazzeo | 0:7cb96171f886 | 2 | * |
bmazzeo | 0:7cb96171f886 | 3 | * Copyright (c) 2014 Brian Mazzeo |
bmazzeo | 0:7cb96171f886 | 4 | * Released under the MIT License: http://mbed.org/license/mit |
bmazzeo | 0:7cb96171f886 | 5 | * |
bmazzeo | 0:7cb96171f886 | 6 | * This 1.8" display has 128x160 color pixels |
bmazzeo | 0:7cb96171f886 | 7 | */ |
bmazzeo | 0:7cb96171f886 | 8 | |
bmazzeo | 0:7cb96171f886 | 9 | #ifndef ADAFRUIT_358_H |
bmazzeo | 0:7cb96171f886 | 10 | #define ADAFRUIT_358_H |
bmazzeo | 0:7cb96171f886 | 11 | |
bmazzeo | 0:7cb96171f886 | 12 | #include "mbed.h" |
bmazzeo | 0:7cb96171f886 | 13 | #include "GraphicsDisplay.h" |
bmazzeo | 0:7cb96171f886 | 14 | |
bmazzeo | 0:7cb96171f886 | 15 | // These controls are very useful and retrived from Paul's Adafruit_ST7735.h library |
bmazzeo | 0:7cb96171f886 | 16 | #define ST7735_TFTWIDTH 128 |
bmazzeo | 0:7cb96171f886 | 17 | #define ST7735_TFTHEIGHT 160 |
bmazzeo | 0:7cb96171f886 | 18 | |
bmazzeo | 0:7cb96171f886 | 19 | #define ST7735_NOP 0x00 |
bmazzeo | 0:7cb96171f886 | 20 | #define ST7735_SWRESET 0x01 |
bmazzeo | 0:7cb96171f886 | 21 | #define ST7735_RDDID 0x04 |
bmazzeo | 0:7cb96171f886 | 22 | #define ST7735_RDDST 0x09 |
bmazzeo | 0:7cb96171f886 | 23 | |
bmazzeo | 0:7cb96171f886 | 24 | #define ST7735_SLPIN 0x10 |
bmazzeo | 0:7cb96171f886 | 25 | #define ST7735_SLPOUT 0x11 |
bmazzeo | 0:7cb96171f886 | 26 | #define ST7735_PTLON 0x12 |
bmazzeo | 0:7cb96171f886 | 27 | #define ST7735_NORON 0x13 |
bmazzeo | 0:7cb96171f886 | 28 | |
bmazzeo | 0:7cb96171f886 | 29 | #define ST7735_INVOFF 0x20 |
bmazzeo | 0:7cb96171f886 | 30 | #define ST7735_INVON 0x21 |
bmazzeo | 0:7cb96171f886 | 31 | #define ST7735_DISPOFF 0x28 |
bmazzeo | 0:7cb96171f886 | 32 | #define ST7735_DISPON 0x29 |
bmazzeo | 0:7cb96171f886 | 33 | #define ST7735_CASET 0x2A |
bmazzeo | 0:7cb96171f886 | 34 | #define ST7735_RASET 0x2B |
bmazzeo | 0:7cb96171f886 | 35 | #define ST7735_RAMWR 0x2C |
bmazzeo | 0:7cb96171f886 | 36 | #define ST7735_RAMRD 0x2E |
bmazzeo | 0:7cb96171f886 | 37 | |
bmazzeo | 0:7cb96171f886 | 38 | #define ST7735_PTLAR 0x30 |
bmazzeo | 0:7cb96171f886 | 39 | #define ST7735_COLMOD 0x3A |
bmazzeo | 0:7cb96171f886 | 40 | #define ST7735_MADCTL 0x36 |
bmazzeo | 0:7cb96171f886 | 41 | |
bmazzeo | 0:7cb96171f886 | 42 | #define ST7735_FRMCTR1 0xB1 |
bmazzeo | 0:7cb96171f886 | 43 | #define ST7735_FRMCTR2 0xB2 |
bmazzeo | 0:7cb96171f886 | 44 | #define ST7735_FRMCTR3 0xB3 |
bmazzeo | 0:7cb96171f886 | 45 | #define ST7735_INVCTR 0xB4 |
bmazzeo | 0:7cb96171f886 | 46 | #define ST7735_DISSET5 0xB6 |
bmazzeo | 0:7cb96171f886 | 47 | |
bmazzeo | 0:7cb96171f886 | 48 | #define ST7735_PWCTR1 0xC0 |
bmazzeo | 0:7cb96171f886 | 49 | #define ST7735_PWCTR2 0xC1 |
bmazzeo | 0:7cb96171f886 | 50 | #define ST7735_PWCTR3 0xC2 |
bmazzeo | 0:7cb96171f886 | 51 | #define ST7735_PWCTR4 0xC3 |
bmazzeo | 0:7cb96171f886 | 52 | #define ST7735_PWCTR5 0xC4 |
bmazzeo | 0:7cb96171f886 | 53 | #define ST7735_VMCTR1 0xC5 |
bmazzeo | 0:7cb96171f886 | 54 | |
bmazzeo | 0:7cb96171f886 | 55 | #define ST7735_RDID1 0xDA |
bmazzeo | 0:7cb96171f886 | 56 | #define ST7735_RDID2 0xDB |
bmazzeo | 0:7cb96171f886 | 57 | #define ST7735_RDID3 0xDC |
bmazzeo | 0:7cb96171f886 | 58 | #define ST7735_RDID4 0xDD |
bmazzeo | 0:7cb96171f886 | 59 | |
bmazzeo | 0:7cb96171f886 | 60 | #define ST7735_PWCTR6 0xFC |
bmazzeo | 0:7cb96171f886 | 61 | |
bmazzeo | 0:7cb96171f886 | 62 | #define ST7735_GMCTRP1 0xE0 |
bmazzeo | 0:7cb96171f886 | 63 | #define ST7735_GMCTRN1 0xE1 |
bmazzeo | 0:7cb96171f886 | 64 | |
bmazzeo | 0:7cb96171f886 | 65 | // Color definitions |
bmazzeo | 0:7cb96171f886 | 66 | #define ST7735_BLACK 0x0000 |
bmazzeo | 0:7cb96171f886 | 67 | #define ST7735_GREEN 0x07E0 |
bmazzeo | 0:7cb96171f886 | 68 | #define ST7735_CYAN 0x07FF |
bmazzeo | 0:7cb96171f886 | 69 | #define ST7735_MAGENTA 0xF81F |
bmazzeo | 0:7cb96171f886 | 70 | #define ST7735_WHITE 0xFFFF |
bmazzeo | 0:7cb96171f886 | 71 | #define ST7735_BLUE 0xFFE0 |
bmazzeo | 0:7cb96171f886 | 72 | #define ST7735_RED 0x001F |
bmazzeo | 0:7cb96171f886 | 73 | #define ST7735_YELLOW 0x07FF |
bmazzeo | 0:7cb96171f886 | 74 | |
bmazzeo | 0:7cb96171f886 | 75 | |
bmazzeo | 0:7cb96171f886 | 76 | class Adafruit_358 : public GraphicsDisplay { |
bmazzeo | 0:7cb96171f886 | 77 | public: |
bmazzeo | 0:7cb96171f886 | 78 | |
bmazzeo | 0:7cb96171f886 | 79 | Adafruit_358(PinName MOSI, PinName MISO, PinName SCLK, PinName CS, PinName RESET, PinName DC, const char* name ="TFT"); |
bmazzeo | 0:7cb96171f886 | 80 | |
bmazzeo | 0:7cb96171f886 | 81 | void screen_reset(void); // for ST7735B displays |
bmazzeo | 0:7cb96171f886 | 82 | void wr_cmd(unsigned char cmd); |
bmazzeo | 0:7cb96171f886 | 83 | void fillrect(int x0, int y0, int x1, int y1, uint16_t color); |
bmazzeo | 0:7cb96171f886 | 84 | |
bmazzeo | 0:7cb96171f886 | 85 | virtual int width(void); |
bmazzeo | 0:7cb96171f886 | 86 | virtual int height(void); |
bmazzeo | 0:7cb96171f886 | 87 | virtual void pixel(int x, int y, int color); |
bmazzeo | 0:7cb96171f886 | 88 | |
bmazzeo | 0:7cb96171f886 | 89 | virtual void cls(void); |
bmazzeo | 0:7cb96171f886 | 90 | |
bmazzeo | 0:7cb96171f886 | 91 | void set_font(unsigned char* f); |
bmazzeo | 0:7cb96171f886 | 92 | |
bmazzeo | 0:7cb96171f886 | 93 | SPI _spi; |
bmazzeo | 0:7cb96171f886 | 94 | DigitalOut _cs; |
bmazzeo | 0:7cb96171f886 | 95 | DigitalOut _reset; |
bmazzeo | 0:7cb96171f886 | 96 | DigitalOut _dc; |
bmazzeo | 0:7cb96171f886 | 97 | unsigned char* font; |
bmazzeo | 0:7cb96171f886 | 98 | |
bmazzeo | 0:7cb96171f886 | 99 | private: |
bmazzeo | 0:7cb96171f886 | 100 | |
bmazzeo | 0:7cb96171f886 | 101 | unsigned int char_x; |
bmazzeo | 0:7cb96171f886 | 102 | unsigned int char_y; |
bmazzeo | 0:7cb96171f886 | 103 | |
bmazzeo | 0:7cb96171f886 | 104 | void WindowMax (void); |
bmazzeo | 0:7cb96171f886 | 105 | |
bmazzeo | 0:7cb96171f886 | 106 | }; |
bmazzeo | 0:7cb96171f886 | 107 | |
bmazzeo | 0:7cb96171f886 | 108 | #endif |