123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #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("Unknown 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)
- {
- nrf_gpio_cfg_input(PIN_TXD_BLE, NRF_GPIO_PIN_NOPULL);
- nrf_gpio_cfg_input(PIN_RXD_BLE, NRF_GPIO_PIN_NOPULL);
- nrf_delay_ms(2000);
- #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();
- }
- }
|