From 4a4cdba890cd0b563d3d9bfb8cbd5d78fd764a66 Mon Sep 17 00:00:00 2001 From: Carlos Pereira Atencio Date: Sat, 31 Dec 2022 19:34:04 +0000 Subject: [PATCH] Wrap `using namespace` in headers with codal config flag. 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 header file to set up this namespace 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 | 13 ++++++++++--- inc/NRF52PDM.h | 9 +++++++++ inc/NRF52PWM.h | 9 ++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/inc/NRF52ADC.h b/inc/NRF52ADC.h index 9def83c..b8c8311 100644 --- a/inc/NRF52ADC.h +++ b/inc/NRF52ADC.h @@ -42,15 +42,21 @@ DEALINGS IN THE SOFTWARE. // #define NRF52_ADC_DATA_READY 1 - -using namespace codal; - // // NRF52ADCChannel status codes // #define NRF52_ADC_CHANNEL_STATUS_ENABLED 0x10 #define NRF52_ADC_CHANNEL_STATUS_CONNECTED 0x20 +// 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 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