добавлена проверка - не превышает ли номер вывода из аргумента функции общее кол-во выводов
This commit is contained in:
1 parent
5b2e2eb1d5
commit
fbaa4b931a
11 files changed
+171
-96
No files matched your search
@@ -67,7 +67,13 @@ const HAL_PinsTypeDef digitalPinToGpioPinArray[] =
|
||||
// determines the address of the port by the board pin number to which this pin belongs on the MCU
|
||||
GPIO_TypeDef* digitalPinToPort(uint32_t digPinNumber)
|
||||
{
|
||||
GPIO_TypeDef* gpioNum = 0;
|
||||
GPIO_TypeDef* gpioNum = NULL;
|
||||
if (digPinNumber >= pinCommonQty())
|
||||
{
|
||||
ErrorMsgHandler("digitalPinToPort(): pin number exceeds the total number of pins");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// port 2 - led (22)
|
||||
if (digPinNumber == LED_BUILTIN)
|
||||
gpioNum = GPIO_2;
|
||||
@@ -85,20 +91,21 @@ GPIO_TypeDef* digitalPinToPort(uint32_t digPinNumber)
|
||||
// determines the pin address inside the port by the board pin number
|
||||
HAL_PinsTypeDef digitalPinToBitMask(uint32_t digPinNumber)
|
||||
{
|
||||
if (digPinNumber < pinCommonQty())
|
||||
if (digPinNumber >= pinCommonQty())
|
||||
{
|
||||
HAL_PinsTypeDef mask;
|
||||
// if spi is on default pin NSS_IN is needed for spi, board pin is replaced to pin NSS_OUT
|
||||
if ((digPinNumber == 10) && spi1NssPinIsBlocked)
|
||||
mask = SPI1_NSS_OUT_PIN;
|
||||
else if ((digPinNumber == 9) && spi0NssPinIsBlocked)
|
||||
mask = SPI0_NSS_OUT_PIN;
|
||||
else
|
||||
mask = digitalPinToGpioPinArray[digPinNumber];
|
||||
return mask;
|
||||
ErrorMsgHandler("digitalPinToBitMask(): pin number exceeds the total number of pins");
|
||||
return NC;
|
||||
}
|
||||
else
|
||||
return NC;
|
||||
|
||||
HAL_PinsTypeDef mask;
|
||||
// if spi is on default pin NSS_IN is needed for spi, board pin is replaced to pin NSS_OUT
|
||||
if ((digPinNumber == 10) && spi1NssPinIsBlocked)
|
||||
mask = SPI1_NSS_OUT_PIN;
|
||||
else if ((digPinNumber == 9) && spi0NssPinIsBlocked)
|
||||
mask = SPI0_NSS_OUT_PIN;
|
||||
else
|
||||
mask = digitalPinToGpioPinArray[digPinNumber];
|
||||
return mask;
|
||||
}
|
||||
|
||||
uint16_t pinCommonQty(void)
|
||||
|
||||
@@ -65,7 +65,13 @@ const HAL_PinsTypeDef digitalPinToGpioPinArray[] =
|
||||
// etermines the address of the port by the board pin number to which this pin belongs on the MCU
|
||||
GPIO_TypeDef* digitalPinToPort(uint32_t digPinNumber)
|
||||
{
|
||||
GPIO_TypeDef* gpioNum = 0;
|
||||
GPIO_TypeDef* gpioNum = NULL;
|
||||
if (digPinNumber >= pinCommonQty())
|
||||
{
|
||||
ErrorMsgHandler("digitalPinToPort(): pin number exceeds the total number of pins");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// port 2 - led and button
|
||||
if (digPinNumber == LED_BUILTIN || digPinNumber == BTN_BUILTIN)
|
||||
gpioNum = GPIO_2;
|
||||
@@ -83,20 +89,21 @@ GPIO_TypeDef* digitalPinToPort(uint32_t digPinNumber)
|
||||
// determines the pin address inside the port by the board pin number
|
||||
HAL_PinsTypeDef digitalPinToBitMask(uint32_t digPinNumber)
|
||||
{
|
||||
if (digPinNumber < pinCommonQty())
|
||||
if (digPinNumber >= pinCommonQty())
|
||||
{
|
||||
HAL_PinsTypeDef mask;
|
||||
// if spi is on default pin NSS_IN is needed for spi, board pin is replaced to pin NSS_OUT
|
||||
if ((digPinNumber == 10) && spi1NssPinIsBlocked)
|
||||
mask = SPI1_NSS_OUT_PIN;
|
||||
else if ((digPinNumber == 9) && spi0NssPinIsBlocked)
|
||||
mask = SPI0_NSS_OUT_PIN;
|
||||
else
|
||||
mask = digitalPinToGpioPinArray[digPinNumber];
|
||||
return mask;
|
||||
ErrorMsgHandler("digitalPinToBitMask(): pin number exceeds the total number of pins");
|
||||
return NC;
|
||||
}
|
||||
else
|
||||
return NC;
|
||||
|
||||
HAL_PinsTypeDef mask;
|
||||
// if spi is on default pin NSS_IN is needed for spi, board pin is replaced to pin NSS_OUT
|
||||
if ((digPinNumber == 10) && spi1NssPinIsBlocked)
|
||||
mask = SPI1_NSS_OUT_PIN;
|
||||
else if ((digPinNumber == 9) && spi0NssPinIsBlocked)
|
||||
mask = SPI0_NSS_OUT_PIN;
|
||||
else
|
||||
mask = digitalPinToGpioPinArray[digPinNumber];
|
||||
return mask;
|
||||
}
|
||||
|
||||
uint16_t pinCommonQty(void)
|
||||
|
||||
@@ -95,13 +95,7 @@ static const uint8_t A7 = PIN_A7;
|
||||
// determines the address of the port by the board pin number to which this pin belongs on the MCU
|
||||
GPIO_TypeDef* digitalPinToPort(uint32_t digPinNumber);
|
||||
// determines the pin address inside the port by the board pin number
|
||||
static inline HAL_PinsTypeDef digitalPinToBitMask(uint32_t digitalPinNumber)
|
||||
{
|
||||
if (digitalPinNumber >= P2_6)
|
||||
return (HAL_PinsTypeDef)(1 << ((digitalPinNumber+6) & 0xF));
|
||||
else
|
||||
return (HAL_PinsTypeDef)(1 << (digitalPinNumber & 0xF));
|
||||
}
|
||||
HAL_PinsTypeDef digitalPinToBitMask(uint32_t digitalPinNumber);
|
||||
// total number of pins available for initialization
|
||||
static inline uint16_t pinCommonQty(void)
|
||||
{
|
||||
|
||||
@@ -23,6 +23,12 @@
|
||||
|
||||
GPIO_TypeDef *digitalPinToPort(uint32_t digitalPinNumber)
|
||||
{
|
||||
if (digitalPinNumber >= pinCommonQty())
|
||||
{
|
||||
ErrorMsgHandler("digitalPinToPort(): pin number exceeds the total number of pins");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (digitalPinNumber <= P0_15)
|
||||
return GPIO_0;
|
||||
else if ((digitalPinNumber >= P1_0) && (digitalPinNumber <= P1_15))
|
||||
@@ -33,6 +39,21 @@ GPIO_TypeDef *digitalPinToPort(uint32_t digitalPinNumber)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// determines the pin address inside the port by the board pin number
|
||||
HAL_PinsTypeDef digitalPinToBitMask(uint32_t digitalPinNumber)
|
||||
{
|
||||
if (digitalPinNumber >= PINS_COMMON_QTY)
|
||||
{
|
||||
ErrorMsgHandler("digitalPinToBitMask(): pin number exceeds the total number of pins");
|
||||
return NC;
|
||||
}
|
||||
|
||||
if (digitalPinNumber >= P2_6)
|
||||
return (HAL_PinsTypeDef)(1 << ((digitalPinNumber+6) & 0xF));
|
||||
else
|
||||
return (HAL_PinsTypeDef)(1 << (digitalPinNumber & 0xF));
|
||||
}
|
||||
|
||||
// the function returns a reference to the OUTPUT address of the GPIO register
|
||||
volatile uint32_t *portOutputRegister(GPIO_TypeDef *GPIO_x)
|
||||
{
|
||||
|
||||
@@ -107,10 +107,7 @@ static const uint8_t A7 = PIN_A7;
|
||||
// determines the address of the port by the board pin number to which this pin belongs on the MCU
|
||||
GPIO_TypeDef* digitalPinToPort(uint32_t digPinNumber);
|
||||
// determines the pin address inside the port by the board pin number
|
||||
static inline HAL_PinsTypeDef digitalPinToBitMask(uint32_t digitalPinNumber)
|
||||
{
|
||||
return (HAL_PinsTypeDef)(1 << (digitalPinNumber & 0xF));
|
||||
}
|
||||
HAL_PinsTypeDef digitalPinToBitMask(uint32_t digitalPinNumber);
|
||||
// total number of pins available for initialization
|
||||
static inline uint16_t pinCommonQty(void)
|
||||
{
|
||||
|
||||
+20
-11
@@ -23,22 +23,31 @@
|
||||
|
||||
GPIO_TypeDef *digitalPinToPort(uint32_t digitalPinNumber)
|
||||
{
|
||||
if (digitalPinNumber < 16u)
|
||||
GPIO_TypeDef* port = NULL;
|
||||
if (digitalPinNumber < pinCommonQty())
|
||||
{
|
||||
return GPIO_0;
|
||||
}
|
||||
else if ((digitalPinNumber >= 16u) && (digitalPinNumber < 32u))
|
||||
{
|
||||
return GPIO_1;
|
||||
}
|
||||
else if ((digitalPinNumber >= 32u) && (digitalPinNumber < 40u))
|
||||
{
|
||||
return GPIO_2;
|
||||
if (digitalPinNumber < 16u)
|
||||
port = GPIO_0;
|
||||
else if ((digitalPinNumber >= 16u) && (digitalPinNumber < 32u))
|
||||
port = GPIO_1;
|
||||
else if ((digitalPinNumber >= 32u) && (digitalPinNumber < 40u))
|
||||
port = GPIO_2;
|
||||
}
|
||||
else
|
||||
ErrorMsgHandler("digitalPinToPort(): pin number exceeds the total number of pins");
|
||||
return port;
|
||||
}
|
||||
|
||||
// determines the pin address inside the port by the board pin number
|
||||
HAL_PinsTypeDef digitalPinToBitMask(uint32_t digitalPinNumber)
|
||||
{
|
||||
if (digitalPinNumber >= pinCommonQty())
|
||||
{
|
||||
return NULL;
|
||||
ErrorMsgHandler("digitalPinToBitMask(): pin number exceeds the total number of pins");
|
||||
return NC;
|
||||
}
|
||||
|
||||
return (HAL_PinsTypeDef)(1 << (digitalPinNumber & 0xF));
|
||||
}
|
||||
|
||||
// the function returns a reference to the OUTPUT address of the GPIO register
|
||||
|
||||
Reference in new issue
Block a user