Understanding pins_arduino.h

Hello all,

I'm trying to use the Arduino IDE to program an ATmega8535 using ArduinoISP. I have the ArduinoISP working so far, and it is coming down to actually writing working code on the 8535. I've made the assumption that I just create a new board in the boards.txt file and create a new variant specifically for the 8535.

Well, I've made that and copied over a pins_arduino.h file to modify. The first part has been self explanatory however the arrays are now confusing me. I have a few generic/specific questions that may help me understand this file better.

In the port_to_mode_pgm[] array

const uint16_t PROGMEM port_to_mode_PGM[] = {
    NOT_A_PORT,
    NOT_A_PORT,
    (uint16_t) &DDRB,
    (uint16_t) &DDRC,
    (uint16_t) &DDRD,
};

Why is there NOT_A_PORT, what's that do and why is it there specifically?

in the digital_pin_to_port_PGM[]

const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
    PD, /* 0 */
    PD,
    PD,
    PD,
    PD,
    PD,
    PD,
    PD,
    PB, /* 8 */
    PB,
    PB,
    PB,
    PB,
    PB,
    PC, /* 14 */
    PC,
    PC,
    PC,
    PC,
    PC,
};

Why is it order the way it is? Same with the digital_pin_to_bit_mask_PGM[].

I was expecting some form of PB7 = 8, like at the beginning, but I haven't been able to make heads nor tails of the way this information is displayed.

There are 3 arrays; one calls out the ports to be used, the 2nd calls out bit for a port, the 3rd identifies if there is a timer for that bit.
The port/bit combination is then known by its place in the array, from 0 up to whatever the last element is (example 19 for a '328P, 31 for a 1284P, 53 for a Mega).
A seperate section links the Analog input name to its digital name.

Why is it order the way it is?

The arrays are indexed by the arduino BOARD "pin-number", which need not have any algorithmic mapping to AVR ports or bits at all. It may be convenient and sensible if pins 0 through 7 are PORTD0 through PORTD7, but it is not required by the Arduino environment. (You can see this in action on the MEGA version of pins_arduino.h)

Thank you. I noticed that in the MEGA header, and I was, well, baffled by the order.

Now, what of the digitalPinToPCICR(p) macro, and the other similar ones? They seem quite odd. That and I'm not 100% up on my C.

Yeah, I can't read those either. Cryptic uncommented C-code. There's got to be a "longhand" way to write those that's more readable but still compiles down the same way.

I wonder why those aren't put in arrays also?

Did you by any chance get it to work? I am myself working on a project where I want to use the 8535 and right now I am at the exact same step - I want to compile my code for this particular chip.

If you got it to work, could you explain what needed to be changed in which files and/or provide the necessary files?

thanks in advance, wiseman