extruder/arduino.h

Go to the documentation of this file.
00001 
00008 #ifndef _ARDUINO_H
00009 #define _ARDUINO_H
00010 
00011 #include  <avr/io.h>
00012 
00013 /*
00014   utility functions
00015 */
00016 
00017 #ifndef   MASK
00018 
00019   #define   MASK(PIN)       (1 << PIN)
00020 #endif
00021 
00022 /*
00023   magic I/O routines
00024 
00025   now you can simply SET_OUTPUT(STEP); WRITE(STEP, 1); WRITE(STEP, 0);
00026 */
00027 
00029 #define   _READ(IO)         (IO ## _RPORT & MASK(IO ## _PIN))
00030 
00031 #define   _WRITE(IO, v)     do { if (v) { IO ## _WPORT |= MASK(IO ## _PIN); } else { IO ## _WPORT &= ~MASK(IO ## _PIN); }; } while (0)
00032 
00033 #define   _TOGGLE(IO)       do { IO ## _RPORT = MASK(IO ## _PIN); } while (0)
00034 
00036 #define   _SET_INPUT(IO)    do { IO ## _DDR &= ~MASK(IO ## _PIN); } while (0)
00037 
00038 #define   _SET_OUTPUT(IO)   do { IO ## _DDR |=  MASK(IO ## _PIN); } while (0)
00039 
00041 #define   _GET_INPUT(IO)    ((IO ## _DDR & MASK(IO ## _PIN)) == 0)
00042 
00043 #define   _GET_OUTPUT(IO)   ((IO ## _DDR & MASK(IO ## _PIN)) != 0)
00044 
00045 //  why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
00046 
00048 #define   READ(IO)          _READ(IO)
00049 
00050 #define   WRITE(IO, v)      _WRITE(IO, v)
00051 
00052 #define   TOGGLE(IO)        _TOGGLE(IO)
00053 
00055 #define   SET_INPUT(IO)     _SET_INPUT(IO)
00056 
00057 #define   SET_OUTPUT(IO)    _SET_OUTPUT(IO)
00058 
00060 #define   GET_INPUT(IO)     _GET_INPUT(IO)
00061 
00062 #define   GET_OUTPUT(IO)    _GET_OUTPUT(IO)
00063 
00064 /*
00065   ports and functions
00066 
00067   added as necessary or if I feel like it- not a comprehensive list!
00068 */
00069 
00070 #if defined (__AVR_ATmega168__) || defined (__AVR_ATmega328__) || defined (__AVR_ATmega328P__)
00071   #include  "arduino_168_328p.h"
00072 #endif  /*  _AVR_ATmega{168,328,328P}__ */
00073 
00074 #if defined (__AVR_ATmega644__) || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644PA__)
00075   #include  "arduino_644.h"
00076 #endif  /*  _AVR_ATmega{644,644P,644PA}__ */
00077 
00078 #if defined (__AVR_ATmega1280__)
00079   #include  "arduino_1280.h"
00080 #endif  /* __AVR_ATmega1280__ */
00081 
00082 #if defined (__AVR_ATmega2560__)
00083   #include    "arduino_1280.h" //2560 has the same pins and ports so we can reuse the 1280 file.
00084 #endif
00085 
00086 #if defined (__AVR_AT90USB1287__)
00087   #include    "arduino_usb1287.h"
00088 #endif
00089 
00090 #ifndef DIO0_PIN
00091 #error pins for this chip not defined in arduino.h! If you write an appropriate pin definition and have this firmware work on your chip, please tell us via the forum thread
00092 #endif
00093 
00094 #endif /* _ARDUINO_H */
 All Data Structures Files Functions Variables Defines