Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @file lib/utils.h
- * @author Alexander Krause <alexander.krause@ed-solutions.de>
- * @date 05.03.2012
- * @version 0.1.0
- *
- *
- */
- #ifndef LIB__UTILS_H
- #define LIB__UTILS_H
- uint8_t mirror_uint8(uint8_t);
- #if defined (__AVR_ATxmega16A4__)
- #define IS_XMEGA
- #elif defined (__AVR_ATxmega16A4U__)
- #define IS_XMEGA
- #elif defined (__AVR_ATxmega16D4__)
- #define IS_XMEGA
- #elif defined (__AVR_ATxmega32A4__)
- #define IS_XMEGA
- #elif defined (__AVR_ATxmega32A4U__)
- #define IS_XMEGA
- #elif defined (__AVR_ATxmega32D4__)
- #define IS_XMEGA
- #elif defined (__AVR_ATxmega64A1__)
- #define IS_XMEGA
- #elif defined (__AVR_ATxmega64A1U__)
- #define IS_XMEGA
- #elif defined (__AVR_ATxmega64A3__)
- #define IS_XMEGA
- #elif defined (__AVR_ATxmega64D3__)
- #define IS_XMEGA
- #elif defined (__AVR_ATxmega128A1__)
- #define IS_XMEGA
- #elif defined (__AVR_ATxmega128A1U__)
- #define IS_XMEGA
- #elif defined (__AVR_ATxmega128A3__)
- #define IS_XMEGA
- #elif defined (__AVR_ATxmega128D3__)
- #define IS_XMEGA
- #elif defined (__AVR_ATxmega192A3__)
- #define IS_XMEGA
- #elif defined (__AVR_ATxmega192D3__)
- #define IS_XMEGA
- #elif defined (__AVR_ATxmega256A3__)
- #define IS_XMEGA
- #elif defined (__AVR_ATxmega256A3B__)
- #define IS_XMEGA
- #elif defined (__AVR_ATxmega256D3__)
- #define IS_XMEGA
- #endif
- #ifdef IS_XMEGA
- #define PORT_DIRSET(x) _port_dirset(x)
- #define PORT_DIRCLR(x) _port_dirclr(x)
- #define PORT_OUTSET(x) _port_outset(x)
- #define PORT_OUTCLR(x) _port_outclr(x)
- #define PORT_OUTTGL(x) _port_outtgl(x)
- #else
- #define PORT(x) _port2(x)
- #define DDR(x) _ddr2(x)
- #define PIN(x) _pin2(x)
- #define REG(x) _reg(x)
- #define PIN_NUM(x) _pin_num(x)
- #endif
- #define PIN_LOW(x) PIN_LOW2(x)
- #define PIN_HIGH(x) PIN_HIGH2(x)
- #define PIN_TOGGLE(x) PIN_TOGGLE2(x)
- #define PIN_SET_OUTPUT(x) PIN_SET_OUTPUT2(x)
- #define PIN_SET_INPUT(x) PIN_SET_INPUT2(x)
- #define PIN_SET_PULLUP(x) PIN_SET2(x)
- #define PIN_IS_SET(x) PIN_IS_SET2(x)
- #define SET_INPUT_WITH_PULLUP(x) SET_INPUT_WITH_PULLUP2(x)
- #ifdef IS_XMEGA
- #define _DIRSET ".DIRSET"
- #define _DIRCLR ".DIRCLR"
- #define _OUTSET ".OUTSET"
- #define _OUTCLR ".OUTCLR"
- #define _port_dirset(x) PORT ## x ## _DIRSET
- #define _port_dirclr(x) PORT ## x ## _DIRCLR
- #define _port_outset(x) PORT ## x ## _OUTSET
- #define _port_outclr(x) PORT ## x ## _OUTCLR
- #else
- #define _port2(x) PORT ## x
- #define _ddr2(x) DDR ## x
- #define _pin2(x) PIN ## x
- #define _reg(x,y) x
- #define _pin_num(x,y) y
- #endif
- #ifdef IS_XMEGA
- #define PIN_LOW2(x,y) PORT_OUTCLR(x) = (1<<y)
- #define PIN_HIGH2(x,y) PORT_OUTSET(x) = (1<<y)
- #define PIN_TOGGLE2(x,y) PORT_OUTTGL(x) = (1<<y)
- #define PIN_SET_OUTPUT2(x,y) PORT_DIRSET(x) = (1<<y)
- #define PIN_SET_INPUT2(x,y) PORT_DIRCLR(x) = (1<<y)
- //#define PIN_SET_INPUT_WITH_PULLUP2(x,y) PIN_SET_INPUT2(x,y);PIN_SET2(x,y)
- //#define PIN_IS_SET2(x,y) ((PIN(x) & (1<<y)) != 0)
- #else
- #define PIN_LOW2(x,y) PORT(x) &= ~(1<<y)
- #define PIN_HIGH2(x,y) PORT(x) |= (1<<y)
- #define PIN_TOGGLE2(x,y) PORT(x) ^= (1<<y)
- #define PIN_SET_OUTPUT2(x,y) DDR(x) |= (1<<y)
- #define PIN_SET_INPUT2(x,y) DDR(x) &= ~(1<<y)
- #define PIN_SET_INPUT_WITH_PULLUP2(x,y) PIN_SET_INPUT2(x,y);PIN_SET2(x,y)
- #define PIN_IS_SET2(x,y) ((PIN(x) & (1<<y)) != 0)
- #endif
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement