diff --git a/Cargo.toml b/Cargo.toml index 21812c4..0af6f14 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [package] +edition = "2018" authors = ["Daniel Egger "] categories = [ "embedded", @@ -17,12 +18,12 @@ license = "0BSD" name = "stm32f0xx-hal" readme = "README.md" repository = "https://github.com/stm32-rs/stm32f0xx-hal" -version = "0.7.0" +version = "0.8.0" [dependencies] bare-metal = { version = "0.2.4", features = ["const-fn"] } cortex-m = "0.5.8" -cortex-m-rt = "0.6.5" +cortex-m-rt = "0.6.6" nb = "0.1.1" void = { version = "1.0.2", default-features = false } stm32f0 = "0.4.0" @@ -36,7 +37,7 @@ features = ["unproven"] version = "0.2.2" [dev-dependencies] -ina260 = "0.2.3" +ina260 = "0.2.6" numtoa = "0.2.3" panic-halt = "0.2.0" diff --git a/examples/blinky.rs b/examples/blinky.rs index fca9c2c..ec81de5 100644 --- a/examples/blinky.rs +++ b/examples/blinky.rs @@ -1,13 +1,12 @@ #![no_main] #![no_std] -extern crate cortex_m_rt; -extern crate panic_halt; +use panic_halt; -extern crate stm32f0xx_hal as hal; +use stm32f0xx_hal as hal; -use hal::prelude::*; -use hal::stm32; +use crate::hal::prelude::*; +use crate::hal::stm32; use cortex_m_rt::entry; diff --git a/examples/blinky_delay.rs b/examples/blinky_delay.rs index 3d4ea28..60eefa5 100644 --- a/examples/blinky_delay.rs +++ b/examples/blinky_delay.rs @@ -1,15 +1,13 @@ #![no_main] #![no_std] -extern crate cortex_m; -extern crate cortex_m_rt; -extern crate panic_halt; +use panic_halt; -extern crate stm32f0xx_hal as hal; +use stm32f0xx_hal as hal; -use hal::delay::Delay; -use hal::prelude::*; -use hal::stm32; +use crate::hal::delay::Delay; +use crate::hal::prelude::*; +use crate::hal::stm32; use cortex_m::peripheral::Peripherals; use cortex_m_rt::entry; @@ -23,7 +21,7 @@ fn main() -> ! { let mut led = gpioa.pa1.into_push_pull_output(); /* Constrain clocking registers */ - let mut rcc = p.RCC.constrain(); + let rcc = p.RCC.constrain(); /* Configure clock to 8 MHz (i.e. the default) and freeze it */ let clocks = rcc.cfgr.sysclk(8.mhz()).freeze(); diff --git a/examples/flash_systick.rs b/examples/flash_systick.rs index 232b041..bc050f0 100644 --- a/examples/flash_systick.rs +++ b/examples/flash_systick.rs @@ -1,15 +1,13 @@ #![no_main] #![no_std] -extern crate cortex_m; -extern crate cortex_m_rt; -extern crate panic_halt; +use panic_halt; -extern crate stm32f0xx_hal as hal; +use stm32f0xx_hal as hal; -use hal::gpio::*; -use hal::prelude::*; -use hal::stm32; +use crate::hal::gpio::*; +use crate::hal::prelude::*; +use crate::hal::stm32; use cortex_m::interrupt::Mutex; use cortex_m::peripheral::syst::SystClkSource::Core; @@ -25,12 +23,12 @@ static GPIO: Mutex>>>> = Mutex::new(R fn main() -> ! { if let (Some(p), Some(cp)) = (stm32::Peripherals::take(), Peripherals::take()) { let gpioa = p.GPIOA.split(); - let mut rcc = p.RCC.constrain(); + let rcc = p.RCC.constrain(); let _ = rcc.cfgr.sysclk(48.mhz()).freeze(); let mut syst = cp.SYST; /* (Re-)configure PA1 as output */ - let mut led = gpioa.pa1.into_push_pull_output(); + let led = gpioa.pa1.into_push_pull_output(); cortex_m::interrupt::free(move |cs| { *GPIO.borrow(cs).borrow_mut() = Some(led); diff --git a/examples/i2c_hal_ina260reader.rs b/examples/i2c_hal_ina260reader.rs index ed24c46..e5ec901 100644 --- a/examples/i2c_hal_ina260reader.rs +++ b/examples/i2c_hal_ina260reader.rs @@ -1,18 +1,13 @@ #![no_main] #![no_std] -extern crate cortex_m; -extern crate cortex_m_rt; -extern crate embedded_hal; -extern crate panic_halt; +use panic_halt; -extern crate stm32f0xx_hal as hal; +use stm32f0xx_hal as hal; -extern crate numtoa; - -use hal::i2c::*; -use hal::prelude::*; -use hal::stm32; +use crate::hal::i2c::*; +use crate::hal::prelude::*; +use crate::hal::stm32; use embedded_hal::blocking::i2c::Write; @@ -45,7 +40,7 @@ const SSD1306_CHARGE_PUMP: u8 = 0x8D; fn main() -> ! { if let Some(p) = stm32::Peripherals::take() { let gpiof = p.GPIOF.split(); - let mut rcc = p.RCC.constrain(); + let rcc = p.RCC.constrain(); let _ = rcc.cfgr.freeze(); let scl = gpiof diff --git a/examples/i2c_hal_ina260serial.rs b/examples/i2c_hal_ina260serial.rs index ba70b17..ec707fd 100644 --- a/examples/i2c_hal_ina260serial.rs +++ b/examples/i2c_hal_ina260serial.rs @@ -1,20 +1,14 @@ #![no_main] #![no_std] -extern crate cortex_m; -extern crate cortex_m_rt; -extern crate embedded_hal; -extern crate panic_halt; +use panic_halt; -extern crate stm32f0xx_hal as hal; +use stm32f0xx_hal as hal; -extern crate ina260; -extern crate numtoa; - -use hal::i2c::*; -use hal::prelude::*; -use hal::serial::*; -use hal::stm32; +use crate::hal::i2c::*; +use crate::hal::prelude::*; +use crate::hal::serial::*; +use crate::hal::stm32; use numtoa::NumToA; @@ -28,7 +22,7 @@ fn main() -> ! { if let Some(p) = stm32::Peripherals::take() { let gpiof = p.GPIOF.split(); let gpioa = p.GPIOA.split(); - let mut clocks = p.RCC.constrain().cfgr.freeze(); + let clocks = p.RCC.constrain().cfgr.freeze(); /* Initialise serial pins */ let tx = gpioa.pa9.into_alternate_af1(); @@ -51,7 +45,7 @@ fn main() -> ! { .set_open_drain(); /* Setup I2C1 */ - let mut i2c = I2c::i2c1(p.I2C1, (scl, sda), 1.khz()); + let i2c = I2c::i2c1(p.I2C1, (scl, sda), 1.khz()); let mut ina260 = INA260::new(i2c, 0x40).unwrap(); /* Endless loop */ diff --git a/examples/i2c_hal_ssd1306alphabeter.rs b/examples/i2c_hal_ssd1306alphabeter.rs index d707ffc..c7ee113 100644 --- a/examples/i2c_hal_ssd1306alphabeter.rs +++ b/examples/i2c_hal_ssd1306alphabeter.rs @@ -1,16 +1,13 @@ #![no_main] #![no_std] -extern crate cortex_m; -extern crate cortex_m_rt; -extern crate embedded_hal; -extern crate panic_halt; +use panic_halt; -extern crate stm32f0xx_hal as hal; +use stm32f0xx_hal as hal; -use hal::i2c::*; -use hal::prelude::*; -use hal::stm32; +use crate::hal::i2c::*; +use crate::hal::prelude::*; +use crate::hal::stm32; use cortex_m_rt::entry; use embedded_hal::blocking::i2c::Write; @@ -40,7 +37,7 @@ const SSD1306_CHARGE_PUMP: u8 = 0x8D; fn main() -> ! { if let Some(p) = stm32::Peripherals::take() { let gpiof = p.GPIOF.split(); - let mut rcc = p.RCC.constrain(); + let rcc = p.RCC.constrain(); let _ = rcc.cfgr.freeze(); let scl = gpiof diff --git a/examples/led_hal_button_irq.rs b/examples/led_hal_button_irq.rs index 021484d..6337a0b 100644 --- a/examples/led_hal_button_irq.rs +++ b/examples/led_hal_button_irq.rs @@ -1,23 +1,21 @@ #![no_main] #![no_std] -extern crate cortex_m; -extern crate cortex_m_rt; -extern crate panic_halt; +use panic_halt; -#[macro_use] -extern crate stm32f0xx_hal as hal; +use stm32f0xx_hal as hal; -use hal::delay::Delay; -use hal::gpio::*; -use hal::prelude::*; +use crate::hal::delay::Delay; +use crate::hal::gpio::*; +use crate::hal::prelude::*; use cortex_m::interrupt::Mutex; use cortex_m::peripheral::Peripherals as c_m_Peripherals; use cortex_m_rt::entry; -pub use hal::stm32; -pub use hal::stm32::*; +pub use crate::hal::interrupt; +pub use crate::hal::stm32; +pub use crate::hal::stm32::*; use core::cell::RefCell; use core::ops::DerefMut; @@ -39,7 +37,7 @@ fn main() -> ! { let exti = p.EXTI; // Enable clock for SYSCFG - let mut rcc = p.RCC; + let rcc = p.RCC; rcc.apb2enr.modify(|_, w| w.syscfgen().set_bit()); // Configure PB1 as input (button) @@ -55,7 +53,7 @@ fn main() -> ! { let clocks = rcc.constrain().cfgr.sysclk(8.mhz()).freeze(); // Initialise delay provider - let mut delay = Delay::new(cp.SYST, clocks); + let delay = Delay::new(cp.SYST, clocks); // Enable external interrupt for PB1 syscfg diff --git a/examples/serial_echo.rs b/examples/serial_echo.rs index 72f81a7..f6d480b 100644 --- a/examples/serial_echo.rs +++ b/examples/serial_echo.rs @@ -1,19 +1,15 @@ #![no_main] #![no_std] -extern crate cortex_m; -extern crate cortex_m_rt; -extern crate panic_halt; +use panic_halt; -extern crate stm32f0xx_hal as hal; +use stm32f0xx_hal as hal; -use hal::prelude::*; -use hal::stm32; +use crate::hal::prelude::*; +use crate::hal::serial::Serial; +use crate::hal::stm32; -#[macro_use(block)] -extern crate nb; - -use hal::serial::Serial; +use nb::block; use cortex_m_rt::entry; @@ -21,7 +17,7 @@ use cortex_m_rt::entry; fn main() -> ! { if let Some(p) = stm32::Peripherals::take() { let gpioa = p.GPIOA.split(); - let mut rcc = p.RCC.constrain(); + let rcc = p.RCC.constrain(); let clocks = rcc.cfgr.sysclk(48.mhz()).freeze(); let tx = gpioa.pa9.into_alternate_af1(); diff --git a/examples/spi_hal_apa102c.rs b/examples/spi_hal_apa102c.rs index bc62a70..df8d5c6 100644 --- a/examples/spi_hal_apa102c.rs +++ b/examples/spi_hal_apa102c.rs @@ -1,16 +1,14 @@ #![no_main] #![no_std] -extern crate cortex_m; -extern crate cortex_m_rt; -extern crate panic_halt; +use panic_halt; -extern crate stm32f0xx_hal as hal; +use stm32f0xx_hal as hal; -use hal::prelude::*; -use hal::spi::Spi; -use hal::spi::{Mode, Phase, Polarity}; -use hal::stm32; +use crate::hal::prelude::*; +use crate::hal::spi::Spi; +use crate::hal::spi::{Mode, Phase, Polarity}; +use crate::hal::stm32; use cortex_m_rt::entry; @@ -22,9 +20,9 @@ fn main() -> ! { }; if let Some(p) = stm32::Peripherals::take() { - let mut rcc = p.RCC.constrain(); + let rcc = p.RCC.constrain(); let clocks = rcc.cfgr.freeze(); - let mut gpioa = p.GPIOA.split(); + let gpioa = p.GPIOA.split(); // Configure pins for SPI let sck = gpioa.pa5.into_alternate_af0(); diff --git a/src/delay.rs b/src/delay.rs index 2b1c5b4..1f960f3 100644 --- a/src/delay.rs +++ b/src/delay.rs @@ -4,8 +4,8 @@ use cast::u32; use cortex_m::peripheral::syst::SystClkSource; use cortex_m::peripheral::SYST; -use hal::blocking::delay::{DelayMs, DelayUs}; -use rcc::Clocks; +use crate::rcc::Clocks; +use embedded_hal::blocking::delay::{DelayMs, DelayUs}; /// System timer (SysTick) as a delay provider pub struct Delay { diff --git a/src/gpio.rs b/src/gpio.rs index bbaac1e..cc159cc 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -57,10 +57,10 @@ macro_rules! gpio { pub mod $gpiox { use core::marker::PhantomData; - use hal::digital::{InputPin, OutputPin, StatefulOutputPin}; - use stm32::$GPIOX; + use embedded_hal::digital::{InputPin, OutputPin, StatefulOutputPin}; + use crate::stm32::$GPIOX; - use stm32::RCC; + use crate::stm32::RCC; use super::{ Alternate, Floating, GpioExt, Input, OpenDrain, Output, PullDown, PullUp, PushPull, AF0, AF1, AF2, AF3, AF4, AF5, AF6, AF7, diff --git a/src/i2c.rs b/src/i2c.rs index e3293b1..8a47dd3 100644 --- a/src/i2c.rs +++ b/src/i2c.rs @@ -1,13 +1,13 @@ -use stm32::{I2C1, RCC}; +use crate::stm32::{I2C1, RCC}; -use hal::blocking::i2c::{Write, WriteRead}; +use embedded_hal::blocking::i2c::{Write, WriteRead}; use core::cmp; -use gpio::gpioa::{PA10, PA11, PA12, PA9}; -use gpio::gpiob::{PB10, PB11, PB13, PB14, PB6, PB7, PB8, PB9}; -use gpio::gpiof::{PF0, PF1}; -use gpio::{Alternate, AF1, AF4, AF5}; -use time::{KiloHertz, U32Ext}; +use crate::gpio::gpioa::{PA10, PA11, PA12, PA9}; +use crate::gpio::gpiob::{PB10, PB11, PB13, PB14, PB6, PB7, PB8, PB9}; +use crate::gpio::gpiof::{PF0, PF1}; +use crate::gpio::{Alternate, AF1, AF4, AF5}; +use crate::time::{KiloHertz, U32Ext}; /// I2C abstraction pub struct I2c { diff --git a/src/lib.rs b/src/lib.rs index 46f83ae..830e15a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,19 +1,11 @@ #![no_std] #![allow(non_camel_case_types)] -extern crate bare_metal; -extern crate cast; -extern crate cortex_m; -pub extern crate embedded_hal as hal; +use bare_metal; +use cast; +use cortex_m; -pub extern crate void; -pub use void::Void; - -#[macro_use(block)] -pub extern crate nb; -pub use nb::block; - -pub extern crate stm32f0; +pub use stm32f0; #[cfg(feature = "stm32f042")] pub use stm32f0::stm32f0x2 as stm32; diff --git a/src/prelude.rs b/src/prelude.rs index 261f0a8..4486f49 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -1,5 +1,5 @@ -pub use hal::prelude::*; +pub use embedded_hal::prelude::*; -pub use gpio::GpioExt as _stm32f042_hal_gpio_GpioExt; -pub use rcc::RccExt as _stm32f042_hal_rcc_RccExt; -pub use time::U32Ext as _stm32f042_hal_time_U32Ext; +pub use crate::gpio::GpioExt as _stm32f042_hal_gpio_GpioExt; +pub use crate::rcc::RccExt as _stm32f042_hal_rcc_RccExt; +pub use crate::time::U32Ext as _stm32f042_hal_time_U32Ext; diff --git a/src/rcc.rs b/src/rcc.rs index d582b9c..695fffd 100644 --- a/src/rcc.rs +++ b/src/rcc.rs @@ -1,9 +1,9 @@ use core::cmp; use cast::u32; -use stm32::{FLASH, RCC}; +use crate::stm32::{FLASH, RCC}; -use time::Hertz; +use crate::time::Hertz; /// Extension trait that constrains the `RCC` peripheral pub trait RccExt { diff --git a/src/serial.rs b/src/serial.rs index cd6a347..6905477 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -2,18 +2,17 @@ use core::fmt::{Result, Write}; use core::marker::PhantomData; use core::ptr; -use hal; -use hal::prelude::*; -use nb; +use embedded_hal::prelude::*; +use nb::block; use void::Void; -use stm32::{RCC, USART1, USART2}; +use crate::stm32::{RCC, USART1, USART2}; -use gpio::gpioa::{PA10, PA14, PA15, PA2, PA3, PA9}; -use gpio::gpiob::{PB6, PB7}; -use gpio::{Alternate, AF0, AF1}; -use rcc::Clocks; -use time::Bps; +use crate::gpio::gpioa::{PA10, PA14, PA15, PA2, PA3, PA9}; +use crate::gpio::gpiob::{PB6, PB7}; +use crate::gpio::{Alternate, AF0, AF1}; +use crate::rcc::Clocks; +use crate::time::Bps; /// Interrupt event pub enum Event { @@ -107,7 +106,7 @@ impl Serial { } } -impl hal::serial::Read for Rx { +impl embedded_hal::serial::Read for Rx { type Error = Error; fn read(&mut self) -> nb::Result { @@ -131,7 +130,7 @@ impl hal::serial::Read for Rx { } } -impl hal::serial::Write for Tx { +impl embedded_hal::serial::Write for Tx { type Error = Void; fn flush(&mut self) -> nb::Result<(), Self::Error> { @@ -201,7 +200,7 @@ impl Serial { } } -impl hal::serial::Read for Rx { +impl embedded_hal::serial::Read for Rx { type Error = Error; fn read(&mut self) -> nb::Result { @@ -225,7 +224,7 @@ impl hal::serial::Read for Rx { } } -impl hal::serial::Write for Tx { +impl embedded_hal::serial::Write for Tx { type Error = Void; fn flush(&mut self) -> nb::Result<(), Self::Error> { @@ -256,14 +255,10 @@ impl hal::serial::Write for Tx { impl Write for Tx where - Tx: hal::serial::Write, + Tx: embedded_hal::serial::Write, { fn write_str(&mut self, s: &str) -> Result { - let _ = s - .as_bytes() - .iter() - .map(|c| block!(self.write(*c))) - .last(); + let _ = s.as_bytes().iter().map(|c| block!(self.write(*c))).last(); Ok(()) } } diff --git a/src/spi.rs b/src/spi.rs index 4cd3352..0703f47 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -2,15 +2,15 @@ use core::ptr; use nb; -pub use hal::spi::{Mode, Phase, Polarity}; -use rcc::Clocks; +pub use embedded_hal::spi::{Mode, Phase, Polarity}; -use stm32::{RCC, SPI1}; +use crate::stm32::{RCC, SPI1}; -use gpio::gpioa::{PA5, PA6, PA7}; -use gpio::gpiob::{PB3, PB4, PB5}; -use gpio::{Alternate, AF0}; -use time::Hertz; +use crate::gpio::gpioa::{PA5, PA6, PA7}; +use crate::gpio::gpiob::{PB3, PB4, PB5}; +use crate::gpio::{Alternate, AF0}; +use crate::rcc::Clocks; +use crate::time::Hertz; /// SPI error #[derive(Debug)] @@ -126,7 +126,7 @@ impl Spi { } } -impl ::hal::spi::FullDuplex for Spi { +impl ::embedded_hal::spi::FullDuplex for Spi { type Error = Error; fn read(&mut self) -> nb::Result { @@ -166,5 +166,5 @@ impl ::hal::spi::FullDuplex for Spi { } } -impl ::hal::blocking::spi::transfer::Default for Spi {} -impl ::hal::blocking::spi::write::Default for Spi {} +impl ::embedded_hal::blocking::spi::transfer::Default for Spi {} +impl ::embedded_hal::blocking::spi::write::Default for Spi {}