{"id":20446275,"url":"https://github.com/rust-embedded/rust-spidev","last_synced_at":"2025-10-20T05:13:35.395Z","repository":{"id":30878489,"uuid":"34436155","full_name":"rust-embedded/rust-spidev","owner":"rust-embedded","description":"Rust library providing access to spidev devices under Linux","archived":false,"fork":false,"pushed_at":"2025-03-04T10:07:15.000Z","size":10729,"stargazers_count":127,"open_issues_count":1,"forks_count":33,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-05-15T10:05:57.852Z","etag":null,"topics":["embedded","linux","rust","spi"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rust-embedded.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-04-23T05:40:20.000Z","updated_at":"2025-05-09T20:49:36.000Z","dependencies_parsed_at":"2022-09-07T17:34:19.284Z","dependency_job_id":"4bf6b2c2-2eb0-4f36-bb2a-fb95f71e497d","html_url":"https://github.com/rust-embedded/rust-spidev","commit_stats":{"total_commits":95,"total_committers":14,"mean_commits":6.785714285714286,"dds":0.4842105263157894,"last_synced_commit":"ec55f00a2363a8fcd321883ca330257a9e85ad2c"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-embedded%2Frust-spidev","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-embedded%2Frust-spidev/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-embedded%2Frust-spidev/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-embedded%2Frust-spidev/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rust-embedded","download_url":"https://codeload.github.com/rust-embedded/rust-spidev/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319720,"owners_count":22051073,"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":["embedded","linux","rust","spi"],"created_at":"2024-11-15T10:18:48.151Z","updated_at":"2025-10-20T05:13:35.299Z","avatar_url":"https://github.com/rust-embedded.png","language":"Rust","readme":"# Rust Spidev\n\n[![Build Status](https://github.com/rust-embedded/rust-spidev/workflows/CI/badge.svg)](https://github.com/rust-embedded/rust-spidev/actions)\n[![Version](https://img.shields.io/crates/v/spidev.svg)](https://crates.io/crates/spidev)\n[![License](https://img.shields.io/crates/l/spidev.svg)](https://github.com/rust-embedded/rust-spidev/blob/master/README.md#license)\n![Minimum Supported Rust Version](https://img.shields.io/badge/rustc-1.69.0+-blue.svg)\n\n[Documentation](https://docs.rs/spidev)\n\nThe Rust `spidev` seeks to provide full access to the Linux spidev\ndevice in Rust without the need to wrap any C code or directly make\nlow-level system calls.  The documentation for the spidev interace can\nbe found at \u003chttps://www.kernel.org/doc/Documentation/spi/spidev\u003e.\n\n## Example/API\n\nThe following is not an exhaustive demonstration of the Spidev\ninterface but provides a pretty good idea of how to use the library in\npractice.\n\n```rust\nextern crate spidev;\nuse std::io;\nuse std::io::prelude::*;\nuse spidev::{Spidev, SpidevOptions, SpidevTransfer, SpiModeFlags};\n\nfn create_spi() -\u003e io::Result\u003cSpidev\u003e {\n    let mut spi = Spidev::open(\"/dev/spidev0.0\")?;\n    let options = SpidevOptions::new()\n         .bits_per_word(8)\n         .max_speed_hz(20_000)\n         .mode(SpiModeFlags::SPI_MODE_0)\n         .build();\n    spi.configure(\u0026options)?;\n    Ok(spi)\n}\n\n/// perform half duplex operations using Read and Write traits\nfn half_duplex(spi: \u0026mut Spidev) -\u003e io::Result\u003c()\u003e {\n    let mut rx_buf = [0_u8; 10];\n    spi.write(\u0026[0x01, 0x02, 0x03])?;\n    spi.read(\u0026mut rx_buf)?;\n    println!(\"{:?}\", rx_buf);\n    Ok(())\n}\n\n/// Perform full duplex operations using Ioctl\nfn full_duplex(spi: \u0026mut Spidev) -\u003e io::Result\u003c()\u003e {\n    // \"write\" transfers are also reads at the same time with\n    // the read having the same length as the write\n    let tx_buf = [0x01, 0x02, 0x03];\n    let mut rx_buf = [0; 3];\n    {\n        let mut transfer = SpidevTransfer::read_write(\u0026tx_buf, \u0026mut rx_buf);\n        spi.transfer(\u0026mut transfer)?;\n    }\n    println!(\"{:?}\", rx_buf);\n    Ok(())\n}\n\nfn main() {\n    let mut spi = create_spi().unwrap();\n    println!(\"{:?}\", half_duplex(\u0026mut spi).unwrap());\n    println!(\"{:?}\", full_duplex(\u0026mut spi).unwrap());\n}\n```\n\n## Features\n\nThe following features are implemented and planned for the library:\n\n- [x] Implement the Read trait\n- [x] Implement the Write trait\n- [x] Support for full-duplex transfers\n- [x] Support for configuring spidev device\n- [x] Support for querying spidev configuration state\n\n## Minimum Supported Rust Version (MSRV)\n\nThis crate is guaranteed to compile on stable Rust 1.69.0 and up.  It *might*\ncompile with older versions but that may change in any new patch release.\n\n## Cross Compiling\n\nMost likely, the machine you are running on is not your development\nmachine (although it could be).  In those cases, you will need to\ncross-compile.  The following basic instructions should work for the\nraspberry pi or beaglebone black:\n\n1. Install rust and cargo\n2. Install an appropriate cross compiler.  On an Ubuntu system, this\n   can be done by doing `sudo apt-get install g++-arm-linux-gnueabihf`.\n3. Build or install rust for your target.  This is necessary in order\n   to have libstd available for your target.  For arm-linux-gnueabihf,\n   you can find binaries at \u003chttps://github.com/japaric/ruststrap\u003e.\n   With this approach or building it yourself, you will need to copy\n   the ${rust}/lib/rustlib/arm-unknown-linux-gnueabihf to your system\n   rust library folder (it is namespaced by triple, so it shouldn't\n   break anything).\n4. Tell cargo how to link by adding the lines below to your\n   ~/.cargo/config file.\n5. Run your build `cargo build --target=arm-unknown-linux-gnueabi`.\n\nThe following snippet added to my ~/.cargo/config worked for me:\n\n```\n[target.arm-unknown-linux-gnueabihf]\nlinker = \"arm-linux-gnueabihf-gcc\"\n```\n\n## License\n\nLicensed under either of\n\n- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or\n  \u003chttp://www.apache.org/licenses/LICENSE-2.0\u003e)\n- MIT license ([LICENSE-MIT](LICENSE-MIT) or \u003chttp://opensource.org/licenses/MIT\u003e)\n\nat your option.\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n\n## Code of Conduct\n\nContribution to this crate is organized under the terms of the [Rust Code of\nConduct][CoC], the maintainer of this crate, the [Embedded Linux Team][team], promises\nto intervene to uphold that code of conduct.\n\n[CoC]: CODE_OF_CONDUCT.md\n[team]: https://github.com/rust-embedded/wg#the-embedded-linux-team\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-embedded%2Frust-spidev","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frust-embedded%2Frust-spidev","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-embedded%2Frust-spidev/lists"}