Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to manage low power mode status #327

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/local/BLELocalDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/local/BLELocalDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions src/utility/HCI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,11 @@ void HCIClass::dumpPkt(const char* prefix, uint8_t plen, uint8_t pdata[])
}
}

void HCIClass::leSetLPMode(bool status)
leonardocavagnis marked this conversation as resolved.
Show resolved Hide resolved
{
HCITransport.setLPMode(status);
leonardocavagnis marked this conversation as resolved.
Show resolved Hide resolved
}

#if !defined(FAKE_HCI)
HCIClass HCIObj;
HCIClass& HCI = HCIObj;
Expand Down
2 changes: 2 additions & 0 deletions src/utility/HCI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
leonardocavagnis marked this conversation as resolved.
Show resolved Hide resolved

virtual void readStoredLKs();
virtual int readStoredLK(uint8_t BD_ADDR[], uint8_t read_all = 0);
virtual void writeLK(uint8_t peerAddress[], uint8_t LK[]);
Expand Down
10 changes: 10 additions & 0 deletions src/utility/HCICordioTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
};
}

Expand Down Expand Up @@ -309,4 +314,9 @@ void HCICordioTransportClass::onDataReceived(uint8_t* data, uint8_t len)
HCICordioTransport.handleRxData(data, len);
}

void HCICordioTransportClass::setLPMode(bool status)
leonardocavagnis marked this conversation as resolved.
Show resolved Hide resolved
{
CordioHCIHook::setLowPowerMode(status);
}

#endif
2 changes: 2 additions & 0 deletions src/utility/HCICordioTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class HCICordioTransportClass : public HCITransportInterface {

virtual size_t write(const uint8_t* data, size_t length);

virtual void setLPMode(bool status);
leonardocavagnis marked this conversation as resolved.
Show resolved Hide resolved

private:
static void onDataReceived(uint8_t* data, uint8_t len);
void handleRxData(uint8_t* data, uint8_t len);
Expand Down
2 changes: 2 additions & 0 deletions src/utility/HCITransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
leonardocavagnis marked this conversation as resolved.
Show resolved Hide resolved
};

extern HCITransportInterface& HCITransport;
Expand Down
5 changes: 5 additions & 0 deletions src/utility/HCIUartTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ size_t HCIUartTransportClass::write(const uint8_t* data, size_t length)
return result;
}

void HCIUartTransportClass::setLPMode(bool status)
leonardocavagnis marked this conversation as resolved.
Show resolved Hide resolved
{
(void)status;
}

#if defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_NANO_RP2040_CONNECT)
HCIUartTransportClass HCIUartTransport(SerialHCI, 119600);
#else
Expand Down
2 changes: 2 additions & 0 deletions src/utility/HCIUartTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class HCIUartTransportClass : public HCITransportInterface {

virtual size_t write(const uint8_t* data, size_t length);

virtual void setLPMode(bool status);
leonardocavagnis marked this conversation as resolved.
Show resolved Hide resolved

private:
HardwareSerial* _uart;
unsigned long _baudrate;
Expand Down
5 changes: 5 additions & 0 deletions src/utility/HCIVirtualTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ size_t HCIVirtualTransportClass::write(const uint8_t* data, size_t length)
return result;
}

void HCIVirtualTransportClass::setLPMode(bool status)
leonardocavagnis marked this conversation as resolved.
Show resolved Hide resolved
{
(void)status;
}

HCIVirtualTransportClass HCIVirtualTransport;

HCITransportInterface& HCITransport = HCIVirtualTransport;
Expand Down
2 changes: 2 additions & 0 deletions src/utility/HCIVirtualTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
leonardocavagnis marked this conversation as resolved.
Show resolved Hide resolved
};
5 changes: 5 additions & 0 deletions src/utility/HCIVirtualTransportAT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ size_t HCIVirtualTransportATClass::write(const uint8_t* data, size_t length)
return 0;
}

void HCIVirtualTransportATClass::setLPMode(bool status)
leonardocavagnis marked this conversation as resolved.
Show resolved Hide resolved
{
(void)status;
}

HCIVirtualTransportATClass HCIVirtualTransportAT;

HCITransportInterface& HCITransport = HCIVirtualTransportAT;
Expand Down
2 changes: 2 additions & 0 deletions src/utility/HCIVirtualTransportAT.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
leonardocavagnis marked this conversation as resolved.
Show resolved Hide resolved
};
Loading