3030#include "ble_drv.h"
3131#include "ble_gatts.h"
3232#include "nrf_soc.h"
33- #include "py/nlr .h"
33+ #include "py/runtime .h"
3434#include "shared-module/bleio/Characteristic.h"
3535
3636static volatile bleio_characteristic_obj_t * m_read_characteristic ;
@@ -48,8 +48,7 @@ STATIC void gatts_write(bleio_characteristic_obj_t *characteristic, mp_buffer_in
4848
4949 const uint32_t err_code = sd_ble_gatts_value_set (conn_handle , characteristic -> handle , & gatts_value );
5050 if (err_code != NRF_SUCCESS ) {
51- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_OSError ,
52- translate ("Failed to write gatts value, status: 0x%08lX" ), err_code ));
51+ mp_raise_OSError_msg (translate ("Failed to write gatts value" ));
5352 }
5453}
5554
@@ -72,8 +71,7 @@ STATIC void gatts_notify(bleio_characteristic_obj_t *characteristic, mp_buffer_i
7271
7372 const uint32_t err_code = sd_ble_gatts_hvx (device -> conn_handle , & hvx_params );
7473 if (err_code != NRF_SUCCESS ) {
75- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_OSError ,
76- translate ("Failed to notify attribute value, status: 0x%08lX" ), err_code ));
74+ mp_raise_OSError_msg (translate ("Failed to notify attribute value" ));
7775 }
7876
7977 m_tx_in_progress += 1 ;
@@ -87,8 +85,7 @@ STATIC void gattc_read(bleio_characteristic_obj_t *characteristic) {
8785
8886 const uint32_t err_code = sd_ble_gattc_read (device -> conn_handle , characteristic -> handle , 0 );
8987 if (err_code != NRF_SUCCESS ) {
90- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_OSError ,
91- translate ("Failed to read attribute value, status: 0x%08lX" ), err_code ));
88+ mp_raise_OSError_msg (translate ("Failed to read attribute value" ));
9289 }
9390
9491 while (m_read_characteristic != NULL ) {
@@ -115,15 +112,13 @@ STATIC void gattc_write(bleio_characteristic_obj_t *characteristic, mp_buffer_in
115112
116113 err_code = sd_mutex_acquire (m_write_mutex );
117114 if (err_code != NRF_SUCCESS ) {
118- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_OSError ,
119- translate ("Failed to acquire mutex, status: 0x%08lX" ), err_code ));
115+ mp_raise_OSError_msg (translate ("Failed to acquire mutex" ));
120116 }
121117 }
122118
123119 err_code = sd_ble_gattc_write (device -> conn_handle , & write_params );
124120 if (err_code != NRF_SUCCESS ) {
125- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_OSError ,
126- translate ("Failed to write attribute value, status: 0x%08lX" ), err_code ));
121+ mp_raise_OSError_msg (translate ("Failed to write attribute value" ));
127122 }
128123
129124 while (sd_mutex_acquire (m_write_mutex ) == NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN ) {
@@ -134,8 +129,7 @@ STATIC void gattc_write(bleio_characteristic_obj_t *characteristic, mp_buffer_in
134129
135130 err_code = sd_mutex_release (m_write_mutex );
136131 if (err_code != NRF_SUCCESS ) {
137- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_OSError ,
138- translate ("Failed to release mutex, status: 0x%08lX" ), err_code ));
132+ mp_raise_OSError_msg (translate ("Failed to release mutex" ));
139133 }
140134}
141135
0 commit comments