Skip to content

Commit

Permalink
No longer publicly expose the PeripheralClockControl struct
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebraham committed Sep 25, 2023
1 parent b91b3b1 commit 4c75124
Show file tree
Hide file tree
Showing 27 changed files with 107 additions and 196 deletions.
4 changes: 2 additions & 2 deletions esp-hal-common/src/aes/esp32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::{
};

impl<'d> Aes<'d> {
pub(super) fn init(&mut self, peripheral_clock_control: &mut PeripheralClockControl) {
peripheral_clock_control.enable(PeripheralEnable::Aes);
pub(super) fn init(&mut self) {
PeripheralClockControl::enable(PeripheralEnable::Aes);
self.write_endianness(
Endianness::BigEndian,
Endianness::BigEndian,
Expand Down
4 changes: 2 additions & 2 deletions esp-hal-common/src/aes/esp32cX.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::{
};

impl<'d> Aes<'d> {
pub(super) fn init(&mut self, peripheral_clock_control: &mut PeripheralClockControl) {
peripheral_clock_control.enable(PeripheralEnable::Aes);
pub(super) fn init(&mut self) {
PeripheralClockControl::enable(PeripheralEnable::Aes);
self.write_dma(false);
}

Expand Down
4 changes: 2 additions & 2 deletions esp-hal-common/src/aes/esp32s2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::{
};

impl<'d> Aes<'d> {
pub(super) fn init(&mut self, peripheral_clock_control: &mut PeripheralClockControl) {
peripheral_clock_control.enable(PeripheralEnable::Aes);
pub(super) fn init(&mut self) {
PeripheralClockControl::enable(PeripheralEnable::Aes);
self.write_dma(false);
self.write_endianness(
Endianness::BigEndian,
Expand Down
4 changes: 2 additions & 2 deletions esp-hal-common/src/aes/esp32s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::{
};

impl<'d> Aes<'d> {
pub(super) fn init(&mut self, peripheral_clock_control: &mut PeripheralClockControl) {
peripheral_clock_control.enable(PeripheralEnable::Aes);
pub(super) fn init(&mut self) {
PeripheralClockControl::enable(PeripheralEnable::Aes);
self.write_dma(false);
}

Expand Down
12 changes: 5 additions & 7 deletions esp-hal-common/src/aes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ use crate::{
generic::{Readable, Reg, RegisterSpec, Resettable, Writable},
AES,
},
system::PeripheralClockControl,
};

#[cfg_attr(esp32, path = "esp32.rs")]
Expand All @@ -84,13 +83,12 @@ pub struct Aes<'d> {
}

impl<'d> Aes<'d> {
pub fn new(
aes: impl Peripheral<P = AES> + 'd,
peripheral_clock_control: &mut PeripheralClockControl,
) -> Self {
pub fn new(aes: impl Peripheral<P = AES> + 'd) -> Self {
crate::into_ref!(aes);
let mut ret = Self { aes: aes };
ret.init(peripheral_clock_control);

let mut ret = Self { aes };
ret.init();

ret
}

Expand Down
3 changes: 1 addition & 2 deletions esp-hal-common/src/analog/adc/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,10 @@ where
ADCI: RegisterAccess + 'd,
{
pub fn adc(
peripheral_clock_controller: &mut PeripheralClockControl,
adc_instance: impl crate::peripheral::Peripheral<P = ADCI> + 'd,
config: AdcConfig<ADCI>,
) -> Result<Self, ()> {
peripheral_clock_controller.enable(Peripheral::ApbSarAdc);
PeripheralClockControl::enable(Peripheral::ApbSarAdc);

let sar_adc = unsafe { &*APB_SARADC::PTR };
sar_adc.ctrl.modify(|_, w| unsafe {
Expand Down
13 changes: 5 additions & 8 deletions esp-hal-common/src/assist_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,19 @@
use crate::{
peripheral::{Peripheral, PeripheralRef},
system::PeripheralClockControl,
peripherals::ASSIST_DEBUG,
};

pub struct DebugAssist<'d> {
debug_assist: PeripheralRef<'d, crate::peripherals::ASSIST_DEBUG>,
debug_assist: PeripheralRef<'d, ASSIST_DEBUG>,
}

impl<'d> DebugAssist<'d> {
pub fn new(
debug_assist: impl Peripheral<P = crate::peripherals::ASSIST_DEBUG> + 'd,
_peripheral_clock_control: &mut PeripheralClockControl,
) -> Self {
pub fn new(debug_assist: impl Peripheral<P = ASSIST_DEBUG> + 'd) -> Self {
crate::into_ref!(debug_assist);

// we should use peripheral clock control to enable the debug assist however
// it's always enabled in ROM code already
// NOTE: We should enable the debug assist, however, it's always enabled in ROM
// code already.

DebugAssist { debug_assist }
}
Expand Down
3 changes: 1 addition & 2 deletions esp-hal-common/src/dma/gdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,10 @@ impl<'d> Gdma<'d> {
/// Create a DMA instance.
pub fn new(
dma: impl crate::peripheral::Peripheral<P = crate::peripherals::DMA> + 'd,
peripheral_clock_control: &mut PeripheralClockControl,
) -> Gdma<'d> {
crate::into_ref!(dma);

peripheral_clock_control.enable(Peripheral::Gdma);
PeripheralClockControl::enable(Peripheral::Gdma);
dma.misc_conf.modify(|_, w| w.ahbm_rst_inter().set_bit());
dma.misc_conf.modify(|_, w| w.ahbm_rst_inter().clear_bit());
dma.misc_conf.modify(|_, w| w.clk_en().set_bit());
Expand Down
7 changes: 2 additions & 5 deletions esp-hal-common/src/dma/pdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,8 @@ pub struct Dma<'d> {

impl<'d> Dma<'d> {
/// Create a DMA instance.
pub fn new(
dma: impl crate::peripheral::Peripheral<P = crate::system::Dma> + 'd,
peripheral_clock_control: &mut PeripheralClockControl,
) -> Dma<'d> {
peripheral_clock_control.enable(Peripheral::Dma);
pub fn new(dma: impl crate::peripheral::Peripheral<P = crate::system::Dma> + 'd) -> Dma<'d> {
PeripheralClockControl::enable(Peripheral::Dma);

Dma {
_inner: dma.into_ref(),
Expand Down
7 changes: 2 additions & 5 deletions esp-hal-common/src/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,10 @@ pub enum WorkMode {
}

impl<'d> Ecc<'d> {
pub fn new(
ecc: impl Peripheral<P = ECC> + 'd,
peripheral_clock_control: &mut PeripheralClockControl,
) -> Self {
pub fn new(ecc: impl Peripheral<P = ECC> + 'd) -> Self {
crate::into_ref!(ecc);

peripheral_clock_control.enable(PeripheralEnable::Ecc);
PeripheralClockControl::enable(PeripheralEnable::Ecc);

Self {
ecc,
Expand Down
9 changes: 3 additions & 6 deletions esp-hal-common/src/hmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,11 @@ enum NextCommand {
}

impl<'d> Hmac<'d> {
pub fn new(
hmac: impl Peripheral<P = HMAC> + 'd,
peripheral_clock_control: &mut PeripheralClockControl,
) -> Self {
pub fn new(hmac: impl Peripheral<P = HMAC> + 'd) -> Self {
crate::into_ref!(hmac);

peripheral_clock_control.enable(PeripheralEnable::Sha);
peripheral_clock_control.enable(PeripheralEnable::Hmac);
PeripheralClockControl::enable(PeripheralEnable::Sha);
PeripheralClockControl::enable(PeripheralEnable::Hmac);

Self {
hmac,
Expand Down
24 changes: 7 additions & 17 deletions esp-hal-common/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,16 @@ where
sda: impl Peripheral<P = SDA> + 'd,
scl: impl Peripheral<P = SCL> + 'd,
frequency: HertzU32,
peripheral_clock_control: &mut PeripheralClockControl,
clocks: &Clocks,
) -> Self {
crate::into_ref!(i2c, sda, scl);
enable_peripheral(&i2c, peripheral_clock_control);

PeripheralClockControl::enable(match i2c.i2c_number() {
0 => crate::system::Peripheral::I2cExt0,
#[cfg(i2c1)]
1 => crate::system::Peripheral::I2cExt1,
_ => unreachable!(), // will never happen
});

let mut i2c = I2C { peripheral: i2c };

Expand Down Expand Up @@ -623,21 +628,6 @@ mod asynch {
}
}

fn enable_peripheral<'d, T>(
i2c: &PeripheralRef<'d, T>,
peripheral_clock_control: &mut PeripheralClockControl,
) where
T: Instance,
{
// enable peripheral
match i2c.i2c_number() {
0 => peripheral_clock_control.enable(crate::system::Peripheral::I2cExt0),
#[cfg(i2c1)]
1 => peripheral_clock_control.enable(crate::system::Peripheral::I2cExt1),
_ => unreachable!(), // will never happen
}
}

/// I2C Peripheral Instance
pub trait Instance {
fn scl_output_signal(&self) -> OutputSignal;
Expand Down
9 changes: 1 addition & 8 deletions esp-hal-common/src/i2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,6 @@ where
data_format: DataFormat,
sample_rate: impl Into<fugit::HertzU32>,
mut channel: Channel<'d, CH>,
peripheral_clock_control: &mut PeripheralClockControl,
clocks: &Clocks,
) -> Self {
// on ESP32-C3 / ESP32-S3 and later RX and TX are independent and
Expand All @@ -640,7 +639,7 @@ where
let mut register_access = i2s.register_access();

channel.tx.init_channel();
peripheral_clock_control.enable(register_access.get_peripheral());
PeripheralClockControl::enable(register_access.get_peripheral());
pins.configure(&mut register_access);
register_access.set_clock(calculate_clock(
sample_rate,
Expand Down Expand Up @@ -682,7 +681,6 @@ where
data_format: DataFormat,
sample_rate: impl Into<fugit::HertzU32>,
channel: Channel<'d, CH>,
peripheral_clock_control: &mut PeripheralClockControl,
clocks: &Clocks,
) -> Self;
}
Expand All @@ -701,7 +699,6 @@ where
data_format: DataFormat,
sample_rate: impl Into<fugit::HertzU32>,
channel: Channel<'d, CH>,
peripheral_clock_control: &mut PeripheralClockControl,
clocks: &Clocks,
) -> Self {
Self::new_internal(
Expand All @@ -711,7 +708,6 @@ where
data_format,
sample_rate,
channel,
peripheral_clock_control,
clocks,
)
}
Expand All @@ -733,7 +729,6 @@ where
data_format: DataFormat,
sample_rate: impl Into<fugit::HertzU32>,
channel: Channel<'d, CH>,
peripheral_clock_control: &mut PeripheralClockControl,
clocks: &Clocks,
) -> Self;
}
Expand All @@ -753,7 +748,6 @@ where
data_format: DataFormat,
sample_rate: impl Into<fugit::HertzU32>,
channel: Channel<'d, CH>,
peripheral_clock_control: &mut PeripheralClockControl,
clocks: &Clocks,
) -> Self {
Self::new_internal(
Expand All @@ -763,7 +757,6 @@ where
data_format,
sample_rate,
channel,
peripheral_clock_control,
clocks,
)
}
Expand Down
3 changes: 1 addition & 2 deletions esp-hal-common/src/ledc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@ impl<'d> LEDC<'d> {
pub fn new(
_instance: impl Peripheral<P = crate::peripherals::LEDC> + 'd,
clock_control_config: &'d Clocks,
system: &mut PeripheralClockControl,
) -> Self {
crate::into_ref!(_instance);
system.enable(PeripheralEnable::Ledc);
PeripheralClockControl::enable(PeripheralEnable::Ledc);

let ledc = unsafe { &*crate::peripherals::LEDC::ptr() };
LEDC {
Expand Down
13 changes: 6 additions & 7 deletions esp-hal-common/src/mcpwm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ impl<'d, PWM: PwmPeripheral> MCPWM<'d, PWM> {
pub fn new(
peripheral: impl Peripheral<P = PWM> + 'd,
peripheral_clock: PeripheralClockConfig,
system: &mut PeripheralClockControl,
) -> Self {
crate::into_ref!(peripheral);

PWM::enable(system);
PWM::enable();

#[cfg(not(esp32c6))]
{
Expand Down Expand Up @@ -289,7 +288,7 @@ pub struct FrequencyError;
/// A MCPWM peripheral
pub unsafe trait PwmPeripheral: Deref<Target = RegisterBlock> {
/// Enable peripheral
fn enable(system: &mut PeripheralClockControl);
fn enable();
/// Get a pointer to the peripheral RegisterBlock
fn block() -> *const RegisterBlock;
/// Get operator GPIO mux output signal
Expand All @@ -298,8 +297,8 @@ pub unsafe trait PwmPeripheral: Deref<Target = RegisterBlock> {

#[cfg(mcpwm0)]
unsafe impl PwmPeripheral for crate::peripherals::MCPWM0 {
fn enable(system: &mut PeripheralClockControl) {
system.enable(PeripheralEnable::Mcpwm0)
fn enable() {
PeripheralClockControl::enable(PeripheralEnable::Mcpwm0)
}

fn block() -> *const RegisterBlock {
Expand All @@ -321,8 +320,8 @@ unsafe impl PwmPeripheral for crate::peripherals::MCPWM0 {

#[cfg(mcpwm1)]
unsafe impl PwmPeripheral for crate::peripherals::MCPWM1 {
fn enable(system: &mut PeripheralClockControl) {
system.enable(PeripheralEnable::Mcpwm1)
fn enable() {
PeripheralClockControl::enable(PeripheralEnable::Mcpwm1)
}

fn block() -> *const RegisterBlock {
Expand Down
5 changes: 3 additions & 2 deletions esp-hal-common/src/otg_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ where
usb_sel: impl Peripheral<P = S> + 'd,
usb_dp: impl Peripheral<P = P> + 'd,
usb_dm: impl Peripheral<P = M> + 'd,
peripheral_clock_control: &mut PeripheralClockControl,
) -> Self {
crate::into_ref!(usb_sel, usb_dp, usb_dm);
peripheral_clock_control.enable(PeripheralEnable::Usb);

PeripheralClockControl::enable(PeripheralEnable::Usb);

Self {
_usb0: usb0.into_ref(),
_usb_sel: usb_sel,
Expand Down
Loading

0 comments on commit 4c75124

Please sign in to comment.