|
| 1 | +//! # Secure Digital I/O - Slave Mode |
| 2 | +//! |
| 3 | +//! ## Overiew |
| 4 | +//! |
| 5 | +//! The peripheral can be used to transfer data over the SDIO bus in `Slave` |
| 6 | +//! mode. |
| 7 | +
|
| 8 | +use embedded_hal::mmc::{ |
| 9 | + CardMode, |
| 10 | + CardType, |
| 11 | + FifoStatus, |
| 12 | + MmcOps, |
| 13 | + Reset, |
| 14 | + command::MmcCommand, |
| 15 | + response::MmcResponse, |
| 16 | + tuning::{TuningMode, TuningWidth}, |
| 17 | +}; |
| 18 | + |
| 19 | +mod slc; |
| 20 | +mod slchost; |
| 21 | + |
| 22 | +pub use slc::*; |
| 23 | +pub use slchost::*; |
| 24 | + |
| 25 | +/// SDIO peripheral instance. |
| 26 | +pub trait PeripheralInstance: crate::private::Sealed { |
| 27 | + /// Represents the peripheral information type containing the register |
| 28 | + /// block. |
| 29 | + type Info; |
| 30 | + |
| 31 | + /// Gets a static shared reference to the peripheral information. |
| 32 | + fn info(&self) -> &'static Self::Info; |
| 33 | +} |
| 34 | + |
| 35 | +/// Represents the SDIO 2.0 peripheral for the microcontroller. |
| 36 | +#[derive(Debug)] |
| 37 | +pub struct Sdio<'d> { |
| 38 | + slc: AnySlc<'d>, |
| 39 | + slchost: AnySlchost<'d>, |
| 40 | +} |
| 41 | + |
| 42 | +impl<'d> Sdio<'d> { |
| 43 | + /// Creates a new [Sdio]. |
| 44 | + /// |
| 45 | + /// # Example |
| 46 | + /// |
| 47 | + /// ```rust,no_run |
| 48 | + /// use esp_hal::sdio::Sdio; |
| 49 | + /// |
| 50 | + /// use crate::peripheral::Peripherals; |
| 51 | + /// |
| 52 | + /// let dp = Peripheral::take().unwrap(); |
| 53 | + /// let _sdio = Sdio::new(dp.slc, dp.slchost); |
| 54 | + /// ``` |
| 55 | + pub fn new(slc: impl SlcInstance + 'd, slchost: impl SlchostInstance + 'd) -> Self { |
| 56 | + Self { |
| 57 | + slc: slc.degrade(), |
| 58 | + slchost: slchost.degrade(), |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + /// Gets a static reference to the SLC information. |
| 63 | + pub fn slc(&self) -> &'static SlcInfo { |
| 64 | + self.slc.info() |
| 65 | + } |
| 66 | + |
| 67 | + /// Gets a static reference to the SLCHOST information. |
| 68 | + pub fn slchost(&self) -> &'static SlchostInfo { |
| 69 | + self.slchost.info() |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +/// Represents the error variants for SDIO peripherals. |
| 74 | +#[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 75 | +pub enum Error { |
| 76 | + /// Indicates a general error occured. |
| 77 | + General, |
| 78 | + /// Indicates use of an illegal command. |
| 79 | + IllegalCommand, |
| 80 | + /// Indicates a CRC error from the previous command. |
| 81 | + Crc, |
| 82 | + /// The function and/or type is unimplemented. |
| 83 | + Unimplemented, |
| 84 | +} |
| 85 | + |
| 86 | +impl Error { |
| 87 | + /// Creates a new [Error]. |
| 88 | + pub const fn new() -> Self { |
| 89 | + Self::Unimplemented |
| 90 | + } |
| 91 | + |
| 92 | + /// Creates an general [Error]. |
| 93 | + #[inline] |
| 94 | + pub const fn general() -> Self { |
| 95 | + Self::General |
| 96 | + } |
| 97 | + |
| 98 | + /// Creates an illegal command [Error]. |
| 99 | + #[inline] |
| 100 | + pub const fn illegal_command() -> Self { |
| 101 | + Self::IllegalCommand |
| 102 | + } |
| 103 | + |
| 104 | + /// Creates an crc [Error]. |
| 105 | + #[inline] |
| 106 | + pub const fn crc() -> Self { |
| 107 | + Self::Crc |
| 108 | + } |
| 109 | + |
| 110 | + /// Creates an unimplemented [Error]. |
| 111 | + #[inline] |
| 112 | + pub const fn unimplemented() -> Self { |
| 113 | + Self::Unimplemented |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +impl Default for Error { |
| 118 | + fn default() -> Self { |
| 119 | + Self::new() |
| 120 | + } |
| 121 | +} |
| 122 | + |
| 123 | +impl core::fmt::Display for Error { |
| 124 | + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 125 | + match self { |
| 126 | + Self::General => write!(f, "general"), |
| 127 | + Self::IllegalCommand => write!(f, "illegal command"), |
| 128 | + Self::Crc => write!(f, "CRC"), |
| 129 | + Self::Unimplemented => write!(f, "unimplemented"), |
| 130 | + } |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +impl core::error::Error for Error {} |
| 135 | + |
| 136 | +impl<'d> MmcOps for Sdio<'d> { |
| 137 | + type Error = Error; |
| 138 | + |
| 139 | + fn card_type(&self) -> CardType { |
| 140 | + CardType::Sd |
| 141 | + } |
| 142 | + |
| 143 | + fn card_mode(&self) -> CardMode { |
| 144 | + CardMode::Sdio |
| 145 | + } |
| 146 | + |
| 147 | + fn setup_bus(&mut self) -> Result<(), Self::Error> { |
| 148 | + Err(Error::unimplemented()) |
| 149 | + } |
| 150 | + |
| 151 | + fn init(&mut self) -> Result<(), Self::Error> { |
| 152 | + Err(Error::unimplemented()) |
| 153 | + } |
| 154 | + |
| 155 | + fn set_sample_phase(&mut self, _sample_phase: u8) {} |
| 156 | + |
| 157 | + fn fifo_ready(&self, _fifo_status: FifoStatus) -> Result<(), Self::Error> { |
| 158 | + Err(Error::unimplemented()) |
| 159 | + } |
| 160 | + |
| 161 | + fn wait_for_reset(&mut self, _reset: Reset, _timeout: u64) -> Result<(), Self::Error> { |
| 162 | + Err(Error::unimplemented()) |
| 163 | + } |
| 164 | + |
| 165 | + fn wait_while_busy(&mut self, _timout_us: u64) -> Result<(), Self::Error> { |
| 166 | + Err(Error::unimplemented()) |
| 167 | + } |
| 168 | + |
| 169 | + fn write_command<C: MmcCommand>(&mut self, _cmd: &C) -> Result<(), Self::Error> { |
| 170 | + Err(Error::unimplemented()) |
| 171 | + } |
| 172 | + |
| 173 | + fn read_response<C: MmcCommand, R: MmcResponse>(&mut self, _cmd: &C) -> Result<R, Self::Error> { |
| 174 | + Err(Error::unimplemented()) |
| 175 | + } |
| 176 | + |
| 177 | + fn response_bytes<const N: usize>(&mut self, _exp_crc: bool) -> Result<[u8; N], Self::Error> { |
| 178 | + Err(Error::unimplemented()) |
| 179 | + } |
| 180 | + |
| 181 | + fn read_data(&mut self, _data: &mut [u8]) -> Result<(), Self::Error> { |
| 182 | + Err(Error::unimplemented()) |
| 183 | + } |
| 184 | + |
| 185 | + fn write_data(&mut self, _data: &[u8]) -> Result<(), Self::Error> { |
| 186 | + Err(Error::unimplemented()) |
| 187 | + } |
| 188 | + |
| 189 | + fn send_tuning(&mut self, _mode: TuningMode, _width: TuningWidth) -> Result<(), Self::Error> { |
| 190 | + Err(Error::unimplemented()) |
| 191 | + } |
| 192 | + |
| 193 | + fn interrupt(&self) -> u32 { |
| 194 | + 0 |
| 195 | + } |
| 196 | + |
| 197 | + fn set_interrupt(&mut self, _int: u32) {} |
| 198 | + |
| 199 | + fn clear_all_interrupt(&mut self) {} |
| 200 | + |
| 201 | + fn response_interrupt(&self) -> u32 { |
| 202 | + 0 |
| 203 | + } |
| 204 | + |
| 205 | + fn set_response_interrupt(&mut self, _int: u32) {} |
| 206 | + |
| 207 | + fn clear_all_response_interrupt(&mut self) {} |
| 208 | +} |
0 commit comments