Skip to content

add ESP8266 interface suspend and resume APIs #12987

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

Closed
Closed
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 components/wifi/esp8266-driver/ESP8266/ESP8266.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1583,4 +1583,9 @@ int ESP8266::uart_enable_input(bool enabled)
return _serial.enable_input(enabled);
}

int ESP8266::uart_enable_output(bool enabled)
{
return _serial.enable_output(enabled);
}

#endif
8 changes: 8 additions & 0 deletions components/wifi/esp8266-driver/ESP8266/ESP8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,14 @@ class ESP8266 {
*/
int uart_enable_input(bool lock);

/**
* Enables or disables uart output and deep sleep
*
* @param lock if TRUE, uart output is enabled and deep sleep is locked
* if FALSE, uart input is disabled and deep sleep is unlocked
*/
int uart_enable_output(bool lock);

private:
// FW version
struct fw_sdk_version _sdk_v;
Expand Down
22 changes: 22 additions & 0 deletions components/wifi/esp8266-driver/ESP8266Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1245,4 +1245,26 @@ nsapi_error_t ESP8266Interface::set_country_code(bool track_ap, const char *coun
return NSAPI_ERROR_OK;
}

void ESP8266Interface::interface_suspend(uint16_t direction)
{
if (ESP8266_INPUT & direction) {
_esp.uart_enable_input(false);
}

if (ESP8266_OUTPUT & direction) {
_esp.uart_enable_output(false);
}
}

void ESP8266Interface::interface_resume(uint16_t direction)
{
if (ESP8266_INPUT & direction) {
_esp.uart_enable_input(true);
}

if (ESP8266_OUTPUT & direction) {
_esp.uart_enable_output(true);
}
}

#endif
22 changes: 22 additions & 0 deletions components/wifi/esp8266-driver/ESP8266Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ class ESP8266Interface : public NetworkStack, public WiFiInterface {
* Will use values defined in mbed_lib.json
*/
ESP8266Interface();

/**
* @brief Enum to ESP8266 interface traffic direction
*/
enum ESP8266_InterfaceMask {
ESP8266_NONE = 0x0,
ESP8266_INPUT = 0x01,
ESP8266_OUTPUT = 0x02,
ESP8266_INPUT_OUTPUT = 0x03
};
#endif

/** ESP8266Interface lifetime
Expand Down Expand Up @@ -293,6 +303,18 @@ class ESP8266Interface : public NetworkStack, public WiFiInterface {
*/
virtual nsapi_connection_status_t get_connection_status() const;

/** Suspend the traffic of the interface
*
* @param direction The direction going to be suspended
*/
virtual void interface_suspend(uint16_t direction);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suspend/resume wouldn't be sufficient (no need for interface_) ? I dont see it defined anywhere in Mbed OS codebase as it is here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well I put the interface_ here because I don't want to confuse the users. The API is not to suspend/resume the ESP8266 itself, but only the traffic.
But on second thought, the class itself is ESP8266Interface, so perhaps it wouldn't confuse users. How do you think?


/** Resume the traffic of the interface
*
* @param direction The direction going to be suspended
*/
virtual void interface_resume(uint16_t direction);

protected:
/** Open a socket
* @param handle Handle in which to store new socket
Expand Down