|
1 | | -use super::Error; |
| 1 | +use bitfield::bitfield; |
2 | 2 |
|
3 | | -/// Represents an interrupt to send to the host. |
4 | | -/// |
5 | | -/// # Note |
6 | | -/// |
7 | | -/// Values derived from [esp-idf](https://github.com/espressif/esp-idf/blob/v5.4.1/components/hal/include/hal/sdio_slave_types.h) SDIO driver. |
8 | | -#[repr(u32)] |
9 | | -#[derive(Clone, Copy, Debug, Eq, PartialEq)] |
10 | | -pub enum HostInterrupt { |
| 3 | +bitfield! { |
| 4 | + /// Represents an interrupt to send to the host. |
| 5 | + /// |
| 6 | + /// # Note |
| 7 | + /// |
| 8 | + /// Values derived from [esp-idf](https://github.com/espressif/esp-idf/blob/v5.4.1/components/hal/include/hal/sdio_slave_types.h) SDIO driver. |
| 9 | + #[repr(C)] |
| 10 | + #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 11 | + pub struct HostInterrupt(u8); |
11 | 12 | /// General purpose host interrupt: 0. |
12 | | - General0 = 1 << 0, |
| 13 | + pub general0, set_general0: 0; |
13 | 14 | /// General purpose host interrupt: 1. |
14 | | - General1 = 1 << 1, |
| 15 | + pub general1, set_general1: 1; |
15 | 16 | /// General purpose host interrupt: 2. |
16 | | - General2 = 1 << 2, |
| 17 | + pub general2, set_general2: 2; |
17 | 18 | /// General purpose host interrupt: 3. |
18 | | - General3 = 1 << 3, |
| 19 | + pub general3, set_general3: 3; |
19 | 20 | /// General purpose host interrupt: 4. |
20 | | - General4 = 1 << 4, |
| 21 | + pub general4, set_general4: 4; |
21 | 22 | /// General purpose host interrupt: 5. |
22 | | - General5 = 1 << 5, |
| 23 | + pub general5, set_general5: 5; |
23 | 24 | /// General purpose host interrupt: 6. |
24 | | - General6 = 1 << 6, |
| 25 | + pub general6, set_general6: 6; |
25 | 26 | /// General purpose host interrupt: 7. |
26 | | - General7 = 1 << 7, |
27 | | - /// New packet available to send to host. |
28 | | - SendNewPacket = 1 << 23, |
| 27 | + pub general7, set_general7: 7; |
29 | 28 | } |
30 | 29 |
|
31 | 30 | impl HostInterrupt { |
32 | | - /// Bit value for general purpose host interrupt: 0. |
33 | | - pub const GENERAL_0: u32 = 1 << 0; |
34 | | - /// Bit value for general purpose host interrupt: 1. |
35 | | - pub const GENERAL_1: u32 = 1 << 1; |
36 | | - /// Bit value for general purpose host interrupt: 2. |
37 | | - pub const GENERAL_2: u32 = 1 << 2; |
38 | | - /// Bit value for general purpose host interrupt: 3. |
39 | | - pub const GENERAL_3: u32 = 1 << 3; |
40 | | - /// Bit value for general purpose host interrupt: 4. |
41 | | - pub const GENERAL_4: u32 = 1 << 4; |
42 | | - /// Bit value for general purpose host interrupt: 5. |
43 | | - pub const GENERAL_5: u32 = 1 << 5; |
44 | | - /// Bit value for general purpose host interrupt: 6. |
45 | | - pub const GENERAL_6: u32 = 1 << 6; |
46 | | - /// Bit value for general purpose host interrupt: 7. |
47 | | - pub const GENERAL_7: u32 = 1 << 7; |
48 | | - /// Bit value for new packet available to send to host. |
49 | | - pub const SEND_NEW_PACKET: u32 = 1 << 23; |
50 | | - |
51 | 31 | /// Creates a new [HostInterrupt]. |
52 | 32 | pub const fn new() -> Self { |
53 | | - Self::General0 |
| 33 | + Self(0) |
54 | 34 | } |
55 | 35 |
|
56 | | - /// Converts the [HostInterrupt] into a [`u32`]. |
57 | | - #[inline] |
58 | | - pub const fn to_u32(self) -> u32 { |
59 | | - self as u32 |
| 36 | + /// Gets the raw bit value of the [HostInterrupt]. |
| 37 | + pub const fn bits(&self) -> u8 { |
| 38 | + self.0 |
60 | 39 | } |
| 40 | +} |
61 | 41 |
|
62 | | - /// Attempts to convert a [`u32`] into a [HostInterrupt]. |
63 | | - #[inline] |
64 | | - pub const fn try_from_u32(val: u32) -> Result<Self, Error> { |
65 | | - match val { |
66 | | - Self::GENERAL_0 => Ok(Self::General0), |
67 | | - Self::GENERAL_1 => Ok(Self::General1), |
68 | | - Self::GENERAL_2 => Ok(Self::General2), |
69 | | - Self::GENERAL_3 => Ok(Self::General3), |
70 | | - Self::GENERAL_4 => Ok(Self::General4), |
71 | | - Self::GENERAL_5 => Ok(Self::General5), |
72 | | - Self::GENERAL_6 => Ok(Self::General6), |
73 | | - Self::GENERAL_7 => Ok(Self::General7), |
74 | | - Self::SEND_NEW_PACKET => Ok(Self::SendNewPacket), |
75 | | - _ => Err(Error::General), |
76 | | - } |
| 42 | +impl From<HostInterrupt> for u8 { |
| 43 | + fn from(val: HostInterrupt) -> Self { |
| 44 | + val.bits() |
77 | 45 | } |
78 | 46 | } |
79 | 47 |
|
80 | | -impl From<HostInterrupt> for u32 { |
81 | | - fn from(val: HostInterrupt) -> Self { |
82 | | - val.to_u32() |
| 48 | +impl From<u8> for HostInterrupt { |
| 49 | + fn from(val: u8) -> Self { |
| 50 | + Self(val) |
83 | 51 | } |
84 | 52 | } |
85 | 53 |
|
86 | | -impl TryFrom<u32> for HostInterrupt { |
87 | | - type Error = Error; |
| 54 | +impl Default for HostInterrupt { |
| 55 | + fn default() -> Self { |
| 56 | + Self::new() |
| 57 | + } |
| 58 | +} |
88 | 59 |
|
89 | | - fn try_from(val: u32) -> Result<Self, Self::Error> { |
90 | | - Self::try_from_u32(val) |
| 60 | +bitfield! { |
| 61 | + /// Represents an interrupt to sent from the host. |
| 62 | + /// |
| 63 | + /// # Note |
| 64 | + /// |
| 65 | + /// Values derived from [esp-idf](https://github.com/espressif/esp-idf/blob/v5.4.1/components/hal/esp32/include/hal/sdio_slave_ll.h) SDIO driver. |
| 66 | + #[repr(C)] |
| 67 | + #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 68 | + pub struct DeviceInterrupt(u8); |
| 69 | + /// General purpose host interrupt: 0. |
| 70 | + pub general0, set_general0: 0; |
| 71 | + /// General purpose host interrupt: 1. |
| 72 | + pub general1, set_general1: 1; |
| 73 | + /// General purpose host interrupt: 2. |
| 74 | + pub general2, set_general2: 2; |
| 75 | + /// General purpose host interrupt: 3. |
| 76 | + pub general3, set_general3: 3; |
| 77 | + /// General purpose host interrupt: 4. |
| 78 | + pub general4, set_general4: 4; |
| 79 | + /// General purpose host interrupt: 5. |
| 80 | + pub general5, set_general5: 5; |
| 81 | + /// General purpose host interrupt: 6. |
| 82 | + pub general6, set_general6: 6; |
| 83 | + /// General purpose host interrupt: 7. |
| 84 | + pub general7, set_general7: 7; |
| 85 | +} |
| 86 | + |
| 87 | +impl DeviceInterrupt { |
| 88 | + /// Creates a new [DeviceInterrupt]. |
| 89 | + pub const fn new() -> Self { |
| 90 | + Self(0) |
| 91 | + } |
| 92 | + |
| 93 | + /// Gets the raw bit value of the [DeviceInterrupt]. |
| 94 | + pub const fn bits(&self) -> u8 { |
| 95 | + self.0 |
91 | 96 | } |
92 | 97 | } |
93 | 98 |
|
94 | | -impl Default for HostInterrupt { |
| 99 | +impl From<DeviceInterrupt> for u8 { |
| 100 | + fn from(val: DeviceInterrupt) -> Self { |
| 101 | + val.bits() |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +impl From<u8> for DeviceInterrupt { |
| 106 | + fn from(val: u8) -> Self { |
| 107 | + Self(val) |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +impl Default for DeviceInterrupt { |
95 | 112 | fn default() -> Self { |
96 | 113 | Self::new() |
97 | 114 | } |
|
0 commit comments