Commit Graph

105 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
Michal Moskal 845bf4838c Fix allocation size for ImageData (the header is 6, not 4 bytes long) 2015-11-17 15:57:19 -08: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
Joe Finney b44095f0c5 BUGFIX: String comparison operations
Corrected response of < and > operations where substrings are compared.
2015-11-17 17:20:30 +00:00
Joe Finney 9b5fa0fcfc minor bugfixes in MICROBIT_HEAP_DEBUG 2015-11-17 16:58:42 +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 ea51f396ca Added compatibility for builds under ARMCC 2015-11-08 18:04:17 +00: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
Joe Finney 1a65e4e7bc microbit: Added support for soft reset button in panic mode
Also recalibrated loop timers in MicroBitDisplay::Error(), as used by panic()...
strange these now seem off by several orders of magnitude.

TODO: Ensure CPU is running at correct internal frequency with an oscilloscope test...
2015-11-01 21:33:46 +00:00
Robert May b8083908a7 Correct warnings supression in more obvious way
Whilst a little more invasive change than the previous warnings
supression this is more correct and more obvious as to what's being done,
and what warnigns will remain in place for the rest of the comilation
unit.
2015-11-01 20:19:18 +00:00
Robert May 9591ef40dc Turn off -Wunused-parameter for include "nrf_soc.h"
Unfortunately we can't turn it off just while nrf_soc.h is being included
as the way the defines are used the compiler can't tell the parameters
are unused until the end of the compilation unit.  So we can't use the
more normal

as that pops the supression too early.

WARNING: including nrf_soc.h will turn off unused-function warnings for
the rest of the compilation unit - see included nrf_svc.h
2015-11-01 20:19:17 +00:00
Robert May 1a1a5976a8 Silence GCC -Wall 2015-11-01 20:19:17 +00:00
Robert May 3a8c72144f up the cmake version required to 2.8.12, which is required for target_compile_options. 2015-11-01 20:19:17 +00:00
Robert May a39ba7d4f7 Turn off GCC warnings when building the dependancies 2015-11-01 20:19:17 +00:00
Robert May b2d3417559 Fix build when $git_branch fails to be set correctly. 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 1b6d6038c1 Merge branch 'master' into tight-validation 2015-11-01 16:28:08 +00:00
Joe Finney 77af825df0 Merge branch 'master' into simplified-eventing 2015-11-01 16:27:15 +00:00
Joe Finney 39abf824dc microbit: More efficient handling of events
Removed unnecessary queing of item on the MessageBus, whilst maintaining causal ordering.
2015-11-01 15:16:27 +00:00
Joe Finney b2e9369771 microbit: BUGFIX DoS attacks on the MessageBus
- Enures an event listener is not deleted whilst a fiber is activiely processing a queue
 - Added support for resurrection of event listeners in cases where identical listeners are removed/added repetitively.
2015-11-01 12:59:52 +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
Joe Finney 0fa8296048 microbit: BUGFIX safe deletion of listeners
also correction to minor bu in MicroBitFiber that could conceivably send more
notifications that it should...
2015-10-29 00:08:33 +00:00
Joe Finney 1eeaeca2c6 microbit: BUGFIX - correct initialization of MicroBitListener
code now correctly initiailizes the evt_queue filed needed to prevent
lockup during event processing (understandably!).
2015-10-28 14:17:12 +00:00
Michal Moskal 3900962556 Remove specific panic codes for ref-counting. 2015-10-27 08:28:06 -07:00
Michal Moskal 59853855b0 Remove caching of getSerial(); use temporary for BLE init 2015-10-27 08:26:07 -07:00
Michal Moskal 6437e714fa Delete when ref-count goes to 1, not 2\! 2015-10-27 08:19:56 -07:00
Michal Moskal c1050df0d9 Make the image width/height 16 bit wide 2015-10-27 08:02:42 -07:00
Joe Finney 7f64a4c703 microbit: BUGFIX Corrected incorrect handling of MicroBitMessageBus::add return values. 2015-10-26 16:37:12 +00: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 7b82f3e8eb Improve comments; cleanup 2015-10-25 13:09:24 -07:00
Michal Moskal 98ffcc1fd1 Add status panic codes for ref-count errors 2015-10-25 12:59:45 -07:00
Michal Moskal 85b4e45863 Order-of-initialization fix. 2015-10-25 11:38:00 -07:00
Michal Moskal d0b75c96d1 Add MicroBitImage::isReadOnly,clone.
Add MicroBitImage,ManagedString::leakData().
Work more on incr()/decr() protocol.
2015-10-25 10:03:14 -07:00
Michal Moskal 11c99d0b84 Make the reference count always odd to make it possible to distinguish it from a vtable 2015-10-25 08:30:05 -07:00
Michal Moskal 5df59c2f7e Remove VirtualRefCounted class; non-virtual <-> virtual casts are not no-ops. 2015-10-24 21:52:51 -07:00
Michal Moskal 4f82a6c37c Use RefCounted also for MicroBitImage. 2015-10-24 20:58:03 -07:00
Michal Moskal 9330b401d5 Move RefCounted class to a separate file 2015-10-24 20:30:15 -07:00
Michal Moskal 5a10bda561 First stab at more memory efficient strings 2015-10-24 19:34:04 -07: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 613f524bab microbit: BUGFIX: micro:bit not entering BLUEZONE mode cleanly
Fixed bug in GAP advertisement configuration.
2015-10-19 14:42:13 +01:00
Joe Finney 72e5a9a6a6 microbit: BUGFIX - post merge fixes
- MicroBitDisplay::scroll() timing bug
  - MicroBitDisplay::print() timing bug
  - MicroBitFiber wait/notify bug
2015-10-18 19:09:54 +01:00