bleio: A bit of cleanup

This commit is contained in:
arturo182 2018-07-23 23:45:16 +02:00
parent cf79316002
commit c7b42d80b3
5 changed files with 17 additions and 18 deletions

View File

@ -25,8 +25,8 @@
* THE SOFTWARE.
*/
#ifndef BLUETOOTH_LE_DRIVER_H__
#define BLUETOOTH_LE_DRIVER_H__
#ifndef MICROPY_INCLUDED_NRF_BLUETOOTH_BLE_DRV_H
#define MICROPY_INCLUDED_NRF_BLUETOOTH_BLE_DRV_H
#include "ble.h"
@ -50,4 +50,4 @@ typedef void (*ble_drv_evt_handler_t)(ble_evt_t*, void*);
void ble_drv_add_event_handler(ble_drv_evt_handler_t func, void *param);
#endif // BLUETOOTH_LE_DRIVER_H__
#endif // MICROPY_INCLUDED_NRF_BLUETOOTH_BLE_DRV_H

View File

@ -36,7 +36,6 @@
static volatile bleio_characteristic_obj_t *m_read_characteristic;
static volatile uint8_t m_tx_in_progress;
static nrf_mutex_t *m_write_mutex;
//static volatile bool m_write_done;
STATIC void gatts_write(bleio_characteristic_obj_t *characteristic, mp_buffer_info_t *bufinfo) {
bleio_device_obj_t *device = characteristic->service->device;
@ -101,23 +100,19 @@ STATIC void gattc_read(bleio_characteristic_obj_t *characteristic) {
STATIC void gattc_write(bleio_characteristic_obj_t *characteristic, mp_buffer_info_t *bufinfo) {
bleio_device_obj_t *device = characteristic->service->device;
uint16_t conn_handle = device->conn_handle;
uint32_t err_code;
ble_gattc_write_params_t write_params;
write_params.write_op = BLE_GATT_OP_WRITE_REQ;
ble_gattc_write_params_t write_params = {
.flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL,
.write_op = BLE_GATT_OP_WRITE_REQ,
.handle = characteristic->handle,
.p_value = bufinfo->buf,
.len = bufinfo->len,
};
if (characteristic->props.write_wo_resp) {
write_params.write_op = BLE_GATT_OP_WRITE_CMD;
}
write_params.flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL;
write_params.handle = characteristic->handle;
write_params.offset = 0;
write_params.len = bufinfo->len;
write_params.p_value = bufinfo->buf;
if (write_params.write_op == BLE_GATT_OP_WRITE_CMD) {
err_code = sd_mutex_acquire(m_write_mutex);
if (err_code != NRF_SUCCESS) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
@ -125,8 +120,8 @@ STATIC void gattc_write(bleio_characteristic_obj_t *characteristic, mp_buffer_in
}
}
err_code = sd_ble_gattc_write(conn_handle, &write_params);
if (err_code != 0) {
err_code = sd_ble_gattc_write(device->conn_handle, &write_params);
if (err_code != NRF_SUCCESS) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Failed to write attribute value, status: 0x%08lX", err_code));
}

View File

@ -297,7 +297,7 @@ STATIC bool discover_characteristics(bleio_device_obj_t *device, bleio_service_o
m_discovery_successful = false;
uint32_t err_code = sd_ble_gattc_characteristics_discover(device->conn_handle, &handle_range);
if (err_code != 0) {
if (err_code != NRF_SUCCESS) {
return false;
}

View File

@ -144,6 +144,8 @@
//| Disconnects from the remote device.
//| This method can only be called for Peripheral devices.
//|
// TODO: Add unique MAC address part to name
static const char default_name[] = "CIRCUITPY";
STATIC void bleio_device_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {

View File

@ -115,6 +115,8 @@ STATIC mp_obj_t bleio_service_add_characteristic(mp_obj_t self_in, mp_obj_t char
characteristic->service_handle = self->handle;
// TODO: If service is 128b then update Chara UUID to be 128b too
common_hal_bleio_service_add_characteristic(self, characteristic);
mp_obj_list_append(self->char_list, characteristic);