Multi-Volume. Select Media for LVGL (#21344)

This commit is contained in:
Victor Oliveira
2021-04-13 19:34:19 -03:00
committed by GitHub
parent a5f0075a60
commit 138340ee99
29 changed files with 546 additions and 279 deletions

View File

@@ -35,47 +35,50 @@
#include "SdFatConfig.h"
#include "SdInfo.h"
#include "disk_io_driver.h"
#include <stdint.h>
uint16_t const SD_INIT_TIMEOUT = 2000, // init timeout ms
SD_ERASE_TIMEOUT = 10000, // erase timeout ms
SD_READ_TIMEOUT = 300, // read timeout ms
SD_WRITE_TIMEOUT = 600; // write time out ms
uint16_t const SD_INIT_TIMEOUT = 2000, // (ms) Init timeout
SD_ERASE_TIMEOUT = 10000, // (ms) Erase timeout
SD_READ_TIMEOUT = 300, // (ms) Read timeout
SD_WRITE_TIMEOUT = 600; // (ms) Write timeout
// SD card errors
uint8_t const SD_CARD_ERROR_CMD0 = 0x01, // timeout error for command CMD0 (initialize card in SPI mode)
SD_CARD_ERROR_CMD8 = 0x02, // CMD8 was not accepted - not a valid SD card
SD_CARD_ERROR_CMD12 = 0x03, // card returned an error response for CMD12 (write stop)
SD_CARD_ERROR_CMD17 = 0x04, // card returned an error response for CMD17 (read block)
SD_CARD_ERROR_CMD18 = 0x05, // card returned an error response for CMD18 (read multiple block)
SD_CARD_ERROR_CMD24 = 0x06, // card returned an error response for CMD24 (write block)
SD_CARD_ERROR_CMD25 = 0x07, // WRITE_MULTIPLE_BLOCKS command failed
SD_CARD_ERROR_CMD58 = 0x08, // card returned an error response for CMD58 (read OCR)
SD_CARD_ERROR_ACMD23 = 0x09, // SET_WR_BLK_ERASE_COUNT failed
SD_CARD_ERROR_ACMD41 = 0x0A, // ACMD41 initialization process timeout
SD_CARD_ERROR_BAD_CSD = 0x0B, // card returned a bad CSR version field
SD_CARD_ERROR_ERASE = 0x0C, // erase block group command failed
SD_CARD_ERROR_ERASE_SINGLE_BLOCK = 0x0D, // card not capable of single block erase
SD_CARD_ERROR_ERASE_TIMEOUT = 0x0E, // Erase sequence timed out
SD_CARD_ERROR_READ = 0x0F, // card returned an error token instead of read data
SD_CARD_ERROR_READ_REG = 0x10, // read CID or CSD failed
SD_CARD_ERROR_READ_TIMEOUT = 0x11, // timeout while waiting for start of read data
SD_CARD_ERROR_STOP_TRAN = 0x12, // card did not accept STOP_TRAN_TOKEN
SD_CARD_ERROR_WRITE = 0x13, // card returned an error token as a response to a write operation
SD_CARD_ERROR_WRITE_BLOCK_ZERO = 0x14, // REMOVE - not used ... attempt to write protected block zero
SD_CARD_ERROR_WRITE_MULTIPLE = 0x15, // card did not go ready for a multiple block write
SD_CARD_ERROR_WRITE_PROGRAMMING = 0x16, // card returned an error to a CMD13 status check after a write
SD_CARD_ERROR_WRITE_TIMEOUT = 0x17, // timeout occurred during write programming
SD_CARD_ERROR_SCK_RATE = 0x18, // incorrect rate selected
SD_CARD_ERROR_INIT_NOT_CALLED = 0x19, // init() not called
// 0x1A is unused now, it was: card returned an error for CMD59 (CRC_ON_OFF)
SD_CARD_ERROR_READ_CRC = 0x1B; // invalid read CRC
typedef enum : uint8_t {
SD_CARD_ERROR_CMD0 = 0x01, // Timeout error for command CMD0 (initialize card in SPI mode)
SD_CARD_ERROR_CMD8 = 0x02, // CMD8 was not accepted - not a valid SD card
SD_CARD_ERROR_CMD12 = 0x03, // Card returned an error response for CMD12 (write stop)
SD_CARD_ERROR_CMD17 = 0x04, // Card returned an error response for CMD17 (read block)
SD_CARD_ERROR_CMD18 = 0x05, // Card returned an error response for CMD18 (read multiple block)
SD_CARD_ERROR_CMD24 = 0x06, // Card returned an error response for CMD24 (write block)
SD_CARD_ERROR_CMD25 = 0x07, // WRITE_MULTIPLE_BLOCKS command failed
SD_CARD_ERROR_CMD58 = 0x08, // Card returned an error response for CMD58 (read OCR)
SD_CARD_ERROR_ACMD23 = 0x09, // SET_WR_BLK_ERASE_COUNT failed
SD_CARD_ERROR_ACMD41 = 0x0A, // ACMD41 initialization process timeout
SD_CARD_ERROR_BAD_CSD = 0x0B, // Card returned a bad CSR version field
SD_CARD_ERROR_ERASE = 0x0C, // Erase block group command failed
SD_CARD_ERROR_ERASE_SINGLE_BLOCK = 0x0D, // Card not capable of single block erase
SD_CARD_ERROR_ERASE_TIMEOUT = 0x0E, // Erase sequence timed out
SD_CARD_ERROR_READ = 0x0F, // Card returned an error token instead of read data
SD_CARD_ERROR_READ_REG = 0x10, // Read CID or CSD failed
SD_CARD_ERROR_READ_TIMEOUT = 0x11, // Timeout while waiting for start of read data
SD_CARD_ERROR_STOP_TRAN = 0x12, // Card did not accept STOP_TRAN_TOKEN
SD_CARD_ERROR_WRITE = 0x13, // Card returned an error token as a response to a write operation
SD_CARD_ERROR_WRITE_BLOCK_ZERO = 0x14, // REMOVE - not used ... attempt to write protected block zero
SD_CARD_ERROR_WRITE_MULTIPLE = 0x15, // Card did not go ready for a multiple block write
SD_CARD_ERROR_WRITE_PROGRAMMING = 0x16, // Card returned an error to a CMD13 status check after a write
SD_CARD_ERROR_WRITE_TIMEOUT = 0x17, // Timeout occurred during write programming
SD_CARD_ERROR_SCK_RATE = 0x18, // Incorrect rate selected
SD_CARD_ERROR_INIT_NOT_CALLED = 0x19, // Init() not called
// 0x1A is unused now, it was: card returned an error for CMD59 (CRC_ON_OFF)
SD_CARD_ERROR_READ_CRC = 0x1B // Invalid read CRC
} sd_error_code_t;
// card types
uint8_t const SD_CARD_TYPE_SD1 = 1, // Standard capacity V1 SD card
SD_CARD_TYPE_SD2 = 2, // Standard capacity V2 SD card
SD_CARD_TYPE_SDHC = 3; // High Capacity SD card
uint8_t const SD_CARD_TYPE_SD1 = 1, // Standard capacity V1 SD card
SD_CARD_TYPE_SD2 = 2, // Standard capacity V2 SD card
SD_CARD_TYPE_SDHC = 3; // High Capacity SD card
/**
* Define SOFTWARE_SPI to use bit-bang SPI
@@ -93,12 +96,11 @@ uint8_t const SD_CARD_TYPE_SD1 = 1, // Standard capacity V1
* \class Sd2Card
* \brief Raw access to SD and SDHC flash memory cards.
*/
class Sd2Card {
class DiskIODriver_SPI_SD : public DiskIODriver {
public:
Sd2Card() : errorCode_(SD_CARD_ERROR_INIT_NOT_CALLED), type_(0) {}
DiskIODriver_SPI_SD() : errorCode_(SD_CARD_ERROR_INIT_NOT_CALLED), type_(0) {}
uint32_t cardSize();
bool erase(uint32_t firstBlock, uint32_t lastBlock);
bool eraseSingleBlockEnable();
@@ -106,7 +108,7 @@ public:
* Set SD error code.
* \param[in] code value for error code.
*/
inline void error(const uint8_t code) { errorCode_ = code; }
void error(const uint8_t code);
/**
* \return error code for last error. See Sd2Card.h for a list of error codes.
@@ -122,9 +124,15 @@ public:
*
* \return true for success or false for failure.
*/
bool init(const uint8_t sckRateID, const pin_t chipSelectPin);
bool init(const uint8_t sckRateID, const pin_t chipSelectPin) override;
bool readBlock(uint32_t block, uint8_t *dst);
bool setSckRate(const uint8_t sckRateID);
/**
* Return the card type: SD V1, SD V2 or SDHC
* \return 0 - SD V1, 1 - SD V2, or 3 - SDHC.
*/
int type() const { return type_; }
/**
* Read a card's CID register. The CID contains card identification
@@ -145,24 +153,27 @@ public:
*
* \return true for success or false for failure.
*/
inline bool readCSD(csd_t *csd) { return readRegister(CMD9, csd); }
inline bool readCSD(csd_t *csd) override { return readRegister(CMD9, csd); }
bool readData(uint8_t *dst);
bool readStart(uint32_t blockNumber);
bool readStop();
bool setSckRate(const uint8_t sckRateID);
bool readData(uint8_t *dst) override;
bool readStart(uint32_t blockNumber) override;
bool readStop() override;
/**
* Return the card type: SD V1, SD V2 or SDHC
* \return 0 - SD V1, 1 - SD V2, or 3 - SDHC.
*/
int type() const {return type_;}
bool writeBlock(uint32_t blockNumber, const uint8_t *src);
bool writeData(const uint8_t *src);
bool writeStart(uint32_t blockNumber, const uint32_t eraseCount);
bool writeStop();
bool writeData(const uint8_t *src) override;
bool writeStart(const uint32_t blockNumber, const uint32_t eraseCount) override;
bool writeStop() override;
bool readBlock(uint32_t block, uint8_t *dst) override;
bool writeBlock(uint32_t blockNumber, const uint8_t *src) override;
uint32_t cardSize() override;
bool isReady() override { return ready; };
void idle() override {}
private:
bool ready = false;
uint8_t chipSelectPin_,
errorCode_,
spiRate_,