diff --git a/examples/peripherals/usb/host/cdc/common/cdc_acm_host/cdc_acm_host.c b/examples/peripherals/usb/host/cdc/common/cdc_acm_host/cdc_acm_host.c index cfdb10e..4d8cfd3 100644 --- a/examples/peripherals/usb/host/cdc/common/cdc_acm_host/cdc_acm_host.c +++ b/examples/peripherals/usb/host/cdc/common/cdc_acm_host/cdc_acm_host.c @@ -946,7 +946,7 @@ static bool cdc_acm_is_transfer_completed(usb_transfer_t *transfer) .type = CDC_ACM_HOST_ERROR, .data.error = (int) transfer->status }; - cdc_dev->notif.cb((cdc_acm_dev_hdl_t) cdc_dev, &error_event, cdc_dev->cb_arg); + cdc_dev->notif.cb(&error_event, cdc_dev->cb_arg); } } return completed; @@ -981,7 +981,7 @@ static void notif_xfer_cb(usb_transfer_t *transfer) .type = CDC_ACM_HOST_NETWORK_CONNECTION, .data.network_connected = (bool) notif->wValue }; - cdc_dev->notif.cb((cdc_acm_dev_hdl_t) cdc_dev, &net_conn_event, cdc_dev->cb_arg); + cdc_dev->notif.cb(&net_conn_event, cdc_dev->cb_arg); } break; } @@ -992,7 +992,7 @@ static void notif_xfer_cb(usb_transfer_t *transfer) .type = CDC_ACM_HOST_SERIAL_STATE, .data.serial_state = cdc_dev->serial_state }; - cdc_dev->notif.cb((cdc_acm_dev_hdl_t) cdc_dev, &serial_state_event, cdc_dev->cb_arg); + cdc_dev->notif.cb(&serial_state_event, cdc_dev->cb_arg); } break; } @@ -1043,8 +1043,9 @@ static void usb_event_cb(const usb_host_client_event_msg_t *event_msg, void *arg // The suddenly disconnected device was opened by this driver: inform user about this const cdc_acm_host_dev_event_data_t disconn_event = { .type = CDC_ACM_HOST_DEVICE_DISCONNECTED, + .data.cdc_hdl = (cdc_acm_dev_hdl_t) cdc_dev, }; - cdc_dev->notif.cb((cdc_acm_dev_hdl_t) cdc_dev, &disconn_event, cdc_dev->cb_arg); + cdc_dev->notif.cb(&disconn_event, cdc_dev->cb_arg); } } break; diff --git a/examples/peripherals/usb/host/cdc/common/cdc_acm_host/include/usb/cdc_acm_host.h b/examples/peripherals/usb/host/cdc/common/cdc_acm_host/include/usb/cdc_acm_host.h index 2e60bed..952ecb8 100644 --- a/examples/peripherals/usb/host/cdc/common/cdc_acm_host/include/usb/cdc_acm_host.h +++ b/examples/peripherals/usb/host/cdc/common/cdc_acm_host/include/usb/cdc_acm_host.h @@ -64,9 +64,10 @@ typedef enum { typedef struct { cdc_acm_host_dev_event_t type; union { - int error; // Error code from USB Host - cdc_acm_uart_state_t serial_state; // Serial (UART) state - bool network_connected; // Network connection event + int error; //!< Error code from USB Host + cdc_acm_uart_state_t serial_state; //!< Serial (UART) state + bool network_connected; //!< Network connection event + cdc_acm_dev_hdl_t cdc_hdl; //!< Disconnection event } data; } cdc_acm_host_dev_event_data_t; @@ -87,9 +88,9 @@ typedef void (*cdc_acm_data_callback_t)(uint8_t* data, size_t data_len, void *us /** * @brief Device event callback type - * @see cdc_acm_host_dev_event_t + * @see cdc_acm_host_dev_event_data_t */ -typedef void (*cdc_acm_host_dev_callback_t)(cdc_acm_dev_hdl_t cdc_hdl, const cdc_acm_host_dev_event_data_t *event, void *user_ctx); +typedef void (*cdc_acm_host_dev_callback_t)(const cdc_acm_host_dev_event_data_t *event, void *user_ctx); /** * @brief Configuration structure of USB Host CDC-ACM driver @@ -298,10 +299,13 @@ public: return cdc_acm_host_open_vendor_specific(vid, pid, interface_idx, dev_config, &this->cdc_hdl); } - inline void close() + inline esp_err_t close() { - cdc_acm_host_close(this->cdc_hdl); - this->cdc_hdl = NULL; + esp_err_t err = cdc_acm_host_close(this->cdc_hdl); + if (err == ESP_OK) { + this->cdc_hdl = NULL; + } + return err; } inline esp_err_t line_coding_get(cdc_acm_line_coding_t *line_coding) diff --git a/examples/peripherals/usb/host/cdc/common/cdc_acm_host/test/test_cdc_acm_host.c b/examples/peripherals/usb/host/cdc/common/cdc_acm_host/test/test_cdc_acm_host.c index dafab15..1ba2bcf 100644 --- a/examples/peripherals/usb/host/cdc/common/cdc_acm_host/test/test_cdc_acm_host.c +++ b/examples/peripherals/usb/host/cdc/common/cdc_acm_host/test/test_cdc_acm_host.c @@ -110,7 +110,7 @@ static void handle_rx2(uint8_t *data, size_t data_len, void *arg) TEST_ASSERT_EQUAL_STRING_LEN(data, arg, data_len); } -static void notif_cb(cdc_acm_dev_hdl_t cdc_hdl, const cdc_acm_host_dev_event_data_t *event, void *user_ctx) +static void notif_cb(const cdc_acm_host_dev_event_data_t *event, void *user_ctx) { switch (event->type) { case CDC_ACM_HOST_ERROR: @@ -122,7 +122,7 @@ static void notif_cb(cdc_acm_dev_hdl_t cdc_hdl, const cdc_acm_host_dev_event_dat break; case CDC_ACM_HOST_DEVICE_DISCONNECTED: printf("Disconnection event\n"); - TEST_ASSERT_EQUAL(ESP_OK, cdc_acm_host_close(cdc_hdl)); + TEST_ASSERT_EQUAL(ESP_OK, cdc_acm_host_close(event->data.cdc_hdl)); xTaskNotifyGive(user_ctx); break; default: