From 16dda9b1882940035e76eca6ff6710233651dbe3 Mon Sep 17 00:00:00 2001 From: Carlos Pereira Atencio Date: Sat, 31 Dec 2022 19:34:04 +0000 Subject: [PATCH] Replace `using namespace` in headers with explicit namespaces. --- inc/NRF52ADC.h | 6 +++--- inc/NRF52PDM.h | 4 +++- inc/NRF52PWM.h | 7 ++++++- inc/neopixel.h | 3 +++ source/NRF52ADC.cpp | 2 ++ source/NRF52PDM.cpp | 2 ++ source/NRF52PWM.cpp | 2 ++ source/neopixel.cpp | 4 +++- 8 files changed, 24 insertions(+), 6 deletions(-) diff --git a/inc/NRF52ADC.h b/inc/NRF52ADC.h index 398f104..7ff29a3 100644 --- a/inc/NRF52ADC.h +++ b/inc/NRF52ADC.h @@ -42,15 +42,14 @@ 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 +namespace codal +{ class NRF52ADC; class NRF52ADCChannel : public DataSource @@ -329,5 +328,6 @@ class NRF52ADC : public CodalComponent */ void configureSampling(); }; +} // namespace codal #endif diff --git a/inc/NRF52PDM.h b/inc/NRF52PDM.h index 691cfdc..eb0ce8f 100755 --- a/inc/NRF52PDM.h +++ b/inc/NRF52PDM.h @@ -40,7 +40,8 @@ DEALINGS IN THE SOFTWARE. // #define NRF52_PDM_BUFFER_SIZE 512 -using namespace codal; +namespace codal +{ class NRF52PDM : public CodalComponent, public DataSource { @@ -103,5 +104,6 @@ class NRF52PDM : public CodalComponent, public DataSource void startDMA(); }; +} // namespace codal #endif diff --git a/inc/NRF52PWM.h b/inc/NRF52PWM.h index d0ee324..dc41227 100755 --- a/inc/NRF52PWM.h +++ b/inc/NRF52PWM.h @@ -15,9 +15,13 @@ #define NRF52PWM_PWM_PERIPHERALS 3 #define NRF52PWM_PWM_CHANNELS 4 - +// TODO: Currently other CODAL libraries depend on this global namespace to +// compile, once those are fixed `using namespace codal;` line can be removed +// https://github.com/lancaster-university/codal-nrf52/pull/43 using namespace codal; +namespace codal +{ class NRF52PWM : public CodalComponent, public DataSink { @@ -147,5 +151,6 @@ class NRF52PWM : public CodalComponent, public DataSink int tryPull(uint8_t b); }; +} // namespace codal #endif diff --git a/inc/neopixel.h b/inc/neopixel.h index cbb9f15..2268fc5 100644 --- a/inc/neopixel.h +++ b/inc/neopixel.h @@ -12,7 +12,10 @@ #include "NRF52PWM.h" #include "WS2812B.h" +namespace codal +{ void neopixel_send_buffer(Pin &pin, const uint8_t *ptr, int numBytes); void neopixel_send_buffer(Pin &pin, ManagedBuffer buffer); +} #endif // CODAL_NEOPIXEL_H diff --git a/source/NRF52ADC.cpp b/source/NRF52ADC.cpp index 30cc2c5..2cf3fa5 100644 --- a/source/NRF52ADC.cpp +++ b/source/NRF52ADC.cpp @@ -29,6 +29,8 @@ DEALINGS IN THE SOFTWARE. #include "nrf.h" #include "cmsis.h" +using namespace codal; + // Calculation to determine the optimal usable space for a DMA buffer for the given number of channels #define NRF52ADC_DMA_ALIGNED_SIZED(c) ((bufferSize - (bufferSize % (c * 2 * softwareOversample)))/2); diff --git a/source/NRF52PDM.cpp b/source/NRF52PDM.cpp index e2878c3..02c6857 100755 --- a/source/NRF52PDM.cpp +++ b/source/NRF52PDM.cpp @@ -26,6 +26,8 @@ DEALINGS IN THE SOFTWARE. #include "NRF52PDM.h" #include "nrf.h" +using namespace codal; + // Handle on the last (and probably only) instance of this class (NRF52 has only one PDM module) static NRF52PDM *nrf52_pdm_driver = NULL; diff --git a/source/NRF52PWM.cpp b/source/NRF52PWM.cpp index f2178cf..cf7d121 100755 --- a/source/NRF52PWM.cpp +++ b/source/NRF52PWM.cpp @@ -2,6 +2,8 @@ #include "nrf.h" #include "cmsis.h" +using namespace codal; + #define NRF52PWM_EMPTY_BUFFERSIZE 8 static uint16_t emptyBuffer[NRF52PWM_EMPTY_BUFFERSIZE]; diff --git a/source/neopixel.cpp b/source/neopixel.cpp index f228f54..f325141 100644 --- a/source/neopixel.cpp +++ b/source/neopixel.cpp @@ -4,6 +4,8 @@ #include "neopixel.h" +using namespace codal; + #if CONFIG_ENABLED(HARDWARE_NEOPIXEL) void neopixel_send_buffer(Pin &pin, const uint8_t *ptr, int numBytes) @@ -88,5 +90,5 @@ __attribute__((noinline)) void neopixel_send_buffer(Pin &pin, const uint8_t *ptr void neopixel_send_buffer(Pin &pin, ManagedBuffer buffer) { - neopixel_send_buffer(pin, &buffer[0], buffer.length()); + codal::neopixel_send_buffer(pin, &buffer[0], buffer.length()); }