pub fn read_block(&mut self, blockaddr: u32, block: &mut [u8; 512]) -> Result<(), Error> {
        let card = self.card()?;

        // Always read 1 block of 512 bytes
        // SDSC cards are byte addressed hence the blockaddress is in multiples of 512 bytes
        let blockaddr = match card.capacity {
            CardCapacity::SDSC => blockaddr * 512,
            _ => blockaddr,
        };
        self.cmd(cmd::set_block_length(512))?;
        self.start_datapath_transfer(512, 9, true);
        self.cmd(cmd::read_single_block(blockaddr))?;

        let mut i = 0;
        let mut sta;

        while {
            sta = self.sdio.sta.read();
            sta.rxact().bit_is_set()
        } {
            if sta.rxfifohf().bit() {
                for _ in 0..8 {
                    let bytes = self.sdio.fifo.read().bits().to_le_bytes();
                    block[i..i + 4].copy_from_slice(&bytes);
                    i += 4;
                }
            }

            if i == block.len() {
                break;
            }
        }

        status_to_error(sta)?;

        // Wait for card to be ready
        while !self.card_ready()? {}

        Ok(())
    }
/// Read a block from the card
Read a block from the card
Read a block from the card
pub fn read_block(&mut self, blockaddr: u32, block: &mut [u8; 512]) -> Result<(), Error> {
        let card = self.card()?;
        // Always read 1 block of 512 bytes
        // SDSC cards are byte addressed hence the blockaddress is in multiples of 512 bytes
        let blockaddr = match card.capacity {
            CardCapacity::SDSC => blockaddr * 512,
            _ => blockaddr,
        };
        self.cmd(cmd::set_block_length(512))?;
        self.start_datapath_transfer(512, 9, true);
        self.cmd(cmd::read_single_block(blockaddr))?;
        let mut i = 0;
        let mut sta;
        while {
            sta = self.sdio.sta.read();
            sta.rxact().bit_is_set()
        } {
            if sta.rxfifohf().bit() {
                for _ in 0..8 {
                    let bytes = self.sdio.fifo.read().bits().to_le_bytes();
                    block[i..i + 4].copy_from_slice(&bytes);
                    i += 4;
                }
            }
            if i == block.len() {
                break;
            }
        }
        status_to_error(sta)?;
        // Wait for card to be ready
        while !self.card_ready()? {}
        Ok(())
    }
pub fn read_block ( & mut self , blockaddr : u32 , block : & mut [ u8 ; 512 ] ) -> Result < ( ) , Error > { let card = self . card ( ) ? ; // Always read 1 block of 512 bytes // SDSC cards are byte addressed hence the blockaddress is in multiples of 512 bytes let blockaddr = match card . capacity { CardCapacity :: SDSC => blockaddr * 512 , _ => blockaddr , } ; self . cmd ( cmd :: set_block_length ( 512 ) ) ? ; self . start_datapath_transfer ( 512 , 9 , true ) ; self . cmd ( cmd :: read_single_block ( blockaddr ) ) ? ; let mut i = 0 ; let mut sta ; while { sta = self . sdio . sta . read ( ) ; sta . rxact ( ) . bit_is_set ( ) } { if sta . rxfifohf ( ) . bit ( ) { for _ in 0 .. 8 { let bytes = self . sdio . fifo . read ( ) . bits ( ) . to_le_bytes ( ) ; block [ i .. i + 4 ] . copy_from_slice ( & bytes ) ; i += 4 ; } } if i == block . len ( ) { break ; } } status_to_error ( sta ) ? ; // Wait for card to be ready while ! self . card_ready ( ) ? { } Ok ( ( ) ) }
Read a block from the card
Read a block from the card
&mut self
blockaddr
u32
block
&mut [u8; 512]
&mut self
blockaddr
u32
block
&mut [u8; 512]