V1.1 of the ILI9340 driver for SPI with integrated graphics functions.
Dependents: ILI9340_Driver SDCard_Aitendo_2p2TFT TFT22ok_test_ILI9340_Driver
ILI9340_Driver.h
00001 /*************************************************************** 00002 ILI9340_Driver v1.1 01.06.14 Ian Weston 00003 00004 Driver and integrated graphics library for displays that use the 00005 ILI9340 controller in SPI mode. Such as the Adafruit 2.2" display. 00006 00007 This code has been ported from several sources. The driver section 00008 was completely ported from the Adafruits Arduino source code, and 00009 the graphics functions were ported from the Adafruits GFX library 00010 and some elements were ported from code by Elmicros seeduio port. 00011 00012 Future revisions will include more advanced graphics functions. 00013 00014 ***************************************************************/ 00015 00016 00017 00018 #include "mbed.h" 00019 00020 #ifndef ILI9340_DRIVER_h 00021 #define ILI9340_DRIVER_h 00022 00023 00024 #define _TFTWIDTH 240 00025 #define _TFTHEIGHT 320 00026 00027 #define ILI9340_NOP 0x00 00028 #define ILI9340_SWRESET 0x01 00029 #define ILI9340_RDDID 0x04 00030 #define ILI9340_RDDST 0x09 00031 00032 #define ILI9340_SLPIN 0x10 00033 #define ILI9340_SLPOUT 0x11 00034 #define ILI9340_PTLON 0x12 00035 #define ILI9340_NORON 0x13 00036 00037 #define ILI9340_RDMODE 0x0A 00038 #define ILI9340_RDMADCTL 0x0B 00039 #define ILI9340_RDPIXFMT 0x0C 00040 #define ILI9340_RDIMGFMT 0x0A 00041 #define ILI9340_RDSELFDIAG 0x0F 00042 00043 #define ILI9340_INVOFF 0x20 00044 #define ILI9340_INVON 0x21 00045 #define ILI9340_GAMMASET 0x26 00046 #define ILI9340_DISPOFF 0x28 00047 #define ILI9340_DISPON 0x29 00048 00049 #define ILI9340_CASET 0x2A 00050 #define ILI9340_PASET 0x2B 00051 #define ILI9340_RAMWR 0x2C 00052 #define ILI9340_RAMRD 0x2E 00053 00054 #define ILI9340_PTLAR 0x30 00055 #define ILI9340_MADCTL 0x36 00056 00057 00058 #define ILI9340_MADCTL_MY 0x80 00059 #define ILI9340_MADCTL_MX 0x40 00060 #define ILI9340_MADCTL_MV 0x20 00061 #define ILI9340_MADCTL_ML 0x10 00062 #define ILI9340_MADCTL_RGB 0x00 00063 #define ILI9340_MADCTL_BGR 0x08 00064 #define ILI9340_MADCTL_MH 0x04 00065 00066 #define ILI9340_PIXFMT 0x3A 00067 00068 #define ILI9340_FRMCTR1 0xB1 00069 #define ILI9340_FRMCTR2 0xB2 00070 #define ILI9340_FRMCTR3 0xB3 00071 #define ILI9340_INVCTR 0xB4 00072 #define ILI9340_DFUNCTR 0xB6 00073 00074 #define ILI9340_PWCTR1 0xC0 00075 #define ILI9340_PWCTR2 0xC1 00076 #define ILI9340_PWCTR3 0xC2 00077 #define ILI9340_PWCTR4 0xC3 00078 #define ILI9340_PWCTR5 0xC4 00079 #define ILI9340_VMCTR1 0xC5 00080 #define ILI9340_VMCTR2 0xC7 00081 00082 #define ILI9340_RDID1 0xDA 00083 #define ILI9340_RDID2 0xDB 00084 #define ILI9340_RDID3 0xDC 00085 #define ILI9340_RDID4 0xDD 00086 00087 #define ILI9340_GMCTRP1 0xE0 00088 #define ILI9340_GMCTRN1 0xE1 00089 /* 00090 #define ILI9340_PWCTR6 0xFC 00091 00092 */ 00093 00094 // Color definitions 00095 #define ILI9340_BLACK 0x0000 00096 #define ILI9340_BLUE 0x001F 00097 #define ILI9340_RED 0xF800 00098 #define ILI9340_GREEN 0x07E0 00099 #define ILI9340_CYAN 0x07FF 00100 #define ILI9340_MAGENTA 0xF81F 00101 #define ILI9340_YELLOW 0xFFE0 00102 #define ILI9340_WHITE 0xFFFF 00103 00104 00105 00106 class ILI9340_Display { 00107 00108 public: 00109 00110 uint16_t _height; 00111 uint16_t _width; 00112 00113 ILI9340_Display(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName rst, PinName dc); 00114 00115 void DispInit(); 00116 void WriteCommand(uint8_t); 00117 void WriteData(uint8_t); 00118 void SetRotation(uint8_t); 00119 void InvertDisplay(bool); 00120 void SetAddrWindow(uint16_t, uint16_t, uint16_t, uint16_t); 00121 00122 void DrawPixel(uint16_t, uint16_t, uint16_t); 00123 void FillScreen(uint16_t); 00124 void DrawFastVLine(int16_t, int16_t, int16_t, uint16_t); 00125 void DrawFastHLine(int16_t, int16_t, int16_t, uint16_t); 00126 void FillRect(int16_t, int16_t, int16_t, int16_t, uint16_t); 00127 void DrawRect(int16_t, int16_t, int16_t, int16_t, uint16_t); 00128 void DrawCircle(int16_t, int16_t, int16_t, uint16_t); 00129 void FillCircle(int16_t, int16_t, int16_t, uint16_t); 00130 void FillCircleHelper(int16_t, int16_t, int16_t, uint8_t, int16_t, uint16_t); 00131 void DrawCircleHelper( int16_t, int16_t, int16_t, uint8_t, uint16_t); 00132 void DrawRoundRect(int16_t, int16_t, int16_t, int16_t, int16_t, uint16_t); 00133 void FillRoundRect(int16_t, int16_t, int16_t, int16_t, int16_t, uint16_t); 00134 uint16_t Colour565(uint8_t, uint8_t, uint8_t); 00135 00136 void DrawAscii(unsigned char, uint16_t, uint16_t, uint16_t, uint16_t); 00137 void DrawString(char *string, uint16_t, uint16_t, uint8_t, uint16_t); 00138 void IntToChars (char*, int, uint8_t, uint8_t, uint16_t, uint16_t, uint8_t, uint16_t); 00139 00140 void Swap(int16_t*, int16_t*); 00141 void DrawLine(int16_t, int16_t, int16_t, int16_t, uint16_t); 00142 00143 protected: 00144 SPI spi; // mosi, miso, sclk 00145 DigitalOut cs; 00146 DigitalOut rst; 00147 DigitalOut dc; 00148 00149 uint8_t orientation; 00150 00151 }; 00152 00153 00154 00155 00156 00157 #endif
Generated on Wed Jul 13 2022 11:08:34 by 1.7.2