Hi all, maybe some of you know these makros and personally I really like the idea because it makes configuration much easier.
To keep things short: #define PORT(x) _port2(x) #define _port2(x) PORT ## x #define PIN_LOW2(x,y) PORT(x) &= ~(1<<y) #define PIN_LOW(x) PIN_LOW2(x) #define MY_IO_PIN D,2 PIN_LOW(MY_IO_PIN) -> PIN_LOW(D,2) -> PORT(D) &= ~(1<<2) -> PORTD &= ~(1<<2) Now I want to use this for the XMega series, where It's not PORTD = ... but instead PORTD.OUTSET or PORTD.OUTCLR. It seems like this works: #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 ... #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 Full utils.h can be found here: http://pastebin.com/eYhwx7yf So, what do you think? Regards, Alex _______________________________________________ AVR-chat mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/avr-chat
