{"id":13631906,"url":"https://github.com/golemparts/rppal","last_synced_at":"2025-04-25T14:48:59.369Z","repository":{"id":38274203,"uuid":"83568737","full_name":"golemparts/rppal","owner":"golemparts","description":"A Rust library that provides access to the Raspberry Pi's GPIO, I2C, PWM, SPI and UART peripherals.","archived":false,"fork":false,"pushed_at":"2024-12-19T17:46:27.000Z","size":1611,"stargazers_count":1362,"open_issues_count":23,"forks_count":102,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-04-24T08:53:34.283Z","etag":null,"topics":["gpio","i2c","pwm","raspberry-pi","raspberrypi","rust","spi","uart"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/golemparts.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["golemparts"]}},"created_at":"2017-03-01T15:16:36.000Z","updated_at":"2025-04-23T20:56:38.000Z","dependencies_parsed_at":"2023-10-04T04:27:28.156Z","dependency_job_id":"8ec6791c-790d-4ce2-a15d-e56fe0daabc1","html_url":"https://github.com/golemparts/rppal","commit_stats":{"total_commits":969,"total_committers":25,"mean_commits":38.76,"dds":0.1341589267285862,"last_synced_commit":"a614532f72642989194e25bfc5ca3073f9bd438b"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemparts%2Frppal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemparts%2Frppal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemparts%2Frppal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemparts%2Frppal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/golemparts","download_url":"https://codeload.github.com/golemparts/rppal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250838269,"owners_count":21495709,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gpio","i2c","pwm","raspberry-pi","raspberrypi","rust","spi","uart"],"created_at":"2024-08-01T22:02:43.578Z","updated_at":"2025-04-25T14:48:59.335Z","avatar_url":"https://github.com/golemparts.png","language":"Rust","funding_links":["https://github.com/sponsors/golemparts"],"categories":["Rust"],"sub_categories":[],"readme":"# RPPAL - Raspberry Pi Peripheral Access Library\n\n[![Build status](https://github.com/golemparts/rppal/actions/workflows/ci.yml/badge.svg)](https://github.com/golemparts/rppal/actions/workflows/ci.yml)\n[![Latest release](https://img.shields.io/crates/v/rppal)](https://crates.io/crates/rppal)\n[![Minimum rustc version](https://img.shields.io/badge/rustc-v1.60.0-lightgray.svg)](https://blog.rust-lang.org/2022/04/07/Rust-1.60.0.html)\n[![Documentation](https://docs.rs/rppal/badge.svg)](https://docs.rs/rppal)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n[![Sponsor](https://img.shields.io/static/v1?label=sponsor\u0026message=golemparts\u0026logo=githubsponsors\u0026color=%23db61a2)](https://github.com/sponsors/golemparts)\n\nRPPAL provides access to the Raspberry Pi's GPIO, I2C, PWM, SPI and UART peripherals through a user-friendly interface. In addition to peripheral access, RPPAL also offers support for USB to serial adapters.\n\nThe library can be used in conjunction with a variety of platform-agnostic drivers through its `embedded-hal` trait implementations. Both `embedded-hal` v0.2.7 and v1 are supported.\n\nRPPAL requires a recent release of Raspberry Pi OS. Similar Linux distributions may work, but are unsupported. Both GNU and musl `libc` targets are supported. RPPAL is compatible with the Raspberry Pi A, A+, B, B+, 2B, 3A+, 3B, 3B+, 4B, 5, CM, CM 3, CM 3+, CM 4, CM 5, CM 5 Lite, 400, 500, Zero, Zero W and Zero 2 W.\n\nThis library is currently in 'maintenance mode'. RPPAL will still receive updates for bugfixes and to add support for new Pi devices. A 1.0 release is planned as well. If you have a feature request you're willing to implement yourself, please open an issue first to discuss the details.\n\nRPPAL is under development on the [master branch](https://github.com/golemparts/rppal/tree/master) of the repository on GitHub. If you're looking for the `README.md` or the `examples` directory for the latest release or any of the earlier releases, visit [crates.io](https://crates.io/crates/rppal), download an archived release from the GitHub [releases](https://github.com/golemparts/rppal/releases) page, or clone and checkout the relevant release tag.\n\n## Table of contents\n\n- [Usage](#usage)\n- [Examples](#examples)\n- [Optional features](#optional-features)\n- [Supported peripherals](#supported-peripherals)\n  - [GPIO](#gpio)\n  - [I2C](#i2c)\n  - [PWM](#pwm)\n  - [SPI](#spi)\n  - [UART](#uart)\n- [Cross compilation](#cross-compilation)\n  - [Cargo](#cargo)\n  - [Visual Studio Code](#visual-studio-code)\n- [Caution](#caution)\n- [Copyright and license](#copyright-and-license)\n\n## Usage\n\nAdd a dependency for `rppal` to your `Cargo.toml` using `cargo add rppal`, or by adding the following line to your dependencies section.\n\n```toml\n[dependencies]\nrppal = \"0.22.1\"\n```\n\nIf your project requires `embedded-hal` trait implementations, specify either the `hal` or `hal-unproven` feature flag in the dependency declaration.\n\n```toml\n[dependencies]\nrppal = { version = \"0.22.1\", features = [\"hal\"] }\n```\n\nCall `new()` on any of the peripherals to construct a new instance.\n\n```rust\nuse rppal::gpio::Gpio;\nuse rppal::i2c::I2c;\nuse rppal::pwm::{Channel, Pwm};\nuse rppal::spi::{Bus, Mode, SlaveSelect, Spi};\nuse rppal::uart::{Parity, Uart};\n\nlet gpio = Gpio::new()?;\nlet i2c = I2c::new()?;\nlet pwm = Pwm::new(Channel::Pwm0)?;\nlet spi = Spi::new(Bus::Spi0, SlaveSelect::Ss0, 16_000_000, Mode::Mode0)?;\nlet uart = Uart::new(115_200, Parity::None, 8, 1)?;\n```\n\nAccess to some peripherals may need to be enabled first through `sudo raspi-config` or by editing `/boot/firmware/config.txt`. Refer to the relevant module's documentation for any required steps.\n\n## Examples\n\nThis example demonstrates how to blink an LED connected to a GPIO pin. Remember to add a resistor of an appropriate value in series, to prevent exceeding the maximum current rating of the GPIO pin and the LED.\n\n```rust\nuse std::error::Error;\nuse std::thread;\nuse std::time::Duration;\n\nuse rppal::gpio::Gpio;\nuse rppal::system::DeviceInfo;\n\n// Gpio uses BCM pin numbering. BCM GPIO 23 is tied to physical pin 16.\nconst GPIO_LED: u8 = 23;\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn Error\u003e\u003e {\n    println!(\"Blinking an LED on a {}.\", DeviceInfo::new()?.model());\n\n    let mut pin = Gpio::new()?.get(GPIO_LED)?.into_output();\n\n    // Blink the LED by setting the pin's logic level high for 500 ms.\n    pin.set_high();\n    thread::sleep(Duration::from_millis(500));\n    pin.set_low();\n\n    Ok(())\n}\n```\n\nAdditional examples can be found in the `examples` directory.\n\n## Optional features\n\nBy default, all optional features are disabled. You can enable a feature by specifying the relevant feature flag(s) in the dependency declaration for `rppal` in your `Cargo.toml`.\n\n* `hal` - Enables `embedded-hal` trait implementations for all supported peripherals. This doesn't include `unproven` traits.\n* `hal-unproven` - Enables `embedded-hal` trait implementations for all supported peripherals, including traits marked as `unproven`. Note that `embedded-hal`'s `unproven` traits don't follow semver rules. Patch releases may introduce breaking changes.\n\n## Supported peripherals\n\n### [GPIO](https://docs.rs/rppal/latest/rppal/gpio)\n\nTo ensure fast performance, RPPAL controls the GPIO peripheral by directly accessing the registers through either `/dev/gpiomem` or `/dev/mem`. GPIO interrupts are configured using the `gpiochip` character device.\n\n#### Features\n\n* Get/set pin mode and logic level\n* Configure built-in pull-up/pull-down resistors\n* Synchronous and asynchronous interrupt handlers\n* Software-based PWM implementation\n* Optional `embedded-hal` trait implementations\n\n### [I2C](https://docs.rs/rppal/latest/rppal/i2c)\n\nThe Broadcom Serial Controller (BSC) peripheral controls a proprietary bus compliant with the I2C bus/interface. RPPAL communicates with the BSC using the `i2cdev` character device.\n\n#### Features\n\n* Single master, 7-bit slave addresses, transfer rates up to 400 kbit/s (Fast-mode)\n* I2C basic read/write, block read/write, combined write+read\n* SMBus protocols: Quick Command, Send/Receive Byte, Read/Write Byte/Word, Process Call, Block Write, PEC\n* Optional `embedded-hal` trait implementations\n\n### [PWM](https://docs.rs/rppal/latest/rppal/pwm)\n\nRPPAL controls the Raspberry Pi's PWM peripheral through the `pwm` sysfs interface.\n\n#### Features\n\n* Up to four hardware PWM channels depending on the Raspberry Pi model\n* Configurable frequency, duty cycle and polarity\n* Optional `embedded-hal` trait implementations\n\n### [SPI](https://docs.rs/rppal/latest/rppal/spi)\n\nRPPAL controls the Raspberry Pi's main and auxiliary SPI peripherals through the `spidev` character device.\n\n#### Features\n\n* SPI master, mode 0-3, Slave Select active-low/active-high, 8 bits per word, configurable clock speed\n* Half-duplex reads, writes, and multi-segment transfers\n* Full-duplex transfers and multi-segment transfers\n* Customizable options for each segment in a multi-segment transfer (clock speed, delay, SS change)\n* Reverse bit order helper function\n* Optional `embedded-hal` trait implementations\n\n### [UART](https://docs.rs/rppal/latest/rppal/uart)\n\nRPPAL controls the Raspberry Pi's UART peripherals through the `ttyAMA0` (PL011) and `ttyS0` (mini UART) character devices. USB to serial adapters are controlled using the `ttyUSBx` and `ttyACMx` character devices.\n\n#### Features\n\n* Support for UART peripherals (PL011, mini UART) and USB to serial adapters\n* None/Even/Odd/Mark/Space parity, 5-8 data bits, 1-2 stop bits\n* Transfer rates up to 4 Mbit/s (device-dependent)\n* XON/XOFF software flow control\n* RTS/CTS hardware flow control with automatic pin configuration\n* Optional `embedded-hal` trait implementations\n\n## Cross compilation\n\nIf you're not working directly on a Raspberry Pi, you'll have to cross-compile your code for the appropriate ARM architecture. Check out [this guide](https://github.com/japaric/rust-cross) for more information, or try the [cross](https://github.com/japaric/cross) project for \"zero setup\" cross compilation.\n\n### Cargo\n\nFor manual cross-compilation without the use of `cross`, you will need to install the appropriate target. Most Raspberry Pi models either need the `armv7-unknown-linux-gnueabihf` target for 32-bit Linux distributions, or `aarch64-unknown-linux-gnu` for 64-bit. For some models, like the Raspberry Pi Zero, a different target triple is required.\n\nInstall the relevant target using `rustup`.\n\n```bash\nrustup target install armv7-unknown-linux-gnueabihf\n```\n\nIn the root directory of your project, create a `.cargo` subdirectory, and save the following snippet to `.cargo/config.toml`.\n\n```toml\n[build]\ntarget = \"armv7-unknown-linux-gnueabihf\"\n```\n\n### Visual Studio Code\n\nThe rust-analyzer extension for Visual Studio Code needs to be made aware of the target platform by setting the `rust-analyzer.cargo.target` configuration option. In the root directory of your project, create a `.vscode` subdirectory, and then save the following snippet to `.vscode/settings.json`.\n\n```json\n{\n    \"rust-analyzer.cargo.target\": \"armv7-unknown-linux-gnueabihf\"\n}\n```\n\n## Caution\n\nAlways be careful when working with the Raspberry Pi's peripherals, especially if you attach any external components to the GPIO pins. Improper use can lead to permanent damage.\n\n## Copyright and license\n\nCopyright (c) 2017-2024 Rene van der Meer. Released under the [MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgolemparts%2Frppal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgolemparts%2Frppal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgolemparts%2Frppal/lists"}