Skip to content
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

Define C++-compatible pin map for Argon #2187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rgiese
Copy link

@rgiese rgiese commented Sep 4, 2020

Problem

The Particle pinmap_defines.h headers establish pin IDs like SCA with a #define, meaning that any stand-alone use of the token SCA gets replaced with a number by the preprocessor. Other Arduino-based platforms don't do this. Because of Particle's headers, Particle apps cannot directly use some Arduino libraries that use a token like SCA internally, such as:

enum class TicPin
{
  SCL = 0,
  SDA = 1,
  TX  = 2,
  RX  = 3,
  RC  = 4,
};

Solution

We should use C++ to establish constants when we're building in C++. This allows library code to safely use tokens like SCA without preprocessor interference.

Since pinmap_defines.h is also used to compile some nRF platform code in C, we unfortunately need to make the pin mappings available through both C and C++ means, whichever we're compiling with. That said, these defines are unlikely to change, to put it mildly, so I think this poses a negligible maintenance burden.

This PR offers this change for the Argon platform only (since that's what I'm using for my current project). If we believe that this is overall a good idea, I'm happy to make the change for all headers and platforms.

Steps to Test

Build device-os/main with make PLATFORM=argon.


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

@rgiese
Copy link
Author

rgiese commented Sep 4, 2020

cc: @DavidEGrayson

@avtolstoy
Copy link
Member

Thanks for the PR. That's always the problem with defines with 'generic' names. We have a couple of other cases (e.g. LED_XXX) where we should move away from such names that could potentially cause problems for applications.

We will consider applying this change into the next major release (3.x). A few points:

  1. The PRs should target develop branch, master always points to the current stable release
  2. Maybe we should come up with something for C as well (e.g. use static const instead; enums won't do unfortunately as they are signed and pin_t is unsigned and we cannot change its type easily) and ideally minimize duplication as much as possible when defining pins. While the pinmap does not change, it still leaves a possibility for a mistake. Perhaps this can be overcome with tests.
  3. This is a breaking change and may break some applications/libraries which rely on #ifdef PIN_NAME

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