Проверка в analogWrite(), добавление экземпляров для Wire, SPI, Serial #21

Merged
klassents merged 12 commits from v0.5.1_editing into v0.5.1 2025-05-27 12:35:38 +03:00
8 changed files with 48 additions and 51 deletions
Showing only changes of commit b85eef9bfe - Show all commits

View File

@ -98,7 +98,7 @@ static inline __attribute__((always_inline)) bool digitalPinHasPWM(uint8_t p)
return false;
}
// 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
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber);
// determines which timer channel the pin belongs to

View File

@ -204,27 +204,27 @@ uint32_t analogInputToChannelNumber(uint32_t PinNumber)
}
// ---------------------- PWM ---------------------- //
// use only if digitalPinHasPWM() == true
#define PWM_PIN_TO_PORT_NUMBER(pin) (((pin==10)||(pin==11)||(pin==12)||(pin==13)) ? 1:0)
// use only if digitalPinHasPWM() == true
// return true if digitalPin configured as pwm
__attribute__((noinline, section(".ram_text"))) bool digitalPinPwmIsOn(uint8_t digitalPin)
// return 1 if digitalPin configured as pwm and enabled,
// 0 if pwm on pin is disabled,
// -1 if pin doesn't support pwm
__attribute__((noinline, section(".ram_text"))) int8_t digitalPinPwmIsOn(uint8_t digitalPin)
{
if (digitalPinHasPWM(digitalPin))
{
uint8_t config = 0;
uint8_t pinShift = PIN_MASK_TO_PIN_NUMBER(digitalPinToBitMask(digitalPin));
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
else
if ((digitalPin==10)||(digitalPin==11)||(digitalPin==12)||(digitalPin==13))
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, pinShift);
else
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
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

View File

@ -93,7 +93,7 @@ static inline __attribute__((always_inline)) bool digitalPinHasPWM(uint8_t p)
return false;
}
// 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
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber);
// determines which timer channel the pin belongs to

View File

@ -167,26 +167,27 @@ uint32_t analogInputToChannelNumber(uint32_t PinNumber)
}
// ---------------------- PWM ---------------------- //
// use only if digitalPinHasPWM() == true
#define PWM_PIN_TO_PORT_NUMBER(pin) (((pin==10)||(pin==11)||(pin==12)||(pin==13)) ? 1:0)
// return true if digitalPin configured as pwm
__attribute__((noinline, section(".ram_text"))) bool digitalPinPwmIsOn(uint8_t digitalPin)
// return 1 if digitalPin configured as pwm and enabled,
// 0 if pwm on pin is disabled,
// -1 if pin doesn't support pwm
__attribute__((noinline, section(".ram_text"))) int8_t digitalPinPwmIsOn(uint8_t digitalPin)
{
if (digitalPinHasPWM(digitalPin))
{
uint8_t config = 0;
uint8_t pinShift = PIN_MASK_TO_PIN_NUMBER(digitalPinToBitMask(digitalPin));
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
else
if ((digitalPin==10)||(digitalPin==11)||(digitalPin==12)||(digitalPin==13))
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, pinShift);
else
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
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

View File

@ -123,7 +123,7 @@ static inline __attribute__((always_inline)) bool digitalPinHasPWM(uint8_t p)
return (p <= P1_15) && ((p & 0xF) < 4);
}
// 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
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber);
// determines which timer channel the pin belongs to

View File

@ -105,27 +105,25 @@ uint32_t analogInputToChannelNumber(uint32_t PinNumber)
}
// ---------------------- PWM ---------------------- //
// use only if digitalPinHasPWM() == true
#define PWM_PIN_TO_PORT_NUMBER(pin) (((pin) & 16) ? 1 : 0)
// use only if digitalPinHasPWM() == true
// return true if digitalPin configured as pwm
__attribute__((noinline, section(".ram_text"))) bool digitalPinPwmIsOn(uint8_t digitalPin)
// return 1 if digitalPin configured as pwm and enabled,
// 0 if pwm on pin is disabled,
// -1 if pin doesn't support pwm
__attribute__((noinline, section(".ram_text"))) int8_t digitalPinPwmIsOn(uint8_t digitalPin)
{
if (digitalPinHasPWM(digitalPin))
{
uint8_t config = 0;
uint8_t pinShift = digitalPin & 0x3;
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
if ((digitalPin & 16) == 0)
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, (digitalPin & 0x3));
else
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, pinShift);
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, (digitalPin & 0x3));
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

View File

@ -136,7 +136,7 @@ static inline __attribute__((always_inline)) bool digitalPinHasPWM(uint8_t p)
return (p < 32) && ((p & 0xF) < 4);
}
// 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
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber);
// determines which timer channel the pin belongs to

View File

@ -101,27 +101,25 @@ uint32_t analogInputToChannelNumber(uint32_t PinNumber)
}
// ---------------------- PWM ---------------------- //
// use only if digitalPinHasPWM() == true
#define PWM_PIN_TO_PORT_NUMBER(pin) (((pin) & 16) ? 1 : 0)
// use only if digitalPinHasPWM() == true
// return true if digitalPin configured as pwm
__attribute__((noinline, section(".ram_text"))) bool digitalPinPwmIsOn(uint8_t digitalPin)
// return 1 if digitalPin configured as pwm and enabled,
// 0 if pwm on pin is disabled,
// -1 if pin doesn't support pwm
__attribute__((noinline, section(".ram_text"))) int8_t digitalPinPwmIsOn(uint8_t digitalPin)
{
if (digitalPinHasPWM(digitalPin))
{
uint8_t config = 0;
uint8_t pinShift = digitalPin & 3;
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
if ((digitalPin & 16) == 0)
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, (digitalPin & 3));
else
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, pinShift);
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, (digitalPin & 3));
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