Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build]
target = "riscv32imc-esp-espidf"
#target = "xtensa-esp32-espidf"
# target = "riscv32imc-esp-espidf"
target = "xtensa-esp32-espidf"

[target.xtensa-esp32-espidf]
linker = "ldproxy"
Expand Down
42 changes: 42 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "rmt_onewire",
// Select between image and build propieties to pull or build the image.
"image": "docker.io/espressif/idf-rust:esp32_latest",
"customizations": {
"vscode": {
"extensions": [
"rust-lang.rust-analyzer",
"tamasfe.even-better-toml",
"serayuzgur.crates",
"mutantdino.resourcemonitor",
"yzhang.markdown-all-in-one",
"ms-vscode.cpptools",
"actboy168.tasks",
"Wokwi.wokwi-vscode",
"ms-azuretools.vscode-docker",
"ms-python.python"
],
"settings": {
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "file",
"editor.formatOnType": true,
"lldb.executable": "/usr/bin/lldb",
"files.watcherExclude": {
"**/target/**": true
},
"rust-analyzer.checkOnSave.command": "clippy",
"rust-analyzer.checkOnSave.allTargets": false,
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
}
}
}
},
"forwardPorts": [
3333,
8000
],
"workspaceMount": "source=${localWorkspaceFolder},target=/home/esp/rmt_onewire,type=bind,consistency=cached",
"workspaceFolder": "/home/esp/rmt_onewire"
}
20 changes: 17 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ std = ["alloc", "esp-idf-sys/std"]
alloc = []
nightly = []
wake-from-isr = [] # Only enable if you plan to use the `edge-executor` crate
embassy-sync = [] # For now, the dependecy on the `embassy-sync` crate is non-optional, but this might change in future
embassy-sync = [
] # For now, the dependecy on the `embassy-sync` crate is non-optional, but this might change in future
# Temporary, until (https://github.com/espressif/esp-idf/issues/13938) is addressed
# - When enabled, the code for the legacy ADC oneshot driver will be compiled;
# - When not enabled (default) the code for the new ADC oneshot driver will be compiled;
# - Since we don't wrap the legacy _continuous_ ADC driver, the new _continuous_ ADC driver is always compiled.
adc-oneshot-legacy = []
# Similar to adc-oneshot-legacy
# - When enabled (default), the code for the legacy RMT TX/RX driver will be compiled.
# - When disabled the code for the new onewire RMT driver will be compiled.
rmt-legacy = []
# Propagated esp-idf-sys features
native = ["esp-idf-sys/native"]
pio = ["esp-idf-sys/pio"]
Expand All @@ -42,13 +47,17 @@ libstart = ["esp-idf-sys/libstart"]
nb = "1"
embedded-can = "0.4.1"
embedded-hal = "1"
embedded-hal-0-2 = { package = "embedded-hal", version = "0.2.7", features = ["unproven"] }
embedded-hal-0-2 = { package = "embedded-hal", version = "0.2.7", features = [
"unproven",
] }
embedded-hal-nb = "1"
embedded-hal-async = "1"
embedded-io = "0.6"
embedded-io-async = "0.6"
esp-idf-sys = { version = "0.35", default-features = false }
critical-section = { version = "1.1.1", optional = true, features = ["restore-state-none"] }
critical-section = { version = "1.1.1", optional = true, features = [
"restore-state-none",
] }
heapless = "0.8"
num_enum = { version = "0.7", default-features = false }
enumset = { version = "1.1", default-features = false }
Expand All @@ -65,3 +74,8 @@ esp-idf-sys = { version = "0.35", features = ["binstart"] }
mipidsi = "0.5.0"
display-interface-spi = "0.4.1"
embedded-graphics = "0.7.1"

[[package.metadata.esp-idf-sys.extra_components]]
remote_component = { name = "onewire_bus", version = "^1.0.2" }
bindings_header = "bindings.h"
bindings_module = "onewire"
7 changes: 7 additions & 0 deletions bindings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// not supported on esp-idf version 4 at all
// this is currently not working
// #if ESP_IDF_VERSION_MAJOR > 4 && defined(ESP_IDF_COMP_ESPRESSIF__ONEWIRE_BUS_ENABLED)
// #include "ds18b20.h"
#include "onewire_bus.h"
#include "onewire_device.h"
// #endif
15 changes: 15 additions & 0 deletions components_esp32.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
dependencies:
espressif/onewire_bus:
component_hash: c4c781940d8bd988432b47ac3ee68479c69e14e01fdfba0b61365b233a3ba5d6
source:
service_url: https://api.components.espressif.com/
type: service
version: 1.0.2
idf:
component_hash: null
source:
type: idf
version: 5.1.2
manifest_hash: 59429c29ab45cee54021836bdacb34b12668b492bd889f9948e1421f9daaec00
target: esp32
version: 1.0.0
17 changes: 17 additions & 0 deletions examples/rmt_morse_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ use esp_idf_hal::delay::Ets;
use esp_idf_hal::gpio::*;
use esp_idf_hal::peripheral::*;
use esp_idf_hal::peripherals::Peripherals;
#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm relatively sure that in the case where rmt-legacy is not enabled, this example will compile with "unused import" warnings, as you import a lot of stuff you don't use. Not the end of the world, but ideally we should fix that too.

The easiest way to do it (and to avoid sprinkling #[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))] all over the example is to just put the whole example in a new module, as in:

#[cfg(not(any(feature = "rmt-legacy", esp_idf_version_major = "4")))]
fn main() -> anyhow::Result<()> {
    println!("This example requires feature `rmt-legacy` enabled or using ESP-IDF v4.4.X");

    loop {
        std::thread::sleep(std::time::Duration::from_millis(1000));
    }
}

#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
fn main() -> anyhow::Result<()> {
    example::main()
}

#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
mod example {
... /// Here you move the whole code of the example, with imports and whatnot.
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Will do the other examples soon.

use esp_idf_hal::rmt::config::{CarrierConfig, DutyPercent, Loop, TransmitConfig};
#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
use esp_idf_hal::rmt::*;
use esp_idf_hal::units::FromValueType;

#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
fn main() -> anyhow::Result<()> {
esp_idf_hal::sys::link_patches();

Expand Down Expand Up @@ -64,6 +67,16 @@ fn main() -> anyhow::Result<()> {
Ok(())
}

#[cfg(not(any(feature = "rmt-legacy", esp_idf_version_major = "4")))]
fn main() -> anyhow::Result<()> {
println!("This example requires feature `rmt-legacy` enabled or using ESP-IDF v4.4.X");

loop {
std::thread::sleep(std::time::Duration::from_millis(1000));
}
}

#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
fn send_morse_code<'d>(
channel: impl Peripheral<P = impl RmtChannel> + 'd,
led: impl Peripheral<P = impl OutputPin> + 'd,
Expand All @@ -85,10 +98,12 @@ fn send_morse_code<'d>(
Ok(tx)
}

#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
fn high() -> Pulse {
Pulse::new(PinState::High, PulseTicks::max())
}

#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
fn low() -> Pulse {
Pulse::new(PinState::Low, PulseTicks::max())
}
Expand All @@ -98,6 +113,7 @@ enum Code {
Dash,
WordGap,
}
#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]

impl Code {
pub fn push_pulse(&self, pulses: &mut Vec<Pulse>) {
Expand All @@ -118,6 +134,7 @@ fn find_codes(c: &char) -> &'static [Code] {
&[]
}

#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
fn str_pulses(s: &str) -> Vec<Pulse> {
let mut pulses = vec![];
for c in s.chars() {
Expand Down
16 changes: 16 additions & 0 deletions examples/rmt_musical_buzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ use core::time::Duration;

use esp_idf_hal::delay::Ets;
use esp_idf_hal::peripherals::Peripherals;
#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
use esp_idf_hal::rmt::{self, config::TransmitConfig, TxRmtDriver};

use esp_idf_hal::units::Hertz;
use notes::*;

#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
fn main() -> anyhow::Result<()> {
esp_idf_hal::sys::link_patches();

Expand All @@ -28,18 +30,30 @@ fn main() -> anyhow::Result<()> {
}
}

#[cfg(not(any(feature = "rmt-legacy", esp_idf_version_major = "4")))]
fn main() -> anyhow::Result<()> {
println!("This example requires feature `rmt-legacy` enabled or using ESP-IDF v4.4.X");

loop {
std::thread::sleep(Duration::from_millis(1000));
}
}

#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
pub fn play_song(tx: &mut TxRmtDriver<'static>, song: &[NoteValue]) -> anyhow::Result<()> {
for note_value in song {
note_value.play(tx)?;
}
Ok(())
}
#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]

pub struct NoteValueIter {
ticks: rmt::PulseTicks,
tone_cycles: u32,
pause_cycles: u32,
}
#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]

impl NoteValueIter {
fn new(ticks_per_sec: Hertz, note: &NoteValue) -> Self {
Expand All @@ -62,6 +76,7 @@ impl NoteValueIter {
}
}
}
#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]

impl std::iter::Iterator for NoteValueIter {
type Item = rmt::Symbol;
Expand Down Expand Up @@ -112,6 +127,7 @@ pub struct NoteValue {
note: Note,
duration: Duration,
}
#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]

impl NoteValue {
pub fn play(&self, tx: &mut TxRmtDriver<'static>) -> anyhow::Result<()> {
Expand Down
13 changes: 13 additions & 0 deletions examples/rmt_neopixel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ use anyhow::{bail, Result};
use core::time::Duration;
use esp_idf_hal::delay::FreeRtos;
use esp_idf_hal::peripherals::Peripherals;
#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

use esp_idf_hal::rmt::config::TransmitConfig;
#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
use esp_idf_hal::rmt::*;

#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
fn main() -> Result<()> {
esp_idf_hal::sys::link_patches();

Expand All @@ -39,6 +42,16 @@ fn main() -> Result<()> {
})
}

#[cfg(not(any(feature = "rmt-legacy", esp_idf_version_major = "4")))]
fn main() -> anyhow::Result<()> {
println!("This example requires feature `rmt-legacy` enabled or using ESP-IDF v4.4.X");

loop {
std::thread::sleep(Duration::from_millis(1000));
}
}

#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
fn neopixel(rgb: Rgb, tx: &mut TxRmtDriver) -> Result<()> {
let color: u32 = rgb.into();
let ticks_hz = tx.counter_clock()?;
Expand Down
48 changes: 48 additions & 0 deletions examples/rmt_onewire.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//! Example demonstrating the use of the onewire component.
//!
//! Connection sketch, this example uses gpio 16, but any pin capable of
//! input AND output is suitable.
//!
//! ┌──────────────────────────┐
//! │ 3.3V├───────┬─────────────┬──────────────────────┐
//! │ │ ┌┴┐ │VDD │VDD
//! │ ESP Board │ 4.7k│ │ ┌──────┴──────┐ ┌──────┴──────┐
//! │ │ └┬┘ DQ│ │ DQ│ │
//! │ ONEWIRE_GPIO_PIN├───────┴──┬───┤ DS18B20 │ ┌───┤ DS18B20 │ ......
//! │ │ └───│-------------│────┴───│-------------│──
//! │ │ └──────┬──────┘ └──────┬──────┘
//! │ │ │GND │GND
//! │ GND├─────────────────────┴──────────────────────┘
//! └──────────────────────────┘

use esp_idf_hal::delay::FreeRtos;
use esp_idf_hal::onewire::{DeviceSearch, OneWireBusDriver};
use esp_idf_hal::peripherals::Peripherals;

#[cfg(not(any(feature = "rmt-legacy", esp_idf_version_major = "4")))]
fn main() -> anyhow::Result<()> {
println!("Starting APP!");

let peripherals = Peripherals::take()?;

let onewire_gpio_pin = peripherals.pins.gpio16;

let mut rmt_onewire: OneWireBusDriver = OneWireBusDriver::new(onewire_gpio_pin)?;
let search: DeviceSearch = rmt_onewire.search()?;

for device in search {
println!("Found Device: {}", device.address());
}
loop {
FreeRtos::delay_ms(3000);
}
}

#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
fn main() -> anyhow::Result<()> {
println!("This example requires feature `rmt-legacy` disabled or using ESP-IDF > v4.4.X");

loop {
std::thread::sleep(std::time::Duration::from_millis(1000));
}
}
11 changes: 11 additions & 0 deletions examples/rmt_transceiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@

use esp_idf_hal::delay::FreeRtos;
use esp_idf_hal::peripherals::Peripherals;
#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto - mod example {}.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

use esp_idf_hal::rmt::{
FixedLengthSignal, PinState, Pulse, PulseTicks, Receive, RmtReceiveConfig, RmtTransmitConfig,
RxRmtDriver, TxRmtDriver,
};

#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]
fn main() -> anyhow::Result<()> {
println!("Starting APP!");

Expand Down Expand Up @@ -105,3 +107,12 @@ fn main() -> anyhow::Result<()> {
FreeRtos::delay_ms(3000);
}
}

#[cfg(not(any(feature = "rmt-legacy", esp_idf_version_major = "4")))]
fn main() -> anyhow::Result<()> {
println!("This example requires feature `rmt-legacy` enabled or using ESP-IDF v4.4.X");

loop {
std::thread::sleep(std::time::Duration::from_millis(1000));
}
}
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ pub mod peripheral;
pub mod peripherals;
pub mod prelude;
pub mod reset;
#[cfg(feature = "rmt-legacy")]
pub mod rmt;
//
#[cfg(all(
any(esp32, esp32c3, esp32c6, esp32h2, esp32p4, esp32s2, esp32s3),
not(feature = "rmt-legacy"),
esp_idf_comp_espressif__onewire_bus_enabled,
))]
pub mod onewire;
pub mod rom;
pub mod spi;
pub mod sys;
Expand Down
Loading