summaryrefslogtreecommitdiff
path: root/extmod/modbluetooth_nimble.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-11-29 12:48:38 +1100
committerDamien George <damien.p.george@gmail.com>2019-12-04 23:23:07 +1100
commit7aeafe2ae9f16af74d22604b3090641a664b2da2 (patch)
tree35b96bd1aa185aa8563cbdcb2c94e605c9d2c872 /extmod/modbluetooth_nimble.c
parent9a849cc7caee63560ecd2455a29615a44e2c809f (diff)
extmod/modbluetooth: Add optional 4th arg to gattc_write for write mode.
This allows the user to explicitly select the behaviour of the write to the remote peripheral. This is needed for peripherals that have characteristics with WRITE_NO_RESPONSE set (instead of normal WRITE). The function's signature is now: BLE.gattc_write(conn_handle, value_handle, data, mode=0) mode=0 means write without response, while mode=1 means write with response. The latter was the original behaviour so this commit is a change in behaviour of this method, and one should specify 1 as the 4th argument to get back the old behaviour. In the future there could be more modes supported, such as long writes.
Diffstat (limited to 'extmod/modbluetooth_nimble.c')
-rw-r--r--extmod/modbluetooth_nimble.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/extmod/modbluetooth_nimble.c b/extmod/modbluetooth_nimble.c
index 83eb4b88a..930dd06d1 100644
--- a/extmod/modbluetooth_nimble.c
+++ b/extmod/modbluetooth_nimble.c
@@ -816,8 +816,15 @@ STATIC int ble_gatt_attr_write_cb(uint16_t conn_handle, const struct ble_gatt_er
}
// Write the value to the remote peripheral.
-int mp_bluetooth_gattc_write(uint16_t conn_handle, uint16_t value_handle, const uint8_t *value, size_t *value_len) {
- int err = ble_gattc_write_flat(conn_handle, value_handle, value, *value_len, &ble_gatt_attr_write_cb, NULL);
+int mp_bluetooth_gattc_write(uint16_t conn_handle, uint16_t value_handle, const uint8_t *value, size_t *value_len, unsigned int mode) {
+ int err;
+ if (mode == MP_BLUETOOTH_WRITE_MODE_NO_RESPONSE) {
+ err = ble_gattc_write_no_rsp_flat(conn_handle, value_handle, value, *value_len);
+ } else if (mode == MP_BLUETOOTH_WRITE_MODE_WITH_RESPONSE) {
+ err = ble_gattc_write_flat(conn_handle, value_handle, value, *value_len, &ble_gatt_attr_write_cb, NULL);
+ } else {
+ err = BLE_HS_EINVAL;
+ }
return ble_hs_err_to_errno(err);
}