ускорение работы digital функций
This commit is contained in:
parent
663ce5bf55
commit
6ced7bdad1
@ -45,7 +45,7 @@ __attribute__((noinline, section(".ram_text"))) HAL_PinsTypeDef digitalPinToBitM
|
|||||||
if (digitalPinNumber >= PINS_COMMON_QTY)
|
if (digitalPinNumber >= PINS_COMMON_QTY)
|
||||||
{
|
{
|
||||||
ErrorMsgHandler("digitalPinToBitMask(): pin number exceeds the total number of pins");
|
ErrorMsgHandler("digitalPinToBitMask(): pin number exceeds the total number of pins");
|
||||||
return NC;
|
return NOT_A_PIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (digitalPinNumber >= P2_6)
|
if (digitalPinNumber >= P2_6)
|
||||||
|
|||||||
@ -78,6 +78,9 @@ typedef enum
|
|||||||
PINS_COMMON_QTY, // 40
|
PINS_COMMON_QTY, // 40
|
||||||
} DigitalPinsTypeDef;
|
} DigitalPinsTypeDef;
|
||||||
|
|
||||||
|
// total number of pins available for initialization
|
||||||
|
#define pinCommonQty() (PINS_COMMON_QTY)
|
||||||
|
|
||||||
// analog pins
|
// analog pins
|
||||||
#define PIN_A0 (P1_5)
|
#define PIN_A0 (P1_5)
|
||||||
#define PIN_A1 (P1_7)
|
#define PIN_A1 (P1_7)
|
||||||
@ -108,11 +111,6 @@ static const uint8_t A7 = PIN_A7;
|
|||||||
GPIO_TypeDef* digitalPinToPort(uint32_t digPinNumber);
|
GPIO_TypeDef* digitalPinToPort(uint32_t digPinNumber);
|
||||||
// determines the pin address inside the port by the board pin number
|
// determines the pin address inside the port by the board pin number
|
||||||
HAL_PinsTypeDef digitalPinToBitMask(uint32_t digitalPinNumber);
|
HAL_PinsTypeDef digitalPinToBitMask(uint32_t digitalPinNumber);
|
||||||
// total number of pins available for initialization
|
|
||||||
static inline uint16_t pinCommonQty(void)
|
|
||||||
{
|
|
||||||
return (uint16_t)PINS_COMMON_QTY;
|
|
||||||
}
|
|
||||||
// the function returns a reference to the OUTPUT address of the GPIO register
|
// the function returns a reference to the OUTPUT address of the GPIO register
|
||||||
volatile uint32_t* portOutputRegister(GPIO_TypeDef* GPIO_x);
|
volatile uint32_t* portOutputRegister(GPIO_TypeDef* GPIO_x);
|
||||||
// the function returns a reference to the STATE address of the GPIO register
|
// the function returns a reference to the STATE address of the GPIO register
|
||||||
@ -132,8 +130,12 @@ uint32_t analogInputToChannelNumber(uint32_t PinNumber);
|
|||||||
|
|
||||||
// PWM
|
// PWM
|
||||||
#define PWM_FREQUENCY_MAX 1000000 // Hz
|
#define PWM_FREQUENCY_MAX 1000000 // Hz
|
||||||
bool digitalPinHasPWM(uint8_t p);
|
static inline __attribute__((always_inline)) bool digitalPinHasPWM(uint8_t p)
|
||||||
bool digitalPinPwmIsOn(uint8_t digitalPin); // use only if digitalPinHasPWM() == true
|
{
|
||||||
|
return (p < 32) && ((p & 0xF) < 4);
|
||||||
|
}
|
||||||
|
// return true if digitalPin configured as pwm
|
||||||
|
bool 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
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
* @return The address of the port corresponding to the board pin number. Can return 0 if the pin not exists
|
* @return The address of the port corresponding to the board pin number. Can return 0 if the pin not exists
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GPIO_TypeDef *digitalPinToPort(uint32_t digitalPinNumber)
|
__attribute__((noinline, section(".ram_text"))) GPIO_TypeDef *digitalPinToPort(uint32_t digitalPinNumber)
|
||||||
{
|
{
|
||||||
GPIO_TypeDef* port = NULL;
|
GPIO_TypeDef* port = NULL;
|
||||||
if (digitalPinNumber < pinCommonQty())
|
if (digitalPinNumber < pinCommonQty())
|
||||||
@ -39,12 +39,12 @@ GPIO_TypeDef *digitalPinToPort(uint32_t digitalPinNumber)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// determines the pin address inside the port by the board pin number
|
// determines the pin address inside the port by the board pin number
|
||||||
HAL_PinsTypeDef digitalPinToBitMask(uint32_t digitalPinNumber)
|
__attribute__((noinline, section(".ram_text"))) HAL_PinsTypeDef digitalPinToBitMask(uint32_t digitalPinNumber)
|
||||||
{
|
{
|
||||||
if (digitalPinNumber >= pinCommonQty())
|
if (digitalPinNumber >= pinCommonQty())
|
||||||
{
|
{
|
||||||
ErrorMsgHandler("digitalPinToBitMask(): pin number exceeds the total number of pins");
|
ErrorMsgHandler("digitalPinToBitMask(): pin number exceeds the total number of pins");
|
||||||
return NC;
|
return NOT_A_PIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (HAL_PinsTypeDef)(1 << (digitalPinNumber & 0xF));
|
return (HAL_PinsTypeDef)(1 << (digitalPinNumber & 0xF));
|
||||||
@ -108,25 +108,22 @@ uint32_t analogInputToChannelNumber(uint32_t PinNumber)
|
|||||||
// return true if digitalPin configured as pwm
|
// return true if digitalPin configured as pwm
|
||||||
bool digitalPinPwmIsOn(uint8_t digitalPin)
|
bool digitalPinPwmIsOn(uint8_t digitalPin)
|
||||||
{
|
{
|
||||||
uint8_t config = 0;
|
if (digitalPinHasPWM(digitalPin))
|
||||||
uint8_t pinShift = digitalPin & 3;
|
{
|
||||||
|
uint8_t config = 0;
|
||||||
|
uint8_t pinShift = digitalPin & 3;
|
||||||
|
|
||||||
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
|
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
|
||||||
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
|
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, pinShift);
|
||||||
|
|
||||||
if (config == 2)
|
if (config == 2)
|
||||||
return true;
|
return true;
|
||||||
else
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool digitalPinHasPWM(uint8_t p)
|
|
||||||
{
|
|
||||||
return (p < 32) && ((p & 0xF) < 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
// function is used only if digitalPinHasPWM() is true
|
// function is used only if digitalPinHasPWM() is true
|
||||||
TIMER32_TypeDef *pwmPinToTimer(uint32_t digPinNumber)
|
TIMER32_TypeDef *pwmPinToTimer(uint32_t digPinNumber)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user