diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL.cpp b/Marlin/src/HAL/HAL_STM32F1/HAL.cpp index f75a071bc..95dbb0a50 100644 --- a/Marlin/src/HAL/HAL_STM32F1/HAL.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/HAL.cpp @@ -101,19 +101,19 @@ uint16_t HAL_adc_result; STM32ADC adc(ADC1); uint8 adc_pins[] = { - #if HAS_TEMP_0 + #if HAS_TEMP_ADC_0 TEMP_0_PIN, #endif - #if HAS_TEMP_1 + #if HAS_TEMP_ADC_1 TEMP_1_PIN #endif - #if HAS_TEMP_2 + #if HAS_TEMP_ADC_2 TEMP_2_PIN, #endif - #if HAS_TEMP_3 + #if HAS_TEMP_ADC_3 TEMP_3_PIN, #endif - #if HAS_TEMP_4 + #if HAS_TEMP_ADC_4 TEMP_4_PIN, #endif #if HAS_HEATED_BED @@ -125,19 +125,19 @@ uint8 adc_pins[] = { }; enum TEMP_PINS : char { - #if HAS_TEMP_0 + #if HAS_TEMP_ADC_0 TEMP_0, #endif - #if HAS_TEMP_1 + #if HAS_TEMP_ADC_1 TEMP_1, #endif - #if HAS_TEMP_2 + #if HAS_TEMP_ADC_2 TEMP_2, #endif - #if HAS_TEMP_3 + #if HAS_TEMP_ADC_3 TEMP_3, #endif - #if HAS_TEMP_4 + #if HAS_TEMP_ADC_4 TEMP_4, #endif #if HAS_HEATED_BED @@ -247,19 +247,19 @@ void HAL_adc_init(void) { void HAL_adc_start_conversion(const uint8_t adc_pin) { TEMP_PINS pin_index; switch (adc_pin) { - #if HAS_TEMP_0 + #if HAS_TEMP_ADC_0 case TEMP_0_PIN: pin_index = TEMP_0; break; #endif - #if HAS_TEMP_1 + #if HAS_TEMP_ADC_1 case TEMP_1_PIN: pin_index = TEMP_1; break; #endif - #if HAS_TEMP_2 + #if HAS_TEMP_ADC_2 case TEMP_2_PIN: pin_index = TEMP_2; break; #endif - #if HAS_TEMP_3 + #if HAS_TEMP_ADC_3 case TEMP_3_PIN: pin_index = TEMP_3; break; #endif - #if HAS_TEMP_4 + #if HAS_TEMP_ADC_4 case TEMP_4_PIN: pin_index = TEMP_4; break; #endif #if HAS_HEATED_BED diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 423dd291e..0845dd54e 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -328,8 +328,10 @@ #if TEMP_SENSOR_1 == -4 #define HEATER_1_USES_AD8495 -#elif TEMP_SENSOR_1 <= -2 - #error "MAX6675 / MAX31855 Thermocouples not supported for TEMP_SENSOR_1" +#elif TEMP_SENSOR_1 == -3 + #error "MAX31855 Thermocouples not supported for TEMP_SENSOR_1" +#elif TEMP_SENSOR_1 == -2 + #error "MAX6675 Thermocouples not supported for TEMP_SENSOR_1" #elif TEMP_SENSOR_1 == -1 #define HEATER_1_USES_AD595 #elif TEMP_SENSOR_1 == 0 @@ -342,8 +344,10 @@ #if TEMP_SENSOR_2 == -4 #define HEATER_2_USES_AD8495 -#elif TEMP_SENSOR_2 <= -2 - #error "MAX6675 / MAX31855 Thermocouples not supported for TEMP_SENSOR_2" +#elif TEMP_SENSOR_2 == -3 + #error "MAX31855 Thermocouples not supported for TEMP_SENSOR_2" +#elif TEMP_SENSOR_2 == -2 + #error "MAX6675 Thermocouples not supported for TEMP_SENSOR_2" #elif TEMP_SENSOR_2 == -1 #define HEATER_2_USES_AD595 #elif TEMP_SENSOR_2 == 0 @@ -356,8 +360,10 @@ #if TEMP_SENSOR_3 == -4 #define HEATER_3_USES_AD8495 -#elif TEMP_SENSOR_3 <= -2 - #error "MAX6675 / MAX31855 Thermocouples not supported for TEMP_SENSOR_3" +#elif TEMP_SENSOR_3 == -3 + #error "MAX31855 Thermocouples not supported for TEMP_SENSOR_3" +#elif TEMP_SENSOR_3 == -2 + #error "MAX6675 Thermocouples not supported for TEMP_SENSOR_3" #elif TEMP_SENSOR_3 == -1 #define HEATER_3_USES_AD595 #elif TEMP_SENSOR_3 == 0 @@ -370,8 +376,10 @@ #if TEMP_SENSOR_4 == -4 #define HEATER_4_USES_AD8495 -#elif TEMP_SENSOR_4 <= -2 - #error "MAX6675 / MAX31855 Thermocouples not supported for TEMP_SENSOR_4" +#elif TEMP_SENSOR_4 == -3 + #error "MAX31855 Thermocouples not supported for TEMP_SENSOR_4" +#elif TEMP_SENSOR_4 == -2 + #error "MAX6675 Thermocouples not supported for TEMP_SENSOR_4" #elif TEMP_SENSOR_4 == -1 #define HEATER_4_USES_AD595 #elif TEMP_SENSOR_4 == 0 @@ -384,8 +392,10 @@ #if TEMP_SENSOR_BED == -4 #define BED_USES_AD8495 -#elif TEMP_SENSOR_BED <= -2 - #error "MAX6675 / MAX31855 Thermocouples not supported for TEMP_SENSOR_BED" +#elif TEMP_SENSOR_BED == -3 + #error "MAX31855 Thermocouples not supported for TEMP_SENSOR_BED" +#elif TEMP_SENSOR_BED == -2 + #error "MAX6675 Thermocouples not supported for TEMP_SENSOR_BED" #elif TEMP_SENSOR_BED == -1 #define BED_USES_AD595 #elif TEMP_SENSOR_BED == 0 @@ -398,8 +408,10 @@ #if TEMP_SENSOR_CHAMBER == -4 #define CHAMBER_USES_AD8495 -#elif TEMP_SENSOR_CHAMBER <= -2 - #error "MAX6675 / MAX31855 Thermocouples not supported for TEMP_SENSOR_CHAMBER" +#elif TEMP_SENSOR_CHAMBER == -3 + #error "MAX31855 Thermocouples not supported for TEMP_SENSOR_CHAMBER" +#elif TEMP_SENSOR_CHAMBER == -2 + #error "MAX6675 Thermocouples not supported for TEMP_SENSOR_CHAMBER" #elif TEMP_SENSOR_CHAMBER == -1 #define CHAMBER_USES_AD595 #elif TEMP_SENSOR_CHAMBER > 0 @@ -407,10 +419,10 @@ #define CHAMBER_USES_THERMISTOR #endif -#define HEATER_USES_AD8495 (ENABLED(HEATER_0_USES_AD8495) || ENABLED(HEATER_1_USES_AD8495) || ENABLED(HEATER_2_USES_AD8495) || ENABLED(HEATER_3_USES_AD8495)) +#define HEATER_USES_AD8495 (ENABLED(HEATER_0_USES_AD8495) || ENABLED(HEATER_1_USES_AD8495) || ENABLED(HEATER_2_USES_AD8495) || ENABLED(HEATER_3_USES_AD8495) || ENABLED(HEATER_4_USES_AD8495)) #ifdef __SAM3X8E__ - #define HEATER_USES_AD595 (ENABLED(HEATER_0_USES_AD595) || ENABLED(HEATER_1_USES_AD595) || ENABLED(HEATER_2_USES_AD595) || ENABLED(HEATER_3_USES_AD595)) + #define HEATER_USES_AD595 (ENABLED(HEATER_0_USES_AD595) || ENABLED(HEATER_1_USES_AD595) || ENABLED(HEATER_2_USES_AD595) || ENABLED(HEATER_3_USES_AD595) || ENABLED(HEATER_4_USES_AD595)) #endif /** @@ -746,12 +758,13 @@ #endif // Endstops and bed probe -#define HAS_X_MIN (PIN_EXISTS(X_MIN) && !IS_X2_ENDSTOP(X,MIN) && !IS_Y2_ENDSTOP(X,MIN) && !IS_Z2_OR_PROBE(X,MIN)) -#define HAS_X_MAX (PIN_EXISTS(X_MAX) && !IS_X2_ENDSTOP(X,MAX) && !IS_Y2_ENDSTOP(X,MAX) && !IS_Z2_OR_PROBE(X,MAX)) -#define HAS_Y_MIN (PIN_EXISTS(Y_MIN) && !IS_X2_ENDSTOP(Y,MIN) && !IS_Y2_ENDSTOP(Y,MIN) && !IS_Z2_OR_PROBE(Y,MIN)) -#define HAS_Y_MAX (PIN_EXISTS(Y_MAX) && !IS_X2_ENDSTOP(Y,MAX) && !IS_Y2_ENDSTOP(Y,MAX) && !IS_Z2_OR_PROBE(Y,MAX)) -#define HAS_Z_MIN (PIN_EXISTS(Z_MIN) && !IS_X2_ENDSTOP(Z,MIN) && !IS_Y2_ENDSTOP(Z,MIN) && !IS_Z2_OR_PROBE(Z,MIN)) -#define HAS_Z_MAX (PIN_EXISTS(Z_MAX) && !IS_X2_ENDSTOP(Z,MAX) && !IS_Y2_ENDSTOP(Z,MAX) && !IS_Z2_OR_PROBE(Z,MAX)) +#define HAS_STOP_TEST(A,M) (PIN_EXISTS(A##_##M) && !IS_X2_ENDSTOP(A,M) && !IS_Y2_ENDSTOP(A,M) && !IS_Z2_OR_PROBE(A,M)) +#define HAS_X_MIN HAS_STOP_TEST(X,MIN) +#define HAS_X_MAX HAS_STOP_TEST(X,MAX) +#define HAS_Y_MIN HAS_STOP_TEST(Y,MIN) +#define HAS_Y_MAX HAS_STOP_TEST(Y,MAX) +#define HAS_Z_MIN HAS_STOP_TEST(Z,MIN) +#define HAS_Z_MAX HAS_STOP_TEST(Z,MAX) #define HAS_X2_MIN (PIN_EXISTS(X2_MIN)) #define HAS_X2_MAX (PIN_EXISTS(X2_MAX)) #define HAS_Y2_MIN (PIN_EXISTS(Y2_MIN)) @@ -761,14 +774,18 @@ #define HAS_Z_MIN_PROBE_PIN (PIN_EXISTS(Z_MIN_PROBE)) // Thermistors -#define HAS_TEMP_0 (PIN_EXISTS(TEMP_0) && TEMP_SENSOR_0 != 0 && TEMP_SENSOR_0 > -2) -#define HAS_TEMP_1 (PIN_EXISTS(TEMP_1) && TEMP_SENSOR_1 != 0 && TEMP_SENSOR_1 > -2) -#define HAS_TEMP_2 (PIN_EXISTS(TEMP_2) && TEMP_SENSOR_2 != 0 && TEMP_SENSOR_2 > -2) -#define HAS_TEMP_3 (PIN_EXISTS(TEMP_3) && TEMP_SENSOR_3 != 0 && TEMP_SENSOR_3 > -2) -#define HAS_TEMP_4 (PIN_EXISTS(TEMP_4) && TEMP_SENSOR_4 != 0 && TEMP_SENSOR_4 > -2) -#define HAS_TEMP_HOTEND (HAS_TEMP_0 || ENABLED(HEATER_0_USES_MAX6675)) -#define HAS_TEMP_BED (PIN_EXISTS(TEMP_BED) && TEMP_SENSOR_BED != 0 && (TEMP_SENSOR_BED > -2 || TEMP_SENSOR_BED == -4)) -#define HAS_TEMP_CHAMBER (PIN_EXISTS(TEMP_CHAMBER) && TEMP_SENSOR_CHAMBER != 0 && TEMP_SENSOR_CHAMBER > -2) +#define HAS_ADC_TEST(P) (PIN_EXISTS(TEMP_##P) && TEMP_SENSOR_##P != 0 && TEMP_SENSOR_##P > -2) +#define HAS_TEMP_ADC_0 (HAS_ADC_TEST(0) && DISABLED(HEATER_0_USES_MAX6675)) +#define HAS_TEMP_ADC_1 HAS_ADC_TEST(1) +#define HAS_TEMP_ADC_2 HAS_ADC_TEST(2) +#define HAS_TEMP_ADC_3 HAS_ADC_TEST(3) +#define HAS_TEMP_ADC_4 HAS_ADC_TEST(4) +#define HAS_TEMP_ADC_BED HAS_ADC_TEST(BED) +#define HAS_TEMP_ADC_CHAMBER HAS_ADC_TEST(CHAMBER) + +#define HAS_TEMP_HOTEND (HAS_TEMP_ADC_0 || ENABLED(HEATER_0_USES_MAX6675)) +#define HAS_TEMP_BED HAS_TEMP_ADC_BED +#define HAS_TEMP_CHAMBER HAS_TEMP_ADC_CHAMBER // Heaters #define HAS_HEATER_0 (PIN_EXISTS(HEATER_0)) diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 3f0e7b604..704baaa93 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -1579,7 +1579,7 @@ void lcd_quick_feedback(const bool clear_buttons) { */ void _lcd_preheat(const int16_t endnum, const int16_t temph, const int16_t tempb, const int16_t fan) { if (temph > 0) thermalManager.setTargetHotend(min(heater_maxtemp[endnum], temph), endnum); - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED if (tempb >= 0) thermalManager.setTargetBed(tempb); #else UNUSED(tempb); @@ -1596,10 +1596,10 @@ void lcd_quick_feedback(const bool clear_buttons) { lcd_return_to_status(); } - #if TEMP_SENSOR_0 != 0 + #if HAS_TEMP_HOTEND void lcd_preheat_m1_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); } void lcd_preheat_m2_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); } - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED void lcd_preheat_m1_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); } void lcd_preheat_m2_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); } #endif @@ -1608,28 +1608,28 @@ void lcd_quick_feedback(const bool clear_buttons) { #if HOTENDS > 1 void lcd_preheat_m1_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); } void lcd_preheat_m2_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); } - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED void lcd_preheat_m1_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); } void lcd_preheat_m2_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); } #endif #if HOTENDS > 2 void lcd_preheat_m1_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); } void lcd_preheat_m2_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); } - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED void lcd_preheat_m1_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); } void lcd_preheat_m2_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); } #endif #if HOTENDS > 3 void lcd_preheat_m1_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); } void lcd_preheat_m2_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); } - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED void lcd_preheat_m1_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); } void lcd_preheat_m2_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); } #endif #if HOTENDS > 4 void lcd_preheat_m1_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); } void lcd_preheat_m2_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); } - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED void lcd_preheat_m1_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); } void lcd_preheat_m2_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); } #endif @@ -1650,7 +1650,7 @@ void lcd_quick_feedback(const bool clear_buttons) { #endif // HOTENDS > 3 #endif // HOTENDS > 2 #endif // HOTENDS > 1 - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED lcd_preheat_m1_e0(); #else lcd_preheat_m1_e0_only(); @@ -1669,7 +1669,7 @@ void lcd_quick_feedback(const bool clear_buttons) { #endif // HOTENDS > 3 #endif // HOTENDS > 2 #endif // HOTENDS > 1 - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED lcd_preheat_m2_e0(); #else lcd_preheat_m2_e0_only(); @@ -1678,25 +1678,25 @@ void lcd_quick_feedback(const bool clear_buttons) { #endif // HOTENDS > 1 - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED void lcd_preheat_m1_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); } void lcd_preheat_m2_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); } #endif - #if TEMP_SENSOR_0 != 0 && (TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || TEMP_SENSOR_BED != 0) + #if HAS_TEMP_HOTEND && (TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || HAS_HEATED_BED) void lcd_preheat_m1_menu() { START_MENU(); MENU_BACK(MSG_PREPARE); #if HOTENDS == 1 - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0); MENU_ITEM(function, MSG_PREHEAT_1_END, lcd_preheat_m1_e0_only); #else MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only); #endif #else - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0); MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E1, lcd_preheat_m1_e0_only); MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1); @@ -1706,21 +1706,21 @@ void lcd_quick_feedback(const bool clear_buttons) { MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1_only); #endif #if HOTENDS > 2 - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2); MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E3, lcd_preheat_m1_e2_only); #else MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2_only); #endif #if HOTENDS > 3 - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3); MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E4, lcd_preheat_m1_e3_only); #else MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3_only); #endif #if HOTENDS > 4 - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4); MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E5, lcd_preheat_m1_e4_only); #else @@ -1731,7 +1731,7 @@ void lcd_quick_feedback(const bool clear_buttons) { #endif // HOTENDS > 2 MENU_ITEM(function, MSG_PREHEAT_1_ALL, lcd_preheat_m1_all); #endif // HOTENDS > 1 - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED MENU_ITEM(function, MSG_PREHEAT_1_BEDONLY, lcd_preheat_m1_bedonly); #endif END_MENU(); @@ -1741,14 +1741,14 @@ void lcd_quick_feedback(const bool clear_buttons) { START_MENU(); MENU_BACK(MSG_PREPARE); #if HOTENDS == 1 - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0); MENU_ITEM(function, MSG_PREHEAT_2_END, lcd_preheat_m2_e0_only); #else MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only); #endif #else - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0); MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E1, lcd_preheat_m2_e0_only); MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1); @@ -1758,21 +1758,21 @@ void lcd_quick_feedback(const bool clear_buttons) { MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1_only); #endif #if HOTENDS > 2 - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2); MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E3, lcd_preheat_m2_e2_only); #else MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2_only); #endif #if HOTENDS > 3 - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3); MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E4, lcd_preheat_m2_e3_only); #else MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3_only); #endif #if HOTENDS > 4 - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4); MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E5, lcd_preheat_m2_e4_only); #else @@ -1783,13 +1783,13 @@ void lcd_quick_feedback(const bool clear_buttons) { #endif // HOTENDS > 2 MENU_ITEM(function, MSG_PREHEAT_2_ALL, lcd_preheat_m2_all); #endif // HOTENDS > 1 - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED MENU_ITEM(function, MSG_PREHEAT_2_BEDONLY, lcd_preheat_m2_bedonly); #endif END_MENU(); } - #endif // TEMP_SENSOR_0 && (TEMP_SENSOR_1 || TEMP_SENSOR_2 || TEMP_SENSOR_3 || TEMP_SENSOR_4 || TEMP_SENSOR_BED) + #endif // HAS_TEMP_HOTEND && (TEMP_SENSOR_1 || TEMP_SENSOR_2 || TEMP_SENSOR_3 || TEMP_SENSOR_4 || TEMP_SENSOR_BED) void lcd_cooldown() { #if FAN_COUNT > 0 @@ -2780,7 +2780,7 @@ void lcd_quick_feedback(const bool clear_buttons) { } #endif // ADVANCED_PAUSE_FEATURE - #if TEMP_SENSOR_0 != 0 + #if HAS_TEMP_HOTEND // // Cooldown @@ -2795,7 +2795,7 @@ void lcd_quick_feedback(const bool clear_buttons) { // // Preheat for Material 1 and 2 // - #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || TEMP_SENSOR_BED != 0 + #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || HAS_HEATED_BED MENU_ITEM(submenu, MSG_PREHEAT_1, lcd_preheat_m1_menu); MENU_ITEM(submenu, MSG_PREHEAT_2, lcd_preheat_m2_menu); #else @@ -2803,7 +2803,7 @@ void lcd_quick_feedback(const bool clear_buttons) { MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only); #endif - #endif // TEMP_SENSOR_0 != 0 + #endif // HAS_TEMP_HOTEND // // BLTouch Self-Test and Reset @@ -3538,7 +3538,7 @@ void lcd_quick_feedback(const bool clear_buttons) { // // Autotemp, Min, Max, Fact // - #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0) + #if ENABLED(AUTOTEMP) && (HAS_TEMP_HOTEND) MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &planner.autotemp_enabled); MENU_ITEM_EDIT(float3, MSG_MIN, &planner.autotemp_min, 0, HEATER_0_MAXTEMP - 15); MENU_ITEM_EDIT(float3, MSG_MAX, &planner.autotemp_max, 0, HEATER_0_MAXTEMP - 15); @@ -3633,10 +3633,10 @@ void lcd_quick_feedback(const bool clear_buttons) { START_MENU(); MENU_BACK(MSG_TEMPERATURE); MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &lcd_preheat_fan_speed[material], 0, 255); - #if TEMP_SENSOR_0 != 0 + #if HAS_TEMP_HOTEND MENU_ITEM_EDIT(int3, MSG_NOZZLE, &lcd_preheat_hotend_temp[material], MINTEMP_ALL, MAXTEMP_ALL - 15); #endif - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED MENU_ITEM_EDIT(int3, MSG_BED, &lcd_preheat_bed_temp[material], BED_MINTEMP, BED_MAXTEMP - 15); #endif #if ENABLED(EEPROM_SETTINGS) @@ -4154,7 +4154,7 @@ void lcd_quick_feedback(const bool clear_buttons) { STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_4_MAXTEMP), false); #endif - #if TEMP_SENSOR_BED != 0 + #if HAS_HEATED_BED #undef THERMISTOR_ID #define THERMISTOR_ID TEMP_SENSOR_BED #include "thermistornames.h" diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index b55fc1c73..a27930ae5 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -952,31 +952,31 @@ float Temperature::analog2temp(const int raw, const uint8_t e) { if (e == 0) return 0.25 * raw; #endif + // Thermistor with conversion table? if (heater_ttbl_map[e] != NULL) { - float celsius = 0; - uint8_t i; short(*tt)[][2] = (short(*)[][2])(heater_ttbl_map[e]); - - for (i = 1; i < heater_ttbllen_map[e]; i++) { - if (PGM_RD_W((*tt)[i][0]) > raw) { - celsius = PGM_RD_W((*tt)[i - 1][1]) + - (raw - PGM_RD_W((*tt)[i - 1][0])) * - (float)(PGM_RD_W((*tt)[i][1]) - PGM_RD_W((*tt)[i - 1][1])) / - (float)(PGM_RD_W((*tt)[i][0]) - PGM_RD_W((*tt)[i - 1][0])); - break; + for (uint8_t i = 1; i < heater_ttbllen_map[e]; i++) { + const short entry10 = PGM_RD_W((*tt)[i][0]); + if (entry10 > raw) { + const short entry00 = PGM_RD_W((*tt)[i - 1][0]), + entry01 = PGM_RD_W((*tt)[i - 1][1]), + entry11 = PGM_RD_W((*tt)[i][1]); + return entry01 + (raw - entry00) * float(entry11 - entry01) / float(entry10 - entry00); } } - - // Overflow: Set to last value in the table - if (i == heater_ttbllen_map[e]) celsius = PGM_RD_W((*tt)[i - 1][1]); - - return celsius; + return PGM_RD_W((*tt)[heater_ttbllen_map[e] - 1][1]); // Overflow: Return last value in the table } - #if defined(HEATER_USES_AD8495) - return ((raw * (660.0 / 1024.0) / OVERSAMPLENR) * (TEMP_SENSOR_AD8495_GAIN)) + TEMP_SENSOR_AD8495_OFFSET; - #else - return ((raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN)) + TEMP_SENSOR_AD595_OFFSET; - #endif + + // Thermocouple with amplifier ADC interface + return (raw * + #if HEATER_USES_AD8495 + 660.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD8495_GAIN) + TEMP_SENSOR_AD8495_OFFSET + #elif HEATER_USES_AD595 + 5.0 * 100.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET + #else + 0 + #endif + ); } #if HAS_HEATED_BED @@ -984,36 +984,31 @@ float Temperature::analog2temp(const int raw, const uint8_t e) { // For bed temperature measurement. float Temperature::analog2tempBed(const int raw) { #if ENABLED(BED_USES_THERMISTOR) - float celsius = 0; - byte i; - - for (i = 1; i < BEDTEMPTABLE_LEN; i++) { - if (PGM_RD_W(BEDTEMPTABLE[i][0]) > raw) { - celsius = PGM_RD_W(BEDTEMPTABLE[i - 1][1]) + - (raw - PGM_RD_W(BEDTEMPTABLE[i - 1][0])) * - (float)(PGM_RD_W(BEDTEMPTABLE[i][1]) - PGM_RD_W(BEDTEMPTABLE[i - 1][1])) / - (float)(PGM_RD_W(BEDTEMPTABLE[i][0]) - PGM_RD_W(BEDTEMPTABLE[i - 1][0])); - break; + + // Thermistor with conversion table + for (uint8_t i = 1; i < BEDTEMPTABLE_LEN; i++) { + const short entry10 = PGM_RD_W(BEDTEMPTABLE[i][0]); + if (entry10 > raw) { + const short entry00 = PGM_RD_W(BEDTEMPTABLE[i - 1][0]), + entry01 = PGM_RD_W(BEDTEMPTABLE[i - 1][1]), + entry11 = PGM_RD_W(BEDTEMPTABLE[i][1]); + return entry01 + (raw - entry00) * float(entry11 - entry01) / float(entry10 - entry00); } } - - // Overflow: Set to last value in the table - if (i == BEDTEMPTABLE_LEN) celsius = PGM_RD_W(BEDTEMPTABLE[i - 1][1]); - - return celsius; - - #elif defined(BED_USES_AD595) - - return ((raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN)) + TEMP_SENSOR_AD595_OFFSET; - - #elif defined(BED_USES_AD8495) - - return ((raw * (660.0 / 1024.0) / OVERSAMPLENR) * (TEMP_SENSOR_AD8495_GAIN)) + TEMP_SENSOR_AD8495_OFFSET; + return PGM_RD_W(BEDTEMPTABLE[BEDTEMPTABLE_LEN - 1][1]); // Overflow: Return last value in the table #else - UNUSED(raw); - return 0; + // Thermocouple with amplifier ADC interface + return (raw * + #if ENABLED(BED_USES_AD595) + 5.0 * 100.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET + #elif ENABLED(BED_USES_AD8495) + 660.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD8495_GAIN) + TEMP_SENSOR_AD8495_OFFSET + #else + 0 + #endif + ); #endif } @@ -1024,36 +1019,31 @@ float Temperature::analog2temp(const int raw, const uint8_t e) { // For chamber temperature measurement. float Temperature::analog2tempChamber(const int raw) { #if ENABLED(CHAMBER_USES_THERMISTOR) - float celsius = 0; - byte i; - - for (i = 1; i < CHAMBERTEMPTABLE_LEN; i++) { - if (PGM_RD_W(CHAMBERTEMPTABLE[i][0]) > raw) { - celsius = PGM_RD_W(CHAMBERTEMPTABLE[i - 1][1]) + - (raw - PGM_RD_W(CHAMBERTEMPTABLE[i - 1][0])) * - (float)(PGM_RD_W(CHAMBERTEMPTABLE[i][1]) - PGM_RD_W(CHAMBERTEMPTABLE[i - 1][1])) / - (float)(PGM_RD_W(CHAMBERTEMPTABLE[i][0]) - PGM_RD_W(CHAMBERTEMPTABLE[i - 1][0])); - break; + + // Thermistor with conversion table + for (uint8_t i = 1; i < CHAMBERTEMPTABLE_LEN; i++) { + const short entry10 = PGM_RD_W(CHAMBERTEMPTABLE[i][0]); + if (entry10 > raw) { + const short entry00 = PGM_RD_W(CHAMBERTEMPTABLE[i - 1][0]), + entry01 = PGM_RD_W(CHAMBERTEMPTABLE[i - 1][1]), + entry11 = PGM_RD_W(CHAMBERTEMPTABLE[i][1]); + return entry01 + (raw - entry00) * float(entry11 - entry01) / float(entry10 - entry00); } } + return PGM_RD_W(CHAMBERTEMPTABLE[CHAMBERTEMPTABLE_LEN - 1][1]); // Overflow: Return last value in the table - // Overflow: Set to last value in the table - if (i == CHAMBERTEMPTABLE_LEN) celsius = PGM_RD_W(CHAMBERTEMPTABLE[i - 1][1]); - - return celsius; - - #elif defined(CHAMBER_USES_AD595) - - return ((raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN)) + TEMP_SENSOR_AD595_OFFSET; - - #elif defined(CHAMBER_USES_AD8495) - - return ((raw * (660.0 / 1024.0) / OVERSAMPLENR) * (TEMP_SENSOR_AD8495_GAIN)) + TEMP_SENSOR_AD8495_OFFSET; - #else - UNUSED(raw); - return 0; + // Thermocouple with amplifier ADC interface + return (raw * + #if ENABLED(CHAMBER_USES_AD595) + 5.0 * 100.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET + #elif ENABLED(CHAMBER_USES_AD8495) + 660.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD8495_GAIN) + TEMP_SENSOR_AD8495_OFFSET + #else + 0 + #endif + ); #endif } @@ -1208,19 +1198,19 @@ void Temperature::init() { HAL_adc_init(); - #if HAS_TEMP_0 + #if HAS_TEMP_ADC_0 HAL_ANALOG_SELECT(TEMP_0_PIN); #endif - #if HAS_TEMP_1 + #if HAS_TEMP_ADC_1 HAL_ANALOG_SELECT(TEMP_1_PIN); #endif - #if HAS_TEMP_2 + #if HAS_TEMP_ADC_2 HAL_ANALOG_SELECT(TEMP_2_PIN); #endif - #if HAS_TEMP_3 + #if HAS_TEMP_ADC_3 HAL_ANALOG_SELECT(TEMP_3_PIN); #endif - #if HAS_TEMP_4 + #if HAS_TEMP_ADC_4 HAL_ANALOG_SELECT(TEMP_4_PIN); #endif #if HAS_HEATED_BED @@ -1687,20 +1677,20 @@ void Temperature::disable_all_heaters() { * Get raw temperatures */ void Temperature::set_current_temp_raw() { - #if HAS_TEMP_0 && DISABLED(HEATER_0_USES_MAX6675) + #if HAS_TEMP_ADC_0 && DISABLED(HEATER_0_USES_MAX6675) current_temperature_raw[0] = raw_temp_value[0]; #endif - #if HAS_TEMP_1 + #if HAS_TEMP_ADC_1 #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT) redundant_temperature_raw = raw_temp_value[1]; #else current_temperature_raw[1] = raw_temp_value[1]; #endif - #if HAS_TEMP_2 + #if HAS_TEMP_ADC_2 current_temperature_raw[2] = raw_temp_value[2]; - #if HAS_TEMP_3 + #if HAS_TEMP_ADC_3 current_temperature_raw[3] = raw_temp_value[3]; - #if HAS_TEMP_4 + #if HAS_TEMP_ADC_4 current_temperature_raw[4] = raw_temp_value[4]; #endif #endif @@ -2050,7 +2040,7 @@ void Temperature::isr() { adc_sensor_state = (ADCSensorState)0; // Fall-through to start first sensor now } - #if HAS_TEMP_0 + #if HAS_TEMP_ADC_0 case PrepareTemp_0: HAL_START_ADC(TEMP_0_PIN); break; @@ -2077,7 +2067,7 @@ void Temperature::isr() { break; #endif - #if HAS_TEMP_1 + #if HAS_TEMP_ADC_1 case PrepareTemp_1: HAL_START_ADC(TEMP_1_PIN); break; @@ -2086,7 +2076,7 @@ void Temperature::isr() { break; #endif - #if HAS_TEMP_2 + #if HAS_TEMP_ADC_2 case PrepareTemp_2: HAL_START_ADC(TEMP_2_PIN); break; @@ -2095,7 +2085,7 @@ void Temperature::isr() { break; #endif - #if HAS_TEMP_3 + #if HAS_TEMP_ADC_3 case PrepareTemp_3: HAL_START_ADC(TEMP_3_PIN); break; @@ -2104,7 +2094,7 @@ void Temperature::isr() { break; #endif - #if HAS_TEMP_4 + #if HAS_TEMP_ADC_4 case PrepareTemp_4: HAL_START_ADC(TEMP_4_PIN); break; diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index e9727c512..3056c92b3 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -50,23 +50,23 @@ * States for ADC reading in the ISR */ enum ADCSensorState : char { - #if HAS_TEMP_0 + #if HAS_TEMP_ADC_0 PrepareTemp_0, MeasureTemp_0, #endif - #if HAS_TEMP_1 + #if HAS_TEMP_ADC_1 PrepareTemp_1, MeasureTemp_1, #endif - #if HAS_TEMP_2 + #if HAS_TEMP_ADC_2 PrepareTemp_2, MeasureTemp_2, #endif - #if HAS_TEMP_3 + #if HAS_TEMP_ADC_3 PrepareTemp_3, MeasureTemp_3, #endif - #if HAS_TEMP_4 + #if HAS_TEMP_ADC_4 PrepareTemp_4, MeasureTemp_4, #endif