-
Notifications
You must be signed in to change notification settings - Fork 1
/
hw_gpio.c
57 lines (50 loc) · 1.7 KB
/
hw_gpio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
******************************************************************************
* @file hw_gpio.c
* @author Fahad Mirza (fahadmirza8@gmail.com)
* @brief GPIO interface on top of HAL GPIO interface
******************************************************************************
* /\ /\
* { `---' }
* { O O }
* ~~> V <~~
* \ \|/ /
* `-----'____
* / \ \_
* { }\ )_\_ _
* | \_/ |/ / \_\_/ )
* \__/ /(_/ \__/
* (__/
******************************************************************************
*/
#include <stdint.h>
#include "stm32f4xx_hal.h"
#include "hw_gpio.h"
/* Exported functions -------------------------------------------------------*/
/**
* @brief Initialize GPIO
* @param port: GPIOx
* GPIO_Pin: GPIO_Pin_x
* initStruct: GPIO_InitTypeDef pointer
* @retval None
*/
void HW_GPIO_Init(GPIO_TypeDef *port, uint16_t GPIO_Pin, GPIO_InitTypeDef *initStruct)
{
/* Check the parameters */
assert_param(IS_GPIO_MODE(GPIO_Init->Mode));
assert_param(IS_GPIO_PULL(GPIO_Init->Pull));
assert_param(IS_GPIO_PIN(GPIO_Pin));
// Enable the corresponding PORT clock
RCC_GPIO_CLK_ENABLE((uint32_t)port);
uint32_t pinPos = 1;
while (GPIO_Pin != 0)
{
if (GPIO_Pin & 0x1)
{
initStruct->Pin = pinPos;
HAL_GPIO_Init(port, initStruct);
}
pinPos++;
GPIO_Pin = GPIO_Pin >> 1;
}
}