Implement core::error::Error for STM32 Serial Devices

This commit is contained in:
Guy Marino 2025-02-26 14:14:16 -08:00
parent 00ef474b94
commit 27709df94a
No known key found for this signature in database
GPG Key ID: 09A963C8B40B2B95
3 changed files with 49 additions and 0 deletions

View File

@ -44,6 +44,24 @@ pub enum Error {
ZeroLengthTransfer,
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let message = match self {
Self::Bus => "Bus Error",
Self::Arbitration => "Arbitration Lost",
Self::Nack => "ACK Not Received",
Self::Timeout => "Request Timed Out",
Self::Crc => "CRC Mismatch",
Self::Overrun => "Buffer Overrun",
Self::ZeroLengthTransfer => "Zero-Length Transfers are not allowed",
};
write!(f, "{}", message)
}
}
impl core::error::Error for Error {}
/// I2C config
#[non_exhaustive]
#[derive(Copy, Clone)]

View File

@ -31,6 +31,21 @@ pub enum Error {
Overrun,
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let message = match self {
Self::Framing => "Invalid Framing",
Self::Crc => "Hardware CRC Check Failed",
Self::ModeFault => "Mode Fault",
Self::Overrun => "Buffer Overrun",
};
write!(f, "{}", message)
}
}
impl core::error::Error for Error {}
/// SPI bit order
#[derive(Copy, Clone)]
pub enum BitOrder {

View File

@ -293,6 +293,22 @@ pub enum Error {
BufferTooLong,
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let message = match self {
Self::Framing => "Framing Error",
Self::Noise => "Noise Error",
Self::Overrun => "RX Buffer Overrun",
Self::Parity => "Parity Check Error",
Self::BufferTooLong => "Buffer too large for DMA",
};
write!(f, "{}", message)
}
}
impl core::error::Error for Error {}
enum ReadCompletionEvent {
// DMA Read transfer completed first
DmaCompleted,