mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2025-01-09 15:55:37 +00:00
add change-channel tool
This commit is contained in:
parent
8f5f89d782
commit
09507369af
8 changed files with 81 additions and 7 deletions
8
common/pids/Cargo.toml
Normal file
8
common/pids/Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
authors = ["Jorge Aparicio <jorge.aparicio@ferrous-systems.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
name = "pids"
|
||||||
|
version = "0.0.0"
|
||||||
|
|
||||||
|
[dependencies]
|
4
common/pids/src/lib.rs
Normal file
4
common/pids/src/lib.rs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
pub const LOOPBACK: u16 = 0x0309;
|
||||||
|
pub const PUZZLE: u16 = 0x0310;
|
25
tools/Cargo.lock
generated
25
tools/Cargo.lock
generated
|
@ -122,9 +122,19 @@ version = "0.1.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "change-channel"
|
||||||
|
version = "0.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"consts",
|
||||||
|
"hidapi",
|
||||||
|
"pids",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "consts"
|
name = "consts"
|
||||||
version = "0.1.0"
|
version = "0.0.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crc32fast"
|
name = "crc32fast"
|
||||||
|
@ -158,7 +168,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dk-run"
|
name = "dk-run"
|
||||||
version = "0.1.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"arrayref",
|
"arrayref",
|
||||||
|
@ -174,7 +184,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dongle-flash"
|
name = "dongle-flash"
|
||||||
version = "0.1.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"ihex",
|
"ihex",
|
||||||
|
@ -516,6 +526,10 @@ dependencies = [
|
||||||
"wasmparser",
|
"wasmparser",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pids"
|
||||||
|
version = "0.0.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pkg-config"
|
name = "pkg-config"
|
||||||
version = "0.3.17"
|
version = "0.3.17"
|
||||||
|
@ -768,7 +782,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serial-term"
|
name = "serial-term"
|
||||||
version = "0.1.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"consts",
|
"consts",
|
||||||
|
@ -932,9 +946,10 @@ checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "usb-list"
|
name = "usb-list"
|
||||||
version = "0.1.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"consts",
|
"consts",
|
||||||
|
"pids",
|
||||||
"rusb",
|
"rusb",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
|
"change-channel",
|
||||||
"dk-run",
|
"dk-run",
|
||||||
"dongle-flash",
|
"dongle-flash",
|
||||||
"serial-term",
|
"serial-term",
|
||||||
|
|
12
tools/change-channel/Cargo.toml
Normal file
12
tools/change-channel/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
[package]
|
||||||
|
authors = ["Jorge Aparicio <jorge.aparicio@ferrous-systems.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
name = "change-channel"
|
||||||
|
version = "0.0.0"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
anyhow = "1.0.27"
|
||||||
|
consts = { path = "../../advanced/common/consts" }
|
||||||
|
hidapi = "1.2.2"
|
||||||
|
pids = { path = "../../common/pids" }
|
33
tools/change-channel/src/main.rs
Normal file
33
tools/change-channel/src/main.rs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
use anyhow::{anyhow, bail, ensure};
|
||||||
|
use hidapi::HidApi;
|
||||||
|
|
||||||
|
fn main() -> Result<(), anyhow::Error> {
|
||||||
|
let args = env::args()
|
||||||
|
.skip(1) // skip program name
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
ensure!(!args.is_empty(), "expected exactly one argument");
|
||||||
|
|
||||||
|
let api = HidApi::new()?;
|
||||||
|
let dev = api
|
||||||
|
.device_list()
|
||||||
|
.filter(|dev| dev.vendor_id() == consts::VID && check_pid(dev.product_id()))
|
||||||
|
.next()
|
||||||
|
.ok_or_else(|| anyhow!("device not found"))?
|
||||||
|
.open_device(&api)?;
|
||||||
|
|
||||||
|
let chan = args[0].parse::<u8>()?;
|
||||||
|
if chan < 11 || chan > 26 {
|
||||||
|
bail!("channel is out of range (`11..=26`)")
|
||||||
|
}
|
||||||
|
const REPORT_ID: u8 = 0;
|
||||||
|
dev.write(&[REPORT_ID, chan])?;
|
||||||
|
println!("requested channel change to channel {}", chan);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_pid(pid: u16) -> bool {
|
||||||
|
pid == pids::LOOPBACK || pid == pids::PUZZLE
|
||||||
|
}
|
|
@ -7,4 +7,5 @@ version = "0.0.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
consts = { path = "../../advanced/common/consts" }
|
consts = { path = "../../advanced/common/consts" }
|
||||||
|
pids = { path = "../../common/pids" }
|
||||||
rusb = "0.5.5"
|
rusb = "0.5.5"
|
||||||
|
|
|
@ -6,8 +6,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let suffix = match (desc.vendor_id(), desc.product_id()) {
|
let suffix = match (desc.vendor_id(), desc.product_id()) {
|
||||||
(0x1366, 0x1015) => " <- J-Link on the nRF52840 Development Kit",
|
(0x1366, 0x1015) => " <- J-Link on the nRF52840 Development Kit",
|
||||||
(0x1915, 0x521f) => " <- nRF52840 Dongle (in bootloader mode)",
|
(0x1915, 0x521f) => " <- nRF52840 Dongle (in bootloader mode)",
|
||||||
(0x2020, 0x0309) => " <- nRF52840 Dongle (loopback.hex)",
|
(0x2020, pids::LOOPBACK) => " <- nRF52840 Dongle (loopback.hex)",
|
||||||
(0x2020, 0x0310) => " <- nRF52840 Dongle (puzzle.hex)",
|
(0x2020, pids::PUZZLE) => " <- nRF52840 Dongle (puzzle.hex)",
|
||||||
(consts::VID, consts::PID) => " <- nRF52840 on the nRF52840 Development Kit",
|
(consts::VID, consts::PID) => " <- nRF52840 on the nRF52840 Development Kit",
|
||||||
_ => "",
|
_ => "",
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue