diff --git a/app_config.h b/app_config.h index a9b922f..43dddf1 100644 --- a/app_config.h +++ b/app_config.h @@ -90,8 +90,7 @@ extern "C" #define NRF_SDH_BLE_OBSERVER_PRIO_LEVELS 4 // Include the Service Changed characteristic in the Attribute Table. #define NRF_SDH_BLE_SERVICE_CHANGED 0 -// Static maximum MTU size. -#define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 247 + // This setting configures how Stack events are dispatched to the application. #define NRF_SDH_DISPATCH_MODEL 2 /* SoftDevice events are to be fetched manually. */ @@ -149,6 +148,24 @@ extern "C" MAJOR_PRODUCT_NUMBER, MINOR_PRODUCT_NUMBER, MAJOR_VERSION_NUMBER, MINOR_VERSION_NUMBER \ } +// Maximum number of peripheral links. +#define NRF_SDH_BLE_PERIPHERAL_LINK_COUNT 1 +// Maximum number of central links. +#define NRF_SDH_BLE_CENTRAL_LINK_COUNT 0 +// Total link count. +#define NRF_SDH_BLE_TOTAL_LINK_COUNT 1 + +// Enable GATT module. +#define NRF_BLE_GATT_ENABLED 1 +// Priority with which BLE events are dispatched to the GATT module. +#define NRF_BLE_GATT_BLE_OBSERVER_PRIO 1 +// Requested BLE GAP data length to be negotiated. +#define NRF_SDH_BLE_GAP_DATA_LENGTH 27 +// GAP event length. The time set aside for this connection on every connection interval in 1.25 ms units. +#define NRF_SDH_BLE_GAP_EVENT_LENGTH 6 +// Static maximum MTU size. +#define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 23 + #ifdef __cplusplus } #endif diff --git a/bmd380_peripheral.vcxproj b/bmd380_peripheral.vcxproj index bd219f5..e63915e 100644 --- a/bmd380_peripheral.vcxproj +++ b/bmd380_peripheral.vcxproj @@ -74,6 +74,7 @@ + @@ -162,6 +163,7 @@ + @@ -222,6 +224,7 @@ + diff --git a/bmd380_peripheral.vcxproj.filters b/bmd380_peripheral.vcxproj.filters index 8bb67a0..f7cd42c 100644 --- a/bmd380_peripheral.vcxproj.filters +++ b/bmd380_peripheral.vcxproj.filters @@ -232,6 +232,12 @@ {defffc43-551c-4791-967b-7d0aee507516} + + {345707cc-7a27-4c28-94b4-19df7d90e78d} + + + {b6e27cec-5179-4ec4-8f4d-e7e9fbaabae8} + @@ -1326,6 +1332,12 @@ Source files + + Source files + + + Source files\ble\nrf_ble_gatt + @@ -1579,6 +1591,9 @@ Header files + + Header files\ble\nrf_ble_gatt + diff --git a/le_gatt.c b/le_gatt.c new file mode 100644 index 0000000..626e9f8 --- /dev/null +++ b/le_gatt.c @@ -0,0 +1,35 @@ +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include "app_config.h" +#include "apply_old_config.h" +#include "sdk_config.h" + +#include "nrf_log.h" +#include "nrf_log_ctrl.h" +#include "nrf_log_default_backends.h" + +#include "nrf_delay.h" +#include "nrf_gpio.h" + +#include "nrf_sdh.h" +#include "nrf_sdh_ble.h" +#include "nrf_sdh_freertos.h" + +#include "ble_gatt.h" +#include "nrf_ble_gatt.h" + +#ifdef __cplusplus +} +#endif + +NRF_BLE_GATT_DEF(m_gatt); /**< GATT module instance. */ +void le_gatt_init(void) { + ret_code_t err_code = nrf_ble_gatt_init(&m_gatt, NULL); + APP_ERROR_CHECK(err_code); +} \ No newline at end of file diff --git a/main.c b/main.c index a882e20..3228d19 100644 --- a/main.c +++ b/main.c @@ -33,7 +33,22 @@ extern "C" static void le_evt_handler(ble_evt_t const *p_ble_evt, void *p_context) { - // TODO... + switch (p_ble_evt->header.evt_id) + { + ret_code_t err_code; + 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; + default: + break; + } } static void le_stack_Init(void) @@ -107,6 +122,9 @@ int main(void) extern void le_gap_init(const char *device_name, uint16_t usAppearance); le_gap_init(ELITE_DEVICE_NAME, BLE_APPEARANCE_UNKNOWN); + extern void le_gatt_init(void); + le_gatt_init(); + extern void le_adv_init(uint8_t ble_conn_cfg_tag); le_adv_init(APP_BLE_CONN_CFG_TAG);