Replace digitalPinHasPWM with HAS_TIMER (#13520)

This commit is contained in:
Alexander Amelkin 2019-03-29 20:21:14 +03:00 committed by Scott Lahteine
parent 5a2c68e995
commit e40636a7c1
11 changed files with 49 additions and 49 deletions

View file

@ -81,9 +81,9 @@
#define _SET_INPUT(IO) CBI(DIO ## IO ## _DDR, DIO ## IO ## _PIN) #define _SET_INPUT(IO) CBI(DIO ## IO ## _DDR, DIO ## IO ## _PIN)
#define _SET_OUTPUT(IO) SBI(DIO ## IO ## _DDR, DIO ## IO ## _PIN) #define _SET_OUTPUT(IO) SBI(DIO ## IO ## _DDR, DIO ## IO ## _PIN)
#define _GET_INPUT(IO) !TEST(DIO ## IO ## _DDR, DIO ## IO ## _PIN) #define _IS_INPUT(IO) !TEST(DIO ## IO ## _DDR, DIO ## IO ## _PIN)
#define _GET_OUTPUT(IO) TEST(DIO ## IO ## _DDR, DIO ## IO ## _PIN) #define _IS_OUTPUT(IO) TEST(DIO ## IO ## _DDR, DIO ## IO ## _PIN)
#define _GET_TIMER(IO) DIO ## IO ## _PWM #define _HAS_TIMER(IO) DIO ## IO ## _PWM
// digitalRead/Write wrappers // digitalRead/Write wrappers
#ifdef FASTIO_EXT_START #ifdef FASTIO_EXT_START
@ -104,9 +104,9 @@
#define SET_PWM(IO) SET_OUTPUT(IO) #define SET_PWM(IO) SET_OUTPUT(IO)
#define GET_INPUT(IO) _GET_INPUT(IO) #define IS_INPUT(IO) _IS_INPUT(IO)
#define GET_OUTPUT(IO) _GET_OUTPUT(IO) #define IS_OUTPUT(IO) _IS_OUTPUT(IO)
#define GET_TIMER(IO) _GET_TIMER(IO) #define HAS_TIMER(IO) _HAS_TIMER(IO)
#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)

View file

@ -177,11 +177,11 @@
#define SET_PWM(IO) SET_OUTPUT(IO) #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 IS_INPUT(IO) ((digitalPinToPort(IO)->PIO_OSR & digitalPinToBitMask(IO)) == 0)
// Check if pin is an output // Check if pin is an output
#define GET_OUTPUT(IO) ((digitalPinToPort(IO)->PIO_OSR & digitalPinToBitMask(IO)) != 0) #define IS_OUTPUT(IO) ((digitalPinToPort(IO)->PIO_OSR & digitalPinToBitMask(IO)) != 0)
// Check if pin is a timer - Must be a constexpr // Check if pin is a timer - Must be a constexpr
#define GET_TIMER(IO) ((IO) >= 2 && (IO) <= 13) #define HAS_TIMER(IO) ((IO) >= 2 && (IO) <= 13)
// Shorthand // Shorthand
#define OUT_WRITE(IO,V) { SET_OUTPUT(IO); WRITE(IO,V); } #define OUT_WRITE(IO,V) { SET_OUTPUT(IO); WRITE(IO,V); }

View file

@ -75,19 +75,19 @@
// hg42: currently not used, but was used by pinsDebug // hg42: currently not used, but was used by pinsDebug
/// check if pin is an input /// check if pin is an input
#define _GET_INPUT(IO) (LPC1768_PIN_PIN(IO) >= 0) #define _IS_INPUT(IO) (LPC1768_PIN_PIN(IO) >= 0)
/// check if pin is an output /// check if pin is an output
#define _GET_OUTPUT(IO) (LPC1768_PIN_PIN(IO) >= 0) #define _IS_OUTPUT(IO) (LPC1768_PIN_PIN(IO) >= 0)
// hg42: GET_TIMER is used only to check if it's a PWM pin // hg42: HAS_TIMER is used only to check if it's a PWM pin
// hg42: we cannot use USEABLE_HARDWARE_PWM because it uses a function that cannot be used statically // hg42: we cannot use USEABLE_HARDWARE_PWM because it uses a function that cannot be used statically
// hg42: instead use PWM bit from the #define // hg42: instead use PWM bit from the #define
/// check if pin is a timer /// check if pin is a timer
#define _GET_TIMER(IO) true // could be LPC1768_PIN_PWM(IO), but there #define _HAS_TIMER(IO) true // could be LPC1768_PIN_PWM(IO), but there
// hg42: could be this: // hg42: could be this:
// #define _GET_TIMER(IO) LPC1768_PIN_PWM(IO) // #define _HAS_TIMER(IO) LPC1768_PIN_PWM(IO)
// but this is an incomplete check (12 pins are PWMable, but only 6 can be used at the same time) // but this is an incomplete check (12 pins are PWMable, but only 6 can be used at the same time)
/// Read a pin wrapper /// Read a pin wrapper
@ -112,12 +112,12 @@
#define SET_PWM(IO) SET_OUTPUT(IO) #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 IS_INPUT(IO) _IS_INPUT(IO)
/// check if pin is an output wrapper /// check if pin is an output wrapper
#define GET_OUTPUT(IO) _GET_OUTPUT(IO) #define IS_OUTPUT(IO) _IS_OUTPUT(IO)
/// check if pin is a timer (wrapper) /// check if pin is a timer (wrapper)
#define GET_TIMER(IO) _GET_TIMER(IO) #define HAS_TIMER(IO) _HAS_TIMER(IO)
// Shorthand // Shorthand
#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)

View file

@ -84,14 +84,14 @@
#define _PULLDOWN(IO,V) pinMode(IO, (V) ? INPUT_PULLDOWN : INPUT) #define _PULLDOWN(IO,V) pinMode(IO, (V) ? INPUT_PULLDOWN : INPUT)
/// check if pin is an input /// check if pin is an input
#define _GET_INPUT(IO) (!gpio_get_dir(IO)) #define _IS_INPUT(IO) (!gpio_get_dir(IO))
/// check if pin is an output /// check if pin is an output
#define _GET_OUTPUT(IO) (gpio_get_dir(IO)) #define _IS_OUTPUT(IO) (gpio_get_dir(IO))
/// check if pin is a timer /// check if pin is a timer
/// all gpio pins are pwm capable, either interrupt or hardware pwm controlled /// all gpio pins are pwm capable, either interrupt or hardware pwm controlled
#define _GET_TIMER(IO) true #define _HAS_TIMER(IO) true
/// Read a pin wrapper /// Read a pin wrapper
#define READ(IO) _READ(IO) #define READ(IO) _READ(IO)
@ -115,12 +115,12 @@
#define SET_PWM(IO) SET_OUTPUT(IO) #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 IS_INPUT(IO) _IS_INPUT(IO)
/// check if pin is an output wrapper /// check if pin is an output wrapper
#define GET_OUTPUT(IO) _GET_OUTPUT(IO) #define IS_OUTPUT(IO) _IS_OUTPUT(IO)
/// check if pin is a timer (wrapper) /// check if pin is a timer (wrapper)
#define GET_TIMER(IO) _GET_TIMER(IO) #define HAS_TIMER(IO) _HAS_TIMER(IO)
// Shorthand // Shorthand
#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)

View file

@ -78,11 +78,11 @@ void FastIO_init(); // Must be called before using fast io macros
#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 SET_PWM(IO) _SET_MODE(IO, PWM)
#define GET_INPUT(IO) #define IS_INPUT(IO)
#define GET_OUTPUT(IO) #define IS_OUTPUT(IO)
#define GET_TIMER(IO) #define HAS_TIMER(IO)
#define PWM_PIN(P) digitalPinHasPWM(P) #define PWM_PIN(P) HAS_TIMER(P)
#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P) #define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
// digitalRead/Write wrappers // digitalRead/Write wrappers

View file

@ -45,11 +45,11 @@
#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 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 IS_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 IS_OUTPUT(IO) (_GET_MODE(IO) == GPIO_OUTPUT_PP)
#define GET_TIMER(IO) (PIN_MAP[IO].timer_device != NULL) #define HAS_TIMER(IO) (PIN_MAP[IO].timer_device != NULL)
#define PWM_PIN(P) digitalPinHasPWM(P) #define PWM_PIN(P) HAS_TIMER(P)
#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P) #define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
// digitalRead/Write wrappers // digitalRead/Write wrappers

View file

@ -48,9 +48,9 @@
#define TOGGLE(IO) OUT_WRITE(IO, !READ(IO)) #define TOGGLE(IO) OUT_WRITE(IO, !READ(IO))
#define GET_INPUT(IO) #define IS_INPUT(IO)
#define GET_OUTPUT(IO) #define IS_OUTPUT(IO)
#define GET_TIMER(IO) #define HAS_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)

View file

@ -47,9 +47,9 @@
#define TOGGLE(IO) OUT_WRITE(IO, !READ(IO)) #define TOGGLE(IO) OUT_WRITE(IO, !READ(IO))
#define GET_INPUT(IO) #define IS_INPUT(IO)
#define GET_OUTPUT(IO) #define IS_OUTPUT(IO)
#define GET_TIMER(IO) #define HAS_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)

View file

@ -67,8 +67,8 @@
GPIO_BITBAND(CORE_PIN ## P ## _DDRREG , CORE_PIN ## P ## _BIT) = 0; \ GPIO_BITBAND(CORE_PIN ## P ## _DDRREG , CORE_PIN ## P ## _BIT) = 0; \
}while(0) }while(0)
#define _GET_INPUT(P) ((CORE_PIN ## P ## _DDRREG & CORE_PIN ## P ## _BITMASK) == 0) #define _IS_INPUT(P) ((CORE_PIN ## P ## _DDRREG & CORE_PIN ## P ## _BITMASK) == 0)
#define _GET_OUTPUT(P) ((CORE_PIN ## P ## _DDRREG & CORE_PIN ## P ## _BITMASK) == 0) #define _IS_OUTPUT(P) ((CORE_PIN ## P ## _DDRREG & CORE_PIN ## P ## _BITMASK) == 0)
#define READ(IO) _READ(IO) #define READ(IO) _READ(IO)
@ -81,8 +81,8 @@
#define SET_OUTPUT(IO) _SET_OUTPUT(IO) #define SET_OUTPUT(IO) _SET_OUTPUT(IO)
#define SET_PWM(IO) SET_OUTPUT(IO) #define SET_PWM(IO) SET_OUTPUT(IO)
#define GET_INPUT(IO) _GET_INPUT(IO) #define IS_INPUT(IO) _IS_INPUT(IO)
#define GET_OUTPUT(IO) _GET_OUTPUT(IO) #define IS_OUTPUT(IO) _IS_OUTPUT(IO)
#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)

View file

@ -66,8 +66,8 @@
GPIO_BITBAND(CORE_PIN ## P ## _DDRREG , CORE_PIN ## P ## _BIT) = 0; \ GPIO_BITBAND(CORE_PIN ## P ## _DDRREG , CORE_PIN ## P ## _BIT) = 0; \
}while(0) }while(0)
#define _GET_INPUT(P) ((CORE_PIN ## P ## _DDRREG & CORE_PIN ## P ## _BITMASK) == 0) #define _IS_INPUT(P) ((CORE_PIN ## P ## _DDRREG & CORE_PIN ## P ## _BITMASK) == 0)
#define _GET_OUTPUT(P) ((CORE_PIN ## P ## _DDRREG & CORE_PIN ## P ## _BITMASK) == 0) #define _IS_OUTPUT(P) ((CORE_PIN ## P ## _DDRREG & CORE_PIN ## P ## _BITMASK) == 0)
#define READ(IO) _READ(IO) #define READ(IO) _READ(IO)
@ -80,8 +80,8 @@
#define SET_OUTPUT(IO) _SET_OUTPUT(IO) #define SET_OUTPUT(IO) _SET_OUTPUT(IO)
#define SET_PWM(IO) SET_OUTPUT(IO) #define SET_PWM(IO) SET_OUTPUT(IO)
#define GET_INPUT(IO) _GET_INPUT(IO) #define IS_INPUT(IO) _IS_INPUT(IO)
#define GET_OUTPUT(IO) _GET_OUTPUT(IO) #define IS_OUTPUT(IO) _IS_OUTPUT(IO)
#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)

View file

@ -139,11 +139,11 @@ inline void report_pin_state_extended(pin_t pin, bool ignore, bool extended = fa
#if AVR_AT90USB1286_FAMILY //Teensy IDEs don't know about these pins so must use FASTIO #if AVR_AT90USB1286_FAMILY //Teensy IDEs don't know about these pins so must use FASTIO
if (pin == 46 || pin == 47) { if (pin == 46 || pin == 47) {
if (pin == 46) { if (pin == 46) {
print_input_or_output(GET_OUTPUT(46)); print_input_or_output(IS_OUTPUT(46));
SERIAL_CHAR('0' + READ(46)); SERIAL_CHAR('0' + READ(46));
} }
else if (pin == 47) { else if (pin == 47) {
print_input_or_output(GET_OUTPUT(47)); print_input_or_output(IS_OUTPUT(47));
SERIAL_CHAR('0' + READ(47)); SERIAL_CHAR('0' + READ(47));
} }
} }
@ -195,11 +195,11 @@ inline void report_pin_state_extended(pin_t pin, bool ignore, bool extended = fa
if (pin == 46 || pin == 47) { if (pin == 46 || pin == 47) {
SERIAL_ECHO_SP(12); SERIAL_ECHO_SP(12);
if (pin == 46) { if (pin == 46) {
print_input_or_output(GET_OUTPUT(46)); print_input_or_output(IS_OUTPUT(46));
SERIAL_CHAR('0' + READ(46)); SERIAL_CHAR('0' + READ(46));
} }
else { else {
print_input_or_output(GET_OUTPUT(47)); print_input_or_output(IS_OUTPUT(47));
SERIAL_CHAR('0' + READ(47)); SERIAL_CHAR('0' + READ(47));
} }
} }