hathach / tinyusb

An open source cross-platform USB stack for embedded system
https://www.tinyusb.org
MIT License
4.93k stars 1.03k forks source link

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

Open tswen opened 3 months ago

tswen commented 3 months ago

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

tswen commented 3 months ago

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));
}
JustAnother1 commented 3 months ago

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?