-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGPIO_control.c
executable file
·72 lines (52 loc) · 2.45 KB
/
GPIO_control.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <GPIO_control.h>
uint8_t leer_entrada(Entrada entrada) {
uint8_t state = GPIO_ReadInputDataBit(entrada.port, entrada.pin);
return state;
}
void escribir_salida(Salida salida, uint8_t state) {
if (!state) GPIO_ResetBits(salida.port, salida.pin);
else GPIO_SetBits(salida.port, salida.pin);
// Si state es 0, apaga
// Cualquier otro valor, prende
}
void conf_in(Entrada entrada, GPIOPuPd_TypeDef PuPd) {
GPIO_InitTypeDef GPIO_InitStructure; //Estructura de configuracion
RCC_AHB1PeriphClockCmd(entrada.periferico, ENABLE); //Habilitacion de la senal de
//reloj para el periferico GPIOD
//Enmascaramos los pines que usaremos
GPIO_InitStructure.GPIO_Pin = entrada.pin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //Los pines seleccionados como salida
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //Tipo de salida como push pull
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //Velocidad del clock para el GPIO
GPIO_InitStructure.GPIO_PuPd = PuPd; //Con pull downs
GPIO_Init(entrada.port, &GPIO_InitStructure); //Se aplica la configuracion definidas anteriormente
}
void conf_out(Salida salida) {
GPIO_InitTypeDef GPIO_InitStructure; //Estructura de configuracion
RCC_AHB1PeriphClockCmd(salida.periferico, ENABLE); //Habilitacion de la senal de
//reloj para el periferico GPIOD
//Enmascaramos los pines que usaremos
GPIO_InitStructure.GPIO_Pin = salida.pin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //Los pines seleccionados como salida
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //Tipo de salida como push pull
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //Velocidad del clock para el GPIO
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //Con pull downs
GPIO_Init(salida.port, &GPIO_InitStructure); //Se aplica la configuracion definidas anteriormente
}
uint8_t pulsador_presionado(
Entrada puls_line_entrada_1,
Entrada puls_line_entrada_2,
Entrada puls_line_entrada_3,
Entrada puls_line_entrada_4
) {
uint8_t botonApretado = NO_BUTTON;
if(leer_entrada(puls_line_entrada_1))
botonApretado = (uint8_t)BUTTON_1;
else if (leer_entrada(puls_line_entrada_2))
botonApretado = (uint8_t)BUTTON_2;
else if (leer_entrada(puls_line_entrada_3))
botonApretado = (uint8_t)BUTTON_3;
else if (leer_entrada(puls_line_entrada_4))
botonApretado = (uint8_t)BUTTON_4;
return botonApretado;
}