summaryrefslogtreecommitdiff
path: root/simonnnnn/Core/Src/led.c
blob: 1a5c58ff00a045402830e1a5c44bcb11383806a8 (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
34
35
36
37
38
39
40
41
42
43
44
/*
 * led.c
 *
 *  Created on: 2 déc. 2020
 *      Author: root
 */

#include "led.h"

void Led_init(LED_TypeDef *led, GPIO_TypeDef * port, uint16_t pn){
led->gpioPort=port;
led->pin=pn;

//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)((uint32_t *)port - IOPPERIPH_BASE)/ (uint32_t)0x400;
//activation de l'hologe
RCC->IOPENR|=1<<nb_port;

//configuration de la pin en sortie
led->gpioPort->MODER&=~(0b11<<2*pn);
led->gpioPort->MODER|=(0b01<<2*pn);
}

uint8_t Led_isOn(LED_TypeDef *led){
return ((led->gpioPort->ODR&(1<<led->pin))!=0);
}

uint8_t Led_isOff(LED_TypeDef *led){
return ((led->gpioPort->ODR&(1<<led->pin))==0);
}
void Led_turnOn(LED_TypeDef *led){
led->gpioPort->ODR|=(1<<led->pin);
}

void Led_turnOff(LED_TypeDef *led){
led->gpioPort->ODR&=~(1<<led->pin);
}

void Led_toggle(LED_TypeDef *led){
	led->gpioPort->ODR^=(1<<led->pin);
}