-
Notifications
You must be signed in to change notification settings - Fork 0
/
leds.h
50 lines (45 loc) · 1.4 KB
/
leds.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
#ifndef LEDS_H
#define LEDS_H
#include <stm32.h>
#include <gpio.h>
#define RED_LED_GPIO GPIOA
#define GREEN_LED_GPIO GPIOA
#define BLUE_LED_GPIO GPIOB
#define GREEN2_LED_GPIO GPIOA
#define RED_LED_PIN 6
#define GREEN_LED_PIN 7
#define BLUE_LED_PIN 0
#define GREEN2_LED_PIN 5
#define RedLEDon() \
RED_LED_GPIO->BSRR = 1 << (RED_LED_PIN + 16)
#define RedLEDoff() \
RED_LED_GPIO->BSRR = 1 << RED_LED_PIN
#define RedLEDtoggle() \
do { \
if ((RED_LED_GPIO->ODR >> RED_LED_PIN) & 1) RedLEDon(); else RedLEDoff(); \
} while(0)
#define GreenLEDon() \
GREEN_LED_GPIO->BSRR = 1 << (GREEN_LED_PIN + 16)
#define GreenLEDoff() \
GREEN_LED_GPIO->BSRR = 1 << GREEN_LED_PIN
#define GreenLEDtoggle() \
do { \
if ((GREEN_LED_GPIO->ODR >> GREEN_LED_PIN) & 1) GreenLEDon(); else GreenLEDoff(); \
} while(0)
#define BlueLEDon() \
BLUE_LED_GPIO->BSRR = 1 << (BLUE_LED_PIN + 16)
#define BlueLEDoff() \
BLUE_LED_GPIO->BSRR = 1 << BLUE_LED_PIN
#define BlueLEDtoggle() \
do { \
if ((BLUE_LED_GPIO->ODR >> BLUE_LED_PIN) & 1) BlueLEDon(); else BlueLEDoff(); \
} while(0)
#define Green2LEDon() \
GREEN2_LED_GPIO->BSRR = 1 << GREEN2_LED_PIN
#define Green2LEDoff() \
GREEN2_LED_GPIO->BSRR = 1 << (GREEN2_LED_PIN + 16)
#define Green2LEDtoggle() \
do { \
if (!((GREEN2_LED_GPIO->ODR >> GREEN2_LED_PIN) & 1)) Green2LEDon(); else Green2LEDoff(); \
} while(0)
#endif