Replacement for regular GPIO (DigitalIn, DigitalOut, DigitalInOut) classes which has superior speed.
Fork of FastIO by
FastIO.h@7:1e784ae11fba, 2014-07-29 (annotated)
- Committer:
- Sissors
- Date:
- Tue Jul 29 18:58:05 2014 +0000
- Revision:
- 7:1e784ae11fba
- Parent:
- 6:da3730030c07
- Child:
- 8:b0d725519c4f
Added LPC1114
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sissors | 0:d394ebd01052 | 1 | #ifndef __FAST_IO_H |
Sissors | 0:d394ebd01052 | 2 | #define __FAST_IO_H |
Sissors | 0:d394ebd01052 | 3 | |
Sissors | 0:d394ebd01052 | 4 | #include "FastIO_LPC1768.h" |
Sissors | 0:d394ebd01052 | 5 | #include "FastIO_LPC11UXX.h" |
Sissors | 1:85a4a54f15e3 | 6 | #include "FastIO_LPC81X.h" |
Sissors | 0:d394ebd01052 | 7 | #include "FastIO_KLXX.h" |
Sissors | 3:3dd9466e73fc | 8 | #include "FastIO_K20D50M.h" |
Sissors | 4:6ebbf25b9167 | 9 | #include "FastIO_NUCLEO_F401.h" |
Sissors | 6:da3730030c07 | 10 | #include "FastIO_NUCLEO_F030.h" |
Sissors | 7:1e784ae11fba | 11 | #include "FastIO_LPC11XX.h" |
Sissors | 0:d394ebd01052 | 12 | |
Sissors | 0:d394ebd01052 | 13 | #ifndef INIT_PIN |
Sissors | 2:1a6ed4b84590 | 14 | #warning Target is not supported by FastIO |
Sissors | 2:1a6ed4b84590 | 15 | #warning Reverting to regular DigitalInOut |
Sissors | 2:1a6ed4b84590 | 16 | #include "FastIO_Unsupported.h" |
Sissors | 0:d394ebd01052 | 17 | #endif |
Sissors | 0:d394ebd01052 | 18 | |
Sissors | 0:d394ebd01052 | 19 | #include "mbed.h" |
Sissors | 0:d394ebd01052 | 20 | |
Sissors | 0:d394ebd01052 | 21 | /** |
Sissors | 0:d394ebd01052 | 22 | * Faster alternative compared to regular DigitalInOut |
Sissors | 0:d394ebd01052 | 23 | * |
Sissors | 0:d394ebd01052 | 24 | * Except the constructor it is compatible with regular DigitalInOut. |
Sissors | 0:d394ebd01052 | 25 | * Code is based on Igor Skochinsky's code (http://mbed.org/users/igorsk/code/FastIO/) |
Sissors | 0:d394ebd01052 | 26 | */ |
Sissors | 0:d394ebd01052 | 27 | template <PinName pin> class FastInOut |
Sissors | 0:d394ebd01052 | 28 | { |
Sissors | 0:d394ebd01052 | 29 | public: |
Sissors | 0:d394ebd01052 | 30 | /** |
Sissors | 0:d394ebd01052 | 31 | * Construct new FastInOut object |
Sissors | 0:d394ebd01052 | 32 | * |
Sissors | 0:d394ebd01052 | 33 | * @code |
Sissors | 0:d394ebd01052 | 34 | * FastInOut<LED1> led1; |
Sissors | 0:d394ebd01052 | 35 | * @endcode |
Sissors | 0:d394ebd01052 | 36 | * |
Sissors | 0:d394ebd01052 | 37 | * No initialization is done regarding input/output mode, |
Sissors | 0:d394ebd01052 | 38 | * FastIn/FastOut can be used if that is required |
Sissors | 0:d394ebd01052 | 39 | * |
Sissors | 0:d394ebd01052 | 40 | * @param pin pin the FastOut object should be used for |
Sissors | 0:d394ebd01052 | 41 | */ |
Sissors | 0:d394ebd01052 | 42 | FastInOut() { |
Sissors | 0:d394ebd01052 | 43 | INIT_PIN; |
Sissors | 0:d394ebd01052 | 44 | } |
Sissors | 2:1a6ed4b84590 | 45 | |
Sissors | 2:1a6ed4b84590 | 46 | ~FastInOut() { |
Sissors | 2:1a6ed4b84590 | 47 | DESTROY_PIN; |
Sissors | 2:1a6ed4b84590 | 48 | } |
Sissors | 0:d394ebd01052 | 49 | |
Sissors | 0:d394ebd01052 | 50 | void write(int value) { |
Sissors | 0:d394ebd01052 | 51 | if ( value ) |
Sissors | 0:d394ebd01052 | 52 | WRITE_PIN_SET; |
Sissors | 0:d394ebd01052 | 53 | else |
Sissors | 0:d394ebd01052 | 54 | WRITE_PIN_CLR; |
Sissors | 0:d394ebd01052 | 55 | } |
Sissors | 0:d394ebd01052 | 56 | int read() { |
Sissors | 0:d394ebd01052 | 57 | return READ_PIN; |
Sissors | 0:d394ebd01052 | 58 | } |
Sissors | 0:d394ebd01052 | 59 | |
Sissors | 0:d394ebd01052 | 60 | void mode(PinMode pull) { |
Sissors | 0:d394ebd01052 | 61 | SET_MODE(pull); |
Sissors | 0:d394ebd01052 | 62 | } |
Sissors | 0:d394ebd01052 | 63 | |
Sissors | 0:d394ebd01052 | 64 | void output() { |
Sissors | 0:d394ebd01052 | 65 | SET_DIR_OUTPUT; |
Sissors | 0:d394ebd01052 | 66 | } |
Sissors | 0:d394ebd01052 | 67 | |
Sissors | 0:d394ebd01052 | 68 | void input() { |
Sissors | 0:d394ebd01052 | 69 | SET_DIR_INPUT; |
Sissors | 0:d394ebd01052 | 70 | } |
Sissors | 0:d394ebd01052 | 71 | |
Sissors | 0:d394ebd01052 | 72 | FastInOut& operator= (int value) { |
Sissors | 0:d394ebd01052 | 73 | write(value); |
Sissors | 0:d394ebd01052 | 74 | return *this; |
Sissors | 0:d394ebd01052 | 75 | }; |
Sissors | 0:d394ebd01052 | 76 | FastInOut& operator= (FastInOut& rhs) { |
Sissors | 0:d394ebd01052 | 77 | return write(rhs.read()); |
Sissors | 0:d394ebd01052 | 78 | }; |
Sissors | 0:d394ebd01052 | 79 | operator int() { |
Sissors | 0:d394ebd01052 | 80 | return read(); |
Sissors | 0:d394ebd01052 | 81 | }; |
Sissors | 0:d394ebd01052 | 82 | |
Sissors | 0:d394ebd01052 | 83 | private: |
Sissors | 0:d394ebd01052 | 84 | fastio_vars container; |
Sissors | 0:d394ebd01052 | 85 | }; |
Sissors | 0:d394ebd01052 | 86 | |
Sissors | 0:d394ebd01052 | 87 | /** |
Sissors | 0:d394ebd01052 | 88 | * Faster alternative compared to regular DigitalOut |
Sissors | 0:d394ebd01052 | 89 | * |
Sissors | 0:d394ebd01052 | 90 | * Except the constructor it is compatible with regular DigitalOut. Aditionally all |
Sissors | 0:d394ebd01052 | 91 | * functions from DigitalInOut are also available (only initialization is different) |
Sissors | 0:d394ebd01052 | 92 | * Code is based on Igor Skochinsky's code (http://mbed.org/users/igorsk/code/FastIO/) |
Sissors | 0:d394ebd01052 | 93 | */ |
Sissors | 0:d394ebd01052 | 94 | template <PinName pin, int initial = 0> class FastOut : public FastInOut<pin> |
Sissors | 0:d394ebd01052 | 95 | { |
Sissors | 0:d394ebd01052 | 96 | public: |
Sissors | 0:d394ebd01052 | 97 | /** |
Sissors | 0:d394ebd01052 | 98 | * Construct new FastOut object |
Sissors | 0:d394ebd01052 | 99 | * |
Sissors | 0:d394ebd01052 | 100 | * @code |
Sissors | 0:d394ebd01052 | 101 | * FastOut<LED1> led1; |
Sissors | 0:d394ebd01052 | 102 | * @endcode |
Sissors | 0:d394ebd01052 | 103 | * |
Sissors | 0:d394ebd01052 | 104 | * @param pin pin the FastOut object should be used for |
Sissors | 0:d394ebd01052 | 105 | * @param initial (optional) initial state of the pin after construction: default is 0 (low) |
Sissors | 0:d394ebd01052 | 106 | */ |
Sissors | 0:d394ebd01052 | 107 | FastOut() { |
Sissors | 0:d394ebd01052 | 108 | FastInOut<pin>::FastInOut(); |
Sissors | 0:d394ebd01052 | 109 | write(initial); |
Sissors | 0:d394ebd01052 | 110 | SET_DIR_OUTPUT; |
Sissors | 0:d394ebd01052 | 111 | } |
Sissors | 0:d394ebd01052 | 112 | |
Sissors | 0:d394ebd01052 | 113 | FastOut& operator= (int value) { |
Sissors | 0:d394ebd01052 | 114 | this->write(value); |
Sissors | 0:d394ebd01052 | 115 | return *this; |
Sissors | 0:d394ebd01052 | 116 | }; |
Sissors | 0:d394ebd01052 | 117 | FastOut& operator= (FastOut& rhs) { |
Sissors | 0:d394ebd01052 | 118 | return this->write(rhs.read()); |
Sissors | 0:d394ebd01052 | 119 | }; |
Sissors | 0:d394ebd01052 | 120 | operator int() { |
Sissors | 0:d394ebd01052 | 121 | return this->read(); |
Sissors | 0:d394ebd01052 | 122 | }; |
Sissors | 0:d394ebd01052 | 123 | }; |
Sissors | 0:d394ebd01052 | 124 | |
Sissors | 0:d394ebd01052 | 125 | /** |
Sissors | 0:d394ebd01052 | 126 | * Faster alternative compared to regular DigitalIn |
Sissors | 0:d394ebd01052 | 127 | * |
Sissors | 0:d394ebd01052 | 128 | * Except the constructor it is compatible with regular DigitalIn. Aditionally all |
Sissors | 0:d394ebd01052 | 129 | * functions from DigitalInOut are also available (only initialization is different) |
Sissors | 0:d394ebd01052 | 130 | * Code is based on Igor Skochinsky's code (http://mbed.org/users/igorsk/code/FastIO/) |
Sissors | 0:d394ebd01052 | 131 | */ |
Sissors | 0:d394ebd01052 | 132 | template <PinName pin, PinMode mode = PullDefault> class FastIn : public FastInOut<pin> |
Sissors | 0:d394ebd01052 | 133 | { |
Sissors | 0:d394ebd01052 | 134 | public: |
Sissors | 0:d394ebd01052 | 135 | /** |
Sissors | 0:d394ebd01052 | 136 | * Construct new FastIn object |
Sissors | 0:d394ebd01052 | 137 | * |
Sissors | 0:d394ebd01052 | 138 | * @code |
Sissors | 0:d394ebd01052 | 139 | * FastIn<LED1> led1; |
Sissors | 0:d394ebd01052 | 140 | * @endcode |
Sissors | 0:d394ebd01052 | 141 | * |
Sissors | 0:d394ebd01052 | 142 | * @param pin pin the FastIn object should be used for |
Sissors | 0:d394ebd01052 | 143 | * @param mode (optional) initial mode of the pin after construction: default is PullDefault |
Sissors | 0:d394ebd01052 | 144 | */ |
Sissors | 0:d394ebd01052 | 145 | FastIn() { |
Sissors | 0:d394ebd01052 | 146 | FastInOut::FastInOut(); |
Sissors | 0:d394ebd01052 | 147 | SET_MODE(mode); |
Sissors | 0:d394ebd01052 | 148 | SET_DIR_INPUT; |
Sissors | 0:d394ebd01052 | 149 | } |
Sissors | 0:d394ebd01052 | 150 | |
Sissors | 0:d394ebd01052 | 151 | FastIn& operator= (int value) { |
Sissors | 0:d394ebd01052 | 152 | this->write(value); |
Sissors | 0:d394ebd01052 | 153 | return *this; |
Sissors | 0:d394ebd01052 | 154 | }; |
Sissors | 0:d394ebd01052 | 155 | FastIn& operator= (FastIn& rhs) { |
Sissors | 0:d394ebd01052 | 156 | return this->write(rhs.read()); |
Sissors | 0:d394ebd01052 | 157 | }; |
Sissors | 0:d394ebd01052 | 158 | operator int() { |
Sissors | 0:d394ebd01052 | 159 | return this->read(); |
Sissors | 0:d394ebd01052 | 160 | }; |
Sissors | 0:d394ebd01052 | 161 | }; |
Sissors | 0:d394ebd01052 | 162 | |
Sissors | 0:d394ebd01052 | 163 | #endif |