функция digitalPinPwmIsOn() теперь возвращает три состояния
This commit is contained in:
parent
fbc87f79b8
commit
b85eef9bfe
@ -98,7 +98,7 @@ static inline __attribute__((always_inline)) bool digitalPinHasPWM(uint8_t p)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// return true if digitalPin configured as pwm
|
// return true if digitalPin configured as pwm
|
||||||
bool digitalPinPwmIsOn(uint8_t digitalPin);
|
int8_t digitalPinPwmIsOn(uint8_t digitalPin);
|
||||||
// determines which timer the pin belongs to
|
// determines which timer the pin belongs to
|
||||||
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber);
|
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber);
|
||||||
// determines which timer channel the pin belongs to
|
// determines which timer channel the pin belongs to
|
||||||
|
|||||||
@ -204,27 +204,27 @@ uint32_t analogInputToChannelNumber(uint32_t PinNumber)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------- PWM ---------------------- //
|
// ---------------------- PWM ---------------------- //
|
||||||
// use only if digitalPinHasPWM() == true
|
// return 1 if digitalPin configured as pwm and enabled,
|
||||||
#define PWM_PIN_TO_PORT_NUMBER(pin) (((pin==10)||(pin==11)||(pin==12)||(pin==13)) ? 1:0)
|
// 0 if pwm on pin is disabled,
|
||||||
|
// -1 if pin doesn't support pwm
|
||||||
// use only if digitalPinHasPWM() == true
|
__attribute__((noinline, section(".ram_text"))) int8_t digitalPinPwmIsOn(uint8_t digitalPin)
|
||||||
// return true if digitalPin configured as pwm
|
|
||||||
__attribute__((noinline, section(".ram_text"))) bool digitalPinPwmIsOn(uint8_t digitalPin)
|
|
||||||
{
|
{
|
||||||
if (digitalPinHasPWM(digitalPin))
|
if (digitalPinHasPWM(digitalPin))
|
||||||
{
|
{
|
||||||
uint8_t config = 0;
|
uint8_t config = 0;
|
||||||
uint8_t pinShift = PIN_MASK_TO_PIN_NUMBER(digitalPinToBitMask(digitalPin));
|
uint8_t pinShift = PIN_MASK_TO_PIN_NUMBER(digitalPinToBitMask(digitalPin));
|
||||||
|
|
||||||
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
|
if ((digitalPin==10)||(digitalPin==11)||(digitalPin==12)||(digitalPin==13))
|
||||||
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
|
|
||||||
else
|
|
||||||
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, pinShift);
|
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, pinShift);
|
||||||
|
else
|
||||||
|
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
|
||||||
|
|
||||||
if (config == 2)
|
if (config == 2)
|
||||||
return true;
|
return 1; // pwm is on
|
||||||
|
else
|
||||||
|
return 0; // pwm is off
|
||||||
}
|
}
|
||||||
return false;
|
return -1; // pin doesn't support pwm
|
||||||
}
|
}
|
||||||
|
|
||||||
// function is used only if digitalPinHasPWM() is true
|
// function is used only if digitalPinHasPWM() is true
|
||||||
|
|||||||
@ -93,7 +93,7 @@ static inline __attribute__((always_inline)) bool digitalPinHasPWM(uint8_t p)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// return true if digitalPin configured as pwm
|
// return true if digitalPin configured as pwm
|
||||||
bool digitalPinPwmIsOn(uint8_t digitalPin);
|
int8_t digitalPinPwmIsOn(uint8_t digitalPin);
|
||||||
// determines which timer the pin belongs to
|
// determines which timer the pin belongs to
|
||||||
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber);
|
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber);
|
||||||
// determines which timer channel the pin belongs to
|
// determines which timer channel the pin belongs to
|
||||||
|
|||||||
@ -167,26 +167,27 @@ uint32_t analogInputToChannelNumber(uint32_t PinNumber)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------- PWM ---------------------- //
|
// ---------------------- PWM ---------------------- //
|
||||||
// use only if digitalPinHasPWM() == true
|
// return 1 if digitalPin configured as pwm and enabled,
|
||||||
#define PWM_PIN_TO_PORT_NUMBER(pin) (((pin==10)||(pin==11)||(pin==12)||(pin==13)) ? 1:0)
|
// 0 if pwm on pin is disabled,
|
||||||
|
// -1 if pin doesn't support pwm
|
||||||
// return true if digitalPin configured as pwm
|
__attribute__((noinline, section(".ram_text"))) int8_t digitalPinPwmIsOn(uint8_t digitalPin)
|
||||||
__attribute__((noinline, section(".ram_text"))) bool digitalPinPwmIsOn(uint8_t digitalPin)
|
|
||||||
{
|
{
|
||||||
if (digitalPinHasPWM(digitalPin))
|
if (digitalPinHasPWM(digitalPin))
|
||||||
{
|
{
|
||||||
uint8_t config = 0;
|
uint8_t config = 0;
|
||||||
uint8_t pinShift = PIN_MASK_TO_PIN_NUMBER(digitalPinToBitMask(digitalPin));
|
uint8_t pinShift = PIN_MASK_TO_PIN_NUMBER(digitalPinToBitMask(digitalPin));
|
||||||
|
|
||||||
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
|
if ((digitalPin==10)||(digitalPin==11)||(digitalPin==12)||(digitalPin==13))
|
||||||
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
|
|
||||||
else
|
|
||||||
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, pinShift);
|
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, pinShift);
|
||||||
|
else
|
||||||
|
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
|
||||||
|
|
||||||
if (config == 2)
|
if (config == 2)
|
||||||
return true;
|
return 1; // pwm is on
|
||||||
|
else
|
||||||
|
return 0; // pwm is off
|
||||||
}
|
}
|
||||||
return false;
|
return -1; // pin doesn't support pwm
|
||||||
}
|
}
|
||||||
|
|
||||||
// function is used only if digitalPinHasPWM() is true
|
// function is used only if digitalPinHasPWM() is true
|
||||||
|
|||||||
@ -123,7 +123,7 @@ static inline __attribute__((always_inline)) bool digitalPinHasPWM(uint8_t p)
|
|||||||
return (p <= P1_15) && ((p & 0xF) < 4);
|
return (p <= P1_15) && ((p & 0xF) < 4);
|
||||||
}
|
}
|
||||||
// return true if digitalPin configured as pwm
|
// return true if digitalPin configured as pwm
|
||||||
bool digitalPinPwmIsOn(uint8_t digitalPin);
|
int8_t digitalPinPwmIsOn(uint8_t digitalPin);
|
||||||
// determines which timer the pin belongs to
|
// determines which timer the pin belongs to
|
||||||
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber);
|
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber);
|
||||||
// determines which timer channel the pin belongs to
|
// determines which timer channel the pin belongs to
|
||||||
|
|||||||
@ -105,27 +105,25 @@ uint32_t analogInputToChannelNumber(uint32_t PinNumber)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------- PWM ---------------------- //
|
// ---------------------- PWM ---------------------- //
|
||||||
// use only if digitalPinHasPWM() == true
|
// return 1 if digitalPin configured as pwm and enabled,
|
||||||
#define PWM_PIN_TO_PORT_NUMBER(pin) (((pin) & 16) ? 1 : 0)
|
// 0 if pwm on pin is disabled,
|
||||||
|
// -1 if pin doesn't support pwm
|
||||||
// use only if digitalPinHasPWM() == true
|
__attribute__((noinline, section(".ram_text"))) int8_t digitalPinPwmIsOn(uint8_t digitalPin)
|
||||||
// return true if digitalPin configured as pwm
|
|
||||||
__attribute__((noinline, section(".ram_text"))) bool digitalPinPwmIsOn(uint8_t digitalPin)
|
|
||||||
{
|
{
|
||||||
if (digitalPinHasPWM(digitalPin))
|
if (digitalPinHasPWM(digitalPin))
|
||||||
{
|
{
|
||||||
uint8_t config = 0;
|
uint8_t config = 0;
|
||||||
uint8_t pinShift = digitalPin & 0x3;
|
if ((digitalPin & 16) == 0)
|
||||||
|
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, (digitalPin & 0x3));
|
||||||
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
|
|
||||||
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
|
|
||||||
else
|
else
|
||||||
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, pinShift);
|
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, (digitalPin & 0x3));
|
||||||
|
|
||||||
if (config == 2)
|
if (config == 2)
|
||||||
return true;
|
return 1; // pwm is on
|
||||||
|
else
|
||||||
|
return 0; // pwm is off
|
||||||
}
|
}
|
||||||
return false;
|
return -1; // pin doesn't support pwm
|
||||||
}
|
}
|
||||||
|
|
||||||
// function is used only if digitalPinHasPWM() is true
|
// function is used only if digitalPinHasPWM() is true
|
||||||
|
|||||||
@ -136,7 +136,7 @@ static inline __attribute__((always_inline)) bool digitalPinHasPWM(uint8_t p)
|
|||||||
return (p < 32) && ((p & 0xF) < 4);
|
return (p < 32) && ((p & 0xF) < 4);
|
||||||
}
|
}
|
||||||
// return true if digitalPin configured as pwm
|
// return true if digitalPin configured as pwm
|
||||||
bool digitalPinPwmIsOn(uint8_t digitalPin);
|
int8_t digitalPinPwmIsOn(uint8_t digitalPin);
|
||||||
// determines which timer the pin belongs to
|
// determines which timer the pin belongs to
|
||||||
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber);
|
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber);
|
||||||
// determines which timer channel the pin belongs to
|
// determines which timer channel the pin belongs to
|
||||||
|
|||||||
@ -101,27 +101,25 @@ uint32_t analogInputToChannelNumber(uint32_t PinNumber)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------- PWM ---------------------- //
|
// ---------------------- PWM ---------------------- //
|
||||||
// use only if digitalPinHasPWM() == true
|
// return 1 if digitalPin configured as pwm and enabled,
|
||||||
#define PWM_PIN_TO_PORT_NUMBER(pin) (((pin) & 16) ? 1 : 0)
|
// 0 if pwm on pin is disabled,
|
||||||
|
// -1 if pin doesn't support pwm
|
||||||
// use only if digitalPinHasPWM() == true
|
__attribute__((noinline, section(".ram_text"))) int8_t digitalPinPwmIsOn(uint8_t digitalPin)
|
||||||
// return true if digitalPin configured as pwm
|
|
||||||
__attribute__((noinline, section(".ram_text"))) bool digitalPinPwmIsOn(uint8_t digitalPin)
|
|
||||||
{
|
{
|
||||||
if (digitalPinHasPWM(digitalPin))
|
if (digitalPinHasPWM(digitalPin))
|
||||||
{
|
{
|
||||||
uint8_t config = 0;
|
uint8_t config = 0;
|
||||||
uint8_t pinShift = digitalPin & 3;
|
if ((digitalPin & 16) == 0)
|
||||||
|
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, (digitalPin & 3));
|
||||||
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
|
|
||||||
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
|
|
||||||
else
|
else
|
||||||
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, pinShift);
|
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, (digitalPin & 3));
|
||||||
|
|
||||||
if (config == 2)
|
if (config == 2)
|
||||||
return true;
|
return 1; // pwm is on
|
||||||
|
else
|
||||||
|
return 0; // pwm is off
|
||||||
}
|
}
|
||||||
return false;
|
return -1; // pin doesn't support pwm
|
||||||
}
|
}
|
||||||
|
|
||||||
// function is used only if digitalPinHasPWM() is true
|
// function is used only if digitalPinHasPWM() is true
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user