Device::Chip::SDCard - chip driver for SD and MMC cards
Device::Chip::SDCard
use Device::Chip::SDCard; my $card = Device::Chip::SDCard->new; $card->mount( Device::Chip::Adapter::...->new )->get; $card->initialise->get; my $bytes = $card->read_block( 0 )->get; print "Read block zero:\n"; printf "%v02X\n", $bytes;
This Device::Chip subclass provides specific communication to an SD or MMC storage card attached via an SPI adapter.
At present it only supports MMC and SDSC ("standard capacity") cards, not SDHC or SDXC.
The following methods documented with a trailing call to ->get return Future instances.
->get
$card->initialise->get
Checks that an SD card is present, switches it into SPI mode and waits for its initialisation process to complete.
$n_bytes = $card->size->get
Returns the size of the media card in bytes.
$data = $card->read_csd->get;
Returns a HASH reference containing decoded fields from the SD card's CSD ("card-specific data") register.
HASH
This hash will contain the following fields:
TAAC NSAC TRAN_SPEED CCC READ_BL_LEN READ_BL_LEN_PARTIAL WRITE_BLK_MISALIGN READ_BLK_MISALIGN DSR_IMP C_SIZE VDD_R_CURR_MIN VDD_R_CURR_MAX VDD_W_CURR_MIN VDD_W_CURR_MAX C_SIZE_MULT ERASE_BLK_EN SECTOR_SIZE WP_GRP_SIZE WP_GRP_ENABLE R2W_FACTOR WRITE_BL_LEN WRITE_BL_PARTIAL FILE_FORMAT_GRP COPY PERM_WRITE_PROTECT TEMP_WRITE_PROTECT FILE_FORMAT
The hash will also contain the following calculated fields, derived from the decoded fields above for convenience of calling code.
blocks # number of blocks implied by C_SIZE / C_SIZE_MULT bytes # number of bytes of storage, implied by blocks and READ_BL_LEN
$fields = $card->read_ocr->get
Returns a HASH reference containing decoded fields from the card's OCR ("operating conditions register").
BUSY CCS UHS_II 1V8_ACCEPTED 3V5, 3V4, 3V3, ..., 2V7
$bytes = $card->read_block( $lba )->get
Returns a 512-byte bytestring containing data read from the given sector of the card.
Support block writing.
Support the different initialisation sequence (and block size requirements) of SDHC cards.
Paul Evans <leonerd@leonerd.org.uk>
To install Device::Chip::SDCard, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Device::Chip::SDCard
CPAN shell
perl -MCPAN -e shell install Device::Chip::SDCard
For more information on module installation, please visit the detailed CPAN module installation guide.