ILI9340 Library based on the Arduino version from Adafruit. It has been tested with a custom STM32F103C8 board.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Adafruit_ILI9340.h Source File

Adafruit_ILI9340.h

00001 /***************************************************
00002   This is an Arduino Library for the Adafruit 2.2" SPI display.
00003   This library works with the Adafruit 2.2" TFT Breakout w/SD card
00004   ----> http://www.adafruit.com/products/1480
00005 
00006   Check out the links above for our tutorials and wiring diagrams
00007   These displays use SPI to communicate, 4 or 5 pins are required to
00008   interface (RST is optional)
00009   Adafruit invests time and resources providing this open source code,
00010   please support Adafruit and open-source hardware by purchasing
00011   products from Adafruit!
00012 
00013   Written by Limor Fried/Ladyada for Adafruit Industries.
00014   MIT license, all text above must be included in any redistribution
00015  ****************************************************/
00016 
00017 // Modified for mbed
00018 // by Georgios Moralis 
00019 
00020 #ifndef _ADAFRUIT_ILI9340H_
00021 #define _ADAFRUIT_ILI9340H_
00022 
00023 #include "mbed.h"
00024 
00025 //#include "core_cm3.h"
00026 #include "stdint.h"
00027 
00028 #include "Adafruit_GFX.h"
00029 
00030 #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
00031 #define pgm_read_word(addr) (*(const unsigned short *)(addr))
00032 
00033 #define HIGH    0x01
00034 #define LOW     0x00
00035 
00036 #define ILI9340_TFTWIDTH  240
00037 #define ILI9340_TFTHEIGHT 320
00038 
00039 #define ILI9340_NOP     0x00
00040 #define ILI9340_SWRESET 0x01
00041 #define ILI9340_RDDID   0x04
00042 #define ILI9340_RDDST   0x09
00043 
00044 #define ILI9340_SLPIN   0x10
00045 #define ILI9340_SLPOUT  0x11
00046 #define ILI9340_PTLON   0x12
00047 #define ILI9340_NORON   0x13
00048 
00049 #define ILI9340_RDMODE  0x0A
00050 #define ILI9340_RDMADCTL  0x0B
00051 #define ILI9340_RDPIXFMT  0x0C
00052 #define ILI9340_RDIMGFMT  0x0A
00053 #define ILI9340_RDSELFDIAG  0x0F
00054 
00055 #define ILI9340_INVOFF  0x20
00056 #define ILI9340_INVON   0x21
00057 #define ILI9340_GAMMASET 0x26
00058 #define ILI9340_DISPOFF 0x28
00059 #define ILI9340_DISPON  0x29
00060 
00061 #define ILI9340_CASET   0x2A
00062 #define ILI9340_PASET   0x2B
00063 #define ILI9340_RAMWR   0x2C
00064 #define ILI9340_RAMRD   0x2E
00065 
00066 #define ILI9340_PTLAR   0x30
00067 #define ILI9340_MADCTL  0x36
00068 
00069 
00070 #define ILI9340_MADCTL_MY  0x80
00071 #define ILI9340_MADCTL_MX  0x40
00072 #define ILI9340_MADCTL_MV  0x20
00073 #define ILI9340_MADCTL_ML  0x10
00074 #define ILI9340_MADCTL_RGB 0x00
00075 #define ILI9340_MADCTL_BGR 0x08
00076 #define ILI9340_MADCTL_MH  0x04
00077 
00078 #define ILI9340_PIXFMT  0x3A
00079 
00080 #define ILI9340_FRMCTR1 0xB1
00081 #define ILI9340_FRMCTR2 0xB2
00082 #define ILI9340_FRMCTR3 0xB3
00083 #define ILI9340_INVCTR  0xB4
00084 #define ILI9340_DFUNCTR 0xB6
00085 
00086 #define ILI9340_PWCTR1  0xC0
00087 #define ILI9340_PWCTR2  0xC1
00088 #define ILI9340_PWCTR3  0xC2
00089 #define ILI9340_PWCTR4  0xC3
00090 #define ILI9340_PWCTR5  0xC4
00091 #define ILI9340_VMCTR1  0xC5
00092 #define ILI9340_VMCTR2  0xC7
00093 
00094 #define ILI9340_RDID1   0xDA
00095 #define ILI9340_RDID2   0xDB
00096 #define ILI9340_RDID3   0xDC
00097 #define ILI9340_RDID4   0xDD
00098 
00099 #define ILI9340_GMCTRP1 0xE0
00100 #define ILI9340_GMCTRN1 0xE1
00101 /*
00102 #define ILI9340_PWCTR6  0xFC
00103 
00104 */
00105 
00106 // Color definitions
00107 #define ILI9340_BLACK   0x0000
00108 #define ILI9340_BLUE    0x001F
00109 #define ILI9340_RED     0xF800
00110 #define ILI9340_GREEN   0x07E0
00111 #define ILI9340_CYAN    0x07FF
00112 #define ILI9340_MAGENTA 0xF81F
00113 #define ILI9340_YELLOW  0xFFE0
00114 #define ILI9340_WHITE   0xFFFF
00115 
00116 
00117 class Adafruit_ILI9340 : public Adafruit_GFX
00118 {
00119 
00120 public:
00121 
00122     Adafruit_ILI9340(SPI *defspi);
00123 
00124     void     begin(void),
00125              setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1),
00126              pushColor(uint16_t color),
00127              fillScreen(uint16_t color),
00128              drawPixel(int16_t x, int16_t y, uint16_t color),
00129              drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
00130              drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
00131              fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
00132              setRotation(uint8_t r),
00133              invertDisplay(char i);
00134 
00135     void setMISO(DigitalIn *gport);
00136     void setMOSI(DigitalOut *gport);
00137     void setCLK(DigitalOut *gport);
00138     void setRST(DigitalOut *gport);
00139     void setCS(DigitalOut *gport);
00140     void setDC(DigitalOut *gport);
00141 
00142     uint16_t Color565(uint8_t r, uint8_t g, uint8_t b);
00143 
00144     /* These are not for current use, 8-bit protocol only! */
00145     uint8_t  readdata(void),
00146              readcommand8(uint8_t);
00147     /*
00148     uint16_t readcommand16(uint8_t);
00149     uint32_t readcommand32(uint8_t);
00150     void     dummyclock(void);
00151     */
00152 
00153     void    spiwrite(uint8_t),
00154             writecommand(uint8_t c),
00155             writedata(uint8_t d),
00156             commandList(uint8_t *addr);
00157     uint8_t  spiread(void);
00158 
00159 private:
00160     uint8_t  tabcolor;
00161 
00162     SPI *hwSPI;
00163     DigitalOut *mosiport, *clkport, *dcport, *rstport, *csport;
00164     DigitalIn *misoport;
00165 };
00166 
00167 #endif
00168