Skip to content

Commit

Permalink
[nrfconnect] Introduce BLE advertising arbiter (#24637)
Browse files Browse the repository at this point in the history
* [nrfconnect] Introduce BLE advertising arbiter

Add a class that enables easier coexistence of Matter and
custom BLE services.

Signed-off-by: Damian Krolik <[email protected]>

* Restyled by clang-format

---------

Signed-off-by: Damian Krolik <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Sep 29, 2023
1 parent 3ac192e commit 59944dd
Show file tree
Hide file tree
Showing 35 changed files with 397 additions and 308 deletions.
4 changes: 1 addition & 3 deletions config/nrfconnect/chip-module/Kconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ config BT_DEVICE_NAME_MAX
default 15

config BT_MAX_CONN
default 2 # a workaround for non-unreferenced BLE connection object
# when restaring the BLE advertising in disconnect callback
# TODO: analyze and revert to 1 if proper fix exists
default 1

config BT_L2CAP_TX_MTU
default 247
Expand Down
10 changes: 0 additions & 10 deletions examples/all-clusters-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,6 @@ void AppTask::FunctionTimerEventHandler(const AppEvent & event)
}
}

#ifdef CONFIG_MCUMGR_SMP_BT
void AppTask::RequestSMPAdvertisingStart(void)
{
AppEvent event;
event.Type = AppEventType::StartSMPAdvertising;
event.Handler = [](const AppEvent &) { GetDFUOverSMP().StartBLEAdvertising(); };
PostEvent(event);
}
#endif

void AppTask::FunctionHandler(const AppEvent & event)
{
if (event.ButtonEvent.PinNo != FUNCTION_BUTTON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ enum class AppEventType : uint8_t
UpdateLedState,
IdentifyStart,
IdentifyStop,
StartSMPAdvertising
};

enum class FunctionEvent : uint8_t
Expand Down
4 changes: 0 additions & 4 deletions examples/all-clusters-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ class AppTask
static void FunctionTimerTimeoutCallback(k_timer * timer);
static void UpdateStatusLED();

#ifdef CONFIG_MCUMGR_SMP_BT
static void RequestSMPAdvertisingStart(void);
#endif

FunctionEvent mFunction = FunctionEvent::NoneSelected;
bool mFunctionTimerActive = false;

Expand Down
10 changes: 0 additions & 10 deletions examples/all-clusters-minimal-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,6 @@ void AppTask::ButtonEventHandler(uint32_t buttonState, uint32_t hasChanged)
}
}

#ifdef CONFIG_MCUMGR_SMP_BT
void AppTask::RequestSMPAdvertisingStart(void)
{
AppEvent event;
event.Type = AppEventType::StartSMPAdvertising;
event.Handler = [](const AppEvent &) { GetDFUOverSMP().StartBLEAdvertising(); };
PostEvent(event);
}
#endif

void AppTask::FunctionTimerTimeoutCallback(k_timer * timer)
{
if (!timer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ enum class AppEventType : uint8_t
UpdateLedState,
IdentifyStart,
IdentifyStop,
StartSMPAdvertising
};

enum class FunctionEvent : uint8_t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ class AppTask
static void FunctionTimerTimeoutCallback(k_timer * timer);
static void UpdateStatusLED();

#ifdef CONFIG_MCUMGR_SMP_BT
static void RequestSMPAdvertisingStart(void);
#endif

FunctionEvent mFunction = FunctionEvent::NoneSelected;
bool mFunctionTimerActive = false;

Expand Down
12 changes: 1 addition & 11 deletions examples/light-switch-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ CHIP_ERROR AppTask::Init()

// Initialize DFU
#ifdef CONFIG_MCUMGR_SMP_BT
GetDFUOverSMP().Init(RequestSMPAdvertisingStart);
GetDFUOverSMP().Init();
GetDFUOverSMP().ConfirmNewImage();
#endif

Expand Down Expand Up @@ -646,16 +646,6 @@ void AppTask::FunctionTimerTimeoutCallback(k_timer * timer)
}
}

#ifdef CONFIG_MCUMGR_SMP_BT
void AppTask::RequestSMPAdvertisingStart(void)
{
AppEvent event;
event.Type = AppEventType::StartSMPAdvertising;
event.Handler = [](const AppEvent &) { GetDFUOverSMP().StartBLEAdvertising(); };
PostEvent(event);
}
#endif

void AppTask::PostEvent(const AppEvent & event)
{
if (k_msgq_put(&sAppEventQueue, &event, K_NO_WAIT) != 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ enum class AppEventType : uint8_t
UpdateLedState,
IdentifyStart,
IdentifyStop,
StartSMPAdvertising
};

enum class FunctionEvent : uint8_t
Expand Down
4 changes: 0 additions & 4 deletions examples/light-switch-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ class AppTask
static void StartTimer(Timer, uint32_t);
static void CancelTimer(Timer);

#ifdef CONFIG_MCUMGR_SMP_BT
static void RequestSMPAdvertisingStart(void);
#endif

FunctionEvent mFunction = FunctionEvent::NoneSelected;

#if CONFIG_CHIP_FACTORY_DATA
Expand Down
12 changes: 1 addition & 11 deletions examples/lighting-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ CHIP_ERROR AppTask::Init()

#ifdef CONFIG_MCUMGR_SMP_BT
// Initialize DFU over SMP
GetDFUOverSMP().Init(RequestSMPAdvertisingStart);
GetDFUOverSMP().Init();
GetDFUOverSMP().ConfirmNewImage();
#endif

Expand Down Expand Up @@ -443,16 +443,6 @@ void AppTask::FunctionTimerEventHandler(const AppEvent & event)
}
}

#ifdef CONFIG_MCUMGR_SMP_BT
void AppTask::RequestSMPAdvertisingStart(void)
{
AppEvent event;
event.Type = AppEventType::StartSMPAdvertising;
event.Handler = [](const AppEvent &) { GetDFUOverSMP().StartBLEAdvertising(); };
PostEvent(event);
}
#endif

void AppTask::FunctionHandler(const AppEvent & event)
{
if (event.ButtonEvent.PinNo != FUNCTION_BUTTON)
Expand Down
1 change: 0 additions & 1 deletion examples/lighting-app/nrfconnect/main/include/AppEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ enum class AppEventType : uint8_t
Lighting,
IdentifyStart,
IdentifyStop,
StartSMPAdvertising
};

enum class FunctionEvent : uint8_t
Expand Down
4 changes: 0 additions & 4 deletions examples/lighting-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ class AppTask
static void FunctionHandler(const AppEvent & event);
static void StartBLEAdvertisementAndLightActionEventHandler(const AppEvent & event);

#ifdef CONFIG_MCUMGR_SMP_BT
static void RequestSMPAdvertisingStart(void);
#endif

FunctionEvent mFunction = FunctionEvent::NoneSelected;
bool mFunctionTimerActive = false;
PWMDevice mPWMDevice;
Expand Down
12 changes: 1 addition & 11 deletions examples/lock-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ CHIP_ERROR AppTask::Init()

#ifdef CONFIG_MCUMGR_SMP_BT
// Initialize DFU over SMP
GetDFUOverSMP().Init(RequestSMPAdvertisingStart);
GetDFUOverSMP().Init();
GetDFUOverSMP().ConfirmNewImage();
#endif

Expand Down Expand Up @@ -399,16 +399,6 @@ void AppTask::FunctionTimerEventHandler(const AppEvent & event)
}
}

#ifdef CONFIG_MCUMGR_SMP_BT
void AppTask::RequestSMPAdvertisingStart(void)
{
AppEvent event;
event.Type = AppEventType::StartSMPAdvertising;
event.Handler = [](const AppEvent &) { GetDFUOverSMP().StartBLEAdvertising(); };
PostEvent(event);
}
#endif

void AppTask::FunctionHandler(const AppEvent & event)
{
if (event.ButtonEvent.PinNo != FUNCTION_BUTTON)
Expand Down
1 change: 0 additions & 1 deletion examples/lock-app/nrfconnect/main/include/AppEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ enum class AppEventType : uint8_t
UpdateLedState,
IdentifyStart,
IdentifyStop,
StartSMPAdvertising
};

enum class FunctionEvent : uint8_t
Expand Down
4 changes: 0 additions & 4 deletions examples/lock-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ class AppTask

static void LockStateChanged(BoltLockManager::State state, BoltLockManager::OperationSource source);

#ifdef CONFIG_MCUMGR_SMP_BT
static void RequestSMPAdvertisingStart(void);
#endif

FunctionEvent mFunction = FunctionEvent::NoneSelected;
bool mFunctionTimerActive = false;

Expand Down
Loading

0 comments on commit 59944dd

Please sign in to comment.