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
73
74
75
76
77
78
79
80
81
82
83
|
#ifndef PIN_H
#define PIN_H
#include "gpio.h"
class GPIO {
private:
GPIO_t& g;
int n;
public:
GPIO(GPIO_t& gpio, int pin) : g(gpio), n(pin) {}
void on() {
g.BSRR = 1 << n;
}
void off() {
g.BSRR = 1 << 16 << n;
}
void toggle() {
if(g.ODR & (1 << n)) {
off();
} else {
on();
}
}
};
template <class... Ts>
class Pin : public Ts... {
public:
Pin(GPIO_t& gpio, int pin) : Ts(gpio, pin)... {}
};
/*
template <int n>
struct U {
struct RX;
struct TX;
};
typedef U<1> U1;
typedef U<2> U2;
typedef U<3> U3;
template <class P, class F>
class AF {
public:
AF(GPIO_t& gpio, int pin) {}
};
template <int AFn, class P, class F>
class Remap : public AF<P, F> {
public:
Remap(GPIO_t& gpio, int pin) : AF<P, F>(gpio, pin) {}
};
class Kake {
public:
template <class U>
Kake(AF<U, class U::RX> rxpin, AF<U, class U::TX> txpin) {}
template <class U>
Kake(const U&&, AF<U, class U::RX> rxpin, AF<U, class U::TX> txpin) {}
};
static Pin<GPIO, Remap<7, U1, U1::RX>> PB6(GPIOB, 6);
static Pin<GPIO, Remap<7, U1, U1::TX>> PB7(GPIOB, 7);
static Pin<GPIO, Remap<7, U2, U2::RX>, AF<U3, U3::RX>> PB8(GPIOB, 8);
static Pin<GPIO, Remap<7, U2, U2::TX>, AF<U3, U3::TX>> PB9(GPIOB, 9);
*/
static Pin<GPIO> PD12(GPIOD, 12);
static Pin<GPIO> PD13(GPIOD, 13);
static Pin<GPIO> PD14(GPIOD, 14);
static Pin<GPIO> PD15(GPIOD, 15);
/*
Kake f1(PB6, PB7);
Kake f2(PB8, PB9);
*/
#endif
|