aboutsummaryrefslogtreecommitdiffstats
path: root/sw/eval-clock-cw-tx/src/usb.rs
diff options
context:
space:
mode:
Diffstat (limited to 'sw/eval-clock-cw-tx/src/usb.rs')
-rw-r--r--sw/eval-clock-cw-tx/src/usb.rs45
1 files changed, 31 insertions, 14 deletions
diff --git a/sw/eval-clock-cw-tx/src/usb.rs b/sw/eval-clock-cw-tx/src/usb.rs
index d75c287..b7e8536 100644
--- a/sw/eval-clock-cw-tx/src/usb.rs
+++ b/sw/eval-clock-cw-tx/src/usb.rs
@@ -52,6 +52,9 @@ static mut USB_DEVICE: Option<UsbDevice<UsbBusType>> = None;
*
* Set FELDHELL narrow font
* fontn
+ *
+ * Trigger a WSPR transmission
+ * wspr
*/
@@ -75,10 +78,13 @@ pub fn enable_interrupts() {
}
}
+#[derive(PartialEq, Clone, Copy)]
+pub enum Transmit { None, FELDHELL, WSPR }
+
pub struct USBData {
font : Font,
- pub frequency : u32,
- pub transmit : bool,
+ frequency : Option<u32>,
+ transmit : Transmit,
current_str : ArrayVec::<u8, 96>,
send_ix : usize,
@@ -121,15 +127,15 @@ impl USBData {
}
USBData {
- font : Font::Wide,
- frequency : 10121000,
- transmit : false,
- current_str : ArrayVec::new(),
- send_ix : 0,
+ font: Font::Wide,
+ frequency: None,
+ transmit: Transmit::None,
+ current_str: ArrayVec::new(),
+ send_ix: 0,
}
}
- fn send_once(&mut self, message : &[u8]) {
+ pub fn send_message(&mut self, message : &[u8]) {
cortex_m::interrupt::free(|_cs| {
let serial = unsafe { USB_SERIAL.as_mut().unwrap() };
serial.write(message).ok();
@@ -137,11 +143,11 @@ impl USBData {
}
pub fn send_receive(&mut self) {
- self.send_once(b"Switch RX\n");
+ self.send_message(b"Switch RX\n");
}
pub fn send_transmit(&mut self) {
- self.send_once(b"Switch TX\n");
+ self.send_message(b"Switch TX\n");
}
pub fn handle(&mut self) {
@@ -189,12 +195,12 @@ impl USBData {
if let Some(m) = in_message {
if m.as_str() == "tx\n" {
outgoing.try_extend_from_slice(b"TX ok\n").ok();
- self.transmit = true;
+ self.transmit = Transmit::FELDHELL;
}
else if m.as_str() == "rx\n" {
outgoing.try_extend_from_slice(b"RX ok\n").ok();
self.current_str.clear();
- self.transmit = false;
+ self.transmit = Transmit::None;
}
else if m.chars().nth(0).unwrap() == 'm' {
self.current_str.clear();
@@ -211,6 +217,10 @@ impl USBData {
self.font = Font::Narrow;
outgoing.try_extend_from_slice(b"fontn ok\n").ok();
}
+ else if m.as_str() == "wspr\n" {
+ outgoing.try_extend_from_slice(b"wspr ok\n").ok();
+ self.transmit = Transmit::WSPR;
+ }
else if m.chars().nth(0).unwrap() == 'f' {
let mut as_str = ArrayString::<MESSAGE_LEN>::new();
@@ -220,7 +230,7 @@ impl USBData {
match u32::from_str_radix(as_str.as_str().trim(), 10) {
Ok(val) => {
- self.frequency = val;
+ self.frequency = Some(val);
outgoing.try_extend_from_slice(b"f ok\n").ok();
}
_ => {
@@ -280,7 +290,14 @@ impl USBData {
}
}
- pub fn is_transmit(&self) -> bool { self.transmit }
+ pub fn take_frequency(&mut self) -> Option<u32> { self.frequency.take() }
+
+ pub fn transmit(&self) -> Transmit { self.transmit }
+
+ pub fn clear_transmit(&mut self) {
+ self.send_message(b"WSPR done\n");
+ self.transmit = Transmit::None
+ }
}
#[allow(non_snake_case)]