Chen Huan
/
Final_DongGanPingTai
Tsinghua Icenter ChenHuan
TFT/TFT_ILI9340.h@0:9b8df4f9b792, 2017-03-16 (annotated)
- Committer:
- heroistired
- Date:
- Thu Mar 16 13:07:14 2017 +0000
- Revision:
- 0:9b8df4f9b792
DongGanPingTai
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
heroistired | 0:9b8df4f9b792 | 1 | #ifndef __TFT_ILI9340_H |
heroistired | 0:9b8df4f9b792 | 2 | #define __TFT_ILI9340_H |
heroistired | 0:9b8df4f9b792 | 3 | /*************************************************************** |
heroistired | 0:9b8df4f9b792 | 4 | 功能 : mbed的ILI9340液晶显示芯片的驱动程序与图形库,使用硬件SPI |
heroistired | 0:9b8df4f9b792 | 5 | 作者 : 陈欢 清华大学电机工程与应用电子技术系 |
heroistired | 0:9b8df4f9b792 | 6 | 邮箱 : h-che14@mails.tsinghua.edu.cn OR heroistired@gmail.com |
heroistired | 0:9b8df4f9b792 | 7 | 声明 : |
heroistired | 0:9b8df4f9b792 | 8 | 本程序移植自 https://developer.mbed.org/users/dextorslabs/code/ILI9340_Driver/ |
heroistired | 0:9b8df4f9b792 | 9 | 在原有基础上做了改进与丰富,本程序仅供学习与交流使用,如需他用,须联系作者 |
heroistired | 0:9b8df4f9b792 | 10 | All rights reserved |
heroistired | 0:9b8df4f9b792 | 11 | 2017.1.30 |
heroistired | 0:9b8df4f9b792 | 12 | ***************************************************************/ |
heroistired | 0:9b8df4f9b792 | 13 | |
heroistired | 0:9b8df4f9b792 | 14 | #include "mbed.h" |
heroistired | 0:9b8df4f9b792 | 15 | #include "PinMap.h" |
heroistired | 0:9b8df4f9b792 | 16 | |
heroistired | 0:9b8df4f9b792 | 17 | #define _TFTWIDTH 240 |
heroistired | 0:9b8df4f9b792 | 18 | #define _TFTHEIGHT 320 |
heroistired | 0:9b8df4f9b792 | 19 | |
heroistired | 0:9b8df4f9b792 | 20 | #define ILI9340_NOP 0x00 |
heroistired | 0:9b8df4f9b792 | 21 | #define ILI9340_SWRESET 0x01 |
heroistired | 0:9b8df4f9b792 | 22 | #define ILI9340_RDDID 0x04 |
heroistired | 0:9b8df4f9b792 | 23 | #define ILI9340_RDDST 0x09 |
heroistired | 0:9b8df4f9b792 | 24 | |
heroistired | 0:9b8df4f9b792 | 25 | #define ILI9340_SLPIN 0x10 |
heroistired | 0:9b8df4f9b792 | 26 | #define ILI9340_SLPOUT 0x11 |
heroistired | 0:9b8df4f9b792 | 27 | #define ILI9340_PTLON 0x12 |
heroistired | 0:9b8df4f9b792 | 28 | #define ILI9340_NORON 0x13 |
heroistired | 0:9b8df4f9b792 | 29 | |
heroistired | 0:9b8df4f9b792 | 30 | #define ILI9340_RDMODE 0x0A |
heroistired | 0:9b8df4f9b792 | 31 | #define ILI9340_RDMADCTL 0x0B |
heroistired | 0:9b8df4f9b792 | 32 | #define ILI9340_RDPIXFMT 0x0C |
heroistired | 0:9b8df4f9b792 | 33 | #define ILI9340_RDIMGFMT 0x0A |
heroistired | 0:9b8df4f9b792 | 34 | #define ILI9340_RDSELFDIAG 0x0F |
heroistired | 0:9b8df4f9b792 | 35 | |
heroistired | 0:9b8df4f9b792 | 36 | #define ILI9340_INVOFF 0x20 |
heroistired | 0:9b8df4f9b792 | 37 | #define ILI9340_INVON 0x21 |
heroistired | 0:9b8df4f9b792 | 38 | #define ILI9340_GAMMASET 0x26 |
heroistired | 0:9b8df4f9b792 | 39 | #define ILI9340_DISPOFF 0x28 |
heroistired | 0:9b8df4f9b792 | 40 | #define ILI9340_DISPON 0x29 |
heroistired | 0:9b8df4f9b792 | 41 | |
heroistired | 0:9b8df4f9b792 | 42 | #define ILI9340_CASET 0x2A |
heroistired | 0:9b8df4f9b792 | 43 | #define ILI9340_PASET 0x2B |
heroistired | 0:9b8df4f9b792 | 44 | #define ILI9340_RAMWR 0x2C |
heroistired | 0:9b8df4f9b792 | 45 | #define ILI9340_RAMRD 0x2E |
heroistired | 0:9b8df4f9b792 | 46 | |
heroistired | 0:9b8df4f9b792 | 47 | #define ILI9340_PTLAR 0x30 |
heroistired | 0:9b8df4f9b792 | 48 | #define ILI9340_MADCTL 0x36 |
heroistired | 0:9b8df4f9b792 | 49 | |
heroistired | 0:9b8df4f9b792 | 50 | |
heroistired | 0:9b8df4f9b792 | 51 | #define ILI9340_MADCTL_MY 0x80 |
heroistired | 0:9b8df4f9b792 | 52 | #define ILI9340_MADCTL_MX 0x40 |
heroistired | 0:9b8df4f9b792 | 53 | #define ILI9340_MADCTL_MV 0x20 |
heroistired | 0:9b8df4f9b792 | 54 | #define ILI9340_MADCTL_ML 0x10 |
heroistired | 0:9b8df4f9b792 | 55 | #define ILI9340_MADCTL_RGB 0x00 |
heroistired | 0:9b8df4f9b792 | 56 | #define ILI9340_MADCTL_BGR 0x08 |
heroistired | 0:9b8df4f9b792 | 57 | #define ILI9340_MADCTL_MH 0x04 |
heroistired | 0:9b8df4f9b792 | 58 | |
heroistired | 0:9b8df4f9b792 | 59 | #define ILI9340_PIXFMT 0x3A |
heroistired | 0:9b8df4f9b792 | 60 | |
heroistired | 0:9b8df4f9b792 | 61 | #define ILI9340_FRMCTR1 0xB1 |
heroistired | 0:9b8df4f9b792 | 62 | #define ILI9340_FRMCTR2 0xB2 |
heroistired | 0:9b8df4f9b792 | 63 | #define ILI9340_FRMCTR3 0xB3 |
heroistired | 0:9b8df4f9b792 | 64 | #define ILI9340_INVCTR 0xB4 |
heroistired | 0:9b8df4f9b792 | 65 | #define ILI9340_DFUNCTR 0xB6 |
heroistired | 0:9b8df4f9b792 | 66 | |
heroistired | 0:9b8df4f9b792 | 67 | #define ILI9340_PWCTR1 0xC0 |
heroistired | 0:9b8df4f9b792 | 68 | #define ILI9340_PWCTR2 0xC1 |
heroistired | 0:9b8df4f9b792 | 69 | #define ILI9340_PWCTR3 0xC2 |
heroistired | 0:9b8df4f9b792 | 70 | #define ILI9340_PWCTR4 0xC3 |
heroistired | 0:9b8df4f9b792 | 71 | #define ILI9340_PWCTR5 0xC4 |
heroistired | 0:9b8df4f9b792 | 72 | #define ILI9340_VMCTR1 0xC5 |
heroistired | 0:9b8df4f9b792 | 73 | #define ILI9340_VMCTR2 0xC7 |
heroistired | 0:9b8df4f9b792 | 74 | |
heroistired | 0:9b8df4f9b792 | 75 | #define ILI9340_RDID1 0xDA |
heroistired | 0:9b8df4f9b792 | 76 | #define ILI9340_RDID2 0xDB |
heroistired | 0:9b8df4f9b792 | 77 | #define ILI9340_RDID3 0xDC |
heroistired | 0:9b8df4f9b792 | 78 | #define ILI9340_RDID4 0xDD |
heroistired | 0:9b8df4f9b792 | 79 | |
heroistired | 0:9b8df4f9b792 | 80 | #define ILI9340_GMCTRP1 0xE0 |
heroistired | 0:9b8df4f9b792 | 81 | #define ILI9340_GMCTRN1 0xE1 |
heroistired | 0:9b8df4f9b792 | 82 | /* |
heroistired | 0:9b8df4f9b792 | 83 | #define ILI9340_PWCTR6 0xFC |
heroistired | 0:9b8df4f9b792 | 84 | |
heroistired | 0:9b8df4f9b792 | 85 | */ |
heroistired | 0:9b8df4f9b792 | 86 | |
heroistired | 0:9b8df4f9b792 | 87 | // Color definitions |
heroistired | 0:9b8df4f9b792 | 88 | #define ILI9340_BLACK 0x0000 |
heroistired | 0:9b8df4f9b792 | 89 | #define ILI9340_BLUE 0x001F |
heroistired | 0:9b8df4f9b792 | 90 | #define ILI9340_RED 0xF800 |
heroistired | 0:9b8df4f9b792 | 91 | #define ILI9340_GREEN 0x07E0 |
heroistired | 0:9b8df4f9b792 | 92 | #define ILI9340_CYAN 0x07FF |
heroistired | 0:9b8df4f9b792 | 93 | #define ILI9340_MAGENTA 0xF81F |
heroistired | 0:9b8df4f9b792 | 94 | #define ILI9340_YELLOW 0xFFE0 |
heroistired | 0:9b8df4f9b792 | 95 | #define ILI9340_WHITE 0xFFFF |
heroistired | 0:9b8df4f9b792 | 96 | |
heroistired | 0:9b8df4f9b792 | 97 | |
heroistired | 0:9b8df4f9b792 | 98 | |
heroistired | 0:9b8df4f9b792 | 99 | class ILI9340_Display { |
heroistired | 0:9b8df4f9b792 | 100 | |
heroistired | 0:9b8df4f9b792 | 101 | public: |
heroistired | 0:9b8df4f9b792 | 102 | |
heroistired | 0:9b8df4f9b792 | 103 | uint16_t _height; |
heroistired | 0:9b8df4f9b792 | 104 | uint16_t _width; |
heroistired | 0:9b8df4f9b792 | 105 | |
heroistired | 0:9b8df4f9b792 | 106 | ILI9340_Display(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName rst, PinName dc); |
heroistired | 0:9b8df4f9b792 | 107 | |
heroistired | 0:9b8df4f9b792 | 108 | void DispInit(); |
heroistired | 0:9b8df4f9b792 | 109 | void WriteCommand(uint8_t); |
heroistired | 0:9b8df4f9b792 | 110 | void WriteData(uint8_t); |
heroistired | 0:9b8df4f9b792 | 111 | void SetRotation(uint8_t); |
heroistired | 0:9b8df4f9b792 | 112 | void InvertDisplay(bool); |
heroistired | 0:9b8df4f9b792 | 113 | void SetAddrWindow(uint16_t, uint16_t, uint16_t, uint16_t); |
heroistired | 0:9b8df4f9b792 | 114 | |
heroistired | 0:9b8df4f9b792 | 115 | void DrawPixel(uint16_t, uint16_t, uint16_t); |
heroistired | 0:9b8df4f9b792 | 116 | void FillScreen(uint16_t); |
heroistired | 0:9b8df4f9b792 | 117 | void DrawFastVLine(int16_t, int16_t, int16_t, uint16_t); |
heroistired | 0:9b8df4f9b792 | 118 | void DrawFastHLine(int16_t, int16_t, int16_t, uint16_t); |
heroistired | 0:9b8df4f9b792 | 119 | void FillRect(int16_t, int16_t, int16_t, int16_t, uint16_t); |
heroistired | 0:9b8df4f9b792 | 120 | void DrawRect(int16_t, int16_t, int16_t, int16_t, uint16_t); |
heroistired | 0:9b8df4f9b792 | 121 | void DrawCircle(int16_t, int16_t, int16_t, uint16_t); |
heroistired | 0:9b8df4f9b792 | 122 | void FillCircle(int16_t, int16_t, int16_t, uint16_t); |
heroistired | 0:9b8df4f9b792 | 123 | void FillCircleHelper(int16_t, int16_t, int16_t, uint8_t, int16_t, uint16_t); |
heroistired | 0:9b8df4f9b792 | 124 | void DrawCircleHelper( int16_t, int16_t, int16_t, uint8_t, uint16_t); |
heroistired | 0:9b8df4f9b792 | 125 | void DrawRoundRect(int16_t, int16_t, int16_t, int16_t, int16_t, uint16_t); |
heroistired | 0:9b8df4f9b792 | 126 | void FillRoundRect(int16_t, int16_t, int16_t, int16_t, int16_t, uint16_t); |
heroistired | 0:9b8df4f9b792 | 127 | uint16_t Colour565(uint8_t, uint8_t, uint8_t); |
heroistired | 0:9b8df4f9b792 | 128 | |
heroistired | 0:9b8df4f9b792 | 129 | void DrawAscii(unsigned char, uint16_t, uint16_t, uint16_t, uint16_t); |
heroistired | 0:9b8df4f9b792 | 130 | void DrawString(char *string, uint16_t, uint16_t, uint8_t, uint16_t); |
heroistired | 0:9b8df4f9b792 | 131 | void IntToChars (char*, int, uint8_t, uint8_t, uint16_t, uint16_t, uint8_t, uint16_t); |
heroistired | 0:9b8df4f9b792 | 132 | |
heroistired | 0:9b8df4f9b792 | 133 | void Swap(int16_t*, int16_t*); |
heroistired | 0:9b8df4f9b792 | 134 | void DrawLine(int16_t, int16_t, int16_t, int16_t, uint16_t); |
heroistired | 0:9b8df4f9b792 | 135 | |
heroistired | 0:9b8df4f9b792 | 136 | protected: |
heroistired | 0:9b8df4f9b792 | 137 | SPI spi; // mosi, miso, sclk |
heroistired | 0:9b8df4f9b792 | 138 | DigitalOut cs; |
heroistired | 0:9b8df4f9b792 | 139 | DigitalOut rst; |
heroistired | 0:9b8df4f9b792 | 140 | DigitalOut dc; |
heroistired | 0:9b8df4f9b792 | 141 | |
heroistired | 0:9b8df4f9b792 | 142 | uint8_t orientation; |
heroistired | 0:9b8df4f9b792 | 143 | |
heroistired | 0:9b8df4f9b792 | 144 | }; |
heroistired | 0:9b8df4f9b792 | 145 | #endif |