mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
shell/democommands: Add example Rust module
This commit is contained in:
parent
841e4deee5
commit
ebfa6f61d6
@ -13,6 +13,9 @@ CARGO_COMPILE_COMMANDS_FLAGS = --clang
|
||||
ifneq (,$(filter lsm303agr,$(USEMODULE)))
|
||||
CARGO_OPTIONS += --features rust_riotmodules/riot-module-lsm303agr
|
||||
endif
|
||||
ifneq (,$(filter shell_democommands,$(USEMODULE)))
|
||||
CARGO_OPTIONS += --features rust_riotmodules/riot-module-shell-democommands
|
||||
endif
|
||||
|
||||
# This is duplicating the compile-commands rule because unlike in the use case
|
||||
# when a $(RIOTBASE)/compile_commands.json is built, we *want* this to be
|
||||
|
@ -338,6 +338,11 @@ ifneq (,$(filter shell_commands,$(USEMODULE)))
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq (,$(filter shell_democommands,$(USEMODULE)))
|
||||
USEMODULE += rust_riotmodules
|
||||
USEMODULE += shell
|
||||
endif
|
||||
|
||||
ifneq (,$(filter md5sum sha1sum sha256sum,$(USEMODULE)))
|
||||
USEMODULE += vfs_util
|
||||
USEMODULE += hashes
|
||||
|
@ -160,6 +160,8 @@ ifneq (,$(filter shell_lock,$(USEMODULE)))
|
||||
include $(RIOTBASE)/sys/shell_lock/Makefile.include
|
||||
endif
|
||||
|
||||
PSEUDOMODULES += shell_democommands
|
||||
|
||||
ifneq (,$(filter rust_riotmodules,$(USEMODULE)))
|
||||
include $(RIOTBASE)/sys/rust_riotmodules/Makefile.include
|
||||
endif
|
||||
|
@ -11,3 +11,4 @@ publish = false
|
||||
# autogenerated (or at least automatically checked for consistency).
|
||||
|
||||
riot-module-lsm303agr = { path = "../../drivers/lsm303agr", optional = true }
|
||||
riot-module-shell-democommands = { path = "../../sys/shell/democommands", optional = true }
|
||||
|
@ -8,3 +8,6 @@
|
||||
|
||||
#[cfg(feature = "riot-module-lsm303agr")]
|
||||
extern crate riot_module_lsm303agr;
|
||||
|
||||
#[cfg(feature = "riot-module-shell-democommands")]
|
||||
extern crate riot_module_shell_democommands;
|
||||
|
14
sys/shell/democommands/Cargo.toml
Normal file
14
sys/shell/democommands/Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "riot-module-shell-democommands"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
authors = ["Christian Amsüss <chrysn@fsfe.org>"]
|
||||
license = "LGPL-2.1-only"
|
||||
|
||||
# Shipped with RIOT-OS; this has no external API that would make
|
||||
# sense to consume in any context than from within RIOT
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
riot-wrappers = "^0.7.17"
|
17
sys/shell/democommands/src/lib.rs
Normal file
17
sys/shell/democommands/src/lib.rs
Normal file
@ -0,0 +1,17 @@
|
||||
#![no_std]
|
||||
|
||||
use riot_wrappers::println;
|
||||
use core::fmt::Write;
|
||||
|
||||
riot_wrappers::static_command!(static_hello_world, "hello_world", "Print a greeting", hello_world);
|
||||
|
||||
pub fn hello_world<'a>(_w: &mut impl Write, args: impl IntoIterator<Item=&'a str>) {
|
||||
let mut args = args.into_iter();
|
||||
let commandname = args.next().expect("How was this started without an argv[0]?");
|
||||
|
||||
match args.next() {
|
||||
Some("--help") => println!("Usage: {commandname}"),
|
||||
None => println!("Hello RIOT!"),
|
||||
_ => println!("Invalid argument."),
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user