diff --git a/.cargo/config b/.cargo/config.toml similarity index 100% rename from .cargo/config rename to .cargo/config.toml diff --git a/Cargo.toml b/Cargo.toml index ef5ad22..f9ffa6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,23 +13,23 @@ 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-graphics-core = { version = "0.3.2", optional = true } +embedded-hal = "1.0.0" +embedded-graphics-core = { version = "0.4.0", optional = true } [dev-dependencies] -cortex-m = "0.7.3" -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" ] } +cortex-m = "0.7.7" +cortex-m-rt = "0.7.5" +panic-semihosting = "0.6.0" +embedded-graphics = "0.8.1" +tinybmp = "0.6.0" +stm32f1xx-hal = { version = "0.10.0", features = ["rt", "stm32f103"] } [features] default = ["graphics"] diff --git a/examples/bmp.rs b/examples/bmp.rs index 0d211c6..639d4c8 100644 --- a/examples/bmp.rs +++ b/examples/bmp.rs @@ -22,12 +22,12 @@ #![no_std] #![no_main] -use cortex_m_rt::{entry, exception, ExceptionFrame}; +use cortex_m::delay::Delay; +use cortex_m_rt::{entry, exception}; use embedded_graphics::{geometry::Point, image::Image, pixelcolor::Rgb565, prelude::*}; use panic_semihosting as _; use ssd1331::{DisplayRotation, Ssd1331}; use stm32f1xx_hal::{ - delay::Delay, prelude::*, spi::{Mode, Phase, Polarity, Spi}, stm32, @@ -44,22 +44,22 @@ fn main() -> ! { let clocks = rcc.cfgr.freeze(&mut flash.acr); - let mut afio = dp.AFIO.constrain(&mut rcc.apb2); + let mut afio = dp.AFIO.constrain(); - let mut gpioa = dp.GPIOA.split(&mut rcc.apb2); - let mut gpiob = dp.GPIOB.split(&mut rcc.apb2); + let mut gpioa = dp.GPIOA.split(); + let mut gpiob = dp.GPIOB.split(); // SPI1 let sck = gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl); let miso = gpioa.pa6; let mosi = gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl); - let mut delay = Delay::new(cp.SYST, clocks); + let mut delay = Delay::new(cp.SYST, clocks.hclk().to_Hz()); let mut rst = gpiob.pb0.into_push_pull_output(&mut gpiob.crl); let dc = gpiob.pb1.into_push_pull_output(&mut gpiob.crl); - let spi = Spi::spi1( + let mut spi = Spi::spi1( dp.SPI1, (sck, miso, mosi), &mut afio.mapr, @@ -67,9 +67,8 @@ fn main() -> ! { polarity: Polarity::IdleLow, phase: Phase::CaptureOnFirstTransition, }, - 8.mhz(), + 8.MHz(), clocks, - &mut rcc.apb2, ); let mut display = Ssd1331::new(spi, dc, DisplayRotation::Rotate0); diff --git a/examples/graphics.rs b/examples/graphics.rs index 6c01e40..728fc6a 100644 --- a/examples/graphics.rs +++ b/examples/graphics.rs @@ -46,10 +46,10 @@ fn main() -> ! { let clocks = rcc.cfgr.freeze(&mut flash.acr); - let mut afio = dp.AFIO.constrain(&mut rcc.apb2); + let mut afio = dp.AFIO.constrain(); - let mut gpioa = dp.GPIOA.split(&mut rcc.apb2); - let mut gpiob = dp.GPIOB.split(&mut rcc.apb2); + let mut gpioa = dp.GPIOA.split(); + let mut gpiob = dp.GPIOB.split(); // SPI1 let sck = gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl); @@ -71,7 +71,6 @@ fn main() -> ! { }, 8.mhz(), clocks, - &mut rcc.apb2, ); let mut display = Ssd1331::new(spi, dc, Rotate0); @@ -105,6 +104,6 @@ fn main() -> ! { } #[exception] -fn HardFault(ef: &ExceptionFrame) -> ! { +unsafe fn HardFault(ef: &ExceptionFrame) -> ! { panic!("{:#?}", ef); } diff --git a/examples/rotation.rs b/examples/rotation.rs index 54009ba..81aa440 100644 --- a/examples/rotation.rs +++ b/examples/rotation.rs @@ -46,10 +46,10 @@ fn main() -> ! { let clocks = rcc.cfgr.freeze(&mut flash.acr); - let mut afio = dp.AFIO.constrain(&mut rcc.apb2); + let mut afio = dp.AFIO.constrain(); - let mut gpioa = dp.GPIOA.split(&mut rcc.apb2); - let mut gpiob = dp.GPIOB.split(&mut rcc.apb2); + let mut gpioa = dp.GPIOA.split(); + let mut gpiob = dp.GPIOB.split(); // SPI1 let sck = gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl); @@ -71,7 +71,6 @@ fn main() -> ! { }, 8.mhz(), clocks, - &mut rcc.apb2, ); // Initialise the display with a default rotation of 90 degrees @@ -98,6 +97,6 @@ fn main() -> ! { } #[exception] -fn HardFault(ef: &ExceptionFrame) -> ! { +unsafe fn HardFault(ef: &ExceptionFrame) -> ! { panic!("{:#?}", ef); } diff --git a/examples/text.rs b/examples/text.rs index 06aa44a..66f14d7 100644 --- a/examples/text.rs +++ b/examples/text.rs @@ -50,10 +50,10 @@ fn main() -> ! { let clocks = rcc.cfgr.freeze(&mut flash.acr); - let mut afio = dp.AFIO.constrain(&mut rcc.apb2); + let mut afio = dp.AFIO.constrain(); - let mut gpioa = dp.GPIOA.split(&mut rcc.apb2); - let mut gpiob = dp.GPIOB.split(&mut rcc.apb2); + let mut gpioa = dp.GPIOA.split(); + let mut gpiob = dp.GPIOB.split(); // SPI1 let sck = gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl); @@ -65,7 +65,7 @@ fn main() -> ! { let mut rst = gpiob.pb0.into_push_pull_output(&mut gpiob.crl); let dc = gpiob.pb1.into_push_pull_output(&mut gpiob.crl); - let spi = Spi::spi1( + let spi = Spi::new( dp.SPI1, (sck, miso, mosi), &mut afio.mapr, @@ -73,12 +73,11 @@ fn main() -> ! { polarity: Polarity::IdleLow, phase: Phase::CaptureOnFirstTransition, }, - 8.mhz(), + 8.MHz(), clocks, - &mut rcc.apb2, ); - let mut display = Ssd1331::new(spi, dc, Rotate0); + let mut display = Ssd1331::new(spi.into(), dc, Rotate0); display.reset(&mut rst, &mut delay).unwrap(); display.init().unwrap(); @@ -115,6 +114,6 @@ fn main() -> ! { } #[exception] -fn HardFault(ef: &ExceptionFrame) -> ! { +unsafe fn HardFault(ef: &ExceptionFrame) -> ! { panic!("{:#?}", ef); } diff --git a/src/command.rs b/src/command.rs index 7832d33..3988ac3 100644 --- a/src/command.rs +++ b/src/command.rs @@ -1,7 +1,8 @@ // Shamefully taken from https://github.com/EdgewaterDevelopment/rust-ssd1331 use crate::error::Error; -use embedded_hal::digital::v2::OutputPin; +use embedded_hal::digital::OutputPin; +use hal::spi::SpiBus; /// SSD1331 Commands #[derive(Debug)] @@ -57,7 +58,7 @@ impl Command { dc: &mut DC, ) -> Result<(), Error> where - SPI: hal::blocking::spi::Write, + SPI: SpiBus, 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 19753a9..1427683 100644 --- a/src/display.rs +++ b/src/display.rs @@ -1,4 +1,4 @@ -use hal::{blocking::delay::DelayMs, digital::v2::OutputPin}; +use hal::{delay::DelayNs, digital::OutputPin, spi::SpiBus}; use crate::{ command::{AddressIncrementMode, ColorMode, Command, VcomhLevel}, @@ -101,7 +101,7 @@ pub struct Ssd1331 { impl Ssd1331 where - SPI: hal::blocking::spi::Write, + SPI: SpiBus, DC: OutputPin, { /// Create new display instance @@ -161,7 +161,7 @@ where ) -> Result<(), Error> where RST: OutputPin, - DELAY: DelayMs, + DELAY: DelayNs, { rst.set_high().map_err(Error::Pin)?; delay.delay_ms(1); @@ -195,7 +195,7 @@ where end: (u8, u8), ) -> Result<(), Error> { Command::ColumnAddress(start.0, end.0).send(&mut self.spi, &mut self.dc)?; - Command::RowAddress(start.1.into(), (end.1).into()).send(&mut self.spi, &mut self.dc)?; + Command::RowAddress(start.1, end.1).send(&mut self.spi, &mut self.dc)?; Ok(()) } @@ -373,7 +373,7 @@ use embedded_graphics_core::{ #[cfg(feature = "graphics")] impl DrawTarget for Ssd1331 where - SPI: hal::blocking::spi::Write, + SPI: SpiBus, DC: OutputPin, { type Color = Rgb565; @@ -399,7 +399,7 @@ where #[cfg(feature = "graphics")] impl OriginDimensions for Ssd1331 where - SPI: hal::blocking::spi::Write, + SPI: SpiBus, DC: OutputPin, { fn size(&self) -> Size { diff --git a/src/test_helpers.rs b/src/test_helpers.rs index 9ac805e..8ad1847 100644 --- a/src/test_helpers.rs +++ b/src/test_helpers.rs @@ -1,42 +1,42 @@ //! Helpers for use in examples and tests -use embedded_hal::{ - blocking::spi::{self, Transfer}, - digital::v2::OutputPin, -}; +use hal::{digital::OutputPin, spi::SpiDevice}; #[allow(dead_code)] #[derive(Debug, Clone, Copy)] pub struct Spi; -impl spi::Write for Spi { - type Error = (); - - fn write(&mut self, _buf: &[u8]) -> Result<(), ()> { +impl SpiDevice for Spi { + fn transaction( + &mut self, + _operations: &mut [hal::spi::Operation<'_, u8>], + ) -> Result<(), Self::Error> { Ok(()) } -} -impl Transfer for Spi { - type Error = (); - - fn transfer<'a>(&mut self, buf: &'a mut [u8]) -> Result<&'a [u8], ()> { - Ok(buf) + fn transfer(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Self::Error> { + self.transaction(&mut [hal::spi::Operation::Transfer(read, write)]) } } +impl hal::spi::ErrorType for Spi { + type Error = hal::spi::ErrorKind; +} + #[allow(dead_code)] #[derive(Debug, Clone, Copy)] pub struct Pin; -impl OutputPin for Pin { - type Error = (); +impl hal::digital::ErrorType for Pin { + type Error = hal::digital::ErrorKind; +} - fn set_high(&mut self) -> Result<(), ()> { +impl OutputPin for Pin { + fn set_low(&mut self) -> Result<(), Self::Error> { Ok(()) } - fn set_low(&mut self) -> Result<(), ()> { + fn set_high(&mut self) -> Result<(), Self::Error> { Ok(()) } }