ST7789 library fusion

Hi folks,
I've recently discovered an interesting little 240x240 IPS display module based on the ST7789V.

It can be found here...

After hacking out the CS pin, this thing worked well with the ATSAMD21-based Arduino boards and the new Adafruit library. After discovering this library by pantata
which has DMA support for the ATSAMD21 chip I was quite impressed with the drawing speed it can acheive. Unfortunately the pantata lib was written for the ILI9341 controller and therefore contains the wrong init sequence, which leads to incorrect color representations and wrong width and height values. I tried to combine both libraries, first trying to taylor Adafruit's init sequence and the accompanying readout function into the pantata code, but failed. Trying to incorporate the DMA-relevant functions into the Adafruit library also failed.
Does anybody have experience with manipulating DMA-based tft libraries and could possibly helb me out? I can imagine that the solution is not that complicated...
Greetings,
AJ

It should be very straightforward to adapt ILI9341 code.
ST7789 follows the same MIPI compliant user commands.
Manufacturer commands are different. Reading registers is different.

The display appears to be 1.3 inch diagonal. So it is physically smaller than 128x128 ILI9163 displays but higher resolution.

I like SPI displays. If it was 240x320 I would buy one.

David.

Thanks for the reply David. I made some progress with creating a working init sequence for the fast pantata library. Interestingly, many settings were not really needed.

static const uint8_t PROGMEM st7789_init_cmd[] = {
	
	2, ST77XX_COLMOD, 0x55, /* Interface Pixel Format, 16bits/pixel for RGB/MCU interface */
	2, ST_CMD_DELAY,  10,    
	//6, 0xB2, 0x0c, 0x0c, 0x00, 0x33, 0x33,     /* Porch Setting */
	//2, 0xB7, 0x45,     /* Gate Control, Vgh=13.65V, Vgl=-10.43V */
	//2, 0xBB, 0x2B,     /* VCOM Setting, VCOM=1.175V */
	//2, 0xC0, 0x2C,     /* LCM Control, XOR: BGR, MX, MH */
	//3, 0xC2, 0x01, 0xFF,     /* VDV and VRH Command Enable, enable=1 */
	//2, 0xC3, 0x11,     /* VRH Set, Vap=4.4+... */
	//2, 0xC4, 0x20,     /* VDV Set, VDV=0 */
	//3, 0xC6, 0x0F,      /* Frame Rate Control, 60Hz, inversion=0 */
	//2, 0xD0, 0xA4, 0xA1,     /* Power Control 1, AVDD=6.8V, AVCL=-4.8V, VDDS=2.3V */
	//15, 0xE0, 0xD0, 0x00, 0x05, 0x0E, 0x15, 0x0D, 0x37, 0x43, 0x47, 0x09, 0x15, 0x12, 0x16, 0x19,     /* Positive Voltage Gamma Control */
	//15, 0xE1, 0xD0, 0x00, 0x05, 0x0D, 0x0C, 0x06, 0x2D, 0x44, 0x40, 0x0E, 0x1C, 0x18, 0x16, 0x19,     /* Negative Voltage Gamma Control */
	2, ST77XX_MADCTL, 0x08,//(1<<5)|(1<<6),     /* Memory Data Access Control, MX=MV=1, MY=ML=MH=0, RGB=0 */
	5, ST77XX_CASET  , 0x00, ST7789_240x240_XSTART,(240+ST7789_240x240_XSTART) >> 8, (240+ST7789_240x240_XSTART) & 0xFF,  // 15: Column addr set, 4 args, no delay:
                   //     XSTART = 0
                //      XEND = 240
    5, ST77XX_RASET , 0x00,ST7789_240x240_YSTART,(240+ST7789_240x240_YSTART) >> 8, (240+ST7789_240x240_YSTART) & 0xFF,   // 16: Row addr set, 4 args, no delay:
                   //     YSTART = 0
                  //      YEND = 240
    1, ST77XX_INVON ,
	2,  ST_CMD_DELAY,10,
	1, ST77XX_NORON  ,
	2,  ST_CMD_DELAY,10,
	//0x80,0x11,0,     /* Sleep Out */
	//0x80, 0x29, 0,     /* Display On */
	//0xFF, 0, 0
	0
};

Now the fonts are mirrored and red and blue swapped, so I think the library has to be further adapted. I suspect that the setXY() function has to be adapted an probably I'll have to mess with some register settings for scan directions...
The display is really cool and it's interesting to dive deeper into those driver libraries.

I have supported ST7789 on MCUFRIEND_kbv for several years. It is pretty straightforward.

I forked the panata library and attempted to drive an ILI9341 with a 3.3V Uno. The init sequence is not being read from Flash. I fixed that and observed the SPI commands with a Logic Analyser. It all looked fine but the display did not come to life.

I might try it later with an Arduino M0 Pro. Probably with my own timed init sequence.

Do you have it working reliably with an ILI9341?
Providing the initialisation and timing is correct, the ST7789 should work 100% like the ILI9341.

Do you have a fork on GitHub?

David.

At the moment I don''t have an ILI9341 at hand otherwise I'd try it out.

My current state of modification on the pantata library.

Swapping the colors is easy by just setting MADCTL_RGB, also, the font mirroring is easily corrected by removing MADCTL_MX | , however I'm still having address issues with the library, sometimes it just draws all over the place...but the speed is remarkable!

Wondering whether it's easier to just incorporate the DMA SPI into the Adafruit library after all, because it has better GFX functions. It does work well, but I want more speeeeed with the ATSAMD21, that's why I placed this topic inside this subforum...

kauz:
Hi folks,
I've recently discovered an interesting little 240x240 IPS display module based on the ST7789V.

It can be found here...

After hacking out the CS pin, this thing worked well with the ATSAMD21-based Arduino boards and the new Adafruit library. After discovering this library by pantata
which has DMA support for the ATSAMD21 chip I was quite impressed with the drawing speed it can acheive. Unfortunately the pantata lib was written for the ILI9341 controller and therefore contains the wrong init sequence, which leads to incorrect color representations and wrong width and height values. I tried to combine both libraries, first trying to taylor Adafruit's init sequence and the accompanying readout function into the pantata code, but failed. Trying to incorporate the DMA-relevant functions into the Adafruit library also failed.
Does anybody have experience with manipulating DMA-based tft libraries and could possibly helb me out? I can imagine that the solution is not that complicated...
Greetings,
AJ

I just got a couple of these displays and I'm trying to get them to work and have scratching my head re: the CS pin. Looks like you're further ahead, what do you mean by 'hacking out' the CS pin?

Yes, the 240x240 ST7789 display works without CS. But it makes it inconvenient.
I would prefer CS pin instead of the BL pin. Both would be better.

Note that VCC must be 3.3V. There is no LDO regulator on the pcb.
BL can be left n.c. or connect to a GPIO pin.

Because there is no CS pin, the controller only works with SPI mode#3.
If you have CS pin, you can use SPI#0 or SPI#3. And if a SCK pulse is missed the controller will re-sync with CS.

The Adafruit_ST7735_ST7789 library will work with the bit-bang constructor.
If you change the hardware mode to SPI#3 in Adafruit_SPI_Macros.h it will work with hardware SPI.

David.

It's not Adafruit_SPI_Macros.h, it's Adafruit_SPITFT_Macros.h thats located in Arduino IDE library folder in Adafruit_GFX_Library.
In Adafruit_SPITFT_Macros.h you need to replace SPI_MODE0 with this SPI_MODE3 in two paces to get ST7789 to work with hardware SPI.

Took me only two weeks to figure this out.... :smiley: