Skip to content

Commit b3ce8c2

Browse files
committed
Prevent using dac with incorrect mode as input to comparator
1 parent 6e4ac90 commit b3ce8c2

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

src/comparator.rs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,9 @@ refint_input!(COMP1, COMP2, COMP3, COMP4,);
345345
))]
346346
refint_input!(COMP5, COMP6, COMP7,);
347347

348-
macro_rules! dac_input {
349-
($COMP:ident: $channel:ty, $bits:expr) => {
350-
impl<const MODE: u8, ED> NegativeInput<$COMP> for &$channel {
348+
macro_rules! dac_input_helper {
349+
($COMP:ident: $channel:ident, $MODE:ident, $bits:expr) => {
350+
impl<ED> NegativeInput<$COMP> for &dac::$channel<{dac::$MODE}, ED> {
351351
const USE_VREFINT: bool = false;
352352

353353
fn use_resistor_divider(&self) -> bool {
@@ -361,62 +361,69 @@ macro_rules! dac_input {
361361
};
362362
}
363363

364-
dac_input!(COMP1: dac::Dac3Ch1<MODE, ED>, 0b100);
365-
dac_input!(COMP1: dac::Dac1Ch1<MODE, ED>, 0b101);
364+
macro_rules! dac_input {
365+
($COMP:ident: $channel:ident, $bits:expr) => {
366+
dac_input_helper!($COMP: $channel, M_MIX_SIG, $bits);
367+
dac_input_helper!($COMP: $channel, M_INT_SIG, $bits);
368+
};
369+
}
370+
371+
dac_input!(COMP1: Dac3Ch1, 0b100);
372+
dac_input!(COMP1: Dac1Ch1, 0b101);
366373

367-
dac_input!(COMP2: dac::Dac3Ch2<MODE, ED>, 0b100);
368-
dac_input!(COMP2: dac::Dac1Ch2<MODE, ED>, 0b101);
374+
dac_input!(COMP2: Dac3Ch2, 0b100);
375+
dac_input!(COMP2: Dac1Ch2, 0b101);
369376

370-
dac_input!(COMP3: dac::Dac3Ch1<MODE, ED>, 0b100);
371-
dac_input!(COMP3: dac::Dac1Ch1<MODE, ED>, 0b101);
377+
dac_input!(COMP3: Dac3Ch1, 0b100);
378+
dac_input!(COMP3: Dac1Ch1, 0b101);
372379

373-
dac_input!(COMP4: dac::Dac3Ch2<MODE, ED>, 0b100);
374-
dac_input!(COMP4: dac::Dac1Ch1<MODE, ED>, 0b101);
380+
dac_input!(COMP4: Dac3Ch2, 0b100);
381+
dac_input!(COMP4: Dac1Ch1, 0b101);
375382

376383
#[cfg(any(
377384
feature = "stm32g473",
378385
feature = "stm32g483",
379386
feature = "stm32g474",
380387
feature = "stm32g484"
381388
))]
382-
dac_input!(COMP5: dac::Dac4Ch1<MODE, ED>, 0b100);
389+
dac_input!(COMP5: Dac4Ch1, 0b100);
383390
#[cfg(any(
384391
feature = "stm32g473",
385392
feature = "stm32g483",
386393
feature = "stm32g474",
387394
feature = "stm32g484"
388395
))]
389-
dac_input!(COMP5: dac::Dac1Ch2<MODE, ED>, 0b101);
396+
dac_input!(COMP5: Dac1Ch2, 0b101);
390397

391398
#[cfg(any(
392399
feature = "stm32g473",
393400
feature = "stm32g483",
394401
feature = "stm32g474",
395402
feature = "stm32g484"
396403
))]
397-
dac_input!(COMP6: dac::Dac4Ch2<MODE, ED>, 0b100);
404+
dac_input!(COMP6: Dac4Ch2, 0b100);
398405
#[cfg(any(
399406
feature = "stm32g473",
400407
feature = "stm32g483",
401408
feature = "stm32g474",
402409
feature = "stm32g484"
403410
))]
404-
dac_input!(COMP6: dac::Dac2Ch1<MODE, ED>, 0b101);
411+
dac_input!(COMP6: Dac2Ch1, 0b101);
405412

406413
#[cfg(any(
407414
feature = "stm32g473",
408415
feature = "stm32g483",
409416
feature = "stm32g474",
410417
feature = "stm32g484"
411418
))]
412-
dac_input!(COMP7: dac::Dac4Ch1<MODE, ED>, 0b100);
419+
dac_input!(COMP7: Dac4Ch1, 0b100);
413420
#[cfg(any(
414421
feature = "stm32g473",
415422
feature = "stm32g483",
416423
feature = "stm32g474",
417424
feature = "stm32g484"
418425
))]
419-
dac_input!(COMP7: dac::Dac2Ch1<MODE, ED>, 0b101);
426+
dac_input!(COMP7: Dac2Ch1, 0b101);
420427

421428
pub struct Comparator<C, ED> {
422429
regs: C,

src/dac.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,14 @@ pub trait Pins<DAC> {
8383
type Output;
8484
}
8585

86-
const M_EXT_PIN: u8 = 0b000;
87-
const M_MIX_SIG: u8 = 0b001;
88-
const M_INT_SIG: u8 = 0b011;
86+
/// Dac output mode: external pin only
87+
pub const M_EXT_PIN: u8 = 0b000;
88+
89+
/// Dac output mode: internal signal and external pin
90+
pub const M_MIX_SIG: u8 = 0b001;
91+
92+
/// Dac output mode: internal signal only
93+
pub const M_INT_SIG: u8 = 0b011;
8994

9095
pub struct Dac1IntSig1;
9196
pub struct Dac1IntSig2;

0 commit comments

Comments
 (0)