Merge pull request #3925 from gmarino2048/gmarino/core-error

Implement `core::error::Error` for STM32 Serial Devices
This commit is contained in:
Dario Nieuwenhuis 2025-02-26 22:17:20 +00:00 committed by GitHub
commit 17301c00e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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,