Commit 2ee55c31 authored by Damien George's avatar Damien George
Browse files

stm: Add option to pyb_usb_dev_init() to use USB HID interface.

With this option selected, only HID on its own works, not VCP+HID.
parent 790eed6f
......@@ -577,7 +577,7 @@ soft_reset:
pyb_usb_host_init();
#elif defined(USE_DEVICE_MODE)
// USB device
pyb_usb_dev_init();
pyb_usb_dev_init(PYB_USB_DEV_VCP_MSC);
#endif
// run main script
......
......@@ -73,6 +73,11 @@
#include "usbd_msc_bot.h"
#include "usbd_msc_mem.h"
// CDC VCP is the first interface
// the option below is supposed to select between MSC (1) and HID (0) for the
// second USB interface, but it does not work (only VCP+MSC works)
// to use HID on its own (ie no VCP), the functions in usbd_pyb_core2.c can be
// used, and selected in the call to pyb_usb_dev_init().
#define USB_PYB_USE_MSC (1)
#if USB_PYB_USE_MSC
......@@ -314,7 +319,7 @@ __ALIGN_BEGIN static uint8_t usbd_pyb_CfgDesc[USB_PYB_CONFIG_DESC_SIZ] __ALIGN_E
0x01, // bNumEndpoints
0x03, // bInterfaceClass: HID Class
0x01, // bInterfaceSubClass: 0=no boot, 1=BOOT
0x01, // nInterfaceProtocol: 0=none, 1=keyboard, 2=mouse
0x02, // nInterfaceProtocol: 0=none, 1=keyboard, 2=mouse
0x00, // iInterface:
// Descriptor of Joystick Mouse HID
......@@ -340,7 +345,7 @@ __ALIGN_BEGIN static uint8_t usbd_pyb_CfgDesc[USB_PYB_CONFIG_DESC_SIZ] __ALIGN_E
#endif
};
#if 0
#if !USB_PYB_USE_MSC
__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __ALIGN_END =
{
0x05, 0x01,
......@@ -559,6 +564,28 @@ static uint8_t usbd_pyb_Setup(void *pdev, USB_SETUP_REQ *req) {
// Standard Interface Request ------------------------------------------
case (USB_REQ_TYPE_STANDARD | USB_REQ_RECIPIENT_INTERFACE):
switch (req->bRequest) {
case USB_REQ_GET_DESCRIPTOR: // needed for HID; SU 0x81 0x06 0x2200 0x00 request
// wIndex & 0xff is the interface
if ((req->wIndex & 0xff) <= 1) {
// CDC VCP
} else {
#if USB_PYB_USE_MSC
#else
uint16_t len = 0;
uint8_t *pbuf = NULL;
if (req->wValue >> 8 == HID_REPORT_DESC) {
len = MIN(HID_MOUSE_REPORT_DESC_SIZE , req->wLength);
pbuf = HID_MOUSE_ReportDesc;
return USBD_CtlSendData(pdev, pbuf, len);
} else if( req->wValue >> 8 == HID_DESCRIPTOR_TYPE) {
pbuf = usbd_pyb_CfgDesc + /* skip VCP */ 0x09 + 0x08 + 0x09 + 0x05 + 0x05 + 0x04 + 0x05 + 0x07 + 0x09 + 0x07 + 0x07 + /* skip iface descr */ 0x09;
len = MIN(0x09, req->wLength);
return USBD_CtlSendData(pdev, pbuf, len);
}
#endif
}
break;
case USB_REQ_GET_INTERFACE:
// wIndex & 0xff is the interface
if ((req->wIndex & 0xff) <= 1) {
......
......@@ -28,12 +28,19 @@ static int rx_buf_out;
static int interrupt_char = VCP_CHAR_NONE;
mp_obj_t mp_const_vcp_interrupt = MP_OBJ_NULL;
void pyb_usb_dev_init(void) {
void pyb_usb_dev_init(int usb_dev_type) {
#ifdef USE_DEVICE_MODE
if (!dev_is_enabled) {
// only init USB once in the device's power-lifetime
USBD_Init(&USB_OTG_Core, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_PYB_cb, &USR_cb);
//USBD_Init(&USB_OTG_Core, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_PYB_HID_cb, &USR_cb);
switch (usb_dev_type) {
case PYB_USB_DEV_VCP_MSC:
USBD_Init(&USB_OTG_Core, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_PYB_cb, &USR_cb);
break;
case PYB_USB_DEV_HID:
USBD_Init(&USB_OTG_Core, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_PYB_HID_cb, &USR_cb);
break;
}
}
rx_buf_in = 0;
rx_buf_out = 0;
......
......@@ -4,7 +4,10 @@
#define VCP_CHAR_CTRL_C (3)
#define VCP_CHAR_CTRL_D (4)
void pyb_usb_dev_init(void);
#define PYB_USB_DEV_VCP_MSC (0)
#define PYB_USB_DEV_HID (1)
void pyb_usb_dev_init(int usb_dev_type);
bool usb_vcp_is_enabled(void);
bool usb_vcp_is_connected(void);
void usb_vcp_set_interrupt_char(int c);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment