Commit graph

122 commits

Author SHA1 Message Date
Joe Finney d9d2343ab6 microbit: Add Multicast peer-to-peer radio capability
Integration of new radio mode that permits simple local area multicast communication
directly between micro:bits using the device's on board radio hardware.

It should be noted that this implementation build directly on the nrf51822
hardware. It is not a BLE protocol, and must (currently) be operated with BLE

A standard on the wire configuration is defined, to promote future
interoperability between projects and languages. A lightweight
packet format is also defined and adhered to, so as to promote future
extensibility without sacrificing compatibility. The notion of groups is also
introduced, that enable multiple groups of children to work in the same area
without compromising each other's projects.

In adition to a low level packet radio driver, two higher level protocols are
defined that allow simple user datagram communication between micro:bits and
an EventBus protocol that allows the micro:bit's MessageBus to be extended to
other micro:bits.
2016-02-01 04:29:27 +00:00
Joe Finney e3a23988f6 microbit: Promote constants in MicroBitBLEManager to .h file
Moved configuration constants from .cpp to .h file, so that they can be reused
more easily from other code, such as the broadcast radio code.
2016-02-01 04:25:51 +00:00
Joe Finney 66ed227663 microbit: Add new eventcodes for micro:bit App and radio broadcast
New registered eventcodes added for:
  - Game controller functions in the micro:bit app
  - General broadcast event ID in preparation for broadcast radio capability
2016-02-01 04:22:36 +00:00
Joe Finney 8756bbd103 WIP: Lower RAM footprint compass calibration
- moved to single precision floats
- optimised transpose/multiply operation
- optimisation of algorithm
2016-01-26 21:52:22 +00:00
Joe Finney e3fdc5a290 microbit: Support for bonding only available in pairing mode
Update to BLE initialisation code. Ability to initiate pairing is now
restricted to pairing mode.
2016-01-25 21:05:15 +00:00
James Devine 46af76fefb Merge pull request #81 from dpgeorge/seedrandom
Make MicroBit::seedRandom a public function with 2 variants.
2016-01-25 15:23:44 +00:00
Damien George 3160ba6268 Make MicroBit::seedRandom a public function with 2 variants.
seedRandom() seeds from the hardware RNG, whilst seedRandom(uint32_t)
seeds from the given 32-bit number.
2016-01-25 15:20:25 +00:00
James Devine 0a5e4a06af microbit: Added details for the i2c silicone glitch
As per the comment in the MicroBitI2c.h file lacked context around a known hardware glitch. This commit rectifies this issue by adding a link to a collection PDF providing a more detailed explanation.
2016-01-25 10:09:53 +00:00
Joe Finney 4f1870fda9 Merge branch 'master' into ble-whitelisting 2016-01-17 00:44:35 +00:00
Joe Finney 1c9ae30d1c microbit: Added basic bond table management
The Nordic BLE stack contains a fixed size bond table - a list of devices that
have paired with our device (in the case the micro:bit). The default mbed
wrapper around the nordic stack does not account for the case where the bond
table is full.

This patch implements basic bounds checking within the MicroBitBLEManager so
that this table cannot overrun. If a new device attempts to pair when the bond
table is full, the table is emptied prior to completing bonding.
2016-01-16 21:05:46 +00:00
Joe Finney e754ecf3aa microbit: Setting of default BLE transmission power level
Added configuration option in MicroBitConfig to allow the default power level
to be defined. Based on experiments undertaken by the BBC and subsequent policies defined by
the BBC's child protection panel, to is set by default it's lowest level (0),
in order to protect children's privacy.

It should be noted that this is 30dB below the device's default setting, so will
inevitably leave the device more susceptible to interference, and therefore
significantly reduce the reliability of the device. This will likely present
itself through increased packet loss, reduced thorughout, lost data and
connection drop outs. The normal BLE power level on commercial devices
translates to  power level of 6.

The author has witnessed an inability to connect to a micro:bit from a
distance of 40cm under domestic conditions using a Samsung S5 mini
running Android 4.4.2.
2016-01-16 17:29:46 +00:00
Joe Finney 07852b0cd6 microbit: Added support for BLE transmission power control
Added new method to MicroBitBLEManager to allow the radio transmission power
to be controlled. Provides a linear power level scale in the range 0..7.
2016-01-16 17:07:20 +00:00
Joe Finney f17151a0bf microbit: Added optional support for whitelisting and limited advertising
Added MicroBitConfig.h option to enable/disable whitelisting
Added MicroBitConfig.h option to enable/disable limited period advertising
Added support for limited period advertising
Minor code cleanups
2016-01-16 16:54:58 +00:00
James Devine acf6bf76eb microbit: further fixes to #73
issue #73 highlighted an issue whereby the destruction of an instance
registered as an idle or system component, would result in a hardfault.

This was due to not deregistering idle or system callbacks.

This patch has been applied to all components currently in use by the
idle or system callbacks.
2016-01-13 16:25:34 +00:00
James Devine 1cc814da60 microbit: further formatting corrections
Corrected trailing whitespace, and tabulated lines with no content for:

* MicroBitCompass.h (.cpp)
* MicroBitDisplay.h (.cpp)
* MicroBitMessageBus.h (.cpp)
2016-01-13 16:16:18 +00:00
James Devine d8240cfb74 microbit: formatting changes to MicroBitAccelerometer.h (.cpp)
Removed trailing whitespace, and tabulated lines with no content.
2016-01-13 16:01:51 +00:00
James Devine 7b7998e4eb microbit: formatting changes to MicroBit.h (.cpp)
Removed trailing whitespace, and tabulated lines with no content.
2016-01-13 15:04:29 +00:00
James Devine 8d3f3affbd microbit: fix for #73
The destructor for MicroBitButton didn't take into account the fact that
an instance can be destructed after registering a callback. This would then
result in a HardFault if an instance was destructed.

A clear repro case was registering a Touch input on a pin (abstracted as a button)
and swapping to a DigitalIn.
2016-01-13 14:15:50 +00:00
James Devine d2df88417b microbit: whitespace changes to MicroBitButton.h and .cpp
Cleared the files of trailing whitespace, and tabulated lines
2016-01-13 14:07:10 +00:00
James Devine 983e9e1ad3 microbit: added Servo API to MicroBitPin
* Added a number of #defines to MicroBitPin.h which ultimately lead to retabulation of the #defines

* Added two new instance methods:

	- setServoValue() which sets the default servo period (20ms) and accepts a value in the range
			  0 - 180, which maps to a duty cycle between 5% and 10% respectively. This
			  mapping is also configurable.

	- setServoPulseUs() which accepts a pulse width in microseconds, and maps it onto the PWM
2016-01-12 20:54:09 +00:00
James Devine 2650aaa569 microbit: MicroBitPin api additions
Based on the previous commit, the api for MicroBitPin
has two new accessor methods:

	* getAnalogPeriodUs
	* getAnalogPeriod

There are also whitespace changes in the MicroBitPin head file
as well as some minor textual changes.
2016-01-12 20:52:50 +00:00
James Devine 32c40cdc29 microbit: DynamicPwm fixes and additions
This commit introduces an initial draft fix
for a bug where it would take two "setPeriods" for the
PWM class to update to the expected value.

This commit also adds three new methods to a DynamicPwm instance:

	* write() -  which is a lightweight wrapper around PwmOut write,
	  so that the value can be trapped. The trapping of the value
	  is necessary for the bug fix.
	* getPeriod() - which returns the value of a static variable,
	  containing the current period shared across the pwm bus.
	* getValue() - which returns a scaled value in the range 0-1024
	  representing the current duty cycle.
2016-01-12 20:50:42 +00:00
James Devine 68474c5e58 microbit: modified constructor for DynamicPwm
Previously there would be the possibility of the period being reset
each time a new DynamicPwm was instantiated. This has now been
removed from the constructor, and the comments have been updated
2016-01-12 20:50:42 +00:00
Joe Finney 56a495fbd7 microbit: Update of MESEvent codes to avoid MICROBIT_EVT_ANY collision
Events listed recorded in MESEvents.h were enumerated from zero.
This is not ideal, as MicroBitMessageBus uses a code of zero for
MICROBIT_EVT_ANY - a wildcard mechanism to register interest in all events
from a given ID.

All event values recorded in MESEvents.h have therefore incremented.
2016-01-12 17:29:54 +00:00
Joe Finney 09cc2d73f4 microbit: update of edge connector pin mappings to match updated hardware design.
Definitions of pins changed as follows:

MICROBIT_PIN_P6 =>  P0_12 (COL9)
MICROBIT_PIN_P7 =>  P0_11 (COL8)
MICROBIT_PIN_P9 =>  P0_10 (COL7)
2016-01-12 14:50:36 +00:00
James Devine 493e174fe8 microbit: Fixed duplicated id for Thermometer
There was a duplication in IDs for MICROBIT_ID_THERMOMETER and MICROBIT_ID_IO_P0
for the event bus. This has been rectified by appending the MICROBIT_ID_THERMOMETER
2016-01-11 13:39:56 +00:00
James Sheppard 13f6bce86b Merge pull request #69 from lancaster-university/events-definition
Events definition updated
2016-01-11 12:09:27 +00:00
James Sheppard 3491187a0d TODOs for DISPLAY_TOAST and PLAY_SOUND 2016-01-11 12:03:50 +00:00
Joe Finney 0da7903e24 Merge branch 'master' into compass-autocalibration 2016-01-09 19:10:04 +00:00
Joe Finney db25d4c0c3 microbit: Further corrections to comment blocks 2016-01-09 18:47:15 +00:00
Joe Finney 0e7a6979da microbit: Comment Cleanup
corrections to comment blocks only.
2016-01-09 11:54:23 +00:00
Joe Finney 92905593f1 microbit: Added support for MicroBitHeapAllocator to allocate C++ style array

Added missing operator new[] wrapper in MicroBitHeapAllocator.h
Ammended defualt microBitConfig.h to allocate 90% of available heap, rather
than 95%. this is to leave a little more heap for external libraries.
2016-01-09 11:33:02 +00:00
Joe Finney 6916d506b8 microbit: Removed print funcitons from matrix class due to SRAM overhead of
native printf() call.

The Matrix4::print() function is useful, but non essential for most
applications, and the underlying printf() call required cost an
additional 1K of RAM on first use, which is currently above the budget for
2016-01-09 10:25:26 +00:00
Joe Finney d51b1205f7 microbit: Added support for compass tilt compensation
An e-compass solution requires knowwlede two pieces of data to provide an
accurate heading:

  - Accurate calibration of the magnetometer hardware so that reliable
    measurements can be taken.
  - Knowledge of the pitch and roll of of device, so that the correct
    components of the X/Y and Z axis sensors of the magnetomer can be used
    to sense the magnetic field in a horizontal plane regardless of the tilt
    of the device.

This commit represent changes to the MicroBitAccelerometer and MicroBitCompass
classes to implemen tthese goals. More specifically, this commit provides:

 - The introduciton of an interactive calibration 'game', that can rapidly
   gather all the data required to calibrate the compass.

 - An improved calibration algorithm based on a Least Mean Squares approach of
   compass samples, as documened in Freescale Application Note AN4248.

 - The inclusion of a simple Matrix4 class to enable efficient Least Mean
   Squares implementation.

 - A change from asynchronous to synchronous calibration of the compass when
   first used. This is in repsonse to a feature request for this from users
   and high level languages using microbit-dal.

 - Support for detemrining tilt and roll angle in MicroBitAccelerometer

 - Support for multiple co-ordinate spaces in MicroBitAccelerometer and
   MicroBitCompass. Data can now be read in either RAW (unaltered) data.
   (the industry convention in mobile phones, tablets and aviation)

 - Implementation of a tilt compensated algorithm, used when determining
   device heading.
2016-01-09 00:20:19 +00:00
James Sheppard e82ca68521 MES_DEVICE_INCOMING_CALL and _MESSAGE values added 2016-01-08 16:22:20 +00:00
James Sheppard 41e2fc6b74 MES_PLAY_CONTROLLER removed (descoped) 2016-01-08 16:15:06 +00:00
James Sheppard db436a4f09 MES_AUDIO_RECORDER events removed 2016-01-08 16:10:14 +00:00
Joe Finney 3416e54a36 microbit: increase sensitivity of freefall detection
Freefall now detected when the net force on the device drops below 0.4g,
rather than 0.2g as previously defined. This improves sensitivity, without
generating false positives under common use.

Also correction of minor typos / layout errors.
2016-01-05 16:23:47 +00:00
Joe Finney 17632adafa Merge branch 'master' into basic-gestures 2016-01-05 15:50:53 +00:00
Joe Finney d3587d888c microbit: code scrub of MicroBitAccelerometer gesture recognition code
- updated acceleration threshold event names to reflect numeric values e.g.
  - Add scoping to elements of SimpleGesture enum.
  - Code scrub of code layout caused by editor with incorrect configuration.
  - rename of internal state variables and functions to better reflect use.
  - added clarification to some comments.
2016-01-05 15:44:57 +00:00
Joe Finney 55601f3e0e Merge branch 'master' into secure-ble 2016-01-05 01:25:52 +00:00
Joe Finney 203246b975 WIP: Revert to public addresses pending further debug 2015-12-18 12:27:08 +00:00
Joe Finney c7ea0af6fe WIP: Analysing correct use of private resolvable addresses 2015-12-17 14:27:57 +00:00
Joe Finney 14831ac9b9 Updates to BLE 2.1.11 / ble-nrf51822 2.2.3
Minor amends:
  - bleDisconnectionCallback signature change
  - bleSetAdvertisingInterval now takes milliseconds as a parameter
  - event based invocation of DFU bootloader
2015-12-11 04:57:06 +00:00
Joe Finney 6d610f049a microbit: Updates to Pairing Mode to improve the user experience
More specifically:

- BLUEZONE mode renamed to PairingMode (by popular request).
- Added timeout of 90 seconds before automatic device reboot.
- Move from a scroll to a print based algorithm to improve the amount of time key is displayed fully.
- Added compulsory 'click to bond' button press.
- Improved response time of tick/cross being displayed.
2015-12-11 03:43:18 +00:00
Joe Finney e042a55522 microbit: Added compile time option to enabe support for BLE private resolvable addresses.
Introduced MICROBIT_BLE_PRIVATE_ADDRESSES configuration option.
Disabled by default, as it did not resolve binds correctly on Android 4.4.2
2015-12-11 01:38:22 +00:00
Joe Finney 1b18ac8641 microbit: Added basic gesture recognition into MicroBitAccelerometer
The following postures of the device are now detected:

In addition, the following gestures are inferred:

- WHEEE (>=3g)
- SICK (>=5g)

Events are now triggered on the MessageBus upon the transition from one posture/gesture to another,
and a synchronous getGesture() method is now also provided to interogate the last gesture recognised.

I should be noted that the default accelerator range of +/-2g will be insufficient to detect some of
the events noted above, and MicroBitAccelerometer::setRange() should be used to increase the range
if required.
2015-12-03 15:11:31 +00:00
Joe Finney f0cbfb4c50 microbit: Default display brightness changed to 100%
Feedback from trials showed that this improved daylight visibility, especially for the first programs before kids have
discovered brightness APIs.
2015-11-30 00:51:26 +00:00
Joe Finney ac381fa5dc microbit: Alpha version of standard BLE MITM passkey security
- refactored BLE funcitonality into BLEManager class.
- added security requirements standard BLE profile services.
- updated bluezone pairing process to use BLE passkey exchange.
2015-11-16 13:44:27 +00:00
Joe Finney 79c739674c first compiling build. 2015-11-15 14:31:44 +00:00