@@ -232,47 +232,46 @@ macro_rules! hal {
232
232
self . enable( ) ;
233
233
}
234
234
235
- /// Check if the specified event has been triggered for this LPTIM .
235
+ /// Check if the specified event has been triggered for this LowPowerTimer .
236
236
///
237
- /// This function must be called if an event which this LPTIM listens to has
238
- /// generated an interrupt
239
- ///
240
- /// If the event has occured, and `clear_interrupt` is true, the interrupt flag for this
241
- /// event will be cleared. Otherwise, the interrupt flag for this event will not
242
- /// be cleared.
243
- pub fn is_event_triggered( & self , event: Event , clear_interrupt: bool ) -> bool {
237
+ /// If this function returns `true` for an `Event` that this LowPowerTimer is listening for,
238
+ /// [`LowPowerTimer::clear_event_flag`] must be called for that event to prevent the
239
+ /// interrupt from looping eternally. This is not done in a single function to
240
+ /// avoid using a mutable reference for an operation that does not require it.
241
+ pub fn is_event_triggered( & self , event: Event ) -> bool {
244
242
let reg_val = self . lptim. isr. read( ) ;
245
- let bit_is_set = match event {
243
+ match event {
246
244
Event :: CompareMatch => reg_val. cmpm( ) . bit_is_set( ) ,
247
245
Event :: AutoReloadMatch => reg_val. arrm( ) . bit_is_set( ) ,
248
- } ;
249
- if bit_is_set && clear_interrupt {
250
- self . lptim. icr. write( |w| match event {
251
- Event :: CompareMatch => w. cmpmcf( ) . set_bit( ) ,
252
- Event :: AutoReloadMatch => w. arrmcf( ) . set_bit( ) ,
253
- } ) ;
254
246
}
255
- bit_is_set
256
247
}
257
248
258
- /// Set the compare match field for this LPTIM
249
+ /// Clear the interrupt flag for the specified event
250
+ pub fn clear_event_flag( & mut self , event: Event ) {
251
+ self . lptim. icr. write( |w| match event {
252
+ Event :: CompareMatch => w. cmpmcf( ) . set_bit( ) ,
253
+ Event :: AutoReloadMatch => w. arrmcf( ) . set_bit( ) ,
254
+ } ) ;
255
+ }
256
+
257
+ /// Set the compare match field for this LowPowerTimer
259
258
#[ inline]
260
259
pub fn set_compare_match( & mut self , value: u16 ) {
261
260
// This operation is sound as compare_value is a u16, and there are 16 writeable bits
262
261
// Additionally, the LPTIM peripheral will always be in the enabled state when this code is called
263
262
self . lptim. cmp. write( |w| unsafe { w. bits( value as u32 ) } ) ;
264
263
}
265
264
266
- /// Get the current counter value for this LPTIM
265
+ /// Get the current counter value for this LowPowerTimer
267
266
#[ inline]
268
- pub fn get_counter( & mut self ) -> u16 {
267
+ pub fn get_counter( & self ) -> u16 {
269
268
self . lptim. cnt. read( ) . bits( ) as u16
270
269
}
271
270
272
- /// Get the value of the LPTIM_ARR register for this
273
- /// LPTIM
271
+ /// Get the value of the ARR register for this
272
+ /// LowPowerTimer
274
273
#[ inline]
275
- pub fn get_arr( & mut self ) -> u16 {
274
+ pub fn get_arr( & self ) -> u16 {
276
275
self . lptim. arr. read( ) . bits( ) as u16
277
276
}
278
277
}
0 commit comments