notro / fbtft

Linux Framebuffer drivers for small TFT LCD display modules. Development has moved to https://git.kernel.org/cgit/linux/kernel/git/gregkh/staging.git/tree/drivers/staging/fbtft?h=staging-testing
1.86k stars 495 forks source link

ST7789v inverted colors #603

Closed mountainstorm closed 12 months ago

mountainstorm commented 12 months ago

Setup:

I've tried every device overlay and config I can find and the best I have managed to achieve is by using dtoverlay=fbtft,st7789v,reset_pin=23,dc_pin=24,led_pin=18,rotate=270,bgr=1,fps=30,width=320,height=240

This starts the screen as /dev/fb0, I can see the boot messages and seems to work, but the screen is inverted. The "background" is white (not black) and where [OK] should be green it's purple. Try as I might I can't figure out how to change this. Note: bgr appears to have no effect regardless of what I set it to.

startx also just gives be a blank white screen, though I suspect that's related to the fact I only have one /dev/fb entry at the moment

Oh it's also worth noting that any other rotation value seems to give weird results e.g. it's like the width is wrong as the line ending appears a few characters in from the left. I've tried reversing width/height and playing with rotation but the above is still the best config I have yet found

Image attached tempImage387H7o

notro commented 12 months ago

You need to find the initialization sequence that matches your display. This is usually found inside the accompanying example code, which seems to missing here. The display is listed as a MSP2402/MSP2401 and there's a wiki for that: http://www.lcdwiki.com/2.4inch_SPI_Module_ILI9341_SKU:MSP2402 Here it's listed as having a ili9341, but this might have changed in newer batches.

I suggest you contact the seller to get some example code or the init sequence.

Here's the init sequence for the driver you are using: https://elixir.bootlin.com/linux/latest/source/drivers/staging/fbtft/fb_st7789v.c#L143

mountainstorm commented 12 months ago

Is there an example dtoverlay which "just" sets the init sequence which I can crib from when I figure out what it is?

notro commented 12 months ago

See here for writing an overlay that overrides the init sequence: https://github.com/notro/fbtft/wiki/FBTFT-RPI-overlays

mountainstorm commented 12 months ago

hmm, I'm at a loss. If I write an overlay, regardless of how much/little I put in it the config described above stops working i.e. if I have both loaded with dtoverlay=. I've then tried fleshing out my overlay on the basis that I should be able to get it to the same state as the dtoverlay=fbtft,st7789v line (above) i.e. inverted colours, and then work on the init sequence. Unfortunately that doesn't seem to work; and I just get an empty screen with the backlight on.

This (custom.dts) seems like it should work but doesn't; though all the ones I cribbed off also seemed ok and they didn't work either.

I did find this works-but-wrong-res.dts which also kind of works, with this one the colors are good but the resolution is all messed up - probably because that's using the wrong controller (it's the st7735)

Any ideas/pointers to at least get an overlay equivalent of the dtoverlay=fbtft,st7789v line would be greatly appreciated. The data sheet has an invert command so adding that as part of init seems like it should be easy enough once something is working.

custom.dts.txt works-but-wrong-res.dts.txt

mountainstorm commented 12 months ago

oh actually, the overlay here seems to achieve that i.e. everything works except it's inverted. I tried this hours ago but must have had some other config broken, now I've fixed those problems I tweak the pinout and that works https://github.com/darrenliew96/gamepi20_drivers/blob/main/gamepi20.dts

mountainstorm commented 12 months ago

haha, victory. Looking at the data sheet the invert command is 21h and the init sequence there includes 0x1000021; remove that line 5th line in the init sequence and bingo, colors the right way round.

Uploading here for posterity and anyone in the future with this issue gamepi20.dts.txt