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.rs30
1 files changed, 14 insertions, 16 deletions
diff --git a/sw/eval-clock-cw-tx/src/usb.rs b/sw/eval-clock-cw-tx/src/usb.rs
index a74ac20..d75c287 100644
--- a/sw/eval-clock-cw-tx/src/usb.rs
+++ b/sw/eval-clock-cw-tx/src/usb.rs
@@ -4,7 +4,7 @@ use stm32f1xx_hal::{
pac,
pac::{interrupt, Interrupt},
gpio,
- timer::CountDownTimer,
+ timer::{CounterHz, Event},
};
use stm32f1xx_hal::usb::{Peripheral, UsbBus, UsbBusType};
use usb_device::{bus::UsbBusAllocator, prelude::*};
@@ -19,7 +19,7 @@ pub const TIMER_FREQ_HZ : u32 = 245;
const FELDHELL_PATTERN_LEN : usize = 16;
const MESSAGE_LEN : usize = 64;
-static mut FELDHELL_TIMER: MaybeUninit<CountDownTimer<pac::TIM4>> = MaybeUninit::uninit();
+static mut FELDHELL_TIMER: MaybeUninit<CounterHz<pac::TIM4>> = MaybeUninit::uninit();
static mut SHARED_USB: MaybeUninit<USBSharedData> = MaybeUninit::uninit();
@@ -63,8 +63,8 @@ enum Font {
// Shared between application and interrupt context
struct USBSharedData {
- incoming_buf: ArrayVec::<[u8; MESSAGE_LEN]>,
- feldhell_pattern: ArrayVec::<[u16; FELDHELL_PATTERN_LEN]>, // FELDHELL columns to transmit
+ incoming_buf: ArrayVec::<u8, MESSAGE_LEN>,
+ feldhell_pattern: ArrayVec::<u16, FELDHELL_PATTERN_LEN>, // FELDHELL columns to transmit
}
pub fn enable_interrupts() {
@@ -80,13 +80,13 @@ pub struct USBData {
pub frequency : u32,
pub transmit : bool,
- current_str : ArrayVec::<[u8; 96]>,
+ current_str : ArrayVec::<u8, 96>,
send_ix : usize,
}
impl USBData {
pub fn new(
- timer4: CountDownTimer<pac::TIM4>,
+ timer4: CounterHz<pac::TIM4>,
usb: pac::USB,
pin_dm: gpio::gpioa::PA11<gpio::Input<gpio::Floating>>,
pin_dp: gpio::gpioa::PA12<gpio::Input<gpio::Floating>>) -> USBData {
@@ -148,7 +148,7 @@ impl USBData {
let in_message = cortex_m::interrupt::free(|_cs| {
let shared_usb = unsafe { &mut *SHARED_USB.as_mut_ptr() };
- let mut message = ArrayString::<[u8; MESSAGE_LEN]>::new();
+ let mut message = ArrayString::<MESSAGE_LEN>::new();
let mut split_at = None;
for (i, c) in shared_usb.incoming_buf.iter().enumerate() {
@@ -168,7 +168,7 @@ impl USBData {
write!(&mut message, "{}", core::str::from_utf8(front).unwrap()).ok();
- let mut keep = ArrayVec::<[u8; MESSAGE_LEN]>::new();
+ let mut keep = ArrayVec::<u8, MESSAGE_LEN>::new();
keep.try_extend_from_slice(back).ok();
shared_usb.incoming_buf.clear();
@@ -185,7 +185,7 @@ impl USBData {
}
});
- let mut outgoing = ArrayVec::<[u8; MESSAGE_LEN]>::new();
+ let mut outgoing = ArrayVec::<u8, MESSAGE_LEN>::new();
if let Some(m) = in_message {
if m.as_str() == "tx\n" {
outgoing.try_extend_from_slice(b"TX ok\n").ok();
@@ -212,7 +212,7 @@ impl USBData {
outgoing.try_extend_from_slice(b"fontn ok\n").ok();
}
else if m.chars().nth(0).unwrap() == 'f' {
- let mut as_str = ArrayString::<[u8; MESSAGE_LEN]>::new();
+ let mut as_str = ArrayString::<MESSAGE_LEN>::new();
for c in m.chars().skip(1) {
as_str.push(c);
@@ -269,7 +269,7 @@ impl USBData {
if self.send_ix >= self.current_str.len() {
cortex_m::interrupt::free(|_cs| {
let serial = unsafe { USB_SERIAL.as_mut().unwrap() };
- let mut outgoing = ArrayString::<[u8; 16]>::new();
+ let mut outgoing = ArrayString::<16>::new();
write!(&mut outgoing, "FH sent {}\n", self.send_ix).ok();
serial.write(outgoing.as_bytes()).ok();
});
@@ -322,7 +322,7 @@ fn usb_interrupt() {
#[interrupt]
fn TIM4() {
let timer = unsafe { &mut *FELDHELL_TIMER.as_mut_ptr() };
- timer.clear_update_interrupt_flag();
+ timer.clear_interrupt(Event::Update);
let shared_usb = unsafe { &mut *SHARED_USB.as_mut_ptr() };
while shared_usb.feldhell_pattern.len() > 0 && shared_usb.feldhell_pattern.as_slice()[0] == 0 {
@@ -335,13 +335,11 @@ fn TIM4() {
let shared = unsafe { &mut *crate::SHARED.as_mut_ptr() };
- use embedded_hal::digital::v2::OutputPin;
-
if shared.state.allow_feldhell_keying() && (*pat & 0b1) == 0b1 {
- shared.cw_key_out_n.set_low().unwrap();
+ shared.cw_key_out_n.set_low();
}
else {
- shared.cw_key_out_n.set_high().unwrap();
+ shared.cw_key_out_n.set_high();
}
*pat >>= 1;