hal_dfu.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "hal_dfu.h"
  2. #include "system.h"
  3. #include "ble_dfu.h"
  4. #include "nrf_dfu_ble_svci_bond_sharing.h"
  5. #include "nrf_svci_async_function.h"
  6. #include "nrf_svci_async_handler.h"
  7. #if BLE_DFU_ENANBLE
  8. static void ble_dfu_evt_handler(ble_dfu_buttonless_evt_type_t event)
  9. {
  10. switch (event)
  11. {
  12. case BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE:
  13. {
  14. #if DEBUG_DFU_EN
  15. DEBUG_LOG("Device is preparing to enter bootloader mode.\n");
  16. #endif
  17. break;
  18. }
  19. case BLE_DFU_EVT_BOOTLOADER_ENTER:
  20. #if DEBUG_DFU_EN
  21. DEBUG_LOG("Device will enter bootloader mode.\n");
  22. #endif
  23. break;
  24. case BLE_DFU_EVT_BOOTLOADER_ENTER_FAILED:
  25. #if DEBUG_DFU_EN
  26. DEBUG_LOG("Request to enter bootloader mode failed asynchroneously.\n");
  27. #endif
  28. break;
  29. case BLE_DFU_EVT_RESPONSE_SEND_ERROR:
  30. #if DEBUG_DFU_EN
  31. DEBUG_LOG("Request to send a response to client failed.\n");
  32. #endif
  33. APP_ERROR_CHECK(false);
  34. break;
  35. default:
  36. #if DEBUG_DFU_EN
  37. DEBUG_LOG("Unknown event from ble_dfu_buttonless.\n");
  38. #endif
  39. break;
  40. }
  41. }
  42. void hal_dfu_init(void){
  43. ret_code_t err_code;
  44. err_code = ble_dfu_buttonless_async_svci_init();
  45. APP_ERROR_CHECK(err_code);
  46. }
  47. void hal_dfu_server_init(void){
  48. ret_code_t err_code;
  49. ble_dfu_buttonless_init_t dfus_init = {0}; //DFU
  50. dfus_init.evt_handler = ble_dfu_evt_handler;
  51. err_code = ble_dfu_buttonless_init(&dfus_init);
  52. APP_ERROR_CHECK(err_code);
  53. bsp_ble_dfu_process_Initialize();
  54. }
  55. #endif