@@ -174,7 +174,7 @@ use crate::pac;
174174
175175use crate :: rcc:: { rec, CoreClocks , ResetEnable } ;
176176use crate :: time:: { Hertz , NanoSeconds } ;
177- use crate :: timer:: GetClk ;
177+ use crate :: timer:: { GetClk , Event } ;
178178use fugit:: ExtU32 ;
179179
180180// This trait marks that a GPIO pin can be used with a specific timer channel
@@ -842,6 +842,49 @@ macro_rules! tim_hal {
842842 }
843843 }
844844
845+ impl <F > PwmControl <$TIMX, F > {
846+ /// Start listening for `event`
847+ pub fn listen( & mut self , event: Event ) {
848+ match event {
849+ Event :: TimeOut => {
850+ let tim = unsafe { <$TIMX>:: steal( ) } ;
851+ // Enable update event interrupt
852+ tim. dier( ) . write( |w| w. uie( ) . set_bit( ) ) ;
853+ }
854+ }
855+ }
856+
857+ /// Stop listening for `event`
858+ pub fn unlisten( & mut self , event: Event ) {
859+ match event {
860+ Event :: TimeOut => {
861+ let tim = unsafe { <$TIMX>:: steal( ) } ;
862+ // Disable update event interrupt
863+ tim. dier( ) . write( |w| w. uie( ) . clear_bit( ) ) ;
864+ let _ = tim. dier( ) . read( ) ;
865+ let _ = tim. dier( ) . read( ) ; // Delay 2 peripheral clocks
866+ }
867+ }
868+ }
869+
870+ /// Check if Update Interrupt flag is cleared
871+ pub fn is_irq_clear( & mut self ) -> bool {
872+ let tim = unsafe { <$TIMX>:: steal( ) } ;
873+ tim. sr( ) . read( ) . uif( ) . bit_is_clear( )
874+ }
875+
876+ /// Clears interrupt flag
877+ pub fn clear_irq( & mut self ) {
878+ let tim = unsafe { <$TIMX>:: steal( ) } ;
879+ tim. sr( ) . modify( |_, w| {
880+ // Clears timeout event
881+ w. uif( ) . clear_bit( )
882+ } ) ;
883+ let _ = tim. sr( ) . read( ) ;
884+ let _ = tim. sr( ) . read( ) ; // Delay 2 peripheral clocks
885+ }
886+ }
887+
845888 impl FaultMonitor for PwmControl <$TIMX, FaultEnabled > {
846889 fn is_fault_active( & self ) -> bool {
847890 let tim = unsafe { & * <$TIMX>:: ptr( ) } ;
0 commit comments