add support for manipulating pwm duty cycle
This commit is contained in:
parent
5e0f55647a
commit
1395e8b410
25
firmware/Cargo.lock
generated
25
firmware/Cargo.lock
generated
@ -31,6 +31,11 @@ dependencies = [
|
|||||||
"stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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]]
|
[[package]]
|
||||||
name = "bare-metal"
|
name = "bare-metal"
|
||||||
version = "0.2.5"
|
version = "0.2.5"
|
||||||
@ -49,6 +54,14 @@ name = "bitflags"
|
|||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
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]]
|
[[package]]
|
||||||
name = "build_const"
|
name = "build_const"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
@ -148,6 +161,7 @@ dependencies = [
|
|||||||
"alloc-cortex-m 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"alloc-cortex-m 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"cortex-m 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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-rt 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -211,6 +225,14 @@ 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"
|
||||||
|
|
||||||
|
[[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]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "0.4.30"
|
version = "0.4.30"
|
||||||
@ -387,9 +409,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
"checksum aligned 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d3a316c7ea8e1e9ece54862c992def5a7ac14de9f5832b69d71760680efeeefa"
|
"checksum aligned 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d3a316c7ea8e1e9ece54862c992def5a7ac14de9f5832b69d71760680efeeefa"
|
||||||
"checksum alloc-cortex-m 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d5f7d01bc93ce089de636f946f7f1fdc5e5d751732367e019c9755440e7aef4"
|
"checksum alloc-cortex-m 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d5f7d01bc93ce089de636f946f7f1fdc5e5d751732367e019c9755440e7aef4"
|
||||||
"checksum as-slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "293dac66b274fab06f95e7efb05ec439a6b70136081ea522d270bc351ae5bb27"
|
"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 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 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 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 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 byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
|
||||||
"checksum cortex-m 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3df5de9a9829f2ccb7defa8945fa020c6614cd2f6ba9b5f33db9241dcc01985e"
|
"checksum cortex-m 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3df5de9a9829f2ccb7defa8945fa020c6614cd2f6ba9b5f33db9241dcc01985e"
|
||||||
@ -408,6 +432,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
"checksum logos-derive 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)" = "13ff1b1068db09ee21d12baf55eccc0900a781a735273e0a606f6f4fbb32a322"
|
"checksum logos-derive 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)" = "13ff1b1068db09ee21d12baf55eccc0900a781a735273e0a606f6f4fbb32a322"
|
||||||
"checksum managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43e2737ecabe4ae36a68061398bf27d2bfd0763f4c3c837a398478459494c4b7"
|
"checksum managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43e2737ecabe4ae36a68061398bf27d2bfd0763f4c3c837a398478459494c4b7"
|
||||||
"checksum nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc"
|
"checksum nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc"
|
||||||
|
"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 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 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"
|
"checksum r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f"
|
||||||
|
@ -21,6 +21,7 @@ bit_field = "0.10"
|
|||||||
bare-metal = "0.2"
|
bare-metal = "0.2"
|
||||||
logos = { version = "~0.9", default-features = false, features = ["export_derive"] }
|
logos = { version = "~0.9", default-features = false, features = ["export_derive"] }
|
||||||
alloc-cortex-m = "0.3"
|
alloc-cortex-m = "0.3"
|
||||||
|
btoi = { version = "~0.4", default-features = false }
|
||||||
|
|
||||||
[dependencies.smoltcp]
|
[dependencies.smoltcp]
|
||||||
git = "https://github.com/m-labs/smoltcp"
|
git = "https://github.com/m-labs/smoltcp"
|
||||||
|
@ -174,6 +174,22 @@ pub fn init() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_timer_pwm(matchr: u32, ilr: u32) {
|
||||||
|
macro_rules! set_timer_pwm {
|
||||||
|
($T: tt) => (
|
||||||
|
let timer = unsafe { &*tm4c129x::$T::ptr() };
|
||||||
|
timer.tamatchr.write(|w| unsafe { w.bits(matchr) });
|
||||||
|
timer.tbmatchr.write(|w| unsafe { w.bits(matchr) });
|
||||||
|
timer.tailr.write(|w| unsafe { w.bits(ilr) });
|
||||||
|
timer.tbilr.write(|w| unsafe { w.bits(ilr) });
|
||||||
|
)
|
||||||
|
}
|
||||||
|
set_timer_pwm!(TIMER2);
|
||||||
|
set_timer_pwm!(TIMER3);
|
||||||
|
set_timer_pwm!(TIMER4);
|
||||||
|
set_timer_pwm!(TIMER5);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_mac_address() -> [u8; 6] {
|
pub fn get_mac_address() -> [u8; 6] {
|
||||||
let (userreg0, userreg1) = cortex_m::interrupt::free(|_cs| {
|
let (userreg0, userreg1) = cortex_m::interrupt::free(|_cs| {
|
||||||
let flashctl = unsafe { &*tm4c129x::FLASH_CTRL::ptr() };
|
let flashctl = unsafe { &*tm4c129x::FLASH_CTRL::ptr() };
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use logos::Logos;
|
use logos::Logos;
|
||||||
|
use btoi::{btoi, ParseIntegerError};
|
||||||
use super::session::ReportMode;
|
use super::session::ReportMode;
|
||||||
|
|
||||||
#[derive(Logos, Debug, PartialEq)]
|
#[derive(Logos, Debug, PartialEq)]
|
||||||
@ -20,6 +21,8 @@ enum Token {
|
|||||||
Once,
|
Once,
|
||||||
#[token = "continuous"]
|
#[token = "continuous"]
|
||||||
Continuous,
|
Continuous,
|
||||||
|
#[token = "pwm"]
|
||||||
|
Pwm,
|
||||||
|
|
||||||
#[regex = "[0-9]+"]
|
#[regex = "[0-9]+"]
|
||||||
Number,
|
Number,
|
||||||
@ -30,6 +33,13 @@ pub enum Error {
|
|||||||
Parser,
|
Parser,
|
||||||
UnexpectedEnd,
|
UnexpectedEnd,
|
||||||
UnexpectedToken(Token),
|
UnexpectedToken(Token),
|
||||||
|
ParseInteger(ParseIntegerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ParseIntegerError> for Error {
|
||||||
|
fn from(e: ParseIntegerError) -> Self {
|
||||||
|
Error::ParseInteger(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -42,6 +52,10 @@ pub enum Command {
|
|||||||
Quit,
|
Quit,
|
||||||
Show(ShowCommand),
|
Show(ShowCommand),
|
||||||
Report(ReportMode),
|
Report(ReportMode),
|
||||||
|
Pwm {
|
||||||
|
pwm_match: u32,
|
||||||
|
pwm_reload: u32,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Command {
|
impl Command {
|
||||||
@ -85,6 +99,27 @@ impl Command {
|
|||||||
],
|
],
|
||||||
End => Ok(Command::Report(ReportMode::Once)),
|
End => Ok(Command::Report(ReportMode::Once)),
|
||||||
],
|
],
|
||||||
|
Pwm => {
|
||||||
|
if lexer.token != Token::Number {
|
||||||
|
return Err(Error::UnexpectedToken(lexer.token));
|
||||||
|
}
|
||||||
|
let pwm_match = btoi(lexer.slice().as_bytes())?;
|
||||||
|
lexer.advance();
|
||||||
|
|
||||||
|
if lexer.token != Token::Number {
|
||||||
|
return Err(Error::UnexpectedToken(lexer.token));
|
||||||
|
}
|
||||||
|
let pwm_reload = btoi(lexer.slice().as_bytes())?;
|
||||||
|
lexer.advance();
|
||||||
|
|
||||||
|
if lexer.token != Token::End {
|
||||||
|
return Err(Error::UnexpectedToken(lexer.token));
|
||||||
|
}
|
||||||
|
|
||||||
|
end!(Command::Pwm {
|
||||||
|
pwm_match, pwm_reload,
|
||||||
|
})
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -263,9 +263,9 @@ fn main() -> ! {
|
|||||||
Command::Show(ShowCommand::ReportMode) => {
|
Command::Show(ShowCommand::ReportMode) => {
|
||||||
let _ = writeln!(socket, "Report mode: {:?}", session.report_mode());
|
let _ = writeln!(socket, "Report mode: {:?}", session.report_mode());
|
||||||
}
|
}
|
||||||
command => {
|
Command::Pwm { pwm_match, pwm_reload } => {
|
||||||
// TODO: remove for exhaustion check
|
board::set_timer_pwm(pwm_match, pwm_reload);
|
||||||
let _ = writeln!(socket, "Not implemented: {:?}", command);
|
let _ = writeln!(socket, "PWM duty cycle: {}/{}", pwm_match, pwm_reload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(SessionOutput::Error(e)) => {
|
Ok(SessionOutput::Error(e)) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user