Skip to content

Commit 7b507b8

Browse files
committed
blockSize
1 parent c07f405 commit 7b507b8

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

lib/storage/storage.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ static_assert(ARDUINO_USB_MODE == 0, "must be used when USB is in OTG mode");
77
#include <FFat.h>
88
#include <USB.h>
99
#include <USBMSC.h>
10+
#include <cstdint>
1011
#include <esp_err.h>
1112
#include <esp_partition.h>
1213

@@ -18,9 +19,7 @@ static_assert(ARDUINO_USB_MODE == 0, "must be used when USB is in OTG mode");
1819

1920
static USBMSC MSC;
2021

21-
static const uint32_t DISK_SECTOR_COUNT = 2 * 8; // 8KB is the smallest size that windows allow to mount
22-
static const uint16_t DISK_SECTOR_SIZE = 512; // Should be 512
23-
static const uint16_t DISC_SECTORS_PER_TABLE = 1; // each table sector can fit 170KB (340 sectors)
22+
static constexpr std::uint16_t blockSize = 512; // Should be 512
2423

2524
static const esp_partition_t *fatPartition = nullptr;
2625

@@ -30,7 +29,7 @@ static const esp_partition_t *fatPartition = nullptr;
3029
static int32_t onWrite(uint32_t lba, uint32_t offset, uint8_t *buffer, uint32_t bufsize)
3130
{
3231
HWSerial.printf("MSC WRITE: lba: %u, offset: %u, bufsize: %u\n", lba, offset, bufsize);
33-
uint32_t byteOffset = lba * DISK_SECTOR_SIZE + offset;
32+
uint32_t byteOffset = lba * blockSize + offset;
3433
// erase must be called before write
3534
ESP_ERROR_CHECK(esp_partition_erase_range(fatPartition, byteOffset, bufsize));
3635
ESP_ERROR_CHECK(esp_partition_write(fatPartition, byteOffset, buffer, bufsize));
@@ -43,7 +42,7 @@ static int32_t onWrite(uint32_t lba, uint32_t offset, uint8_t *buffer, uint32_t
4342
static int32_t onRead(uint32_t lba, uint32_t offset, void *buffer, uint32_t bufsize)
4443
{
4544
HWSerial.printf("MSC READ: lba: %u, offset: %u, bufsize: %u\n", lba, offset, bufsize);
46-
uint32_t byteOffset = lba * DISK_SECTOR_SIZE + offset;
45+
uint32_t byteOffset = lba * blockSize + offset;
4746
ESP_ERROR_CHECK(esp_partition_read(fatPartition, byteOffset, buffer, bufsize));
4847
return bufsize;
4948
}
@@ -171,6 +170,6 @@ void Storage::begin()
171170
MSC.mediaPresent(true);
172171

173172
// Set disk size, block size should be 512 regardless of spi flash page size
174-
MSC.begin(FFat.totalBytes() / DISK_SECTOR_SIZE, DISK_SECTOR_SIZE);
173+
MSC.begin(FFat.totalBytes() / blockSize, blockSize);
175174
USB.begin();
176175
}

0 commit comments

Comments
 (0)