-
- // register read of length len into buffer
- mmcerror_t SD_readRegister(const uint8_t reg, const uint8_t len, uint8_t * buffer){
- uint8_t uc, rvalue = MMC_TIMEOUT_ERROR;
-
- if((SD_setBlockLength (len)) == MMC_SUCCESS){
- CS_LOW ();
- // CRC not used: 0xff as last byte
- sendCmd(reg, 0x000000, 0xff);
-
- // wait for response
- // in the R1 format (0x00 is no errors)
- if(getResponse() == 0x00){
- if(getXXResponse(0xfe) == 0xfe)
- for(uc = 0; uc < len; uc++)
- buffer[uc] = spiSendByte(0xff);
-
- // get CRC bytes (not really needed by us, but required by MMC)
- spiSendByte(0xff);
- spiSendByte(0xff);
- rvalue = MMC_SUCCESS;
+ /*
+ * feel our way out over the cliff of the card to estimate the size
+ * turns out cmd9 is not supported on sdio, as there's no csd register
+ */
+ uint32_t hackGetCardSize() {
+ uint32_t howbig = 0;
+ uint8_t b[512];
+ error_t failed;
+
+ /* we'll estimate based upon popular sizes of cards, e.g. 128mb, 256 mb, 512mb, 1gb, 2gb
+ * experimentally, we find that 512mb == ~990900 sectors, 1gb == ~1983000 sectors
+ * extrapolating down, we'll say that 247700 should be readable on a 128mb
+ * reading beyond that returns an error
+ */
+
+ failed = call SD.readBlock(0, b);
+ failed = call SD.readBlock(200000, b);
+ // if we can't get this far, we're toast anyway
+ if(!failed){
+ howbig = 247000;
+ while(!call SD.readBlock(howbig, b)){
+ howbig = howbig * 2;