From 7195ddf32c35a7f4c92a9228cecaef30c9dfaa29 Mon Sep 17 00:00:00 2001 From: Dan Whitman Date: Sat, 9 Nov 2024 19:16:00 -0500 Subject: [PATCH] * Updates to the `pygamer` BSP to bring it to Tier 1 status: * Upgrades the display and graphics dependencies: st7735-lcd, embedded-graphics, tinybmp * This completes the upgrades of all dependencies. * Corrects the README.md to list `pygamer` as a `samd51j` BSP instead of the erroneous `same53j`. * Adds an empty `DisplayError` and a `DisplayDriver` type alias, both to address clippy lints. --- boards/pygamer/Cargo.toml | 13 ++++++------ boards/pygamer/src/pins.rs | 41 ++++++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/boards/pygamer/Cargo.toml b/boards/pygamer/Cargo.toml index cb5bf24643f0..b0e30b4efea8 100644 --- a/boards/pygamer/Cargo.toml +++ b/boards/pygamer/Cargo.toml @@ -16,7 +16,9 @@ version = "0.11.0" [dependencies] cortex-m = {version = "0.7", features = ["critical-section-single-core"]} -st7735-lcd = "0.8.1" +embedded-hal-bus = "0.2.0" +# This version is pinned as recommended by: https://docs.rs/embedded-hal-bus/0.2.0/embedded_hal_bus/spi/struct.ExclusiveDevice.html#method.new_no_delay +st7735-lcd = "=0.10.0" [dependencies.cortex-m-rt] optional = true @@ -29,18 +31,17 @@ version = "0.18.2" [dependencies.usb-device] optional = true -version = "0.3.1" +version = "0.3.2" [dev-dependencies] -embedded-graphics = "0.7.1" -embedded-hal-bus = "0.2.0" +embedded-graphics = "0.8.1" embedded-sdmmc = "0.8.0" lis3dh = "0.4.3" micromath = "2.1" -panic-halt = "0.2" +panic-halt = "1" rtic = {version = "2.1.1", features = ["thumbv7-backend"]} smart-leds = "0.4" -tinybmp = "0.3.1" +tinybmp = "0.6" usbd-serial = "0.2" [features] diff --git a/boards/pygamer/src/pins.rs b/boards/pygamer/src/pins.rs index 410f3abe38c8..4cee2655b9c8 100644 --- a/boards/pygamer/src/pins.rs +++ b/boards/pygamer/src/pins.rs @@ -4,6 +4,7 @@ use super::{hal, pac}; use hal::prelude::*; +use embedded_hal_bus::spi as bspi; use hal::clock::GenericClockController; use hal::gpio::PA01; use hal::pwm; @@ -581,11 +582,30 @@ pub struct Display { pub tft_backlight: TftBacklightReset, } +/// This empty error occurs if there is an issue setting up the on-board +/// display. +#[derive(Debug)] +pub struct DisplayError; +impl From<()> for DisplayError { + fn from(_value: ()) -> Self { + DisplayError + } +} + pub type TftPads = spi::Pads; -pub type TftSpi = spi::Spi, spi::Tx>; +pub type TftSpi = bspi::ExclusiveDevice< + spi::PanicOnRead, spi::Tx>>, + TftCs, + bspi::NoDelay, +>; + +/// The on-board display driver that is a +/// [`DrawTarget`](https://docs.rs/embedded-graphics/latest/embedded_graphics/draw_target/trait.DrawTarget.html) +/// for embedded graphics. +pub type DisplayDriver = ST7735; impl Display { - /// Convenience for setting up the on board display. + /// Convenience for setting up the on-board display. pub fn init( self, clocks: &mut GenericClockController, @@ -593,18 +613,23 @@ impl Display { mclk: &mut pac::Mclk, timer2: pac::Tc2, delay: &mut hal::delay::Delay, - ) -> Result<(ST7735, Pwm2), ()> { + ) -> Result<(DisplayDriver, Pwm2), DisplayError> { let gclk0 = clocks.gclk0(); - let clock = &clocks.sercom4_core(&gclk0).ok_or(())?; + let clock = &clocks.sercom4_core(&gclk0).ok_or(DisplayError)?; let pads = spi::Pads::default() .sclk(self.tft_sclk) .data_out(self.tft_mosi); - let tft_spi = spi::Config::new(mclk, sercom4, pads, clock.freq()) - .spi_mode(spi::MODE_0) - .baud(16.MHz()) - .enable(); let mut tft_cs: TftCs = self.tft_cs.into(); tft_cs.set_low().ok(); + let tft_spi = bspi::ExclusiveDevice::new_no_delay( + spi::Config::new(mclk, sercom4, pads, clock.freq()) + .spi_mode(spi::MODE_0) + .baud(16.MHz()) + .enable() + .into_panic_on_read(), + tft_cs, + ) + .map_err(|_| DisplayError)?; let mut display = st7735_lcd::ST7735::new( tft_spi, self.tft_dc.into(),