From b0d621d8b96fffda485efa45e61a68126613a766 Mon Sep 17 00:00:00 2001 From: John Robertson Date: Mon, 4 Apr 2022 00:47:55 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Define=20is?= =?UTF-8?q?r=5Ffloat=5Ft=20to=20assert=20a=20non-FPU=20float=20(#23969)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Scott Lahteine --- Marlin/src/HAL/AVR/HAL.h | 2 +- Marlin/src/HAL/DUE/HAL.h | 2 +- Marlin/src/HAL/ESP32/HAL.cpp | 3 ++- Marlin/src/HAL/ESP32/HAL.h | 3 ++- Marlin/src/HAL/LPC1768/HAL.h | 2 +- Marlin/src/HAL/NATIVE_SIM/HAL.h | 2 +- Marlin/src/HAL/SAMD51/HAL.h | 2 +- Marlin/src/HAL/STM32/HAL.h | 4 +++- Marlin/src/HAL/STM32F1/HAL.h | 2 +- Marlin/src/HAL/TEENSY31_32/HAL.h | 2 +- Marlin/src/HAL/TEENSY35_36/HAL.h | 2 +- Marlin/src/HAL/TEENSY40_41/HAL.h | 2 +- Marlin/src/lcd/e3v2/marlinui/ui_status_480x272.cpp | 8 ++++---- 13 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Marlin/src/HAL/AVR/HAL.h b/Marlin/src/HAL/AVR/HAL.h index e825b4def3..c7454a5234 100644 --- a/Marlin/src/HAL/AVR/HAL.h +++ b/Marlin/src/HAL/AVR/HAL.h @@ -229,7 +229,7 @@ public: SBI(DIDR0, ch); } - // Begin ADC sampling on the given channel + // Begin ADC sampling on the given channel. Called from Temperature::isr! static void adc_start(const uint8_t ch) { #ifdef MUX5 ADCSRB = ch > 7 ? _BV(MUX5) : 0; diff --git a/Marlin/src/HAL/DUE/HAL.h b/Marlin/src/HAL/DUE/HAL.h index 9a02c9a0dc..d00c4d3da1 100644 --- a/Marlin/src/HAL/DUE/HAL.h +++ b/Marlin/src/HAL/DUE/HAL.h @@ -209,7 +209,7 @@ public: // Called by Temperature::init for each sensor at startup static void adc_enable(const uint8_t ch) {} - // Begin ADC sampling on the given channel + // Begin ADC sampling on the given channel. Called from Temperature::isr! static void adc_start(const uint8_t ch) { adc_result = analogRead(ch); } // Is the ADC ready for reading? diff --git a/Marlin/src/HAL/ESP32/HAL.cpp b/Marlin/src/HAL/ESP32/HAL.cpp index 44be0b540a..fbb3eac0db 100644 --- a/Marlin/src/HAL/ESP32/HAL.cpp +++ b/Marlin/src/HAL/ESP32/HAL.cpp @@ -244,7 +244,8 @@ void MarlinHAL::adc_start(const pin_t pin) { const adc1_channel_t chan = get_channel(pin); uint32_t mv; esp_adc_cal_get_voltage((adc_channel_t)chan, &characteristics[attenuations[chan]], &mv); - adc_result = mv * 1023.0f / float(ADC_REFERENCE_VOLTAGE) / 1000.0f; + + adc_result = mv * isr_float_t(1023) / isr_float_t(ADC_REFERENCE_VOLTAGE) / isr_float_t(1000); // Change the attenuation level based on the new reading adc_atten_t atten; diff --git a/Marlin/src/HAL/ESP32/HAL.h b/Marlin/src/HAL/ESP32/HAL.h index 8b26c3471d..f7e4383a85 100644 --- a/Marlin/src/HAL/ESP32/HAL.h +++ b/Marlin/src/HAL/ESP32/HAL.h @@ -74,6 +74,7 @@ // Types // ------------------------ +typedef double isr_float_t; // FPU ops are used for single-precision, so use double for ISRs. typedef int16_t pin_t; class Servo; @@ -205,7 +206,7 @@ public: // Called by Temperature::init for each sensor at startup static void adc_enable(const pin_t pin) {} - // Begin ADC sampling on the given channel + // Begin ADC sampling on the given pin. Called from Temperature::isr! static void adc_start(const pin_t pin); // Is the ADC ready for reading? diff --git a/Marlin/src/HAL/LPC1768/HAL.h b/Marlin/src/HAL/LPC1768/HAL.h index eefacae995..0f26509129 100644 --- a/Marlin/src/HAL/LPC1768/HAL.h +++ b/Marlin/src/HAL/LPC1768/HAL.h @@ -234,7 +234,7 @@ public: FilteredADC::enable_channel(pin); } - // Begin ADC sampling on the given pin + // Begin ADC sampling on the given pin. Called from Temperature::isr! static uint32_t adc_result; static void adc_start(const pin_t pin) { adc_result = FilteredADC::read(pin) >> (16 - HAL_ADC_RESOLUTION); // returns 16bit value, reduce to required bits diff --git a/Marlin/src/HAL/NATIVE_SIM/HAL.h b/Marlin/src/HAL/NATIVE_SIM/HAL.h index ee2e31fc7f..49a5b6ea56 100644 --- a/Marlin/src/HAL/NATIVE_SIM/HAL.h +++ b/Marlin/src/HAL/NATIVE_SIM/HAL.h @@ -242,7 +242,7 @@ public: // Called by Temperature::init for each sensor at startup static void adc_enable(const uint8_t ch); - // Begin ADC sampling on the given channel + // Begin ADC sampling on the given channel. Called from Temperature::isr! static void adc_start(const uint8_t ch); // Is the ADC ready for reading? diff --git a/Marlin/src/HAL/SAMD51/HAL.h b/Marlin/src/HAL/SAMD51/HAL.h index 3b09a885a5..abcc280987 100644 --- a/Marlin/src/HAL/SAMD51/HAL.h +++ b/Marlin/src/HAL/SAMD51/HAL.h @@ -190,7 +190,7 @@ public: // Called by Temperature::init for each sensor at startup static void adc_enable(const uint8_t ch) {} - // Begin ADC sampling on the given channel + // Begin ADC sampling on the given pin. Called from Temperature::isr! static void adc_start(const pin_t pin); // Is the ADC ready for reading? diff --git a/Marlin/src/HAL/STM32/HAL.h b/Marlin/src/HAL/STM32/HAL.h index f5e8c1187d..d88342b889 100644 --- a/Marlin/src/HAL/STM32/HAL.h +++ b/Marlin/src/HAL/STM32/HAL.h @@ -127,6 +127,8 @@ // Types // ------------------------ +typedef double isr_float_t; // FPU ops are used for single-precision, so use double for ISRs. + #ifdef STM32G0B1xx typedef int32_t pin_t; #else @@ -241,7 +243,7 @@ public: // Called by Temperature::init for each sensor at startup static void adc_enable(const pin_t pin) { pinMode(pin, INPUT); } - // Begin ADC sampling on the given channel + // Begin ADC sampling on the given pin. Called from Temperature::isr! static void adc_start(const pin_t pin) { adc_result = analogRead(pin); } // Is the ADC ready for reading? diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h index ceb17b4884..a42dd89b8d 100644 --- a/Marlin/src/HAL/STM32F1/HAL.h +++ b/Marlin/src/HAL/STM32F1/HAL.h @@ -280,7 +280,7 @@ public: // Called by Temperature::init for each sensor at startup static void adc_enable(const pin_t pin) { pinMode(pin, INPUT_ANALOG); } - // Begin ADC sampling on the given channel + // Begin ADC sampling on the given pin. Called from Temperature::isr! static void adc_start(const pin_t pin); // Is the ADC ready for reading? diff --git a/Marlin/src/HAL/TEENSY31_32/HAL.h b/Marlin/src/HAL/TEENSY31_32/HAL.h index 50c0f411cf..dc0d2d3fa9 100644 --- a/Marlin/src/HAL/TEENSY31_32/HAL.h +++ b/Marlin/src/HAL/TEENSY31_32/HAL.h @@ -166,7 +166,7 @@ public: // Called by Temperature::init for each sensor at startup static void adc_enable(const pin_t ch) {} - // Begin ADC sampling on the given channel + // Begin ADC sampling on the given channel. Called from Temperature::isr! static void adc_start(const pin_t ch); // Is the ADC ready for reading? diff --git a/Marlin/src/HAL/TEENSY35_36/HAL.h b/Marlin/src/HAL/TEENSY35_36/HAL.h index e4c57f8d1e..c45f2aa493 100644 --- a/Marlin/src/HAL/TEENSY35_36/HAL.h +++ b/Marlin/src/HAL/TEENSY35_36/HAL.h @@ -173,7 +173,7 @@ public: // Called by Temperature::init for each sensor at startup static void adc_enable(const pin_t) {} - // Begin ADC sampling on the given channel + // Begin ADC sampling on the given pin. Called from Temperature::isr! static void adc_start(const pin_t pin); // Is the ADC ready for reading? diff --git a/Marlin/src/HAL/TEENSY40_41/HAL.h b/Marlin/src/HAL/TEENSY40_41/HAL.h index a21e652854..ea874da2fa 100644 --- a/Marlin/src/HAL/TEENSY40_41/HAL.h +++ b/Marlin/src/HAL/TEENSY40_41/HAL.h @@ -195,7 +195,7 @@ public: // Called by Temperature::init for each sensor at startup static void adc_enable(const pin_t pin) {} - // Begin ADC sampling on the given channel + // Begin ADC sampling on the given pin. Called from Temperature::isr! static void adc_start(const pin_t pin); // Is the ADC ready for reading? diff --git a/Marlin/src/lcd/e3v2/marlinui/ui_status_480x272.cpp b/Marlin/src/lcd/e3v2/marlinui/ui_status_480x272.cpp index 2a4909d921..ba6814a57a 100644 --- a/Marlin/src/lcd/e3v2/marlinui/ui_status_480x272.cpp +++ b/Marlin/src/lcd/e3v2/marlinui/ui_status_480x272.cpp @@ -196,13 +196,13 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater, const uint16_t x #else #define HOTEND_STATS 1 #endif - static celsius_t old_temp[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, 500), - old_target[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, 500); - static bool old_on[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, false); + static celsius_t old_temp[HOTEND_STATS] = { 0 }, + old_target[HOTEND_STATS] = { 0 }; + static bool old_on[HOTEND_STATS] = { false }; #endif #if HAS_HEATED_BED - static celsius_t old_bed_temp = 500, old_bed_target = 500; + static celsius_t old_bed_temp = 0, old_bed_target = 0; static bool old_bed_on = false; #if HAS_LEVELING static bool old_leveling_on = false;