Merge branch 'feat/usb_host_cmock_add_device' into 'master'

feature(usb_host): cmock add device

See merge request espressif/esp-idf!34932
This commit is contained in:
Peter Marcisovsky
2024-12-17 22:01:22 +08:00
6 changed files with 688 additions and 2 deletions

View File

@@ -10,6 +10,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <sys/queue.h>
#include "esp_assert.h"
#include "usb/usb_types_ch9.h"
#include "usb/usb_types_stack.h"
@@ -34,7 +35,7 @@ typedef struct {
int num_isoc_packets;
usb_isoc_packet_desc_t isoc_packet_desc[0];
} usb_transfer_dummy_t;
_Static_assert(sizeof(usb_transfer_dummy_t) == sizeof(usb_transfer_t), "usb_transfer_dummy_t does not match usb_transfer_t");
ESP_STATIC_ASSERT(sizeof(usb_transfer_dummy_t) == sizeof(usb_transfer_t), "usb_transfer_dummy_t does not match usb_transfer_t");
struct urb_s {
TAILQ_ENTRY(urb_s) tailq_entry;

View File

@@ -15,10 +15,18 @@ urb_t *urb_alloc(size_t data_buffer_size, int num_isoc_packets)
if (urb == NULL || data_buffer == NULL) {
goto err;
}
#if CONFIG_IDF_TARGET_LINUX
// heap_caps_get_allocated_size() return 0 on Linux target
const size_t allocated_size = data_buffer_size;
#else
const size_t allocated_size = heap_caps_get_allocated_size(data_buffer);
#endif
// Cast as dummy transfer so that we can assign to const fields
usb_transfer_dummy_t *dummy_transfer = (usb_transfer_dummy_t *)&urb->transfer;
dummy_transfer->data_buffer = data_buffer;
dummy_transfer->data_buffer_size = heap_caps_get_allocated_size(data_buffer);
dummy_transfer->data_buffer_size = allocated_size;
dummy_transfer->num_isoc_packets = num_isoc_packets;
return urb;
err: