Skip to content

Commit 448954a

Browse files
committed
Remove comp impl of devices other than g474
1 parent eb0cac8 commit 448954a

File tree

3 files changed

+55
-24
lines changed

3 files changed

+55
-24
lines changed

examples/comp.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,29 @@
88
#![no_main]
99
#![no_std]
1010

11-
use hal::comparator::{ComparatorExt, ComparatorSplit, Config, Hysteresis, RefintInput};
12-
use hal::gpio::GpioExt;
13-
use hal::prelude::OutputPin;
14-
use hal::rcc::RccExt;
15-
use stm32g4xx_hal as hal;
11+
1612
mod utils;
1713
extern crate cortex_m_rt as rt;
1814

19-
use hal::stm32;
15+
2016
use rt::entry;
2117

18+
#[cfg(not(feature = "stm32g474"))]
2219
#[entry]
2320
fn main() -> ! {
21+
loop{} // TODO: add support for more devices
22+
}
23+
24+
#[cfg(feature = "stm32g474")]
25+
#[entry]
26+
fn main() -> ! {
27+
use hal::stm32;
28+
use hal::comparator::{ComparatorExt, ComparatorSplit, Config, Hysteresis, RefintInput};
29+
use hal::gpio::GpioExt;
30+
use hal::prelude::OutputPin;
31+
use hal::rcc::RccExt;
32+
use stm32g4xx_hal as hal;
33+
2434
let dp = stm32::Peripherals::take().expect("cannot take peripherals");
2535
let mut rcc = dp.RCC.constrain();
2636

examples/comp_w_dac.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,29 @@
33
#![no_main]
44
#![no_std]
55

6-
use embedded_hal::Direction;
7-
use hal::comparator::{self, ComparatorExt, ComparatorSplit};
8-
use hal::dac::{Dac1IntSig1, DacExt, DacOut};
9-
use hal::delay::SYSTDelayExt;
10-
use hal::gpio::GpioExt;
11-
use hal::rcc::RccExt;
12-
use stm32g4xx_hal as hal;
136
mod utils;
147
extern crate cortex_m_rt as rt;
158

16-
use hal::stm32;
179
use rt::entry;
1810

11+
#[cfg(not(feature = "stm32g474"))]
1912
#[entry]
2013
fn main() -> ! {
14+
loop{} // TODO: add support for more devices
15+
}
16+
17+
#[cfg(feature = "stm32g474")]
18+
#[entry]
19+
fn main() -> ! {
20+
use hal::stm32;
21+
use embedded_hal::Direction;
22+
use hal::comparator::{self, ComparatorExt, ComparatorSplit};
23+
use hal::dac::{Dac1IntSig1, DacExt, DacOut};
24+
use hal::delay::SYSTDelayExt;
25+
use hal::gpio::GpioExt;
26+
use hal::rcc::RccExt;
27+
use stm32g4xx_hal as hal;
28+
2129
let dp = stm32::Peripherals::take().expect("cannot take peripherals");
2230
let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals");
2331

src/comparator.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@ use core::marker::PhantomData;
99

1010
use crate::dac;
1111
use crate::exti::{Event as ExtiEvent, ExtiExt};
12-
use crate::gpio::gpioa::{PA0, PA1, PA11, PA12, PA2, PA3, PA4, PA5, PA6, PA7};
13-
use crate::gpio::gpiob::{PB0, PB1, PB14, PB2, PB6, PB7, PB8, PB9};
12+
use crate::gpio::gpioa::{PA0, PA1, PA2, PA3, PA4, PA5, PA7};
13+
use crate::gpio::gpiob::{PB0, PB1, PB2};
1414
use crate::gpio::*;
1515

16+
#[cfg(any(feature = "stm32g474"))]
17+
use crate::gpio::{
18+
gpiob::{PB6, PB7, PB8, PB9},
19+
gpioc::PC2,
20+
gpiof::PF4,
21+
gpioa::{PA11, PA12, PA6},
22+
};
23+
1624
#[cfg(any(
1725
feature = "stm32g473",
1826
feature = "stm32g483",
@@ -27,7 +35,7 @@ use crate::gpio::gpioa::{PA10, PA8, PA9};
2735
feature = "stm32g474",
2836
feature = "stm32g484"
2937
))]
30-
use crate::gpio::gpiob::{PB10, PB11, PB12, PB13, PB15};
38+
use crate::gpio::gpiob::{PB10, PB11, PB12, PB13, PB14, PB15};
3139

3240
#[cfg(any(
3341
feature = "stm32g473",
@@ -43,12 +51,11 @@ use crate::gpio::gpioc::{PC6, PC7, PC8};
4351
feature = "stm32g474",
4452
feature = "stm32g484"
4553
))]
46-
use crate::gpio::gpiod::{PD10, PD11, PD12, PD13, PD15};
54+
use crate::gpio::gpiod::{PD10, PD11, PD12, PD13, PD14, PD15};
4755

48-
use crate::gpio::gpioc::{PC0, PC1, PC2};
49-
use crate::gpio::gpiod::PD14;
56+
use crate::gpio::gpioc::{PC0, PC1};
5057
use crate::gpio::gpioe::{PE7, PE8};
51-
use crate::gpio::gpiof::{PF1, PF4};
58+
use crate::gpio::gpiof::PF1;
5259
use crate::rcc::{Clocks, Rcc};
5360
use crate::stm32::{COMP, EXTI};
5461

@@ -773,6 +780,7 @@ pub trait OutputPin<COMP> {
773780
fn setup(self);
774781
}
775782

783+
#[allow(unused_macros)] // TODO: add support for more devices
776784
macro_rules! output_pin {
777785
($COMP:ident, $pin:ident, $AF:ident, $mode_t:ident, $into:ident) => {
778786
impl OutputPin<$COMP> for $pin<Output<$mode_t>> {
@@ -787,6 +795,9 @@ macro_rules! output_pin {
787795
)+};
788796
}
789797

798+
// TODO: look up alternate functions for more devices than g474
799+
// https://www.mouser.se/datasheet/2/389/stm32g474cb-1600828.pdf#page=73
800+
#[cfg(feature = "stm32g474")]
790801
output_pin! {
791802
COMP1: PA0, AF8,
792803
COMP1: PA6, AF8,
@@ -808,11 +819,13 @@ output_pin! {
808819
COMP4: PB14, AF8,
809820
}
810821

822+
// TODO: look up alternate functions for more devices than g474
823+
// https://www.mouser.se/datasheet/2/389/stm32g474cb-1600828.pdf#page=73
811824
#[cfg(any(
812-
feature = "stm32g473",
813-
feature = "stm32g483",
825+
//feature = "stm32g473",
826+
//feature = "stm32g483",
814827
feature = "stm32g474",
815-
feature = "stm32g484"
828+
//feature = "stm32g484"
816829
))]
817830
output_pin! {
818831
COMP5: PA9, AF8,

0 commit comments

Comments
 (0)