pub trait Receive<'a> {
// Required methods
fn set_receive_client(&self, client: &'a dyn ReceiveClient);
fn receive_buffer(
&self,
rx_buffer: &'static mut [u8],
rx_len: usize
) -> Result<(), (ErrorCode, &'static mut [u8])>;
fn receive_word(&self) -> Result<(), ErrorCode>;
fn receive_abort(&self) -> Result<(), ErrorCode>;
}
Required Methods§
sourcefn set_receive_client(&self, client: &'a dyn ReceiveClient)
fn set_receive_client(&self, client: &'a dyn ReceiveClient)
Set the receive client, which will he called when reads complete.
sourcefn receive_buffer(
&self,
rx_buffer: &'static mut [u8],
rx_len: usize
) -> Result<(), (ErrorCode, &'static mut [u8])>
fn receive_buffer( &self, rx_buffer: &'static mut [u8], rx_len: usize ) -> Result<(), (ErrorCode, &'static mut [u8])>
Receive rx_len
bytes into rx_buffer
, making a callback to
the ReceiveClient
when complete. If the Result<(), ErrorCode>
of
receive_buffer
’s return is Ok(())
, the struct will issue a received_buffer
callback in the future. If the value of the Result<(), ErrorCode>
is
Err()
, then the rx_buffer
argument is returned in the
Err()
. Valid ErrorCode
values are:
- OFF: The underlying hardware is not available, perhaps because it has not been initialized or in the case of a shared hardware USART controller because it is set up for SPI.
- BUSY: the UART is already receiving and has not made a
reception
complete
callback yet. - SIZE :
rx_len
is larger than the passed slice. Each byte inrx_buffer
is a UART transfer word of 8 or fewer bits. The width is determined by the UART configuration. Clients that need to transfer 9-bit words should usereceive_word
. Callingreceive_buffer
while there is an outstandingreceive_buffer
orreceive_word
operation will returnErr(BUSY, rx_buffer)
.
sourcefn receive_word(&self) -> Result<(), ErrorCode>
fn receive_word(&self) -> Result<(), ErrorCode>
Receive a single word of data. The word length is determined
by the UART configuration: it can be 6, 7, 8, or 9 bits long.
If the Result<(), ErrorCode>
is Ok(()), on completion,
received_word
will be called on the ReceiveClient
.
Other valid ErrorCode
values are:
- OFF: The underlying hardware is not available, perhaps because it has not been initialized or in the case of a shared hardware USART controller because it is set up for SPI.
- BUSY: the UART is already receiving and has not made a reception callback yet.
- FAIL: not supported or some other error.
Calling
receive_word
while there is an outstandingreceive_buffer
orreceive_word
operation will return `Err(BUSY).
sourcefn receive_abort(&self) -> Result<(), ErrorCode>
fn receive_abort(&self) -> Result<(), ErrorCode>
Abort any ongoing receive transfers and return what is in the
receive buffer with the receive_complete
callback. If
Ok(()) is returned, there will be no callback (no call to
receive
was outstanding). If there was a receive
outstanding, which is cancelled successfully then BUSY
will
be returned and there will be a callback with a Result<(), ErrorCode>
of CANCEL
. If there was a reception outstanding, which is
not cancelled successfully, then FAIL
will be returned and
there will be a later callback.