Fixed constructor for latest mbed library.

Dependents:   Pinscape_Controller_v1 Pinscape_Controller Pinscape_Controller_V2_arnoz Pinscape_Controller_V2

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