mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-09-28 21:00:59 +00:00
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:
parent
debe2b8004
commit
a95f6efb35
@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Removed
|
||||
|
||||
- Remove the `allow-opt-level-z` feature from `esp32c3-hal` (#654)
|
||||
- Remove the old `pulse_control` driver (#694)
|
||||
|
||||
### Breaking
|
||||
|
||||
|
@ -53,8 +53,6 @@ pub use self::dma::pdma;
|
||||
#[cfg(gpio)]
|
||||
pub use self::gpio::IO;
|
||||
#[cfg(rmt)]
|
||||
pub use self::pulse_control::PulseControl;
|
||||
#[cfg(rmt)]
|
||||
pub use self::rmt::Rmt;
|
||||
#[cfg(rng)]
|
||||
pub use self::rng::Rng;
|
||||
@ -111,8 +109,6 @@ pub mod otg_fs;
|
||||
pub mod pcnt;
|
||||
pub mod peripheral;
|
||||
pub mod prelude;
|
||||
#[cfg(rmt)]
|
||||
pub mod pulse_control;
|
||||
#[cfg(radio)]
|
||||
pub mod radio;
|
||||
pub mod reset;
|
||||
|
@ -60,11 +60,6 @@ pub use crate::ledc::{
|
||||
},
|
||||
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)]
|
||||
pub use crate::radio::RadioExt as _esp_hal_RadioExt;
|
||||
#[cfg(any(esp32, esp32s2, esp32s3))]
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -12,33 +12,28 @@
|
||||
//!
|
||||
//! ```rust,ignore
|
||||
//! let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
//! let pulse = PulseControl::new(
|
||||
//! let rmt = Rmt::new(
|
||||
//! peripherals.RMT,
|
||||
//! 80u32.MHz(),
|
||||
//! &mut system.peripheral_clock_control,
|
||||
//! ClockSource::APB,
|
||||
//! 0,
|
||||
//! 0,
|
||||
//! 0,
|
||||
//! &clocks,
|
||||
//! )
|
||||
//! .unwrap();
|
||||
//!
|
||||
//! let led = <smartLedAdapter!(1)>::new(pulse.channel0, io.pins.gpio0);
|
||||
//! let led = <smartLedAdapter!(0, 1)>::new(rmt.channel0, io.pins.gpio0);
|
||||
//! ```
|
||||
|
||||
#![no_std]
|
||||
#![deny(missing_docs)]
|
||||
#![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::{
|
||||
gpio::OutputPin,
|
||||
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};
|
||||
|
||||
// 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_T1L_NS: u32 = SK68XX_CODE_PERIOD - SK68XX_T1H_NS;
|
||||
|
||||
const SK68XX_T0H_CYCLES: NanosDuration<u32> =
|
||||
NanosDuration::<u32>::from_ticks((SK68XX_T0H_NS * (SOURCE_CLK_FREQ / 1_000_000)) / 500);
|
||||
const SK68XX_T0L_CYCLES: NanosDuration<u32> =
|
||||
NanosDuration::<u32>::from_ticks((SK68XX_T0L_NS * (SOURCE_CLK_FREQ / 1_000_000)) / 500);
|
||||
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);
|
||||
const SK68XX_T0H_CYCLES: u16 = ((SK68XX_T0H_NS * (SOURCE_CLK_FREQ / 1_000_000)) / 500) as u16;
|
||||
const SK68XX_T0L_CYCLES: u16 = ((SK68XX_T0L_NS * (SOURCE_CLK_FREQ / 1_000_000)) / 500) as u16;
|
||||
const SK68XX_T1H_CYCLES: u16 = ((SK68XX_T1H_NS * (SOURCE_CLK_FREQ / 1_000_000)) / 500) as u16;
|
||||
const SK68XX_T1L_CYCLES: u16 = ((SK68XX_T1L_NS * (SOURCE_CLK_FREQ / 1_000_000)) / 500) as u16;
|
||||
|
||||
/// All types of errors that can happen during the conversion and transmission
|
||||
/// of LED commands
|
||||
@ -81,7 +72,7 @@ pub enum LedAdapterError {
|
||||
/// Raised in the event that the provided data container is not large enough
|
||||
BufferSizeExceeded,
|
||||
/// Raised if something goes wrong in the transmission,
|
||||
TransmissionError(TransmissionError),
|
||||
TransmissionError(RmtError),
|
||||
}
|
||||
|
||||
/// Macro to generate adapters with an arbitrary buffer size fitting for a
|
||||
@ -91,55 +82,53 @@ pub enum LedAdapterError {
|
||||
/// an `LedAdapterError:BufferSizeExceeded` error.
|
||||
#[macro_export]
|
||||
macro_rules! smartLedAdapter {
|
||||
( $buffer_size: literal ) => {
|
||||
( $channel: literal, $buffer_size: literal ) => {
|
||||
// The size we're assigning here is calculated as following
|
||||
// (
|
||||
// Nr. of LEDs
|
||||
// * channels (r,g,b -> 3)
|
||||
// * pulses per channel 8)
|
||||
// ) + 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
|
||||
/// interaction functionality using the `smart-leds` crate
|
||||
pub struct SmartLedsAdapter<CHANNEL, const BUFFER_SIZE: usize> {
|
||||
channel: CHANNEL,
|
||||
pub struct SmartLedsAdapter<TX, const CHANNEL: u8, const BUFFER_SIZE: usize>
|
||||
where
|
||||
TX: TxChannel<CHANNEL>,
|
||||
{
|
||||
channel: Option<TX>,
|
||||
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
|
||||
CHANNEL: ConfiguredChannel,
|
||||
TX: TxChannel<CHANNEL>,
|
||||
{
|
||||
/// Create a new adapter object that drives the pin using the RMT channel.
|
||||
pub fn new<UnconfiguredChannel, O: OutputPin + 'd>(
|
||||
mut channel: UnconfiguredChannel,
|
||||
pub fn new<C, O>(
|
||||
channel: C,
|
||||
pin: impl Peripheral<P = O> + 'd,
|
||||
) -> SmartLedsAdapter<CHANNEL, BUFFER_SIZE>
|
||||
) -> SmartLedsAdapter<TX, CHANNEL, BUFFER_SIZE>
|
||||
where
|
||||
UnconfiguredChannel: OutputChannel<ConfiguredChannel<'d, O> = CHANNEL>,
|
||||
O: OutputPin + 'd,
|
||||
C: TxChannelCreator<'d, TX, O, CHANNEL>,
|
||||
{
|
||||
#[cfg(not(any(feature = "esp32", feature = "esp32s2")))]
|
||||
channel
|
||||
.set_idle_output_level(false)
|
||||
.set_carrier_modulation(false)
|
||||
.set_channel_divider(1)
|
||||
.set_idle_output(true);
|
||||
let config = TxChannelConfig {
|
||||
clk_divider: 1,
|
||||
idle_output_level: false,
|
||||
carrier_modulation: false,
|
||||
idle_output: true,
|
||||
|
||||
#[cfg(any(feature = "esp32", feature = "esp32s2"))]
|
||||
channel
|
||||
.set_idle_output_level(false)
|
||||
.set_carrier_modulation(false)
|
||||
.set_channel_divider(1)
|
||||
.set_idle_output(true)
|
||||
.set_clock_source(ClockSource::APB);
|
||||
..TxChannelConfig::default()
|
||||
};
|
||||
|
||||
let channel = channel.assign_pin(pin);
|
||||
let channel = channel.configure(pin, config).unwrap();
|
||||
|
||||
Self {
|
||||
channel,
|
||||
channel: Some(channel),
|
||||
rmt_buffer: [0; BUFFER_SIZE],
|
||||
}
|
||||
}
|
||||
@ -148,9 +137,9 @@ where
|
||||
value: RGB8,
|
||||
mut_iter: &mut IterMut<u32>,
|
||||
) -> Result<(), LedAdapterError> {
|
||||
SmartLedsAdapter::<CHANNEL, BUFFER_SIZE>::convert_rgb_channel_to_pulses(value.g, mut_iter)?;
|
||||
SmartLedsAdapter::<CHANNEL, BUFFER_SIZE>::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.g, mut_iter)?;
|
||||
Self::convert_rgb_channel_to_pulses(value.r, mut_iter)?;
|
||||
Self::convert_rgb_channel_to_pulses(value.b, mut_iter)?;
|
||||
|
||||
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
|
||||
CHANNEL: ConfiguredChannel,
|
||||
TX: TxChannel<CHANNEL>,
|
||||
{
|
||||
type Error = LedAdapterError;
|
||||
type Color = RGB8;
|
||||
@ -205,22 +195,23 @@ where
|
||||
// This will result in an `BufferSizeExceeded` error in case
|
||||
// the iterator provides more elements than the buffer can take.
|
||||
for item in iterator {
|
||||
SmartLedsAdapter::<CHANNEL, BUFFER_SIZE>::convert_rgb_to_pulse(
|
||||
item.into(),
|
||||
&mut seq_iter,
|
||||
)?;
|
||||
Self::convert_rgb_to_pulse(item.into(), &mut seq_iter)?;
|
||||
}
|
||||
|
||||
// Finally, add an end element.
|
||||
*seq_iter.next().ok_or(LedAdapterError::BufferSizeExceeded)? = 0;
|
||||
|
||||
// Perform the actual RMT operation. We use the u32 values here right away.
|
||||
match self
|
||||
.channel
|
||||
.send_pulse_sequence_raw(RepeatMode::SingleShot, &self.rmt_buffer)
|
||||
{
|
||||
Ok(_) => Ok(()),
|
||||
Err(x) => Err(LedAdapterError::TransmissionError(x)),
|
||||
let channel = self.channel.take().unwrap();
|
||||
match channel.transmit(&self.rmt_buffer).wait() {
|
||||
Ok(chan) => {
|
||||
self.channel = Some(chan);
|
||||
Ok(())
|
||||
}
|
||||
Err((e, chan)) => {
|
||||
self.channel = Some(chan);
|
||||
Err(LedAdapterError::TransmissionError(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,13 +17,12 @@ use esp32_hal::{
|
||||
clock::ClockControl,
|
||||
peripherals,
|
||||
prelude::*,
|
||||
rmt::Rmt,
|
||||
timer::TimerGroup,
|
||||
Delay,
|
||||
PulseControl,
|
||||
Rtc,
|
||||
IO,
|
||||
};
|
||||
#[allow(unused_imports)]
|
||||
use esp_backtrace as _;
|
||||
use esp_hal_smartled::{smartLedAdapter, SmartLedsAdapter};
|
||||
use smart_leds::{
|
||||
@ -40,27 +39,33 @@ fn main() -> ! {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let mut rtc = Rtc::new(peripherals.RTC_CNTL);
|
||||
let timer_group0 = TimerGroup::new(
|
||||
let mut timer_group0 = TimerGroup::new(
|
||||
peripherals.TIMG0,
|
||||
&clocks,
|
||||
&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
|
||||
wdt.disable();
|
||||
timer_group0.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 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
|
||||
// be used directly with all `smart_led` implementations
|
||||
// -> We need to use the macro `smartLedAdapter!` with the number of addressed
|
||||
// LEDs here to initialize the internal LED pulse buffer to the correct
|
||||
// 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
|
||||
// loop.
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -15,14 +15,12 @@ use esp32c3_hal::{
|
||||
clock::ClockControl,
|
||||
peripherals,
|
||||
prelude::*,
|
||||
pulse_control::ClockSource,
|
||||
rmt::Rmt,
|
||||
timer::TimerGroup,
|
||||
Delay,
|
||||
PulseControl,
|
||||
Rtc,
|
||||
IO,
|
||||
};
|
||||
#[allow(unused_imports)]
|
||||
use esp_backtrace as _;
|
||||
use esp_hal_smartled::{smartLedAdapter, SmartLedsAdapter};
|
||||
use smart_leds::{
|
||||
@ -39,33 +37,31 @@ fn main() -> ! {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let mut rtc = Rtc::new(peripherals.RTC_CNTL);
|
||||
let timer_group0 = TimerGroup::new(
|
||||
let mut timer_group0 = TimerGroup::new(
|
||||
peripherals.TIMG0,
|
||||
&clocks,
|
||||
&mut system.peripheral_clock_control,
|
||||
);
|
||||
let mut wdt0 = timer_group0.wdt;
|
||||
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
// Disable watchdogs
|
||||
rtc.swd.disable();
|
||||
rtc.rwdt.disable();
|
||||
wdt0.disable();
|
||||
timer_group0.wdt.disable();
|
||||
|
||||
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
// Configure RMT peripheral globally
|
||||
let pulse = PulseControl::new(
|
||||
let rmt = Rmt::new(
|
||||
peripherals.RMT,
|
||||
80u32.MHz(),
|
||||
&mut system.peripheral_clock_control,
|
||||
ClockSource::APB,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
&clocks,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can
|
||||
// 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
|
||||
// loop.
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -14,10 +14,9 @@ use esp32c6_hal::{
|
||||
clock::ClockControl,
|
||||
peripherals,
|
||||
prelude::*,
|
||||
pulse_control::ClockSource,
|
||||
rmt::Rmt,
|
||||
timer::TimerGroup,
|
||||
Delay,
|
||||
PulseControl,
|
||||
Rtc,
|
||||
IO,
|
||||
};
|
||||
@ -39,40 +38,37 @@ fn main() -> ! {
|
||||
// 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(
|
||||
let mut timer_group0 = TimerGroup::new(
|
||||
peripherals.TIMG0,
|
||||
&clocks,
|
||||
&mut system.peripheral_clock_control,
|
||||
);
|
||||
let mut wdt0 = timer_group0.wdt;
|
||||
let timer_group1 = TimerGroup::new(
|
||||
let mut 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();
|
||||
timer_group0.wdt.disable();
|
||||
timer_group1.wdt.disable();
|
||||
|
||||
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
// Configure RMT peripheral globally
|
||||
let pulse = PulseControl::new(
|
||||
let rmt = Rmt::new(
|
||||
peripherals.RMT,
|
||||
80u32.MHz(),
|
||||
&mut system.peripheral_clock_control,
|
||||
ClockSource::APB,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
&clocks,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can
|
||||
// be used directly with all `smart_led` implementations
|
||||
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
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
|
||||
// loop.
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -14,10 +14,9 @@ use esp32h2_hal::{
|
||||
clock::ClockControl,
|
||||
peripherals,
|
||||
prelude::*,
|
||||
pulse_control::ClockSource,
|
||||
rmt::Rmt,
|
||||
timer::TimerGroup,
|
||||
Delay,
|
||||
PulseControl,
|
||||
Rtc,
|
||||
IO,
|
||||
};
|
||||
@ -39,40 +38,37 @@ fn main() -> ! {
|
||||
// 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(
|
||||
let mut timer_group0 = TimerGroup::new(
|
||||
peripherals.TIMG0,
|
||||
&clocks,
|
||||
&mut system.peripheral_clock_control,
|
||||
);
|
||||
let mut wdt0 = timer_group0.wdt;
|
||||
let timer_group1 = TimerGroup::new(
|
||||
let mut 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();
|
||||
timer_group0.wdt.disable();
|
||||
timer_group1.wdt.disable();
|
||||
|
||||
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
// Configure RMT peripheral globally
|
||||
let pulse = PulseControl::new(
|
||||
let rmt = Rmt::new(
|
||||
peripherals.RMT,
|
||||
80u32.MHz(),
|
||||
&mut system.peripheral_clock_control,
|
||||
ClockSource::XTAL,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
&clocks,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can
|
||||
// be used directly with all `smart_led` implementations
|
||||
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
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
|
||||
// loop.
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -15,13 +15,12 @@ use esp32s2_hal::{
|
||||
clock::ClockControl,
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
rmt::Rmt,
|
||||
timer::TimerGroup,
|
||||
Delay,
|
||||
PulseControl,
|
||||
Rtc,
|
||||
IO,
|
||||
};
|
||||
#[allow(unused_imports)]
|
||||
use esp_backtrace as _;
|
||||
use esp_hal_smartled::{smartLedAdapter, SmartLedsAdapter};
|
||||
use smart_leds::{
|
||||
@ -38,24 +37,30 @@ fn main() -> ! {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let mut rtc = Rtc::new(peripherals.RTC_CNTL);
|
||||
let timer_group0 = TimerGroup::new(
|
||||
let mut timer_group0 = TimerGroup::new(
|
||||
peripherals.TIMG0,
|
||||
&clocks,
|
||||
&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
|
||||
wdt.disable();
|
||||
timer_group0.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 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
|
||||
// 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
|
||||
// loop.
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -15,14 +15,12 @@ use esp32s3_hal::{
|
||||
clock::ClockControl,
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
pulse_control::ClockSource,
|
||||
rmt::Rmt,
|
||||
timer::TimerGroup,
|
||||
Delay,
|
||||
PulseControl,
|
||||
Rtc,
|
||||
IO,
|
||||
};
|
||||
#[allow(unused_imports)]
|
||||
use esp_backtrace as _;
|
||||
use esp_hal_smartled::{smartLedAdapter, SmartLedsAdapter};
|
||||
use smart_leds::{
|
||||
@ -39,32 +37,30 @@ fn main() -> ! {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let mut rtc = Rtc::new(peripherals.RTC_CNTL);
|
||||
let timer_group0 = TimerGroup::new(
|
||||
let mut timer_group0 = TimerGroup::new(
|
||||
peripherals.TIMG0,
|
||||
&clocks,
|
||||
&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
|
||||
wdt.disable();
|
||||
timer_group0.wdt.disable();
|
||||
rtc.rwdt.disable();
|
||||
|
||||
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
// Configure RMT peripheral globally
|
||||
let pulse = PulseControl::new(
|
||||
let rmt = Rmt::new(
|
||||
peripherals.RMT,
|
||||
80u32.MHz(),
|
||||
&mut system.peripheral_clock_control,
|
||||
ClockSource::APB,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
&clocks,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can
|
||||
// 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
|
||||
// loop.
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user