Adafruit library for our project

Dependents:   ece495_firmware

Fork of Adafruit_ILI9341 by James Kidd

Committer:
bdk9
Date:
Thu Dec 08 20:00:16 2016 +0000
Revision:
3:faeae97c1170
Parent:
2:dd1efb72ee21
Port to f401re

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 */
bdk9 2:dd1efb72ee21 16
bdk9 2:dd1efb72ee21 17 #ifndef ADAFRUIT_ILI9341_H
bdk9 2:dd1efb72ee21 18 #define ADAFRUIT_ILI9341_H
bdk9 2:dd1efb72ee21 19
infotech1 0:16926c5097c9 20 #include <stdint.h>
infotech1 0:16926c5097c9 21 #include <stdbool.h>
infotech1 0:16926c5097c9 22 #include "Adafruit_GFX.h"
infotech1 0:16926c5097c9 23 #include "mbed.h"
infotech1 0:16926c5097c9 24
bdk9 3:faeae97c1170 25 //#include "BurstSPI.h"
infotech1 0:16926c5097c9 26 #define spi_begin()
infotech1 0:16926c5097c9 27 #define spi_end()
infotech1 0:16926c5097c9 28
infotech1 0:16926c5097c9 29 //#defines
infotech1 0:16926c5097c9 30
infotech1 0:16926c5097c9 31 #define LCD_SPI_MODE 0x03
infotech1 0:16926c5097c9 32 #define LCD_SPI_BITS 0x10
infotech1 0:16926c5097c9 33
infotech1 0:16926c5097c9 34 //May need to lower this on certain boards
infotech1 0:16926c5097c9 35 #define LCD_FREQ 6200000
infotech1 0:16926c5097c9 36
infotech1 0:16926c5097c9 37 #define PIN_RST 0x00
infotech1 0:16926c5097c9 38 #define PIN_SCE 0x01
infotech1 0:16926c5097c9 39 #define PIN_DC 0x02
infotech1 0:16926c5097c9 40
infotech1 0:16926c5097c9 41 #define ILI9341_TFTWIDTH 240
infotech1 0:16926c5097c9 42 #define ILI9341_TFTHEIGHT 320
infotech1 0:16926c5097c9 43
infotech1 0:16926c5097c9 44 #define ILI9341_NOP 0x00
infotech1 0:16926c5097c9 45 #define ILI9341_SWRESET 0x01
infotech1 0:16926c5097c9 46 #define ILI9341_RDDID 0x04
infotech1 0:16926c5097c9 47 #define ILI9341_RDDST 0x09
infotech1 0:16926c5097c9 48
infotech1 0:16926c5097c9 49 #define ILI9341_SLPIN 0x10
infotech1 0:16926c5097c9 50 #define ILI9341_SLPOUT 0x11
infotech1 0:16926c5097c9 51 #define ILI9341_PTLON 0x12
infotech1 0:16926c5097c9 52 #define ILI9341_NORON 0x13
infotech1 0:16926c5097c9 53
infotech1 0:16926c5097c9 54 #define ILI9341_RDMODE 0x0A
infotech1 0:16926c5097c9 55 #define ILI9341_RDMADCTL 0x0B
infotech1 0:16926c5097c9 56 #define ILI9341_RDPIXFMT 0x0C
infotech1 0:16926c5097c9 57 #define ILI9341_RDIMGFMT 0x0A
infotech1 0:16926c5097c9 58 #define ILI9341_RDSELFDIAG 0x0F
infotech1 0:16926c5097c9 59
infotech1 0:16926c5097c9 60 #define ILI9341_INVOFF 0x20
infotech1 0:16926c5097c9 61 #define ILI9341_INVON 0x21
infotech1 0:16926c5097c9 62 #define ILI9341_GAMMASET 0x26
infotech1 0:16926c5097c9 63 #define ILI9341_DISPOFF 0x28
infotech1 0:16926c5097c9 64 #define ILI9341_DISPON 0x29
infotech1 0:16926c5097c9 65
infotech1 0:16926c5097c9 66 #define ILI9341_CASET 0x2A
infotech1 0:16926c5097c9 67 #define ILI9341_PASET 0x2B
infotech1 0:16926c5097c9 68 #define ILI9341_RAMWR 0x2C
infotech1 0:16926c5097c9 69 #define ILI9341_RAMRD 0x2E
infotech1 0:16926c5097c9 70
infotech1 0:16926c5097c9 71 #define ILI9341_PTLAR 0x30
infotech1 0:16926c5097c9 72 #define ILI9341_MADCTL 0x36
infotech1 0:16926c5097c9 73 #define ILI9341_PIXFMT 0x3A
infotech1 0:16926c5097c9 74
infotech1 0:16926c5097c9 75 #define ILI9341_FRMCTR1 0xB1
infotech1 0:16926c5097c9 76 #define ILI9341_FRMCTR2 0xB2
infotech1 0:16926c5097c9 77 #define ILI9341_FRMCTR3 0xB3
infotech1 0:16926c5097c9 78 #define ILI9341_INVCTR 0xB4
infotech1 0:16926c5097c9 79 #define ILI9341_DFUNCTR 0xB6
infotech1 0:16926c5097c9 80
infotech1 0:16926c5097c9 81 #define ILI9341_PWCTR1 0xC0
infotech1 0:16926c5097c9 82 #define ILI9341_PWCTR2 0xC1
infotech1 0:16926c5097c9 83 #define ILI9341_PWCTR3 0xC2
infotech1 0:16926c5097c9 84 #define ILI9341_PWCTR4 0xC3
infotech1 0:16926c5097c9 85 #define ILI9341_PWCTR5 0xC4
infotech1 0:16926c5097c9 86 #define ILI9341_VMCTR1 0xC5
infotech1 0:16926c5097c9 87 #define ILI9341_VMCTR2 0xC7
infotech1 0:16926c5097c9 88
infotech1 0:16926c5097c9 89 #define ILI9341_RDID1 0xDA
infotech1 0:16926c5097c9 90 #define ILI9341_RDID2 0xDB
infotech1 0:16926c5097c9 91 #define ILI9341_RDID3 0xDC
infotech1 0:16926c5097c9 92 #define ILI9341_RDID4 0xDD
infotech1 0:16926c5097c9 93
infotech1 0:16926c5097c9 94 #define ILI9341_GMCTRP1 0xE0
infotech1 0:16926c5097c9 95 #define ILI9341_GMCTRN1 0xE1
infotech1 0:16926c5097c9 96 /*
infotech1 0:16926c5097c9 97 #define ILI9341_PWCTR6 0xFC
infotech1 0:16926c5097c9 98 */
infotech1 0:16926c5097c9 99
infotech1 0:16926c5097c9 100 // Color definitions
bdk9 1:cee7cf5065a1 101 #define BLACK 0x0000
bdk9 1:cee7cf5065a1 102 #define BLUE 0x001F
bdk9 1:cee7cf5065a1 103 #define RED 0xF800
bdk9 1:cee7cf5065a1 104 #define GREEN 0x07E0
bdk9 1:cee7cf5065a1 105 #define CYAN 0x07FF
bdk9 1:cee7cf5065a1 106 #define MAGENTA 0xF81F
bdk9 1:cee7cf5065a1 107 #define YELLOW 0xFFE0
bdk9 1:cee7cf5065a1 108 #define WHITE 0xFFFF
infotech1 0:16926c5097c9 109
infotech1 0:16926c5097c9 110 #define DELAY 0x80
infotech1 0:16926c5097c9 111 //structs
infotech1 0:16926c5097c9 112 struct AdaLcdPins
infotech1 0:16926c5097c9 113 {
infotech1 0:16926c5097c9 114 PinName mosi;
infotech1 0:16926c5097c9 115 PinName miso;
infotech1 0:16926c5097c9 116 PinName sclk;
infotech1 0:16926c5097c9 117 PinName dc;
infotech1 0:16926c5097c9 118 PinName cs;
infotech1 0:16926c5097c9 119 PinName rst;
infotech1 0:16926c5097c9 120 };
infotech1 0:16926c5097c9 121
infotech1 0:16926c5097c9 122
infotech1 0:16926c5097c9 123 class Adafruit_ILI9341 : public Adafruit_GFX {
infotech1 0:16926c5097c9 124 public:
infotech1 0:16926c5097c9 125 Adafruit_ILI9341(PinName DC, PinName CS, PinName RST);
infotech1 0:16926c5097c9 126
bdk9 1:cee7cf5065a1 127 void begin(void),
infotech1 0:16926c5097c9 128 setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1),
infotech1 0:16926c5097c9 129 pushColor(uint16_t color),
infotech1 0:16926c5097c9 130 fillScreen(uint16_t color),
infotech1 0:16926c5097c9 131 drawPixel(int16_t x, int16_t y, uint16_t color),
infotech1 0:16926c5097c9 132 drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
infotech1 0:16926c5097c9 133 drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
infotech1 0:16926c5097c9 134 fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
infotech1 0:16926c5097c9 135 uint16_t color),
infotech1 0:16926c5097c9 136 setRotation(uint8_t r),
infotech1 0:16926c5097c9 137 invertDisplay(bool i);
infotech1 0:16926c5097c9 138 uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
infotech1 0:16926c5097c9 139
infotech1 0:16926c5097c9 140 void spiwrite(uint16_t),
infotech1 0:16926c5097c9 141 writecommand(uint8_t c),
infotech1 0:16926c5097c9 142 writedata(uint16_t d),
infotech1 0:16926c5097c9 143 commandList(uint8_t *addr);
infotech1 0:16926c5097c9 144 uint8_t spiread(void);
infotech1 0:16926c5097c9 145
infotech1 0:16926c5097c9 146
infotech1 0:16926c5097c9 147
infotech1 0:16926c5097c9 148 uint8_t readdata(void),
infotech1 0:16926c5097c9 149 readcommand8(uint8_t reg, uint8_t index = 0);
infotech1 0:16926c5097c9 150 // uint8_t readdata(void),
infotech1 0:16926c5097c9 151 // readcommand8(uint8_t reg, uint8_t index = 0);
infotech1 0:16926c5097c9 152
infotech1 0:16926c5097c9 153 private:
infotech1 0:16926c5097c9 154 bool hwSPI;
infotech1 0:16926c5097c9 155 AdaLcdPins _pins;
bdk9 3:faeae97c1170 156 SPI* LcdSPI;
infotech1 0:16926c5097c9 157 DigitalOut** Pins;
infotech1 0:16926c5097c9 158 uint8_t tabcolor;
infotech1 0:16926c5097c9 159 };
bdk9 2:dd1efb72ee21 160
bdk9 2:dd1efb72ee21 161 #endif