summaryrefslogtreecommitdiff
path: root/simonnnnn/Core/Src/button.c
blob: a9333d914f1fa473ad9e2f409f21b0e857a66d6f (plain)
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
/*
 * button.c
 *
 *  Created on: 2 déc. 2020
 *      Author: root
 */

#include "button.h"

void Button_init(BUTTON_TypeDef *button, GPIO_TypeDef * port, uint8_t pn,uint8_t pl) {
button->gpioPort = port;
button->pin = pn;
button->pull = pl;

//Activation de l'horloge sur le port en question

//déterminer le numéro du port 0--> GPIOA, 1-->GPIOB, etc.
uint8_t nb_port;
nb_port = ((uint32_t) port - IOPPERIPH_BASE) / 0x400;
//activation de l'hologe
RCC->IOPENR |= 1 << nb_port;
//configuration de la pin en entrée
button->gpioPort->MODER &= ~(0b11 << 2 * pn);
//configuration du type de pull
button->gpioPort->PUPDR &= ~(0b11 << 2 * pn);
button->gpioPort->PUPDR |= (pl << 2 * pn);
}

uint8_t Button_State(BUTTON_TypeDef *button) {
if ((button->gpioPort->IDR & (1 << button->pin)) != 0)
return 1;
return 0;
}