ili9341_t3dma.h
1 /* 2 ILI9341 SPI driver inspired from the Teensy version of Frank Bösing, 2017 3 */ 4 5 #ifndef _ILI9341_T3DMAH_ 6 #define _ILI9341_T3DMAH_ 7 8 9 #define FLIP_SCREEN 1 10 11 12 #define RGBVAL32(r,g,b) ( (r<<16) | (g<<8) | b ) 13 #define RGBVAL16(r,g,b) ( (((r>>3)&0x1f)<<11) | (((g>>2)&0x3f)<<5) | (((b>>3)&0x1f)<<0) ) 14 #define RGBVAL8(r,g,b) ( (((r>>5)&0x07)<<5) | (((g>>5)&0x07)<<2) | (((b>>6)&0x3)<<0) ) 15 16 17 #define ILI9341_TFTWIDTH 320 18 #define ILI9341_TFTHEIGHT 240 19 #define ILI9341_TFTREALWIDTH 320 20 #define ILI9341_TFTREALHEIGHT 240 21 22 23 #define ILI9341_NOP 0x00 24 #define ILI9341_SWRESET 0x01 25 #define ILI9341_RDDID 0x04 26 #define ILI9341_RDDST 0x09 27 28 #define ILI9341_SLPIN 0x10 29 #define ILI9341_SLPOUT 0x11 30 #define ILI9341_PTLON 0x12 31 #define ILI9341_NORON 0x13 32 33 #define ILI9341_RDMODE 0x0A 34 #define ILI9341_RDMADCTL 0x0B 35 #define ILI9341_RDPIXFMT 0x0C 36 #define ILI9341_RDIMGFMT 0x0D 37 #define ILI9341_RDSELFDIAG 0x0F 38 39 #define ILI9341_INVOFF 0x20 40 #define ILI9341_INVON 0x21 41 #define ILI9341_GAMMASET 0x26 42 #define ILI9341_DISPOFF 0x28 43 #define ILI9341_DISPON 0x29 44 45 #define ILI9341_CASET 0x2A 46 #define ILI9341_PASET 0x2B 47 #define ILI9341_RAMWR 0x2C 48 #define ILI9341_RAMRD 0x2E 49 50 #define ILI9341_PTLAR 0x30 51 #define ILI9341_MADCTL 0x36 52 #define ILI9341_VSCRSADD 0x37 53 #define ILI9341_PIXFMT 0x3A 54 55 #define ILI9341_FRMCTR1 0xB1 56 #define ILI9341_FRMCTR2 0xB2 57 #define ILI9341_FRMCTR3 0xB3 58 #define ILI9341_INVCTR 0xB4 59 #define ILI9341_DFUNCTR 0xB6 60 61 #define ILI9341_PWCTR1 0xC0 62 #define ILI9341_PWCTR2 0xC1 63 #define ILI9341_PWCTR3 0xC2 64 #define ILI9341_PWCTR4 0xC3 65 #define ILI9341_PWCTR5 0xC4 66 #define ILI9341_VMCTR1 0xC5 67 #define ILI9341_VMCTR2 0xC7 68 69 #define ILI9341_RDID1 0xDA 70 #define ILI9341_RDID2 0xDB 71 #define ILI9341_RDID3 0xDC 72 #define ILI9341_RDID4 0xDD 73 74 #define ILI9341_GMCTRP1 0xE0 75 #define ILI9341_GMCTRN1 0xE1 76 77 #define MADCTL_MY 0x80 78 #define MADCTL_MX 0x40 79 #define MADCTL_MV 0x20 80 #define MADCTL_ML 0x10 81 #define MADCTL_RGB 0x00 82 #define MADCTL_BGR 0x08 83 #define MADCTL_MH 0x04 84 85 #ifdef __cplusplus 86 87 88 #define MAX_SPI_TRANS 7 89 #define NR_OF_BLOCK 4 90 #define LINES_PER_BLOCK 64 //(ILI9341_TFTREALHEIGHT/4) 91 92 typedef struct { 93 uint8_t cmd; 94 uint8_t data[16]; 95 uint8_t databytes; //No of data in data; bit 7 = delay after set; 0xFF = end of cmds. 96 } lcd_init_cmd_t; 97 98 99 class ILI9341_t3DMA 100 { 101 public: 102 ILI9341_t3DMA(uint8_t _CS = 17, uint8_t _DC = 18, uint8_t _RST = 255, uint8_t _MOSI=23, uint8_t _CLK=18, uint8_t _MISO=19, uint8_t touch_cs=32, uint8_t touch_irq=33); 103 104 //void setFrameBuffer(uint16_t * fb); 105 //static uint16_t * getFrameBuffer(void); 106 107 void begin(void); 108 void flipscreen(bool flip); 109 bool isflipped(void); 110 void start(void); 111 void refresh(void); 112 void refreshPrepare(void); 113 void refreshFinish(void); 114 //void stop(); 115 //void wait(void); 116 uint16_t * getLineBuffer(int j); 117 118 void fillScreen(uint16_t color); 119 void writeScreen(int width, int height, int stride, uint8_t *buffer, uint16_t *palette16); 120 void writeLine(int width, int height, int stride, uint8_t *buffer, uint16_t *palette16); 121 void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 122 void drawSprite(int16_t x, int16_t y, const uint16_t *bitmap); 123 void drawSprite(int16_t x, int16_t y, const uint16_t *bitmap, uint16_t croparx, uint16_t cropary, uint16_t croparw, uint16_t croparh); 124 void drawText(int16_t x, int16_t y, const char * text, uint16_t fgcolor, uint16_t bgcolor, bool doublesize); 125 126 void fillScreenNoDma(uint16_t color) { fillScreen(color); }; 127 void drawSpriteNoDma(int16_t x, int16_t y, const uint16_t *bitmap) { drawSprite(x,y,bitmap); }; 128 void drawSpriteNoDma(int16_t x, int16_t y, const uint16_t *bitmap, uint16_t croparx, uint16_t cropary, uint16_t croparw, uint16_t croparh) { drawSprite(x,y,bitmap,croparx,cropary,croparw,croparh); }; 129 void drawRectNoDma(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) { drawRect(x,y,w,h,color); }; 130 void drawTextNoDma(int16_t x, int16_t y, const char * text, uint16_t fgcolor, uint16_t bgcolor, bool doublesize) { drawText(x,y,text,fgcolor,bgcolor,doublesize); }; 131 132 /* 133 void writeScreenNoDma(const uint16_t *pcolors); 134 void drawPixel(int16_t x, int16_t y, uint16_t color); 135 uint16_t getPixel(int16_t x, int16_t y); 136 */ 137 138 139 void touchBegin(); 140 void readRo(uint16_t * oX, uint16_t * oY, uint16_t * oZ); 141 bool isTouching(); 142 void readRaw(uint16_t * oX, uint16_t * oY, uint16_t * oZ); 143 void readCal(uint16_t * oX, uint16_t * oY, uint16_t * oZ); 144 void callibrateTouch(uint16_t xMin,uint16_t yMin,uint16_t xMax,uint16_t yMax); 145 146 protected: 147 bool flipped=false; 148 void enableTouchIrq(); 149 }; 150 151 #endif 152 #endif 153