Skip to content

Commit c7b42d8

Browse files
committed
bleio: A bit of cleanup
1 parent cf79316 commit c7b42d8

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

ports/nrf/bluetooth/ble_drv.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
* THE SOFTWARE.
2626
*/
2727

28-
#ifndef BLUETOOTH_LE_DRIVER_H__
29-
#define BLUETOOTH_LE_DRIVER_H__
28+
#ifndef MICROPY_INCLUDED_NRF_BLUETOOTH_BLE_DRV_H
29+
#define MICROPY_INCLUDED_NRF_BLUETOOTH_BLE_DRV_H
3030

3131
#include "ble.h"
3232

@@ -50,4 +50,4 @@ typedef void (*ble_drv_evt_handler_t)(ble_evt_t*, void*);
5050

5151
void ble_drv_add_event_handler(ble_drv_evt_handler_t func, void *param);
5252

53-
#endif // BLUETOOTH_LE_DRIVER_H__
53+
#endif // MICROPY_INCLUDED_NRF_BLUETOOTH_BLE_DRV_H

ports/nrf/common-hal/bleio/Characteristic.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
static volatile bleio_characteristic_obj_t *m_read_characteristic;
3737
static volatile uint8_t m_tx_in_progress;
3838
static nrf_mutex_t *m_write_mutex;
39-
//static volatile bool m_write_done;
4039

4140
STATIC void gatts_write(bleio_characteristic_obj_t *characteristic, mp_buffer_info_t *bufinfo) {
4241
bleio_device_obj_t *device = characteristic->service->device;
@@ -101,32 +100,28 @@ STATIC void gattc_read(bleio_characteristic_obj_t *characteristic) {
101100

102101
STATIC void gattc_write(bleio_characteristic_obj_t *characteristic, mp_buffer_info_t *bufinfo) {
103102
bleio_device_obj_t *device = characteristic->service->device;
104-
uint16_t conn_handle = device->conn_handle;
105103
uint32_t err_code;
106104

107-
ble_gattc_write_params_t write_params;
108-
write_params.write_op = BLE_GATT_OP_WRITE_REQ;
105+
ble_gattc_write_params_t write_params = {
106+
.flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL,
107+
.write_op = BLE_GATT_OP_WRITE_REQ,
108+
.handle = characteristic->handle,
109+
.p_value = bufinfo->buf,
110+
.len = bufinfo->len,
111+
};
109112

110113
if (characteristic->props.write_wo_resp) {
111114
write_params.write_op = BLE_GATT_OP_WRITE_CMD;
112-
}
113-
114-
write_params.flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL;
115-
write_params.handle = characteristic->handle;
116-
write_params.offset = 0;
117-
write_params.len = bufinfo->len;
118-
write_params.p_value = bufinfo->buf;
119115

120-
if (write_params.write_op == BLE_GATT_OP_WRITE_CMD) {
121116
err_code = sd_mutex_acquire(m_write_mutex);
122117
if (err_code != NRF_SUCCESS) {
123118
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
124119
"Failed to acquire mutex, status: 0x%08lX", err_code));
125120
}
126121
}
127122

128-
err_code = sd_ble_gattc_write(conn_handle, &write_params);
129-
if (err_code != 0) {
123+
err_code = sd_ble_gattc_write(device->conn_handle, &write_params);
124+
if (err_code != NRF_SUCCESS) {
130125
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
131126
"Failed to write attribute value, status: 0x%08lX", err_code));
132127
}

ports/nrf/common-hal/bleio/Device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ STATIC bool discover_characteristics(bleio_device_obj_t *device, bleio_service_o
297297
m_discovery_successful = false;
298298

299299
uint32_t err_code = sd_ble_gattc_characteristics_discover(device->conn_handle, &handle_range);
300-
if (err_code != 0) {
300+
if (err_code != NRF_SUCCESS) {
301301
return false;
302302
}
303303

shared-bindings/bleio/Device.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@
144144
//| Disconnects from the remote device.
145145
//| This method can only be called for Peripheral devices.
146146
//|
147+
148+
// TODO: Add unique MAC address part to name
147149
static const char default_name[] = "CIRCUITPY";
148150

149151
STATIC void bleio_device_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {

shared-bindings/bleio/Service.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ STATIC mp_obj_t bleio_service_add_characteristic(mp_obj_t self_in, mp_obj_t char
115115

116116
characteristic->service_handle = self->handle;
117117

118+
// TODO: If service is 128b then update Chara UUID to be 128b too
119+
118120
common_hal_bleio_service_add_characteristic(self, characteristic);
119121

120122
mp_obj_list_append(self->char_list, characteristic);

0 commit comments

Comments
 (0)