Introduce static USB output driver boundary
This commit is contained in:
parent
1837f42e21
commit
31a8cfb9d3
24 changed files with 1292 additions and 534 deletions
36
tests/native_stubs/device/usbd_pvt.h
Normal file
36
tests/native_stubs/device/usbd_pvt.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#pragma once
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char const* name;
|
||||
void (*init)(void);
|
||||
bool (*deinit)(void);
|
||||
void (*reset)(uint8_t rhport);
|
||||
uint16_t (*open)(uint8_t rhport,
|
||||
tusb_desc_interface_t const* interface_descriptor,
|
||||
uint16_t max_length);
|
||||
bool (*control_xfer_cb)(uint8_t rhport, uint8_t stage,
|
||||
tusb_control_request_t const* request);
|
||||
bool (*xfer_cb)(uint8_t rhport, uint8_t endpoint,
|
||||
xfer_result_t result, uint32_t transferred);
|
||||
void (*sof)(uint8_t rhport, uint32_t frame_count);
|
||||
} usbd_class_driver_t;
|
||||
|
||||
usbd_class_driver_t const* usbd_app_driver_get_cb(uint8_t* driver_count);
|
||||
|
||||
bool usbd_edpt_open(uint8_t rhport,
|
||||
tusb_desc_endpoint_t const* endpoint_descriptor);
|
||||
bool usbd_edpt_xfer(uint8_t rhport, uint8_t endpoint, uint8_t* buffer,
|
||||
uint16_t total_bytes);
|
||||
bool usbd_edpt_busy(uint8_t rhport, uint8_t endpoint);
|
||||
bool usbd_edpt_claim(uint8_t rhport, uint8_t endpoint);
|
||||
bool usbd_edpt_release(uint8_t rhport, uint8_t endpoint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
@ -14,6 +15,54 @@ typedef enum {
|
|||
HID_REPORT_TYPE_FEATURE = 3,
|
||||
} hid_report_type_t;
|
||||
|
||||
typedef enum {
|
||||
XFER_RESULT_SUCCESS = 0,
|
||||
XFER_RESULT_FAILED,
|
||||
} xfer_result_t;
|
||||
|
||||
enum {
|
||||
TUSB_DIR_OUT = 0,
|
||||
TUSB_DIR_IN = 1,
|
||||
TUSB_DESC_ENDPOINT = 5,
|
||||
TUSB_DESC_STRING = 3,
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bInterfaceNumber;
|
||||
uint8_t bAlternateSetting;
|
||||
uint8_t bNumEndpoints;
|
||||
uint8_t bInterfaceClass;
|
||||
uint8_t bInterfaceSubClass;
|
||||
uint8_t bInterfaceProtocol;
|
||||
uint8_t iInterface;
|
||||
} tusb_desc_interface_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bEndpointAddress;
|
||||
uint8_t bmAttributes;
|
||||
uint16_t wMaxPacketSize;
|
||||
uint8_t bInterval;
|
||||
} tusb_desc_endpoint_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
static inline uint8_t const* tu_desc_next(void const* descriptor) {
|
||||
uint8_t const* bytes = (uint8_t const*)descriptor;
|
||||
return bytes + bytes[0];
|
||||
}
|
||||
|
||||
static inline uint8_t tu_desc_type(void const* descriptor) {
|
||||
return ((uint8_t const*)descriptor)[1];
|
||||
}
|
||||
|
||||
static inline uint8_t tu_edpt_dir(uint8_t endpoint) {
|
||||
return (endpoint & 0x80u) != 0 ? TUSB_DIR_IN : TUSB_DIR_OUT;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
uint8_t bmRequestType;
|
||||
uint8_t bRequest;
|
||||
|
|
@ -27,6 +76,7 @@ bool tud_hid_n_report(uint8_t instance, uint8_t report_id,
|
|||
const void* report, uint16_t length);
|
||||
bool tud_suspended(void);
|
||||
bool tud_remote_wakeup(void);
|
||||
bool tud_ready(void);
|
||||
|
||||
uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id,
|
||||
hid_report_type_t report_type, uint8_t* buffer,
|
||||
|
|
@ -39,6 +89,14 @@ void tud_hid_report_received_cb(uint8_t instance, uint8_t report_id,
|
|||
uint8_t const* tud_hid_descriptor_report_cb(uint8_t instance);
|
||||
void tud_mount_cb(void);
|
||||
void tud_umount_cb(void);
|
||||
uint8_t const* tud_descriptor_device_cb(void);
|
||||
uint8_t const* tud_descriptor_configuration_cb(uint8_t index);
|
||||
uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid);
|
||||
bool tud_vendor_control_xfer_cb(
|
||||
uint8_t rhport, uint8_t stage,
|
||||
tusb_control_request_t const* request);
|
||||
bool tud_control_request_cb(uint8_t rhport,
|
||||
tusb_control_request_t const* request);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue