From d4415dcf592bbb1db869316a3020d92fa5a23edb Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 2 Jul 2019 04:04:49 -0500 Subject: [PATCH] Fix analogWrite ambiguity --- Marlin/src/HAL/HAL_ESP32/HAL.cpp | 2 +- Marlin/src/HAL/HAL_ESP32/HAL.h | 2 +- Marlin/src/feature/caselight.cpp | 2 +- Marlin/src/feature/controllerfan.cpp | 2 +- Marlin/src/feature/spindle_laser.cpp | 8 ++++---- Marlin/src/module/planner.cpp | 4 ++-- Marlin/src/module/stepper.cpp | 2 +- Marlin/src/module/temperature.cpp | 10 +++++----- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Marlin/src/HAL/HAL_ESP32/HAL.cpp b/Marlin/src/HAL/HAL_ESP32/HAL.cpp index f5a601dc34..299aee46fe 100644 --- a/Marlin/src/HAL/HAL_ESP32/HAL.cpp +++ b/Marlin/src/HAL/HAL_ESP32/HAL.cpp @@ -192,7 +192,7 @@ void HAL_adc_start_conversion(uint8_t adc_pin) { HAL_adc_result = mv*1023.0/3300.0; } -void analogWrite(int pin, int value) { +void analogWrite(pin_t pin, int value) { if (!PWM_PIN(pin)) return; diff --git a/Marlin/src/HAL/HAL_ESP32/HAL.h b/Marlin/src/HAL/HAL_ESP32/HAL.h index 79a0877e7c..0fc1d71bc4 100644 --- a/Marlin/src/HAL/HAL_ESP32/HAL.h +++ b/Marlin/src/HAL/HAL_ESP32/HAL.h @@ -98,7 +98,7 @@ void _delay_ms(int delay); int freeMemory(void); -void analogWrite(int pin, int value); +void analogWrite(pin_t pin, int value); // EEPROM void eeprom_write_byte(uint8_t *pos, unsigned char value); diff --git a/Marlin/src/feature/caselight.cpp b/Marlin/src/feature/caselight.cpp index f677b558d5..81eb4aaac4 100644 --- a/Marlin/src/feature/caselight.cpp +++ b/Marlin/src/feature/caselight.cpp @@ -71,7 +71,7 @@ void update_case_light() { #if DISABLED(CASE_LIGHT_NO_BRIGHTNESS) if (PWM_PIN(CASE_LIGHT_PIN)) - analogWrite(CASE_LIGHT_PIN, n10ct); + analogWrite(pin_t(CASE_LIGHT_PIN), n10ct); else #endif { diff --git a/Marlin/src/feature/controllerfan.cpp b/Marlin/src/feature/controllerfan.cpp index f42b735a58..a75f4d9822 100644 --- a/Marlin/src/feature/controllerfan.cpp +++ b/Marlin/src/feature/controllerfan.cpp @@ -81,7 +81,7 @@ void controllerfan_update() { // allows digital or PWM fan output to be used (see M42 handling) WRITE(CONTROLLER_FAN_PIN, speed); - analogWrite(CONTROLLER_FAN_PIN, speed); + analogWrite(pin_t(CONTROLLER_FAN_PIN), speed); } } diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index a03a4bdbaf..81865fddb6 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -41,7 +41,7 @@ void SpindleLaser::init() { #endif #if ENABLED(SPINDLE_LASER_PWM) && PIN_EXISTS(SPINDLE_LASER_PWM) SET_PWM(SPINDLE_LASER_PWM_PIN); - analogWrite(SPINDLE_LASER_PWM_PIN, SPINDLE_LASER_PWM_INVERT ? 255 : 0); // set to lowest speed + analogWrite(pin_t(SPINDLE_LASER_PWM_PIN), SPINDLE_LASER_PWM_INVERT ? 255 : 0); // set to lowest speed #endif } @@ -55,7 +55,7 @@ void SpindleLaser::init() { void SpindleLaser::set_ocr(const uint8_t ocr) { WRITE(SPINDLE_LASER_ENA_PIN, SPINDLE_LASER_ACTIVE_HIGH); // turn spindle on (active low) #if ENABLED(SPINDLE_LASER_PWM) - analogWrite(SPINDLE_LASER_PWM_PIN, (SPINDLE_LASER_PWM_INVERT) ? 255 - ocr : ocr); + analogWrite(pin_t(SPINDLE_LASER_PWM_PIN), (SPINDLE_LASER_PWM_INVERT) ? 255 - ocr : ocr); #endif } @@ -75,8 +75,8 @@ void SpindleLaser::update_output() { set_ocr(ocr_val & 0xFF); // ...limited to Atmel PWM max } else { // Convert RPM to PWM duty cycle - WRITE(SPINDLE_LASER_ENA_PIN, !SPINDLE_LASER_ACTIVE_HIGH); // Turn spindle off (active low) - analogWrite(SPINDLE_LASER_PWM_PIN, SPINDLE_LASER_PWM_INVERT ? 255 : 0); // Only write low byte + WRITE(SPINDLE_LASER_ENA_PIN, !SPINDLE_LASER_ACTIVE_HIGH); // Turn spindle off (active low) + analogWrite(pin_t(SPINDLE_LASER_PWM_PIN), SPINDLE_LASER_PWM_INVERT ? 255 : 0); // Only write low byte } #else WRITE(SPINDLE_LASER_ENA_PIN, ena ? SPINDLE_LASER_ACTIVE_HIGH : !SPINDLE_LASER_ACTIVE_HIGH); diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index e6f07b66c5..6f531c7208 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -1289,10 +1289,10 @@ void Planner::check_axes_activity() { #if ENABLED(BARICUDA) #if HAS_HEATER_1 - analogWrite(HEATER_1_PIN, tail_valve_pressure); + analogWrite(pin_t(HEATER_1_PIN), tail_valve_pressure); #endif #if HAS_HEATER_2 - analogWrite(HEATER_2_PIN, tail_e_to_p_pressure); + analogWrite(pin_t(HEATER_2_PIN), tail_e_to_p_pressure); #endif #endif } diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 6a862a2492..a5c73bb3ff 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -2502,7 +2502,7 @@ void Stepper::report_positions() { if (WITHIN(driver, 0, COUNT(motor_current_setting) - 1)) motor_current_setting[driver] = current; // update motor_current_setting - #define _WRITE_CURRENT_PWM(P) analogWrite(MOTOR_CURRENT_PWM_## P ##_PIN, 255L * current / (MOTOR_CURRENT_PWM_RANGE)) + #define _WRITE_CURRENT_PWM(P) analogWrite(pin_t(MOTOR_CURRENT_PWM_## P ##_PIN), 255L * current / (MOTOR_CURRENT_PWM_RANGE)) switch (driver) { case 0: #if PIN_EXISTS(MOTOR_CURRENT_PWM_X) diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index ea01cc27be..9856dc0f34 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -699,11 +699,11 @@ int16_t Temperature::getHeaterPower(const int8_t heater) { SBI(fanState, pgm_read_byte(&fanBit[CHAMBER_FAN_INDEX])); #endif - #define _UPDATE_AUTO_FAN(P,D,A) do{ \ - if (PWM_PIN(P##_AUTO_FAN_PIN) && A < 255) \ - analogWrite(P##_AUTO_FAN_PIN, D ? A : 0); \ - else \ - WRITE(P##_AUTO_FAN_PIN, D); \ + #define _UPDATE_AUTO_FAN(P,D,A) do{ \ + if (PWM_PIN(P##_AUTO_FAN_PIN) && A < 255) \ + analogWrite(pin_t(P##_AUTO_FAN_PIN), D ? A : 0); \ + else \ + WRITE(P##_AUTO_FAN_PIN, D); \ }while(0) uint8_t fanDone = 0;