Library ILI9481 320*480 3.5

Working libraries, libraries being ported and related hardware
User avatar
Vnk8
Posts: 12
Joined: Wed Sep 27, 2017 4:57 pm

Re: Library ILI9481 320*480 3.5

Post by Vnk8 » Fri Sep 29, 2017 2:16 pm

the used TFT LCD lib (link?)
ILI9481 320*480 3.5
the used core (Arduino_STM32?)
"generic STM32F103C series"
the used sketch (link?)

Code: Select all

[code]




#include "Adafruit_GFX.h"
//#include "gfxfont.h"



#include "Adafruit_ILI9481_8bit_STM.h"

// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9481_8bit_STM tft = Adafruit_ILI9481_8bit_STM();
// If using the breakout, change pins as desired
//Adafruit_ILI9481_8bit_STM tft = Adafruit_ILI9481_8bit_STM(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);




void setup() {
  
  Serial.begin(115200);
  Serial.println("ILI9481 Test!"); 
  
 
  tft.begin();
  //tft.invertDisplay(true);
  tft.setRotation(3);                                     //Устанавливаем заставку
      tft.fillScreen(ILI9481_BLUE);
      tft.setCursor(10, 10);
      tft.setTextColor(ILI9481_WHITE,ILI9481_BLUE);
      tft.setTextSize(3);
      tft.print("Adafruit_ILI9481_8bit_STM");
      tft.setCursor(10, 50);
      tft.setTextColor(ILI9481_WHITE,ILI9481_BLUE);
      tft.setTextSize(3);
      tft.print("3.2 TFTLCD Shield for Mega           2560");
      tft.setCursor(10, 140);
      tft.setTextColor(ILI9481_WHITE,ILI9481_BLUE);
      tft.setTextSize(7);
      tft.print("TEST");
      //tft.setCursor(170, 170);
      tft.print("ILI9481"); 
      delay(200); 
      tft.setCursor(70, 230);
      tft.setTextColor(ILI9481_WHITE,ILI9481_BLUE);
      tft.setTextSize(5); 
      tft.print("VERSION ");
      tft.print("V1.1");
      tft.setCursor(190, 280);
      tft.print("2017"); 
      delay(30000);
      tft.fillScreen(ILI9481_BLACK); 

}



void loop() {
tft.fillScreen(ILI9481_BLUE);
tft.setCursor(170, 270);
tft.setTextColor(ILI9481_WHITE,ILI9481_BLUE);
      tft.setTextSize(5);
      tft.print("BLUE"); 
delay(3000);
tft.fillScreen(ILI9481_WHITE);
tft.setCursor(170, 270);
tft.setTextColor(ILI9481_WHITE,ILI9481_BLUE);
      tft.setTextSize(5);
      tft.print("WHITE");
delay(3000);
tft.fillScreen(ILI9481_BLACK);
tft.setCursor(170, 270);
tft.setTextColor(ILI9481_WHITE,ILI9481_BLUE);
      tft.setTextSize(5);
      tft.print("BLACK");
delay(3000);
tft.fillScreen(ILI9481_RED);
tft.setCursor(170, 270);
tft.setTextColor(ILI9481_WHITE,ILI9481_BLUE);
      tft.setTextSize(5);
      tft.print("RED");
delay(3000);
tft.fillScreen(ILI9481_ORANGE);
tft.setCursor(170, 270);
tft.setTextColor(ILI9481_WHITE,ILI9481_BLUE);
      tft.setTextSize(5);
      tft.print("ORANGE");
delay(3000);

}

[code]
on which OS are you developing
So far there is a task to make friends STM32 and ILI9481. The further course of developments depends on it.
VLADIMIR

stevestrong
Posts: 1735
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Library ILI9481 320*480 3.5

Post by stevestrong » Fri Sep 29, 2017 3:35 pm

- I cannot find the source code of the TFT library used by you.
- it looks like you are using an 8 bit library for a 16 bit parallel bus driven display. In this case it is normal that you at least one color is missing.
- how (which pins) did you connect the blue pill to the LCD? Photo of the hardware setup?

User avatar
Vnk8
Posts: 12
Joined: Wed Sep 27, 2017 4:57 pm

Re: Library ILI9481 320*480 3.5

Post by Vnk8 » Fri Sep 29, 2017 5:22 pm

how (which pins) did you connect the blue pill to the LCD?

Code: Select all

//Port data |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 |
//Pin stm32 |PA7|PA6|PA5|PA4|PA3|PA2|PA1|PA0|
//Control pins |RD |WR |RS |CS |RST|
//Pin stm32    |PB4|PB5|PB6|PB7|PB8|
#define TFT_RD         PB4
#define TFT_WR         PB5
#define TFT_RS         PB6
#define TFT_CS         PB7
#define TFT_RST        PB8
https://yadi.sk/d/zmwyQLKy3NLE2n
VLADIMIR

stevestrong
Posts: 1735
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Library ILI9481 320*480 3.5

Post by stevestrong » Fri Sep 29, 2017 8:36 pm

You need a 16 bit library.

User avatar
Vnk8
Posts: 12
Joined: Wed Sep 27, 2017 4:57 pm

Re: Library ILI9481 320*480 3.5

Post by Vnk8 » Sat Sep 30, 2017 4:43 am

on your display can not be run on the bus 8-bit ??
VLADIMIR

stevestrong
Posts: 1735
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Library ILI9481 320*480 3.5

Post by stevestrong » Sat Sep 30, 2017 8:29 am

My display, just like yours, has a 16 bit parallel interface.
You have to connect and control all 16 data bits, otherwise it will not work correctly.
My lib is adapted to drive those 16 bits for ILI9341 compatible TFTs.
You have to comment out (disable) this line if you are not using FSMC.

User avatar
Vnk8
Posts: 12
Joined: Wed Sep 27, 2017 4:57 pm

Re: Library ILI9481 320*480 3.5

Post by Vnk8 » Sun Oct 01, 2017 3:30 pm

ok, let's try.
VLADIMIR

User avatar
Vnk8
Posts: 12
Joined: Wed Sep 27, 2017 4:57 pm

Re: Library ILI9481 320*480 3.5

Post by Vnk8 » Sun Oct 01, 2017 6:53 pm

My lib is adapted to drive those 16 bits for ILI9341 compatible TFTs.
You have to comment out (disable) this line if you are not using FSMC.
But unfortunately:

Code: Select all

Arduino: 1.8.4 (Windows 10), Плата:"Generic STM32F103C series, STM32F103CB (20k RAM. 128k Flash), STM32duino bootloader, 72Mhz (Normal), Smallest (default)"

Изменены опции сборки, пересобираем все
In file included from C:\Users\User\Documents\Arduino\libraries\Adafruit_TFTLCD_16bit_STM32-master\src/Adafruit_TFTLCD_16bit_STM32.h:56:0,

                 from C:\Users\User\Documents\Arduino\libraries\Adafruit_TFTLCD_16bit_STM32-master\examples\graphicstest\graphicstest.ino:7:

C:\Users\User\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple/include/libmaple/fsmc.h:47:2: error: #error "FSMC is unavailable on your MCU"

 #error "FSMC is unavailable on your MCU"
VLADIMIR

stevestrong
Posts: 1735
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Library ILI9481 320*480 3.5

Post by stevestrong » Mon Oct 02, 2017 7:09 am

I told you, you have to change line 15: https://github.com/stevstrong/Adafruit_ ... TM32.h#L15
to this:

Code: Select all

//#define USE_FSCM 1 // use FSCM interface instead raw GPIO access
This will force the compiler to use 16 bit parallel bit-banging.

Next, you have to define the GPIO port use for data here: https://github.com/stevstrong/Adafruit_ ... TM32.h#L80
Currently is GPIOC, but you can change it to GPIOB.

Then you have to configure the GPIO port and the pins for control signals starting from here: https://github.com/stevstrong/Adafruit_ ... TM32.h#L92

I confess, I did test it only with FSMC for F4, and not in 16 bit parallel mode, so may have further errors/warnings.

User avatar
Vnk8
Posts: 12
Joined: Wed Sep 27, 2017 4:57 pm

Re: Library ILI9481 320*480 3.5

Post by Vnk8 » Tue Oct 03, 2017 6:35 am

I have corrected the library for your recommendations:

Code: Select all

// IMPORTANT: SEE COMMENTS @ LINE 15 REGARDING SHIELD VS BREAKOUT BOARD USAGE.

// Graphics library by ladyada/adafruit with init code from Rossum
// MIT license

#ifndef _ADAFRUIT_TFTLCD_16BIT_STM32_H_
#define _ADAFRUIT_TFTLCD_16BIT_STM32_H_

    #define PROGMEM
    #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
    #define pgm_read_word(addr) (*(const unsigned short *)(addr))

#include <Adafruit_GFX.h>

//#define USE_FSCM 1 // use FSCM interface instead raw GPIO access

//#define USE_MAPLE_MINI_PINOUT // for use with maple mini

/*****************************************************************************/
// LCD controller chip identifiers
#define ID_932X    0
#define ID_7575    1
#define ID_9341    2
#define ID_HX8357D    3
#define ID_UNKNOWN 0xFF

/*****************************************************************************/
#ifndef TFTWIDTH
  #define TFTWIDTH   320
  #define TFTHEIGHT  480
#endif
// Initialization command tables for different LCD controllers
#define TFTLCD_DELAY 0xFF

// For compatibility with sketches written for older versions of library.
// Color function name was changed to 'color565' for parity with 2.2" LCD
// library.
#define Color565 color565

/*****************************************************************************/
#define	BLACK   0x0000
#define	BLUE    0x001F
#define	RED     0xF800
#define	GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
/*****************************************************************************/
// Define pins and Output Data Registers
/*****************************************************************************/

#ifdef USE_FSCM

// use FSCM peripheral
#include <libmaple/fsmc.h>

 #define CD_COMMAND
 #define CD_DATA
 #define CS_ACTIVE
 #define CS_IDLE
 #define CS_ACTIVE_CD_COMMAND

#define lcdCommand (*fsmcCommand)
#define lcdData    (*fsmcData)

 // set pins to output the 8 bit value
 #define writeCmd(d)    { lcdCommand = d; } //(d&0x00FF); }
 #define writeData(d)	{ lcdData = d; }

 #define WR_STROBE   writeData(color)

#else    

// use normal GPIO access
#include <libmaple/gpio.h>

// Port data bits D0..D16:
#if defined (__STM32F1__)
  #define TFT_DATA_PORT	GPIOA
//#elif defined (__STM32F4__)
 // #define TFT_DATA_PORT	(&GPIOD)
#endif
#define TFT_DATA_IO_PORT	'A'

//Control pins |RD |WR |RS |CS |RST|
#if defined (__STM32F1__)
  #define TFT_CNTRL_PORT	GPIOB
//#elif defined (__STM32F4__)
 // #define TFT_CNTRL_PORT	(&GPIOC)
#endif
#define TFT_CNTRL_IO_PORT	'B'
//#define TFT_RD_BIT		5
#define TFT_RS_BIT		6
#define TFT_WR_BIT		5
#define TFT_CS_BIT		7

#define Port2Pin(port, bit) ((port-'A')*16+bit)

//#define TFT_RD_PIN		Port2Pin(TFT_CNTRL_IO_PORT, TFT_RD_BIT)
#define TFT_WR_PIN		Port2Pin(TFT_CNTRL_IO_PORT, TFT_WR_BIT)
#define TFT_RS_PIN		Port2Pin(TFT_CNTRL_IO_PORT, TFT_RS_BIT)
#define TFT_CS_PIN		Port2Pin(TFT_CNTRL_IO_PORT, TFT_CS_BIT)

	#define RST_ACTIVE	digitalWrite(TFT_RST_PIN, LOW)
	#define RST_IDLE	digitalWrite(TFT_RST_PIN, HIGH)
#if 0 // used TFT does not support RD operation
	#define RD_ACTIVE    digitalWrite(TFT_RD_PIN, LOW)
	#define RD_IDLE      digitalWrite(TFT_RD_PIN, HIGH)
#endif 
#if 0
	// use old definition, standard bit toggling, low speed
	#define WR_ACTIVE    digitalWrite(TFT_WR_PIN, LOW) //
	#define WR_IDLE      digitalWrite(TFT_WR_PIN, HIGH) //
	#define CD_COMMAND   digitalWrite(TFT_RS_PIN, LOW)
	#define CD_DATA      digitalWrite(TFT_RS_PIN, HIGH)
	#define CS_ACTIVE    digitalWrite(TFT_CS_PIN, LOW)
	#define CS_IDLE      digitalWrite(TFT_CS_PIN, HIGH)
	#define CS_ACTIVE_CD_COMMAND	{ CS_ACTIVE; CD_COMMAND; }
#else
	// use fast bit toggling, very fast speed!
extern gpio_reg_map * cntrlRegs;
	#define WR_ACTIVE				gpio_clear_dev_bit(TFT_CNTRL_PORT, TFT_WR_BIT) //digitalWrite(TFT_WR_PIN, LOW)//
	#define WR_IDLE					digitalWrite(TFT_WR_PIN, HIGH)//gpio_set_dev_bit(TFT_CNTRL_PORT, TFT_WR_BIT) //
	#define CD_COMMAND				gpio_clear_dev_bit(TFT_CNTRL_PORT, TFT_RS_BIT) //{ cntrlRegs->BSRRH = BIT(TFT_RS_BIT); } //
	#define CD_DATA					gpio_set_dev_bit(TFT_CNTRL_PORT, TFT_RS_BIT) //{ cntrlRegs->BSRRH = BIT(TFT_RS_BIT); } //
	#define CS_ACTIVE				gpio_clear_dev_bit(TFT_CNTRL_PORT, TFT_CS_BIT) //{ cntrlRegs->BSRRL = BIT(TFT_CS_BIT); } //
	#define CS_IDLE					gpio_set_dev_bit(TFT_CNTRL_PORT, TFT_CS_BIT) //{ cntrlRegs->BSRRH = BIT(TFT_CS_BIT); } //
	#define CS_ACTIVE_CD_COMMAND	{ cntrlRegs->BSRRH = BIT(TFT_CS_BIT)|BIT(TFT_RS_BIT); }
#endif  

#define WR_STROBE { WR_ACTIVE; WR_IDLE; }

extern gpio_reg_map * dataRegs;

#if 0 // used TFT cannot be read
  extern uint8_t read8_(void);
  #define read8(x) ( x = read8_() )
  #define setReadDir() { for (uint8 i = 0; i<16; i++) { pinMode(Port2Pin(TFT_DATA_IO_PORT,0)+i, OUTPUT); } }	// set the bits as input
#endif // used TFT cannot be read
#define setWriteDir() { for (uint8 i = 0; i<16; i++) { pinMode(Port2Pin(TFT_DATA_IO_PORT,0)+i, OUTPUT); } }	// set the bits as output

// set pins to output the 8 bit value
 #define writeData_(d)	{ dataRegs->ODR = d;}
 //#define writeCmd(d)	{ writeData_(d&0x00FF); WR_STROBE; }
 #define writeCmd(d)	{ writeData_(d); WR_STROBE; }
 #define writeData(d)	{ writeData_(d); WR_STROBE; }

#endif // USE_FSCM

#define TFT_RST_PIN		PB8

/*****************************************************************************/

#define swap(a, b) { int16_t t = a; a = b; b = t; }

/*****************************************************************************/
class Adafruit_TFTLCD_16bit_STM32 : public Adafruit_GFX {

 public:

  //Adafruit_TFTLCD_8bit_STM32(uint8_t cs, uint8_t cd, uint8_t wr, uint8_t rd, uint8_t rst);
  Adafruit_TFTLCD_16bit_STM32(void);

  void     begin(uint16_t id = 0x9341);
  void     drawPixel(int16_t x, int16_t y, uint16_t color);
  void     drawFastHLine(int16_t x0, int16_t y0, int16_t w, uint16_t color);
  void     drawFastVLine(int16_t x0, int16_t y0, int16_t h, uint16_t color);
  void     fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t c);
  void     fillScreen(uint16_t color);
  void     reset(void);
  void     setRegisters8(uint8_t *ptr, uint8_t n);
  void     setRegisters16(uint16_t *ptr, uint8_t n);
  void     setRotation(uint8_t x);
       // These methods are public in order for BMP examples to work:
  void     setAddrWindow(int16_t x1, int16_t y1, int16_t x2, int16_t y2);
  void     invertDisplay(boolean i),
			pushColors(uint16_t *data, int16_t len, boolean first),
           drawBitmap(int16_t x, int16_t y, int16_t w, int16_t h, const uint16_t * bitmap);
#if 0 // used TFT cannot be read
  uint16_t readPixel(int16_t x, int16_t y),
           readID(void);
#endif
 private:

  void     init(),
           flood(uint16_t color, uint32_t len);
  uint8_t  driver;
};

extern uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
#if 0 // used TFT cannot be read
extern uint16_t readReg(uint8_t r);
extern uint32_t readReg32(uint8_t r);
#endif

static inline void writeCommand(uint16_t c) __attribute__((always_inline));
static inline void writeCommand(uint16_t c) {
	CS_ACTIVE_CD_COMMAND;
	writeCmd(c);
}

extern void writeRegister8(uint16_t a, uint8_t d);
extern void writeRegister16(uint16_t a, uint16_t d);
//extern void writeRegister24(uint16_t a, uint32_t d);
extern void writeRegister32(uint16_t a, uint32_t d);
//extern void writeRegister32(uint16_t a, uint16_t d1, uint16_t d2);
extern void writeRegisterPair(uint16_t aH, uint16_t aL, uint16_t d);


#endif
But still compile error:

Code: Select all

Arduino: 1.8.4 (Windows 10), Плата:"Generic STM32F103C series, STM32F103CB (20k RAM. 128k Flash), STM32duino bootloader, 72Mhz (Normal), Smallest (default)"

In file included from C:\Users\User\Documents\Arduino\libraries\Adafruit_TFTLCD_16bit_STM32-master\examples\graphicstest\graphicstest.ino:7:0:

C:\Users\User\Documents\Arduino\libraries\Adafruit_TFTLCD_16bit_STM32-master\src/Adafruit_TFTLCD_16bit_STM32.h: In function 'void writeCommand(uint16_t)':

C:\Users\User\Documents\Arduino\libraries\Adafruit_TFTLCD_16bit_STM32-master\src/Adafruit_TFTLCD_16bit_STM32.h:129:44: error: 'gpio_reg_map' has no member named 'BSRRH'

  #define CS_ACTIVE_CD_COMMAND { cntrlRegs->BSRRH = BIT(TFT_CS_BIT)|BIT(TFT_RS_BIT); }

                                            ^

C:\Users\User\Documents\Arduino\libraries\Adafruit_TFTLCD_16bit_STM32-master\src/Adafruit_TFTLCD_16bit_STM32.h:199:2: note: in expansion of macro 'CS_ACTIVE_CD_COMMAND'

  CS_ACTIVE_CD_COMMAND;

  ^

C:\Users\User\Documents\Arduino\libraries\Adafruit_TFTLCD_16bit_STM32-master\src/Adafruit_TFTLCD_16bit_STM32.h:123:68: error: 'gpio_clear_dev_bit' was not declared in this scope

  #define WR_ACTIVE    gpio_clear_dev_bit(TFT_CNTRL_PORT, TFT_WR_BIT) //digitalWrite(TFT_WR_PIN, LOW)//

                                                                    ^

C:\Users\User\Documents\Arduino\libraries\Adafruit_TFTLCD_16bit_STM32-master\src/Adafruit_TFTLCD_16bit_STM32.h:132:21: note: in expansion of macro 'WR_ACTIVE'

 #define WR_STROBE { WR_ACTIVE; WR_IDLE; }

                     ^

C:\Users\User\Documents\Arduino\libraries\Adafruit_TFTLCD_16bit_STM32-master\src/Adafruit_TFTLCD_16bit_STM32.h:146:39: note: in expansion of macro 'WR_STROBE'

  #define writeCmd(d) { writeData_(d); WR_STROBE; }

                                       ^

C:\Users\User\Documents\Arduino\libraries\Adafruit_TFTLCD_16bit_STM32-master\src/Adafruit_TFTLCD_16bit_STM32.h:200:2: note: in expansion of macro 'writeCmd'

  writeCmd(c);

  ^

Несколько библиотек найдено для "Adafruit_GFX.h"
 Используется: C:\Users\User\Documents\Arduino\libraries\Adafruit_GFX
Не используется: C:\Users\User\Documents\Arduino\libraries\Adafruit_GFX_Library
exit status 1
Ошибка компиляции для платы Generic STM32F103C series.
Неверная библиотека найдена в C:\Users\User\Documents\Arduino\libraries\Adafruit_ILI9341_8bit_STM-master: C:\Users\User\Documents\Arduino\libraries\Adafruit_ILI9341_8bit_STM-master
Неверная библиотека найдена в C:\Users\User\Documents\Arduino\libraries\Adafruit_ILI9341_8bit_STM-master: C:\Users\User\Documents\Arduino\libraries\Adafruit_ILI9341_8bit_STM-master

Этот отчёт будет иметь больше информации с
включенной опцией Файл -> Настройки ->
"Показать подробный вывод во время компиляции"
VLADIMIR

Post Reply