Skip to content

Commit

Permalink
treewide: i2c: Rename I2c struct to I2cMaster
Browse files Browse the repository at this point in the history
In preparation for a future addition of an I2C slave driver, rename the
I2C master driver to `I2cMaster`.  To ease migration, add a type-alias
for the old name which is marked as deprecated.  This alias will be
removed at a later time when most users have switched to the new name.

Co-authored-by: toddg <toddg@zwrob.com>
Signed-off-by: Rahix <rahix@rahix.de>
  • Loading branch information
Rahix and ToddG committed Nov 15, 2020
1 parent 6fa17e3 commit 0735300
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 28 deletions.
28 changes: 14 additions & 14 deletions avr-hal-generic/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,16 @@ macro_rules! impl_twi_i2c {
scl: $sclmod:ident::$SCL:ident,
},
}
) => {
) => {$crate::paste::paste! {
$(#[$i2c_attr])*
pub struct $I2c<CLOCK: $crate::clock::Clock, M> {
pub struct [<$I2c Master>]<CLOCK: $crate::clock::Clock, M> {
p: $I2C,
_clock: ::core::marker::PhantomData<CLOCK>,
sda: $sdamod::$SDA<M>,
scl: $sclmod::$SCL<M>,
}

impl<CLOCK> $I2c<CLOCK, $crate::i2c::I2cPullUp>
impl<CLOCK> [<$I2c Master>]<CLOCK, $crate::i2c::I2cPullUp>
where
CLOCK: $crate::clock::Clock,
{
Expand All @@ -209,8 +209,8 @@ macro_rules! impl_twi_i2c {
sda: $sdamod::$SDA<$crate::port::mode::Input<$crate::port::mode::PullUp>>,
scl: $sclmod::$SCL<$crate::port::mode::Input<$crate::port::mode::PullUp>>,
speed: u32,
) -> $I2c<CLOCK, $crate::i2c::I2cPullUp> {
let mut i2c = $I2c {
) -> [<$I2c Master>]<CLOCK, $crate::i2c::I2cPullUp> {
let mut i2c = [<$I2c Master>] {
p,
sda,
scl,
Expand All @@ -222,7 +222,7 @@ macro_rules! impl_twi_i2c {
}
}

impl<CLOCK> $I2c<CLOCK, $crate::i2c::I2cFloating>
impl<CLOCK> [<$I2c Master>]<CLOCK, $crate::i2c::I2cFloating>
where
CLOCK: $crate::clock::Clock,
{
Expand All @@ -236,8 +236,8 @@ macro_rules! impl_twi_i2c {
sda: $sdamod::$SDA<$crate::port::mode::Input<$crate::port::mode::Floating>>,
scl: $sclmod::$SCL<$crate::port::mode::Input<$crate::port::mode::Floating>>,
speed: u32,
) -> $I2c<CLOCK, $crate::i2c::I2cFloating> {
let mut i2c = $I2c {
) -> [<$I2c Master>]<CLOCK, $crate::i2c::I2cFloating> {
let mut i2c = [<$I2c Master>] {
p,
sda,
scl,
Expand All @@ -249,7 +249,7 @@ macro_rules! impl_twi_i2c {
}
}

impl<CLOCK, M> $I2c<CLOCK, M>
impl<CLOCK, M> [<$I2c Master>]<CLOCK, M>
where
CLOCK: $crate::clock::Clock,
{
Expand Down Expand Up @@ -414,7 +414,7 @@ macro_rules! impl_twi_i2c {
}
}

impl<CLOCK, M> $I2c<CLOCK, M>
impl<CLOCK, M> [<$I2c Master>]<CLOCK, M>
where
CLOCK: $crate::clock::Clock,
$crate::delay::Delay<CLOCK>: $crate::hal::blocking::delay::DelayMs<u16>,
Expand All @@ -438,7 +438,7 @@ macro_rules! impl_twi_i2c {
}


impl<CLOCK, M> $crate::hal::blocking::i2c::Write for $I2c<CLOCK, M>
impl<CLOCK, M> $crate::hal::blocking::i2c::Write for [<$I2c Master>]<CLOCK, M>
where
CLOCK: $crate::clock::Clock,
{
Expand All @@ -452,7 +452,7 @@ macro_rules! impl_twi_i2c {
}
}

impl<CLOCK, M> $crate::hal::blocking::i2c::Read for $I2c<CLOCK, M>
impl<CLOCK, M> $crate::hal::blocking::i2c::Read for [<$I2c Master>]<CLOCK, M>
where
CLOCK: $crate::clock::Clock,
{
Expand All @@ -466,7 +466,7 @@ macro_rules! impl_twi_i2c {
}
}

impl<CLOCK, M> $crate::hal::blocking::i2c::WriteRead for $I2c<CLOCK, M>
impl<CLOCK, M> $crate::hal::blocking::i2c::WriteRead for [<$I2c Master>]<CLOCK, M>
where
CLOCK: $crate::clock::Clock,
{
Expand All @@ -486,5 +486,5 @@ macro_rules! impl_twi_i2c {
Ok(())
}
}
};
}};
}
2 changes: 1 addition & 1 deletion boards/arduino-diecimila/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ pub use crate::hal::spi;

pub type Delay = crate::hal::delay::Delay<hal::clock::MHz16>;
pub type Serial<IMODE> = crate::hal::usart::Usart0<hal::clock::MHz16, IMODE>;
pub type I2c<M> = crate::hal::i2c::I2c<hal::clock::MHz16, M>;
pub type I2cMaster<M> = crate::hal::i2c::I2cMaster<hal::clock::MHz16, M>;
2 changes: 1 addition & 1 deletion boards/arduino-leonardo/examples/leonardo-i2cdetect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() -> ! {
pins.d1.into_output(&mut pins.ddr),
57600.into_baudrate(),
);
let mut i2c = arduino_leonardo::I2c::new(
let mut i2c = arduino_leonardo::I2cMaster::new(
dp.TWI,
pins.d2.into_pull_up_input(&mut pins.ddr),
pins.d3.into_pull_up_input(&mut pins.ddr),
Expand Down
7 changes: 5 additions & 2 deletions boards/arduino-leonardo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ pub type Serial<IMODE> = hal::usart::Usart1<hal::clock::MHz16, IMODE>;
///
/// let mut pins = arduino_leonardo::Pins::new(dp.PORTB, dp.PORTC, dp.PORTD, dp.PORTE);
///
/// let mut i2c = arduino_leonardo::I2c::new(
/// let mut i2c = arduino_leonardo::I2cMaster::new(
/// dp.TWI,
/// pins.d2.into_pull_up_input(&mut pins.ddr),
/// pins.d3.into_pull_up_input(&mut pins.ddr),
Expand All @@ -218,7 +218,10 @@ pub type Serial<IMODE> = hal::usart::Usart1<hal::clock::MHz16, IMODE>;
/// ```
///
/// [ex-i2c]: https://github.com/Rahix/avr-hal/blob/master/boards/arduino-leonardo/examples/leonardo-i2cdetect.rs
pub type I2c<M> = hal::i2c::I2c<hal::clock::MHz16, M>;
pub type I2cMaster<M> = hal::i2c::I2cMaster<hal::clock::MHz16, M>;
#[doc(hidden)]
#[deprecated = "Please use `I2cMaster` instead of `I2c`"]
pub type I2c<M> = I2cMaster<M>;

/// Support for the Watchdog Timer
///
Expand Down
2 changes: 1 addition & 1 deletion boards/arduino-mega2560/examples/mega2560-i2cdetect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() -> ! {
porte.pe1.into_output(&mut porte.ddr),
57600.into_baudrate(),
);
let mut i2c = arduino_mega2560::I2c::new(
let mut i2c = arduino_mega2560::I2cMaster::new(
dp.TWI,
portd.pd1.into_pull_up_input(&mut portd.ddr),
portd.pd0.into_pull_up_input(&mut portd.ddr),
Expand Down
5 changes: 4 additions & 1 deletion boards/arduino-mega2560/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ pub mod usart {
pub type Usart3<IMODE> = crate::hal::usart::Usart3<crate::hal::clock::MHz16, IMODE>;
}

pub type I2c<M> = crate::hal::i2c::I2c<hal::clock::MHz16, M>;
pub type I2cMaster<M> = crate::hal::i2c::I2cMaster<hal::clock::MHz16, M>;
#[doc(hidden)]
#[deprecated = "Please use `I2cMaster` instead of `I2c`"]
pub type I2c<M> = I2cMaster<M>;

/// Support for PWM pins
///
Expand Down
2 changes: 1 addition & 1 deletion boards/arduino-uno/examples/uno-i2cdetect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() -> ! {
pins.d1.into_output(&mut pins.ddr),
57600.into_baudrate(),
);
let mut i2c = arduino_uno::I2c::new(
let mut i2c = arduino_uno::I2cMaster::new(
dp.TWI,
pins.a4.into_pull_up_input(&mut pins.ddr),
pins.a5.into_pull_up_input(&mut pins.ddr),
Expand Down
7 changes: 5 additions & 2 deletions boards/arduino-uno/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ pub type Serial<IMODE> = hal::usart::Usart0<hal::clock::MHz16, IMODE>;
///
/// let mut pins = arduino_uno::Pins::new(dp.PORTB, dp.PORTC, dp.PORTD);
///
/// let mut i2c = arduino_uno::I2c::new(
/// let mut i2c = arduino_uno::I2cMaster::new(
/// dp.TWI,
/// pins.a4.into_pull_up_input(&mut pins.ddr),
/// pins.a5.into_pull_up_input(&mut pins.ddr),
Expand All @@ -222,7 +222,10 @@ pub type Serial<IMODE> = hal::usart::Usart0<hal::clock::MHz16, IMODE>;
/// ```
///
/// [ex-i2c]: https://github.com/Rahix/avr-hal/blob/master/boards/arduino-uno/examples/uno-i2cdetect.rs
pub type I2c<M> = hal::i2c::I2c<hal::clock::MHz16, M>;
pub type I2cMaster<M> = hal::i2c::I2cMaster<hal::clock::MHz16, M>;
#[doc(hidden)]
#[deprecated = "Please use `I2cMaster` instead of `I2c`"]
pub type I2c<M> = I2cMaster<M>;

/// Support for the WatchDog Timer
///
Expand Down
2 changes: 1 addition & 1 deletion boards/bigavr6/examples/bigavr6-i2cdetect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() -> ! {
porte.pe1.into_output(&mut porte.ddr),
57600.into_baudrate(),
);
let mut i2c = bigavr6::I2c::new(
let mut i2c = bigavr6::I2cMaster::new(
dp.TWI,
portd.pd1.into_pull_up_input(&mut portd.ddr),
portd.pd0.into_pull_up_input(&mut portd.ddr),
Expand Down
5 changes: 4 additions & 1 deletion boards/bigavr6/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ pub mod prelude {

pub type Delay = crate::hal::delay::Delay<hal::clock::MHz16>;
pub type Serial<IMODE> = crate::hal::usart::Usart0<hal::clock::MHz16, IMODE>;
pub type I2c<M> = crate::hal::i2c::I2c<hal::clock::MHz16, M>;
pub type I2cMaster<M> = crate::hal::i2c::I2cMaster<hal::clock::MHz16, M>;
#[doc(hidden)]
#[deprecated = "Please use `I2cMaster` instead of `I2c`"]
pub type I2c<M> = I2cMaster<M>;
2 changes: 1 addition & 1 deletion boards/sparkfun-pro-micro/examples/pro-micro-i2cdetect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() -> ! {
pins.d1.into_output(&mut pins.ddr),
57600.into_baudrate(),
);
let mut i2c = sparkfun_pro_micro::I2c::new(
let mut i2c = sparkfun_pro_micro::I2cMaster::new(
dp.TWI,
pins.d2.into_pull_up_input(&mut pins.ddr),
pins.d3.into_pull_up_input(&mut pins.ddr),
Expand Down
7 changes: 5 additions & 2 deletions boards/sparkfun-pro-micro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub type Serial<IMODE> = hal::usart::Usart1<hal::clock::MHz16, IMODE>;
///
/// let mut pins = sparkfun_pro_micro::Pins::new(dp.PORTB, dp.PORTC, dp.PORTD, dp.PORTE, dp.PORTF);
///
/// let mut i2c = sparkfun_pro_micro::I2c::new(
/// let mut i2c = sparkfun_pro_micro::I2cMaster::new(
/// dp.TWI,
/// pins.d2.into_pull_up_input(&mut pins.ddr),
/// pins.d3.into_pull_up_input(&mut pins.ddr),
Expand All @@ -213,4 +213,7 @@ pub type Serial<IMODE> = hal::usart::Usart1<hal::clock::MHz16, IMODE>;
/// ```
///
/// [ex-i2c]: https://github.com/Rahix/avr-hal/blob/master/boards/sparkfun-pro-micro/examples/pro-micro-i2cdetect.rs
pub type I2c<M> = hal::i2c::I2c<hal::clock::MHz16, M>;
pub type I2cMaster<M> = hal::i2c::I2cMaster<hal::clock::MHz16, M>;
#[doc(hidden)]
#[deprecated = "Please use `I2cMaster` instead of `I2c`"]
pub type I2c<M> = I2cMaster<M>;

0 comments on commit 0735300

Please sign in to comment.