Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Define isr_float_t to assert a non-FPU float (MarlinFirmware#23969)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <[email protected]>
  • Loading branch information
HoverClub and thinkyhead authored Apr 3, 2022
1 parent 283aca5 commit f7fff4d
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/HAL/AVR/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class MarlinHAL {
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;
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/DUE/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class MarlinHAL {
// 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?
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/HAL/ESP32/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/HAL/ESP32/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -205,7 +206,7 @@ class MarlinHAL {
// 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?
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/LPC1768/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class MarlinHAL {
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
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/NATIVE_SIM/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class MarlinHAL {
// 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?
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/SAMD51/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class MarlinHAL {
// 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?
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/HAL/STM32/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -241,7 +243,7 @@ class MarlinHAL {
// 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?
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32F1/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class MarlinHAL {
// 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?
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/TEENSY31_32/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class MarlinHAL {
// 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?
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/TEENSY35_36/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class MarlinHAL {
// 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?
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/TEENSY40_41/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class MarlinHAL {
// 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?
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/lcd/e3v2/marlinui/ui_status_480x272.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f7fff4d

Please sign in to comment.