|
|
@ -231,6 +231,13 @@ bool Sd2Card::eraseSingleBlockEnable() {
|
|
|
|
* The reason for failure can be determined by calling errorCode() and errorData().
|
|
|
|
* The reason for failure can be determined by calling errorCode() and errorData().
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
|
|
|
|
bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
|
|
|
|
|
|
|
|
#if IS_TEENSY_35_36 || IS_TEENSY_40_41
|
|
|
|
|
|
|
|
chipSelectPin_ = BUILTIN_SDCARD;
|
|
|
|
|
|
|
|
const uint8_t ret = SDHC_CardInit();
|
|
|
|
|
|
|
|
type_ = SDHC_CardGetType();
|
|
|
|
|
|
|
|
return (ret == 0);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
errorCode_ = type_ = 0;
|
|
|
|
errorCode_ = type_ = 0;
|
|
|
|
chipSelectPin_ = chipSelectPin;
|
|
|
|
chipSelectPin_ = chipSelectPin;
|
|
|
|
// 16-bit init start time allows over a minute
|
|
|
|
// 16-bit init start time allows over a minute
|
|
|
@ -332,6 +339,10 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
|
|
|
|
* \return true for success, false for failure.
|
|
|
|
* \return true for success, false for failure.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
bool Sd2Card::readBlock(uint32_t blockNumber, uint8_t* dst) {
|
|
|
|
bool Sd2Card::readBlock(uint32_t blockNumber, uint8_t* dst) {
|
|
|
|
|
|
|
|
#if IS_TEENSY_35_36 || IS_TEENSY_40_41
|
|
|
|
|
|
|
|
return 0 == SDHC_CardReadBlock(dst, blockNumber);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9; // Use address if not SDHC card
|
|
|
|
if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9; // Use address if not SDHC card
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(SD_CHECK_AND_RETRY)
|
|
|
|
#if ENABLED(SD_CHECK_AND_RETRY)
|
|
|
@ -547,6 +558,10 @@ bool Sd2Card::waitNotBusy(const millis_t timeout_ms) {
|
|
|
|
bool Sd2Card::writeBlock(uint32_t blockNumber, const uint8_t* src) {
|
|
|
|
bool Sd2Card::writeBlock(uint32_t blockNumber, const uint8_t* src) {
|
|
|
|
if (ENABLED(SDCARD_READONLY)) return false;
|
|
|
|
if (ENABLED(SDCARD_READONLY)) return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if IS_TEENSY_35_36 || IS_TEENSY_40_41
|
|
|
|
|
|
|
|
return 0 == SDHC_CardWriteBlock(src, blockNumber);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
bool success = false;
|
|
|
|
bool success = false;
|
|
|
|
if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9; // Use address if not SDHC card
|
|
|
|
if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9; // Use address if not SDHC card
|
|
|
|
if (!cardCommand(CMD24, blockNumber)) {
|
|
|
|
if (!cardCommand(CMD24, blockNumber)) {
|
|
|
|