@@ -26,29 +26,6 @@ use crate::target_constants::EASY_DMA_SIZE;
26
26
27
27
pub use crate :: target:: twim0:: frequency:: FREQUENCYW as Frequency ;
28
28
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 , ) ;
52
29
53
30
/// Interface to a TWIM instance
54
31
///
@@ -61,7 +38,7 @@ impl_twim_ext!(TWIM1,);
61
38
/// section 6.1.2 for nRF52840).
62
39
pub struct Twim < T > ( T ) ;
63
40
64
- impl < T > Twim < T > where T : TwimExt {
41
+ impl < T > Twim < T > where T : Instance {
65
42
pub fn new ( twim : T , pins : Pins , frequency : Frequency ) -> Self {
66
43
// The TWIM peripheral requires the pins to be in a mode that is not
67
44
// exposed through the GPIO API, and might it might not make sense to
@@ -374,23 +351,23 @@ impl<T> Twim<T> where T: TwimExt {
374
351
375
352
/// Implementation of embedded_hal::blocking::i2c Traits
376
353
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 {
378
355
type Error = Error ;
379
356
380
357
fn write < ' w > ( & mut self , addr : u8 , bytes : & ' w [ u8 ] ) -> Result < ( ) , Error > {
381
358
self . write ( addr, bytes)
382
359
}
383
360
}
384
361
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 {
386
363
type Error = Error ;
387
364
388
365
fn read < ' w > ( & mut self , addr : u8 , bytes : & ' w mut [ u8 ] ) -> Result < ( ) , Error > {
389
366
self . read ( addr, bytes)
390
367
}
391
368
}
392
369
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 {
394
371
type Error = Error ;
395
372
396
373
fn write_read < ' w > ( & mut self , addr : u8 , bytes : & ' w [ u8 ] , buffer : & ' w mut [ u8 ] ) -> Result < ( ) , Error > {
@@ -417,3 +394,12 @@ pub enum Error {
417
394
Transmit ,
418
395
Receive ,
419
396
}
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