Apply loop shorthand macros (#17159)

This commit is contained in:
Scott Lahteine
2020-03-13 23:18:16 -05:00
committed by GitHub
parent a96be32fae
commit 118bd2f8b2
93 changed files with 465 additions and 505 deletions

View File

@ -197,7 +197,7 @@ void spiBegin() {
// output pin high - like sending 0xFF
WRITE(MOSI_PIN, HIGH);
for (uint8_t i = 0; i < 8; i++) {
LOOP_L_N(i, 8) {
WRITE(SCK_PIN, HIGH);
nop; // adjust so SCK is nice
@ -224,7 +224,7 @@ void spiBegin() {
void spiSend(uint8_t data) {
// no interrupts during byte send - about 8µs
cli();
for (uint8_t i = 0; i < 8; i++) {
LOOP_L_N(i, 8) {
WRITE(SCK_PIN, LOW);
WRITE(MOSI_PIN, data & 0x80);
data <<= 1;

View File

@ -682,7 +682,7 @@
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i = 0; i < digits; ++i) rounding *= 0.1;
LOOP_L_N(i, digits) rounding *= 0.1;
number += rounding;
// Extract the integer part of the number and print it

View File

@ -167,7 +167,7 @@ void set_pwm_frequency(const pin_t pin, int f_desired) {
uint16_t prescaler[] = { 0, 1, 8, /*TIMER2 ONLY*/32, 64, /*TIMER2 ONLY*/128, 256, 1024 };
// loop over prescaler values
for (uint8_t i = 1; i < 8; i++) {
LOOP_S_L_N(i, 1, 8) {
uint16_t res_temp_fast = 255, res_temp_phase_correct = 255;
if (timer.n == 2) {
// No resolution calculation for TIMER2 unless enabled USE_OCR2A_AS_TOP

View File

@ -70,12 +70,12 @@
void PRINT_ARRAY_NAME(uint8_t x) {
char *name_mem_pointer = (char*)pgm_read_ptr(&pin_array[x].name);
for (uint8_t y = 0; y < MAX_NAME_LENGTH; y++) {
LOOP_L_N(y, MAX_NAME_LENGTH) {
char temp_char = pgm_read_byte(name_mem_pointer + y);
if (temp_char != 0)
SERIAL_CHAR(temp_char);
else {
for (uint8_t i = 0; i < MAX_NAME_LENGTH - y; i++) SERIAL_CHAR(' ');
LOOP_L_N(i, MAX_NAME_LENGTH - y) SERIAL_CHAR(' ');
break;
}
}

View File

@ -88,7 +88,7 @@ void u8g_spiSend_sw_AVR_mode_0(uint8_t val) {
volatile uint8_t *outData = u8g_outData,
*outClock = u8g_outClock;
U8G_ATOMIC_START();
for (uint8_t i = 0; i < 8; i++) {
LOOP_L_N(i, 8) {
if (val & 0x80)
*outData |= bitData;
else
@ -108,7 +108,7 @@ void u8g_spiSend_sw_AVR_mode_3(uint8_t val) {
volatile uint8_t *outData = u8g_outData,
*outClock = u8g_outClock;
U8G_ATOMIC_START();
for (uint8_t i = 0; i < 8; i++) {
LOOP_L_N(i, 8) {
*outClock &= bitNotClock;
if (val & 0x80)
*outData |= bitData;

View File

@ -606,7 +606,7 @@ void MarlinSerial<Cfg>::printFloat(double number, uint8_t digits) {
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i = 0; i < digits; ++i) rounding *= 0.1;
LOOP_L_N(i, digits) rounding *= 0.1;
number += rounding;
// Extract the integer part of the number and print it

View File

@ -259,7 +259,7 @@ void MarlinSerialUSB::printFloat(double number, uint8_t digits) {
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i = 0; i < digits; ++i)
LOOP_L_N(i, digits)
rounding *= 0.1;
number += rounding;

View File

@ -80,7 +80,7 @@ Pio *SCK_pPio, *MOSI_pPio;
uint32_t SCK_dwMask, MOSI_dwMask;
void u8g_spiSend_sw_DUE_mode_0(uint8_t val) { // 3MHz
for (uint8_t i = 0; i < 8; i++) {
LOOP_L_N(i, 8) {
if (val & 0x80)
MOSI_pPio->PIO_SODR = MOSI_dwMask;
else
@ -94,7 +94,7 @@ void u8g_spiSend_sw_DUE_mode_0(uint8_t val) { // 3MHz
}
void u8g_spiSend_sw_DUE_mode_3(uint8_t val) { // 3.5MHz
for (uint8_t i = 0; i < 8; i++) {
LOOP_L_N(i, 8) {
SCK_pPio->PIO_CODR = SCK_dwMask;
DELAY_NS(50);
if (val & 0x80)

View File

@ -63,7 +63,7 @@ extern PWM_map ISR_table[NUM_PWMS];
extern uint32_t motor_current_setting[3];
#define IR_BIT(p) (WITHIN(p, 0, 3) ? (p) : (p) + 4)
#define COPY_ACTIVE_TABLE() do{ for (uint8_t i = 0; i < 6 ; i++) work_table[i] = active_table[i]; }while(0)
#define COPY_ACTIVE_TABLE() do{ LOOP_L_N(i, 6) work_table[i] = active_table[i]; }while(0)
#define PWM_MR0 19999 // base repetition rate minus one count - 20mS
#define PWM_PR 24 // prescaler value - prescaler divide by 24 + 1 - 1 MHz output

View File

@ -67,7 +67,7 @@ void HAL_init() {
#endif
// Flash status LED 3 times to indicate Marlin has started booting
for (uint8_t i = 0; i < 6; ++i) {
LOOP_L_N(i, 6) {
TOGGLE(LED_PIN);
delay(100);
}

View File

@ -73,7 +73,7 @@
uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, const pin_t sck_pin, const pin_t miso_pin, const pin_t mosi_pin ) {
for (uint8_t i = 0; i < 8; i++) {
LOOP_L_N(i, 8) {
if (spi_speed == 0) {
LPC176x::gpio_set(mosi_pin, !!(b & 0x80));
LPC176x::gpio_set(sck_pin, HIGH);
@ -83,16 +83,16 @@ uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, const pin_t sck
}
else {
const uint8_t state = (b & 0x80) ? HIGH : LOW;
for (uint8_t j = 0; j < spi_speed; j++)
LOOP_L_N(j, spi_speed)
LPC176x::gpio_set(mosi_pin, state);
for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
LOOP_L_N(j, spi_speed + (miso_pin >= 0 ? 0 : 1))
LPC176x::gpio_set(sck_pin, HIGH);
b <<= 1;
if (miso_pin >= 0 && LPC176x::gpio_get(miso_pin)) b |= 1;
for (uint8_t j = 0; j < spi_speed; j++)
LOOP_L_N(j, spi_speed)
LPC176x::gpio_set(sck_pin, LOW);
}
}
@ -102,7 +102,7 @@ uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, const pin_t sck
uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, const pin_t sck_pin, const pin_t miso_pin, const pin_t mosi_pin ) {
for (uint8_t i = 0; i < 8; i++) {
LOOP_L_N(i, 8) {
const uint8_t state = (b & 0x80) ? HIGH : LOW;
if (spi_speed == 0) {
LPC176x::gpio_set(sck_pin, LOW);
@ -111,13 +111,13 @@ uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, const pin_t sck
LPC176x::gpio_set(sck_pin, HIGH);
}
else {
for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
LOOP_L_N(j, spi_speed + (miso_pin >= 0 ? 0 : 1))
LPC176x::gpio_set(sck_pin, LOW);
for (uint8_t j = 0; j < spi_speed; j++)
LOOP_L_N(j, spi_speed)
LPC176x::gpio_set(mosi_pin, state);
for (uint8_t j = 0; j < spi_speed; j++)
LOOP_L_N(j, spi_speed)
LPC176x::gpio_set(sck_pin, HIGH);
}
b <<= 1;

View File

@ -478,10 +478,10 @@ void HAL_adc_init() {
#if ADC_IS_REQUIRED
memset(HAL_adc_results, 0xFF, sizeof(HAL_adc_results)); // Fill result with invalid values
for (uint8_t pi = 0; pi < COUNT(adc_pins); ++pi)
LOOP_L_N(pi, COUNT(adc_pins))
pinPeripheral(adc_pins[pi], PIO_ANALOG);
for (uint8_t ai = FIRST_ADC; ai <= LAST_ADC; ++ai) {
LOOP_S_LE_N(ai, FIRST_ADC, LAST_ADC) {
Adc* adc = ((Adc*[])ADC_INSTS)[ai];
// ADC clock setup
@ -513,7 +513,7 @@ void HAL_adc_init() {
void HAL_adc_start_conversion(const uint8_t adc_pin) {
#if ADC_IS_REQUIRED
for (uint8_t pi = 0; pi < COUNT(adc_pins); ++pi) {
LOOP_L_N(pi, COUNT(adc_pins)) {
if (adc_pin == adc_pins[pi]) {
HAL_adc_result = HAL_adc_results[pi];
return;

View File

@ -27,7 +27,7 @@
GPIO_TypeDef* FastIOPortMap[LastPort + 1];
void FastIO_init() {
for (uint8_t i = 0; i < NUM_DIGITAL_PINS; i++)
LOOP_L_N(i, NUM_DIGITAL_PINS)
FastIOPortMap[STM_PORT(digitalPin[i])] = get_GPIO_Port(STM_PORT(digitalPin[i]));
}

View File

@ -32,7 +32,7 @@
static uint8_t SPI_speed = SPI_SPEED;
static inline uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, const pin_t miso_pin=-1) {
for (uint8_t i = 0; i < 8; i++) {
LOOP_L_N(i, 8) {
if (spi_speed == 0) {
WRITE(DOGLCD_MOSI, !!(b & 0x80));
WRITE(DOGLCD_SCK, HIGH);
@ -42,16 +42,16 @@ static inline uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, c
}
else {
const uint8_t state = (b & 0x80) ? HIGH : LOW;
for (uint8_t j = 0; j < spi_speed; j++)
LOOP_L_N(j, spi_speed)
WRITE(DOGLCD_MOSI, state);
for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
LOOP_L_N(j, spi_speed + (miso_pin >= 0 ? 0 : 1))
WRITE(DOGLCD_SCK, HIGH);
b <<= 1;
if (miso_pin >= 0 && READ(miso_pin)) b |= 1;
for (uint8_t j = 0; j < spi_speed; j++)
LOOP_L_N(j, spi_speed)
WRITE(DOGLCD_SCK, LOW);
}
}
@ -59,7 +59,7 @@ static inline uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, c
}
static inline uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, const pin_t miso_pin=-1) {
for (uint8_t i = 0; i < 8; i++) {
LOOP_L_N(i, 8) {
const uint8_t state = (b & 0x80) ? HIGH : LOW;
if (spi_speed == 0) {
WRITE(DOGLCD_SCK, LOW);
@ -68,13 +68,13 @@ static inline uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, c
WRITE(DOGLCD_SCK, HIGH);
}
else {
for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
LOOP_L_N(j, spi_speed + (miso_pin >= 0 ? 0 : 1))
WRITE(DOGLCD_SCK, LOW);
for (uint8_t j = 0; j < spi_speed; j++)
LOOP_L_N(j, spi_speed)
WRITE(DOGLCD_MOSI, state);
for (uint8_t j = 0; j < spi_speed; j++)
LOOP_L_N(j, spi_speed)
WRITE(DOGLCD_SCK, HIGH);
}
b <<= 1;

View File

@ -102,7 +102,7 @@ void eeprom_read_block(void *__dst, const void *__src, size_t __n) {
uint16_t data = 0xFF;
uint16_t eeprom_address = unsigned(__src);
for (uint8_t c = 0; c < __n; c++) {
LOOP_L_N(c, __n) {
EE_ReadVariable(eeprom_address+c, &data);
*((uint8_t*)__dst + c) = data;
}

View File

@ -68,7 +68,7 @@ uint8_t ServoCount = 0; // the total number of attached
static boolean isTimerActive(timer16_Sequence_t timer) {
// returns true if any servo is active on this timer
for (uint8_t channel = 0; channel < SERVOS_PER_TIMER; channel++) {
LOOP_L_N(channel, SERVOS_PER_TIMER) {
if (SERVO(timer, channel).Pin.isActive)
return true;
}