From f1bdb4276917aa9a35e3e76486a563b7129aef95 Mon Sep 17 00:00:00 2001 From: James McKenzie Date: Fri, 9 Feb 2024 09:38:39 +0000 Subject: rmeove btn bsp code --- bsp/bsp_btn_ble.c | 240 ------------------------------------------------------ bsp/bsp_btn_ble.h | 72 ---------------- main.c | 1 - 3 files changed, 313 deletions(-) delete mode 100644 bsp/bsp_btn_ble.c delete mode 100644 bsp/bsp_btn_ble.h diff --git a/bsp/bsp_btn_ble.c b/bsp/bsp_btn_ble.c deleted file mode 100644 index 6eb01fe..0000000 --- a/bsp/bsp_btn_ble.c +++ /dev/null @@ -1,240 +0,0 @@ - - -#include "bsp_btn_ble.h" -#include -#include -#include -#include -#include "bsp.h" - - -#define BTN_ID_WAKEUP 0 /**< ID of button used to wake up the application. */ -#define BTN_ID_SLEEP 0 /**< ID of button used to put the application into sleep mode. */ -#define BTN_ID_DISCONNECT 0 /**< ID of button used to gracefully terminate a connection on long press. */ -#define BTN_ID_WAKEUP_BOND_DELETE 1 /**< ID of button used to wake up the application and delete all bonding information. */ -#define BTN_ID_WHITELIST_OFF 1 /**< ID of button used to turn off usage of the whitelist. */ - -#define BTN_ACTION_SLEEP BSP_BUTTON_ACTION_RELEASE /**< Button action used to put the application into sleep mode. */ -#define BTN_ACTION_DISCONNECT BSP_BUTTON_ACTION_LONG_PUSH /**< Button action used to gracefully terminate a connection on long press. */ -#define BTN_ACTION_WHITELIST_OFF BSP_BUTTON_ACTION_LONG_PUSH /**< Button action used to turn off usage of the whitelist. */ - - - -/**@brief This macro will return from the current function if err_code - * is not NRF_SUCCESS. - */ -#define RETURN_ON_ERROR(err_code) \ -do \ -{ \ - if ((err_code) != NRF_SUCCESS) \ - { \ - return err_code; \ - } \ -} \ -while(0) - - -/**@brief This macro will return from the current function if err_code - * is not NRF_SUCCESS or NRF_ERROR_INVALID_PARAM. - */ -#define RETURN_ON_ERROR_NOT_INVALID_PARAM(err_code) \ -do \ -{ \ - if (((err_code) != NRF_SUCCESS) && ((err_code) != NRF_ERROR_INVALID_PARAM)) \ - { \ - return err_code; \ - } \ -} \ -while(0) - - -/**@brief This macro will return from the current function if err_code - * is not NRF_SUCCESS or NRF_ERROR_NOT_SUPPORTED. - */ -#define RETURN_ON_ERROR_NOT_NOT_SUPPORTED(err_code) \ -do \ -{ \ - if (((err_code) != NRF_SUCCESS) && ((err_code) != NRF_ERROR_NOT_SUPPORTED)) \ - { \ - return err_code; \ - } \ -} \ -while(0) - - -/**@brief This macro will call the registered error handler if err_code - * is not NRF_SUCCESS and the error handler is not NULL. - */ -#define CALL_HANDLER_ON_ERROR(err_code) \ -do \ -{ \ - if (((err_code) != NRF_SUCCESS) && (m_error_handler != NULL)) \ - { \ - m_error_handler(err_code); \ - } \ -} \ -while(0) - - -static bsp_btn_ble_error_handler_t m_error_handler = NULL; /**< Error handler registered by the user. */ -static uint32_t m_num_connections = 0; /**< Number of connections the device is currently in. */ - - -/**@brief Function for configuring the buttons for connection. - * - * @retval NRF_SUCCESS Configured successfully. - * @return A propagated error code. - */ -static uint32_t connection_buttons_configure() -{ - uint32_t err_code; - - err_code = bsp_event_to_button_action_assign(BTN_ID_SLEEP, - BTN_ACTION_SLEEP, - BSP_EVENT_DEFAULT); - RETURN_ON_ERROR_NOT_INVALID_PARAM(err_code); - - err_code = bsp_event_to_button_action_assign(BTN_ID_WHITELIST_OFF, - BTN_ACTION_WHITELIST_OFF, - BSP_EVENT_WHITELIST_OFF); - RETURN_ON_ERROR_NOT_INVALID_PARAM(err_code); - - err_code = bsp_event_to_button_action_assign(BTN_ID_DISCONNECT, - BTN_ACTION_DISCONNECT, - BSP_EVENT_DISCONNECT); - RETURN_ON_ERROR_NOT_INVALID_PARAM(err_code); - - return NRF_SUCCESS; -} - - -/**@brief Function for configuring the buttons for advertisement. - * - * @retval NRF_SUCCESS Configured successfully. - * @return A propagated error code. - */ -static uint32_t advertising_buttons_configure() -{ - uint32_t err_code; - - err_code = bsp_event_to_button_action_assign(BTN_ID_DISCONNECT, - BTN_ACTION_DISCONNECT, - BSP_EVENT_DEFAULT); - RETURN_ON_ERROR_NOT_INVALID_PARAM(err_code); - - err_code = bsp_event_to_button_action_assign(BTN_ID_WHITELIST_OFF, - BTN_ACTION_WHITELIST_OFF, - BSP_EVENT_WHITELIST_OFF); - RETURN_ON_ERROR_NOT_INVALID_PARAM(err_code); - - err_code = bsp_event_to_button_action_assign(BTN_ID_SLEEP, - BTN_ACTION_SLEEP, - BSP_EVENT_SLEEP); - RETURN_ON_ERROR_NOT_INVALID_PARAM(err_code); - - return NRF_SUCCESS; -} - - -/**@brief Function for extracting the BSP event valid at startup. - * - * @details When a button was used to wake up the device, the button press will not generate an - * interrupt. This function reads which button was pressed at startup, and returns the - * appropriate BSP event. - * - * @param[out] p_startup_event Where to put the extracted BSP event. - * - * @retval NRF_SUCCESS Extraction was successful. - * @return A propagated error code. - */ -static uint32_t startup_event_extract(bsp_event_t * p_startup_event) -{ - uint32_t err_code; - bool wakeup_button_is_pressed, bond_erase_button_is_pressed; - - // Read buttons - err_code = bsp_button_is_pressed(BTN_ID_WAKEUP, &wakeup_button_is_pressed); - RETURN_ON_ERROR(err_code); - - err_code = bsp_button_is_pressed(BTN_ID_WAKEUP_BOND_DELETE, &bond_erase_button_is_pressed); - RETURN_ON_ERROR(err_code); - - // React to button states - if (bond_erase_button_is_pressed) - { - *p_startup_event = BSP_EVENT_CLEAR_BONDING_DATA; - } - else if (wakeup_button_is_pressed) - { - *p_startup_event = BSP_EVENT_WAKEUP; - } - else - { - *p_startup_event = BSP_EVENT_NOTHING; - } - - return NRF_SUCCESS; -} - - -uint32_t bsp_btn_ble_sleep_mode_prepare(void) -{ - uint32_t err_code = bsp_wakeup_buttons_set((1 << BTN_ID_WAKEUP) | (1 << BTN_ID_WAKEUP_BOND_DELETE)); - - RETURN_ON_ERROR_NOT_NOT_SUPPORTED(err_code); - - return NRF_SUCCESS; -} - - -void bsp_btn_ble_on_ble_evt(ble_evt_t * p_ble_evt) -{ - uint32_t err_code; - - switch (p_ble_evt->header.evt_id) - { - case BLE_GAP_EVT_CONNECTED: - if (m_num_connections == 0) - { - err_code = connection_buttons_configure(); - CALL_HANDLER_ON_ERROR(err_code); - } - - m_num_connections++; - break; - - case BLE_GAP_EVT_DISCONNECTED: - m_num_connections--; - - if (m_num_connections == 0) - { - err_code = advertising_buttons_configure(); - CALL_HANDLER_ON_ERROR(err_code); - } - break; - - default: - break; - } -} - - -uint32_t bsp_btn_ble_init(bsp_btn_ble_error_handler_t error_handler, bsp_event_t * p_startup_bsp_evt) -{ - uint32_t err_code = NRF_SUCCESS; - - m_error_handler = error_handler; - - if (p_startup_bsp_evt != NULL) - { - err_code = startup_event_extract(p_startup_bsp_evt); - RETURN_ON_ERROR(err_code); - } - - if (m_num_connections == 0) - { - err_code = advertising_buttons_configure(); - } - - return err_code; -} diff --git a/bsp/bsp_btn_ble.h b/bsp/bsp_btn_ble.h deleted file mode 100644 index 833e120..0000000 --- a/bsp/bsp_btn_ble.h +++ /dev/null @@ -1,72 +0,0 @@ -/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ - -/**@file - * - * @defgroup bsp_btn_ble Board Support Package: BLE Button Module - * @{ - * @ingroup app_common - * - * @brief Module for controlling BLE behavior through button actions. - * - * @details The application must propagate BLE events to the BLE Button Module. - * Based on these events, the BLE Button Module configures the Board Support Package - * to generate BSP events for certain button actions. These BSP events should then be - * handled by the application's BSP event handler. - * - */ - -#ifndef BSP_BTN_BLE_H__ -#define BSP_BTN_BLE_H__ - -#include -#include -#include "bsp.h" - -/**@brief BLE Button Module error handler type. */ -typedef void (*bsp_btn_ble_error_handler_t) (uint32_t nrf_error); - -/**@brief Function for initializing the BLE Button Module. - * - * Before calling this function, the BSP module must be initialized with buttons. - * - * @param[out] error_handler Error handler to call in case of internal errors in BLE Button - * Module. - * @param[out] p_startup_bsp_evt If not a NULL pointer, the value is filled with an event - * (or BSP_EVENT_NOTHING) derived from the buttons pressed on - * startup. For example, if the bond delete wakeup button was pressed - * to wake up the device, *p_startup_bsp_evt is set to - * @ref BSP_EVENT_CLEAR_BONDING_DATA. - * - * @retval NRF_SUCCESS If initialization was successful. Otherwise, a propagated error code is - * returned. - */ -uint32_t bsp_btn_ble_init(bsp_btn_ble_error_handler_t error_handler, bsp_event_t * p_startup_bsp_evt); - -/**@brief Function for setting up wakeup buttons before going into sleep mode. - * - * @retval NRF_SUCCESS If the buttons were prepared successfully. Otherwise, a propagated error - * code is returned. - */ -uint32_t bsp_btn_ble_sleep_mode_prepare(void); - -/**@brief Function for handling the application's BLE stack events. - * - * @details This function handles all events from the BLE stack that are of interest to this module. - * - * @param[in] p_ble_evt BLE stack event. - */ -void bsp_btn_ble_on_ble_evt(ble_evt_t * p_ble_evt); - -#endif /* BSP_BTN_BLE_H__ */ - -/** @} */ diff --git a/main.c b/main.c index 5ab2c36..41d1b0b 100644 --- a/main.c +++ b/main.c @@ -34,7 +34,6 @@ #include #include "bsp/bsp.h" -#include "bsp/bsp_btn_ble.h" -- cgit v1.2.3