Browse Source

update

master
zhaohe 1 year ago
parent
commit
af647e62b4
  1. 49
      src/zble_module.c

49
src/zble_module.c

@ -157,10 +157,8 @@ void zble_module_reglistener(zble_event_listener_t event_listener) { m_event_lis
* *
* @retval True if shutdown is allowed by this power manager handler, otherwise false. * @retval True if shutdown is allowed by this power manager handler, otherwise false.
*/ */
static bool app_shutdown_handler(nrf_pwr_mgmt_evt_t event)
{
switch (event)
{
static bool app_shutdown_handler(nrf_pwr_mgmt_evt_t event) {
switch (event) {
case NRF_PWR_MGMT_EVT_PREPARE_DFU: case NRF_PWR_MGMT_EVT_PREPARE_DFU:
NRF_LOG_INFO("Power management wants to reset to DFU mode."); NRF_LOG_INFO("Power management wants to reset to DFU mode.");
// YOUR_JOB: Get ready to reset into DFU mode // YOUR_JOB: Get ready to reset into DFU mode
@ -203,11 +201,8 @@ static bool app_shutdown_handler(nrf_pwr_mgmt_evt_t event)
*/ */
NRF_PWR_MGMT_HANDLER_REGISTER(app_shutdown_handler, 0); NRF_PWR_MGMT_HANDLER_REGISTER(app_shutdown_handler, 0);
static void buttonless_dfu_sdh_state_observer(nrf_sdh_state_evt_t state, void * p_context)
{
if (state == NRF_SDH_EVT_STATE_DISABLED)
{
static void buttonless_dfu_sdh_state_observer(nrf_sdh_state_evt_t state, void* p_context) {
if (state == NRF_SDH_EVT_STATE_DISABLED) {
// Softdevice was disabled before going into reset. Inform bootloader to skip CRC on next boot. // Softdevice was disabled before going into reset. Inform bootloader to skip CRC on next boot.
nrf_power_gpregret2_set(BOOTLOADER_DFU_SKIP_CRC); nrf_power_gpregret2_set(BOOTLOADER_DFU_SKIP_CRC);
@ -217,14 +212,11 @@ static void buttonless_dfu_sdh_state_observer(nrf_sdh_state_evt_t state, void *
} }
/* nrf_sdh state observer. */ /* nrf_sdh state observer. */
NRF_SDH_STATE_OBSERVER(m_buttonless_dfu_state_obs, 0) =
{
NRF_SDH_STATE_OBSERVER(m_buttonless_dfu_state_obs, 0) = {
.handler = buttonless_dfu_sdh_state_observer, .handler = buttonless_dfu_sdh_state_observer,
}; };
static void advertising_config_get(ble_adv_modes_config_t * p_config)
{
static void advertising_config_get(ble_adv_modes_config_t* p_config) {
memset(p_config, 0, sizeof(ble_adv_modes_config_t)); memset(p_config, 0, sizeof(ble_adv_modes_config_t));
p_config->ble_adv_fast_enabled = true; p_config->ble_adv_fast_enabled = true;
@ -232,34 +224,25 @@ static void advertising_config_get(ble_adv_modes_config_t * p_config)
p_config->ble_adv_fast_timeout = APP_ADV_DURATION; p_config->ble_adv_fast_timeout = APP_ADV_DURATION;
} }
static void disconnect(uint16_t conn_handle, void * p_context)
{
static void disconnect(uint16_t conn_handle, void* p_context) {
UNUSED_PARAMETER(p_context); UNUSED_PARAMETER(p_context);
ret_code_t err_code = sd_ble_gap_disconnect(conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); ret_code_t err_code = sd_ble_gap_disconnect(conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
if (err_code != NRF_SUCCESS)
{
if (err_code != NRF_SUCCESS) {
NRF_LOG_WARNING("Failed to disconnect connection. Connection handle: %d Error: %d", conn_handle, err_code); NRF_LOG_WARNING("Failed to disconnect connection. Connection handle: %d Error: %d", conn_handle, err_code);
}
else
{
} else {
NRF_LOG_DEBUG("Disconnected connection handle %d", conn_handle); NRF_LOG_DEBUG("Disconnected connection handle %d", conn_handle);
} }
} }
// YOUR_JOB: Update this code if you want to do anything given a DFU event (optional). // YOUR_JOB: Update this code if you want to do anything given a DFU event (optional).
/**@brief Function for handling dfu events from the Buttonless Secure DFU service /**@brief Function for handling dfu events from the Buttonless Secure DFU service
* *
* @param[in] event Event from the Buttonless Secure DFU service. * @param[in] event Event from the Buttonless Secure DFU service.
*/ */
static void ble_dfu_evt_handler(ble_dfu_buttonless_evt_type_t event)
{
switch (event)
{
case BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE:
{
static void ble_dfu_evt_handler(ble_dfu_buttonless_evt_type_t event) {
switch (event) {
case BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE: {
NRF_LOG_INFO("Device is preparing to enter bootloader mode."); NRF_LOG_INFO("Device is preparing to enter bootloader mode.");
// Prevent device from advertising on disconnect. // Prevent device from advertising on disconnect.
@ -350,10 +333,10 @@ void zble_module_init(zble_module_cfg_t* cfg) {
*******************************************************************************/ *******************************************************************************/
#if BLE_DFU_ENABLED #if BLE_DFU_ENABLED
{ {
ble_dfu_buttonless_init_t dfus_init = {0};
dfus_init.evt_handler = ble_dfu_evt_handler;
ret_code_t err_code = ble_dfu_buttonless_init(&dfus_init);
ZERROR_CHECK(err_code);
// ble_dfu_buttonless_init_t dfus_init = {0};
// dfus_init.evt_handler = ble_dfu_evt_handler;
// ret_code_t err_code = ble_dfu_buttonless_init(&dfus_init);
// ZERROR_CHECK(err_code);
if (cfg->on_service_init) cfg->on_service_init(); if (cfg->on_service_init) cfg->on_service_init();
} }

Loading…
Cancel
Save