[Cryptech-Commits] [sw/stm32] 01/02: Change gpio setups from macros to inline functions.
git at cryptech.is
git at cryptech.is
Tue Jun 14 16:09:53 UTC 2016
This is an automated email from the git hooks/post-receive script.
paul at psgd.org pushed a commit to branch master
in repository sw/stm32.
commit 91db5e0c49b77c7a21a3b6d1c70b7128dcfa55a9
Author: Paul Selkirk <paul at psgd.org>
AuthorDate: Mon Jun 13 22:38:00 2016 -0400
Change gpio setups from macros to inline functions.
---
stm-init.c | 4 +---
stm-init.h | 43 ++++++++++++++++++++++++++-----------------
2 files changed, 27 insertions(+), 20 deletions(-)
diff --git a/stm-init.c b/stm-init.c
index d2d8d65..0016e13 100644
--- a/stm-init.c
+++ b/stm-init.c
@@ -157,8 +157,6 @@ static void MX_USART2_UART_Init(void)
/* Configure General Purpose Input/Output pins */
static void MX_GPIO_Init(void)
{
- GPIO_InitTypeDef GPIO_InitStruct;
-
/* GPIO Ports Clock Enable */
LED_CLK_ENABLE();
@@ -217,7 +215,7 @@ void MX_I2C2_Init(void)
hi2c_rtc.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
if (HAL_I2C_Init(&hi2c_rtc) != HAL_OK) {
- Error_Handler();
+ Error_Handler();
}
}
#endif
diff --git a/stm-init.h b/stm-init.h
index 252485d..2c3ec99 100644
--- a/stm-init.h
+++ b/stm-init.h
@@ -37,24 +37,33 @@
#include "stm32f4xx_hal.h"
-/* Macros used to make GPIO pin setup (in stm-init.c) easier */
-#define gpio_output(output_port, output_pins, output_level) \
- /* Configure GPIO pin Output Level */ \
- HAL_GPIO_WritePin(output_port, output_pins, output_level); \
- /* Configure pin as output */ \
- GPIO_InitStruct.Pin = output_pins; \
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; \
- GPIO_InitStruct.Pull = GPIO_NOPULL; \
- GPIO_InitStruct.Speed = GPIO_SPEED_LOW; \
- HAL_GPIO_Init(output_port, &GPIO_InitStruct)
-
-#define gpio_input(input_port, input_pin, input_pull) \
- GPIO_InitStruct.Pin = input_pin; \
- GPIO_InitStruct.Mode = GPIO_MODE_INPUT; \
- GPIO_InitStruct.Pull = input_pull; \
- GPIO_InitStruct.Speed = GPIO_SPEED_LOW; \
- HAL_GPIO_Init(input_port, &GPIO_InitStruct)
+/* Functions used to make GPIO pin setup (in stm-init.c) easier */
+inline void gpio_output(GPIO_TypeDef* output_port, uint16_t output_pins, GPIO_PinState output_level)
+{
+ GPIO_InitTypeDef GPIO_InitStruct;
+
+ /* Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(output_port, output_pins, output_level);
+
+ /* Configure pin as output */
+ GPIO_InitStruct.Pin = output_pins;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
+ HAL_GPIO_Init(output_port, &GPIO_InitStruct);
+}
+
+inline void gpio_input(GPIO_TypeDef* input_port, uint16_t input_pin, GPIO_PinState input_pull)
+{
+ GPIO_InitTypeDef GPIO_InitStruct;
+
+ GPIO_InitStruct.Pin = input_pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
+ GPIO_InitStruct.Pull = input_pull;
+ GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
+ HAL_GPIO_Init(input_port, &GPIO_InitStruct);
+}
extern void stm_init(void);
extern void Error_Handler(void);
More information about the Commits
mailing list