Skip to content

Commit

Permalink
🎨 Apply const (MarlinFirmware#25643)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored and EvilGremlin committed Apr 8, 2023
1 parent ae6e956 commit e392e5f
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 155 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
* - Update the Průša MMU2
* - Handle Joystick jogging
*/
void idle(bool no_stepper_sleep/*=false*/) {
void idle(const bool no_stepper_sleep/*=false*/) {
#ifdef MAX7219_DEBUG_PROFILE
CodeProfiler idle_profiler;
#endif
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/MarlinCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
void stop();

// 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); }

#if ENABLED(G38_PROBE_TARGET)
Expand Down
18 changes: 9 additions & 9 deletions Marlin/src/lcd/extui/mks_ui/SPIFlashStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ uint32_t SPIFlashStorage::m_startAddress;

#endif // HAS_SPI_FLASH_COMPRESSION

void SPIFlashStorage::beginWrite(uint32_t startAddress) {
void SPIFlashStorage::beginWrite(const uint32_t startAddress) {
m_pageDataUsed = 0;
m_currentPage = 0;
m_startAddress = startAddress;
Expand All @@ -171,7 +171,7 @@ void SPIFlashStorage::endWrite() {
#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);
// Test env
// char fname[256];
Expand All @@ -181,7 +181,7 @@ void SPIFlashStorage::savePage(uint8_t *buffer) {
// 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);
// Test env
// char fname[256];
Expand Down Expand Up @@ -260,20 +260,20 @@ void SPIFlashStorage::readPage() {
#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
NOMORE(size, pageDataFree());
memcpy(m_pageData + m_pageDataUsed, data, size);
m_pageDataUsed += 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
if (pageDataFree() == 0) flushPage();

while (size > 0) {
uint16_t written = inData(data, size);
const uint16_t written = inData(data, size);
size -= written;
// Need to write more? Flush page and continue!
if (size > 0) {
Expand All @@ -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_currentPage = 0;
// Nothing in memory now
Expand All @@ -293,7 +293,7 @@ void SPIFlashStorage::beginRead(uint32_t startAddress) {
#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
NOMORE(size, pageDataFree());
memcpy(data, m_pageData + m_pageDataUsed, size);
Expand All @@ -306,7 +306,7 @@ void SPIFlashStorage::readData(uint8_t *data, uint16_t size) {
if (pageDataFree() == 0) readPage();

while (size > 0) {
uint16_t read = outData(data, size);
const uint16_t read = outData(data, size);
size -= read;
// Need to write more? Flush page and continue!
if (size > 0) {
Expand Down
14 changes: 7 additions & 7 deletions Marlin/src/lcd/extui/mks_ui/SPIFlashStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,23 @@
class SPIFlashStorage {
public:
// Write operation
static void beginWrite(uint32_t startAddress);
static void beginWrite(const uint32_t startAddress);
static void endWrite();
static void writeData(uint8_t *data, uint16_t size);
static void writeData(const uint8_t *data, uint16_t size);

// 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 uint32_t getCurrentPage() { return m_currentPage; }

private:
static void flushPage();
static void savePage(uint8_t *buffer);
static void loadPage(uint8_t *buffer);
static void savePage(uint8_t * const buffer);
static void loadPage(uint8_t * const buffer);
static void readPage();
static uint16_t inData(uint8_t *data, uint16_t size);
static uint16_t outData(uint8_t *data, uint16_t size);
static uint16_t inData(const uint8_t * const data, uint16_t size);
static uint16_t outData(uint8_t * const data, uint16_t size);

static uint8_t m_pageData[SPI_FLASH_PageSize];
static uint32_t m_currentPage;
Expand Down
16 changes: 8 additions & 8 deletions Marlin/src/sd/Sd2Card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* \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
return 0 == SDHC_CardReadBlock(dst, blockNumber);
#endif
Expand Down Expand Up @@ -385,7 +385,7 @@ bool DiskIODriver_SPI_SD::readBlock(uint32_t blockNumber, uint8_t *dst) {
*
* \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();
return readData(dst, 512);
}
Expand Down Expand Up @@ -455,7 +455,7 @@ bool DiskIODriver_SPI_SD::readData(uint8_t *dst) {

#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;

const millis_t read_timeout = millis() + SD_READ_TIMEOUT;
Expand Down Expand Up @@ -487,8 +487,8 @@ bool DiskIODriver_SPI_SD::readData(uint8_t *dst, const uint16_t count) {
}

/** read CID or CSR register */
bool DiskIODriver_SPI_SD::readRegister(const uint8_t cmd, void *buf) {
uint8_t *dst = reinterpret_cast<uint8_t*>(buf);
bool DiskIODriver_SPI_SD::readRegister(const uint8_t cmd, void * const buf) {
uint8_t * const dst = reinterpret_cast<uint8_t*>(buf);
if (cardCommand(cmd, 0)) {
error(SD_CARD_ERROR_READ_REG);
chipDeselect();
Expand Down Expand Up @@ -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.
* \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 IS_TEENSY_35_36 || IS_TEENSY_40_41
Expand Down Expand Up @@ -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.
* \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;

bool success = true;
Expand All @@ -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
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;

const uint16_t crc = TERN(SD_CHECK_AND_RETRY, CRC_CCITT(src, 512), 0xFFFF);
Expand Down
20 changes: 10 additions & 10 deletions Marlin/src/sd/Sd2Card.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class DiskIODriver_SPI_SD : public DiskIODriver {
*
* \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
Expand All @@ -153,18 +153,18 @@ class DiskIODriver_SPI_SD : public DiskIODriver {
*
* \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 readStop() override;

bool writeData(const uint8_t *src) override;
bool writeStart(const uint32_t blockNumber, const uint32_t eraseCount) override;
bool writeData(const uint8_t * const src) override;
bool writeStart(uint32_t blockNumber, const uint32_t eraseCount) override;
bool writeStop() override;

bool readBlock(uint32_t block, uint8_t *dst) override;
bool writeBlock(uint32_t blockNumber, const uint8_t *src) override;
bool readBlock(uint32_t blockNumber, uint8_t * const dst) override;
bool writeBlock(uint32_t blockNumber, const uint8_t * const src) override;

uint32_t cardSize() override;

Expand All @@ -187,11 +187,11 @@ class DiskIODriver_SPI_SD : public DiskIODriver {
}
uint8_t cardCommand(const uint8_t cmd, const uint32_t arg);

bool readData(uint8_t *dst, const uint16_t count);
bool readRegister(const uint8_t cmd, void *buf);
bool readData(uint8_t * const dst, const uint16_t count);
bool readRegister(const uint8_t cmd, void * const buf);
void chipDeselect();
void chipSelect();
inline void type(const uint8_t value) { type_ = value; }
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);
};
Loading

0 comments on commit e392e5f

Please sign in to comment.