mirror of
https://github.com/espressif/esp-idf
synced 2025-03-10 01:29:21 -04:00
usb_host: Unify CDC event callbacks
And return error code from C++ close method.
This commit is contained in:
parent
0428efa4ad
commit
880b5a4bef
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user