#ifndef _USB_H_ #define _USB_H_ #include #include enum control_state {CONTROL_SETUP, CONTROL_DATA_TX, CONTROL_DATA_RX, CONTROL_STATUS_RX, CONTROL_STATUS_TX, CONTROL_NOT_HANDLED}; struct usb_descriptor_entry { uint16_t w_index; uint16_t w_value; const uint8_t *descriptor; uint32_t size; }; enum usb_ep_type { EP_CONTROL, EP_BULK, EP_ISOCHRON, EP_INTERRUPT }; struct setup_packet { uint8_t bm_req_type; uint8_t b_request; uint16_t w_value; uint16_t w_index; uint16_t w_length; }; struct usb_callbacks { void (*ep_rx_data_callback)(uint8_t endpoint, const uint8_t *buffer, uint32_t len); enum control_state (*ep_rx_setup_received_callback)(uint8_t endpoint, const struct setup_packet *setup_pkg); void (*ep_tx_complete_callback)(uint8_t endpoint); void (*usb_sof_callback)(void); void (*usb_reset_callback)(void); void (*usb_configured_callback)(uint16_t config_idx); }; void usb_init(const struct usb_callbacks *callbacks); void usb_enable(const struct usb_descriptor_entry *descriptors); void usb_endpoint_send_status_stage(uint8_t endpoint); void usb_endpoint_stall(uint8_t endpoint, bool tx_dir, bool rx_dir); void usb_endpoint_config(enum usb_ep_type type, uint8_t epnum, bool rx, bool tx); int usb_endpoint_prepare_receive(uint8_t endpoint, uint8_t *buffer, uint32_t bufflen); int usb_endpoint_send(uint8_t endpoint, const uint8_t *data, uint32_t len); #endif /* _USB_H_ */