[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-chat] PIN_LOW PIN_HIGH makros for XMega? (preprocessor with ##)
From: |
Alexander Krause |
Subject: |
[avr-chat] PIN_LOW PIN_HIGH makros for XMega? (preprocessor with ##) |
Date: |
Tue, 18 Feb 2014 11:46:33 +0100 |
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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [avr-chat] PIN_LOW PIN_HIGH makros for XMega? (preprocessor with ##),
Alexander Krause <=