Git Product home page Git Product logo

rust-sysfs-pwm's Introduction

sysfs-pwm

Build Status Version Minimum Supported Rust Version License

rust-sysfs-pwm is a rust library/crate providing access to the Linux sysfs PWM interface. It seeks to provide an API that is safe, convenient, and efficient.

Install/Use

To use sysfs-pwm, first add this to your Cargo.toml:

[dependencies]
# or latest version
sysfs-pwm = "0.2.0"

Then, add this to your crate root:

use sysfs_pwm;

MSRV (Minimum Supported Rust Version)

This crate is guaranteed to compile on stable Rust 1.28.0 and up. It might compile with older versions but that may change in any new patch release.

Example/API

The main API consists of a Pwm struct with the following methods:

  • Pwm::new - Create a Pwm instance
  • pwm.with_exported - Execute a block with the Pwm exported
  • pwm.set_active - Enable/Disable the Pwm
  • pwm.get_duty_cycle - Get duty cycle as percentage of period
  • pwm.set_duty_cycle - Set duty cycle as percentage of period
  • pwm.get_duty_cycle_ns - Get duty cycle in nanoseconds
  • pwm.set_duty_cycle_ns - Set duty cyle in nanoseconds
  • pwm.get_period_ns - Get the Pwm period in nanoseconds
  • pwm.set_period_ns - Set the Pwm period in nanoseconds

Check out the Breathing LED example for a usage example.

Cross Compiling

Most likely, the machine you are running on is not your development machine (although it could be). In those cases, you will need to cross-compile. The instructions here provide great details on cross compiling for your platform.

Running the Example

Cross-compiling can be done by specifying an appropriate target. You can then move that to your device by whatever means and run it.

$ cargo build --target=arm-unknown-linux-gnueabihf --example breathe
$ scp target/arm-unknown-linux-gnueabihf/debug/examples/breathe ...

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Code of Conduct

Contribution to this crate is organized under the terms of the Rust Code of Conduct, the maintainer of this crate, the Embedded Linux Team, promises to intervene to uphold that code of conduct.

rust-sysfs-pwm's People

Contributors

andful avatar bors[bot] avatar contradict avatar ekmecic avatar eldruin avatar kofron avatar leseulartichaut avatar lucavuitton avatar posborne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rust-sysfs-pwm's Issues

Crate panic on Beaglebone green (seed)

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })', src/libcore/result.rs:999:5
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:47
   3: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:36
   4: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:200
   5: std::panicking::default_hook
             at src/libstd/panicking.rs:214
   6: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:477
   7: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:384
   8: rust_begin_unwind
             at src/libstd/panicking.rs:311
   9: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  10: core::result::unwrap_failed
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b/src/libcore/macros.rs:18
  11: core::result::Result<T,E>::unwrap
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b/src/libcore/result.rs:800
  12: cucaracha::pwmled::PwmLed::new
             at src/pwmled.rs:40
  13: cucaracha::main
             at src/main.rs:22
  14: std::rt::lang_start::{{closure}}
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b/src/libstd/rt.rs:64
  15: std::rt::lang_start_internal::{{closure}}
             at src/libstd/rt.rs:49
  16: std::panicking::try::do_call
             at src/libstd/panicking.rs:296
  17: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:82
  18: std::panicking::try
             at src/libstd/panicking.rs:275
  19: std::panic::catch_unwind
             at src/libstd/panic.rs:394
  20: std::rt::lang_start_internal
             at src/libstd/rt.rs:48
  21: std::rt::lang_start
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b/src/libstd/rt.rs:64
  22: main
  23: __libc_start_main

because the crate is trying to get /sys/class/pwm/pwmchip{}/pwm{}/{} where on my beaglebone it's /sys/class/pwm/pwmchip4/pwm-4\:0/

The line in my code causing this is pwm.enable(true).unwrap();

rust-sysfs-pwm is not on cargo

Hello @posborne I noticed this package was not on crates.io.

What is the path forward for that, if there is one? Currently I am using cargo's ability to install packages using git urls, but I think this would be useful to more people eventually.

Clean up CI targets

Currently some CI targets fail because they are not available on Rust stable anymore.
See here

Can't make example to work

Hi!
I'm probably missing something very fundamental here, but I can't make the example work. It compiles and runs, however nothing happens to the LED connected to P9.22 on my beaglebone black.

I also couldn't figure out the pin to chip mappings, but shame on me for that. I tried all pwm capable pins with pretty much all number combinations but still none worked.

Could you point me to the right directions on what should I look for?

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.