pimoroni / st7735-python

Python library to control an ST7735 TFT LCD display. Allows simple drawing on the display without installing a kernel module.
MIT License
58 stars 29 forks source link

Mirrored image #19

Open santisis opened 2 years ago

santisis commented 2 years ago

Deploying the library into a generic ST7735S display I'm obtaining a x-mirrored image.

Reading the ST7735 datasheet I've found that the "MX" (Mirror X-axis) parameter is the 7th bit of the memory access control (MADCTL) which is setting in 0xC8 by the library at init. So, the library is forcing the mirroring in the X-axis.

Is it OK if I made a PR to add a mirror/flip as a new parameter into the constructor of the ST7735 class?

Thanks!

Gadgetoid commented 2 years ago

Sure! Give it a go. I think MX/MY are used in conjunction with each other for a 180 degree rotation IIRC but it's been a while since I've delved into this codebase.

I wonder why ours are not mirrored, though!

santisis commented 2 years ago

Yes!, there are three parameters of interest: MV, MY and MV; the conjunction of the three performs all of the eight combinations of rotation and mirroring.

I'm making tests and it's possible to eliminate the numpy rot90 call by setting the three register bits with a value that depends on the desired rotation+flip.

It needs a bit of retouching on the set_window method because the rotation occurs in the display not in the library.

In my display handling the rotation by the ST7735 needs a bit of touching on the offset parameters, I'm working to handle this automatically.

My effort is put on making a patch that works with backward compatibility.