diff --git a/firmware/Cargo.lock b/firmware/Cargo.lock index bf69463..d04105b 100644 --- a/firmware/Cargo.lock +++ b/firmware/Cargo.lock @@ -22,11 +22,6 @@ dependencies = [ "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "autocfg" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "bare-metal" version = "0.2.5" @@ -45,14 +40,6 @@ name = "bitflags" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "btoi" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "build_const" version = "0.2.1" @@ -63,6 +50,24 @@ name = "byteorder" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "cc" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cfg-if" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "compiler_builtins" +version = "0.1.19" +source = "git+https://github.com/rust-lang-nursery/compiler-builtins#1ac39708554b196f54ebc414f3e78574d40f2d8f" +dependencies = [ + "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cortex-m" version = "0.5.10" @@ -143,13 +148,14 @@ version = "1.0.0" dependencies = [ "bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "bit_field 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "btoi 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "compiler_builtins 0.1.19 (git+https://github.com/rust-lang-nursery/compiler-builtins)", "cortex-m 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "cortex-m-rt 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "cortex-m-semihosting 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "lexical-core 0.6.0 (git+https://github.com/astro/rust-lexical.git)", "libm 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "nom 5.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -167,6 +173,16 @@ dependencies = [ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "lexical-core" +version = "0.6.0" +source = "git+https://github.com/astro/rust-lexical.git#5b0ba2c0525c64911c74c16813ed3ac0dc0f157c" +dependencies = [ + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "static_assertions 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "libm" version = "0.1.4" @@ -196,14 +212,6 @@ dependencies = [ "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "num-traits" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "proc-macro2" version = "0.4.30" @@ -291,6 +299,11 @@ name = "stable_deref_trait" version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "static_assertions" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "syn" version = "0.15.44" @@ -369,13 +382,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum aligned 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d39da9b88ae1a81c03c9c082b8db83f1d0e93914126041962af61034ab44c4a5" "checksum aligned 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d3a316c7ea8e1e9ece54862c992def5a7ac14de9f5832b69d71760680efeeefa" "checksum as-slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "293dac66b274fab06f95e7efb05ec439a6b70136081ea522d270bc351ae5bb27" -"checksum autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b671c8fb71b457dd4ae18c4ba1e59aa81793daacc361d82fcd410cef0d491875" "checksum bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" "checksum bit_field 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a165d606cf084741d4ac3a28fb6e9b1eb0bd31f6cd999098cfddb0b2ab381dc0" "checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd" -"checksum btoi 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e4ced8205e70d9e553d008d53ded735808fa6133597318d48f74fc2bf9861471" "checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39" "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" +"checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be" +"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" +"checksum compiler_builtins 0.1.19 (git+https://github.com/rust-lang-nursery/compiler-builtins)" = "" "checksum cortex-m 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0b159a1e8306949579de3698c841dba58058197b65c60807194e4fa1e7a554" "checksum cortex-m 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "145da2fc379bbd378ed425e75e1748214add9bbd800d4d5b77abb54ca423dbca" "checksum cortex-m-rt 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "17805910e3ecf029bdbfcc42b7384d9e3d9e5626153fa810002c1ef9839338ac" @@ -385,12 +399,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "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 kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +"checksum lexical-core 0.6.0 (git+https://github.com/astro/rust-lexical.git)" = "" "checksum libm 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a" "checksum managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43e2737ecabe4ae36a68061398bf27d2bfd0763f4c3c837a398478459494c4b7" "checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" "checksum nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc" "checksum nom 5.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c618b63422da4401283884e6668d39f819a106ef51f5f59b81add00075da35ca" -"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" "checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" "checksum r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f" @@ -403,6 +417,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp?rev=cd893e6)" = "" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" +"checksum static_assertions 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7f3eb36b47e512f8f1c9e3d10c2c1965bc992bd9cdb024fa581e2194501c83d3" "checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" "checksum tm4c129x 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d430ed4ed06dd9fff3d4517a37343e1b53789218f2f608bf1e0432f67abf624" "checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" diff --git a/firmware/Cargo.toml b/firmware/Cargo.toml index 73e5507..7eaf0fb 100644 --- a/firmware/Cargo.toml +++ b/firmware/Cargo.toml @@ -19,7 +19,9 @@ cortex-m-semihosting = "0.3" byteorder = { version = "1.3", default-features = false } bit_field = "0.10" bare-metal = "0.2" -btoi = { version = "~0.4", default-features = false } +#lexical-core = { version = "~0.6", default-features = false } +# TODO: pending https://github.com/Alexhuszagh/rust-lexical/pull/25 +lexical-core = { git = "https://github.com/astro/rust-lexical.git", default-features = false } nom = { version = "~5", default-features = false } [dependencies.smoltcp] @@ -28,6 +30,11 @@ rev = "cd893e6" features = ["proto-ipv4", "socket-tcp"] default-features = false +[dependencies.compiler_builtins] +git = "https://github.com/rust-lang-nursery/compiler-builtins" +default-features = false +features = ["mem", "no-lang-items", "c"] + [profile.release] lto = true debug = true diff --git a/firmware/src/command_parser.rs b/firmware/src/command_parser.rs index 2ddfb82..c1173b1 100644 --- a/firmware/src/command_parser.rs +++ b/firmware/src/command_parser.rs @@ -2,14 +2,14 @@ use core::fmt; use nom::{ IResult, branch::alt, - bytes::complete::{tag, take_while1}, + bytes::complete::{is_a, tag, take_while1}, character::{is_digit, complete::char}, combinator::{map, value}, sequence::preceded, multi::fold_many1, error::ErrorKind, }; -use btoi::{btoi, ParseIntegerError}; +use lexical_core as lexical; use super::session::ReportMode; @@ -18,7 +18,7 @@ pub enum Error { Parser(ErrorKind), Incomplete, UnexpectedInput(u8), - ParseInteger(ParseIntegerError) + ParseNumber(lexical::Error) } impl<'t> From> for Error { @@ -34,9 +34,9 @@ impl<'t> From> for Error { } } -impl From for Error { - fn from(e: ParseIntegerError) -> Self { - Error::ParseInteger(e) +impl From for Error { + fn from(e: lexical::Error) -> Self { + Error::ParseNumber(e) } } @@ -53,9 +53,9 @@ impl fmt::Display for Error { "parser: ".fmt(fmt)?; (e as &dyn core::fmt::Debug).fmt(fmt) } - Error::ParseInteger(e) => { + Error::ParseNumber(e) => { "parsing number: ".fmt(fmt)?; - e.fmt(fmt) + (e as &dyn core::fmt::Debug).fmt(fmt) } } } @@ -98,9 +98,18 @@ fn whitespace(input: &[u8]) -> IResult<&[u8], ()> { fold_many1(char(' '), (), |(), _| ())(input) } -fn unsigned(input: &[u8]) -> IResult<&[u8], Result> { +fn unsigned(input: &[u8]) -> IResult<&[u8], Result> { take_while1(is_digit)(input) - .map(|(input, digits)| (input, btoi(digits))) + .map(|(input, digits)| (input, lexical::parse(digits))) +} + +fn float(input: &[u8]) -> IResult<&[u8], Result> { + let (input, sign) = is_a("-")(input)?; + let negative = sign.len() > 0; + let (input, digits) = take_while1(|c| is_digit(c) || c == '.' as u8)(input)?; + let result = lexical::parse(digits) + .map(|result: f32| if negative { -result } else { result }); + Ok((input, result)) } fn report_mode(input: &[u8]) -> IResult<&[u8], ReportMode> { @@ -165,9 +174,9 @@ fn pid_parameter(input: &[u8]) -> IResult<&[u8], Result> { ))(input)?; let (input, _) = whitespace(input)?; // TODO: parse float - let (input, value) = unsigned(input)?; + let (input, value) = float(input)?; let result = value - .map(|value| Command::Pid { parameter, value: value as f32 }) + .map(|value| Command::Pid { parameter, value }) .map_err(|e| e.into()); Ok((input, result)) } diff --git a/shell.nix b/shell.nix index 88641d2..20ce061 100644 --- a/shell.nix +++ b/shell.nix @@ -12,12 +12,14 @@ stdenv.mkDerivation { buildInputs = with rustPlatform.rust; [ rustc cargo cargo-xbuild rustcSrc + pkgsCross.arm-embedded.stdenv.cc openocd ]; # Set Environment Variables RUST_BACKTRACE = 1; XARGO_RUST_SRC = "${rustcSrc}/src"; + RUST_COMPILER_RT_ROOT = "${rustcSrc}/src/llvm-project/compiler-rt"; shellHook = '' echo "Run 'cargo xbuild --release' to build."