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

Trim down xtensa crates #2357

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
41 changes: 20 additions & 21 deletions esp-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,32 @@ nb = "1.1.0"
paste = "1.0.15"
portable-atomic = { version = "1.9.0", default-features = false }
procmacros = { version = "0.14.0", features = ["enum-dispatch", "interrupt", "ram"], package = "esp-hal-procmacros", path = "../esp-hal-procmacros" }
riscv = { version = "0.11.1", optional = true }
strum = { version = "0.26.3", default-features = false, features = ["derive"] }
void = { version = "1.0.2", default-features = false }
usb-device = { version = "0.3.2", optional = true }
rand_core = "0.6.4"
ufmt-write = "0.1.0"
xtensa-lx = { version = "0.9.0", optional = true }

# IMPORTANT:
# Each supported device MUST have its PAC included below along with a
# corresponding feature.
esp32 = { version = "0.33.0", git = "https://github.com/esp-rs/esp-pacs.git", rev = "390c88b", features = ["critical-section", "rt"], optional = true }
esp32c2 = { version = "0.22.0", git = "https://github.com/esp-rs/esp-pacs.git", rev = "390c88b", features = ["critical-section", "rt"], optional = true }
esp32c3 = { version = "0.25.0", git = "https://github.com/esp-rs/esp-pacs.git", rev = "390c88b", features = ["critical-section", "rt"], optional = true }
esp32c6 = { version = "0.16.0", git = "https://github.com/esp-rs/esp-pacs.git", rev = "390c88b", features = ["critical-section", "rt"], optional = true }
esp32h2 = { version = "0.12.0", git = "https://github.com/esp-rs/esp-pacs.git", rev = "390c88b", features = ["critical-section", "rt"], optional = true }
esp32s2 = { version = "0.24.0", git = "https://github.com/esp-rs/esp-pacs.git", rev = "390c88b", features = ["critical-section", "rt"], optional = true }
esp32s3 = { version = "0.28.0", git = "https://github.com/esp-rs/esp-pacs.git", rev = "390c88b", features = ["critical-section", "rt"], optional = true }
esp32 = { version = "0.33.0", git = "https://github.com/esp-rs/esp-pacs", rev = "2d9fb24a7077aea7b071e2dfb63d81764957b1e9", features = ["critical-section", "rt"], optional = true }
esp32c2 = { version = "0.22.0", git = "https://github.com/esp-rs/esp-pacs", rev = "2d9fb24a7077aea7b071e2dfb63d81764957b1e9", features = ["critical-section", "rt"], optional = true }
esp32c3 = { version = "0.25.0", git = "https://github.com/esp-rs/esp-pacs", rev = "2d9fb24a7077aea7b071e2dfb63d81764957b1e9", features = ["critical-section", "rt"], optional = true }
esp32c6 = { version = "0.16.0", git = "https://github.com/esp-rs/esp-pacs", rev = "2d9fb24a7077aea7b071e2dfb63d81764957b1e9", features = ["critical-section", "rt"], optional = true }
esp32h2 = { version = "0.12.0", git = "https://github.com/esp-rs/esp-pacs", rev = "2d9fb24a7077aea7b071e2dfb63d81764957b1e9", features = ["critical-section", "rt"], optional = true }
esp32s2 = { version = "0.24.0", git = "https://github.com/esp-rs/esp-pacs", rev = "2d9fb24a7077aea7b071e2dfb63d81764957b1e9", features = ["critical-section", "rt"], optional = true }
esp32s3 = { version = "0.28.0", git = "https://github.com/esp-rs/esp-pacs", rev = "2d9fb24a7077aea7b071e2dfb63d81764957b1e9", features = ["critical-section", "rt"], optional = true }

[target.'cfg(target_arch = "riscv32")'.dependencies]
esp-riscv-rt = { version = "0.9.0", path = "../esp-riscv-rt" }
riscv = { version = "0.11.1" }
esp-riscv-rt = { version = "0.9.0", path = "../esp-riscv-rt" }
critical-section = { version = "1.1.3", features = ["restore-state-u8"] }

[target.'cfg(target_arch = "xtensa")'.dependencies]
xtensa-lx-rt = { version = "0.17.0", path = "../xtensa-lx-rt" }
xtensa-lx = { version = "0.9.0", path = "../xtensa-lx" }
xtensa-lx-rt = { version = "0.17.0", path = "../xtensa-lx-rt" }
critical-section = { version = "1.1.3", features = ["restore-state-u32"] }

[build-dependencies]
basic-toml = "0.1.9"
Expand All @@ -81,9 +83,6 @@ serde = { version = "1.0.210", features = ["derive"] }
[features]
default = []

riscv = ["dep:riscv", "critical-section/restore-state-u8"]
xtensa = ["dep:xtensa-lx", "critical-section/restore-state-u32"]

bluetooth = []

usb-otg = ["dep:embassy-usb-driver", "dep:embassy-usb-synopsys-otg", "dep:esp-synopsys-usb-otg", "dep:usb-device"]
Expand All @@ -105,19 +104,19 @@ log = ["dep:log"]

# Chip Support Feature Flags
# Target the ESP32.
esp32 = ["dep:esp32", "xtensa", "xtensa-lx/spin", "xtensa-lx-rt/esp32"]
esp32 = ["dep:esp32", "xtensa-lx-rt/esp32"]
# Target the ESP32-C2.
esp32c2 = ["dep:esp32c2", "riscv", "portable-atomic/unsafe-assume-single-core"]
esp32c2 = ["dep:esp32c2", "portable-atomic/unsafe-assume-single-core"]
# Target the ESP32-C3.
esp32c3 = ["dep:esp32c3", "riscv", "portable-atomic/unsafe-assume-single-core", "esp-riscv-rt/rtc-ram"]
esp32c3 = ["dep:esp32c3", "portable-atomic/unsafe-assume-single-core", "esp-riscv-rt/rtc-ram"]
# Target the ESP32-C6.
esp32c6 = ["dep:esp32c6", "riscv", "procmacros/has-lp-core", "esp-riscv-rt/rtc-ram"]
esp32c6 = ["dep:esp32c6", "procmacros/has-lp-core", "esp-riscv-rt/rtc-ram"]
# Target the ESP32-H2.
esp32h2 = ["dep:esp32h2", "riscv", "esp-riscv-rt/rtc-ram"]
esp32h2 = ["dep:esp32h2", "esp-riscv-rt/rtc-ram"]
# Target the ESP32-S2.
esp32s2 = ["dep:esp32s2", "xtensa", "portable-atomic/critical-section", "procmacros/has-ulp-core", "xtensa-lx-rt/esp32s2", "usb-otg"]
esp32s2 = ["dep:esp32s2", "portable-atomic/critical-section", "procmacros/has-ulp-core", "xtensa-lx-rt/esp32s2", "usb-otg"]
# Target the ESP32-S3.
esp32s3 = ["dep:esp32s3", "xtensa", "procmacros/has-ulp-core", "xtensa-lx/spin", "xtensa-lx-rt/esp32s3", "usb-otg"]
esp32s3 = ["dep:esp32s3", "procmacros/has-ulp-core", "xtensa-lx-rt/esp32s3", "usb-otg"]

#! ### RISC-V Exclusive Feature Flags
## Move the stack to start of RAM to get zero-cost stack overflow protection
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/aes/esp32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl<'d> Aes<'d> {
}

pub(super) fn write_start(&mut self) {
self.aes.start().write(|w| w.start().set_bit())
self.aes.start().write(|w| w.start().set_bit());
}

pub(super) fn read_idle(&mut self) -> bool {
Expand Down
11 changes: 5 additions & 6 deletions esp-hal/src/aes/esp32s2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
system::{Peripheral as PeripheralEnable, PeripheralClockControl},
};

impl<'d> Aes<'d> {
impl Aes<'_> {
pub(super) fn init(&mut self) {
PeripheralClockControl::enable(PeripheralEnable::Aes);
self.write_dma(false);
Expand All @@ -18,10 +18,9 @@ impl<'d> Aes<'d> {
}

fn write_dma(&mut self, enable_dma: bool) {
match enable_dma {
true => self.aes.dma_enable().write(|w| w.dma_enable().set_bit()),
false => self.aes.dma_enable().write(|w| w.dma_enable().clear_bit()),
}
self.aes
.dma_enable()
.write(|w| w.dma_enable().bit(enable_dma));
}

pub(super) fn write_key(&mut self, key: &[u8]) {
Expand Down Expand Up @@ -67,7 +66,7 @@ impl<'d> Aes<'d> {
}

pub(super) fn write_start(&mut self) {
self.aes.trigger().write(|w| w.trigger().set_bit())
self.aes.trigger().write(|w| w.trigger().set_bit());
}

pub(super) fn read_idle(&mut self) -> bool {
Expand Down
11 changes: 5 additions & 6 deletions esp-hal/src/aes/esp32s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ use crate::{
system::{Peripheral as PeripheralEnable, PeripheralClockControl},
};

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

fn write_dma(&mut self, enable_dma: bool) {
match enable_dma {
true => self.aes.dma_enable().write(|w| w.dma_enable().set_bit()),
false => self.aes.dma_enable().write(|w| w.dma_enable().clear_bit()),
}
self.aes
.dma_enable()
.write(|w| w.dma_enable().bit(enable_dma));
}

pub(super) fn write_key(&mut self, key: &[u8]) {
Expand All @@ -39,7 +38,7 @@ impl<'d> Aes<'d> {
}

pub(super) fn write_start(&mut self) {
self.aes.trigger().write(|w| w.trigger().set_bit())
self.aes.trigger().write(|w| w.trigger().set_bit());
}

pub(super) fn read_idle(&mut self) -> bool {
Expand Down
6 changes: 3 additions & 3 deletions esp-hal/src/dma/gdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<C: GdmaChannel> InterruptAccess<DmaTxInterrupt> for ChannelTxImpl<C> {
};
}
w
})
});
}

fn is_listening(&self) -> EnumSet<DmaTxInterrupt> {
Expand Down Expand Up @@ -250,7 +250,7 @@ impl<C: GdmaChannel> InterruptAccess<DmaTxInterrupt> for ChannelTxImpl<C> {
};
}
w
})
});
}

fn pending_interrupts(&self) -> EnumSet<DmaTxInterrupt> {
Expand Down Expand Up @@ -438,7 +438,7 @@ impl<C: GdmaChannel> InterruptAccess<DmaRxInterrupt> for ChannelRxImpl<C> {
};
}
w
})
});
}

fn pending_interrupts(&self) -> EnumSet<DmaRxInterrupt> {
Expand Down
16 changes: 8 additions & 8 deletions esp-hal/src/dma/pdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<C: PdmaChannel<RegisterBlock = SpiRegisterBlock>> InterruptAccess<DmaTxInte
};
}
w
})
});
}

fn is_listening(&self) -> EnumSet<DmaTxInterrupt> {
Expand Down Expand Up @@ -160,7 +160,7 @@ impl<C: PdmaChannel<RegisterBlock = SpiRegisterBlock>> InterruptAccess<DmaTxInte
};
}
w
})
});
}

fn pending_interrupts(&self) -> EnumSet<DmaTxInterrupt> {
Expand Down Expand Up @@ -259,7 +259,7 @@ impl<C: PdmaChannel<RegisterBlock = SpiRegisterBlock>> InterruptAccess<DmaRxInte
};
}
w
})
});
}

fn is_listening(&self) -> EnumSet<DmaRxInterrupt> {
Expand Down Expand Up @@ -299,7 +299,7 @@ impl<C: PdmaChannel<RegisterBlock = SpiRegisterBlock>> InterruptAccess<DmaRxInte
};
}
w
})
});
}

fn pending_interrupts(&self) -> EnumSet<DmaRxInterrupt> {
Expand Down Expand Up @@ -535,7 +535,7 @@ impl<C: PdmaChannel<RegisterBlock = I2sRegisterBlock>> InterruptAccess<DmaTxInte
};
}
w
})
});
}

fn is_listening(&self) -> EnumSet<DmaTxInterrupt> {
Expand Down Expand Up @@ -592,7 +592,7 @@ impl<C: PdmaChannel<RegisterBlock = I2sRegisterBlock>> InterruptAccess<DmaTxInte
};
}
w
})
});
}

fn waker(&self) -> &'static AtomicWaker {
Expand Down Expand Up @@ -676,7 +676,7 @@ impl<C: PdmaChannel<RegisterBlock = I2sRegisterBlock>> InterruptAccess<DmaRxInte
};
}
w
})
});
}

fn is_listening(&self) -> EnumSet<DmaRxInterrupt> {
Expand Down Expand Up @@ -740,7 +740,7 @@ impl<C: PdmaChannel<RegisterBlock = I2sRegisterBlock>> InterruptAccess<DmaRxInte
};
}
w
})
});
}

fn waker(&self) -> &'static AtomicWaker {
Expand Down
34 changes: 12 additions & 22 deletions esp-hal/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,6 @@ where

w.arbitration_lost().set_bit();
w.time_out().set_bit();

#[cfg(esp32)]
w.ack_err().set_bit();
#[cfg(not(esp32))]
w.nack().set_bit();

w
Expand Down Expand Up @@ -680,16 +676,10 @@ where
return Err(Error::TimeOut);
}

#[cfg(not(esp32))]
if r.nack().bit_is_set() {
return Err(Error::AckCheckFailed);
}

#[cfg(esp32)]
if r.ack_err().bit_is_set() {
return Err(Error::AckCheckFailed);
}

#[cfg(not(esp32))]
if r.trans_complete().bit_is_set()
&& self
Expand Down Expand Up @@ -1144,17 +1134,13 @@ fn handler(regs: &RegisterBlock) {
w.end_detect().clear_bit();
w.trans_complete().clear_bit();
w.arbitration_lost().clear_bit();
w.time_out().clear_bit()
});

#[cfg(not(any(esp32, esp32s2)))]
regs.int_ena().modify(|_, w| w.txfifo_wm().clear_bit());
w.time_out().clear_bit();

#[cfg(not(esp32))]
regs.int_ena().modify(|_, w| w.nack().clear_bit());
#[cfg(not(any(esp32, esp32s2)))]
w.txfifo_wm().clear_bit();

#[cfg(esp32)]
regs.int_ena().modify(|_, w| w.ack_err().clear_bit());
w.nack().clear_bit()
});
}

#[handler]
Expand Down Expand Up @@ -1289,15 +1275,19 @@ pub trait Instance: Peripheral<P = Self> + PeripheralMarker + Into<AnyI2c> + 'st
sda_register.modify(|_, w| unsafe { w.sda_filter_thres().bits(threshold) });
sda_register.modify(|_, w| w.sda_filter_en().set_bit());
}
None => sda_register.modify(|_, w| w.sda_filter_en().clear_bit()),
None => {
sda_register.modify(|_, w| w.sda_filter_en().clear_bit());
}
}

match scl_threshold {
Some(threshold) => {
scl_register.modify(|_, w| unsafe { w.scl_filter_thres().bits(threshold) });
scl_register.modify(|_, w| w.scl_filter_en().set_bit());
}
None => scl_register.modify(|_, w| w.scl_filter_en().clear_bit()),
None => {
scl_register.modify(|_, w| w.scl_filter_en().clear_bit());
}
}
}

Expand Down Expand Up @@ -1825,7 +1815,7 @@ pub trait Instance: Peripheral<P = Self> + PeripheralMarker + Into<AnyI2c> + 'st
// Handle error cases
let retval = if interrupts.time_out().bit_is_set() {
Err(Error::TimeOut)
} else if interrupts.ack_err().bit_is_set() {
} else if interrupts.nack().bit_is_set() {
Err(Error::AckCheckFailed)
} else if interrupts.arbitration_lost().bit_is_set() {
Err(Error::ArbitrationLost)
Expand Down
4 changes: 2 additions & 2 deletions esp-hal/src/interrupt/software.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<const NUM: u8> SoftwareInterrupt<NUM> {
.cpu_intr_from_cpu_3()
.write(|w| w.cpu_intr_from_cpu_3().set_bit()),
_ => unreachable!(),
}
};
}

/// Resets this software-interrupt
Expand All @@ -120,7 +120,7 @@ impl<const NUM: u8> SoftwareInterrupt<NUM> {
.cpu_intr_from_cpu_3()
.write(|w| w.cpu_intr_from_cpu_3().clear_bit()),
_ => unreachable!(),
}
};
}

/// Unsafely create an instance of this peripheral out of thin air.
Expand Down
12 changes: 6 additions & 6 deletions esp-hal/src/mcpwm/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl<'d, PWM: PwmPeripheral, const OP: u8, const IS_A: bool> PwmPin<'d, PWM, OP,

// SAFETY:
// `bits` is a valid bit pattern
ch.gen((!IS_A) as usize).write(|w| unsafe { w.bits(bits) })
ch.gen((!IS_A) as usize).write(|w| unsafe { w.bits(bits) });
}

/// Set how a new timestamp syncs with the timer
Expand All @@ -336,7 +336,7 @@ impl<'d, PWM: PwmPeripheral, const OP: u8, const IS_A: bool> PwmPin<'d, PWM, OP,
} else {
w.b_upmethod().bits(bits)
}
})
});
}

/// Write a new timestamp.
Expand All @@ -349,16 +349,16 @@ impl<'d, PWM: PwmPeripheral, const OP: u8, const IS_A: bool> PwmPin<'d, PWM, OP,

#[cfg(esp32s3)]
if IS_A {
ch.cmpr_value0().write(|w| unsafe { w.a().bits(value) })
ch.cmpr_value0().write(|w| unsafe { w.a().bits(value) });
} else {
ch.cmpr_value1().write(|w| unsafe { w.b().bits(value) })
ch.cmpr_value1().write(|w| unsafe { w.b().bits(value) });
}

#[cfg(any(esp32, esp32c6, esp32h2))]
if IS_A {
ch.gen_tstmp_a().write(|w| unsafe { w.a().bits(value) })
ch.gen_tstmp_a().write(|w| unsafe { w.a().bits(value) });
} else {
ch.gen_tstmp_b().write(|w| unsafe { w.b().bits(value) })
ch.gen_tstmp_b().write(|w| unsafe { w.b().bits(value) });
}
}

Expand Down
Loading
Loading