Skip to content

Commit 0705187

Browse files
Adds new input test sample program.
1 parent c0954dd commit 0705187

File tree

6 files changed

+97
-3
lines changed

6 files changed

+97
-3
lines changed

samples/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ Build the application as follows:
88

99
```console
1010
$ cargo build --release --target=thumbv6m-none-eabi
11-
$ rust-objcopy -O binary ./target/thumbv6m-none-eabi/release/hello hello.bin
11+
$ cp ./target/thumbv6m-none-eabi/release/hello /my/sdcard/hello.elf
1212
```
1313

14-
Then copy the resulting `hello.bin` file to an SD card and insert it into your Neotron system. You can load the application with something like:
14+
Then copy the resulting `hello.elf` file to an SD card and insert it into your Neotron system. You can load the application with something like:
1515

1616
```text
17-
> load hello.bin
17+
> load hello.elf
1818
> run
1919
```
2020

@@ -30,6 +30,10 @@ $ rustup component add llvm-tools
3030

3131
This is a basic "Hello World" application. It prints the string "Hello, world" to *standard output* and then exits with an exit code of 0.
3232

33+
## [`input-test`](./input-test)
34+
35+
This reports any bytes received on Standard Input. Press Ctrl-X to quit.
36+
3337
## [`panic`](./panic)
3438

3539
This application panics, printing a nice panic message.

samples/input_test/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

samples/input_test/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "input-test"
3+
version = "0.1.0"
4+
edition = "2021"
5+
license = "MIT OR Apache-2.0"
6+
authors = ["Jonathan 'theJPster' Pallant <[email protected]>"]
7+
description = "Hello World for Neotron systems"
8+
9+
[dependencies]
10+
neotron-sdk = { path = "../.." }
11+
12+
[profile.dev]
13+
panic = "abort"
14+
15+
[profile.release]
16+
panic = "unwind"
17+
opt-level = "z"
18+
lto = "fat"

samples/input_test/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Hello, World!
2+
3+
A basic standard input test application for Neotron systems.
4+
5+
See the general sample application [README](../README.md) for compilation instructions.
6+
7+
## Licence
8+
9+
Copyright (c) The Neotron Developers, 2023
10+
11+
Licensed under either [MIT](../../LICENSE-MIT) or [Apache-2.0](../../LICENSE-APACHE) at
12+
your option.
13+
14+
## Contribution
15+
16+
Unless you explicitly state otherwise, any contribution intentionally submitted
17+
for inclusion in the work by you shall be licensed as above, without any
18+
additional terms or conditions.

samples/input_test/build.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use std::env;
2+
use std::fs::File;
3+
use std::io::Write;
4+
use std::path::PathBuf;
5+
6+
fn main() {
7+
// Put `neotron-cortex-m.ld` in our output directory and ensure it's
8+
// on the linker search path.
9+
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
10+
File::create(out.join("neotron-cortex-m.ld"))
11+
.unwrap()
12+
.write_all(include_bytes!("../neotron-cortex-m.ld"))
13+
.unwrap();
14+
println!("cargo:rustc-link-search={}", out.display());
15+
16+
// By default, Cargo will re-run a build script whenever
17+
// any file in the project changes. By specifying `neotron-cortex-m.ld`
18+
// here, we ensure the build script is only re-run when
19+
// `neotron-cortex-m.ld` is changed.
20+
println!("cargo:rerun-if-changed=../neotron-cortex-m.ld");
21+
}

samples/input_test/src/main.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#![no_std]
2+
#![no_main]
3+
4+
extern crate neotron_sdk;
5+
6+
use core::fmt::Write;
7+
8+
#[no_mangle]
9+
extern "C" fn neotron_main() -> i32 {
10+
let mut stdout = neotron_sdk::stdout();
11+
let stdin = neotron_sdk::stdin();
12+
let _ = stdout.write(b"Type some things, press Ctrl-X to quit...\n");
13+
loop {
14+
let mut buffer = [0u8; 16];
15+
match stdin.read(&mut buffer) {
16+
Err(_) => {
17+
return 1;
18+
}
19+
Ok(0) => {
20+
// Do nothing
21+
}
22+
Ok(n) => {
23+
for b in &buffer[0..n] {
24+
let _ = writeln!(stdout, "0x{:02x}", b);
25+
if *b == 0x18 {
26+
return 0;
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)