Port of the Adafruit_ILI9341 library for MBED. Depends on BurstSPI. fillRect, drawFastVLine, drawFastHLine are optimized to use BurstSPI fastwrites and perform a clearRX afterwards. MIT license Due to 600 character limit please find complete license/Adafruit header in license.txt Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! http://www.adafruit.com Original written by Limor Fried/Ladyada for Adafruit Industries.

Dependents:   ili9341_test

Committer:
infotech1
Date:
Fri Dec 05 06:42:42 2014 +0000
Revision:
0:16926c5097c9
Initial commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
infotech1 0:16926c5097c9 1 /***************************************************
infotech1 0:16926c5097c9 2 This is our GFX example for the Adafruit ILI9341 Breakout and Shield
infotech1 0:16926c5097c9 3 ----> http://www.adafruit.com/products/1651
infotech1 0:16926c5097c9 4 Check out the links above for our tutorials and wiring diagrams
infotech1 0:16926c5097c9 5 These displays use SPI to communicate, 4 or 5 pins are required to
infotech1 0:16926c5097c9 6 interface (RST is optional)
infotech1 0:16926c5097c9 7 Adafruit invests time and resources providing this open source code,
infotech1 0:16926c5097c9 8 please support Adafruit and open-source hardware by purchasing
infotech1 0:16926c5097c9 9 products from Adafruit!
infotech1 0:16926c5097c9 10 Written by Limor Fried/Ladyada for Adafruit Industries.
infotech1 0:16926c5097c9 11 MIT license, all text above must be included in any redistribution
infotech1 0:16926c5097c9 12 ****************************************************/
infotech1 0:16926c5097c9 13 /*
infotech1 0:16926c5097c9 14 Ported to mbed by James Kidd
infotech1 0:16926c5097c9 15 */
infotech1 0:16926c5097c9 16 #include <stdint.h>
infotech1 0:16926c5097c9 17 #include <stdbool.h>
infotech1 0:16926c5097c9 18 #include "Adafruit_GFX.h"
infotech1 0:16926c5097c9 19 #include "mbed.h"
infotech1 0:16926c5097c9 20
infotech1 0:16926c5097c9 21 #include "BurstSPI.h"
infotech1 0:16926c5097c9 22 #define spi_begin()
infotech1 0:16926c5097c9 23 #define spi_end()
infotech1 0:16926c5097c9 24
infotech1 0:16926c5097c9 25 //#defines
infotech1 0:16926c5097c9 26
infotech1 0:16926c5097c9 27 #define LCD_SPI_MODE 0x03
infotech1 0:16926c5097c9 28 #define LCD_SPI_BITS 0x10
infotech1 0:16926c5097c9 29
infotech1 0:16926c5097c9 30 //May need to lower this on certain boards
infotech1 0:16926c5097c9 31 #define LCD_FREQ 6200000
infotech1 0:16926c5097c9 32
infotech1 0:16926c5097c9 33 #define PIN_RST 0x00
infotech1 0:16926c5097c9 34 #define PIN_SCE 0x01
infotech1 0:16926c5097c9 35 #define PIN_DC 0x02
infotech1 0:16926c5097c9 36
infotech1 0:16926c5097c9 37 #define ILI9341_TFTWIDTH 240
infotech1 0:16926c5097c9 38 #define ILI9341_TFTHEIGHT 320
infotech1 0:16926c5097c9 39
infotech1 0:16926c5097c9 40 #define ILI9341_NOP 0x00
infotech1 0:16926c5097c9 41 #define ILI9341_SWRESET 0x01
infotech1 0:16926c5097c9 42 #define ILI9341_RDDID 0x04
infotech1 0:16926c5097c9 43 #define ILI9341_RDDST 0x09
infotech1 0:16926c5097c9 44
infotech1 0:16926c5097c9 45 #define ILI9341_SLPIN 0x10
infotech1 0:16926c5097c9 46 #define ILI9341_SLPOUT 0x11
infotech1 0:16926c5097c9 47 #define ILI9341_PTLON 0x12
infotech1 0:16926c5097c9 48 #define ILI9341_NORON 0x13
infotech1 0:16926c5097c9 49
infotech1 0:16926c5097c9 50 #define ILI9341_RDMODE 0x0A
infotech1 0:16926c5097c9 51 #define ILI9341_RDMADCTL 0x0B
infotech1 0:16926c5097c9 52 #define ILI9341_RDPIXFMT 0x0C
infotech1 0:16926c5097c9 53 #define ILI9341_RDIMGFMT 0x0A
infotech1 0:16926c5097c9 54 #define ILI9341_RDSELFDIAG 0x0F
infotech1 0:16926c5097c9 55
infotech1 0:16926c5097c9 56 #define ILI9341_INVOFF 0x20
infotech1 0:16926c5097c9 57 #define ILI9341_INVON 0x21
infotech1 0:16926c5097c9 58 #define ILI9341_GAMMASET 0x26
infotech1 0:16926c5097c9 59 #define ILI9341_DISPOFF 0x28
infotech1 0:16926c5097c9 60 #define ILI9341_DISPON 0x29
infotech1 0:16926c5097c9 61
infotech1 0:16926c5097c9 62 #define ILI9341_CASET 0x2A
infotech1 0:16926c5097c9 63 #define ILI9341_PASET 0x2B
infotech1 0:16926c5097c9 64 #define ILI9341_RAMWR 0x2C
infotech1 0:16926c5097c9 65 #define ILI9341_RAMRD 0x2E
infotech1 0:16926c5097c9 66
infotech1 0:16926c5097c9 67 #define ILI9341_PTLAR 0x30
infotech1 0:16926c5097c9 68 #define ILI9341_MADCTL 0x36
infotech1 0:16926c5097c9 69 #define ILI9341_PIXFMT 0x3A
infotech1 0:16926c5097c9 70
infotech1 0:16926c5097c9 71 #define ILI9341_FRMCTR1 0xB1
infotech1 0:16926c5097c9 72 #define ILI9341_FRMCTR2 0xB2
infotech1 0:16926c5097c9 73 #define ILI9341_FRMCTR3 0xB3
infotech1 0:16926c5097c9 74 #define ILI9341_INVCTR 0xB4
infotech1 0:16926c5097c9 75 #define ILI9341_DFUNCTR 0xB6
infotech1 0:16926c5097c9 76
infotech1 0:16926c5097c9 77 #define ILI9341_PWCTR1 0xC0
infotech1 0:16926c5097c9 78 #define ILI9341_PWCTR2 0xC1
infotech1 0:16926c5097c9 79 #define ILI9341_PWCTR3 0xC2
infotech1 0:16926c5097c9 80 #define ILI9341_PWCTR4 0xC3
infotech1 0:16926c5097c9 81 #define ILI9341_PWCTR5 0xC4
infotech1 0:16926c5097c9 82 #define ILI9341_VMCTR1 0xC5
infotech1 0:16926c5097c9 83 #define ILI9341_VMCTR2 0xC7
infotech1 0:16926c5097c9 84
infotech1 0:16926c5097c9 85 #define ILI9341_RDID1 0xDA
infotech1 0:16926c5097c9 86 #define ILI9341_RDID2 0xDB
infotech1 0:16926c5097c9 87 #define ILI9341_RDID3 0xDC
infotech1 0:16926c5097c9 88 #define ILI9341_RDID4 0xDD
infotech1 0:16926c5097c9 89
infotech1 0:16926c5097c9 90 #define ILI9341_GMCTRP1 0xE0
infotech1 0:16926c5097c9 91 #define ILI9341_GMCTRN1 0xE1
infotech1 0:16926c5097c9 92 /*
infotech1 0:16926c5097c9 93 #define ILI9341_PWCTR6 0xFC
infotech1 0:16926c5097c9 94 */
infotech1 0:16926c5097c9 95
infotech1 0:16926c5097c9 96 // Color definitions
infotech1 0:16926c5097c9 97 #define ILI9341_BLACK 0x0000
infotech1 0:16926c5097c9 98 #define ILI9341_BLUE 0x001F
infotech1 0:16926c5097c9 99 #define ILI9341_RED 0xF800
infotech1 0:16926c5097c9 100 #define ILI9341_GREEN 0x07E0
infotech1 0:16926c5097c9 101 #define ILI9341_CYAN 0x07FF
infotech1 0:16926c5097c9 102 #define ILI9341_MAGENTA 0xF81F
infotech1 0:16926c5097c9 103 #define ILI9341_YELLOW 0xFFE0
infotech1 0:16926c5097c9 104 #define ILI9341_WHITE 0xFFFF
infotech1 0:16926c5097c9 105
infotech1 0:16926c5097c9 106 #define DELAY 0x80
infotech1 0:16926c5097c9 107 //structs
infotech1 0:16926c5097c9 108 struct AdaLcdPins
infotech1 0:16926c5097c9 109 {
infotech1 0:16926c5097c9 110 PinName mosi;
infotech1 0:16926c5097c9 111 PinName miso;
infotech1 0:16926c5097c9 112 PinName sclk;
infotech1 0:16926c5097c9 113 PinName dc;
infotech1 0:16926c5097c9 114 PinName cs;
infotech1 0:16926c5097c9 115 PinName rst;
infotech1 0:16926c5097c9 116 };
infotech1 0:16926c5097c9 117
infotech1 0:16926c5097c9 118
infotech1 0:16926c5097c9 119 class Adafruit_ILI9341 : public Adafruit_GFX {
infotech1 0:16926c5097c9 120 public:
infotech1 0:16926c5097c9 121 Adafruit_ILI9341(PinName DC, PinName CS, PinName RST);
infotech1 0:16926c5097c9 122
infotech1 0:16926c5097c9 123 void begin(void),
infotech1 0:16926c5097c9 124 setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1),
infotech1 0:16926c5097c9 125 pushColor(uint16_t color),
infotech1 0:16926c5097c9 126 fillScreen(uint16_t color),
infotech1 0:16926c5097c9 127 drawPixel(int16_t x, int16_t y, uint16_t color),
infotech1 0:16926c5097c9 128 drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
infotech1 0:16926c5097c9 129 drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
infotech1 0:16926c5097c9 130 fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
infotech1 0:16926c5097c9 131 uint16_t color),
infotech1 0:16926c5097c9 132 setRotation(uint8_t r),
infotech1 0:16926c5097c9 133 invertDisplay(bool i);
infotech1 0:16926c5097c9 134 uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
infotech1 0:16926c5097c9 135
infotech1 0:16926c5097c9 136 void spiwrite(uint16_t),
infotech1 0:16926c5097c9 137 writecommand(uint8_t c),
infotech1 0:16926c5097c9 138 writedata(uint16_t d),
infotech1 0:16926c5097c9 139 commandList(uint8_t *addr);
infotech1 0:16926c5097c9 140 uint8_t spiread(void);
infotech1 0:16926c5097c9 141
infotech1 0:16926c5097c9 142
infotech1 0:16926c5097c9 143
infotech1 0:16926c5097c9 144 uint8_t readdata(void),
infotech1 0:16926c5097c9 145 readcommand8(uint8_t reg, uint8_t index = 0);
infotech1 0:16926c5097c9 146 // uint8_t readdata(void),
infotech1 0:16926c5097c9 147 // readcommand8(uint8_t reg, uint8_t index = 0);
infotech1 0:16926c5097c9 148
infotech1 0:16926c5097c9 149 private:
infotech1 0:16926c5097c9 150 bool hwSPI;
infotech1 0:16926c5097c9 151 AdaLcdPins _pins;
infotech1 0:16926c5097c9 152 BurstSPI* LcdSPI;
infotech1 0:16926c5097c9 153 DigitalOut** Pins;
infotech1 0:16926c5097c9 154 uint8_t tabcolor;
infotech1 0:16926c5097c9 155 };