hathach / tinyusb

An open source cross-platform USB stack for embedded system

Home Page:https://www.tinyusb.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to provide an `ncm_open`, `ncm_close` API interface to control the connection and disconnection of USB?

tswen opened this issue · comments

Related area

net class

Hardware specification

esp32-S2, esp32-S3

Is your feature request related to a problem?

None

Describe the solution you'd like

None

I have checked existing issues, dicussion and documentation

  • I confirm I have checked existing issues, dicussion and documentation.

Such as

void ecm_close(void)
{
  printf("Ecm close\n");
  tusb_control_request_t notify_data =
  {
    .bmRequestType = 0xA1,
    .bRequest = 0 /* NETWORK_CONNECTION aka NetworkConnection */,
    .wValue = 0 /* Disconnected */,
    .wLength = 0,
  };
  notify_data.wIndex = _netd_itf.itf_num;
  netd_report((uint8_t *)&notify_data, sizeof(notify_data));
}

void ecm_open(void)
{
  printf("Ecm OPEN\n");
  tusb_control_request_t notify_data =
  {
    .bmRequestType = 0xA1,
    .bRequest = 0 /* NETWORK_CONNECTION aka NetworkConnection */,
    .wValue = 1 /* Connected */,
    .wLength = 0,
  };
  notify_data.wIndex = _netd_itf.itf_num;
  netd_report((uint8_t *)&notify_data, sizeof(notify_data));
}

you could use the already defined tu_static struct ncm_notify_t ncm_notify_connected to implement these functions, right?

Wouldn't it also make sense to define the startup behavior? Currently it just automatically is connected. That is a good default behavior. But in a scenario where the firmware wants to change the connected state it might also want to start out in disconnected state, right?