Skip to content

Commit df6a459

Browse files
committed
remove requestPHY() from 1MB to 2MB, old Mac may not support 2MB. Leave it to central to switch
also add hci str debug
1 parent d244596 commit df6a459

File tree

5 files changed

+50
-84
lines changed

5 files changed

+50
-84
lines changed

cores/nRF5/utility/debug.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,53 @@ const char* dbg_err_str(int32_t err_id)
438438
return str;
439439
}
440440

441+
//--------------------------------------------------------------------+
442+
// HCI STATUS
443+
//--------------------------------------------------------------------+
444+
static lookup_entry_t const _strhci_lookup[] =
445+
{
446+
{ .key = BLE_HCI_STATUS_CODE_SUCCESS , .data = "STATUS_CODE_SUCCESS" },
447+
{ .key = BLE_HCI_STATUS_CODE_UNKNOWN_BTLE_COMMAND , .data = "STATUS_CODE_UNKNOWN_BTLE_COMMAND " },
448+
{ .key = BLE_HCI_STATUS_CODE_UNKNOWN_CONNECTION_IDENTIFIER , .data = "STATUS_CODE_UNKNOWN_CONNECTION_IDENTIFIER" },
449+
{ .key = BLE_HCI_AUTHENTICATION_FAILURE , .data = "AUTHENTICATION_FAILURE " },
450+
{ .key = BLE_HCI_STATUS_CODE_PIN_OR_KEY_MISSING , .data = "STATUS_CODE_PIN_OR_KEY_MISSING " },
451+
{ .key = BLE_HCI_MEMORY_CAPACITY_EXCEEDED , .data = "MEMORY_CAPACITY_EXCEEDED " },
452+
{ .key = BLE_HCI_CONNECTION_TIMEOUT , .data = "CONNECTION_TIMEOUT " },
453+
{ .key = BLE_HCI_STATUS_CODE_COMMAND_DISALLOWED , .data = "STATUS_CODE_COMMAND_DISALLOWED " },
454+
{ .key = BLE_HCI_STATUS_CODE_INVALID_BTLE_COMMAND_PARAMETERS , .data = "STATUS_CODE_INVALID_BTLE_COMMAND_PARAMETERS" },
455+
{ .key = BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION , .data = "REMOTE_USER_TERMINATED_CONNECTION" },
456+
{ .key = BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES , .data = "REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES" },
457+
{ .key = BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF , .data = "REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF" },
458+
{ .key = BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION , .data = "LOCAL_HOST_TERMINATED_CONNECTION " },
459+
{ .key = BLE_HCI_UNSUPPORTED_REMOTE_FEATURE , .data = "UNSUPPORTED_REMOTE_FEATURE" },
460+
{ .key = BLE_HCI_STATUS_CODE_INVALID_LMP_PARAMETERS , .data = "STATUS_CODE_INVALID_LMP_PARAMETERS " },
461+
{ .key = BLE_HCI_STATUS_CODE_UNSPECIFIED_ERROR , .data = "STATUS_CODE_UNSPECIFIED_ERROR" },
462+
{ .key = BLE_HCI_STATUS_CODE_LMP_RESPONSE_TIMEOUT , .data = "STATUS_CODE_LMP_RESPONSE_TIMEOUT " },
463+
{ .key = BLE_HCI_STATUS_CODE_LMP_ERROR_TRANSACTION_COLLISION , .data = "STATUS_CODE_LMP_ERROR_TRANSACTION_COLLISION" },
464+
{ .key = BLE_HCI_STATUS_CODE_LMP_PDU_NOT_ALLOWED , .data = "STATUS_CODE_LMP_PDU_NOT_ALLOWED" },
465+
{ .key = BLE_HCI_INSTANT_PASSED , .data = "INSTANT_PASSED " },
466+
{ .key = BLE_HCI_PAIRING_WITH_UNIT_KEY_UNSUPPORTED , .data = "PAIRING_WITH_UNIT_KEY_UNSUPPORTED" },
467+
{ .key = BLE_HCI_DIFFERENT_TRANSACTION_COLLISION , .data = "DIFFERENT_TRANSACTION_COLLISION" },
468+
{ .key = BLE_HCI_PARAMETER_OUT_OF_MANDATORY_RANGE , .data = "PARAMETER_OUT_OF_MANDATORY_RANGE " },
469+
{ .key = BLE_HCI_CONTROLLER_BUSY , .data = "CONTROLLER_BUSY" },
470+
{ .key = BLE_HCI_CONN_INTERVAL_UNACCEPTABLE , .data = "CONN_INTERVAL_UNACCEPTABLE " },
471+
{ .key = BLE_HCI_DIRECTED_ADVERTISER_TIMEOUT , .data = "DIRECTED_ADVERTISER_TIMEOUT" },
472+
{ .key = BLE_HCI_CONN_TERMINATED_DUE_TO_MIC_FAILURE , .data = "CONN_TERMINATED_DUE_TO_MIC_FAILURE " },
473+
{ .key = BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED , .data = "CONN_FAILED_TO_BE_ESTABLISHED" }
474+
};
475+
476+
lookup_table_t const _strhci_table =
477+
{
478+
.count = arrcount(_strhci_lookup),
479+
.items = _strhci_lookup
480+
};
481+
482+
483+
const char* dbg_hci_str(uint8_t id)
484+
{
485+
return (const char *) lookup_find(&_strhci_table, id);
486+
}
487+
441488
#endif
442489

443490
}

cores/nRF5/utility/debug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#if CFG_DEBUG
4747
const char* dbg_ble_event_str(uint16_t evt_id);
4848
const char* dbg_err_str(int32_t err_id);
49+
const char* dbg_hci_str(uint8_t id);
4950
#endif
5051

5152
int dbgHeapTotal(void);

libraries/Bluefruit52Lib/examples/Peripheral/image_eink_upload/image_eink_upload.ino

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ uint32_t totalPixel = 0; // received pixel
6161
// pixel line buffer, should be large enough to hold an image width
6262
uint16_t pixel_buf[512];
6363

64-
// Use software timer to schedule bandwidth negotiation a few seconds after connection
65-
SoftwareTimer negoTimer;
66-
6764
// Statistics for speed testing
6865
uint32_t rxStartTime = 0;
6966
uint32_t rxLastTime = 0;
@@ -112,9 +109,6 @@ void setup()
112109

113110
bleuart.setRxOverflowCallback(bleuart_overflow_callback);
114111

115-
// one-shot (non-repeating) 2 seconds timer
116-
negoTimer.begin(2000, negotiate_bandwidth, NULL, false);
117-
118112
// Set up and start advertising
119113
startAdv();
120114

@@ -260,43 +254,8 @@ void bleuart_rx_callback(uint16_t conn_hdl)
260254
}
261255
}
262256

263-
void negotiate_bandwidth(TimerHandle_t xTimer)
264-
{
265-
(void) xTimer;
266-
267-
uint16_t conn_hdl = (uint16_t) ((uint32_t) negoTimer.getID());
268-
BLEConnection* conn = Bluefruit.Connection(conn_hdl);
269-
270-
// Switching from 1 Mb to 2 Mb PHY if needed
271-
if ( conn->connected() )
272-
{
273-
// Requesting to Switching to 2MB PHY, larger data length and bigger MTU
274-
// will increase the throughput on supported central. This should already
275-
// be done with latest Bluefruit app.
276-
//
277-
// However, some Android devices require 2Mb PHY switching must be initiated
278-
// from nRF side
279-
if ( conn->getPHY() == BLE_GAP_PHY_1MBPS )
280-
{
281-
Serial.println("Requesting PHY change from 1 Mb to 2Mb");
282-
conn->requestPHY();
283-
284-
// Data Length and MTU should already be done by Bluefruit app
285-
// conn->requestDataLengthUpdate();
286-
// conn->requestMtuExchange(247);
287-
}
288-
}
289-
}
290-
291257
void connect_callback(uint16_t conn_handle)
292258
{
293-
// Set connection handle as timer ID
294-
// Then schedule negotiation after a few seconds, we should not
295-
// negotiate here since it increases chance to conflict with other
296-
// on-going negotiation from central after connection
297-
negoTimer.setID((void*) conn_handle);
298-
negoTimer.start();
299-
300259
Serial.println("Connected");
301260
Serial.println("Ready to receive new image");
302261
}

libraries/Bluefruit52Lib/examples/Peripheral/image_upload/image_upload.ino

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#define TFT_24_FEATHERWING 2
4242

4343
// [Configurable] For other boards please select which external display to match your hardware setup
44-
#define TFT_IN_USE TFT_35_FEATHERWING
44+
#define TFT_IN_USE TFT_24_FEATHERWING
4545

4646
#if defined(ARDUINO_NRF52832_FEATHER)
4747
// Feather nRF52832 pin map is different from others
@@ -97,9 +97,6 @@ uint32_t totalPixel = 0; // received pixel
9797
// pixel line buffer, should be large enough to hold an image width
9898
uint16_t pixel_buf[512];
9999

100-
// Use software timer to schedule bandwidth negotiation a few seconds after connection
101-
SoftwareTimer negoTimer;
102-
103100
// Statistics for speed testing
104101
uint32_t rxStartTime = 0;
105102
uint32_t rxLastTime = 0;
@@ -173,9 +170,6 @@ void setup()
173170

174171
bleuart.setRxOverflowCallback(bleuart_overflow_callback);
175172

176-
// one-shot (non-repeating) 2 seconds timer
177-
negoTimer.begin(2000, negotiate_bandwidth, NULL, false);
178-
179173
// Set up and start advertising
180174
startAdv();
181175

@@ -296,43 +290,8 @@ void bleuart_rx_callback(uint16_t conn_hdl)
296290
}
297291
}
298292

299-
void negotiate_bandwidth(TimerHandle_t xTimer)
300-
{
301-
(void) xTimer;
302-
303-
uint16_t conn_hdl = (uint16_t) ((uint32_t) negoTimer.getID());
304-
BLEConnection* conn = Bluefruit.Connection(conn_hdl);
305-
306-
// Switching from 1 Mb to 2 Mb PHY if needed
307-
if ( conn->connected() )
308-
{
309-
// Requesting to Switching to 2MB PHY, larger data length and bigger MTU
310-
// will increase the throughput on supported central. This should already
311-
// be done with latest Bluefruit app.
312-
//
313-
// However, some Android devices require 2Mb PHY switching must be initiated
314-
// from nRF side
315-
if ( conn->getPHY() == BLE_GAP_PHY_1MBPS )
316-
{
317-
Serial.println("Requesting PHY change from 1 Mb to 2Mb");
318-
conn->requestPHY();
319-
320-
// Data Length and MTU should already be done by Bluefruit app
321-
// conn->requestDataLengthUpdate();
322-
// conn->requestMtuExchange(247);
323-
}
324-
}
325-
}
326-
327293
void connect_callback(uint16_t conn_handle)
328294
{
329-
// Set connection handle as timer ID
330-
// Then schedule negotiation after a few seconds, we should not
331-
// negotiate here since it increases chance to conflict with other
332-
// on-going negotiation from central after connection
333-
negoTimer.setID((void*) ((uint32_t)conn_handle));
334-
negoTimer.start();
335-
336295
tft.println("Connected");
337296
tft.setTextColor(COLOR_GREEN);
338297
tft.println("Ready to receive new image");

libraries/Bluefruit52Lib/src/bluefruit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
823823
{
824824
ble_gap_evt_disconnected_t const* para = &evt->evt.gap_evt.params.disconnected;
825825

826-
LOG_LV2("GAP", "Disconnect Reason 0x%02X", evt->evt.gap_evt.params.disconnected.reason);
826+
LOG_LV2("GAP", "Disconnect Reason: %s", dbg_hci_str(evt->evt.gap_evt.params.disconnected.reason));
827827

828828
// Turn off Conn LED If not connected at all
829829
if ( !this->connected() ) _setConnLed(false);

0 commit comments

Comments
 (0)