@@ -50,8 +50,8 @@ ch.set_freq(2.kHz());
5050use core:: marker:: PhantomData ;
5151
5252use crate :: clocks:: { Clock , HostClock , PeripheralIdentifier } ;
53- use crate :: legacy_ehal:: PwmPin ;
5453use crate :: fugit:: HertzU32 as Hertz ;
54+ use crate :: legacy_ehal:: PwmPin ;
5555use crate :: pac:: {
5656 pwm0:: { RegisterBlock , PWM_CH_NUM as ChannelRegister } ,
5757 PWM0 , PWM1 ,
@@ -730,7 +730,8 @@ impl<M: PwmMeta, I: ChannelId> ErrorType for Channel<M, I> {
730730}
731731
732732impl < M : PwmMeta , I : ChannelId > SetDutyCycle for Channel < M , I > {
733- fn max_duty_cycle ( & self ) -> u16 { // TODO: we need to be smarter with scaling
733+ fn max_duty_cycle ( & self ) -> u16 {
734+ // TODO: we need to be smarter with scaling
734735 let max = self . reg ( ) . cprd ( ) . read ( ) . cprd ( ) . bits ( ) ;
735736 let shift = max. leading_zeros ( ) . saturating_sub ( 16 ) ;
736737 ( self . reg ( ) . cprd ( ) . read ( ) . cprd ( ) . bits ( ) >> shift & 0xFFFF ) as u16 // ? what if frequency changes
@@ -744,13 +745,13 @@ impl<M: PwmMeta, I: ChannelId> SetDutyCycle for Channel<M, I> {
744745 let max = self . reg ( ) . cprd ( ) . read ( ) . cprd ( ) . bits ( ) ;
745746 let shift = max. leading_zeros ( ) . saturating_sub ( 16 ) ;
746747 if duty > ( max >> ( shift & 0xFFFF ) ) as u16 {
747- return core:: result:: Result :: Err ( Self :: Error :: InvalidDutyCycle )
748+ return core:: result:: Result :: Err ( Self :: Error :: InvalidDutyCycle ) ;
748749 }
749750 // TODO: that's copy&paste from `self.apply_duty()`, consider commonalization
750751 if self . is_enabled ( ) {
751- self . reg ( )
752- . cdtyupd ( )
753- . write ( |w| unsafe { w. cdtyupd ( ) . bits ( ( duty as u32 ) << shift) } ) ;
752+ self . reg ( )
753+ . cdtyupd ( )
754+ . write ( |w| unsafe { w. cdtyupd ( ) . bits ( ( duty as u32 ) << shift) } ) ;
754755 } else {
755756 self . reg ( )
756757 . cdty ( )
@@ -759,4 +760,4 @@ impl<M: PwmMeta, I: ChannelId> SetDutyCycle for Channel<M, I> {
759760 core:: result:: Result :: Ok ( ( ) )
760761 }
761762 }
762- }
763+ }
0 commit comments