Skip to content

Commit

Permalink
Some general cleanup (#777)
Browse files Browse the repository at this point in the history
* Executor related touchups

* Fix typos

* Clean up DAC, remove hidden public API

* Clean up ADC

* Clean up analog peripheral reexports

* Properly hide rmt macros
  • Loading branch information
bugadani authored Sep 4, 2023
1 parent 2f5ebad commit 48e6171
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 108 deletions.
16 changes: 5 additions & 11 deletions esp-hal-common/src/analog/adc/esp32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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<Analog> {
impl embedded_hal::adc::Channel<$adc> for crate::gpio::$pin<crate::gpio::Analog> {
type ID = u8;

fn channel() -> u8 { $channel }
Expand All @@ -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
Expand Down Expand Up @@ -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 [
Expand Down
38 changes: 12 additions & 26 deletions esp-hal-common/src/analog/adc/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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<Analog> {
impl embedded_hal::adc::Channel<$adc> for crate::gpio::$pin<crate::gpio::Analog> {
type ID = u8;

fn channel() -> u8 { $channel }
Expand All @@ -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
Expand Down Expand Up @@ -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 [
Expand All @@ -744,7 +739,7 @@ pub mod implementation {
}

#[cfg(esp32c3)]
pub mod implementation {
mod implementation {
//! # Analog to digital (ADC) conversion support.
//!
//! ## Overview
Expand Down Expand Up @@ -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 [
Expand All @@ -805,7 +797,7 @@ pub mod implementation {
}

#[cfg(esp32c6)]
pub mod implementation {
mod implementation {
//! # Analog to digital (ADC) conversion support.
//!
//! ## Overview
Expand Down Expand Up @@ -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 [
Expand All @@ -861,7 +850,7 @@ pub mod implementation {
}

#[cfg(esp32h2)]
pub mod implementation {
mod implementation {
//! # Analog to digital (ADC) conversion support.
//!
//! ## Overview
Expand Down Expand Up @@ -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 [
Expand Down
24 changes: 7 additions & 17 deletions esp-hal-common/src/analog/adc/xtensa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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<Analog> {
impl embedded_hal::adc::Channel<$adc> for crate::gpio::$pin<crate::gpio::Analog> {
type ID = u8;

fn channel() -> u8 { $channel }
Expand All @@ -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
Expand Down Expand Up @@ -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 [
Expand Down Expand Up @@ -825,7 +819,7 @@ pub mod implementation {
}

#[cfg(esp32s2)]
pub mod implementation {
mod implementation {
//! # Analog to digital (ADC) conversion support.
//!
//! ## Overview
Expand Down Expand Up @@ -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 [
Expand Down
54 changes: 19 additions & 35 deletions esp-hal-common/src/analog/dac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -58,8 +54,7 @@ pub trait DAC1Impl {
}
}

#[doc(hidden)]
pub trait DAC2Impl {
trait DAC2Impl {
fn set_power(self) -> Self
where
Self: Sized,
Expand Down Expand Up @@ -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::[<DAC $number Impl>];
use $crate::analog::dac::[<DAC $number Impl>];

/// DAC channel
#[doc = "DAC channel " $number]
pub struct [<DAC $number>]<'d, DAC> {
_dac: PeripheralRef<'d, DAC>,
_private: PhantomData<()>,
_dac: $crate::peripheral::PeripheralRef<'d, DAC>,
_private: ::core::marker::PhantomData<()>,
}

impl<'d, DAC> [<DAC $number Impl>] for [<DAC $number>]<'d, DAC> {}
Expand All @@ -119,17 +109,17 @@ macro_rules! impl_dac {
/// Constructs a new DAC instance
pub fn dac(
dac: impl $crate::peripheral::Peripheral<P = DAC> +'d,
_pin: gpio::$gpio<$crate::gpio::Analog>,
_pin: $crate::gpio::$gpio<$crate::gpio::Analog>,
) -> Result<Self, ()> {
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
Expand All @@ -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);
}
7 changes: 0 additions & 7 deletions esp-hal-common/src/embassy/executor/xtensa/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions esp-hal-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Loading

0 comments on commit 48e6171

Please sign in to comment.