PCD_HandleTypeDef *hpcd;
byte state; // USB_STATE_xxx
byte pre_suspend_state;
- byte address;
- byte config;
- byte remote_wakeup;
+ byte address; // Device address assigned by the host (0=none)
+ byte config; // Selected configuration (0=none)
+ byte remote_wakeup; // State of remote wakeup feature
+
+ // State of endpoint 00
byte ep0_state; // USB_EP0_xxx
u16 ep0_setup_data_length;
u16 ep0_remaining_length;
u16 ep0_total_length;
byte ep0_buf[USB_EP0_BUF_SIZE];
+
// Descriptor data to be filled by the user during usb_dev_reset()
const byte *desc_device;
const byte *desc_config;
u16 desc_config_len;
u16 desc_string_items;
u16 desc_languages_len;
+
+ // Internal use
+ u16 last_pma_alloc;
};
enum usb_device_state {
// Wrappers return HAL_OK / HAL_ERROR / HAL_BUSY / HAL_TIMEOUT
+// Call from configure callback
static inline HAL_StatusTypeDef usb_ep_open(struct usb *usb, byte ep_addr, byte ep_type, byte ep_max_size)
{
+ HAL_PCDEx_PMAConfig(usb->hpcd, ep_addr, PCD_SNG_BUF, usb->last_pma_alloc);
+ usb->last_pma_alloc += (ep_max_size + 7) & ~7U;
return HAL_PCD_EP_Open(usb->hpcd, ep_addr, ep_max_size, ep_type);
}
+// Call from unconfigure callback
static inline HAL_StatusTypeDef usb_ep_close(struct usb *usb, byte ep_addr)
{
return HAL_PCD_EP_Close(usb->hpcd, ep_addr);