mbed.org local branch of microbit-dal. The real version lives in git at https://github.com/lancaster-university/microbit-dal
Dependencies: BLE_API nRF51822 mbed-dev-bin
Dependents: microbit Microbit IoTChallenge1 microbit ... more
MicroBitDevice.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 /** 00027 * Device specific funcitons for the nrf51822 device. 00028 * 00029 * Provides a degree of platform independence for microbit-dal functionality. 00030 * 00031 * TODO: Determine if any of this belongs in an mbed target definition. 00032 * TODO: Review microbit-dal to place all such functions here. 00033 */ 00034 #ifndef MICROBIT_DEVICE_H 00035 #define MICROBIT_DEVICE_H 00036 00037 #define MICROBIT_NAME_LENGTH 5 00038 #define MICROBIT_NAME_CODE_LETTERS 5 00039 #define MICROBIT_PANIC_ERROR_CHARS 4 00040 00041 #include "MicroBitConfig.h" 00042 #include "MicroBitMatrixMaps.h" 00043 00044 /** 00045 * Determines if a BLE stack is currently running. 00046 * 00047 * @return true is a bluetooth stack is operational, false otherwise. 00048 */ 00049 bool ble_running(); 00050 00051 /** 00052 * Derive a unique, consistent serial number of this device from internal data. 00053 * 00054 * @return the serial number of this device. 00055 */ 00056 uint32_t microbit_serial_number(); 00057 00058 /** 00059 * Derive the friendly name for this device, based on its serial number. 00060 * 00061 * @return the serial number of this device. 00062 */ 00063 char* microbit_friendly_name(); 00064 00065 /** 00066 * Perform a hard reset of the micro:bit. 00067 */ 00068 void microbit_reset(); 00069 00070 /** 00071 * Determine the version of microbit-dal currently running. 00072 * @return a pointer to a character buffer containing a representation of the semantic version number. 00073 */ 00074 const char * microbit_dal_version(); 00075 00076 /** 00077 * Disables all interrupts and user processing. 00078 * Displays "=(" and an accompanying status code on the default display. 00079 * @param statusCode the appropriate status code, must be in the range 0-999. 00080 * 00081 * @code 00082 * microbit_panic(20); 00083 * @endcode 00084 */ 00085 void microbit_panic(int statusCode); 00086 00087 /** 00088 * Defines the length of time that the device will remain in a error state before resetting. 00089 * 00090 * @param iteration The number of times the error code will be displayed before resetting. Set to zero to remain in error state forever. 00091 * 00092 * @code 00093 * microbit_panic_timeout(4); 00094 * @endcode 00095 */ 00096 void microbit_panic_timeout(int iterations); 00097 00098 /** 00099 * Generate a random number in the given range. 00100 * We use a simple Galois LFSR random number generator here, 00101 * as a Galois LFSR is sufficient for our applications, and much more lightweight 00102 * than the hardware random number generator built int the processor, which takes 00103 * a long time and uses a lot of energy. 00104 * 00105 * KIDS: You shouldn't use this is the real world to generte cryptographic keys though... 00106 * have a think why not. :-) 00107 * 00108 * @param max the upper range to generate a number for. This number cannot be negative. 00109 * 00110 * @return A random, natural number between 0 and the max-1. Or MICROBIT_INVALID_VALUE if max is <= 0. 00111 * 00112 * @code 00113 * microbit_random(200); //a number between 0 and 199 00114 * @endcode 00115 */ 00116 int microbit_random(int max); 00117 00118 /** 00119 * Seed the random number generator (RNG). 00120 * 00121 * This function uses the NRF51822's in built cryptographic random number generator to seed a Galois LFSR. 00122 * We do this as the hardware RNG is relatively high power, and is locked out by the BLE stack internally, 00123 * with a less than optimal application interface. A Galois LFSR is sufficient for our 00124 * applications, and much more lightweight. 00125 */ 00126 void microbit_seed_random(); 00127 00128 /** 00129 * Seed the pseudo random number generator (RNG) using the given 32-bit value. 00130 * This function does not use the NRF51822's in built cryptographic random number generator. 00131 * 00132 * @param seed The value to use as a seed. 00133 */ 00134 void microbit_seed_random(uint32_t seed); 00135 00136 #endif
Generated on Tue Jul 12 2022 15:22:56 by 1.7.2