microbit-dal/inc/MicroBitComponent.h

98 lines
3.5 KiB
C
Raw Normal View History

#ifndef MICROBIT_COMPONENT_H
#define MICROBIT_COMPONENT_H
/**
* Class definition for MicroBitComponent
* All components should inherit from this class.
* @note if a component needs to be called regularly, then you should add the component to the systemTick and idleTick queues.
* If it's in the systemTick queue, you should override systemTick and implement the required functionality.
* Similarly if the component is in the idleTick queue, the idleTick member function should be overridden.
*/
microbit: Added configurable concurrency modes for MicroBitMessageBus handlers. MessageBus handlers can now have one of four concurrency modes for the eventuality of an event being raised whilst a previous event is still being processed. An additional (optional) parameter is provided to the listen() functions to allow this to be selected on a per event handler basis. The permissable options are: MESSAGE_BUS_LISTENER_REENTRANT: The event handler is fired with the new event, regardless of whether or not a previous event is still be processed by that handler. MESSAGE_BUS_LISTENER_QUEUE_IF_BUSY: The new event is queued until such a time as the previous event has completed execution. The new event is then processed. This option does not preclude the processing of the new event by other event handlers. MESSAGE_BUS_LISTENER_DROP_IF_BUSY: The new event is dropped, and will never be processed the the event handler. This option does not preclude the processing of the new event by other event handlers. MESSAGE_BUS_LISTENER_NONBLOCKING: The event handler is self-declaring that it never blocks. This flag is used purely for optimisation, as it permits direct execution of the event hadnelr without inducing any overhead from the scheduler. In addition, the following minor revisions were made in this release: * Cleanup of the #include dependencies contained in the microbit-dal .h files * Bugfix to the scheduler block on event matching code. * Introduced a MICROBIT_ID_ALERT MessageBus channel, for general purpose eventing using nonces.
2015-09-11 15:39:38 +00:00
// Enumeration of core components.
#define MICROBIT_ID_BUTTON_A 1
#define MICROBIT_ID_BUTTON_B 2
#define MICROBIT_ID_BUTTON_RESET 3
#define MICROBIT_ID_ACCELEROMETER 4
#define MICROBIT_ID_COMPASS 5
#define MICROBIT_ID_DISPLAY 6
//EDGE connector events
#define MICROBIT_IO_PINS 20
#define MICROBIT_ID_IO_P0 7 //P0 is the left most pad (ANALOG/DIGITAL)
#define MICROBIT_ID_IO_P1 8 //P1 is the middle pad (ANALOG/DIGITAL)
#define MICROBIT_ID_IO_P2 9 //P2 is the right most pad (ANALOG/DIGITAL)
#define MICROBIT_ID_IO_P3 10 //COL1 (ANALOG/DIGITAL)
#define MICROBIT_ID_IO_P4 11 //BTN_A
#define MICROBIT_ID_IO_P5 12 //COL2 (ANALOG/DIGITAL)
#define MICROBIT_ID_IO_P6 13 //ROW2
#define MICROBIT_ID_IO_P7 14 //ROW1
#define MICROBIT_ID_IO_P8 15 //PIN 18
#define MICROBIT_ID_IO_P9 16 //ROW3
#define MICROBIT_ID_IO_P10 17 //COL3 (ANALOG/DIGITAL)
#define MICROBIT_ID_IO_P11 18 //BTN_B
#define MICROBIT_ID_IO_P12 19 //PIN 20
#define MICROBIT_ID_IO_P13 20 //SCK
#define MICROBIT_ID_IO_P14 21 //MISO
#define MICROBIT_ID_IO_P15 22 //MOSI
#define MICROBIT_ID_IO_P16 23 //PIN 16
#define MICROBIT_ID_IO_P19 24 //SCL
#define MICROBIT_ID_IO_P20 25 //SDA
#define MICROBIT_ID_BUTTON_AB 26 // Button A+B multibutton
#define MICROBIT_ID_ALERT 27 // Alert channel, used for general purpose condition synchronisation and alerting.
class MicroBitComponent
{
protected:
uint16_t id; // Event Bus ID
uint8_t status; // keeps track of various component state, and also indicates if data is ready.
public:
/**
* The default constructor of a MicroBitComponent
*/
MicroBitComponent()
{
this->id = 0;
this->status = 0;
}
/**
* Once added to the systemTickComponents array, this member function will be
* called in interrupt context on every system tick.
*/
virtual void systemTick(){
}
/**
* Once added to the idleThreadComponents array, this member function will be
* called in idle thread context indiscriminately.
*/
virtual void idleTick()
{
}
/**
* When added to the idleThreadComponents array, this function will be called to determine
* if and when data is ready.
* @note override this if you want to request to be scheduled imminently
*/
virtual int isIdleCallbackNeeded()
{
return 0;
}
virtual ~MicroBitComponent()
{
}
};
#endif