Skip to content

Commit 5d2fb04

Browse files
committed
refactor(hcd): Added getter for the port number
1 parent 55ffe1f commit 5d2fb04

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

host/usb/private_include/hcd.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,15 @@ hcd_port_state_t hcd_port_get_state(hcd_port_handle_t port_hdl);
303303
*/
304304
esp_err_t hcd_port_get_speed(hcd_port_handle_t port_hdl, usb_speed_t *speed);
305305

306+
/**
307+
* @brief Get the port number
308+
*
309+
* @param[in] port_hdl Port handle
310+
*
311+
* @return uint8_t Port number
312+
*/
313+
uint8_t hcd_port_get_number(hcd_port_handle_t port_hdl);
314+
306315
/**
307316
* @brief Handle a ports event
308317
*

host/usb/src/hcd_dwc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ struct port_obj {
256256
uint32_t val;
257257
} flags;
258258
bool initialized;
259+
uint8_t port_num;
259260
// FIFO related
260261
usb_dwc_hal_fifo_config_t fifo_config; // FIFO config to be applied at HAL level
261262
// Port callback and context
@@ -1418,6 +1419,7 @@ esp_err_t hcd_port_init(int port_number, const hcd_port_config_t *port_config, h
14181419
HCD_CHECK_FROM_CRIT(port_obj->hal->channels.hdls != NULL, ESP_ERR_NO_MEM);
14191420

14201421
port_obj->initialized = true;
1422+
port_obj->port_num = port_number;
14211423
// Clear the frame list. We will set the frame list register and enable periodic scheduling after a successful reset
14221424
memset(port_obj->frame_list, 0, FRAME_LIST_LEN * sizeof(uint32_t));
14231425
// If FIFO config is zeroed -> calculate from bias
@@ -1518,6 +1520,12 @@ esp_err_t hcd_port_get_speed(hcd_port_handle_t port_hdl, usb_speed_t *speed)
15181520
return ESP_OK;
15191521
}
15201522

1523+
uint8_t hcd_port_get_number(hcd_port_handle_t port_hdl)
1524+
{
1525+
port_t *port = (port_t *)port_hdl;
1526+
return port->port_num;
1527+
}
1528+
15211529
hcd_port_event_t hcd_port_handle_event(hcd_port_handle_t port_hdl)
15221530
{
15231531
port_t *port = (port_t *)port_hdl;

0 commit comments

Comments
 (0)