@@ -428,6 +428,42 @@ impl Adc {
428
428
adc
429
429
}
430
430
431
+ /// Create a new ADC driver from an ADC peripheral without initialization.
432
+ ///
433
+ /// This is a slightly safer version of [`steal`](Self::steal).
434
+ ///
435
+ /// # Safety
436
+ ///
437
+ /// 1. Reset the ADC peripheral if determinism is required.
438
+ /// 2. Enable the ADC peripheral clock before using the ADC.
439
+ /// 3. Select the clock source if a non-default clock is required.
440
+ ///
441
+ /// # Example
442
+ ///
443
+ /// ```no_run
444
+ /// use stm32wl_hal::{
445
+ /// adc::{self, Adc},
446
+ /// pac,
447
+ /// };
448
+ ///
449
+ /// let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
450
+ ///
451
+ /// // safety: nothing is using the peripheral
452
+ /// unsafe { Adc::pulse_reset(&mut dp.RCC) };
453
+ ///
454
+ /// Adc::enable_clock(&mut dp.RCC);
455
+ ///
456
+ /// // safety: ADC peripheral has been reset and clocks are enabled
457
+ /// let mut adc: Adc = unsafe { Adc::new_no_init(dp.ADC) };
458
+ ///
459
+ /// // select the ADC clock, optional
460
+ /// adc.set_clock_source(adc::Clk::PClkDiv4, &mut dp.RCC);
461
+ /// ```
462
+ #[ inline]
463
+ pub const unsafe fn new_no_init ( adc : pac:: ADC ) -> Self {
464
+ Self { adc }
465
+ }
466
+
431
467
/// Free the ADC peripheral from the driver.
432
468
///
433
469
/// # Example
@@ -456,16 +492,29 @@ impl Adc {
456
492
///
457
493
/// 1. Ensure that the code stealing the ADC has exclusive access to the
458
494
/// peripheral. Singleton checks are bypassed with this method.
459
- /// 2. You are responsible for setting up the ADC correctly.
495
+ /// 2. Reset the ADC peripheral if determinism is required.
496
+ /// 3. Enable the ADC peripheral clock before using the ADC.
497
+ /// 4. Select the clock source if a non-default clock is required.
460
498
///
461
499
/// # Example
462
500
///
463
- /// ```
464
- /// use stm32wl_hal::adc::Adc;
501
+ /// ```no_run
502
+ /// use stm32wl_hal::{
503
+ /// adc::{self, Adc},
504
+ /// pac,
505
+ /// };
506
+ ///
507
+ /// let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
508
+ /// let _: pac::ADC = dp.ADC;
509
+ ///
510
+ /// unsafe { Adc::pulse_reset(&mut dp.RCC) };
465
511
///
466
- /// // ... setup happens here
512
+ /// Adc::enable_clock(&mut dp.RCC);
467
513
///
468
- /// let adc = unsafe { Adc::steal() };
514
+ /// let mut adc: Adc = unsafe { Adc::steal() };
515
+ ///
516
+ /// // select the ADC clock, optional
517
+ /// adc.set_clock_source(adc::Clk::PClkDiv4, &mut dp.RCC);
469
518
/// ```
470
519
///
471
520
/// [`new`]: Adc::new
0 commit comments