1
Fork 0

serial recv arch

This commit is contained in:
Andy Killorin 2025-07-11 23:39:21 -05:00
parent f7028b3f8c
commit 028458d80b
Signed by: ank
GPG key ID: 80BA307A6BD7A7E4

View file

@ -1,9 +1,15 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
#![feature(abi_avr_interrupt)]
use core::mem::MaybeUninit;
use arduino_hal::clock::MHz16;
use arduino_hal::hal::port::*; use arduino_hal::hal::port::*;
use arduino_hal::hal::usart::UsartReader;
use arduino_hal::pac::USART0;
use arduino_hal::port::mode::*; use arduino_hal::port::mode::*;
use embedded_hal::digital::OutputPin; use arduino_hal::prelude::*;
use panic_halt as _; use panic_halt as _;
fn shift_out(data_pin: &mut Pin<Output, PB0>, clock_pin: &mut Pin<Output, PD4>, data: &u8) { fn shift_out(data_pin: &mut Pin<Output, PB0>, clock_pin: &mut Pin<Output, PD4>, data: &u8) {
@ -34,6 +40,16 @@ fn update_shift_register(
latch_pin.set_high(); latch_pin.set_high();
} }
static mut UART_RX: MaybeUninit<UsartReader<USART0, Pin<Input, PD0>, Pin<Output, PD1>, MHz16>> = MaybeUninit::uninit();
#[avr_device::interrupt(atmega328p)]
fn USART_RX() {
let rx = unsafe{ &mut *UART_RX.as_mut_ptr() };
rx.read();
}
#[arduino_hal::entry] #[arduino_hal::entry]
fn main() -> ! { fn main() -> ! {
let dp = arduino_hal::Peripherals::take().unwrap(); let dp = arduino_hal::Peripherals::take().unwrap();
@ -65,6 +81,18 @@ fn main() -> ! {
let mut led = pins.d13.into_output(); let mut led = pins.d13.into_output();
let mut serial = arduino_hal::default_serial!(dp, pins, 115200);
avr_device::interrupt::disable();
serial.listen(arduino_hal::hal::usart::Event::RxComplete);
let (rx,tx) = serial.split();
unsafe {
UART_RX = MaybeUninit::new(rx);
avr_device::interrupt::enable();
};
loop { loop {
let mut shift_register = 0; let mut shift_register = 0;
const LEFT_FWD: u8 = 1 << 5; // 1a const LEFT_FWD: u8 = 1 << 5; // 1a