#pwm #interface #sysfs #pin #linux #period #access

sysfs-pwm

Provides access to the Linux sysfs interfaces to PWMs. Via this crate you can export, unexport, and control PWM pins for which there is an appropriate driver loaded in the kernel. See https://www.kernel.org/doc/Documentation/pwm.txt

1 unstable release

Uses old Rust 2015

0.1.0 Dec 16, 2016

#741 in Unix APIs

Download history 162/week @ 2023-11-25 96/week @ 2023-12-02 96/week @ 2023-12-09 125/week @ 2023-12-16 47/week @ 2023-12-23 112/week @ 2023-12-30 208/week @ 2024-01-06 169/week @ 2024-01-13 109/week @ 2024-01-20 155/week @ 2024-01-27 43/week @ 2024-02-03 146/week @ 2024-02-10 108/week @ 2024-02-17 111/week @ 2024-02-24 136/week @ 2024-03-02 36/week @ 2024-03-09

424 downloads per month

MIT/Apache

11KB
167 lines

rust-sysfs-pwm

Build Status 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.1.0"

Then, add this to your crate root:

extern crate sysfs_pwm;

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

Copyright (c) 2016, Paul Osborne <ospbau@gmail.com>

Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
http://www.apache.org/license/LICENSE-2.0> or the MIT license
<LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
option.  This file may not be copied, modified, or distributed
except according to those terms.

No runtime deps