@@ -815,39 +815,44 @@ pub trait Capture {
815
815
/// # Pwm1
816
816
/// };
817
817
///
818
- /// pwm.set_period (1.khz());
818
+ /// pwm.try_set_period (1.khz()).unwrap( );
819
819
///
820
- /// let max_duty = pwm.get_max_duty ();
820
+ /// let max_duty = pwm.try_get_max_duty().unwrap ();
821
821
///
822
822
/// // brightest LED
823
- /// pwm.set_duty (Channel::_1, max_duty);
823
+ /// pwm.try_set_duty (Channel::_1, max_duty).unwrap( );
824
824
///
825
825
/// // dimmer LED
826
- /// pwm.set_duty (Channel::_2, max_duty / 4);
826
+ /// pwm.try_set_duty (Channel::_2, max_duty / 4).unwrap( );
827
827
/// }
828
828
///
829
+ /// # use core::convert::Infallible;
829
830
/// # struct KiloHertz(u32);
830
831
/// # trait U32Ext { fn khz(self) -> KiloHertz; }
831
832
/// # impl U32Ext for u32 { fn khz(self) -> KiloHertz { KiloHertz(self) } }
832
833
/// # enum Channel { _1, _2 }
833
834
/// # struct Pwm1;
834
835
/// # impl hal::Pwm for Pwm1 {
836
+ /// # type Error = Infallible;
835
837
/// # type Channel = Channel;
836
838
/// # type Time = KiloHertz;
837
839
/// # type Duty = u16;
838
- /// # fn disable (&mut self, _: Channel) { unimplemented!() }
839
- /// # fn enable (&mut self, _: Channel) { unimplemented!() }
840
- /// # fn get_duty (&self, _: Channel) -> u16 { unimplemented!() }
841
- /// # fn get_max_duty (&self) -> u16 { 0 }
842
- /// # fn set_duty (&mut self, _: Channel, _: u16) {}
843
- /// # fn get_period (&self) -> KiloHertz { unimplemented!() }
844
- /// # fn set_period <T>(&mut self, _: T) where T: Into<KiloHertz> {}
840
+ /// # fn try_disable (&mut self, _: Channel) -> Result<(), Self::Error> { unimplemented!() }
841
+ /// # fn try_enable (&mut self, _: Channel) -> Result<(), Self::Error> { unimplemented!() }
842
+ /// # fn try_get_duty (&self, _: Channel) -> Result< u16, Self::Error> { unimplemented!() }
843
+ /// # fn try_get_max_duty (&self) -> Result< u16, Self::Error> { 0 }
844
+ /// # fn try_set_duty (&mut self, _: Channel, _: u16) -> Result<(), Self::Error> {}
845
+ /// # fn try_get_period (&self) -> Result< KiloHertz, Self::Error> { unimplemented!() }
846
+ /// # fn try_set_period <T>(&mut self, _: T) -> Result<(), Self::Error> where T: Into<KiloHertz> {}
845
847
/// # }
846
848
/// ```
847
849
#[ cfg( feature = "unproven" ) ]
848
850
// reason: pre-singletons API. The `PwmPin` trait seems more useful because it models independent
849
851
// PWM channels. Here a certain number of channels are multiplexed in a single implementer.
850
852
pub trait Pwm {
853
+ /// Enumeration of `Pwm` errors
854
+ type Error ;
855
+
851
856
/// Enumeration of channels that can be used with this `Pwm` interface
852
857
///
853
858
/// If your `Pwm` interface has no channels you can use the type `()`
@@ -864,25 +869,26 @@ pub trait Pwm {
864
869
type Duty ;
865
870
866
871
/// Disables a PWM `channel`
867
- fn disable ( & mut self , channel : Self :: Channel ) ;
872
+ fn try_disable ( & mut self , channel : Self :: Channel ) -> Result < ( ) , Self :: Error > ;
868
873
869
874
/// Enables a PWM `channel`
870
- fn enable ( & mut self , channel : Self :: Channel ) ;
875
+ fn try_enable ( & mut self , channel : Self :: Channel ) -> Result < ( ) , Self :: Error > ;
871
876
872
877
/// Returns the current PWM period
873
- fn get_period ( & self ) -> Self :: Time ;
878
+ fn try_get_period ( & self ) -> Result < Self :: Time , Self :: Error > ;
874
879
875
880
/// Returns the current duty cycle
876
- fn get_duty ( & self , channel : Self :: Channel ) -> Self :: Duty ;
881
+ fn try_get_duty ( & self , channel : Self :: Channel ) -> Result < Self :: Duty , Self :: Error > ;
877
882
878
883
/// Returns the maximum duty cycle value
879
- fn get_max_duty ( & self ) -> Self :: Duty ;
884
+ fn try_get_max_duty ( & self ) -> Result < Self :: Duty , Self :: Error > ;
880
885
881
886
/// Sets a new duty cycle
882
- fn set_duty ( & mut self , channel : Self :: Channel , duty : Self :: Duty ) ;
887
+ fn try_set_duty ( & mut self , channel : Self :: Channel , duty : Self :: Duty )
888
+ -> Result < ( ) , Self :: Error > ;
883
889
884
890
/// Sets a new PWM period
885
- fn set_period < P > ( & mut self , period : P )
891
+ fn try_set_period < P > ( & mut self , period : P ) -> Result < ( ) , Self :: Error >
886
892
where
887
893
P : Into < Self :: Time > ;
888
894
}
0 commit comments