-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1dc9481
commit be44cca
Showing
3 changed files
with
150 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Print debug support | ||
use crate::print_debug_message; | ||
use core::fmt::Write; | ||
|
||
// USB Communications Class Device support | ||
use usbd_serial::SerialPort; | ||
|
||
/// Application Digital I/O | ||
pub struct AppDio { | ||
// ... | ||
} | ||
|
||
impl AppDio { | ||
pub fn new() -> Self { | ||
AppDio { | ||
// ... | ||
} | ||
} | ||
|
||
pub fn process_incoming_data( | ||
&mut self, | ||
serial: &mut SerialPort<rp2040_hal::usb::UsbBus>, | ||
data: &[u8], | ||
) { | ||
print_debug_message!("Received data: {:?}", data); | ||
|
||
// ... | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use rp_pico as bsp; | ||
|
||
use bsp::hal::pac; | ||
use rp2040_hal::uart::UartPeripheral; | ||
use rp_pico::hal::gpio::Pin; | ||
|
||
/// Type alias for the UART peripheral 0 | ||
type UartType = UartPeripheral< | ||
rp2040_hal::uart::Enabled, | ||
pac::UART0, | ||
( | ||
Pin< | ||
rp2040_hal::gpio::bank0::Gpio0, | ||
rp2040_hal::gpio::FunctionUart, | ||
rp2040_hal::gpio::PullDown, | ||
>, | ||
Pin< | ||
rp2040_hal::gpio::bank0::Gpio1, | ||
rp2040_hal::gpio::FunctionUart, | ||
rp2040_hal::gpio::PullDown, | ||
>, | ||
), | ||
>; | ||
|
||
static mut DEBUG_UART: Option<UartType> = None; | ||
|
||
pub fn uart_debug_init(uart: UartType) { | ||
unsafe { | ||
DEBUG_UART = Some(uart); | ||
} | ||
} | ||
|
||
pub fn uart_debug_print(data: &[u8]) { | ||
unsafe { | ||
if let Some(uart) = DEBUG_UART.as_ref() { | ||
uart.write_full_blocking(data); | ||
} | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! print_debug_message { | ||
($fmt:expr) => {{ | ||
uart_debug_print($fmt); | ||
}}; | ||
($fmt:expr, $arg0:expr) => {{ | ||
let mut debug_message = heapless::String::<512>::new(); | ||
writeln!(&mut debug_message, $fmt, $arg0).unwrap(); | ||
crate::uart_debug_print(debug_message.as_bytes()); | ||
}}; | ||
($fmt:expr, $arg0:expr, $arg1:expr) => {{ | ||
let mut debug_message = String::<512>::new(); | ||
writeln!(&mut debug_message, $fmt, $arg0, $arg1).unwrap(); | ||
crate::uart_debug_print(debug_message.as_bytes()); | ||
}}; | ||
} |