{"id":13685121,"url":"https://github.com/rp-rs/pio-rs","last_synced_at":"2025-05-15T07:03:50.980Z","repository":{"id":38195041,"uuid":"332844085","full_name":"rp-rs/pio-rs","owner":"rp-rs","description":"Support crate for Raspberry Pi's PIO architecture.","archived":false,"fork":false,"pushed_at":"2025-03-03T18:40:48.000Z","size":186,"stargazers_count":164,"open_issues_count":6,"forks_count":25,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-05-15T07:03:44.811Z","etag":null,"topics":["assembler","raspberry-pi-pico","rust"],"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/rp-rs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null}},"created_at":"2021-01-25T18:29:28.000Z","updated_at":"2025-04-18T07:07:33.000Z","dependencies_parsed_at":"2024-06-19T06:15:29.694Z","dependency_job_id":"9cce1baa-7718-4dc6-9c16-fe8674792f0e","html_url":"https://github.com/rp-rs/pio-rs","commit_stats":{"total_commits":67,"total_committers":17,"mean_commits":"3.9411764705882355","dds":0.6567164179104478,"last_synced_commit":"35d92059963fd9124b3af2d895e0c6d2d23ce45e"},"previous_names":["devsnek/pio-rs"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rp-rs%2Fpio-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rp-rs%2Fpio-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rp-rs%2Fpio-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rp-rs%2Fpio-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rp-rs","download_url":"https://codeload.github.com/rp-rs/pio-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254291961,"owners_count":22046424,"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":["assembler","raspberry-pi-pico","rust"],"created_at":"2024-08-02T14:00:44.256Z","updated_at":"2025-05-15T07:03:50.947Z","avatar_url":"https://github.com/rp-rs.png","language":"Rust","funding_links":[],"categories":["资源","Rust"],"sub_categories":["项目"],"readme":"# pio-rs\n\nSupport for the Raspberry Silicon RP2040's *PIO* State Machines.\n\n## What is PIO?\n\nSee https://www.raspberrypi.com/news/what-is-pio/. You can also read the PIO\nsection in the (very well written) RP2040 datasheet:\nhttps://datasheets.raspberrypi.org/rp2040/rp2040-datasheet.pdf.\n\n## What is pio-rs?\n\nPIO programs must be compiled from PIO Assembly Language into a special PIO\nmachine code. This machine code is then stored in your C or Rust program, and\nprogram is copied to the PIO hardware at the relevant point in time.\n\nRaspberry Pi provide a PIO assembler called pioasm, and it lives at\nhttps://github.com/raspberrypi/pico-sdk/tree/master/tools/pioasm. This is an\nexcellent choice if you want use the Raspberry Pi Pico SDK\n(https://github.com/raspberrypi/pico-sdk) to write C or C++ programs for your\nRP2040.\n\nThe pio-rs project provides an alternative implementation of pioasm. The main\nbenefits are:\n\n* It's easier to integrate into an Embedded Rust program for the RP2040 than\n  `pioasm`\n* It provides a `pio_asm!` macro that can assemble PIO at compile-time.\n* The compiler itself can be included in your Embedded Rust program as a library,\n  so you can compile PIO code on the RP2040, at run-time!\n* Writing an assembler was a good way to test our understanding of the\n  specification.\n* It's written in Rust :)\n\n## How do I use pio-rs?\n\nIf you want to write a program in Rust that uses the RP2040's PIO block, there\nare three ways to use pio-rs:\n\n### pio!\n\nThere is a macro called `pio!` which allows you to place PIO assembly language\nsource into your Rust program. This source code is assembled into a PIO program\nat compile time.\n\nYour `Cargo.toml` file should include:\n\n```toml\n[dependencies]\npio = \"0.2\"\n```\n\nYour Rust program should contain your PIO program, as follows with PIO asm directly in the file:\n\n```rust\nlet program_with_defines = pio::pio_asm!(\n    \"set pindirs, 1\",\n    \".wrap_target\",\n    \"set pins, 0 [31]\",\n    \"set pins, 1 [31]\",\n    \".wrap\",\n    options(max_program_size = 32) // Optional, defaults to 32\n);\nlet program = program_with_defines.program;\n```\n\nOr you can assemble a stand-alone PIO file from disk:\n\n```rust\nlet program_with_defines = pio::pio_file!(\n    \"./tests/test.pio\",\n    select_program(\"test\"), // Optional if only one program in the file\n    options(max_program_size = 32) // Optional, defaults to 32\n);\nlet program = program_with_defines.program;\n```\n\nThe syntax should be the same as supported by the official pioasm tool.\n\n### pio::Assembler::new()\n\nYou can call `pio::Assembler::new()` and construct a PIO program using\nthe 'builder pattern' - effectively you are compiling a PIO program at\nrun-time on the RP2040 itself!\n\n```rust\n// Define some simple PIO program.\nconst MAX_DELAY: u8 = 31;\nlet mut assembler = pio::Assembler::\u003c32\u003e::new();\nlet mut wrap_target = assembler.label();\nlet mut wrap_source = assembler.label();\n// Set pin as Out\nassembler.set(pio::SetDestination::PINDIRS, 1);\n// Define begin of program loop\nassembler.bind(\u0026mut wrap_target);\n// Set pin low\nassembler.set_with_delay(pio::SetDestination::PINS, 0, MAX_DELAY);\n// Set pin high\nassembler.set_with_delay(pio::SetDestination::PINS, 1, MAX_DELAY);\n// Define end of program loop\nassembler.bind(\u0026mut wrap_source);\n// The labels wrap_target and wrap_source, as set above,\n// define a loop which is executed repeatedly by the PIO\n// state machine.\nlet program = assembler.assemble_with_wrap(wrap_source, wrap_target);\n```\n\nEach line starting `assembler.` adds a new line to the program. The completed\nprogram can be passed to the PIO driver in the Rust-language [RP2040\nHAL](https://docs.rs/rp2040-hal/).\n\n## PIO Examples\n\nThis crate is just the PIO assembler. If you want to see some fully-featured\nPIO examples integrated with Embedded Rust on the RP2040, check out the\n[rp-hal examples](https://github.com/rp-rs/rp-hal/tree/main/rp2040-hal/examples).\n\n## Roadmap\n\nNOTE This tool is under active development. As such, it is likely to remain\nvolatile until a 1.0.0 release.\n\nSee the [open issues](https://github.com/rp-rs/pio-rs/issues) for a list of\nproposed features (and known issues).\n\n## Contributing\n\nContributions are what make the open source community such an amazing place to\nbe learn, inspire, and create. Any contributions you make are **greatly\nappreciated**.\n\n1. Fork the Project\n2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the Branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n## License\n\nDistributed under the MIT License. See `LICENSE` for more information.\n\n## Contact\n\nProject Link: [https://github.com/rp-rs/pio-rs/issues](https://github.com/rp-rs/pio-rs/issues)\nMatrix: [#rp-rs:matrix.org](https://matrix.to/#/#rp-rs:matrix.org)\n\n## Acknowledgements\n\n* [pioasm](https://github.com/raspberrypi/pico-sdk/tree/master/tools/pioasm)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frp-rs%2Fpio-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frp-rs%2Fpio-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frp-rs%2Fpio-rs/lists"}