Prusa3d Marlin fork
Public Member Functions | List of all members
Sd2Card Class Reference

Raw access to SD and SDHC flash memory cards.

#include <Sd2Card.h>

Public Member Functions

 Sd2Card ()
 
uint32_t cardSize ()
 
bool erase (uint32_t firstBlock, uint32_t lastBlock)
 
bool eraseSingleBlockEnable ()
 
void error (uint8_t code)
 
uint8_t errorCode () const
 
uint8_t errorData () const
 
bool init (uint8_t sckRateID=SPI_FULL_SPEED)
 
bool readBlock (uint32_t block, uint8_t *dst)
 
bool readCID (cid_t *cid)
 
bool readCSD (csd_t *csd)
 
bool readData (uint8_t *dst)
 
bool readStart (uint32_t blockNumber)
 
bool readStop ()
 
bool setSckRate (uint8_t sckRateID)
 
int type () const
 
bool writeBlock (uint32_t blockNumber, const uint8_t *src)
 
bool writeData (const uint8_t *src)
 
bool writeStart (uint32_t blockNumber, uint32_t eraseCount)
 
bool writeStop ()
 
uint8_t readExtMemory (uint8_t mio, uint8_t func, uint32_t addr, uint16_t count, uint8_t *dst)
 
void setFlashAirCompatible (bool flashAirCompatible)
 
bool getFlashAirCompatible () const
 

Constructor & Destructor Documentation

◆ Sd2Card()

Sd2Card::Sd2Card ( )
inline

Construct an instance of Sd2Card.

Member Function Documentation

◆ cardSize()

uint32_t Sd2Card::cardSize ( )

Determine the size of an SD flash memory card.

Returns
The number of 512 byte data blocks in the card or zero if an error occurs.

◆ erase()

bool Sd2Card::erase ( uint32_t  firstBlock,
uint32_t  lastBlock 
)

Erase a range of blocks.

Parameters
[in]firstBlockThe address of the first block in the range.
[in]lastBlockThe address of the last block in the range.
Note
This function requests the SD card to do a flash erase for a range of blocks. The data on the card after an erase operation is either 0 or 1, depends on the card vendor. The card must support single block erase.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ eraseSingleBlockEnable()

bool Sd2Card::eraseSingleBlockEnable ( )

Determine if card supports single block erase.

Returns
The value one, true, is returned if single block erase is supported. The value zero, false, is returned if single block erase is not supported.

◆ error()

void Sd2Card::error ( uint8_t  code)
inline

Set SD error code.

Parameters
[in]codevalue for error code.

◆ errorCode()

uint8_t Sd2Card::errorCode ( ) const
inline
Returns
error code for last error. See Sd2Card.h for a list of error codes.

◆ errorData()

uint8_t Sd2Card::errorData ( ) const
inline
Returns
error data for last error.

◆ init()

bool Sd2Card::init ( uint8_t  sckRateID = SPI_FULL_SPEED)

Initialize an SD flash memory card with default clock rate and chip select pin. See sd2Card::init(uint8_t sckRateID).

Returns
true for success or false for failure.

Initialize an SD flash memory card.

Parameters
[in]sckRateIDSPI clock rate selector. See setSckRate().
[in]chipSelectPinSD chip select pin number.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure. The reason for failure can be determined by calling errorCode() and errorData().

◆ readBlock()

bool Sd2Card::readBlock ( uint32_t  blockNumber,
uint8_t *  dst 
)

Read a 512 byte block from an SD card.

Parameters
[in]blockNumberLogical block to be read.
[out]dstPointer to the location that will receive the data.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ readCID()

bool Sd2Card::readCID ( cid_t cid)
inline

Read a card's CID register. The CID contains card identification information such as Manufacturer ID, Product name, Product serial number and Manufacturing date.

Parameters
[out]cidpointer to area for returned data.
Returns
true for success or false for failure.

◆ readCSD()

bool Sd2Card::readCSD ( csd_t csd)
inline

Read a card's CSD register. The CSD contains Card-Specific Data that provides information regarding access to the card's contents.

Parameters
[out]csdpointer to area for returned data.
Returns
true for success or false for failure.

◆ readData()

bool Sd2Card::readData ( uint8_t *  dst)

Read one data block in a multiple block read sequence

Parameters
[in]dstPointer to the location for the data to be read.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ readExtMemory()

uint8_t Sd2Card::readExtMemory ( uint8_t  mio,
uint8_t  func,
uint32_t  addr,
uint16_t  count,
uint8_t *  dst 
)

Read an extension register space.

Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ readStart()

bool Sd2Card::readStart ( uint32_t  blockNumber)

Start a read multiple blocks sequence.

Parameters
[in]blockNumberAddress of first block in sequence.
Note
This function is used with readData() and readStop() for optimized multiple block reads. SPI chipSelect must be low for the entire sequence.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ readStop()

bool Sd2Card::readStop ( )

End a read multiple blocks sequence.

Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ setSckRate()

bool Sd2Card::setSckRate ( uint8_t  sckRateID)

Set the SPI clock rate.

Parameters
[in]sckRateIDA value in the range [0, 6].

The SPI clock will be set to F_CPU/pow(2, 1 + sckRateID). The maximum SPI rate is F_CPU/2 for sckRateID = 0 and the minimum rate is F_CPU/128 for scsRateID = 6.

Returns
The value one, true, is returned for success and the value zero, false, is returned for an invalid value of sckRateID.

◆ type()

int Sd2Card::type ( ) const
inline

Return the card type: SD V1, SD V2 or SDHC

Returns
0 - SD V1, 1 - SD V2, or 3 - SDHC.

◆ writeBlock()

bool Sd2Card::writeBlock ( uint32_t  blockNumber,
const uint8_t *  src 
)

Writes a 512 byte block to an SD card.

Parameters
[in]blockNumberLogical block to be written.
[in]srcPointer to the location of the data to be written.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ writeData()

bool Sd2Card::writeData ( const uint8_t *  src)

Write one data block in a multiple block write sequence

Parameters
[in]srcPointer to the location of the data to be written.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ writeStart()

bool Sd2Card::writeStart ( uint32_t  blockNumber,
uint32_t  eraseCount 
)

Start a write multiple blocks sequence.

Parameters
[in]blockNumberAddress of first block in sequence.
[in]eraseCountThe number of blocks to be pre-erased.
Note
This function is used with writeData() and writeStop() for optimized multiple block writes.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ writeStop()

bool Sd2Card::writeStop ( )

End a write multiple blocks sequence.

Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

The documentation for this class was generated from the following files: