Commit Graph

230 Commits

Author SHA1 Message Date
James Devine 732971e758 microbit-dal: Added events to MicroBitPin
Added rise, fall, pulse HI and LO events.

The pulse Hi and LO event timestamp given in the MicroBitEvent is the
duration for which the input was HI or LO for.

eventOn(int eventType) is used to configure the events generated
from the pin instance.
2016-04-27 13:59:11 +01:00
James Devine 3923dffffc microbit-dal: increase granularity of the system wide timer
Added an mbed Timer instance to maintain a microsecond level timestamp.

Added a function system_timer_current_time_us() which now returns the
time since power on in microseconds.

MicroBitEvents now call system_timer_current_time_us() giving
microsecond level timestamps.
2016-04-25 11:30:28 +01:00
James Devine 8875dc35d2 microbit-dal: added yotta configuration mappings to DAL specific configuration options.
Yotta can now be used to configure the configuration options for the
dal.

An full config.json looks like:

{
    "microbit-dal":{
        "bluetooth":{
            "enabled": 1,
            "pairing_mode": 0,
            "private_addressing": 0,
            "open": 0,
            "whitelist": 1,
            "advertising_timeout": 0,
            "tx_power": 0,
            "dfu_service": 1,
            "event_service": 1,
            "device_info_service": 1
        },
        "reuse_sd": 1,
        "gatt_table_size": "0x300",
        "heap_allocator": 1,
        "nested_heap_proportion": 0.75,
        "system_tick_period": 6,
        "system_components": 10,
        "idle_components": 6,
        "use_accel_lsb": 0,
        "min_display_brightness": 1,
        "max_display_brightness": 255,
        "display_scroll_speed": 120,
        "display_scroll_stride": -1,
        "display_print_speed": 400,
        "panic_on_heap_full": 1,
        "debug": 0,
        "heap_debug": 0,
        "stack_size":2048,
        "sram_base":"0x20000008",
        "sram_end":"0x20004000",
        "sd_limit":"0x20002000",
        "gatt_table_start":"0x20001900"
    }
}
2016-04-19 15:02:28 +01:00
James Devine 44b3daeca2 microbit-dal: modified duplicate conflicting ID for MICROBIT_ID_BLE_UART 2016-04-15 14:16:31 +01:00
James Devine 9914a98050 Merge pull request #120 from bluetooth-mdw/master
Added BLE connect/disconnect events and fixed bug in MagnetometerService.cpp

Possible fix for #114
2016-04-15 14:12:19 +01:00
Martin Woolley 051abec174 Changed BLE connection event constant names to match LU groovy naming convention 2016-04-15 13:56:23 +01:00
James Devine 7cf98c2290 microbit-dal: patch for fiber_wake_on_event
fiber_wake_on_event used to crash after forking a FOB fiber.

It would attempt to obtain a new fiber context, and would place it on the wait queue.
Then when that fiber was paged in, the context of that fiber would not have been
initialised, as the function presumed schedule would be called immediately after
fiber initialisation.

This patch catches that edge case.
2016-04-15 13:40:41 +01:00
Martin Woolley 87f7233a84 Added BLE connect/disconnect events and fixed bug in MagnetometerService re: bearing characteristic 2016-04-15 13:38:24 +01:00
Joe Finney 94e2c66185 microbit: Additional optional autoClear parameter to MicroBitDisplay::animate
The MicroBitDisplay::animate() and MicroBitDisplayAnimateAsync() function both
assumed that the display should be cleared once the requested animation was
complete.

This patch allows the user to control this funcitonality through an
addiitonal, optional boolean parameter to the animate() and animateAsync()
functions.
2016-04-15 12:37:09 +01:00
Joe Finney b5193dbcb7 microbit: BUGFIX - missing NULL initialisation in templated MicroBitListener 2016-04-07 17:41:21 +01:00
James Devine 63a8ae81ec microbit-dal: Fixed multiline note which had artefacts in microbit-docs. 2016-04-07 11:32:13 +01:00
James Devine 387c4f18e4 microbit-dal: fixed C99 incompatible array initialisation.
Removed { 0 }; from all buffer initialisations.

Also replaced all uses of Serial::IrqType:: with IrqType::
2016-04-07 11:31:33 +01:00
James Devine 55cb919987 microbit-dal: Added MIT license information. 2016-04-06 17:07:03 +01:00
James Devine ea91e0281a microbit-dal: more doxygen documentation updates. 2016-04-05 23:41:32 +01:00
James Devine d6310db9aa microbit-dal: further updates to doxygen style comments used for documentation 2016-04-04 02:01:15 +01:00
James Devine 2f7d361ed5 microbit-dal: updates to doxygen style comments used for documentation generation. 2016-03-29 08:02:57 +01:00
Joe Finney d6079d45d2 microbit: Updated SERIAL_DEBUG symbol to a pointer
Moved the global SERIAL_DEBUG symbol from a reference to a pointer. This is to
enable late binding of a debug channel.
2016-03-26 20:31:29 +00:00
James Devine b5c8714ea3 microbit: added BLE UART service
Added a serial implementation for bluetooth, needs a review at a later date.
2016-03-26 19:53:28 +00:00
James Devine 728604423f microbit: refactored event codes used by a shared listener "MICROBIT_ID_NOTIFY"
There was no common place to track event codes used in Events intended
for the shared channel using the ID MICROBIT_ID_NOTIFY. This commit
adds a common place for these Event codes.
2016-03-26 19:39:05 +00:00
Joe Finney 3efd76e9d4 microbit: Update to MicroBitMultiButton contructor signature
Changed ordering of parameters to promote consistency with other components.
2016-03-26 11:58:36 +00:00
Joe Finney 0a1a9c7865 microbit: Consistency change in scheduler_init()
Updated parameter of scheduler_init() to accpet a reference to an EventModel,
rather than a pointer. This is simply to promote consistency with the other
components.
2016-03-24 23:30:17 +00:00
James Devine f35c4b359e microbit: MicroBitLightSensor startSensing is now public! 2016-03-24 16:05:11 +00:00
Joe Finney 06c3c95609 microbit: Restructure of repo
- Introduction of core, drivers, types and bluetooth folders in source and inc
- Added all inc subfolfers to the search path
- Removed MicroBit.cpp and MicroBit.h (yay!)
2016-03-24 14:00:11 +00:00
Joe Finney 2b684c6204 microbit: Added default parameter values to common case operations
MicroBitImage::paste() now assumes the image to be pasted should be positioned
at the top left of the image by default, with no transparency.

MicroBitImage::print() now assumes the char to be printed should be positioned
at the top left of the image by default.
2016-03-24 11:40:20 +00:00
Joe Finney f5f983dbdd microbit: Added explicit support for printing characters in MicroBitDisplay
The C type system connaot easily distinguish integer literals from character
literals. To promote a simpler API, the print() overload for numeric values
has been replaced with an explicit printChar() method.

Print operation on single byte strings have been ammended to act consistently
with printing a single digit.
2016-03-24 11:40:18 +00:00
James Devine 03a5353cc0 microbit: Added MicroBitSerial default mode config option, and modified overload for send(char)
MicroBitSerial now uses a #define in MicroBitConfig.h to configure the default mode
for send and read calls.

send(char c, MicroBitSerialMode mode) has now been renamed to sendChar(char c, MicroBitSerialMode mode),
which means if users want to send an integer as a char, they have to do so explicitly.
2016-03-24 11:17:23 +00:00
Joe Finney cc2beb02c6 microbit: Added overload to allow direct send/receive of strings via
MicroBitRadioDatagram

 - Added constructor into managedString to allow conversion from PcketBuffer
 - Added overload of MicroBitRadioDatagram::send() to accpet a string
2016-03-24 10:33:05 +00:00
James Devine 79a13c7edf Merge branch 'component-refactor' of https://github.com/lancaster-university/microbit-dal into component-refactor 2016-03-24 00:45:33 +00:00
James Devine a512afb1b3 microbit: MicroBitSerial memory optimisation
Previously, MicroBitSerial inherited from Serial, which had a large
memory overhead.

n.b. This is due to a setbuf call in the underlying stdio library that
mallocs a massive struct, which is largely unused.

MicroBitSerial now inherits from RawSerial, which doesn’t use any
setbuf calls, thus reducing the static memory overhead of
MicroBitSerial to 8 bytes (448 bytes), when unused.

The definition for SERIAL_DEBUG in MicroBitConfig has now been updated
to use RawSerial instead of Serial.
2016-03-24 00:43:10 +00:00
James Devine 613a0aef2c microbit: MicroBitStorage additional comments, and page location changes
Added additional information for the arrangement memory for a
KeyValueStore in persistent storage.

Also moved the storage page to an unused page after the BLE bond data,
and the scratch page to where application storage page was previously
located.
2016-03-24 00:34:46 +00:00
James Devine 12c84395d3 microbit: Added fiber_wake_on_event to MicroBitFiber[.h,.cpp]
Added a new call fiber_wake_on_event which does not call schedule. This
means that execution continues after the context has been set until the
next use of schedule (i.e. fiber_sleep).
2016-03-24 00:32:41 +00:00
Joe Finney 91cd6d2a08 microbit: Updated enable/disable functions in MicroBitDisplay to free pin
resources cleanly.
2016-03-24 00:18:32 +00:00
Joe Finney 10298934da microbit: Generalised MicrobitDisplay to be mbed compliant
Removed references to direct nrf51 sdk calls, in favour of the mbed
PortOut class, which provides equivalent functionality whilst remaining
platform agnostic.
2016-03-23 21:25:51 +00:00
Joe Finney 31b7eb487f microbit: Factored repurposeable functionality out of MicroBit.cpp
- moved all device specific utility funcitons into MicroBitDevice.cpp
 - moved compass calibration funcitonality into a dedicated class
 - moved panic() from MicroBitDisplay into MicroBitDevice
 - introduced inline utility functions into MicroBit to promote a degree of
   backward compatibility and easy of use.
 - updated panic() to use platform agnostic mbed calls.
2016-03-23 19:30:15 +00:00
Joe Finney 6b6c83092a microbit: Added validation check on MicroBit::init()
Added simple validation check to protect against accidental re-initialisation.
2016-03-22 19:49:14 +00:00
Joe Finney 34856a6942 microbit: refactor of component constructors
- Updates to ordering and default values for component constructors to improve
consistency, and to common default default values for parameters where
applicable.

- Updates to MiroBitDisplay MatrixMap to record physical geometry in addition
to logical geometry of LED matrix display layouts. This removes the need for
explicit (and unecessary) definition of display size by the user.
2016-03-22 19:36:23 +00:00
James Devine 8bd34edfd1 microbit: updated MicroBitStorage to use our new MICROBIT_NO_DATA error code
MicroBitStorage previously used MICROBIT_NOT_SUPPORTED if the given key was not found
during a remove call, it now returns MICROBIT_NO_DATA.
2016-03-21 13:31:14 +00:00
James Devine 937395f0f4 microbit: MicroBitSerial redesign
This implementation uses a circular buffer for both transmission and reception of data.

There are a number of new methods:

	* redirect - which dynamically redirects the output of the serial module
	* eventOn and eventAfter - which fire events based on delimeters, or x number of characters.
	* operations on the circular buffers.

A main difference is the ability to select the mode you want to perform your operation in:

	* ASYNC - reads directly from the circular buffer, returning immediately.
	* SYNC_SPINWAIT - spins whilst reading from the circular buffer.
	* SYNC_SLEEP - blocks the current fiber, but doesn't lock out the processor,
		       whilst reading from the circular buffer.

This should support a wide variety of operations. To see more specific details of the different methods,
it is advised to read the doxygen comments for each method.
2016-03-21 13:27:20 +00:00
James Devine 174fa29c81 microbit: fixed overload ambiguity in MicroBitStorage
MicroBitStorage accepts both ManagedString and char * variants, this
caused ambiguity at compile time, and meant that the ManagedString
variant was never selected when given character literals. This meant
that the only way to access the ManagedString variant, was to explicitly
wrap the character literals.

This applies to:
	* put
	* get
	* remove

The fix was to apply a const prefix to all member functions accepting
a char *.
2016-03-20 18:28:48 +00:00
James Devine 468d7e24c5 microbit: MicroBitThermometer lazy addition to fiber components
Previously, MicroBitThermometer was always added to fiber_components,
even in the case where it wasn't actually in use.

This commit introduces a similar behaviour to that introduced to the compass
and accelerometer classes in previous commits, where these components
are only added to fiber_components when in use.

Similarly, MicroBitThermometer now has an exposed updateSample() member
function that can be used to manually drive temperature updates, if
the fiber scheduler is not in use.
2016-03-20 17:05:32 +00:00
James Devine aca1c24a24 microbit: added calibration and persistence to MicroBitThermometer
MicroBitThermometer now persists data using MicroBitStorage. An instance
of MicroBitStorage must be given at construction, if data is required to
be persisted.

The ability to calibrate the thermometer using an offset has been added
as well, produces the data that is then persisted by MicroBitStorage.
2016-03-20 17:05:31 +00:00
James Devine 4988fd4ea7 microbit: moved MicroBitStorage to a Key Value Store
MicroBitStorage used to rely on a static struct as a memory
map when writing to flash "MicroBitConfigBlock", this solution
was constraining, and not fit for general purpose.

Whilst modularising the runtime, a cyclic dependency between
MicroBitStorage and MicroBitCompass was discovered, which meant
these two class could not be fully decoupled.

This version of MicroBitStorage is a Key Value Store, and allows
3 base operations:

	* put - add a new KeyValuePair to flash
	* get - retreive a KeyValuePair from flash
	* remove - delete a KeyValuePair from flash

An instance of MicroBitStorage is also now a part of uBit (uBit.storage)
and this is now passed as a parameter to the constructors of BLEManager
and compass, both of which require the persistence of data.

There are also overloads for the constructors of MicroBitBLEManager
and MicroBitCompass, which do not require an instance of
MicroBitStorage to be passed.
2016-03-20 17:05:31 +00:00
Joe Finney 78ed31961c microbit: BUGFIX blocking display functions not terminating when scheduler
disabled

Calls to synchronous/blocking display animations, e.g. scroll("HELLO!"), did
not terminate correctly due to over optimisation in the
MicroBitDisplay::FiberWait() method.

Also corrected potential deadlock caused by an animation being explicitly
terminated.
2016-03-19 01:48:23 +00:00
Joe Finney 1dce004f10 microbit: Updates to enable BLE services to utilise the EventModel interface
- Updated all BLE services from the standard profile to us the defualt registered event model
- Updates to trigger calibration (when necessary) when BLE MagnetometerService is activated
- Updates to compass calibration algorithm to be non blocking (reduce unecessary fiber stack overhead)
- Cleanup of unused/out of date MicroBitConfig BLE options
2016-03-19 00:46:34 +00:00
Joe Finney 398f054956 microbit: Refactor of MicroBitHeap Allocator
- Cleanup of MicroBitHeapAllocator related CONFIG options to add clarity
 - Refactor of MicroBitHeapAllocator to provide more control over heap
   initialisation.
 - Creation of SERIAL_DEBUG macro in MicroBitConfig to permite external
   definition of a debug console.
 - Added validation cases to MicroBitFiber to protect against calls to fiber
   operations when the scheduler has not been initialised.
2016-03-18 01:30:54 +00:00
Joe Finney 3531cde893 microbit: Updates to all components to include MicroBitConfig.h
Also added configuration option to enable / disable MicroBitHeapAllocator
overloads.
2016-03-17 17:33:57 +00:00
Joe Finney 0e8034c5bc microbit: Replaced all internal references of the MicroBitMessageBus class
to the abstract EventModel interface.
2016-03-17 16:57:22 +00:00
Joe Finney 83390b9663 microbit: Update to camel case in comment blocks: uBit.MessageBus -> uBit.messageBus 2016-03-17 16:09:41 +00:00
Joe Finney 5b167fb743 microbit: completed removal of internal #include dependencies on Microbit.h 2016-03-17 16:02:50 +00:00
James Devine 7fc98ccaf8 microbit: WIP header refactor
Removed references to MicroBit.h in some header and cpp files.

As a result a number of changes had to be made in order to satisfy
include dependencies.
2016-03-17 14:47:43 +00:00