Skip to content

pin initialization #428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sslupsky opened this issue Jul 3, 2019 · 5 comments
Closed

pin initialization #428

sslupsky opened this issue Jul 3, 2019 · 5 comments
Labels

Comments

@sslupsky
Copy link

sslupsky commented Jul 3, 2019

Pin initialization appears to default to "INPUT" per PR #28 to maintain compatibility with AVR Arduinos. It is not clear to me what the consequence is if this was changed. Could someone please explain why this is necessary?

I would like to suggest that the pins should be initialized according to their definition in the boards corresponding variant.cpp file as follows:

// Setup all pins as configured in variant.c
  for (uint32_t ul = 0 ; ul < PINS_COUNT ; ul++ )
  {
    pinPeripheral( ul, g_APinDescription[ul].ulPinType );
  }
}

That would ensure that there is no confusion regarding what the intended "default" state of the pins is when the initialization is complete.

@sandeepmistry
Copy link
Contributor

Hi @sslupsky,

This was done to maintain compatibility with AVR, where the default modes of pins in INPUT.

@sslupsky
Copy link
Author

I see. Could a compiler directive be used to selectively set the mode to inputs if AVR otherwise, use the variant?

@sandeepmistry
Copy link
Contributor

Sorry, it's not clear what you mean. I was talking more about existing sketches that run on AVR could run on SAMD boards as is, if they don't explicitly set the pin mode to input.

@sslupsky
Copy link
Author

Ok. I mistakenly thought the issue was to ensure existing AVR sketches would run on AVR hardware.

Perhaps the best way then is to use an approach similar to what is done with the new VERY_LOW_POWER directive. However, instead of not initializing the pins at all, initialize them as described by the variant definition (variant.cpp).

The VERY_LOW_POWER directive itself mostly addresses this issue though since the original motivation was to avoid excessive current.

@facchinm
Copy link
Member

Yup, VERY_LOW_POWER defines targets exactly this problem, not by initializing all the pins to the expected function but avoiding any initialization and waiting for the proper user action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants