Skip to content

Commit 1846fcc

Browse files
hannobraunYatekii
authored andcommitted
Remove TwimExt
1 parent f2bf323 commit 1846fcc

File tree

3 files changed

+16
-33
lines changed

3 files changed

+16
-33
lines changed

examples/twi-ssd1306/src/main.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@ use ssd1306::Builder;
1414
use nrf52832_hal::{
1515
nrf52832_pac as pac,
1616
gpio::*,
17-
twim,
18-
prelude::TwimExt,
17+
twim::{self, Twim},
1918
};
2019

2120
#[cfg(feature = "52840")]
2221
use nrf52840_hal::{
2322
nrf52840_pac as pac,
2423
gpio::*,
25-
twim,
26-
prelude::TwimExt,
24+
twim::{self, Twim},
2725
};
2826

2927

@@ -43,7 +41,7 @@ fn main() -> ! {
4341

4442
let pins = twim::Pins { scl, sda };
4543

46-
let i2c = p.TWIM0.constrain(pins, twim::Frequency::K100);
44+
let i2c = Twim::new(p.TWIM0, pins, twim::Frequency::K100);
4745

4846
let mut disp: GraphicsMode<_> = Builder::new().connect_i2c(i2c).into();
4947

nrf52-hal-common/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ pub mod prelude {
3030
pub use crate::clocks::ClocksExt;
3131
pub use crate::gpio::GpioExt;
3232
pub use crate::time::U32Ext;
33-
pub use crate::twim::TwimExt;
3433
pub use crate::uarte::UarteExt;
3534
}
3635

nrf52-hal-common/src/twim.rs

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,6 @@ use crate::target_constants::EASY_DMA_SIZE;
2626

2727
pub use crate::target::twim0::frequency::FREQUENCYW as Frequency;
2828

29-
pub trait TwimExt: Deref<Target=twim0::RegisterBlock> + Sized {
30-
fn constrain(self, pins: Pins, frequency: Frequency)
31-
-> Twim<Self>;
32-
}
33-
34-
macro_rules! impl_twim_ext {
35-
($($twim:ty,)*) => {
36-
$(
37-
impl TwimExt for $twim {
38-
fn constrain(self, pins: Pins, frequency: Frequency)
39-
-> Twim<Self>
40-
{
41-
Twim::new(self, pins, frequency)
42-
}
43-
}
44-
)*
45-
}
46-
}
47-
48-
impl_twim_ext!(TWIM0,);
49-
50-
#[cfg(any(feature = "52832", feature = "52840"))]
51-
impl_twim_ext!(TWIM1,);
5229

5330
/// Interface to a TWIM instance
5431
///
@@ -61,7 +38,7 @@ impl_twim_ext!(TWIM1,);
6138
/// section 6.1.2 for nRF52840).
6239
pub struct Twim<T>(T);
6340

64-
impl<T> Twim<T> where T: TwimExt {
41+
impl<T> Twim<T> where T: Instance {
6542
pub fn new(twim: T, pins: Pins, frequency: Frequency) -> Self {
6643
// The TWIM peripheral requires the pins to be in a mode that is not
6744
// exposed through the GPIO API, and might it might not make sense to
@@ -374,23 +351,23 @@ impl<T> Twim<T> where T: TwimExt {
374351

375352
/// Implementation of embedded_hal::blocking::i2c Traits
376353
377-
impl<T> embedded_hal::blocking::i2c::Write for Twim<T> where T: TwimExt {
354+
impl<T> embedded_hal::blocking::i2c::Write for Twim<T> where T: Instance {
378355
type Error = Error;
379356

380357
fn write<'w>(&mut self, addr: u8, bytes: &'w [u8]) -> Result<(), Error> {
381358
self.write(addr, bytes)
382359
}
383360
}
384361

385-
impl<T> embedded_hal::blocking::i2c::Read for Twim<T> where T: TwimExt {
362+
impl<T> embedded_hal::blocking::i2c::Read for Twim<T> where T: Instance {
386363
type Error = Error;
387364

388365
fn read<'w>(&mut self, addr: u8, bytes: &'w mut [u8]) -> Result<(), Error> {
389366
self.read(addr, bytes)
390367
}
391368
}
392369

393-
impl<T> embedded_hal::blocking::i2c::WriteRead for Twim<T> where T: TwimExt {
370+
impl<T> embedded_hal::blocking::i2c::WriteRead for Twim<T> where T: Instance {
394371
type Error = Error;
395372

396373
fn write_read<'w>(&mut self, addr: u8, bytes:&'w[u8], buffer: &'w mut [u8]) -> Result<(), Error> {
@@ -417,3 +394,12 @@ pub enum Error {
417394
Transmit,
418395
Receive,
419396
}
397+
398+
399+
/// Implemented by all TWIM instances
400+
pub trait Instance: Deref<Target=twim0::RegisterBlock> {}
401+
402+
impl Instance for TWIM0 {}
403+
404+
#[cfg(any(feature = "52832", feature = "52840"))]
405+
impl Instance for TWIM1 {}

0 commit comments

Comments
 (0)