* Read a 512 byte block from an SD card. * * \param[in] blockNumber Logical block to be read. * \param[out] dst Pointer to the location that will receive the data. * \return true for success, false for failure. */
| 396 | * \return true for success, false for failure. |
| 397 | */ |
| 398 | bool DiskIODriver_SPI_SD::readBlock(uint32_t blockNumber, uint8_t * const dst) { |
| 399 | #if IS_TEENSY_35_36 || IS_TEENSY_40_41 |
| 400 | return 0 == SDHC_CardReadBlock(dst, blockNumber); |
| 401 | #endif |
| 402 | |
| 403 | if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9; // Use address if not SDHC card |
| 404 | |
| 405 | #if ENABLED(SD_CHECK_AND_RETRY) |
| 406 | uint8_t retryCnt = SD_RETRY_COUNT; |
| 407 | for (;;) { |
| 408 | if (cardCommand(CMD17, blockNumber)) |
| 409 | error(SD_CARD_ERROR_CMD17); |
| 410 | else if (readData(dst, 512)) |
| 411 | return true; |
| 412 | |
| 413 | chipDeselect(); |
| 414 | if (!--retryCnt) break; |
| 415 | |
| 416 | cardCommand(CMD12, 0); // Try sending a stop command, ignore the result. |
| 417 | errorCode_ = 0; |
| 418 | } |
| 419 | return false; |
| 420 | #else |
| 421 | if (cardCommand(CMD17, blockNumber)) { |
| 422 | error(SD_CARD_ERROR_CMD17); |
| 423 | chipDeselect(); |
| 424 | return false; |
| 425 | } |
| 426 | else |
| 427 | return readData(dst, 512); |
| 428 | #endif |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * Read one data block in a multiple block read sequence |
no test coverage detected