#include "stm32f1xx.h"
#include "stm32f1xx_hal.h"
+#include "util.h"
#include "usb.h"
#include <string.h>
usb->hpcd = hpcd;
usb->state = USB_STATE_DEFAULT;
usb->ep0_state = USB_EP0_IDLE;
+ hpcd->pData = usb;
+}
- HAL_PCDEx_PMAConfig(hpcd, 0x00, PCD_SNG_BUF, 0x18);
- HAL_PCDEx_PMAConfig(hpcd, 0x80, PCD_SNG_BUF, 0x58);
+void usb_start(struct usb *usb)
+{
+ HAL_PCDEx_PMAConfig(usb->hpcd, 0x00, PCD_SNG_BUF, 0x18);
+ HAL_PCDEx_PMAConfig(usb->hpcd, 0x80, PCD_SNG_BUF, 0x58);
- HAL_PCD_Start(hpcd);
+ HAL_PCD_Start(usb->hpcd);
}
static inline uint get_u16(byte *p)
p[1] = x >> 8;
}
-#if 0 // FIXME
-static struct usb_endpoint *ep_by_addr(struct usb *usb, byte ep_addr)
-{
- return ((ep_addr & 0x80) ? usb->ep_in : usb->ep_out) + (ep_addr & 0x7f);
-}
-#endif
-
static void usb_ctl_send_status(struct usb *usb)
{
+ usb_debug("Control send: status\n");
usb->ep0_state = USB_EP0_STATUS_IN;
usb_ep_transmit(usb, 0x00, NULL, 0);
}
static void usb_ctl_send_data(struct usb *usb, const byte *data, uint len)
{
+ usb_debug("Control send: %u bytes\n", len);
usb->ep0_state = USB_EP0_DATA_IN;
usb->ep0_total_length = len;
usb->ep0_remaining_length = len;
#if 0 // FIXME
static void usb_ctl_recv_data(struct usb *usb, byte *data, uint len)
{
+ usb_debug("Control recv: %u bytes\n", len);
usb->ep0_state = USB_EP0_DATA_OUT;
usb->ep0_total_length = len;
usb->ep0_remaining_length = len;
static void usb_ctl_error(struct usb *usb)
{
+ usb_debug("Control packet error\n");
usb_ep_stall(usb, 0x00);
usb_ep_stall(usb, 0x80);
}
static void usb_ctl_setup_error(struct usb *usb, struct setup_request *setup)
{
+ usb_debug("Setup packet error\n");
usb_ep_stall(usb, setup->bmRequest & USB_REQ_DIRECTION);
}
static void usb_handle_setup(struct usb *usb, struct setup_request *setup)
{
+ usb_debug("Setup: type=%02x req=%02x val=%04x idx=%04x len=%04x\n", setup->bmRequest, setup->bRequest, setup->wValue, setup->wIndex, setup->wLength);
+
usb->ep0_state = USB_EP0_SETUP;
usb->ep0_setup_data_length = setup->wLength;
.bRequest = req[1],
.wValue = get_u16(req+2),
.wIndex = get_u16(req+4),
- .wLength = get_u16(req+2),
+ .wLength = get_u16(req+6),
};
usb_handle_setup(usb, &setup);
}