Skip to content

Commit

Permalink
Replace Slave with paste [<$I2c Slave>]
Browse files Browse the repository at this point in the history
  • Loading branch information
ToddG committed Oct 27, 2020
1 parent d093d42 commit 0b4b50a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions avr-hal-generic/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ macro_rules! impl_twi_i2c {
data: $twdr:ident,
},
}
) => {
) => {$crate::paste::paste! {
$(#[$i2c_attr])*
pub struct $I2c<CLOCK: $crate::clock::Clock, M> {
p: $I2C,
Expand Down Expand Up @@ -501,15 +501,15 @@ macro_rules! impl_twi_i2c {
}

$(#[$i2c_attr])*
pub struct Slave<CLOCK: $crate::clock::Clock, M> {
pub struct [<$I2c Slave>]<CLOCK: $crate::clock::Clock, M> {
p: $I2C,
_clock: ::core::marker::PhantomData<CLOCK>,
sda: $sdamod::$SDA<M>,
scl: $sclmod::$SCL<M>,
address: u8,
}

impl<CLOCK> Slave<CLOCK, $crate::i2c::I2cPullUp>
impl<CLOCK> [<$I2c Slave>]<CLOCK, $crate::i2c::I2cPullUp>
where
CLOCK: $crate::clock::Clock,
{
Expand All @@ -526,14 +526,14 @@ macro_rules! impl_twi_i2c {
scl: $sclmod::$SCL<$crate::port::mode::Input<$crate::port::mode::PullUp>>,
speed: u32,
address: u8,
) -> Slave<CLOCK, $crate::i2c::I2cPullUp> {
) -> [<$I2c Slave>]<CLOCK, $crate::i2c::I2cPullUp> {
// Calculate TWBR
let twbr = ((CLOCK::FREQ / speed) - 16) / 2;
p.$twbr.write(|w| unsafe { w.bits(twbr as u8) });
// Disable prescaler
p.$twsr.write(|w| w.$twps().prescaler_1());

Slave {
[<$I2c Slave>] {
p,
sda,
scl,
Expand All @@ -543,7 +543,7 @@ macro_rules! impl_twi_i2c {
}
}

impl<CLOCK> Slave<CLOCK, $crate::i2c::I2cFloating>
impl<CLOCK> [<$I2c Slave>]<CLOCK, $crate::i2c::I2cFloating>
where
CLOCK: $crate::clock::Clock,
{
Expand All @@ -560,14 +560,14 @@ macro_rules! impl_twi_i2c {
scl: $sclmod::$SCL<$crate::port::mode::Input<$crate::port::mode::Floating>>,
speed: u32,
address: u8,
) -> Slave<CLOCK, $crate::i2c::I2cFloating> {
) -> [<$I2c Slave>]<CLOCK, $crate::i2c::I2cFloating> {
// Calculate TWBR
let twbr = ((CLOCK::FREQ / speed) - 16) / 2;
p.$twbr.write(|w| unsafe { w.bits(twbr as u8) });
// Disable prescaler
p.$twsr.write(|w| w.$twps().prescaler_1());

Slave {
[<$I2c Slave>] {
p,
sda,
scl,
Expand All @@ -576,5 +576,5 @@ macro_rules! impl_twi_i2c {
}
}
}
};
}};
}

0 comments on commit 0b4b50a

Please sign in to comment.