hal_dfu.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. }
  54. #endif