#define USB_SELF_POWERED
+#define USB_NUM_CONFIGURATIONS 1
typedef unsigned int uint;
typedef uint8_t byte;
/*** USB state structure ***/
+/*
+ * We have a single buffer for all control transfers.
+ * It must be able to contain:
+ *
+ * - 2-byte status replies
+ * - UTF-16 versions of all string descriptors
+ *
+ * In addition to that, its length must be even.
+ */
+#define USB_EP0_BUF_SIZE 256
+
struct usb {
PCD_HandleTypeDef *hpcd;
byte state; // USB_STATE_xxx
u16 ep0_setup_data_length;
u16 ep0_remaining_length;
u16 ep0_total_length;
- byte status_buf[2];
+ byte ep0_buf[USB_EP0_BUF_SIZE];
};
void usb_init(struct usb *usb, PCD_HandleTypeDef *hpcd);
return ((ep_addr & 0x80) ? usb->hpcd->IN_ep : usb->hpcd->OUT_ep) [ep_addr & 0x7f].is_stall;
}
-static inline HAL_StatusTypeDef usb_ep_transmit(struct usb *usb, byte ep_addr, byte *buf, u32 size)
+static inline HAL_StatusTypeDef usb_ep_transmit(struct usb *usb, byte ep_addr, const byte *buf, u32 size)
{
- return HAL_PCD_EP_Transmit(usb->hpcd, ep_addr, buf, size);
+ return HAL_PCD_EP_Transmit(usb->hpcd, ep_addr, (byte *) buf, size);
}
static inline HAL_StatusTypeDef usb_ep_receive(struct usb *usb, byte ep_addr, byte *buf, u32 size)