Skip to content

Commit

Permalink
ESP32C6: Make ADC usable after TRNG deinitialization (#1945)
Browse files Browse the repository at this point in the history
* Make `ADC` usable after `TRNG` deinicialization (esp32c6)

* Changelog entry
  • Loading branch information
playfulFence authored Aug 14, 2024
1 parent c83d1de commit 945f8b3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
1 change: 1 addition & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- SPI: Clear DMA interrupts before (not after) DMA starts (#1859)
- SPI: disable and re-enable MISO and MOSI in `start_transfer_dma`, `start_read_bytes_dma` and `start_write_bytes_dma` accordingly (#1894)
- TWAI: GPIO pins are not configured as input and output (#1906)
- ESP32C6: Make ADC usable after TRNG deinicialization (#1945)

### Removed

Expand Down
10 changes: 3 additions & 7 deletions esp-hal/src/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl rand_core::RngCore for Rng {
/// let mut trng = Trng::new(peripherals.RNG, &mut peripherals.ADC1);
/// trng.read(&mut buf);
/// let mut true_rand = trng.random();
#[cfg_attr(not(esp32c6), doc = "let mut rng = trng.downgrade();")]
/// let mut rng = trng.downgrade();
/// // ADC is available now
#[cfg_attr(esp32, doc = "let analog_pin = io.pins.gpio32;")]
#[cfg_attr(not(esp32), doc = "let analog_pin = io.pins.gpio3;")]
Expand All @@ -161,8 +161,8 @@ impl rand_core::RngCore for Rng {
/// Attenuation::Attenuation11dB); let mut adc1 =
/// Adc::<ADC1>::new(peripherals.ADC1, adc1_config); let pin_value: u16 =
/// nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap();
#[cfg_attr(not(esp32c6), doc = "rng.read(&mut buf);")]
#[cfg_attr(not(esp32c6), doc = "true_rand = rng.random();")]
/// rng.read(&mut buf);
/// true_rand = rng.random();
/// let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap();
/// # }
/// ```
Expand Down Expand Up @@ -208,15 +208,11 @@ impl<'d> Trng<'d> {

/// Downgrades the `Trng` instance to a `Rng` instance and releases the
/// ADC1.
/// For esp32c6 - blocked on <https://github.com/espressif/esp-idf/issues/14124>
#[cfg(not(esp32c6))]
pub fn downgrade(self) -> Rng {
self.rng
}
}

/// For esp32c6 - blocked on <https://github.com/espressif/esp-idf/issues/14124>
#[cfg(not(esp32c6))]
impl<'d> Drop for Trng<'d> {
fn drop(&mut self) {
crate::soc::trng::revert_trng();
Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/soc/esp32c6/trng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,6 @@ pub(crate) fn revert_trng() {
0,
);

pmu.rf_pwc().modify(|_, w| w.perif_i2c_rstb().clear_bit());

pcr.saradc_clkm_conf().modify(|_, w| w.bits(0x00404000));

pcr.saradc_conf().modify(|_, w| w.bits(0x5));
Expand Down

0 comments on commit 945f8b3

Please sign in to comment.