diff --git a/.vscode/settings.json b/.vscode/settings.json
index 5ecc8746..bc2285d3 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,8 +1,6 @@
{
"rust-analyzer.check.allTargets": false,
- "rust-analyzer.check.extraArgs": [
- "--examples",
- ],
+ "rust-analyzer.check.extraArgs": ["--examples"],
"rust-analyzer.cargo.target": "thumbv7em-none-eabihf",
"rust-analyzer.cargo.features": [
"stm32g484",
diff --git a/Cargo.toml b/Cargo.toml
index b1cb7421..0d6df68a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -80,19 +80,225 @@ rt = ["stm32g4/rt"]
usb = ["dep:stm32-usbd"]
stm32g431 = ["stm32g4/stm32g431", "cat2"]
stm32g441 = ["stm32g4/stm32g441", "cat2"]
-stm32g473 = ["stm32g4/stm32g473", "cat3", "adc3", "adc4", "adc5"]
-stm32g474 = ["stm32g4/stm32g474", "cat3", "adc3", "adc4", "adc5"]
-stm32g483 = ["stm32g4/stm32g483", "cat3", "adc3", "adc4", "adc5"]
-stm32g484 = ["stm32g4/stm32g484", "cat3", "adc3", "adc4", "adc5"]
-stm32g491 = ["stm32g4/stm32g491", "cat4", "adc3"]
-stm32g4a1 = ["stm32g4/stm32g4a1", "cat4", "adc3"]
+stm32g473 = ["stm32g4/stm32g473", "cat3"]
+stm32g474 = ["stm32g4/stm32g474", "cat3"]
+stm32g483 = ["stm32g4/stm32g483", "cat3"]
+stm32g484 = ["stm32g4/stm32g484", "cat3"]
+stm32g491 = ["stm32g4/stm32g491", "cat4"]
+stm32g4a1 = ["stm32g4/stm32g4a1", "cat4"]
+gpio-g43x = [
+ "comp1",
+ "comp2",
+ "comp3",
+ "comp4",
+ "crs",
+ "fdcan1",
+ "gpioa",
+ "gpiob",
+ "gpioc",
+ "gpiod",
+ "gpioe",
+ "gpiof",
+ "gpiog",
+ "i2c1",
+ "i2c2",
+ "i2c3",
+ "i2s",
+ "i2s2",
+ "i2s3",
+ "ir",
+ "lptim1",
+ "lpuart1",
+ "rcc",
+ "rtc",
+ "sai1",
+ "spi1",
+ "spi2",
+ "spi3",
+ "sys",
+ "tim1",
+ "tim15",
+ "tim16",
+ "tim17",
+ "tim2",
+ "tim3",
+ "tim4",
+ "tim8",
+ "uart4",
+ "ucpd1",
+ "usart1",
+ "usart2",
+ "usart3",
+]
+gpio-g47x = [
+ "adc3",
+ "adc4",
+ "adc5",
+ "comp1",
+ "comp2",
+ "comp3",
+ "comp4",
+ "comp5",
+ "comp6",
+ "comp7",
+ "crs",
+ "fdcan1",
+ "fdcan2",
+ "fdcan3",
+ "fmc",
+ "gpioa",
+ "gpiob",
+ "gpioc",
+ "gpiod",
+ "gpioe",
+ "gpiof",
+ "gpiog",
+ "hrtim1",
+ "i2c1",
+ "i2c2",
+ "i2c3",
+ "i2c4",
+ "i2s",
+ "i2s2",
+ "i2s3",
+ "ir",
+ "lptim1",
+ "lpuart1",
+ "quadspi1",
+ "rcc",
+ "rtc",
+ "sai1",
+ "spi1",
+ "spi2",
+ "spi3",
+ "spi4",
+ "sys",
+ "tim1",
+ "tim15",
+ "tim16",
+ "tim17",
+ "tim2",
+ "tim20",
+ "tim3",
+ "tim4",
+ "tim5",
+ "tim8",
+ "uart4",
+ "uart5",
+ "ucpd1",
+ "usart1",
+ "usart2",
+ "usart3",
+]
+gpio-g49x = [
+ "adc3",
+ "comp1",
+ "comp2",
+ "comp3",
+ "comp4",
+ "crs",
+ "fdcan1",
+ "fdcan2",
+ "gpioa",
+ "gpiob",
+ "gpioc",
+ "gpiod",
+ "gpioe",
+ "gpiof",
+ "gpiog",
+ "i2c1",
+ "i2c2",
+ "i2c3",
+ "i2s",
+ "i2s2",
+ "i2s3",
+ "ir",
+ "lptim1",
+ "lpuart1",
+ "quadspi1",
+ "rcc",
+ "rtc",
+ "sai1",
+ "spi1",
+ "spi2",
+ "spi3",
+ "sys",
+ "tim1",
+ "tim15",
+ "tim16",
+ "tim17",
+ "tim2",
+ "tim20",
+ "tim3",
+ "tim4",
+ "tim8",
+ "uart4",
+ "uart5",
+ "ucpd1",
+ "usart1",
+ "usart2",
+ "usart3",
+]
-gpio-g43x = []
-
-gpio-g47x = []
-
-gpio-g49x = []
+adc3 = []
+adc4 = []
+adc5 = []
+comp1 = []
+comp2 = []
+comp3 = []
+comp4 = []
+comp5 = []
+comp6 = []
+comp7 = []
+crs = []
+fdcan1 = []
+fdcan2 = []
+fdcan3 = []
+fmc = []
+gpioa = []
+gpiob = []
+gpioc = []
+gpiod = []
+gpioe = []
+gpiof = []
+gpiog = []
+hrtim1 = []
+i2c1 = []
+i2c2 = []
+i2c3 = []
+i2c4 = []
+i2s = []
+i2s2 = []
+i2s3 = []
+ir = []
+lptim1 = []
+lpuart1 = []
+quadspi1 = []
+rcc = []
+rtc = []
+sai1 = []
+spi1 = []
+spi2 = []
+spi3 = []
+spi4 = []
+sys = []
+tim1 = []
+tim15 = []
+tim16 = []
+tim17 = []
+tim2 = []
+tim20 = []
+tim3 = []
+tim4 = []
+tim5 = []
+tim8 = []
+uart4 = []
+uart5 = []
+ucpd1 = []
+usart1 = []
+usart2 = []
+usart3 = []
log-itm = ["cortex-m-log/itm"]
log-rtt = []
@@ -106,9 +312,6 @@ defmt = [
"embedded-io/defmt-03",
]
cordic = ["dep:fixed"]
-adc3 = []
-adc4 = []
-adc5 = []
# Device category
cat2 = ["gpio-g43x"]
diff --git a/examples/adc-continious.rs b/examples/adc-continious.rs
index b44b4755..10094c6b 100644
--- a/examples/adc-continious.rs
+++ b/examples/adc-continious.rs
@@ -42,7 +42,6 @@ fn main() -> ! {
info!("Setup Gpio");
let gpioa = dp.GPIOA.split(&mut rcc);
- let pa0 = gpioa.pa0.into_analog();
info!("Setup Adc1");
let mut delay = cp.SYST.delay(&rcc.clocks);
@@ -54,7 +53,7 @@ fn main() -> ! {
adc.set_auto_delay(true);
adc.set_continuous(Continuous::Continuous);
adc.reset_sequence();
- adc.configure_channel(&pa0, Sequence::One, SampleTime::Cycles_640_5);
+ adc.configure_channel(&gpioa.pa0, Sequence::One, SampleTime::Cycles_640_5);
adc.configure_channel(&Vref, Sequence::Two, SampleTime::Cycles_640_5);
adc.configure_channel(&Temperature, Sequence::Three, SampleTime::Cycles_640_5);
let adc = adc.enable();
diff --git a/examples/adc-one-shot.rs b/examples/adc-one-shot.rs
index 388b6757..efa30118 100644
--- a/examples/adc-one-shot.rs
+++ b/examples/adc-one-shot.rs
@@ -43,13 +43,12 @@ fn main() -> ! {
info!("Setup Gpio");
let gpioa = dp.GPIOA.split(&mut rcc);
- let pa7 = gpioa.pa7.into_analog();
info!("Enter Loop");
loop {
info!("Convert");
- let sample = adc.convert(&pa7, SampleTime::Cycles_640_5);
+ let sample = adc.convert(&gpioa.pa7, SampleTime::Cycles_640_5);
info!("sample to mv");
let millivolts = adc.sample_to_millivolts(sample);
info!("pa7: {}mV", millivolts);
diff --git a/examples/button.rs b/examples/button.rs
index c3530b90..0e1551ac 100644
--- a/examples/button.rs
+++ b/examples/button.rs
@@ -17,7 +17,7 @@ use cortex_m_rt::entry;
type ButtonPin = gpio::PC13;
-// Make LED pin globally available
+// Make LED and BUTTON pins globally available
static G_BUTTON: Mutex>> = Mutex::new(RefCell::new(None));
static G_LED_ON: AtomicBool = AtomicBool::new(true);
diff --git a/examples/can-echo.rs b/examples/can-echo.rs
index 2f8c0890..7720d3d0 100644
--- a/examples/can-echo.rs
+++ b/examples/can-echo.rs
@@ -61,7 +61,7 @@ fn main() -> ! {
let tx = gpiob.pb9.into_alternate().speed(Speed::VeryHigh);
info!("-- Create CAN 1 instance");
- let mut can = dp.FDCAN1.fdcan(tx, rx, &mut rcc);
+ let mut can = dp.FDCAN1.fdcan((tx, rx), &mut rcc);
can.set_protocol_exception_handling(false);
info!("-- Configure nominal timing");
diff --git a/examples/comp.rs b/examples/comp.rs
index 1b4deb5a..8ba44e37 100644
--- a/examples/comp.rs
+++ b/examples/comp.rs
@@ -9,53 +9,47 @@
#![no_std]
mod utils;
-extern crate cortex_m_rt as rt;
-use rt::entry;
+use cortex_m_rt::entry;
#[entry]
fn main() -> ! {
- use hal::comparator::{refint_input, ComparatorExt, ComparatorSplit, Config, Hysteresis};
- use hal::gpio::GpioExt;
- use hal::rcc::RccExt;
- use hal::stm32;
- use stm32g4xx_hal as hal;
-
- let dp = stm32::Peripherals::take().expect("cannot take peripherals");
+ use stm32g4xx_hal::{
+ comparator::{refint_input, ComparatorExt, ComparatorSplit, Config, Hysteresis},
+ gpio::{GpioExt, PushPull},
+ pac,
+ rcc::RccExt,
+ };
+
+ let dp = pac::Peripherals::take().expect("cannot take peripherals");
let mut rcc = dp.RCC.constrain();
let gpioa = dp.GPIOA.split(&mut rcc);
let (comp1, comp2, ..) = dp.COMP.split(&mut rcc);
- let pa1 = gpioa.pa1.into_analog();
- let pa0 = gpioa.pa0.into_analog();
- let comp1 = comp1.comparator(pa1, pa0, Config::default(), &rcc.clocks);
+ let comp1 = comp1.comparator(gpioa.pa1, gpioa.pa0, Config::default(), &rcc.clocks);
let comp1 = comp1.enable();
// led1 pa1 will be updated manually when to match comp1 value
let mut led1 = gpioa.pa5.into_push_pull_output();
- let pa7 = gpioa.pa7.into_analog();
let comp2 = comp2.comparator(
- pa7,
+ gpioa.pa7,
refint_input::VRefintM12,
Config::default()
.hysteresis(Hysteresis::None)
.output_inverted(),
&rcc.clocks,
);
- let led2 = gpioa.pa12.into_push_pull_output();
+ let led2 = gpioa.pa12;
// Configure PA12 to the comparator's alternate function so it gets
// changed directly by the comparator.
- comp2.output_pin(led2);
+ comp2.output_pin::(led2);
let _comp2 = comp2.enable().lock();
loop {
// Read comp1 output and update led1 accordingly
- match comp1.output() {
- true => led1.set_high(),
- false => led1.set_low(),
- }
+ led1.set_state(comp1.output().into());
}
}
diff --git a/examples/comp_w_dac.rs b/examples/comp_w_dac.rs
index 679d819b..1f1dd244 100644
--- a/examples/comp_w_dac.rs
+++ b/examples/comp_w_dac.rs
@@ -10,16 +10,17 @@ use rt::entry;
#[entry]
fn main() -> ! {
- use hal::comparator::{self, ComparatorExt, ComparatorSplit};
- use hal::dac::{Dac1IntSig1, DacExt, DacOut};
- use hal::delay::SYSTDelayExt;
- use hal::gpio::GpioExt;
- use hal::rcc::RccExt;
- use hal::stasis::Freeze;
- use hal::stm32;
- use stm32g4xx_hal as hal;
+ use stm32g4xx_hal::{
+ comparator::{self, ComparatorExt, ComparatorSplit},
+ dac::{Dac1IntSig1, DacExt, DacOut},
+ delay::SYSTDelayExt,
+ gpio::{GpioExt, PushPull},
+ pac,
+ rcc::RccExt,
+ stasis::Freeze,
+ };
- let dp = stm32::Peripherals::take().expect("cannot take peripherals");
+ let dp = pac::Peripherals::take().expect("cannot take peripherals");
let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals");
let mut rcc = dp.RCC.constrain();
@@ -34,20 +35,19 @@ fn main() -> ! {
let (mut dac, [dac_token]) = dac.freeze();
let (comp1, _comp2, ..) = dp.COMP.split(&mut rcc);
- let pa1 = gpioa.pa1.into_analog();
// Set up comparator with pa1 as positive, and the DAC as negative input
let comp = comp1.comparator(
- pa1,
+ gpioa.pa1,
dac_token,
comparator::Config::default().hysteresis(comparator::Hysteresis::None),
&rcc.clocks,
);
- let led2 = gpioa.pa0.into_push_pull_output();
+ let led2 = gpioa.pa0;
// Configure PA12 to the comparator's alternate function so it gets
// changed directly by the comparator.
- comp.output_pin(led2);
+ comp.output_pin::(led2);
let _comp1 = comp.enable().lock();
enum Direction {
diff --git a/examples/cordic.rs b/examples/cordic.rs
index a3efa083..08437212 100644
--- a/examples/cordic.rs
+++ b/examples/cordic.rs
@@ -3,22 +3,20 @@
#![no_main]
#![no_std]
-extern crate cortex_m;
-extern crate cortex_m_rt as rt;
-extern crate stm32g4xx_hal as hal;
-
-use hal::cordic::{
- op::{dynamic::Mode as _, Magnitude, SinCos, Sqrt},
- prec::P60,
- scale::N0,
- types::{I1F15, Q15, Q31},
- Ext as _,
+use cortex_m_rt::entry;
+use stm32g4xx_hal::{
+ cordic::{
+ op::{dynamic::Mode as _, Magnitude, SinCos, Sqrt},
+ prec::P60,
+ scale::N0,
+ types::{I1F15, Q15, Q31},
+ Ext as _,
+ },
+ pac,
+ prelude::*,
+ pwr::PwrExt,
+ rcc::Config,
};
-use hal::prelude::*;
-use hal::pwr::PwrExt;
-use hal::rcc::Config;
-use hal::stm32;
-use rt::entry;
#[macro_use]
mod utils;
@@ -27,7 +25,7 @@ use utils::logger::println;
#[entry]
fn main() -> ! {
- let dp = stm32::Peripherals::take().expect("cannot take peripherals");
+ let dp = pac::Peripherals::take().expect("cannot take peripherals");
let pwr = dp.PWR.constrain().freeze();
let mut rcc = dp.RCC.freeze(Config::hsi(), pwr);
diff --git a/examples/i2c.rs b/examples/i2c.rs
index 4bf0366e..8dacce08 100644
--- a/examples/i2c.rs
+++ b/examples/i2c.rs
@@ -22,12 +22,13 @@ fn main() -> ! {
let mut rcc = dp.RCC.constrain();
let gpiob = dp.GPIOB.split(&mut rcc);
- let sda = gpiob.pb9.into_alternate_open_drain();
- let scl = gpiob.pb8.into_alternate_open_drain();
+ let sda = gpiob.pb9;
+ let scl = gpiob.pb8;
let mut i2c = dp.I2C1.i2c(sda, scl, 40.kHz(), &mut rcc);
// Alternatively, it is possible to specify the exact timing as follows (see the documentation
// of with_timing() for an explanation of the constant):
+ //use hal::i2c::Config;
//let mut i2c = dp
// .I2C1
// .i2c(sda, scl, Config::with_timing(0x3042_0f13), &mut rcc);
diff --git a/examples/spi-dma.rs b/examples/spi-dma.rs
index 318ab48f..5e2cd299 100644
--- a/examples/spi-dma.rs
+++ b/examples/spi-dma.rs
@@ -6,7 +6,6 @@
use crate::hal::{
delay::DelayFromCountDownTimer,
- gpio::{AF5, PA5, PA6, PA7},
prelude::*,
pwr::PwrExt,
rcc::Config,
@@ -40,9 +39,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 = gpioa.pa5.into_alternate();
- let miso: PA6 = gpioa.pa6.into_alternate();
- let mosi: PA7 = gpioa.pa7.into_alternate();
+ let sclk = Some(gpioa.pa5);
+ let miso = Some(gpioa.pa6);
+ let mosi = Some(gpioa.pa7);
let spi = dp
.SPI1
diff --git a/examples/spi-example.rs b/examples/spi-example.rs
index 34194167..3d520b40 100644
--- a/examples/spi-example.rs
+++ b/examples/spi-example.rs
@@ -41,9 +41,12 @@ fn main() -> ! {
let miso: PA6 = gpioa.pa6.into_alternate();
let mosi: PA7 = gpioa.pa7.into_alternate();
- let mut spi = dp
- .SPI1
- .spi((sclk, miso, mosi), spi::MODE_0, 400.kHz(), &mut rcc);
+ let mut spi = dp.SPI1.spi(
+ (Some(sclk), Some(miso), Some(mosi)),
+ spi::MODE_0,
+ 400.kHz(),
+ &mut rcc,
+ );
let mut cs = gpioa.pa8.into_push_pull_output();
cs.set_high();
diff --git a/examples/spi-sd.rs b/examples/spi-sd.rs
index 46e10df2..3dc80386 100644
--- a/examples/spi-sd.rs
+++ b/examples/spi-sd.rs
@@ -43,9 +43,12 @@ fn main() -> ! {
let miso: PB14 = gpiob.pb14.into_alternate();
let mosi: PB15 = gpiob.pb15.into_alternate();
- let spi = dp
- .SPI2
- .spi((sck, miso, mosi), spi::MODE_0, 400.kHz(), &mut rcc);
+ let spi = dp.SPI2.spi(
+ (Some(sck), Some(miso), Some(mosi)),
+ spi::MODE_0,
+ 400.kHz(),
+ &mut rcc,
+ );
struct Clock;
diff --git a/examples/uart-dma-rx.rs b/examples/uart-dma-rx.rs
index 4b26d3fc..bf09f681 100644
--- a/examples/uart-dma-rx.rs
+++ b/examples/uart-dma-rx.rs
@@ -42,14 +42,13 @@ fn main() -> ! {
//let rx = gpioa.pa3.into_alternate();
let gpioc = dp.GPIOC.split(&mut rcc);
let tx = gpioc.pc10.into_alternate();
- let rx = gpioc.pc11.into_alternate();
+ let rx = gpioc.pc11;
let usart = dp
//.USART2
.USART3
.usart(
- tx,
- rx,
+ (tx, rx),
FullConfig::default()
.baudrate(115200.bps())
.receiver_timeout_us(1000), // Timeout after 1ms
diff --git a/examples/uart-dma-tx.rs b/examples/uart-dma-tx.rs
index c52b10e6..a79e28dc 100644
--- a/examples/uart-dma-tx.rs
+++ b/examples/uart-dma-tx.rs
@@ -10,7 +10,6 @@ use core::fmt::Write;
use hal::dma::{channel::DMAExt, config::DmaConfig, TransferExt};
use hal::prelude::*;
use hal::pwr::PwrExt;
-use hal::serial::*;
use hal::time::ExtU32;
use hal::{rcc, stm32};
use stm32g4xx_hal as hal;
@@ -41,16 +40,8 @@ fn main() -> ! {
info!("Init UART");
let gpioa = dp.GPIOA.split(&mut rcc);
let tx = gpioa.pa2.into_alternate();
- let rx = gpioa.pa3.into_alternate();
- let mut usart = dp
- .USART2
- .usart(
- tx,
- rx,
- FullConfig::default().baudrate(115200.bps()),
- &mut rcc,
- )
- .unwrap();
+ let rx = gpioa.pa3;
+ let mut usart = dp.USART2.usart((tx, rx), 115200.bps(), &mut rcc).unwrap();
let mut delay_syst = cp.SYST.delay(&rcc.clocks);
let mut led = gpioa.pa5.into_push_pull_output();
diff --git a/examples/uart-fifo.rs b/examples/uart-fifo.rs
index 801ae471..eb1da3b3 100644
--- a/examples/uart-fifo.rs
+++ b/examples/uart-fifo.rs
@@ -36,8 +36,7 @@ fn main() -> ! {
let mut usart = dp
.USART2
.usart(
- tx,
- rx,
+ (tx, rx),
FullConfig::default()
.baudrate(115200.bps())
.fifo_enable()
diff --git a/examples/uart.rs b/examples/uart.rs
index e4ec6519..8693a37b 100644
--- a/examples/uart.rs
+++ b/examples/uart.rs
@@ -33,14 +33,14 @@ fn main() -> ! {
let rx = gpioa.pa3.into_alternate();
let mut usart = dp
.USART2
- .usart(tx, rx, FullConfig::default(), &mut rcc)
+ .usart(((Some(tx), Some(rx)), FullConfig::default(), &mut rcc)
.unwrap();*/
/*let gpioc = dp.GPIOC.split(&mut rcc);
let tx = gpioc.pc4.into_alternate();
let rx = gpioc.pc5.into_alternate();
let mut usart = dp
.USART1
- .usart(tx, rx, FullConfig::default(), &mut rcc)
+ .usart(((Some(tx), Some(rx)), FullConfig::default(), &mut rcc)
.unwrap();*/
let gpioc = dp.GPIOC.split(&mut rcc);
@@ -48,7 +48,7 @@ fn main() -> ! {
let rx = gpioc.pc11.into_alternate();
let mut usart = dp
.USART3
- .usart(tx, rx, FullConfig::default(), &mut rcc)
+ .usart((tx, rx), FullConfig::default(), &mut rcc)
.unwrap();
writeln!(usart, "Hello USART3, yay!!\r\n").unwrap();
diff --git a/src/can.rs b/src/can.rs
index 8e89eb14..928a2a60 100644
--- a/src/can.rs
+++ b/src/can.rs
@@ -1,193 +1,103 @@
//! # Controller Area Network (CAN) Interface
//!
+use crate::gpio::alt::CanCommon;
use crate::rcc::{self, Rcc};
-mod sealed {
- /// A TX pin configured for CAN communication
- pub trait Tx {}
- /// An RX pin configured for CAN communication
- pub trait Rx {}
-}
+pub trait Instance: CanCommon + rcc::Instance + crate::Ptr {}
/// Storage type for the CAN controller
#[derive(Debug)]
-pub struct Can {
- rb: FDCAN,
+pub struct Can {
+ rb: CAN,
}
#[allow(dead_code)]
-impl Can {
+impl Can {
/// Returns a reference to the inner peripheral
- fn inner(&self) -> &FDCAN {
+ fn inner(&self) -> &CAN {
&self.rb
}
}
/// Extension trait for CAN controller
-pub trait CanExt: Sized
+pub trait CanExt: Sized + Instance
where
- Self: rcc::Instance,
Can: fdcan::Instance,
{
- fn fdcan(
+ fn fdcan(
self,
- _tx: TX,
- _rx: RX,
+ pins: (impl Into, impl Into),
rcc: &mut Rcc,
- ) -> fdcan::FdCan, fdcan::ConfigMode>
- where
- TX: sealed::Tx,
- RX: sealed::Rx,
- {
+ ) -> fdcan::FdCan, fdcan::ConfigMode> {
Self::enable(rcc);
+ let _pins = (pins.0.into(), pins.1.into());
self.fdcan_unchecked()
}
fn fdcan_unchecked(self) -> fdcan::FdCan, fdcan::ConfigMode>;
}
-/// Implements sealed::{Tx,Rx} for pins associated with a CAN peripheral
-macro_rules! pins {
- ($PER:ident =>
- (tx: [ $($( #[ $pmetatx:meta ] )* $tx:ident<$txaf:ident>),+ $(,)? ],
- rx: [ $($( #[ $pmetarx:meta ] )* $rx:ident<$rxaf:ident>),+ $(,)? ])) => {
- $(
- $( #[ $pmetatx ] )*
- impl sealed::Tx<$PER> for $tx<$txaf> {}
- )+
- $(
- $( #[ $pmetarx ] )*
- impl sealed::Rx<$PER> for $rx<$rxaf> {}
- )+
- };
+
+impl Can
+where
+ Self: fdcan::message_ram::Instance,
+{
+ pub fn new(rb: CAN) -> fdcan::FdCan {
+ fdcan::FdCan::new(Self { rb }).into_config_mode()
+ }
+}
+
+unsafe impl fdcan::Instance for Can
+where
+ Self: fdcan::message_ram::Instance,
+{
+ const REGISTERS: *mut fdcan::RegisterBlock = CAN::PTR as *mut _;
+}
+
+impl CanExt for CAN
+where
+ Can: fdcan::message_ram::Instance,
+{
+ fn fdcan_unchecked(self) -> fdcan::FdCan, fdcan::ConfigMode> {
+ Can::new(self)
+ }
}
mod fdcan1 {
- use super::sealed;
- use super::{Can, CanExt};
- use crate::gpio::{AF9, PA11, PA12, PB8, PB9, PD0, PD1};
+ use super::{Can, Instance};
use crate::stm32::FDCAN1;
use fdcan;
- // All STM32G4 models with CAN support these pins
- pins! {
- FDCAN1 => (
- tx: [
- PA12,
- PB9,
- PD1,
- ],
- rx: [
- PA11,
- PB8,
- PD0,
- ]
- )
- }
+ impl Instance for FDCAN1 {}
- impl Can {
- pub fn fdcan1(rb: FDCAN1) -> fdcan::FdCan {
- fdcan::FdCan::new(Self { rb }).into_config_mode()
- }
- }
- impl CanExt for FDCAN1 {
- fn fdcan_unchecked(self) -> fdcan::FdCan, fdcan::ConfigMode> {
- Can::fdcan1(self)
- }
- }
- unsafe impl fdcan::Instance for Can {
- const REGISTERS: *mut fdcan::RegisterBlock = FDCAN1::ptr() as *mut _;
- }
unsafe impl fdcan::message_ram::Instance for Can {
const MSG_RAM: *mut fdcan::message_ram::RegisterBlock = (0x4000_a400 as *mut _);
}
}
-#[cfg(any(
- feature = "stm32g473",
- feature = "stm32g474",
- feature = "stm32g483",
- feature = "stm32g484",
- feature = "stm32g491",
- feature = "stm32g4a1",
-))]
+#[cfg(feature = "fdcan2")]
mod fdcan2 {
- use super::sealed;
- use super::{Can, CanExt};
- use crate::gpio::{AF9, PB12, PB13, PB5, PB6};
+ use super::{Can, Instance};
use crate::stm32::FDCAN2;
use fdcan;
use fdcan::message_ram;
- pins! {
- FDCAN2 => (
- tx: [
- PB6,
- PB13,
- ],
- rx: [
- PB5,
- PB12,
- ])
- }
+ impl Instance for FDCAN2 {}
- impl Can {
- pub fn fdcan2(rb: FDCAN2) -> fdcan::FdCan {
- fdcan::FdCan::new(Self { rb }).into_config_mode()
- }
- }
- impl CanExt for FDCAN2 {
- fn fdcan_unchecked(self) -> fdcan::FdCan, fdcan::ConfigMode> {
- Can::fdcan2(self)
- }
- }
- unsafe impl fdcan::Instance for Can {
- const REGISTERS: *mut fdcan::RegisterBlock = FDCAN2::ptr() as *mut _;
- }
unsafe impl fdcan::message_ram::Instance for Can {
const MSG_RAM: *mut message_ram::RegisterBlock = (0x4000_a750 as *mut _);
}
}
-#[cfg(any(
- feature = "stm32g473",
- feature = "stm32g474",
- feature = "stm32g483",
- feature = "stm32g484",
-))]
+#[cfg(feature = "fdcan3")]
mod fdcan3 {
- use super::sealed;
- use super::{Can, CanExt};
- use crate::gpio::{AF11, PA15, PA8, PB3, PB4};
+ use super::{Can, Instance};
use crate::stm32::FDCAN3;
use fdcan;
use fdcan::message_ram;
- pins! {
- FDCAN3 => (
- tx: [
- PA15,
- PB4,
- ],
- rx: [
- PA8,
- PB3,
- ])
- }
+ impl Instance for FDCAN3 {}
- impl Can {
- pub fn fdcan3(rb: FDCAN3) -> fdcan::FdCan {
- fdcan::FdCan::new(Self { rb }).into_config_mode()
- }
- }
- impl CanExt for FDCAN3 {
- fn fdcan_unchecked(self) -> fdcan::FdCan, fdcan::ConfigMode> {
- Can::fdcan3(self)
- }
- }
- unsafe impl fdcan::Instance for Can {
- const REGISTERS: *mut fdcan::RegisterBlock = FDCAN3::ptr() as *mut _;
- }
unsafe impl fdcan::message_ram::Instance for Can {
const MSG_RAM: *mut message_ram::RegisterBlock = (0x4000_aaa0 as *mut _);
}
diff --git a/src/comparator.rs b/src/comparator.rs
index e5603f4e..1490e928 100644
--- a/src/comparator.rs
+++ b/src/comparator.rs
@@ -9,7 +9,7 @@ use core::marker::PhantomData;
use crate::dac;
use crate::exti::{Event as ExtiEvent, ExtiExt};
-use crate::gpio::{self, Analog, OpenDrain, Output, PushPull, SignalEdge};
+use crate::gpio::{self, alt::CompOutput, Analog, SignalEdge};
use crate::rcc::{Clocks, Rcc};
use crate::stasis;
@@ -157,28 +157,13 @@ positive_input_pin!(COMP2, PA7, PA3);
positive_input_pin!(COMP3, PA0, PC1);
positive_input_pin!(COMP4, PB0, PE7);
-#[cfg(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
-))]
+#[cfg(feature = "comp5")]
positive_input_pin!(COMP5, PB13, PD12);
-#[cfg(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
-))]
+#[cfg(feature = "comp6")]
positive_input_pin!(COMP6, PB11, PD11);
-#[cfg(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
-))]
+#[cfg(feature = "comp7")]
positive_input_pin!(COMP7, PB14, PD14);
macro_rules! negative_input_pin_helper {
@@ -207,12 +192,7 @@ negative_input_pin! {
COMP4: gpio::PE8, gpio::PB2,
}
-#[cfg(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
-))]
+#[cfg(feature = "comp7")]
negative_input_pin! {
COMP5: gpio::PB10, gpio::PD13,
COMP6: gpio::PD10, gpio::PB15,
@@ -273,12 +253,7 @@ macro_rules! refint_input {
refint_input!(COMP1, COMP2, COMP3, COMP4,);
-#[cfg(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
-))]
+#[cfg(feature = "comp7")]
refint_input!(COMP5, COMP6, COMP7,);
macro_rules! dac_input_helper {
@@ -312,49 +287,19 @@ dac_input!(COMP3: Dac1Ch1, 0b101);
dac_input!(COMP4: Dac3Ch2, 0b100);
dac_input!(COMP4: Dac1Ch1, 0b101);
-#[cfg(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
-))]
+#[cfg(feature = "comp5")]
dac_input!(COMP5: Dac4Ch1, 0b100);
-#[cfg(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
-))]
+#[cfg(feature = "comp5")]
dac_input!(COMP5: Dac1Ch2, 0b101);
-#[cfg(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
-))]
+#[cfg(feature = "comp6")]
dac_input!(COMP6: Dac4Ch2, 0b100);
-#[cfg(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
-))]
+#[cfg(feature = "comp6")]
dac_input!(COMP6: Dac2Ch1, 0b101);
-#[cfg(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
-))]
+#[cfg(feature = "comp7")]
dac_input!(COMP7: Dac4Ch1, 0b100);
-#[cfg(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
-))]
+#[cfg(feature = "comp7")]
dac_input!(COMP7: Dac2Ch1, 0b101);
pub struct Comparator {
@@ -400,14 +345,10 @@ macro_rules! impl_comparator {
let voltage_scaler_delay = clocks.sys_clk.raw() / (1_000_000 / 200); // 200us
cortex_m::asm::delay(voltage_scaler_delay);
self.csr().modify(|_, w| unsafe {
- w.hyst()
- .bits(config.hysteresis as u8)
- .scalen()
- .bit(NP::USE_VREFINT)
- .brgen()
- .bit(NP::USE_RESISTOR_DIVIDER)
- .pol()
- .bit(config.inverted)
+ w.hyst().bits(config.hysteresis as u8);
+ w.scalen().bit(NP::USE_VREFINT);
+ w.brgen().bit(NP::USE_RESISTOR_DIVIDER);
+ w.pol().bit(config.inverted)
});
Comparator {
@@ -492,60 +433,37 @@ macro_rules! impl_comparator {
pub fn unpend(&self, exti: &EXTI) {
exti.unpend($Event);
}
-
- /// Configures a GPIO pin to output the signal of the comparator
- ///
- /// Multiple GPIO pins may be configured as the output simultaneously.
- pub fn output_pin>(&self, pin: P) {
- pin.setup();
- }
}
};
}
+impl Comparator {
+ /// Configures a GPIO pin to output the signal of the comparator
+ ///
+ /// Multiple GPIO pins may be configured as the output simultaneously.
+ pub fn output_pin(&self, pin: impl Into>) {
+ let _pin = pin.into();
+ }
+}
+
impl_comparator!(COMP1, comp1, ExtiEvent::COMP1);
impl_comparator!(COMP2, comp2, ExtiEvent::COMP2);
impl_comparator!(COMP3, comp1, ExtiEvent::COMP3);
impl_comparator!(COMP4, comp2, ExtiEvent::COMP4);
-#[cfg(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
-))]
+#[cfg(feature = "comp5")]
impl_comparator!(COMP5, comp1, ExtiEvent::COMP5);
-#[cfg(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
-))]
+#[cfg(feature = "comp6")]
impl_comparator!(COMP6, comp2, ExtiEvent::COMP6);
-#[cfg(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
-))]
+#[cfg(feature = "comp7")]
impl_comparator!(COMP7, comp2, ExtiEvent::COMP7);
-#[cfg(not(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
-)))]
+#[cfg(not(feature = "comp7"))]
type Comparators = (COMP1, COMP2, COMP3, COMP4);
-#[cfg(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
-))]
+#[cfg(feature = "comp7")]
type Comparators = (COMP1, COMP2, COMP3, COMP4, COMP5, COMP6, COMP7);
/// Enables the comparator peripheral, and splits the [`COMP`] into independent [`COMP1`] and [`COMP2`]
@@ -562,26 +480,11 @@ pub fn split(_comp: COMP, rcc: &mut Rcc) -> Comparators {
COMP2 { _rb: PhantomData },
COMP3 { _rb: PhantomData },
COMP4 { _rb: PhantomData },
- #[cfg(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
- ))]
+ #[cfg(feature = "comp5")]
COMP5 { _rb: PhantomData },
- #[cfg(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
- ))]
+ #[cfg(feature = "comp6")]
COMP6 { _rb: PhantomData },
- #[cfg(any(
- feature = "stm32g473",
- feature = "stm32g483",
- feature = "stm32g474",
- feature = "stm32g484"
- ))]
+ #[cfg(feature = "comp7")]
COMP7 { _rb: PhantomData },
)
}
@@ -596,56 +499,3 @@ impl ComparatorSplit for COMP {
split(self, rcc)
}
}
-
-pub trait OutputPin {
- fn setup(self);
-}
-
-#[allow(unused_macros)] // TODO: add support for more devices
-macro_rules! output_pin {
- ($COMP:ident, $pin:ident, $AF:literal, $mode_t:ident, $into:ident) => {
- impl OutputPin<$COMP> for gpio::$pin