rsta2 / circle

A C++ bare metal environment for Raspberry Pi with USB (32 and 64 bit)
https://circle-rpi.readthedocs.io
GNU General Public License v3.0
1.84k stars 243 forks source link

Suggestion ST7789 LCD Driver #256

Closed froggestspirit closed 2 years ago

froggestspirit commented 2 years ago

There's a couple open source drivers for screens like the ST7789, which are popular amongst some portable projects. Is there any chance that something like this could be supported in an example?

rsta2 commented 2 years ago

I will work on a ST7789 display driver and sample program after preparing Circle release 44.2, which will come soon. Thanks for the suggestion.

froggestspirit commented 2 years ago

Thank you! In the meantime, I took a stab at it myself, by modifying the 23-spisimple example. I didn't get it working, (I'd imagine I missed some steps since I'm a bit new to writing SPI stuff). If it helps at all, I've attached the modified example. Tested on Raspberry pi Zero (Had the screen working before with a full linux setup, so I know the hardware is ok) 23-spisimple_ST7789.zip

Edit: the "Wake" and "Sleep" pins can be ignored, my setup has a specific wiring for an attiny chip to controll the backlight levels

rsta2 commented 2 years ago

Thanks for the source code, I will check this after preparing the Circle release.

rsta2 commented 2 years ago

After the following modifications to your code my (new) ST7789 display is on and shows some random pixels at least:

for(int i = 0; i < TEST_DATA_LENGTH; i++){
    CTimer::SimpleMsDelay(TxData[i] & 0xFE);
    pDC.Write(TxData[i++] & 1);             // swapped
    m_SPIMaster.Write(SPI_CHIP_SELECT, (TxData + i), 1);    // swapped
}

Unfortunately setting specific pixels does not work yet with your code, but perhaps with the display showing something, you can sort out this. The whole display initialization is a bit error-prone and I found some code, which does different things here, but I'm not familiar with ST7789 displays yet, so I cannot say, what is right and what is wrong. After porting this code, I can also set pixels, but my code has currently not the quality to release it. I'm still working on it.

froggestspirit commented 2 years ago

Thanks!! I can try working with that later. I think it initializes with random pixels, so it sounds like a step in the right direction!

On Fri, Oct 29, 2021, 12:22 AM Rene Stange @.***> wrote:

After the following modifications to your code my (new) ST7789 display is on and shows some random pixels at least:

  • Define SPI_CPOL as 1, not 0.
  • Remove the CGPIOPin pCE0, pCE1 and pCE2, because they are already handled by the SPI master driver (but are not connected to my display).
  • Add pReset.Write(1) before the first CTimer::SimpleMsDelay(200).
  • The for() loop must look like that:

for(int i = 0; i < TEST_DATA_LENGTH; i++){ CTimer::SimpleMsDelay(TxData[i] & 0xFE); pDC.Write(TxData[i++] & 1); // swapped m_SPIMaster.Write(SPI_CHIP_SELECT, (TxData + i), 1); // swapped }

Unfortunately setting specific pixels does not work yet with your code, but perhaps with the display showing something, you can sort out this. The whole display initialization is a bit error-prone and I found some code https://github.com/pimoroni/st7789-python/blob/master/library/ST7789/__init__.py#L204, which does different things here, but I'm not familiar with ST7789 displays yet, so I cannot say, what is right and what is wrong. After porting this code, I can also set pixels, but my code has currently not the quality to release it. I'm still working on it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rsta2/circle/issues/256#issuecomment-954418559, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2OD37UDROY6TUKZUD7JO3UJIVRLANCNFSM5GSL7JZA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

rsta2 commented 2 years ago

There is a new driver for ST7789-based displays and a sample program in addon/display on the st7789-display branch. It is working well here.

froggestspirit commented 2 years ago

Thank you!! I'll check this one out!

On Sat, Oct 30, 2021, 2:00 PM Rene Stange @.***> wrote:

There is a new driver for ST7789-based displays and a sample program in addon/display https://github.com/rsta2/circle/tree/st7789-display/addon/display on the st7789-display branch. It is working well here.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rsta2/circle/issues/256#issuecomment-955570391, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2OD355CPQHEEKLY2Z65P3UJQ6E3ANCNFSM5GSL7JZA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

froggestspirit commented 2 years ago

I finally got around to testing this, and it works great on one of my displays! I had to use reset pin 27 and DC pin 25. My other setup with the ATTiny controlling the backlight wasn't displaying, but I'm pretty sure that's just me forgetting what pins I had to toggle to have the ATTiny turn it on. Thanks again!!!

rsta2 commented 2 years ago

Thanks for the info, that the driver is working for you. That's valuable feedback. I will merge the ST7789 support to the develop branch soon, so it will be part of the next release.

rsta2 commented 2 years ago

The ST7789 display support is on the develop branch now. The st7789-display branch has been deleted.

rsta2 commented 2 years ago

The ST7789 support has been released with Circle 44.3, so this can be closed.

incanus commented 2 years ago

I'm curious where you want to draw the line on addons like this. I have written drivers for the ILI9341 and SH1106 displays as well using Circle and could clean them up and contribute.

rsta2 commented 2 years ago

It would be great to have drivers for more displays for Circle. So if you want to contribute your drivers, you are invited to do so. Please branch off from the develop branch, add the display drivers to addon/display/ and send a Pull Request. Unfortunately I do not have ILI9341- and SH1106-based displays, so I won't be able to test your code with Circle. That's why you have to do this carefully.

probonopd commented 2 years ago

Many 3D printers come with variations of this display and rotary encoder combination using a ST7920 chip. I think it would be very useful to have it supported in Circle, because these are widely available at good prices.

rsta2 commented 2 years ago

@probonopd Yes, a driver for this device in Circle would be great. Unfortunately I do not have this device, so I cannot test this and hence I cannot implement it. Perhaps somebody else, who owns this device, can deal with this?