Commit graph

37 commits

Author SHA1 Message Date
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.
   MICORBIT_SIMPLE_CARTESIAN (as used previously) or NORTH_EAST_DOWN
   (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
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
f5cf8f2dd4 microbit: Minor optimisations to patch
- LFSR generated values in a subset of the range requested (rounded to the nearest lower power of 2).
   Corrected by increasing the number of bits usedby one, such that it now generated st least the power of 2 greater.

 - replaced enable/disable of interrupts with a local snapshot of randomValue. Much of the nordic software is sensitive to interrupt timings,
   so best avoided where possible. Chance of race condition is low, and effect is minimal (duplicate number returned).
2015-11-30 00:43:24 +00:00
Joe Finney
958136673f Merge branch 'fix-random' of https://github.com/remay/microbit-dal into remay-fix-random 2015-11-29 23:43:46 +00:00
Robert May
5333729644 Revert "Cchange random() to use libc srand()/rand()"
This reverts commit db5227872a.

return to using our own random implementation.
2015-11-18 15:50:44 +00:00
Robert May
db5227872a Cchange random() to use libc srand()/rand()
Uisng libc's implementation is likely to be safer than rolling our own.  At least
the failure modes are well documented. (glibc's implementation of rand() is
actually not bad).
2015-11-18 14:15:17 +00:00
Robert May
1bb4377c8c Combine loops and fix max returned value. 2015-11-18 12:08:34 +00:00
Robert May
901faaeec7 reset variable m in the correct place. 2015-11-17 18:51:10 +00:00
Robert May
892689c54a Fix Microbit::random() to be random
The LFSR used only provides 1 bit of random data each time it is cycled.
This implementation generates the minimum number of bits needed.  Further
it discards numbers that are bigger than required and re-calculates -
this keeps the distribution flat.
2015-11-17 18:33:34 +00:00
Michal Moskal
56a560e5bc Merge branch 'master' into flatstring
Conflicts:
	.gitignore
	inc/ErrorNo.h
	source/MicroBitDisplay.cpp
	source/MicroBitImage.cpp
2015-11-12 16:13:45 -08:00
Joe Finney
435debffed Merge branch 'quiet-gcc-build' of https://github.com/remay/microbit-dal into remay-quiet-gcc-build 2015-11-08 13:50:33 +00:00
Joe Finney
13456c60c1 microbit: Removal of explicit Serial instance for debugging.
Debugging now runs via the standrad MicroBit::serial interface.
2015-11-01 23:42:53 +00:00
Robert May
1a1a5976a8 Silence GCC -Wall 2015-11-01 20:19:17 +00:00
Joe Finney
194f19a428 Merge branch 'simplified-eventing' 2015-11-01 18:22:27 +00:00
Joe Finney
84da6a4a09 microbit: Minor bug fixes and refinements
- Add maximum depth for event queues, to prevent buggy scripts causing total memory exhaustion.
  - Suppress generation of A/B click events when A+B click is generated
  - preservation of event ordering on messagebus for resursive event generation cases.
  - bugfix of message bus processing to prevent occasional dual processing of events
  - bugfix MicroBitDisplay to behave correctly when delay parameter is zero.
2015-10-31 10:27:38 +00:00
Michal Moskal
59853855b0 Remove caching of getSerial(); use temporary for BLE init 2015-10-27 08:26:07 -07:00
Joe Finney
823a956d68 microbit: First cut at updates to provide tight validation within the runtime code, with a view to moving
NOP/clamping behaviour out of teh micro:bit runtime and into the glue layers of higher level
languages.

 - Updates to many functions to provide explicut return codes.
 - Updates to many functions to remove heuristic calidation (NOP/clamping/defaults)
 - Updates to ErrorNo.h to provide clearer return values, and place return values in a better scope
 - Updates to MicroBitDisplay to use enums where appropriate.
2015-10-25 21:51:33 +00:00
Michal Moskal
057158c9f3 Cache getSerial(); otherwise BLE information device initalization may crash 2015-10-24 19:28:36 -07:00
Joe Finney
bfe1b4db53 microbit: some work on tightening the API return codes.
still work in progress.
2015-10-21 11:35:59 +01:00
Joe Finney
80f79f7faf Merge branch 'master' into ble-profile
Conflicts:
	source/CMakeLists.txt
	source/MicroBit.cpp
	source/MicroBitFiber.cpp
	source/MicroBitMessageBus.cpp
	source/MicroBitSuperMain.cpp
2015-10-18 17:54:37 +01:00
Joe Finney
db3eccf6ff microbit: Final updates to BLE profile
Minor changes to BLE profile services (cleanup prior to merge with master branch):

  - Added temperature period characteristic to match design pattern of other sensors.
  - Updated endinaness of MicroBitLEDService Matrix to be more intuitive.
  - Cleaned up Microbit.cpp by removing unused reference to BLE services.
  - Exposed serial number and naming information thr BLE DeviceInformation and API.
  - Updated BLE advertisement period to be alightly more repsonsive (200ms vs 1000ms).
  - BUGFIX: micro:bit name is now always generated, regardless of BLE services.
  - BUGFIX: Scroll Period data length.
2015-10-18 14:46:42 +01:00
Joe Finney
122d885ee8 microbit: Updated Bluetooth device name from MicroBit to micro:bit to match brand guidelines 2015-10-09 00:03:01 +01:00
Joe Finney
85a26dc8e1 microbit: Updates to enable semantic versioning of the micro:bit runtime DAL
More specifically, the build system now uses the semantic versioning meta-data
held in module.json to define a major.minor.patch version. Additionally, is the branch
being compiled is *not* the master branch, the version is appended with <branchname><githash>.

Specific updates:

- Updates to CMake files to expose this to the micro:bit runtime code.
- Addition of uBit.systemVersion() to expose this to application code.
- Displaying of version string over serial if MICROBIT_DBG is enabled.
- Distribution of version string over BLE via the firmware revision characteristic.
2015-10-08 14:37:35 +01:00
Joe Finney
18236810a3 microbit: BLE Profile Beta 1
First functionally complete BLE profile, matching BLE speicfication v1.6.
More specifically, the following services are now functional:

  - AccelerometerService
  - MeganetometerService
  - EventService
  - TemperatureServide
  - IOPinService
  - DFUService
  - ButtonService
  - LEDService

Also, updates to underlying device drivers to enable greater configurability:

  - MicroBitCompass now supports variable sample rates and temperature sensing
  - MicroBitAccelerometer now supports variable sample rates and ranges
  - MicroBitThermometer introduced
  - MicroBitMessageBus adapted to permit enumeration and block removal of listeners

Finally, MicroBit DFU Service has been changed to the new UUIDs specificed in v1.6 of BLE spec.
2015-09-28 21:40:44 +01:00
Joe Finney
4314b68643 microbit: First implementation of Temperature Service 2015-09-23 22:15:44 +01:00
Joe Finney
eb5ed28f74 microbit: First cut at MicroBitButtonService and microBitIOPinService
Strictly still development - untested code.
2015-09-22 16:13:08 +01:00
Joe Finney
ef613e9d86 microbit: Added BLE Magnetometer service compilation, initialization and configuration options 2015-09-19 22:19:57 +01:00
Joe Finney
ae0e5611c3 microbit: First draft of reconfigurable frequencies of MicroBitCompass 2015-09-19 21:00:38 +01:00
Joe Finney
ec30695d7d microbit: BUGFIX MicroBit::reset() now operates correctly 2015-09-17 23:32:40 +01:00
Joe Finney
7e18131849 microbit: Added MicroBitLEDService
One of the standard services defiend with the Bluetooth SIG. Allows remote control
of the LED matrix display over BLE.
2015-09-07 17:09:17 +01:00
Joe Finney
6470b71b1d microbit: Conditional compilation on MicroBitConfig
All options defined in MicroBitConfig are now set IFF they already do not have a value.
This allows external configuration of these options much more cleanly. Additional macros
also defined to provide clean implementation for boolean configuration switches.

Also some minor bugfixes:

  - Correction of typo of "Microbit.h" => "MicroBit.h"
  - Fixed heap corruption bug on gcc as a result of a debug printf in an unsafe context.
2015-09-02 12:42:24 +01:00
Joe Finney
857a626ed0 microbit: Memory Optimisation Mega Update
This release contains a widespread set of updates and optimisations to the micro:bit
runtime, with a view to reducing the SRAM footprint of the whole system. This is to
provide as much usable HEAP storage for application programs as possible.

Specific updates and optimisations include:

  - Additional compilation flags to allow the core micro:bit runtime to be configured.
    These are defined in MicroBitConfig.h

  - A custom heap allocator. This is now included for two reasons:

    1) To provide a simple mechanism to to utilise both the mbed heap space and other memory
       regions (such as unused memory in the SoftDevice region) as a single virtual heap.
    2) To address some issues that have been noted that are attributable to heap fragmentation.
       The micro:bit heap allocator has a simple algorithm, but one that is chosen to respond
       well to the relativelt high 'heap churn' found in the micro:bit environment.

    All micro:bit components and user programs now use this heap allocator trasparently.

  - Updates to BLE services to remove persistent references to their GATT services. This consumes
    vast amounts SRAM, rather unecessarily. Instead only handles to the relevant GATT characteristics
    are now stored. This specifically includes:
      + MicroBitDFUService
      + MicroBitEventService
      + DeviceInformationService

  - Updates to the Fiber scheduler to save SRAM. More specifically:
      + Removed the need to hold an empty processor context to intialise fibers.
      + The IDLE fiber now runs without a stack
      + fiber stacks are now only created when a fiber is descheduled for the first time, thereby reducing heap churn.
      + the 'main' fiber is now recycled into the fiber_pool if it leaves app_main()
      + fibers created through invoke() now only maintains the necessary part of teh parent stack that is needed, thereby
        reducing the stack size of spawned fibers.

  - Updates to the Message Bus to reduce the overall memory footprint of processing events. More specifically:
      + Event handlers are now always called using invoke(), such that non-blocking event handlers no longer need
        a dedicated fiber to execute - thereby saving SRAM and processor time.
      + Processing of events from the event queue is now rate paced. Events only continue to be processed as long as there
        are no fibers on the run queue. i.e. event processing is no longer greedy, thereby reducing the number of fibers
        created on the runqueue.

  - Updates to BLUEZOENE code to bring up core BLE services even if they are not enabled by default. This allows
    programs that do not require BLE to operate to benefit from the full range of SRAM, whilst still allowing the
    device to be programmed over BLE.

  - Updates to the Soft Device initialisation configuration, reducing the size of the GATT table held in the top 1.8K
    of its 8K memory region to around 800 bytes. This is sufficient to run the default set of BLE services on the micro:bit
    so the additional memory is configured as HEAP storage by MicroBitHeapAllocator.

  - Minor changes to a range of components to integrate with the above changes.
    + rename of free() to release() in DynamicPWM to avoid namespace collision with MicroBitHeap free()
    + rename of fork_on_block to invoke() to enhance readbility.

  - Many code cleanups and updates to out of date comments.
2015-08-31 23:25:10 +01:00
Joe Finney
42f43b2255 Merge branch 'master' of https://github.com/lancaster-university/microbit-dal 2015-08-19 23:48:36 +01:00
Joe Finney
58d24ab0a8 microbit: Updated MicroBitMessageBus to use fork_on_block functionality
Updates the MicroBitMessageBus implementation to use fork_on_block() calls rather
than create_fiber() calls when servicing events. This provides greater optimisation
for non-blocking event handlers.

More specifically, this update:

 - Replaces calls to create_fiber() ith fork_on_block during event send operations.
 - Adds a queue of events, to ensure events generated from interrupt context are not serviced in interrupt context.
 - Registers a listener with the idle process to empty the event queue.
2015-08-19 23:35:45 +01:00
James Devine
3ef5901c5b microbit-dal: added a reset mechanism to uBit
Users can now call uBit.reset() to reset the device.
2015-08-14 16:51:45 +01:00
James Devine
f8ebfc69fb microbit-dal: added #define to determine BLE usage
NO_BLE can now be defined to determine whether ble
will be brought up or not at initialisation of uBit.
This is especially useful for two new Yotta targets:
bbc-microbit-classic-gcc-nosd,
bbc-microbit-classic-armcc-nosd, which do not use
softdevice.
2015-08-13 00:49:48 +01:00
James Devine
538e1c48bd microbit-dal: Initial Commit
This is the first commit of the microbit-dal on GitHub.
This repository contains the runtime, which is a light
weight operating system developed by Lancaster University.
2015-08-12 11:53:41 +01:00