Skip to content

Commit 382f718

Browse files
committed
nrf5/sdk: Updating BLE UART implementation by swapping TX and RX uuid and characterisitic handling. Removed dummy write delay of 10 ms.
1 parent b032d76 commit 382f718

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

nrf5/sdk/ble_uart.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ static ubluepy_uuid_obj_t uuid_obj_service = {
4040
static ubluepy_uuid_obj_t uuid_obj_char_tx = {
4141
.base.type = &ubluepy_uuid_type,
4242
.type = UBLUEPY_UUID_128_BIT,
43-
.value = {0x02, 0x00}
43+
.value = {0x03, 0x00}
4444
};
4545

4646
static ubluepy_uuid_obj_t uuid_obj_char_rx = {
4747
.base.type = &ubluepy_uuid_type,
4848
.type = UBLUEPY_UUID_128_BIT,
49-
.value = {0x03, 0x00}
49+
.value = {0x02, 0x00}
5050
};
5151

5252
static ubluepy_service_obj_t ble_uart_service = {
@@ -55,16 +55,16 @@ static ubluepy_service_obj_t ble_uart_service = {
5555
.type = UBLUEPY_SERVICE_PRIMARY
5656
};
5757

58-
static ubluepy_characteristic_obj_t ble_uart_char_tx = {
58+
static ubluepy_characteristic_obj_t ble_uart_char_rx = {
5959
.base.type = &ubluepy_characteristic_type,
60-
.p_uuid = &uuid_obj_char_tx,
60+
.p_uuid = &uuid_obj_char_rx,
6161
.props = UBLUEPY_PROP_WRITE | UBLUEPY_PROP_WRITE_WO_RESP,
6262
.attrs = 0,
6363
};
6464

65-
static ubluepy_characteristic_obj_t ble_uart_char_rx = {
65+
static ubluepy_characteristic_obj_t ble_uart_char_tx = {
6666
.base.type = &ubluepy_characteristic_type,
67-
.p_uuid = &uuid_obj_char_rx,
67+
.p_uuid = &uuid_obj_char_tx,
6868
.props = UBLUEPY_PROP_NOTIFY,
6969
.attrs = UBLUEPY_ATTR_CCCD,
7070
};
@@ -104,7 +104,7 @@ void mp_hal_stdout_tx_strn(const char *str, size_t len) {
104104
send_len = len;
105105
}
106106

107-
ubluepy_characteristic_obj_t * p_char = &ble_uart_char_rx;
107+
ubluepy_characteristic_obj_t * p_char = &ble_uart_char_tx;
108108

109109
ble_drv_attr_notify(p_char->p_service->p_periph->conn_handle,
110110
p_char->handle,
@@ -119,8 +119,6 @@ void mp_hal_stdout_tx_strn(const char *str, size_t len) {
119119
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
120120
for (uint8_t i = 0; i < len; i++) {
121121
mp_hal_stdout_tx_strn(&str[i], 1);
122-
// for now put in a small delay as it could look like packets are issued to fast.
123-
mp_hal_delay_ms(10);
124122
}
125123
}
126124

@@ -139,9 +137,9 @@ STATIC void gatts_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t at
139137
(void)self;
140138

141139
if (event_id == 80) { // gatts write
142-
if (ble_uart_char_rx.cccd_handle == attr_handle) {
140+
if (ble_uart_char_tx.cccd_handle == attr_handle) {
143141
cccd_enabled = true;
144-
} else if (ble_uart_char_tx.handle == attr_handle) {
142+
} else if (ble_uart_char_rx.handle == attr_handle) {
145143
for (uint16_t i = 0; i < length; i++) {
146144
bufferWrite(mp_rx_ring_buffer, data[i]);
147145
}

0 commit comments

Comments
 (0)