-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFastIO.h
166 lines (150 loc) · 3.85 KB
/
FastIO.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#ifndef __FAST_IO_H
#define __FAST_IO_H
#include "FastIO_LPC1768.h"
#include "FastIO_LPC11UXX.h"
#include "FastIO_LPC11U6X.h"
#include "FastIO_LPC81X.h"
#include "FastIO_KLXX.h"
#include "FastIO_K20D50M_KPSDK.h"
#include "FastIO_STM32F4.h"
#include "FastIO_STM32L073XX.h"
#include "FastIO_NUCLEO_F030.h"
#include "FastIO_LPC11XX.h"
#include "FastIO_EFM32.h"
#include "FastIO_LPC43XX.h"
#include "FastIO_NRF51822.h"
#ifndef INIT_PIN
#warning Target is not supported by FastIO
#warning Reverting to regular DigitalInOut
#include "FastIO_Unsupported.h"
#endif
#include "mbed.h"
/**
* Faster alternative compared to regular DigitalInOut
*
* Except the constructor it is compatible with regular DigitalInOut.
* Code is based on Igor Skochinsky's code (http://mbed.org/users/igorsk/code/FastIO/)
*/
template <PinName pin> class FastInOut
{
public:
/**
* Construct new FastInOut object
*
* @code
* FastInOut<LED1> led1;
* @endcode
*
* No initialization is done regarding input/output mode,
* FastIn/FastOut can be used if that is required
*
* @param pin pin the FastOut object should be used for
*/
FastInOut() {
INIT_PIN;
}
~FastInOut() {
DESTROY_PIN;
}
void write(int value) {
if ( value )
WRITE_PIN_SET;
else
WRITE_PIN_CLR;
}
int read() {
return READ_PIN;
}
void mode(PinMode pull) {
SET_MODE(pull);
}
void output() {
SET_DIR_OUTPUT;
}
void input() {
SET_DIR_INPUT;
}
FastInOut& operator= (int value) {
write(value);
return *this;
};
FastInOut& operator= (FastInOut& rhs) {
return write(rhs.read());
};
operator int() {
return read();
};
protected:
fastio_vars container;
};
/**
* Faster alternative compared to regular DigitalOut
*
* Except the constructor it is compatible with regular DigitalOut. Aditionally all
* functions from DigitalInOut are also available (only initialization is different)
* Code is based on Igor Skochinsky's code (http://mbed.org/users/igorsk/code/FastIO/)
*/
template <PinName pin, int initial = 0> class FastOut : public FastInOut<pin>
{
public:
/**
* Construct new FastOut object
*
* @code
* FastOut<LED1> led1;
* @endcode
*
* @param pin pin the FastOut object should be used for
* @param initial (optional) initial state of the pin after construction: default is 0 (low)
*/
FastOut() : FastInOut<pin>::FastInOut() {
this->write(initial);
SET_DIR_OUTPUT;
}
FastOut& operator= (int value) {
this->write(value);
return *this;
};
FastOut& operator= (FastOut& rhs) {
return this->write(rhs.read());
};
operator int() {
return this->read();
};
};
/**
* Faster alternative compared to regular DigitalIn
*
* Except the constructor it is compatible with regular DigitalIn. Aditionally all
* functions from DigitalInOut are also available (only initialization is different)
* Code is based on Igor Skochinsky's code (http://mbed.org/users/igorsk/code/FastIO/)
*/
template <PinName pin, PinMode pinmode = PullDefault> class FastIn : public FastInOut<pin>
{
public:
/**
* Construct new FastIn object
*
* @code
* FastIn<LED1> led1;
* @endcode
*
* @param pin pin the FastIn object should be used for
* @param pinmode (optional) initial mode of the pin after construction: default is PullDefault
*/
FastIn() : FastInOut<pin>::FastInOut() {
SET_MODE(pinmode);
SET_DIR_INPUT;
}
FastIn& operator= (int value) {
this->write(value);
return *this;
};
FastIn& operator= (FastIn& rhs) {
return this->write(rhs.read());
};
operator int() {
return this->read();
};
};
#endif