Skip to content

Commit

Permalink
Merge pull request #11 from calliope-mini/merge-upstream
Browse files Browse the repository at this point in the history
Merge upstream into master, confirmed by Calliope Team
  • Loading branch information
gruenwaldi authored Oct 15, 2019
2 parents 16f82c9 + c7331c1 commit ae1b537
Show file tree
Hide file tree
Showing 64 changed files with 6,310 additions and 5,981 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ build
yotta_modules
yotta_targets
*.swp
*~
Makefile
.idea
*.iml
46 changes: 46 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
This file highlights all notable changes between tagged releases on the master branch of this repository, in the form of release notes.

For a more detailed treatment of changes, please see the commit history of the github repository containing this file.

Version 2.1.1 (23/11/19 [email protected])
- Partial flashing is no longer a default service in C++ builds
- Make microbit_heap_print() available globally
- Remove unused MicroBitPin objects
- Add capability to set radio upper and lower frequency bands in yotta config
- Fix radio power in C++ builds

Version 2.1.0 (18/10/18 [email protected])
- Refactor of motion sensor devices to support a range of accelerometer/magnetometer
sensors through abstract high level classes and concrete device specific subclasses.
- Introduction of resusable 3D coordinate space transformation code.
- Autodetection algorithm for I2C based accelerometer/magnetometer sensors.
- Add support for LSM303 accelerometer/magnetometer sensor.
- Add support for FXOS8700 accelerometer/magnetometer sensor.
- Update compass calibration UX to gather more samples during calibration
in order to improve accuracy. The algorithm now asks the user to "tilt to
fill the screen" with pixels, rather than 'draw a circle' of pixels.
- More resilient compass calibration algorithm based on iterative
approximation that provides more accurate calibration in the presence of
local magnetic fileds, such as those caused by a battery pack.
- Updates to heap memory allocator. The MicroBitHeapAllocator now replaces
the GNU libc heap allocator, rather than exisitng in parallel with it, in
order to reduce memory fragmentation and ensure that all allocations
benefit from multiple heap region support and interrupt safety.
- Added new bluetooth partial flashing service, that allows rapid
reprogramming of the micro:bit over bluetooth in the common case.
- Improved graphics for bluetooth pairing mode.
- Support to allow explicit launch of conmpass calibration algorithm via BLE characteristic.
- Support for integrated hardware quadrature decoder

- Minor bug fixes/code optimisations including:
- the message bus event routing code to support multiple event listeners
with the same id, value and context.
- accelerometer pitch measurement algorithm now has a full 0..360 degree range.
- Support for SHAKE gesture recognition in tight loops.
- prevent device lockups when routing UART pins to the edge connector.
- support for changing RADIO frequency whilst active.
- accurate configurations for optional SoftDevice S130v2.

Version 2.0.0
Initial Open Source Release

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The core set of drivers, mechanisms and types that make up the micro:bit runtime

The micro:bit runtime provides an easy to use environment for programming the BBC micro:bit in the C/C++ language, written by Lancaster University. It contains device drivers for all the hardware capabilities of the micro:bit, and also a suite of runtime mechanisms to make programming the micro:bit easier and more flexible. These range from control of the LED matrix display to peer-to-peer radio communication and secure Bluetooth Low Energy services. The micro:bit runtime is proudly built on the ARM mbed and Nordic nrf51 platforms.

In addition to supporting development in C/C++, the runtime is also designed specifically to support higher level languages provided by our partners that target the micro:bit. It is currently used as a support library for all the languages on the BBC www.microbit.co.uk website, including the Microsoft Block Editor, Microsoft Touch Develop, Code Kingdoms JavaScript and Micropython languages.
In addition to supporting development in C/C++, the runtime is also designed specifically to support higher level languages provided by our partners that target the micro:bit. It is currently used as a support library for all the languages on the BBC www.microbit.org website; including the Javascript Blocks Editor and Micropython

## Links

Expand Down Expand Up @@ -40,4 +40,4 @@ int main()

## BBC Community Guidelines

[BBC Community Guidelines](https://www.microbit.co.uk/help#sect_cg)
[Microbit Community Guidelines](http://microbit.org/community/)
4 changes: 0 additions & 4 deletions inc/bluetooth/MicroBitAccelerometerService.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ DEALINGS IN THE SOFTWARE.

#include "MicroBitConfig.h"
#include "ble/BLE.h"
#ifdef TARGET_NRF51_CALLIOPE
#include "MicroBitAccelerometer-bmx.h"
#else
#include "MicroBitAccelerometer.h"
#endif
#include "EventModel.h"

// UUIDs for our service and characteristics
Expand Down
29 changes: 29 additions & 0 deletions inc/bluetooth/MicroBitBLEManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ DEALINGS IN THE SOFTWARE.
#include "MicroBitButtonService.h"
#include "MicroBitIOPinService.h"
#include "MicroBitTemperatureService.h"
#include "MicroBitPartialFlashingService.h"
#include "ExternalEvents.h"
#include "MicroBitButton.h"
#include "MicroBitStorage.h"
Expand Down Expand Up @@ -281,6 +282,19 @@ class MicroBitBLEManager : MicroBitComponent
int advertiseEddystoneUid(const char* uid_namespace, const char* uid_instance, int8_t calibratedPower = MICROBIT_BLE_EDDYSTONE_DEFAULT_POWER, bool connectable = true, uint16_t interval = MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL);
#endif

/**
* Restarts in BLE Mode
*
*/
void restartInBLEMode();

/**
* Get current BLE mode; application, pairing
* #define MICROBIT_MODE_PAIRING 0x00
* #define MICROBIT_MODE_APPLICATION 0x01
*/
uint8_t getCurrentMode();

private:
/**
* Displays the device's ID code as a histogram on the provided MicroBitDisplay instance.
Expand All @@ -289,12 +303,27 @@ class MicroBitBLEManager : MicroBitComponent
*/
void showNameHistogram(MicroBitDisplay &display);


/**
* Displays pairing mode animation
*
* @param display The display instance used for displaying the histogram.
*/
void showManagementModeAnimation(MicroBitDisplay &display);

#define MICROBIT_BLE_DISCONNECT_AFTER_PAIRING_DELAY 500
unsigned long pairing_completed_at_time;

int pairingStatus;
ManagedString passKey;
ManagedString deviceName;

/*
* Default to Application Mode
* This variable will be set to MICROBIT_MODE_PAIRING if pairingMode() is executed.
*/
uint8_t currentMode = MICROBIT_MODE_APPLICATION;

};

#endif
2 changes: 1 addition & 1 deletion inc/bluetooth/MicroBitIOPinService.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ DEALINGS IN THE SOFTWARE.
#include "ble/BLE.h"
#include "MicroBitIO.h"

#define MICROBIT_IO_PIN_SERVICE_PINCOUNT 19
#define MICROBIT_IO_PIN_SERVICE_PINCOUNT 20
#define MICROBIT_IO_PIN_SERVICE_DATA_SIZE 10
#define MICROBIT_PWM_PIN_SERVICE_DATA_SIZE 2

Expand Down
4 changes: 0 additions & 4 deletions inc/bluetooth/MicroBitMagnetometerService.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ DEALINGS IN THE SOFTWARE.

#include "ble/BLE.h"
#include "MicroBitConfig.h"
#ifdef TARGET_NRF51_CALLIOPE
#include "MicroBitCompass-bmx.h"
#else
#include "MicroBitCompass.h"
#endif
#include "EventModel.h"

#define COMPASS_CALIBRATION_STATUS_UNKNOWN 0
Expand Down
111 changes: 111 additions & 0 deletions inc/bluetooth/MicroBitPartialFlashingService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
The MIT License (MIT)
This class has been written by Sam Kent for the Microbit Educational Foundation.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/

#ifndef MICROBIT_PARTIAL_FLASH_SERVICE_H
#define MICROBIT_PARTIAL_FLASH_SERVICE_H

#include "MicroBitConfig.h"
#include "MicroBitBLEManager.h"
#include "ble/BLE.h"
#include "MicroBitMemoryMap.h"

#include "MicroBitFlash.h"
#include "MicroBitStorage.h"

#include "MicroBitComponent.h"
#include "MicroBitEvent.h"
#include "MicroBitListener.h"
#include "EventModel.h"

#define PARTIAL_FLASHING_VERSION 0x01

// BLE PF Control Codes
#define REGION_INFO 0x00
#define FLASH_DATA 0x01
#define END_OF_TRANSMISSION 0x02

// BLE Utilities
#define MICROBIT_STATUS 0xEE
#define MICROBIT_RESET 0xFF

// UUIDs for our service and characteristics
extern const uint8_t MicroBitPartialFlashingServiceUUID[];
extern const uint8_t MicroBitPartialFlashingServiceCharacteristicUUID[];

/**
* Class definition for the custom MicroBit Partial Flash Service.
* Provides a BLE service to remotely read the memory map and flash the PXT program.
*/
class MicroBitPartialFlashingService
{
public:
/**
* Constructor.
* Create a representation of the Partial Flash Service
* @param _ble The instance of a BLE device that we're running on.
* @param _memoryMap An instance of MicroBiteMemoryMap to interface with.
*/
MicroBitPartialFlashingService(BLEDevice &_ble, EventModel &_messageBus);

/**
* Callback. Invoked when any of our attributes are written via BLE.
*/
void onDataWritten(const GattWriteCallbackParams *params);

/**
* Callback. Invoked when any of our attributes are read via BLE.
*/
void onDataRead(GattReadAuthCallbackParams *params);

private:
// M:B Bluetooth stack and MessageBus
BLEDevice &ble;
EventModel &messageBus;

/**
* Writing to flash inside MicroBitEvent rather than in the ISR
*/
void partialFlashingEvent(MicroBitEvent e);

// Handles to access each characteristic when they are held by Soft Device.
GattAttribute::Handle_t partialFlashCharacteristicHandle;

/**
* Process a Partial Flashing data packet
*/
void flashData(uint8_t *data);

// Ensure packets are in order
uint8_t packetCount = 0;
uint8_t blockPacketCount = 0;

// Keep track of blocks of data
uint32_t block[16];
uint8_t blockNum = 0;
uint32_t offset = 0;

};


#endif
4 changes: 4 additions & 0 deletions inc/core/ErrorNo.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,9 @@ enum PanicCode{

// Dereference of a NULL pointer through the ManagedType class,
MICROBIT_NULL_DEREFERENCE = 40,

// A requested hardware peripheral could not be found,
MICROBIT_HARDWARE_UNAVAILABLE_ACC = 50,
MICROBIT_HARDWARE_UNAVAILABLE_MAG = 51,
};
#endif
23 changes: 21 additions & 2 deletions inc/core/EventModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@ DEALINGS IN THE SOFTWARE.
*/
class EventModel
{
protected:
void (*listener_deletion_callback)(MicroBitListener *); // if not null, this function is invoked when a listener is removed.

public:

static EventModel *defaultEventBus;

// Set listener_deletion_callback to NULL.
EventModel() : listener_deletion_callback(NULL) {}

/**
* Queues the given event to be sent to all registered recipients.
* The method of delivery will vary depending on the underlying implementation.
Expand Down Expand Up @@ -130,6 +136,17 @@ class EventModel
return MICROBIT_OK;
}

/**
* Sets a pointer to handler that's invoked when any listener is deleted.
*
* @returns MICROBIT_OK on success.
**/
int setListenerDeletionCallback(void (*listener_deletion_callback)(MicroBitListener *))
{
this->listener_deletion_callback = listener_deletion_callback;
return MICROBIT_OK;
}

/**
* Register a listener function.
*
Expand Down Expand Up @@ -298,6 +315,8 @@ class EventModel
* @param id The Event ID used to register the listener.
* @param value The Event value used to register the listener.
* @param handler The function used to register the listener.
* @param arg the arg that is passed to the handler on an event. Used to differentiate between handlers with the same id and source, but not the same arg.
* Defaults to NULL, which means any handler with the same id, event and callback is removed.
*
* @return MICROBIT_OK on success or MICROBIT_INVALID_PARAMETER if the handler
* given is NULL.
Expand All @@ -315,12 +334,12 @@ class EventModel
* uBit.messageBus.ignore(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonBClick);
* @endcode
*/
int ignore(int id, int value, void (*handler)(MicroBitEvent, void*))
int ignore(int id, int value, void (*handler)(MicroBitEvent, void*), void* arg = NULL)
{
if (handler == NULL)
return MICROBIT_INVALID_PARAMETER;

MicroBitListener listener(id, value, handler, NULL);
MicroBitListener listener(id, value, handler, arg);
remove(&listener);

return MICROBIT_OK;
Expand Down
5 changes: 5 additions & 0 deletions inc/core/MicroBitComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ und Björn Eberhardt GbR by arrangement with Calliope GbR.
#define MICROBIT_ID_MULTIBUTTON_ATTACH 31
#define MICROBIT_ID_SERIAL 32

#define MICROBIT_ID_IO_INT1 33 //INT1
#define MICROBIT_ID_IO_INT2 34 //INT2
#define MICROBIT_ID_IO_INT3 35 //INT3
#define MICROBIT_ID_PARTIAL_FLASHING 36

#define MICROBIT_ID_MESSAGE_BUS_LISTENER 1021 // Message bus indication that a handler for a given ID has been registered.
#define MICROBIT_ID_NOTIFY_ONE 1022 // Notfication channel, for general purpose synchronisation
#define MICROBIT_ID_NOTIFY 1023 // Notfication channel, for general purpose synchronisation
Expand Down
Loading

0 comments on commit ae1b537

Please sign in to comment.