mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-14 14:52:32 +00:00
Merge branch 'develop' into ble-Banner
This commit is contained in:
@@ -630,8 +630,8 @@ class NimbleBluetoothServerCallback : public NimBLEServerCallbacks
|
|||||||
{
|
{
|
||||||
LOG_INFO("BLE incoming connection %s", connInfo.getAddress().toString().c_str());
|
LOG_INFO("BLE incoming connection %s", connInfo.getAddress().toString().c_str());
|
||||||
|
|
||||||
#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C6)
|
|
||||||
const uint16_t connHandle = connInfo.getConnHandle();
|
const uint16_t connHandle = connInfo.getConnHandle();
|
||||||
|
#if NIMBLE_ENABLE_2M_PHY && (defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C6))
|
||||||
int phyResult =
|
int phyResult =
|
||||||
ble_gap_set_prefered_le_phy(connHandle, BLE_GAP_LE_PHY_2M_MASK, BLE_GAP_LE_PHY_2M_MASK, BLE_GAP_LE_PHY_CODED_ANY);
|
ble_gap_set_prefered_le_phy(connHandle, BLE_GAP_LE_PHY_2M_MASK, BLE_GAP_LE_PHY_2M_MASK, BLE_GAP_LE_PHY_CODED_ANY);
|
||||||
if (phyResult == 0) {
|
if (phyResult == 0) {
|
||||||
@@ -639,6 +639,7 @@ class NimbleBluetoothServerCallback : public NimBLEServerCallbacks
|
|||||||
} else {
|
} else {
|
||||||
LOG_WARN("Failed to prefer 2M PHY for conn %u, rc=%d", connHandle, phyResult);
|
LOG_WARN("Failed to prefer 2M PHY for conn %u, rc=%d", connHandle, phyResult);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int dataLenResult = ble_gap_set_data_len(connHandle, kPreferredBleTxOctets, kPreferredBleTxTimeUs);
|
int dataLenResult = ble_gap_set_data_len(connHandle, kPreferredBleTxOctets, kPreferredBleTxTimeUs);
|
||||||
if (dataLenResult == 0) {
|
if (dataLenResult == 0) {
|
||||||
@@ -649,9 +650,10 @@ class NimbleBluetoothServerCallback : public NimBLEServerCallbacks
|
|||||||
|
|
||||||
LOG_INFO("BLE conn %u initial MTU %u (target %u)", connHandle, connInfo.getMTU(), kPreferredBleMtu);
|
LOG_INFO("BLE conn %u initial MTU %u (target %u)", connHandle, connInfo.getMTU(), kPreferredBleMtu);
|
||||||
pServer->updateConnParams(connHandle, 6, 12, 0, 200);
|
pServer->updateConnParams(connHandle, 6, 12, 0, 200);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef NIMBLE_TWO
|
||||||
virtual void onDisconnect(NimBLEServer *pServer, NimBLEConnInfo &connInfo, int reason)
|
virtual void onDisconnect(NimBLEServer *pServer, NimBLEConnInfo &connInfo, int reason)
|
||||||
{
|
{
|
||||||
LOG_INFO("BLE disconnect reason: %d", reason);
|
LOG_INFO("BLE disconnect reason: %d", reason);
|
||||||
@@ -797,7 +799,7 @@ void NimbleBluetooth::setup()
|
|||||||
NimBLEDevice::init(getDeviceName());
|
NimBLEDevice::init(getDeviceName());
|
||||||
NimBLEDevice::setPower(ESP_PWR_LVL_P9);
|
NimBLEDevice::setPower(ESP_PWR_LVL_P9);
|
||||||
|
|
||||||
#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C6)
|
#if NIMBLE_ENABLE_2M_PHY && (defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C6))
|
||||||
int mtuResult = NimBLEDevice::setMTU(kPreferredBleMtu);
|
int mtuResult = NimBLEDevice::setMTU(kPreferredBleMtu);
|
||||||
if (mtuResult == 0) {
|
if (mtuResult == 0) {
|
||||||
LOG_INFO("BLE MTU request set to %u", kPreferredBleMtu);
|
LOG_INFO("BLE MTU request set to %u", kPreferredBleMtu);
|
||||||
|
|||||||
@@ -64,6 +64,16 @@ void onConnect(uint16_t conn_handle)
|
|||||||
connection->getPeerName(central_name, sizeof(central_name));
|
connection->getPeerName(central_name, sizeof(central_name));
|
||||||
LOG_INFO("BLE Connected to %s", central_name);
|
LOG_INFO("BLE Connected to %s", central_name);
|
||||||
|
|
||||||
|
// negotiate connections params as soon as possible
|
||||||
|
|
||||||
|
ble_gap_conn_params_t newParams;
|
||||||
|
newParams.min_conn_interval = 24;
|
||||||
|
newParams.max_conn_interval = 40;
|
||||||
|
newParams.slave_latency = 5;
|
||||||
|
newParams.conn_sup_timeout = 400;
|
||||||
|
|
||||||
|
sd_ble_gap_conn_param_update(conn_handle, &newParams);
|
||||||
|
|
||||||
// Notify UI (or any other interested firmware components)
|
// Notify UI (or any other interested firmware components)
|
||||||
meshtastic::BluetoothStatus newStatus(meshtastic::BluetoothStatus::ConnectionState::CONNECTED);
|
meshtastic::BluetoothStatus newStatus(meshtastic::BluetoothStatus::ConnectionState::CONNECTED);
|
||||||
bluetoothStatus->updateStatus(&newStatus);
|
bluetoothStatus->updateStatus(&newStatus);
|
||||||
@@ -119,7 +129,7 @@ void startAdv(void)
|
|||||||
Bluefruit.Advertising.addService(meshBleService);
|
Bluefruit.Advertising.addService(meshBleService);
|
||||||
/* Start Advertising
|
/* Start Advertising
|
||||||
* - Enable auto advertising if disconnected
|
* - Enable auto advertising if disconnected
|
||||||
* - Interval: fast mode = 20 ms, slow mode = 152.5 ms
|
* - Interval: fast mode = 20 ms, slow mode = 417,5 ms
|
||||||
* - Timeout for fast mode is 30 seconds
|
* - Timeout for fast mode is 30 seconds
|
||||||
* - Start(timeout) with timeout = 0 will advertise forever (until connected)
|
* - Start(timeout) with timeout = 0 will advertise forever (until connected)
|
||||||
*
|
*
|
||||||
@@ -127,7 +137,7 @@ void startAdv(void)
|
|||||||
* https://developer.apple.com/library/content/qa/qa1931/_index.html
|
* https://developer.apple.com/library/content/qa/qa1931/_index.html
|
||||||
*/
|
*/
|
||||||
Bluefruit.Advertising.restartOnDisconnect(true);
|
Bluefruit.Advertising.restartOnDisconnect(true);
|
||||||
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
|
Bluefruit.Advertising.setInterval(32, 668); // in unit of 0.625 ms
|
||||||
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
|
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
|
||||||
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds. FIXME, we should stop advertising after X
|
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds. FIXME, we should stop advertising after X
|
||||||
}
|
}
|
||||||
@@ -272,6 +282,24 @@ void NRF52Bluetooth::setup()
|
|||||||
// Set the connect/disconnect callback handlers
|
// Set the connect/disconnect callback handlers
|
||||||
Bluefruit.Periph.setConnectCallback(onConnect);
|
Bluefruit.Periph.setConnectCallback(onConnect);
|
||||||
Bluefruit.Periph.setDisconnectCallback(onDisconnect);
|
Bluefruit.Periph.setDisconnectCallback(onDisconnect);
|
||||||
|
|
||||||
|
// Set slave latency to 5 to conserve power
|
||||||
|
// Despite name this does not impact data transfer
|
||||||
|
// https://docs.silabs.com/bluetooth/2.13/bluetooth-general-system-and-performance/optimizing-current-consumption-in-bluetooth-low-energy-devices
|
||||||
|
|
||||||
|
Bluefruit.Periph.setConnSlaveLatency(5);
|
||||||
|
|
||||||
|
// TODO: Adafruit defaul min, max interval seems to be (20,30) [in 1.25 ms units] -> (25.00, 31.25) milliseconds
|
||||||
|
// so using formula Interval Max * (Slave Latency + 1) ≤ 2 seconds
|
||||||
|
// max slave latency we can use is 30 (max available in BLE)
|
||||||
|
// and even double max inteval (see apple doc linked above for formulas)
|
||||||
|
// See Periph.SetConnInterval method
|
||||||
|
|
||||||
|
// Tweak this later for even more power savings once those changes are confirmed to work well.
|
||||||
|
// Changing min, max interval may slow BLE transfer a bit - bumping slave latency will most likely not.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef BLE_DFU_SECURE
|
#ifndef BLE_DFU_SECURE
|
||||||
bledfu.setPermission(SECMODE_ENC_WITH_MITM, SECMODE_ENC_WITH_MITM);
|
bledfu.setPermission(SECMODE_ENC_WITH_MITM, SECMODE_ENC_WITH_MITM);
|
||||||
bledfu.begin(); // Install the DFU helper
|
bledfu.begin(); // Install the DFU helper
|
||||||
@@ -300,7 +328,7 @@ void NRF52Bluetooth::setup()
|
|||||||
void NRF52Bluetooth::resumeAdvertising()
|
void NRF52Bluetooth::resumeAdvertising()
|
||||||
{
|
{
|
||||||
Bluefruit.Advertising.restartOnDisconnect(true);
|
Bluefruit.Advertising.restartOnDisconnect(true);
|
||||||
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
|
Bluefruit.Advertising.setInterval(32, 668); // in unit of 0.625 ms
|
||||||
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
|
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
|
||||||
Bluefruit.Advertising.start(0);
|
Bluefruit.Advertising.start(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,8 @@
|
|||||||
/** Master clock frequency */
|
/** Master clock frequency */
|
||||||
#define VARIANT_MCK (64000000ul)
|
#define VARIANT_MCK (64000000ul)
|
||||||
|
|
||||||
#define USE_LFXO // Board uses 32khz crystal for LF
|
//#define USE_LFXO // Board uses 32khz crystal for LF
|
||||||
|
#define USE_LFRC // Board uses RC for LF
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
* Headers
|
* Headers
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -22,7 +22,9 @@
|
|||||||
/** Master clock frequency */
|
/** Master clock frequency */
|
||||||
#define VARIANT_MCK (64000000ul)
|
#define VARIANT_MCK (64000000ul)
|
||||||
|
|
||||||
#define USE_LFXO // Board uses 32khz crystal for LF
|
//#define USE_LFXO // Board uses 32khz crystal for LF
|
||||||
|
|
||||||
|
#define USE_LFRC
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
* Headers
|
* Headers
|
||||||
|
|||||||
@@ -8,7 +8,18 @@ extra_scripts =
|
|||||||
extra_scripts/disable_adafruit_usb.py
|
extra_scripts/disable_adafruit_usb.py
|
||||||
|
|
||||||
# Remove adafruit USB serial from the build (it is incompatible with using the ch340 serial chip on this board)
|
# Remove adafruit USB serial from the build (it is incompatible with using the ch340 serial chip on this board)
|
||||||
build_unflags = ${nrf52840_base:build_unflags} -DUSBCON -DUSE_TINYUSB
|
build_unflags =
|
||||||
|
-Ofast
|
||||||
|
-Og
|
||||||
|
-ggdb3
|
||||||
|
-ggdb2
|
||||||
|
-g3
|
||||||
|
-g2
|
||||||
|
-g
|
||||||
|
-g1
|
||||||
|
-g0
|
||||||
|
-DUSBCON
|
||||||
|
-DUSE_TINYUSB
|
||||||
build_flags = ${nrf52840_base.build_flags}
|
build_flags = ${nrf52840_base.build_flags}
|
||||||
-Ivariants/nrf52840/wio-sdk-wm1110
|
-Ivariants/nrf52840/wio-sdk-wm1110
|
||||||
-Isrc/platform/nrf52/softdevice
|
-Isrc/platform/nrf52/softdevice
|
||||||
|
|||||||
Reference in New Issue
Block a user