Fixes and improvements for PWM pins (#13383)

This commit is contained in:
Scott Lahteine 2019-03-13 06:51:15 -05:00 committed by GitHub
parent 87162658c4
commit f89b375fb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 196 additions and 193 deletions

View file

@ -94,6 +94,8 @@
#define extDigitalRead(IO) digitalRead(IO) #define extDigitalRead(IO) digitalRead(IO)
#endif #endif
#define ANALOG_WRITE(IO,V) analogWrite(IO,V)
#define READ(IO) _READ(IO) #define READ(IO) _READ(IO)
#define WRITE(IO,V) _WRITE(IO,V) #define WRITE(IO,V) _WRITE(IO,V)
#define TOGGLE(IO) _TOGGLE(IO) #define TOGGLE(IO) _TOGGLE(IO)
@ -102,6 +104,8 @@
#define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _WRITE(IO, HIGH); }while(0) #define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _WRITE(IO, HIGH); }while(0)
#define SET_OUTPUT(IO) _SET_OUTPUT(IO) #define SET_OUTPUT(IO) _SET_OUTPUT(IO)
#define SET_PWM(IO) SET_OUTPUT(IO)
#define GET_INPUT(IO) _GET_INPUT(IO) #define GET_INPUT(IO) _GET_INPUT(IO)
#define GET_OUTPUT(IO) _GET_OUTPUT(IO) #define GET_OUTPUT(IO) _GET_OUTPUT(IO)
#define GET_TIMER(IO) _GET_TIMER(IO) #define GET_TIMER(IO) _GET_TIMER(IO)
@ -279,75 +283,75 @@ enum ClockSource2 : char {
// Determine which harware PWMs are already in use // Determine which harware PWMs are already in use
#if PIN_EXISTS(CONTROLLER_FAN) #if PIN_EXISTS(CONTROLLER_FAN)
#define PWM_CHK_FAN_B(p) (p == CONTROLLER_FAN_PIN || p == E0_AUTO_FAN_PIN || p == E1_AUTO_FAN_PIN || p == E2_AUTO_FAN_PIN || p == E3_AUTO_FAN_PIN || p == E4_AUTO_FAN_PIN || p == E5_AUTO_FAN_PIN || p == CHAMBER_AUTO_FAN_PIN) #define PWM_CHK_FAN_B(P) (P == CONTROLLER_FAN_PIN || P == E0_AUTO_FAN_PIN || P == E1_AUTO_FAN_PIN || P == E2_AUTO_FAN_PIN || P == E3_AUTO_FAN_PIN || P == E4_AUTO_FAN_PIN || P == E5_AUTO_FAN_PIN || P == CHAMBER_AUTO_FAN_PIN)
#else #else
#define PWM_CHK_FAN_B(p) (p == E0_AUTO_FAN_PIN || p == E1_AUTO_FAN_PIN || p == E2_AUTO_FAN_PIN || p == E3_AUTO_FAN_PIN || p == E4_AUTO_FAN_PIN || p == E5_AUTO_FAN_PIN || p == CHAMBER_AUTO_FAN_PIN) #define PWM_CHK_FAN_B(P) (P == E0_AUTO_FAN_PIN || P == E1_AUTO_FAN_PIN || P == E2_AUTO_FAN_PIN || P == E3_AUTO_FAN_PIN || P == E4_AUTO_FAN_PIN || P == E5_AUTO_FAN_PIN || P == CHAMBER_AUTO_FAN_PIN)
#endif #endif
#if PIN_EXISTS(FAN) || PIN_EXISTS(FAN1) || PIN_EXISTS(FAN2) #if PIN_EXISTS(FAN) || PIN_EXISTS(FAN1) || PIN_EXISTS(FAN2)
#if PIN_EXISTS(FAN2) #if PIN_EXISTS(FAN2)
#define PWM_CHK_FAN_A(p) (p == FAN_PIN || p == FAN1_PIN || p == FAN2_PIN) #define PWM_CHK_FAN_A(P) (P == FAN_PIN || P == FAN1_PIN || P == FAN2_PIN)
#elif PIN_EXISTS(FAN1) #elif PIN_EXISTS(FAN1)
#define PWM_CHK_FAN_A(p) (p == FAN_PIN || p == FAN1_PIN) #define PWM_CHK_FAN_A(P) (P == FAN_PIN || P == FAN1_PIN)
#else #else
#define PWM_CHK_FAN_A(p) (p == FAN_PIN) #define PWM_CHK_FAN_A(P) (P == FAN_PIN)
#endif #endif
#else #else
#define PWM_CHK_FAN_A(p) false #define PWM_CHK_FAN_A(P) false
#endif #endif
#if HAS_MOTOR_CURRENT_PWM #if HAS_MOTOR_CURRENT_PWM
#if PIN_EXISTS(MOTOR_CURRENT_PWM_XY) #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
#define PWM_CHK_MOTOR_CURRENT(p) (p == MOTOR_CURRENT_PWM_E || p == MOTOR_CURRENT_PWM_Z || p == MOTOR_CURRENT_PWM_XY) #define PWM_CHK_MOTOR_CURRENT(P) (P == MOTOR_CURRENT_PWM_E || P == MOTOR_CURRENT_PWM_Z || P == MOTOR_CURRENT_PWM_XY)
#elif PIN_EXISTS(MOTOR_CURRENT_PWM_Z) #elif PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
#define PWM_CHK_MOTOR_CURRENT(p) (p == MOTOR_CURRENT_PWM_E || p == MOTOR_CURRENT_PWM_Z) #define PWM_CHK_MOTOR_CURRENT(P) (P == MOTOR_CURRENT_PWM_E || P == MOTOR_CURRENT_PWM_Z)
#else #else
#define PWM_CHK_MOTOR_CURRENT(p) (p == MOTOR_CURRENT_PWM_E) #define PWM_CHK_MOTOR_CURRENT(P) (P == MOTOR_CURRENT_PWM_E)
#endif #endif
#else #else
#define PWM_CHK_MOTOR_CURRENT(p) false #define PWM_CHK_MOTOR_CURRENT(P) false
#endif #endif
#ifdef NUM_SERVOS #ifdef NUM_SERVOS
#if AVR_ATmega2560_FAMILY #if AVR_ATmega2560_FAMILY
#define PWM_CHK_SERVO(p) (p == 5 || (NUM_SERVOS > 12 && p == 6) || (NUM_SERVOS > 24 && p == 46)) // PWMS 3A, 4A & 5A #define PWM_CHK_SERVO(P) (P == 5 || (NUM_SERVOS > 12 && P == 6) || (NUM_SERVOS > 24 && P == 46)) // PWMS 3A, 4A & 5A
#elif AVR_ATmega2561_FAMILY #elif AVR_ATmega2561_FAMILY
#define PWM_CHK_SERVO(p) (p == 5) // PWM3A #define PWM_CHK_SERVO(P) (P == 5) // PWM3A
#elif AVR_ATmega1284_FAMILY #elif AVR_ATmega1284_FAMILY
#define PWM_CHK_SERVO(p) false #define PWM_CHK_SERVO(P) false
#elif AVR_AT90USB1286_FAMILY #elif AVR_AT90USB1286_FAMILY
#define PWM_CHK_SERVO(p) (p == 16) // PWM3A #define PWM_CHK_SERVO(P) (P == 16) // PWM3A
#elif AVR_ATmega328_FAMILY #elif AVR_ATmega328_FAMILY
#define PWM_CHK_SERVO(p) false #define PWM_CHK_SERVO(P) false
#endif #endif
#else #else
#define PWM_CHK_SERVO(p) false #define PWM_CHK_SERVO(P) false
#endif #endif
#if ENABLED(BARICUDA) #if ENABLED(BARICUDA)
#if HAS_HEATER_1 && HAS_HEATER_2 #if HAS_HEATER_1 && HAS_HEATER_2
#define PWM_CHK_HEATER(p) (p == HEATER_1_PIN || p == HEATER_2_PIN) #define PWM_CHK_HEATER(P) (P == HEATER_1_PIN || P == HEATER_2_PIN)
#elif HAS_HEATER_1 #elif HAS_HEATER_1
#define PWM_CHK_HEATER(p) (p == HEATER_1_PIN) #define PWM_CHK_HEATER(P) (P == HEATER_1_PIN)
#endif #endif
#else #else
#define PWM_CHK_HEATER(p) false #define PWM_CHK_HEATER(P) false
#endif #endif
#define PWM_CHK(p) (PWM_CHK_HEATER(p) || PWM_CHK_SERVO(p) || PWM_CHK_MOTOR_CURRENT(p) || PWM_CHK_FAN_A(p) || PWM_CHK_FAN_B(p)) #define PWM_CHK(P) (PWM_CHK_HEATER(P) || PWM_CHK_SERVO(P) || PWM_CHK_MOTOR_CURRENT(P) || PWM_CHK_FAN_A(P) || PWM_CHK_FAN_B(P))
// define which hardware PWMs are available for the current CPU // define which hardware PWMs are available for the current CPU
// all timer 1 PWMS deleted from this list because they are never available // all timer 1 PWMS deleted from this list because they are never available
#if AVR_ATmega2560_FAMILY #if AVR_ATmega2560_FAMILY
#define PWM_PIN(p) ((p >= 2 && p <= 10) || p == 13 || p == 44 || p == 45 || p == 46) #define PWM_PIN(P) ((P >= 2 && P <= 10) || P == 13 || P == 44 || P == 45 || P == 46)
#elif AVR_ATmega2561_FAMILY #elif AVR_ATmega2561_FAMILY
#define PWM_PIN(p) ((p >= 2 && p <= 6) || p == 9) #define PWM_PIN(P) ((P >= 2 && P <= 6) || P == 9)
#elif AVR_ATmega1284_FAMILY #elif AVR_ATmega1284_FAMILY
#define PWM_PIN(p) (p == 3 || p == 4 || p == 14 || p == 15) #define PWM_PIN(P) (P == 3 || P == 4 || P == 14 || P == 15)
#elif AVR_AT90USB1286_FAMILY #elif AVR_AT90USB1286_FAMILY
#define PWM_PIN(p) (p == 0 || p == 1 || p == 14 || p == 15 || p == 16 || p == 24) #define PWM_PIN(P) (P == 0 || P == 1 || P == 14 || P == 15 || P == 16 || P == 24)
#elif AVR_ATmega328_FAMILY #elif AVR_ATmega328_FAMILY
#define PWM_PIN(p) (p == 3 || p == 5 || p == 6 || p == 11) #define PWM_PIN(P) (P == 3 || P == 5 || P == 6 || P == 11)
#else #else
#error "unknown CPU" #error "unknown CPU"
#endif #endif

View file

@ -45,7 +45,8 @@
// Due has 12 PWMs assigned to logical pins 2-13. // Due has 12 PWMs assigned to logical pins 2-13.
// 6, 7, 8 & 9 come from the PWM controller. The others come from the timers. // 6, 7, 8 & 9 come from the PWM controller. The others come from the timers.
#define USEABLE_HARDWARE_PWM(p) WITHIN(p, 2, 13) #define PWM_PIN(P) WITHIN(P, 2, 13)
#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
#ifndef MASK #ifndef MASK
#define MASK(PIN) (1 << PIN) #define MASK(PIN) (1 << PIN)
@ -172,6 +173,8 @@
#define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0) #define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
// Set pin as output (wrapper) - reads the pin and sets the output to that value // Set pin as output (wrapper) - reads the pin and sets the output to that value
#define SET_OUTPUT(IO) _SET_OUTPUT(IO) #define SET_OUTPUT(IO) _SET_OUTPUT(IO)
// Set pin as PWM
#define SET_PWM(IO) SET_OUTPUT(IO)
// Check if pin is an input // Check if pin is an input
#define GET_INPUT(IO) ((digitalPinToPort(IO)->PIO_OSR & digitalPinToBitMask(IO)) == 0) #define GET_INPUT(IO) ((digitalPinToPort(IO)->PIO_OSR & digitalPinToBitMask(IO)) == 0)
@ -187,6 +190,8 @@
#define extDigitalRead(IO) digitalRead(IO) #define extDigitalRead(IO) digitalRead(IO)
#define extDigitalWrite(IO,V) digitalWrite(IO,V) #define extDigitalWrite(IO,V) digitalWrite(IO,V)
#define ANALOG_WRITE(IO,V) analogWrite(IO,V)
/** /**
* Ports and functions * Ports and functions
* Added as necessary or if I feel like it- not a comprehensive list! * Added as necessary or if I feel like it- not a comprehensive list!

View file

@ -49,14 +49,23 @@
#define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0) #define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
// Set pin as output wrapper // Set pin as output wrapper
#define SET_OUTPUT(IO) do{ _SET_OUTPUT(IO); WRITE(IO, LOW); }while(0) #define SET_OUTPUT(IO) do{ _SET_OUTPUT(IO); }while(0)
// Set pin as PWM
#define SET_PWM(IO) SET_OUTPUT(IO)
// Set pin as output and init
#define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0) #define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0)
// digitalRead/Write wrappers // digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO) #define extDigitalRead(IO) digitalRead(IO)
#define extDigitalWrite(IO,V) digitalWrite(IO,V) #define extDigitalWrite(IO,V) digitalWrite(IO,V)
#define ANALOG_WRITE(IO,V) analogWrite(IO,V)
#define PWM_PIN(P) true
#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
// //
// Ports and functions // Ports and functions
// //

View file

@ -28,8 +28,6 @@
#include <Arduino.h> #include <Arduino.h>
#include <pinmapping.h> #include <pinmapping.h>
#define USEABLE_HARDWARE_PWM(pin) false
#define SET_DIR_INPUT(IO) Gpio::setDir(IO, 1) #define SET_DIR_INPUT(IO) Gpio::setDir(IO, 1)
#define SET_DIR_OUTPUT(IO) Gpio::setDir(IO, 0) #define SET_DIR_OUTPUT(IO) Gpio::setDir(IO, 0)
@ -110,6 +108,8 @@
#define SET_INPUT_PULLDOWN(IO) do{ _SET_INPUT(IO); _PULLDOWN(IO, HIGH); }while(0) #define SET_INPUT_PULLDOWN(IO) do{ _SET_INPUT(IO); _PULLDOWN(IO, HIGH); }while(0)
/// set pin as output wrapper - reads the pin and sets the output to that value /// set pin as output wrapper - reads the pin and sets the output to that value
#define SET_OUTPUT(IO) do{ _WRITE(IO, _READ(IO)); _SET_OUTPUT(IO); }while(0) #define SET_OUTPUT(IO) do{ _WRITE(IO, _READ(IO)); _SET_OUTPUT(IO); }while(0)
// set pin as PWM
#define SET_PWM(IO) SET_OUTPUT(IO)
/// check if pin is an input wrapper /// check if pin is an input wrapper
#define GET_INPUT(IO) _GET_INPUT(IO) #define GET_INPUT(IO) _GET_INPUT(IO)
@ -125,3 +125,7 @@
// digitalRead/Write wrappers // digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO) #define extDigitalRead(IO) digitalRead(IO)
#define extDigitalWrite(IO,V) digitalWrite(IO,V) #define extDigitalWrite(IO,V) digitalWrite(IO,V)
#define ANALOG_WRITE(IO,V) analogWrite(IO,V)
#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)

View file

@ -111,6 +111,8 @@
#define SET_INPUT_PULLDOWN(IO) do{ _SET_INPUT(IO); _PULLDOWN(IO, HIGH); }while(0) #define SET_INPUT_PULLDOWN(IO) do{ _SET_INPUT(IO); _PULLDOWN(IO, HIGH); }while(0)
/// set pin as output wrapper - reads the pin and sets the output to that value /// set pin as output wrapper - reads the pin and sets the output to that value
#define SET_OUTPUT(IO) do{ _WRITE(IO, _READ(IO)); _SET_OUTPUT(IO); }while(0) #define SET_OUTPUT(IO) do{ _WRITE(IO, _READ(IO)); _SET_OUTPUT(IO); }while(0)
// set pin as PWM
#define SET_PWM(IO) SET_OUTPUT(IO)
/// check if pin is an input wrapper /// check if pin is an input wrapper
#define GET_INPUT(IO) _GET_INPUT(IO) #define GET_INPUT(IO) _GET_INPUT(IO)
@ -126,3 +128,5 @@
// digitalRead/Write wrappers // digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO) #define extDigitalRead(IO) digitalRead(IO)
#define extDigitalWrite(IO,V) digitalWrite(IO,V) #define extDigitalWrite(IO,V) digitalWrite(IO,V)
#define ANALOG_WRITE(IO,V) analogWrite(IO,V)

View file

@ -72,14 +72,17 @@ void FastIO_init(); // Must be called before using fast io macros
#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) /*!< Input with Pull-up activation */ #define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) /*!< Input with Pull-up activation */
#define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN) /*!< Input with Pull-down activation */ #define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN) /*!< Input with Pull-down activation */
#define SET_OUTPUT(IO) OUT_WRITE(IO, LOW) #define SET_OUTPUT(IO) OUT_WRITE(IO, LOW)
#define SET_PWM(IO) _SET_MODE(IO, PWM)
#define GET_INPUT(IO) #define GET_INPUT(IO)
#define GET_OUTPUT(IO) #define GET_OUTPUT(IO)
#define GET_TIMER(IO) #define GET_TIMER(IO)
#define PWM_PIN(p) digitalPinHasPWM(p) #define PWM_PIN(P) digitalPinHasPWM(P)
#define USEABLE_HARDWARE_PWM(p) PWM_PIN(p) #define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
// digitalRead/Write wrappers // digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO) #define extDigitalRead(IO) digitalRead(IO)
#define extDigitalWrite(IO,V) digitalWrite(IO,V) #define extDigitalWrite(IO,V) digitalWrite(IO,V)
#define ANALOG_WRITE(IO,V) analogWrite(IO,V)

View file

@ -43,14 +43,17 @@
#define SET_INPUT(IO) _SET_MODE(IO, GPIO_INPUT_FLOATING) #define SET_INPUT(IO) _SET_MODE(IO, GPIO_INPUT_FLOATING)
#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, GPIO_INPUT_PU) #define SET_INPUT_PULLUP(IO) _SET_MODE(IO, GPIO_INPUT_PU)
#define SET_OUTPUT(IO) OUT_WRITE(IO, LOW) #define SET_OUTPUT(IO) OUT_WRITE(IO, LOW)
#define SET_PWM(IO) pinMode(IO, PWM) // do{ gpio_set_mode(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, GPIO_AF_OUTPUT_PP); timer_set_mode(PIN_MAP[pin].timer_device, PIN_MAP[pin].timer_channel, TIMER_PWM); }while(0)
#define GET_INPUT(IO) (_GET_MODE(IO) == GPIO_INPUT_FLOATING || _GET_MODE(IO) == GPIO_INPUT_ANALOG || _GET_MODE(IO) == GPIO_INPUT_PU || _GET_MODE(IO) == GPIO_INPUT_PD) #define GET_INPUT(IO) (_GET_MODE(IO) == GPIO_INPUT_FLOATING || _GET_MODE(IO) == GPIO_INPUT_ANALOG || _GET_MODE(IO) == GPIO_INPUT_PU || _GET_MODE(IO) == GPIO_INPUT_PD)
#define GET_OUTPUT(IO) (_GET_MODE(IO) == GPIO_OUTPUT_PP) #define GET_OUTPUT(IO) (_GET_MODE(IO) == GPIO_OUTPUT_PP)
#define GET_TIMER(IO) (PIN_MAP[IO].timer_device != NULL) #define GET_TIMER(IO) (PIN_MAP[IO].timer_device != NULL)
#define PWM_PIN(p) true #define PWM_PIN(P) digitalPinHasPWM(P)
#define USEABLE_HARDWARE_PWM(p) PWM_PIN(p) #define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
// digitalRead/Write wrappers // digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO) #define extDigitalRead(IO) digitalRead(IO)
#define extDigitalWrite(IO,V) digitalWrite(IO,V) #define extDigitalWrite(IO,V) digitalWrite(IO,V)
#define ANALOG_WRITE(IO,V) analogWrite(IO,(V)*65535/255)

View file

@ -44,6 +44,7 @@
#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) /*!< Input with Pull-up activation */ #define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) /*!< Input with Pull-up activation */
#define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN) /*!< Input with Pull-down activation */ #define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN) /*!< Input with Pull-down activation */
#define SET_OUTPUT(IO) OUT_WRITE(IO, LOW) #define SET_OUTPUT(IO) OUT_WRITE(IO, LOW)
#define SET_PWM(IO) pinMode(IO, PWM)
#define TOGGLE(IO) OUT_WRITE(IO, !READ(IO)) #define TOGGLE(IO) OUT_WRITE(IO, !READ(IO))
@ -51,13 +52,15 @@
#define GET_OUTPUT(IO) #define GET_OUTPUT(IO)
#define GET_TIMER(IO) #define GET_TIMER(IO)
#define PWM_PIN(p) true #define PWM_PIN(P) true
#define USEABLE_HARDWARE_PWM(p) PWM_PIN(p) #define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
// digitalRead/Write wrappers // digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO) #define extDigitalRead(IO) digitalRead(IO)
#define extDigitalWrite(IO,V) digitalWrite(IO,V) #define extDigitalWrite(IO,V) digitalWrite(IO,V)
#define ANALOG_WRITE(IO,V) analogWrite(IO,(V)*65535/255)
// //
// Pins Definitions // Pins Definitions
// //

View file

@ -43,6 +43,7 @@
#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) /*!< Input with Pull-up activation */ #define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) /*!< Input with Pull-up activation */
#define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN) /*!< Input with Pull-down activation */ #define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN) /*!< Input with Pull-down activation */
#define SET_OUTPUT(IO) OUT_WRITE(IO, LOW) #define SET_OUTPUT(IO) OUT_WRITE(IO, LOW)
#define SET_PWM(IO) _SET_MODE(IO, PWM)
#define TOGGLE(IO) OUT_WRITE(IO, !READ(IO)) #define TOGGLE(IO) OUT_WRITE(IO, !READ(IO))
@ -50,13 +51,15 @@
#define GET_OUTPUT(IO) #define GET_OUTPUT(IO)
#define GET_TIMER(IO) #define GET_TIMER(IO)
#define PWM_PIN(p) true #define PWM_PIN(P) true
#define USEABLE_HARDWARE_PWM(p) PWM_PIN(p) #define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
// digitalRead/Write wrappers // digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO) #define extDigitalRead(IO) digitalRead(IO)
#define extDigitalWrite(IO,V) digitalWrite(IO,V) #define extDigitalWrite(IO,V) digitalWrite(IO,V)
#define ANALOG_WRITE(IO,V) analogWrite(IO,(V)*65535/255)
// //
// Pins Definitions // Pins Definitions
// //

View file

@ -43,7 +43,7 @@
* Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html * Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
*/ */
#define _READ(p) bool(CORE_PIN ## p ## _PINREG & CORE_PIN ## p ## _BITMASK) #define _READ(P) bool(CORE_PIN ## P ## _PINREG & CORE_PIN ## P ## _BITMASK)
#define _WRITE(P,V) do{ \ #define _WRITE(P,V) do{ \
if (V) CORE_PIN ## P ## _PORTSET = CORE_PIN ## P ## _BITMASK; \ if (V) CORE_PIN ## P ## _PORTSET = CORE_PIN ## P ## _BITMASK; \
@ -79,6 +79,7 @@
#define SET_INPUT(IO) _SET_INPUT(IO) #define SET_INPUT(IO) _SET_INPUT(IO)
#define SET_INPUT_PULLUP(IO) _SET_INPUT_PULLUP(IO) #define SET_INPUT_PULLUP(IO) _SET_INPUT_PULLUP(IO)
#define SET_OUTPUT(IO) _SET_OUTPUT(IO) #define SET_OUTPUT(IO) _SET_OUTPUT(IO)
#define SET_PWM(IO) SET_OUTPUT(IO)
#define GET_INPUT(IO) _GET_INPUT(IO) #define GET_INPUT(IO) _GET_INPUT(IO)
#define GET_OUTPUT(IO) _GET_OUTPUT(IO) #define GET_OUTPUT(IO) _GET_OUTPUT(IO)
@ -89,6 +90,11 @@
#define extDigitalRead(IO) digitalRead(IO) #define extDigitalRead(IO) digitalRead(IO)
#define extDigitalWrite(IO,V) digitalWrite(IO,V) #define extDigitalWrite(IO,V) digitalWrite(IO,V)
#define ANALOG_WRITE(IO,V) analogWrite(IO,V)
#define PWM_PIN(P) digitalPinHasPWM(P)
#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
/** /**
* Ports, functions, and pins * Ports, functions, and pins
*/ */

View file

@ -42,7 +42,7 @@
* Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html * Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
*/ */
#define _READ(p) bool(CORE_PIN ## p ## _PINREG & CORE_PIN ## p ## _BITMASK) #define _READ(P) bool(CORE_PIN ## P ## _PINREG & CORE_PIN ## P ## _BITMASK)
#define _WRITE(P,V) do{ \ #define _WRITE(P,V) do{ \
if (V) CORE_PIN ## P ## _PORTSET = CORE_PIN ## P ## _BITMASK; \ if (V) CORE_PIN ## P ## _PORTSET = CORE_PIN ## P ## _BITMASK; \
@ -78,6 +78,7 @@
#define SET_INPUT(IO) _SET_INPUT(IO) #define SET_INPUT(IO) _SET_INPUT(IO)
#define SET_INPUT_PULLUP(IO) _SET_INPUT_PULLUP(IO) #define SET_INPUT_PULLUP(IO) _SET_INPUT_PULLUP(IO)
#define SET_OUTPUT(IO) _SET_OUTPUT(IO) #define SET_OUTPUT(IO) _SET_OUTPUT(IO)
#define SET_PWM(IO) SET_OUTPUT(IO)
#define GET_INPUT(IO) _GET_INPUT(IO) #define GET_INPUT(IO) _GET_INPUT(IO)
#define GET_OUTPUT(IO) _GET_OUTPUT(IO) #define GET_OUTPUT(IO) _GET_OUTPUT(IO)
@ -88,6 +89,11 @@
#define extDigitalRead(IO) digitalRead(IO) #define extDigitalRead(IO) digitalRead(IO)
#define extDigitalWrite(IO,V) digitalWrite(IO,V) #define extDigitalWrite(IO,V) digitalWrite(IO,V)
#define ANALOG_WRITE(IO,V) analogWrite(IO,V)
#define PWM_PIN(P) digitalPinHasPWM(P)
#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
/** /**
* Ports, functions, and pins * Ports, functions, and pins
*/ */

View file

@ -975,8 +975,8 @@ void setup() {
OUT_WRITE(SPINDLE_DIR_PIN, SPINDLE_INVERT_DIR ? 255 : 0); // init rotation to clockwise (M3) OUT_WRITE(SPINDLE_DIR_PIN, SPINDLE_INVERT_DIR ? 255 : 0); // init rotation to clockwise (M3)
#endif #endif
#if ENABLED(SPINDLE_LASER_PWM) && defined(SPINDLE_LASER_PWM_PIN) && SPINDLE_LASER_PWM_PIN >= 0 #if ENABLED(SPINDLE_LASER_PWM) && defined(SPINDLE_LASER_PWM_PIN) && SPINDLE_LASER_PWM_PIN >= 0
SET_OUTPUT(SPINDLE_LASER_PWM_PIN); SET_PWM(SPINDLE_LASER_PWM_PIN);
analogWrite(SPINDLE_LASER_PWM_PIN, SPINDLE_LASER_PWM_INVERT ? 255 : 0); // set to lowest speed ANALOG_WRITE(SPINDLE_LASER_PWM_PIN, SPINDLE_LASER_PWM_INVERT ? 255 : 0); // set to lowest speed
#endif #endif
#endif #endif
@ -1022,7 +1022,7 @@ void setup() {
#if HAS_CASE_LIGHT #if HAS_CASE_LIGHT
#if DISABLED(CASE_LIGHT_USE_NEOPIXEL) #if DISABLED(CASE_LIGHT_USE_NEOPIXEL)
SET_OUTPUT(CASE_LIGHT_PIN); if (PWM_PIN(CASE_LIGHT_PIN)) SET_PWM(CASE_LIGHT_PIN); else SET_OUTPUT(CASE_LIGHT_PIN);
#endif #endif
update_case_light(); update_case_light();
#endif #endif

View file

@ -69,8 +69,8 @@ void update_case_light() {
#else // !CASE_LIGHT_USE_NEOPIXEL #else // !CASE_LIGHT_USE_NEOPIXEL
if (USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN)) if (PWM_PIN(CASE_LIGHT_PIN))
analogWrite(CASE_LIGHT_PIN, n10ct); ANALOG_WRITE(CASE_LIGHT_PIN, n10ct);
else { else {
const bool s = case_light_on ? !INVERT_CASE_LIGHT : INVERT_CASE_LIGHT; const bool s = case_light_on ? !INVERT_CASE_LIGHT : INVERT_CASE_LIGHT;
WRITE(CASE_LIGHT_PIN, s ? HIGH : LOW); WRITE(CASE_LIGHT_PIN, s ? HIGH : LOW);

View file

@ -81,7 +81,7 @@ void controllerfan_update() {
// allows digital or PWM fan output to be used (see M42 handling) // allows digital or PWM fan output to be used (see M42 handling)
WRITE(CONTROLLER_FAN_PIN, speed); WRITE(CONTROLLER_FAN_PIN, speed);
analogWrite(CONTROLLER_FAN_PIN, speed); ANALOG_WRITE(CONTROLLER_FAN_PIN, speed);
} }
} }

View file

@ -61,11 +61,11 @@ LEDLights leds;
void LEDLights::setup() { void LEDLights::setup() {
#if ENABLED(RGB_LED) || ENABLED(RGBW_LED) #if ENABLED(RGB_LED) || ENABLED(RGBW_LED)
SET_OUTPUT(RGB_LED_R_PIN); if (PWM_PIN(RGB_LED_R_PIN)) SET_PWM(RGB_LED_R_PIN); else SET_OUTPUT(RGB_LED_R_PIN);
SET_OUTPUT(RGB_LED_G_PIN); if (PWM_PIN(RGB_LED_G_PIN)) SET_PWM(RGB_LED_G_PIN); else SET_OUTPUT(RGB_LED_G_PIN);
SET_OUTPUT(RGB_LED_B_PIN); if (PWM_PIN(RGB_LED_B_PIN)) SET_PWM(RGB_LED_B_PIN); else SET_OUTPUT(RGB_LED_B_PIN);
#if ENABLED(RGBW_LED) #if ENABLED(RGBW_LED)
SET_OUTPUT(RGB_LED_W_PIN); if (PWM_PIN(RGB_LED_W_PIN)) SET_PWM(RGB_LED_W_PIN); else SET_OUTPUT(RGB_LED_W_PIN);
#endif #endif
#endif #endif
#if ENABLED(NEOPIXEL_LED) #if ENABLED(NEOPIXEL_LED)
@ -112,16 +112,12 @@ void LEDLights::set_color(const LEDColor &incol
// This variant uses 3-4 separate pins for the RGB(W) components. // This variant uses 3-4 separate pins for the RGB(W) components.
// If the pins can do PWM then their intensity will be set. // If the pins can do PWM then their intensity will be set.
WRITE(RGB_LED_R_PIN, incol.r ? HIGH : LOW); #define UPDATE_RGBW(C,c) do{ if (PWM_PIN(RGB_LED_##C##_PIN)) ANALOG_WRITE(RGB_LED_##C##_PIN, incol.r); else WRITE(RGB_LED_##C##_PIN, incol.c ? HIGH : LOW); }while(0)
WRITE(RGB_LED_G_PIN, incol.g ? HIGH : LOW); UPDATE_RGBW(R,r);
WRITE(RGB_LED_B_PIN, incol.b ? HIGH : LOW); UPDATE_RGBW(G,g);
analogWrite(RGB_LED_R_PIN, incol.r); UPDATE_RGBW(B,b);
analogWrite(RGB_LED_G_PIN, incol.g);
analogWrite(RGB_LED_B_PIN, incol.b);
#if ENABLED(RGBW_LED) #if ENABLED(RGBW_LED)
WRITE(RGB_LED_W_PIN, incol.w ? HIGH : LOW); UPDATE_RGBW(W,w);
analogWrite(RGB_LED_W_PIN, incol.w);
#endif #endif
#endif #endif

View file

@ -74,7 +74,7 @@ inline void delay_for_power_down() { safe_delay(SPINDLE_LASER_POWERDOWN_DELAY);
inline void set_spindle_laser_ocr(const uint8_t ocr) { inline void set_spindle_laser_ocr(const uint8_t ocr) {
WRITE(SPINDLE_LASER_ENABLE_PIN, SPINDLE_LASER_ENABLE_INVERT); // turn spindle on (active low) WRITE(SPINDLE_LASER_ENABLE_PIN, SPINDLE_LASER_ENABLE_INVERT); // turn spindle on (active low)
analogWrite(SPINDLE_LASER_PWM_PIN, (SPINDLE_LASER_PWM_INVERT) ? 255 - ocr : ocr); ANALOG_WRITE(SPINDLE_LASER_PWM_PIN, (SPINDLE_LASER_PWM_INVERT) ? 255 - ocr : ocr);
} }
#if ENABLED(SPINDLE_LASER_PWM) #if ENABLED(SPINDLE_LASER_PWM)
@ -82,7 +82,7 @@ inline void set_spindle_laser_ocr(const uint8_t ocr) {
void update_spindle_laser_power() { void update_spindle_laser_power() {
if (spindle_laser_power == 0) { if (spindle_laser_power == 0) {
WRITE(SPINDLE_LASER_ENABLE_PIN, !SPINDLE_LASER_ENABLE_INVERT); // turn spindle off (active low) WRITE(SPINDLE_LASER_ENABLE_PIN, !SPINDLE_LASER_ENABLE_INVERT); // turn spindle off (active low)
analogWrite(SPINDLE_LASER_PWM_PIN, SPINDLE_LASER_PWM_INVERT ? 255 : 0); // only write low byte ANALOG_WRITE(SPINDLE_LASER_PWM_PIN, SPINDLE_LASER_PWM_INVERT ? 255 : 0); // only write low byte
delay_for_power_down(); delay_for_power_down();
} }
else { // Convert RPM to PWM duty cycle else { // Convert RPM to PWM duty cycle

View file

@ -51,7 +51,7 @@ void GcodeSuite::M42() {
pinMode(pin, OUTPUT); pinMode(pin, OUTPUT);
extDigitalWrite(pin, pin_status); extDigitalWrite(pin, pin_status);
analogWrite(pin, pin_status); ANALOG_WRITE(pin, pin_status);
#if FAN_COUNT > 0 #if FAN_COUNT > 0
switch (pin) { switch (pin) {

View file

@ -57,7 +57,7 @@
SERIAL_ECHOLNPGM("Case light: off"); SERIAL_ECHOLNPGM("Case light: off");
} }
else { else {
if (!USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN)) SERIAL_ECHOLNPGM("Case light: on"); if (!PWM_PIN(CASE_LIGHT_PIN)) SERIAL_ECHOLNPGM("Case light: on");
else SERIAL_ECHOLNPAIR("Case light: ", case_light_brightness); else SERIAL_ECHOLNPAIR("Case light: ", case_light_brightness);
} }
} }

View file

@ -125,7 +125,7 @@ void GcodeSuite::M115() {
); );
cap_line(PSTR("CASE_LIGHT_BRIGHTNESS") cap_line(PSTR("CASE_LIGHT_BRIGHTNESS")
#if HAS_CASE_LIGHT #if HAS_CASE_LIGHT
, USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN) , PWM_PIN(CASE_LIGHT_PIN)
#endif #endif
); );

View file

@ -958,27 +958,6 @@
#define HAS_AUTO_FAN_5 (HOTENDS > 5 && PIN_EXISTS(E5_AUTO_FAN)) #define HAS_AUTO_FAN_5 (HOTENDS > 5 && PIN_EXISTS(E5_AUTO_FAN))
#define HAS_AUTO_CHAMBER_FAN (PIN_EXISTS(CHAMBER_AUTO_FAN)) #define HAS_AUTO_CHAMBER_FAN (PIN_EXISTS(CHAMBER_AUTO_FAN))
#define HAS_AUTO_FAN (HAS_AUTO_FAN_0 || HAS_AUTO_FAN_1 || HAS_AUTO_FAN_2 || HAS_AUTO_FAN_3 || HAS_AUTO_FAN_4 || HAS_AUTO_FAN_5 || HAS_AUTO_CHAMBER_FAN) #define HAS_AUTO_FAN (HAS_AUTO_FAN_0 || HAS_AUTO_FAN_1 || HAS_AUTO_FAN_2 || HAS_AUTO_FAN_3 || HAS_AUTO_FAN_4 || HAS_AUTO_FAN_5 || HAS_AUTO_CHAMBER_FAN)
#define AUTO_1_IS_0 (E1_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
#define AUTO_2_IS_0 (E2_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
#define AUTO_2_IS_1 (E2_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
#define AUTO_3_IS_0 (E3_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
#define AUTO_3_IS_1 (E3_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
#define AUTO_3_IS_2 (E3_AUTO_FAN_PIN == E2_AUTO_FAN_PIN)
#define AUTO_4_IS_0 (E4_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
#define AUTO_4_IS_1 (E4_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
#define AUTO_4_IS_2 (E4_AUTO_FAN_PIN == E2_AUTO_FAN_PIN)
#define AUTO_4_IS_3 (E4_AUTO_FAN_PIN == E3_AUTO_FAN_PIN)
#define AUTO_5_IS_0 (E5_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
#define AUTO_5_IS_1 (E5_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
#define AUTO_5_IS_2 (E5_AUTO_FAN_PIN == E2_AUTO_FAN_PIN)
#define AUTO_5_IS_3 (E5_AUTO_FAN_PIN == E3_AUTO_FAN_PIN)
#define AUTO_5_IS_4 (E5_AUTO_FAN_PIN == E4_AUTO_FAN_PIN)
#define AUTO_CHAMBER_IS_0 (CHAMBER_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
#define AUTO_CHAMBER_IS_1 (CHAMBER_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
#define AUTO_CHAMBER_IS_2 (CHAMBER_AUTO_FAN_PIN == E2_AUTO_FAN_PIN)
#define AUTO_CHAMBER_IS_3 (CHAMBER_AUTO_FAN_PIN == E3_AUTO_FAN_PIN)
#define AUTO_CHAMBER_IS_4 (CHAMBER_AUTO_FAN_PIN == E4_AUTO_FAN_PIN)
#define AUTO_CHAMBER_IS_5 (CHAMBER_AUTO_FAN_PIN == E5_AUTO_FAN_PIN)
// Other fans // Other fans
#define HAS_FAN0 (PIN_EXISTS(FAN)) #define HAS_FAN0 (PIN_EXISTS(FAN))

View file

@ -1700,13 +1700,13 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#if HAS_AUTO_FAN && EXTRUDER_AUTO_FAN_SPEED != 255 #if HAS_AUTO_FAN && EXTRUDER_AUTO_FAN_SPEED != 255
#define AF_ERR_SUFF "_AUTO_FAN_PIN is not a PWM pin. Set EXTRUDER_AUTO_FAN_SPEED to 255." #define AF_ERR_SUFF "_AUTO_FAN_PIN is not a PWM pin. Set EXTRUDER_AUTO_FAN_SPEED to 255."
#if HAS_AUTO_FAN_0 #if HAS_AUTO_FAN_0
static_assert(GET_TIMER(E0_AUTO_FAN_PIN), "E0" AF_ERR_SUFF); static_assert(PWM_PIN(E0_AUTO_FAN_PIN), "E0" AF_ERR_SUFF);
#elif HAS_AUTO_FAN_1 #elif HAS_AUTO_FAN_1
static_assert(GET_TIMER(E1_AUTO_FAN_PIN), "E1" AF_ERR_SUFF); static_assert(PWM_PIN(E1_AUTO_FAN_PIN), "E1" AF_ERR_SUFF);
#elif HAS_AUTO_FAN_2 #elif HAS_AUTO_FAN_2
static_assert(GET_TIMER(E2_AUTO_FAN_PIN), "E2" AF_ERR_SUFF); static_assert(PWM_PIN(E2_AUTO_FAN_PIN), "E2" AF_ERR_SUFF);
#elif HAS_AUTO_FAN_3 #elif HAS_AUTO_FAN_3
static_assert(GET_TIMER(E3_AUTO_FAN_PIN), "E3" AF_ERR_SUFF); static_assert(PWM_PIN(E3_AUTO_FAN_PIN), "E3" AF_ERR_SUFF);
#endif #endif
#endif #endif

View file

@ -299,7 +299,7 @@ void menu_configuration() {
// Set Case light on/off/brightness // Set Case light on/off/brightness
// //
#if ENABLED(MENU_ITEM_CASE_LIGHT) #if ENABLED(MENU_ITEM_CASE_LIGHT)
if (USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN)) if (PWM_PIN(CASE_LIGHT_PIN))
MENU_ITEM(submenu, MSG_CASE_LIGHT, menu_case_light); MENU_ITEM(submenu, MSG_CASE_LIGHT, menu_case_light);
else else
MENU_ITEM_EDIT_CALLBACK(bool, MSG_CASE_LIGHT, (bool*)&case_light_on, update_case_light); MENU_ITEM_EDIT_CALLBACK(bool, MSG_CASE_LIGHT, (bool*)&case_light_on, update_case_light);

View file

@ -886,7 +886,7 @@ void Endstops::update() {
ES_REPORT_CHANGE(Z3_MAX); ES_REPORT_CHANGE(Z3_MAX);
#endif #endif
SERIAL_ECHOLNPGM("\n"); SERIAL_ECHOLNPGM("\n");
analogWrite(LED_PIN, local_LED_status); ANALOG_WRITE(LED_PIN, local_LED_status);
local_LED_status ^= 255; local_LED_status ^= 255;
old_live_state_local = live_state_local; old_live_state_local = live_state_local;
} }

View file

@ -1290,13 +1290,13 @@ void Planner::check_axes_activity() {
#else #else
#if HAS_FAN0 #if HAS_FAN0
analogWrite(FAN_PIN, CALC_FAN_SPEED(0)); ANALOG_WRITE(FAN_PIN, CALC_FAN_SPEED(0));
#endif #endif
#if HAS_FAN1 #if HAS_FAN1
analogWrite(FAN1_PIN, CALC_FAN_SPEED(1)); ANALOG_WRITE(FAN1_PIN, CALC_FAN_SPEED(1));
#endif #endif
#if HAS_FAN2 #if HAS_FAN2
analogWrite(FAN2_PIN, CALC_FAN_SPEED(2)); ANALOG_WRITE(FAN2_PIN, CALC_FAN_SPEED(2));
#endif #endif
#endif #endif
@ -1308,10 +1308,10 @@ void Planner::check_axes_activity() {
#if ENABLED(BARICUDA) #if ENABLED(BARICUDA)
#if HAS_HEATER_1 #if HAS_HEATER_1
analogWrite(HEATER_1_PIN, tail_valve_pressure); ANALOG_WRITE(HEATER_1_PIN, tail_valve_pressure);
#endif #endif
#if HAS_HEATER_2 #if HAS_HEATER_2
analogWrite(HEATER_2_PIN, tail_e_to_p_pressure); ANALOG_WRITE(HEATER_2_PIN, tail_e_to_p_pressure);
#endif #endif
#endif #endif
} }

View file

@ -2510,7 +2510,7 @@ void Stepper::report_positions() {
if (WITHIN(driver, 0, COUNT(motor_current_setting) - 1)) if (WITHIN(driver, 0, COUNT(motor_current_setting) - 1))
motor_current_setting[driver] = current; // update motor_current_setting 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) ANALOG_WRITE(MOTOR_CURRENT_PWM_## P ##_PIN, 255L * current / (MOTOR_CURRENT_PWM_RANGE))
switch (driver) { switch (driver) {
case 0: case 0:
#if PIN_EXISTS(MOTOR_CURRENT_PWM_X) #if PIN_EXISTS(MOTOR_CURRENT_PWM_X)
@ -2560,25 +2560,25 @@ void Stepper::report_positions() {
#elif HAS_MOTOR_CURRENT_PWM #elif HAS_MOTOR_CURRENT_PWM
#if PIN_EXISTS(MOTOR_CURRENT_PWM_X) #if PIN_EXISTS(MOTOR_CURRENT_PWM_X)
SET_OUTPUT(MOTOR_CURRENT_PWM_X_PIN); SET_PWM(MOTOR_CURRENT_PWM_X_PIN);
#endif #endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Y) #if PIN_EXISTS(MOTOR_CURRENT_PWM_Y)
SET_OUTPUT(MOTOR_CURRENT_PWM_Y_PIN); SET_PWM(MOTOR_CURRENT_PWM_Y_PIN);
#endif #endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_XY) #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
SET_OUTPUT(MOTOR_CURRENT_PWM_XY_PIN); SET_PWM(MOTOR_CURRENT_PWM_XY_PIN);
#endif #endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z) #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
SET_OUTPUT(MOTOR_CURRENT_PWM_Z_PIN); SET_PWM(MOTOR_CURRENT_PWM_Z_PIN);
#endif #endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E) #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
SET_OUTPUT(MOTOR_CURRENT_PWM_E_PIN); SET_PWM(MOTOR_CURRENT_PWM_E_PIN);
#endif #endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E0) #if PIN_EXISTS(MOTOR_CURRENT_PWM_E0)
SET_OUTPUT(MOTOR_CURRENT_PWM_E0_PIN); SET_PWM(MOTOR_CURRENT_PWM_E0_PIN);
#endif #endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E1) #if PIN_EXISTS(MOTOR_CURRENT_PWM_E1)
SET_OUTPUT(MOTOR_CURRENT_PWM_E1_PIN); SET_PWM(MOTOR_CURRENT_PWM_E1_PIN);
#endif #endif
refresh_motor_power(); refresh_motor_power();

View file

@ -610,6 +610,28 @@ int Temperature::getHeaterPower(const int heater) {
#if HAS_AUTO_FAN #if HAS_AUTO_FAN
#define AUTO_1_IS_0 (E1_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
#define AUTO_2_IS_0 (E2_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
#define AUTO_2_IS_1 (E2_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
#define AUTO_3_IS_0 (E3_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
#define AUTO_3_IS_1 (E3_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
#define AUTO_3_IS_2 (E3_AUTO_FAN_PIN == E2_AUTO_FAN_PIN)
#define AUTO_4_IS_0 (E4_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
#define AUTO_4_IS_1 (E4_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
#define AUTO_4_IS_2 (E4_AUTO_FAN_PIN == E2_AUTO_FAN_PIN)
#define AUTO_4_IS_3 (E4_AUTO_FAN_PIN == E3_AUTO_FAN_PIN)
#define AUTO_5_IS_0 (E5_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
#define AUTO_5_IS_1 (E5_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
#define AUTO_5_IS_2 (E5_AUTO_FAN_PIN == E2_AUTO_FAN_PIN)
#define AUTO_5_IS_3 (E5_AUTO_FAN_PIN == E3_AUTO_FAN_PIN)
#define AUTO_5_IS_4 (E5_AUTO_FAN_PIN == E4_AUTO_FAN_PIN)
#define AUTO_CHAMBER_IS_0 (CHAMBER_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
#define AUTO_CHAMBER_IS_1 (CHAMBER_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
#define AUTO_CHAMBER_IS_2 (CHAMBER_AUTO_FAN_PIN == E2_AUTO_FAN_PIN)
#define AUTO_CHAMBER_IS_3 (CHAMBER_AUTO_FAN_PIN == E3_AUTO_FAN_PIN)
#define AUTO_CHAMBER_IS_4 (CHAMBER_AUTO_FAN_PIN == E4_AUTO_FAN_PIN)
#define AUTO_CHAMBER_IS_5 (CHAMBER_AUTO_FAN_PIN == E5_AUTO_FAN_PIN)
void Temperature::checkExtruderAutoFans() { void Temperature::checkExtruderAutoFans() {
static const uint8_t fanBit[] PROGMEM = { static const uint8_t fanBit[] PROGMEM = {
0, 0,
@ -634,8 +656,8 @@ int Temperature::getHeaterPower(const int heater) {
#endif #endif
#define _UPDATE_AUTO_FAN(P,D,A) do{ \ #define _UPDATE_AUTO_FAN(P,D,A) do{ \
if (USEABLE_HARDWARE_PWM(P##_AUTO_FAN_PIN)) \ if (PWM_PIN(P##_AUTO_FAN_PIN) && EXTRUDER_AUTO_FAN_SPEED < 255) \
analogWrite(P##_AUTO_FAN_PIN, A); \ ANALOG_WRITE(P##_AUTO_FAN_PIN, A); \
else \ else \
WRITE(P##_AUTO_FAN_PIN, D); \ WRITE(P##_AUTO_FAN_PIN, D); \
}while(0) }while(0)
@ -1280,6 +1302,25 @@ void Temperature::updateTemperaturesFromRawValues() {
SPIclass<MAX6675_DO_PIN, MOSI_PIN, MAX6675_SCK_PIN> max6675_spi; SPIclass<MAX6675_DO_PIN, MOSI_PIN, MAX6675_SCK_PIN> max6675_spi;
#endif #endif
// Init fans according to whether they're native PWM or Software PWM
#define _INIT_SOFT_FAN(P) OUT_WRITE(P, FAN_INVERTING ? LOW : HIGH)
#if ENABLED(FAN_SOFT_PWM)
#define _INIT_FAN_PIN(P) _INIT_SOFT_FAN(P)
#else
#define _INIT_FAN_PIN(P) do{ if (PWM_PIN(P)) SET_PWM(P); else _INIT_SOFT_FAN(P); }while(0)
#endif
#if ENABLED(FAST_PWM_FAN)
#define SET_FAST_PWM_FREQ(P) set_pwm_frequency(P, FAST_PWM_FAN_FREQUENCY)
#else
#define SET_FAST_PWM_FREQ(P) NOOP
#endif
#define INIT_FAN_PIN(P) do{ _INIT_FAN_PIN(P); SET_FAST_PWM_FREQ(P); }while(0)
#if EXTRUDER_AUTO_FAN_SPEED != 255
#define INIT_AUTO_FAN_PIN(P) do{ if (P == FAN1_PIN || P == FAN2_PIN) { SET_PWM(P); SET_FAST_PWM_FREQ(FAST_PWM_FAN_FREQUENCY); } else SET_OUTPUT(P); }while(0)
#else
#define INIT_AUTO_FAN_PIN(P) SET_OUTPUT(P)
#endif
/** /**
* Initialize the temperature manager * Initialize the temperature manager
* The manager is implemented by periodic calls to manage_heater() * The manager is implemented by periodic calls to manage_heater()
@ -1329,32 +1370,18 @@ void Temperature::init() {
#if HAS_HEATED_CHAMBER #if HAS_HEATED_CHAMBER
OUT_WRITE(HEATER_CHAMBER_PIN, HEATER_CHAMBER_INVERTING); OUT_WRITE(HEATER_CHAMBER_PIN, HEATER_CHAMBER_INVERTING);
#endif #endif
#if HAS_FAN0 #if HAS_FAN0
SET_OUTPUT(FAN_PIN); INIT_FAN_PIN(FAN_PIN);
#if ENABLED(FAST_PWM_FAN)
set_pwm_frequency(FAN_PIN, FAST_PWM_FAN_FREQUENCY);
#endif #endif
#endif
#if HAS_FAN1 #if HAS_FAN1
SET_OUTPUT(FAN1_PIN); INIT_FAN_PIN(FAN1_PIN);
#if ENABLED(FAST_PWM_FAN)
set_pwm_frequency(FAN1_PIN, FAST_PWM_FAN_FREQUENCY);
#endif #endif
#endif
#if HAS_FAN2 #if HAS_FAN2
SET_OUTPUT(FAN2_PIN); INIT_FAN_PIN(FAN2_PIN);
#if ENABLED(FAST_PWM_FAN)
set_pwm_frequency(FAN2_PIN, FAST_PWM_FAN_FREQUENCY);
#endif #endif
#endif
#if ENABLED(USE_CONTROLLER_FAN) #if ENABLED(USE_CONTROLLER_FAN)
SET_OUTPUT(CONTROLLER_FAN_PIN); INIT_FAN_PIN(CONTROLLER_FAN_PIN);
#if ENABLED(FAST_PWM_FAN)
set_pwm_frequency(CONTROLLER_FAN_PIN, FAST_PWM_FAN_FREQUENCY);
#endif
#endif #endif
#if MAX6675_SEPARATE_SPI #if MAX6675_SEPARATE_SPI
@ -1408,74 +1435,25 @@ void Temperature::init() {
ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_TEMPERATURE_INTERRUPT();
#if HAS_AUTO_FAN_0 #if HAS_AUTO_FAN_0
#if E0_AUTO_FAN_PIN == FAN1_PIN INIT_AUTO_FAN_PIN(E0_AUTO_FAN_PIN);
SET_OUTPUT(E0_AUTO_FAN_PIN);
#if ENABLED(FAST_PWM_FAN)
set_pwm_frequency(E0_AUTO_FAN_PIN, FAST_PWM_FAN_FREQUENCY);
#endif
#else
SET_OUTPUT(E0_AUTO_FAN_PIN);
#endif
#endif #endif
#if HAS_AUTO_FAN_1 && !AUTO_1_IS_0 #if HAS_AUTO_FAN_1 && !AUTO_1_IS_0
#if E1_AUTO_FAN_PIN == FAN1_PIN INIT_AUTO_FAN_PIN(E1_AUTO_FAN_PIN);
SET_OUTPUT(E1_AUTO_FAN_PIN);
#if ENABLED(FAST_PWM_FAN)
set_pwm_frequency(E1_AUTO_FAN_PIN, FAST_PWM_FAN_FREQUENCY);
#endif
#else
SET_OUTPUT(E1_AUTO_FAN_PIN);
#endif
#endif #endif
#if HAS_AUTO_FAN_2 && !(AUTO_2_IS_0 || AUTO_2_IS_1) #if HAS_AUTO_FAN_2 && !(AUTO_2_IS_0 || AUTO_2_IS_1)
#if E2_AUTO_FAN_PIN == FAN1_PIN INIT_AUTO_FAN_PIN(E2_AUTO_FAN_PIN);
SET_OUTPUT(E2_AUTO_FAN_PIN);
#if ENABLED(FAST_PWM_FAN)
set_pwm_frequency(E2_AUTO_FAN_PIN, FAST_PWM_FAN_FREQUENCY);
#endif
#else
SET_OUTPUT(E2_AUTO_FAN_PIN);
#endif
#endif #endif
#if HAS_AUTO_FAN_3 && !(AUTO_3_IS_0 || AUTO_3_IS_1 || AUTO_3_IS_2) #if HAS_AUTO_FAN_3 && !(AUTO_3_IS_0 || AUTO_3_IS_1 || AUTO_3_IS_2)
#if E3_AUTO_FAN_PIN == FAN1_PIN INIT_AUTO_FAN_PIN(E3_AUTO_FAN_PIN);
SET_OUTPUT(E3_AUTO_FAN_PIN);
#if ENABLED(FAST_PWM_FAN)
set_pwm_frequency(E3_AUTO_FAN_PIN, FAST_PWM_FAN_FREQUENCY);
#endif
#else
SET_OUTPUT(E3_AUTO_FAN_PIN);
#endif
#endif #endif
#if HAS_AUTO_FAN_4 && !(AUTO_4_IS_0 || AUTO_4_IS_1 || AUTO_4_IS_2 || AUTO_4_IS_3) #if HAS_AUTO_FAN_4 && !(AUTO_4_IS_0 || AUTO_4_IS_1 || AUTO_4_IS_2 || AUTO_4_IS_3)
#if E4_AUTO_FAN_PIN == FAN1_PIN INIT_AUTO_FAN_PIN(E4_AUTO_FAN_PIN);
SET_OUTPUT(E4_AUTO_FAN_PIN);
#if ENABLED(FAST_PWM_FAN)
set_pwm_frequency(E4_AUTO_FAN_PIN, FAST_PWM_FAN_FREQUENCY);
#endif
#else
SET_OUTPUT(E4_AUTO_FAN_PIN);
#endif
#endif #endif
#if HAS_AUTO_FAN_5 && !(AUTO_5_IS_0 || AUTO_5_IS_1 || AUTO_5_IS_2 || AUTO_5_IS_3 || AUTO_5_IS_4) #if HAS_AUTO_FAN_5 && !(AUTO_5_IS_0 || AUTO_5_IS_1 || AUTO_5_IS_2 || AUTO_5_IS_3 || AUTO_5_IS_4)
#if E5_AUTO_FAN_PIN == FAN1_PIN INIT_AUTO_FAN_PIN(E5_AUTO_FAN_PIN);
SET_OUTPUT(E5_AUTO_FAN_PIN);
#if ENABLED(FAST_PWM_FAN)
set_pwm_frequency(E5_AUTO_FAN_PIN, FAST_PWM_FAN_FREQUENCY);
#endif
#else
SET_OUTPUT(E5_AUTO_FAN_PIN);
#endif
#endif #endif
#if HAS_AUTO_CHAMBER_FAN && !(AUTO_CHAMBER_IS_0 || AUTO_CHAMBER_IS_1 || AUTO_CHAMBER_IS_2 || AUTO_CHAMBER_IS_3 || AUTO_CHAMBER_IS_4 || AUTO_CHAMBER_IS_5) #if HAS_AUTO_CHAMBER_FAN && !(AUTO_CHAMBER_IS_0 || AUTO_CHAMBER_IS_1 || AUTO_CHAMBER_IS_2 || AUTO_CHAMBER_IS_3 || AUTO_CHAMBER_IS_4 || AUTO_CHAMBER_IS_5)
#if CHAMBER_AUTO_FAN_PIN == FAN1_PIN INIT_AUTO_FAN_PIN(CHAMBER_AUTO_FAN_PIN);
SET_OUTPUT(CHAMBER_AUTO_FAN_PIN);
#if ENABLED(FAST_PWM_FAN)
set_pwm_frequency(CHAMBER_AUTO_FAN_PIN, FAST_PWM_FAN_FREQUENCY);
#endif
#else
SET_OUTPUT(CHAMBER_AUTO_FAN_PIN);
#endif
#endif #endif
// Wait for temperature measurement to settle // Wait for temperature measurement to settle