hi vadim,
here is what i have right now, works for my ili9341 and almost works for the ili9328/ili9325 (slower and doesnt work in landscape reverse)
with pb8-pb15 as d0-d7
i dont exactly remember what i have modified but it should still run with good performance for the ili9341
i have also added a pushcolors function for displaying sdcard stuff faster
.h
/*
See rights and use declaration in License.h
This library has been modified for the Maple Mini
*/
#ifndef _ADAFRUIT_ILI9341H_
#define _ADAFRUIT_ILI9341H_
#include "Arduino.h"
#include "Print.h"
#include <Adafruit_GFX.h>
#include <avr/pgmspace.h>
#define TFTLCD_DELAY 0xFF
#define ILI9341_TFTWIDTH 240
#define ILI9341_TFTHEIGHT 320
#define ILI9341_NOP 0x00
#define ILI9341_SWRESET 0x01
#define ILI9341_RDDIDIF 0x04
#define ILI9341_RDDID 0xD3
#define ILI9341_RDDST 0x09
#define ILI9341_SLPIN 0x10
#define ILI9341_SLPOUT 0x11
#define ILI9341_PTLON 0x12
#define ILI9341_NORON 0x13
#define ILI9341_RDMODE 0x0A
#define ILI9341_RDMADCTL 0x0B
#define ILI9341_RDPIXFMT 0x0C
#define ILI9341_RDIMGFMT 0x0D
#define ILI9341_RDDSM 0x0E
#define ILI9341_RDSELFDIAG 0x0F
#define ILI9341_INVOFF 0x20
#define ILI9341_INVON 0x21
#define ILI9341_GAMMASET 0x26
#define ILI9341_DISPOFF 0x28
#define ILI9341_DISPON 0x29
#define ILI9341_CASET 0x2A
#define ILI9341_PASET 0x2B
#define ILI9341_RAMWR 0x2C
#define ILI9341_RGBSET 0x2D
#define ILI9341_RAMRD 0x2E
#define ILI9341_PTLAR 0x30
#define ILI9341_VSCRDEF 0x33
#define ILI9341_TEOFF 0x34
#define ILI9341_TEON 0x35
#define ILI9341_MADCTL 0x36
#define ILI9341_VSCRSADD 0x37
#define ILI9341_IDMOFF 0x38
#define ILI9341_IDMON 0x39
#define ILI9341_PIXFMT 0x3A
#define ILI9341_FRMCTR1 0xB1
#define ILI9341_FRMCTR2 0xB2
#define ILI9341_FRMCTR3 0xB3
#define ILI9341_INVCTR 0xB4
#define ILI9341_PRCTR 0xB5
#define ILI9341_DFUNCTR 0xB6
#define ILI9341_ETMOD 0xB7
#define ILI9341_PWCTR1 0xC0
#define ILI9341_PWCTR2 0xC1
#define ILI9341_PWCTR3 0xC2
#define ILI9341_PWCTR4 0xC3
#define ILI9341_PWCTR5 0xC4
#define ILI9341_VMCTR1 0xC5
#define ILI9341_VMCTR2 0xC7
#define ILI9341_PWCTRLA 0xCB
#define ILI9341_PWCTRLB 0xCF
#define ILI9341_RDID1 0xDA
#define ILI9341_RDID2 0xDB
#define ILI9341_RDID3 0xDC
#define ILI9341_RDID4 0xD3
#define ILI9341_GMCTRP1 0xE0
#define ILI9341_GMCTRN1 0xE1
#define ILI9341_DGAMCTRL1 0xE2
#define ILI9341_DGAMCTRL2 0xE3
#define ILI9341_TCTRLA 0xE8
#define ILI9341_TCTRLB 0xEA
#define ILI9341_PWRSEQ 0xED
#define ILI9341_EN3GAM 0xF2
#define ILI9341_IFCTL 0xF6
#define ILI9341_PUMP 0xF7
#define ILI9341_MADCTL_MV BIT(5)
#define ILI9341_MADCTL_MX BIT(6)
#define ILI9341_MADCTL_MY BIT(7)
#define ILI932X_START_OSC 0x00
#define ILI932X_DRIV_OUT_CTRL 0x01
#define ILI932X_DRIV_WAV_CTRL 0x02
#define ILI932X_ENTRY_MOD 0x03
#define ILI932X_RESIZE_CTRL 0x04
#define ILI932X_DISP_CTRL1 0x07
#define ILI932X_DISP_CTRL2 0x08
#define ILI932X_DISP_CTRL3 0x09
#define ILI932X_DISP_CTRL4 0x0A
#define ILI932X_RGB_DISP_IF_CTRL1 0x0C
#define ILI932X_FRM_MARKER_POS 0x0D
#define ILI932X_RGB_DISP_IF_CTRL2 0x0F
#define ILI932X_POW_CTRL1 0x10
#define ILI932X_POW_CTRL2 0x11
#define ILI932X_POW_CTRL3 0x12
#define ILI932X_POW_CTRL4 0x13
#define ILI932X_GRAM_HOR_AD 0x20
#define ILI932X_GRAM_VER_AD 0x21
#define ILI932X_RW_GRAM 0x22
#define ILI932X_POW_CTRL7 0x29
#define ILI932X_FRM_RATE_COL_CTRL 0x2B
#define ILI932X_GAMMA_CTRL1 0x30
#define ILI932X_GAMMA_CTRL2 0x31
#define ILI932X_GAMMA_CTRL3 0x32
#define ILI932X_GAMMA_CTRL4 0x35
#define ILI932X_GAMMA_CTRL5 0x36
#define ILI932X_GAMMA_CTRL6 0x37
#define ILI932X_GAMMA_CTRL7 0x38
#define ILI932X_GAMMA_CTRL8 0x39
#define ILI932X_GAMMA_CTRL9 0x3C
#define ILI932X_GAMMA_CTRL10 0x3D
#define ILI932X_HOR_START_AD 0x50
#define ILI932X_HOR_END_AD 0x51
#define ILI932X_VER_START_AD 0x52
#define ILI932X_VER_END_AD 0x53
#define ILI932X_GATE_SCAN_CTRL1 0x60
#define ILI932X_GATE_SCAN_CTRL2 0x61
#define ILI932X_GATE_SCAN_CTRL3 0x62
#define ILI932X_PART_IMG1_DISP_POS 0x80
#define ILI932X_PART_IMG1_START_AD 0x81
#define ILI932X_PART_IMG1_END_AD 0x82
#define ILI932X_PART_IMG2_DISP_POS 0x83
#define ILI932X_PART_IMG2_START_AD 0x84
#define ILI932X_PART_IMG2_END_AD 0x85
#define ILI932X_PANEL_IF_CTRL1 0x90
#define ILI932X_PANEL_IF_CTRL2 0x92
#define ILI932X_PANEL_IF_CTRL3 0x93
#define ILI932X_PANEL_IF_CTRL4 0x95
#define ILI932X_PANEL_IF_CTRL5 0x97
#define ILI932X_PANEL_IF_CTRL6 0x98
/*
#define ILI9341_PWCTR6 0xFC
*/
// Color definitions
#define ILI9341_BLACK 0x0000 /* 0, 0, 0 */
#define ILI9341_NAVY 0x000F /* 0, 0, 128 */
#define ILI9341_DARKGREEN 0x03E0 /* 0, 128, 0 */
#define ILI9341_DARKCYAN 0x03EF /* 0, 128, 128 */
#define ILI9341_MAROON 0x7800 /* 128, 0, 0 */
#define ILI9341_PURPLE 0x780F /* 128, 0, 128 */
#define ILI9341_OLIVE 0x7BE0 /* 128, 128, 0 */
#define ILI9341_LIGHTGREY 0xC618 /* 192, 192, 192 */
#define ILI9341_DARKGREY 0x7BEF /* 128, 128, 128 */
#define ILI9341_BLUE 0x001F /* 0, 0, 255 */
#define ILI9341_GREEN 0x07E0 /* 0, 255, 0 */
#define ILI9341_CYAN 0x07FF /* 0, 255, 255 */
#define ILI9341_RED 0xF800 /* 255, 0, 0 */
#define ILI9341_MAGENTA 0xF81F /* 255, 0, 255 */
#define ILI9341_YELLOW 0xFFE0 /* 255, 255, 0 */
#define ILI9341_WHITE 0xFFFF /* 255, 255, 255 */
#define ILI9341_ORANGE 0xFD20 /* 255, 165, 0 */
#define ILI9341_GREENYELLOW 0xAFE5 /* 173, 255, 47 */
#define ILI9341_PINK 0xF81F
/*
Define pins and Output Data Registers
*/
//Port data |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 |
//Pin stm32 |PA7|PA6|PA5|PA4|PA3|PA2|PC1|PA0|
//Control pins |RD |WR |RS |CS |RST|
//Pin stm32 |PB4|PB5|PB6|PB7|PB8|
#define TFT_CNTRL GPIOA
#define TFT_DATA GPIOB
#define TFT_RD PA0
#define TFT_WR PA1
#define TFT_RS PA2
#define TFT_CS PA3
#define TFT_RST PA8
#define TFT_RD_MASK digitalPinToBitMask(TFT_RD)
#define TFT_WR_MASK digitalPinToBitMask(TFT_WR)
#define TFT_RS_MASK digitalPinToBitMask(TFT_RS)
#define TFT_CS_MASK digitalPinToBitMask(TFT_CS)
#define RD_ACTIVE TFT_CNTRL->regs->BRR = TFT_RD_MASK
#define RD_IDLE TFT_CNTRL->regs->BSRR = TFT_RD_MASK
#define WR_ACTIVE TFT_CNTRL->regs->BRR = TFT_WR_MASK
#define WR_IDLE TFT_CNTRL->regs->BSRR = TFT_WR_MASK
#define CD_COMMAND TFT_CNTRL->regs->BRR = TFT_RS_MASK
#define CD_DATA TFT_CNTRL->regs->BSRR = TFT_RS_MASK
#define CS_ACTIVE TFT_CNTRL->regs->BRR = TFT_CS_MASK
#define CS_IDLE TFT_CNTRL->regs->BSRR = TFT_CS_MASK
#ifndef RD_STROBE
#define RD_STROBE {RD_ACTIVE; RD_IDLE;}
#endif
#define WR_STROBE { WR_ACTIVE; WR_IDLE; }
#define swap(a, b) { int16_t t = a; a = b; b = t; }
//Set pins to the 8 bit number
#define write8special(c) { TFT_DATA->regs->BSRR = ((~c)<<24) | ((c)<<8); WR_STROBE; }
class Adafruit_ILI9341_8bit_STM : public Adafruit_GFX {
public:
Adafruit_ILI9341_8bit_STM(void);
void begin(void),
begin(uint16_t id),
setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1),
pushColors(uint16_t *data, uint8_t len, boolean first),
pushColors(uint8_t *data, uint8_t len, boolean first),
pushColor(uint16_t color),
fillScreen(uint16_t color),
#if defined (__STM32F1__)
drawLine(int16_t x0, int16_t y0,int16_t x1, int16_t y1, uint16_t color),
#endif
drawPixel(int16_t x, int16_t y, uint16_t color),
drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
uint16_t color),
setRotation(uint8_t r),
write8(uint8_t),
writedata(uint8_t d),
writecommand(uint8_t c),
invertDisplay(boolean i);
uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
/* These are not for current use, 8-bit protocol only! */
//uint8_t readdata(void),
uint8_t readcommand8(uint8_t reg);
uint32_t readID(void);
uint8_t driver;
private:
uint8_t tabcolor;
uint8_t read8(void);
void setReadDataBus(void),
setWriteDataBus(void),
commandList(uint8_t *addr),
flood(uint16_t color, uint32_t len),
writeRegister16(uint16_t a,uint16_t d) ;
#if defined (__STM32F1__)
uint16_t lineBuffer[ILI9341_TFTHEIGHT]; // DMA buffer. 16bit color data per pixel
#endif
};
#endif //endif of the header file