pub fn init(&self) -> Result<SD_CardInfo, InitError> {
        /* Initialize SD_SPI */
        self.lowlevel_init();
        /* SD chip select high */
        self.CS_HIGH();
        /* NOTE: this reset doesn't always seem to work if the SD access was broken off in the
         * middle of an operation: CMDFailed(CMD0, 127). */

        /* Send dummy byte 0xFF, 10 times with CS high */
        /* Rise CS and MOSI for 80 clocks cycles */
        /* Send dummy byte 0xFF */
        self.write_data(&[0xff; 10]);
        /*------------Put SD in SPI mode--------------*/
        /* SD initialized and set to SPI mode properly */

        /* Send software reset */
        self.send_cmd(CMD::CMD0, 0, 0x95);
        let result = self.get_response();
        self.end_cmd();
        if result != 0x01 {
            return Err(InitError::CMDFailed(CMD::CMD0, result));
        }

        /* Check voltage range */
        self.send_cmd(CMD::CMD8, 0x01AA, 0x87);
        /* 0x01 or 0x05 */
        let result = self.get_response();
        let mut frame = [0u8; 4];
        self.read_data(&mut frame);
        self.end_cmd();
        if result != 0x01 {
            return Err(InitError::CMDFailed(CMD::CMD8, result));
        }
        let mut index = 255;
        while index != 0 {
            /* <ACMD> */
            self.send_cmd(CMD::CMD55, 0, 0);
            let result = self.get_response();
            self.end_cmd();
            if result != 0x01 {
                return Err(InitError::CMDFailed(CMD::CMD55, result));
            }
            /* Initiate SDC initialization process */
            self.send_cmd(CMD::ACMD41, 0x40000000, 0);
            let result = self.get_response();
            self.end_cmd();
            if result == 0x00 {
                break;
            }
            index -= 1;
        }
        if index == 0 {
            return Err(InitError::CMDFailed(CMD::ACMD41, result));
        }
        index = 255;
        let mut frame = [0u8; 4];
        while index != 0 {
            /* Read OCR */
            self.send_cmd(CMD::CMD58, 0, 1);
            let result = self.get_response();
            self.read_data(&mut frame);
            self.end_cmd();
            if result == 0 {
                break;
            }
            index -= 1;
        }
        if index == 0 {
            return Err(InitError::CMDFailed(CMD::CMD58, result));
        }
        if (frame[0] & 0x40) == 0 {
            return Err(InitError::CardCapacityStatusNotSet(frame));
        }
        self.HIGH_SPEED_ENABLE();
        self.get_cardinfo()
            .map_err(|_| InitError::CannotGetCardInfo)
    }
/*
     * Initializes the SD/SD communication in SPI mode.
     * @param  None
     * @retval The SD Response info if succeeeded, otherwise Err
     */
Initializes the SD/SD communication in SPI mode.
@param  None
@retval The SD Response info if succeeeded, otherwise Err
Initializes the SD / SD communication in SPI mode . @param None @retval The SD Response info if succeeeded otherwise Err
pub fn init(&self) -> Result<SD_CardInfo, InitError> {
        /* Initialize SD_SPI */
        self.lowlevel_init();
        /* SD chip select high */
        self.CS_HIGH();
        /* NOTE: this reset doesn't always seem to work if the SD access was broken off in the
         * middle of an operation: CMDFailed(CMD0, 127). */
        /* Send dummy byte 0xFF, 10 times with CS high */
        /* Rise CS and MOSI for 80 clocks cycles */
        /* Send dummy byte 0xFF */
        self.write_data(&[0xff; 10]);
        /*------------Put SD in SPI mode--------------*/
        /* SD initialized and set to SPI mode properly */
        /* Send software reset */
        self.send_cmd(CMD::CMD0, 0, 0x95);
        let result = self.get_response();
        self.end_cmd();
        if result != 0x01 {
            return Err(InitError::CMDFailed(CMD::CMD0, result));
        }
        /* Check voltage range */
        self.send_cmd(CMD::CMD8, 0x01AA, 0x87);
        /* 0x01 or 0x05 */
        let result = self.get_response();
        let mut frame = [0u8; 4];
        self.read_data(&mut frame);
        self.end_cmd();
        if result != 0x01 {
            return Err(InitError::CMDFailed(CMD::CMD8, result));
        }
        let mut index = 255;
        while index != 0 {
            /* <ACMD> */
            self.send_cmd(CMD::CMD55, 0, 0);
            let result = self.get_response();
            self.end_cmd();
            if result != 0x01 {
                return Err(InitError::CMDFailed(CMD::CMD55, result));
            }
            /* Initiate SDC initialization process */
            self.send_cmd(CMD::ACMD41, 0x40000000, 0);
            let result = self.get_response();
            self.end_cmd();
            if result == 0x00 {
                break;
            }
            index -= 1;
        }
        if index == 0 {
            return Err(InitError::CMDFailed(CMD::ACMD41, result));
        }
        index = 255;
        let mut frame = [0u8; 4];
        while index != 0 {
            /* Read OCR */
            self.send_cmd(CMD::CMD58, 0, 1);
            let result = self.get_response();
            self.read_data(&mut frame);
            self.end_cmd();
            if result == 0 {
                break;
            }
            index -= 1;
        }
        if index == 0 {
            return Err(InitError::CMDFailed(CMD::CMD58, result));
        }
        if (frame[0] & 0x40) == 0 {
            return Err(InitError::CardCapacityStatusNotSet(frame));
        }
        self.HIGH_SPEED_ENABLE();
        self.get_cardinfo()
            .map_err(|_| InitError::CannotGetCardInfo)
    }
pub fn init ( & self ) -> Result < SD_CardInfo , InitError > { /* Initialize SD_SPI */ self . lowlevel_init ( ) ; /* SD chip select high */ self . CS_HIGH ( ) ; /* NOTE: this reset doesn't always seem to work if the SD access was broken off in the
         * middle of an operation: CMDFailed(CMD0, 127). */ /* Send dummy byte 0xFF, 10 times with CS high */ /* Rise CS and MOSI for 80 clocks cycles */ /* Send dummy byte 0xFF */ self . write_data ( & [ 0xff ; 10 ] ) ; /*------------Put SD in SPI mode--------------*/ /* SD initialized and set to SPI mode properly */ /* Send software reset */ self . send_cmd ( CMD :: CMD0 , 0 , 0x95 ) ; let result = self . get_response ( ) ; self . end_cmd ( ) ; if result != 0x01 { return Err ( InitError :: CMDFailed ( CMD :: CMD0 , result ) ) ; } /* Check voltage range */ self . send_cmd ( CMD :: CMD8 , 0x01AA , 0x87 ) ; /* 0x01 or 0x05 */ let result = self . get_response ( ) ; let mut frame = [ 0u8 ; 4 ] ; self . read_data ( & mut frame ) ; self . end_cmd ( ) ; if result != 0x01 { return Err ( InitError :: CMDFailed ( CMD :: CMD8 , result ) ) ; } let mut index = 255 ; while index != 0 { /* <ACMD> */ self . send_cmd ( CMD :: CMD55 , 0 , 0 ) ; let result = self . get_response ( ) ; self . end_cmd ( ) ; if result != 0x01 { return Err ( InitError :: CMDFailed ( CMD :: CMD55 , result ) ) ; } /* Initiate SDC initialization process */ self . send_cmd ( CMD :: ACMD41 , 0x40000000 , 0 ) ; let result = self . get_response ( ) ; self . end_cmd ( ) ; if result == 0x00 { break ; } index -= 1 ; } if index == 0 { return Err ( InitError :: CMDFailed ( CMD :: ACMD41 , result ) ) ; } index = 255 ; let mut frame = [ 0u8 ; 4 ] ; while index != 0 { /* Read OCR */ self . send_cmd ( CMD :: CMD58 , 0 , 1 ) ; let result = self . get_response ( ) ; self . read_data ( & mut frame ) ; self . end_cmd ( ) ; if result == 0 { break ; } index -= 1 ; } if index == 0 { return Err ( InitError :: CMDFailed ( CMD :: CMD58 , result ) ) ; } if ( frame [ 0 ] & 0x40 ) == 0 { return Err ( InitError :: CardCapacityStatusNotSet ( frame ) ) ; } self . HIGH_SPEED_ENABLE ( ) ; self . get_cardinfo ( ) . map_err ( | _ | InitError :: CannotGetCardInfo ) }
Initializes the SD/SD communication in SPI mode.
Initializes the SD / SD communication in SPI mode .
&self
&self