diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 146d99b9..59278988 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -478,6 +478,11 @@ void BLELocalDevice::noDebug() HCI.noDebug(); } +void BLELocalDevice::setLowPowerModeEnabled(bool enabled) +{ + HCI.leSetLPMode(enabled); +} + #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj; BLELocalDevice& BLE = BLEObj; diff --git a/src/local/BLELocalDevice.h b/src/local/BLELocalDevice.h index 6c45c063..bb96bb7a 100644 --- a/src/local/BLELocalDevice.h +++ b/src/local/BLELocalDevice.h @@ -107,6 +107,9 @@ class BLELocalDevice { virtual void setDisplayCode(void (*displayCode)(uint32_t confirmationCode)); virtual void setBinaryConfirmPairing(bool (*binaryConfirmPairing)()); + + virtual void setLowPowerModeEnabled(bool enabled); + uint8_t BDaddress[6]; protected: diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index e9743758..1db4b10c 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -1481,6 +1481,11 @@ void HCIClass::dumpPkt(const char* prefix, uint8_t plen, uint8_t pdata[]) } } +void HCIClass::leSetLPMode(bool status) +{ + HCITransport.setLPMode(status); +} + #if !defined(FAKE_HCI) HCIClass HCIObj; HCIClass& HCI = HCIObj; diff --git a/src/utility/HCI.h b/src/utility/HCI.h index 0a530ceb..8d756879 100644 --- a/src/utility/HCI.h +++ b/src/utility/HCI.h @@ -105,6 +105,8 @@ class HCIClass { virtual int leStartResolvingAddresses(); virtual int leReadPeerResolvableAddress(uint8_t peerAddressType, uint8_t* peerIdentityAddress, uint8_t* peerResolvableAddress); + virtual void leSetLPMode(bool status); + virtual void readStoredLKs(); virtual int readStoredLK(uint8_t BD_ADDR[], uint8_t read_all = 0); virtual void writeLK(uint8_t peerAddress[], uint8_t LK[]); diff --git a/src/utility/HCICordioTransport.cpp b/src/utility/HCICordioTransport.cpp index 947378cf..9387d4df 100644 --- a/src/utility/HCICordioTransport.cpp +++ b/src/utility/HCICordioTransport.cpp @@ -54,6 +54,7 @@ #endif extern BLE_NAMESPACE::CordioHCIDriver& ble_cordio_get_hci_driver(); +extern void ble_cordio_set_lp_mode(bool status); namespace BLE_NAMESPACE { struct CordioHCIHook { @@ -68,6 +69,10 @@ namespace BLE_NAMESPACE { static void setDataReceivedHandler(void (*handler)(uint8_t*, uint8_t)) { getTransportDriver().set_data_received_handler(handler); } + + static void setLowPowerMode(bool status) { + ble_cordio_set_lp_mode(status); + } }; } @@ -309,4 +314,9 @@ void HCICordioTransportClass::onDataReceived(uint8_t* data, uint8_t len) HCICordioTransport.handleRxData(data, len); } +void HCICordioTransportClass::setLPMode(bool status) +{ + CordioHCIHook::setLowPowerMode(status); +} + #endif diff --git a/src/utility/HCICordioTransport.h b/src/utility/HCICordioTransport.h index b8d0596a..ec172a34 100644 --- a/src/utility/HCICordioTransport.h +++ b/src/utility/HCICordioTransport.h @@ -42,6 +42,8 @@ class HCICordioTransportClass : public HCITransportInterface { virtual size_t write(const uint8_t* data, size_t length); + virtual void setLPMode(bool status); + private: static void onDataReceived(uint8_t* data, uint8_t len); void handleRxData(uint8_t* data, uint8_t len); diff --git a/src/utility/HCITransport.h b/src/utility/HCITransport.h index d8aa6a95..123219a6 100644 --- a/src/utility/HCITransport.h +++ b/src/utility/HCITransport.h @@ -34,6 +34,8 @@ class HCITransportInterface { virtual int read() = 0; virtual size_t write(const uint8_t* data, size_t length) = 0; + + virtual void setLPMode(bool status); }; extern HCITransportInterface& HCITransport; diff --git a/src/utility/HCIUartTransport.cpp b/src/utility/HCIUartTransport.cpp index d3c44d8f..0fc37a1c 100644 --- a/src/utility/HCIUartTransport.cpp +++ b/src/utility/HCIUartTransport.cpp @@ -97,6 +97,11 @@ size_t HCIUartTransportClass::write(const uint8_t* data, size_t length) return result; } +void HCIUartTransportClass::setLPMode(bool status) +{ + (void)status; +} + #if defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_NANO_RP2040_CONNECT) HCIUartTransportClass HCIUartTransport(SerialHCI, 119600); #else diff --git a/src/utility/HCIUartTransport.h b/src/utility/HCIUartTransport.h index ba70dff4..b3ead7f0 100644 --- a/src/utility/HCIUartTransport.h +++ b/src/utility/HCIUartTransport.h @@ -38,6 +38,8 @@ class HCIUartTransportClass : public HCITransportInterface { virtual size_t write(const uint8_t* data, size_t length); + virtual void setLPMode(bool status); + private: HardwareSerial* _uart; unsigned long _baudrate; diff --git a/src/utility/HCIVirtualTransport.cpp b/src/utility/HCIVirtualTransport.cpp index 046a0e72..15d8a711 100644 --- a/src/utility/HCIVirtualTransport.cpp +++ b/src/utility/HCIVirtualTransport.cpp @@ -135,6 +135,11 @@ size_t HCIVirtualTransportClass::write(const uint8_t* data, size_t length) return result; } +void HCIVirtualTransportClass::setLPMode(bool status) +{ + (void)status; +} + HCIVirtualTransportClass HCIVirtualTransport; HCITransportInterface& HCITransport = HCIVirtualTransport; diff --git a/src/utility/HCIVirtualTransport.h b/src/utility/HCIVirtualTransport.h index 0da43cac..8d071eb4 100644 --- a/src/utility/HCIVirtualTransport.h +++ b/src/utility/HCIVirtualTransport.h @@ -47,4 +47,6 @@ class HCIVirtualTransportClass : public HCITransportInterface { virtual int read(); virtual size_t write(const uint8_t* data, size_t length); + + virtual void setLPMode(bool status); }; \ No newline at end of file diff --git a/src/utility/HCIVirtualTransportAT.cpp b/src/utility/HCIVirtualTransportAT.cpp index 7b3a24a9..2e7f33c9 100644 --- a/src/utility/HCIVirtualTransportAT.cpp +++ b/src/utility/HCIVirtualTransportAT.cpp @@ -105,6 +105,11 @@ size_t HCIVirtualTransportATClass::write(const uint8_t* data, size_t length) return 0; } +void HCIVirtualTransportATClass::setLPMode(bool status) +{ + (void)status; +} + HCIVirtualTransportATClass HCIVirtualTransportAT; HCITransportInterface& HCITransport = HCIVirtualTransportAT; diff --git a/src/utility/HCIVirtualTransportAT.h b/src/utility/HCIVirtualTransportAT.h index 8e29801d..a86afb05 100644 --- a/src/utility/HCIVirtualTransportAT.h +++ b/src/utility/HCIVirtualTransportAT.h @@ -39,4 +39,6 @@ class HCIVirtualTransportATClass : public HCITransportInterface { virtual int read(); virtual size_t write(const uint8_t* data, size_t length); + + virtual void setLPMode(bool status); }; \ No newline at end of file