Prusa MINI Firmware overview
Sd2Card Class Reference

Raw access to SD and SDHC flash memory cards. More...

#include <Sd2Card.h>

Public Member Functions

 Sd2Card ()
 
uint32_t cardSize ()
 
bool erase (uint32_t firstBlock, uint32_t lastBlock)
 
bool eraseSingleBlockEnable ()
 
void error (const uint8_t code)
 
int errorCode () const
 
int errorData () const
 
bool init (const uint8_t sckRateID, const pin_t chipSelectPin)
 
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 (const 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, const uint32_t eraseCount)
 
bool writeStop ()
 
bool init (const uint8_t sckRateID=0, const pin_t chipSelectPin=SD_CHIP_SELECT_PIN)
 
bool readStart (const uint32_t block)
 
bool readData (uint8_t *dst)
 
bool readStop () const
 
bool writeStart (const uint32_t block, const uint32_t)
 
bool writeData (uint8_t *src)
 
bool writeStop () const
 
bool readBlock (uint32_t block, uint8_t *dst)
 
bool writeBlock (uint32_t blockNumber, const uint8_t *src)
 
uint32_t cardSize ()
 

Static Public Member Functions

static bool usbStartup ()
 
static void idle ()
 
static bool isInserted ()
 
static bool ready ()
 

Detailed Description

Raw access to SD and SDHC flash memory cards.

define SOFTWARE_SPI to use bit-bang SPI

Constructor & Destructor Documentation

◆ Sd2Card()

Sd2Card::Sd2Card ( )
96 : errorCode_(SD_CARD_ERROR_INIT_NOT_CALLED), type_(0) {}

Member Function Documentation

◆ cardSize() [1/2]

uint32_t Sd2Card::cardSize ( )

◆ erase()

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

◆ eraseSingleBlockEnable()

bool Sd2Card::eraseSingleBlockEnable ( )

◆ error()

void Sd2Card::error ( const uint8_t  code)

Set SD error code.

Parameters
[in]codevalue for error code.
106 { errorCode_ = code; }

◆ errorCode()

int Sd2Card::errorCode ( ) const
Returns
error code for last error. See Sd2Card.h for a list of error codes.
111 { return errorCode_; }

◆ errorData()

int Sd2Card::errorData ( ) const
Returns
error data for last error.
114 { return status_; }

◆ init() [1/2]

bool Sd2Card::init ( const uint8_t  sckRateID,
const pin_t  chipSelectPin 
)

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

Returns
true for success or false for failure.

◆ readBlock() [1/2]

bool Sd2Card::readBlock ( uint32_t  block,
uint8_t dst 
)
Here is the caller graph for this function:

◆ readCID()

bool Sd2Card::readCID ( cid_t cid)

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.
135 { return readRegister(CMD10, cid); }

◆ readCSD()

bool Sd2Card::readCSD ( csd_t csd)

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.
145 { return readRegister(CMD9, csd); }

◆ readData() [1/2]

bool Sd2Card::readData ( uint8_t dst)

◆ readStart() [1/2]

bool Sd2Card::readStart ( uint32_t  blockNumber)

◆ readStop() [1/2]

bool Sd2Card::readStop ( )

◆ setSckRate()

bool Sd2Card::setSckRate ( const uint8_t  sckRateID)

◆ type()

int Sd2Card::type ( ) const

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

Returns
0 - SD V1, 1 - SD V2, or 3 - SDHC.
156 {return type_;}

◆ writeBlock() [1/2]

bool Sd2Card::writeBlock ( uint32_t  blockNumber,
const uint8_t src 
)
Here is the caller graph for this function:

◆ writeData() [1/2]

bool Sd2Card::writeData ( const uint8_t src)

◆ writeStart() [1/2]

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

◆ writeStop() [1/2]

bool Sd2Card::writeStop ( )

◆ usbStartup()

static bool Sd2Card::usbStartup ( )
static

◆ init() [2/2]

bool Sd2Card::init ( const uint8_t  sckRateID = 0,
const pin_t  chipSelectPin = SD_CHIP_SELECT_PIN 
)

◆ idle()

void Sd2Card::idle ( )
static
633  {
634 }
Here is the caller graph for this function:

◆ readStart() [2/2]

bool Sd2Card::readStart ( const uint32_t  block)
60 { pos = block; return ready(); }
Here is the call graph for this function:

◆ readData() [2/2]

bool Sd2Card::readData ( uint8_t dst)
61 { return readBlock(pos++, dst); }
Here is the call graph for this function:

◆ readStop() [2/2]

bool Sd2Card::readStop ( ) const
62 { return true; }

◆ writeStart() [2/2]

bool Sd2Card::writeStart ( const uint32_t  block,
const uint32_t   
)
64 { pos = block; return ready(); }
Here is the call graph for this function:

◆ writeData() [2/2]

bool Sd2Card::writeData ( uint8_t src)
65 { return writeBlock(pos++, src); }
Here is the call graph for this function:

◆ writeStop() [2/2]

bool Sd2Card::writeStop ( ) const
66 { return true; }

◆ readBlock() [2/2]

bool Sd2Card::readBlock ( uint32_t  block,
uint8_t dst 
)

◆ writeBlock() [2/2]

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

◆ cardSize() [2/2]

uint32_t Sd2Card::cardSize ( )

◆ isInserted()

bool Sd2Card::isInserted ( )
static
629  {
630  return media_is_inserted();
631 }
Here is the call graph for this function:

◆ ready()

static bool Sd2Card::ready ( )
static
Here is the caller graph for this function:
Sd2Card::writeBlock
bool writeBlock(uint32_t blockNumber, const uint8_t *src)
media_is_inserted
bool media_is_inserted()
Definition: Marlin_CardReader.cpp:17
Sd2Card::ready
static bool ready()
CMD9
const uint8_t CMD9
Definition: SdInfo.h:47
Sd2Card::readBlock
bool readBlock(uint32_t block, uint8_t *dst)
CMD10
const uint8_t CMD10
Definition: SdInfo.h:48
SD_CARD_ERROR_INIT_NOT_CALLED
const uint8_t SD_CARD_ERROR_INIT_NOT_CALLED
Definition: Sd2Card.h:71
code
Definition: inftrees.h:24