Skip to content

Define digital pins via static const instead of #define #54

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

Merged
merged 5 commits into from
Jul 31, 2023

Conversation

mjs513
Copy link
Contributor

@mjs513 mjs513 commented Jul 18, 2023

@aentinger
Sorry for the delay in getting this to you. Got side tracked with a weird issue as I was trying to get the Encoder library updated so people can use with the R4 boards. But in accordance with your request for me to submit a PR for [ArduinoEigen] Pin Definitions Conflict with Sketch/Library Variables when used with ArduinoCore-renesas Issue #50 this is the update. As I mentioned "constexpr" throws a error so I left it as const like the analog pins. Out of curiosity what version of c++ are the R4 using?

regards
Mike

@CLAassistant
Copy link

CLAassistant commented Jul 18, 2023

CLA assistant check
All committers have signed the CLA.

@aentinger aentinger changed the title update for digital pin definitions Define digital pins via static const instead of #define Jul 18, 2023
@aentinger
Copy link
Contributor

Out of curiosity what version of c++ are the R4 using?

C++17, see here.

Consequently constexpr should not be a problem.

Mind updating the PR accordingly?, i.e. constexpr uint8_t D0 = PIN_D0;.

@mjs513
Copy link
Contributor Author

mjs513 commented Jul 18, 2023

@aentinger - done. Faster turn time than yesterday. But if I try to compile this example on the minima:

void setup() {
  Serial.begin(115200);
  while(!Serial && millis() < 5000) {}
  int D0 = 1;
  Serial.println(D0);
  //digitalWrite(D0, HIGH);
}

void loop() {}

I will get this error using constexpr:


C:\Users\Merli\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\variants\MINIMA/pins_arduino.h:75:8: error: unknown type name 'constexpr'
 static constexpr uint8_t D0 = PIN_D0;
        ^~~~~~~~~
C:\Users\Merli\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\variants\MINIMA/pins_arduino.h:75:26: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'D0'
 static constexpr uint8_t D0 = PIN_D0;

@aentinger
Copy link
Contributor

Well, I get a lot of errors, but none like you ... 🤔

/home/alex/Arduino/hardware/arduino-git/renesas/variants/UNOWIFIR4/pins_arduino.h:54:31: error: 'PIN_D0' was not declared in this scope
 static constexpr uint8_t D0 = PIN_D0;
                               ^~~~~~
/home/alex/Arduino/hardware/arduino-git/renesas/variants/UNOWIFIR4/pins_arduino.h:54:31: note: suggested alternative: 'PIN_A0'
 static constexpr uint8_t D0 = PIN_D0;
                               ^~~~~~
                               PIN_A0
/home/alex/Arduino/hardware/arduino-git/renesas/variants/UNOWIFIR4/pins_arduino.h:55:31: error: 'PIN_D1' was not declared in this scope
 static constexpr uint8_t D1 = PIN_D1;
                               ^~~~~~

@mjs513
Copy link
Contributor Author

mjs513 commented Jul 18, 2023

oops - darn copy and paste error. Just pushed the fix to clear up the errors you are seeing.

@aentinger
Copy link
Contributor

I suppose you'll also need to extend support for Portenta C33?

@mjs513
Copy link
Contributor Author

mjs513 commented Jul 18, 2023 via email

@mjs513
Copy link
Contributor Author

mjs513 commented Jul 18, 2023

Ok - updated.

@aentinger
Copy link
Contributor

It seems the problem is that Arduino.h and by extension pins_arduino.h produce an error when included into a C file, i.e. cortex_handlers.c in this case.

Try renaming cortex_handlers.c to .cpp and prefix Stacktrace_Handler with extern "C":

-void Stacktrace_Handler(void) {
+extern "C" void Stacktrace_Handler(void) {

@aentinger
Copy link
Contributor

I've reconsidered, drop constexpr and let's go with const as you've proposed since it will provide broader compatibility.

@mjs513
Copy link
Contributor Author

mjs513 commented Jul 24, 2023

@aentinger
Revert back to const . And Welcome back.

@facchinm facchinm merged commit cda972e into arduino:main Jul 31, 2023
@facchinm
Copy link
Member

Merged, thank you!

pennam pushed a commit to pennam/ArduinoCore-renesas that referenced this pull request Aug 9, 2023
cristidragomir97 pushed a commit to cristidragomir97/ArduinoCore-renesas that referenced this pull request May 20, 2024
Muxto i2c support and gpio bug fix

Former-commit-id: 1873eaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants