From 48e6171930aaf55ae79eab323f50a0b666dc38f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Mon, 4 Sep 2023 12:24:45 +0200 Subject: [PATCH] Some general cleanup (#777) * Executor related touchups * Fix typos * Clean up DAC, remove hidden public API * Clean up ADC * Clean up analog peripheral reexports * Properly hide rmt macros --- esp-hal-common/src/analog/adc/esp32.rs | 16 ++---- esp-hal-common/src/analog/adc/riscv.rs | 38 +++++-------- esp-hal-common/src/analog/adc/xtensa.rs | 24 +++------ esp-hal-common/src/analog/dac.rs | 54 +++++++------------ .../src/embassy/executor/xtensa/thread.rs | 7 --- esp-hal-common/src/lib.rs | 4 +- esp-hal-common/src/rmt.rs | 14 ++--- esp32s2-hal/src/lib.rs | 2 + 8 files changed, 51 insertions(+), 108 deletions(-) diff --git a/esp-hal-common/src/analog/adc/esp32.rs b/esp-hal-common/src/analog/adc/esp32.rs index 34a56ec75bd..87a7160e175 100644 --- a/esp-hal-common/src/analog/adc/esp32.rs +++ b/esp-hal-common/src/analog/adc/esp32.rs @@ -2,8 +2,8 @@ use core::marker::PhantomData; use embedded_hal::adc::{Channel, OneShot}; +pub use crate::analog::{ADC1, ADC2}; use crate::{ - analog::{ADC1, ADC2}, peripheral::PeripheralRef, peripherals::{RTC_IO, SENS}, }; @@ -401,15 +401,13 @@ where } } -#[doc(hidden)] -#[macro_export] macro_rules! impl_adc_interface { ($adc:ident [ $( ($pin:ident, $channel:expr) ,)+ ]) => { $( - impl Channel<$adc> for $pin { + impl embedded_hal::adc::Channel<$adc> for crate::gpio::$pin { type ID = u8; fn channel() -> u8 { $channel } @@ -418,9 +416,9 @@ macro_rules! impl_adc_interface { } } -pub use impl_adc_interface; +pub use implementation::*; -pub mod implementation { +mod implementation { //! # Analog to digital (ADC) conversion support. //! //! ## Overview @@ -468,11 +466,7 @@ pub mod implementation { //! } //! ``` - use embedded_hal::adc::Channel; - - use super::impl_adc_interface; - pub use crate::analog::{adc::*, ADC1, ADC2}; - use crate::gpio::*; + use crate::analog::{ADC1, ADC2}; impl_adc_interface! { ADC1 [ diff --git a/esp-hal-common/src/analog/adc/riscv.rs b/esp-hal-common/src/analog/adc/riscv.rs index f0e0c7f8ca1..94aacb9e558 100644 --- a/esp-hal-common/src/analog/adc/riscv.rs +++ b/esp-hal-common/src/analog/adc/riscv.rs @@ -2,14 +2,14 @@ use core::marker::PhantomData; use embedded_hal::adc::{Channel, OneShot}; +pub use crate::analog::ADC1; #[cfg(esp32c3)] -use crate::analog::ADC2; +pub use crate::analog::ADC2; #[cfg(any(esp32c6, esp32h2))] use crate::clock::clocks_ll::regi2c_write_mask; #[cfg(any(esp32c2, esp32c3, esp32c6))] use crate::efuse::Efuse; use crate::{ - analog::ADC1, peripheral::PeripheralRef, peripherals::APB_SARADC, system::{Peripheral, PeripheralClockControl}, @@ -670,15 +670,13 @@ where } } -#[doc(hidden)] -#[macro_export] macro_rules! impl_adc_interface { ($adc:ident [ $( ($pin:ident, $channel:expr) ,)+ ]) => { $( - impl Channel<$adc> for $pin { + impl embedded_hal::adc::Channel<$adc> for crate::gpio::$pin { type ID = u8; fn channel() -> u8 { $channel } @@ -687,10 +685,10 @@ macro_rules! impl_adc_interface { } } -pub use impl_adc_interface; +pub use implementation::*; #[cfg(esp32c2)] -pub mod implementation { +mod implementation { //! # Analog to digital (ADC) conversion support. //! //! ## Overview @@ -727,10 +725,7 @@ pub mod implementation { //! } //! ``` - use embedded_hal::adc::Channel; - - pub use crate::analog::{adc::*, ADC1}; - use crate::gpio::*; + pub use crate::analog::ADC1; impl_adc_interface! { ADC1 [ @@ -744,7 +739,7 @@ pub mod implementation { } #[cfg(esp32c3)] -pub mod implementation { +mod implementation { //! # Analog to digital (ADC) conversion support. //! //! ## Overview @@ -782,10 +777,7 @@ pub mod implementation { //! } //! ``` - use embedded_hal::adc::Channel; - - pub use crate::analog::{adc::*, ADC1, ADC2}; - use crate::gpio::*; + pub use crate::analog::{ADC1, ADC2}; impl_adc_interface! { ADC1 [ @@ -805,7 +797,7 @@ pub mod implementation { } #[cfg(esp32c6)] -pub mod implementation { +mod implementation { //! # Analog to digital (ADC) conversion support. //! //! ## Overview @@ -842,10 +834,7 @@ pub mod implementation { //! } //! ``` - use embedded_hal::adc::Channel; - - pub use crate::analog::{adc::*, ADC1}; - use crate::gpio::*; + pub use crate::analog::ADC1; impl_adc_interface! { ADC1 [ @@ -861,7 +850,7 @@ pub mod implementation { } #[cfg(esp32h2)] -pub mod implementation { +mod implementation { //! # Analog to digital (ADC) conversion support. //! //! ## Overview @@ -898,10 +887,7 @@ pub mod implementation { //! } //! ``` - use embedded_hal::adc::Channel; - - pub use crate::analog::{adc::*, ADC1}; - use crate::gpio::*; + pub use crate::analog::ADC1; impl_adc_interface! { ADC1 [ diff --git a/esp-hal-common/src/analog/adc/xtensa.rs b/esp-hal-common/src/analog/adc/xtensa.rs index 4f790e37135..191c4f1432c 100644 --- a/esp-hal-common/src/analog/adc/xtensa.rs +++ b/esp-hal-common/src/analog/adc/xtensa.rs @@ -2,10 +2,10 @@ use core::marker::PhantomData; use embedded_hal::adc::{Channel, OneShot}; +pub use crate::analog::{ADC1, ADC2}; #[cfg(esp32s3)] use crate::efuse::Efuse; use crate::{ - analog::{ADC1, ADC2}, peripheral::PeripheralRef, peripherals::{APB_SARADC, SENS}, }; @@ -733,15 +733,13 @@ where } } -#[doc(hidden)] -#[macro_export] macro_rules! impl_adc_interface { ($adc:ident [ $( ($pin:ident, $channel:expr) ,)+ ]) => { $( - impl Channel<$adc> for $pin { + impl embedded_hal::adc::Channel<$adc> for crate::gpio::$pin { type ID = u8; fn channel() -> u8 { $channel } @@ -750,10 +748,10 @@ macro_rules! impl_adc_interface { } } -pub use impl_adc_interface; +pub use implementation::*; #[cfg(esp32s3)] -pub mod implementation { +mod implementation { //! # Analog to digital (ADC) conversion support. //! //! ## Overview @@ -787,11 +785,7 @@ pub mod implementation { //! } //! ``` - use embedded_hal::adc::Channel; - - use super::impl_adc_interface; - pub use crate::analog::{adc::*, ADC1, ADC2}; - use crate::gpio::*; + use crate::analog::{ADC1, ADC2}; impl_adc_interface! { ADC1 [ @@ -825,7 +819,7 @@ pub mod implementation { } #[cfg(esp32s2)] -pub mod implementation { +mod implementation { //! # Analog to digital (ADC) conversion support. //! //! ## Overview @@ -859,11 +853,7 @@ pub mod implementation { //! } //! ``` - use embedded_hal::adc::Channel; - - use super::impl_adc_interface; - pub use crate::analog::{adc::*, ADC1, ADC2}; - use crate::gpio::*; + use crate::analog::{ADC1, ADC2}; impl_adc_interface! { ADC1 [ diff --git a/esp-hal-common/src/analog/dac.rs b/esp-hal-common/src/analog/dac.rs index 598bd357fb3..2715738e65c 100644 --- a/esp-hal-common/src/analog/dac.rs +++ b/esp-hal-common/src/analog/dac.rs @@ -12,16 +12,12 @@ //! makes it easier for users to generate accurate analog voltages in their //! applications, such as audio generation, sensor calibration, and analog //! signal synthesis. -use crate::{ - peripheral::PeripheralRef, - peripherals::{RTC_IO, SENS}, -}; +use crate::peripherals::{RTC_IO, SENS}; pub trait DAC { fn write(&mut self, value: u8); } -#[doc(hidden)] -pub trait DAC1Impl { +trait DAC1Impl { fn set_power(self) -> Self where Self: Sized, @@ -58,8 +54,7 @@ pub trait DAC1Impl { } } -#[doc(hidden)] -pub trait DAC2Impl { +trait DAC2Impl { fn set_power(self) -> Self where Self: Sized, @@ -96,21 +91,16 @@ pub trait DAC2Impl { } } -#[doc(hidden)] -#[macro_export] macro_rules! impl_dac { - ($($number:literal => $gpio:ident,)+) => { - use core::marker::PhantomData; - use crate::gpio; - + ($($number:literal => $gpio:ident),+) => { $( paste::paste! { - pub use $crate::analog::dac::[]; + use $crate::analog::dac::[]; - /// DAC channel + #[doc = "DAC channel " $number] pub struct []<'d, DAC> { - _dac: PeripheralRef<'d, DAC>, - _private: PhantomData<()>, + _dac: $crate::peripheral::PeripheralRef<'d, DAC>, + _private: ::core::marker::PhantomData<()>, } impl<'d, DAC> [] for []<'d, DAC> {} @@ -119,17 +109,17 @@ macro_rules! impl_dac { /// Constructs a new DAC instance pub fn dac( dac: impl $crate::peripheral::Peripheral

+'d, - _pin: gpio::$gpio<$crate::gpio::Analog>, + _pin: $crate::gpio::$gpio<$crate::gpio::Analog>, ) -> Result { let dac = Self { _dac: dac.into_ref(), - _private: PhantomData, + _private: ::core::marker::PhantomData, } .set_power(); Ok(dac) } - /// Write the given value + /// Writes the given value /// /// For each DAC channel, the output analog voltage can be calculated as follows: /// DACn_OUT = VDD3P3_RTC * PDACn_DAC/256 @@ -142,34 +132,28 @@ macro_rules! impl_dac { }; } -pub use impl_dac; +pub use implementation::*; #[cfg(esp32)] -pub mod implementation { +mod implementation { //! Digital to analog (DAC) conversion. //! - //! This module provides functions for controling two digital to + //! This module provides functions for controlling two digital to //! analog converters, available on ESP32: `DAC1` and `DAC2`. //! //! The DAC1 is available on the GPIO pin 25, and DAC2 on pin 26. - pub use super::*; - use crate::impl_dac; - - impl_dac!(1 => Gpio25, 2 => Gpio26,); + impl_dac!(1 => Gpio25, 2 => Gpio26); } #[cfg(esp32s2)] -pub mod implementation { +mod implementation { //! Digital to analog (DAC) conversion. //! - //! This module provides functions for controling two digital to - //! analog converters, available on ESP32: `DAC1` and `DAC2`. + //! This module provides functions for controlling two digital to + //! analog converters, available on ESP32-S2: `DAC1` and `DAC2`. //! //! The DAC1 is available on the GPIO pin 17, and DAC2 on pin 18. - pub use super::*; - use crate::impl_dac; - - impl_dac!(1 => Gpio17, 2 => Gpio18,); + impl_dac!(1 => Gpio17, 2 => Gpio18); } diff --git a/esp-hal-common/src/embassy/executor/xtensa/thread.rs b/esp-hal-common/src/embassy/executor/xtensa/thread.rs index 184ae1560f8..7c346e50014 100644 --- a/esp-hal-common/src/embassy/executor/xtensa/thread.rs +++ b/esp-hal-common/src/embassy/executor/xtensa/thread.rs @@ -37,13 +37,6 @@ fn FROM_CPU_INTR0() { } pub(super) fn pend_thread_mode(core: usize) { - use core::sync::atomic::Ordering; - - #[cfg(dport)] - use crate::peripherals::DPORT as SystemPeripheral; - #[cfg(system)] - use crate::peripherals::SYSTEM as SystemPeripheral; - // Signal that there is work to be done. SIGNAL_WORK_THREAD_MODE[core].store(true, Ordering::SeqCst); diff --git a/esp-hal-common/src/lib.rs b/esp-hal-common/src/lib.rs index 3f086834fc5..18e2d52e635 100644 --- a/esp-hal-common/src/lib.rs +++ b/esp-hal-common/src/lib.rs @@ -41,9 +41,9 @@ pub use xtensa_lx; pub use xtensa_lx_rt::{self, entry}; #[cfg(adc)] -pub use self::analog::adc::implementation as adc; +pub use self::analog::adc; #[cfg(dac)] -pub use self::analog::dac::implementation as dac; +pub use self::analog::dac; #[cfg(any(xtensa, all(riscv, systimer)))] pub use self::delay::Delay; #[cfg(gdma)] diff --git a/esp-hal-common/src/rmt.rs b/esp-hal-common/src/rmt.rs index 5880957916f..c9f0997a491 100644 --- a/esp-hal-common/src/rmt.rs +++ b/esp-hal-common/src/rmt.rs @@ -1068,7 +1068,6 @@ mod chip_specific { } } - #[macro_export] macro_rules! impl_tx_channel { ($channel:ident, $signal:ident, $ch_num:literal) => { paste::paste! { @@ -1228,7 +1227,6 @@ mod chip_specific { } } - #[macro_export] macro_rules! impl_rx_channel { ($channel:ident, $signal:ident, $ch_num:literal) => { paste::paste! { @@ -1338,8 +1336,8 @@ mod chip_specific { } } - pub use impl_rx_channel; - pub use impl_tx_channel; + pub(crate) use impl_rx_channel; + pub(crate) use impl_tx_channel; } #[cfg(any(esp32, esp32s2))] @@ -1365,8 +1363,6 @@ mod chip_specific { rmt.apb_conf.modify(|_, w| w.clk_en().set_bit()); } - #[doc(hidden)] - #[macro_export] macro_rules! impl_tx_channel { ($channel:ident, $signal:ident, $ch_num:literal) => { paste::paste! { @@ -1506,8 +1502,6 @@ mod chip_specific { } } - #[doc(hidden)] - #[macro_export] macro_rules! impl_rx_channel { ($channel:ident, $signal:ident, $ch_num:literal) => { paste::paste! { @@ -1624,6 +1618,6 @@ mod chip_specific { } } - pub use impl_rx_channel; - pub use impl_tx_channel; + pub(crate) use impl_rx_channel; + pub(crate) use impl_tx_channel; } diff --git a/esp32s2-hal/src/lib.rs b/esp32s2-hal/src/lib.rs index e558c89e556..58c3310e2d2 100644 --- a/esp32s2-hal/src/lib.rs +++ b/esp32s2-hal/src/lib.rs @@ -14,6 +14,8 @@ //! [embedded-hal], [embedded-hal-nb], and [embedded-io] //! - `embassy` - Enable support for [embassy], a modern asynchronous embedded //! framework +//! - `embassy-executor-interrupt` - Use the interrupt-mode embassy executor +//! - `embassy-executor-thread` - Use the thread-mode embassy executor //! - `embassy-time-timg0` - Enable the [embassy] time driver using the `TIMG0` //! peripheral //! - `psram_2m` - Use externally connected PSRAM (2MB)