Go Down

Topic: portOutputRegister and portInputRegister are useless (Read 2299 times) previous topic - next topic

Baltasar

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:

Code: [Select]
g_APinDescription[ulPin].pPort -> PIO_OWER = g_APinDescription[ulPin].ulPin;
Check all my projects based on Atmel/Arduino -> www.aqualed-light.com

cmaglie


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).

C.

Baltasar

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.
Check all my projects based on Atmel/Arduino -> www.aqualed-light.com

cmaglie

Baltasar,

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

https://github.com/arduino/Arduino/commit/74dea07f2c7e977bacf5c61f7e8502609b285dbb

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:

Code: [Select]


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);
}

C.

Paul Stoffregen

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

cmaglie

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:

Code: [Select]

typedef volatile uint32_t *OutputRegister;


together with portOutputRegister?
C.

Go Up