Arduino Pin to Port n,x conversion ?

Is there a function call that allows conversion of Arduino Pin Numbers to Port and Bit address?

The resultant address will be used for port,bit manipulation within an interrupt.
if possible is there a device independent method of doing it so that one piece of code can run on any Arduino and resolve to the correct port,pin?
I was thinking of allocating an array of pin mappings, but I need to keep the footprint small, and it occurred to me that such a mapping and a function to use it may already exist in the core libs but I have not found anything in arduino.cc or playground.

Cheers
Chris

EDIT:

I found this thread http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1267553811/0 which whilst not directly answering my question did provide an elegant solution to the problem I was attempting to solve, so rather than reinvent any wheels I will use the digitalWriteFast library.

I've done direct port manipulation with a class (with changing pins) and it's not that hard. In your constructor/initialization where you get the pin numbers, do

pinBit = digitalPinToBitMask(pinNumber);
pinBitNOT = ~pinBit; //Optional -- uses more memory, but makes writing LOWs faster
uint8_t pinPort = digitalPinToPort(pinNumber);
pinOut = portOutputRegister(pinPort);

EDIT: You also have to include pins_arduino.h

where pinNumber is the user-supplied pin number, pinBit and pinBitNOT are class variables of uint8_t type, and pinOut is another class variable, but is a pointer to a uint8_t. Then, to do the actual writing, do this:

if (/*you want to write HIGH*/) {
    *pinOut |= clockBit;
}
else {
    *pinOut &= clockBitNOT;
    //if you don't want to use the extra memory of clockBitNOT, do this
    *pinOut &= ~clockBit;
}

digitalWrite also likes to disable interrupts while writing to the registers, which can be done by

 uint8_t old_SREG = SREG;
cli();

before you write to *pinOut and SREG = old_SREG; afterward.

If you follow the code in the core libs you should find the macro's

On my win7 PC ==> C:\Program Files (x86)\arduino-0022\hardware\arduino\cores\arduino\pins_arduin.c or .h

Thanks WizenedEE,

digitalPinToBitMask(pinNumber) and digitalPinToPort(pinNumber) were the functions I was after, not sure how I missed them.
and thanks robtillaart, it will be useful to know where to look for the libraries in future.

I am an assembly language person and new to working with C. I know the Arduino IDE is designed to hide all the technical stuff but it can be annoying for technical people who are used to having direct control of the tools. At this stage I am still benefiting from the ease of use of the Arduino and it's libraries, but hankering after greater control of the chip that I am used too with assembler. I think I may be at the point that I should install AVR Studio :slight_smile:

Cheers
Chris