9
9
#![ cfg_attr( feature = "stm32wl5x_cm0p" , allow( dead_code) ) ]
10
10
#![ cfg_attr( feature = "stm32wl5x_cm0p" , allow( unused_imports) ) ]
11
11
12
- use crate :: Ratio ;
12
+ #[ cfg( not( feature = "stm32wl5x_cm0p" ) ) ]
13
+ pub use pac:: adc:: cfgr2:: { OVSR_A as OversampleRatio , OVSS_A as OversampleShift } ;
13
14
14
15
use crate :: gpio;
16
+ use crate :: Ratio ;
15
17
16
18
use super :: pac;
17
19
use core:: { ptr:: read_volatile, time:: Duration } ;
@@ -1057,7 +1059,7 @@ impl Adc {
1057
1059
1058
1060
/// Returns `true` if the temperature sensor is enabled.
1059
1061
#[ inline]
1060
- #[ must_use = "no reason to call this function if you are not using the result" ]
1062
+ #[ must_use]
1061
1063
pub fn is_tsen_enabled ( & mut self ) -> bool {
1062
1064
self . adc . ccr . read ( ) . tsen ( ) . is_enabled ( )
1063
1065
}
@@ -1145,11 +1147,48 @@ impl Adc {
1145
1147
1146
1148
/// Returns `true` if the internal voltage reference is enabled.
1147
1149
#[ inline]
1148
- #[ must_use = "no reason to call this function if you are not using the result" ]
1150
+ #[ must_use]
1149
1151
pub fn is_vref_enabled ( & mut self ) -> bool {
1150
1152
self . adc . ccr . read ( ) . vrefen ( ) . is_enabled ( )
1151
1153
}
1152
1154
1155
+ /// Enable oversampling.
1156
+ ///
1157
+ /// # Panics
1158
+ ///
1159
+ /// * (debug) ADC is enabled
1160
+ #[ inline]
1161
+ #[ cfg( not( feature = "stm32wl5x_cm0p" ) ) ]
1162
+ pub fn enable_oversampling ( & mut self , ratio : OversampleRatio , shift : OversampleShift ) {
1163
+ debug_assert ! ( !self . is_enabled( ) ) ;
1164
+ self . adc . cfgr2 . modify ( |_, w| {
1165
+ w. ovse ( )
1166
+ . enabled ( )
1167
+ . ovsr ( )
1168
+ . variant ( ratio)
1169
+ . ovss ( )
1170
+ . variant ( shift)
1171
+ } )
1172
+ }
1173
+
1174
+ /// Disables oversampling.
1175
+ ///
1176
+ /// # Panics
1177
+ ///
1178
+ /// * (debug) ADC is enabled
1179
+ #[ inline]
1180
+ pub fn disable_oversampling ( & mut self ) {
1181
+ debug_assert ! ( !self . is_enabled( ) ) ;
1182
+ self . adc . cfgr2 . modify ( |_, w| w. ovse ( ) . disabled ( ) )
1183
+ }
1184
+
1185
+ /// Returns `true` if oversampling is enabled.
1186
+ #[ inline]
1187
+ #[ must_use]
1188
+ pub fn is_oversampling_enabled ( & mut self ) -> bool {
1189
+ self . adc . cfgr2 . read ( ) . ovse ( ) . is_enabled ( )
1190
+ }
1191
+
1153
1192
/// Read the internal voltage reference.
1154
1193
///
1155
1194
/// # Panics
@@ -1304,7 +1343,7 @@ impl Adc {
1304
1343
1305
1344
/// Returns `true` if V<sub>BAT</sub> is enabled.
1306
1345
#[ inline]
1307
- #[ must_use = "no reason to call this function if you are not using the result" ]
1346
+ #[ must_use]
1308
1347
pub fn is_vbat_enabled ( & self ) -> bool {
1309
1348
self . adc . ccr . read ( ) . vbaten ( ) . is_enabled ( )
1310
1349
}
@@ -1381,14 +1420,14 @@ impl Adc {
1381
1420
/// assert_eq!(adc.is_enabled(), false);
1382
1421
/// ```
1383
1422
#[ inline]
1384
- #[ must_use = "no reason to call this function if you are not using the result" ]
1423
+ #[ must_use]
1385
1424
pub fn is_enabled ( & self ) -> bool {
1386
1425
self . adc . cr . read ( ) . aden ( ) . bit_is_set ( )
1387
1426
}
1388
1427
1389
1428
/// Returns `true` if an ADC disable command is in-progress.
1390
1429
#[ inline]
1391
- #[ must_use = "no reason to call this function if you are not using the result" ]
1430
+ #[ must_use]
1392
1431
pub fn disable_in_progress ( & self ) -> bool {
1393
1432
self . adc . cr . read ( ) . addis ( ) . bit_is_set ( )
1394
1433
}
@@ -1414,7 +1453,7 @@ impl Adc {
1414
1453
/// assert_eq!(adc.is_disabled(), true);
1415
1454
/// ```
1416
1455
#[ inline]
1417
- #[ must_use = "no reason to call this function if you are not using the result" ]
1456
+ #[ must_use]
1418
1457
pub fn is_disabled ( & self ) -> bool {
1419
1458
let cr = self . adc . cr . read ( ) ;
1420
1459
cr. aden ( ) . bit_is_clear ( ) && cr. addis ( ) . bit_is_clear ( )
0 commit comments