Commit Graph

200 Commits

Author SHA1 Message Date
Joe Finney 2f6d405e81 microbit: Introduced managed type for packet buffers.
Introduce PacketBuffer as a mutable reference counted type Radio operations
Updated send() and recv() to use PacketBuffer rather than ManagedString
2016-02-09 01:04:57 +00:00
James Devine af13c940c1 microbit: add RSSI to MicroBitRadio
Added the ability to capture the RSSI value, and an accessor and
mutator for the last received RSSI value.
2016-02-04 03:45:57 +00:00
James Devine ffc217e7ac microbit: fixed formatting issues in MicroBitRadio
Removed trailing whitespace.
2016-02-04 03:44:25 +00:00
Joe Finney 9d039fd9be microbit: BUGFIX Corrected length calculation for validation case
Incorreclty calculated payload bug also addressed here.
2016-02-03 14:41:45 +00:00
Joe Finney 5cb265c158 microbit: BUGFIX: Length field of datagram receive now correct
Datagram receive code incorrectly calculated the payload length, resulting in
packets being delivered to applications that were two bytes shorter than they
should be.
2016-02-03 14:35:12 +00:00
James Devine 41447b634d Merge pull request #89 from lancaster-university/ble-ccccd-persist
Basic Persistent Storage
2016-02-02 21:50:33 +00:00
James Devine 23d56edbdd microbit: integrated MicroBitStorage with MicroBitCompass
This commit introduces persistent storage for the compass between
device resets.

setCalibration now also stores the data in FLASH if it differs from
what it contains.

In source/MicroBitSuperMain.cpp, the data is restored if there is
persistent data available that is non-zero.

(i.e. x, y and z are NOT zero).

This ensures that users can code without interference from persistent
storage.
2016-02-02 21:24:40 +00:00
James Devine 4c9f32d79a microbit: added debug to MicroBitStorage
Added debug to make testing simpler and faster.
2016-02-02 21:24:40 +00:00
Joe Finney 5e7334b0bf microbit: integrated persistent storage for CCCD data.
There is an issue (https://github.com/bbc/microbit-extras/issues/2755)
whereby CCCD data is required to be persisted through device resets.

This commit integrates the new MicroBitStorage class, and persistently
stores this information in flash.

P.S. what a long night!
2016-02-02 21:24:40 +00:00
Joe Finney d1d78b9b35 microbit: added MicroBitStorage for Persistent data
Integrated simple 1K block buffer to host small amount of persistent
data and a 1K FLASH memory block located immediately below the FOTA/DFU
bootloader and APPDATA region that intended to hold core configuration
information, such as:

* BLE bonding information.
* Compass Calibration data.
* Thermometer Calibration data.

The block is resident at 0x0003B400 - 0x0003B800.
2016-02-02 21:22:49 +00:00
James Devine f546da66e8 microbit: improved appearance of greyscale
The impact of the pixels at lower values was  not distinct enough
this commit adds a blocking wait for the first two timings for
greyscale.

Additionally, this commit  modifies the timings const array to
take into account the time taken for renderGreyscale to execute.
2016-02-02 17:05:59 +00:00
James Devine 3596f3d842 microbit: update to greyscale mode
Floats were used as timings for the renderTimer in MicroBitDisplay.
Now timings are in us, and a direct called to renderTimer.attach_us
is now used.
2016-02-02 16:36:09 +00:00
James Devine 4cefd55ef5 microbit: updated the dal to use a higher resolution ticker.
Previously the DAL relied upon an implementation of a timer that
was very imprecise and lacked resolution, this commit adds a reference
to a frozen repo with us_ticker.c modifications, so that a higher resolution
timer is utilised.

This fixes #13 (finally), and also fixes lower brightness levels when using
DISPLAY_MODE_BLACK_AND_WHITE to not cause a device lockup.
2016-02-02 16:21:28 +00:00
James Devine 3fa9bb09c2 microbit: fixed an off by 10 bug
Missed a zero in a previous commit, that caused a system lockup due to
a missed timer event.

This commit also changes the minimum display brightness to 4, to also
minimise another feature that needs fixing in the future, where the
timer does not interrupt in the expected time frame.
2016-02-02 01:13:39 +00:00
James Devine a27b2314be microbit: modified the range of read() MicroBitLightSensor
Previously the range of MicrobitLightSensor read() was 0 - 100,
this didn't align with other APIs.

The new range is 0-255 which aligns with display brightness to give
a more consistent overall API.
2016-02-01 23:58:33 +00:00
Joe Finney e983b80b0b Merge branch 'master' into ble-bondtablepurge 2016-02-01 22:50:05 +00:00
Joe Finney e7132b0d13 microbit: Change to BLE bonding table replacement policy
Previous revisions of microbit-dal would handle the case of a bonding request
when the bond table was full by attempting to purge the bonding table on
demand. This suffered two flaws:

 1) Nordic's device manager does not support the purging of the bonding table
while a connection is active (including a pairing request).

 2) Some devices (e.g. Android 4.4.2 take two entries in the bonding table
when paired), thus making predictions of how 'full' the table is challenging.

This patch employs a simpler replacement policy. The maximum size of the bond
table has been increased to 6 (from 4). However, if the bond table contains 4
or more entries when entering pairing mode it will be purged in advance of any
pairing requetss being initiated.
2016-02-01 22:30:03 +00:00
James Devine 97c49d3279 Merge pull request #87 from lancaster-university/broadcast-radio
Adding Multicast peer-to-peer radio support MicroBitRadio!
2016-02-01 21:50:54 +00:00
James Devine 004b701419 Merge pull request #86 from lancaster-university/light-sensor
Adding MicroBitLightSensor to the DAL
2016-02-01 21:50:22 +00:00
James Devine 8150b2ac67 microbit: modified as per suggestions
* This commit fixes an exposed member variable
  that was not intended to be public 'tickPeriod'

* normalised the light level to return values between 0 - 100
2016-02-01 21:46:15 +00:00
Joe Finney 9026ca6e98 microbit: Optimisation of BLE mutex.
The BLE stack locks out the CPU for long periods of time when necessary. This
can be alleviated by eans of a flag that release the CPU between radio events.
(BLE_COMMON_OPT_RADIO_CPU_MUTEX).

This can cause issues from applications with tighter timing requirements.
This patch only enables this MUTEX when a BLE connection is active, rather
than automatically at startup. Therefore, application that do not actively use
BLE will not suffer this penalty.
2016-02-01 19:25:07 +00:00
Joe Finney 6838b38fc1 microbit: Remove redundant characteristics in BLE DeviceInformationService
The MANUFACTURER and HARDWARE_REVISION fields from this standard service have
been removed, as they carried no useful information.
2016-02-01 18:59:48 +00:00
Joe Finney 8bec31fe76 microbit: Additional validation on MicroBitRadio methods
MicroBitRadio methods that touch internal RADIO registers now ensure that
the BLE stack is not running before changing such registers.
2016-02-01 18:19:02 +00:00
Joe Finney d7aa95e867 microbit: minor updates to consistently use the MICROBIT_RADIO_HEADER_SIZE constant 2016-02-01 18:05:02 +00:00
Joe Finney 12c9ed246a microbit: Whitespace fixes 2016-02-01 17:54:33 +00:00
Joe Finney 420a73673d microbit: rename of MicroBitRadioEvent methods to align with MessageBus naming conventions. 2016-02-01 17:43:17 +00:00
Joe Finney 336c30f2ec microbit: Integrate Multicast peer to peer communications into MicroBit.cpp
- Added instance variable and constructor call in MircoBit.cpp
  - Added event definitions for RADIO related indications
2016-02-01 04:40:21 +00:00
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
disabled.

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
James Devine 6b0e9cf489 microbit: integrated MicroBitLightSensor with MicroBitDisplay
Previously, to light sense a user would have to configure a
MicroBitLightSensor instance themselves, and flip the display mode
manually. This is difficult in languages that target our API.

This commit resolves that by adding a new method readLightLevel which
flips the display mode, and instantiates a light sensor.

When changing the mode, the tickSpeed is also modified to reduce
artefacts on the display.
2016-01-29 14:13:41 +00:00
James Devine 2049e63039 microbit: added MicroBitLightSensor
Added a new class called MicroBitLightSensor which interleaves sensing
with the display.

This class takes advantage of the previous commits which add a dynamic
system tick, and a new display mode for the display.

A future optimisation would be for the display to handle the instantion
of a light sensor when the display mode is changed!
2016-01-29 14:10:52 +00:00
James Devine 6e316dc741 microbit: added accessor/mutator for systemTick
This commit adds a mutator that dynamically reconfigures the
systemTicker to call systemTick at a different period to the default.

The accessor returns the current tick speed in milliseconds.

The accessor is now also used in scheduler_tick to keep timing as
accurate as possible.

MICROBIT_DISPLAY_REFRESH_PERIOD has now been removed, and replaced with
MICROBIT_DEFAULT_TICK_PERIOD.
2016-01-29 14:07:36 +00:00
James Devine 6f812aa474 microbit: added new display mode, and accessor
This commit introduces a new display mode,
DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE, where the 4th render in
every “frame” is dropped allowing for other components that use the
display to use this dropped frame for processing. This is in
preparation for Light Sensing on the 5x5 LED matrix.

An accessor has also been added to MicroBitDisplay to check the current
display mode!
2016-01-29 14:03:24 +00:00
James Devine 6939ad25d9 microbit: formatting changes to MicroBitFiber
Corrected whitespace in MicroBitFiber.
2016-01-29 13:57:34 +00:00
Joe Finney 0bbb5b9123 microbit: Code cleanup
Removal of debugging information and redundant algorithms.
2016-01-28 17:09:01 +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
Joe Finney 99d7231945 microbit: Persistance of BLE Service Chnaged metadata
BLE maintains metadata on its characterisitics, some of which record whether
or not a central device (phone/tablet) wishes to receive notifications when a
given BLE characteristic changes value. One such characterisitic is used as
part of a core BLE service to indicate of the BLE profile of a device has
changed.

IOS is heavily reliant on this feature, and expects the state of this metadata
to be persistent across device reboots. This patch ensures that this metadata
is always set to allow Service Changed indications to be propagated to central
devices.
2016-01-25 21:05:13 +00:00
Joe Finney 6a7436e5c7 Merge pull request #48 from remay/quiet-gcc-build
Tidy up gcc -Wall fixes

Thanks @remay!
2016-01-25 20:55:37 +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
Joe Finney a4c0915fff microbit: BUGFIX Prevent BLE Magnetometer service from initiating compass
calibration

MicroBitCompass initiates a calibration procedure on demand if a heading is
requested from an uncalibrated device. The BLE MagnetometerService also
attempts to retrieve a heading periodically, but it is not good behaviour to
initiate calibration as a response to this.

This patch introduces a check such that the BLE MagnetometerService will only
attempt to read heading data from a previously calibrated compass.
2016-01-19 00:32:02 +00:00
Joe Finney 4f1870fda9 Merge branch 'master' into ble-whitelisting 2016-01-17 00:44:35 +00:00
Joe Finney 13eb3c07e7 microbit: Add explicit service changed notification
BLE central devices (such as mobile phones/tablets) are permitted to cache the
list of services and characteristics provided by a BLE peripheral such as the
micro:bit. This was causing compatibility problems with IOS during FOTA
flashing, as the the list of BLE services may change after flashing.
2016-01-17 00:23:00 +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 b2484dcc97 microbit: patch for animation/scroll behaviour for images
See bbc/microbit-extras/issues/#1100 or lancaster-university/microbit-dal/issues/5 for full details.

Summary:

A stride of 0 would lock the calling fiber indefinitely, which was not the expected behaviour
for many people.

This update fixes this issue in both animate and scroll, returning immediately when there is
a stride of zero.
2016-01-14 12:56:58 +00:00
Robert May 098a2378e3 Merge lancaster-university/master and silence warnings. 2016-01-13 20:51:49 +01: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