Skip to content
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

Rmt Driver missing in latest esp-idf-hal #512

Closed
joebnb opened this issue Jan 23, 2025 · 4 comments
Closed

Rmt Driver missing in latest esp-idf-hal #512

joebnb opened this issue Jan 23, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@joebnb
Copy link

joebnb commented Jan 23, 2025

i yesterday i updated esp-idf-hal and found that hal no longer expose TxRmtDriver and rust analyzer throw, and i'm not found release not note or change log, would help me explain how to solve this?

error[E0432]: unresolved import `esp_idf_svc::hal::rmt::TxRmtDriver`
 --> common/lib/rgb-led/src/lib.rs:6:83
  |
6 |     rmt::{config::TransmitConfig, FixedLengthSignal, PinState, Pulse, RmtChannel, TxRmtDriver},
  |                                                                                   ^^^^^^^^^^^ no `TxRmtDriver` in `rmt`

For more information about this error, try `rustc --explain E0432`.

this this code

use anyhow::Result;
use core::time::Duration;
use esp_idf_svc::hal::{
    gpio::OutputPin,
    peripheral::Peripheral,
    rmt::{config::TransmitConfig, FixedLengthSignal, PinState, Pulse, RmtChannel, TxRmtDriver},
};

pub use rgb::RGB8;

pub struct WS2812RMT<'a> {
    tx_rtm_driver: TxRmtDriver<'a>,
}

impl<'d> WS2812RMT<'d> {
    // Rust ESP Board gpio2,  ESP32-C3-DevKitC-02 gpio8
    pub fn new(
        led: impl Peripheral<P = impl OutputPin> + 'd,
        channel: impl Peripheral<P = impl RmtChannel> + 'd,
    ) -> Result<Self> {
        let config = TransmitConfig::new().clock_divider(2);
        let tx = TxRmtDriver::new(channel, led, &config)?;
        Ok(Self { tx_rtm_driver: tx })
    }

    pub fn set_pixel(&mut self, rgb: RGB8) -> Result<()> {
        let color: u32 = ((rgb.g as u32) << 16) | ((rgb.r as u32) << 8) | rgb.b as u32;
        let ticks_hz = self.tx_rtm_driver.counter_clock()?;
        let t0h = Pulse::new_with_duration(ticks_hz, PinState::High, &ns(350))?;
        let t0l = Pulse::new_with_duration(ticks_hz, PinState::Low, &ns(800))?;
        let t1h = Pulse::new_with_duration(ticks_hz, PinState::High, &ns(700))?;
        let t1l = Pulse::new_with_duration(ticks_hz, PinState::Low, &ns(600))?;
        let mut signal = FixedLengthSignal::<24>::new();
        for i in (0..24).rev() {
            let p = 2_u32.pow(i);
            let bit = p & color != 0;
            let (high_pulse, low_pulse) = if bit { (t1h, t1l) } else { (t0h, t0l) };
            signal.set(23 - i as usize, &(high_pulse, low_pulse))?;
        }
        self.tx_rtm_driver.start_blocking(&signal)?;

        Ok(())
    }
}

fn ns(nanos: u64) -> Duration {
    Duration::from_nanos(nanos)
}
@joebnb joebnb added the bug Something isn't working label Jan 23, 2025
@joebnb joebnb changed the title Rmt Driver lost in latestd esp-idf-hal Rmt Driver missing in latestd esp-idf-hal Jan 23, 2025
@joebnb joebnb changed the title Rmt Driver missing in latestd esp-idf-hal Rmt Driver missing in latest esp-idf-hal Jan 23, 2025
@joebnb
Copy link
Author

joebnb commented Jan 23, 2025

#[cfg(any(feature = "rmt-legacy", esp_idf_version_major = "4"))]

is this feature need add in cargo.toml ?


when added legacy feature it works well, but i have another question, if using rmt to drive is legacy the recommend drive method is what?

@ivmarkov
Copy link
Collaborator

The recommended method is the new ESP IDF RMT driver, but it does not have safe Rust bindings yet, because nobody implemented the bindings. There are only raw C-style APIs to the new driver in esp-idf-sys.

@github-project-automation github-project-automation bot moved this from Todo to Done in esp-rs Jan 23, 2025
@joebnb
Copy link
Author

joebnb commented Jan 23, 2025

The recommended method is the new ESP IDF RMT driver, but it does not have safe Rust bindings yet, because nobody implemented the bindings. There are only raw C-style APIs to the new driver in esp-idf-sys.

thanks for clarify this. i'm little bit worry about api stability for long term support, i think esp-rs may change API quick, it's not a complain, just worry about the eco and some developer choose this to production. any way thanks for clarify and contribute

@ivmarkov
Copy link
Collaborator

There was no change in the API, just an introduction of an extra feature. You can still use the driver once you enable the feature, and I don't have plans to retire the old driver, even after/if a new one is implemented.

With that said, breaking changes are expected from time to time. If you want more stability and paid developers assigned to the HAL, you should perhaps be using esp-hal and not esp-idf-*, because the baremetal HAL is supported by Espressif (with paid developers), while the esp-idf-* crates are a community effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

2 participants