Code up a couple of the example apps for study purposes
This commit is contained in:
parent
a9a552684b
commit
7badd4384c
|
@ -875,6 +875,14 @@ dependencies = [
|
|||
"ufmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flipperzero-alloc"
|
||||
version = "0.11.0"
|
||||
source = "git+https://github.com/flipperzero-rs/flipperzero.git#2d9ef4a23f4e055ad6489a406d250d61d24b996f"
|
||||
dependencies = [
|
||||
"flipperzero-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flipperzero-rt"
|
||||
version = "0.11.0"
|
||||
|
@ -3171,6 +3179,16 @@ dependencies = [
|
|||
"winreg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "resistor-decoder"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"flipperzero",
|
||||
"flipperzero-alloc",
|
||||
"flipperzero-rt",
|
||||
"flipperzero-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "result-extended"
|
||||
version = "0.1.0"
|
||||
|
|
|
@ -18,6 +18,7 @@ members = [
|
|||
"kifu/gtk",
|
||||
"memorycache",
|
||||
"nom-training",
|
||||
"resistor-decoder",
|
||||
"result-extended",
|
||||
"screenplay",
|
||||
"sgf",
|
||||
|
|
|
@ -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"
|
|
@ -0,0 +1,6 @@
|
|||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
|
@ -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"
|
|
@ -0,0 +1,27 @@
|
|||
cargo-features = ["different-binary-name"]
|
||||
|
||||
[package]
|
||||
name = "resistor-decoder"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
rust-version = "1.64.0"
|
||||
autobins = false
|
||||
autoexamples = false
|
||||
autotests = false
|
||||
autobenches = false
|
||||
|
||||
[features]
|
||||
alloc = []
|
||||
|
||||
[[bin]]
|
||||
name = "resistor-decoder"
|
||||
filename = "resistor-decoder.fap"
|
||||
bench = false
|
||||
test = false
|
||||
required-features = ["alloc"]
|
||||
|
||||
[dependencies]
|
||||
flipperzero = { git = "https://github.com/flipperzero-rs/flipperzero.git", features = [ "alloc" ] }
|
||||
flipperzero-sys = { git = "https://github.com/flipperzero-rs/flipperzero.git" }
|
||||
flipperzero-rt = { git = "https://github.com/flipperzero-rs/flipperzero.git" }
|
||||
flipperzero-alloc = { git = "https://github.com/flipperzero-rs/flipperzero.git" }
|
|
@ -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).
|
|
@ -0,0 +1,3 @@
|
|||
[toolchain]
|
||||
channel = "nightly"
|
||||
targets = [ "thumbv7em-none-eabihf" ]
|
|
@ -0,0 +1,102 @@
|
|||
//! 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;
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
extern crate flipperzero_alloc;
|
||||
|
||||
use core::{
|
||||
ffi::{c_char, c_void, CStr},
|
||||
ptr,
|
||||
time::Duration,
|
||||
};
|
||||
use flipperzero::gui::canvas::*;
|
||||
use flipperzero::{dialogs, furi::thread::sleep};
|
||||
use flipperzero_rt::{entry, manifest};
|
||||
use flipperzero_sys as sys;
|
||||
|
||||
// Define the FAP Manifest for this application
|
||||
manifest!(
|
||||
name = "Resistor Decoder",
|
||||
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 {
|
||||
let mut dialog = dialogs::DialogsApp::open();
|
||||
|
||||
let mut message = dialogs::DialogMessage::new();
|
||||
message.set_header(
|
||||
CStr::from_bytes_with_nul(b"Make your move!\0").unwrap(),
|
||||
0,
|
||||
0,
|
||||
Align::Left,
|
||||
Align::Top,
|
||||
);
|
||||
message.set_text(
|
||||
CStr::from_bytes_with_nul(b"Choose one of the following:\0").unwrap(),
|
||||
0,
|
||||
26,
|
||||
Align::Left,
|
||||
Align::Top,
|
||||
);
|
||||
message.set_buttons(
|
||||
Some(CStr::from_bytes_with_nul(b"Rock\0").unwrap()),
|
||||
Some(CStr::from_bytes_with_nul(b"Paper\0").unwrap()),
|
||||
Some(CStr::from_bytes_with_nul(b"Scissors\0").unwrap()),
|
||||
);
|
||||
|
||||
let button = dialog.show_message(&message);
|
||||
|
||||
match button {
|
||||
dialogs::DialogMessageButton::Left => dialogs::alert("You chose Rock..."),
|
||||
dialogs::DialogMessageButton::Center => dialogs::alert("You chose Paper..."),
|
||||
dialogs::DialogMessageButton::Right => dialogs::alert("You chose Scissors..."),
|
||||
dialogs::DialogMessageButton::Back => dialogs::alert("You chose not to play..."),
|
||||
}
|
||||
|
||||
dialogs::alert("... but dolphins can't play rock paper scissors anyways :)");
|
||||
|
||||
0
|
||||
}
|
||||
*/
|
||||
|
||||
const RECORD_GUI: *const c_char = sys::c_string!("gui");
|
||||
const FULLSCREEN: sys::GuiLayer = sys::GuiLayer_GuiLayerFullscreen;
|
||||
|
||||
pub unsafe extern "C" fn draw_callback(canvas: *mut sys::Canvas, _context: *mut c_void) {
|
||||
unsafe {
|
||||
sys::canvas_draw_str(canvas, 39, 31, sys::c_string!("Hello, Rust!"));
|
||||
}
|
||||
}
|
||||
|
||||
fn main(_args: *mut u8) -> i32 {
|
||||
unsafe {
|
||||
let view_port = sys::view_port_alloc();
|
||||
sys::view_port_draw_callback_set(view_port, Some(draw_callback), ptr::null_mut());
|
||||
|
||||
let gui = sys::furi_record_open(RECORD_GUI) as *mut sys::Gui;
|
||||
sys::gui_add_view_port(gui, view_port, FULLSCREEN);
|
||||
|
||||
sleep(Duration::from_secs(1));
|
||||
|
||||
sys::view_port_enabled_set(view_port, false);
|
||||
sys::gui_remove_view_port(gui, view_port);
|
||||
sys::furi_record_close(RECORD_GUI);
|
||||
sys::view_port_free(view_port);
|
||||
}
|
||||
|
||||
0
|
||||
}
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 159 B |
Loading…
Reference in New Issue