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