fork microbit-dal
Dependencies: BLE_API mbed-dev-bin nRF51822
Fork of microbit-dal by
MicroBitDFUService.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_DFU_SERVICE_H 00027 #define MICROBIT_DFU_SERVICE_H 00028 00029 #include "mbed.h" 00030 #include "MicroBitConfig.h" 00031 #include "ble/BLE.h" 00032 #include "MicroBitEvent.h" 00033 00034 // MicroBit ControlPoint OpCodes 00035 // Requests transfer to the Nordic DFU bootloader. 00036 #define MICROBIT_DFU_OPCODE_START_DFU 1 00037 00038 // visual ID code constants 00039 #define MICROBIT_DFU_HISTOGRAM_WIDTH 5 00040 #define MICROBIT_DFU_HISTOGRAM_HEIGHT 5 00041 00042 // UUIDs for our service and characteristics 00043 extern const uint8_t MicroBitDFUServiceUUID[]; 00044 extern const uint8_t MicroBitDFUServiceControlCharacteristicUUID[]; 00045 extern const uint8_t MicroBitDFUServiceFlashCodeCharacteristicUUID[]; 00046 00047 // Handle on the memory resident Nordic bootloader. 00048 extern "C" void bootloader_start(void); 00049 00050 /** 00051 * Class definition for a MicroBit Device Firmware Update loader. 00052 * This service allows hexes to be flashed remotely from another Bluetooth 00053 * device. 00054 */ 00055 class MicroBitDFUService 00056 { 00057 public: 00058 00059 /** 00060 * Constructor. 00061 * Initialise the Device Firmware Update service. 00062 * @param _ble The instance of a BLE device that we're running on. 00063 */ 00064 MicroBitDFUService(BLEDevice &_ble); 00065 00066 /** 00067 * Callback. Invoked when any of our attributes are written via BLE. 00068 */ 00069 virtual void onDataWritten(const GattWriteCallbackParams *params); 00070 00071 private: 00072 00073 // State of paiting process. 00074 bool authenticated; 00075 bool flashCodeRequested; 00076 00077 // Bluetooth stack we're running on. 00078 BLEDevice &ble; 00079 00080 // memory for our 8 bit control characteristic. 00081 uint8_t controlByte; 00082 00083 // BLE pairing name of this device, encoded as an integer. 00084 uint32_t flashCode; 00085 00086 GattAttribute::Handle_t microBitDFUServiceControlCharacteristicHandle; 00087 GattAttribute::Handle_t microBitDFUServiceFlashCodeCharacteristicHandle; 00088 00089 // Displays the device's ID code as a histogram on the LED matrix display. 00090 void showNameHistogram(); 00091 00092 // Displays an acknowledgement on the LED matrix display. 00093 void showTick(); 00094 00095 // Update BLE characteristic to release our flash code. 00096 void releaseFlashCode(); 00097 00098 // Event handlers for button clicks. 00099 void onButtonA(MicroBitEvent e); 00100 void onButtonB(MicroBitEvent e); 00101 }; 00102 00103 #endif
Generated on Tue Jul 12 2022 18:28:21 by 1.7.2