Microbug / MicroBitDAL_SB2_TEST

Fork of MicroBitDALImageRewrite by Joe Finney

Committer:
finneyj
Date:
Sun Apr 12 17:38:56 2015 +0000
Revision:
0:47d8ba08580f
Child:
1:3e0360107f98
First draft implementation of core functionality. Includes:; ;   - OO model of microBit device.;   - Flexible geometry LD matirx driver.;   - Lazy, instatiation free I/O; ; Please note this code is largely untested.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
finneyj 0:47d8ba08580f 1 /**
finneyj 0:47d8ba08580f 2 * Class definition for a MicroBit device.
finneyj 0:47d8ba08580f 3 *
finneyj 0:47d8ba08580f 4 * Represents the device as a whole, and includes member variables to that reflect the components of the system.
finneyj 0:47d8ba08580f 5 */
finneyj 0:47d8ba08580f 6
finneyj 0:47d8ba08580f 7 #ifndef MICROBIT_H
finneyj 0:47d8ba08580f 8 #define MICROBIT_H
finneyj 0:47d8ba08580f 9
finneyj 0:47d8ba08580f 10 #include "mbed.h"
finneyj 0:47d8ba08580f 11 #include "MicroBitButton.h"
finneyj 0:47d8ba08580f 12 #include "MicroBitDisplay.h"
finneyj 0:47d8ba08580f 13 #include "MicroBitImage.h"
finneyj 0:47d8ba08580f 14 #include "MicroBitIO.h"
finneyj 0:47d8ba08580f 15 #include "MicroBitLED.h"
finneyj 0:47d8ba08580f 16
finneyj 0:47d8ba08580f 17 #define MICROBIT_IO_PINS 8 // TODO: Need to know how many. :-)
finneyj 0:47d8ba08580f 18
finneyj 0:47d8ba08580f 19 // Enumeration of core components.
finneyj 0:47d8ba08580f 20 #define MICROBIT_ID_LEFT_BUTTON 1
finneyj 0:47d8ba08580f 21 #define MICROBIT_ID_RIGHT_BUTTON 2
finneyj 0:47d8ba08580f 22 #define MICROBIT_ID_USER_LED 3
finneyj 0:47d8ba08580f 23 #define MICROBIT_ID_DISPLAY 5
finneyj 0:47d8ba08580f 24 #define MICROBIT_ID_IO_1 6
finneyj 0:47d8ba08580f 25 #define MICROBIT_ID_IO_2 7
finneyj 0:47d8ba08580f 26 #define MICROBIT_ID_IO_3 8
finneyj 0:47d8ba08580f 27 #define MICROBIT_ID_IO_4 9
finneyj 0:47d8ba08580f 28 #define MICROBIT_ID_IO_5 10
finneyj 0:47d8ba08580f 29 #define MICROBIT_ID_IO_6 11
finneyj 0:47d8ba08580f 30 #define MICROBIT_ID_IO_7 12
finneyj 0:47d8ba08580f 31 #define MICROBIT_ID_IO_8 13
finneyj 0:47d8ba08580f 32
finneyj 0:47d8ba08580f 33 // mBed pin assignments of core components.
finneyj 0:47d8ba08580f 34 #define MICROBIT_PIN_USER_LED P0_18
finneyj 0:47d8ba08580f 35
finneyj 0:47d8ba08580f 36
finneyj 0:47d8ba08580f 37 struct MicroBitEvent
finneyj 0:47d8ba08580f 38 {
finneyj 0:47d8ba08580f 39 int source; // ID of the component sending the event.
finneyj 0:47d8ba08580f 40 int value; // context specific value.
finneyj 0:47d8ba08580f 41 void *context; // context specific data.
finneyj 0:47d8ba08580f 42 };
finneyj 0:47d8ba08580f 43
finneyj 0:47d8ba08580f 44 class MicroBit
finneyj 0:47d8ba08580f 45 {
finneyj 0:47d8ba08580f 46 static void (*messageBus)(MicroBitEvent *); // Message Bus Handle
finneyj 0:47d8ba08580f 47 void init(); // Internal constructor. ARM compiler doesn't seem to support constructor chaining...
finneyj 0:47d8ba08580f 48
finneyj 0:47d8ba08580f 49 public:
finneyj 0:47d8ba08580f 50
finneyj 0:47d8ba08580f 51 //
finneyj 0:47d8ba08580f 52 // Add member variables to represent each of the core components on the device.
finneyj 0:47d8ba08580f 53 //
finneyj 0:47d8ba08580f 54
finneyj 0:47d8ba08580f 55
finneyj 0:47d8ba08580f 56 MicroBitLED userLED;
finneyj 0:47d8ba08580f 57 MicroBitDisplay display;
finneyj 0:47d8ba08580f 58
finneyj 0:47d8ba08580f 59 /*
finneyj 0:47d8ba08580f 60 MicroBitButton leftButton;
finneyj 0:47d8ba08580f 61 MicroBitButton rightButton;
finneyj 0:47d8ba08580f 62 MicroBitIO pins[MICROBIT_IO_PINS];
finneyj 0:47d8ba08580f 63 */
finneyj 0:47d8ba08580f 64
finneyj 0:47d8ba08580f 65 /**
finneyj 0:47d8ba08580f 66 * Constructor.
finneyj 0:47d8ba08580f 67 * Create a representation of a MicroBit device.
finneyj 0:47d8ba08580f 68 * @param messageBus callback function to receive MicroBitMessageBus events.
finneyj 0:47d8ba08580f 69 */
finneyj 0:47d8ba08580f 70 MicroBit(void (*messageBus)(MicroBitEvent *));
finneyj 0:47d8ba08580f 71 };
finneyj 0:47d8ba08580f 72
finneyj 0:47d8ba08580f 73 #endif
finneyj 0:47d8ba08580f 74