{"id":25932520,"url":"https://github.com/secfurry/rpsp","last_synced_at":"2025-03-04T00:38:01.997Z","repository":{"id":279498231,"uuid":"938990578","full_name":"secfurry/rpsp","owner":"secfurry","description":"Simple, small, but extensible platform support package for RP2040 devices","archived":false,"fork":false,"pushed_at":"2025-02-25T21:30:36.000Z","size":91,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T22:24:29.085Z","etag":null,"topics":["embedded","embedded-rust","pico","rp2040","rust","rust-packages"],"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/secfurry.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2025-02-25T20:19:31.000Z","updated_at":"2025-02-25T21:30:40.000Z","dependencies_parsed_at":"2025-02-25T22:35:01.620Z","dependency_job_id":null,"html_url":"https://github.com/secfurry/rpsp","commit_stats":null,"previous_names":["secfurry/rpsp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secfurry%2Frpsp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secfurry%2Frpsp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secfurry%2Frpsp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secfurry%2Frpsp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/secfurry","download_url":"https://codeload.github.com/secfurry/rpsp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241763766,"owners_count":20016161,"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","embedded-rust","pico","rp2040","rust","rust-packages"],"created_at":"2025-03-04T00:38:01.363Z","updated_at":"2025-03-04T00:38:01.931Z","avatar_url":"https://github.com/secfurry.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RPSP\n\nRP2040 Platform Support Package\n\nRust library for easy methods to program and design programs for RP2040 devices.\n\n## Device Selection\n\nTo select the proper pin layout, you must specify the device in the \"features\"\nwhen declaring this crate as a depdency.\n\nExample for the PiPico\n\n```text\nrpsp = { version = \"0.1.0\", features = [ \"pico\" ] }\n```\n\n### Supported Devices\n\nThe following device pinouts are supported:\n\n- Pico / PicoW (`pico`)\n- Tiny2040 (`tiny2040`)\n- Seed Studio 2040 (`xiao2040`)\n\nIf your device has no support, you can still use the `pico` deice, but __BE CAREFUL__\n__OF THE PINS USED__.\n\nI'm open to more devices, I just don't have examples to use ^_^\n\nIf you'd like to contribute, pinouts are generated from layout text files in the\n`boards/data` directory. These are converted into `.rs` files via the `generate.py`\npython script in `boards`. This will write board files into the `src/pin/boards`\ndirectory and updates the `src/pin/boards/lib.rs` with all the tags and modules.\nThe text format is pretty simple, it takes the Pin number and it's capabilities\nfor each line, but I'll make some proper documentation soon.\n\n## Note\n\nYou'll need to make sure you have the `flip-link` linker installed before compiling.\nTo do this, use the command `cargo install flip-link` to install it.\n\n### Additional Cargo Configuration\n\nFor best results, create a `.cargo/config.toml` file in your project root directory\nand specify somthing like this:\n\n```toml\n[target.'cfg(all(target_arch = \"arm\", target_os = \"none\"))']\nrustflags  = [\n    \"-C\", \"linker=flip-link\",\n    \"-C\", \"link-arg=--nmagic\",\n    \"-C\", \"link-arg=-Tlink.x\",\n    \"-Z\", \"trap-unreachable=no\",\n    \"-C\", \"no-vectorize-loops\",\n]\n\n[build]\ntarget    = \"thumbv6m-none-eabi\"\n```\n\nRequires the `nightly` version of the compiler to use `\"-Z\", \"trap-unreachable=no\",`\nand can be removed, but will increase binary size slightly.\n\nExtra bonus points if you add:\n\n```toml\nrunner    = \"probe-rs run --chip RP2040\"\n```\n\nUnder the `rustflags` option. This allows you to flash the firmware on the device\ndirectly from `cargo run`. (Pico debug probe probe and `probe-rs` required. Can be\ninstalled using `cargo install probe-rs-tools`. Pico probe can be made from another\nPico! [see here](https://mcuoneclipse.com/2022/09/17/picoprobe-using-the-raspberry-pi-pico-as-debug-probe/)).\n\nLastly, these are the recommended profile settings for best program results. These\ngo inside the `Cargo.toml` file in the project root directory.\n\n```toml\n[profile.dev]\ndebug            = 2\nstrip            = false\nopt-level        = 3\nincremental      = false\ncodegen-units    = 1\noverflow-checks  = true\ndebug-assertions = true\n\n[profile.release]\nlto              = \"fat\"\npanic            = \"abort\"\ndebug            = false\nstrip            = true\nopt-level        = 3\nincremental      = false\ncodegen-units    = 1\noverflow-checks  = false\ndebug-assertions = false\n```\n\n## Usage\n\nTo use this library, just import `rpsp::Pico` and call `Pico::get()`. On the first\ncall, the device and it's clocks will be initialized and setup fully.\n\nThe configuration is automatic and uses the ROSC as the system clock, disables\nthe XOSC and PLLs and allows for DORMANT sleep, for maximum power savings.\n\nTo supply main, you must setup the `main` function with the `#[rpsp::entry]` macro,\nwhich will setup the locks and properly redirect execution to the selected function.\n\nBasic programs should look something like this:\n\n```rust\n#![no_std]\n#![no_main]\n\n#[rpsp::entry]\nfn main() -\u003e ! {\n    // do stuff here\n}\n```\n\nIf you're not using something like `defmt`, _(which is not included by default)_\nyou'll need a `panic_handler`. The example below is a pretty basic one that just\nloops the CPU:\n\n```rust\n#[panic_handler]\nfn panic(_p: \u0026core::panic::PanicInfo\u003c'_\u003e) -\u003e ! {\n    loop {}\n}\n```\n\nFor the below examples, the `panic_handler` is omitted, so if you want to use\nthese, you'll need to add it in order for it to compile.\n\n### GPIO\n\nControl Pin output:\n\n```rust\nuse rpsp::Pico\nuse rpsp::pin::PinID;\n\n#[rpsp::entry]\nfn main() -\u003e ! {\n    let p = Pico::get();\n    let my_pin = p.pin(PinID::Pin5);\n    // You could also do..\n    // let my_pin = Pin::get(\u0026p, PinID::Pin5);\n\n    // Set High\n    my_pin.high();\n\n    // Set Low\n    my_pin.low();\n\n    // Need this at the end since it's a '!' function.\n    loop {}\n}\n```\n\nRead Pin output:\n\n```rust\nuse rpsp::Pico\nuse rpsp::pin::PinID;\n\n#[rpsp::entry]\nfn main() -\u003e ! {\n    let p = Pico::get();\n    let my_pin = p.pin(PinID::Pin6).into_input();\n\n    // Set High\n    if my_pin.is_high() {\n        // Do stuff..\n    }\n\n    if my_pin.is_low() {\n        // Do other stuff..\n    }\n\n    // Need this at the end since it's a '!' function.\n    loop {}\n}\n```\n\n### UART\n\n```rust\nuse rpsp::Pico\nuse rpsp::pin::PinID;\nuse rpsp::uart::{Uart, UartConfig, UartDev};\n\n#[rpsp::entry]\nfn main() -\u003e ! {\n    let p = Pico::get();\n\n    // DEFAULT_BAUDRATE is 115,200\n    let mut u = Uart::new(\n        \u0026p,\n        UartConfig::DEFAULT_BAUDRATE,\n        UartConfig::new(), // Default is NoParity, 8 Bits, 1 Stop Bit.\n        UartDev::new(PinID::Pin0, PinID::Pin1).unwrap(),\n        // ^ This can error since not all Pinouts are a valid UART set.\n        // You can also use..\n        // (PinID::Pin0, PinID::Pin1).into()\n    ).unwrap();\n\n    let _ = u.write(\"HEY THERE\\n\".as_bytes()).unwrap();\n    // Returns the amount of bytes written.\n\n    let mut buf = [0u8; 32];\n    let n = u.read(\u0026mut buf).unwrap();\n    // Read up to 32 bytes.\n\n    // Echo it back.\n    let _ = u.write(\u0026buf[0:n]).unwrap();\n\n    // Cleanup\n    u.close();\n\n    // Need this at the end since it's a '!' function.\n    loop {}\n}\n```\n\n### Time  and Sleep\n\n```rust\nuse rpsp::Pico\n\n#[rpsp::entry]\nfn main() -\u003e ! {\n    let p = Pico::get();\n\n    for i in 0..25 {\n        p.sleep(5_000); // Wait 5 seconds.\n\n        // Get current RTC time.\n        let now = p.rtc().now().unwrap();\n\n        debug!(\"the time is now {now:?}\");\n    }\n\n    // Need this at the end since it's a '!' function.\n    loop {}\n}\n```\n\n### Watchdog\n\n```rust\nuse rpsp::Pico\n\n#[rpsp::entry]\nfn main() -\u003e ! {\n    let p = Pico::get();\n    let dog = p.watchdog();\n\n    dog.start(5_000); // Die if we don't feed the dog every 5 seconds.\n\n    for _ in 0..10 {\n        p.sleep(2_500); // ait 2.5 seconds.\n\n        dog.feed(); // Feed da dog.\n    }\n\n    p.sleep(10_000); // Device will restart during here.\n\n    // Need this at the end since it's a '!' function.\n    loop {}\n}\n```\n\nTheres alot of more examples I need to add..\n\n## TODO\n\n- CYW Driver\n  - Networking??\n- Document Board layout format\n\nLicense for the CYW driver is [here](src/cyw/firmware/LICENSE-permissive-binary-license-1.0.txt)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecfurry%2Frpsp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsecfurry%2Frpsp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecfurry%2Frpsp/lists"}