feat: Remove nb stuff from usb_serial_jtag

This commit is contained in:
Sergio Gasquez 2025-01-08 11:27:18 +01:00
parent 8dadabb5d4
commit 8be4ff21a9

View File

@ -198,28 +198,6 @@ where
Ok(()) Ok(())
} }
/// Write data to the serial output in a non-blocking manner
/// Requires manual flushing (automatically flushed every 64 bytes)
pub fn write_byte_nb(&mut self, word: u8) -> Option<()> {
let reg_block = USB_DEVICE::register_block();
if reg_block
.ep1_conf()
.read()
.serial_in_ep_data_free()
.bit_is_set()
{
// the FIFO is not full
unsafe {
reg_block.ep1().write(|w| w.rdwr_byte().bits(word));
}
Some(())
} else {
None
}
}
/// Flush the output FIFO and block until it has been sent /// Flush the output FIFO and block until it has been sent
pub fn flush_tx(&mut self) -> Result<(), Error> { pub fn flush_tx(&mut self) -> Result<(), Error> {
let reg_block = USB_DEVICE::register_block(); let reg_block = USB_DEVICE::register_block();
@ -231,18 +209,6 @@ where
Ok(()) Ok(())
} }
/// Flush the output FIFO but don't block if it isn't ready immediately
pub fn flush_tx_nb(&mut self) -> Option<()> {
let reg_block = USB_DEVICE::register_block();
reg_block.ep1_conf().modify(|_, w| w.wr_done().set_bit());
if reg_block.ep1_conf().read().bits() & 0b011 == 0b000 {
None
} else {
Some(())
}
}
} }
impl<'d, Dm> UsbSerialJtagRx<'d, Dm> impl<'d, Dm> UsbSerialJtagRx<'d, Dm>
@ -407,22 +373,11 @@ where
self.tx.write_bytes(data) self.tx.write_bytes(data)
} }
/// Write data to the serial output in a non-blocking manner
/// Requires manual flushing (automatically flushed every 64 bytes)
pub fn write_byte_nb(&mut self, word: u8) -> Option<()> {
self.tx.write_byte_nb(word)
}
/// Flush the output FIFO and block until it has been sent /// Flush the output FIFO and block until it has been sent
pub fn flush_tx(&mut self) -> Result<(), Error> { pub fn flush_tx(&mut self) -> Result<(), Error> {
self.tx.flush_tx() self.tx.flush_tx()
} }
/// Flush the output FIFO but don't block if it isn't ready immediately
pub fn flush_tx_nb(&mut self) -> Option<()> {
self.tx.flush_tx_nb()
}
/// Read a single byte but don't block if it isn't ready immediately /// Read a single byte but don't block if it isn't ready immediately
pub fn read_byte(&mut self) -> Option<u8> { pub fn read_byte(&mut self) -> Option<u8> {
self.rx.read_byte() self.rx.read_byte()
@ -543,74 +498,6 @@ where
} }
} }
impl<Dm> embedded_hal_nb::serial::ErrorType for UsbSerialJtag<'_, Dm>
where
Dm: DriverMode,
{
type Error = Error;
}
impl<Dm> embedded_hal_nb::serial::ErrorType for UsbSerialJtagTx<'_, Dm>
where
Dm: DriverMode,
{
type Error = Error;
}
impl<Dm> embedded_hal_nb::serial::ErrorType for UsbSerialJtagRx<'_, Dm>
where
Dm: DriverMode,
{
type Error = Error;
}
impl<Dm> embedded_hal_nb::serial::Read for UsbSerialJtag<'_, Dm>
where
Dm: DriverMode,
{
fn read(&mut self) -> embedded_hal_nb::nb::Result<u8, Self::Error> {
embedded_hal_nb::serial::Read::read(&mut self.rx)
}
}
impl<Dm> embedded_hal_nb::serial::Read for UsbSerialJtagRx<'_, Dm>
where
Dm: DriverMode,
{
fn read(&mut self) -> embedded_hal_nb::nb::Result<u8, Self::Error> {
self.read_byte()
.ok_or(embedded_hal_nb::nb::Error::WouldBlock)
}
}
impl<Dm> embedded_hal_nb::serial::Write for UsbSerialJtag<'_, Dm>
where
Dm: DriverMode,
{
fn write(&mut self, word: u8) -> embedded_hal_nb::nb::Result<(), Self::Error> {
embedded_hal_nb::serial::Write::write(&mut self.tx, word)
}
fn flush(&mut self) -> embedded_hal_nb::nb::Result<(), Self::Error> {
embedded_hal_nb::serial::Write::flush(&mut self.tx)
}
}
impl<Dm> embedded_hal_nb::serial::Write for UsbSerialJtagTx<'_, Dm>
where
Dm: DriverMode,
{
fn write(&mut self, word: u8) -> embedded_hal_nb::nb::Result<(), Self::Error> {
self.write_byte_nb(word)
.ok_or(embedded_hal_nb::nb::Error::WouldBlock)
}
fn flush(&mut self) -> embedded_hal_nb::nb::Result<(), Self::Error> {
self.flush_tx_nb()
.ok_or(embedded_hal_nb::nb::Error::WouldBlock)
}
}
#[cfg(any(doc, feature = "unstable"))] #[cfg(any(doc, feature = "unstable"))]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
impl<Dm> embedded_io::ErrorType for UsbSerialJtag<'_, Dm> impl<Dm> embedded_io::ErrorType for UsbSerialJtag<'_, Dm>