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
61 stars 29 forks source link

Repackage to pyproject/hatch and port to gpiod #33

Closed Gadgetoid closed 12 months ago

Gadgetoid commented 1 year ago

This PR upgrades the packaging to our latest boilerplate and ports additional pins to gpiod/gpiodevice. Part of an effort to bring enviro up to speed with Raspberry Pi 5 - https://github.com/pimoroni/enviroplus-python/pull/126

Note: This library uses SPI and requires this patch - https://github.com/raspberrypi/linux/commit/686fe776309fba5cad642c40177d39bf1fb320b2 - to function without raising a TimeoutError on Pi 5.

Pi 5 / Raspberry Pi OS

Make sure your user is in the group spi and enable SPI with dtparam=spi=on or via raspi-config

Rock 5B / Armbian

On ROCK5B and possibly other modern platforms, it needs a custom dtoverlay to remove control of MISO from the spi driver, otherwise the data/command pin cannot be asserted by gpiod.

In /etc/udev/rules.d/60-spidev.rules:

SUBSYSTEM=="spidev", GROUP="gpio", MODE="0660"

Then:

sudo udevadm control --reload-rules
sudo udevadm trigger

Make sure your user is in the gpio group:

sudo usermod -a -G gpio $USER

Create a new file rk3588-spi0-m2-cs1-nomiso-spidev.dts with the dts code below.

Install with: sudo armbian-add-overlay rk3588-spi0-m2-cs1-nomiso-spidev.dts

/dts-v1/;
/plugin/;

/ {
    fragment@0 {
        target = <&spi0>;

        __overlay__ {
            status = "okay";
            #address-cells = <1>;
            #size-cells = <0>;
            pinctrl-names = "default";
            pinctrl-0 = <&spi0m2_cs1 &spi0m2_nomiso_pins>;
            max-freq = <50000000>;

            spidev@1 {
                compatible = "rockchip,spidev";
                status = "okay";
                reg = <1>;
                spi-max-frequency = <50000000>;
            };
        };
    };
    fragment@1 {
        target = <&pinctrl>;

        __overlay__ {

            spi0 {

                spi0m2_nomiso_pins: spi0m2-nomiso-pins {
                    rockchip,pins =
                        /* spi0_clk_m2 */
                        <1 11 8 &pcfg_pull_up_drv_level_6>,
                        /* spi0_miso_m2 */
                        /*<1 9 8 &pcfg_pull_up_drv_level_6>,*/
                        /* spi0_mosi_m2 */
                        <1 10 8 &pcfg_pull_up_drv_level_6>;
                };
            };
        };
    };
};
coveralls commented 1 year ago

Pull Request Test Coverage Report for Build 6796461761


Totals Coverage Status
Change from base Build 5784058181: 0.4%
Covered Lines: 313
Relevant Lines: 318

💛 - Coveralls