fix baud rate and enable arduino tx
This commit is contained in:
parent
8e91a0d950
commit
e440b2f72f
2 changed files with 8 additions and 5 deletions
|
@ -5,7 +5,7 @@ use postcard::to_vec_cobs;
|
|||
use heapless::Vec;
|
||||
|
||||
fn main() {
|
||||
let mut port = serialport::new("/dev/ttyACM0", 1152000)
|
||||
let mut port = serialport::new("/dev/ttyACM0", 115200)
|
||||
.open().expect("port missing");
|
||||
println!("port open");
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use core::cell::RefCell;
|
||||
use core::mem::MaybeUninit;
|
||||
|
||||
use arduino_hal::clock::MHz16;
|
||||
use arduino_hal::{clock::MHz16, hal::usart::UsartWriter};
|
||||
use arduino_hal::hal::port::*;
|
||||
use arduino_hal::hal::usart::UsartReader;
|
||||
use arduino_hal::pac::USART0;
|
||||
|
@ -43,6 +43,7 @@ fn update_shift_register(
|
|||
latch_pin.set_high();
|
||||
}
|
||||
|
||||
static mut UART_TX: MaybeUninit<UsartWriter<USART0, Pin<Input, PD0>, Pin<Output, PD1>, MHz16>> = MaybeUninit::uninit();
|
||||
static mut UART_RX: MaybeUninit<UsartReader<USART0, Pin<Input, PD0>, Pin<Output, PD1>, MHz16>> = MaybeUninit::uninit();
|
||||
|
||||
static INPUT_LINE: Mutex<RefCell<[u8; 20]>> = Mutex::new(RefCell::new([0;20]));
|
||||
|
@ -50,6 +51,7 @@ static INPUT_LINE: Mutex<RefCell<[u8; 20]>> = Mutex::new(RefCell::new([0;20]));
|
|||
#[avr_device::interrupt(atmega328p)]
|
||||
unsafe fn USART_RX() {
|
||||
let rx = &mut *UART_RX.as_mut_ptr();
|
||||
let tx = &mut *UART_TX.as_mut_ptr();
|
||||
|
||||
static mut BUF: [u8; 20] = [0;20];
|
||||
static mut N: usize = 0; // index into line
|
||||
|
@ -111,10 +113,11 @@ fn main() -> ! {
|
|||
avr_device::interrupt::disable();
|
||||
serial.listen(arduino_hal::hal::usart::Event::RxComplete);
|
||||
|
||||
let (rx,tx) = serial.split();
|
||||
let (rx,mut tx) = serial.split();
|
||||
|
||||
unsafe {
|
||||
UART_RX = MaybeUninit::new(rx);
|
||||
UART_TX = MaybeUninit::new(tx);
|
||||
avr_device::interrupt::enable();
|
||||
};
|
||||
|
||||
|
@ -144,7 +147,7 @@ fn main() -> ! {
|
|||
}
|
||||
|
||||
fn to_pwm(val: f32) -> u8 {
|
||||
(val.abs() * 255.0) as u8
|
||||
(val.abs().min(1.0) * 255.0) as u8
|
||||
}
|
||||
|
||||
// 16/255
|
||||
|
@ -164,5 +167,5 @@ fn decode_command() -> Command {
|
|||
|
||||
let Some(length) = input.iter().position(|n| *n == 0) else { return Default::default() };
|
||||
|
||||
postcard::from_bytes_cobs(&mut input[..length]).unwrap_or(Default::default())
|
||||
postcard::from_bytes_cobs(&mut input[..=length]).unwrap_or(Default::default())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue