Giter VIP home page Giter VIP logo

Comments (13)

ilikepi63 avatar ilikepi63 commented on June 18, 2024 1

I ran into a similar problem and decided to write my own library over esp-idf-sys.

You can find it here: https://crates.io/crates/esp-idf-servo

from esp-idf-hal.

usbalbin avatar usbalbin commented on June 18, 2024

I found the esp32 crate which seems to have this. However I am assuming that should not be used at the same time as this crate due to the crates having their own individual locks?

from esp-idf-hal.

MabezDev avatar MabezDev commented on June 18, 2024

Correct, this crate utilizes esp-idf functions and creates safe Rust wrappers around them. If you would like to try, you can create a wrapper around the MCPWM api and submit a PR (happy to review & mentor if you need some help). If not, someone will implement this eventually :).

from esp-idf-hal.

usbalbin avatar usbalbin commented on June 18, 2024

Maybe I will give it a try if I get time. Thanks! :)

from esp-idf-hal.

usbalbin avatar usbalbin commented on June 18, 2024

Do you think looking at something like ledc.rs and its correlation to the idf would be a good starting point for how to design the api?

from esp-idf-hal.

MabezDev avatar MabezDev commented on June 18, 2024

Do you think looking at something like ledc.rs and its correlation to the idf would be a good starting point for how to design the api?

Yes! I would definitely spend some time looking at LEDC, and some other peripherals just to get a feel of how to use the esp-idf functions within Rust, then you can start to think about how to safely wrap the MCPWM API in Rust :).

Feel free to join the matrix chat if you want: https://matrix.to/#/#esp-rs:matrix.org

from esp-idf-hal.

usbalbin avatar usbalbin commented on June 18, 2024

Am I missing something or are there no mcpwm related functions such as mcpwm_init in esp_idf_sys?

from esp-idf-hal.

MabezDev avatar MabezDev commented on June 18, 2024

So we don't produce bindings for everything in esp-idf, we have a whitelist in this file, inside esp-idf-sys. What you'll need to do is modify esp-idf-sys to include the mcpwm headers.

// binding.h
#include "driver/mcpwm.h"

Hopefully, that should be fairly simple! Let me know if you run into any issues or need some help :).

from esp-idf-hal.

usbalbin avatar usbalbin commented on June 18, 2024

Thanks a lot. I will try to take a look :)

from esp-idf-hal.

usbalbin avatar usbalbin commented on June 18, 2024

As far as I can see #include "driver/mcpwm.h" is already present in that file (just below the inclusion of driver/ledc.h).

When searching for ledc in the repo I can not find any more places than the file mentioned above (exept for what I believe is the corresponding file for the esp8266) where ledc is mentioned.

from esp-idf-hal.

MabezDev avatar MabezDev commented on June 18, 2024

Did you actually try to use the MCPWM functions in the HAL? I think the docs are built for the esp32c3, which doesn't have the MCPWM peripheral so it won't show up there.

from esp-idf-hal.

usbalbin avatar usbalbin commented on June 18, 2024

Oh, just checked locally and yes esp_idf_sys::mcpwm_init and friends are there.

from esp-idf-hal.

usbalbin avatar usbalbin commented on June 18, 2024

@MabezDev do you think an API that would allow you to write something roughly like this would make sense?

let peripherals = Peripherals::take().unwrap();
let config = OperatorConfig::default().frequency(25.kHz().into());
let mcpwm = Mcpwm::new(peripherals.mcpwm0.mcpwm)?;
let mut operator = Operator::new(
    peripherals.mcpwm0.operator0,
    &mcpwm,
    &config,
    peripherals.pins.gpio4,
    peripherals.pins.gpio5,
)?;

operator.set_duty_a(my_duty_percentage_a)?;
operator.set_duty_b(my_duty_percentage_b)?;

see #93, or do you have any other suggestions :)

from esp-idf-hal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.