/* Port I/O abstraction macros - by Tom Torfs, 2006 * MSP430 implementation * Donated to the public domain. No warranties whatsoever. * * These macros allow you to make easy abstraction of I/O port & pin numbers. * You simply define your signal location like: * #define LED P1,0 * and then use them like: * SETDIR(LED); * CLR(LED); * TOGGLE(LED); * ... * * The obvious advantage, besides readability, is that in the next * hardware design or layout iteration - when most of the signals have * shifted to different pins on different ports - all you need to change * is one simple and readable #define in a central location * * In addition, nothing stops you from porting this header to other * microcontroller families. The specifics such as direction and interrupt * registers may be different but the basic concepts hold. * * Overview of user macros: * - Reading from port registers: (these are meant to be used in expressions) * x = IN(signal), OUTBUF(signal), DIR(signal), SEL(signal), IE(signal), IES(signal), IFG(signal) * - Writing to port registers: (these are meant to be used as statements) * output bit manipulation: SET(signal); CLR(signal); TOGGLE(signal); * direction bit manipulation: SETDIR(signal); CLRDIR(signal); * special function bit manipulation: SETSEL(signal); CLRSEL(signal); * interrupt bits manipulation: SETIE(signal); CLRIE(signal); SETIES(signal); CLRIES(signal); * interrupt flag manipulation: SETIFG(signal); CLRIFG(signal); * copy 1 or 0 into output bit: CPYBIT(signal,bitvalue) * - Getting the port name (string) or bit number (integer literal) corresponding to a signal: * const char s[] = PORTNAME(name); * x = BITNUM(name); * - Interrupt vector for port corresponding to a signal: (requires compiler-specific mapping) * INTVECTOR(name) */ /********** HELPER MACROS **********/ #define POUT_(Pn) Pn##OUT #define PIN_(Pn) Pn##IN #define PDIR_(Pn) Pn##DIR #define PSEL_(Pn) Pn##SEL #define PIE_(Pn) Pn##IE #define PIES_(Pn) Pn##IES #define PIFG_(Pn) Pn##IFG #define IN_(p,b) (PIN_(p)&(1<