Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor for embedded-hal 1.0.0 #157

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,29 @@ version = "0.6.0"
features = ["stm32f746", "rt"]

[dependencies]
as-slice = "0.1.0"
as-slice = "0.2.1"
cortex-m = "0.7"
cortex-m-rt = ">=0.6.15, <0.8"
embedded-time = "0.12.0"
nb = "0.1.2"
nb = "1.0.0"
rtcc = "0.2"
stm32f7 = "0.14.0"
micromath = "1.0.0"
micromath = "2.0.0"
synopsys-usb-otg = { version = "0.2.3", features = ["cortex-m"], optional = true }
stm32-fmc = { version = "0.2.0", features = ["sdram"], optional = true }
rand_core = "0.6"
bxcan = "0.6"


[dependencies.bare-metal]
version = "0.2.4"
features = ["const-fn"]
version = "1.0.0"

[dependencies.cast]
default-features = false
version = "0.2.2"
version = "0.3.0"

[dependencies.embedded-hal]
features = ["unproven"]
version = "0.2.3"
version = "1.0.0-alpha.6"

[dependencies.void]
default-features = false
Expand All @@ -52,7 +51,7 @@ version = "0.4.1"
cortex-m-semihosting = "0.3.3"
panic-halt = "0.2.0"
panic-semihosting = "0.5.2"
embedded-graphics = "0.6.1"
embedded-graphics = "0.6.2"
usb-device = "0.2.5"
usbd-serial = "0.1.0"

Expand Down
5 changes: 3 additions & 2 deletions examples/blinky_delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
extern crate panic_halt;

use cortex_m_rt::entry;
use embedded_hal::delay::blocking::DelayUs;
use stm32f7xx_hal::{delay::Delay, pac, prelude::*};

#[entry]
Expand All @@ -29,9 +30,9 @@ fn main() -> ! {

loop {
led.set_high();
delay.delay_ms(500_u16);
delay.delay_ms(500).unwrap();

led.set_low();
delay.delay_ms(500_u16);
delay.delay_ms(500).unwrap();
}
}
1 change: 1 addition & 0 deletions examples/i2c_scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use panic_semihosting as _;
use cortex_m_rt::entry;
use cortex_m_semihosting::{hprint, hprintln};

use embedded_hal::i2c::blocking::Write;
use stm32f7xx_hal::{self as hal, gpio::GpioExt, pac, prelude::*};

const VALID_ADDR_RANGE: Range<u8> = 0x08..0x78;
Expand Down
3 changes: 2 additions & 1 deletion examples/serial_delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern crate panic_halt;
use core::fmt::Write;

use cortex_m_rt::entry;
use embedded_hal::delay::blocking::DelayUs;
use stm32f7xx_hal::{
delay::Delay,
pac,
Expand Down Expand Up @@ -50,6 +51,6 @@ fn main() -> ! {
let hello: &str = "Hello, I'm a STM32F7xx!\r\n";
loop {
tx.write_str(hello).unwrap();
delay.delay_ms(500_u16);
delay.delay_ms(500).unwrap();
}
}
1 change: 1 addition & 0 deletions examples/serial_echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern crate panic_halt;
use nb::block;

use cortex_m_rt::entry;
use embedded_hal::serial::nb::{Read, Write};
use stm32f7xx_hal::{
pac,
prelude::*,
Expand Down
3 changes: 2 additions & 1 deletion examples/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
extern crate panic_semihosting;

use cortex_m_rt::entry;
use embedded_hal::spi::blocking::TransferInplace;
use stm32f7xx_hal::{
pac,
prelude::*,
Expand Down Expand Up @@ -48,7 +49,7 @@ fn main() -> ! {
let mut buffer = [0; 2];
buffer[0] = 0x75 | 0x80;
ncs.set_low();
spi.transfer(&mut buffer).unwrap();
spi.transfer_inplace(&mut buffer).unwrap();
ncs.set_high();

// The WHO_AM_I register should always return 0x71.
Expand Down
1 change: 1 addition & 0 deletions examples/spi_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
extern crate panic_semihosting;

use cortex_m_rt::entry;
use embedded_hal::spi::blocking::Write;
use stm32f7xx_hal::{
pac,
prelude::*,
Expand Down
2 changes: 1 addition & 1 deletion examples/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn main() -> ! {
unsafe {
NVIC::unmask(pac::Interrupt::TIM2);
}
let mut timer = Timer::tim2(dp.TIM2, 1.Hz(), clocks, &mut rcc.apb1);
let mut timer = Timer::tim2(dp.TIM2, 1.Hz(), clocks, &mut rcc.apb1).unwrap();
timer.listen(Event::TimeOut);

loop {}
Expand Down
8 changes: 4 additions & 4 deletions src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::pac::{ADC1, ADC2, ADC3, ADC_COMMON};

use cortex_m::asm::delay;

use embedded_hal::adc::{Channel, OneShot};
use embedded_hal::adc::nb::{Channel, OneShot};

#[derive(Clone, Copy, Debug, PartialEq)]
#[allow(non_camel_case_types)]
Expand Down Expand Up @@ -95,7 +95,7 @@ macro_rules! adc_pins {
impl Channel<$ADC> for $pin {
type ID = u8;

fn channel() -> u8 { $chan }
fn channel(&self) -> u8 { $chan }
}
)+
};
Expand Down Expand Up @@ -442,8 +442,8 @@ macro_rules! adc_hal {
{
type Error = ();

fn read(&mut self, _pin: &mut PIN) -> nb::Result<WORD, Self::Error> {
let res = self.convert(PIN::channel());
fn read(&mut self, pin: &mut PIN) -> nb::Result<WORD, Self::Error> {
let res = self.convert(PIN::channel(pin));
Ok(res.into())
}
}
Expand Down
38 changes: 5 additions & 33 deletions src/delay.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//! Delays

use cast::u32;
use cortex_m::peripheral::syst::SystClkSource;
use cortex_m::peripheral::SYST;

use crate::hal::blocking::delay::{DelayMs, DelayUs};
use crate::hal::delay::blocking::DelayUs;
use crate::rcc::Clocks;

/// System timer (SysTick) as a delay provider
Expand All @@ -27,26 +26,10 @@ impl Delay {
}
}

impl DelayMs<u32> for Delay {
fn delay_ms(&mut self, ms: u32) {
self.delay_us(ms * 1_000);
}
}

impl DelayMs<u16> for Delay {
fn delay_ms(&mut self, ms: u16) {
self.delay_ms(u32(ms));
}
}

impl DelayMs<u8> for Delay {
fn delay_ms(&mut self, ms: u8) {
self.delay_ms(u32(ms));
}
}
impl DelayUs for Delay {
type Error = ();

impl DelayUs<u32> for Delay {
fn delay_us(&mut self, us: u32) {
fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> {
// The SysTick Reload Value register supports values between 1 and 0x00FFFFFF.
const MAX_RVR: u32 = 0x00FF_FFFF;

Expand All @@ -70,17 +53,6 @@ impl DelayUs<u32> for Delay {

self.syst.disable_counter();
}
}
}

impl DelayUs<u16> for Delay {
fn delay_us(&mut self, us: u16) {
self.delay_us(u32(us))
}
}

impl DelayUs<u8> for Delay {
fn delay_us(&mut self, us: u8) {
self.delay_us(u32(us))
Ok(())
}
}
6 changes: 3 additions & 3 deletions src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
use core::convert::Infallible;
use core::marker::PhantomData;

pub use embedded_hal::digital::v2::PinState;
use embedded_hal::digital::v2::{
use embedded_hal::digital::blocking::{
InputPin, IoPin, OutputPin, StatefulOutputPin, ToggleableOutputPin,
};
pub use embedded_hal::digital::PinState;

use crate::pac::{EXTI, SYSCFG};
use crate::rcc::{Enable, APB2};
Expand Down Expand Up @@ -450,7 +450,7 @@ impl<MODE, const P: char, const N: u8> Pin<Output<MODE>, P, N> {

#[inline(always)]
pub fn toggle(&mut self) {
if self.is_set_low() {
if self.is_set_low().unwrap() {
self.set_high()
} else {
self.set_low()
Expand Down
2 changes: 1 addition & 1 deletion src/gpio/erased.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<MODE> ErasedPin<Output<MODE>> {

#[inline(always)]
pub fn toggle(&mut self) {
if self.is_set_low() {
if self.is_set_low().unwrap() {
self.set_high()
} else {
self.set_low()
Expand Down
2 changes: 1 addition & 1 deletion src/gpio/partially_erased.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<MODE, const P: char> PartiallyErasedPin<Output<MODE>, P> {

#[inline(always)]
pub fn toggle(&mut self) {
if self.is_set_low() {
if self.is_set_low().unwrap() {
self.set_high()
} else {
self.set_low()
Expand Down
Loading