rp2040/driver/inc/usb.h

57 lines
1.5 KiB
C
Raw Normal View History

2025-03-29 22:24:07 +08:00
#ifndef __HARDWARE_USB_H__
#define __HARDWARE_USB_H__
#include "usb_reg.h"
#include "usb_common.h"
typedef void (*usb_ep_handler)(uint8_t *buf, uint16_t len);
// Struct in which we keep the endpoint configuration
struct usb_endpoint_configuration {
const struct usb_endpoint_descriptor *descriptor;
usb_ep_handler handler;
// Pointers to endpoint + buffer control registers
// in the USB controller DPSRAM
volatile uint32_t *endpoint_control;
volatile uint32_t *buffer_control;
volatile uint8_t *data_buffer;
// Toggle after each packet (unless replying to a SETUP)
uint8_t next_pid;
};
// Struct in which we keep the device configuration
struct usb_device_configuration {
const struct usb_device_descriptor *device_descriptor;
const struct usb_interface_descriptor *interface_descriptor;
const struct usb_configuration_descriptor *config_descriptor;
const unsigned char *lang_descriptor;
const unsigned char **descriptor_strings;
// USB num endpoints is 16
struct usb_endpoint_configuration endpoints[USB_NUM_ENDPOINTS];
};
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif
#ifndef MAX
#define MAX(a,b) ((a)>(b)?(a):(b))
#endif
int usb_is_configured(void);
2025-03-29 22:24:07 +08:00
void usb_start_transfer(struct usb_endpoint_configuration *ep, uint8_t *buf, uint16_t len);
void usb_device_init(struct usb_device_configuration *dev_config);
struct usb_endpoint_configuration *usb_get_endpoint_configuration(uint8_t addr);
#ifdef __cplusplus
}
#endif
#endif /* __HARDWARE_USB_H__ */