From a46c58c6fb453b2d929cd922e9bce2fe7acd5413 Mon Sep 17 00:00:00 2001 From: Carlos Pereira Atencio Date: Tue, 23 Jul 2024 11:12:30 +0100 Subject: [PATCH] Ensure header files and .cpp files use the codal namespace appropriately. Also update the codal-core and codal-nrf52 dependencies as they include changes on the same topic. The classes declared in the Mbed compatibility header files have not been wrapped in the codal namespace, as programmes including the mbed.h header might not expect them to be inside that namespace. This header file is not included in any of the codal-microbit-v2 or dependencies, it's mostly used by MakeCode extensions that were accessing Mbed-specific libraries in micro:bit V1. --- inc/MicroBitBLEChar.h | 7 ++++-- inc/MicroBitBLEService.h | 8 +++++-- inc/MicroBitBLEServices.h | 7 ++++-- inc/MicroBitDevice.h | 2 -- inc/MicroBitFile.h | 5 +++++ inc/MicroBitFileSystem.h | 4 ++++ inc/MicroBitFlash.h | 5 +++++ inc/MicroBitMemoryMap.h | 5 +++++ inc/MicroBitPowerManager.h | 5 +++++ inc/MicroBitUSBFlashManager.h | 6 +++++ inc/bluetooth/MicroBitAccelerometerService.h | 7 ++++-- inc/bluetooth/MicroBitBLEManager.h | 9 ++++++-- inc/bluetooth/MicroBitBLETypes.h | 9 ++++++-- inc/bluetooth/MicroBitButtonService.h | 7 ++++-- inc/bluetooth/MicroBitEddystone.h | 9 ++++++-- inc/bluetooth/MicroBitEventService.h | 7 ++++-- inc/bluetooth/MicroBitIOPinService.h | 9 ++++++-- inc/bluetooth/MicroBitLEDService.h | 7 ++++-- inc/bluetooth/MicroBitMagnetometerService.h | 8 +++++-- .../MicroBitPartialFlashingService.h | 7 ++++-- inc/bluetooth/MicroBitTemperatureService.h | 7 ++++-- inc/bluetooth/MicroBitUARTService.h | 9 ++++++-- inc/bluetooth/MicroBitUtilityService.h | 7 ++++-- inc/bluetooth/MicroBitUtilityTypes.h | 2 +- inc/compat/DigitalIn.h | 12 +++++----- inc/compat/DigitalOut.h | 12 +++++----- inc/compat/InterruptIn.h | 22 +++++++++---------- inc/compat/MbedTimer.h | 14 ++++++------ inc/compat/MicroBitCompat.h | 2 -- inc/compat/PwmOut.h | 4 ++-- inc/compat/Ticker.h | 14 ++++++------ inc/compat/Timeout.h | 14 ++++++------ model/MicroBit.h | 3 ++- source/MicroBitFile.cpp | 2 ++ source/MicroBitFileSystem.cpp | 2 ++ source/MicroBitMemoryMap.cpp | 2 ++ source/MicroBitPowerManager.cpp | 2 ++ source/MicroBitUSBFlashManager.cpp | 2 ++ source/MicroSynth.cpp | 2 ++ source/SoundExpressions.cpp | 2 ++ .../MicroBitAccelerometerService.cpp | 1 + source/bluetooth/MicroBitBLEChar.cpp | 2 ++ source/bluetooth/MicroBitBLEManager.cpp | 1 + source/bluetooth/MicroBitBLEService.cpp | 1 + source/bluetooth/MicroBitBLEServices.cpp | 1 + source/bluetooth/MicroBitBLETypes.cpp | 1 + source/bluetooth/MicroBitButtonService.cpp | 2 ++ source/bluetooth/MicroBitEddystone.cpp | 2 ++ source/bluetooth/MicroBitEventService.cpp | 1 + source/bluetooth/MicroBitIOPinService.cpp | 2 ++ source/bluetooth/MicroBitLEDService.cpp | 1 + .../bluetooth/MicroBitMagnetometerService.cpp | 1 + .../bluetooth/MicroBitTemperatureService.cpp | 1 + source/bluetooth/MicroBitUARTService.cpp | 1 + source/bluetooth/MicroBitUtilityService.cpp | 17 ++++++-------- target-locked.json | 4 ++-- 56 files changed, 212 insertions(+), 96 deletions(-) diff --git a/inc/MicroBitBLEChar.h b/inc/MicroBitBLEChar.h index ed9b4953..d7a17858 100644 --- a/inc/MicroBitBLEChar.h +++ b/inc/MicroBitBLEChar.h @@ -32,6 +32,8 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitBLETypes.h" +namespace codal +{ /** * Class definition for MicroBitBLEChar. @@ -67,6 +69,7 @@ class MicroBitBLEChar uint16_t cccd; }; +} // namespace codal -#endif -#endif +#endif // CONFIG_ENABLED(DEVICE_BLE) +#endif // MICROBIT_BLE_CHAR_H diff --git a/inc/MicroBitBLEService.h b/inc/MicroBitBLEService.h index 219800ba..6fd2f169 100644 --- a/inc/MicroBitBLEService.h +++ b/inc/MicroBitBLEService.h @@ -32,6 +32,9 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitBLEChar.h" +namespace codal +{ + /** * Class definition for MicroBitBLEService. * Provides a base class for the BLE sevices. @@ -141,6 +144,7 @@ class MicroBitBLEService static const uint8_t bs_base_uuid[16]; }; +} // namespace codal -#endif -#endif +#endif // CONFIG_ENABLED(DEVICE_BLE) +#endif // MICROBIT_BLE_SERVICE_H diff --git a/inc/MicroBitBLEServices.h b/inc/MicroBitBLEServices.h index 279cd0e9..6c6941a1 100644 --- a/inc/MicroBitBLEServices.h +++ b/inc/MicroBitBLEServices.h @@ -41,6 +41,8 @@ DEALINGS IN THE SOFTWARE. #define MICROBIT_BLE_SERVICES_OBSERVER_PRIO 2 #endif +namespace codal +{ /** * Class definition for MicroBitBLEServices. @@ -74,6 +76,7 @@ class MicroBitBLEServices MicroBitBLEService *bs_services[ MICROBIT_BLE_SERVICES_MAX]; }; +} // namespace codal -#endif -#endif +#endif // CONFIG_ENABLED(DEVICE_BLE) +#endif // MICROBIT_BLE_SERVICES_H diff --git a/inc/MicroBitDevice.h b/inc/MicroBitDevice.h index a95cd68f..935d0277 100644 --- a/inc/MicroBitDevice.h +++ b/inc/MicroBitDevice.h @@ -170,6 +170,4 @@ namespace codal extern codal::MicroBitDevice *microbit_device_instance; -using namespace codal; - #endif diff --git a/inc/MicroBitFile.h b/inc/MicroBitFile.h index a43fed54..8c5da7b7 100644 --- a/inc/MicroBitFile.h +++ b/inc/MicroBitFile.h @@ -31,6 +31,9 @@ DEALINGS IN THE SOFTWARE. #define READ_AND_WRITE READ | WRITE #define CREATE MB_CREAT +namespace codal +{ + class MicroBitFile { @@ -192,4 +195,6 @@ class MicroBitFile ~MicroBitFile(); }; +} // namespace codal + #endif diff --git a/inc/MicroBitFileSystem.h b/inc/MicroBitFileSystem.h index 82c59b58..584c810a 100644 --- a/inc/MicroBitFileSystem.h +++ b/inc/MicroBitFileSystem.h @@ -61,6 +61,8 @@ DEALINGS IN THE SOFTWARE. #define MBFS_BLOCK_TYPE_DIRECTORY 2 #define MBFS_BLOCK_TYPE_FILETABLE 3 +namespace codal +{ // // Every file in the file system has a file descriptor. @@ -517,4 +519,6 @@ class MicroBitFileSystem int createDirectory(char const *name); }; +} // namespace codal + #endif diff --git a/inc/MicroBitFlash.h b/inc/MicroBitFlash.h index c510ca73..a9461e2b 100644 --- a/inc/MicroBitFlash.h +++ b/inc/MicroBitFlash.h @@ -24,6 +24,9 @@ DEALINGS IN THE SOFTWARE. #include "nrf.h" +namespace codal +{ + class MicroBitFlash { private: @@ -86,4 +89,6 @@ class MicroBitFlash }; +} // namespace codal + #endif diff --git a/inc/MicroBitMemoryMap.h b/inc/MicroBitMemoryMap.h index 3348a881..1fb34cab 100644 --- a/inc/MicroBitMemoryMap.h +++ b/inc/MicroBitMemoryMap.h @@ -36,6 +36,9 @@ DEALINGS IN THE SOFTWARE. #define REGION_MAKECODE 2 #define REGION_PYTHON 3 +namespace codal +{ + /** * Structure definition for the reserved, noinit memory segment placed at the end of memory. */ @@ -142,4 +145,6 @@ class MicroBitMemoryMap int processRecord(uint32_t *address); }; +} // namespace codal + #endif diff --git a/inc/MicroBitPowerManager.h b/inc/MicroBitPowerManager.h index 143d4fca..f765c4c5 100644 --- a/inc/MicroBitPowerManager.h +++ b/inc/MicroBitPowerManager.h @@ -164,6 +164,8 @@ typedef struct { #define CONFIG_MINIMUM_POWER_ON_TIME 500 #endif +namespace codal +{ /** * Class definition for MicroBitPowerManager. @@ -479,4 +481,7 @@ class MicroBitPowerManager : public CodalComponent */ int simpleDeepSleep( bool wakeOnTime, CODAL_TIMESTAMP wakeUpTime, bool wakeUpSources, NRF52Pin *wakeUpPin); }; + +} // namespace codal + #endif diff --git a/inc/MicroBitUSBFlashManager.h b/inc/MicroBitUSBFlashManager.h index 9991a5c5..f4cde378 100644 --- a/inc/MicroBitUSBFlashManager.h +++ b/inc/MicroBitUSBFlashManager.h @@ -74,6 +74,9 @@ DEALINGS IN THE SOFTWARE. #define MICROBIT_USB_FLASH_WRITE_CMD 0x0B // Perform a WRITE operation from applicaiton FLASH memory. #define MICROBIT_USB_FLASH_ERASE_CMD 0x0C // Perform a ERASE operation from applicaiton FLASH memory. +namespace codal +{ + typedef struct { ManagedString fileName; // MUST be in 8.3 format @@ -290,4 +293,7 @@ class MicroBitUSBFlashManager : public CodalComponent, public NVMController bool isValidChar(char c); }; + +} // namespace codal + #endif diff --git a/inc/bluetooth/MicroBitAccelerometerService.h b/inc/bluetooth/MicroBitAccelerometerService.h index b2848074..62e673d6 100644 --- a/inc/bluetooth/MicroBitAccelerometerService.h +++ b/inc/bluetooth/MicroBitAccelerometerService.h @@ -35,6 +35,8 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitAccelerometer.h" #include "EventModel.h" +namespace codal +{ /** * Class definition for a MicroBit BLE Accelerometer Service. @@ -110,6 +112,7 @@ class MicroBitAccelerometerService : public MicroBitBLEService MicroBitBLEChar *characteristicPtr( int idx) { return &chars[ idx]; }; }; +} // namespace codal -#endif -#endif +#endif // CONFIG_ENABLED(DEVICE_BLE) +#endif // MICROBIT_ACCELEROMETER_SERVICE_H diff --git a/inc/bluetooth/MicroBitBLEManager.h b/inc/bluetooth/MicroBitBLEManager.h index af655d74..438679f2 100644 --- a/inc/bluetooth/MicroBitBLEManager.h +++ b/inc/bluetooth/MicroBitBLEManager.h @@ -62,6 +62,9 @@ DEALINGS IN THE SOFTWARE. #define MICROBIT_MODE_PAIRING 0 #define MICROBIT_MODE_APPLICATION 1 +namespace codal +{ + class MicroBitBLEManager; typedef MicroBitBLEManager BLEDevice; @@ -322,6 +325,8 @@ class MicroBitBLEManager : public CodalComponent bool advertiseOnDisconnect = true; }; -#endif +} // namespace codal -#endif +#endif // CONFIG_ENABLED(DEVICE_BLE) + +#endif // MICROBIT_BLE_MANAGER_H diff --git a/inc/bluetooth/MicroBitBLETypes.h b/inc/bluetooth/MicroBitBLETypes.h index 000be358..159a9ee0 100644 --- a/inc/bluetooth/MicroBitBLETypes.h +++ b/inc/bluetooth/MicroBitBLETypes.h @@ -95,6 +95,9 @@ DEALINGS IN THE SOFTWARE. #include "ble.h" #include "ble_gatts.h" +namespace codal +{ + typedef uint32_t microbit_ble_ret_code_t; typedef uint16_t microbit_gaphandle_t; typedef uint16_t microbit_servicehandle_t; @@ -142,6 +145,8 @@ extern microbit_ble_ret_code_t microbit_ble_on_error( microbit_ble_ret_code_t er #define MICROBIT_BLE_ECHK( err) (err) #endif -#endif +} // namespace codal -#endif +#endif // CONFIG_ENABLED(DEVICE_BLE) + +#endif // MICROBIT_BLE_TYPES_H diff --git a/inc/bluetooth/MicroBitButtonService.h b/inc/bluetooth/MicroBitButtonService.h index 2b4fefbf..6ae868d0 100644 --- a/inc/bluetooth/MicroBitButtonService.h +++ b/inc/bluetooth/MicroBitButtonService.h @@ -34,6 +34,8 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitBLEService.h" #include "EventModel.h" +namespace codal +{ /** * Class definition for a MicroBit BLE Button Service. @@ -102,6 +104,7 @@ class MicroBitButtonService : public MicroBitBLEService MicroBitBLEChar *characteristicPtr( int idx) { return &chars[ idx]; }; }; +} // namespace codal -#endif -#endif +#endif // CONFIG_ENABLED(DEVICE_BLE) +#endif // MICROBIT_BUTTON_SERVICE_H diff --git a/inc/bluetooth/MicroBitEddystone.h b/inc/bluetooth/MicroBitEddystone.h index 2e4a8979..2ed51f90 100644 --- a/inc/bluetooth/MicroBitEddystone.h +++ b/inc/bluetooth/MicroBitEddystone.h @@ -40,6 +40,9 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitBLEManager.h" +namespace codal +{ + /** * Class definition for the MicroBitEddystone. * @@ -109,5 +112,7 @@ class MicroBitEddystone static MicroBitEddystone *_instance; }; -#endif -#endif +} // namespace codal + +#endif // CONFIG_ENABLED(DEVICE_BLE) +#endif // MICROBIT_EDDYSTONE_H diff --git a/inc/bluetooth/MicroBitEventService.h b/inc/bluetooth/MicroBitEventService.h index 6920c83c..580f8f11 100644 --- a/inc/bluetooth/MicroBitEventService.h +++ b/inc/bluetooth/MicroBitEventService.h @@ -35,6 +35,8 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitEvent.h" #include "EventModel.h" +namespace codal +{ struct EventServiceEvent { @@ -121,6 +123,7 @@ class MicroBitEventService : public MicroBitBLEService, MicroBitComponent MicroBitBLEChar *characteristicPtr( int idx) { return &chars[ idx]; }; }; +} // namespace codal -#endif -#endif +#endif // CONFIG_ENABLED(DEVICE_BLE) +#endif // MICROBIT_EVENT_SERVICE_H diff --git a/inc/bluetooth/MicroBitIOPinService.h b/inc/bluetooth/MicroBitIOPinService.h index 2ba80176..752f0ffc 100644 --- a/inc/bluetooth/MicroBitIOPinService.h +++ b/inc/bluetooth/MicroBitIOPinService.h @@ -38,6 +38,9 @@ DEALINGS IN THE SOFTWARE. #define MICROBIT_IO_PIN_SERVICE_DATA_SIZE 10 #define MICROBIT_PWM_PIN_SERVICE_DATA_SIZE 2 +namespace codal +{ + /** * Name value pair definition, as used to read and write pin values over BLE. */ @@ -172,5 +175,7 @@ class MicroBitIOPinService : public MicroBitBLEService, MicroBitComponent MicroBitBLEChar *characteristicPtr( int idx) { return &chars[ idx]; }; }; -#endif -#endif +} // namespace codal + +#endif // CONFIG_ENABLED(DEVICE_BLE) +#endif // MICROBIT_IO_PIN_SERVICE_H diff --git a/inc/bluetooth/MicroBitLEDService.h b/inc/bluetooth/MicroBitLEDService.h index 29396cf7..d603ed4a 100644 --- a/inc/bluetooth/MicroBitLEDService.h +++ b/inc/bluetooth/MicroBitLEDService.h @@ -38,6 +38,8 @@ DEALINGS IN THE SOFTWARE. // the maximum string length that can be scrolled via the BLE service. #define MICROBIT_BLE_MAXIMUM_SCROLLTEXT 20 +namespace codal +{ /** * Class definition for the custom MicroBit LED Service. @@ -98,6 +100,7 @@ class MicroBitLEDService : public MicroBitBLEService MicroBitBLEChar *characteristicPtr( int idx) { return &chars[ idx]; }; }; +} // namespace codal -#endif -#endif +#endif // CONFIG_ENABLED(DEVICE_BLE) +#endif // MICROBIT_LED_SERVICE_H diff --git a/inc/bluetooth/MicroBitMagnetometerService.h b/inc/bluetooth/MicroBitMagnetometerService.h index 8b948747..04266ef7 100644 --- a/inc/bluetooth/MicroBitMagnetometerService.h +++ b/inc/bluetooth/MicroBitMagnetometerService.h @@ -40,6 +40,8 @@ DEALINGS IN THE SOFTWARE. #define COMPASS_CALIBRATION_COMPLETED_OK 2 #define COMPASS_CALIBRATION_COMPLETED_ERR 3 +namespace codal +{ /** * Class definition for the MicroBit BLE Magnetometer Service. @@ -138,5 +140,7 @@ class MicroBitMagnetometerService : public MicroBitBLEService MicroBitBLEChar *characteristicPtr( int idx) { return &chars[ idx]; }; }; -#endif -#endif +} // namespace codal + +#endif // CONFIG_ENABLED(DEVICE_BLE) +#endif // MICROBIT_MAGNETOMETER_SERVICE_H diff --git a/inc/bluetooth/MicroBitPartialFlashingService.h b/inc/bluetooth/MicroBitPartialFlashingService.h index ea0fb599..d7f3ea61 100644 --- a/inc/bluetooth/MicroBitPartialFlashingService.h +++ b/inc/bluetooth/MicroBitPartialFlashingService.h @@ -51,6 +51,8 @@ DEALINGS IN THE SOFTWARE. #define MICROBIT_STATUS 0xEE #define MICROBIT_RESET 0xFF +namespace codal +{ /** * Class definition for the custom MicroBit Partial Flash Service. @@ -129,6 +131,7 @@ class MicroBitPartialFlashingService : public MicroBitBLEService MicroBitBLEChar *characteristicPtr( int idx) { return &chars[ idx]; }; }; +} // namespace -#endif -#endif +#endif // CONFIG_ENABLED(DEVICE_BLE) +#endif // MICROBIT_PARTIAL_FLASH_SERVICE_H diff --git a/inc/bluetooth/MicroBitTemperatureService.h b/inc/bluetooth/MicroBitTemperatureService.h index df3b93eb..176030f6 100644 --- a/inc/bluetooth/MicroBitTemperatureService.h +++ b/inc/bluetooth/MicroBitTemperatureService.h @@ -35,6 +35,8 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitThermometer.h" #include "EventModel.h" +namespace codal +{ /** * Class definition for the custom MicroBit Temperature Service. @@ -106,6 +108,7 @@ class MicroBitTemperatureService : public MicroBitBLEService MicroBitBLEChar *characteristicPtr( int idx) { return &chars[ idx]; }; }; +} // namespace codal -#endif -#endif +#endif // CONFIG_ENABLED(DEVICE_BLE) +#endif // MICROBIT_TEMPERATURE_SERVICE_H diff --git a/inc/bluetooth/MicroBitUARTService.h b/inc/bluetooth/MicroBitUARTService.h index 804f34c5..1cbb1c91 100644 --- a/inc/bluetooth/MicroBitUARTService.h +++ b/inc/bluetooth/MicroBitUARTService.h @@ -40,6 +40,9 @@ DEALINGS IN THE SOFTWARE. #define MICROBIT_UART_S_EVT_HEAD_MATCH 2 #define MICROBIT_UART_S_EVT_RX_FULL 3 +namespace codal +{ + /** * Class definition for the custom MicroBit UART Service. * Provides a BLE service that acts as a UART port, enabling the reception and transmission @@ -341,5 +344,7 @@ class MicroBitUARTService : public MicroBitBLEService MicroBitBLEChar *characteristicPtr( int idx) { return &chars[ idx]; }; }; -#endif -#endif +} // namespace codal + +#endif // CONFIG_ENABLED(DEVICE_BLE) +#endif // MICROBIT_UART_SERVICE_H diff --git a/inc/bluetooth/MicroBitUtilityService.h b/inc/bluetooth/MicroBitUtilityService.h index 91d528e3..19428ae5 100644 --- a/inc/bluetooth/MicroBitUtilityService.h +++ b/inc/bluetooth/MicroBitUtilityService.h @@ -41,6 +41,8 @@ DEALINGS IN THE SOFTWARE. #include "EventModel.h" #include "MicroBitLog.h" +namespace codal +{ class MicroBitUtilityWorkspace; @@ -172,6 +174,7 @@ class MicroBitUtilityService : public MicroBitBLEService int processLogRead(); }; +} // namespace codal -#endif -#endif +#endif // CONFIG_ENABLED(DEVICE_BLE) +#endif // MICROBIT_UTILITY_SERVICE_H diff --git a/inc/bluetooth/MicroBitUtilityTypes.h b/inc/bluetooth/MicroBitUtilityTypes.h index 04878bde..52b8b8da 100644 --- a/inc/bluetooth/MicroBitUtilityTypes.h +++ b/inc/bluetooth/MicroBitUtilityTypes.h @@ -59,7 +59,7 @@ DEALINGS IN THE SOFTWARE. * reply data (up to 19 bytes) - 1 or more reply packets, to total batchlen bytes * */ -namespace MicroBitUtility +namespace codal::MicroBitUtility { typedef enum requestType_t { diff --git a/inc/compat/DigitalIn.h b/inc/compat/DigitalIn.h index 063982db..999c9d85 100644 --- a/inc/compat/DigitalIn.h +++ b/inc/compat/DigitalIn.h @@ -5,27 +5,27 @@ class DigitalIn: public codal::NRF52Pin { public: - DigitalIn(PinName pin) : codal::NRF52Pin(pin, pin, PIN_CAPABILITY_DIGITAL) + DigitalIn(PinName pin) : codal::NRF52Pin(pin, pin, codal::PIN_CAPABILITY_DIGITAL) { } - void mode(PullMode pull) { + void mode(codal::PullMode pull) { this->setPull(pull); } void mode(int pull) { switch(pull) { case PullNone: - this->setPull(PullMode::None); + this->setPull(codal::PullMode::None); break; case PullDown: - this->setPull(PullMode::Down); + this->setPull(codal::PullMode::Down); break; case PullUp: - this->setPull(PullMode::Up); + this->setPull(codal::PullMode::Up); break; default: - this->setPull(PullMode::Up); + this->setPull(codal::PullMode::Up); break; } } diff --git a/inc/compat/DigitalOut.h b/inc/compat/DigitalOut.h index 1b89176d..9cc6c94f 100644 --- a/inc/compat/DigitalOut.h +++ b/inc/compat/DigitalOut.h @@ -5,27 +5,27 @@ class DigitalOut: public codal::NRF52Pin { public: - DigitalOut(PinName pin) : codal::NRF52Pin(pin, pin, PIN_CAPABILITY_DIGITAL) + DigitalOut(PinName pin) : codal::NRF52Pin(pin, pin, codal::PIN_CAPABILITY_DIGITAL) { } - void mode(PullMode pull) { + void mode(codal::PullMode pull) { this->setPull(pull); } void mode(int pull) { switch(pull) { case PullNone: - this->setPull(PullMode::None); + this->setPull(codal::PullMode::None); break; case PullDown: - this->setPull(PullMode::Down); + this->setPull(codal::PullMode::Down); break; case PullUp: - this->setPull(PullMode::Up); + this->setPull(codal::PullMode::Up); break; default: - this->setPull(PullMode::Up); + this->setPull(codal::PullMode::Up); break; } } diff --git a/inc/compat/InterruptIn.h b/inc/compat/InterruptIn.h index 43e2ce09..1feda6d3 100644 --- a/inc/compat/InterruptIn.h +++ b/inc/compat/InterruptIn.h @@ -6,7 +6,7 @@ #ifdef MICROBIT_DAL_FIBER_USER_DATA #include "pxt.h" #else -extern MicroBit uBit; +extern codal::MicroBit uBit; #endif #include "MicroBitCompat.h" @@ -16,13 +16,13 @@ extern MicroBit uBit; class InterruptIn { - MbedMemberFunctionCallback *_rise; - MbedMemberFunctionCallback *_fall; - NRF52Pin *p; + codal::MbedMemberFunctionCallback *_rise; + codal::MbedMemberFunctionCallback *_fall; + codal::NRF52Pin *p; public: InterruptIn(PinName pin) { - p = new NRF52Pin(MICROBIT_ID_MBED_INTERRUPT_IN, pin, PIN_CAPABILITY_DIGITAL); + p = new codal::NRF52Pin(MICROBIT_ID_MBED_INTERRUPT_IN, pin, codal::PIN_CAPABILITY_DIGITAL); p->eventOn(MICROBIT_PIN_EVENT_ON_EDGE); return; } @@ -30,16 +30,16 @@ class InterruptIn { void mode(int pull) { switch(pull) { case PullNone: - p->setPull(PullMode::None); + p->setPull(codal::PullMode::None); break; case PullDown: - p->setPull(PullMode::Down); + p->setPull(codal::PullMode::Down); break; case PullUp: - p->setPull(PullMode::Up); + p->setPull(codal::PullMode::Up); break; default: - p->setPull(PullMode::Up); + p->setPull(codal::PullMode::Up); break; } } @@ -50,7 +50,7 @@ class InterruptIn { template void fall(T* tptr, void (T::*mptr)(void)) { - this->_fall = new MbedMemberFunctionCallback(tptr, mptr); + this->_fall = new codal::MbedMemberFunctionCallback(tptr, mptr); uBit.messageBus.listen(MICROBIT_ID_MBED_INTERRUPT_IN, MICROBIT_PIN_EVT_FALL, this, &InterruptIn::onFall); } @@ -60,7 +60,7 @@ class InterruptIn { template void rise(T* tptr, void (T::*mptr)(void)) { - this->_rise = new MbedMemberFunctionCallback(tptr, mptr); + this->_rise = new codal::MbedMemberFunctionCallback(tptr, mptr); uBit.messageBus.listen(MICROBIT_ID_MBED_INTERRUPT_IN, MICROBIT_PIN_EVT_RISE, this, &InterruptIn::onRise); } diff --git a/inc/compat/MbedTimer.h b/inc/compat/MbedTimer.h index c70c2874..c01baf4e 100644 --- a/inc/compat/MbedTimer.h +++ b/inc/compat/MbedTimer.h @@ -7,22 +7,22 @@ class MbedTimer { uint32_t _stop = 0; public: void start() { - _start = system_timer_current_time_us(); + _start = codal::system_timer_current_time_us(); } void stop() { - _stop = system_timer_current_time_us(); + _stop = codal::system_timer_current_time_us(); } void reset() { - _start = system_timer_current_time_us(); + _start = codal::system_timer_current_time_us(); } float read() { if(_stop > 0) { return (_stop - _start) / 1000000.0; } else { - return (system_timer_current_time_us() - _start) / 1000000.0; + return (codal::system_timer_current_time_us() - _start) / 1000000.0; } } @@ -31,15 +31,15 @@ class MbedTimer { if(_stop > 0) { return (_stop - _start) / 1000; } else { - return (system_timer_current_time_us() - _start) / 1000; + return (codal::system_timer_current_time_us() - _start) / 1000; } } int read_us() { if(_stop > 0) { - return system_timer_current_time_us() - _start; + return codal::system_timer_current_time_us() - _start; } else { - return system_timer_current_time_us() - _start; + return codal::system_timer_current_time_us() - _start; } } diff --git a/inc/compat/MicroBitCompat.h b/inc/compat/MicroBitCompat.h index 61f18602..3c5fd15a 100644 --- a/inc/compat/MicroBitCompat.h +++ b/inc/compat/MicroBitCompat.h @@ -401,8 +401,6 @@ namespace codal uint16_t htons(uint16_t v); }; -using namespace codal; - // // MicroBitButton has dependencies on the definitions here, so needs to be included // after these are defined to avoid having to redeclare everything needlessly or have diff --git a/inc/compat/PwmOut.h b/inc/compat/PwmOut.h index 96a9b570..b334ade4 100644 --- a/inc/compat/PwmOut.h +++ b/inc/compat/PwmOut.h @@ -8,10 +8,10 @@ class PwmOut { private: - NRF52Pin p; + codal::NRF52Pin p; public: - PwmOut(PinName pin) : p(MICROBIT_ID_MBED_PWM, pin, PIN_CAPABILITY_ANALOG) { + PwmOut(PinName pin) : p(MICROBIT_ID_MBED_PWM, pin, codal::PIN_CAPABILITY_ANALOG) { return; } diff --git a/inc/compat/Ticker.h b/inc/compat/Ticker.h index aebf2704..7df853ca 100644 --- a/inc/compat/Ticker.h +++ b/inc/compat/Ticker.h @@ -6,7 +6,7 @@ #ifdef MICROBIT_DAL_FIBER_USER_DATA #include "pxt.h" #else -extern MicroBit uBit; +extern codal::MicroBit uBit; #endif #include "MicroBitCompat.h" @@ -17,7 +17,7 @@ extern MicroBit uBit; class Ticker { private: uint32_t interval; - MbedMemberFunctionCallback *func; + codal::MbedMemberFunctionCallback *func; public: @@ -30,23 +30,23 @@ class Ticker { template void attach(T* tptr, void (T::*mptr)(void), float s) { - this->func = new MbedMemberFunctionCallback(tptr, mptr); + this->func = new codal::MbedMemberFunctionCallback(tptr, mptr); this->interval = (s * 1000000.0f); uBit.messageBus.listen(MICROBIT_ID_MBED_TICKER, 0x0, this, &Ticker::onTick); - system_timer_event_every_us(interval, MICROBIT_ID_MBED_TICKER, 0x0); + codal::system_timer_event_every_us(interval, MICROBIT_ID_MBED_TICKER, 0x0); } template void attach_us(T* tptr, void (T::*mptr)(void), int us) { - this->func = new MbedMemberFunctionCallback(tptr, mptr); + this->func = new codal::MbedMemberFunctionCallback(tptr, mptr); this->interval = (us * 1000); uBit.messageBus.listen(MICROBIT_ID_MBED_TICKER, 0x0, this, &Ticker::onTick); - system_timer_event_every_us(interval, MICROBIT_ID_MBED_TICKER, 0x0); + codal::system_timer_event_every_us(interval, MICROBIT_ID_MBED_TICKER, 0x0); } void detach() { - system_timer_cancel_event(MICROBIT_ID_MBED_TICKER, 0x0); + codal::system_timer_cancel_event(MICROBIT_ID_MBED_TICKER, 0x0); } }; diff --git a/inc/compat/Timeout.h b/inc/compat/Timeout.h index d030b1ad..1504cdf9 100644 --- a/inc/compat/Timeout.h +++ b/inc/compat/Timeout.h @@ -6,7 +6,7 @@ #ifdef MICROBIT_DAL_FIBER_USER_DATA #include "pxt.h" #else -extern MicroBit uBit; +extern codal::MicroBit uBit; #endif #include "MicroBitCompat.h" @@ -18,7 +18,7 @@ class Timeout { private: uint32_t interval; - MbedMemberFunctionCallback *func; + codal::MbedMemberFunctionCallback *func; public: @@ -31,24 +31,24 @@ class Timeout { template void attach(T* tptr, void (T::*mptr)(void), float s) { - this->func = new MbedMemberFunctionCallback(tptr, mptr); + this->func = new codal::MbedMemberFunctionCallback(tptr, mptr); this->interval = (s * 1000000.0f); uBit.messageBus.listen(MICROBIT_ID_MBED_TIMEOUT, 0x0, this, &Timeout::onTimeout); - system_timer_event_after_us(interval, MICROBIT_ID_MBED_TIMEOUT, 0x0); + codal::system_timer_event_after_us(interval, MICROBIT_ID_MBED_TIMEOUT, 0x0); } template void attach_us(T* tptr, void (T::*mptr)(void), int us) { - this->func = new MbedMemberFunctionCallback(tptr, mptr); + this->func = new codal::MbedMemberFunctionCallback(tptr, mptr); this->interval = (us * 1000); uBit.messageBus.listen(MICROBIT_ID_MBED_TIMEOUT, 0x0, this, &Timeout::onTimeout); - system_timer_event_after_us(interval, MICROBIT_ID_MBED_TIMEOUT, 0x0); + codal::system_timer_event_after_us(interval, MICROBIT_ID_MBED_TIMEOUT, 0x0); } void detach() { - system_timer_cancel_event(MICROBIT_ID_MBED_TIMEOUT, 0x0); + codal::system_timer_cancel_event(MICROBIT_ID_MBED_TIMEOUT, 0x0); } }; diff --git a/model/MicroBit.h b/model/MicroBit.h index d5f57883..62a497dc 100644 --- a/model/MicroBit.h +++ b/model/MicroBit.h @@ -31,7 +31,6 @@ DEALINGS IN THE SOFTWARE. #include "CodalDevice.h" #include "ErrorNo.h" #include "NRFLowLevelTimer.h" -#include "Matrix4.h" #include "CodalCompat.h" #include "CodalComponent.h" #include "CodalDmesg.h" @@ -317,7 +316,9 @@ namespace codal void microbit_dmesg_flush(); +#if CONFIG_ENABLED(CODAL_USE_GLOBAL_NAMESPACE) using namespace codal; +#endif #define DEVICE_ID_MICROPHONE 3001 diff --git a/source/MicroBitFile.cpp b/source/MicroBitFile.cpp index 4d993bdd..9f89d408 100644 --- a/source/MicroBitFile.cpp +++ b/source/MicroBitFile.cpp @@ -22,6 +22,8 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitFile.h" #include "ErrorNo.h" +using namespace codal; + /** * Creates an instance of a MicroBitFile and creates a new file if required. * diff --git a/source/MicroBitFileSystem.cpp b/source/MicroBitFileSystem.cpp index 971729fb..b36ab817 100644 --- a/source/MicroBitFileSystem.cpp +++ b/source/MicroBitFileSystem.cpp @@ -26,6 +26,8 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitCompat.h" #include "ErrorNo.h" +using namespace codal; + static uint32_t *defaultScratchPage = (uint32_t *)MICROBIT_DEFAULT_SCRATCH_PAGE; MicroBitFileSystem* MicroBitFileSystem::defaultFileSystem = NULL; diff --git a/source/MicroBitMemoryMap.cpp b/source/MicroBitMemoryMap.cpp index b6c3d6d1..da6f7c8c 100644 --- a/source/MicroBitMemoryMap.cpp +++ b/source/MicroBitMemoryMap.cpp @@ -40,6 +40,8 @@ DEALINGS IN THE SOFTWARE. #include "app_util.h" #include "crc32.h" +using namespace codal; + #define MAX_STRING_LENGTH 100 /** diff --git a/source/MicroBitPowerManager.cpp b/source/MicroBitPowerManager.cpp index 6118c96b..a4194cb2 100644 --- a/source/MicroBitPowerManager.cpp +++ b/source/MicroBitPowerManager.cpp @@ -25,6 +25,8 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitPowerManager.h" #include "MicroBit.h" +using namespace codal; + static const uint8_t UIPM_I2C_NOP[3] = {0,0,0}; // Developer note - if any of these get longer than 8 bytes of payload, MICROBIT_UIPM_MAX_BUFFER_SIZE will also have to be updated diff --git a/source/MicroBitUSBFlashManager.cpp b/source/MicroBitUSBFlashManager.cpp index 530d832c..f894acb0 100644 --- a/source/MicroBitUSBFlashManager.cpp +++ b/source/MicroBitUSBFlashManager.cpp @@ -24,6 +24,8 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitUSBFlashManager.h" +using namespace codal; + static const KeyValueTableEntry usbFlashPropertyLengthData[] = { {MICROBIT_USB_FLASH_FILENAME_CMD, 12}, {MICROBIT_USB_FLASH_FILESIZE_CMD, 5}, diff --git a/source/MicroSynth.cpp b/source/MicroSynth.cpp index 153f698f..6592bfb8 100644 --- a/source/MicroSynth.cpp +++ b/source/MicroSynth.cpp @@ -29,6 +29,8 @@ SOFTWARE. #include #include +using namespace codal; + bool SynthTables::inited_ = false; float SynthTables::notetab_[129]; diff --git a/source/SoundExpressions.cpp b/source/SoundExpressions.cpp index e711a33d..a95163d5 100644 --- a/source/SoundExpressions.cpp +++ b/source/SoundExpressions.cpp @@ -34,6 +34,8 @@ DEALINGS IN THE SOFTWARE. #define CLAMP(lo, v, hi) ((v) = ((v) < (lo) ? (lo) : (v) > (hi) ? (hi) : (v))) +using namespace codal; + /** * Default Constructor. */ diff --git a/source/bluetooth/MicroBitAccelerometerService.cpp b/source/bluetooth/MicroBitAccelerometerService.cpp index 46f34cc9..2dad6cc1 100644 --- a/source/bluetooth/MicroBitAccelerometerService.cpp +++ b/source/bluetooth/MicroBitAccelerometerService.cpp @@ -33,6 +33,7 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitAccelerometerService.h" +using namespace codal; const uint16_t MicroBitAccelerometerService::serviceUUID = 0x0753; const uint16_t MicroBitAccelerometerService::charUUID[ mbbs_cIdxCOUNT] = { 0xca4b, 0xfb24 }; diff --git a/source/bluetooth/MicroBitBLEChar.cpp b/source/bluetooth/MicroBitBLEChar.cpp index 54d1b184..98b1c830 100644 --- a/source/bluetooth/MicroBitBLEChar.cpp +++ b/source/bluetooth/MicroBitBLEChar.cpp @@ -39,6 +39,8 @@ DEALINGS IN THE SOFTWARE. #include "ble_srv_common.h" #include "ble_conn_state.h" +using namespace codal; + /** * Constructor. * Create a representation of a BLEService diff --git a/source/bluetooth/MicroBitBLEManager.cpp b/source/bluetooth/MicroBitBLEManager.cpp index 1e51d371..34a72875 100644 --- a/source/bluetooth/MicroBitBLEManager.cpp +++ b/source/bluetooth/MicroBitBLEManager.cpp @@ -73,6 +73,7 @@ DEALINGS IN THE SOFTWARE. #include "CodalDmesg.h" #include "nrf_log_backend_dmesg.h" +using namespace codal; #define MICROBIT_PAIRING_FADE_SPEED 4 diff --git a/source/bluetooth/MicroBitBLEService.cpp b/source/bluetooth/MicroBitBLEService.cpp index cb314dc7..3bb61bc3 100644 --- a/source/bluetooth/MicroBitBLEService.cpp +++ b/source/bluetooth/MicroBitBLEService.cpp @@ -40,6 +40,7 @@ DEALINGS IN THE SOFTWARE. #include "ble_conn_state.h" #include "peer_manager.h" +using namespace codal; const uint8_t MicroBitBLEService::bs_base_uuid[ 16] = { 0xe9,0x5d,0x00,0x00,0x25,0x1d,0x47,0x0a,0xa0,0x62,0xfa,0x19,0x22,0xdf,0xa9,0xa8 }; diff --git a/source/bluetooth/MicroBitBLEServices.cpp b/source/bluetooth/MicroBitBLEServices.cpp index 95cab9df..77704909 100644 --- a/source/bluetooth/MicroBitBLEServices.cpp +++ b/source/bluetooth/MicroBitBLEServices.cpp @@ -38,6 +38,7 @@ DEALINGS IN THE SOFTWARE. #include "nrf_sdh_ble.h" +using namespace codal; /** * getShared diff --git a/source/bluetooth/MicroBitBLETypes.cpp b/source/bluetooth/MicroBitBLETypes.cpp index d37c77f6..0cba0e9c 100644 --- a/source/bluetooth/MicroBitBLETypes.cpp +++ b/source/bluetooth/MicroBitBLETypes.cpp @@ -31,6 +31,7 @@ DEALINGS IN THE SOFTWARE. #include "nrf_log_ctrl.h" +using namespace codal; #if ( MICROBIT_DMESG_LEVEL >= MICROBIT_DMESG_LEVEL_DEBUG) microbit_ble_ret_code_t microbit_ble_on_error( microbit_ble_ret_code_t err, const char *msg) diff --git a/source/bluetooth/MicroBitButtonService.cpp b/source/bluetooth/MicroBitButtonService.cpp index 43397e9c..66746579 100644 --- a/source/bluetooth/MicroBitButtonService.cpp +++ b/source/bluetooth/MicroBitButtonService.cpp @@ -34,6 +34,8 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitButtonService.h" #include "MicroBitButton.h" +using namespace codal; + const uint16_t MicroBitButtonService::serviceUUID = 0x9882; const uint16_t MicroBitButtonService::charUUID[ mbbs_cIdxCOUNT] = { 0xda90, 0xda91 }; diff --git a/source/bluetooth/MicroBitEddystone.cpp b/source/bluetooth/MicroBitEddystone.cpp index 5131f972..39724967 100644 --- a/source/bluetooth/MicroBitEddystone.cpp +++ b/source/bluetooth/MicroBitEddystone.cpp @@ -29,6 +29,8 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitEddystone.h" +using namespace codal; + MicroBitEddystone *MicroBitEddystone::_instance = NULL; diff --git a/source/bluetooth/MicroBitEventService.cpp b/source/bluetooth/MicroBitEventService.cpp index 73a7f9e6..0ad27ba2 100644 --- a/source/bluetooth/MicroBitEventService.cpp +++ b/source/bluetooth/MicroBitEventService.cpp @@ -36,6 +36,7 @@ DEALINGS IN THE SOFTWARE. #include "ExternalEvents.h" #include "MicroBitFiber.h" +using namespace codal; const uint16_t MicroBitEventService::serviceUUID = 0x93af; const uint16_t MicroBitEventService::charUUID[ mbbs_cIdxCOUNT] = { 0x9775, 0xb84c, 0x5404, 0x23c4 }; diff --git a/source/bluetooth/MicroBitIOPinService.cpp b/source/bluetooth/MicroBitIOPinService.cpp index 558b9d82..826aa46b 100644 --- a/source/bluetooth/MicroBitIOPinService.cpp +++ b/source/bluetooth/MicroBitIOPinService.cpp @@ -34,6 +34,8 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitIOPinService.h" #include "MicroBitFiber.h" +using namespace codal; + const uint16_t MicroBitIOPinService::serviceUUID = 0x127b; const uint16_t MicroBitIOPinService::charUUID[ mbbs_cIdxCOUNT] = { 0x5899, 0xb9fe, 0xd822, 0x8d00 }; diff --git a/source/bluetooth/MicroBitLEDService.cpp b/source/bluetooth/MicroBitLEDService.cpp index a79454d5..246a4a54 100644 --- a/source/bluetooth/MicroBitLEDService.cpp +++ b/source/bluetooth/MicroBitLEDService.cpp @@ -33,6 +33,7 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitLEDService.h" +using namespace codal; const uint16_t MicroBitLEDService::serviceUUID = 0xd91d; const uint16_t MicroBitLEDService::charUUID[ mbbs_cIdxCOUNT] = { 0x7b77, 0x93ee, 0x0d2d }; diff --git a/source/bluetooth/MicroBitMagnetometerService.cpp b/source/bluetooth/MicroBitMagnetometerService.cpp index 311874c3..be1053cb 100644 --- a/source/bluetooth/MicroBitMagnetometerService.cpp +++ b/source/bluetooth/MicroBitMagnetometerService.cpp @@ -34,6 +34,7 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitMagnetometerService.h" +using namespace codal; const uint16_t MicroBitMagnetometerService::serviceUUID = 0xf2d8; const uint16_t MicroBitMagnetometerService::charUUID[ mbbs_cIdxCOUNT] = { 0xfb11, 0x9715, 0x386c, 0xB358 }; diff --git a/source/bluetooth/MicroBitTemperatureService.cpp b/source/bluetooth/MicroBitTemperatureService.cpp index d0c4ff01..27151976 100644 --- a/source/bluetooth/MicroBitTemperatureService.cpp +++ b/source/bluetooth/MicroBitTemperatureService.cpp @@ -33,6 +33,7 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitTemperatureService.h" +using namespace codal; const uint16_t MicroBitTemperatureService::serviceUUID = 0x6100; const uint16_t MicroBitTemperatureService::charUUID[ mbbs_cIdxCOUNT] = { 0x9250, 0x1b25 }; diff --git a/source/bluetooth/MicroBitUARTService.cpp b/source/bluetooth/MicroBitUARTService.cpp index 091919cd..c1e454ce 100644 --- a/source/bluetooth/MicroBitUARTService.cpp +++ b/source/bluetooth/MicroBitUARTService.cpp @@ -39,6 +39,7 @@ DEALINGS IN THE SOFTWARE. #include "ErrorNo.h" #include "NotifyEvents.h" +using namespace codal; const uint8_t MicroBitUARTService::base_uuid[ 16] = { 0x6e, 0x40, 0x00, 0x00, 0xb5, 0xa3, 0xf3, 0x93, 0xe0, 0xa9, 0xe5, 0x0e, 0x24, 0xdc, 0xca, 0x9e }; diff --git a/source/bluetooth/MicroBitUtilityService.cpp b/source/bluetooth/MicroBitUtilityService.cpp index 6644c4bf..74855bc3 100644 --- a/source/bluetooth/MicroBitUtilityService.cpp +++ b/source/bluetooth/MicroBitUtilityService.cpp @@ -35,22 +35,19 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitUtilityTypes.h" using namespace codal; -using namespace MicroBitUtility; +using namespace codal::MicroBitUtility; #define MICROBIT_ID_UTILITY_PROCESS 0 #define MicroBitUtilityService_SLEEP 10 #define MicroBitUtilityService_TIMEOUT 10 -namespace MicroBitUtility +typedef enum replyState_t { - typedef enum replyState_t - { - replyStateClear, - replyStateReady, // reply has been prepared but not sent - replyStateError - } replyState_t; -}; + replyStateClear, + replyStateReady, // reply has been prepared but not sent + replyStateError +} replyState_t; //TODO How to choose service and characteristic IDs? @@ -66,7 +63,7 @@ MicroBitUtilityService *MicroBitUtilityService::shared = NULL; * Provides simple BLE request/response * See MicroBitUtilityTypes.h */ -class MicroBitUtilityWorkspace +class codal::MicroBitUtilityWorkspace { public: diff --git a/target-locked.json b/target-locked.json index 0a88b058..5740c7ea 100644 --- a/target-locked.json +++ b/target-locked.json @@ -50,13 +50,13 @@ "generate_hex": true, "libraries": [ { - "branch": "c46d62943bc05a1b8296663ac4c643475a3e8a4c", + "branch": "509086cc8590465041b15493ab52b56e7071c110", "name": "codal-core", "type": "git", "url": "https://github.com/lancaster-university/codal-core" }, { - "branch": "0643733703b4f8f788af81a996f40d1f1a1527bc", + "branch": "8802eb49140e0389e535cb6160d9080efd951ba7", "name": "codal-nrf52", "type": "git", "url": "https://github.com/lancaster-university/codal-nrf52"