Skip to content
Closed
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
9 changes: 2 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,18 @@ default-target = "x86_64-unknown-linux-gnu"

[dependencies]
cortex-m = "0.6.0"
nb = "0.1.2"
nb = "1"
cortex-m-rt = "0.6.8"
stm32f1 = "0.11.0"
embedded-dma = "0.1.2"
bxcan = "0.4.0"

[dependencies.void]
default-features = false
version = "1.0.2"

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

[dependencies.embedded-hal]
version = "0.2.3"
features = ["unproven"]
git = "https://github.com/rust-embedded/embedded-hal"

[dependencies.stm32-usbd]
version = "0.5.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use panic_halt as _;
use nb::block;

use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::OutputPin;
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};

#[entry]
Expand Down
2 changes: 1 addition & 1 deletion examples/blinky_generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use panic_halt as _;
use nb::block;

use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::OutputPin;
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};

#[entry]
Expand Down
2 changes: 1 addition & 1 deletion examples/blinky_rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use panic_halt as _;
use stm32f1xx_hal::{pac, prelude::*, rtc::Rtc};

use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::OutputPin;
use nb::block;

#[entry]
Expand Down
2 changes: 1 addition & 1 deletion examples/blinky_rtcalarm_irq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::hal::{
use core::cell::RefCell;
use cortex_m::{asm::wfi, interrupt::Mutex};
use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::OutputPin;

// A type definition for the GPIO pin to be used for our LED
type LEDPIN = gpioc::PC13<Output<PushPull>>;
Expand Down
2 changes: 1 addition & 1 deletion examples/blinky_timer_irq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::hal::{
use core::cell::RefCell;
use cortex_m::{asm::wfi, interrupt::Mutex};
use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::OutputPin;

// NOTE You can uncomment 'hprintln' here and in the code below for a bit more
// verbosity at runtime, at the cost of throwing off the timing of the blink
Expand Down
2 changes: 1 addition & 1 deletion examples/can-loopback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use bxcan::{
use panic_halt as _;

use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::OutputPin;
use nb::block;
use stm32f1xx_hal::{can::Can, pac, prelude::*};

Expand Down
6 changes: 3 additions & 3 deletions examples/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use panic_halt as _;

use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::OutputPin;
use stm32f1xx_hal::{delay::Delay, pac, prelude::*};

#[entry]
Expand Down Expand Up @@ -35,8 +35,8 @@ fn main() -> ! {

loop {
led.set_high().unwrap();
delay.delay_ms(1_000_u16);
delay.delay_ms(1_000_u16).unwrap();
led.set_low().unwrap();
delay.delay_ms(1_000_u16);
delay.delay_ms(1_000_u16).unwrap();
}
}
2 changes: 1 addition & 1 deletion examples/dynamic_gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use nb::block;

use cortex_m_rt::entry;
use cortex_m_semihosting::hprintln;
use embedded_hal::digital::v2::{InputPin, OutputPin};
use embedded_hal::digital::{InputPin, OutputPin};
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};

#[entry]
Expand Down
2 changes: 1 addition & 1 deletion examples/led.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use panic_halt as _;

use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::OutputPin;
use stm32f1xx_hal::{pac, prelude::*};

#[entry]
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/multi_mode_gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use nb::block;

use cortex_m_rt::entry;
use cortex_m_semihosting::hprintln;
use embedded_hal::digital::v2::{InputPin, OutputPin};
use embedded_hal::digital::{InputPin, OutputPin};
use stm32f1xx_hal::{gpio::State, pac, prelude::*, timer::Timer};

#[entry]
Expand Down
12 changes: 6 additions & 6 deletions examples/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ fn main() -> ! {
);

// Enable clock on each of the channels
pwm.enable(Channel::C1);
pwm.enable(Channel::C2);
pwm.enable(Channel::C3);
pwm.enable(&Channel::C1);
pwm.enable(&Channel::C2);
pwm.enable(&Channel::C3);

//// Operations affecting all defined channels on the Timer

Expand All @@ -79,17 +79,17 @@ fn main() -> ! {
//// the Pwm object or via dereferencing to the pin.

// Use the Pwm object to set C3 to full strength
pwm.set_duty(Channel::C3, max);
pwm.set_duty(&Channel::C3, max);

asm::bkpt();

// Use the Pwm object to set C3 to be dim
pwm.set_duty(Channel::C3, max / 4);
pwm.set_duty(&Channel::C3, max / 4);

asm::bkpt();

// Use the Pwm object to set C3 to be zero
pwm.set_duty(Channel::C3, 0);
pwm.set_duty(&Channel::C3, 0);

asm::bkpt();

Expand Down
2 changes: 1 addition & 1 deletion examples/qei.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn main() -> ! {

loop {
let before = qei.count();
delay.delay_ms(1_000_u16);
delay.delay_ms(1_000_u16).unwrap();
let after = qei.count();

let elapsed = after.wrapping_sub(before) as i16;
Expand Down
2 changes: 1 addition & 1 deletion examples/timer-interrupt-rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use panic_halt as _;

use rtic::app;

use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::OutputPin;
use stm32f1xx_hal::{
gpio::{gpioc::PC13, Output, PushPull, State},
pac,
Expand Down
4 changes: 2 additions & 2 deletions examples/usb_serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ extern crate panic_semihosting;

use cortex_m::asm::delay;
use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::OutputPin;
use stm32f1xx_hal::usb::{Peripheral, UsbBus};
use stm32f1xx_hal::{prelude::*, stm32};
use stm32f1xx_hal::{prelude::*, pac};
use usb_device::prelude::*;
use usbd_serial::{SerialPort, USB_CLASS_CDC};

Expand Down
7 changes: 3 additions & 4 deletions examples/usb_serial_interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ extern crate panic_semihosting;

use cortex_m::asm::{delay, wfi};
use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use stm32f1xx_hal::pac::{interrupt, Interrupt};
use stm32f1xx_hal::usb::{Peripheral, UsbBus, UsbBusType};
use stm32f1xx_hal::{prelude::*, stm32};
use stm32f1xx_hal::{prelude::*, pac};
use usb_device::{bus::UsbBusAllocator, prelude::*};
use usbd_serial::{SerialPort, USB_CLASS_CDC};

Expand Down Expand Up @@ -74,8 +73,8 @@ fn main() -> ! {

let mut nvic = p.NVIC;

nvic.enable(Interrupt::USB_HP_CAN_TX);
nvic.enable(Interrupt::USB_LP_CAN_RX0);
nvic.request(Interrupt::USB_HP_CAN_TX);
nvic.request(Interrupt::USB_LP_CAN_RX0);

loop {
wfi();
Expand Down
2 changes: 1 addition & 1 deletion examples/usb_serial_rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
extern crate panic_semihosting;

use cortex_m::asm::delay;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::OutputPin;
use rtic::app;
use stm32f1xx_hal::prelude::*;
use stm32f1xx_hal::usb::{Peripheral, UsbBus, UsbBusType};
Expand Down
10 changes: 5 additions & 5 deletions src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,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 @@ -426,8 +426,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());
Ok(res.into())
}
}
Expand Down Expand Up @@ -616,10 +616,10 @@ impl Adc<ADC1> {
{
self.rb.cr1.modify(|_, w| w.discen().clear_bit());
self.rb.cr2.modify(|_, w| w.align().bit(self.align.into()));
self.set_channel_sample_time(PIN::channel(), self.sample_time);
self.set_channel_sample_time(pins.channel(), self.sample_time);
self.rb
.sqr3
.modify(|_, w| unsafe { w.sq1().bits(PIN::channel()) });
.modify(|_, w| unsafe { w.sq1().bits(pins.channel()) });
self.rb.cr2.modify(|_, w| w.dma().set_bit());

let payload = AdcPayload {
Expand Down
27 changes: 17 additions & 10 deletions src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,31 @@ impl Delay {
self.syst
}
}

use core::convert::Infallible;
impl DelayMs<u32> for Delay {
fn delay_ms(&mut self, ms: u32) {
self.delay_us(ms * 1_000);
type Error = Infallible;
fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> {
self.delay_us(ms * 1_000)
}
}

impl DelayMs<u16> for Delay {
fn delay_ms(&mut self, ms: u16) {
self.delay_ms(u32(ms));
type Error = Infallible;
fn delay_ms(&mut self, ms: u16) -> Result<(), Self::Error> {
self.delay_ms(u32(ms))
}
}

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

impl DelayUs<u32> for Delay {
fn delay_us(&mut self, us: u32) {
type Error = Infallible;
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 +74,20 @@ impl DelayUs<u32> for Delay {

self.syst.disable_counter();
}
Ok(())
}
}

impl DelayUs<u16> for Delay {
fn delay_us(&mut self, us: u16) {
type Error = Infallible;
fn delay_us(&mut self, us: u16) -> Result<(), Self::Error> {
self.delay_us(u32(us))
}
}

impl DelayUs<u8> for Delay {
fn delay_us(&mut self, us: u8) {
type Error = Infallible;
fn delay_us(&mut self, us: u8) -> Result<(), Self::Error> {
self.delay_us(u32(us))
}
}
4 changes: 2 additions & 2 deletions src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ macro_rules! gpio {
use core::convert::Infallible;
use core::marker::PhantomData;

use crate::hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, toggleable};
use crate::hal::digital::{InputPin, OutputPin, StatefulOutputPin, toggleable};
use crate::pac::{$gpioy, $GPIOX};
use crate::pac::EXTI;
use crate::afio;
Expand Down Expand Up @@ -1120,7 +1120,7 @@ macro_rules! gpio {

macro_rules! impl_pxx {
($(($port:ident :: $pin:ident)),*) => {
use embedded_hal::digital::v2::{InputPin, StatefulOutputPin, OutputPin};
use embedded_hal::digital::{InputPin, StatefulOutputPin, OutputPin};
use core::convert::Infallible;

pub enum Pxx<MODE> {
Expand Down
4 changes: 2 additions & 2 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pub use crate::dma::WriteDma as _stm32_hal_dma_WriteDma;
pub use crate::flash::FlashExt as _stm32_hal_flash_FlashExt;
pub use crate::gpio::GpioExt as _stm32_hal_gpio_GpioExt;
pub use crate::hal::adc::OneShot as _embedded_hal_adc_OneShot;
pub use crate::hal::digital::v2::StatefulOutputPin as _embedded_hal_digital_StatefulOutputPin;
pub use crate::hal::digital::v2::ToggleableOutputPin as _embedded_hal_digital_ToggleableOutputPin;
pub use crate::hal::digital::StatefulOutputPin as _embedded_hal_digital_StatefulOutputPin;
pub use crate::hal::digital::ToggleableOutputPin as _embedded_hal_digital_ToggleableOutputPin;
pub use crate::hal::prelude::*;
pub use crate::rcc::RccExt as _stm32_hal_rcc_RccExt;
pub use crate::time::U32Ext as _stm32_hal_time_U32Ext;
Loading