From 8802eb49140e0389e535cb6160d9080efd951ba7 Mon Sep 17 00:00:00 2001 From: Carlos Pereira Atencio <4189262+carlosperate@users.noreply.github.com> Date: Wed, 24 Jul 2024 17:30:20 +0100 Subject: [PATCH] Wrap `using namespace` in headers with codal config flag. (#43) Flag introduced in codal-core in: https://github.com/lancaster-university/codal-core/commit/509086cc8590465041b15493ab52b56e7071c110 By default the `using namespace` line would still be present, as removing it can cause some codal targets to break if they depend on the namespace to be set up globally. For example, the codal-microbit-v2 target had this update to fix the namespacing: https://github.com/lancaster-university/codal-microbit-v2/pull/437 This patch is part of: https://github.com/lancaster-university/codal-microbit-v2/issues/240 --- inc/NRF52ADC.h | 9 ++++++++- inc/NRF52PDM.h | 9 +++++++++ inc/NRF52PWM.h | 9 ++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/inc/NRF52ADC.h b/inc/NRF52ADC.h index 9def83c..44e0a0e 100644 --- a/inc/NRF52ADC.h +++ b/inc/NRF52ADC.h @@ -42,8 +42,12 @@ DEALINGS IN THE SOFTWARE. // #define NRF52_ADC_DATA_READY 1 - +// This "using namespace codal" cannot be removed from this header file without +// breaking targets where some .cpp files depend on it. So this config flag is +// enabled by default and keeps the namespace for compatibility. +#if CONFIG_ENABLED(CODAL_USE_GLOBAL_NAMESPACE) using namespace codal; +#endif // // NRF52ADCChannel status codes @@ -51,6 +55,8 @@ using namespace codal; #define NRF52_ADC_CHANNEL_STATUS_ENABLED 0x10 #define NRF52_ADC_CHANNEL_STATUS_CONNECTED 0x20 +namespace codal +{ class NRF52ADC; class NRF52ADCChannel : public DataSource @@ -350,5 +356,6 @@ class NRF52ADC : public CodalComponent, public PinPeripheral */ void configureSampling(); }; +} // namespace codal #endif diff --git a/inc/NRF52PDM.h b/inc/NRF52PDM.h index 691cfdc..eba7fb7 100755 --- a/inc/NRF52PDM.h +++ b/inc/NRF52PDM.h @@ -40,7 +40,15 @@ DEALINGS IN THE SOFTWARE. // #define NRF52_PDM_BUFFER_SIZE 512 +// This "using namespace codal" cannot be removed from this header file without +// breaking targets where some .cpp files depend on it. So this config flag is +// enabled by default and keeps the namespace for compatibility. +#if CONFIG_ENABLED(CODAL_USE_GLOBAL_NAMESPACE) using namespace codal; +#endif + +namespace codal +{ class NRF52PDM : public CodalComponent, public DataSource { @@ -103,5 +111,6 @@ class NRF52PDM : public CodalComponent, public DataSource void startDMA(); }; +} // namespace codal #endif diff --git a/inc/NRF52PWM.h b/inc/NRF52PWM.h index 946aa6c..362197e 100755 --- a/inc/NRF52PWM.h +++ b/inc/NRF52PWM.h @@ -15,9 +15,15 @@ #define NRF52PWM_PWM_PERIPHERALS 3 #define NRF52PWM_PWM_CHANNELS 4 - +// This "using namespace codal" cannot be removed from this header file without +// breaking targets where some .cpp files depend on it. So this config flag is +// enabled by default and keeps the namespace for compatibility. +#if CONFIG_ENABLED(CODAL_USE_GLOBAL_NAMESPACE) using namespace codal; +#endif +namespace codal +{ class NRF52PWM : public CodalComponent, public DataSink, public PinPeripheral { @@ -153,5 +159,6 @@ class NRF52PWM : public CodalComponent, public DataSink, public PinPeripheral int tryPull(uint8_t b); }; +} // namespace codal #endif