diff --git a/inc/MicroBit.h b/inc/MicroBit.h deleted file mode 100644 index 5dfdc69..0000000 --- a/inc/MicroBit.h +++ /dev/null @@ -1,471 +0,0 @@ -#ifndef MICROBIT_H -#define MICROBIT_H - -#include "mbed.h" - -#include "MicroBitConfig.h" -#include "MicroBitHeapAllocator.h" -#include "MicroBitDevice.h" -#include "ErrorNo.h" -#include "MicroBitSystemTimer.h" -#include "Matrix4.h" -#include "MicroBitCompat.h" -#include "MicroBitComponent.h" -#include "ManagedType.h" -#include "ManagedString.h" -#include "MicroBitImage.h" -#include "MicroBitFont.h" -#include "MicroBitEvent.h" -#include "DynamicPwm.h" -#include "MicroBitI2C.h" -#include "MESEvents.h" - -#include "MicroBitButton.h" -#include "MicroBitPin.h" -#include "MicroBitCompass.h" -#include "MicroBitCompassCalibrator.h" -#include "MicroBitAccelerometer.h" -#include "MicroBitThermometer.h" -#include "MicroBitLightSensor.h" -#include "MicroBitMultiButton.h" - -#include "MicroBitSerial.h" -#include "MicroBitIO.h" -#include "MicroBitMatrixMaps.h" -#include "MicroBitDisplay.h" - -#include "MicroBitFiber.h" -#include "MicroBitMessageBus.h" - -#include "MicroBitBLEManager.h" -#include "MicroBitRadio.h" -#include "MicroBitStorage.h" - -// MicroBit::flags values -#define MICROBIT_INITIALIZED 0x01 - -// Random number generator -#define NRF51822_RNG_ADDRESS 0x4000D000 - -// mbed pin assignments of core components. -#define MICROBIT_PIN_SDA P0_30 -#define MICROBIT_PIN_SCL P0_0 - -/** - * Class definition for a MicroBit device. - * - * Represents the device as a whole, and includes member variables to that reflect the components of the system. - */ -class MicroBit -{ - private: - - void onListenerRegisteredEvent(MicroBitEvent evt); - uint8_t status; - - public: - - // Reset Button - InterruptIn resetButton; - - // Persistent key value store - MicroBitStorage storage; - - // I2C Interface - MicroBitI2C i2c; - - // Serial Interface - MicroBitSerial serial; - - // Device level Message Bus abstraction - MicroBitMessageBus messageBus; - - // Member variables to represent each of the core components on the device. - MicroBitDisplay display; - MicroBitButton buttonA; - MicroBitButton buttonB; - MicroBitMultiButton buttonAB; - MicroBitAccelerometer accelerometer; - MicroBitCompass compass; - MicroBitCompassCalibrator compassCalibrator; - MicroBitThermometer thermometer; - - //An object of available IO pins on the device - MicroBitIO io; - - // Bluetooth related member variables. - MicroBitBLEManager bleManager; - MicroBitRadio radio; - BLEDevice *ble; - - /** - * Constructor. - * Create a representation of a MicroBit device as a global singleton. - * @param messageBus callback function to receive MicroBitMessageBus events. - * - * Exposed objects: - * @code - * uBit.messageBus; //The message bus where events are fired. - * uBit.display; //The display object for the LED matrix. - * uBit.buttonA; //The buttonA object for button a. - * uBit.buttonB; //The buttonB object for button b. - * uBit.resetButton; //The resetButton used for soft resets. - * uBit.accelerometer; //The object that represents the inbuilt accelerometer - * uBit.compass; //The object that represents the inbuilt compass(magnetometer) - * uBit.io.P*; //Where P* is P0 to P16, P19 & P20 on the edge connector - * @endcode - */ - MicroBit(); - - /** - * Post constructor initialisation method. - * After *MUCH* pain, it's noted that the BLE stack can't be brought up in a - * static context, so we bring it up here rather than in the constructor. - * n.b. This method *must* be called in main() or later, not before. - * - * Example: - * @code - * uBit.init(); - * @endcode - */ - void init(); - - /** - * Return the friendly name for this device. - * - * @return A string representing the friendly name of this device. - */ - static ManagedString getName(); - - /** - * Return the serial number of this device. - * - * @return A string representing the serial number of this device. - */ - static ManagedString getSerial(); - - /** - * Will reset the micro:bit when called. - * - * Example: - * @code - * uBit.reset(); - * @endcode - */ - void reset(); - - /** - * Delay for the given amount of time. - * If the scheduler is running, this will deschedule the current fiber and perform - * a power efficent, concurrent sleep operation. - * If the scheduler is disabled or we're running in an interrupt context, this - * will revert to a busy wait. - * - * @note Values of 6 and below tend to lose resolution - do you really need to sleep for this short amount of time? - * - * @param milliseconds the amount of time, in ms, to wait for. This number cannot be negative. - * @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER milliseconds is less than zero. - * - * Example: - * @code - * MicroBit::sleep(20); //sleep for 20ms - * @endcode - */ - void sleep(uint32_t milliseconds); - - /** - * Seed the pseudo random number generator using the hardware generator. - * - * Example: - * @code - * uBit.seedRandom(); - * @endcode - */ - void seedRandom(); - - /** - * Seed the pseudo random number generator using the given value. - * - * @param seed The 32-bit value to seed the generator with. - * - * Example: - * @code - * uBit.seedRandom(0x12345678); - * @endcode - */ - void seedRandom(uint32_t seed); - - /** - * Generate a random number in the given range. - * We use the NRF51822 in built random number generator here - * TODO: Determine if we want to, given its relatively high power consumption! - * - * @param max the upper range to generate a number for. This number cannot be negative - * @return A random, natural number between 0 and the max-1. Or MICROBIT_INVALID_PARAMETER if max is <= 0. - * - * Example: - * @code - * uBit.random(200); //a number between 0 and 199 - * @endcode - */ - int random(int max); - - /** - * Determine the time since this MicroBit was last reset. - * - * @return The time since the last reset, in milliseconds. This will result in overflow after 1.6 months. - * TODO: handle overflow case. - */ - unsigned long systemTime(); - - /** - * Determine the version of the micro:bit runtime currently in use. - * - * @return A textual description of the currentlt executing micro:bit runtime. - * TODO: handle overflow case. - */ - const char *systemVersion(); - - /** - * Triggers a microbit panic where an infinite loop will occur swapping between the panicFace and statusCode if provided. - * - * @param statusCode the status code of the associated error. Status codes must be in the range 0-255. - */ - void panic(int statusCode = 0); - - /** - * add a component to the array of components which invocate the systemTick member function during a systemTick - * @param component The component to add. - * @return MICROBIT_OK on success. MICROBIT_NO_RESOURCES is returned if further components cannot be supported. - * @note This interface is now deprecated. See fiber_add_system_component(). - */ - int addSystemComponent(MicroBitComponent *component); - - /** - * remove a component from the array of components - * @param component The component to remove. - * @return MICROBIT_OK on success. MICROBIT_INVALID_PARAMTER is returned if the given component has not been previous added. - * @note This interface is now deprecated. See fiber_remove_system_component(). - */ - int removeSystemComponent(MicroBitComponent *component); - - /** - * add a component to the array of components which invocate the systemTick member function during a systemTick - * @param component The component to add. - * @return MICROBIT_OK on success. MICROBIT_NO_RESOURCES is returned if further components cannot be supported. - * @note This interface is now deprecated. See fiber_add_idle_component(). - */ - int addIdleComponent(MicroBitComponent *component); - - /** - * remove a component from the array of components - * @param component The component to remove. - * @return MICROBIT_OK on success. MICROBIT_INVALID_PARAMTER is returned if the given component has not been previous added. - * @note This interface is now deprecated. See fiber_remove_idle_component(). - */ - int removeIdleComponent(MicroBitComponent *component); -}; - -/** - * Return the friendly name for this device. - * - * @return A string representing the friendly name of this device. - */ -inline ManagedString MicroBit::getName() -{ - return ManagedString(microbit_friendly_name()); -} - -/** - * Return the serial number of this device. - * - * @return A string representing the serial number of this device. - */ -inline ManagedString MicroBit::getSerial() -{ - // We take to 16 bit numbers here, as we want the full range of ID bits, but don't want negative numbers... - int n1 = microbit_serial_number() & 0xffff; - int n2 = (microbit_serial_number() >> 16) & 0xffff; - - // Simply concat the two numbers. - ManagedString s1(n1); - ManagedString s2(n2); - - return s1 + s2; -} - -/** - * Will reset the micro:bit when called. - * - * Example: - * @code - * uBit.reset(); - * @endcode - */ -inline void MicroBit::reset() -{ - if(ble && ble->getGapState().connected) { - - // We have a connected BLE peer. Disconnect the BLE session. - ble->gap().disconnect(Gap::REMOTE_USER_TERMINATED_CONNECTION); - - // Wait a little while for the connection to drop. - wait_ms(100); - } - - microbit_reset(); -} - -/** - * Delay for the given amount of time. - * If the scheduler is running, this will deschedule the current fiber and perform - * a power efficent, concurrent sleep operation. - * If the scheduler is disabled or we're running in an interrupt context, this - * will revert to a busy wait. - * - * @note Values of below below the scheduling period (typical 6ms) tend to lose resolution. - * - * @param milliseconds the amount of time, in ms, to wait for. This number cannot be negative. - * @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER milliseconds is less than zero. - * - * Example: - * @code - * uBit.sleep(20); //sleep for 20ms - * @endcode - */ -inline void MicroBit::sleep(uint32_t milliseconds) -{ - fiber_sleep(milliseconds); -} - - -/** - * Generate a random number in the given range. - * We use a simple Galois LFSR random number generator here, - * as a Galois LFSR is sufficient for our applications, and much more lightweight - * than the hardware random number generator built int the processor, which takes - * a long time and uses a lot of energy. - * - * KIDS: You shouldn't use this is the real world to generte cryptographic keys though... - * have a think why not. :-) - * - * @param max the upper range to generate a number for. This number cannot be negative - * @return A random, natural number between 0 and the max-1. Or MICROBIT_INVALID_VALUE (defined in ErrorNo.h) if max is <= 0. - * - * Example: - * @code - * uBit.random(200); //a number between 0 and 199 - * @endcode - */ -inline int MicroBit::random(int max) -{ - return microbit_random(max); -} - -/** - * Seed our a random number generator (RNG). - * We use the NRF51822 in built cryptographic random number generator to seed a Galois LFSR. - * We do this as the hardware RNG is relatively high power, and use the the BLE stack internally, - * with a less than optimal application interface. A Galois LFSR is sufficient for our - * applications, and much more lightweight. - */ -inline void MicroBit::seedRandom() -{ - microbit_seed_random(); -} - - -/** - * Seed our pseudo random number generator (PRNG) using the given 32-bit value. - */ -inline void MicroBit::seedRandom(uint32_t seed) -{ - microbit_seed_random(seed); -} - - -/** - * add a component to the array of components which invocate the systemTick member function during a systemTick - * @param component The component to add. - * @return MICROBIT_OK on success. MICROBIT_NO_RESOURCES is returned if further components cannot be supported. - * @note this will be converted into a dynamic list of components - */ -inline int MicroBit::addSystemComponent(MicroBitComponent *component) -{ - return system_timer_add_component(component); -} - -/** - * remove a component from the array of components - * @param component The component to remove. - * @return MICROBIT_OK on success. MICROBIT_INVALID_PARAMTER is returned if the given component has not been previous added. - * @note this will be converted into a dynamic list of components - */ -inline int MicroBit::removeSystemComponent(MicroBitComponent *component) -{ - return system_timer_remove_component(component); -} - -/** - * add a component to the array of components which invocate the systemTick member function during a systemTick - * @param component The component to add. - * @return MICROBIT_OK on success. MICROBIT_NO_RESOURCES is returned if further components cannot be supported. - * @note this will be converted into a dynamic list of components - */ -inline int MicroBit::addIdleComponent(MicroBitComponent *component) -{ - return fiber_add_idle_component(component); -} - -/** - * remove a component from the array of components - * @param component The component to remove. - * @return MICROBIT_OK on success. MICROBIT_INVALID_PARAMTER is returned if the given component has not been previous added. - * @note this will be converted into a dynamic list of components - */ -inline int MicroBit::removeIdleComponent(MicroBitComponent *component) -{ - return fiber_remove_idle_component(component); -} - - -/** - * Determine the time since this MicroBit was last reset. - * - * @return The time since the last reset, in milliseconds. This will result in overflow after 1.6 months. - * TODO: handle overflow case. - */ -inline unsigned long MicroBit::systemTime() -{ - return system_timer_current_time(); -} - - -/** - * Determine the version of the micro:bit runtime currently in use. - * - * @return A textual description of the currentlt executing micro:bit runtime. - * TODO: handle overflow case. - */ -inline const char *MicroBit::systemVersion() -{ - return microbit_dal_version(); -} - -/** - * Triggers a microbit panic. All functionality will cease, and a sad face displayed along with an error code. - * @param statusCode the status code of the associated error. Status codes must be in the range 0-255. - */ -inline void MicroBit::panic(int statusCode) -{ - //show error and enter infinite while - microbit_panic(statusCode); -} - - -// Entry point for application programs. Called after the super-main function -// has initialized the device and runtime environment. -extern "C" void app_main(); - - -#endif diff --git a/inc/ExternalEvents.h b/inc/bluetooth/ExternalEvents.h similarity index 100% rename from inc/ExternalEvents.h rename to inc/bluetooth/ExternalEvents.h diff --git a/inc/MESEvents.h b/inc/bluetooth/MESEvents.h similarity index 100% rename from inc/MESEvents.h rename to inc/bluetooth/MESEvents.h diff --git a/inc/MicroBitAccelerometerService.h b/inc/bluetooth/MicroBitAccelerometerService.h similarity index 100% rename from inc/MicroBitAccelerometerService.h rename to inc/bluetooth/MicroBitAccelerometerService.h diff --git a/inc/MicroBitBLEManager.h b/inc/bluetooth/MicroBitBLEManager.h similarity index 100% rename from inc/MicroBitBLEManager.h rename to inc/bluetooth/MicroBitBLEManager.h diff --git a/inc/MicroBitButtonService.h b/inc/bluetooth/MicroBitButtonService.h similarity index 100% rename from inc/MicroBitButtonService.h rename to inc/bluetooth/MicroBitButtonService.h diff --git a/inc/MicroBitDFUService.h b/inc/bluetooth/MicroBitDFUService.h similarity index 100% rename from inc/MicroBitDFUService.h rename to inc/bluetooth/MicroBitDFUService.h diff --git a/inc/MicroBitEventService.h b/inc/bluetooth/MicroBitEventService.h similarity index 100% rename from inc/MicroBitEventService.h rename to inc/bluetooth/MicroBitEventService.h diff --git a/inc/MicroBitIOPinService.h b/inc/bluetooth/MicroBitIOPinService.h similarity index 100% rename from inc/MicroBitIOPinService.h rename to inc/bluetooth/MicroBitIOPinService.h diff --git a/inc/MicroBitLEDService.h b/inc/bluetooth/MicroBitLEDService.h similarity index 100% rename from inc/MicroBitLEDService.h rename to inc/bluetooth/MicroBitLEDService.h diff --git a/inc/MicroBitMagnetometerService.h b/inc/bluetooth/MicroBitMagnetometerService.h similarity index 100% rename from inc/MicroBitMagnetometerService.h rename to inc/bluetooth/MicroBitMagnetometerService.h diff --git a/inc/MicroBitTemperatureService.h b/inc/bluetooth/MicroBitTemperatureService.h similarity index 100% rename from inc/MicroBitTemperatureService.h rename to inc/bluetooth/MicroBitTemperatureService.h diff --git a/inc/ErrorNo.h b/inc/core/ErrorNo.h similarity index 100% rename from inc/ErrorNo.h rename to inc/core/ErrorNo.h diff --git a/inc/EventModel.h b/inc/core/EventModel.h similarity index 100% rename from inc/EventModel.h rename to inc/core/EventModel.h diff --git a/inc/MemberFunctionCallback.h b/inc/core/MemberFunctionCallback.h similarity index 100% rename from inc/MemberFunctionCallback.h rename to inc/core/MemberFunctionCallback.h diff --git a/inc/MicroBitCompat.h b/inc/core/MicroBitCompat.h similarity index 100% rename from inc/MicroBitCompat.h rename to inc/core/MicroBitCompat.h diff --git a/inc/MicroBitComponent.h b/inc/core/MicroBitComponent.h similarity index 100% rename from inc/MicroBitComponent.h rename to inc/core/MicroBitComponent.h diff --git a/inc/MicroBitConfig.h b/inc/core/MicroBitConfig.h similarity index 100% rename from inc/MicroBitConfig.h rename to inc/core/MicroBitConfig.h diff --git a/inc/MicroBitDevice.h b/inc/core/MicroBitDevice.h similarity index 100% rename from inc/MicroBitDevice.h rename to inc/core/MicroBitDevice.h diff --git a/inc/MicroBitFiber.h b/inc/core/MicroBitFiber.h similarity index 100% rename from inc/MicroBitFiber.h rename to inc/core/MicroBitFiber.h diff --git a/inc/MicroBitFont.h b/inc/core/MicroBitFont.h similarity index 100% rename from inc/MicroBitFont.h rename to inc/core/MicroBitFont.h diff --git a/inc/MicroBitHeapAllocator.h b/inc/core/MicroBitHeapAllocator.h similarity index 100% rename from inc/MicroBitHeapAllocator.h rename to inc/core/MicroBitHeapAllocator.h diff --git a/inc/MicroBitListener.h b/inc/core/MicroBitListener.h similarity index 100% rename from inc/MicroBitListener.h rename to inc/core/MicroBitListener.h diff --git a/inc/MicroBitSystemTimer.h b/inc/core/MicroBitSystemTimer.h similarity index 100% rename from inc/MicroBitSystemTimer.h rename to inc/core/MicroBitSystemTimer.h diff --git a/inc/DynamicPwm.h b/inc/drivers/DynamicPwm.h similarity index 100% rename from inc/DynamicPwm.h rename to inc/drivers/DynamicPwm.h diff --git a/inc/MicroBitAccelerometer.h b/inc/drivers/MicroBitAccelerometer.h similarity index 100% rename from inc/MicroBitAccelerometer.h rename to inc/drivers/MicroBitAccelerometer.h diff --git a/inc/MicroBitButton.h b/inc/drivers/MicroBitButton.h similarity index 100% rename from inc/MicroBitButton.h rename to inc/drivers/MicroBitButton.h diff --git a/inc/MicroBitCompass.h b/inc/drivers/MicroBitCompass.h similarity index 100% rename from inc/MicroBitCompass.h rename to inc/drivers/MicroBitCompass.h diff --git a/inc/MicroBitCompassCalibrator.h b/inc/drivers/MicroBitCompassCalibrator.h similarity index 100% rename from inc/MicroBitCompassCalibrator.h rename to inc/drivers/MicroBitCompassCalibrator.h diff --git a/inc/MicroBitDisplay.h b/inc/drivers/MicroBitDisplay.h similarity index 100% rename from inc/MicroBitDisplay.h rename to inc/drivers/MicroBitDisplay.h diff --git a/inc/MicroBitI2C.h b/inc/drivers/MicroBitI2C.h similarity index 100% rename from inc/MicroBitI2C.h rename to inc/drivers/MicroBitI2C.h diff --git a/inc/MicroBitIO.h b/inc/drivers/MicroBitIO.h similarity index 100% rename from inc/MicroBitIO.h rename to inc/drivers/MicroBitIO.h diff --git a/inc/MicroBitLightSensor.h b/inc/drivers/MicroBitLightSensor.h similarity index 100% rename from inc/MicroBitLightSensor.h rename to inc/drivers/MicroBitLightSensor.h diff --git a/inc/MicroBitMatrixMaps.h b/inc/drivers/MicroBitMatrixMaps.h similarity index 100% rename from inc/MicroBitMatrixMaps.h rename to inc/drivers/MicroBitMatrixMaps.h diff --git a/inc/MicroBitMessageBus.h b/inc/drivers/MicroBitMessageBus.h similarity index 100% rename from inc/MicroBitMessageBus.h rename to inc/drivers/MicroBitMessageBus.h diff --git a/inc/MicroBitMultiButton.h b/inc/drivers/MicroBitMultiButton.h similarity index 100% rename from inc/MicroBitMultiButton.h rename to inc/drivers/MicroBitMultiButton.h diff --git a/inc/MicroBitPin.h b/inc/drivers/MicroBitPin.h similarity index 100% rename from inc/MicroBitPin.h rename to inc/drivers/MicroBitPin.h diff --git a/inc/MicroBitRadio.h b/inc/drivers/MicroBitRadio.h similarity index 100% rename from inc/MicroBitRadio.h rename to inc/drivers/MicroBitRadio.h diff --git a/inc/MicroBitRadioDatagram.h b/inc/drivers/MicroBitRadioDatagram.h similarity index 100% rename from inc/MicroBitRadioDatagram.h rename to inc/drivers/MicroBitRadioDatagram.h diff --git a/inc/MicroBitRadioEvent.h b/inc/drivers/MicroBitRadioEvent.h similarity index 100% rename from inc/MicroBitRadioEvent.h rename to inc/drivers/MicroBitRadioEvent.h diff --git a/inc/MicroBitSerial.h b/inc/drivers/MicroBitSerial.h similarity index 100% rename from inc/MicroBitSerial.h rename to inc/drivers/MicroBitSerial.h diff --git a/inc/MicroBitStorage.h b/inc/drivers/MicroBitStorage.h similarity index 100% rename from inc/MicroBitStorage.h rename to inc/drivers/MicroBitStorage.h diff --git a/inc/MicroBitThermometer.h b/inc/drivers/MicroBitThermometer.h similarity index 100% rename from inc/MicroBitThermometer.h rename to inc/drivers/MicroBitThermometer.h diff --git a/inc/ManagedString.h b/inc/types/ManagedString.h similarity index 100% rename from inc/ManagedString.h rename to inc/types/ManagedString.h diff --git a/inc/ManagedType.h b/inc/types/ManagedType.h similarity index 100% rename from inc/ManagedType.h rename to inc/types/ManagedType.h diff --git a/inc/Matrix4.h b/inc/types/Matrix4.h similarity index 100% rename from inc/Matrix4.h rename to inc/types/Matrix4.h diff --git a/inc/MicroBitCoordinateSystem.h b/inc/types/MicroBitCoordinateSystem.h similarity index 100% rename from inc/MicroBitCoordinateSystem.h rename to inc/types/MicroBitCoordinateSystem.h diff --git a/inc/MicroBitEvent.h b/inc/types/MicroBitEvent.h similarity index 100% rename from inc/MicroBitEvent.h rename to inc/types/MicroBitEvent.h diff --git a/inc/MicroBitImage.h b/inc/types/MicroBitImage.h similarity index 100% rename from inc/MicroBitImage.h rename to inc/types/MicroBitImage.h diff --git a/inc/PacketBuffer.h b/inc/types/PacketBuffer.h similarity index 100% rename from inc/PacketBuffer.h rename to inc/types/PacketBuffer.h diff --git a/inc/RefCounted.h b/inc/types/RefCounted.h similarity index 100% rename from inc/RefCounted.h rename to inc/types/RefCounted.h diff --git a/module.json b/module.json index 92964ed..6d78a5a 100644 --- a/module.json +++ b/module.json @@ -20,6 +20,9 @@ "nrf51-sdk": "lancaster-university/nrf51-sdk#v2.2.0+mb3" }, "extraIncludes": [ - "inc" + "inc/core", + "inc/types", + "inc/drivers", + "inc/bluetooth" ] } diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index ab1c363..5ca57a2 100755 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -6,49 +6,50 @@ cmake_minimum_required(VERSION 2.8.12) enable_language(ASM) set(YOTTA_AUTO_MICROBIT-DAL_CPP_FILES - "MicroBitSuperMain.cpp" - "MicroBitI2C.cpp" - "MicroBitMultiButton.cpp" - "MicroBitFont.cpp" - "MicroBit.cpp" - "MicroBitButton.cpp" - "MicroBitMessageBus.cpp" - "MicroBitCompass.cpp" - "MicroBitCompassCalibrator.cpp" - "MicroBitEvent.cpp" - "MicroBitFiber.cpp" - "MicroBitSystemTimer.cpp" - "ManagedString.cpp" - "Matrix4.cpp" - "MicroBitAccelerometer.cpp" - "MicroBitThermometer.cpp" - "MicroBitIO.cpp" - "MicroBitCompat.cpp" - "MicroBitDevice.cpp" - "MicroBitImage.cpp" - "MicroBitDisplay.cpp" - "DynamicPwm.cpp" - "MicroBitPin.cpp" - "MicroBitSerial.cpp" - "MicroBitHeapAllocator.cpp" - "MicroBitListener.cpp" - "MicroBitLightSensor.cpp" - "RefCounted.cpp" - "MemberFunctionCallback.cpp" - "MicroBitStorage.cpp" - "PacketBuffer.cpp" - "ble-services/MicroBitBLEManager.cpp" - "ble-services/MicroBitDFUService.cpp" - "ble-services/MicroBitEventService.cpp" - "ble-services/MicroBitLEDService.cpp" - "ble-services/MicroBitAccelerometerService.cpp" - "ble-services/MicroBitMagnetometerService.cpp" - "ble-services/MicroBitButtonService.cpp" - "ble-services/MicroBitIOPinService.cpp" - "ble-services/MicroBitTemperatureService.cpp" - "ble-services/MicroBitRadio.cpp" - "ble-services/MicroBitRadioDatagram.cpp" - "ble-services/MicroBitRadioEvent.cpp" + "core/MemberFunctionCallback.cpp" + "core/MicroBitCompat.cpp" + "core/MicroBitDevice.cpp" + "core/MicroBitFiber.cpp" + "core/MicroBitFont.cpp" + "core/MicroBitHeapAllocator.cpp" + "core/MicroBitListener.cpp" + "core/MicroBitSystemTimer.cpp" + + "types/ManagedString.cpp" + "types/Matrix4.cpp" + "types/MicroBitEvent.cpp" + "types/MicroBitImage.cpp" + "types/PacketBuffer.cpp" + "types/RefCounted.cpp" + + "drivers/DynamicPwm.cpp" + "drivers/MicroBitAccelerometer.cpp" + "drivers/MicroBitButton.cpp" + "drivers/MicroBitCompass.cpp" + "drivers/MicroBitCompassCalibrator.cpp" + "drivers/MicroBitDisplay.cpp" + "drivers/MicroBitI2C.cpp" + "drivers/MicroBitIO.cpp" + "drivers/MicroBitLightSensor.cpp" + "drivers/MicroBitMessageBus.cpp" + "drivers/MicroBitMultiButton.cpp" + "drivers/MicroBitPin.cpp" + "drivers/MicroBitRadio.cpp" + "drivers/MicroBitRadioDatagram.cpp" + "drivers/MicroBitRadioEvent.cpp" + "drivers/MicroBitSerial.cpp" + "drivers/MicroBitStorage.cpp" + "drivers/MicroBitThermometer.cpp" + + "bluetooth/MicroBitAccelerometerService.cpp" + "bluetooth/MicroBitBLEManager.cpp" + "bluetooth/MicroBitButtonService.cpp" + "bluetooth/MicroBitDFUService.cpp" + "bluetooth/MicroBitEventService.cpp" + "bluetooth/MicroBitIOPinService.cpp" + "bluetooth/MicroBitLEDService.cpp" + "bluetooth/MicroBitMagnetometerService.cpp" + "bluetooth/MicroBitTemperatureService.cpp" ) execute_process(WORKING_DIRECTORY "../../yotta_modules/${PROJECT_NAME}" COMMAND "git" "log" "--pretty=format:%h" "-n" "1" OUTPUT_VARIABLE git_hash) diff --git a/source/MicroBit.cpp b/source/MicroBit.cpp deleted file mode 100644 index 72bd1e1..0000000 --- a/source/MicroBit.cpp +++ /dev/null @@ -1,203 +0,0 @@ -#include "MicroBitConfig.h" -/* - * The underlying Nordic libraries that support BLE do not compile cleanly with the stringent GCC settings we employ - * If we're compiling under GCC, then we suppress any warnings generated from this code (but not the rest of the DAL) - * The ARM cc compiler is more tolerant. We don't test __GNUC__ here to detect GCC as ARMCC also typically sets this - * as a compatability option, but does not support the options used... - */ -#if !defined(__arm) -#pragma GCC diagnostic ignored "-Wunused-function" -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" -#endif - -#include "MicroBit.h" - -#include "nrf_soc.h" - -/* - * Return to our predefined compiler settings. - */ -#if !defined(__arm) -#pragma GCC diagnostic pop -#endif - - -/** - * Constructor. - * Create a representation of a MicroBit device as a global singleton. - * @param messageBus callback function to receive MicroBitMessageBus events. - * - * Exposed objects: - * @code - * uBit.systemTicker; //the Ticker callback that performs routines like updating the display. - * uBit.messageBus; //The message bus where events are fired. - * uBit.display; //The display object for the LED matrix. - * uBit.buttonA; //The buttonA object for button a. - * uBit.buttonB; //The buttonB object for button b. - * uBit.buttonAB; //The buttonAB object for button a+b multi press. - * uBit.resetButton; //The resetButton used for soft resets. - * uBit.accelerometer; //The object that represents the inbuilt accelerometer - * uBit.compass; //The object that represents the inbuilt compass(magnetometer) - * uBit.io.P*; //Where P* is P0 to P16, P19 & P20 on the edge connector - * @endcode - */ -MicroBit::MicroBit() : - resetButton(MICROBIT_PIN_BUTTON_RESET), - storage(), - i2c(MICROBIT_PIN_SDA, MICROBIT_PIN_SCL), - serial(USBTX, USBRX), - messageBus(), - display(), - buttonA(MICROBIT_PIN_BUTTON_A, MICROBIT_ID_BUTTON_A), - buttonB(MICROBIT_PIN_BUTTON_B, MICROBIT_ID_BUTTON_B), - buttonAB(MICROBIT_ID_BUTTON_A,MICROBIT_ID_BUTTON_B, MICROBIT_ID_BUTTON_AB), - accelerometer(i2c), - compass(i2c, accelerometer, storage), - compassCalibrator(compass, accelerometer, display), - thermometer(storage), - io(MICROBIT_ID_IO_P0,MICROBIT_ID_IO_P1,MICROBIT_ID_IO_P2, - MICROBIT_ID_IO_P3,MICROBIT_ID_IO_P4,MICROBIT_ID_IO_P5, - MICROBIT_ID_IO_P6,MICROBIT_ID_IO_P7,MICROBIT_ID_IO_P8, - MICROBIT_ID_IO_P9,MICROBIT_ID_IO_P10,MICROBIT_ID_IO_P11, - MICROBIT_ID_IO_P12,MICROBIT_ID_IO_P13,MICROBIT_ID_IO_P14, - MICROBIT_ID_IO_P15,MICROBIT_ID_IO_P16,MICROBIT_ID_IO_P19, - MICROBIT_ID_IO_P20), - bleManager(storage), - radio(), - ble(NULL) -{ - // Clear our status - status = 0; - - // Bring up soft reset functionality as soon as possible. - resetButton.mode(PullUp); - resetButton.fall(this, &MicroBit::reset); -} - -/** - * Post constructor initialisation method. - * After *MUCH* pain, it's noted that the BLE stack can't be brought up in a - * static context, so we bring it up here rather than in the constructor. - * n.b. This method *must* be called in main() or later, not before. - * - * Example: - * @code - * uBit.init(); - * @endcode - */ -void MicroBit::init() -{ - if (status & MICROBIT_INITIALIZED) - return; - -#if CONFIG_ENABLED(MICROBIT_HEAP_ALLOCATOR) - // Bring up a nested heap allocator. - microbit_create_nested_heap(MICROBIT_NESTED_HEAP_SIZE); -#endif - - // Bring up fiber scheduler. - scheduler_init(&messageBus); - - // Seed our random number generator - seedRandom(); - - // Create an event handler to trap any handlers being created for I2C services. - // We do this to enable initialisation of those services only when they're used, - // which saves processor time, memeory and battery life. - messageBus.listen(MICROBIT_ID_MESSAGE_BUS_LISTENER, MICROBIT_EVT_ANY, this, &MicroBit::onListenerRegisteredEvent); - - status |= MICROBIT_INITIALIZED; - -#if CONFIG_ENABLED(MICROBIT_BLE_PAIRING_MODE) - // Test if we need to enter BLE pairing mode... - int i=0; - sleep(100); - while (buttonA.isPressed() && buttonB.isPressed() && i<10) - { - sleep(100); - i++; - - if (i == 10) - { -#if CONFIG_ENABLED(MICROBIT_HEAP_ALLOCATOR) && CONFIG_ENABLED(MICROBIT_HEAP_REUSE_SD) - microbit_create_heap(MICROBIT_SD_GATT_TABLE_START + MICROBIT_SD_GATT_TABLE_SIZE, MICROBIT_SD_LIMIT); -#endif - // Start the BLE stack, if it isn't already running. - if (!ble) - { - bleManager.init(getName(), getSerial(), messageBus, true); - ble = bleManager.ble; - } - - // Enter pairing mode, using the LED matrix for any necessary pairing operations - bleManager.pairingMode(display, buttonA); - } - } -#endif - - // Attempt to bring up a second heap region, using unused memory normally reserved for Soft Device. -#if CONFIG_ENABLED(MICROBIT_HEAP_ALLOCATOR) && CONFIG_ENABLED(MICROBIT_HEAP_REUSE_SD) -#if CONFIG_ENABLED(MICROBIT_BLE_ENABLED) - microbit_create_heap(MICROBIT_SD_GATT_TABLE_START + MICROBIT_SD_GATT_TABLE_SIZE, MICROBIT_SD_LIMIT); -#else - microbit_create_heap(MICROBIT_SRAM_BASE, MICROBIT_SD_LIMIT); -#endif -#endif - -#if CONFIG_ENABLED(MICROBIT_BLE_ENABLED) - // Start the BLE stack, if it isn't already running. - if (!ble) - { - bleManager.init(getName(), getSerial(), messageBus, false); - ble = bleManager.ble; - } -#endif -} - -/** - * A listener to perform actions as a result of Message Bus reflection. - * - * In some cases we want to perform lazy instantiation of components, such as - * the compass and the accelerometer, where we only want to add them to the idle - * fiber when someone has the intention of using these components. - */ -void MicroBit::onListenerRegisteredEvent(MicroBitEvent evt) -{ - switch(evt.value) - { - case MICROBIT_ID_BUTTON_AB: - // A user has registered to receive events from the buttonAB multibutton. - // Disable click events from being generated by ButtonA and ButtonB, and defer the - // control of this to the multibutton handler. - // - // This way, buttons look independent unless a buttonAB is requested, at which - // point button A+B clicks can be correclty handled without breaking - // causal ordering. - buttonA.setEventConfiguration(MICROBIT_BUTTON_SIMPLE_EVENTS); - buttonB.setEventConfiguration(MICROBIT_BUTTON_SIMPLE_EVENTS); - buttonAB.setEventConfiguration(MICROBIT_BUTTON_ALL_EVENTS); - break; - - case MICROBIT_ID_COMPASS: - // A listener has been registered for the compass. - // The compass uses lazy instantiation, we just need to read the data once to start it running. - // Touch the compass through the heading() function to ensure it is calibrated. if it isn't this will launch any associated calibration algorithms. - compass.heading(); - - break; - - case MICROBIT_ID_ACCELEROMETER: - // A listener has been registered for the accelerometer. - // The accelerometer uses lazy instantiation, we just need to read the data once to start it running. - accelerometer.updateSample(); - break; - - case MICROBIT_ID_THERMOMETER: - // A listener has been registered for the thermometer. - // The thermometer uses lazy instantiation, we just need to read the data once to start it running. - thermometer.updateSample(); - break; - } -} - diff --git a/source/MicroBitSuperMain.cpp b/source/MicroBitSuperMain.cpp deleted file mode 100644 index 776bcf3..0000000 --- a/source/MicroBitSuperMain.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifdef UBIT_SUPERMAIN - -#include "MicroBitConfig.h" -#include "MicroBit.h" - -MicroBit uBit; - -int main() -{ -#if CONFIG_ENABLED(MICROBIT_DBG) - uBit.serial.printf("micro:bit runtime version %s\n", MICROBIT_DAL_VERSION); -#endif - - // Bring up random number generator, BLE, display and system timers. - uBit.init(); - - // Start the user application - app_main(); - - // If app_main exits, there may still be other fibers running, registered event handlers etc. - // Simply release this fiber, which will mean we enter the scheduler. Worse case, we then - // sit in the idle task forever, in a power efficient sleep. - release_fiber(); - - // We should never get here, but just in case. - while(1); -} - -#endif diff --git a/source/ble-services/MicroBitAccelerometerService.cpp b/source/bluetooth/MicroBitAccelerometerService.cpp similarity index 100% rename from source/ble-services/MicroBitAccelerometerService.cpp rename to source/bluetooth/MicroBitAccelerometerService.cpp diff --git a/source/ble-services/MicroBitBLEManager.cpp b/source/bluetooth/MicroBitBLEManager.cpp similarity index 100% rename from source/ble-services/MicroBitBLEManager.cpp rename to source/bluetooth/MicroBitBLEManager.cpp diff --git a/source/ble-services/MicroBitButtonService.cpp b/source/bluetooth/MicroBitButtonService.cpp similarity index 100% rename from source/ble-services/MicroBitButtonService.cpp rename to source/bluetooth/MicroBitButtonService.cpp diff --git a/source/ble-services/MicroBitDFUService.cpp b/source/bluetooth/MicroBitDFUService.cpp similarity index 100% rename from source/ble-services/MicroBitDFUService.cpp rename to source/bluetooth/MicroBitDFUService.cpp diff --git a/source/ble-services/MicroBitEventService.cpp b/source/bluetooth/MicroBitEventService.cpp similarity index 100% rename from source/ble-services/MicroBitEventService.cpp rename to source/bluetooth/MicroBitEventService.cpp diff --git a/source/ble-services/MicroBitIOPinService.cpp b/source/bluetooth/MicroBitIOPinService.cpp similarity index 100% rename from source/ble-services/MicroBitIOPinService.cpp rename to source/bluetooth/MicroBitIOPinService.cpp diff --git a/source/ble-services/MicroBitLEDService.cpp b/source/bluetooth/MicroBitLEDService.cpp similarity index 100% rename from source/ble-services/MicroBitLEDService.cpp rename to source/bluetooth/MicroBitLEDService.cpp diff --git a/source/ble-services/MicroBitMagnetometerService.cpp b/source/bluetooth/MicroBitMagnetometerService.cpp similarity index 100% rename from source/ble-services/MicroBitMagnetometerService.cpp rename to source/bluetooth/MicroBitMagnetometerService.cpp diff --git a/source/ble-services/MicroBitTemperatureService.cpp b/source/bluetooth/MicroBitTemperatureService.cpp similarity index 100% rename from source/ble-services/MicroBitTemperatureService.cpp rename to source/bluetooth/MicroBitTemperatureService.cpp diff --git a/source/MemberFunctionCallback.cpp b/source/core/MemberFunctionCallback.cpp similarity index 100% rename from source/MemberFunctionCallback.cpp rename to source/core/MemberFunctionCallback.cpp diff --git a/source/MicroBitCompat.cpp b/source/core/MicroBitCompat.cpp similarity index 100% rename from source/MicroBitCompat.cpp rename to source/core/MicroBitCompat.cpp diff --git a/source/MicroBitDevice.cpp b/source/core/MicroBitDevice.cpp similarity index 100% rename from source/MicroBitDevice.cpp rename to source/core/MicroBitDevice.cpp diff --git a/source/MicroBitFiber.cpp b/source/core/MicroBitFiber.cpp similarity index 100% rename from source/MicroBitFiber.cpp rename to source/core/MicroBitFiber.cpp diff --git a/source/MicroBitFont.cpp b/source/core/MicroBitFont.cpp similarity index 100% rename from source/MicroBitFont.cpp rename to source/core/MicroBitFont.cpp diff --git a/source/MicroBitHeapAllocator.cpp b/source/core/MicroBitHeapAllocator.cpp similarity index 100% rename from source/MicroBitHeapAllocator.cpp rename to source/core/MicroBitHeapAllocator.cpp diff --git a/source/MicroBitListener.cpp b/source/core/MicroBitListener.cpp similarity index 100% rename from source/MicroBitListener.cpp rename to source/core/MicroBitListener.cpp diff --git a/source/MicroBitSystemTimer.cpp b/source/core/MicroBitSystemTimer.cpp similarity index 100% rename from source/MicroBitSystemTimer.cpp rename to source/core/MicroBitSystemTimer.cpp diff --git a/source/DynamicPwm.cpp b/source/drivers/DynamicPwm.cpp similarity index 100% rename from source/DynamicPwm.cpp rename to source/drivers/DynamicPwm.cpp diff --git a/source/MicroBitAccelerometer.cpp b/source/drivers/MicroBitAccelerometer.cpp similarity index 100% rename from source/MicroBitAccelerometer.cpp rename to source/drivers/MicroBitAccelerometer.cpp diff --git a/source/MicroBitButton.cpp b/source/drivers/MicroBitButton.cpp similarity index 100% rename from source/MicroBitButton.cpp rename to source/drivers/MicroBitButton.cpp diff --git a/source/MicroBitCompass.cpp b/source/drivers/MicroBitCompass.cpp similarity index 100% rename from source/MicroBitCompass.cpp rename to source/drivers/MicroBitCompass.cpp diff --git a/source/MicroBitCompassCalibrator.cpp b/source/drivers/MicroBitCompassCalibrator.cpp similarity index 100% rename from source/MicroBitCompassCalibrator.cpp rename to source/drivers/MicroBitCompassCalibrator.cpp diff --git a/source/MicroBitDisplay.cpp b/source/drivers/MicroBitDisplay.cpp similarity index 100% rename from source/MicroBitDisplay.cpp rename to source/drivers/MicroBitDisplay.cpp diff --git a/source/MicroBitI2C.cpp b/source/drivers/MicroBitI2C.cpp similarity index 100% rename from source/MicroBitI2C.cpp rename to source/drivers/MicroBitI2C.cpp diff --git a/source/MicroBitIO.cpp b/source/drivers/MicroBitIO.cpp similarity index 100% rename from source/MicroBitIO.cpp rename to source/drivers/MicroBitIO.cpp diff --git a/source/MicroBitLightSensor.cpp b/source/drivers/MicroBitLightSensor.cpp similarity index 100% rename from source/MicroBitLightSensor.cpp rename to source/drivers/MicroBitLightSensor.cpp diff --git a/source/MicroBitMessageBus.cpp b/source/drivers/MicroBitMessageBus.cpp similarity index 100% rename from source/MicroBitMessageBus.cpp rename to source/drivers/MicroBitMessageBus.cpp diff --git a/source/MicroBitMultiButton.cpp b/source/drivers/MicroBitMultiButton.cpp similarity index 100% rename from source/MicroBitMultiButton.cpp rename to source/drivers/MicroBitMultiButton.cpp diff --git a/source/MicroBitPin.cpp b/source/drivers/MicroBitPin.cpp similarity index 100% rename from source/MicroBitPin.cpp rename to source/drivers/MicroBitPin.cpp diff --git a/source/ble-services/MicroBitRadio.cpp b/source/drivers/MicroBitRadio.cpp similarity index 100% rename from source/ble-services/MicroBitRadio.cpp rename to source/drivers/MicroBitRadio.cpp diff --git a/source/ble-services/MicroBitRadioDatagram.cpp b/source/drivers/MicroBitRadioDatagram.cpp similarity index 100% rename from source/ble-services/MicroBitRadioDatagram.cpp rename to source/drivers/MicroBitRadioDatagram.cpp diff --git a/source/ble-services/MicroBitRadioEvent.cpp b/source/drivers/MicroBitRadioEvent.cpp similarity index 100% rename from source/ble-services/MicroBitRadioEvent.cpp rename to source/drivers/MicroBitRadioEvent.cpp diff --git a/source/MicroBitSerial.cpp b/source/drivers/MicroBitSerial.cpp similarity index 100% rename from source/MicroBitSerial.cpp rename to source/drivers/MicroBitSerial.cpp diff --git a/source/MicroBitStorage.cpp b/source/drivers/MicroBitStorage.cpp similarity index 100% rename from source/MicroBitStorage.cpp rename to source/drivers/MicroBitStorage.cpp diff --git a/source/MicroBitThermometer.cpp b/source/drivers/MicroBitThermometer.cpp similarity index 100% rename from source/MicroBitThermometer.cpp rename to source/drivers/MicroBitThermometer.cpp diff --git a/source/ManagedString.cpp b/source/types/ManagedString.cpp similarity index 100% rename from source/ManagedString.cpp rename to source/types/ManagedString.cpp diff --git a/source/Matrix4.cpp b/source/types/Matrix4.cpp similarity index 100% rename from source/Matrix4.cpp rename to source/types/Matrix4.cpp diff --git a/source/MicroBitEvent.cpp b/source/types/MicroBitEvent.cpp similarity index 100% rename from source/MicroBitEvent.cpp rename to source/types/MicroBitEvent.cpp diff --git a/source/MicroBitImage.cpp b/source/types/MicroBitImage.cpp similarity index 100% rename from source/MicroBitImage.cpp rename to source/types/MicroBitImage.cpp diff --git a/source/PacketBuffer.cpp b/source/types/PacketBuffer.cpp similarity index 100% rename from source/PacketBuffer.cpp rename to source/types/PacketBuffer.cpp diff --git a/source/RefCounted.cpp b/source/types/RefCounted.cpp similarity index 100% rename from source/RefCounted.cpp rename to source/types/RefCounted.cpp