Skip to content

Commit c251541

Browse files
MarekPietakapi-no
authored andcommitted
applications: nrf_desktop: Align initialization of keys_state utility
Change updates the utility to rely on runtime assertions ensuring that the initialization function is called only once and other APIs of the utility are called after the utility was initialized. This is done to align the utility with other application utilities. Jira: NCSDK-35363 Signed-off-by: Marek Pieta <[email protected]> Signed-off-by: Pekka Niskanen <[email protected]>
1 parent 3439f18 commit c251541

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

applications/nrf_desktop/src/util/keys_state.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ void keys_state_init(struct keys_state *ks, uint8_t key_cnt_max)
2727
{
2828
LOG_DBG("ks:%p, key_cnt_max:%" PRIu8, (void *)ks, key_cnt_max);
2929

30+
ARG_UNUSED(keys_state_is_initialized);
31+
3032
__ASSERT_NO_MSG(!keys_state_is_initialized(ks));
3133
__ASSERT_NO_MSG((key_cnt_max > 0) && (key_cnt_max <= ARRAY_SIZE(ks->keys)));
3234

@@ -112,6 +114,7 @@ int keys_state_key_update(struct keys_state *ks, uint16_t key_id, bool pressed,
112114
(void *)ks, key_id, pressed ? "press" : "release");
113115

114116
__ASSERT_NO_MSG(ks_changed);
117+
__ASSERT_NO_MSG(keys_state_is_initialized(ks));
115118

116119
int err = 0;
117120
uint8_t prev_cnt = ks->cnt;
@@ -152,10 +155,10 @@ void keys_state_clear(struct keys_state *ks)
152155
{
153156
LOG_DBG("ks:%p", (void *)ks);
154157

155-
if (keys_state_is_initialized(ks)) {
156-
memset(ks->keys, 0, sizeof(ks->keys));
157-
ks->cnt = 0;
158-
}
158+
__ASSERT_NO_MSG(keys_state_is_initialized(ks));
159+
160+
memset(ks->keys, 0, sizeof(ks->keys));
161+
ks->cnt = 0;
159162
}
160163

161164
size_t keys_state_keys_get(const struct keys_state *ks, uint16_t *res, size_t res_size)
@@ -166,6 +169,8 @@ size_t keys_state_keys_get(const struct keys_state *ks, uint16_t *res, size_t re
166169
__ASSERT_NO_MSG(res_size >= ks->cnt_max);
167170
ARG_UNUSED(res_size);
168171

172+
__ASSERT_NO_MSG(keys_state_is_initialized(ks));
173+
169174
for (uint8_t i = 0; i < ks->cnt; i++) {
170175
res[i] = ks->keys[i].id;
171176
}

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ nRF Desktop
408408
* Application image configurations to explicitly specify the LED driver used by the :ref:`nrf_desktop_leds` (:kconfig:option:`CONFIG_CAF_LEDS_GPIO` or :kconfig:option:`CONFIG_CAF_LEDS_PWM`).
409409
Also, disabled unused LED drivers enabled by default to reduce memory footprint.
410410
* The :ref:`nrf_desktop_hid_forward` to allow using the module when configuration channel support (:ref:`CONFIG_DESKTOP_CONFIG_CHANNEL_ENABLE <config_desktop_app_options>`) is disabled in the application configuration.
411+
* The :ref:`nrf_desktop_keys_state` to rely on runtime assertions, ensuring that the initialization function is called only once and other APIs of the utility are called after the utility was initialized.
412+
This is done to align the utility with other application utilities.
411413

412414
nRF Machine Learning (Edge Impulse)
413415
-----------------------------------

0 commit comments

Comments
 (0)