Skip to content
Merged
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
4 changes: 2 additions & 2 deletions examples/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use stm32g4xx_hal::{
//delay::{DelayExt, SYSTDelayExt},
gpio::{gpioc, ExtiPin, GpioExt, Input, PullDown, SignalEdge},
gpio::{self, ExtiPin, GpioExt, Input, PullDown, SignalEdge},
rcc::RccExt,
stm32,
stm32::{interrupt, Interrupt},
Expand All @@ -16,7 +16,7 @@ use cortex_m::{asm::wfi, interrupt::Mutex};
use cortex_m_rt::entry;
use embedded_hal::digital::OutputPin;

type ButtonPin = gpioc::PC13<Input<PullDown>>;
type ButtonPin = gpio::PC13<Input<PullDown>>;

// Make LED pin globally available
static G_BUTTON: Mutex<RefCell<Option<ButtonPin>>> = Mutex::new(RefCell::new(None));
Expand Down
6 changes: 2 additions & 4 deletions examples/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#![no_std]

use cortex_m_rt::entry;
use hal::gpio::gpioa::PA8;
use hal::gpio::Alternate;
use hal::gpio::AF6;
use hal::gpio::{AF6, PA8};
use hal::prelude::*;
use hal::stm32;
use hal::time::RateExtU32;
Expand All @@ -23,7 +21,7 @@ fn main() -> ! {
let dp = stm32::Peripherals::take().expect("cannot take peripherals");
let mut rcc = dp.RCC.constrain();
let gpioa = dp.GPIOA.split(&mut rcc);
let pin: PA8<Alternate<AF6>> = gpioa.pa8.into_alternate();
let pin: PA8<AF6> = gpioa.pa8.into_alternate();

let mut pwm = dp.TIM1.pwm(pin, 100.Hz(), &mut rcc);

Expand Down
12 changes: 4 additions & 8 deletions examples/spi-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@

use crate::hal::{
delay::DelayFromCountDownTimer,
gpio::gpioa::PA5,
gpio::gpioa::PA6,
gpio::gpioa::PA7,
gpio::Alternate,
gpio::AF5,
gpio::{AF5, PA5, PA6, PA7},
prelude::*,
pwr::PwrExt,
rcc::Config,
Expand Down Expand Up @@ -44,9 +40,9 @@ fn main() -> ! {
let mut delay_tim2 = DelayFromCountDownTimer::new(timer2.start_count_down(100.millis()));

let gpioa = dp.GPIOA.split(&mut rcc);
let sclk: PA5<Alternate<AF5>> = gpioa.pa5.into_alternate();
let miso: PA6<Alternate<AF5>> = gpioa.pa6.into_alternate();
let mosi: PA7<Alternate<AF5>> = gpioa.pa7.into_alternate();
let sclk: PA5<AF5> = gpioa.pa5.into_alternate();
let miso: PA6<AF5> = gpioa.pa6.into_alternate();
let mosi: PA7<AF5> = gpioa.pa7.into_alternate();

let spi = dp
.SPI1
Expand Down
18 changes: 7 additions & 11 deletions examples/spi-example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@

use hal::{
delay::DelayFromCountDownTimer,
gpio::gpioa::PA5,
gpio::gpioa::PA6,
gpio::gpioa::PA7,
gpio::Alternate,
gpio::AF5,
gpio::{AF5, PA5, PA6, PA7},
hal_02::spi::FullDuplex,
prelude::*,
pwr::PwrExt,
Expand Down Expand Up @@ -41,9 +37,9 @@ fn main() -> ! {
let mut delay_tim2 = DelayFromCountDownTimer::new(timer2.start_count_down(100.millis()));

let gpioa = dp.GPIOA.split(&mut rcc);
let sclk: PA5<Alternate<AF5>> = gpioa.pa5.into_alternate();
let miso: PA6<Alternate<AF5>> = gpioa.pa6.into_alternate();
let mosi: PA7<Alternate<AF5>> = gpioa.pa7.into_alternate();
let sclk: PA5<AF5> = gpioa.pa5.into_alternate();
let miso: PA6<AF5> = gpioa.pa6.into_alternate();
let mosi: PA7<AF5> = gpioa.pa7.into_alternate();

let mut spi = dp
.SPI1
Expand All @@ -52,13 +48,13 @@ fn main() -> ! {
cs.set_high().unwrap();

// "Hello world!"
let message: [char; 12] = ['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!'];
let message = b"Hello world!";
let mut received_byte: u8;

loop {
for byte in message.iter() {
for &byte in message {
cs.set_low().unwrap();
spi.send(*byte as u8).unwrap();
spi.send(byte).unwrap();
received_byte = nb::block!(FullDuplex::read(&mut spi)).unwrap();
cs.set_high().unwrap();

Expand Down
12 changes: 4 additions & 8 deletions examples/spi-sd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
extern crate embedded_sdmmc;

use fugit::RateExtU32;
use hal::gpio::gpiob::PB14;
use hal::gpio::gpiob::PB15;
use hal::gpio::gpiof::PF9;
use hal::gpio::Alternate;
use hal::gpio::AF5;
use hal::gpio::{AF5, PB14, PB15, PF9};
use hal::prelude::*;
use hal::pwr::PwrExt;
use hal::rcc::Config;
Expand Down Expand Up @@ -43,9 +39,9 @@ fn main() -> ! {
cs
};

let sck: PF9<Alternate<AF5>> = gpiof.pf9.into_alternate();
let miso: PB14<Alternate<AF5>> = gpiob.pb14.into_alternate();
let mosi: PB15<Alternate<AF5>> = gpiob.pb15.into_alternate();
let sck: PF9<AF5> = gpiof.pf9.into_alternate();
let miso: PB14<AF5> = gpiob.pb14.into_alternate();
let mosi: PB15<AF5> = gpiob.pb15.into_alternate();

let spi = dp
.SPI2
Expand Down
22 changes: 5 additions & 17 deletions src/can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,19 @@ macro_rules! pins {
rx: [ $($( #[ $pmetarx:meta ] )* $rx:ident<$rxaf:ident>),+ $(,)? ])) => {
$(
$( #[ $pmetatx ] )*
impl sealed::Tx<$PER> for $tx<crate::gpio::Alternate<$txaf>> {}
impl sealed::Tx<$PER> for $tx<$txaf> {}
)+
$(
$( #[ $pmetarx ] )*
impl sealed::Rx<$PER> for $rx<crate::gpio::Alternate<$rxaf>> {}
impl sealed::Rx<$PER> for $rx<$rxaf> {}
)+
};
}

mod fdcan1 {
use super::sealed;
use super::{Can, CanExt};
use crate::gpio::{
gpioa::{PA11, PA12},
gpiob::{PB8, PB9},
gpiod::{PD0, PD1},
AF9,
};
use crate::gpio::{AF9, PA11, PA12, PB8, PB9, PD0, PD1};
use crate::stm32::FDCAN1;
use fdcan;

Expand Down Expand Up @@ -119,10 +114,7 @@ mod fdcan1 {
mod fdcan2 {
use super::sealed;
use super::{Can, CanExt};
use crate::gpio::{
gpiob::{PB12, PB13, PB5, PB6},
AF9,
};
use crate::gpio::{AF9, PB12, PB13, PB5, PB6};
use crate::stm32::FDCAN2;
use fdcan;
use fdcan::message_ram;
Expand Down Expand Up @@ -166,11 +158,7 @@ mod fdcan2 {
mod fdcan3 {
use super::sealed;
use super::{Can, CanExt};
use crate::gpio::{
gpioa::{PA15, PA8},
gpiob::{PB3, PB4},
AF11,
};
use crate::gpio::{AF11, PA15, PA8, PB3, PB4};
use crate::stm32::FDCAN3;
use fdcan;
use fdcan::message_ram;
Expand Down
97 changes: 37 additions & 60 deletions src/comparator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,8 @@ use core::marker::PhantomData;

use crate::dac;
use crate::exti::{Event as ExtiEvent, ExtiExt};
use crate::gpio::{
gpioa::{PA0, PA1, PA11, PA12, PA2, PA3, PA4, PA5, PA6, PA7},
gpiob::{PB0, PB1, PB14, PB15, PB2, PB6, PB7, PB8, PB9},
gpioc::PC2,
gpiof::PF4,
Analog, OpenDrain, Output, PushPull, SignalEdge, AF2, AF3, AF8,
};
use crate::gpio::{self, Analog, OpenDrain, Output, PushPull, SignalEdge};

#[cfg(any(
feature = "stm32g473",
feature = "stm32g483",
feature = "stm32g474",
feature = "stm32g484"
))]
use crate::gpio::{
gpioa::{PA10, PA8, PA9},
gpiob::{PB10, PB11, PB12, PB13},
gpioc::{PC6, PC7, PC8},
gpiod::{PD10, PD11, PD12, PD13, PD14, PD15},
AF7,
};

use crate::gpio::gpioc::{PC0, PC1};
use crate::gpio::gpioe::{PE7, PE8};
use crate::gpio::gpiof::PF1;
use crate::rcc::{Clocks, Rcc};
use crate::stasis;
use crate::stm32::{COMP, EXTI};
Expand Down Expand Up @@ -161,13 +138,13 @@ pub trait NegativeInput<C> {

macro_rules! positive_input_pin {
($COMP:ident, $pin_0:ident, $pin_1:ident) => {
impl PositiveInput<$COMP> for $pin_0<Analog> {
impl PositiveInput<$COMP> for gpio::$pin_0<Analog> {
fn setup(_s: impl stasis::EntitlementLock<Resource = Self>, comp: &mut $COMP) {
comp.csr().modify(|_, w| w.inpsel().bit(false));
}
}

impl PositiveInput<$COMP> for $pin_1<Analog> {
impl PositiveInput<$COMP> for gpio::$pin_1<Analog> {
fn setup(_s: impl stasis::EntitlementLock<Resource = Self>, comp: &mut $COMP) {
comp.csr().modify(|_, w| w.inpsel().bit(true));
}
Expand Down Expand Up @@ -224,10 +201,10 @@ macro_rules! negative_input_pin {
}

negative_input_pin! {
COMP1: PA4<Analog>, PA0<Analog>,
COMP2: PA5<Analog>, PA2<Analog>,
COMP3: PF1<Analog>, PC0<Analog>,
COMP4: PE8<Analog>, PB2<Analog>,
COMP1: gpio::PA4<Analog>, gpio::PA0<Analog>,
COMP2: gpio::PA5<Analog>, gpio::PA2<Analog>,
COMP3: gpio::PF1<Analog>, gpio::PC0<Analog>,
COMP4: gpio::PE8<Analog>, gpio::PB2<Analog>,
}

#[cfg(any(
Expand All @@ -237,9 +214,9 @@ negative_input_pin! {
feature = "stm32g484"
))]
negative_input_pin! {
COMP5: PB10<Analog>, PD13<Analog>,
COMP6: PD10<Analog>, PB15<Analog>,
COMP7: PD15<Analog>, PB12<Analog>,
COMP5: gpio::PB10<Analog>, gpio::PD13<Analog>,
COMP6: gpio::PD10<Analog>, gpio::PB15<Analog>,
COMP7: gpio::PD15<Analog>, gpio::PB12<Analog>,
}

pub mod refint_input {
Expand Down Expand Up @@ -626,38 +603,38 @@ pub trait OutputPin<COMP> {

#[allow(unused_macros)] // TODO: add support for more devices
macro_rules! output_pin {
($COMP:ident, $pin:ident, $AF:ident, $mode_t:ident, $into:ident) => {
impl OutputPin<$COMP> for $pin<Output<$mode_t>> {
($COMP:ident, $pin:ident, $AF:literal, $mode_t:ident, $into:ident) => {
impl OutputPin<$COMP> for gpio::$pin<Output<$mode_t>> {
fn setup(self) {
self.$into::<$AF>();
}
}
};
($($COMP:ident: $pin:ident, $AF:ident,)+) => {$(
($($COMP:ident: $pin:ident, $AF:literal,)+) => {$(
output_pin!($COMP, $pin, $AF, PushPull, into_alternate);
output_pin!($COMP, $pin, $AF, OpenDrain, into_alternate_open_drain);
)+};
}

output_pin! {
COMP1: PA0, AF8,
COMP1: PA6, AF8,
COMP1: PA11, AF8,
COMP1: PB8, AF8,
COMP1: PF4, AF2,

COMP2: PA2, AF8,
COMP2: PA7, AF8,
COMP2: PA12, AF8,
COMP2: PB9, AF8,

COMP3: PB7, AF8,
COMP3: PB15, AF3,
COMP3: PC2, AF3,

COMP4: PB1, AF8,
COMP4: PB6, AF8,
COMP4: PB14, AF8,
COMP1: PA0, 8,
COMP1: PA6, 8,
COMP1: PA11, 8,
COMP1: PB8, 8,
COMP1: PF4, 2,

COMP2: PA2, 8,
COMP2: PA7, 8,
COMP2: PA12, 8,
COMP2: PB9, 8,

COMP3: PB7, 8,
COMP3: PB15, 3,
COMP3: PC2, 3,

COMP4: PB1, 8,
COMP4: PB6, 8,
COMP4: PB14, 8,
}

#[cfg(any(
Expand All @@ -667,12 +644,12 @@ output_pin! {
feature = "stm32g484",
))]
output_pin! {
COMP5: PA9, AF8,
COMP5: PC7, AF7,
COMP5: PA9, 8,
COMP5: PC7, 7,

COMP6: PA10, AF8,
COMP6: PC6, AF7,
COMP6: PA10, 8,
COMP6: PC6, 7,

COMP7: PA8, AF8,
COMP7: PC8, AF7,
COMP7: PA8, 8,
COMP7: PC8, 7,
}
3 changes: 1 addition & 2 deletions src/dac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use core::marker::PhantomData;
use core::mem::MaybeUninit;
use core::ops::Deref;

use crate::gpio::gpioa::{PA4, PA5, PA6};
use crate::gpio::DefaultMode;
use crate::gpio::{DefaultMode, PA4, PA5, PA6};
use crate::pac;
use crate::rcc::{self, *};
use crate::stm32::RCC;
Expand Down
Loading
Loading