Skip to content

Commit 965ce66

Browse files
bluetooth: services: ble_lbs: change error codes to nrf_error
Change error codes to nrf_errors. Signed-off-by: Eivind Jølsgard <eivind.jolsgard@nordicsemi.no>
1 parent 23fcc52 commit 965ce66

4 files changed

Lines changed: 39 additions & 33 deletions

File tree

doc/nrf-bm/release_notes/release_notes_changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Libraries
7878
* :ref:`lib_ble_service_bas` service.
7979
* :ref:`lib_ble_service_dis` service.
8080
* :ref:`lib_ble_service_hrs` service.
81+
* :ref:`lib_ble_service_lbs` service.
8182

8283
* :ref:`lib_ble_conn_params` library:
8384

include/bm/bluetooth/services/ble_lbs.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ struct ble_lbs {
9494
* be used to identify this particular service instance.
9595
* @param[in] cfg Information needed to initialize the service.
9696
*
97-
* @retval 0 If the service was initialized successfully. Otherwise, an error code is returned.
97+
* @retval NRF_SUCCESS If the service was initialized successfully.
98+
* @retval NRF_ERROR_NULL If @p lbs or @p cfg is NULL.
99+
* @retval NRF_ERROR_INVALID_PARAM If the supplied configuration is invalid.
98100
*/
99-
int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg);
101+
uint32_t ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg);
100102

101103
/**
102104
* @brief Function for handling the application's BLE stack events.
@@ -117,9 +119,11 @@ void ble_lbs_on_ble_evt(const ble_evt_t *ble_evt, void *lbs_instance);
117119
* @param[in] lbs LED Button Service structure.
118120
* @param[in] button_state New button state.
119121
*
120-
* @retval 0 If the notification was sent successfully. Otherwise, an error code is returned.
122+
* @retval NRF_SUCCESS If the notification was sent successfully.
123+
* @retval NRF_ERROR_NULL If @p lbs is NULL.
124+
* @retval NRF_ERROR_INVALID_PARAM If the parameters are invalid.
121125
*/
122-
int ble_lbs_on_button_change(struct ble_lbs *lbs, uint16_t conn_handle, uint8_t button_state);
126+
uint32_t ble_lbs_on_button_change(struct ble_lbs *lbs, uint16_t conn_handle, uint8_t button_state);
123127

124128
#ifdef __cplusplus
125129
}

samples/bluetooth/ble_lbs/src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ int main(void)
180180
goto idle;
181181
}
182182

183-
err = ble_lbs_init(&ble_lbs, &lbs_cfg);
184-
if (err) {
185-
LOG_ERR("Failed to setup LED Button Service, err %d", err);
183+
nrf_err = ble_lbs_init(&ble_lbs, &lbs_cfg);
184+
if (nrf_err) {
185+
LOG_ERR("Failed to setup LED Button Service, nrf_error %#x", nrf_err);
186186
goto idle;
187187
}
188188

subsys/bluetooth/services/ble_lbs/lbs.c

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
*/
66

7+
#include <nrf_error.h>
78
#include <zephyr/sys/__assert.h>
89
#include <zephyr/logging/log.h>
910
#include <bm/bluetooth/services/ble_lbs.h>
@@ -52,23 +53,23 @@ void ble_lbs_on_ble_evt(const ble_evt_t *ble_evt, void *lbs_instance)
5253

5354
int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg)
5455
{
55-
int err;
56+
uint32_t nrf_err;
5657
ble_uuid_t ble_uuid;
5758
uint8_t initial_value = 0;
5859

5960
if (!lbs || !cfg) {
60-
return -EFAULT;
61+
return NRF_ERROR_NULL;
6162
}
6263

6364
/* Initialize service structure. */
6465
lbs->evt_handler = cfg->evt_handler;
6566

6667
ble_uuid128_t base_uuid = { .uuid128 = BLE_UUID_LBS_BASE };
6768

68-
err = sd_ble_uuid_vs_add(&base_uuid, &lbs->uuid_type);
69-
if (err != NRF_SUCCESS) {
70-
LOG_ERR("Failed to add vendor UUID, nrf_error %#x", err);
71-
return -EINVAL;
69+
nrf_err = sd_ble_uuid_vs_add(&base_uuid, &lbs->uuid_type);
70+
if (nrf_err) {
71+
LOG_ERR("Failed to add vendor UUID, nrf_error %#x", nrf_err);
72+
return NRF_ERROR_INVALID_PARAM;
7273
}
7374

7475
ble_uuid = (ble_uuid_t) {
@@ -77,11 +78,11 @@ int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg)
7778
};
7879

7980
/* Add service. */
80-
err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid,
81+
nrf_err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid,
8182
&lbs->service_handle);
82-
if (err != NRF_SUCCESS) {
83-
LOG_ERR("Failed to add GATT service, nrf_error %#x", err);
84-
return -EINVAL;
83+
if (nrf_err != NRF_SUCCESS) {
84+
LOG_ERR("Failed to add GATT service, nrf_error %#x", nrf_err);
85+
return NRF_ERROR_INVALID_PARAM;
8586
}
8687

8788
/* Add Button characteristic. */
@@ -113,11 +114,11 @@ int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg)
113114
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
114115
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
115116

116-
err = sd_ble_gatts_characteristic_add(lbs->service_handle, &char_md, &attr_char_value,
117+
nrf_err = sd_ble_gatts_characteristic_add(lbs->service_handle, &char_md, &attr_char_value,
117118
&lbs->button_char_handles);
118-
if (err) {
119-
LOG_ERR("Failed to add button GATT characteristic, nrf_error %#x", err);
120-
return -EINVAL;
119+
if (nrf_err) {
120+
LOG_ERR("Failed to add button GATT characteristic, nrf_error %#x", nrf_err);
121+
return NRF_ERROR_INVALID_PARAM;
121122
}
122123

123124
/* Add LED characteristic. */
@@ -145,24 +146,24 @@ int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg)
145146
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
146147
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
147148

148-
err = sd_ble_gatts_characteristic_add(lbs->service_handle, &char_md, &attr_char_value,
149+
nrf_err = sd_ble_gatts_characteristic_add(lbs->service_handle, &char_md, &attr_char_value,
149150
&lbs->led_char_handles);
150-
if (err) {
151-
LOG_ERR("Failed to add LED GATT characteristic, nrf_error %#x", err);
152-
return -EINVAL;
151+
if (nrf_err) {
152+
LOG_ERR("Failed to add LED GATT characteristic, nrf_error %#x", nrf_err);
153+
return NRF_ERROR_INVALID_PARAM;
153154
}
154155

155-
return 0;
156+
return NRF_SUCCESS;
156157
}
157158

158159
int ble_lbs_on_button_change(struct ble_lbs *lbs, uint16_t conn_handle, uint8_t button_state)
159160
{
160-
int err;
161+
uint32_t nrf_err;
161162

162163
uint16_t len = sizeof(button_state);
163164

164165
if (!lbs) {
165-
return -EFAULT;
166+
return NRF_ERROR_NULL;
166167
}
167168

168169
ble_gatts_hvx_params_t hvx = {
@@ -172,11 +173,11 @@ int ble_lbs_on_button_change(struct ble_lbs *lbs, uint16_t conn_handle, uint8_t
172173
.p_len = &len,
173174
};
174175

175-
err = sd_ble_gatts_hvx(conn_handle, &hvx);
176-
if (err) {
177-
LOG_ERR("Failed to notify button change, nrf_error %#x", err);
178-
return -EINVAL;
176+
nrf_err = sd_ble_gatts_hvx(conn_handle, &hvx);
177+
if (nrf_err) {
178+
LOG_ERR("Failed to notify button change, nrf_error %#x", nrf_err);
179+
return NRF_ERROR_INVALID_PARAM;
179180
}
180181

181-
return 0;
182+
return NRF_SUCCESS;
182183
}

0 commit comments

Comments
 (0)