def read(self, sector): """read a sector (512 bytes) from the card. argument is the sector number (512 bytes) returns a string with the binary data""" self.command(MMC_READ_SINGLE_BLOCK, sector * 512) if self.dataToken() != 0xFE: # check answer raise MMCError_no_answer # Fehler data = hilspi.shift("\xff" * 512) hilspi.shift("\xff" * 2) # Dummy-CRC return data
def info(self): """get a dictionary with some card info in it""" info = {} self.command(MMC_SEND_CID, 0x00000000) if (self.dataToken() != 0xFE): raise MMCError("error during CID read") hilspi.shift("\xff" * 3) info["Product Name:"] = hilspi.shift("\xff" * 6) hilspi.shift("\xff" * 7) return info
def info(self): """get a dictionary with some card info in it""" info = {} self.command(MMC_SEND_CID, 0x00000000) if self.dataToken() != 0xFE: raise MMCError("error during CID read") hilspi.shift("\xff" * 3) info["Product Name:"] = hilspi.shift("\xff" * 6) hilspi.shift("\xff" * 7) return info
def write(self, sector, data): """write the given data in the specified sector""" if len(data) != 512: raise ValueError("Can only handle blocks of 512 bytes size") self.command(MMC_WRITE_BLOCK, sector * 512) if self.get() == 0xFF: raise MMCError_no_answer SpiByte(0xFE) # Start-Byte data = hilspi.shift(data) hilspi.shift("\xff" * 2) # Dummy-CRC SpiByte(0xFF) # lese Antwort-Byte for i in range(50000): if SpiByte(0xFF) != 0x00: break else: raise MMCError("error while writing data")
def SpiByte(byte): return ord(hilspi.shift(chr(byte)))