From 5be4b2875cdff1b0e3d9edc1abc4a0c564e7ca6c Mon Sep 17 00:00:00 2001 From: Jacob Rosenthal Date: Mon, 15 Nov 2021 14:37:23 -0700 Subject: [PATCH 1/7] async test --- Cargo.toml | 8 +++++--- examples/bmp.rs | 3 +++ src/display.rs | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ef5ad22..b346132 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,15 +13,16 @@ version = "0.3.0" edition = "2018" [package.metadata.docs.rs] -targets = [ "thumbv7m-none-eabi" ] +targets = ["thumbv7m-none-eabi"] all-features = true [badges] circle-ci = { repository = "jamwaffles/ssd1331", branch = "master" } [dependencies] -embedded-hal = "0.2.3" +embedded-hal = "0.2.6" embedded-graphics-core = { version = "0.3.2", optional = true } +embassy-traits = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", optional = true } [dev-dependencies] cortex-m = "0.7.3" @@ -29,11 +30,12 @@ cortex-m-rt = "0.6.11" panic-semihosting = "0.5.3" embedded-graphics = "0.7.1" tinybmp = "0.3.1" -stm32f1xx-hal = { version = "0.7.0", features = [ "rt", "stm32f103" ] } +stm32f1xx-hal = { version = "0.7.0", features = ["rt", "stm32f103"] } [features] default = ["graphics"] graphics = ["embedded-graphics-core"] +async = ["embassy-traits"] [profile.dev] codegen-units = 1 diff --git a/examples/bmp.rs b/examples/bmp.rs index 0d211c6..1089382 100644 --- a/examples/bmp.rs +++ b/examples/bmp.rs @@ -21,6 +21,9 @@ #![no_std] #![no_main] +#![feature(type_alias_impl_trait)] +#![feature(unchecked_math)] +#![allow(incomplete_features)] use cortex_m_rt::{entry, exception, ExceptionFrame}; use embedded_graphics::{geometry::Point, image::Image, pixelcolor::Rgb565, prelude::*}; diff --git a/src/display.rs b/src/display.rs index 19753a9..ba1f0fe 100644 --- a/src/display.rs +++ b/src/display.rs @@ -188,6 +188,25 @@ where Ok(()) } + /// Send the full framebuffer to the display + /// + /// This resets the draw area the full size of the display + #[cfg(feature = "async")] + pub async fn flush_async(&mut self) -> Result<(), Error> { + use embassy_traits::spi::Write as SpiTrait; + + // Ensure the display buffer is at the origin of the display before we send the full frame + // to prevent accidental offsets + self.set_draw_area((0, 0), (DISPLAY_WIDTH - 1, DISPLAY_HEIGHT - 1))?; + + // 1 = data, 0 = command + self.dc.set_high().map_err(Error::Pin)?; + + self.spi.write(&self.buffer).map_err(Error::Comm)?; + + Ok(()) + } + /// Set the top left and bottom right corners of a bounding box to draw to pub fn set_draw_area( &mut self, From b03a99952b81846036ddf687801e38ac6db3a85b Mon Sep 17 00:00:00 2001 From: Jacob Rosenthal Date: Tue, 16 Nov 2021 16:35:15 -0700 Subject: [PATCH 2/7] bmp example block_on flush_async --- Cargo.toml | 1 + examples/bmp.rs | 31 ++++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b346132..6d717a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ panic-semihosting = "0.5.3" embedded-graphics = "0.7.1" tinybmp = "0.3.1" stm32f1xx-hal = { version = "0.7.0", features = ["rt", "stm32f103"] } +futures = { version = "0.3.17", default-features = false } [features] default = ["graphics"] diff --git a/examples/bmp.rs b/examples/bmp.rs index 1089382..caeb60d 100644 --- a/examples/bmp.rs +++ b/examples/bmp.rs @@ -17,15 +17,13 @@ //! PB1 -> D/C //! ``` //! -//! Run on a Blue Pill with `cargo run --release --example image`. +//! Run on a Blue Pill with `cargo +nightly run --release --example bmp --features=async`. #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] -#![feature(unchecked_math)] -#![allow(incomplete_features)] use cortex_m_rt::{entry, exception, ExceptionFrame}; +use embassy_traits::spi::Write; use embedded_graphics::{geometry::Point, image::Image, pixelcolor::Rgb565, prelude::*}; use panic_semihosting as _; use ssd1331::{DisplayRotation, Ssd1331}; @@ -96,7 +94,7 @@ fn main() -> ! { moved.draw(&mut display).unwrap(); - display.flush().unwrap(); + block_on(display.flush_async()).unwrap(); loop {} } @@ -105,3 +103,26 @@ fn main() -> ! { fn HardFault(ef: &ExceptionFrame) -> ! { panic!("{:#?}", ef); } + +use core::future::Future; +use core::ptr::null_mut; +use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; + +unsafe fn waker_clone(p: *const ()) -> RawWaker { + RawWaker::new(p, &VTABLE) +} + +unsafe fn waker_nop(_p: *const ()) {} + +static VTABLE: RawWakerVTable = RawWakerVTable::new(waker_clone, waker_nop, waker_nop, waker_nop); + +pub fn block_on(future: F) -> F::Output { + futures::pin_mut!(future); + let waker = &unsafe { Waker::from_raw(RawWaker::new(null_mut(), &VTABLE)) }; + let mut cx = Context::from_waker(waker); + loop { + if let Poll::Ready(output) = future.as_mut().poll(&mut cx) { + return output; + } + } +} From 531ec85c074a9326d5029138ee744d33fbad24a7 Mon Sep 17 00:00:00 2001 From: Jacob Rosenthal Date: Sat, 20 Nov 2021 12:22:32 -0700 Subject: [PATCH 3/7] fix async trait and add nrf52840 example --- .cargo/config | 4 +- Cargo.toml | 20 +++++++- examples/bmp.rs | 17 +++++-- examples/embassy.rs | 112 ++++++++++++++++++++++++++++++++++++++++++++ memory.x | 8 ++-- src/command.rs | 68 +++++++++++++++++++++++++++ src/display.rs | 49 +++++++++++-------- 7 files changed, 246 insertions(+), 32 deletions(-) create mode 100644 examples/embassy.rs diff --git a/.cargo/config b/.cargo/config index 3d6d7d4..9b21092 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,8 +1,8 @@ [target.'cfg(all(target_arch = "arm", target_os = "none"))'] -runner = "probe-run --chip STM32F103C8" +runner = "probe-run --chip nrf52840" rustflags = [ "-C", "link-arg=-Tlink.x", ] [build] -target = "thumbv7m-none-eabi" +target = "thumbv7em-none-eabihf" diff --git a/Cargo.toml b/Cargo.toml index 6d717a8..a49878e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ readme = "README.md" repository = "https://github.com/jamwaffles/ssd1331" version = "0.3.0" edition = "2018" +resolver = "2" [package.metadata.docs.rs] targets = ["thumbv7m-none-eabi"] @@ -22,6 +23,10 @@ circle-ci = { repository = "jamwaffles/ssd1331", branch = "master" } [dependencies] embedded-hal = "0.2.6" embedded-graphics-core = { version = "0.3.2", optional = true } +# stm32f1xx-hal = { version = "0.7.0", optional = true, features = [ +# "rt", +# "stm32f103" +# ] } embassy-traits = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", optional = true } [dev-dependencies] @@ -30,13 +35,24 @@ cortex-m-rt = "0.6.11" panic-semihosting = "0.5.3" embedded-graphics = "0.7.1" tinybmp = "0.3.1" -stm32f1xx-hal = { version = "0.7.0", features = ["rt", "stm32f103"] } futures = { version = "0.3.17", default-features = false } +embassy = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy" } +embassy-nrf = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = [ + "nrf52840", + "gpiote", + "time-driver-rtc1" +] } + +[patch.crates-io] +embassy = { git = "https://github.com/embassy-rs/embassy" } +embassy-nrf = { git = "https://github.com/embassy-rs/embassy" } +embassy-macros = { git = "https://github.com/embassy-rs/embassy" } +embassy-traits = { git = "https://github.com/embassy-rs/embassy" } [features] default = ["graphics"] graphics = ["embedded-graphics-core"] -async = ["embassy-traits"] +embassy-async = ["embassy-traits"] [profile.dev] codegen-units = 1 diff --git a/examples/bmp.rs b/examples/bmp.rs index caeb60d..0c49f7f 100644 --- a/examples/bmp.rs +++ b/examples/bmp.rs @@ -22,8 +22,10 @@ #![no_std] #![no_main] +use core::future::Future; +use core::ptr::null_mut; +use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; use cortex_m_rt::{entry, exception, ExceptionFrame}; -use embassy_traits::spi::Write; use embedded_graphics::{geometry::Point, image::Image, pixelcolor::Rgb565, prelude::*}; use panic_semihosting as _; use ssd1331::{DisplayRotation, Ssd1331}; @@ -104,10 +106,6 @@ fn HardFault(ef: &ExceptionFrame) -> ! { panic!("{:#?}", ef); } -use core::future::Future; -use core::ptr::null_mut; -use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; - unsafe fn waker_clone(p: *const ()) -> RawWaker { RawWaker::new(p, &VTABLE) } @@ -126,3 +124,12 @@ pub fn block_on(future: F) -> F::Output { } } } + +impl<'d, T: Instance> embassy_traits::spi::Write for Spim<'d, T> { + #[rustfmt::skip] + type WriteFuture<'a> where Self: 'a = impl Future> + 'a; + + fn write<'a>(&'a mut self, data: &'a [u8]) -> Self::WriteFuture<'a> { + self.read_write(&mut [], data) + } +} diff --git a/examples/embassy.rs b/examples/embassy.rs new file mode 100644 index 0000000..d0db122 --- /dev/null +++ b/examples/embassy.rs @@ -0,0 +1,112 @@ +//! cargo +nightly run --release --example embassy --features=embassy-async,embassy-dep +//! +#![no_main] +#![no_std] +#![feature(type_alias_impl_trait)] + +use core::future::pending; +use embassy::interrupt::InterruptExt; +use embassy::time::{Duration, Timer}; +use embassy::util::Forever; +use embassy_nrf::gpio::{self, AnyPin, Level, NoPin, Output, OutputDrive, Pin}; +use embassy_nrf::{interrupt, spim}; +use embedded_graphics::prelude::*; +use embedded_graphics::{image::Image, pixelcolor::Rgb565}; +use embedded_hal::digital::v2::OutputPin; +use ssd1331::{DisplayRotation, Ssd1331}; +use tinybmp::Bmp; + +// we make a lazily created static +static EXECUTOR: Forever = Forever::new(); + +#[cortex_m_rt::entry] +fn main() -> ! { + // once we hit runtime we create and fill that executor finally + let executor = EXECUTOR.put(embassy::executor::Executor::new()); + + // provides the peripherals from the async first pac if you selected it + let dp = embassy_nrf::init(Default::default()); + + let green = gpio::Output::new( + // degrade just a typesystem hack to forget which pin it is so we can + // call it Anypin and make our function calls more generic + dp.P0_22.degrade(), + gpio::Level::High, + gpio::OutputDrive::Standard, + ); + + // spawn tasks + executor.run(|spawner| { + let _ = spawner.spawn(blinky_task(green)); + let _ = spawner.spawn(display_task()); + }) +} + +#[embassy::task] +async fn blinky_task(mut green: gpio::Output<'static, AnyPin>) { + loop { + green.set_high().unwrap(); + Timer::after(Duration::from_millis(300)).await; + green.set_low().unwrap(); + Timer::after(Duration::from_millis(1000)).await; + } +} + +#[embassy::task] +pub async fn display_task() { + // Too lazy to pass all the pins and peripherals we need. + // Safety: Fragile but safe as long as pins and peripherals arent used + // anywhere else + let mut dp = unsafe { ::steal() }; + + let mut spim_irq = interrupt::take!(SPIM3); + spim_irq.set_priority(interrupt::Priority::P4); + + let mut spim_config = spim::Config::default(); + spim_config.frequency = spim::Frequency::M16; + let spim = spim::Spim::new( + &mut dp.SPI3, + &mut spim_irq, + &mut dp.P0_21, + NoPin, + &mut dp.P0_17, + spim_config, + ); + + let mut rst = Output::new(&mut dp.P0_16, Level::High, OutputDrive::Standard); + let dc = Output::new(&mut dp.P0_15, Level::High, OutputDrive::Standard); + let mut display = Ssd1331::new(spim, dc, DisplayRotation::Rotate0); + Timer::after(Duration::from_millis(1)).await; + rst.set_low().ok(); + Timer::after(Duration::from_millis(1)).await; + rst.set_high().ok(); + display.init().unwrap(); + + let (w, h) = display.dimensions(); + + let bmp = + Bmp::from_slice(include_bytes!("./rust-pride.bmp")).expect("Failed to load BMP image"); + + let im: Image> = Image::new(&bmp, Point::zero()); + + // Position image in the center of the display + let moved = im.translate(Point::new( + (w as u32 - bmp.size().width) as i32 / 2, + (h as u32 - bmp.size().height) as i32 / 2, + )); + + moved.draw(&mut display).unwrap(); + + display.flush_async().await.unwrap(); + // display.flush().unwrap(); + + // Block forever so the above drivers don't get dropped + pending::<()>().await; +} + +#[panic_handler] // panicking behavior +fn panic(_: &core::panic::PanicInfo) -> ! { + loop { + cortex_m::asm::bkpt(); + } +} diff --git a/memory.x b/memory.x index a120f83..b86bf59 100644 --- a/memory.x +++ b/memory.x @@ -1,6 +1,6 @@ -/* Linker script for the STM32F103C8T6 */ MEMORY { - FLASH : ORIGIN = 0x08000000, LENGTH = 128K - RAM : ORIGIN = 0x20000000, LENGTH = 20K -} \ No newline at end of file + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + FLASH : ORIGIN = 0x00000000, LENGTH = 1024K + RAM : ORIGIN = 0x20000000, LENGTH = 256K +} diff --git a/src/command.rs b/src/command.rs index 7832d33..f7612a7 100644 --- a/src/command.rs +++ b/src/command.rs @@ -50,6 +50,74 @@ pub enum Command { } impl Command { + /// Send command to SSD1331 + pub async fn send_async( + self, + spi: &mut SPI, + dc: &mut DC, + ) -> Result<(), Error> + where + SPI: embassy_traits::spi::Write + embassy_traits::spi::Spi, + DC: OutputPin, + { + // Transform command into a fixed size array of 7 u8 and the real length for sending + let (data, len) = match self { + Command::Contrast(a, b, c) => ([0x81, a, 0x82, b, 0x83, c, 0], 6), + // TODO: Collapse AllOn and Invert commands into new DisplayMode cmd with enum + Command::AllOn(on) => ([if on { 0xA5 } else { 0xA6 }, 0, 0, 0, 0, 0, 0], 1), + Command::Invert(inv) => ([if inv { 0xA7 } else { 0xA4 }, 0, 0, 0, 0, 0, 0], 1), + Command::DisplayOn(on) => ([0xAE | (on as u8), 0, 0, 0, 0, 0, 0], 1), + Command::ColumnAddress(start, end) => ([0x15, start, end, 0, 0, 0, 0], 3), + Command::RowAddress(start, end) => ([0x75, start, end, 0, 0, 0, 0], 3), + Command::StartLine(line) => ([0xA1, (0x3F & line), 0, 0, 0, 0, 0], 2), + Command::RemapAndColorDepth(hremap, vremap, cmode, addr_inc_mode) => ( + [ + 0xA0, + 0x20 | ((vremap as u8) << 4 + | (hremap as u8) << 1 + | (cmode as u8) << 6 + | (addr_inc_mode as u8)), + 0, + 0, + 0, + 0, + 0, + ], + 2, + ), + Command::Multiplex(ratio) => ([0xA8, ratio, 0, 0, 0, 0, 0], 2), + Command::ReverseComDir(rev) => ([0xC0 | ((rev as u8) << 3), 0, 0, 0, 0, 0, 0], 1), + Command::DisplayOffset(offset) => ([0xA2, offset, 0, 0, 0, 0, 0], 2), + Command::ComPinConfig(alt, lr) => ( + [ + 0xDA, + 0x2 | ((alt as u8) << 4) | ((lr as u8) << 5), + 0, + 0, + 0, + 0, + 0, + ], + 2, + ), + Command::DisplayClockDiv(fosc, div) => { + ([0xB3, ((0xF & fosc) << 4) | (0xF & div), 0, 0, 0, 0, 0], 2) + } + Command::PreChargePeriod(phase1, phase2) => ( + [0x3e, ((0xF & phase2) << 4) | (0xF & phase1), 0, 0, 0, 0, 0], + 2, + ), + Command::VcomhDeselect(level) => ([0xBE, (level as u8) << 1, 0, 0, 0, 0, 0], 2), + Command::Noop => ([0xE3, 0, 0, 0, 0, 0, 0], 1), + }; + + // Command mode. 1 = data, 0 = command + dc.set_low().map_err(Error::Pin)?; + + // Send command over the interface + spi.write(&data[0..len]).await.map_err(Error::Comm) + } + /// Send command to SSD1331 pub fn send( self, diff --git a/src/display.rs b/src/display.rs index ba1f0fe..a50322c 100644 --- a/src/display.rs +++ b/src/display.rs @@ -99,6 +99,36 @@ pub struct Ssd1331 { dc: DC, } +#[cfg(feature = "embassy-async")] +impl Ssd1331 +where + SPI: embassy_traits::spi::Write + embassy_traits::spi::Spi, + DC: OutputPin, +{ + /// Send the full framebuffer to the display + /// + /// This resets the draw area the full size of the display + pub async fn flush_async(&mut self) -> Result<(), Error> { + // Ensure the display buffer is at the origin of the display before we send the full frame + // to prevent accidental offsets + // self.set_draw_area((0, 0), (DISPLAY_WIDTH - 1, DISPLAY_HEIGHT - 1))?; + + Command::ColumnAddress(0, DISPLAY_WIDTH - 1) + .send_async(&mut self.spi, &mut self.dc) + .await?; + Command::RowAddress(0.into(), (DISPLAY_HEIGHT - 1).into()) + .send_async(&mut self.spi, &mut self.dc) + .await?; + + // 1 = data, 0 = command + self.dc.set_high().map_err(Error::Pin)?; + + embassy_traits::spi::Write::write(&mut self.spi, &self.buffer) + .await + .map_err(Error::Comm) + } +} + impl Ssd1331 where SPI: hal::blocking::spi::Write, @@ -188,25 +218,6 @@ where Ok(()) } - /// Send the full framebuffer to the display - /// - /// This resets the draw area the full size of the display - #[cfg(feature = "async")] - pub async fn flush_async(&mut self) -> Result<(), Error> { - use embassy_traits::spi::Write as SpiTrait; - - // Ensure the display buffer is at the origin of the display before we send the full frame - // to prevent accidental offsets - self.set_draw_area((0, 0), (DISPLAY_WIDTH - 1, DISPLAY_HEIGHT - 1))?; - - // 1 = data, 0 = command - self.dc.set_high().map_err(Error::Pin)?; - - self.spi.write(&self.buffer).map_err(Error::Comm)?; - - Ok(()) - } - /// Set the top left and bottom right corners of a bounding box to draw to pub fn set_draw_area( &mut self, From 1515ea4e2e18114ce23a8021708ce4f27ebe9d25 Mon Sep 17 00:00:00 2001 From: Jacob Rosenthal Date: Sat, 20 Nov 2021 12:23:30 -0700 Subject: [PATCH 4/7] restore bmp --- examples/bmp.rs | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/examples/bmp.rs b/examples/bmp.rs index 0c49f7f..0d211c6 100644 --- a/examples/bmp.rs +++ b/examples/bmp.rs @@ -17,14 +17,11 @@ //! PB1 -> D/C //! ``` //! -//! Run on a Blue Pill with `cargo +nightly run --release --example bmp --features=async`. +//! Run on a Blue Pill with `cargo run --release --example image`. #![no_std] #![no_main] -use core::future::Future; -use core::ptr::null_mut; -use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; use cortex_m_rt::{entry, exception, ExceptionFrame}; use embedded_graphics::{geometry::Point, image::Image, pixelcolor::Rgb565, prelude::*}; use panic_semihosting as _; @@ -96,7 +93,7 @@ fn main() -> ! { moved.draw(&mut display).unwrap(); - block_on(display.flush_async()).unwrap(); + display.flush().unwrap(); loop {} } @@ -105,31 +102,3 @@ fn main() -> ! { fn HardFault(ef: &ExceptionFrame) -> ! { panic!("{:#?}", ef); } - -unsafe fn waker_clone(p: *const ()) -> RawWaker { - RawWaker::new(p, &VTABLE) -} - -unsafe fn waker_nop(_p: *const ()) {} - -static VTABLE: RawWakerVTable = RawWakerVTable::new(waker_clone, waker_nop, waker_nop, waker_nop); - -pub fn block_on(future: F) -> F::Output { - futures::pin_mut!(future); - let waker = &unsafe { Waker::from_raw(RawWaker::new(null_mut(), &VTABLE)) }; - let mut cx = Context::from_waker(waker); - loop { - if let Poll::Ready(output) = future.as_mut().poll(&mut cx) { - return output; - } - } -} - -impl<'d, T: Instance> embassy_traits::spi::Write for Spim<'d, T> { - #[rustfmt::skip] - type WriteFuture<'a> where Self: 'a = impl Future> + 'a; - - fn write<'a>(&'a mut self, data: &'a [u8]) -> Self::WriteFuture<'a> { - self.read_write(&mut [], data) - } -} From c6770a9b7aee944e2968462abde5282aeb11ecad Mon Sep 17 00:00:00 2001 From: Jacob Rosenthal Date: Sat, 20 Nov 2021 15:14:44 -0700 Subject: [PATCH 5/7] move examples to ssd1331-examples to support multiple targets --- .gitignore | 2 +- Cargo.toml | 21 +---------- README.md | 8 +++- {examples => assets}/ferris.png | Bin {examples => assets}/ferris.raw | Bin {examples => assets}/rust-pride.bmp | Bin {examples => assets}/rust.png | Bin {examples => assets}/rust.raw | Bin build.sh | 10 +++-- src/command.rs | 1 + src/display.rs | 2 +- src/lib.rs | 2 +- .../embassy-nrf/.cargo}/config | 2 +- ssd1331-examples/embassy-nrf/Cargo.toml | 35 ++++++++++++++++++ .../embassy-nrf/build.rs | 0 .../embassy-nrf/examples/bmp.rs | 7 +++- .../embassy-nrf/memory.x | 0 ssd1331-examples/embassy-nrf/rust-toolchain | 6 +++ .../stm32f1-examples/.cargo/config | 8 ++++ ssd1331-examples/stm32f1-examples/Cargo.toml | 24 ++++++++++++ ssd1331-examples/stm32f1-examples/build.rs | 14 +++++++ .../stm32f1-examples/examples}/bmp.rs | 4 +- .../stm32f1-examples/examples}/graphics.rs | 0 .../stm32f1-examples/examples}/image.rs | 2 +- .../stm32f1-examples/examples}/pixelsquare.rs | 0 .../stm32f1-examples/examples}/rotation.rs | 2 +- .../stm32f1-examples/examples}/text.rs | 0 ssd1331-examples/stm32f1-examples/memory.x | 6 +++ 28 files changed, 122 insertions(+), 34 deletions(-) rename {examples => assets}/ferris.png (100%) rename {examples => assets}/ferris.raw (100%) rename {examples => assets}/rust-pride.bmp (100%) rename {examples => assets}/rust.png (100%) rename {examples => assets}/rust.raw (100%) rename {.cargo => ssd1331-examples/embassy-nrf/.cargo}/config (77%) create mode 100644 ssd1331-examples/embassy-nrf/Cargo.toml rename build.rs => ssd1331-examples/embassy-nrf/build.rs (100%) rename examples/embassy.rs => ssd1331-examples/embassy-nrf/examples/bmp.rs (93%) rename memory.x => ssd1331-examples/embassy-nrf/memory.x (100%) create mode 100644 ssd1331-examples/embassy-nrf/rust-toolchain create mode 100644 ssd1331-examples/stm32f1-examples/.cargo/config create mode 100644 ssd1331-examples/stm32f1-examples/Cargo.toml create mode 100644 ssd1331-examples/stm32f1-examples/build.rs rename {examples => ssd1331-examples/stm32f1-examples/examples}/bmp.rs (95%) rename {examples => ssd1331-examples/stm32f1-examples/examples}/graphics.rs (100%) rename {examples => ssd1331-examples/stm32f1-examples/examples}/image.rs (96%) rename {examples => ssd1331-examples/stm32f1-examples/examples}/pixelsquare.rs (100%) rename {examples => ssd1331-examples/stm32f1-examples/examples}/rotation.rs (96%) rename {examples => ssd1331-examples/stm32f1-examples/examples}/text.rs (100%) create mode 100644 ssd1331-examples/stm32f1-examples/memory.x diff --git a/.gitignore b/.gitignore index 143b1ca..4353154 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/target/ +**/target/ **/*.rs.bk Cargo.lock diff --git a/Cargo.toml b/Cargo.toml index a49878e..13bbe21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ readme = "README.md" repository = "https://github.com/jamwaffles/ssd1331" version = "0.3.0" edition = "2018" -resolver = "2" [package.metadata.docs.rs] targets = ["thumbv7m-none-eabi"] @@ -21,12 +20,8 @@ all-features = true circle-ci = { repository = "jamwaffles/ssd1331", branch = "master" } [dependencies] -embedded-hal = "0.2.6" +embedded-hal = "0.2.3" embedded-graphics-core = { version = "0.3.2", optional = true } -# stm32f1xx-hal = { version = "0.7.0", optional = true, features = [ -# "rt", -# "stm32f103" -# ] } embassy-traits = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", optional = true } [dev-dependencies] @@ -35,19 +30,7 @@ cortex-m-rt = "0.6.11" panic-semihosting = "0.5.3" embedded-graphics = "0.7.1" tinybmp = "0.3.1" -futures = { version = "0.3.17", default-features = false } -embassy = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy" } -embassy-nrf = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = [ - "nrf52840", - "gpiote", - "time-driver-rtc1" -] } - -[patch.crates-io] -embassy = { git = "https://github.com/embassy-rs/embassy" } -embassy-nrf = { git = "https://github.com/embassy-rs/embassy" } -embassy-macros = { git = "https://github.com/embassy-rs/embassy" } -embassy-traits = { git = "https://github.com/embassy-rs/embassy" } +stm32f1xx-hal = { version = "0.7.0", features = ["rt", "stm32f103"] } [features] default = ["graphics"] diff --git a/README.md b/README.md index 2c4da32..1e6e1d7 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,14 @@ You can also export images directly from The GIMP by saving as `.bmp` and choosi ## [Examples](examples) +Examples are stored in per target directories in ssd1331-examples. cd to your preferred example + +`cd ssd1331-examples/stm32f1-examples/` + This crate uses [`probe-run`](https://crates.io/crates/probe-run) to run the examples. Once set up, it should be as simple as `cargo run --example --release`. `--release` will be required for some examples to reduce FLASH usage. Load a BMP image of the Rust logo and display it in the center of the display. From -[`examples/bmp.rs`](examples/bmp.rs): +[`ssd1331-examples/stm32f1-examples/bmp.rs`](examples/bmp.rs): ```rust #![no_std] @@ -93,7 +97,7 @@ fn main() -> ! { let (w, h) = disp.dimensions(); let bmp = - Bmp::from_slice(include_bytes!("./rust-pride.bmp")).expect("Failed to load BMP image"); + Bmp::from_slice(include_bytes!("../../../assets/rust-pride.bmp")).expect("Failed to load BMP image"); let im: Image> = Image::new(&bmp, Point::zero()); diff --git a/examples/ferris.png b/assets/ferris.png similarity index 100% rename from examples/ferris.png rename to assets/ferris.png diff --git a/examples/ferris.raw b/assets/ferris.raw similarity index 100% rename from examples/ferris.raw rename to assets/ferris.raw diff --git a/examples/rust-pride.bmp b/assets/rust-pride.bmp similarity index 100% rename from examples/rust-pride.bmp rename to assets/rust-pride.bmp diff --git a/examples/rust.png b/assets/rust.png similarity index 100% rename from examples/rust.png rename to assets/rust.png diff --git a/examples/rust.raw b/assets/rust.raw similarity index 100% rename from examples/rust.raw rename to assets/rust.raw diff --git a/build.sh b/build.sh index 5710494..a5670c7 100755 --- a/build.sh +++ b/build.sh @@ -14,19 +14,23 @@ fi cargo fmt --all -- --check -cargo build --target $TARGET --all-features --release +# todo not building all features +cargo build --target $TARGET --release cargo test --lib --target x86_64-unknown-linux-gnu cargo test --doc --target x86_64-unknown-linux-gnu if [ -z $DISABLE_EXAMPLES ]; then - cargo build --target $TARGET --all-features --examples + # todo list of example directories in metadata so other + (cd ssd1331-examples/stm32f1-examples && cargo build --examples) + (cd ssd1331-examples/embassy-nrf && cargo build --examples) fi # Remove stale docs - the linkchecker might miss links to old files if they're not removed cargo clean --doc cargo clean --doc --target $TARGET -cargo doc --all-features --target $TARGET +# todo not building all features +cargo doc --target $TARGET linkchecker target/$TARGET/doc/ssd1331/index.html diff --git a/src/command.rs b/src/command.rs index f7612a7..5759ee0 100644 --- a/src/command.rs +++ b/src/command.rs @@ -51,6 +51,7 @@ pub enum Command { impl Command { /// Send command to SSD1331 + #[cfg(feature = "embassy-async")] pub async fn send_async( self, spi: &mut SPI, diff --git a/src/display.rs b/src/display.rs index a50322c..3f548c3 100644 --- a/src/display.rs +++ b/src/display.rs @@ -39,7 +39,7 @@ const BUF_SIZE: usize = 96 * 64 * 2; /// let dc = Pin; /// /// let mut display = Ssd1331::new(spi, dc, Rotate0); -/// let raw = ImageRawLE::new(include_bytes!("../examples/ferris.raw"), 86); +/// let raw = ImageRawLE::new(include_bytes!("../assets/ferris.raw"), 86); /// /// let image: Image> = Image::new(&raw, Point::zero()); /// diff --git a/src/lib.rs b/src/lib.rs index 38e072b..53c4060 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,7 +60,7 @@ //! //! let (w, h) = display.dimensions(); //! -//! let bmp = Bmp::from_slice(include_bytes!("../examples/rust-pride.bmp")) +//! let bmp = Bmp::from_slice(include_bytes!("../assets/rust-pride.bmp")) //! .expect("Failed to load BMP image"); //! //! let im: Image> = Image::new(&bmp, Point::zero()); diff --git a/.cargo/config b/ssd1331-examples/embassy-nrf/.cargo/config similarity index 77% rename from .cargo/config rename to ssd1331-examples/embassy-nrf/.cargo/config index 9b21092..efe3b32 100644 --- a/.cargo/config +++ b/ssd1331-examples/embassy-nrf/.cargo/config @@ -1,5 +1,5 @@ [target.'cfg(all(target_arch = "arm", target_os = "none"))'] -runner = "probe-run --chip nrf52840" +runner = "probe-run --chip nRF52840_xxAA" rustflags = [ "-C", "link-arg=-Tlink.x", ] diff --git a/ssd1331-examples/embassy-nrf/Cargo.toml b/ssd1331-examples/embassy-nrf/Cargo.toml new file mode 100644 index 0000000..0307be2 --- /dev/null +++ b/ssd1331-examples/embassy-nrf/Cargo.toml @@ -0,0 +1,35 @@ +[package] +name = "embassy-nrf" +version = "0.1.0" +edition = "2021" + +[dependencies] +embedded-hal = "0.2.6" +embedded-graphics-core = { version = "0.3.2", optional = true } +cortex-m = "0.7.3" +cortex-m-rt = "0.6.11" +embedded-graphics = "0.7.1" +tinybmp = "0.3.1" +futures = { version = "0.3.17", default-features = false } +embassy = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy" } +embassy-nrf = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = [ + "nrf52840", + "gpiote", + "time-driver-rtc1" +] } +ssd1331 = { path = "../../", features = ["embassy-async"] } + +[patch.crates-io] +embassy = { git = "https://github.com/embassy-rs/embassy" } +embassy-nrf = { git = "https://github.com/embassy-rs/embassy" } +embassy-macros = { git = "https://github.com/embassy-rs/embassy" } +embassy-traits = { git = "https://github.com/embassy-rs/embassy" } + +[profile.dev] +codegen-units = 1 +incremental = false + +[profile.release] +codegen-units = 1 +debug = true +lto = true diff --git a/build.rs b/ssd1331-examples/embassy-nrf/build.rs similarity index 100% rename from build.rs rename to ssd1331-examples/embassy-nrf/build.rs diff --git a/examples/embassy.rs b/ssd1331-examples/embassy-nrf/examples/bmp.rs similarity index 93% rename from examples/embassy.rs rename to ssd1331-examples/embassy-nrf/examples/bmp.rs index d0db122..abe26ef 100644 --- a/examples/embassy.rs +++ b/ssd1331-examples/embassy-nrf/examples/bmp.rs @@ -1,4 +1,7 @@ -//! cargo +nightly run --release --example embassy --features=embassy-async,embassy-dep +//! The rust-toolchain will pull in the correct nightly and target so all you +//! need to run is +//! +//! cargo run --release //! #![no_main] #![no_std] @@ -85,7 +88,7 @@ pub async fn display_task() { let (w, h) = display.dimensions(); let bmp = - Bmp::from_slice(include_bytes!("./rust-pride.bmp")).expect("Failed to load BMP image"); + Bmp::from_slice(include_bytes!("../../../assets/rust-pride.bmp")).expect("Failed to load BMP image"); let im: Image> = Image::new(&bmp, Point::zero()); diff --git a/memory.x b/ssd1331-examples/embassy-nrf/memory.x similarity index 100% rename from memory.x rename to ssd1331-examples/embassy-nrf/memory.x diff --git a/ssd1331-examples/embassy-nrf/rust-toolchain b/ssd1331-examples/embassy-nrf/rust-toolchain new file mode 100644 index 0000000..ed08935 --- /dev/null +++ b/ssd1331-examples/embassy-nrf/rust-toolchain @@ -0,0 +1,6 @@ +# Before upgrading check that everything is available on all tier1 targets here: +# https://rust-lang.github.io/rustup-components-history +[toolchain] +channel = "nightly-2021-10-16" +components = ["rust-src", "rustfmt"] +targets = ["thumbv7em-none-eabihf"] diff --git a/ssd1331-examples/stm32f1-examples/.cargo/config b/ssd1331-examples/stm32f1-examples/.cargo/config new file mode 100644 index 0000000..3d6d7d4 --- /dev/null +++ b/ssd1331-examples/stm32f1-examples/.cargo/config @@ -0,0 +1,8 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +runner = "probe-run --chip STM32F103C8" +rustflags = [ + "-C", "link-arg=-Tlink.x", +] + +[build] +target = "thumbv7m-none-eabi" diff --git a/ssd1331-examples/stm32f1-examples/Cargo.toml b/ssd1331-examples/stm32f1-examples/Cargo.toml new file mode 100644 index 0000000..241a2ba --- /dev/null +++ b/ssd1331-examples/stm32f1-examples/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "stm32f1-examples" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] +embedded-hal = "0.2.6" +cortex-m = "0.7.3" +cortex-m-rt = "0.6.11" +embedded-graphics = "0.7.1" +tinybmp = "0.3.1" +stm32f1xx-hal = { version = "0.7.0", features = ["rt", "stm32f103"] } +panic-semihosting = "0.5.3" +ssd1331 = { path = "../../" } + +[profile.dev] +codegen-units = 1 +incremental = false + +[profile.release] +codegen-units = 1 +debug = true +lto = true diff --git a/ssd1331-examples/stm32f1-examples/build.rs b/ssd1331-examples/stm32f1-examples/build.rs new file mode 100644 index 0000000..364f9a0 --- /dev/null +++ b/ssd1331-examples/stm32f1-examples/build.rs @@ -0,0 +1,14 @@ +use std::{env, fs::File, io::Write, path::PathBuf}; + +pub fn main() { + // Put the linker script somewhere the linker can find it + let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + File::create(out.join("memory.x")) + .unwrap() + .write_all(include_bytes!("memory.x")) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + + println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rerun-if-changed=memory.x"); +} diff --git a/examples/bmp.rs b/ssd1331-examples/stm32f1-examples/examples/bmp.rs similarity index 95% rename from examples/bmp.rs rename to ssd1331-examples/stm32f1-examples/examples/bmp.rs index 0d211c6..82fa4e9 100644 --- a/examples/bmp.rs +++ b/ssd1331-examples/stm32f1-examples/examples/bmp.rs @@ -80,8 +80,8 @@ fn main() -> ! { let (w, h) = display.dimensions(); - let bmp = - Bmp::from_slice(include_bytes!("./rust-pride.bmp")).expect("Failed to load BMP image"); + let bmp = Bmp::from_slice(include_bytes!("../../../assets/rust-pride.bmp")) + .expect("Failed to load BMP image"); let im: Image> = Image::new(&bmp, Point::zero()); diff --git a/examples/graphics.rs b/ssd1331-examples/stm32f1-examples/examples/graphics.rs similarity index 100% rename from examples/graphics.rs rename to ssd1331-examples/stm32f1-examples/examples/graphics.rs diff --git a/examples/image.rs b/ssd1331-examples/stm32f1-examples/examples/image.rs similarity index 96% rename from examples/image.rs rename to ssd1331-examples/stm32f1-examples/examples/image.rs index 5b04f0a..a893ad7 100644 --- a/examples/image.rs +++ b/ssd1331-examples/stm32f1-examples/examples/image.rs @@ -85,7 +85,7 @@ fn main() -> ! { // Loads an 86x64px image encoded in LE (Little Endian) format. This image is a 16BPP image of // the Rust mascot, Ferris. - let im = ImageRawLE::new(include_bytes!("./ferris.raw"), 86); + let im = ImageRawLE::new(include_bytes!("../../../assets/ferris.raw"), 86); Image::new(&im, Point::new((96 - 86) / 2, 0)) .draw(&mut display) diff --git a/examples/pixelsquare.rs b/ssd1331-examples/stm32f1-examples/examples/pixelsquare.rs similarity index 100% rename from examples/pixelsquare.rs rename to ssd1331-examples/stm32f1-examples/examples/pixelsquare.rs diff --git a/examples/rotation.rs b/ssd1331-examples/stm32f1-examples/examples/rotation.rs similarity index 96% rename from examples/rotation.rs rename to ssd1331-examples/stm32f1-examples/examples/rotation.rs index 54009ba..aa69653 100644 --- a/examples/rotation.rs +++ b/ssd1331-examples/stm32f1-examples/examples/rotation.rs @@ -86,7 +86,7 @@ fn main() -> ! { // Load a 1BPP 64x64px image with LE (Little Endian) encoding of the Rust logo, white foreground // black background - let im = ImageRawLE::::new(include_bytes!("./rust.raw"), 64); + let im = ImageRawLE::::new(include_bytes!("../../../assets/rust.raw"), 64); // Use `color_converted` to create a wrapper that converts BinaryColors to Rgb565 colors to send // to the display. diff --git a/examples/text.rs b/ssd1331-examples/stm32f1-examples/examples/text.rs similarity index 100% rename from examples/text.rs rename to ssd1331-examples/stm32f1-examples/examples/text.rs diff --git a/ssd1331-examples/stm32f1-examples/memory.x b/ssd1331-examples/stm32f1-examples/memory.x new file mode 100644 index 0000000..b86bf59 --- /dev/null +++ b/ssd1331-examples/stm32f1-examples/memory.x @@ -0,0 +1,6 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + FLASH : ORIGIN = 0x00000000, LENGTH = 1024K + RAM : ORIGIN = 0x20000000, LENGTH = 256K +} From 8d428ccce13a0b2fbb2a5aa4e69917352f00fedf Mon Sep 17 00:00:00 2001 From: Jacob Rosenthal Date: Mon, 22 Nov 2021 09:33:08 -0700 Subject: [PATCH 6/7] fix stm32f1 memory.x --- ssd1331-examples/stm32f1-examples/memory.x | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ssd1331-examples/stm32f1-examples/memory.x b/ssd1331-examples/stm32f1-examples/memory.x index b86bf59..a120f83 100644 --- a/ssd1331-examples/stm32f1-examples/memory.x +++ b/ssd1331-examples/stm32f1-examples/memory.x @@ -1,6 +1,6 @@ +/* Linker script for the STM32F103C8T6 */ MEMORY { - /* NOTE 1 K = 1 KiBi = 1024 bytes */ - FLASH : ORIGIN = 0x00000000, LENGTH = 1024K - RAM : ORIGIN = 0x20000000, LENGTH = 256K -} + FLASH : ORIGIN = 0x08000000, LENGTH = 128K + RAM : ORIGIN = 0x20000000, LENGTH = 20K +} \ No newline at end of file From 785abea1cb927bb874f214ab9c7c97a3851ba71c Mon Sep 17 00:00:00 2001 From: Jacob Rosenthal Date: Sun, 22 May 2022 12:22:49 -0700 Subject: [PATCH 7/7] update for embedded-hal-async and embassy --- Cargo.toml | 4 ++-- src/command.rs | 4 ++-- src/display.rs | 6 +++--- ssd1331-examples/embassy-nrf/Cargo.toml | 10 +++++++--- ssd1331-examples/embassy-nrf/examples/bmp.rs | 14 ++++++-------- ssd1331-examples/embassy-nrf/rust-toolchain | 6 +++--- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 13bbe21..c3fbb06 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ circle-ci = { repository = "jamwaffles/ssd1331", branch = "master" } [dependencies] embedded-hal = "0.2.3" embedded-graphics-core = { version = "0.3.2", optional = true } -embassy-traits = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", optional = true } +embedded-hal-async = { git = "https://github.com/rust-embedded/embedded-hal" } [dev-dependencies] cortex-m = "0.7.3" @@ -35,7 +35,7 @@ stm32f1xx-hal = { version = "0.7.0", features = ["rt", "stm32f103"] } [features] default = ["graphics"] graphics = ["embedded-graphics-core"] -embassy-async = ["embassy-traits"] +embedded-async = [] [profile.dev] codegen-units = 1 diff --git a/src/command.rs b/src/command.rs index 5759ee0..12bcb6a 100644 --- a/src/command.rs +++ b/src/command.rs @@ -51,14 +51,14 @@ pub enum Command { impl Command { /// Send command to SSD1331 - #[cfg(feature = "embassy-async")] + #[cfg(feature = "embedded-async")] pub async fn send_async( self, spi: &mut SPI, dc: &mut DC, ) -> Result<(), Error> where - SPI: embassy_traits::spi::Write + embassy_traits::spi::Spi, + SPI: embedded_hal_async::spi::SpiBusWrite, DC: OutputPin, { // Transform command into a fixed size array of 7 u8 and the real length for sending diff --git a/src/display.rs b/src/display.rs index 3f548c3..aabe339 100644 --- a/src/display.rs +++ b/src/display.rs @@ -99,10 +99,10 @@ pub struct Ssd1331 { dc: DC, } -#[cfg(feature = "embassy-async")] +#[cfg(feature = "embedded-async")] impl Ssd1331 where - SPI: embassy_traits::spi::Write + embassy_traits::spi::Spi, + SPI: embedded_hal_async::spi::SpiBusWrite, DC: OutputPin, { /// Send the full framebuffer to the display @@ -123,7 +123,7 @@ where // 1 = data, 0 = command self.dc.set_high().map_err(Error::Pin)?; - embassy_traits::spi::Write::write(&mut self.spi, &self.buffer) + embedded_hal_async::spi::SpiBusWrite::write(&mut self.spi, &self.buffer) .await .map_err(Error::Comm) } diff --git a/ssd1331-examples/embassy-nrf/Cargo.toml b/ssd1331-examples/embassy-nrf/Cargo.toml index 0307be2..89b631a 100644 --- a/ssd1331-examples/embassy-nrf/Cargo.toml +++ b/ssd1331-examples/embassy-nrf/Cargo.toml @@ -4,7 +4,8 @@ version = "0.1.0" edition = "2021" [dependencies] -embedded-hal = "0.2.6" +embedded-hal = "0.2.7" +embedded-hal-async = { version = "0.1.0-alpha.0" } embedded-graphics-core = { version = "0.3.2", optional = true } cortex-m = "0.7.3" cortex-m-rt = "0.6.11" @@ -13,17 +14,20 @@ tinybmp = "0.3.1" futures = { version = "0.3.17", default-features = false } embassy = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy" } embassy-nrf = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = [ + "nightly", + "unstable-traits", "nrf52840", "gpiote", "time-driver-rtc1" ] } -ssd1331 = { path = "../../", features = ["embassy-async"] } +ssd1331 = { path = "../../", features = ["embedded-async"] } [patch.crates-io] embassy = { git = "https://github.com/embassy-rs/embassy" } embassy-nrf = { git = "https://github.com/embassy-rs/embassy" } embassy-macros = { git = "https://github.com/embassy-rs/embassy" } -embassy-traits = { git = "https://github.com/embassy-rs/embassy" } +embedded-hal-async = { git = "https://github.com/rust-embedded/embedded-hal" } +embedded-hal = { git = "https://github.com/rust-embedded/embedded-hal" } [profile.dev] codegen-units = 1 diff --git a/ssd1331-examples/embassy-nrf/examples/bmp.rs b/ssd1331-examples/embassy-nrf/examples/bmp.rs index abe26ef..ec492ff 100644 --- a/ssd1331-examples/embassy-nrf/examples/bmp.rs +++ b/ssd1331-examples/embassy-nrf/examples/bmp.rs @@ -11,11 +11,10 @@ use core::future::pending; use embassy::interrupt::InterruptExt; use embassy::time::{Duration, Timer}; use embassy::util::Forever; -use embassy_nrf::gpio::{self, AnyPin, Level, NoPin, Output, OutputDrive, Pin}; +use embassy_nrf::gpio::{self, AnyPin, Level, Output, OutputDrive, Pin}; use embassy_nrf::{interrupt, spim}; use embedded_graphics::prelude::*; use embedded_graphics::{image::Image, pixelcolor::Rgb565}; -use embedded_hal::digital::v2::OutputPin; use ssd1331::{DisplayRotation, Ssd1331}; use tinybmp::Bmp; @@ -48,9 +47,9 @@ fn main() -> ! { #[embassy::task] async fn blinky_task(mut green: gpio::Output<'static, AnyPin>) { loop { - green.set_high().unwrap(); + green.set_high(); Timer::after(Duration::from_millis(300)).await; - green.set_low().unwrap(); + green.set_low(); Timer::after(Duration::from_millis(1000)).await; } } @@ -67,11 +66,10 @@ pub async fn display_task() { let mut spim_config = spim::Config::default(); spim_config.frequency = spim::Frequency::M16; - let spim = spim::Spim::new( + let spim = spim::Spim::new_txonly( &mut dp.SPI3, &mut spim_irq, &mut dp.P0_21, - NoPin, &mut dp.P0_17, spim_config, ); @@ -80,9 +78,9 @@ pub async fn display_task() { let dc = Output::new(&mut dp.P0_15, Level::High, OutputDrive::Standard); let mut display = Ssd1331::new(spim, dc, DisplayRotation::Rotate0); Timer::after(Duration::from_millis(1)).await; - rst.set_low().ok(); + rst.set_low(); Timer::after(Duration::from_millis(1)).await; - rst.set_high().ok(); + rst.set_high(); display.init().unwrap(); let (w, h) = display.dimensions(); diff --git a/ssd1331-examples/embassy-nrf/rust-toolchain b/ssd1331-examples/embassy-nrf/rust-toolchain index ed08935..05204be 100644 --- a/ssd1331-examples/embassy-nrf/rust-toolchain +++ b/ssd1331-examples/embassy-nrf/rust-toolchain @@ -1,6 +1,6 @@ # Before upgrading check that everything is available on all tier1 targets here: # https://rust-lang.github.io/rustup-components-history [toolchain] -channel = "nightly-2021-10-16" -components = ["rust-src", "rustfmt"] -targets = ["thumbv7em-none-eabihf"] +channel = "nightly-2022-04-24" +components = [ "rust-src", "rustfmt" ] +targets = ["thumbv7em-none-eabi"]