lexus2k / lcdgfx

Driver for LCD displays running on Arduino/Avr/ESP32/Linux (including Rasperry) platforms
MIT License
356 stars 51 forks source link

Add support for Raspberry Pi Pico - Pull Request #116

Open simon-77 opened 2 months ago

simon-77 commented 2 months ago

The library lcdgfx has a long list of supported platforms, but it still lacks support for the Raspberry Pi Pico micro controller using the pico C/C++ SDK.

I have implemented some of the lcd_hal functions using the pico-sdk, especially for the SPI implementation and also verified this implementation using hardware.

Implementation

Using this library

As the Raspberry Pi Pico suite also uses CMake (and ninja) for the projects, it is fairly straight forward to "include" the source of this library (at least once I figured it out correctly).

I have provided an example with 4 additional statements in the CMakeList.txt of the Raspberry Pi Pico project to include the lcdgfx CMake folder, as well as to compile and link it correctly. Using the lcdgfx library does work the same as on the Arduino platform.

With this approach none additional compile or link process is required, as it is seemingly implemented into the CMake build process of the Raspberry Pi Pico prject.

Best regards Simon

simon-77 commented 2 months ago

One workaround I forgot to mention regarding the SPI hardware:

The Rapsberry Pi Pico has 2 SPI hardware peripherals (spi0 and spi1) which can each be routed to multiple different pins. The pin routing is implemented in the pico-hal and can be achieved by providing the correct pin numbers to the constructor of lcdgfx. As there are no additional parameters in the constructor, I used a define to distinguish between these 2 SPI peripherals

I have therefore introduced the following snippet of the pico_spi.h file:

#if defined(PICO_USE_SPI1)
#define PICO_SPI spi1
#else
#define PICO_SPI spi0
#endif

Maybe not the most elegant solution ... but I did not know how to do it otherwise.

lexus2k commented 1 month ago

Hi @simon-77 You solution is merged to the project. It passed automatic checked and conform code style. Thank you