67 lines
1.8 KiB
C
67 lines
1.8 KiB
C
|
|
#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
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Given an endpoint configuration, returns true if the endpoint
|
||
|
|
* is transmitting data to the host (i.e. is an IN endpoint)
|
||
|
|
*
|
||
|
|
* @param ep, the endpoint configuration
|
||
|
|
* @return true
|
||
|
|
* @return false
|
||
|
|
*/
|
||
|
|
static inline int ep_is_tx(struct usb_endpoint_configuration *ep) {
|
||
|
|
return ep->descriptor->bEndpointAddress & USB_DIR_IN;
|
||
|
|
}
|
||
|
|
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__ */
|