@@ -497,15 +497,14 @@ where
497497 sda : impl Peripheral < P = SDA > + ' d ,
498498 scl : impl Peripheral < P = SCL > + ' d ,
499499 frequency : HertzU32 ,
500- timeout : Option < u32 > ,
501500 ) -> Self {
502501 crate :: into_ref!( i2c, sda, scl) ;
503502
504503 let i2c = I2c {
505504 i2c,
506505 phantom : PhantomData ,
507506 frequency,
508- timeout,
507+ timeout : None ,
509508 } ;
510509
511510 PeripheralClockControl :: reset ( i2c. i2c . peripheral ( ) ) ;
@@ -530,7 +529,7 @@ where
530529 sda. connect_input_to_peripheral ( i2c. i2c . sda_input_signal ( ) , crate :: private:: Internal ) ;
531530 sda. connect_peripheral_to_output ( i2c. i2c . sda_output_signal ( ) , crate :: private:: Internal ) ;
532531
533- i2c. i2c . setup ( frequency, timeout ) ;
532+ i2c. i2c . setup ( frequency, None ) ;
534533 i2c
535534 }
536535
@@ -548,35 +547,34 @@ where
548547
549548 self . i2c . setup ( self . frequency , self . timeout ) ;
550549 }
550+
551+ /// Set the I2C timeout.
552+ // TODO: explain this function better - what's the unit, what happens on
553+ // timeout, and just what exactly is a timeout in this context?
554+ pub fn set_timeout ( & mut self , timeout : Option < u32 > ) {
555+ self . timeout = timeout;
556+ self . i2c . setup ( self . frequency , self . timeout ) ;
557+ }
558+
559+ /// Moving version of [`Self::set_timeout`] suitable for use during
560+ /// peripheral initialization.
561+ pub fn with_timeout ( mut self , timeout : Option < u32 > ) -> Self {
562+ self . set_timeout ( timeout) ;
563+ self
564+ }
551565}
552566
553567impl < ' d > I2c < ' d , Blocking > {
554568 /// Create a new I2C instance
555569 /// This will enable the peripheral but the peripheral won't get
556570 /// automatically disabled when this gets dropped.
557571 pub fn new < SDA : PeripheralOutput + PeripheralInput , SCL : PeripheralOutput + PeripheralInput > (
558- i2c : impl Peripheral < P = impl Into < AnyI2c > > + ' d ,
559- sda : impl Peripheral < P = SDA > + ' d ,
560- scl : impl Peripheral < P = SCL > + ' d ,
561- frequency : HertzU32 ,
562- ) -> Self {
563- Self :: new_with_timeout ( i2c, sda, scl, frequency, None )
564- }
565-
566- /// Create a new I2C instance with a custom timeout value.
567- /// This will enable the peripheral but the peripheral won't get
568- /// automatically disabled when this gets dropped.
569- pub fn new_with_timeout <
570- SDA : PeripheralOutput + PeripheralInput ,
571- SCL : PeripheralOutput + PeripheralInput ,
572- > (
573- i2c : impl Peripheral < P = impl Into < AnyI2c > > + ' d ,
572+ i2c : impl Peripheral < P = impl Instance > + ' d ,
574573 sda : impl Peripheral < P = SDA > + ' d ,
575574 scl : impl Peripheral < P = SCL > + ' d ,
576575 frequency : HertzU32 ,
577- timeout : Option < u32 > ,
578576 ) -> Self {
579- Self :: new_with_timeout_typed ( i2c. map_into ( ) , sda, scl, frequency, timeout )
577+ Self :: new_typed ( i2c. map_into ( ) , sda, scl, frequency)
580578 }
581579}
582580
@@ -596,23 +594,7 @@ where
596594 scl : impl Peripheral < P = SCL > + ' d ,
597595 frequency : HertzU32 ,
598596 ) -> Self {
599- Self :: new_with_timeout_typed ( i2c, sda, scl, frequency, None )
600- }
601-
602- /// Create a new I2C instance with a custom timeout value.
603- /// This will enable the peripheral but the peripheral won't get
604- /// automatically disabled when this gets dropped.
605- pub fn new_with_timeout_typed <
606- SDA : PeripheralOutput + PeripheralInput ,
607- SCL : PeripheralOutput + PeripheralInput ,
608- > (
609- i2c : impl Peripheral < P = T > + ' d ,
610- sda : impl Peripheral < P = SDA > + ' d ,
611- scl : impl Peripheral < P = SCL > + ' d ,
612- frequency : HertzU32 ,
613- timeout : Option < u32 > ,
614- ) -> Self {
615- Self :: new_internal ( i2c, sda, scl, frequency, timeout)
597+ Self :: new_internal ( i2c, sda, scl, frequency)
616598 }
617599}
618600
@@ -627,39 +609,40 @@ where
627609 }
628610}
629611
630- impl < ' d , T > I2c < ' d , Async , T >
631- where
632- T : Instance ,
633- {
612+ impl < ' d > I2c < ' d , Async > {
634613 /// Create a new I2C instance
635614 /// This will enable the peripheral but the peripheral won't get
636615 /// automatically disabled when this gets dropped.
637616 pub fn new_async <
638617 SDA : PeripheralOutput + PeripheralInput ,
639618 SCL : PeripheralOutput + PeripheralInput ,
640619 > (
641- i2c : impl Peripheral < P = T > + ' d ,
620+ i2c : impl Peripheral < P = impl Instance > + ' d ,
642621 sda : impl Peripheral < P = SDA > + ' d ,
643622 scl : impl Peripheral < P = SCL > + ' d ,
644623 frequency : HertzU32 ,
645624 ) -> Self {
646- Self :: new_with_timeout_async ( i2c, sda, scl, frequency, None )
625+ Self :: new_async_typed ( i2c. map_into ( ) , sda, scl, frequency)
647626 }
627+ }
648628
649- /// Create a new I2C instance with a custom timeout value.
629+ impl < ' d , T > I2c < ' d , Async , T >
630+ where
631+ T : Instance ,
632+ {
633+ /// Create a new I2C instance
650634 /// This will enable the peripheral but the peripheral won't get
651635 /// automatically disabled when this gets dropped.
652- pub fn new_with_timeout_async <
636+ pub fn new_async_typed <
653637 SDA : PeripheralOutput + PeripheralInput ,
654638 SCL : PeripheralOutput + PeripheralInput ,
655639 > (
656640 i2c : impl Peripheral < P = T > + ' d ,
657641 sda : impl Peripheral < P = SDA > + ' d ,
658642 scl : impl Peripheral < P = SCL > + ' d ,
659643 frequency : HertzU32 ,
660- timeout : Option < u32 > ,
661644 ) -> Self {
662- let mut this = Self :: new_internal ( i2c, sda, scl, frequency, timeout ) ;
645+ let mut this = Self :: new_internal ( i2c, sda, scl, frequency) ;
663646
664647 this. internal_set_interrupt_handler ( this. i2c . async_handler ( ) ) ;
665648
0 commit comments