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