Replacement for regular GPIO (DigitalIn, DigitalOut, DigitalInOut) classes which has superior speed.

Dependents:   Eavesdropper BitstreamGenerator SimpleDecimationFilter 11U68_MP3Player with TFTLCD ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FastIO.h Source File

FastIO.h

00001 #ifndef __FAST_IO_H
00002 #define __FAST_IO_H
00003 
00004 #include "FastIO_LPC1768.h"
00005 #include "FastIO_LPC11UXX.h"
00006 #include "FastIO_LPC11U6X.h"
00007 #include "FastIO_LPC81X.h"
00008 #include "FastIO_KLXX.h"
00009 #include "FastIO_K20D50M_KPSDK.h"
00010 #include "FastIO_STM32F4.h"
00011 #include "FastIO_STM32L073XX.h"
00012 #include "FastIO_NUCLEO_F030.h"
00013 #include "FastIO_LPC11XX.h"
00014 #include "FastIO_EFM32.h"
00015 #include "FastIO_LPC43XX.h"
00016 #include "FastIO_NRF51822.h"
00017 
00018 #ifndef INIT_PIN
00019 #warning Target is not supported by FastIO
00020 #warning Reverting to regular DigitalInOut
00021 #include "FastIO_Unsupported.h"
00022 #endif
00023 
00024 #include "mbed.h"
00025 
00026 /**
00027  * Faster alternative compared to regular DigitalInOut
00028  *
00029  * Except the constructor it is compatible with regular DigitalInOut.
00030  * Code is based on Igor Skochinsky's code (http://mbed.org/users/igorsk/code/FastIO/)
00031  */
00032 template <PinName pin> class FastInOut
00033 {
00034 public:
00035     /**
00036      * Construct new FastInOut object
00037      *
00038      * @code
00039      * FastInOut<LED1> led1;
00040      * @endcode
00041      *
00042      * No initialization is done regarding input/output mode,
00043      * FastIn/FastOut can be used if that is required
00044      *
00045      * @param pin pin the FastOut object should be used for
00046      */
00047     FastInOut() {
00048         INIT_PIN;
00049     }
00050     
00051     ~FastInOut() {
00052         DESTROY_PIN;
00053     }
00054 
00055     void write(int value) {
00056         if ( value )
00057             WRITE_PIN_SET;
00058         else
00059             WRITE_PIN_CLR;
00060     }
00061     int read() {
00062         return READ_PIN;
00063     }
00064 
00065     void mode(PinMode pull) {
00066         SET_MODE(pull);
00067     }
00068 
00069     void output() {
00070         SET_DIR_OUTPUT;
00071     }
00072 
00073     void input() {
00074         SET_DIR_INPUT;
00075     }
00076 
00077     FastInOut& operator= (int value) {
00078         write(value);
00079         return *this;
00080     };
00081     FastInOut& operator= (FastInOut& rhs) {
00082         return write(rhs.read());
00083     };
00084     operator int() {
00085         return read();
00086     };
00087     
00088     protected:
00089     fastio_vars container;
00090 };
00091 
00092 /**
00093  * Faster alternative compared to regular DigitalOut
00094  *
00095  * Except the constructor it is compatible with regular DigitalOut. Aditionally all
00096  * functions from DigitalInOut are also available (only initialization is different)
00097  * Code is based on Igor Skochinsky's code (http://mbed.org/users/igorsk/code/FastIO/)
00098  */
00099 template <PinName pin, int initial = 0> class FastOut : public FastInOut<pin>
00100 {
00101 public:
00102     /**
00103      * Construct new FastOut object
00104      *
00105      * @code
00106      * FastOut<LED1> led1;
00107      * @endcode
00108      *
00109      * @param pin pin the FastOut object should be used for
00110      * @param initial (optional) initial state of the pin after construction: default is 0 (low)
00111      */
00112     FastOut() : FastInOut<pin>::FastInOut() {
00113         write(initial);
00114         SET_DIR_OUTPUT;
00115     }
00116 
00117     FastOut& operator= (int value) {
00118         this->write(value);
00119         return *this;
00120     };
00121     FastOut& operator= (FastOut& rhs) {
00122         return this->write(rhs.read());
00123     };
00124     operator int() {
00125         return this->read();
00126     };
00127 };
00128 
00129 /**
00130  * Faster alternative compared to regular DigitalIn
00131  *
00132  * Except the constructor it is compatible with regular DigitalIn. Aditionally all
00133  * functions from DigitalInOut are also available (only initialization is different)
00134  * Code is based on Igor Skochinsky's code (http://mbed.org/users/igorsk/code/FastIO/)
00135  */
00136 template <PinName pin, PinMode pinmode = PullDefault> class FastIn : public FastInOut<pin>
00137 {
00138 public:
00139     /**
00140      * Construct new FastIn object
00141      *
00142      * @code
00143      * FastIn<LED1> led1;
00144      * @endcode
00145      *
00146      * @param pin pin the FastIn object should be used for
00147      * @param pinmode (optional) initial mode of the pin after construction: default is PullDefault
00148      */
00149     FastIn() : FastInOut<pin>::FastInOut() {
00150         SET_MODE(pinmode);
00151         SET_DIR_INPUT;
00152     }
00153 
00154     FastIn& operator= (int value) {
00155         this->write(value);
00156         return *this;
00157     };
00158     FastIn& operator= (FastIn& rhs) {
00159         return this->write(rhs.read());
00160     };
00161     operator int() {
00162         return this->read();
00163     };
00164 };
00165 
00166 #endif