escw_mcu/common.rs
1//! Some common definations and types of this trait.
2
3// use core::fmt;
4
5/// The result type for all possible-failure function.
6pub type Result<T> = core::result::Result<T, Error>;
7
8/// The error list.
9///
10/// Every MCU fireware libraries may has their own error types.
11/// So every implementation crates need to convert between the real error types and these types.
12#[derive(Debug)]
13pub enum Error {
14    /// Transport a wrong parameters to the C function.
15    Param,
16
17    /// The periphery is still busy and can't do the request operation.
18    PeripheralBusy,
19
20    /// Some operation over the specfic waitting time.
21    WaitTimeout,
22
23    /// Unknown reason errors.
24    Unknown,
25}
26
27// impl fmt::Display for Error {
28//     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29//         match self {
30//             Error::Param => write!(f, "Ok"),
31//             Error::PeripheralBusy => write!(f, "Ok"),
32//             Error::WaitTimeout => write!(f, "Ok"),
33//             Error::Unknown => write!(f, "Ok"),
34//         }
35//     }
36// }
37
38/// The async transmission kind for some communication peripheral like UART, I2C and so on.
39///
40/// For async transmission, it means you could not blocking to wait the transmission action completed.
41/// You can switch the processor to do other codes when wait for the remote feedback signal or in the
42/// time of register operation.
43pub enum AsyncKind {
44    /// Transmit data in interrupt, it not a real asyn transmission. The processor will also take the
45    /// responsibility of the transmission.
46    /// But the difference is you cound not be blocked in your code.
47    Interrupt,
48
49    /// Transmis data with DAM, it is a real async transmission, DMA will do the transmission.
50    Dma,
51}
52
53/// The transmission direction.
54pub enum TransmitDirection {
55    /// MCU send message to another device.
56    Send,
57
58    /// MCU receive messages from another device.
59    Receive,
60
61    /// Any one of Send or Receive.
62    Any,
63}
64
65#[derive(PartialEq, Eq)]
66/// The state of a transmission action, including sending and receiving.
67pub enum TransmitState {
68    /// The transmission completed, all data has been transmisted.
69    Completed,
70
71    /// Transmited data size has been over half of the buffer.
72    Half,
73
74    /// The transmission has been aborted.
75    Aborted,
76
77    /// The transmission failed, may be some error occurred.
78    Failure,
79}