-
Notifications
You must be signed in to change notification settings - Fork 204
RMT Onewire Peripheral #454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
a37af47
d45b33f
4a62132
b9de421
cc879bf
0183797
6e3f9b0
7148db1
719911b
c72e53c
cb17743
af7827b
f2453a4
9696af5
a72fb45
d0f1185
389135b
f8145c1
831be2d
bcf0ddd
8a8d7fd
c110fef
a7e26a9
fd076e8
269f4f3
eb6b1c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| { | ||
ivmarkov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "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" | ||
| } | ||
| 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" | ||
ivmarkov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #include "onewire_device.h" | ||
| // #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| dependencies: | ||
ivmarkov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"))] | ||
|
||
| 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(); | ||
|
|
||
|
|
@@ -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, | ||
|
|
@@ -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()) | ||
| } | ||
|
|
@@ -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>) { | ||
|
|
@@ -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() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"))] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
|
||
|
|
@@ -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()?; | ||
|
|
||
| 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)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"))] | ||
|
||
| 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!"); | ||
|
|
||
|
|
@@ -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)); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.