Add basic usb serial shell

This commit is contained in:
2021-01-25 22:36:11 +01:00
parent 8e00a9b341
commit ecd2d92b52
12 changed files with 777 additions and 192 deletions

379
Cargo.lock generated
View File

@ -4,365 +4,478 @@
name = "aligned" name = "aligned"
version = "0.3.2" version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb1ce8b3382016136ab1d31a1b5ce807144f8b7eb2d5f16b2108f0f07edceb94"
dependencies = [ dependencies = [
"as-slice 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "as-slice",
]
[[package]]
name = "apa102-spi"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d92cd690fd2aae5bc549e2dc392d9082aab3ccf851aa39b0ab84b2934f4c57a3"
dependencies = [
"embedded-hal",
"smart-leds-trait",
] ]
[[package]] [[package]]
name = "as-slice" name = "as-slice"
version = "0.1.3" version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37dfb65bc03b2bc85ee827004f14a6817e04160e3b1a28931986a666a9290e70"
dependencies = [ dependencies = [
"generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", "generic-array 0.12.3",
"generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", "generic-array 0.13.2",
"stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "stable_deref_trait",
] ]
[[package]] [[package]]
name = "atsamd-hal" name = "atsamd-hal"
version = "0.8.2" version = "0.12.0"
source = "git+https://github.com/atsamd-rs/atsamd#b7619155806fd853887e07fe271d7c1b0cf424a0" source = "git+https://github.com/atsamd-rs/atsamd#8e507a7b76c441d87d302b107c6b06485e9b6478"
dependencies = [ dependencies = [
"atsamd21g18a 0.6.0 (git+https://github.com/atsamd-rs/atsamd)", "atsamd21g",
"bitfield 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", "bitfield",
"cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "cortex-m",
"embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-hal",
"nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "nb",
"paste 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "paste",
"rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core",
"vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "usb-device",
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "vcell",
"void",
] ]
[[package]] [[package]]
name = "atsamd21g18a" name = "atsamd21g"
version = "0.6.0" version = "0.9.0"
source = "git+https://github.com/atsamd-rs/atsamd#b7619155806fd853887e07fe271d7c1b0cf424a0" source = "git+https://github.com/atsamd-rs/atsamd#8e507a7b76c441d87d302b107c6b06485e9b6478"
dependencies = [ dependencies = [
"bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "bare-metal",
"cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "cortex-m",
"cortex-m-rt 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "cortex-m-rt",
"vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "vcell",
] ]
[[package]] [[package]]
name = "bare-metal" name = "bare-metal"
version = "0.2.5" version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3"
dependencies = [ dependencies = [
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version",
]
[[package]]
name = "bitbang-hal"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "470e1522d257e4c76245980d27d5d279442cb18955cc6341249b904074033f4a"
dependencies = [
"embedded-hal",
"nb",
] ]
[[package]] [[package]]
name = "bitfield" name = "bitfield"
version = "0.13.2" version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719"
[[package]]
name = "bytemuck"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a4bad0c5981acc24bc09e532f35160f952e35422603f0563cd7a73c2c2e65a0"
[[package]]
name = "byteorder"
version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
[[package]] [[package]]
name = "cortex-m" name = "cortex-m"
version = "0.6.2" version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2954942fbbdd49996704e6f048ce57567c3e1a4e2dc59b41ae9fde06a01fc763"
dependencies = [ dependencies = [
"aligned 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "aligned",
"bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "bare-metal",
"volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "volatile-register",
] ]
[[package]] [[package]]
name = "cortex-m-rt" name = "cortex-m-rt"
version = "0.6.12" version = "0.6.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00d518da72bba39496024b62607c1d8e37bcece44b2536664f1132a73a499a28"
dependencies = [ dependencies = [
"cortex-m-rt-macros 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "cortex-m-rt-macros",
"r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "r0",
] ]
[[package]] [[package]]
name = "cortex-m-rt-macros" name = "cortex-m-rt-macros"
version = "0.1.8" version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4717562afbba06e760d34451919f5c3bf3ac15c7bb897e8b04862a7428378647"
dependencies = [ dependencies = [
"proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2",
"quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "quote",
"syn 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)", "syn",
] ]
[[package]] [[package]]
name = "embedded-graphics" name = "embedded-graphics"
version = "0.4.9" version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2e7ee289ac88cbeea6f749cd72c6eb4cdeb801f4ea26795aace97b9776a2db2"
dependencies = [ dependencies = [
"tinybmp 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tinybmp",
"tinytga 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tinytga",
] ]
[[package]] [[package]]
name = "embedded-hal" name = "embedded-hal"
version = "0.2.3" version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee4908a155094da7723c2d60d617b820061e3b4efcc3d9e293d206a5a76c170b"
dependencies = [ dependencies = [
"nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "nb",
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "void",
] ]
[[package]]
name = "encode_unicode"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]] [[package]]
name = "generic-array" name = "generic-array"
version = "0.12.3" version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec"
dependencies = [ dependencies = [
"typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "typenum",
] ]
[[package]] [[package]]
name = "generic-array" name = "generic-array"
version = "0.13.2" version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ed1e761351b56f54eb9dcd0cfaca9fd0daecf93918e1cfc01c8a3d26ee7adcd"
dependencies = [ dependencies = [
"typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "typenum",
] ]
[[package]] [[package]]
name = "itsybitsy_m0" name = "itsybitsy_m0"
version = "0.7.0" version = "0.10.0"
source = "git+https://github.com/atsamd-rs/atsamd#b7619155806fd853887e07fe271d7c1b0cf424a0" source = "git+https://github.com/atsamd-rs/atsamd#8e507a7b76c441d87d302b107c6b06485e9b6478"
dependencies = [ dependencies = [
"atsamd-hal 0.8.2 (git+https://github.com/atsamd-rs/atsamd)", "apa102-spi",
"cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "atsamd-hal",
"cortex-m-rt 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "bitbang-hal",
"embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "cortex-m",
"nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "cortex-m-rt",
"embedded-hal",
"nb",
"smart-leds",
"usb-device",
"usbd-hid",
"usbd-serial",
] ]
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.3.3" version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
[[package]] [[package]]
name = "nb" name = "nb"
version = "0.1.2" version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc"
[[package]] [[package]]
name = "neowatch" name = "neowatch"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"atsamd-hal 0.8.2 (git+https://github.com/atsamd-rs/atsamd)", "atsamd-hal",
"cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "cortex-m",
"cortex-m-rt 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "cortex-m-rt",
"embedded-graphics 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-graphics",
"embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-hal",
"itsybitsy_m0 0.7.0 (git+https://github.com/atsamd-rs/atsamd)", "itsybitsy_m0",
"nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "nb",
"ssd1351 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "ssd1351",
"usb-device",
"usbd-serial",
] ]
[[package]] [[package]]
name = "nom" name = "nom"
version = "4.2.3" version = "4.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6"
dependencies = [ dependencies = [
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "memchr",
"version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "version_check 0.1.5",
] ]
[[package]] [[package]]
name = "nom" name = "nom"
version = "5.1.1" version = "5.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b471253da97532da4b61552249c521e01e736071f71c1a4f7ebbfbf0a06aad6"
dependencies = [ dependencies = [
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "memchr",
"version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "version_check 0.9.1",
] ]
[[package]] [[package]]
name = "paste" name = "paste"
version = "0.1.10" version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"paste-impl 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro-hack 0.5.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "paste-impl"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro-hack 0.5.15 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "proc-macro-hack"
version = "0.5.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5d65c4d95931acda4498f675e332fcbdc9a06705cd07086c510e9b6009cd1c1"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.10" version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3"
dependencies = [ dependencies = [
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid",
] ]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.3" version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f"
dependencies = [ dependencies = [
"proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2",
] ]
[[package]] [[package]]
name = "r0" name = "r0"
version = "0.2.2" version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f"
[[package]] [[package]]
name = "rand_core" name = "rand_core"
version = "0.5.1" version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
[[package]]
name = "rgb"
version = "0.8.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "287f3c3f8236abb92d8b7e36797f19159df4b58f0a658cc3fb6dd3004b1f3bd3"
dependencies = [
"bytemuck",
]
[[package]] [[package]]
name = "rustc_version" name = "rustc_version"
version = "0.2.3" version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [ dependencies = [
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "semver",
] ]
[[package]] [[package]]
name = "semver" name = "semver"
version = "0.9.0" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [ dependencies = [
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "semver-parser",
] ]
[[package]] [[package]]
name = "semver-parser" name = "semver-parser"
version = "0.7.0" version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "1.0.122"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "974ef1bd2ad8a507599b336595454081ff68a9599b4890af7643c0c0ed73a62c"
[[package]]
name = "smart-leds"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38dd45fa275f70b4110eac5f5182611ad384f88bb22b68b9a9c3cafd7015290b"
dependencies = [
"smart-leds-trait",
]
[[package]]
name = "smart-leds-trait"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebf6d833fa93f16a1c1874e62c2aebe8567e5bdd436d59bf543ed258b6f7a8e3"
dependencies = [
"rgb",
]
[[package]] [[package]]
name = "ssd1351" name = "ssd1351"
version = "0.2.2" version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"embedded-graphics 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-graphics",
"embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-hal",
]
[[package]]
name = "ssmarshal"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3e6ad23b128192ed337dfa4f1b8099ced0c2bf30d61e551b65fda5916dbb850"
dependencies = [
"encode_unicode",
"serde",
] ]
[[package]] [[package]]
name = "stable_deref_trait" name = "stable_deref_trait"
version = "1.1.1" version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.17" version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03"
dependencies = [ dependencies = [
"proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2",
"quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "quote",
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid",
] ]
[[package]] [[package]]
name = "tinybmp" name = "tinybmp"
version = "0.1.1" version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30d12b7f8b271567d6d072c49dee16b22271aabfc473e2066e3353e5af0f5230"
dependencies = [ dependencies = [
"nom 5.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "nom 5.1.1",
] ]
[[package]] [[package]]
name = "tinytga" name = "tinytga"
version = "0.1.0" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc9485052c1f4b541d888f1d564dd9957671e0c21da9bca0c9824c1123e03f07"
dependencies = [ dependencies = [
"nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "nom 4.2.3",
] ]
[[package]] [[package]]
name = "typenum" name = "typenum"
version = "1.12.0" version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.2.0" version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
[[package]]
name = "usb-device"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "849eed9b4dc61a1f17ba1d7a5078ceb095b9410caa38a506eb281ed5eff12fbd"
[[package]]
name = "usbd-hid"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3404cbb66a4d6a092d8e88c3e62dcc6f339536e2cf66dfedad342eb0013c7cd"
dependencies = [
"serde",
"ssmarshal",
"usb-device",
"usbd-hid-macros",
]
[[package]]
name = "usbd-hid-descriptors"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e00430c0b39caf3957aba6c2b2824f8e70e1ac0278941418bf1fe35f9566d64"
dependencies = [
"bitfield",
]
[[package]]
name = "usbd-hid-macros"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "673a04e28e2949d0b8d3307996a37330a297d863b6ec1e8904552ca2051c1a7e"
dependencies = [
"byteorder",
"proc-macro2",
"quote",
"serde",
"syn",
"usbd-hid-descriptors",
]
[[package]]
name = "usbd-serial"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db75519b86287f12dcf0d171c7cf4ecc839149fe9f3b720ac4cfce52959e1dfe"
dependencies = [
"embedded-hal",
"nb",
"usb-device",
]
[[package]] [[package]]
name = "vcell" name = "vcell"
version = "0.1.2" version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "876e32dcadfe563a4289e994f7cb391197f362b6315dc45e8ba4aa6f564a4b3c"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.1.5" version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.1" version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce"
[[package]] [[package]]
name = "void" name = "void"
version = "1.0.2" version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
[[package]] [[package]]
name = "volatile-register" name = "volatile-register"
version = "0.2.0" version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d67cb4616d99b940db1d6bd28844ff97108b498a6ca850e5b6191a532063286"
dependencies = [ dependencies = [
"vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "vcell",
] ]
[metadata]
"checksum aligned 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eb1ce8b3382016136ab1d31a1b5ce807144f8b7eb2d5f16b2108f0f07edceb94"
"checksum as-slice 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "37dfb65bc03b2bc85ee827004f14a6817e04160e3b1a28931986a666a9290e70"
"checksum atsamd-hal 0.8.2 (git+https://github.com/atsamd-rs/atsamd)" = "<none>"
"checksum atsamd21g18a 0.6.0 (git+https://github.com/atsamd-rs/atsamd)" = "<none>"
"checksum bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3"
"checksum bitfield 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719"
"checksum cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2954942fbbdd49996704e6f048ce57567c3e1a4e2dc59b41ae9fde06a01fc763"
"checksum cortex-m-rt 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "00d518da72bba39496024b62607c1d8e37bcece44b2536664f1132a73a499a28"
"checksum cortex-m-rt-macros 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "4717562afbba06e760d34451919f5c3bf3ac15c7bb897e8b04862a7428378647"
"checksum embedded-graphics 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b2e7ee289ac88cbeea6f749cd72c6eb4cdeb801f4ea26795aace97b9776a2db2"
"checksum embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ee4908a155094da7723c2d60d617b820061e3b4efcc3d9e293d206a5a76c170b"
"checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec"
"checksum generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0ed1e761351b56f54eb9dcd0cfaca9fd0daecf93918e1cfc01c8a3d26ee7adcd"
"checksum itsybitsy_m0 0.7.0 (git+https://github.com/atsamd-rs/atsamd)" = "<none>"
"checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
"checksum nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc"
"checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6"
"checksum nom 5.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b471253da97532da4b61552249c521e01e736071f71c1a4f7ebbfbf0a06aad6"
"checksum paste 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab4fb1930692d1b6a9cfabdde3d06ea0a7d186518e2f4d67660d8970e2fa647a"
"checksum paste-impl 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "a62486e111e571b1e93b710b61e8f493c0013be39629b714cb166bdb06aa5a8a"
"checksum proc-macro-hack 0.5.15 (registry+https://github.com/rust-lang/crates.io-index)" = "0d659fe7c6d27f25e9d80a1a094c223f5246f6a6596453e09d7229bf42750b63"
"checksum proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)" = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3"
"checksum quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f"
"checksum r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f"
"checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum ssd1351 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c80bbad15958832bc5cbddd1b2b63157165fed1f90f22c1b47e7aebddcadac03"
"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
"checksum syn 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03"
"checksum tinybmp 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "30d12b7f8b271567d6d072c49dee16b22271aabfc473e2066e3353e5af0f5230"
"checksum tinytga 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dc9485052c1f4b541d888f1d564dd9957671e0c21da9bca0c9824c1123e03f07"
"checksum typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33"
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
"checksum vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "876e32dcadfe563a4289e994f7cb391197f362b6315dc45e8ba4aa6f564a4b3c"
"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
"checksum version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d67cb4616d99b940db1d6bd28844ff97108b498a6ca850e5b6191a532063286"

View File

@ -17,26 +17,33 @@ lto = false
cortex-m = "~0.6" cortex-m = "~0.6"
cortex-m-rt = "~0.6" cortex-m-rt = "~0.6"
nb = "~0.1" nb = "~0.1"
#ssd1306 = "~0.2" #ssd1351 = "~0.2"
ssd1351 = "~0.2"
embedded-graphics = "^0.4.0" embedded-graphics = "^0.4.0"
embedded-hal = "=0.2.3" embedded-hal = "=0.2.3"
usb-device = "0.2"
usbd-serial = "0.1"
[dependencies.ssd1351]
version = "0.3"
#git = "https://github.com/MabezDev/ssd1351"
#branch = "crude-ehal-digital-v2-support"
path = "../ssd1351"
[dependencies.itsybitsy_m0] [dependencies.itsybitsy_m0]
version = "~0.7" version = "~0.10"
git = "https://github.com/atsamd-rs/atsamd" git = "https://github.com/atsamd-rs/atsamd"
features = [ features = [
"rt", "rt",
"unproven", "unproven",
"usb",
] ]
[dependencies.atsamd-hal] [dependencies.atsamd-hal]
version = "~0.8" version = "~0.12"
git = "https://github.com/atsamd-rs/atsamd" git = "https://github.com/atsamd-rs/atsamd"
features = [ features = [
"atsamd21g18a", "atsamd21g",
"samd21g18a", "samd21g",
"samd21g18a-rt", "samd21g-rt",
"unproven", "unproven",
] ]

64
src/bl_demo.rs Normal file
View File

@ -0,0 +1,64 @@
use crate::rn4020::{BaudRate, RN4020};
use hal::{
clock::GenericClockController,
delay::Delay,
//digital::v1::OutputPin,
gpio::{Pa10, Pa11, PfC},
pac::{CorePeripherals, Peripherals},
prelude::*,
sercom::{PadPin, Sercom0Pad2, Sercom0Pad3},
};
#[allow(dead_code)]
fn demo() -> ! {
let mut peripherals = Peripherals::take().unwrap();
let core = CorePeripherals::take().unwrap();
let mut clocks = GenericClockController::with_internal_32kosc(
peripherals.GCLK,
&mut peripherals.PM,
&mut peripherals.SYSCTRL,
&mut peripherals.NVMCTRL,
);
let mut pins = hal::Pins::new(peripherals.PORT);
let mut delay = Delay::new(core.SYST, &mut clocks);
let mut red_led = pins.d13.into_open_drain_output(&mut pins.port);
let button_in = pins.d12.into_pull_up_input(&mut pins.port);
let mut button_last: bool = false;
let glck0 = clocks.gclk0();
let bl_baud_rate = BaudRate::BR115200;
let mut bluetooth: RN4020<Sercom0Pad3<Pa11<PfC>>, Sercom0Pad2<Pa10<PfC>>> = RN4020::new(
&clocks.sercom0_core(&glck0).unwrap(),
bl_baud_rate,
peripherals.SERCOM0,
&mut peripherals.PM,
(
pins.d0.into_pad(&mut pins.port),
pins.d1.into_pad(&mut pins.port),
),
);
loop {
//match uart.read() {
// Ok(word) => uart.write(word).unwrap(),
// Err(nb::Error::WouldBlock) => {}
// Err(_) => panic!("Something went wrong when reading from UART"),
//}
let button = button_in.is_low().unwrap();
if button && !button_last {
red_led.set_high().unwrap();
bluetooth.set_serialized_name("MyDude123").unwrap();
delay.delay_ms(200u8);
red_led.set_low().unwrap();
}
button_last = button;
}
}

114
src/display_demo.rs Normal file
View File

@ -0,0 +1,114 @@
use hal::clock::GenericClockController;
use hal::delay::Delay;
use hal::pac::{CorePeripherals, Peripherals};
use hal::prelude::*;
use hal::time::MegaHertz;
//use embedded_graphics::pixelcolor::BinaryColor;
use embedded_graphics::pixelcolor::PixelColorU16;
use embedded_graphics::prelude::*;
use embedded_graphics::primitives::{Circle, Line, Rect};
use embedded_graphics::style::Style;
use ssd1351::{
builder::Builder,
//ininterface::spi::SpiInterface,
//display::Display,
mode::GraphicsMode,
properties::{DisplayRotation, DisplaySize},
};
#[allow(dead_code)]
pub fn demo() -> ! {
let mut peripherals = Peripherals::take().unwrap();
let core = CorePeripherals::take().unwrap();
let mut clocks = GenericClockController::with_internal_32kosc(
peripherals.GCLK,
&mut peripherals.PM,
&mut peripherals.SYSCTRL,
&mut peripherals.NVMCTRL,
);
let mut pins = hal::Pins::new(peripherals.PORT);
let mut red_led = pins.d13.into_open_drain_output(&mut pins.port);
let mut delay = Delay::new(core.SYST, &mut clocks);
let spi = hal::spi_master(
&mut clocks,
MegaHertz(12),
peripherals.SERCOM4,
&mut peripherals.PM,
pins.sck,
pins.mosi,
pins.miso,
&mut pins.port,
);
let dc = pins.d9.into_open_drain_output(&mut pins.port);
let mut rst = pins.d7.into_open_drain_output(&mut pins.port);
//let interface = SpiInterface::new(spi, dc);
//let display = Display::new(interface, DisplaySize::Display128x128, DisplayRotation::Rotate0);
//display.set_draw_area((0, 0), (128, 96));
// NOTE the `DisplaySize` enum comes from the ssd1351 package,
// and currently only supports certain display sizes; see
// https://jamwaffles.github.io/ssd1306/master/ssd1306/prelude/enum.DisplaySize.html
let mut disp: GraphicsMode<_> = Builder::new()
.with_size(DisplaySize::Display128x96)
.with_rotation(DisplayRotation::Rotate0)
.connect_spi(spi, dc)
.into();
loop {
disp.reset(&mut rst, &mut delay).unwrap();
disp.init().unwrap();
//disp.flush().unwrap();
let style = Style {
stroke_width: 10,
fill_color: Some(PixelColorU16(100)),
stroke_color: Some(PixelColorU16(50000)),
};
disp.draw(
Line::new(Coord::new(8, 16 + 16), Coord::new(8 + 8, 16))
.with_style(style)
.into_iter(),
);
disp.draw(
Line::new(Coord::new(8, 16 + 16), Coord::new(8 + 16, 16 + 16))
.with_style(style)
.into_iter(),
);
disp.draw(
Line::new(Coord::new(8 + 16, 16 + 16), Coord::new(8 + 8, 16))
.with_style(style)
.into_iter(),
);
disp.draw(
Rect::new(Coord::new(48, 16), Coord::new(48 + 16, 16 + 16))
.with_style(style)
.into_iter(),
);
disp.draw(
Circle::new(Coord::new(96, 16 + 8), 8)
.with_style(style)
.into_iter(),
);
//disp.flush().unwrap();
//loop {
delay.delay_ms(200u8);
red_led.set_high().unwrap();
delay.delay_ms(50u8);
red_led.set_low().unwrap();
delay.delay_ms(200u8);
red_led.set_high().unwrap();
delay.delay_ms(200u8);
red_led.set_low().unwrap();
}
}

View File

@ -4,74 +4,71 @@
extern crate itsybitsy_m0 as hal; extern crate itsybitsy_m0 as hal;
mod panic; mod panic;
#[allow(dead_code)]
mod rn4020; mod rn4020;
//use core::fmt::Write; mod bl_demo;
use crate::rn4020::{BaudRate, RN4020}; mod display_demo;
use hal::{ mod usb_shell;
clock::GenericClockController, mod wait_delay;
delay::Delay,
//digital::v1::OutputPin, use hal::clock::GenericClockController;
entry, use hal::delay::Delay;
gpio::{Pa10, Pa11, PfC}, use hal::entry;
prelude::*, use hal::pac::{interrupt, CorePeripherals, Peripherals};
sercom::{PadPin, Sercom0Pad2, Sercom0Pad3}, use hal::prelude::*;
pac::{ use usb_shell::{init, poll_usb};
CorePeripherals, use wait_delay::WaitDelay;
Peripherals,
},
};
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let mut peripherals = Peripherals::take().unwrap(); let mut peripherals = Peripherals::take().unwrap();
let core = CorePeripherals::take().unwrap(); let mut core = CorePeripherals::take().unwrap();
let mut clocks = GenericClockController::with_internal_32kosc( let mut clocks = GenericClockController::with_internal_32kosc(
peripherals.GCLK, peripherals.GCLK,
&mut peripherals.PM, &mut peripherals.PM,
&mut peripherals.SYSCTRL, &mut peripherals.SYSCTRL,
&mut peripherals.NVMCTRL, &mut peripherals.NVMCTRL,
); );
let glck0 = clocks.gclk0();
let mut pins = hal::Pins::new(peripherals.PORT); let mut pins = hal::Pins::new(peripherals.PORT);
let mut delay = Delay::new(core.SYST, &mut clocks);
let mut red_led = pins.d13.into_open_drain_output(&mut pins.port); let mut red_led = pins.d13.into_open_drain_output(&mut pins.port);
//let mut delay = Delay::new(core.SYST, &mut clocks);
let mut delay = WaitDelay::new(core.SYST, &mut clocks);
let button_in = pins.d12.into_pull_up_input(&mut pins.port); let mut blip = || {
let mut button_last: bool = false; red_led.set_low().ok();
delay.delay_ms(200u8);
red_led.toggle();
delay.delay_ms(200u8);
};
let bl_baud_rate = BaudRate::BR115200; blip();
let mut bluetooth: RN4020<Sercom0Pad3<Pa11<PfC>>, Sercom0Pad2<Pa10<PfC>>> = RN4020::new(
&clocks.sercom0_core(&glck0).unwrap(), init(
bl_baud_rate, &mut core.NVIC,
peripherals.SERCOM0, peripherals.USB,
&mut clocks,
&mut peripherals.PM, &mut peripherals.PM,
( pins.usb_dm,
pins.d0.into_pad(&mut pins.port), pins.usb_dp,
pins.d1.into_pad(&mut pins.port), &mut pins.port,
), &mut blip,
); );
blip();
blip();
blip();
blip();
// Flash the LED in a spin loop to demonstrate that USB is
// entirely interrupt driven.
loop { loop {
//match uart.read() { blip();
// Ok(word) => uart.write(word).unwrap(),
// Err(nb::Error::WouldBlock) => {}
// Err(_) => panic!("Something went wrong when reading from UART"),
//}
let button = button_in.is_low().unwrap();
if button && !button_last {
red_led.set_high().unwrap();
bluetooth.set_serialized_name("MyDude123").unwrap();
delay.delay_ms(200u8);
red_led.set_low().unwrap();
}
button_last = button;
} }
} }
#[interrupt]
fn USB() {
poll_usb();
}

View File

@ -3,10 +3,10 @@ use core::panic::PanicInfo;
use hal::{ use hal::{
clock::GenericClockController, clock::GenericClockController,
gpio::{Pa10, Pa11, PfC}, gpio::{Pa10, Pa11, PfC},
pac::Peripherals,
prelude::*, prelude::*,
sercom::{PadPin, Sercom0Pad2, Sercom0Pad3, UART0}, sercom::{PadPin, Sercom0Pad2, Sercom0Pad3, UART0},
time, time,
pac::Peripherals,
}; };
#[panic_handler] #[panic_handler]

View File

@ -1,9 +1,9 @@
use core::fmt::Write; use core::fmt::Write;
use hal::{ use hal::{
clock::Sercom0CoreClock, clock::Sercom0CoreClock,
sercom::{RxpoTxpo, UART0Padout, UART0},
//target_device::{NVIC, PM, SERCOM0}, //target_device::{NVIC, PM, SERCOM0},
pac::{PM, SERCOM0}, pac::{PM, SERCOM0},
sercom::{RxpoTxpo, UART0Padout, UART0},
time::Hertz, time::Hertz,
//prelude::_embedded_hal_serial_Read as Read, //prelude::_embedded_hal_serial_Read as Read,
//prelude::_embedded_hal_serial_Write as WriteHal, //prelude::_embedded_hal_serial_Write as WriteHal,

147
src/usb_shell.rs Normal file
View File

@ -0,0 +1,147 @@
mod cmds;
use core::str::from_utf8;
use core::sync::atomic::AtomicBool;
use core::sync::atomic::Ordering;
use cortex_m::peripheral::NVIC;
use hal::clock::GenericClockController;
use hal::gpio::{
v2::{PA24, PA25},
Pin, Port,
};
use hal::pac::{interrupt, PM, USB};
use hal::usb::UsbBus;
use usb_device::bus::UsbBusAllocator;
use usb_device::prelude::*;
use usbd_serial::{SerialPort, USB_CLASS_CDC};
struct ShellState {
line_buf: [u8; 255],
buf_size: usize,
}
static USB_READY: AtomicBool = AtomicBool::new(false);
static mut USB_ALLOCATOR: Option<UsbBusAllocator<UsbBus>> = None;
static mut USB_BUS: Option<UsbDevice<UsbBus>> = None;
static mut USB_SERIAL: Option<SerialPort<UsbBus>> = None;
static mut SHELL_STATE: Option<ShellState> = None;
const PROMPT: &[u8] = b"[neowatch]# ";
pub fn init<F: FnMut()>(
nvic: &mut NVIC,
//bus_allocator: UsbBusAllocator<UsbBus>,
usb: USB,
clocks: &mut GenericClockController,
pm: &mut PM,
usb_dm: Pin<PA24, hal::gpio::v2::Input<hal::gpio::v2::Floating>>,
usb_dp: Pin<PA25, hal::gpio::v2::Input<hal::gpio::v2::Floating>>,
port: &mut Port,
f: &mut F,
) {
let bus_allocator = unsafe {
USB_ALLOCATOR = Some(hal::usb_allocator(usb, clocks, pm, usb_dm, usb_dp, port));
USB_ALLOCATOR.as_ref().unwrap()
};
f();
unsafe {
USB_SERIAL = Some(SerialPort::new(&bus_allocator));
USB_BUS = Some(
UsbDeviceBuilder::new(&bus_allocator, UsbVidPid(0x16c0, 0x27dd))
.manufacturer("Fake company")
.product("Serial port")
.serial_number("TEST")
.device_class(USB_CLASS_CDC)
.build(),
);
SHELL_STATE = Some(ShellState {
line_buf: [0; 255],
buf_size: 0,
});
}
f();
USB_READY.store(true, Ordering::SeqCst);
f();
unsafe {
nvic.set_priority(interrupt::USB, 1);
f();
NVIC::unmask(interrupt::USB);
f();
}
}
pub fn poll_usb() {
if !USB_READY.load(Ordering::SeqCst) {
return;
}
unsafe { USB_BUS.as_mut() }
.zip(unsafe { USB_SERIAL.as_mut() })
.zip(unsafe { SHELL_STATE.as_mut() })
.map(|((bus, serial), state)| {
bus.poll(&mut [serial]);
let mut buf = [0u8; 64];
if let Ok(count) = serial.read(&mut buf) {
for &c in buf.iter().take(count) {
match c {
b'\t' => {}
127 | 08 /* del or backspace */ => {
if state.buf_size > 0 {
// FIXME: This is not utf-8 compatible. It should decrease
// buf_size by the size of the last unicode scalar.
state.buf_size -= 1;
// erase previous character
serial.write(&[08, b' ', 08]).unwrap();
}
}
b'\n' | b'\r' => {
if state.buf_size > 0 {
serial.write(b"\r\n").unwrap();
match from_utf8(&state.line_buf[..state.buf_size]) {
Ok(s) => {
let mut args = s.split(" ");
let arg0 = args.next().unwrap_or("");
match arg0 {
"help" => cmds::help::exec(args, serial),
"echo" => cmds::echo::exec(args, serial),
_ => {
serial.write(b"Unknown command: ").unwrap();
serial.write(arg0.as_bytes()).unwrap();
}
}
}
Err(_) => {
serial.write(b"ERROR: not valid utf-8").unwrap();
}
}
}
serial.write(b"\r\n").unwrap();
serial.write(PROMPT).unwrap();
state.buf_size = 0;
}
_ => {
if state.buf_size >= state.line_buf.len() {
state.buf_size = 0;
serial
.write(b"\r\nERROR: line buffer size exceeded\r\n")
.unwrap();
break;
}
state.line_buf[state.buf_size] = c;
state.buf_size += 1;
serial.write(&[c]).unwrap();
}
}
}
crate::wait_delay::wakeup();
};
});
}

View File

@ -0,0 +1,27 @@
use hal::usb::UsbBus;
use usbd_serial::SerialPort;
/// Echo
pub fn exec<'a, I: Iterator<Item = &'a str>>(args: I, serial: &mut SerialPort<UsbBus>) {
for arg in args {
// inspect bytes
//for &byte in arg.as_bytes() {
// let mut decimal = [0u8; 3];
// decimal[2] = byte % 10;
// decimal[1] = byte % 100 / 10;
// decimal[0] = byte / 100;
// serial.write(&[byte]).unwrap();
// serial.write(b" has dec code ").unwrap();
// for &digit in &decimal {
// let c =
// [b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9'][digit as usize];
// serial.write(&[c]).unwrap();
// }
// serial.write(b"\r\n").unwrap();
//}
serial.write(arg.as_bytes()).unwrap();
serial.write(b" ").unwrap();
}
}

View File

@ -0,0 +1,13 @@
use hal::usb::UsbBus;
use usbd_serial::SerialPort;
/// Help
pub fn exec<'a, I: Iterator<Item = &'a str>>(_args: I, serial: &mut SerialPort<UsbBus>) {
serial
.write(
b"available commands:\r\n\
- help\r\n\
- echo",
)
.unwrap();
}

View File

@ -0,0 +1,2 @@
pub mod echo;
pub mod help;

101
src/wait_delay.rs Normal file
View File

@ -0,0 +1,101 @@
//! Delay module for waking the system up
use cortex_m::peripheral::syst::SystClkSource;
use cortex_m::peripheral::SYST;
use embedded_hal::blocking::delay::{DelayMs, DelayUs};
use itsybitsy_m0::clock::GenericClockController;
use itsybitsy_m0::time::Hertz;
static mut SLEEPING: bool = false;
pub fn wakeup() {
unsafe {
SLEEPING = false;
}
}
/// System timer (SysTick) as a delay provider
pub struct WaitDelay {
sysclock: Hertz,
syst: SYST,
}
impl WaitDelay {
/// Configures the system timer (SysTick) as a delay provider
pub fn new(mut syst: SYST, clocks: &mut GenericClockController) -> Self {
syst.set_clock_source(SystClkSource::Core);
WaitDelay {
syst,
sysclock: clocks.gclk0().into(),
}
}
/// Releases the system timer (SysTick) resource
pub fn free(self) -> SYST {
self.syst
}
}
impl DelayMs<u32> for WaitDelay {
fn delay_ms(&mut self, ms: u32) {
self.delay_us(ms * 1_000);
}
}
impl DelayMs<u16> for WaitDelay {
fn delay_ms(&mut self, ms: u16) {
self.delay_ms(ms as u32);
}
}
impl DelayMs<u8> for WaitDelay {
fn delay_ms(&mut self, ms: u8) {
self.delay_ms(ms as u32);
}
}
impl DelayUs<u32> for WaitDelay {
fn delay_us(&mut self, us: u32) {
// The SysTick Reload Value register supports values between 1 and 0x00FFFFFF.
const MAX_RVR: u32 = 0x00FF_FFFF;
let mut total_rvr = us * (self.sysclock.0 / 1_000_000);
//unsafe {
// SLEEPING = true;
//}
while total_rvr != 0 {
let current_rvr = if total_rvr <= MAX_RVR {
total_rvr
} else {
MAX_RVR
};
self.syst.set_reload(current_rvr);
self.syst.clear_current();
self.syst.enable_counter();
// Update the tracking variable while we are waiting...
total_rvr -= current_rvr;
while !self.syst.has_wrapped() {}
self.syst.disable_counter();
}
}
}
impl DelayUs<u16> for WaitDelay {
fn delay_us(&mut self, us: u16) {
self.delay_us(us as u32)
}
}
impl DelayUs<u8> for WaitDelay {
fn delay_us(&mut self, us: u8) {
self.delay_us(us as u32)
}
}