Apply loop shorthand macros (#17159)
This commit is contained in:
@ -74,7 +74,7 @@
|
||||
#else
|
||||
static uint8_t CRC7(const uint8_t* data, uint8_t n) {
|
||||
uint8_t crc = 0;
|
||||
for (uint8_t i = 0; i < n; i++) {
|
||||
LOOP_L_N(i, n) {
|
||||
uint8_t d = data[i];
|
||||
d ^= crc << 1;
|
||||
if (d & 0x80) d ^= 9;
|
||||
@ -106,7 +106,7 @@ uint8_t Sd2Card::cardCommand(const uint8_t cmd, const uint32_t arg) {
|
||||
d[5] = CRC7(d, 5);
|
||||
|
||||
// Send message
|
||||
for (uint8_t k = 0; k < 6; k++) spiSend(d[k]);
|
||||
LOOP_L_N(k, 6) spiSend(d[k]);
|
||||
|
||||
#else
|
||||
// Send command
|
||||
@ -246,7 +246,7 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
|
||||
spiInit(spiRate_);
|
||||
|
||||
// Must supply min of 74 clock cycles with CS high.
|
||||
for (uint8_t i = 0; i < 10; i++) spiSend(0xFF);
|
||||
LOOP_L_N(i, 10) spiSend(0xFF);
|
||||
|
||||
watchdog_refresh(); // In case init takes too long
|
||||
|
||||
@ -272,7 +272,7 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
|
||||
}
|
||||
|
||||
// Get the last byte of r7 response
|
||||
for (uint8_t i = 0; i < 4; i++) status_ = spiRec();
|
||||
LOOP_L_N(i, 4) status_ = spiRec();
|
||||
if (status_ == 0xAA) {
|
||||
type(SD_CARD_TYPE_SD2);
|
||||
break;
|
||||
@ -303,7 +303,7 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
|
||||
}
|
||||
if ((spiRec() & 0xC0) == 0xC0) type(SD_CARD_TYPE_SDHC);
|
||||
// Discard rest of ocr - contains allowed voltage range
|
||||
for (uint8_t i = 0; i < 3; i++) spiRec();
|
||||
LOOP_L_N(i, 3) spiRec();
|
||||
}
|
||||
chipDeselect();
|
||||
|
||||
|
@ -204,7 +204,7 @@ bool SdBaseFile::dirEntry(dir_t* dir) {
|
||||
*/
|
||||
void SdBaseFile::dirName(const dir_t& dir, char* name) {
|
||||
uint8_t j = 0;
|
||||
for (uint8_t i = 0; i < 11; i++) {
|
||||
LOOP_L_N(i, 11) {
|
||||
if (dir.name[i] == ' ')continue;
|
||||
if (i == 8) name[j++] = '.';
|
||||
name[j++] = dir.name[i];
|
||||
@ -345,10 +345,10 @@ int8_t SdBaseFile::lsPrintNext(uint8_t flags, uint8_t indent) {
|
||||
&& DIR_IS_FILE_OR_SUBDIR(&dir)) break;
|
||||
}
|
||||
// indent for dir level
|
||||
for (uint8_t i = 0; i < indent; i++) SERIAL_CHAR(' ');
|
||||
LOOP_L_N(i, indent) SERIAL_CHAR(' ');
|
||||
|
||||
// print name
|
||||
for (uint8_t i = 0; i < 11; i++) {
|
||||
LOOP_L_N(i, 11) {
|
||||
if (dir.name[i] == ' ')continue;
|
||||
if (i == 8) {
|
||||
SERIAL_CHAR('.');
|
||||
@ -478,7 +478,7 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const uint8_t dname[11]) {
|
||||
// make entry for '.'
|
||||
memcpy(&d, p, sizeof(d));
|
||||
d.name[0] = '.';
|
||||
for (uint8_t i = 1; i < 11; i++) d.name[i] = ' ';
|
||||
LOOP_S_L_N(i, 1, 11) d.name[i] = ' ';
|
||||
|
||||
// cache block for '.' and '..'
|
||||
block = vol_->clusterStartBlock(firstCluster_);
|
||||
@ -1088,7 +1088,7 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
|
||||
if (WITHIN(seq, 1, MAX_VFAT_ENTRIES)) {
|
||||
// TODO: Store the filename checksum to verify if a long-filename-unaware system modified the file table.
|
||||
n = (seq - 1) * (FILENAME_LENGTH);
|
||||
for (uint8_t i = 0; i < FILENAME_LENGTH; i++)
|
||||
LOOP_L_N(i, FILENAME_LENGTH)
|
||||
longFilename[n + i] = (i < 5) ? VFAT->name1[i] : (i < 11) ? VFAT->name2[i - 5] : VFAT->name3[i - 11];
|
||||
// If this VFAT entry is the last one, add a NUL terminator at the end of the string
|
||||
if (VFAT->sequenceNumber & 0x40) longFilename[n + FILENAME_LENGTH] = '\0';
|
||||
|
@ -143,7 +143,7 @@ CardReader::CardReader() {
|
||||
//
|
||||
char *createFilename(char * const buffer, const dir_t &p) {
|
||||
char *pos = buffer;
|
||||
for (uint8_t i = 0; i < 11; i++) {
|
||||
LOOP_L_N(i, 11) {
|
||||
if (p.name[i] == ' ') continue;
|
||||
if (i == 8) *pos++ = '.';
|
||||
*pos++ = p.name[i];
|
||||
@ -435,7 +435,7 @@ void CardReader::getAbsFilename(char *dst) {
|
||||
if (cnt < MAXPATHNAMELENGTH) { *dst = '/'; dst++; cnt++; }
|
||||
};
|
||||
|
||||
for (uint8_t i = 0; i < workDirDepth; i++) // Loop down to current work dir
|
||||
LOOP_L_N(i, workDirDepth) // Loop down to current work dir
|
||||
appendAtom(workDirParents[i]);
|
||||
|
||||
if (cnt < MAXPATHNAMELENGTH - (FILENAME_LENGTH) - 1) { // Leave room for filename and nul
|
||||
@ -1046,7 +1046,7 @@ void CardReader::cdroot() {
|
||||
#if ENABLED(SDSORT_DYNAMIC_RAM)
|
||||
delete sort_order;
|
||||
#if ENABLED(SDSORT_CACHE_NAMES)
|
||||
for (uint8_t i = 0; i < sort_count; ++i) {
|
||||
LOOP_L_N(i, sort_count) {
|
||||
free(sortshort[i]); // strdup
|
||||
free(sortnames[i]); // strdup
|
||||
}
|
||||
|
Reference in New Issue
Block a user