Ledc clusters (#1368)

* ledc: make compile

* unpaste

* clean changelog

* Update esp-hal/CHANGELOG.md

Co-authored-by: Scott Mabin <scott@mabez.dev>

---------

Co-authored-by: Scott Mabin <scott@mabez.dev>
This commit is contained in:
Zgarbul Andrey 2024-04-01 17:07:27 +03:00 committed by GitHub
parent dc6f8378e2
commit 2440c240ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 384 additions and 888 deletions

View File

@ -44,10 +44,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- DMA channels can/have to be explicitly created for async or blocking drivers, added `set_interrupt_handler` to DMA channels, SPI, I2S, PARL_IO, don't enable interrupts on startup for DMA, I2S, PARL_IO, GPIO (#1300)
- UART: Rework `change_baud` so it is possible to set baud rate even after instantiation (#1350)
- Runtime ISR binding for SHA,ECC and RSA (#1354)
- Update `pac`s with removed suffixes in `int` field names. Use `W1TC` for `int_clr` (#1357)
MCPWM clusters (#1360)
TIMG clusters (#1364)
SOC_ETM clusters (#1365)
### Removed

View File

@ -52,14 +52,14 @@ xtensa-lx = { version = "0.9.0", optional = true }
# IMPORTANT:
# Each supported device MUST have its PAC included below along with a
# corresponding feature.
esp32 = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true }
esp32c2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true }
esp32c3 = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true }
esp32c6 = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true }
esp32h2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true }
esp32p4 = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true }
esp32s2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true }
esp32s3 = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true }
esp32 = { git = "https://github.com/esp-rs/esp-pacs", rev = "a8a8340", features = ["critical-section"], optional = true }
esp32c2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "a8a8340", features = ["critical-section"], optional = true }
esp32c3 = { git = "https://github.com/esp-rs/esp-pacs", rev = "a8a8340", features = ["critical-section"], optional = true }
esp32c6 = { git = "https://github.com/esp-rs/esp-pacs", rev = "a8a8340", features = ["critical-section"], optional = true }
esp32h2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "a8a8340", features = ["critical-section"], optional = true }
esp32p4 = { git = "https://github.com/esp-rs/esp-pacs", rev = "a8a8340", features = ["critical-section"], optional = true }
esp32s2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "a8a8340", features = ["critical-section"], optional = true }
esp32s3 = { git = "https://github.com/esp-rs/esp-pacs", rev = "a8a8340", features = ["critical-section"], optional = true }
[target.'cfg(target_arch = "riscv32")'.dependencies]
esp-riscv-rt = { version = "0.7.0", optional = true, path = "../esp-riscv-rt" }

File diff suppressed because it is too large Load Diff

View File

@ -96,12 +96,18 @@ pub struct HighSpeed {}
/// Used to specify LowSpeed Timer/Channel
pub struct LowSpeed {}
pub trait Speed {}
pub trait Speed {
const IS_HS: bool;
}
#[cfg(esp32)]
impl Speed for HighSpeed {}
impl Speed for HighSpeed {
const IS_HS: bool = true;
}
impl Speed for LowSpeed {}
impl Speed for LowSpeed {
const IS_HS: bool = false;
}
impl<'d> LEDC<'d> {
/// Return a new LEDC
@ -125,7 +131,8 @@ impl<'d> LEDC<'d> {
pub fn set_global_slow_clock(&mut self, _clock_source: LSGlobalClkSource) {
self.ledc.conf().write(|w| w.apb_clk_sel().set_bit());
self.ledc
.lstimer0_conf()
.lstimer(0)
.conf()
.modify(|_, w| w.para_up().set_bit());
}
@ -152,7 +159,10 @@ impl<'d> LEDC<'d> {
.write(|w| unsafe { w.ledc_sclk_sel().bits(0) });
}
}
self.ledc.timer0_conf().modify(|_, w| w.para_up().set_bit());
self.ledc
.timer(0)
.conf()
.modify(|_, w| w.para_up().set_bit());
}
/// Return a new timer

View File

@ -47,10 +47,10 @@ pub enum LSClockSource {
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Number {
Timer0,
Timer1,
Timer2,
Timer3,
Timer0 = 0,
Timer1 = 1,
Timer2 = 2,
Timer3 = 3,
}
/// Timer configuration
@ -256,56 +256,16 @@ impl<'a> TimerHW<LowSpeed> for Timer<'a, LowSpeed> {
let duty = unwrap!(self.duty) as u8;
let use_apb = !self.use_ref_tick;
match self.number {
Number::Timer0 => self.ledc.lstimer0_conf().modify(|_, w| unsafe {
w.tick_sel()
.bit(use_apb)
.rst()
.clear_bit()
.pause()
.clear_bit()
.div_num()
.bits(divisor)
.duty_res()
.bits(duty)
}),
Number::Timer1 => self.ledc.lstimer1_conf().modify(|_, w| unsafe {
w.tick_sel()
.bit(use_apb)
.rst()
.clear_bit()
.pause()
.clear_bit()
.div_num()
.bits(divisor)
.duty_res()
.bits(duty)
}),
Number::Timer2 => self.ledc.lstimer2_conf().modify(|_, w| unsafe {
w.tick_sel()
.bit(use_apb)
.rst()
.clear_bit()
.pause()
.clear_bit()
.div_num()
.bits(divisor)
.duty_res()
.bits(duty)
}),
Number::Timer3 => self.ledc.lstimer3_conf().modify(|_, w| unsafe {
w.tick_sel()
.bit(use_apb)
.rst()
.clear_bit()
.pause()
.clear_bit()
.div_num()
.bits(divisor)
.duty_res()
.bits(duty)
}),
};
self.ledc
.lstimer(self.number as usize)
.conf()
.modify(|_, w| unsafe {
w.tick_sel().bit(use_apb);
w.rst().clear_bit();
w.pause().clear_bit();
w.div_num().bits(divisor);
w.duty_res().bits(duty)
});
}
#[cfg(not(esp32))]
@ -314,90 +274,26 @@ impl<'a> TimerHW<LowSpeed> for Timer<'a, LowSpeed> {
let duty = unwrap!(self.duty) as u8;
let use_ref_tick = self.use_ref_tick;
match self.number {
Number::Timer0 => self.ledc.timer0_conf().modify(|_, w| unsafe {
w.tick_sel()
.bit(use_ref_tick)
.rst()
.clear_bit()
.pause()
.clear_bit()
.clk_div()
.bits(divisor)
.duty_res()
.bits(duty)
}),
Number::Timer1 => self.ledc.timer1_conf().modify(|_, w| unsafe {
w.tick_sel()
.bit(use_ref_tick)
.rst()
.clear_bit()
.pause()
.clear_bit()
.clk_div()
.bits(divisor)
.duty_res()
.bits(duty)
}),
Number::Timer2 => self.ledc.timer2_conf().modify(|_, w| unsafe {
w.tick_sel()
.bit(use_ref_tick)
.rst()
.clear_bit()
.pause()
.clear_bit()
.clk_div()
.bits(divisor)
.duty_res()
.bits(duty)
}),
Number::Timer3 => self.ledc.timer3_conf().modify(|_, w| unsafe {
w.tick_sel()
.bit(use_ref_tick)
.rst()
.clear_bit()
.pause()
.clear_bit()
.clk_div()
.bits(divisor)
.duty_res()
.bits(duty)
}),
};
self.ledc
.timer(self.number as usize)
.conf()
.modify(|_, w| unsafe {
w.tick_sel().bit(use_ref_tick);
w.rst().clear_bit();
w.pause().clear_bit();
w.clk_div().bits(divisor);
w.duty_res().bits(duty)
});
}
#[cfg(esp32)]
/// Update the timer in HW
fn update_hw(&self) {
match self.number {
Number::Timer0 => self
.ledc
.lstimer0_conf()
.modify(|_, w| w.para_up().set_bit()),
Number::Timer1 => self
.ledc
.lstimer1_conf()
.modify(|_, w| w.para_up().set_bit()),
Number::Timer2 => self
.ledc
.lstimer2_conf()
.modify(|_, w| w.para_up().set_bit()),
Number::Timer3 => self
.ledc
.lstimer3_conf()
.modify(|_, w| w.para_up().set_bit()),
};
}
#[cfg(esp32)]
let tmr = self.ledc.lstimer(self.number as usize);
#[cfg(not(esp32))]
let tmr = self.ledc.timer(self.number as usize);
#[cfg(not(esp32))]
/// Update the timer in HW
fn update_hw(&self) {
match self.number {
Number::Timer0 => self.ledc.timer0_conf().modify(|_, w| w.para_up().set_bit()),
Number::Timer1 => self.ledc.timer1_conf().modify(|_, w| w.para_up().set_bit()),
Number::Timer2 => self.ledc.timer2_conf().modify(|_, w| w.para_up().set_bit()),
Number::Timer3 => self.ledc.timer3_conf().modify(|_, w| w.para_up().set_bit()),
};
tmr.conf().modify(|_, w| w.para_up().set_bit());
}
}
@ -417,56 +313,16 @@ impl<'a> TimerHW<HighSpeed> for Timer<'a, HighSpeed> {
let duty = unwrap!(self.duty) as u8;
let sel_hstimer = self.clock_source == Some(HSClockSource::APBClk);
match self.number {
Number::Timer0 => self.ledc.hstimer0_conf().modify(|_, w| unsafe {
w.tick_sel()
.bit(sel_hstimer)
.rst()
.clear_bit()
.pause()
.clear_bit()
.div_num()
.bits(divisor)
.duty_res()
.bits(duty)
}),
Number::Timer1 => self.ledc.hstimer1_conf().modify(|_, w| unsafe {
w.tick_sel()
.bit(sel_hstimer)
.rst()
.clear_bit()
.pause()
.clear_bit()
.div_num()
.bits(divisor)
.duty_res()
.bits(duty)
}),
Number::Timer2 => self.ledc.hstimer2_conf().modify(|_, w| unsafe {
w.tick_sel()
.bit(sel_hstimer)
.rst()
.clear_bit()
.pause()
.clear_bit()
.div_num()
.bits(divisor)
.duty_res()
.bits(duty)
}),
Number::Timer3 => self.ledc.hstimer3_conf().modify(|_, w| unsafe {
w.tick_sel()
.bit(sel_hstimer)
.rst()
.clear_bit()
.pause()
.clear_bit()
.div_num()
.bits(divisor)
.duty_res()
.bits(duty)
}),
};
self.ledc
.hstimer(self.number as usize)
.conf()
.modify(|_, w| unsafe {
w.tick_sel().bit(sel_hstimer);
w.rst().clear_bit();
w.pause().clear_bit();
w.div_num().bits(divisor);
w.duty_res().bits(duty)
});
}
/// Update the timer in HW

View File

@ -24,9 +24,9 @@ categories = [
cfg-if = "1.0.0"
embedded-hal-02 = { version = "0.2.7", package = "embedded-hal", optional = true, features = ["unproven"] }
embedded-hal-1 = { version = "1.0.0", package = "embedded-hal", optional = true }
esp32c6-lp = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true }
esp32s2-ulp = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true }
esp32s3-ulp = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true }
esp32c6-lp = { git = "https://github.com/esp-rs/esp-pacs", rev = "a8a8340", features = ["critical-section"], optional = true }
esp32s2-ulp = { git = "https://github.com/esp-rs/esp-pacs", rev = "a8a8340", features = ["critical-section"], optional = true }
esp32s3-ulp = { git = "https://github.com/esp-rs/esp-pacs", rev = "a8a8340", features = ["critical-section"], optional = true }
nb = { version = "1.1.0", optional = true }
paste = { version = "1.0.14", optional = true }
procmacros = { package = "esp-hal-procmacros", path = "../esp-hal-procmacros" }