@@ -177,14 +177,11 @@ void pbdrv_bluetooth_peripheral_release(pbdrv_bluetooth_peripheral_t *peripheral
177177 peripheral -> user = NULL ;
178178}
179179
180- const char * pbdrv_bluetooth_peripheral_get_name (void ) {
181- pbdrv_bluetooth_peripheral_t * peri = & peripheral_singleton ;
180+ const char * pbdrv_bluetooth_peripheral_get_name (pbdrv_bluetooth_peripheral_t * peri ) {
182181 return peri -> name ;
183182}
184183
185- pbio_error_t pbdrv_bluetooth_peripheral_scan_and_connect (pbdrv_bluetooth_peripheral_connect_config_t * config ) {
186-
187- pbdrv_bluetooth_peripheral_t * peri = & peripheral_singleton ;
184+ pbio_error_t pbdrv_bluetooth_peripheral_scan_and_connect (pbdrv_bluetooth_peripheral_t * peri , pbdrv_bluetooth_peripheral_connect_config_t * config ) {
188185
189186 if (!pbdrv_bluetooth_is_connected (PBDRV_BLUETOOTH_CONNECTION_HCI )) {
190187 return PBIO_ERROR_INVALID_OP ;
@@ -214,9 +211,7 @@ pbio_error_t pbdrv_bluetooth_peripheral_scan_and_connect(pbdrv_bluetooth_periphe
214211 return PBIO_SUCCESS ;
215212}
216213
217- pbio_error_t pbdrv_bluetooth_peripheral_disconnect (void ) {
218-
219- pbdrv_bluetooth_peripheral_t * peri = & peripheral_singleton ;
214+ pbio_error_t pbdrv_bluetooth_peripheral_disconnect (pbdrv_bluetooth_peripheral_t * peri ) {
220215
221216 // Busy doing something else.
222217 if (peri -> func ) {
@@ -236,9 +231,7 @@ pbio_error_t pbdrv_bluetooth_peripheral_disconnect(void) {
236231 return PBIO_SUCCESS ;
237232}
238233
239- pbio_error_t pbdrv_bluetooth_peripheral_discover_characteristic (pbdrv_bluetooth_peripheral_char_t * characteristic ) {
240-
241- pbdrv_bluetooth_peripheral_t * peri = & peripheral_singleton ;
234+ pbio_error_t pbdrv_bluetooth_peripheral_discover_characteristic (pbdrv_bluetooth_peripheral_t * peri , pbdrv_bluetooth_peripheral_char_t * characteristic ) {
242235
243236 if (!pbdrv_bluetooth_is_connected (PBDRV_BLUETOOTH_CONNECTION_PERIPHERAL )) {
244237 return PBIO_ERROR_NO_DEV ;
@@ -249,16 +242,14 @@ pbio_error_t pbdrv_bluetooth_peripheral_discover_characteristic(pbdrv_bluetooth_
249242
250243 // Initialize operation for handling on the main thread.
251244 characteristic -> handle = 0 ;
252- peripheral_singleton . char_now = characteristic ;
245+ peri -> char_now = characteristic ;
253246 peri -> func = pbdrv_bluetooth_peripheral_discover_characteristic_func ;
254247 peri -> err = PBIO_ERROR_AGAIN ;
255248 pbio_os_request_poll ();
256249 return PBIO_SUCCESS ;
257250}
258251
259- pbio_error_t pbdrv_bluetooth_peripheral_read_characteristic (pbdrv_bluetooth_peripheral_char_t * characteristic ) {
260-
261- pbdrv_bluetooth_peripheral_t * peri = & peripheral_singleton ;
252+ pbio_error_t pbdrv_bluetooth_peripheral_read_characteristic (pbdrv_bluetooth_peripheral_t * peri , pbdrv_bluetooth_peripheral_char_t * characteristic ) {
262253
263254 if (!pbdrv_bluetooth_is_connected (PBDRV_BLUETOOTH_CONNECTION_PERIPHERAL )) {
264255 return PBIO_ERROR_NO_DEV ;
@@ -268,7 +259,7 @@ pbio_error_t pbdrv_bluetooth_peripheral_read_characteristic(pbdrv_bluetooth_peri
268259 }
269260
270261 // Initialize operation for handling on the main thread.
271- peripheral_singleton . char_now = characteristic ;
262+ peri -> char_now = characteristic ;
272263 peri -> func = pbdrv_bluetooth_peripheral_read_characteristic_func ;
273264 peri -> err = PBIO_ERROR_AGAIN ;
274265 pbio_os_request_poll ();
@@ -279,9 +270,7 @@ uint16_t pbdrv_bluetooth_char_write_handle;
279270uint8_t pbdrv_bluetooth_char_write_data [PBDRV_BLUETOOTH_MAX_CHAR_SIZE ];
280271size_t pbdrv_bluetooth_char_write_size ;
281272
282- pbio_error_t pbdrv_bluetooth_peripheral_write_characteristic (uint16_t handle , const uint8_t * data , size_t size ) {
283-
284- pbdrv_bluetooth_peripheral_t * peri = & peripheral_singleton ;
273+ pbio_error_t pbdrv_bluetooth_peripheral_write_characteristic (pbdrv_bluetooth_peripheral_t * peri , uint16_t handle , const uint8_t * data , size_t size ) {
285274
286275 if (!pbdrv_bluetooth_is_connected (PBDRV_BLUETOOTH_CONNECTION_PERIPHERAL )) {
287276 return PBIO_ERROR_NO_DEV ;
@@ -306,7 +295,7 @@ pbio_error_t pbdrv_bluetooth_peripheral_write_characteristic(uint16_t handle, co
306295
307296pbio_error_t pbdrv_bluetooth_await_peripheral_command (pbio_os_state_t * state , void * context ) {
308297
309- pbdrv_bluetooth_peripheral_t * peri = & peripheral_singleton ;
298+ pbdrv_bluetooth_peripheral_t * peri = context ;
310299
311300 // If the user is no longer calling this then the operation is no longer
312301 // of interest and will be cancelled if the active function supports it.
@@ -626,12 +615,12 @@ pbio_error_t pbdrv_bluetooth_close_user_tasks(pbio_os_state_t *state, pbio_os_ti
626615 pbdrv_bluetooth_cancel_operation_request ();
627616
628617 // Let ongoing user tasks finish first.
629- PBIO_OS_AWAIT (state , & sub , pbdrv_bluetooth_await_peripheral_command (& sub , NULL ));
618+ PBIO_OS_AWAIT (state , & sub , pbdrv_bluetooth_await_peripheral_command (& sub , & peripheral_singleton ));
630619 PBIO_OS_AWAIT (state , & sub , pbdrv_bluetooth_await_advertise_or_scan_command (& sub , NULL ));
631620
632621 // Disconnect peripheral.
633- pbdrv_bluetooth_peripheral_disconnect ();
634- PBIO_OS_AWAIT (state , & sub , pbdrv_bluetooth_await_peripheral_command (& sub , NULL ));
622+ pbdrv_bluetooth_peripheral_disconnect (& peripheral_singleton );
623+ PBIO_OS_AWAIT (state , & sub , pbdrv_bluetooth_await_peripheral_command (& sub , & peripheral_singleton ));
635624
636625 // Stop scanning.
637626 pbdrv_bluetooth_start_observing (NULL );
0 commit comments