Skip to content

Commit

Permalink
fear(host/uvc): Add libuvc_get_usb_device_info() function
Browse files Browse the repository at this point in the history
This allows users to get detailed information about
underlying USB device.

Closes #19
  • Loading branch information
tore-espressif committed Mar 8, 2024
1 parent ea0b3bf commit 83cf701
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions host/class/uvc/usb_host_uvc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Added support for ESP32-P4
- Bumped libuvc version to relax frame format negotiation
- Fixed crash on opening non-UVC devices
- Added `libuvc_get_usb_device_info` function

## 1.0.2

Expand Down
12 changes: 11 additions & 1 deletion host/class/uvc/usb_host_uvc/include/libuvc_adapter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -8,6 +8,8 @@
#include <stdbool.h>
#include <stdint.h>
#include "esp_err.h"
#include "usb/usb_types_stack.h"
#include "libuvc/libuvc.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -60,6 +62,14 @@ esp_err_t libuvc_adapter_print_descriptors(uvc_device_handle_t *device);
*/
esp_err_t libuvc_adapter_handle_events(uint32_t timeout_ms);

/**
* @brief Get information about underlying USB device
*
* @param[in] dev UVC device handle obtained from uvc_find_device()
* @param[out] dev_info Pointer to structure where the information will be saved
*/
esp_err_t libuvc_get_usb_device_info(uvc_device_t *dev, usb_device_info_t *dev_info);

#ifdef __cplusplus
}
#endif
20 changes: 19 additions & 1 deletion host/class/uvc/usb_host_uvc/src/libusb_adapter.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -192,6 +192,24 @@ esp_err_t libuvc_adapter_print_descriptors(uvc_device_handle_t *device)
return ESP_OK;
}

esp_err_t libuvc_get_usb_device_info(uvc_device_t *dev, usb_device_info_t *dev_info)
{
uvc_error_t ret;
struct libusb_device_handle *usb_devh;

ret = libusb_open(dev->usb_dev, &usb_devh);
UVC_DEBUG("libusb_open() = %d", ret);
if (ret != UVC_SUCCESS) {
return ESP_FAIL;
}

uvc_camera_t *camera = (uvc_camera_t *)(usb_devh);
RETURN_ON_ERROR( usb_host_device_info(camera->handle, dev_info) );

libusb_close(usb_devh);
return ESP_OK;
}

esp_err_t libuvc_adapter_handle_events(uint32_t timeout_ms)
{
if (s_uvc_driver == NULL) {
Expand Down

0 comments on commit 83cf701

Please sign in to comment.