ускорение работы функций digital
This commit is contained in:
parent
ca11ae5dbd
commit
663ce5bf55
@ -71,6 +71,8 @@ typedef enum
|
|||||||
P2_7, // 33
|
P2_7, // 33
|
||||||
PINS_COMMON_QTY, // 34
|
PINS_COMMON_QTY, // 34
|
||||||
} 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)
|
||||||
@ -96,11 +98,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
|
||||||
@ -120,8 +117,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 <= P1_15) && ((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)
|
||||||
{
|
{
|
||||||
if (digitalPinNumber >= pinCommonQty())
|
if (digitalPinNumber >= pinCommonQty())
|
||||||
{
|
{
|
||||||
@ -40,7 +40,7 @@ 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 >= PINS_COMMON_QTY)
|
if (digitalPinNumber >= PINS_COMMON_QTY)
|
||||||
{
|
{
|
||||||
@ -112,25 +112,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 & 0x3;
|
{
|
||||||
|
uint8_t config = 0;
|
||||||
|
uint8_t pinShift = digitalPin & 0x3;
|
||||||
|
|
||||||
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 digitalPin)
|
|
||||||
{
|
|
||||||
return (digitalPin <= P1_15) && ((digitalPin & 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