Update esp-hal-smartled to use the new rmt driver, remove old pulse_control driver (#694)

* Remove the old `pulse_control` driver

* Update `esp-hal-smartled` to use the new `rmt` driver instead

* Update the `hello_rgb` example for each chip

* Update CHANGELOG
This commit is contained in:
Jesse Braham 2023-07-27 08:07:15 -07:00 committed by GitHub
parent debe2b8004
commit a95f6efb35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 118 additions and 1868 deletions

View File

@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed ### Removed
- Remove the `allow-opt-level-z` feature from `esp32c3-hal` (#654) - Remove the `allow-opt-level-z` feature from `esp32c3-hal` (#654)
- Remove the old `pulse_control` driver (#694)
### Breaking ### Breaking

View File

@ -53,8 +53,6 @@ pub use self::dma::pdma;
#[cfg(gpio)] #[cfg(gpio)]
pub use self::gpio::IO; pub use self::gpio::IO;
#[cfg(rmt)] #[cfg(rmt)]
pub use self::pulse_control::PulseControl;
#[cfg(rmt)]
pub use self::rmt::Rmt; pub use self::rmt::Rmt;
#[cfg(rng)] #[cfg(rng)]
pub use self::rng::Rng; pub use self::rng::Rng;
@ -111,8 +109,6 @@ pub mod otg_fs;
pub mod pcnt; pub mod pcnt;
pub mod peripheral; pub mod peripheral;
pub mod prelude; pub mod prelude;
#[cfg(rmt)]
pub mod pulse_control;
#[cfg(radio)] #[cfg(radio)]
pub mod radio; pub mod radio;
pub mod reset; pub mod reset;

View File

@ -60,11 +60,6 @@ pub use crate::ledc::{
}, },
timer::{TimerHW as _esp_hal_ledc_timer_TimerHW, TimerIFace as _esp_hal_ledc_timer_TimerIFace}, timer::{TimerHW as _esp_hal_ledc_timer_TimerHW, TimerIFace as _esp_hal_ledc_timer_TimerIFace},
}; };
#[cfg(rmt)]
pub use crate::pulse_control::{
ConfiguredChannel as _esp_hal_pulse_control_ConfiguredChannel,
OutputChannel as _esp_hal_pulse_control_OutputChannel,
};
#[cfg(radio)] #[cfg(radio)]
pub use crate::radio::RadioExt as _esp_hal_RadioExt; pub use crate::radio::RadioExt as _esp_hal_RadioExt;
#[cfg(any(esp32, esp32s2, esp32s3))] #[cfg(any(esp32, esp32s2, esp32s3))]

File diff suppressed because it is too large Load Diff

View File

@ -12,33 +12,28 @@
//! //!
//! ```rust,ignore //! ```rust,ignore
//! let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); //! let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
//! let pulse = PulseControl::new( //! let rmt = Rmt::new(
//! peripherals.RMT, //! peripherals.RMT,
//! 80u32.MHz(),
//! &mut system.peripheral_clock_control, //! &mut system.peripheral_clock_control,
//! ClockSource::APB, //! &clocks,
//! 0,
//! 0,
//! 0,
//! ) //! )
//! .unwrap(); //! .unwrap();
//! //!
//! let led = <smartLedAdapter!(1)>::new(pulse.channel0, io.pins.gpio0); //! let led = <smartLedAdapter!(0, 1)>::new(rmt.channel0, io.pins.gpio0);
//! ``` //! ```
#![no_std] #![no_std]
#![deny(missing_docs)] #![deny(missing_docs)]
#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/46717278")] #![doc(html_logo_url = "https://avatars.githubusercontent.com/u/46717278")]
use core::slice::IterMut; use core::{fmt::Debug, slice::IterMut};
#[cfg(any(feature = "esp32", feature = "esp32s2"))]
use esp_hal_common::pulse_control::ClockSource;
use esp_hal_common::{ use esp_hal_common::{
gpio::OutputPin, gpio::OutputPin,
peripheral::Peripheral, peripheral::Peripheral,
pulse_control::{ConfiguredChannel, OutputChannel, PulseCode, RepeatMode, TransmissionError}, rmt::{Error as RmtError, PulseCode, TxChannel, TxChannelConfig, TxChannelCreator},
}; };
use fugit::NanosDuration;
use smart_leds_trait::{SmartLedsWrite, RGB8}; use smart_leds_trait::{SmartLedsWrite, RGB8};
// Specifies what clock frequency we're using for the RMT peripheral (if // Specifies what clock frequency we're using for the RMT peripheral (if
@ -65,14 +60,10 @@ const SK68XX_T0L_NS: u32 = SK68XX_CODE_PERIOD - SK68XX_T0H_NS;
const SK68XX_T1H_NS: u32 = 640; const SK68XX_T1H_NS: u32 = 640;
const SK68XX_T1L_NS: u32 = SK68XX_CODE_PERIOD - SK68XX_T1H_NS; const SK68XX_T1L_NS: u32 = SK68XX_CODE_PERIOD - SK68XX_T1H_NS;
const SK68XX_T0H_CYCLES: NanosDuration<u32> = const SK68XX_T0H_CYCLES: u16 = ((SK68XX_T0H_NS * (SOURCE_CLK_FREQ / 1_000_000)) / 500) as u16;
NanosDuration::<u32>::from_ticks((SK68XX_T0H_NS * (SOURCE_CLK_FREQ / 1_000_000)) / 500); const SK68XX_T0L_CYCLES: u16 = ((SK68XX_T0L_NS * (SOURCE_CLK_FREQ / 1_000_000)) / 500) as u16;
const SK68XX_T0L_CYCLES: NanosDuration<u32> = const SK68XX_T1H_CYCLES: u16 = ((SK68XX_T1H_NS * (SOURCE_CLK_FREQ / 1_000_000)) / 500) as u16;
NanosDuration::<u32>::from_ticks((SK68XX_T0L_NS * (SOURCE_CLK_FREQ / 1_000_000)) / 500); const SK68XX_T1L_CYCLES: u16 = ((SK68XX_T1L_NS * (SOURCE_CLK_FREQ / 1_000_000)) / 500) as u16;
const SK68XX_T1H_CYCLES: NanosDuration<u32> =
NanosDuration::<u32>::from_ticks((SK68XX_T1H_NS * (SOURCE_CLK_FREQ / 1_000_000)) / 500);
const SK68XX_T1L_CYCLES: NanosDuration<u32> =
NanosDuration::<u32>::from_ticks((SK68XX_T1L_NS * (SOURCE_CLK_FREQ / 1_000_000)) / 500);
/// All types of errors that can happen during the conversion and transmission /// All types of errors that can happen during the conversion and transmission
/// of LED commands /// of LED commands
@ -81,7 +72,7 @@ pub enum LedAdapterError {
/// Raised in the event that the provided data container is not large enough /// Raised in the event that the provided data container is not large enough
BufferSizeExceeded, BufferSizeExceeded,
/// Raised if something goes wrong in the transmission, /// Raised if something goes wrong in the transmission,
TransmissionError(TransmissionError), TransmissionError(RmtError),
} }
/// Macro to generate adapters with an arbitrary buffer size fitting for a /// Macro to generate adapters with an arbitrary buffer size fitting for a
@ -91,55 +82,53 @@ pub enum LedAdapterError {
/// an `LedAdapterError:BufferSizeExceeded` error. /// an `LedAdapterError:BufferSizeExceeded` error.
#[macro_export] #[macro_export]
macro_rules! smartLedAdapter { macro_rules! smartLedAdapter {
( $buffer_size: literal ) => { ( $channel: literal, $buffer_size: literal ) => {
// The size we're assigning here is calculated as following // The size we're assigning here is calculated as following
// ( // (
// Nr. of LEDs // Nr. of LEDs
// * channels (r,g,b -> 3) // * channels (r,g,b -> 3)
// * pulses per channel 8) // * pulses per channel 8)
// ) + 1 additional pulse for the end delimiter // ) + 1 additional pulse for the end delimiter
SmartLedsAdapter::<_, { $buffer_size * 24 + 1 }> SmartLedsAdapter::<_, $channel, { $buffer_size * 24 + 1 }>
}; };
} }
/// Adapter taking an RMT channel and a specific pin and providing RGB LED /// Adapter taking an RMT channel and a specific pin and providing RGB LED
/// interaction functionality using the `smart-leds` crate /// interaction functionality using the `smart-leds` crate
pub struct SmartLedsAdapter<CHANNEL, const BUFFER_SIZE: usize> { pub struct SmartLedsAdapter<TX, const CHANNEL: u8, const BUFFER_SIZE: usize>
channel: CHANNEL, where
TX: TxChannel<CHANNEL>,
{
channel: Option<TX>,
rmt_buffer: [u32; BUFFER_SIZE], rmt_buffer: [u32; BUFFER_SIZE],
} }
impl<'d, CHANNEL, const BUFFER_SIZE: usize> SmartLedsAdapter<CHANNEL, BUFFER_SIZE> impl<'d, TX, const CHANNEL: u8, const BUFFER_SIZE: usize> SmartLedsAdapter<TX, CHANNEL, BUFFER_SIZE>
where where
CHANNEL: ConfiguredChannel, TX: TxChannel<CHANNEL>,
{ {
/// Create a new adapter object that drives the pin using the RMT channel. /// Create a new adapter object that drives the pin using the RMT channel.
pub fn new<UnconfiguredChannel, O: OutputPin + 'd>( pub fn new<C, O>(
mut channel: UnconfiguredChannel, channel: C,
pin: impl Peripheral<P = O> + 'd, pin: impl Peripheral<P = O> + 'd,
) -> SmartLedsAdapter<CHANNEL, BUFFER_SIZE> ) -> SmartLedsAdapter<TX, CHANNEL, BUFFER_SIZE>
where where
UnconfiguredChannel: OutputChannel<ConfiguredChannel<'d, O> = CHANNEL>, O: OutputPin + 'd,
C: TxChannelCreator<'d, TX, O, CHANNEL>,
{ {
#[cfg(not(any(feature = "esp32", feature = "esp32s2")))] let config = TxChannelConfig {
channel clk_divider: 1,
.set_idle_output_level(false) idle_output_level: false,
.set_carrier_modulation(false) carrier_modulation: false,
.set_channel_divider(1) idle_output: true,
.set_idle_output(true);
#[cfg(any(feature = "esp32", feature = "esp32s2"))] ..TxChannelConfig::default()
channel };
.set_idle_output_level(false)
.set_carrier_modulation(false)
.set_channel_divider(1)
.set_idle_output(true)
.set_clock_source(ClockSource::APB);
let channel = channel.assign_pin(pin); let channel = channel.configure(pin, config).unwrap();
Self { Self {
channel, channel: Some(channel),
rmt_buffer: [0; BUFFER_SIZE], rmt_buffer: [0; BUFFER_SIZE],
} }
} }
@ -148,9 +137,9 @@ where
value: RGB8, value: RGB8,
mut_iter: &mut IterMut<u32>, mut_iter: &mut IterMut<u32>,
) -> Result<(), LedAdapterError> { ) -> Result<(), LedAdapterError> {
SmartLedsAdapter::<CHANNEL, BUFFER_SIZE>::convert_rgb_channel_to_pulses(value.g, mut_iter)?; Self::convert_rgb_channel_to_pulses(value.g, mut_iter)?;
SmartLedsAdapter::<CHANNEL, BUFFER_SIZE>::convert_rgb_channel_to_pulses(value.r, mut_iter)?; Self::convert_rgb_channel_to_pulses(value.r, mut_iter)?;
SmartLedsAdapter::<CHANNEL, BUFFER_SIZE>::convert_rgb_channel_to_pulses(value.b, mut_iter)?; Self::convert_rgb_channel_to_pulses(value.b, mut_iter)?;
Ok(()) Ok(())
} }
@ -183,9 +172,10 @@ where
} }
} }
impl<CHANNEL, const BUFFER_SIZE: usize> SmartLedsWrite for SmartLedsAdapter<CHANNEL, BUFFER_SIZE> impl<TX, const CHANNEL: u8, const BUFFER_SIZE: usize> SmartLedsWrite
for SmartLedsAdapter<TX, CHANNEL, BUFFER_SIZE>
where where
CHANNEL: ConfiguredChannel, TX: TxChannel<CHANNEL>,
{ {
type Error = LedAdapterError; type Error = LedAdapterError;
type Color = RGB8; type Color = RGB8;
@ -205,22 +195,23 @@ where
// This will result in an `BufferSizeExceeded` error in case // This will result in an `BufferSizeExceeded` error in case
// the iterator provides more elements than the buffer can take. // the iterator provides more elements than the buffer can take.
for item in iterator { for item in iterator {
SmartLedsAdapter::<CHANNEL, BUFFER_SIZE>::convert_rgb_to_pulse( Self::convert_rgb_to_pulse(item.into(), &mut seq_iter)?;
item.into(),
&mut seq_iter,
)?;
} }
// Finally, add an end element. // Finally, add an end element.
*seq_iter.next().ok_or(LedAdapterError::BufferSizeExceeded)? = 0; *seq_iter.next().ok_or(LedAdapterError::BufferSizeExceeded)? = 0;
// Perform the actual RMT operation. We use the u32 values here right away. // Perform the actual RMT operation. We use the u32 values here right away.
match self let channel = self.channel.take().unwrap();
.channel match channel.transmit(&self.rmt_buffer).wait() {
.send_pulse_sequence_raw(RepeatMode::SingleShot, &self.rmt_buffer) Ok(chan) => {
{ self.channel = Some(chan);
Ok(_) => Ok(()), Ok(())
Err(x) => Err(LedAdapterError::TransmissionError(x)), }
Err((e, chan)) => {
self.channel = Some(chan);
Err(LedAdapterError::TransmissionError(e))
}
} }
} }
} }

View File

@ -17,13 +17,12 @@ use esp32_hal::{
clock::ClockControl, clock::ClockControl,
peripherals, peripherals,
prelude::*, prelude::*,
rmt::Rmt,
timer::TimerGroup, timer::TimerGroup,
Delay, Delay,
PulseControl,
Rtc, Rtc,
IO, IO,
}; };
#[allow(unused_imports)]
use esp_backtrace as _; use esp_backtrace as _;
use esp_hal_smartled::{smartLedAdapter, SmartLedsAdapter}; use esp_hal_smartled::{smartLedAdapter, SmartLedsAdapter};
use smart_leds::{ use smart_leds::{
@ -40,27 +39,33 @@ fn main() -> ! {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let mut rtc = Rtc::new(peripherals.RTC_CNTL); let mut rtc = Rtc::new(peripherals.RTC_CNTL);
let timer_group0 = TimerGroup::new( let mut timer_group0 = TimerGroup::new(
peripherals.TIMG0, peripherals.TIMG0,
&clocks, &clocks,
&mut system.peripheral_clock_control, &mut system.peripheral_clock_control,
); );
let mut wdt = timer_group0.wdt;
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
// Disable MWDT and RWDT (Watchdog) flash boot protection // Disable MWDT and RWDT (Watchdog) flash boot protection
wdt.disable(); timer_group0.wdt.disable();
rtc.rwdt.disable(); rtc.rwdt.disable();
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
// Configure RMT peripheral globally // Configure RMT peripheral globally
let pulse = PulseControl::new(peripherals.RMT, &mut system.peripheral_clock_control).unwrap(); let rmt = Rmt::new(
peripherals.RMT,
80u32.MHz(),
&mut system.peripheral_clock_control,
&clocks,
)
.unwrap();
// We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can // We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can
// be used directly with all `smart_led` implementations // be used directly with all `smart_led` implementations
// -> We need to use the macro `smartLedAdapter!` with the number of addressed // -> We need to use the macro `smartLedAdapter!` with the number of addressed
// LEDs here to initialize the internal LED pulse buffer to the correct // LEDs here to initialize the internal LED pulse buffer to the correct
// size! // size!
let mut led = <smartLedAdapter!(12)>::new(pulse.channel0, io.pins.gpio33); let mut led = <smartLedAdapter!(0, 12)>::new(rmt.channel0, io.pins.gpio33);
// Initialize the Delay peripheral, and use it to toggle the LED state in a // Initialize the Delay peripheral, and use it to toggle the LED state in a
// loop. // loop.

View File

@ -1,86 +0,0 @@
//! RMT / PulseControl
//!
//! Folowing pins are used:
//! GPIO4 (RMT channel 0)
//!
//! Depending on your target and the board you are using you have to change the
//! pins.
//!
//! This is an example of generating pulses. Attach a Logic Analyzer to the RTM
//! channel 0 pin to see the gerated signal.
#![no_std]
#![no_main]
use esp32_hal::{
clock::ClockControl,
gpio::IO,
peripherals::Peripherals,
prelude::*,
pulse_control::{ConfiguredChannel, OutputChannel, PulseCode, RepeatMode},
timer::TimerGroup,
PulseControl,
Rtc,
};
use esp_backtrace as _;
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let mut system = peripherals.DPORT.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt = timer_group0.wdt;
let mut rtc = Rtc::new(peripherals.RTC_CNTL);
// Disable MWDT and RWDT (Watchdog) flash boot protection
wdt.disable();
rtc.rwdt.disable();
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
// Configure RMT peripheral globally
let pulse = PulseControl::new(peripherals.RMT, &mut system.peripheral_clock_control).unwrap();
let mut rmt_channel0 = pulse.channel0;
rmt_channel0
.set_idle_output_level(false)
.set_carrier_modulation(false)
.set_channel_divider(1)
.set_idle_output(true);
// Assign GPIO pin where pulses should be sent to
let mut rmt_channel0 = rmt_channel0.assign_pin(io.pins.gpio4);
// Create pulse sequence
let mut seq = [PulseCode {
level1: true,
length1: 0u32.nanos(),
level2: false,
length2: 0u32.nanos(),
}; 128];
// -1 to make sure that the last element is a transmission end marker (i.e.
// lenght 0)
for i in 0..(seq.len() - 1) {
seq[i] = PulseCode {
level1: true,
length1: (10u32 * (i as u32 + 1u32)).nanos(),
level2: false,
length2: 60u32.nanos(),
};
}
loop {
// Send sequence
rmt_channel0
.send_pulse_sequence(RepeatMode::SingleShot, &seq)
.unwrap();
}
}

View File

@ -15,14 +15,12 @@ use esp32c3_hal::{
clock::ClockControl, clock::ClockControl,
peripherals, peripherals,
prelude::*, prelude::*,
pulse_control::ClockSource, rmt::Rmt,
timer::TimerGroup, timer::TimerGroup,
Delay, Delay,
PulseControl,
Rtc, Rtc,
IO, IO,
}; };
#[allow(unused_imports)]
use esp_backtrace as _; use esp_backtrace as _;
use esp_hal_smartled::{smartLedAdapter, SmartLedsAdapter}; use esp_hal_smartled::{smartLedAdapter, SmartLedsAdapter};
use smart_leds::{ use smart_leds::{
@ -39,33 +37,31 @@ fn main() -> ! {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let mut rtc = Rtc::new(peripherals.RTC_CNTL); let mut rtc = Rtc::new(peripherals.RTC_CNTL);
let timer_group0 = TimerGroup::new( let mut timer_group0 = TimerGroup::new(
peripherals.TIMG0, peripherals.TIMG0,
&clocks, &clocks,
&mut system.peripheral_clock_control, &mut system.peripheral_clock_control,
); );
let mut wdt0 = timer_group0.wdt;
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
// Disable watchdogs // Disable watchdogs
rtc.swd.disable(); rtc.swd.disable();
rtc.rwdt.disable(); rtc.rwdt.disable();
wdt0.disable(); timer_group0.wdt.disable();
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
// Configure RMT peripheral globally // Configure RMT peripheral globally
let pulse = PulseControl::new( let rmt = Rmt::new(
peripherals.RMT, peripherals.RMT,
80u32.MHz(),
&mut system.peripheral_clock_control, &mut system.peripheral_clock_control,
ClockSource::APB, &clocks,
0,
0,
0,
) )
.unwrap(); .unwrap();
// We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can // We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can
// be used directly with all `smart_led` implementations // be used directly with all `smart_led` implementations
let mut led = <smartLedAdapter!(1)>::new(pulse.channel0, io.pins.gpio8); let mut led = <smartLedAdapter!(0, 1)>::new(rmt.channel0, io.pins.gpio8);
// Initialize the Delay peripheral, and use it to toggle the LED state in a // Initialize the Delay peripheral, and use it to toggle the LED state in a
// loop. // loop.

View File

@ -1,104 +0,0 @@
//! RMT / PulseControl
//!
//! Folowing pins are used:
//! GPIO4 (RMT channel 0)
//!
//! Depending on your target and the board you are using you have to change the
//! pins.
//!
//! This is an example of generating pulses. Attach a Logic Analyzer to the RTM
//! channel 0 pin to see the gerated signal.
#![no_std]
#![no_main]
use esp32c3_hal::{
clock::ClockControl,
gpio::IO,
peripherals::Peripherals,
prelude::*,
pulse_control::{ClockSource, ConfiguredChannel, OutputChannel, PulseCode, RepeatMode},
timer::TimerGroup,
PulseControl,
Rtc,
};
use esp_backtrace as _;
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let mut system = peripherals.SYSTEM.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
// Disable the watchdog timers. For the ESP32-C3, this includes the Super WDT,
// the RTC WDT, and the TIMG WDTs.
let mut rtc = Rtc::new(peripherals.RTC_CNTL);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt0 = timer_group0.wdt;
let timer_group1 = TimerGroup::new(
peripherals.TIMG1,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt1 = timer_group1.wdt;
rtc.swd.disable();
rtc.rwdt.disable();
wdt0.disable();
wdt1.disable();
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
// Configure RMT peripheral globally
let pulse = PulseControl::new(
peripherals.RMT,
&mut system.peripheral_clock_control,
ClockSource::APB,
0,
0,
0,
)
.unwrap();
let mut rmt_channel0 = pulse.channel0;
// Set up channel
rmt_channel0
.set_idle_output_level(false)
.set_carrier_modulation(false)
.set_channel_divider(1)
.set_idle_output(true);
// Assign GPIO pin where pulses should be sent to
let mut rmt_channel0 = rmt_channel0.assign_pin(io.pins.gpio4);
// Create pulse sequence
let mut seq = [PulseCode {
level1: true,
length1: 0u32.nanos(),
level2: false,
length2: 0u32.nanos(),
}; 128];
// -1 to make sure that the last element is a transmission end marker (i.e.
// lenght 0)
for i in 0..(seq.len() - 1) {
seq[i] = PulseCode {
level1: true,
length1: (10u32 * (i as u32 + 1u32)).nanos(),
level2: false,
length2: 60u32.nanos(),
};
}
loop {
// Send sequence
rmt_channel0
.send_pulse_sequence(RepeatMode::SingleShot, &seq)
.unwrap();
}
}

View File

@ -14,10 +14,9 @@ use esp32c6_hal::{
clock::ClockControl, clock::ClockControl,
peripherals, peripherals,
prelude::*, prelude::*,
pulse_control::ClockSource, rmt::Rmt,
timer::TimerGroup, timer::TimerGroup,
Delay, Delay,
PulseControl,
Rtc, Rtc,
IO, IO,
}; };
@ -39,40 +38,37 @@ fn main() -> ! {
// Disable the watchdog timers. For the ESP32-C6, this includes the Super WDT, // Disable the watchdog timers. For the ESP32-C6, this includes the Super WDT,
// and the TIMG WDTs. // and the TIMG WDTs.
let mut rtc = Rtc::new(peripherals.LP_CLKRST); let mut rtc = Rtc::new(peripherals.LP_CLKRST);
let timer_group0 = TimerGroup::new( let mut timer_group0 = TimerGroup::new(
peripherals.TIMG0, peripherals.TIMG0,
&clocks, &clocks,
&mut system.peripheral_clock_control, &mut system.peripheral_clock_control,
); );
let mut wdt0 = timer_group0.wdt; let mut timer_group1 = TimerGroup::new(
let timer_group1 = TimerGroup::new(
peripherals.TIMG1, peripherals.TIMG1,
&clocks, &clocks,
&mut system.peripheral_clock_control, &mut system.peripheral_clock_control,
); );
let mut wdt1 = timer_group1.wdt;
// Disable watchdog timers // Disable watchdog timers
rtc.swd.disable(); rtc.swd.disable();
rtc.rwdt.disable(); rtc.rwdt.disable();
wdt0.disable(); timer_group0.wdt.disable();
wdt1.disable(); timer_group1.wdt.disable();
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
// Configure RMT peripheral globally // Configure RMT peripheral globally
let pulse = PulseControl::new( let rmt = Rmt::new(
peripherals.RMT, peripherals.RMT,
80u32.MHz(),
&mut system.peripheral_clock_control, &mut system.peripheral_clock_control,
ClockSource::APB, &clocks,
0,
0,
0,
) )
.unwrap(); .unwrap();
// We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can // We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can
// be used directly with all `smart_led` implementations // be used directly with all `smart_led` implementations
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); let mut led = <smartLedAdapter!(0, 1)>::new(rmt.channel0, io.pins.gpio8);
let mut led = <smartLedAdapter!(1)>::new(pulse.channel0, io.pins.gpio8);
// Initialize the Delay peripheral, and use it to toggle the LED state in a // Initialize the Delay peripheral, and use it to toggle the LED state in a
// loop. // loop.

View File

@ -1,105 +0,0 @@
//! RMT / PulseControl
//!
//! Folowing pins are used:
//! GPIO4 (RMT channel 0)
//!
//! Depending on your target and the board you are using you have to change the
//! pins.
//!
//! This is an example of generating pulses. Attach a Logic Analyzer to the RTM
//! channel 0 pin to see the gerated signal.
#![no_std]
#![no_main]
use esp32c6_hal::{
clock::ClockControl,
gpio::IO,
peripherals::Peripherals,
prelude::*,
pulse_control::{ClockSource, ConfiguredChannel, OutputChannel, PulseCode, RepeatMode},
timer::TimerGroup,
PulseControl,
Rtc,
};
use esp_backtrace as _;
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let mut system = peripherals.PCR.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
// Disable the watchdog timers. For the ESP32-C6, this includes the Super WDT,
// and the TIMG WDTs.
let mut rtc = Rtc::new(peripherals.LP_CLKRST);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt0 = timer_group0.wdt;
let timer_group1 = TimerGroup::new(
peripherals.TIMG1,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt1 = timer_group1.wdt;
// Disable watchdog timers
rtc.swd.disable();
rtc.rwdt.disable();
wdt0.disable();
wdt1.disable();
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
// Configure RMT peripheral globally
let pulse = PulseControl::new(
peripherals.RMT,
&mut system.peripheral_clock_control,
ClockSource::APB,
0,
0,
0,
)
.unwrap();
let mut rmt_channel0 = pulse.channel0;
// Set up channel
rmt_channel0
.set_idle_output_level(false)
.set_carrier_modulation(false)
.set_channel_divider(1)
.set_idle_output(true);
// Assign GPIO pin where pulses should be sent to
let mut rmt_channel0 = rmt_channel0.assign_pin(io.pins.gpio4);
// Create pulse sequence
let mut seq = [PulseCode {
level1: true,
length1: 0u32.nanos(),
level2: false,
length2: 0u32.nanos(),
}; 128];
// -1 to make sure that the last element is a transmission end marker (i.e.
// lenght 0)
for i in 0..(seq.len() - 1) {
seq[i] = PulseCode {
level1: true,
length1: (10u32 * (i as u32 + 1u32)).nanos(),
level2: false,
length2: 60u32.nanos(),
};
}
loop {
// Send sequence
rmt_channel0
.send_pulse_sequence(RepeatMode::SingleShot, &seq)
.unwrap();
}
}

View File

@ -14,10 +14,9 @@ use esp32h2_hal::{
clock::ClockControl, clock::ClockControl,
peripherals, peripherals,
prelude::*, prelude::*,
pulse_control::ClockSource, rmt::Rmt,
timer::TimerGroup, timer::TimerGroup,
Delay, Delay,
PulseControl,
Rtc, Rtc,
IO, IO,
}; };
@ -39,40 +38,37 @@ fn main() -> ! {
// Disable the watchdog timers. For the ESP32-H2, this includes the Super WDT, // Disable the watchdog timers. For the ESP32-H2, this includes the Super WDT,
// and the TIMG WDTs. // and the TIMG WDTs.
let mut rtc = Rtc::new(peripherals.LP_CLKRST); let mut rtc = Rtc::new(peripherals.LP_CLKRST);
let timer_group0 = TimerGroup::new( let mut timer_group0 = TimerGroup::new(
peripherals.TIMG0, peripherals.TIMG0,
&clocks, &clocks,
&mut system.peripheral_clock_control, &mut system.peripheral_clock_control,
); );
let mut wdt0 = timer_group0.wdt; let mut timer_group1 = TimerGroup::new(
let timer_group1 = TimerGroup::new(
peripherals.TIMG1, peripherals.TIMG1,
&clocks, &clocks,
&mut system.peripheral_clock_control, &mut system.peripheral_clock_control,
); );
let mut wdt1 = timer_group1.wdt;
// Disable watchdog timers // Disable watchdog timers
rtc.swd.disable(); rtc.swd.disable();
rtc.rwdt.disable(); rtc.rwdt.disable();
wdt0.disable(); timer_group0.wdt.disable();
wdt1.disable(); timer_group1.wdt.disable();
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
// Configure RMT peripheral globally // Configure RMT peripheral globally
let pulse = PulseControl::new( let rmt = Rmt::new(
peripherals.RMT, peripherals.RMT,
80u32.MHz(),
&mut system.peripheral_clock_control, &mut system.peripheral_clock_control,
ClockSource::XTAL, &clocks,
0,
0,
0,
) )
.unwrap(); .unwrap();
// We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can // We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can
// be used directly with all `smart_led` implementations // be used directly with all `smart_led` implementations
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); let mut led = <smartLedAdapter!(0, 1)>::new(rmt.channel0, io.pins.gpio8);
let mut led = <smartLedAdapter!(1)>::new(pulse.channel0, io.pins.gpio8);
// Initialize the Delay peripheral, and use it to toggle the LED state in a // Initialize the Delay peripheral, and use it to toggle the LED state in a
// loop. // loop.

View File

@ -1,105 +0,0 @@
//! RMT / PulseControl
//!
//! Folowing pins are used:
//! GPIO4 (RMT channel 0)
//!
//! Depending on your target and the board you are using you have to change the
//! pins.
//!
//! This is an example of generating pulses. Attach a Logic Analyzer to the RTM
//! channel 0 pin to see the gerated signal.
#![no_std]
#![no_main]
use esp32h2_hal::{
clock::ClockControl,
gpio::IO,
peripherals::Peripherals,
prelude::*,
pulse_control::{ClockSource, ConfiguredChannel, OutputChannel, PulseCode, RepeatMode},
timer::TimerGroup,
PulseControl,
Rtc,
};
use esp_backtrace as _;
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let mut system = peripherals.PCR.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
// Disable the watchdog timers. For the ESP32-H2, this includes the Super WDT,
// and the TIMG WDTs.
let mut rtc = Rtc::new(peripherals.LP_CLKRST);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt0 = timer_group0.wdt;
let timer_group1 = TimerGroup::new(
peripherals.TIMG1,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt1 = timer_group1.wdt;
// Disable watchdog timers
rtc.swd.disable();
rtc.rwdt.disable();
wdt0.disable();
wdt1.disable();
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
// Configure RMT peripheral globally
let pulse = PulseControl::new(
peripherals.RMT,
&mut system.peripheral_clock_control,
ClockSource::XTAL,
0,
0,
0,
)
.unwrap();
let mut rmt_channel0 = pulse.channel0;
// Set up channel
rmt_channel0
.set_idle_output_level(false)
.set_carrier_modulation(false)
.set_channel_divider(1)
.set_idle_output(true);
// Assign GPIO pin where pulses should be sent to
let mut rmt_channel0 = rmt_channel0.assign_pin(io.pins.gpio4);
// Create pulse sequence
let mut seq = [PulseCode {
level1: true,
length1: 0u32.nanos(),
level2: false,
length2: 0u32.nanos(),
}; 128];
// -1 to make sure that the last element is a transmission end marker (i.e.
// lenght 0)
for i in 0..(seq.len() - 1) {
seq[i] = PulseCode {
level1: true,
length1: (10u32 * (i as u32 + 1u32)).nanos(),
level2: false,
length2: 60u32.nanos(),
};
}
loop {
// Send sequence
rmt_channel0
.send_pulse_sequence(RepeatMode::SingleShot, &seq)
.unwrap();
}
}

View File

@ -15,13 +15,12 @@ use esp32s2_hal::{
clock::ClockControl, clock::ClockControl,
peripherals::Peripherals, peripherals::Peripherals,
prelude::*, prelude::*,
rmt::Rmt,
timer::TimerGroup, timer::TimerGroup,
Delay, Delay,
PulseControl,
Rtc, Rtc,
IO, IO,
}; };
#[allow(unused_imports)]
use esp_backtrace as _; use esp_backtrace as _;
use esp_hal_smartled::{smartLedAdapter, SmartLedsAdapter}; use esp_hal_smartled::{smartLedAdapter, SmartLedsAdapter};
use smart_leds::{ use smart_leds::{
@ -38,24 +37,30 @@ fn main() -> ! {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let mut rtc = Rtc::new(peripherals.RTC_CNTL); let mut rtc = Rtc::new(peripherals.RTC_CNTL);
let timer_group0 = TimerGroup::new( let mut timer_group0 = TimerGroup::new(
peripherals.TIMG0, peripherals.TIMG0,
&clocks, &clocks,
&mut system.peripheral_clock_control, &mut system.peripheral_clock_control,
); );
let mut wdt = timer_group0.wdt;
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
// Disable MWDT and RWDT (Watchdog) flash boot protection // Disable MWDT and RWDT (Watchdog) flash boot protection
wdt.disable(); timer_group0.wdt.disable();
rtc.rwdt.disable(); rtc.rwdt.disable();
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
// Configure RMT peripheral globally // Configure RMT peripheral globally
let pulse = PulseControl::new(peripherals.RMT, &mut system.peripheral_clock_control).unwrap(); let rmt = Rmt::new(
peripherals.RMT,
80u32.MHz(),
&mut system.peripheral_clock_control,
&clocks,
)
.unwrap();
// We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can // We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can
// be used directly with all `smart_led` implementations // be used directly with all `smart_led` implementations
let mut led = <smartLedAdapter!(1)>::new(pulse.channel0, io.pins.gpio18); let mut led = <smartLedAdapter!(0, 1)>::new(rmt.channel0, io.pins.gpio18);
// Initialize the Delay peripheral, and use it to toggle the LED state in a // Initialize the Delay peripheral, and use it to toggle the LED state in a
// loop. // loop.

View File

@ -1,87 +0,0 @@
//! RMT / PulseControl
//!
//! Folowing pins are used:
//! GPIO4 (RMT channel 0)
//!
//! Depending on your target and the board you are using you have to change the
//! pins.
//!
//! This is an example of generating pulses. Attach a Logic Analyzer to the RTM
//! channel 0 pin to see the gerated signal.
#![no_std]
#![no_main]
use esp32s2_hal::{
clock::ClockControl,
gpio::IO,
peripherals::Peripherals,
prelude::*,
pulse_control::{ConfiguredChannel, OutputChannel, PulseCode, RepeatMode},
timer::TimerGroup,
PulseControl,
Rtc,
};
use esp_backtrace as _;
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let mut system = peripherals.SYSTEM.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt = timer_group0.wdt;
let mut rtc = Rtc::new(peripherals.RTC_CNTL);
// Disable MWDT and RWDT (Watchdog) flash boot protection
wdt.disable();
rtc.rwdt.disable();
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
// Configure RMT peripheral globally
let pulse = PulseControl::new(peripherals.RMT, &mut system.peripheral_clock_control).unwrap();
let mut rmt_channel0 = pulse.channel0;
// Set up channel
rmt_channel0
.set_idle_output_level(false)
.set_carrier_modulation(false)
.set_channel_divider(1)
.set_idle_output(true);
// Assign GPIO pin where pulses should be sent to
let mut rmt_channel0 = rmt_channel0.assign_pin(io.pins.gpio4);
// Create pulse sequence
let mut seq = [PulseCode {
level1: true,
length1: 0u32.nanos(),
level2: false,
length2: 0u32.nanos(),
}; 128];
// -1 to make sure that the last element is a transmission end marker (i.e.
// lenght 0)
for i in 0..(seq.len() - 1) {
seq[i] = PulseCode {
level1: true,
length1: (10u32 * (i as u32 + 1u32)).nanos(),
level2: false,
length2: 60u32.nanos(),
};
}
loop {
// Send sequence
rmt_channel0
.send_pulse_sequence(RepeatMode::SingleShot, &seq)
.unwrap();
}
}

View File

@ -15,14 +15,12 @@ use esp32s3_hal::{
clock::ClockControl, clock::ClockControl,
peripherals::Peripherals, peripherals::Peripherals,
prelude::*, prelude::*,
pulse_control::ClockSource, rmt::Rmt,
timer::TimerGroup, timer::TimerGroup,
Delay, Delay,
PulseControl,
Rtc, Rtc,
IO, IO,
}; };
#[allow(unused_imports)]
use esp_backtrace as _; use esp_backtrace as _;
use esp_hal_smartled::{smartLedAdapter, SmartLedsAdapter}; use esp_hal_smartled::{smartLedAdapter, SmartLedsAdapter};
use smart_leds::{ use smart_leds::{
@ -39,32 +37,30 @@ fn main() -> ! {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let mut rtc = Rtc::new(peripherals.RTC_CNTL); let mut rtc = Rtc::new(peripherals.RTC_CNTL);
let timer_group0 = TimerGroup::new( let mut timer_group0 = TimerGroup::new(
peripherals.TIMG0, peripherals.TIMG0,
&clocks, &clocks,
&mut system.peripheral_clock_control, &mut system.peripheral_clock_control,
); );
let mut wdt = timer_group0.wdt;
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
// Disable MWDT and RWDT (Watchdog) flash boot protection // Disable MWDT and RWDT (Watchdog) flash boot protection
wdt.disable(); timer_group0.wdt.disable();
rtc.rwdt.disable(); rtc.rwdt.disable();
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
// Configure RMT peripheral globally // Configure RMT peripheral globally
let pulse = PulseControl::new( let rmt = Rmt::new(
peripherals.RMT, peripherals.RMT,
80u32.MHz(),
&mut system.peripheral_clock_control, &mut system.peripheral_clock_control,
ClockSource::APB, &clocks,
0,
0,
0,
) )
.unwrap(); .unwrap();
// We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can // We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can
// be used directly with all `smart_led` implementations // be used directly with all `smart_led` implementations
let mut led = <smartLedAdapter!(1)>::new(pulse.channel0, io.pins.gpio48); let mut led = <smartLedAdapter!(0, 1)>::new(rmt.channel0, io.pins.gpio48);
// Initialize the Delay peripheral, and use it to toggle the LED state in a // Initialize the Delay peripheral, and use it to toggle the LED state in a
// loop. // loop.

View File

@ -1,95 +0,0 @@
//! RMT / PulseControl
//!
//! Folowing pins are used:
//! GPIO4 (RMT channel 0)
//!
//! Depending on your target and the board you are using you have to change the
//! pins.
//!
//! This is an example of generating pulses. Attach a Logic Analyzer to the RTM
//! channel 0 pin to see the gerated signal.
#![no_std]
#![no_main]
use esp32s3_hal::{
clock::ClockControl,
gpio::IO,
peripherals::Peripherals,
prelude::*,
pulse_control::{ClockSource, ConfiguredChannel, OutputChannel, PulseCode, RepeatMode},
timer::TimerGroup,
PulseControl,
Rtc,
};
use esp_backtrace as _;
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let mut system = peripherals.SYSTEM.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt = timer_group0.wdt;
let mut rtc = Rtc::new(peripherals.RTC_CNTL);
// Disable MWDT and RWDT (Watchdog) flash boot protection
wdt.disable();
rtc.rwdt.disable();
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
// Configure RMT peripheral globally
let pulse = PulseControl::new(
peripherals.RMT,
&mut system.peripheral_clock_control,
ClockSource::APB,
0,
0,
0,
)
.unwrap();
let mut rmt_channel0 = pulse.channel0;
// Set up channel
rmt_channel0
.set_idle_output_level(false)
.set_carrier_modulation(false)
.set_channel_divider(1)
.set_idle_output(true);
// Assign GPIO pin where pulses should be sent to
let mut rmt_channel0 = rmt_channel0.assign_pin(io.pins.gpio4);
// Create pulse sequence
let mut seq = [PulseCode {
level1: true,
length1: 0u32.nanos(),
level2: false,
length2: 0u32.nanos(),
}; 128];
// -1 to make sure that the last element is a transmission end marker (i.e.
// lenght 0)
for i in 0..(seq.len() - 1) {
seq[i] = PulseCode {
level1: true,
length1: (10u32 * (i as u32 + 1u32)).nanos(),
level2: false,
length2: 60u32.nanos(),
};
}
loop {
// Send sequence
rmt_channel0
.send_pulse_sequence(RepeatMode::SingleShot, &seq)
.unwrap();
}
}