From ba5644376c51be7f126c10b37c726ee22c867c6d Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 4 Apr 2021 18:07:16 -0500 Subject: [PATCH] misc. pointer formatting --- Marlin/src/HAL/DUE/eeprom_flash.cpp | 4 +- Marlin/src/HAL/ESP32/i2s.cpp | 2 +- Marlin/src/HAL/STM32/MarlinSerial.h | 2 +- Marlin/src/HAL/STM32F1/onboard_sd.h | 2 +- Marlin/src/HAL/shared/backtrace/backtrace.cpp | 2 +- Marlin/src/HAL/shared/backtrace/unwinder.h | 2 +- Marlin/src/feature/spindle_laser.h | 2 +- Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp | 4 +- Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.h | 4 +- .../extui/lib/dgus/mks/DGUSScreenHandler.cpp | 2 +- .../extui/lib/dgus/mks/DGUSScreenHandler.h | 2 +- .../ftdi_eve_lib/basic/commands.cpp | 2 +- .../ftdi_eve_lib/basic/commands.h | 2 +- .../ftdi_eve_lib/extended/command_processor.h | 2 +- Marlin/src/sd/Sd2Card.cpp | 2 +- Marlin/src/sd/Sd2Card.h | 2 +- Marlin/src/sd/SdBaseFile.cpp | 82 ++++++++----------- Marlin/src/sd/SdBaseFile.h | 36 ++++---- Marlin/src/sd/SdFile.cpp | 2 +- Marlin/src/sd/SdFile.h | 4 +- Marlin/src/sd/SdVolume.h | 8 +- Marlin/src/sd/cardreader.cpp | 8 +- Marlin/src/sd/cardreader.h | 6 +- 23 files changed, 85 insertions(+), 99 deletions(-) diff --git a/Marlin/src/HAL/DUE/eeprom_flash.cpp b/Marlin/src/HAL/DUE/eeprom_flash.cpp index 14c843576..b4cb9912b 100644 --- a/Marlin/src/HAL/DUE/eeprom_flash.cpp +++ b/Marlin/src/HAL/DUE/eeprom_flash.cpp @@ -135,7 +135,7 @@ static uint8_t buffer[256] = {0}, // The RAM buffer to accumulate writes #define DEBUG_OUT ENABLED(EE_EMU_DEBUG) #include "../../core/debug_out.h" -static void ee_Dump(const int page, const void* data) { +static void ee_Dump(const int page, const void *data) { #ifdef EE_EMU_DEBUG @@ -181,7 +181,7 @@ static void ee_Dump(const int page, const void* data) { * @param data (pointer to the data buffer) */ __attribute__ ((long_call, section (".ramfunc"))) -static bool ee_PageWrite(uint16_t page, const void* data) { +static bool ee_PageWrite(uint16_t page, const void *data) { uint16_t i; uint32_t addrflash = uint32_t(getFlashStorage(page)); diff --git a/Marlin/src/HAL/ESP32/i2s.cpp b/Marlin/src/HAL/ESP32/i2s.cpp index e8f380654..c28c00879 100644 --- a/Marlin/src/HAL/ESP32/i2s.cpp +++ b/Marlin/src/HAL/ESP32/i2s.cpp @@ -139,7 +139,7 @@ static void IRAM_ATTR i2s_intr_handler_default(void *arg) { I2S0.int_clr.val = I2S0.int_st.val; //clear pending interrupt } -void stepperTask(void* parameter) { +void stepperTask(void *parameter) { uint32_t remaining = 0; while (1) { diff --git a/Marlin/src/HAL/STM32/MarlinSerial.h b/Marlin/src/HAL/STM32/MarlinSerial.h index d9e845701..ab5c4260a 100644 --- a/Marlin/src/HAL/STM32/MarlinSerial.h +++ b/Marlin/src/HAL/STM32/MarlinSerial.h @@ -29,7 +29,7 @@ typedef void (*usart_rx_callback_t)(serial_t * obj); struct MarlinSerial : public HardwareSerial { - MarlinSerial(void* peripheral, usart_rx_callback_t rx_callback) : + MarlinSerial(void *peripheral, usart_rx_callback_t rx_callback) : HardwareSerial(peripheral), _rx_callback(rx_callback) { } diff --git a/Marlin/src/HAL/STM32F1/onboard_sd.h b/Marlin/src/HAL/STM32F1/onboard_sd.h index 1dc7ec5b3..1c0a1c5b8 100644 --- a/Marlin/src/HAL/STM32F1/onboard_sd.h +++ b/Marlin/src/HAL/STM32F1/onboard_sd.h @@ -48,7 +48,7 @@ DRESULT disk_read(BYTE pdrv, BYTE* buff, DWORD sector, UINT count); DRESULT disk_write(BYTE pdrv, const BYTE* buff, DWORD sector, UINT count); #endif #if _DISKIO_IOCTL - DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void* buff); + DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff); #endif /* Disk Status Bits (DSTATUS) */ diff --git a/Marlin/src/HAL/shared/backtrace/backtrace.cpp b/Marlin/src/HAL/shared/backtrace/backtrace.cpp index e4ae502a8..ad88de838 100644 --- a/Marlin/src/HAL/shared/backtrace/backtrace.cpp +++ b/Marlin/src/HAL/shared/backtrace/backtrace.cpp @@ -29,7 +29,7 @@ #include // Dump a backtrace entry -static bool UnwReportOut(void* ctx, const UnwReport* bte) { +static bool UnwReportOut(void *ctx, const UnwReport *bte) { int *p = (int*)ctx; (*p)++; diff --git a/Marlin/src/HAL/shared/backtrace/unwinder.h b/Marlin/src/HAL/shared/backtrace/unwinder.h index 157808d54..8692c7a1a 100644 --- a/Marlin/src/HAL/shared/backtrace/unwinder.h +++ b/Marlin/src/HAL/shared/backtrace/unwinder.h @@ -114,7 +114,7 @@ typedef struct { * report function maybe called again in future. If false is returned, * unwinding will stop with UnwindStart() returning UNWIND_TRUNCATED. */ -typedef bool (*UnwindReportFunc)(void* data, const UnwReport* bte); +typedef bool (*UnwindReportFunc)(void *data, const UnwReport *bte); /** Structure that holds memory callback function pointers. */ diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index bf7106fab..88cf372a0 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -215,7 +215,7 @@ public: static inline void disable() { isReady = false; set_enabled(false); } #if HAS_LCD_MENU - static inline void enable_with_dir(const bool reverse) { + static inline void enable_with_dir(const bool reverse) { isReady = true; const uint8_t ocr = TERN(SPINDLE_LASER_PWM, upower_to_ocr(menuPower), 255); if (menuPower) diff --git a/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp b/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp index 2c283b1a9..2f3376865 100644 --- a/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp +++ b/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp @@ -70,7 +70,7 @@ void DGUSDisplay::InitDisplay() { RequestScreen(TERN(SHOW_BOOTSCREEN, DGUSLCD_SCREEN_BOOT, DGUSLCD_SCREEN_MAIN)); } -void DGUSDisplay::WriteVariable(uint16_t adr, const void* values, uint8_t valueslen, bool isstr) { +void DGUSDisplay::WriteVariable(uint16_t adr, const void *values, uint8_t valueslen, bool isstr) { const char* myvalues = static_cast(values); bool strend = !myvalues; WriteHeader(adr, DGUS_CMD_WRITEVAR, valueslen); @@ -120,7 +120,7 @@ void DGUSDisplay::WriteVariable(uint16_t adr, long value) { WriteVariable(adr, static_cast(&tmp), sizeof(long)); } -void DGUSDisplay::WriteVariablePGM(uint16_t adr, const void* values, uint8_t valueslen, bool isstr) { +void DGUSDisplay::WriteVariablePGM(uint16_t adr, const void *values, uint8_t valueslen, bool isstr) { const char* myvalues = static_cast(values); bool strend = !myvalues; WriteHeader(adr, DGUS_CMD_WRITEVAR, valueslen); diff --git a/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.h b/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.h index c017d69da..f33935a26 100644 --- a/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.h +++ b/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.h @@ -56,8 +56,8 @@ public: static void InitDisplay(); // Variable access. - static void WriteVariable(uint16_t adr, const void* values, uint8_t valueslen, bool isstr=false); - static void WriteVariablePGM(uint16_t adr, const void* values, uint8_t valueslen, bool isstr=false); + static void WriteVariable(uint16_t adr, const void *values, uint8_t valueslen, bool isstr=false); + static void WriteVariablePGM(uint16_t adr, const void *values, uint8_t valueslen, bool isstr=false); static void WriteVariable(uint16_t adr, int16_t value); static void WriteVariable(uint16_t adr, uint16_t value); static void WriteVariable(uint16_t adr, uint8_t value); diff --git a/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.cpp index 54500011f..109e9a8ac 100644 --- a/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.cpp @@ -75,7 +75,7 @@ void DGUSScreenHandler::sendinfoscreen_en_mks(const char *line1, const char *lin dgusdisplay.WriteVariable(VP_MSGSTR4, line4, 32, true); } -void DGUSScreenHandler::sendinfoscreen_mks(const void* line1, const void* line2, const void* line3, const void* line4, uint16_t language) { +void DGUSScreenHandler::sendinfoscreen_mks(const void *line1, const void *line2, const void *line3, const void *line4, uint16_t language) { if (language == MKS_English) DGUSScreenHandler::sendinfoscreen_en_mks((char *)line1, (char *)line2, (char *)line3, (char *)line4); else if (language == MKS_SimpleChinese) diff --git a/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.h b/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.h index 382197c7d..ef67635f8 100644 --- a/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.h +++ b/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.h @@ -44,7 +44,7 @@ public: #if 0 static void sendinfoscreen_ch_mks(const uint16_t *line1, const uint16_t *line2, const uint16_t *line3, const uint16_t *line4); static void sendinfoscreen_en_mks(const char *line1, const char *line2, const char *line3, const char *line4) ; - static void sendinfoscreen_mks(const void* line1, const void* line2, const void* line3, const void* line4,uint16_t language); + static void sendinfoscreen_mks(const void *line1, const void *line2, const void *line3, const void *line4, uint16_t language); #endif // "M117" Message -- msg is a RAM ptr. diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/commands.cpp b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/commands.cpp index 736809323..47ce1c700 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/commands.cpp +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/commands.cpp @@ -229,7 +229,7 @@ void CLCD::CommandFifo::cmd(uint32_t cmd32) { write((void*)&cmd32, sizeof(uint32_t)); } -void CLCD::CommandFifo::cmd(void* data, uint16_t len) { +void CLCD::CommandFifo::cmd(void *data, uint16_t len) { write(data, len); } diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/commands.h b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/commands.h index 376beaec4..eea24b06b 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/commands.h +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/commands.h @@ -196,7 +196,7 @@ class CLCD::CommandFifo { void execute(); void cmd(uint32_t cmd32); - void cmd(void* data, uint16_t len); + void cmd(void *data, uint16_t len); void dlstart() {cmd(FTDI::CMD_DLSTART);} void swap() {cmd(FTDI::CMD_SWAP);} diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/command_processor.h b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/command_processor.h index da51ee638..225852922 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/command_processor.h +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/command_processor.h @@ -149,7 +149,7 @@ class CommandProcessor : public CLCD::CommandFifo { // Wrap all the CommandFifo routines to allow method chaining inline CommandProcessor& cmd (uint32_t cmd32) {CLCD::CommandFifo::cmd(cmd32); return *this;} - inline CommandProcessor& cmd (void* data, uint16_t len) {CLCD::CommandFifo::cmd(data, len); return *this;} + inline CommandProcessor& cmd (void *data, uint16_t len) {CLCD::CommandFifo::cmd(data, len); return *this;} inline CommandProcessor& execute() {CLCD::CommandFifo::execute(); return *this;} inline CommandProcessor& fgcolor (uint32_t rgb) {CLCD::CommandFifo::fgcolor(rgb); return *this;} diff --git a/Marlin/src/sd/Sd2Card.cpp b/Marlin/src/sd/Sd2Card.cpp index b914b2963..28049c7e7 100644 --- a/Marlin/src/sd/Sd2Card.cpp +++ b/Marlin/src/sd/Sd2Card.cpp @@ -477,7 +477,7 @@ bool Sd2Card::readData(uint8_t *dst, const uint16_t count) { } /** read CID or CSR register */ -bool Sd2Card::readRegister(const uint8_t cmd, void* buf) { +bool Sd2Card::readRegister(const uint8_t cmd, void *buf) { uint8_t *dst = reinterpret_cast(buf); if (cardCommand(cmd, 0)) { error(SD_CARD_ERROR_READ_REG); diff --git a/Marlin/src/sd/Sd2Card.h b/Marlin/src/sd/Sd2Card.h index d82cb10a1..eb7f9bb2c 100644 --- a/Marlin/src/sd/Sd2Card.h +++ b/Marlin/src/sd/Sd2Card.h @@ -177,7 +177,7 @@ private: 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 readRegister(const uint8_t cmd, void *buf); void chipDeselect(); void chipSelect(); inline void type(const uint8_t value) { type_ = value; } diff --git a/Marlin/src/sd/SdBaseFile.cpp b/Marlin/src/sd/SdBaseFile.cpp index 120668baa..ac73a5a80 100644 --- a/Marlin/src/sd/SdBaseFile.cpp +++ b/Marlin/src/sd/SdBaseFile.cpp @@ -40,7 +40,7 @@ #include "SdBaseFile.h" #include "../MarlinCore.h" -SdBaseFile* SdBaseFile::cwd_ = 0; // Pointer to Current Working Directory +SdBaseFile *SdBaseFile::cwd_ = 0; // Pointer to Current Working Directory // callback function for date/time void (*SdBaseFile::dateTime_)(uint16_t *date, uint16_t *time) = 0; @@ -155,7 +155,7 @@ bool SdBaseFile::contiguousRange(uint32_t *bgnBlock, uint32_t *endBlock) { * a file is already open, the file already exists, the root * directory is full or an I/O error. */ -bool SdBaseFile::createContiguous(SdBaseFile* dirFile, const char *path, uint32_t size) { +bool SdBaseFile::createContiguous(SdBaseFile *dirFile, const char *path, uint32_t size) { if (ENABLED(SDCARD_READONLY)) return false; uint32_t count; @@ -187,12 +187,11 @@ bool SdBaseFile::createContiguous(SdBaseFile* dirFile, const char *path, uint32_ * \return true for success, false for failure. */ bool SdBaseFile::dirEntry(dir_t *dir) { - dir_t *p; // make sure fields on SD are correct if (!sync()) return false; // read entry - p = cacheDirEntry(SdVolume::CACHE_FOR_READ); + dir_t *p = cacheDirEntry(SdVolume::CACHE_FOR_READ); if (!p) return false; // copy to caller's struct @@ -207,7 +206,7 @@ bool SdBaseFile::dirEntry(dir_t *dir) { * \param[in] dir The directory structure containing the name. * \param[out] name A 13 byte char array for the formatted name. */ -void SdBaseFile::dirName(const dir_t& dir, char *name) { +void SdBaseFile::dirName(const dir_t &dir, char *name) { uint8_t j = 0; LOOP_L_N(i, 11) { if (dir.name[i] == ' ')continue; @@ -386,7 +385,7 @@ int8_t SdBaseFile::lsPrintNext(uint8_t flags, uint8_t indent) { } // 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 *name, const char **ptr) { uint8_t n = 7, // Max index until a dot is found i = 11; while (i) name[--i] = ' '; // Set whole FILENAME.EXT to spaces @@ -423,13 +422,13 @@ 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 * 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, bool pFlag) { if (ENABLED(SDCARD_READONLY)) return false; uint8_t dname[11]; SdBaseFile dir1, dir2; - SdBaseFile* sub = &dir1; - SdBaseFile* start = parent; + SdBaseFile *sub = &dir1; + SdBaseFile *start = parent; if (!parent || isOpen()) return false; @@ -455,13 +454,9 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const char *path, bool pFlag) { return mkdir(parent, dname); } -bool SdBaseFile::mkdir(SdBaseFile* parent, const uint8_t dname[11]) { +bool SdBaseFile::mkdir(SdBaseFile *parent, const uint8_t dname[11]) { if (ENABLED(SDCARD_READONLY)) return false; - uint32_t block; - dir_t d; - dir_t *p; - if (!parent->isDir()) return false; // create a normal file @@ -478,19 +473,20 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const uint8_t dname[11]) { if (!sync()) return false; // cache entry - should already be in cache due to sync() call - p = cacheDirEntry(SdVolume::CACHE_FOR_WRITE); + dir_t *p = cacheDirEntry(SdVolume::CACHE_FOR_WRITE); if (!p) return false; // change directory entry attribute p->attributes = DIR_ATT_DIRECTORY; // make entry for '.' + dir_t d; memcpy(&d, p, sizeof(d)); d.name[0] = '.'; LOOP_S_L_N(i, 1, 11) d.name[i] = ' '; // cache block for '.' and '..' - block = vol_->clusterStartBlock(firstCluster_); + uint32_t block = vol_->clusterStartBlock(firstCluster_); if (!vol_->cacheRawBlock(block, SdVolume::CACHE_FOR_WRITE)) return false; // copy '.' to block @@ -577,7 +573,7 @@ bool SdBaseFile::open(const char *path, uint8_t oflag) { * a directory, \a path is invalid, the file does not exist * 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 *dirFile, const char *path, uint8_t oflag) { uint8_t dname[11]; SdBaseFile dir1, dir2; SdBaseFile *parent = dirFile, *sub = &dir1; @@ -605,7 +601,7 @@ bool SdBaseFile::open(SdBaseFile* dirFile, const char *path, uint8_t oflag) { } // open with filename in dname -bool SdBaseFile::open(SdBaseFile* dirFile, const uint8_t dname[11], uint8_t oflag) { +bool SdBaseFile::open(SdBaseFile *dirFile, const uint8_t dname[11], uint8_t oflag) { bool emptyFound = false, fileFound = false; uint8_t index; dir_t *p; @@ -696,9 +692,7 @@ bool SdBaseFile::open(SdBaseFile* dirFile, const uint8_t dname[11], uint8_t ofla * See open() by path for definition of flags. * \return true for success or false for failure. */ -bool SdBaseFile::open(SdBaseFile* dirFile, uint16_t index, uint8_t oflag) { - dir_t *p; - +bool SdBaseFile::open(SdBaseFile *dirFile, uint16_t index, uint8_t oflag) { vol_ = dirFile->vol_; // error if already open @@ -711,7 +705,7 @@ bool SdBaseFile::open(SdBaseFile* dirFile, uint16_t index, uint8_t oflag) { if (!dirFile->seekSet(32 * index)) return false; // read entry into cache - p = dirFile->readDirCache(); + dir_t *p = dirFile->readDirCache(); if (!p) return false; // error if empty slot or '.' or '..' @@ -784,10 +778,7 @@ bool SdBaseFile::openCachedEntry(uint8_t dirIndex, uint8_t oflag) { * See open() by path for definition of flags. * \return true for success or false for failure. */ -bool SdBaseFile::openNext(SdBaseFile* dirFile, uint8_t oflag) { - dir_t *p; - uint8_t index; - +bool SdBaseFile::openNext(SdBaseFile *dirFile, uint8_t oflag) { if (!dirFile) return false; // error if already open @@ -796,10 +787,10 @@ bool SdBaseFile::openNext(SdBaseFile* dirFile, uint8_t oflag) { vol_ = dirFile->vol_; while (1) { - index = 0xF & (dirFile->curPosition_ >> 5); + uint8_t index = 0xF & (dirFile->curPosition_ >> 5); // read entry into cache - p = dirFile->readDirCache(); + dir_t *p = dirFile->readDirCache(); if (!p) return false; // done if last entry @@ -825,9 +816,8 @@ bool SdBaseFile::openNext(SdBaseFile* dirFile, uint8_t oflag) { * * \return true for success, false for failure. */ -bool SdBaseFile::openParent(SdBaseFile* dir) { +bool SdBaseFile::openParent(SdBaseFile *dir) { dir_t entry; - dir_t *p; SdBaseFile file; uint32_t c; uint32_t cluster; @@ -850,7 +840,7 @@ bool SdBaseFile::openParent(SdBaseFile* dir) { // first block of parent dir if (!vol_->cacheRawBlock(lbn, SdVolume::CACHE_FOR_READ)) return false; - p = &vol_->cacheBuffer_.dir[1]; + dir_t *p = &vol_->cacheBuffer_.dir[1]; // verify name for '../..' if (p->name[0] != '.' || p->name[1] != '.') return false; // '..' is pointer to first cluster of parent. open '../..' to find parent @@ -881,7 +871,7 @@ bool SdBaseFile::openParent(SdBaseFile* dir) { * Reasons for failure include the file is already open, the FAT volume has * not been initialized or it a FAT12 volume. */ -bool SdBaseFile::openRoot(SdVolume* vol) { +bool SdBaseFile::openRoot(SdVolume *vol) { // error if file is already open if (isOpen()) return false; @@ -1008,7 +998,7 @@ int16_t SdBaseFile::read() { * read() called before a file has been opened, corrupt file system * or an I/O error occurred. */ -int16_t SdBaseFile::read(void* buf, uint16_t nbyte) { +int16_t SdBaseFile::read(void *buf, uint16_t nbyte) { uint8_t *dst = reinterpret_cast(buf); uint16_t offset, toRead; uint32_t block; // raw device block number @@ -1136,7 +1126,7 @@ int8_t SdBaseFile::readDir(dir_t *dir, char *longFilename) { // Reset n to the start of the long name n = 0; for (uint16_t idx = 0; idx < (LONG_FILENAME_LENGTH) / 2; idx += 2) { // idx is fixed since FAT LFN always contains UTF-16LE encoding - uint16_t utf16_ch = longFilename[idx] | (longFilename[idx + 1] << 8); + const uint16_t utf16_ch = longFilename[idx] | (longFilename[idx + 1] << 8); if (0xD800 == (utf16_ch & 0xF800)) // Surrogate pair - encode as '_' longFilename[n++] = '_'; else if (0 == (utf16_ch & 0xFF80)) // Encode as 1-byte UTF-8 char @@ -1199,12 +1189,11 @@ dir_t* SdBaseFile::readDirCache() { bool SdBaseFile::remove() { if (ENABLED(SDCARD_READONLY)) return false; - dir_t *d; // free any clusters - will fail if read-only or directory if (!truncate(0)) return false; // cache directory entry - d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE); + dir_t *d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE); if (!d) return false; // mark entry deleted @@ -1235,7 +1224,7 @@ bool SdBaseFile::remove() { * \a dirFile is not a directory, \a path is not found * or an I/O error occurred. */ -bool SdBaseFile::remove(SdBaseFile* dirFile, const char *path) { +bool SdBaseFile::remove(SdBaseFile *dirFile, const char *path) { if (ENABLED(SDCARD_READONLY)) return false; SdBaseFile file; @@ -1252,13 +1241,10 @@ bool SdBaseFile::remove(SdBaseFile* dirFile, const char *path) { * 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. */ -bool SdBaseFile::rename(SdBaseFile* dirFile, const char *newPath) { +bool SdBaseFile::rename(SdBaseFile *dirFile, const char *newPath) { if (ENABLED(SDCARD_READONLY)) return false; - dir_t entry; uint32_t dirCluster = 0; - SdBaseFile file; - dir_t *d; // must be an open file or subdirectory if (!(isFile() || isSubDir())) return false; @@ -1268,16 +1254,18 @@ bool SdBaseFile::rename(SdBaseFile* dirFile, const char *newPath) { // sync() and cache directory entry sync(); - d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE); + dir_t *d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE); if (!d) return false; // save directory entry + dir_t entry; memcpy(&entry, d, sizeof(entry)); // mark entry deleted d->name[0] = DIR_NAME_DELETED; // make directory entry for new path + SdBaseFile file; if (isFile()) { if (!file.open(dirFile, newPath, O_CREAT | O_EXCL | O_WRITE)) { goto restore; @@ -1536,8 +1524,7 @@ bool SdBaseFile::sync() { * * \return true for success, false for failure. */ -bool SdBaseFile::timestamp(SdBaseFile* file) { - dir_t *d; +bool SdBaseFile::timestamp(SdBaseFile *file) { dir_t dir; // get timestamps @@ -1546,7 +1533,7 @@ bool SdBaseFile::timestamp(SdBaseFile* file) { // update directory fields if (!sync()) return false; - d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE); + dir_t *d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE); if (!d) return false; // copy timestamps @@ -1599,7 +1586,6 @@ bool SdBaseFile::timestamp(uint8_t flags, uint16_t year, uint8_t month, if (ENABLED(SDCARD_READONLY)) return false; uint16_t dirDate, dirTime; - dir_t *d; if (!isOpen() || year < 1980 @@ -1616,7 +1602,7 @@ bool SdBaseFile::timestamp(uint8_t flags, uint16_t year, uint8_t month, // update directory entry if (!sync()) return false; - d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE); + dir_t *d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE); if (!d) return false; dirDate = FAT_DATE(year, month, day); @@ -1710,7 +1696,7 @@ bool SdBaseFile::truncate(uint32_t length) { * 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. */ -int16_t SdBaseFile::write(const void* buf, uint16_t nbyte) { +int16_t SdBaseFile::write(const void *buf, uint16_t nbyte) { #if ENABLED(SDCARD_READONLY) writeError = true; return -1; #endif diff --git a/Marlin/src/sd/SdBaseFile.h b/Marlin/src/sd/SdBaseFile.h index 1e2bc5d09..342edefb7 100644 --- a/Marlin/src/sd/SdBaseFile.h +++ b/Marlin/src/sd/SdBaseFile.h @@ -189,7 +189,7 @@ class SdBaseFile { bool close(); bool contiguousRange(uint32_t *bgnBlock, uint32_t *endBlock); - bool createContiguous(SdBaseFile* dirFile, + bool createContiguous(SdBaseFile *dirFile, const char *path, uint32_t size); /** * \return The current cluster number for a file or directory. @@ -204,7 +204,7 @@ class SdBaseFile { /** * \return Current working directory */ - static SdBaseFile* cwd() { return cwd_; } + static SdBaseFile *cwd() { return cwd_; } /** * Set the date/time callback function @@ -286,27 +286,27 @@ class SdBaseFile { bool getDosName(char * const name); void ls(uint8_t flags = 0, uint8_t indent = 0); - bool mkdir(SdBaseFile* dir, const char *path, bool pFlag = true); - bool open(SdBaseFile* dirFile, uint16_t index, uint8_t oflag); - bool open(SdBaseFile* dirFile, const char *path, uint8_t oflag); + bool mkdir(SdBaseFile *dir, const char *path, bool pFlag = true); + bool open(SdBaseFile *dirFile, uint16_t index, uint8_t oflag); + bool open(SdBaseFile *dirFile, const char *path, uint8_t oflag); bool open(const char *path, uint8_t oflag = O_READ); - bool openNext(SdBaseFile* dirFile, uint8_t oflag); - bool openRoot(SdVolume* vol); + bool openNext(SdBaseFile *dirFile, uint8_t oflag); + bool openRoot(SdVolume *vol); int peek(); static void printFatDate(uint16_t fatDate); static void printFatTime(uint16_t fatTime); bool printName(); int16_t read(); - int16_t read(void* buf, uint16_t nbyte); + int16_t read(void *buf, uint16_t nbyte); int8_t readDir(dir_t *dir, char *longFilename); - static bool remove(SdBaseFile* dirFile, const char *path); + static bool remove(SdBaseFile *dirFile, const char *path); bool remove(); /** * Set the file's current position to zero. */ void rewind() { seekSet(0); } - bool rename(SdBaseFile* dirFile, const char *newPath); + bool rename(SdBaseFile *dirFile, const char *newPath); bool rmdir(); bool rmRfStar(); @@ -325,7 +325,7 @@ class SdBaseFile { bool seekEnd(const int32_t offset = 0) { return seekSet(fileSize_ + offset); } bool seekSet(const uint32_t pos); bool sync(); - bool timestamp(SdBaseFile* file); + bool timestamp(SdBaseFile *file); bool timestamp(uint8_t flag, uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second); @@ -341,11 +341,11 @@ class SdBaseFile { * \return SdVolume that contains this file. */ SdVolume* volume() const { return vol_; } - int16_t write(const void* buf, uint16_t nbyte); + int16_t write(const void *buf, uint16_t nbyte); private: friend class SdFat; // allow SdFat to set cwd_ - static SdBaseFile* cwd_; // global pointer to cwd dir + static SdBaseFile *cwd_; // global pointer to cwd dir // data time callback function static void (*dateTime_)(uint16_t *date, uint16_t *time); @@ -364,21 +364,21 @@ class SdBaseFile { uint8_t dirIndex_; // index of directory entry in dirBlock uint32_t fileSize_; // file size in bytes uint32_t firstCluster_; // first cluster of file - SdVolume* vol_; // volume where file is located + SdVolume *vol_; // volume where file is located /** * EXPERIMENTAL - Don't use! */ - //bool openParent(SdBaseFile* dir); + //bool openParent(SdBaseFile *dir); // private functions bool addCluster(); bool addDirCluster(); dir_t* cacheDirEntry(uint8_t action); int8_t lsPrintNext(uint8_t flags, uint8_t indent); - static bool make83Name(const char *str, uint8_t *name, const char** ptr); - bool mkdir(SdBaseFile* parent, const uint8_t dname[11]); - bool open(SdBaseFile* dirFile, const uint8_t dname[11], uint8_t oflag); + static bool make83Name(const char *str, uint8_t *name, const char **ptr); + bool mkdir(SdBaseFile *parent, const uint8_t dname[11]); + bool open(SdBaseFile *dirFile, const uint8_t dname[11], uint8_t oflag); bool openCachedEntry(uint8_t cacheIndex, uint8_t oflags); dir_t* readDirCache(); }; diff --git a/Marlin/src/sd/SdFile.cpp b/Marlin/src/sd/SdFile.cpp index cc86ce819..bce96ef02 100644 --- a/Marlin/src/sd/SdFile.cpp +++ b/Marlin/src/sd/SdFile.cpp @@ -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 * 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 *buf, uint16_t nbyte) { return SdBaseFile::write(buf, nbyte); } /** * Write a byte to a file. Required by the Arduino Print class. diff --git a/Marlin/src/sd/SdFile.h b/Marlin/src/sd/SdFile.h index 69fe05b49..169189889 100644 --- a/Marlin/src/sd/SdFile.h +++ b/Marlin/src/sd/SdFile.h @@ -46,10 +46,10 @@ class SdFile : public SdBaseFile { #if ARDUINO >= 100 size_t write(uint8_t b); #else - void write(uint8_t b); + void write(uint8_t b); #endif - int16_t write(const void* buf, uint16_t nbyte); + int16_t write(const void *buf, uint16_t nbyte); void write(const char *str); void write_P(PGM_P str); void writeln_P(PGM_P str); diff --git a/Marlin/src/sd/SdVolume.h b/Marlin/src/sd/SdVolume.h index 812208745..c2eaf0bd1 100644 --- a/Marlin/src/sd/SdVolume.h +++ b/Marlin/src/sd/SdVolume.h @@ -90,8 +90,8 @@ class SdVolume { * Reasons for failure include not finding a valid partition, not finding * a valid FAT file system or an I/O error. */ - bool init(Sd2Card* dev) { return init(dev, 1) ? true : init(dev, 0); } - bool init(Sd2Card* dev, uint8_t part); + bool init(Sd2Card *dev) { return init(dev, 1) ? true : init(dev, 0); } + bool init(Sd2Card *dev, uint8_t part); // inline functions that return volume info uint8_t blocksPerCluster() const { return blocksPerCluster_; } //> \return The volume's cluster size in blocks. @@ -138,13 +138,13 @@ class SdVolume { #if USE_MULTIPLE_CARDS cache_t cacheBuffer_; // 512 byte cache for device blocks uint32_t cacheBlockNumber_; // Logical number of block in the cache - Sd2Card* sdCard_; // Sd2Card object for cache + Sd2Card *sdCard_; // Sd2Card object for cache bool cacheDirty_; // cacheFlush() will write block if true uint32_t cacheMirrorBlock_; // block number for mirror FAT #else static cache_t cacheBuffer_; // 512 byte cache for device blocks static uint32_t cacheBlockNumber_; // Logical number of block in the cache - static Sd2Card* sdCard_; // Sd2Card object for cache + static Sd2Card *sdCard_; // Sd2Card object for cache static bool cacheDirty_; // cacheFlush() will write block if true static uint32_t cacheMirrorBlock_; // block number for mirror FAT #endif diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index 53053e88d..225f7d9a9 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -723,9 +723,9 @@ void CardReader::report_status() { } void CardReader::write_command(char * const buf) { - char* begin = buf; - char* npos = nullptr; - char* end = buf + strlen(buf) - 1; + char *begin = buf; + char *npos = nullptr; + char *end = buf + strlen(buf) - 1; file.writeError = false; if ((npos = strchr(buf, 'N'))) { @@ -845,7 +845,7 @@ uint16_t CardReader::countFilesInWorkDir() { * * A nullptr result indicates an unrecoverable error. */ -const char* CardReader::diveToFile(const bool update_cwd, SdFile*& diveDir, const char * const path, const bool echo/*=false*/) { +const char* CardReader::diveToFile(const bool update_cwd, SdFile* &diveDir, const char * const path, const bool echo/*=false*/) { // Track both parent and subfolder static SdFile newDir1, newDir2; SdFile *sub = &newDir1, *startDir; diff --git a/Marlin/src/sd/cardreader.h b/Marlin/src/sd/cardreader.h index 1f917f857..9528c4ac2 100644 --- a/Marlin/src/sd/cardreader.h +++ b/Marlin/src/sd/cardreader.h @@ -141,7 +141,7 @@ public: static inline uint8_t percentDone() { return (isFileOpen() && filesize) ? sdpos / ((filesize + 99) / 100) : 0; } // Helper for open and remove - static const char* diveToFile(const bool update_cwd, SdFile*& curDir, const char * const path, const bool echo=false); + static const char* diveToFile(const bool update_cwd, SdFile* &curDir, const char * const path, const bool echo=false); #if ENABLED(SDCARD_SORT_ALPHA) static void presort(); @@ -168,8 +168,8 @@ public: static inline void setIndex(const uint32_t index) { file.seekSet((sdpos = index)); } static inline char* getWorkDirName() { workDir.getDosName(filename); return filename; } static inline int16_t get() { int16_t out = (int16_t)file.read(); sdpos = file.curPosition(); return out; } - static inline int16_t read(void* buf, uint16_t nbyte) { return file.isOpen() ? file.read(buf, nbyte) : -1; } - static inline int16_t write(void* buf, uint16_t nbyte) { return file.isOpen() ? file.write(buf, nbyte) : -1; } + static inline int16_t read(void *buf, uint16_t nbyte) { return file.isOpen() ? file.read(buf, nbyte) : -1; } + static inline int16_t write(void *buf, uint16_t nbyte) { return file.isOpen() ? file.write(buf, nbyte) : -1; } static Sd2Card& getSd2Card() { return sd2card; }