Skip to content

Commit bf2be08

Browse files
committed
USBDevice: Add method to enable/disable phy
The new method can be call to disables the USB Phy to not block deep sleep.
1 parent eeb033f commit bf2be08

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

drivers/internal/USBDevice.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,17 @@ class USBDevice: public USBPhyEvents {
256256
*/
257257
uint32_t write_finish(usb_ep_t endpoint);
258258

259+
/** Enable or disable phy
260+
*
261+
* Control enabling of device's phy. This is primarily intended
262+
* for temporary power-saving; This call can
263+
* allow usb to be temporarily disabled to permit power saving without
264+
* losing device state.
265+
*
266+
* @param enabled true to enable, false to disable.
267+
*/
268+
void enable_phy(bool enabled = true);
269+
259270
/*
260271
* Get device descriptor.
261272
*
@@ -595,6 +606,7 @@ class USBDevice: public USBPhyEvents {
595606
endpoint_info_t _endpoint_info[32 - 2];
596607

597608
USBPhy *_phy;
609+
bool _phy_enabled;
598610
bool _initialized;
599611
bool _connected;
600612
bool _endpoint_add_remove_allowed;

drivers/source/usb/USBDevice.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,12 @@ void USBDevice::sof(int frame_number)
13421342
}
13431343

13441344

1345-
USBDevice::USBDevice(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
1345+
USBDevice::USBDevice(
1346+
USBPhy *phy,
1347+
uint16_t vendor_id,
1348+
uint16_t product_id,
1349+
uint16_t product_release
1350+
) : _phy_enabled(true)
13461351
{
13471352
this->vendor_id = vendor_id;
13481353
this->product_id = product_id;
@@ -1771,3 +1776,17 @@ void USBDevice::_run_later(void (USBDevice::*function)())
17711776
{
17721777
_post_process = function;
17731778
}
1779+
1780+
void USBDevice::enable_phy(bool enabled)
1781+
{
1782+
core_util_critical_section_enter();
1783+
if (_phy_enabled != enabled) {
1784+
if (enabled) {
1785+
USBDevice::connect();
1786+
} else {
1787+
USBDevice::deinit();
1788+
}
1789+
_phy_enabled = enabled;
1790+
}
1791+
core_util_critical_section_exit();
1792+
}

0 commit comments

Comments
 (0)