2021-08-24 11:20:50 -04:00
|
|
|
/*
|
2023-11-21 11:47:38 -05:00
|
|
|
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
2021-08-24 11:20:50 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2021-06-09 09:49:08 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stddef.h>
|
2021-08-24 11:20:50 -04:00
|
|
|
#include <stdbool.h>
|
2021-06-09 09:49:08 -04:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/queue.h>
|
2021-08-24 11:20:50 -04:00
|
|
|
#include "usb/usb_types_ch9.h"
|
|
|
|
#include "usb/usb_types_stack.h"
|
2021-06-09 09:49:08 -04:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-08-24 11:20:50 -04:00
|
|
|
// ------------------------------------------------------ Types --------------------------------------------------------
|
|
|
|
|
2021-06-09 09:49:08 -04:00
|
|
|
typedef struct {
|
|
|
|
uint8_t *data_buffer;
|
|
|
|
size_t data_buffer_size;
|
|
|
|
int num_bytes;
|
|
|
|
int actual_num_bytes;
|
|
|
|
uint32_t flags;
|
2021-08-24 11:20:50 -04:00
|
|
|
usb_device_handle_t device_handle;
|
|
|
|
uint8_t bEndpointAddress;
|
2021-06-09 09:49:08 -04:00
|
|
|
usb_transfer_status_t status;
|
|
|
|
uint32_t timeout;
|
|
|
|
usb_transfer_cb_t callback;
|
|
|
|
void *context;
|
|
|
|
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");
|
|
|
|
|
2023-05-08 12:53:27 -04:00
|
|
|
struct urb_s {
|
2021-08-24 11:20:50 -04:00
|
|
|
TAILQ_ENTRY(urb_s) tailq_entry;
|
2023-05-08 12:53:27 -04:00
|
|
|
// HCD Layer: Handler pointer and variables. Must be initialized to NULL and 0 respectively
|
2021-06-09 09:49:08 -04:00
|
|
|
void *hcd_ptr;
|
|
|
|
uint32_t hcd_var;
|
2023-05-08 12:53:27 -04:00
|
|
|
// Host Lib Layer:
|
|
|
|
void *usb_host_client; // Currently only used when submitted to shared pipes (i.e., Device default pipes)
|
|
|
|
bool usb_host_inflight; // Debugging variable, used to prevent re-submitting URBs already inflight
|
|
|
|
// Public transfer structure. Must be last due to variable length array
|
2021-06-09 09:49:08 -04:00
|
|
|
usb_transfer_t transfer;
|
|
|
|
};
|
2021-08-24 11:20:50 -04:00
|
|
|
typedef struct urb_s urb_t;
|
|
|
|
|
2023-05-08 12:43:32 -04:00
|
|
|
/**
|
|
|
|
* @brief Processing request source
|
|
|
|
*
|
|
|
|
* Enum to indicate which layer of the USB Host stack requires processing. The main handling loop should then call that
|
|
|
|
* layer's processing function (i.e., xxx_process()).
|
|
|
|
*/
|
2021-08-24 11:20:50 -04:00
|
|
|
typedef enum {
|
2023-05-08 12:43:32 -04:00
|
|
|
USB_PROC_REQ_SOURCE_USBH = 0x01,
|
|
|
|
USB_PROC_REQ_SOURCE_HUB = 0x02,
|
2024-03-04 15:11:43 -05:00
|
|
|
USB_PROC_REQ_SOURCE_ENUM = 0x03
|
2023-05-08 12:43:32 -04:00
|
|
|
} usb_proc_req_source_t;
|
2021-08-24 11:20:50 -04:00
|
|
|
|
2023-05-08 12:43:32 -04:00
|
|
|
/**
|
|
|
|
* @brief Processing request callback
|
|
|
|
*
|
|
|
|
* Callback function provided to each layer of the USB Host stack so that each layer can request calls to their
|
|
|
|
* processing function.
|
|
|
|
*/
|
|
|
|
typedef bool (*usb_proc_req_cb_t)(usb_proc_req_source_t source, bool in_isr, void *context);
|
2021-08-24 11:20:50 -04:00
|
|
|
|
|
|
|
// --------------------------------------------------- Allocation ------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Allocate a URB
|
|
|
|
*
|
|
|
|
* - Data buffer is allocated in DMA capable memory
|
|
|
|
* - The constant fields of the URB are also set
|
2023-11-21 11:47:38 -05:00
|
|
|
* - The data_buffer field of the URB is set to point to start of the allocated data buffer.
|
2021-08-24 11:20:50 -04:00
|
|
|
*
|
|
|
|
* @param data_buffer_size Size of the URB's data buffer
|
|
|
|
* @param num_isoc_packets Number of isochronous packet descriptors
|
|
|
|
* @return urb_t* URB object
|
|
|
|
*/
|
2023-11-21 11:47:38 -05:00
|
|
|
urb_t *urb_alloc(size_t data_buffer_size, int num_isoc_packets);
|
2021-06-09 09:49:08 -04:00
|
|
|
|
2021-08-24 11:20:50 -04:00
|
|
|
/**
|
|
|
|
* @brief Free a URB
|
|
|
|
*
|
|
|
|
* @param urb URB object
|
|
|
|
*/
|
|
|
|
void urb_free(urb_t *urb);
|
2021-06-09 09:49:08 -04:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|