Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32C6: Make ADC usable after TRNG deinitialization #1945

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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