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

Porting of the ILI9340 Library from Adafruit. It has been tested on a custom board based on a STM32F103C8 microcontroller.

Please, see the Wiki page on how to use the library

Committer:
gmoralis
Date:
Wed Dec 17 07:57:28 2014 +0000
Revision:
2:effcedd42f1b
Parent:
1:5f8309157018
Added glcdfont.c which I forgot to include in the initial release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gmoralis 0:0bf2453a67ba 1 /***************************************************
gmoralis 0:0bf2453a67ba 2 This is an Arduino Library for the Adafruit 2.2" SPI display.
gmoralis 0:0bf2453a67ba 3 This library works with the Adafruit 2.2" TFT Breakout w/SD card
gmoralis 0:0bf2453a67ba 4 ----> http://www.adafruit.com/products/1480
gmoralis 0:0bf2453a67ba 5
gmoralis 0:0bf2453a67ba 6 Check out the links above for our tutorials and wiring diagrams
gmoralis 0:0bf2453a67ba 7 These displays use SPI to communicate, 4 or 5 pins are required to
gmoralis 0:0bf2453a67ba 8 interface (RST is optional)
gmoralis 0:0bf2453a67ba 9 Adafruit invests time and resources providing this open source code,
gmoralis 0:0bf2453a67ba 10 please support Adafruit and open-source hardware by purchasing
gmoralis 0:0bf2453a67ba 11 products from Adafruit!
gmoralis 0:0bf2453a67ba 12
gmoralis 0:0bf2453a67ba 13 Written by Limor Fried/Ladyada for Adafruit Industries.
gmoralis 0:0bf2453a67ba 14 MIT license, all text above must be included in any redistribution
gmoralis 0:0bf2453a67ba 15 ****************************************************/
gmoralis 0:0bf2453a67ba 16
gmoralis 0:0bf2453a67ba 17 // Modified for mbed
gmoralis 0:0bf2453a67ba 18 // by Georgios Moralis
gmoralis 0:0bf2453a67ba 19
gmoralis 0:0bf2453a67ba 20 #ifndef _ADAFRUIT_ILI9340H_
gmoralis 0:0bf2453a67ba 21 #define _ADAFRUIT_ILI9340H_
gmoralis 0:0bf2453a67ba 22
gmoralis 0:0bf2453a67ba 23 #include "mbed.h"
gmoralis 0:0bf2453a67ba 24
gmoralis 0:0bf2453a67ba 25 //#include "core_cm3.h"
gmoralis 0:0bf2453a67ba 26 #include "stdint.h"
gmoralis 0:0bf2453a67ba 27
gmoralis 0:0bf2453a67ba 28 #include "Adafruit_GFX.h"
gmoralis 0:0bf2453a67ba 29
gmoralis 0:0bf2453a67ba 30 #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
gmoralis 0:0bf2453a67ba 31 #define pgm_read_word(addr) (*(const unsigned short *)(addr))
gmoralis 0:0bf2453a67ba 32
gmoralis 0:0bf2453a67ba 33 #define HIGH 0x01
gmoralis 0:0bf2453a67ba 34 #define LOW 0x00
gmoralis 0:0bf2453a67ba 35
gmoralis 0:0bf2453a67ba 36 #define ILI9340_TFTWIDTH 240
gmoralis 0:0bf2453a67ba 37 #define ILI9340_TFTHEIGHT 320
gmoralis 0:0bf2453a67ba 38
gmoralis 0:0bf2453a67ba 39 #define ILI9340_NOP 0x00
gmoralis 0:0bf2453a67ba 40 #define ILI9340_SWRESET 0x01
gmoralis 0:0bf2453a67ba 41 #define ILI9340_RDDID 0x04
gmoralis 0:0bf2453a67ba 42 #define ILI9340_RDDST 0x09
gmoralis 0:0bf2453a67ba 43
gmoralis 0:0bf2453a67ba 44 #define ILI9340_SLPIN 0x10
gmoralis 0:0bf2453a67ba 45 #define ILI9340_SLPOUT 0x11
gmoralis 0:0bf2453a67ba 46 #define ILI9340_PTLON 0x12
gmoralis 0:0bf2453a67ba 47 #define ILI9340_NORON 0x13
gmoralis 0:0bf2453a67ba 48
gmoralis 0:0bf2453a67ba 49 #define ILI9340_RDMODE 0x0A
gmoralis 0:0bf2453a67ba 50 #define ILI9340_RDMADCTL 0x0B
gmoralis 0:0bf2453a67ba 51 #define ILI9340_RDPIXFMT 0x0C
gmoralis 0:0bf2453a67ba 52 #define ILI9340_RDIMGFMT 0x0A
gmoralis 0:0bf2453a67ba 53 #define ILI9340_RDSELFDIAG 0x0F
gmoralis 0:0bf2453a67ba 54
gmoralis 0:0bf2453a67ba 55 #define ILI9340_INVOFF 0x20
gmoralis 0:0bf2453a67ba 56 #define ILI9340_INVON 0x21
gmoralis 0:0bf2453a67ba 57 #define ILI9340_GAMMASET 0x26
gmoralis 0:0bf2453a67ba 58 #define ILI9340_DISPOFF 0x28
gmoralis 0:0bf2453a67ba 59 #define ILI9340_DISPON 0x29
gmoralis 0:0bf2453a67ba 60
gmoralis 0:0bf2453a67ba 61 #define ILI9340_CASET 0x2A
gmoralis 0:0bf2453a67ba 62 #define ILI9340_PASET 0x2B
gmoralis 0:0bf2453a67ba 63 #define ILI9340_RAMWR 0x2C
gmoralis 0:0bf2453a67ba 64 #define ILI9340_RAMRD 0x2E
gmoralis 0:0bf2453a67ba 65
gmoralis 0:0bf2453a67ba 66 #define ILI9340_PTLAR 0x30
gmoralis 0:0bf2453a67ba 67 #define ILI9340_MADCTL 0x36
gmoralis 0:0bf2453a67ba 68
gmoralis 0:0bf2453a67ba 69
gmoralis 0:0bf2453a67ba 70 #define ILI9340_MADCTL_MY 0x80
gmoralis 0:0bf2453a67ba 71 #define ILI9340_MADCTL_MX 0x40
gmoralis 0:0bf2453a67ba 72 #define ILI9340_MADCTL_MV 0x20
gmoralis 0:0bf2453a67ba 73 #define ILI9340_MADCTL_ML 0x10
gmoralis 0:0bf2453a67ba 74 #define ILI9340_MADCTL_RGB 0x00
gmoralis 0:0bf2453a67ba 75 #define ILI9340_MADCTL_BGR 0x08
gmoralis 0:0bf2453a67ba 76 #define ILI9340_MADCTL_MH 0x04
gmoralis 0:0bf2453a67ba 77
gmoralis 0:0bf2453a67ba 78 #define ILI9340_PIXFMT 0x3A
gmoralis 0:0bf2453a67ba 79
gmoralis 0:0bf2453a67ba 80 #define ILI9340_FRMCTR1 0xB1
gmoralis 0:0bf2453a67ba 81 #define ILI9340_FRMCTR2 0xB2
gmoralis 0:0bf2453a67ba 82 #define ILI9340_FRMCTR3 0xB3
gmoralis 0:0bf2453a67ba 83 #define ILI9340_INVCTR 0xB4
gmoralis 0:0bf2453a67ba 84 #define ILI9340_DFUNCTR 0xB6
gmoralis 0:0bf2453a67ba 85
gmoralis 0:0bf2453a67ba 86 #define ILI9340_PWCTR1 0xC0
gmoralis 0:0bf2453a67ba 87 #define ILI9340_PWCTR2 0xC1
gmoralis 0:0bf2453a67ba 88 #define ILI9340_PWCTR3 0xC2
gmoralis 0:0bf2453a67ba 89 #define ILI9340_PWCTR4 0xC3
gmoralis 0:0bf2453a67ba 90 #define ILI9340_PWCTR5 0xC4
gmoralis 0:0bf2453a67ba 91 #define ILI9340_VMCTR1 0xC5
gmoralis 0:0bf2453a67ba 92 #define ILI9340_VMCTR2 0xC7
gmoralis 0:0bf2453a67ba 93
gmoralis 0:0bf2453a67ba 94 #define ILI9340_RDID1 0xDA
gmoralis 0:0bf2453a67ba 95 #define ILI9340_RDID2 0xDB
gmoralis 0:0bf2453a67ba 96 #define ILI9340_RDID3 0xDC
gmoralis 0:0bf2453a67ba 97 #define ILI9340_RDID4 0xDD
gmoralis 0:0bf2453a67ba 98
gmoralis 0:0bf2453a67ba 99 #define ILI9340_GMCTRP1 0xE0
gmoralis 0:0bf2453a67ba 100 #define ILI9340_GMCTRN1 0xE1
gmoralis 0:0bf2453a67ba 101 /*
gmoralis 0:0bf2453a67ba 102 #define ILI9340_PWCTR6 0xFC
gmoralis 0:0bf2453a67ba 103
gmoralis 0:0bf2453a67ba 104 */
gmoralis 0:0bf2453a67ba 105
gmoralis 0:0bf2453a67ba 106 // Color definitions
gmoralis 0:0bf2453a67ba 107 #define ILI9340_BLACK 0x0000
gmoralis 0:0bf2453a67ba 108 #define ILI9340_BLUE 0x001F
gmoralis 0:0bf2453a67ba 109 #define ILI9340_RED 0xF800
gmoralis 0:0bf2453a67ba 110 #define ILI9340_GREEN 0x07E0
gmoralis 0:0bf2453a67ba 111 #define ILI9340_CYAN 0x07FF
gmoralis 0:0bf2453a67ba 112 #define ILI9340_MAGENTA 0xF81F
gmoralis 0:0bf2453a67ba 113 #define ILI9340_YELLOW 0xFFE0
gmoralis 0:0bf2453a67ba 114 #define ILI9340_WHITE 0xFFFF
gmoralis 0:0bf2453a67ba 115
gmoralis 0:0bf2453a67ba 116
gmoralis 0:0bf2453a67ba 117 class Adafruit_ILI9340 : public Adafruit_GFX
gmoralis 0:0bf2453a67ba 118 {
gmoralis 0:0bf2453a67ba 119
gmoralis 0:0bf2453a67ba 120 public:
gmoralis 0:0bf2453a67ba 121
gmoralis 0:0bf2453a67ba 122 Adafruit_ILI9340(SPI *defspi);
gmoralis 0:0bf2453a67ba 123
gmoralis 0:0bf2453a67ba 124 void begin(void),
gmoralis 0:0bf2453a67ba 125 setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1),
gmoralis 0:0bf2453a67ba 126 pushColor(uint16_t color),
gmoralis 0:0bf2453a67ba 127 fillScreen(uint16_t color),
gmoralis 0:0bf2453a67ba 128 drawPixel(int16_t x, int16_t y, uint16_t color),
gmoralis 0:0bf2453a67ba 129 drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
gmoralis 0:0bf2453a67ba 130 drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
gmoralis 1:5f8309157018 131 fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
gmoralis 0:0bf2453a67ba 132 setRotation(uint8_t r),
gmoralis 0:0bf2453a67ba 133 invertDisplay(char i);
gmoralis 0:0bf2453a67ba 134
gmoralis 0:0bf2453a67ba 135 void setMISO(DigitalIn *gport);
gmoralis 0:0bf2453a67ba 136 void setMOSI(DigitalOut *gport);
gmoralis 0:0bf2453a67ba 137 void setCLK(DigitalOut *gport);
gmoralis 0:0bf2453a67ba 138 void setRST(DigitalOut *gport);
gmoralis 0:0bf2453a67ba 139 void setCS(DigitalOut *gport);
gmoralis 0:0bf2453a67ba 140 void setDC(DigitalOut *gport);
gmoralis 0:0bf2453a67ba 141
gmoralis 0:0bf2453a67ba 142 uint16_t Color565(uint8_t r, uint8_t g, uint8_t b);
gmoralis 0:0bf2453a67ba 143
gmoralis 0:0bf2453a67ba 144 /* These are not for current use, 8-bit protocol only! */
gmoralis 0:0bf2453a67ba 145 uint8_t readdata(void),
gmoralis 0:0bf2453a67ba 146 readcommand8(uint8_t);
gmoralis 0:0bf2453a67ba 147 /*
gmoralis 0:0bf2453a67ba 148 uint16_t readcommand16(uint8_t);
gmoralis 0:0bf2453a67ba 149 uint32_t readcommand32(uint8_t);
gmoralis 0:0bf2453a67ba 150 void dummyclock(void);
gmoralis 0:0bf2453a67ba 151 */
gmoralis 0:0bf2453a67ba 152
gmoralis 0:0bf2453a67ba 153 void spiwrite(uint8_t),
gmoralis 0:0bf2453a67ba 154 writecommand(uint8_t c),
gmoralis 0:0bf2453a67ba 155 writedata(uint8_t d),
gmoralis 0:0bf2453a67ba 156 commandList(uint8_t *addr);
gmoralis 0:0bf2453a67ba 157 uint8_t spiread(void);
gmoralis 0:0bf2453a67ba 158
gmoralis 0:0bf2453a67ba 159 private:
gmoralis 0:0bf2453a67ba 160 uint8_t tabcolor;
gmoralis 0:0bf2453a67ba 161
gmoralis 0:0bf2453a67ba 162 SPI *hwSPI;
gmoralis 0:0bf2453a67ba 163 DigitalOut *mosiport, *clkport, *dcport, *rstport, *csport;
gmoralis 0:0bf2453a67ba 164 DigitalIn *misoport;
gmoralis 0:0bf2453a67ba 165 };
gmoralis 0:0bf2453a67ba 166
gmoralis 0:0bf2453a67ba 167 #endif
gmoralis 0:0bf2453a67ba 168