0
0
Fork 0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2025-03-15 18:56:13 +00:00

🎨 Apply const (#25643)

This commit is contained in:
Scott Lahteine 2023-04-07 01:33:03 -05:00 committed by GitHub
parent 74b205c7ab
commit 27b828891d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 152 additions and 154 deletions

View file

@ -782,7 +782,7 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
* - Update the Průša MMU2 * - Update the Průša MMU2
* - Handle Joystick jogging * - Handle Joystick jogging
*/ */
void idle(bool no_stepper_sleep/*=false*/) { void idle(const bool no_stepper_sleep/*=false*/) {
#ifdef MAX7219_DEBUG_PROFILE #ifdef MAX7219_DEBUG_PROFILE
CodeProfiler idle_profiler; CodeProfiler idle_profiler;
#endif #endif

View file

@ -30,7 +30,7 @@
void stop(); void stop();
// Pass true to keep steppers from timing out // Pass true to keep steppers from timing out
void idle(bool no_stepper_sleep=false); void idle(const bool no_stepper_sleep=false);
inline void idle_no_sleep() { idle(true); } inline void idle_no_sleep() { idle(true); }
#if ENABLED(G38_PROBE_TARGET) #if ENABLED(G38_PROBE_TARGET)

View file

@ -148,7 +148,7 @@ uint32_t SPIFlashStorage::m_startAddress;
#endif // HAS_SPI_FLASH_COMPRESSION #endif // HAS_SPI_FLASH_COMPRESSION
void SPIFlashStorage::beginWrite(uint32_t startAddress) { void SPIFlashStorage::beginWrite(const uint32_t startAddress) {
m_pageDataUsed = 0; m_pageDataUsed = 0;
m_currentPage = 0; m_currentPage = 0;
m_startAddress = startAddress; m_startAddress = startAddress;
@ -171,7 +171,7 @@ void SPIFlashStorage::endWrite() {
#endif #endif
} }
void SPIFlashStorage::savePage(uint8_t *buffer) { void SPIFlashStorage::savePage(uint8_t * const buffer) {
W25QXX.SPI_FLASH_BufferWrite(buffer, m_startAddress + (SPI_FLASH_PageSize * m_currentPage), SPI_FLASH_PageSize); W25QXX.SPI_FLASH_BufferWrite(buffer, m_startAddress + (SPI_FLASH_PageSize * m_currentPage), SPI_FLASH_PageSize);
// Test env // Test env
// char fname[256]; // char fname[256];
@ -181,7 +181,7 @@ void SPIFlashStorage::savePage(uint8_t *buffer) {
// fclose(fp); // fclose(fp);
} }
void SPIFlashStorage::loadPage(uint8_t *buffer) { void SPIFlashStorage::loadPage(uint8_t * const buffer) {
W25QXX.SPI_FLASH_BufferRead(buffer, m_startAddress + (SPI_FLASH_PageSize * m_currentPage), SPI_FLASH_PageSize); W25QXX.SPI_FLASH_BufferRead(buffer, m_startAddress + (SPI_FLASH_PageSize * m_currentPage), SPI_FLASH_PageSize);
// Test env // Test env
// char fname[256]; // char fname[256];
@ -260,7 +260,7 @@ void SPIFlashStorage::readPage() {
#endif #endif
} }
uint16_t SPIFlashStorage::inData(uint8_t *data, uint16_t size) { uint16_t SPIFlashStorage::inData(const uint8_t * const data, uint16_t size) {
// Don't write more than we can // Don't write more than we can
NOMORE(size, pageDataFree()); NOMORE(size, pageDataFree());
memcpy(m_pageData + m_pageDataUsed, data, size); memcpy(m_pageData + m_pageDataUsed, data, size);
@ -268,12 +268,12 @@ uint16_t SPIFlashStorage::inData(uint8_t *data, uint16_t size) {
return size; return size;
} }
void SPIFlashStorage::writeData(uint8_t *data, uint16_t size) { void SPIFlashStorage::writeData(const uint8_t *data, uint16_t size) {
// Flush a page if needed // Flush a page if needed
if (pageDataFree() == 0) flushPage(); if (pageDataFree() == 0) flushPage();
while (size > 0) { while (size > 0) {
uint16_t written = inData(data, size); const uint16_t written = inData(data, size);
size -= written; size -= written;
// Need to write more? Flush page and continue! // Need to write more? Flush page and continue!
if (size > 0) { if (size > 0) {
@ -283,7 +283,7 @@ void SPIFlashStorage::writeData(uint8_t *data, uint16_t size) {
} }
} }
void SPIFlashStorage::beginRead(uint32_t startAddress) { void SPIFlashStorage::beginRead(const uint32_t startAddress) {
m_startAddress = startAddress; m_startAddress = startAddress;
m_currentPage = 0; m_currentPage = 0;
// Nothing in memory now // Nothing in memory now
@ -293,7 +293,7 @@ void SPIFlashStorage::beginRead(uint32_t startAddress) {
#endif #endif
} }
uint16_t SPIFlashStorage::outData(uint8_t *data, uint16_t size) { uint16_t SPIFlashStorage::outData(uint8_t * const data, uint16_t size) {
// Don't read more than we have // Don't read more than we have
NOMORE(size, pageDataFree()); NOMORE(size, pageDataFree());
memcpy(data, m_pageData + m_pageDataUsed, size); memcpy(data, m_pageData + m_pageDataUsed, size);
@ -306,7 +306,7 @@ void SPIFlashStorage::readData(uint8_t *data, uint16_t size) {
if (pageDataFree() == 0) readPage(); if (pageDataFree() == 0) readPage();
while (size > 0) { while (size > 0) {
uint16_t read = outData(data, size); const uint16_t read = outData(data, size);
size -= read; size -= read;
// Need to write more? Flush page and continue! // Need to write more? Flush page and continue!
if (size > 0) { if (size > 0) {

View file

@ -75,23 +75,23 @@
class SPIFlashStorage { class SPIFlashStorage {
public: public:
// Write operation // Write operation
static void beginWrite(uint32_t startAddress); static void beginWrite(const uint32_t startAddress);
static void endWrite(); static void endWrite();
static void writeData(uint8_t *data, uint16_t size); static void writeData(const uint8_t *data, uint16_t size);
// Read operation // Read operation
static void beginRead(uint32_t startAddress); static void beginRead(const uint32_t startAddress);
static void readData(uint8_t *data, uint16_t size); static void readData(uint8_t *data, uint16_t size);
static uint32_t getCurrentPage() { return m_currentPage; } static uint32_t getCurrentPage() { return m_currentPage; }
private: private:
static void flushPage(); static void flushPage();
static void savePage(uint8_t *buffer); static void savePage(uint8_t * const buffer);
static void loadPage(uint8_t *buffer); static void loadPage(uint8_t * const buffer);
static void readPage(); static void readPage();
static uint16_t inData(uint8_t *data, uint16_t size); static uint16_t inData(const uint8_t * const data, uint16_t size);
static uint16_t outData(uint8_t *data, uint16_t size); static uint16_t outData(uint8_t * const data, uint16_t size);
static uint8_t m_pageData[SPI_FLASH_PageSize]; static uint8_t m_pageData[SPI_FLASH_PageSize];
static uint32_t m_currentPage; static uint32_t m_currentPage;

View file

@ -345,7 +345,7 @@ bool DiskIODriver_SPI_SD::init(const uint8_t sckRateID, const pin_t chipSelectPi
* \param[out] dst Pointer to the location that will receive the data. * \param[out] dst Pointer to the location that will receive the data.
* \return true for success, false for failure. * \return true for success, false for failure.
*/ */
bool DiskIODriver_SPI_SD::readBlock(uint32_t blockNumber, uint8_t *dst) { bool DiskIODriver_SPI_SD::readBlock(uint32_t blockNumber, uint8_t * const dst) {
#if IS_TEENSY_35_36 || IS_TEENSY_40_41 #if IS_TEENSY_35_36 || IS_TEENSY_40_41
return 0 == SDHC_CardReadBlock(dst, blockNumber); return 0 == SDHC_CardReadBlock(dst, blockNumber);
#endif #endif
@ -385,7 +385,7 @@ bool DiskIODriver_SPI_SD::readBlock(uint32_t blockNumber, uint8_t *dst) {
* *
* \return true for success, false for failure. * \return true for success, false for failure.
*/ */
bool DiskIODriver_SPI_SD::readData(uint8_t *dst) { bool DiskIODriver_SPI_SD::readData(uint8_t * const dst) {
chipSelect(); chipSelect();
return readData(dst, 512); return readData(dst, 512);
} }
@ -455,7 +455,7 @@ bool DiskIODriver_SPI_SD::readData(uint8_t *dst) {
#endif // SD_CHECK_AND_RETRY #endif // SD_CHECK_AND_RETRY
bool DiskIODriver_SPI_SD::readData(uint8_t *dst, const uint16_t count) { bool DiskIODriver_SPI_SD::readData(uint8_t * const dst, const uint16_t count) {
bool success = false; bool success = false;
const millis_t read_timeout = millis() + SD_READ_TIMEOUT; const millis_t read_timeout = millis() + SD_READ_TIMEOUT;
@ -487,8 +487,8 @@ bool DiskIODriver_SPI_SD::readData(uint8_t *dst, const uint16_t count) {
} }
/** read CID or CSR register */ /** read CID or CSR register */
bool DiskIODriver_SPI_SD::readRegister(const uint8_t cmd, void *buf) { bool DiskIODriver_SPI_SD::readRegister(const uint8_t cmd, void * const buf) {
uint8_t *dst = reinterpret_cast<uint8_t*>(buf); uint8_t * const dst = reinterpret_cast<uint8_t*>(buf);
if (cardCommand(cmd, 0)) { if (cardCommand(cmd, 0)) {
error(SD_CARD_ERROR_READ_REG); error(SD_CARD_ERROR_READ_REG);
chipDeselect(); chipDeselect();
@ -567,7 +567,7 @@ void DiskIODriver_SPI_SD::error(const uint8_t code) { errorCode_ = code; }
* \param[in] src Pointer to the location of the data to be written. * \param[in] src Pointer to the location of the data to be written.
* \return true for success, false for failure. * \return true for success, false for failure.
*/ */
bool DiskIODriver_SPI_SD::writeBlock(uint32_t blockNumber, const uint8_t *src) { bool DiskIODriver_SPI_SD::writeBlock(uint32_t blockNumber, const uint8_t * const src) {
if (ENABLED(SDCARD_READONLY)) return false; if (ENABLED(SDCARD_READONLY)) return false;
#if IS_TEENSY_35_36 || IS_TEENSY_40_41 #if IS_TEENSY_35_36 || IS_TEENSY_40_41
@ -598,7 +598,7 @@ bool DiskIODriver_SPI_SD::writeBlock(uint32_t blockNumber, const uint8_t *src) {
* \param[in] src Pointer to the location of the data to be written. * \param[in] src Pointer to the location of the data to be written.
* \return true for success, false for failure. * \return true for success, false for failure.
*/ */
bool DiskIODriver_SPI_SD::writeData(const uint8_t *src) { bool DiskIODriver_SPI_SD::writeData(const uint8_t * const src) {
if (ENABLED(SDCARD_READONLY)) return false; if (ENABLED(SDCARD_READONLY)) return false;
bool success = true; bool success = true;
@ -613,7 +613,7 @@ bool DiskIODriver_SPI_SD::writeData(const uint8_t *src) {
} }
// Send one block of data for write block or write multiple blocks // Send one block of data for write block or write multiple blocks
bool DiskIODriver_SPI_SD::writeData(const uint8_t token, const uint8_t *src) { bool DiskIODriver_SPI_SD::writeData(const uint8_t token, const uint8_t * const src) {
if (ENABLED(SDCARD_READONLY)) return false; if (ENABLED(SDCARD_READONLY)) return false;
const uint16_t crc = TERN(SD_CHECK_AND_RETRY, CRC_CCITT(src, 512), 0xFFFF); const uint16_t crc = TERN(SD_CHECK_AND_RETRY, CRC_CCITT(src, 512), 0xFFFF);

View file

@ -143,7 +143,7 @@ public:
* *
* \return true for success or false for failure. * \return true for success or false for failure.
*/ */
bool readCID(cid_t *cid) { return readRegister(CMD10, cid); } bool readCID(cid_t * const cid) { return readRegister(CMD10, cid); }
/** /**
* Read a card's CSD register. The CSD contains Card-Specific Data that * Read a card's CSD register. The CSD contains Card-Specific Data that
@ -153,18 +153,18 @@ public:
* *
* \return true for success or false for failure. * \return true for success or false for failure.
*/ */
inline bool readCSD(csd_t *csd) override { return readRegister(CMD9, csd); } inline bool readCSD(csd_t * const csd) override { return readRegister(CMD9, csd); }
bool readData(uint8_t *dst) override; bool readData(uint8_t * const dst) override;
bool readStart(uint32_t blockNumber) override; bool readStart(uint32_t blockNumber) override;
bool readStop() override; bool readStop() override;
bool writeData(const uint8_t *src) override; bool writeData(const uint8_t * const src) override;
bool writeStart(const uint32_t blockNumber, const uint32_t eraseCount) override; bool writeStart(uint32_t blockNumber, const uint32_t eraseCount) override;
bool writeStop() override; bool writeStop() override;
bool readBlock(uint32_t block, uint8_t *dst) override; bool readBlock(uint32_t blockNumber, uint8_t * const dst) override;
bool writeBlock(uint32_t blockNumber, const uint8_t *src) override; bool writeBlock(uint32_t blockNumber, const uint8_t * const src) override;
uint32_t cardSize() override; uint32_t cardSize() override;
@ -187,11 +187,11 @@ private:
} }
uint8_t cardCommand(const uint8_t cmd, const uint32_t arg); uint8_t cardCommand(const uint8_t cmd, const uint32_t arg);
bool readData(uint8_t *dst, const uint16_t count); bool readData(uint8_t * const dst, const uint16_t count);
bool readRegister(const uint8_t cmd, void *buf); bool readRegister(const uint8_t cmd, void * const buf);
void chipDeselect(); void chipDeselect();
void chipSelect(); void chipSelect();
inline void type(const uint8_t value) { type_ = value; } inline void type(const uint8_t value) { type_ = value; }
bool waitNotBusy(const millis_t timeout_ms); bool waitNotBusy(const millis_t timeout_ms);
bool writeData(const uint8_t token, const uint8_t *src); bool writeData(const uint8_t token, const uint8_t * const src);
}; };

View file

@ -91,7 +91,7 @@ bool SdBaseFile::addDirCluster() {
// cache a file's directory entry // cache a file's directory entry
// cache the current "dirBlock_" and return the entry at index "dirIndex_" // cache the current "dirBlock_" and return the entry at index "dirIndex_"
// return pointer to cached entry or null for failure // return pointer to cached entry or null for failure
dir_t* SdBaseFile::cacheDirEntry(uint8_t action) { dir_t* SdBaseFile::cacheDirEntry(const uint8_t action) {
if (!vol_->cacheRawBlock(dirBlock_, action)) return nullptr; if (!vol_->cacheRawBlock(dirBlock_, action)) return nullptr;
return vol_->cache()->dir + dirIndex_; return vol_->cache()->dir + dirIndex_;
} }
@ -119,7 +119,7 @@ bool SdBaseFile::close() {
* Reasons for failure include file is not contiguous, file has zero length * Reasons for failure include file is not contiguous, file has zero length
* or an I/O error occurred. * or an I/O error occurred.
*/ */
bool SdBaseFile::contiguousRange(uint32_t *bgnBlock, uint32_t *endBlock) { bool SdBaseFile::contiguousRange(uint32_t * const bgnBlock, uint32_t * const endBlock) {
// error if no blocks // error if no blocks
if (firstCluster_ == 0) return false; if (firstCluster_ == 0) return false;
@ -156,7 +156,7 @@ bool SdBaseFile::contiguousRange(uint32_t *bgnBlock, uint32_t *endBlock) {
* a file is already open, the file already exists, the root * a file is already open, the file already exists, the root
* directory is full or an I/O error. * directory is full or an I/O error.
*/ */
bool SdBaseFile::createContiguous(SdBaseFile *dirFile, const char *path, uint32_t size) { bool SdBaseFile::createContiguous(SdBaseFile * const dirFile, const char * const path, const uint32_t size) {
if (ENABLED(SDCARD_READONLY)) return false; if (ENABLED(SDCARD_READONLY)) return false;
uint32_t count; uint32_t count;
@ -301,7 +301,7 @@ bool SdBaseFile::getDosName(char * const name) {
return true; return true;
} }
void SdBaseFile::getpos(filepos_t *pos) { void SdBaseFile::getpos(filepos_t * const pos) {
pos->position = curPosition_; pos->position = curPosition_;
pos->cluster = curCluster_; pos->cluster = curCluster_;
} }
@ -337,7 +337,7 @@ void SdBaseFile::ls(uint8_t flags, uint8_t indent) {
// saves 32 bytes on stack for ls recursion // saves 32 bytes on stack for ls recursion
// return 0 - EOF, 1 - normal file, or 2 - directory // return 0 - EOF, 1 - normal file, or 2 - directory
int8_t SdBaseFile::lsPrintNext(uint8_t flags, uint8_t indent) { int8_t SdBaseFile::lsPrintNext(const uint8_t flags, const uint8_t indent) {
dir_t dir; dir_t dir;
uint8_t w = 0; uint8_t w = 0;
@ -400,7 +400,7 @@ uint8_t lfn_checksum(const uint8_t *name) {
} }
// Format directory name field from a 8.3 name string // Format directory name field from a 8.3 name string
bool SdBaseFile::make83Name(const char *str, uint8_t *name, const char **ptr) { bool SdBaseFile::make83Name(const char *str, uint8_t * const name, const char **ptr) {
uint8_t n = 7, // Max index until a dot is found uint8_t n = 7, // Max index until a dot is found
i = 11; i = 11;
while (i) name[--i] = ' '; // Set whole FILENAME.EXT to spaces while (i) name[--i] = ' '; // Set whole FILENAME.EXT to spaces
@ -437,13 +437,11 @@ bool SdBaseFile::make83Name(const char *str, uint8_t *name, const char **ptr) {
* Reasons for failure include this file is already open, \a parent is not a * Reasons for failure include this file is already open, \a parent is not a
* directory, \a path is invalid or already exists in \a parent. * directory, \a path is invalid or already exists in \a parent.
*/ */
bool SdBaseFile::mkdir(SdBaseFile *parent, const char *path, bool pFlag) { bool SdBaseFile::mkdir(SdBaseFile *parent, const char *path, const bool pFlag/*=true*/) {
if (ENABLED(SDCARD_READONLY)) return false; if (ENABLED(SDCARD_READONLY)) return false;
uint8_t dname[11]; SdBaseFile dir1, dir2, *sub = &dir1;
SdBaseFile dir1, dir2; SdBaseFile * const start = parent;
SdBaseFile *sub = &dir1;
SdBaseFile *start = parent;
#if ENABLED(LONG_FILENAME_WRITE_SUPPORT) #if ENABLED(LONG_FILENAME_WRITE_SUPPORT)
uint8_t dlname[LONG_FILENAME_LENGTH]; uint8_t dlname[LONG_FILENAME_LENGTH];
@ -459,6 +457,7 @@ bool SdBaseFile::mkdir(SdBaseFile *parent, const char *path, bool pFlag) {
} }
} }
uint8_t dname[11];
for (;;) { for (;;) {
if (!TERN(LONG_FILENAME_WRITE_SUPPORT, parsePath(path, dname, dlname, &path), make83Name(path, dname, &path))) return false; if (!TERN(LONG_FILENAME_WRITE_SUPPORT, parsePath(path, dname, dlname, &path), make83Name(path, dname, &path))) return false;
while (*path == '/') path++; while (*path == '/') path++;
@ -474,7 +473,7 @@ bool SdBaseFile::mkdir(SdBaseFile *parent, const char *path, bool pFlag) {
return mkdir(parent, dname OPTARG(LONG_FILENAME_WRITE_SUPPORT, dlname)); return mkdir(parent, dname OPTARG(LONG_FILENAME_WRITE_SUPPORT, dlname));
} }
bool SdBaseFile::mkdir(SdBaseFile *parent, const uint8_t dname[11] bool SdBaseFile::mkdir(SdBaseFile * const parent, const uint8_t dname[11]
OPTARG(LONG_FILENAME_WRITE_SUPPORT, const uint8_t dlname[LONG_FILENAME_LENGTH]) OPTARG(LONG_FILENAME_WRITE_SUPPORT, const uint8_t dlname[LONG_FILENAME_LENGTH])
) { ) {
if (ENABLED(SDCARD_READONLY)) return false; if (ENABLED(SDCARD_READONLY)) return false;
@ -541,7 +540,7 @@ bool SdBaseFile::mkdir(SdBaseFile *parent, const uint8_t dname[11]
* *
* \return true for success, false for failure. * \return true for success, false for failure.
*/ */
bool SdBaseFile::open(const char *path, uint8_t oflag) { bool SdBaseFile::open(const char * const path, const uint8_t oflag) {
return open(cwd_, path, oflag); return open(cwd_, path, oflag);
} }
@ -595,7 +594,7 @@ bool SdBaseFile::open(const char *path, uint8_t oflag) {
* a directory, \a path is invalid, the file does not exist * a directory, \a path is invalid, the file does not exist
* or can't be opened in the access mode specified by oflag. * or can't be opened in the access mode specified by oflag.
*/ */
bool SdBaseFile::open(SdBaseFile *dirFile, const char *path, uint8_t oflag) { bool SdBaseFile::open(SdBaseFile * const dirFile, const char *path, const uint8_t oflag) {
uint8_t dname[11]; uint8_t dname[11];
SdBaseFile dir1, dir2; SdBaseFile dir1, dir2;
SdBaseFile *parent = dirFile, *sub = &dir1; SdBaseFile *parent = dirFile, *sub = &dir1;
@ -627,9 +626,9 @@ bool SdBaseFile::open(SdBaseFile *dirFile, const char *path, uint8_t oflag) {
} }
// open with filename in dname and long filename in dlname // open with filename in dname and long filename in dlname
bool SdBaseFile::open(SdBaseFile *dirFile, const uint8_t dname[11] bool SdBaseFile::open(SdBaseFile * const dirFile, const uint8_t dname[11]
OPTARG(LONG_FILENAME_WRITE_SUPPORT, const uint8_t dlname[LONG_FILENAME_LENGTH]) OPTARG(LONG_FILENAME_WRITE_SUPPORT, const uint8_t dlname[LONG_FILENAME_LENGTH])
, uint8_t oflag , const uint8_t oflag
) { ) {
bool emptyFound = false, fileFound = false; bool emptyFound = false, fileFound = false;
uint8_t index = 0; uint8_t index = 0;
@ -876,7 +875,7 @@ bool SdBaseFile::open(SdBaseFile *dirFile, const uint8_t dname[11]
* See open() by path for definition of flags. * See open() by path for definition of flags.
* \return true for success or false for failure. * \return true for success or false for failure.
*/ */
bool SdBaseFile::open(SdBaseFile *dirFile, uint16_t index, uint8_t oflag) { bool SdBaseFile::open(SdBaseFile *dirFile, uint16_t index, const uint8_t oflag) {
vol_ = dirFile->vol_; vol_ = dirFile->vol_;
// error if already open // error if already open
@ -902,7 +901,7 @@ bool SdBaseFile::open(SdBaseFile *dirFile, uint16_t index, uint8_t oflag) {
} }
// open a cached directory entry. Assumes vol_ is initialized // open a cached directory entry. Assumes vol_ is initialized
bool SdBaseFile::openCachedEntry(uint8_t dirIndex, uint8_t oflag) { bool SdBaseFile::openCachedEntry(const uint8_t dirIndex, const uint8_t oflag) {
dir_t *p; dir_t *p;
#if ENABLED(SDCARD_READONLY) #if ENABLED(SDCARD_READONLY)
@ -962,7 +961,7 @@ bool SdBaseFile::openCachedEntry(uint8_t dirIndex, uint8_t oflag) {
* See open() by path for definition of flags. * See open() by path for definition of flags.
* \return true for success or false for failure. * \return true for success or false for failure.
*/ */
bool SdBaseFile::openNext(SdBaseFile *dirFile, uint8_t oflag) { bool SdBaseFile::openNext(SdBaseFile *dirFile, const uint8_t oflag) {
if (!dirFile) return false; if (!dirFile) return false;
// error if already open // error if already open
@ -1017,7 +1016,7 @@ bool SdBaseFile::openNext(SdBaseFile *dirFile, uint8_t oflag) {
* \return true if the dirname is a long file name (LFN) * \return true if the dirname is a long file name (LFN)
* \return false if the dirname is a short file name 8.3 (SFN) * \return false if the dirname is a short file name 8.3 (SFN)
*/ */
bool SdBaseFile::isDirNameLFN(const char *dirname) { bool SdBaseFile::isDirNameLFN(const char * const dirname) {
uint8_t length = strlen(dirname), idx = length; uint8_t length = strlen(dirname), idx = length;
bool dotFound = false; bool dotFound = false;
if (idx > 12) return true; // LFN due to filename length > 12 ("filename.ext") if (idx > 12) return true; // LFN due to filename length > 12 ("filename.ext")
@ -1048,7 +1047,7 @@ bool SdBaseFile::openNext(SdBaseFile *dirFile, uint8_t oflag) {
* The SFN is without dot ("FILENAMEEXT") * The SFN is without dot ("FILENAMEEXT")
* The LFN is complete ("Filename.ext") * The LFN is complete ("Filename.ext")
*/ */
bool SdBaseFile::parsePath(const char *path, uint8_t *name, uint8_t *lname, const char **ptrNextPath) { bool SdBaseFile::parsePath(const char *path, uint8_t * const name, uint8_t * const lname, const char **ptrNextPath) {
// Init randomizer for SFN generation // Init randomizer for SFN generation
randomSeed(millis()); randomSeed(millis());
// Parse the LFN // Parse the LFN
@ -1136,7 +1135,7 @@ bool SdBaseFile::openNext(SdBaseFile *dirFile, uint8_t oflag) {
/** /**
* Get the LFN filename block from a dir. Get the block in lname at startOffset * Get the LFN filename block from a dir. Get the block in lname at startOffset
*/ */
void SdBaseFile::getLFNName(vfat_t *pFatDir, char *lname, uint8_t sequenceNumber) { void SdBaseFile::getLFNName(vfat_t *pFatDir, char *lname, const uint8_t sequenceNumber) {
const uint8_t startOffset = (sequenceNumber - 1) * FILENAME_LENGTH; const uint8_t startOffset = (sequenceNumber - 1) * FILENAME_LENGTH;
LOOP_L_N(i, FILENAME_LENGTH) { LOOP_L_N(i, FILENAME_LENGTH) {
const uint16_t utf16_ch = (i >= 11) ? pFatDir->name3[i - 11] : (i >= 5) ? pFatDir->name2[i - 5] : pFatDir->name1[i]; const uint16_t utf16_ch = (i >= 11) ? pFatDir->name3[i - 11] : (i >= 5) ? pFatDir->name2[i - 5] : pFatDir->name1[i];
@ -1156,7 +1155,7 @@ bool SdBaseFile::openNext(SdBaseFile *dirFile, uint8_t oflag) {
/** /**
* Set the LFN filename block lname to a dir. Put the block based on sequence number * Set the LFN filename block lname to a dir. Put the block based on sequence number
*/ */
void SdBaseFile::setLFNName(vfat_t *pFatDir, char *lname, uint8_t sequenceNumber) { void SdBaseFile::setLFNName(vfat_t *pFatDir, char *lname, const uint8_t sequenceNumber) {
const uint8_t startOffset = (sequenceNumber - 1) * FILENAME_LENGTH, const uint8_t startOffset = (sequenceNumber - 1) * FILENAME_LENGTH,
nameLength = strlen(lname); nameLength = strlen(lname);
LOOP_L_N(i, FILENAME_LENGTH) { LOOP_L_N(i, FILENAME_LENGTH) {
@ -1305,7 +1304,7 @@ static void print2u(const uint8_t v) {
* \param[in] pr Print stream for output. * \param[in] pr Print stream for output.
* \param[in] fatDate The date field from a directory entry. * \param[in] fatDate The date field from a directory entry.
*/ */
void SdBaseFile::printFatDate(uint16_t fatDate) { void SdBaseFile::printFatDate(const uint16_t fatDate) {
SERIAL_ECHO(FAT_YEAR(fatDate)); SERIAL_ECHO(FAT_YEAR(fatDate));
SERIAL_CHAR('-'); SERIAL_CHAR('-');
print2u(FAT_MONTH(fatDate)); print2u(FAT_MONTH(fatDate));
@ -1322,7 +1321,7 @@ void SdBaseFile::printFatDate(uint16_t fatDate) {
* \param[in] pr Print stream for output. * \param[in] pr Print stream for output.
* \param[in] fatTime The time field from a directory entry. * \param[in] fatTime The time field from a directory entry.
*/ */
void SdBaseFile::printFatTime(uint16_t fatTime) { void SdBaseFile::printFatTime(const uint16_t fatTime) {
print2u(FAT_HOUR(fatTime)); print2u(FAT_HOUR(fatTime));
SERIAL_CHAR(':'); SERIAL_CHAR(':');
print2u(FAT_MINUTE(fatTime)); print2u(FAT_MINUTE(fatTime));
@ -1367,7 +1366,7 @@ int16_t SdBaseFile::read() {
* read() called before a file has been opened, corrupt file system * read() called before a file has been opened, corrupt file system
* or an I/O error occurred. * or an I/O error occurred.
*/ */
int16_t SdBaseFile::read(void *buf, uint16_t nbyte) { int16_t SdBaseFile::read(void * const buf, uint16_t nbyte) {
uint8_t *dst = reinterpret_cast<uint8_t*>(buf); uint8_t *dst = reinterpret_cast<uint8_t*>(buf);
uint16_t offset, toRead; uint16_t offset, toRead;
uint32_t block; // raw device block number uint32_t block; // raw device block number
@ -1429,7 +1428,7 @@ int16_t SdBaseFile::read(void *buf, uint16_t nbyte) {
* readDir() called before a directory has been opened, this is not * readDir() called before a directory has been opened, this is not
* a directory file or an I/O error occurred. * a directory file or an I/O error occurred.
*/ */
int8_t SdBaseFile::readDir(dir_t *dir, char * const longFilename) { int8_t SdBaseFile::readDir(dir_t * const dir, char * const longFilename) {
int16_t n; int16_t n;
// if not a directory file or miss-positioned return an error // if not a directory file or miss-positioned return an error
if (!isDir() || (0x1F & curPosition_)) return -1; if (!isDir() || (0x1F & curPosition_)) return -1;
@ -1676,7 +1675,7 @@ bool SdBaseFile::remove() {
* \a dirFile is not a directory, \a path is not found * \a dirFile is not a directory, \a path is not found
* or an I/O error occurred. * or an I/O error occurred.
*/ */
bool SdBaseFile::remove(SdBaseFile *dirFile, const char *path) { bool SdBaseFile::remove(SdBaseFile * const dirFile, const char * const path) {
if (ENABLED(SDCARD_READONLY)) return false; if (ENABLED(SDCARD_READONLY)) return false;
SdBaseFile file; SdBaseFile file;
@ -1715,7 +1714,7 @@ bool SdBaseFile::hide(const bool hidden) {
* Reasons for failure include \a dirFile is not open or is not a directory * Reasons for failure include \a dirFile is not open or is not a directory
* file, newPath is invalid or already exists, or an I/O error occurs. * file, newPath is invalid or already exists, or an I/O error occurs.
*/ */
bool SdBaseFile::rename(SdBaseFile *dirFile, const char *newPath) { bool SdBaseFile::rename(SdBaseFile * const dirFile, const char * const newPath) {
if (ENABLED(SDCARD_READONLY)) return false; if (ENABLED(SDCARD_READONLY)) return false;
uint32_t dirCluster = 0; uint32_t dirCluster = 0;
@ -1900,7 +1899,7 @@ bool SdBaseFile::rmRfStar() {
* \param[in] oflag Values for \a oflag are constructed by a bitwise-inclusive * \param[in] oflag Values for \a oflag are constructed by a bitwise-inclusive
* OR of open flags. see SdBaseFile::open(SdBaseFile*, const char*, uint8_t). * OR of open flags. see SdBaseFile::open(SdBaseFile*, const char*, uint8_t).
*/ */
SdBaseFile::SdBaseFile(const char *path, uint8_t oflag) { SdBaseFile::SdBaseFile(const char * const path, const uint8_t oflag) {
type_ = FAT_FILE_TYPE_CLOSED; type_ = FAT_FILE_TYPE_CLOSED;
writeError = false; writeError = false;
open(path, oflag); open(path, oflag);
@ -1943,7 +1942,7 @@ bool SdBaseFile::seekSet(const uint32_t pos) {
return true; return true;
} }
void SdBaseFile::setpos(filepos_t *pos) { void SdBaseFile::setpos(filepos_t * const pos) {
curPosition_ = pos->position; curPosition_ = pos->position;
curCluster_ = pos->cluster; curCluster_ = pos->cluster;
} }
@ -1998,7 +1997,7 @@ bool SdBaseFile::sync() {
* *
* \return true for success, false for failure. * \return true for success, false for failure.
*/ */
bool SdBaseFile::timestamp(SdBaseFile *file) { bool SdBaseFile::timestamp(SdBaseFile * const file) {
dir_t dir; dir_t dir;
// get timestamps // get timestamps
@ -2055,8 +2054,8 @@ bool SdBaseFile::timestamp(SdBaseFile *file) {
* *
* \return true for success, false for failure. * \return true for success, false for failure.
*/ */
bool SdBaseFile::timestamp(uint8_t flags, uint16_t year, uint8_t month, bool SdBaseFile::timestamp(const uint8_t flags, const uint16_t year, const uint8_t month,
uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) { const uint8_t day, const uint8_t hour, const uint8_t minute, const uint8_t second) {
if (ENABLED(SDCARD_READONLY)) return false; if (ENABLED(SDCARD_READONLY)) return false;
uint16_t dirDate, dirTime; uint16_t dirDate, dirTime;

View file

@ -89,7 +89,7 @@ uint8_t const FAT_FILE_TYPE_CLOSED = 0, // This file h
* *
* \return Packed date for dir_t entry. * \return Packed date for dir_t entry.
*/ */
static inline uint16_t FAT_DATE(uint16_t year, uint8_t month, uint8_t day) { return (year - 1980) << 9 | month << 5 | day; } static inline uint16_t FAT_DATE(const uint16_t year, const uint8_t month, const uint8_t day) { return (year - 1980) << 9 | month << 5 | day; }
/** /**
* year part of FAT directory date field * year part of FAT directory date field
@ -97,7 +97,7 @@ static inline uint16_t FAT_DATE(uint16_t year, uint8_t month, uint8_t day) { ret
* *
* \return Extracted year [1980,2107] * \return Extracted year [1980,2107]
*/ */
static inline uint16_t FAT_YEAR(uint16_t fatDate) { return 1980 + (fatDate >> 9); } static inline uint16_t FAT_YEAR(const uint16_t fatDate) { return 1980 + (fatDate >> 9); }
/** /**
* month part of FAT directory date field * month part of FAT directory date field
@ -105,7 +105,7 @@ static inline uint16_t FAT_YEAR(uint16_t fatDate) { return 1980 + (fatDate >> 9)
* *
* \return Extracted month [1,12] * \return Extracted month [1,12]
*/ */
static inline uint8_t FAT_MONTH(uint16_t fatDate) { return (fatDate >> 5) & 0xF; } static inline uint8_t FAT_MONTH(const uint16_t fatDate) { return (fatDate >> 5) & 0xF; }
/** /**
* day part of FAT directory date field * day part of FAT directory date field
@ -113,7 +113,7 @@ static inline uint8_t FAT_MONTH(uint16_t fatDate) { return (fatDate >> 5) & 0xF;
* *
* \return Extracted day [1,31] * \return Extracted day [1,31]
*/ */
static inline uint8_t FAT_DAY(uint16_t fatDate) { return fatDate & 0x1F; } static inline uint8_t FAT_DAY(const uint16_t fatDate) { return fatDate & 0x1F; }
/** /**
* time field for FAT directory entry * time field for FAT directory entry
@ -123,7 +123,7 @@ static inline uint8_t FAT_DAY(uint16_t fatDate) { return fatDate & 0x1F; }
* *
* \return Packed time for dir_t entry. * \return Packed time for dir_t entry.
*/ */
static inline uint16_t FAT_TIME(uint8_t hour, uint8_t minute, uint8_t second) { return hour << 11 | minute << 5 | second >> 1; } static inline uint16_t FAT_TIME(const uint8_t hour, const uint8_t minute, const uint8_t second) { return hour << 11 | minute << 5 | second >> 1; }
/** /**
* hour part of FAT directory time field * hour part of FAT directory time field
@ -131,7 +131,7 @@ static inline uint16_t FAT_TIME(uint8_t hour, uint8_t minute, uint8_t second) {
* *
* \return Extracted hour [0,23] * \return Extracted hour [0,23]
*/ */
static inline uint8_t FAT_HOUR(uint16_t fatTime) { return fatTime >> 11; } static inline uint8_t FAT_HOUR(const uint16_t fatTime) { return fatTime >> 11; }
/** /**
* minute part of FAT directory time field * minute part of FAT directory time field
@ -139,7 +139,7 @@ static inline uint8_t FAT_HOUR(uint16_t fatTime) { return fatTime >> 11; }
* *
* \return Extracted minute [0,59] * \return Extracted minute [0,59]
*/ */
static inline uint8_t FAT_MINUTE(uint16_t fatTime) { return (fatTime >> 5) & 0x3F; } static inline uint8_t FAT_MINUTE(const uint16_t fatTime) { return (fatTime >> 5) & 0x3F; }
/** /**
* second part of FAT directory time field * second part of FAT directory time field
@ -149,7 +149,7 @@ static inline uint8_t FAT_MINUTE(uint16_t fatTime) { return (fatTime >> 5) & 0x3
* *
* \return Extracted second [0,58] * \return Extracted second [0,58]
*/ */
static inline uint8_t FAT_SECOND(uint16_t fatTime) { return 2 * (fatTime & 0x1F); } static inline uint8_t FAT_SECOND(const uint16_t fatTime) { return 2 * (fatTime & 0x1F); }
// Default date for file timestamps is 1 Jan 2000 // Default date for file timestamps is 1 Jan 2000
uint16_t const FAT_DEFAULT_DATE = ((2000 - 1980) << 9) | (1 << 5) | 1; uint16_t const FAT_DEFAULT_DATE = ((2000 - 1980) << 9) | (1 << 5) | 1;
@ -163,7 +163,7 @@ uint16_t const FAT_DEFAULT_TIME = (1 << 11);
class SdBaseFile { class SdBaseFile {
public: public:
SdBaseFile() : writeError(false), type_(FAT_FILE_TYPE_CLOSED) {} SdBaseFile() : writeError(false), type_(FAT_FILE_TYPE_CLOSED) {}
SdBaseFile(const char *path, uint8_t oflag); SdBaseFile(const char * const path, const uint8_t oflag);
~SdBaseFile() { if (isOpen()) close(); } ~SdBaseFile() { if (isOpen()) close(); }
/** /**
@ -179,18 +179,17 @@ class SdBaseFile {
* get position for streams * get position for streams
* \param[out] pos struct to receive position * \param[out] pos struct to receive position
*/ */
void getpos(filepos_t *pos); void getpos(filepos_t * const pos);
/** /**
* set position for streams * set position for streams
* \param[out] pos struct with value for new position * \param[out] pos struct with value for new position
*/ */
void setpos(filepos_t *pos); void setpos(filepos_t * const pos);
bool close(); bool close();
bool contiguousRange(uint32_t *bgnBlock, uint32_t *endBlock); bool contiguousRange(uint32_t * const bgnBlock, uint32_t * const endBlock);
bool createContiguous(SdBaseFile *dirFile, bool createContiguous(SdBaseFile * const dirFile, const char * const path, const uint32_t size);
const char *path, uint32_t size);
/** /**
* \return The current cluster number for a file or directory. * \return The current cluster number for a file or directory.
*/ */
@ -235,7 +234,7 @@ class SdBaseFile {
* See the timestamp() function. * See the timestamp() function.
*/ */
static void dateTimeCallback( static void dateTimeCallback(
void (*dateTime)(uint16_t *date, uint16_t *time)) { void (*dateTime)(uint16_t * const date, uint16_t * const time)) {
dateTime_ = dateTime; dateTime_ = dateTime;
} }
@ -246,7 +245,7 @@ class SdBaseFile {
bool dirEntry(dir_t *dir); bool dirEntry(dir_t *dir);
static void dirName(const dir_t& dir, char *name); static void dirName(const dir_t& dir, char *name);
bool exists(const char *name); bool exists(const char *name);
int16_t fgets(char *str, int16_t num, char *delim = 0); int16_t fgets(char *str, int16_t num, char *delim=0);
/** /**
* \return The total number of bytes in a file or directory. * \return The total number of bytes in a file or directory.
@ -284,29 +283,29 @@ class SdBaseFile {
bool isRoot() const { return type_ == FAT_FILE_TYPE_ROOT_FIXED || type_ == FAT_FILE_TYPE_ROOT32; } bool isRoot() const { return type_ == FAT_FILE_TYPE_ROOT_FIXED || type_ == FAT_FILE_TYPE_ROOT32; }
bool getDosName(char * const name); bool getDosName(char * const name);
void ls(uint8_t flags = 0, uint8_t indent = 0); void ls(uint8_t flags=0, uint8_t indent=0);
bool mkdir(SdBaseFile *dir, const char *path, bool pFlag = true); bool mkdir(SdBaseFile *parent, const char *path, const bool pFlag=true);
bool open(SdBaseFile *dirFile, uint16_t index, uint8_t oflag); bool open(SdBaseFile * const dirFile, uint16_t index, const uint8_t oflag);
bool open(SdBaseFile *dirFile, const char *path, uint8_t oflag); bool open(SdBaseFile * const dirFile, const char *path, const uint8_t oflag);
bool open(const char *path, uint8_t oflag = O_READ); bool open(const char * const path, const uint8_t oflag=O_READ);
bool openNext(SdBaseFile *dirFile, uint8_t oflag); bool openNext(SdBaseFile * const dirFile, const uint8_t oflag);
bool openRoot(SdVolume *vol); bool openRoot(SdVolume * const vol);
int peek(); int peek();
static void printFatDate(uint16_t fatDate); static void printFatDate(const uint16_t fatDate);
static void printFatTime(uint16_t fatTime); static void printFatTime(const uint16_t fatTime);
bool printName(); bool printName();
int16_t read(); int16_t read();
int16_t read(void *buf, uint16_t nbyte); int16_t read(void * const buf, uint16_t nbyte);
int8_t readDir(dir_t *dir, char * const longFilename); int8_t readDir(dir_t * const dir, char * const longFilename);
static bool remove(SdBaseFile *dirFile, const char *path); static bool remove(SdBaseFile * const dirFile, const char * const path);
bool remove(); bool remove();
/** /**
* Set the file's current position to zero. * Set the file's current position to zero.
*/ */
void rewind() { seekSet(0); } void rewind() { seekSet(0); }
bool rename(SdBaseFile *dirFile, const char *newPath); bool rename(SdBaseFile * const dirFile, const char * const newPath);
bool rmdir(); bool rmdir();
bool rmRfStar(); bool rmRfStar();
@ -327,12 +326,12 @@ class SdBaseFile {
* \param[in] offset The new position in bytes from end-of-file. * \param[in] offset The new position in bytes from end-of-file.
* \return true for success or false for failure. * \return true for success or false for failure.
*/ */
bool seekEnd(const int32_t offset = 0) { return seekSet(fileSize_ + offset); } bool seekEnd(const int32_t offset=0) { return seekSet(fileSize_ + offset); }
bool seekSet(const uint32_t pos); bool seekSet(const uint32_t pos);
bool sync(); bool sync();
bool timestamp(SdBaseFile *file); bool timestamp(SdBaseFile * const file);
bool timestamp(uint8_t flag, uint16_t year, uint8_t month, uint8_t day, bool timestamp(const uint8_t flag, const uint16_t year, const uint8_t month, const uint8_t day,
uint8_t hour, uint8_t minute, uint8_t second); const uint8_t hour, const uint8_t minute, const uint8_t second);
/** /**
* Type of file. Use isFile() or isDir() instead of type() if possible. * Type of file. Use isFile() or isDir() instead of type() if possible.
@ -379,17 +378,17 @@ class SdBaseFile {
// private functions // private functions
bool addCluster(); bool addCluster();
bool addDirCluster(); bool addDirCluster();
dir_t* cacheDirEntry(uint8_t action); dir_t* cacheDirEntry(const uint8_t action);
int8_t lsPrintNext(uint8_t flags, uint8_t indent); int8_t lsPrintNext(const uint8_t flags, const uint8_t indent);
static bool make83Name(const char *str, uint8_t *name, const char **ptr); static bool make83Name(const char *str, uint8_t * const name, const char **ptr);
bool mkdir(SdBaseFile *parent, const uint8_t dname[11] bool mkdir(SdBaseFile * const parent, const uint8_t dname[11]
OPTARG(LONG_FILENAME_WRITE_SUPPORT, const uint8_t dlname[LONG_FILENAME_LENGTH]) OPTARG(LONG_FILENAME_WRITE_SUPPORT, const uint8_t dlname[LONG_FILENAME_LENGTH])
); );
bool open(SdBaseFile *dirFile, const uint8_t dname[11] bool open(SdBaseFile *dirFile, const uint8_t dname[11]
OPTARG(LONG_FILENAME_WRITE_SUPPORT, const uint8_t dlname[LONG_FILENAME_LENGTH]) OPTARG(LONG_FILENAME_WRITE_SUPPORT, const uint8_t dlname[LONG_FILENAME_LENGTH])
, uint8_t oflag , const uint8_t oflag
); );
bool openCachedEntry(uint8_t cacheIndex, uint8_t oflags); bool openCachedEntry(const uint8_t dirIndex, const uint8_t oflags);
dir_t* readDirCache(); dir_t* readDirCache();
#if ENABLED(UTF_FILENAME_SUPPORT) #if ENABLED(UTF_FILENAME_SUPPORT)
@ -399,11 +398,11 @@ class SdBaseFile {
// Long Filename create/write support // Long Filename create/write support
#if ENABLED(LONG_FILENAME_WRITE_SUPPORT) #if ENABLED(LONG_FILENAME_WRITE_SUPPORT)
static bool isDirLFN(const dir_t* dir); static bool isDirLFN(const dir_t* dir);
static bool isDirNameLFN(const char *dirname); static bool isDirNameLFN(const char * const dirname);
static bool parsePath(const char *str, uint8_t *name, uint8_t *lname, const char **ptr); static bool parsePath(const char *str, uint8_t * const name, uint8_t * const lname, const char **ptr);
// Return the number of entries needed in the FAT for this LFN // Return the number of entries needed in the FAT for this LFN
static inline uint8_t getLFNEntriesNum(const char *lname) { return (strlen(lname) + 12) / 13; } static uint8_t getLFNEntriesNum(const char * const lname) { return (strlen(lname) + 12) / 13; }
static void getLFNName(vfat_t *vFatDir, char *lname, uint8_t startOffset); static void getLFNName(vfat_t *vFatDir, char *lname, const uint8_t sequenceNumber);
static void setLFNName(vfat_t *vFatDir, char *lname, uint8_t lfnSequenceNumber); static void setLFNName(vfat_t *vFatDir, char *lname, const uint8_t sequenceNumber);
#endif #endif
}; };

View file

@ -43,7 +43,7 @@
* \param[in] oflag Values for \a oflag are constructed by a bitwise-inclusive * \param[in] oflag Values for \a oflag are constructed by a bitwise-inclusive
* OR of open flags. see SdBaseFile::open(SdBaseFile*, const char*, uint8_t). * OR of open flags. see SdBaseFile::open(SdBaseFile*, const char*, uint8_t).
*/ */
SdFile::SdFile(const char *path, uint8_t oflag) : SdBaseFile(path, oflag) { } SdFile::SdFile(const char * const path, const uint8_t oflag) : SdBaseFile(path, oflag) { }
/** /**
* Write data to an open file. * Write data to an open file.
@ -60,7 +60,7 @@ SdFile::SdFile(const char *path, uint8_t oflag) : SdBaseFile(path, oflag) { }
* include write() is called before a file has been opened, write is called * include write() is called before a file has been opened, write is called
* for a read-only file, device is full, a corrupt file system or an I/O error. * for a read-only file, device is full, a corrupt file system or an I/O error.
*/ */
int16_t SdFile::write(const void *buf, uint16_t nbyte) { return SdBaseFile::write(buf, nbyte); } int16_t SdFile::write(const void * const buf, const uint16_t nbyte) { return SdBaseFile::write(buf, nbyte); }
/** /**
* Write a byte to a file. Required by the Arduino Print class. * Write a byte to a file. Required by the Arduino Print class.
@ -68,9 +68,9 @@ int16_t SdFile::write(const void *buf, uint16_t nbyte) { return SdBaseFile::writ
* Use writeError to check for errors. * Use writeError to check for errors.
*/ */
#if ARDUINO >= 100 #if ARDUINO >= 100
size_t SdFile::write(uint8_t b) { return SdBaseFile::write(&b, 1); } size_t SdFile::write(const uint8_t b) { return SdBaseFile::write(&b, 1); }
#else #else
void SdFile::write(uint8_t b) { SdBaseFile::write(&b, 1); } void SdFile::write(const uint8_t b) { SdBaseFile::write(&b, 1); }
#endif #endif
/** /**
@ -78,7 +78,7 @@ int16_t SdFile::write(const void *buf, uint16_t nbyte) { return SdBaseFile::writ
* \param[in] str Pointer to the string. * \param[in] str Pointer to the string.
* Use writeError to check for errors. * Use writeError to check for errors.
*/ */
void SdFile::write(const char *str) { SdBaseFile::write(str, strlen(str)); } void SdFile::write(const char * const str) { SdBaseFile::write(str, strlen(str)); }
/** /**
* Write a PROGMEM string to a file. * Write a PROGMEM string to a file.
@ -94,7 +94,7 @@ void SdFile::write_P(PGM_P str) {
* \param[in] str Pointer to the PROGMEM string. * \param[in] str Pointer to the PROGMEM string.
* Use writeError to check for errors. * Use writeError to check for errors.
*/ */
void SdFile::writeln_P(PGM_P str) { void SdFile::writeln_P(PGM_P const str) {
write_P(str); write_P(str);
write_P(PSTR("\r\n")); write_P(PSTR("\r\n"));
} }

View file

@ -41,17 +41,17 @@
class SdFile : public SdBaseFile { class SdFile : public SdBaseFile {
public: public:
SdFile() {} SdFile() {}
SdFile(const char *name, uint8_t oflag); SdFile(const char * const name, const uint8_t oflag);
#if ARDUINO >= 100 #if ARDUINO >= 100
size_t write(uint8_t b); size_t write(const uint8_t b);
#else #else
void write(uint8_t b); void write(const uint8_t b);
#endif #endif
int16_t write(const void *buf, uint16_t nbyte); int16_t write(const void * const buf, const uint16_t nbyte);
void write(const char *str); void write(const char * const str);
void write_P(PGM_P str); void write_P(PGM_P str);
void writeln_P(PGM_P str); void writeln_P(PGM_P const str);
}; };
using MediaFile = SdFile; using MediaFile = SdFile;

View file

@ -47,7 +47,7 @@
#endif #endif
// find a contiguous group of clusters // find a contiguous group of clusters
bool SdVolume::allocContiguous(uint32_t count, uint32_t *curCluster) { bool SdVolume::allocContiguous(const uint32_t count, uint32_t * const curCluster) {
if (ENABLED(SDCARD_READONLY)) return false; if (ENABLED(SDCARD_READONLY)) return false;
// start of group // start of group
@ -138,7 +138,7 @@ bool SdVolume::cacheFlush() {
return true; return true;
} }
bool SdVolume::cacheRawBlock(uint32_t blockNumber, bool dirty) { bool SdVolume::cacheRawBlock(const uint32_t blockNumber, const bool dirty) {
if (cacheBlockNumber_ != blockNumber) { if (cacheBlockNumber_ != blockNumber) {
if (!cacheFlush()) return false; if (!cacheFlush()) return false;
if (!sdCard_->readBlock(blockNumber, cacheBuffer_.data)) return false; if (!sdCard_->readBlock(blockNumber, cacheBuffer_.data)) return false;
@ -149,7 +149,7 @@ bool SdVolume::cacheRawBlock(uint32_t blockNumber, bool dirty) {
} }
// return the size in bytes of a cluster chain // return the size in bytes of a cluster chain
bool SdVolume::chainSize(uint32_t cluster, uint32_t *size) { bool SdVolume::chainSize(uint32_t cluster, uint32_t * const size) {
uint32_t s = 0; uint32_t s = 0;
do { do {
if (!fatGet(cluster, &cluster)) return false; if (!fatGet(cluster, &cluster)) return false;
@ -160,7 +160,7 @@ bool SdVolume::chainSize(uint32_t cluster, uint32_t *size) {
} }
// Fetch a FAT entry // Fetch a FAT entry
bool SdVolume::fatGet(uint32_t cluster, uint32_t *value) { bool SdVolume::fatGet(const uint32_t cluster, uint32_t * const value) {
uint32_t lba; uint32_t lba;
if (cluster > (clusterCount_ + 1)) return false; if (cluster > (clusterCount_ + 1)) return false;
if (FAT12_SUPPORT && fatType_ == 12) { if (FAT12_SUPPORT && fatType_ == 12) {
@ -195,7 +195,7 @@ bool SdVolume::fatGet(uint32_t cluster, uint32_t *value) {
} }
// Store a FAT entry // Store a FAT entry
bool SdVolume::fatPut(uint32_t cluster, uint32_t value) { bool SdVolume::fatPut(const uint32_t cluster, const uint32_t value) {
if (ENABLED(SDCARD_READONLY)) return false; if (ENABLED(SDCARD_READONLY)) return false;
uint32_t lba; uint32_t lba;
@ -326,7 +326,7 @@ int32_t SdVolume::freeClusterCount() {
* Reasons for failure include not finding a valid partition, not finding a valid * Reasons for failure include not finding a valid partition, not finding a valid
* FAT file system in the specified partition or an I/O error. * FAT file system in the specified partition or an I/O error.
*/ */
bool SdVolume::init(DiskIODriver* dev, uint8_t part) { bool SdVolume::init(DiskIODriver * const dev, const uint8_t part) {
uint32_t totalBlocks, volumeStartBlock = 0; uint32_t totalBlocks, volumeStartBlock = 0;
fat32_boot_t *fbs; fat32_boot_t *fbs;

View file

@ -93,8 +93,8 @@ class SdVolume {
* Reasons for failure include not finding a valid partition, not finding * Reasons for failure include not finding a valid partition, not finding
* a valid FAT file system or an I/O error. * a valid FAT file system or an I/O error.
*/ */
bool init(DiskIODriver *dev) { return init(dev, 1) || init(dev, 0); } bool init(DiskIODriver * const dev) { return init(dev, 1) || init(dev, 0); }
bool init(DiskIODriver *dev, uint8_t part); bool init(DiskIODriver * const dev, const uint8_t part);
// inline functions that return volume info // inline functions that return volume info
uint8_t blocksPerCluster() const { return blocksPerCluster_; } //> \return The volume's cluster size in blocks. uint8_t blocksPerCluster() const { return blocksPerCluster_; } //> \return The volume's cluster size in blocks.
@ -127,7 +127,7 @@ class SdVolume {
* \param[out] v value of entry * \param[out] v value of entry
* \return true for success or false for failure * \return true for success or false for failure
*/ */
bool dbgFat(uint32_t n, uint32_t *v) { return fatGet(n, v); } bool dbgFat(const uint32_t n, uint32_t * const v) { return fatGet(n, v); }
private: private:
// Allow SdBaseFile access to SdVolume private data. // Allow SdBaseFile access to SdVolume private data.
@ -164,20 +164,20 @@ class SdVolume {
uint16_t rootDirEntryCount_; // number of entries in FAT16 root dir uint16_t rootDirEntryCount_; // number of entries in FAT16 root dir
uint32_t rootDirStart_; // root start block for FAT16, cluster for FAT32 uint32_t rootDirStart_; // root start block for FAT16, cluster for FAT32
bool allocContiguous(uint32_t count, uint32_t *curCluster); bool allocContiguous(const uint32_t count, uint32_t * const curCluster);
uint8_t blockOfCluster(uint32_t position) const { return (position >> 9) & (blocksPerCluster_ - 1); } uint8_t blockOfCluster(const uint32_t position) const { return (position >> 9) & (blocksPerCluster_ - 1); }
uint32_t clusterStartBlock(uint32_t cluster) const { return dataStartBlock_ + ((cluster - 2) << clusterSizeShift_); } uint32_t clusterStartBlock(const uint32_t cluster) const { return dataStartBlock_ + ((cluster - 2) << clusterSizeShift_); }
uint32_t blockNumber(uint32_t cluster, uint32_t position) const { return clusterStartBlock(cluster) + blockOfCluster(position); } uint32_t blockNumber(const uint32_t cluster, const uint32_t position) const { return clusterStartBlock(cluster) + blockOfCluster(position); }
cache_t* cache() { return &cacheBuffer_; } cache_t* cache() { return &cacheBuffer_; }
uint32_t cacheBlockNumber() const { return cacheBlockNumber_; } uint32_t cacheBlockNumber() const { return cacheBlockNumber_; }
#if USE_MULTIPLE_CARDS #if USE_MULTIPLE_CARDS
bool cacheFlush(); bool cacheFlush();
bool cacheRawBlock(uint32_t blockNumber, bool dirty); bool cacheRawBlock(const uint32_t blockNumber, const bool dirty);
#else #else
static bool cacheFlush(); static bool cacheFlush();
static bool cacheRawBlock(uint32_t blockNumber, bool dirty); static bool cacheRawBlock(const uint32_t blockNumber, const bool dirty);
#endif #endif
// used by SdBaseFile write to assign cache to SD location // used by SdBaseFile write to assign cache to SD location
@ -186,18 +186,18 @@ class SdVolume {
cacheBlockNumber_ = blockNumber; cacheBlockNumber_ = blockNumber;
} }
void cacheSetDirty() { cacheDirty_ |= CACHE_FOR_WRITE; } void cacheSetDirty() { cacheDirty_ |= CACHE_FOR_WRITE; }
bool chainSize(uint32_t beginCluster, uint32_t *size); bool chainSize(uint32_t cluster, uint32_t * const size);
bool fatGet(uint32_t cluster, uint32_t *value); bool fatGet(const uint32_t cluster, uint32_t * const value);
bool fatPut(uint32_t cluster, uint32_t value); bool fatPut(const uint32_t cluster, const uint32_t value);
bool fatPutEOC(uint32_t cluster) { return fatPut(cluster, 0x0FFFFFFF); } bool fatPutEOC(const uint32_t cluster) { return fatPut(cluster, 0x0FFFFFFF); }
bool freeChain(uint32_t cluster); bool freeChain(uint32_t cluster);
bool isEOC(uint32_t cluster) const { bool isEOC(const uint32_t cluster) const {
if (FAT12_SUPPORT && fatType_ == 12) return cluster >= FAT12EOC_MIN; if (FAT12_SUPPORT && fatType_ == 12) return cluster >= FAT12EOC_MIN;
if (fatType_ == 16) return cluster >= FAT16EOC_MIN; if (fatType_ == 16) return cluster >= FAT16EOC_MIN;
return cluster >= FAT32EOC_MIN; return cluster >= FAT32EOC_MIN;
} }
bool readBlock(uint32_t block, uint8_t *dst) { return sdCard_->readBlock(block, dst); } bool readBlock(const uint32_t block, uint8_t * const dst) { return sdCard_->readBlock(block, dst); }
bool writeBlock(uint32_t block, const uint8_t *dst) { return sdCard_->writeBlock(block, dst); } bool writeBlock(const uint32_t block, const uint8_t * const dst) { return sdCard_->writeBlock(block, dst); }
}; };
using MarlinVolume = SdVolume; using MarlinVolume = SdVolume;

View file

@ -47,18 +47,18 @@ public:
* *
* \return true for success or false for failure. * \return true for success or false for failure.
*/ */
virtual bool readCSD(csd_t* csd) = 0; virtual bool readCSD(csd_t * const csd) = 0;
virtual bool readStart(const uint32_t block) = 0; virtual bool readStart(const uint32_t block) = 0;
virtual bool readData(uint8_t* dst) = 0; virtual bool readData(uint8_t * const dst) = 0;
virtual bool readStop() = 0; virtual bool readStop() = 0;
virtual bool writeStart(const uint32_t block, const uint32_t) = 0; virtual bool writeStart(const uint32_t block, const uint32_t) = 0;
virtual bool writeData(const uint8_t* src) = 0; virtual bool writeData(const uint8_t* src) = 0;
virtual bool writeStop() = 0; virtual bool writeStop() = 0;
virtual bool readBlock(uint32_t block, uint8_t* dst) = 0; virtual bool readBlock(const uint32_t block, uint8_t * const dst) = 0;
virtual bool writeBlock(uint32_t blockNumber, const uint8_t* src) = 0; virtual bool writeBlock(const uint32_t blockNumber, const uint8_t * const src) = 0;
virtual uint32_t cardSize() = 0; virtual uint32_t cardSize() = 0;