From a9a552684baebac7f417c9c23742bbe2feca77e4 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Sun, 29 Oct 2023 12:28:27 -0400 Subject: [PATCH] Quick flipper-zero test app --- Cargo.lock | 86 +++++++++++ Cargo.toml | 1 + flipper-zero/.cargo/config.toml | 23 +++ flipper-zero/.gitignore | 6 + flipper-zero/Cargo.lock | 214 ++++++++++++++++++++++++++ flipper-zero/Cargo.toml | 22 +++ flipper-zero/README.md | 47 ++++++ flipper-zero/rust-toolchain.toml | 3 + flipper-zero/src/main.rs | 30 ++++ flipper-zero/src/rustacean-10x10.icon | Bin 0 -> 21 bytes flipper-zero/src/rustacean-10x10.png | Bin 0 -> 159 bytes rust-toolchain | 2 +- 12 files changed, 433 insertions(+), 1 deletion(-) create mode 100644 flipper-zero/.cargo/config.toml create mode 100644 flipper-zero/.gitignore create mode 100644 flipper-zero/Cargo.lock create mode 100644 flipper-zero/Cargo.toml create mode 100644 flipper-zero/README.md create mode 100644 flipper-zero/rust-toolchain.toml create mode 100644 flipper-zero/src/main.rs create mode 100644 flipper-zero/src/rustacean-10x10.icon create mode 100644 flipper-zero/src/rustacean-10x10.png diff --git a/Cargo.lock b/Cargo.lock index 4d963ce..2560f0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -861,6 +861,56 @@ dependencies = [ "miniz_oxide 0.7.1", ] +[[package]] +name = "flipperzero" +version = "0.11.0" +source = "git+https://github.com/flipperzero-rs/flipperzero.git#2d9ef4a23f4e055ad6489a406d250d61d24b996f" +dependencies = [ + "bitflags 1.3.2", + "digest", + "flipperzero-sys", + "flipperzero-test", + "lock_api", + "rand_core 0.6.4", + "ufmt", +] + +[[package]] +name = "flipperzero-rt" +version = "0.11.0" +source = "git+https://github.com/flipperzero-rs/flipperzero.git#2d9ef4a23f4e055ad6489a406d250d61d24b996f" +dependencies = [ + "flipperzero-sys", +] + +[[package]] +name = "flipperzero-sys" +version = "0.11.0" +source = "git+https://github.com/flipperzero-rs/flipperzero.git#2d9ef4a23f4e055ad6489a406d250d61d24b996f" +dependencies = [ + "ufmt", +] + +[[package]] +name = "flipperzero-test" +version = "0.11.0" +source = "git+https://github.com/flipperzero-rs/flipperzero.git#2d9ef4a23f4e055ad6489a406d250d61d24b996f" +dependencies = [ + "flipperzero-sys", + "flipperzero-test-macros", + "ufmt", +] + +[[package]] +name = "flipperzero-test-macros" +version = "0.11.0" +source = "git+https://github.com/flipperzero-rs/flipperzero.git#2d9ef4a23f4e055ad6489a406d250d61d24b996f" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "fluent" version = "0.16.0" @@ -2266,6 +2316,15 @@ dependencies = [ "version_check 0.9.4", ] +[[package]] +name = "my-project" +version = "0.1.0" +dependencies = [ + "flipperzero", + "flipperzero-rt", + "flipperzero-sys", +] + [[package]] name = "native-tls" version = "0.2.11" @@ -4141,6 +4200,33 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "ufmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a64846ec02b57e9108d6469d98d1648782ad6bb150a95a9baac26900bbeab9d" +dependencies = [ + "ufmt-macros", + "ufmt-write", +] + +[[package]] +name = "ufmt-macros" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d337d3be617449165cb4633c8dece429afd83f84051024079f97ad32a9663716" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ufmt-write" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69" + [[package]] name = "unarray" version = "0.1.4" diff --git a/Cargo.toml b/Cargo.toml index 80b71cc..44483fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ members = [ "dashboard", "emseries", "file-service", + "flipper-zero", "fluent-ergonomics", "geo-types", "gm-control-panel", diff --git a/flipper-zero/.cargo/config.toml b/flipper-zero/.cargo/config.toml new file mode 100644 index 0000000..c44af23 --- /dev/null +++ b/flipper-zero/.cargo/config.toml @@ -0,0 +1,23 @@ +[target.thumbv7em-none-eabihf] +rustflags = [ + # CPU is Cortex-M4 (STM32WB55) + "-C", "target-cpu=cortex-m4", + + # Size optimizations + "-C", "panic=abort", + "-C", "debuginfo=0", + "-C", "opt-level=z", + + # LTO helps reduce binary size + "-C", "embed-bitcode=yes", + "-C", "lto=yes", + + # Linker flags for relocatable binary + "-C", "link-args=--script=flipperzero-rt.ld --Bstatic --relocatable --discard-all --strip-all --lto-O3 --lto-whole-program-visibility", + + # Required to link with `lld` + "-Z", "no-unique-section-names=yes", +] + +[build] +target = "thumbv7em-none-eabihf" diff --git a/flipper-zero/.gitignore b/flipper-zero/.gitignore new file mode 100644 index 0000000..35aab9e --- /dev/null +++ b/flipper-zero/.gitignore @@ -0,0 +1,6 @@ +# Generated by Cargo +# will have compiled files and executables +/target + +# These are backup files generated by rustfmt +**/*.rs.bk diff --git a/flipper-zero/Cargo.lock b/flipper-zero/Cargo.lock new file mode 100644 index 0000000..fb8b0d4 --- /dev/null +++ b/flipper-zero/Cargo.lock @@ -0,0 +1,214 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "flipperzero" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3380d6c3367774a275a79a5e914878828be697bdc099769507cd8757b4b28749" +dependencies = [ + "bitflags", + "digest", + "flipperzero-sys", + "flipperzero-test", + "lock_api", + "rand_core", + "ufmt", +] + +[[package]] +name = "flipperzero-rt" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86417901345f40afd691706c8f34bde52cbe111d6fd517fb28465bd2e3e681f" +dependencies = [ + "flipperzero-sys", +] + +[[package]] +name = "flipperzero-sys" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab88bf1a72204a89320d3ac60a39890a0112443b520cb9bbf560a128c3830acb" +dependencies = [ + "ufmt", +] + +[[package]] +name = "flipperzero-test" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e3cb46bb9aa07d65662c4a3c60717cdedd19a7f4c55e5888ce83c2126786cda" +dependencies = [ + "flipperzero-sys", + "flipperzero-test-macros", + "ufmt", +] + +[[package]] +name = "flipperzero-test-macros" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c93395d56046aa6c1bb8f18b38cb3bc56223e9fd5b5f8e9e885d14f422c9869" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "lock_api" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "proc-macro2" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "hello-rust" +version = "0.1.0" +dependencies = [ + "flipperzero", + "flipperzero-rt", + "flipperzero-sys", +] + +[[package]] +name = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + +[[package]] +name = "ufmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a64846ec02b57e9108d6469d98d1648782ad6bb150a95a9baac26900bbeab9d" +dependencies = [ + "ufmt-macros", + "ufmt-write", +] + +[[package]] +name = "ufmt-macros" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d337d3be617449165cb4633c8dece429afd83f84051024079f97ad32a9663716" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "ufmt-write" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69" + +[[package]] +name = "unicode-ident" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" diff --git a/flipper-zero/Cargo.toml b/flipper-zero/Cargo.toml new file mode 100644 index 0000000..f48a319 --- /dev/null +++ b/flipper-zero/Cargo.toml @@ -0,0 +1,22 @@ +cargo-features = ["different-binary-name"] + +[package] +name = "my-project" +version = "0.1.0" +edition = "2021" +rust-version = "1.64.0" +autobins = false +autoexamples = false +autotests = false +autobenches = false + +[[bin]] +name = "my-project" +filename = "my-project.fap" +bench = false +test = false + +[dependencies] +flipperzero = { git = "https://github.com/flipperzero-rs/flipperzero.git" } +flipperzero-sys = { git = "https://github.com/flipperzero-rs/flipperzero.git" } +flipperzero-rt = { git = "https://github.com/flipperzero-rs/flipperzero.git" } diff --git a/flipper-zero/README.md b/flipper-zero/README.md new file mode 100644 index 0000000..55c9993 --- /dev/null +++ b/flipper-zero/README.md @@ -0,0 +1,47 @@ +# `flipperzero-template`🚀 + +A template for kick-starting a Rust + FlipperZero project using [`flipperzero-rs`](https://github.com/flipperzero-rs/flipperzero) 🐬❤️🦀. + +Currently supports SDK 35.0 ([flipperzero-firmware@0.89.0](https://github.com/flipperdevices/flipperzero-firmware/tree/0.89.0)). + +# Usage + +## Initial setup + +1. Install [`rustup`](https://rust-lang.github.io/rustup/) by following the instructions on [`rustup.rs`](https://rustup.rs/). +1. Install the nightly build tool-chain to support the[`different-binary-name`](https://doc.rust-lang.org/cargo/reference/unstable.html#different-binary-name) feature: + ``` + rustup toolchain install nightly + ``` +1. Install [`cargo-generate`](https://github.com/cargo-generate/cargo-generate): + ``` + cargo install cargo-generate + ``` +1. Use `rustup` to install the `thumbv7em-none-eabihf` target to the nightly build: + ``` + rustup target add --toolchain nightly thumbv7em-none-eabihf + ``` + +## Generate the project +1. Use `cargo generate` to clone this template: + ``` + cargo generate --git https://github.com/flipperzero-rs/flipperzero-template.git --name my-project + ``` +1. Switch into the local directory: + ``` + cd my-project + ``` + +## Build with `cargo build` + +``` +cargo build +``` + +## Copy the binary to your Flipper Zero + +The resulting `.fap` binary can be found in [`target/thumbv7em-none-eabihf/debug`](target/thumbv7em-none-eabihf/debug). + +# License + +This template is licensed under the [MIT License](https://github.com/flipperzero-rs/flipperzero/blob/v0.7.2/LICENSE). diff --git a/flipper-zero/rust-toolchain.toml b/flipper-zero/rust-toolchain.toml new file mode 100644 index 0000000..25056f6 --- /dev/null +++ b/flipper-zero/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "nightly" +targets = [ "thumbv7em-none-eabihf" ] \ No newline at end of file diff --git a/flipper-zero/src/main.rs b/flipper-zero/src/main.rs new file mode 100644 index 0000000..f34ac3b --- /dev/null +++ b/flipper-zero/src/main.rs @@ -0,0 +1,30 @@ +//! Template project for Flipper Zero. +//! This app prints "Hello, Rust!" to the console then exits. + +#![no_main] +#![no_std] + +// Required for panic handler +extern crate flipperzero_rt; + +use flipperzero::println; +use flipperzero_rt::{entry, manifest}; + +// Define the FAP Manifest for this application +manifest!( + name = "Flipper Zero Rust", + app_version = 1, + has_icon = true, + // See https://github.com/flipperzero-rs/flipperzero/blob/v0.7.2/docs/icons.md for icon format + icon = "rustacean-10x10.icon", +); + +// Define the entry function +entry!(main); + +// Entry point +fn main(_args: *mut u8) -> i32 { + println!("Hello, Rust!"); + + 0 +} diff --git a/flipper-zero/src/rustacean-10x10.icon b/flipper-zero/src/rustacean-10x10.icon new file mode 100644 index 0000000000000000000000000000000000000000..206e9d54460bb4fb6681ec3e32be9dcacfed3021 GIT binary patch literal 21 acmZQzU^v6j!eGGgj}Zj_FnBO9FaQ8PGzG!{ literal 0 HcmV?d00001 diff --git a/flipper-zero/src/rustacean-10x10.png b/flipper-zero/src/rustacean-10x10.png new file mode 100644 index 0000000000000000000000000000000000000000..a23b718d723b3bb615dab4a2e0dd1a8756709768 GIT binary patch literal 159 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2xGmzZ=C-xtZVk{1FcVbv~PUa<$!;&U>c zv7h@-A}f&37T^=&`rgU+*Tbi3c{_Q5BAf*tk;M!Qe1}1p@p%4<6riAzr;B5V#O354 y^$ictFt$~*OW4ULWE3