#include "main.h" #include "bsp_time.h" #include "hal_ble_client.h" #include "hal_ble_host.h" #include "nrf_delay.h" void ble_dfu_evt_handler(ble_dfu_buttonless_evt_type_t event) { switch (event) { case BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE: { #if DEBUG_EN #if NRF_LOG_ENABLED NRF_LOG_INFO("Device is preparing to enter bootloader mode.\n"); #endif #endif break; } case BLE_DFU_EVT_BOOTLOADER_ENTER: // YOUR_JOB: Write app-specific unwritten data to FLASH, control finalization of this // by delaying reset by reporting false in app_shutdown_handler #if DEBUG_EN #if NRF_LOG_ENABLED NRF_LOG_INFO("Device will enter bootloader mode.\n"); #endif #endif break; case BLE_DFU_EVT_BOOTLOADER_ENTER_FAILED: #if DEBUG_EN #if NRF_LOG_ENABLED NRF_LOG_INFO("Request to enter bootloader mode failed asynchroneously.\n"); #endif #endif // YOUR_JOB: Take corrective measures to resolve the issue // like calling APP_ERROR_CHECK to reset the device. break; case BLE_DFU_EVT_RESPONSE_SEND_ERROR: #if DEBUG_EN NRF_LOG_INFO("Request to send a response to client failed.\n"); #endif // YOUR_JOB: Take corrective measures to resolve the issue // like calling APP_ERROR_CHECK to reset the device. APP_ERROR_CHECK(false); break; default: #if DEBUG_EN #if NRF_LOG_ENABLED NRF_LOG_INFO("Unkn own event from ble_dfu_buttonless.\n"); #endif #endif break; } } #if NRF_LOG_ENABLED static void log_init(void) { ret_code_t err_code = NRF_LOG_INIT(NULL); APP_ERROR_CHECK(err_code); NRF_LOG_DEFAULT_BACKENDS_INIT(); } #endif extern void PRE_Init(void); extern void USR_Init(void); extern void USR_Process(void); int main(void) { #if BLE_DFU_ENANBLE ret_code_t err_code; err_code = ble_dfu_buttonless_async_svci_init(); APP_ERROR_CHECK(err_code); #endif #if NRF_LOG_ENABLED log_init(); #endif PRE_Init(); //用户初始化 #if BLE_DFU_ENANBLE ble_dfu_buttonless_init_t dfus_init = {0}; //DFU dfus_init.evt_handler = ble_dfu_evt_handler; err_code = ble_dfu_buttonless_init(&dfus_init); APP_ERROR_CHECK(err_code); #endif USR_Init(); //用户初始化 while (1) { #if NRF_LOG_ENABLED NRF_LOG_FLUSH(); #endif USR_Process(); } }