Attempting to publish a tree
Dependencies: BLE_API mbed-dev-bin nRF51822
Fork of microbit-dal by
MicroBitComponent.h
00001 /* 00002 The MIT License (MIT) 00003 00004 Copyright (c) 2016 British Broadcasting Corporation. 00005 This software is provided by Lancaster University by arrangement with the BBC. 00006 00007 Permission is hereby granted, free of charge, to any person obtaining a 00008 copy of this software and associated documentation files (the "Software"), 00009 to deal in the Software without restriction, including without limitation 00010 the rights to use, copy, modify, merge, publish, distribute, sublicense, 00011 and/or sell copies of the Software, and to permit persons to whom the 00012 Software is furnished to do so, subject to the following conditions: 00013 00014 The above copyright notice and this permission notice shall be included in 00015 all copies or substantial portions of the Software. 00016 00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00020 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00021 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00022 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00023 DEALINGS IN THE SOFTWARE. 00024 */ 00025 00026 #ifndef MICROBIT_COMPONENT_H 00027 #define MICROBIT_COMPONENT_H 00028 00029 #include "MicroBitConfig.h" 00030 00031 // Enumeration of core components. 00032 #define MICROBIT_ID_BUTTON_A 1 00033 #define MICROBIT_ID_BUTTON_B 2 00034 #define MICROBIT_ID_BUTTON_RESET 3 00035 #define MICROBIT_ID_ACCELEROMETER 4 00036 #define MICROBIT_ID_COMPASS 5 00037 #define MICROBIT_ID_DISPLAY 6 00038 00039 //EDGE connector events 00040 #define MICROBIT_IO_PINS 20 00041 00042 #define MICROBIT_ID_IO_P0 7 //P0 is the left most pad (ANALOG/DIGITAL) 00043 #define MICROBIT_ID_IO_P1 8 //P1 is the middle pad (ANALOG/DIGITAL) 00044 #define MICROBIT_ID_IO_P2 9 //P2 is the right most pad (ANALOG/DIGITAL) 00045 #define MICROBIT_ID_IO_P3 10 //COL1 (ANALOG/DIGITAL) 00046 #define MICROBIT_ID_IO_P4 11 //BTN_A 00047 #define MICROBIT_ID_IO_P5 12 //COL2 (ANALOG/DIGITAL) 00048 #define MICROBIT_ID_IO_P6 13 //ROW2 00049 #define MICROBIT_ID_IO_P7 14 //ROW1 00050 #define MICROBIT_ID_IO_P8 15 //PIN 18 00051 #define MICROBIT_ID_IO_P9 16 //ROW3 00052 #define MICROBIT_ID_IO_P10 17 //COL3 (ANALOG/DIGITAL) 00053 #define MICROBIT_ID_IO_P11 18 //BTN_B 00054 #define MICROBIT_ID_IO_P12 19 //PIN 20 00055 #define MICROBIT_ID_IO_P13 20 //SCK 00056 #define MICROBIT_ID_IO_P14 21 //MISO 00057 #define MICROBIT_ID_IO_P15 22 //MOSI 00058 #define MICROBIT_ID_IO_P16 23 //PIN 16 00059 #define MICROBIT_ID_IO_P19 24 //SCL 00060 #define MICROBIT_ID_IO_P20 25 //SDA 00061 00062 #define MICROBIT_ID_BUTTON_AB 26 // Button A+B multibutton 00063 #define MICROBIT_ID_GESTURE 27 // Gesture events 00064 00065 #define MICROBIT_ID_THERMOMETER 28 00066 #define MICROBIT_ID_RADIO 29 00067 #define MICROBIT_ID_RADIO_DATA_READY 30 00068 #define MICROBIT_ID_MULTIBUTTON_ATTACH 31 00069 #define MICROBIT_ID_SERIAL 32 00070 00071 #define MICROBIT_ID_MESSAGE_BUS_LISTENER 1021 // Message bus indication that a handler for a given ID has been registered. 00072 #define MICROBIT_ID_NOTIFY_ONE 1022 // Notfication channel, for general purpose synchronisation 00073 #define MICROBIT_ID_NOTIFY 1023 // Notfication channel, for general purpose synchronisation 00074 00075 // Universal flags used as part of the status field 00076 #define MICROBIT_COMPONENT_RUNNING 0x01 00077 00078 00079 /** 00080 * Class definition for MicroBitComponent. 00081 * 00082 * All components should inherit from this class. 00083 * 00084 * If a component requires regular updates, then you should add the component 00085 * to the systemTick and idleTick queues. 00086 * 00087 * The system timer will call systemTick() once the component has been added to 00088 * the array of system components using system_timer_add_component. This callback 00089 * will be in interrupt context. 00090 * 00091 * The idle thread will call idleTick() once the component has been added to the array 00092 * of idle components using fiber_add_idle_component. Updates are determined by 00093 * the isIdleCallbackNeeded() member function. 00094 */ 00095 class MicroBitComponent 00096 { 00097 protected: 00098 00099 uint16_t id; // Event Bus ID 00100 uint8_t status; // keeps track of various component state, and also indicates if data is ready. 00101 00102 public: 00103 00104 /** 00105 * The default constructor of a MicroBitComponent 00106 */ 00107 MicroBitComponent() 00108 { 00109 this->id = 0; 00110 this->status = 0; 00111 } 00112 00113 /** 00114 * The system timer will call this member function once the component has been added to 00115 * the array of system components using system_timer_add_component. This callback 00116 * will be in interrupt context. 00117 */ 00118 virtual void systemTick(){ 00119 00120 } 00121 00122 /** 00123 * The idle thread will call this member function once the component has been added to the array 00124 * of idle components using fiber_add_idle_component. Updates are determined by 00125 * the isIdleCallbackNeeded() member function. 00126 */ 00127 virtual void idleTick() 00128 { 00129 00130 } 00131 00132 /** 00133 * When added to the idleThreadComponents array, this function will be called to determine 00134 * if and when data is ready. 00135 * 00136 * @note override this if you want to request to be scheduled as soon as possible. 00137 */ 00138 virtual int isIdleCallbackNeeded() 00139 { 00140 return 0; 00141 } 00142 00143 /** 00144 * If you have added your component to the idle or system tick component arrays, 00145 * you must remember to remove your component from them if your component is destructed. 00146 */ 00147 virtual ~MicroBitComponent() 00148 { 00149 } 00150 }; 00151 00152 #endif
Generated on Tue Jul 12 2022 19:58:09 by 1.7.2