Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Support crate for Raspberry Pi's PIO architecture.

License

NotificationsYou must be signed in to change notification settings

rp-rs/pio-rs

Repository files navigation

Support for the Raspberry Silicon RP2040'sPIO State Machines.

What is PIO?

Seehttps://www.raspberrypi.com/news/what-is-pio/. You can also read the PIOsection in the (very well written) RP2040 datasheet:https://datasheets.raspberrypi.org/rp2040/rp2040-datasheet.pdf.

What is pio-rs?

PIO programs must be compiled from PIO Assembly Language into a special PIOmachine code. This machine code is then stored in your C or Rust program, andprogram is copied to the PIO hardware at the relevant point in time.

Raspberry Pi provide a PIO assembler called pioasm, and it lives athttps://github.com/raspberrypi/pico-sdk/tree/master/tools/pioasm. This is anexcellent choice if you want use the Raspberry Pi Pico SDK(https://github.com/raspberrypi/pico-sdk) to write C or C++ programs for yourRP2040.

The pio-rs project provides an alternative implementation of pioasm. The mainbenefits are:

  • It's easier to integrate into an Embedded Rust program for the RP2040 thanpioasm
  • It provides apio_asm! macro that can assemble PIO at compile-time.
  • The compiler itself can be included in your Embedded Rust program as a library,so you can compile PIO code on the RP2040, at run-time!
  • Writing an assembler was a good way to test our understanding of thespecification.
  • It's written in Rust :)

How do I use pio-rs?

If you want to write a program in Rust that uses the RP2040's PIO block, thereare three ways to use pio-rs:

pio!

There is a macro calledpio! which allows you to place PIO assembly languagesource into your Rust program. This source code is assembled into a PIO programat compile time.

YourCargo.toml file should include:

[dependencies]pio ="0.2"

Your Rust program should contain your PIO program, as follows with PIO asm directly in the file:

let program_with_defines = pio::pio_asm!("set pindirs, 1",".wrap_target","set pins, 0 [31]","set pins, 1 [31]",".wrap",    options(max_program_size =32)// Optional, defaults to 32);let program = program_with_defines.program;

Or you can assemble a stand-alone PIO file from disk:

let program_with_defines = pio::pio_file!("./tests/test.pio",    select_program("test"),// Optional if only one program in the file    options(max_program_size =32)// Optional, defaults to 32);let program = program_with_defines.program;

The syntax should be the same as supported by the official pioasm tool.

pio::Assembler::new()

You can callpio::Assembler::new() and construct a PIO program usingthe 'builder pattern' - effectively you are compiling a PIO program atrun-time on the RP2040 itself!

// Define some simple PIO program.constMAX_DELAY:u8 =31;letmut assembler = pio::Assembler::<32>::new();letmut wrap_target = assembler.label();letmut wrap_source = assembler.label();// Set pin as Outassembler.set(pio::SetDestination::PINDIRS,1);// Define begin of program loopassembler.bind(&mut wrap_target);// Set pin lowassembler.set_with_delay(pio::SetDestination::PINS,0,MAX_DELAY);// Set pin highassembler.set_with_delay(pio::SetDestination::PINS,1,MAX_DELAY);// Define end of program loopassembler.bind(&mut wrap_source);// The labels wrap_target and wrap_source, as set above,// define a loop which is executed repeatedly by the PIO// state machine.let program = assembler.assemble_with_wrap(wrap_source, wrap_target);

Each line startingassembler. adds a new line to the program. The completedprogram can be passed to the PIO driver in the Rust-languageRP2040HAL.

PIO Examples

This crate is just the PIO assembler. If you want to see some fully-featuredPIO examples integrated with Embedded Rust on the RP2040, check out therp-hal examples.

Roadmap

NOTE This tool is under active development. As such, it is likely to remainvolatile until a 1.0.0 release.

See theopen issues for a list ofproposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place tobe learn, inspire, and create. Any contributions you make aregreatlyappreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. SeeLICENSE for more information.

Contact

Project Link:https://github.com/rp-rs/pio-rs/issuesMatrix:#rp-rs:matrix.org

Acknowledgements

About

Support crate for Raspberry Pi's PIO architecture.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp