Forked to avoid changing the publioc repo
Dependencies: BLE_API mbed-dev-bin nRF51822
Fork of microbit-dal by
inc/core/MicroBitComponent.h@41:da05ec75cd5d, 2016-07-13 (annotated)
- Committer:
- LancasterUniversity
- Date:
- Wed Jul 13 12:18:21 2016 +0100
- Revision:
- 41:da05ec75cd5d
- Parent:
- 1:8aa5cdb4ab67
Synchronized with git rev e0369cab
Author: Joe Finney
microbit: Removed legacy isIdleCallbackNeeded() method. [issue #138]
This function has been deprecated, so now removed for v2.0.0 release.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jonathan Austin |
1:8aa5cdb4ab67 | 1 | /* |
Jonathan Austin |
1:8aa5cdb4ab67 | 2 | The MIT License (MIT) |
Jonathan Austin |
1:8aa5cdb4ab67 | 3 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 4 | Copyright (c) 2016 British Broadcasting Corporation. |
Jonathan Austin |
1:8aa5cdb4ab67 | 5 | This software is provided by Lancaster University by arrangement with the BBC. |
Jonathan Austin |
1:8aa5cdb4ab67 | 6 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 7 | Permission is hereby granted, free of charge, to any person obtaining a |
Jonathan Austin |
1:8aa5cdb4ab67 | 8 | copy of this software and associated documentation files (the "Software"), |
Jonathan Austin |
1:8aa5cdb4ab67 | 9 | to deal in the Software without restriction, including without limitation |
Jonathan Austin |
1:8aa5cdb4ab67 | 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, |
Jonathan Austin |
1:8aa5cdb4ab67 | 11 | and/or sell copies of the Software, and to permit persons to whom the |
Jonathan Austin |
1:8aa5cdb4ab67 | 12 | Software is furnished to do so, subject to the following conditions: |
Jonathan Austin |
1:8aa5cdb4ab67 | 13 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 14 | The above copyright notice and this permission notice shall be included in |
Jonathan Austin |
1:8aa5cdb4ab67 | 15 | all copies or substantial portions of the Software. |
Jonathan Austin |
1:8aa5cdb4ab67 | 16 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Jonathan Austin |
1:8aa5cdb4ab67 | 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Jonathan Austin |
1:8aa5cdb4ab67 | 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
Jonathan Austin |
1:8aa5cdb4ab67 | 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Jonathan Austin |
1:8aa5cdb4ab67 | 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
Jonathan Austin |
1:8aa5cdb4ab67 | 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
Jonathan Austin |
1:8aa5cdb4ab67 | 23 | DEALINGS IN THE SOFTWARE. |
Jonathan Austin |
1:8aa5cdb4ab67 | 24 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 25 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 26 | #ifndef MICROBIT_COMPONENT_H |
Jonathan Austin |
1:8aa5cdb4ab67 | 27 | #define MICROBIT_COMPONENT_H |
Jonathan Austin |
1:8aa5cdb4ab67 | 28 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 29 | #include "MicroBitConfig.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 30 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 31 | // Enumeration of core components. |
Jonathan Austin |
1:8aa5cdb4ab67 | 32 | #define MICROBIT_ID_BUTTON_A 1 |
Jonathan Austin |
1:8aa5cdb4ab67 | 33 | #define MICROBIT_ID_BUTTON_B 2 |
Jonathan Austin |
1:8aa5cdb4ab67 | 34 | #define MICROBIT_ID_BUTTON_RESET 3 |
Jonathan Austin |
1:8aa5cdb4ab67 | 35 | #define MICROBIT_ID_ACCELEROMETER 4 |
Jonathan Austin |
1:8aa5cdb4ab67 | 36 | #define MICROBIT_ID_COMPASS 5 |
Jonathan Austin |
1:8aa5cdb4ab67 | 37 | #define MICROBIT_ID_DISPLAY 6 |
Jonathan Austin |
1:8aa5cdb4ab67 | 38 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 39 | //EDGE connector events |
Jonathan Austin |
1:8aa5cdb4ab67 | 40 | #define MICROBIT_IO_PINS 20 |
Jonathan Austin |
1:8aa5cdb4ab67 | 41 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 42 | #define MICROBIT_ID_IO_P0 7 //P0 is the left most pad (ANALOG/DIGITAL) |
Jonathan Austin |
1:8aa5cdb4ab67 | 43 | #define MICROBIT_ID_IO_P1 8 //P1 is the middle pad (ANALOG/DIGITAL) |
Jonathan Austin |
1:8aa5cdb4ab67 | 44 | #define MICROBIT_ID_IO_P2 9 //P2 is the right most pad (ANALOG/DIGITAL) |
Jonathan Austin |
1:8aa5cdb4ab67 | 45 | #define MICROBIT_ID_IO_P3 10 //COL1 (ANALOG/DIGITAL) |
Jonathan Austin |
1:8aa5cdb4ab67 | 46 | #define MICROBIT_ID_IO_P4 11 //BTN_A |
Jonathan Austin |
1:8aa5cdb4ab67 | 47 | #define MICROBIT_ID_IO_P5 12 //COL2 (ANALOG/DIGITAL) |
Jonathan Austin |
1:8aa5cdb4ab67 | 48 | #define MICROBIT_ID_IO_P6 13 //ROW2 |
Jonathan Austin |
1:8aa5cdb4ab67 | 49 | #define MICROBIT_ID_IO_P7 14 //ROW1 |
Jonathan Austin |
1:8aa5cdb4ab67 | 50 | #define MICROBIT_ID_IO_P8 15 //PIN 18 |
Jonathan Austin |
1:8aa5cdb4ab67 | 51 | #define MICROBIT_ID_IO_P9 16 //ROW3 |
Jonathan Austin |
1:8aa5cdb4ab67 | 52 | #define MICROBIT_ID_IO_P10 17 //COL3 (ANALOG/DIGITAL) |
Jonathan Austin |
1:8aa5cdb4ab67 | 53 | #define MICROBIT_ID_IO_P11 18 //BTN_B |
Jonathan Austin |
1:8aa5cdb4ab67 | 54 | #define MICROBIT_ID_IO_P12 19 //PIN 20 |
Jonathan Austin |
1:8aa5cdb4ab67 | 55 | #define MICROBIT_ID_IO_P13 20 //SCK |
Jonathan Austin |
1:8aa5cdb4ab67 | 56 | #define MICROBIT_ID_IO_P14 21 //MISO |
Jonathan Austin |
1:8aa5cdb4ab67 | 57 | #define MICROBIT_ID_IO_P15 22 //MOSI |
Jonathan Austin |
1:8aa5cdb4ab67 | 58 | #define MICROBIT_ID_IO_P16 23 //PIN 16 |
Jonathan Austin |
1:8aa5cdb4ab67 | 59 | #define MICROBIT_ID_IO_P19 24 //SCL |
Jonathan Austin |
1:8aa5cdb4ab67 | 60 | #define MICROBIT_ID_IO_P20 25 //SDA |
Jonathan Austin |
1:8aa5cdb4ab67 | 61 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 62 | #define MICROBIT_ID_BUTTON_AB 26 // Button A+B multibutton |
Jonathan Austin |
1:8aa5cdb4ab67 | 63 | #define MICROBIT_ID_GESTURE 27 // Gesture events |
Jonathan Austin |
1:8aa5cdb4ab67 | 64 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 65 | #define MICROBIT_ID_THERMOMETER 28 |
Jonathan Austin |
1:8aa5cdb4ab67 | 66 | #define MICROBIT_ID_RADIO 29 |
Jonathan Austin |
1:8aa5cdb4ab67 | 67 | #define MICROBIT_ID_RADIO_DATA_READY 30 |
Jonathan Austin |
1:8aa5cdb4ab67 | 68 | #define MICROBIT_ID_MULTIBUTTON_ATTACH 31 |
Jonathan Austin |
1:8aa5cdb4ab67 | 69 | #define MICROBIT_ID_SERIAL 32 |
Jonathan Austin |
1:8aa5cdb4ab67 | 70 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 71 | #define MICROBIT_ID_MESSAGE_BUS_LISTENER 1021 // Message bus indication that a handler for a given ID has been registered. |
Jonathan Austin |
1:8aa5cdb4ab67 | 72 | #define MICROBIT_ID_NOTIFY_ONE 1022 // Notfication channel, for general purpose synchronisation |
Jonathan Austin |
1:8aa5cdb4ab67 | 73 | #define MICROBIT_ID_NOTIFY 1023 // Notfication channel, for general purpose synchronisation |
Jonathan Austin |
1:8aa5cdb4ab67 | 74 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 75 | // Universal flags used as part of the status field |
Jonathan Austin |
1:8aa5cdb4ab67 | 76 | #define MICROBIT_COMPONENT_RUNNING 0x01 |
Jonathan Austin |
1:8aa5cdb4ab67 | 77 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 78 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 79 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 80 | * Class definition for MicroBitComponent. |
Jonathan Austin |
1:8aa5cdb4ab67 | 81 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 82 | * All components should inherit from this class. |
Jonathan Austin |
1:8aa5cdb4ab67 | 83 | * |
LancasterUniversity | 41:da05ec75cd5d | 84 | * If a component requires regular updates, then that component can be added to the |
LancasterUniversity | 41:da05ec75cd5d | 85 | * to the systemTick and/or idleTick queues. This provides a simple, extensible mechanism |
LancasterUniversity | 41:da05ec75cd5d | 86 | * for code that requires periodic/occasional background processing but does not warrant |
LancasterUniversity | 41:da05ec75cd5d | 87 | * the complexity of maintaining its own thread. |
LancasterUniversity | 41:da05ec75cd5d | 88 | * |
LancasterUniversity | 41:da05ec75cd5d | 89 | * Two levels of support are available. |
Jonathan Austin |
1:8aa5cdb4ab67 | 90 | * |
LancasterUniversity | 41:da05ec75cd5d | 91 | * systemTick() provides a periodic callback during the |
LancasterUniversity | 41:da05ec75cd5d | 92 | * micro:bit's system timer interrupt. This provides a guaranteed periodic callback, but in interrupt context |
LancasterUniversity | 41:da05ec75cd5d | 93 | * and is suitable for code with lightweight processing requirements, but strict time constraints. |
LancasterUniversity | 41:da05ec75cd5d | 94 | * |
LancasterUniversity | 41:da05ec75cd5d | 95 | * idleTick() provides a periodic callback whenever the scheduler is idle. This provides occasional, callbacks |
LancasterUniversity | 41:da05ec75cd5d | 96 | * in the main thread context, but with no guarantees of frequency. This is suitable for non-urgent background tasks. |
Jonathan Austin |
1:8aa5cdb4ab67 | 97 | * |
LancasterUniversity | 41:da05ec75cd5d | 98 | * Components wishing to use these facilities should override the systemTick and/or idleTick functions defined here, and |
LancasterUniversity | 41:da05ec75cd5d | 99 | * register their components using system_timer_add_component() fiber_add_idle_component() respectively. |
LancasterUniversity | 41:da05ec75cd5d | 100 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 101 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 102 | class MicroBitComponent |
Jonathan Austin |
1:8aa5cdb4ab67 | 103 | { |
Jonathan Austin |
1:8aa5cdb4ab67 | 104 | protected: |
Jonathan Austin |
1:8aa5cdb4ab67 | 105 | |
LancasterUniversity | 41:da05ec75cd5d | 106 | uint16_t id; // Event Bus ID of this component |
LancasterUniversity | 41:da05ec75cd5d | 107 | uint8_t status; // Component defined state. |
Jonathan Austin |
1:8aa5cdb4ab67 | 108 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 109 | public: |
Jonathan Austin |
1:8aa5cdb4ab67 | 110 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 111 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 112 | * The default constructor of a MicroBitComponent |
Jonathan Austin |
1:8aa5cdb4ab67 | 113 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 114 | MicroBitComponent() |
Jonathan Austin |
1:8aa5cdb4ab67 | 115 | { |
Jonathan Austin |
1:8aa5cdb4ab67 | 116 | this->id = 0; |
Jonathan Austin |
1:8aa5cdb4ab67 | 117 | this->status = 0; |
Jonathan Austin |
1:8aa5cdb4ab67 | 118 | } |
Jonathan Austin |
1:8aa5cdb4ab67 | 119 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 120 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 121 | * The system timer will call this member function once the component has been added to |
Jonathan Austin |
1:8aa5cdb4ab67 | 122 | * the array of system components using system_timer_add_component. This callback |
Jonathan Austin |
1:8aa5cdb4ab67 | 123 | * will be in interrupt context. |
Jonathan Austin |
1:8aa5cdb4ab67 | 124 | */ |
LancasterUniversity | 41:da05ec75cd5d | 125 | virtual void systemTick() |
LancasterUniversity | 41:da05ec75cd5d | 126 | { |
Jonathan Austin |
1:8aa5cdb4ab67 | 127 | } |
Jonathan Austin |
1:8aa5cdb4ab67 | 128 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 129 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 130 | * The idle thread will call this member function once the component has been added to the array |
LancasterUniversity | 41:da05ec75cd5d | 131 | * of idle components using fiber_add_idle_component. |
Jonathan Austin |
1:8aa5cdb4ab67 | 132 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 133 | virtual void idleTick() |
Jonathan Austin |
1:8aa5cdb4ab67 | 134 | { |
Jonathan Austin |
1:8aa5cdb4ab67 | 135 | } |
Jonathan Austin |
1:8aa5cdb4ab67 | 136 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 137 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 138 | * If you have added your component to the idle or system tick component arrays, |
Jonathan Austin |
1:8aa5cdb4ab67 | 139 | * you must remember to remove your component from them if your component is destructed. |
Jonathan Austin |
1:8aa5cdb4ab67 | 140 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 141 | virtual ~MicroBitComponent() |
Jonathan Austin |
1:8aa5cdb4ab67 | 142 | { |
Jonathan Austin |
1:8aa5cdb4ab67 | 143 | } |
Jonathan Austin |
1:8aa5cdb4ab67 | 144 | }; |
Jonathan Austin |
1:8aa5cdb4ab67 | 145 | |
LancasterUniversity | 41:da05ec75cd5d | 146 | #endif |