-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpio.h
59 lines (41 loc) · 1.13 KB
/
gpio.h
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
56
57
58
59
#ifndef gpio
#define gpio
#include "stm32f051x8.h"
// MODER REGISTER
#define input_mode ((uint32_t) 0x00)
#define output_mode ((uint32_t) 0x01)
#define alt_func ((uint32_t) 0x02)
#define analog_mode ((uint32_t) 0x03)
// OTYPER REGISTER
#define pp ((uint32_t) 0x00)
#define od ((uint32_t) 0x01)
//PUPDR
#define nopupd ((uint32_t) 0x00)
#define pu ((uint32_t) 0x01)
#define pd ((uint32_t) 0x02)
//OSPEEDDR
#define ls ((uint32_t) 0x01)
#define ms ((uint32_t) 0x02)
#define hs ((uint32_t) 0x03)
typedef struct
{
GPIO_TypeDef *gp;
uint32_t pin;
uint32_t mode;
uint32_t type;
uint32_t speed;
uint32_t af;
uint32_t res;
}GPIO_TYPE;
typedef enum{
RISING_EDGE,
FALLING_EDGE,
RISING_FALLING_EDGE
}edge_select;
void gpio_init(GPIO_TYPE gpio_type);
void gpio_write(GPIO_TypeDef *gp, uint32_t pinNumber, uint8_t state);
void gpio_toggle(GPIO_TypeDef *gp, uint32_t pinNumber);
void configure_gpio_interrupt(GPIO_TypeDef*gp, uint32_t pinNumber, edge_select edge);
void enable_gpio_interrupt(uint32_t pinNumber,IRQn_Type irqNumber);
void clear_gpio_interrupt (uint32_t pinNumber);
#endif