portOutputRegister and portInputRegister are useless

This macros are useless or they don't do nothing as pinMode(pinX,OUTPUT); comand does not turn on the PIO_OWER register need for operations on PIO_ODSR and PIO_PDSR.

I think some sort of code like this inside the pinMode void on OUTPUT case will solve that:

g_APinDescription[ulPin].pPort -> PIO_OWER = g_APinDescription[ulPin].ulPin;

I need to check if setting OWER has some other side-effects (from the datasheet seems not, but the fact that is disable by default makes me some suspect).

Ok sorry I just realised now that alvesjc allready reported the same.

Yes you should check it, but I think for keeping compatibility with most of the code out there since for normal Arduinos the macros get someting that can be used straight without the need of further comands and that should be good with users thinking that doesn't work as there is nothing documented anyware related this specifc cases.

Baltasar,

it should work now, I prefer to do something like this:

by looking the datasheet and asking advice to Atmel, we shouldn't have any side effects in doing this. (I hope.........)

here my test sketch:

volatile uint32_t *REG;
uint32_t MASK;

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  REG = portOutputRegister(digitalPinToPort(13));
  MASK = digitalPinToBitMask(13);
}


void loop() {
  Serial.println("ON");
  *REG |= MASK;
  delay(1000);
  Serial.println("OFF");
  *REG &= ~MASK;
  delay(1000);
}

The Arduino world is filled with code with stores the bitmask in a uint8_t and the address in a uint8_t *.

Paul good point,

from a compatibility point of view: we should ensure that these macros returns an uint8_t *, so the libraries made for AVR could work without (or with less) effort.

from an API point of view: portOutputRegister returns a pointer to the Output Register (as the macro name suggests) and I expect this pointer to be of same size of the register.

Maybe we should add something like:

typedef volatile uint32_t *OutputRegister;

together with portOutputRegister?