diff options
| author | Damien George <damien@micropython.org> | 2022-06-10 12:48:14 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-06-10 12:56:30 +1000 |
| commit | 203b98c42b535a9c76f914b18dec4e221294b78c (patch) | |
| tree | a45c08c44a3fe17755ecf40f6a6dc679009f6d9e | |
| parent | ab6ad867935ea18c67368f5f0f9716421f201af4 (diff) | |
drivers/sdcard: Make ioctl(4), ioctl(5) return num blocks, block size.
For CSD v1.0 the computed size is in bytes, so convert it to number of
512-byte blocks, and then ioctl(4) will return the correct value.
Also implement ioctl(5) to return the block size, which is always 512.
Signed-off-by: Damien George <damien@micropython.org>
| -rw-r--r-- | drivers/sdcard/sdcard.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/sdcard/sdcard.py b/drivers/sdcard/sdcard.py index 57800a43b..edcf14cad 100644 --- a/drivers/sdcard/sdcard.py +++ b/drivers/sdcard/sdcard.py @@ -103,7 +103,8 @@ class SDCard: c_size = (csd[6] & 0b11) << 10 | csd[7] << 2 | csd[8] >> 6 c_size_mult = (csd[9] & 0b11) << 1 | csd[10] >> 7 read_bl_len = csd[5] & 0b1111 - self.sectors = (c_size + 1) * (2 ** (c_size_mult + 2)) * (2**read_bl_len) + capacity = (c_size + 1) * (2 ** (c_size_mult + 2)) * (2**read_bl_len) + self.sectors = capacity // 512 else: raise OSError("SD card CSD format not supported") # print('sectors', self.sectors) @@ -282,3 +283,5 @@ class SDCard: def ioctl(self, op, arg): if op == 4: # get number of blocks return self.sectors + if op == 5: # get block size in bytes + return 512 |
