Skip to content

Commit 1347252

Browse files
ATmobicapull[bot]
authored andcommitted
Mbed OS capsense module support (#9398)
* Add mbed cypress capsense lib to third_party Add capsesne support to ligthing-app and lock-app * Update mbed-os-cypress-capsense-button lib version * Changes restyle * Restore gitmodules file formatting * Remove sleep workaround and restyle
1 parent f2b79a1 commit 1347252

File tree

12 files changed

+125
-33
lines changed

12 files changed

+125
-33
lines changed

.gitmodules

+4
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@
9595
path = third_party/mbed-os-posix-socket/repo
9696
url = https://github.com/ARMmbed/mbed-os-posix-socket.git
9797
branch = main
98+
[submodule "mbed-os-cypress-capsense-button"]
99+
path = third_party/mbed-os-cypress-capsense-button/repo
100+
url = https://github.com/ARMmbed/mbed-os-cypress-capsense-button.git
101+
branch = main
98102
[submodule "p6/abstraction-rtos"]
99103
path = third_party/p6/p6_sdk/libs/abstraction-rtos
100104
url = https://github.com/Infineon/abstraction-rtos

examples/lighting-app/mbed/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ if("WHD" IN_LIST MBED_TARGET_LABELS)
121121
)
122122
endif()
123123

124+
if("capsense" IN_LIST MBED_TARGET_LABELS)
125+
add_subdirectory(${CHIP_ROOT}/third_party/mbed-os-cypress-capsense-button/repo ./capsense_build)
126+
target_link_libraries(${APP_TARGET} capsense)
127+
endif()
128+
124129
mbed_set_post_build(${APP_TARGET})
125130

126131
option(VERBOSE_BUILD "Have a verbose build process")

examples/lighting-app/mbed/main/AppTask.cpp

+63-16
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#include "LightingManager.h"
2222
#include <app/server/OnboardingCodesUtil.h>
2323

24+
#ifdef CAPSENSE_ENABLED
25+
#include "capsense.h"
26+
#endif
27+
2428
// FIXME: Undefine the `sleep()` function included by the CHIPDeviceLayer.h
2529
// from unistd.h to avoid a conflicting declaration with the `sleep()` provided
2630
// by Mbed-OS in mbed_power_mgmt.h.
@@ -58,13 +62,16 @@ static LEDWidget sStatusLED(MBED_CONF_APP_SYSTEM_STATE_LED);
5862

5963
static mbed::InterruptIn sLightingButton(LIGHTING_BUTTON);
6064
static mbed::InterruptIn sFunctionButton(FUNCTION_BUTTON);
61-
65+
#ifdef CAPSENSE_ENABLED
66+
static mbed::CapsenseButton CapFunctionButton(Capsense::getInstance(), 0);
67+
static mbed::CapsenseButton CapLockButton(Capsense::getInstance(), 1);
68+
static mbed::CapsenseSlider CapSlider(Capsense::getInstance());
69+
#endif
6270
static bool sIsWiFiStationProvisioned = false;
6371
static bool sIsWiFiStationEnabled = false;
6472
static bool sIsWiFiStationConnected = false;
6573
static bool sIsPairedToAccount = false;
6674
static bool sHaveBLEConnections = false;
67-
static bool sHaveServiceConnectivity = false;
6875

6976
static mbed::Timeout sFunctionTimer;
7077

@@ -95,10 +102,17 @@ int AppTask::Init()
95102

96103
//-------------
97104
// Initialize button
105+
#ifdef CAPSENSE_ENABLED
106+
CapFunctionButton.fall(mbed::callback(this, &AppTask::FunctionButtonPressEventHandler));
107+
CapFunctionButton.rise(mbed::callback(this, &AppTask::FunctionButtonReleaseEventHandler));
108+
CapLockButton.fall(mbed::callback(this, &AppTask::LightingButtonPressEventHandler));
109+
CapSlider.on_move(mbed::callback(this, &AppTask::SliderEventHandler));
110+
#else
98111
sLightingButton.fall(mbed::callback(this, &AppTask::LightingButtonPressEventHandler));
99112
sFunctionButton.fall(mbed::callback(this, &AppTask::FunctionButtonPressEventHandler));
100113
sFunctionButton.rise(mbed::callback(this, &AppTask::FunctionButtonReleaseEventHandler));
101-
//----------------
114+
#endif
115+
102116
// Initialize lighting manager
103117
LightingMgr().Init(MBED_CONF_APP_LIGHTING_STATE_LED);
104118
LightingMgr().SetCallbacks(ActionInitiated, ActionCompleted);
@@ -153,20 +167,14 @@ int AppTask::StartApp()
153167
sIsWiFiStationEnabled = ConnectivityMgr().IsWiFiStationEnabled();
154168
sIsWiFiStationConnected = ConnectivityMgr().IsWiFiStationConnected();
155169
sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0);
156-
sHaveServiceConnectivity = ConnectivityMgr().HaveServiceConnectivity();
157170
PlatformMgr().UnlockChipStack();
158171
}
159172

160-
// Consider the system to be "fully connected" if it has service
161-
// connectivity and it is able to interact with the service on a regular basis.
162-
bool isFullyConnected = sHaveServiceConnectivity;
163-
164173
// Update the status LED if factory reset has not been initiated.
165174
//
166-
// If system has "full connectivity", keep the LED On constantly.
175+
// If system is connected to Wi-Fi station, keep the LED On constantly.
167176
//
168-
// If thread and service provisioned, but not attached to the thread network yet OR no
169-
// connectivity to the service OR subscriptions are not fully established
177+
// If Wi-Fi is provisioned, but not connected to Wi-Fi station yet
170178
// THEN blink the LED Off for a short period of time.
171179
//
172180
// If the system has ble connection(s) uptill the stage above, THEN blink the LEDs at an even
@@ -175,12 +183,11 @@ int AppTask::StartApp()
175183
// Otherwise, blink the LED ON for a very short time.
176184
if (sAppTask.mFunction != kFunction_FactoryReset)
177185
{
178-
if (isFullyConnected)
186+
if (sIsWiFiStationConnected)
179187
{
180188
sStatusLED.Set(true);
181189
}
182-
else if (sIsWiFiStationProvisioned && sIsWiFiStationEnabled && sIsPairedToAccount &&
183-
(!sIsWiFiStationConnected || !isFullyConnected))
190+
else if (sIsWiFiStationProvisioned && sIsWiFiStationEnabled && sIsPairedToAccount && !sIsWiFiStationConnected)
184191
{
185192
sStatusLED.Blink(950, 50);
186193
}
@@ -202,7 +209,7 @@ void AppTask::LightingActionEventHandler(AppEvent * aEvent)
202209
{
203210
LightingManager::Action_t action = LightingManager::INVALID_ACTION;
204211
int32_t actor = 0;
205-
212+
uint8_t value = 0;
206213
if (aEvent->Type == AppEvent::kEventType_Lighting)
207214
{
208215
action = static_cast<LightingManager::Action_t>(aEvent->LightingEvent.Action);
@@ -213,8 +220,14 @@ void AppTask::LightingActionEventHandler(AppEvent * aEvent)
213220
action = LightingMgr().IsTurnedOn() ? LightingManager::OFF_ACTION : LightingManager::ON_ACTION;
214221
actor = AppEvent::kEventType_Button;
215222
}
223+
else if (aEvent->Type == AppEvent::kEventType_Slider)
224+
{
225+
action = LightingManager::LEVEL_ACTION;
226+
actor = AppEvent::kEventType_Slider;
227+
value = aEvent->SliderEvent.Value;
228+
}
216229

217-
if (action != LightingManager::INVALID_ACTION && !LightingMgr().InitiateAction(action, actor, 0, NULL))
230+
if (action != LightingManager::INVALID_ACTION && !LightingMgr().InitiateAction(action, actor, 0, &value))
218231
ChipLogProgress(NotSpecified, "Action is already in progress or active.");
219232
}
220233

@@ -248,6 +261,40 @@ void AppTask::FunctionButtonReleaseEventHandler()
248261
sAppTask.PostEvent(&button_event);
249262
}
250263

264+
void AppTask::ButtonEventHandler(uint32_t id, bool pushed)
265+
{
266+
if (id > 1)
267+
{
268+
ChipLogError(NotSpecified, "Wrong button ID");
269+
return;
270+
}
271+
272+
AppEvent button_event;
273+
button_event.Type = AppEvent::kEventType_Button;
274+
button_event.ButtonEvent.Pin = id == 0 ? LIGHTING_BUTTON : FUNCTION_BUTTON;
275+
button_event.ButtonEvent.Action = pushed ? BUTTON_PUSH_EVENT : BUTTON_RELEASE_EVENT;
276+
277+
if (id == 0)
278+
{
279+
button_event.Handler = LightingActionEventHandler;
280+
}
281+
else
282+
{
283+
button_event.Handler = FunctionHandler;
284+
}
285+
286+
sAppTask.PostEvent(&button_event);
287+
}
288+
289+
void AppTask::SliderEventHandler(int slider_pos)
290+
{
291+
AppEvent slider_event;
292+
slider_event.Type = AppEvent::kEventType_Slider;
293+
slider_event.SliderEvent.Value = slider_pos;
294+
slider_event.Handler = LightingActionEventHandler;
295+
sAppTask.PostEvent(&slider_event);
296+
}
297+
251298
void AppTask::ActionInitiated(LightingManager::Action_t aAction, int32_t aActor)
252299
{
253300
if (aAction == LightingManager::ON_ACTION)

examples/lighting-app/mbed/main/include/AppEvent.h

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct AppEvent
3232
kEventType_Timer,
3333
kEventType_Lighting,
3434
kEventType_Install,
35+
kEventType_Slider,
3536
};
3637

3738
uint16_t Type;
@@ -52,6 +53,10 @@ struct AppEvent
5253
uint8_t Action;
5354
int32_t Actor;
5455
} LightingEvent;
56+
struct
57+
{
58+
uint8_t Value;
59+
} SliderEvent;
5560
};
5661

5762
EventHandler Handler;

examples/lighting-app/mbed/main/include/AppTask.h

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class AppTask
5050
void LightingButtonPressEventHandler(void);
5151
void FunctionButtonPressEventHandler(void);
5252
void FunctionButtonReleaseEventHandler(void);
53+
void ButtonEventHandler(uint32_t id, bool pushed);
54+
void SliderEventHandler(int slider_pos);
5355
void TimerEventHandler(void);
5456

5557
void StartTimer(uint32_t aTimeoutInMs);

examples/lighting-app/mbed/main/main.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
#include "AppTask.h"
2121

22+
#ifdef CAPSENSE_ENABLED
23+
#include "capsense.h"
24+
#endif
25+
2226
#include "mbedtls/platform.h"
2327
#include <lib/support/CHIPMem.h>
2428
#include <lib/support/logging/CHIPLogging.h>
@@ -37,6 +41,10 @@ int main()
3741

3842
mbed_logging_init();
3943

44+
#ifdef CAPSENSE_ENABLED
45+
Capsense::getInstance().init();
46+
#endif
47+
4048
ret = mbedtls_platform_setup(NULL);
4149
if (ret)
4250
{

examples/lighting-app/mbed/mbed_app.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
"NL_ASSERT_EXPECT_FLAGS=NL_ASSERT_FLAG_LOG",
3131
"WHD_PRINT_DISABLE"
3232
],
33+
"target.components_add": ["capsense"],
3334
"led-active-state": 0,
3435
"system-state-led": "LED1",
3536
"lighting-state-led": "P9_6",
36-
"lighting-button": "USER_BUTTON",
37-
"function-button": "P9_7"
37+
"lighting-button": "USER_BUTTON"
3838
}
3939
},
4040
"config": {

examples/lock-app/mbed/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ if("WHD" IN_LIST MBED_TARGET_LABELS)
124124
)
125125
endif()
126126

127+
if("capsense" IN_LIST MBED_TARGET_LABELS)
128+
add_subdirectory(${CHIP_ROOT}/third_party/mbed-os-cypress-capsense-button/repo ./capsense_build)
129+
target_link_libraries(${APP_TARGET} capsense)
130+
endif()
131+
127132
mbed_set_post_build(${APP_TARGET})
128133

129134
option(VERBOSE_BUILD "Have a verbose build process")

examples/lock-app/mbed/main/AppTask.cpp

+19-12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#include "LEDWidget.h"
2222
#include <app/server/OnboardingCodesUtil.h>
2323

24+
#ifdef CAPSENSE_ENABLED
25+
#include "capsense.h"
26+
#endif
27+
2428
// FIXME: Undefine the `sleep()` function included by the CHIPDeviceLayer.h
2529
// from unistd.h to avoid a conflicting declaration with the `sleep()` provided
2630
// by Mbed-OS in mbed_power_mgmt.h.
@@ -58,15 +62,19 @@ constexpr uint32_t kPublishServicePeriodUs = 5000000;
5862
static LEDWidget sStatusLED(MBED_CONF_APP_SYSTEM_STATE_LED);
5963
static LEDWidget sLockLED(MBED_CONF_APP_LOCK_STATE_LED);
6064

65+
#ifdef CAPSENSE_ENABLED
66+
static mbed::CapsenseButton CapFunctionButton(Capsense::getInstance(), 0);
67+
static mbed::CapsenseButton CapLockButton(Capsense::getInstance(), 1);
68+
#else
6169
static mbed::InterruptIn sLockButton(LOCK_BUTTON);
6270
static mbed::InterruptIn sFunctionButton(FUNCTION_BUTTON);
71+
#endif
6372

6473
static bool sIsWiFiStationProvisioned = false;
6574
static bool sIsWiFiStationEnabled = false;
6675
static bool sIsWiFiStationConnected = false;
6776
static bool sIsPairedToAccount = false;
6877
static bool sHaveBLEConnections = false;
69-
static bool sHaveServiceConnectivity = false;
7078

7179
static mbed::Timeout sFunctionTimer;
7280

@@ -99,9 +107,15 @@ int AppTask::Init()
99107
sLockLED.Set(!BoltLockMgr().IsUnlocked());
100108

101109
// Initialize buttons
110+
#ifdef CAPSENSE_ENABLED
111+
CapFunctionButton.fall(mbed::callback(this, &AppTask::FunctionButtonPressEventHandler));
112+
CapFunctionButton.rise(mbed::callback(this, &AppTask::FunctionButtonReleaseEventHandler));
113+
CapLockButton.fall(mbed::callback(this, &AppTask::LockButtonPressEventHandler));
114+
#else
102115
sLockButton.fall(mbed::callback(this, &AppTask::LockButtonPressEventHandler));
103116
sFunctionButton.fall(mbed::callback(this, &AppTask::FunctionButtonPressEventHandler));
104117
sFunctionButton.rise(mbed::callback(this, &AppTask::FunctionButtonReleaseEventHandler));
118+
#endif
105119

106120
// Initialize lock manager
107121
BoltLockMgr().Init();
@@ -156,20 +170,14 @@ int AppTask::StartApp()
156170
sIsWiFiStationEnabled = ConnectivityMgr().IsWiFiStationEnabled();
157171
sIsWiFiStationConnected = ConnectivityMgr().IsWiFiStationConnected();
158172
sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0);
159-
sHaveServiceConnectivity = ConnectivityMgr().HaveServiceConnectivity();
160173
PlatformMgr().UnlockChipStack();
161174
}
162175

163-
// Consider the system to be "fully connected" if it has service
164-
// connectivity and it is able to interact with the service on a regular basis.
165-
bool isFullyConnected = sHaveServiceConnectivity;
166-
167176
// Update the status LED if factory reset has not been initiated.
168177
//
169-
// If system has "full connectivity", keep the LED On constantly.
178+
// If system is connected to Wi-Fi station, keep the LED On constantly.
170179
//
171-
// If thread and service provisioned, but not attached to the thread network yet OR no
172-
// connectivity to the service OR subscriptions are not fully established
180+
// If Wi-Fi is provisioned, but not connected to Wi-Fi station yet
173181
// THEN blink the LED Off for a short period of time.
174182
//
175183
// If the system has ble connection(s) uptill the stage above, THEN blink the LEDs at an even
@@ -178,12 +186,11 @@ int AppTask::StartApp()
178186
// Otherwise, blink the LED ON for a very short time.
179187
if (sAppTask.mFunction != kFunction_FactoryReset)
180188
{
181-
if (isFullyConnected)
189+
if (sIsWiFiStationConnected)
182190
{
183191
sStatusLED.Set(true);
184192
}
185-
else if (sIsWiFiStationProvisioned && sIsWiFiStationEnabled && sIsPairedToAccount &&
186-
(!sIsWiFiStationConnected || !isFullyConnected))
193+
else if (sIsWiFiStationProvisioned && sIsWiFiStationEnabled && sIsPairedToAccount && !sIsWiFiStationConnected)
187194
{
188195
sStatusLED.Blink(950, 50);
189196
}

examples/lock-app/mbed/main/main.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
#include "AppTask.h"
2121

22+
#ifdef CAPSENSE_ENABLED
23+
#include "capsense.h"
24+
#endif
25+
2226
#include "mbedtls/platform.h"
2327
#include <lib/support/CHIPMem.h>
2428
#include <lib/support/logging/CHIPLogging.h>
@@ -37,6 +41,10 @@ int main()
3741

3842
mbed_logging_init();
3943

44+
#ifdef CAPSENSE_ENABLED
45+
Capsense::getInstance().init();
46+
#endif
47+
4048
ret = mbedtls_platform_setup(NULL);
4149
if (ret)
4250
{

examples/lock-app/mbed/mbed_app.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
"NL_ASSERT_EXPECT_FLAGS=NL_ASSERT_FLAG_LOG",
3131
"WHD_PRINT_DISABLE"
3232
],
33-
"led-active-state": 1,
33+
"target.components_add": ["capsense"],
34+
"led-active-state": 0,
3435
"system-state-led": "LED1",
3536
"lock-state-led": "P9_6",
36-
"lock-button": "USER_BUTTON",
37-
"function-button": "P9_7"
37+
"lock-button": "USER_BUTTON"
3838
}
3939
},
4040
"config": {
Submodule repo added at fef47a0

0 commit comments

Comments
 (0)