Under Cover / projet_pololu_et5_ees

Fork of FastIO by Erik -

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