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