sd_ble_gap_scan_start returned 0x7

I'm attempting to get our wearable remote to interact with a GoPro using their API and am getting the error in the subject line when attempting to start scanning. I've checked out a couple of resolutions of this error (wrong parameters, increase the size of the scan buffer, etc) but still getting the error. Does anybody have an example for this? Code attached...

  /**@brief GoPro service Handler.
   */
  static void gopro_svc_evt_handler(ble_gopro_t * p_gopro, ble_gopro_evt_t * p_gopro_evt)
  {
      ret_code_t err_code;

      switch (p_gopro_evt->evt_type)
      {
          case BLE_GOPRO_EVT_DISCOVERY_COMPLETE:
          {
              NRF_LOG_DEBUG("Heart rate service discovered.");

              err_code = ble_gopro_handles_assign(p_gopro,
                                                  p_gopro_evt->conn_handle,
                                                  &p_gopro_evt->params.peer_db);
              APP_ERROR_CHECK(err_code);

              // Heart rate service discovered. Enable notification of Heart Rate Measurement.
              err_code = ble_gopro_hrm_notif_enable(p_gopro);
              APP_ERROR_CHECK(err_code);
          } break;

          case BLE_GOPRO_EVT_HRM_NOTIFICATION:
          {
              NRF_LOG_INFO("Heart Rate = %d.", p_gopro_evt->params.hrm.hr_value);

              if (p_gopro_evt->params.hrm.rr_intervals_cnt != 0)
              {
                  uint32_t rr_avg = 0;
                  for (uint32_t i = 0; i < p_gopro_evt->params.hrm.rr_intervals_cnt; i++)
                  {
                      rr_avg += p_gopro_evt->params.hrm.rr_intervals[i];
                  }
                  rr_avg = rr_avg / p_gopro_evt->params.hrm.rr_intervals_cnt;
                  NRF_LOG_DEBUG("rr_interval (avg) = %d.", rr_avg);
              }
          } break;

          default:
              break;
      }
  }

  /**
   * @brief gopro service initialization.
   */
  static void gopro_svc_init(void)
  {
      ble_gopro_init_t gopro_init_obj;

      gopro_init_obj.evt_handler   = gopro_svc_evt_handler;
      gopro_init_obj.error_handler = service_error_handler;
      gopro_init_obj.p_gatt_queue  = &m_ble_gatt_queue;

      ret_code_t err_code = ble_gopro_init(&m_gopro, &gopro_init_obj);
      APP_ERROR_CHECK(err_code);
  }

    /**@brief Function for handling BLE events.
     *
     * @param[in]   p_ble_evt   Bluetooth stack event.
     * @param[in]   p_context   Unused.
     */
  static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
  {
      ret_code_t            err_code;
      ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;

      switch (p_ble_evt->header.evt_id)
      {
          case BLE_GAP_EVT_CONNECTED:
          {
              NRF_LOG_INFO("Connected.");

              // Discover peer's services.
              err_code = ble_db_discovery_start(&m_db_disc, p_ble_evt->evt.gap_evt.conn_handle);
              APP_ERROR_CHECK(err_code);

              if (ble_conn_state_central_conn_count() < NRF_SDH_BLE_CENTRAL_LINK_COUNT)
              {
                  scan_start();
              }
          } break;

          case BLE_GAP_EVT_DISCONNECTED:
          {
              NRF_LOG_INFO("Disconnected, reason 0x%x.",
                           p_gap_evt->params.disconnected.reason);

              if (ble_conn_state_central_conn_count() < NRF_SDH_BLE_CENTRAL_LINK_COUNT)
              {
                  scan_start();
              }
          } break;

          case BLE_GAP_EVT_TIMEOUT:
          {
              if (p_gap_evt->params.timeout.src == BLE_GAP_TIMEOUT_SRC_CONN)
              {
                  NRF_LOG_INFO("Connection Request timed out.");
              }
          } break;

          case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
              // Accepting parameters requested by peer.
              err_code = sd_ble_gap_conn_param_update(p_gap_evt->conn_handle,
                                                      &p_gap_evt->params.conn_param_update_request.conn_params);
              APP_ERROR_CHECK(err_code);
              break;

          case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
          {
              NRF_LOG_DEBUG("PHY update request.");
              ble_gap_phys_t const phys =
              {
                  .rx_phys = BLE_GAP_PHY_AUTO,
                  .tx_phys = BLE_GAP_PHY_AUTO,
              };
              err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
              APP_ERROR_CHECK(err_code);
          } break;

          case BLE_GATTC_EVT_TIMEOUT:
              // Disconnect on GATT Client timeout event.
              NRF_LOG_DEBUG("GATT Client Timeout.");
              err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gattc_evt.conn_handle,
                                               BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
              APP_ERROR_CHECK(err_code);
              break;

          case BLE_GATTS_EVT_TIMEOUT:
              // Disconnect on GATT Server timeout event.
              NRF_LOG_DEBUG("GATT Server Timeout.");
              err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gatts_evt.conn_handle,
                                               BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
              APP_ERROR_CHECK(err_code);
              break;
    
          case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
              NRF_LOG_DEBUG("BLE_GAP_EVT_SEC_PARAMS_REQUEST");
              break;

          case BLE_GAP_EVT_AUTH_KEY_REQUEST:
              NRF_LOG_INFO("BLE_GAP_EVT_AUTH_KEY_REQUEST");
              break;

          case BLE_GAP_EVT_LESC_DHKEY_REQUEST:
              NRF_LOG_INFO("BLE_GAP_EVT_LESC_DHKEY_REQUEST");
              break;

           case BLE_GAP_EVT_AUTH_STATUS:
               NRF_LOG_INFO("BLE_GAP_EVT_AUTH_STATUS: status=0x%x bond=0x%x lv4: %d kdist_own:0x%x kdist_peer:0x%x",
                            p_ble_evt->evt.gap_evt.params.auth_status.auth_status,
                            p_ble_evt->evt.gap_evt.params.auth_status.bonded,
                            p_ble_evt->evt.gap_evt.params.auth_status.sm1_levels.lv4,
                            *((uint8_t *)&p_ble_evt->evt.gap_evt.params.auth_status.kdist_own),
                            *((uint8_t *)&p_ble_evt->evt.gap_evt.params.auth_status.kdist_peer));
              break;

          default:
              break;
      }
  }

  /**@brief GATT module event handler.
   */
  static void gatt_evt_handler(nrf_ble_gatt_t * p_gatt, nrf_ble_gatt_evt_t const * p_evt)
  {
      switch (p_evt->evt_id)
      {
          case NRF_BLE_GATT_EVT_ATT_MTU_UPDATED:
          {
              NRF_LOG_INFO("GATT ATT MTU on connection 0x%x changed to %d.",
                           p_evt->conn_handle,
                           p_evt->params.att_mtu_effective);
          } break;

          case NRF_BLE_GATT_EVT_DATA_LENGTH_UPDATED:
          {
              NRF_LOG_INFO("Data length for connection 0x%x updated to %d.",
                           p_evt->conn_handle,
                           p_evt->params.data_length);
          } break;

          default:
              break;
      }
  }


  /**@brief Function for handling Scaning events.
   *
   * @param[in]   p_scan_evt   Scanning event.
   */
  static void scan_evt_handler(scan_evt_t const * p_scan_evt)
  {
      ret_code_t err_code;
      switch(p_scan_evt->scan_evt_id)
      {
          //case NRF_BLE_SCAN_EVT_WHITELIST_REQUEST:
          //{
          //    on_whitelist_req();
          //    m_whitelist_disabled = false;
          //} break;

          case NRF_BLE_SCAN_EVT_CONNECTING_ERROR:
          {
              err_code = p_scan_evt->params.connecting_err.err_code;
              APP_ERROR_CHECK(err_code);
          } break;

          case NRF_BLE_SCAN_EVT_CONNECTED:
          {
              ble_gap_evt_connected_t const * p_connected =
                               p_scan_evt->params.connected.p_connected;
             // Scan is automatically stopped by the connection.
             NRF_LOG_INFO("Connecting to target %02x%02x%02x%02x%02x%02x",
                      p_connected->peer_addr.addr[0],
                      p_connected->peer_addr.addr[1],
                      p_connected->peer_addr.addr[2],
                      p_connected->peer_addr.addr[3],
                      p_connected->peer_addr.addr[4],
                      p_connected->peer_addr.addr[5]
                      );
          } break;

          case NRF_BLE_SCAN_EVT_SCAN_TIMEOUT:
          {
              NRF_LOG_INFO("Scan timed out.");
              scan_start();
          } break;

          case NRF_BLE_SCAN_EVT_FILTER_MATCH:
              break;
          case NRF_BLE_SCAN_EVT_WHITELIST_ADV_REPORT:
              break;

          default:
            break;
      }
  }

  /**@brief Function for handling database discovery events.
   *
   * @details This function is callback function to handle events from the database discovery module.
   *          Depending on the UUIDs that are discovered, this function should forward the events
   *          to their respective services.
   *
   * @param[in] p_event  Pointer to the database discovery event.
   */
  static void db_disc_handler(ble_db_discovery_evt_t * p_evt)
  {
      ble_gopro_on_db_disc_evt(&m_gopro, p_evt);
  }

  /**@brief Database discovery initialization.
   */
  static void db_discovery_init(void)
  {
      ble_db_discovery_init_t db_init;

      memset(&db_init, 0, sizeof(db_init));

      db_init.p_gatt_queue = &m_ble_gatt_queue;

      //apdobaj
      db_init.evt_handler = db_disc_handler;

      ret_code_t err_code = ble_db_discovery_init(&db_init);
      APP_ERROR_CHECK(err_code);
  }

  /*

#define SCAN_ACTIVE 0
#define SCAN_INTERVAL 0x0040
#define SCAN_WINDOW	0x0020
#define SCAN_TIMEOUT 0
#define SCAN_FP	0

NRF_BLE_SCAN_DEF(m_scan);           /**< Scanning module instance. 

void scan_init(void)
{
    ret_code_t          err_code;
    nrf_ble_scan_init_t init_scan;

    memset(&init_scan, 0, sizeof(init_scan));
	
	//change.scan_interval_multiple_double is global variable and can changed by user action
	uint16_t scan_interval = SCAN_INTERVAL*(change.scan_interval_multiple_double);
	
	ble_gap_scan_params_t nrf_ble_scan_params_1M_test =
	{
		.active = SCAN_ACTIVE,
		.interval = scan_interval,
		.window = SCAN_WINDOW,
		.timeout = SCAN_TIMEOUT,
		.filter_policy = SCAN_FP,
		.scan_phys = BLE_GAP_PHY_1MBPS,
	
	};

    init_scan.connect_if_match = false;
    init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;


	MAIN_DEBUG(("scan_init - SCAN_PHY Normal\r"));
	init_scan.p_scan_param = &nrf_ble_scan_params_1M_test;
	init_scan.p_conn_param = &nrf_ble_conn_params;
    err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);

    //init result always return 0x00(NRF_SUCCESS)
	MAIN_DEBUG(("scan init result[0x%02X]", err_code));
    APP_ERROR_CHECK(err_code);

}
*/

  /**@brief Function for initialization scanning and setting filters.
   */
  static void scan_init(void)
  {
      ret_code_t          err_code;
      nrf_ble_scan_init_t init_scan;

      memset(&init_scan, 0, sizeof(init_scan));

      init_scan.p_scan_param     = &m_scan_param;
      init_scan.connect_if_match = true;
      init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;

      err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
      APP_ERROR_CHECK(err_code);

      ble_uuid128_t uuid =
      {
          .uuid128 = TARGET_UUID
          //128-bit uuid doesn't have a type
          //.type = BLE_UUID_TYPE_BLE,
      };

#if NRF_BLE_SCAN_FILTER_ENABLE
      err_code = nrf_ble_scan_filter_set(&m_scan,
                                         SCAN_UUID_FILTER,
                                         &uuid);
      APP_ERROR_CHECK(err_code);

      if (strlen(m_target_periph_name) != 0)
      {
          err_code = nrf_ble_scan_filter_set(&m_scan,
                                             SCAN_NAME_FILTER,
                                             m_target_periph_name);
          APP_ERROR_CHECK(err_code);
      }

      if (is_connect_per_addr)
      {
         err_code = nrf_ble_scan_filter_set(&m_scan,
                                            SCAN_ADDR_FILTER,
                                            m_target_periph_addr.addr);
         APP_ERROR_CHECK(err_code);
      }

      err_code = nrf_ble_scan_filters_enable(&m_scan,
                                             NRF_BLE_SCAN_ALL_FILTER,
                                             false);
      APP_ERROR_CHECK(err_code);
#endif
  }
/**
 * Copyright (c) 2012 - 2021, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
/**@cond To Make Doxygen skip documentation generation for this file.
 * @{
 */
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(BLE_GOPRO_SVC)
#include "ble_gopro.h"
#include "ble_db_discovery.h"
#include "ble_types.h"
#include "ble_gattc.h"

#define NRF_LOG_MODULE_NAME ble_gopro_svc
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();

#define HRM_FLAG_MASK_HR_16BIT  (0x01 << 0)           /**< Bit mask used to extract the type of heart rate value. This is used to find if the received heart rate is a 16 bit value or an 8 bit value. */
#define HRM_FLAG_MASK_HR_RR_INT (0x01 << 4)           /**< Bit mask used to extract the presence of RR_INTERVALS. This is used to find if the received measurement includes RR_INTERVALS. */


/**@brief Function for interception of the errors of GATTC and the BLE GATT Queue.
 *
 * @param[in] nrf_error   Error code.
 * @param[in] p_ctx       Parameter from the event handler.
 * @param[in] conn_handle Connection handle.
 */
static void gatt_error_handler(uint32_t   nrf_error,
                               void     * p_ctx,
                               uint16_t   conn_handle)
{
    ble_gopro_t * p_ble_gopro = (ble_gopro_t *)p_ctx;

    NRF_LOG_DEBUG("A GATT Client error has occurred on conn_handle: 0X%X", conn_handle);

    if (p_ble_gopro->error_handler != NULL)
    {
        p_ble_gopro->error_handler(nrf_error);
    }
}


/**@brief     Function for handling Handle Value Notification received from the SoftDevice.
 *
 * @details   This function uses the Handle Value Notification received from the SoftDevice
 *            and checks whether it is a notification of the heart rate measurement from the peer. If
 *            it is, this function decodes the heart rate measurement and sends it to the
 *            application.
 *
 * @param[in] p_ble_gopro Pointer to the Heart Rate Client structure.
 * @param[in] p_ble_evt   Pointer to the BLE event received.
 */
static void on_hvx(ble_gopro_t * p_ble_gopro, const ble_evt_t * p_ble_evt)
{
    // Check if the event is on the link for this instance.
    if (p_ble_gopro->conn_handle != p_ble_evt->evt.gattc_evt.conn_handle)
    {
        NRF_LOG_DEBUG("Received HVX on link 0x%x, not associated to this instance. Ignore.",
                      p_ble_evt->evt.gattc_evt.conn_handle);
        return;
    }

    NRF_LOG_DEBUG("Received HVX on link 0x%x, hrm_handle 0x%x",
    p_ble_evt->evt.gattc_evt.params.hvx.handle,
    p_ble_gopro->peer_hrs_db.hrm_handle);

    // Check if this is a heart rate notification.
    if (p_ble_evt->evt.gattc_evt.params.hvx.handle == p_ble_gopro->peer_hrs_db.hrm_handle)
    {
        ble_gopro_evt_t ble_gopro_evt;
        uint32_t        index = 0;

        ble_gopro_evt.evt_type                    = BLE_GOPRO_EVT_HRM_NOTIFICATION;
        ble_gopro_evt.conn_handle                 = p_ble_gopro->conn_handle;
        ble_gopro_evt.params.hrm.rr_intervals_cnt = 0;

        if (!(p_ble_evt->evt.gattc_evt.params.hvx.data[index++] & HRM_FLAG_MASK_HR_16BIT))
        {
            // 8-bit heart rate value received.
            ble_gopro_evt.params.hrm.hr_value = p_ble_evt->evt.gattc_evt.params.hvx.data[index++];  //lint !e415 suppress Lint Warning 415: Likely access out of bond
        }
        else
        {
            // 16-bit heart rate value received.
            ble_gopro_evt.params.hrm.hr_value =
                uint16_decode(&(p_ble_evt->evt.gattc_evt.params.hvx.data[index]));
            index += sizeof(uint16_t);
        }

        if ((p_ble_evt->evt.gattc_evt.params.hvx.data[0] & HRM_FLAG_MASK_HR_RR_INT))
        {
            uint32_t i;
            /*lint --e{415} --e{416} --e{662} --e{661} -save suppress Warning 415: possible access out of bond */
            for (i = 0; i < BLE_GOPRO_RR_INTERVALS_MAX_CNT; i ++)
            {
                if (index >= p_ble_evt->evt.gattc_evt.params.hvx.len)
                {
                    break;
                }
                ble_gopro_evt.params.hrm.rr_intervals[i] =
                    uint16_decode(&(p_ble_evt->evt.gattc_evt.params.hvx.data[index]));
                index += sizeof(uint16_t);
            }
            /*lint -restore*/
            ble_gopro_evt.params.hrm.rr_intervals_cnt = (uint8_t)i;
        }
        p_ble_gopro->evt_handler(p_ble_gopro, &ble_gopro_evt);
    }
}


/**@brief     Function for handling Disconnected event received from the SoftDevice.
 *
 * @details   This function checks whether the disconnect event is happening on the link
 *            associated with the current instance of the module. If the event is happening, the function sets the instance's
 *            conn_handle to invalid.
 *
 * @param[in] p_ble_gopro Pointer to the Heart Rate Client structure.
 * @param[in] p_ble_evt   Pointer to the BLE event received.
 */
static void on_disconnected(ble_gopro_t * p_ble_gopro, const ble_evt_t * p_ble_evt)
{
    if (p_ble_gopro->conn_handle == p_ble_evt->evt.gap_evt.conn_handle)
    {
        p_ble_gopro->conn_handle                 = BLE_CONN_HANDLE_INVALID;
        p_ble_gopro->peer_hrs_db.hrm_cccd_handle = BLE_GATT_HANDLE_INVALID;
        p_ble_gopro->peer_hrs_db.hrm_handle      = BLE_GATT_HANDLE_INVALID;
    }
}


void ble_gopro_on_db_disc_evt(ble_gopro_t * p_ble_gopro, const ble_db_discovery_evt_t * p_evt)
{
    // Check if the Heart Rate Service was discovered.
    if (p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE &&
        p_evt->params.discovered_db.srv_uuid.uuid == BLE_UUID_GOPRO_SERVICE &&
        p_evt->params.discovered_db.srv_uuid.type == BLE_UUID_TYPE_BLE)

    {
        // Find the CCCD Handle of the Heart Rate Measurement characteristic.
        uint32_t i;

        ble_gopro_evt_t evt;

        evt.evt_type    = BLE_GOPRO_EVT_DISCOVERY_COMPLETE;
        evt.conn_handle = p_evt->conn_handle;

        for (i = 0; i < p_evt->params.discovered_db.char_count; i++)
        {
            if (p_evt->params.discovered_db.charateristics[i].characteristic.uuid.uuid ==
                BLE_UUID_HEART_RATE_MEASUREMENT_CHAR)
            {
                // Found Heart Rate characteristic. Store CCCD handle and break.
                evt.params.peer_db.hrm_cccd_handle =
                    p_evt->params.discovered_db.charateristics[i].cccd_handle;
                evt.params.peer_db.hrm_handle =
                    p_evt->params.discovered_db.charateristics[i].characteristic.handle_value;
                break;
            }
        }

        NRF_LOG_DEBUG("Heart Rate Service discovered at peer.");
        //If the instance has been assigned prior to db_discovery, assign the db_handles.
        if (p_ble_gopro->conn_handle != BLE_CONN_HANDLE_INVALID)
        {
            if ((p_ble_gopro->peer_hrs_db.hrm_cccd_handle == BLE_GATT_HANDLE_INVALID)&&
                (p_ble_gopro->peer_hrs_db.hrm_handle == BLE_GATT_HANDLE_INVALID))
            {
                p_ble_gopro->peer_hrs_db = evt.params.peer_db;
            }
        }


        p_ble_gopro->evt_handler(p_ble_gopro, &evt);
    }
}


uint32_t ble_gopro_init(ble_gopro_t * p_ble_gopro, ble_gopro_init_t * p_ble_gopro_init)
{
    VERIFY_PARAM_NOT_NULL(p_ble_gopro);
    VERIFY_PARAM_NOT_NULL(p_ble_gopro_init);

    ble_uuid128_t gopro_uuid = GOPRO_SERVICE_UUID_128;

    // Add GoPro Service UUID
    //ble_uuid128_t base_uuid = {GOPRO_SERVICE_UUID_BASE};
    //err_code =  sd_ble_uuid_vs_add(&base_uuid, gopro_uuid.type);
    //VERIFY_SUCCESS(err_code);
    
    p_ble_gopro->evt_handler                 = p_ble_gopro_init->evt_handler;
    p_ble_gopro->error_handler               = p_ble_gopro_init->error_handler;
    p_ble_gopro->p_gatt_queue                = p_ble_gopro_init->p_gatt_queue;
    p_ble_gopro->conn_handle                 = BLE_CONN_HANDLE_INVALID;
    p_ble_gopro->peer_hrs_db.hrm_cccd_handle = BLE_GATT_HANDLE_INVALID;
    p_ble_gopro->peer_hrs_db.hrm_handle      = BLE_GATT_HANDLE_INVALID;

    return ble_db_discovery_evt_register(&gopro_uuid);
}

void ble_gopro_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
{
    ble_gopro_t * p_ble_gopro = (ble_gopro_t *)p_context;

    if ((p_ble_gopro == NULL) || (p_ble_evt == NULL))
    {
        return;
    }

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GATTC_EVT_HVX:
            on_hvx(p_ble_gopro, p_ble_evt);
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnected(p_ble_gopro, p_ble_evt);
            break;

        default:
            break;
    }
}


/**@brief Function for creating a message for writing to the CCCD.
 */
static uint32_t cccd_configure(ble_gopro_t * p_ble_gopro, bool enable)
{
    NRF_LOG_DEBUG("Configuring CCCD. CCCD Handle = %d, Connection Handle = %d",
                  p_ble_gopro->peer_hrs_db.hrm_cccd_handle,
                  p_ble_gopro->conn_handle);

    nrf_ble_gq_req_t gopro_req;
    uint8_t          cccd[BLE_CCCD_VALUE_LEN];
    uint16_t         cccd_val = enable ? BLE_GATT_HVX_NOTIFICATION : 0;

    cccd[0] = LSB_16(cccd_val);
    cccd[1] = MSB_16(cccd_val);

    memset(&gopro_req, 0, sizeof(gopro_req));

    gopro_req.type                        = NRF_BLE_GQ_REQ_GATTC_WRITE;
    gopro_req.error_handler.cb            = gatt_error_handler;
    gopro_req.error_handler.p_ctx         = p_ble_gopro;
    gopro_req.params.gattc_write.handle   = p_ble_gopro->peer_hrs_db.hrm_cccd_handle;
    gopro_req.params.gattc_write.len      = BLE_CCCD_VALUE_LEN;
    gopro_req.params.gattc_write.p_value  = cccd;
    gopro_req.params.gattc_write.write_op = BLE_GATT_OP_WRITE_REQ;

    return nrf_ble_gq_item_add(p_ble_gopro->p_gatt_queue, &gopro_req, p_ble_gopro->conn_handle);
}


uint32_t ble_gopro_hrm_notif_enable(ble_gopro_t * p_ble_gopro)
{
    VERIFY_PARAM_NOT_NULL(p_ble_gopro);

    return cccd_configure(p_ble_gopro, true);
}


uint32_t ble_gopro_handles_assign(ble_gopro_t    * p_ble_gopro,
                                  uint16_t         conn_handle,
                                  const hrs_db_t * p_peer_hrs_handles)
{
    VERIFY_PARAM_NOT_NULL(p_ble_gopro);

    p_ble_gopro->conn_handle = conn_handle;
    if (p_peer_hrs_handles != NULL)
    {
        p_ble_gopro->peer_hrs_db = *p_peer_hrs_handles;
    }

    return nrf_ble_gq_conn_handle_register(p_ble_gopro->p_gatt_queue, conn_handle);
}
/** @}
 *  @endcond
 */
#endif // NRF_MODULE_ENABLED(BLE_gopro)
/**@brief Function for application main entry.
 */
int main(void)
 {
    bool erase_bonds;
    //the following line for monitor mode debugging (doesn't work with the mini)
    //NVIC_SetPriority(DebugMonitor_IRQn, _PRIO_SD_LOW)
    // Initialize.
    //bsp_board_init(BSP_INIT_LEDS & BSP_INIT_BUTTONS);
    lfclk_config();
    gpio_init();
    batt_charger_init();
    nrf_gpio_pin_write(LED_RED_PIN, 0); //LED on
    SEGGER_RTT_Init();
    //apdobaj 11Mar2024 try using SystemView
#if defined(USE_SYSVIEW)
    SEGGER_SYSVIEW_Conf();
    SEGGER_SYSVIEW_Start();
#endif
    //regout0 set in boards.c
    //set_regout0_3v();
    log_init();
    timers_init();
    nrf_mem_init();
    //buttons_leds_init(&erase_bonds);
    //nrf_gpio_pin_write(LED2_B, 0);
    power_management_init();
    
    
    ble_stack_init();
    scheduler_init();
    gap_params_init();
    gatt_init();
    //apdobaj changed order of next two statements per custom service tutorial
    services_init();
    // initialize services separately so they can both be connected
    advertising_init_hid();
    //sensor_simulator_init();
    //haptic_init();
    conn_params_init();
    buffer_init();
    peer_manager_init();

    //clear the bootloader start bit after reset
    sd_power_gpregret_clr(0, BOOTLOADER_DFU_GPREGRET_MASK);

    //apdobaj add i2c and sensor init routines
    twi_init_i2c();
    da7280_init();
    gesture_sensor_init();
    gestureCaptureSequence = linkedListCreate();
    gestureSequenceCountList = linkedListCreate();
#if defined(USE_TWR)
    //link to qorvo forum from previous design: https://forum.qorvo.com/t/ds-two-way-ranging-example-code-not-communicating/12178/13?page=2
    init_spim();
    twr_init();
#endif
    // implement a watchdog timer
    //wdt_start();
    // Start execution.
    NRF_LOG_INFO("HID Keyboard example started.");
    timers_start();
    erase_bonds = false;
#if defined(OPERATE_AS_CENTRAL)
    scan_init();
    db_discovery_init();
    gopro_svc_init();
    scan_start();
#else
    advertising_start();
#endif
    nrf_gpio_pin_write(LED_RED_PIN, 1); //LED off
#if defined(USE_SYSVIEW)
    //SEGGER_SYSVIEW_Stop();
#endif

    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
}

Related