X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=Inc%2Fusb.h;h=1d8291ff61e53a580a8be62fcd66bac1e1d1d86c;hb=1de7d1160ef286ba7ba1c63d7ecab977bdf2362d;hp=589774d6af50e02404e6fa48976edcc392e6f049;hpb=514b48b7205e1be5e1b0fc66bc073aa724dd98c9;p=home-hw.git diff --git a/Inc/usb.h b/Inc/usb.h index 589774d..1d8291f 100644 --- a/Inc/usb.h +++ b/Inc/usb.h @@ -1,4 +1,5 @@ #define USB_SELF_POWERED +#define USB_NUM_CONFIGURATIONS 1 typedef unsigned int uint; typedef uint8_t byte; @@ -12,6 +13,17 @@ typedef int32_t s32; /*** 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 @@ -23,7 +35,7 @@ struct usb { 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); @@ -144,9 +156,9 @@ static inline int usb_ep_is_stalled(struct usb *usb, byte ep_addr) 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)