Skip to content

Commit 2bcebfe

Browse files
Piroro-hsSh3Rm4n
authored andcommitted
Simplify I2C hal macro invocation
1 parent b492dc4 commit 2bcebfe

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/i2c.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ macro_rules! busy_wait {
8282
};
8383
}
8484

85-
macro_rules! hal {
85+
macro_rules! i2c {
8686
($($I2CX:ident: ($i2cX:ident, $i2cXen:ident, $i2cXrst:ident, $i2cXsw:ident),)+) => {
8787
$(
8888
impl<SCL, SDA> I2c<$I2CX, (SCL, SDA)> {
@@ -417,7 +417,15 @@ macro_rules! hal {
417417
}
418418
}
419419
)+
420-
}
420+
};
421+
422+
([ $($X:literal),+ ]) => {
423+
paste::paste! {
424+
i2c!(
425+
$([<I2C $X>]: ([<i2c $X>], [<i2c $X en>], [<i2c $X rst>], [<i2c $X sw>]),)+
426+
);
427+
}
428+
};
421429
}
422430

423431
#[cfg(any(
@@ -431,12 +439,7 @@ macro_rules! hal {
431439
feature = "stm32f378",
432440
feature = "stm32f398",
433441
))]
434-
hal! {
435-
I2C1: (i2c1, i2c1en, i2c1rst, i2c1sw),
436-
I2C2: (i2c2, i2c2en, i2c2rst, i2c2sw),
437-
}
442+
i2c!([1, 2]);
438443

439444
#[cfg(feature = "stm32f334")]
440-
hal! {
441-
I2C1: (i2c1, i2c1en, i2c1rst, i2c1sw),
442-
}
445+
i2c!([1]);

0 commit comments

Comments
 (0)