|
| 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` mode. |
| 6 | +
|
| 7 | +use embedded_hal::mmc::command::MmcCommand; |
| 8 | +use embedded_hal::mmc::response::MmcResponse; |
| 9 | +use embedded_hal::mmc::tuning::{TuningMode, TuningWidth}; |
| 10 | +use embedded_hal::mmc::{CardMode, CardType, FifoStatus, MmcOps, Reset}; |
| 11 | + |
| 12 | +pub mod error; |
| 13 | + |
| 14 | +use error::Error; |
| 15 | + |
| 16 | +mod slc; |
| 17 | +mod slchost; |
| 18 | + |
| 19 | +pub use slc::*; |
| 20 | +pub use slchost::*; |
| 21 | + |
| 22 | +/// SDIO peripheral instance. |
| 23 | +pub trait PeripheralInstance: crate::private::Sealed { |
| 24 | + /// Represents the peripheral information type containing the register block. |
| 25 | + type Info; |
| 26 | + |
| 27 | + /// Gets a static shared reference to the peripheral information. |
| 28 | + fn info(&self) -> &'static Self::Info; |
| 29 | +} |
| 30 | + |
| 31 | +/// Represents the SDIO 2.0 peripheral for the microcontroller. |
| 32 | +#[derive(Debug)] |
| 33 | +pub struct Sdio<'d> { |
| 34 | + slc: AnySlc<'d>, |
| 35 | + slchost: AnySlchost<'d>, |
| 36 | +} |
| 37 | + |
| 38 | +impl<'d> Sdio<'d> { |
| 39 | + /// Creates a new [Sdio]. |
| 40 | + /// |
| 41 | + /// # Example |
| 42 | + /// |
| 43 | + /// ```rust,no_run |
| 44 | + /// use crate::peripheral::Peripherals; |
| 45 | + /// use esp_hal::sdio::Sdio; |
| 46 | + /// |
| 47 | + /// let dp = Peripheral::take().unwrap(); |
| 48 | + /// let _sdio = Sdio::new(dp.slc, dp.slchost); |
| 49 | + /// ``` |
| 50 | + pub fn new(slc: impl SlcInstance + 'd, slchost: impl SlchostInstance + 'd) -> Self { |
| 51 | + Self { |
| 52 | + slc: slc.degrade(), |
| 53 | + slchost: slchost.degrade(), |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + /// Gets a static reference to the SLC information. |
| 58 | + pub fn slc(&self) -> &'static SlcInfo { |
| 59 | + self.slc.info() |
| 60 | + } |
| 61 | + |
| 62 | + /// Gets a static reference to the SLCHOST information. |
| 63 | + pub fn slchost(&self) -> &'static SlchostInfo { |
| 64 | + self.slchost.info() |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +impl<'d> MmcOps for Sdio<'d> { |
| 69 | + type Error = Error; |
| 70 | + |
| 71 | + fn card_type(&self) -> CardType { |
| 72 | + CardType::Sd |
| 73 | + } |
| 74 | + |
| 75 | + fn card_mode(&self) -> CardMode { |
| 76 | + CardMode::Sdio |
| 77 | + } |
| 78 | + |
| 79 | + fn setup_bus(&mut self) -> Result<(), Self::Error> { |
| 80 | + Err(Error::unimplemented()) |
| 81 | + } |
| 82 | + |
| 83 | + fn init(&mut self) -> Result<(), Self::Error> { |
| 84 | + Err(Error::unimplemented()) |
| 85 | + } |
| 86 | + |
| 87 | + fn set_sample_phase(&mut self, _sample_phase: u8) {} |
| 88 | + |
| 89 | + fn fifo_ready(&self, _fifo_status: FifoStatus) -> Result<(), Self::Error> { |
| 90 | + Err(Error::unimplemented()) |
| 91 | + } |
| 92 | + |
| 93 | + fn wait_for_reset(&mut self, _reset: Reset, _timeout: u64) -> Result<(), Self::Error> { |
| 94 | + Err(Error::unimplemented()) |
| 95 | + } |
| 96 | + |
| 97 | + fn wait_while_busy(&mut self, _timout_us: u64) -> Result<(), Self::Error> { |
| 98 | + Err(Error::unimplemented()) |
| 99 | + } |
| 100 | + |
| 101 | + fn write_command<C: MmcCommand>(&mut self, _cmd: &C) -> Result<(), Self::Error> { |
| 102 | + Err(Error::unimplemented()) |
| 103 | + } |
| 104 | + |
| 105 | + fn read_response<C: MmcCommand, R: MmcResponse>(&mut self, _cmd: &C) -> Result<R, Self::Error> { |
| 106 | + Err(Error::unimplemented()) |
| 107 | + } |
| 108 | + |
| 109 | + fn response_bytes<const N: usize>(&mut self, _exp_crc: bool) -> Result<[u8; N], Self::Error> { |
| 110 | + Err(Error::unimplemented()) |
| 111 | + } |
| 112 | + |
| 113 | + fn read_data(&mut self, _data: &mut [u8]) -> Result<(), Self::Error> { |
| 114 | + Err(Error::unimplemented()) |
| 115 | + } |
| 116 | + |
| 117 | + fn write_data(&mut self, _data: &[u8]) -> Result<(), Self::Error> { |
| 118 | + Err(Error::unimplemented()) |
| 119 | + } |
| 120 | + |
| 121 | + fn send_tuning(&mut self, _mode: TuningMode, _width: TuningWidth) -> Result<(), Self::Error> { |
| 122 | + Err(Error::unimplemented()) |
| 123 | + } |
| 124 | + |
| 125 | + fn interrupt(&self) -> u32 { |
| 126 | + 0 |
| 127 | + } |
| 128 | + |
| 129 | + fn set_interrupt(&mut self, _int: u32) {} |
| 130 | + |
| 131 | + fn clear_all_interrupt(&mut self) {} |
| 132 | + |
| 133 | + fn response_interrupt(&self) -> u32 { |
| 134 | + 0 |
| 135 | + } |
| 136 | + |
| 137 | + fn set_response_interrupt(&mut self, _int: u32) {} |
| 138 | + |
| 139 | + fn clear_all_response_interrupt(&mut self) {} |
| 140 | +} |
0 commit comments