Skip to content

refactor!: namespace nRF24L01.h defines to avoid name collisions#1066

Merged
2bndy5 merged 5 commits intomasterfrom
copilot/sub-pr-1065
Apr 4, 2026
Merged

refactor!: namespace nRF24L01.h defines to avoid name collisions#1066
2bndy5 merged 5 commits intomasterfrom
copilot/sub-pr-1065

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

Converts all #define macros in nRF24L01.h to typed constants under a namespace nRF24L01 to eliminate global namespace pollution and prevent name collisions (e.g., CD, TX_DS, RX_DR).

Changes

  • nRF24L01.h:
    • Added include guards and #include <stdint.h>; replaced all #define macros with constexpr uint8_t constants inside namespace nRF24L01
    • renamed certain constants because prefixes are no longer needed inside a namespace:
      • NRF_CONFIGCONFIG
      • NRF_STATUSSTATUS
      • RF24_NOPNOP
  • RF24.h:
    • Moved #include "nRF24L01.h" from inside a typedef enum block to top-level
    • updated enum values to use nRF24L01:: prefix
  • RF24.cpp:
    • Added using namespace nRF24L01; to keep the implementation unchanged
    • updated all renamed references:
      • NRF_CONFIGCONFIG
      • NRF_STATUSSTATUS
      • RF24_NOPNOP

Migration

User code that includes nRF24L01.h and uses these constants directly must either add a using directive or qualify with the namespace prefix:

// Option A
using namespace nRF24L01;
write_register(CONFIG, ...);
spi_txbuff[0] = NOP;

// Option B
write_register(nRF24L01::CONFIG, ...);
spi_txbuff[0] = nRF24L01::NOP;

Copilot AI mentioned this pull request Apr 3, 2026
Copilot AI changed the title [WIP] [WIP] Address feedback from PR #1065 by creating separate patch for master branch refactor: namespace nRF24L01.h register defines to avoid name collisions Apr 3, 2026
Copilot AI requested a review from 2bndy5 April 3, 2026 22:39
@2bndy5

This comment was marked as resolved.

This comment was marked as resolved.

@2bndy5 2bndy5 changed the base branch from nRF54L15 to master April 4, 2026 00:51
@2bndy5 2bndy5 force-pushed the copilot/sub-pr-1065 branch from 092a00c to 38e42c7 Compare April 4, 2026 01:28
@2bndy5 2bndy5 force-pushed the copilot/sub-pr-1065 branch from 38e42c7 to 2bd5fa1 Compare April 4, 2026 01:33
@2bndy5 2bndy5 marked this pull request as ready for review April 4, 2026 01:43
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

Memory usage change @ 7c2159a

Board Flash % RAM for global variables %
arduino:avr:nano 0 - 0 0 - 0 0 - 0 0 - 0
arduino:samd:mkrzero 0 - 0 0 - 0 0 - 0 0 - 0
Click for full report per board

arduino:avr:nano

Sketch Flash % RAM for global variables %
examples/GettingStarted 0 0 0 0
examples/AcknowledgementPayloads 0 0 0 0
examples/ManualAcknowledgements 0 0 0 0
examples/StreamingData 0 0 0 0
examples/MulticeiverDemo 0 0 0 0
examples/InterruptConfigure 0 0 0 0
examples/scanner 0 0 0 0
examples/encodeRadioDetails 0 0 0 0

arduino:samd:mkrzero

Sketch Flash % RAM for global variables %
examples/GettingStarted 0 0 0 0
examples/AcknowledgementPayloads 0 0 0 0
examples/ManualAcknowledgements 0 0 0 0
examples/StreamingData 0 0 0 0
examples/MulticeiverDemo 0 0 0 0
examples/InterruptConfigure 0 0 0 0
examples/scanner 0 0 0 0
examples/encodeRadioDetails 0 0 0 0

Copy link
Copy Markdown
Member

@2bndy5 2bndy5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

No compile size consequence from switching to constexpr!

Copilot AI requested a review from 2bndy5 April 4, 2026 01:53
@2bndy5 2bndy5 changed the title refactor: namespace nRF24L01.h register defines to avoid name collisions refactor: namespace nRF24L01.h defines to avoid name collisions Apr 4, 2026
@2bndy5
Copy link
Copy Markdown
Member

2bndy5 commented Apr 4, 2026

@TMRh20 What do you think? This should prevent further name collisions in the global namespace. I also reverted patches that were done to fix previously discovered collisions.

As for breaking user code, I don't think nRF24L01.h serves any real utility for users. It would seem as though most 3rd-party tutorials still #include <nRF24L01.h> because the old examples (from maniacbug days) did that needlessly.

Copy link
Copy Markdown
Member

@2bndy5 2bndy5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

The new namespace is not confusingly added to the API docs

@TMRh20
Copy link
Copy Markdown
Member

TMRh20 commented Apr 4, 2026

I think this is a great idea instead of renaming things every time there is a naming conflict.

@2bndy5 2bndy5 changed the title refactor: namespace nRF24L01.h defines to avoid name collisions refactor!: namespace nRF24L01.h defines to avoid name collisions Apr 4, 2026
@2bndy5 2bndy5 merged commit 4c4e74e into master Apr 4, 2026
81 checks passed
@2bndy5 2bndy5 deleted the copilot/sub-pr-1065 branch April 4, 2026 06:27
This was referenced Apr 4, 2026
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.

3 participants