mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-09-28 21:00:59 +00:00
Merge pull request #181 from JurajSadel/refactor/LEDC_ctor
Make it impossible to create multiple instances of LEDC
This commit is contained in:
commit
dd1f94f347
@ -11,7 +11,7 @@
|
||||
//! 10% duty using the ABPClock
|
||||
//!
|
||||
//! ```rust,ignore
|
||||
//! let mut ledc = LEDC::new(&clock_control, &mut system.peripheral_clock_control);
|
||||
//! let mut ledc = LEDC::new(peripherals.LEDC, &clock_control, &mut system.peripheral_clock_control);
|
||||
//! ledc.set_global_slow_clock(LSGlobalClkSource::APBClk);
|
||||
//!
|
||||
//! let mut lstimer0 = ledc.get_timer::<LowSpeed>(timer::Number::Timer0);
|
||||
@ -38,7 +38,7 @@
|
||||
//! 10% duty using the ABPClock
|
||||
//!
|
||||
//! ```rust,ignore
|
||||
//! let ledc = LEDC::new(&clock_control, &mut system.peripheral_clock_control);
|
||||
//! let ledc = LEDC::new(peripherals.LEDC, &clock_control, &mut system.peripheral_clock_control);
|
||||
//!
|
||||
//! let mut hstimer0 = ledc.get_timer::<HighSpeed>(timer::Number::Timer0);
|
||||
//! hstimer0
|
||||
@ -85,6 +85,7 @@ pub enum LSGlobalClkSource {
|
||||
|
||||
/// LEDC (LED PWM Controller)
|
||||
pub struct LEDC<'a> {
|
||||
_instance: crate::pac::LEDC,
|
||||
ledc: &'a crate::pac::ledc::RegisterBlock,
|
||||
clock_control_config: &'a Clocks,
|
||||
}
|
||||
@ -105,11 +106,12 @@ impl Speed for LowSpeed {}
|
||||
|
||||
impl<'a> LEDC<'a> {
|
||||
/// Return a new LEDC
|
||||
pub fn new(clock_control_config: &'a Clocks, system: &mut PeripheralClockControl) -> Self {
|
||||
pub fn new(_instance: crate::pac::LEDC, clock_control_config: &'a Clocks, system: &mut PeripheralClockControl) -> Self {
|
||||
system.enable(Peripheral::Ledc);
|
||||
|
||||
let ledc = unsafe { &*crate::pac::LEDC::ptr() };
|
||||
LEDC {
|
||||
_instance,
|
||||
ledc,
|
||||
clock_control_config,
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ fn main() -> ! {
|
||||
|
||||
writeln!(serial0, "\nESP32 Started\n\n").unwrap();
|
||||
|
||||
let ledc = LEDC::new(&clocks, &mut system.peripheral_clock_control);
|
||||
let ledc = LEDC::new(peripherals.LEDC, &clocks, &mut system.peripheral_clock_control);
|
||||
|
||||
let mut hstimer0 = ledc.get_timer::<HighSpeed>(timer::Number::Timer0);
|
||||
|
||||
|
@ -49,7 +49,7 @@ fn main() -> ! {
|
||||
|
||||
esp_println::println!("\nESP32C3 Started\n\n");
|
||||
|
||||
let mut ledc = LEDC::new(&clocks, &mut system.peripheral_clock_control);
|
||||
let mut ledc = LEDC::new(peripherals.LEDC, &clocks, &mut system.peripheral_clock_control);
|
||||
|
||||
ledc.set_global_slow_clock(LSGlobalClkSource::APBClk);
|
||||
|
||||
|
@ -47,7 +47,7 @@ fn main() -> ! {
|
||||
|
||||
esp_println::println!("\nESP32S2 Started\n\n");
|
||||
|
||||
let mut ledc = LEDC::new(&clocks, &mut system.peripheral_clock_control);
|
||||
let mut ledc = LEDC::new(peripherals.LEDC, &clocks, &mut system.peripheral_clock_control);
|
||||
|
||||
ledc.set_global_slow_clock(LSGlobalClkSource::APBClk);
|
||||
|
||||
|
@ -47,7 +47,7 @@ fn main() -> ! {
|
||||
|
||||
esp_println::println!("\nESP32S3 Started\n\n");
|
||||
|
||||
let mut ledc = LEDC::new(&clocks, &mut system.peripheral_clock_control);
|
||||
let mut ledc = LEDC::new(peripherals.LEDC, &clocks, &mut system.peripheral_clock_control);
|
||||
|
||||
ledc.set_global_slow_clock(LSGlobalClkSource::APBClk);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user