StepperII
Dual Axis Stepper Controller

CBitio.h

00001 
00002 #pragma once
00003 
00004 #include "CBaseio.h"
00005 
00006 /*
00007 READ_ONLY (or READ_ONLY_AL)
00008         CBitRO();                               // Constructor - config bit for input                   
00009         initPullup();                   // Turn on weak pull up
00010         unsigned char read();   // Return input bit value
00011 WRITE_ONLY
00012         init()
00013         on()
00014         off()
00015         toggle()
00016         hiZ()
00017 READ_WRITE (or READ_WRITE_AL)
00018         - initOut()
00019         - initIn()
00020         - initPullup()
00021         - on()
00022         - off()
00023         - toggle()
00024         - hiZ()
00025         - read()
00026 */
00027 
00028 /*
00029         There are 7 possible bit operations per I/O bit:
00030         1) Clear DDxn
00031         2) Set   DDxn
00032         3) Read  DDxn
00033         4) Clear PORTxn
00034         5) Set   PORTxn
00035         6) Read  PORTxn
00036         7) Read  PINxn
00037         
00038         Operations that can be affected by "active low" logic are 4, 5, 6, and 7.
00039         (4, 5, and 7 affect the outside world.  6 is internal, but must adhere to
00040         convention.)
00041 */
00042 
00043 //---------------------------------------------------------------------------
00045 /*
00046         Use: READ_ONLY_IO(funcName, THE_PORT, THE_BIT)
00047         Parameters:
00048                 funcName: The name of the READ ONLY object to be declared
00049                 THE_PORT: Port letter for the AVR port B, C, D...
00050                 THE_BIT:  Bit number for the AVR port 0, 1, 2... 7.
00051         Example: To create a switch input on I/O bit PD5
00052                 READ_ONLY_IO(switchInput, D, 5)
00053                 calls BUILD_CLASS(RO, switchInput, D, 5)
00054                         calls DECLARE_BASE_IO_CLASS(switchInput, D, 5)
00055                                 calls BASE_IO(PORTD, DDRD, PIND, PD5, BASE_IO_D5)
00056                                 [Creates base class called BASE_IO_D5]
00057                         calls DECLARE_IO_CLASS(RO_IO, switchInput, D, 5)
00058                                 calls RO_IO(switchInput, RO_D5, BASE_IO_D5)
00059                                 [Creates class RO_D5 : BASE_IO_D5
00060                                         amd declares class RO_IO_D5 switchInput]
00061         Creates:
00062                 1) Unique base class BASE_IO_D5
00063                 2) Unique io class RO_IO_D5 : public BASE_IO_D5
00064                 3) Instance of class RO_IO_D5 switchInput
00065         Note that the base class includes all possible I/O operations. However,
00066         all of the functions are protected, meaning that they don't beome
00067         public until a new class is declared that defines the public interface
00068         to the I/O operations.  This is the process that defines the personality
00069         of the I/O bit - read-only, write-only, etc.
00070 */
00071 //---------------------------------------------------------------------------
00072 
00073 //---------------------------------------------------------------------------
00085 //---------------------------------------------------------------------------
00086 
00087 #define CBit(port, bit, type)                   \
00088         DECLARE_BASE_IO_CLASS(port, bit);       \
00089         CBit ## type<BASE_IO_ ## port ## bit>
00090 
00091 //---------------------------------------------------------------------------
00093 
00094 
00095 
00096 
00097 
00098 //---------------------------------------------------------------------------
00099 template <class BASE_CLASS>
00100 class CBitRO : BASE_CLASS
00101 {
00102 public:
00103         CBitRO()                                                                
00104                 { BASE_CLASS::initIn();                 }
00105         void initPullup(void)                                   //*! Initializes input with pullup
00106                 { BASE_CLASS::initPullup();             }
00107         unsigned char read(void)                                
00108                 { return BASE_CLASS::read();    }
00109 };
00110 
00111 //---------------------------------------------------------------------------
00113 
00114 
00115 
00116 
00117 //---------------------------------------------------------------------------
00118 template <class BASE_CLASS>
00119 class CBitRO_PU : BASE_CLASS
00120 {
00121 public:
00122         CBitRO_PU()                                                             
00123                 { BASE_CLASS::initPullup();     }
00124         unsigned char read(void)                                
00125                 { return BASE_CLASS::read();    }
00126 };
00127 
00128 //---------------------------------------------------------------------------
00130 //---------------------------------------------------------------------------
00131 template <class BASE_CLASS>
00132 class CBitRO_AL : BASE_CLASS
00133 {
00134 public:
00135         CBitRO_AL()                                                             // Constructor                                  
00136                 { initPullup();                                 }
00137         void initPullup(void)
00138                 { BASE_CLASS::initPullup();             }
00139         unsigned char read(void)                                // Return "active low" read
00140                 { return BASE_CLASS::read_al(); }
00141         void hiZ(void)
00142                 { BASE_CLASS::hiZ();                    }
00143 };
00144 
00145 //---------------------------------------------------------------------------
00154 //---------------------------------------------------------------------------
00155 template <class BASE_CLASS>
00156 class CBitWO : BASE_CLASS
00157 {
00158 public:
00159         CBitWO()                                                                // Constructor
00160                 { BASE_CLASS::initOut();                }       // Set pin direction to output
00161         void init(void)                                                 // init()
00162                 { BASE_CLASS::initOut();                }
00163         void on(void)                                                   // Set output high
00164                 { BASE_CLASS::on();                             }
00165         void off(void)                                                  // Set output low
00166                 { BASE_CLASS::off();                    }
00167         void hiZ(void)                                                  // Set pin to high Z
00168                 { BASE_CLASS::hiZ();                    }
00169         void toggle(void)                                               // Toggle the output
00170 // ATmega48,88,168  or  ATmega32u4
00171 #if defined(_AVR_IOMX8_H_) || defined(_AVR_IOXXX_H_)
00172                 { BASE_CLASS::toggleMX();               }
00173 #else
00174                 { BASE_CLASS::toggle();                 }
00175 #endif
00176         unsigned char toggle(char x)                    // Toggle and return value
00177                 { return BASE_CLASS::toggle(0); }
00178         // Sometimes one needs to read the state of an output, i.e. OC1
00179         unsigned char read(void)                                // Read state of output pin
00180                 { return BASE_CLASS::read();    }
00181 };
00182 
00183 //---------------------------------------------------------------------------
00185 //---------------------------------------------------------------------------
00186 template <class BASE_CLASS>
00187 class CBitWO_AL : BASE_CLASS
00188 {
00189 public:
00190         CBitWO_AL()                                                             // Constructor
00191                 { BASE_CLASS::initOut_al();             }       // Output with data high
00192         void init(void)                                                 // Output with data low
00193                 { BASE_CLASS::initOut();                }
00194         void on(void)                                                   // Data active (low)
00195                 { BASE_CLASS::on_al();                  }
00196         void off(void)                                                  // Data inactive (high)
00197                 { BASE_CLASS::off_al();                 }
00198         void hiZ(void)                                                  // Input, pullup off
00199                 { BASE_CLASS::hiZ();                    }
00200         void toggle(void)                                               // Toggle
00201                 { BASE_CLASS::toggle();                 }
00202         unsigned char toggle(char x)                    // Toggle and return active low val
00203                 { return BASE_CLASS::toggle_al(0); }
00204 };
00205 
00206 //---------------------------------------------------------------------------
00211 //---------------------------------------------------------------------------
00212 template <class BASE_CLASS>
00213 class CBitWO_AL_OC : BASE_CLASS
00214 {
00215 public:
00216         CBitWO_AL_OC()                                                  // Constructor
00217                 { BASE_CLASS::initPullup();             }       // Init to input w/pullup
00218         void on(void)
00219                 { BASE_CLASS::initOut();                }       // Set to output, data low
00220         void off(void)
00221                 { BASE_CLASS::initPullup();             }       // Off is input w/pullup
00222 };
00223 
00224 //---------------------------------------------------------------------------
00229 //---------------------------------------------------------------------------
00230 template <class BASE_CLASS>
00231 class CBitWO_NC : BASE_CLASS
00232 {
00233 public:
00234         void init(void)                                                 // Output with data low
00235                 { BASE_CLASS::initOut();                }
00236         void on(void)
00237                 { BASE_CLASS::on();                             }       // Set output high
00238         void off(void)
00239                 { BASE_CLASS::off();                    }       // Set output low
00240         void toggle(void)                                               // Toggle the output
00241 // ATmega48,88,168  or  ATmega32u4
00242 #if defined(_AVR_IOMX8_H_) || defined(_AVR_IOXXX_H_)
00243                 { BASE_CLASS::toggleMX();               }
00244 #else
00245                 { BASE_CLASS::toggle();                 }
00246 #endif
00247         unsigned char read(void)                                // Read state of output pin
00248                 { return BASE_CLASS::read();    }
00249 };
00250 
00251 //---------------------------------------------------------------------------
00256 //---------------------------------------------------------------------------
00257 template <class BASE_CLASS>
00258 class CBitWO_AL_NC : BASE_CLASS
00259 {
00260 public:
00261         void init(void)                                                 // Output with data low
00262                 { BASE_CLASS::initOut_al();             }       // Output with data high
00263         void on(void)
00264                 { BASE_CLASS::on_al();                  }       // Set output low
00265         void off(void)
00266                 { BASE_CLASS::off_al();                 }       // Set output high
00267         void toggle(void)                                               // Toggle the output
00268 // ATmega48,88,168  or  ATmega32u4
00269 #if defined(_AVR_IOMX8_H_) || defined(_AVR_IOXXX_H_)
00270                 { BASE_CLASS::toggleMX();               }
00271 #else
00272                 { BASE_CLASS::toggle();                 }
00273 #endif
00274         unsigned char read(void)                                // Read state of output pin
00275                 { return BASE_CLASS::read_al(); }
00276 };
00277 
00278 //---------------------------------------------------------------------------
00280 //---------------------------------------------------------------------------
 All Classes Files Functions Variables Defines