Browse Source

Updated to edition 2018, bumped crate version to 0.8.0

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
features/pwm v0.8.0
Daniel Egger 4 years ago
parent
commit
162083af74
  1. 7
      Cargo.toml
  2. 9
      examples/blinky.rs
  3. 14
      examples/blinky_delay.rs
  4. 16
      examples/flash_systick.rs
  5. 17
      examples/i2c_hal_ina260reader.rs
  6. 22
      examples/i2c_hal_ina260serial.rs
  7. 15
      examples/i2c_hal_ssd1306alphabeter.rs
  8. 22
      examples/led_hal_button_irq.rs
  9. 18
      examples/serial_echo.rs
  10. 18
      examples/spi_hal_apa102c.rs
  11. 4
      src/delay.rs
  12. 6
      src/gpio.rs
  13. 14
      src/i2c.rs
  14. 16
      src/lib.rs
  15. 8
      src/prelude.rs
  16. 4
      src/rcc.rs
  17. 33
      src/serial.rs
  18. 20
      src/spi.rs

7
Cargo.toml

@ -1,4 +1,5 @@
[package]
edition = "2018"
authors = ["Daniel Egger <daniel@eggers-club.de>"]
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"

9
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;

14
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();

16
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<RefCell<Option<gpioa::PA1<Output<PushPull>>>>> = 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);

17
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

22
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 */

15
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

22
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

18
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();

18
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();

4
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 {

6
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,

14
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<I2C, PINS> {

16
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;

8
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;

4
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 {

33
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<PINS> Serial<USART1, PINS> {
}
}
impl hal::serial::Read<u8> for Rx<USART1> {
impl embedded_hal::serial::Read<u8> for Rx<USART1> {
type Error = Error;
fn read(&mut self) -> nb::Result<u8, Error> {
@ -131,7 +130,7 @@ impl hal::serial::Read<u8> for Rx<USART1> {
}
}
impl hal::serial::Write<u8> for Tx<USART1> {
impl embedded_hal::serial::Write<u8> for Tx<USART1> {
type Error = Void;
fn flush(&mut self) -> nb::Result<(), Self::Error> {
@ -201,7 +200,7 @@ impl<PINS> Serial<USART2, PINS> {
}
}
impl hal::serial::Read<u8> for Rx<USART2> {
impl embedded_hal::serial::Read<u8> for Rx<USART2> {
type Error = Error;
fn read(&mut self) -> nb::Result<u8, Error> {
@ -225,7 +224,7 @@ impl hal::serial::Read<u8> for Rx<USART2> {
}
}
impl hal::serial::Write<u8> for Tx<USART2> {
impl embedded_hal::serial::Write<u8> for Tx<USART2> {
type Error = Void;
fn flush(&mut self) -> nb::Result<(), Self::Error> {
@ -256,14 +255,10 @@ impl hal::serial::Write<u8> for Tx<USART2> {
impl<USART> Write for Tx<USART>
where
Tx<USART>: hal::serial::Write<u8>,
Tx<USART>: embedded_hal::serial::Write<u8>,
{
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(())
}
}

20
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<PINS> Spi<SPI1, PINS> {
}
}
impl<PINS> ::hal::spi::FullDuplex<u8> for Spi<SPI1, PINS> {
impl<PINS> ::embedded_hal::spi::FullDuplex<u8> for Spi<SPI1, PINS> {
type Error = Error;
fn read(&mut self) -> nb::Result<u8, Error> {
@ -166,5 +166,5 @@ impl<PINS> ::hal::spi::FullDuplex<u8> for Spi<SPI1, PINS> {
}
}
impl<PINS> ::hal::blocking::spi::transfer::Default<u8> for Spi<SPI1, PINS> {}
impl<PINS> ::hal::blocking::spi::write::Default<u8> for Spi<SPI1, PINS> {}
impl<PINS> ::embedded_hal::blocking::spi::transfer::Default<u8> for Spi<SPI1, PINS> {}
impl<PINS> ::embedded_hal::blocking::spi::write::Default<u8> for Spi<SPI1, PINS> {}

Loading…
Cancel
Save