-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make RMT TX larger than one block work on ESP32-C3 and ESP32-S3
- Loading branch information
1 parent
4c44f3e
commit 91373ac
Showing
8 changed files
with
388 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//! This demos basic usage of RMT / PulseControl | ||
//! Use a logic analyzer to see the generated pulses. | ||
//! The correct output is only achieved when running in release mode. | ||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
use esp32_hal::{ | ||
clock::ClockControl, | ||
gpio::IO, | ||
pac::Peripherals, | ||
prelude::*, | ||
pulse_control::{OutputChannel, PulseCode, RepeatMode}, | ||
timer::TimerGroup, | ||
PulseControl, | ||
Rtc, | ||
}; | ||
use panic_halt as _; | ||
use xtensa_lx_rt::entry; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
let peripherals = Peripherals::take().unwrap(); | ||
let mut system = peripherals.DPORT.split(); | ||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); | ||
|
||
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); | ||
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 | ||
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(), | ||
}; | ||
} | ||
|
||
esp_println::println!("Start"); | ||
|
||
loop { | ||
// Send sequence | ||
rmt_channel0 | ||
.send_pulse_sequence(RepeatMode::SingleShot, &seq) | ||
.unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
//! This demos basic usage of RMT / PulseControl | ||
//! Use a logic analyzer to see the generated pulses. | ||
//! The correct output is only achieved when running in release mode. | ||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
use esp32c3_hal::{ | ||
clock::ClockControl, | ||
gpio::IO, | ||
pac::Peripherals, | ||
prelude::*, | ||
pulse_control::{ClockSource, OutputChannel, PulseCode, RepeatMode}, | ||
system::SystemExt, | ||
timer::TimerGroup, | ||
PulseControl, | ||
Rtc, | ||
}; | ||
use panic_halt as _; | ||
use riscv_rt::entry; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
let peripherals = Peripherals::take().unwrap(); | ||
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); | ||
let mut wdt0 = timer_group0.wdt; | ||
let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks); | ||
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 | ||
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(), | ||
}; | ||
} | ||
|
||
esp_println::println!("Start"); | ||
|
||
loop { | ||
// Send sequence | ||
rmt_channel0 | ||
.send_pulse_sequence(RepeatMode::SingleShot, &seq) | ||
.unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//! This demos basic usage of RMT / PulseControl | ||
//! Use a logic analyzer to see the generated pulses. | ||
//! The correct output is only achieved when running in release mode. | ||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
use esp32s2_hal::{ | ||
clock::ClockControl, | ||
gpio::IO, | ||
pac::Peripherals, | ||
prelude::*, | ||
pulse_control::{OutputChannel, PulseCode, RepeatMode}, | ||
timer::TimerGroup, | ||
PulseControl, | ||
Rtc, | ||
}; | ||
use panic_halt as _; | ||
use xtensa_lx_rt::entry; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
let peripherals = Peripherals::take().unwrap(); | ||
let mut system = peripherals.SYSTEM.split(); | ||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); | ||
|
||
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); | ||
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 | ||
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(), | ||
}; | ||
} | ||
|
||
esp_println::println!("Start"); | ||
|
||
loop { | ||
// Send sequence | ||
rmt_channel0 | ||
.send_pulse_sequence(RepeatMode::SingleShot, &seq) | ||
.unwrap(); | ||
} | ||
} |
Oops, something went wrong.