Pages: [1]   Go Down
Author Topic: portOutputRegister and portInputRegister are useless  (Read 1919 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino DUE rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
g_APinDescription[ulPin].pPort -> PIO_OWER = g_APinDescription[ulPin].ulPin;
Logged

Check all my projects based on Atmel/Arduino -> www.aqualed-light.com

Forum Administrator
Milano, Italy
Offline Offline
Sr. Member
*****
Karma: 23
Posts: 292
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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

Logged

C.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino DUE rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Check all my projects based on Atmel/Arduino -> www.aqualed-light.com

Forum Administrator
Milano, Italy
Offline Offline
Sr. Member
*****
Karma: 23
Posts: 292
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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

C.

0
Offline Offline
God Member
*****
Karma: 25
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Forum Administrator
Milano, Italy
Offline Offline
Sr. Member
*****
Karma: 23
Posts: 292
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
typedef volatile uint32_t *OutputRegister;

together with portOutputRegister?
Logged

C.

Pages: [1]   Go Up
Jump to: