diff options
| author | root <root@no.no.james.local> | 2015-07-15 20:17:30 +0100 | 
|---|---|---|
| committer | root <root@no.no.james.local> | 2015-07-15 20:17:30 +0100 | 
| commit | 39044e272695c5f9c43a0560ae00ea440881d464 (patch) | |
| tree | 666d206036ceae71058bd9617d215fd83da63358 | |
| parent | 500561f54adabc9aaf5b3548744b5bc8b4381c89 (diff) | |
| download | stm32_usb_kvm-39044e272695c5f9c43a0560ae00ea440881d464.tar.gz stm32_usb_kvm-39044e272695c5f9c43a0560ae00ea440881d464.tar.bz2 stm32_usb_kvm-39044e272695c5f9c43a0560ae00ea440881d464.zip | |
from-nofrom-no
| -rw-r--r-- | app/dfu.c | 2 | ||||
| -rw-r--r-- | app/keyboard.c | 28 | ||||
| -rw-r--r-- | app/kvm.c | 14 | ||||
| -rw-r--r-- | app/mouse.c | 24 | ||||
| -rw-r--r-- | app/project.h | 2 | ||||
| -rw-r--r-- | app/tablet.c | 22 | ||||
| -rw-r--r-- | app/usb.c | 13 | 
7 files changed, 84 insertions, 21 deletions
| @@ -22,7 +22,7 @@ const struct usb_interface_descriptor dfu_iface = {    .bInterfaceClass = 0xFE,    .bInterfaceSubClass = 1,    .bInterfaceProtocol = 1, -  .iInterface = 0, +  .iInterface = 8,    .extra = &dfu_function,    .extralen = sizeof (dfu_function), diff --git a/app/keyboard.c b/app/keyboard.c index 9799629..b4727a8 100644 --- a/app/keyboard.c +++ b/app/keyboard.c @@ -56,14 +56,30 @@ static const uint8_t keyboard_report_descriptor[] = {    0x95, 0x06,                   /*     Report count (6) */    0x75, 0x08,                   /*     Report size (8) */    0x15, 0x00,                   /*     Logical minimum (0) */ -  0x25, 0x65,                   /*     Logical maximum (101) */ +  //0x25, 0x65,                   /*     Logical maximum (101) */ +  //0x25, 0x7f,                   /*     Logical maximum (127) */ +  0x26, 0xff, 0x00,             /*     Logical maximum (255) */    0x05, 0x07,                   /*   Usage page (key codes) */    0x19, 0x00,                   /*     Usage minimum (0) */    0x2A, 0xff, 0x00,             /*     Usage maximum (255) */  //  0x29, 0x65,                   /*     Usage maximum (101) */  //  0x2A, 0xff, 0x03,             /*     Usage maximum (1023) */    0x81, 0x00,                   /*   Input (data, array) */ -  0xC0                          /* End Collection */ +  	0x05, 0x01,		/*   USAGE_PAGE (Generic Desktop)      */ +	0x09, 0x80,		/*   USAGE (System Control)            */ +	0xA1, 0x01,		/*   COLLECTION (Application)          */ +	0x75, 0x02,		/*   REPORT_SIZE (2)                   */ +	0x95, 0x01,		/*   REPORT_COUNT (1)                  */ +	0x15, 0x01,		/*   LOGICAL_MIN (1)                   */ +	0x25, 0x03,		/*   LOGICAL_MAX (3)                   */ +	0x09, 0x82,		/*   USAGE (System Sleep)              */ +	0x09, 0x81,		/*   USAGE (System Power Down)         */ +	0x09, 0x83,		/*   USAGE (System Wake Up)            */ +	0x81, 0x60,		/*   INPUT (Data Ary Abs NPrf Null)    */ +	0x75, 0x06,		/*   REPORT_SIZE (6)                   */ +	0x81, 0x03,		/*   INPUT (Cnst Var Abs)              */ +        0xc0,                   /*   END COLLECTION                    */ +0xC0                          /* End Collection */  }; @@ -92,7 +108,7 @@ const struct usb_endpoint_descriptor keyboard_endpoint = {    .bDescriptorType = USB_DT_ENDPOINT,    .bEndpointAddress = 0x81,    .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, -  .wMaxPacketSize = 8, +  .wMaxPacketSize = 9,    .bInterval = 0x1 //0x20,  }; @@ -105,7 +121,7 @@ const struct usb_interface_descriptor keyboard_iface = {    .bInterfaceClass = USB_CLASS_HID,    .bInterfaceSubClass = 1,      /* boot */    .bInterfaceProtocol = 1,      /* keyboard */ -  .iInterface = 0, +  .iInterface = 5,    .endpoint = &keyboard_endpoint, @@ -127,7 +143,7 @@ void  keyboard_test (void)  {    static int c = 0; -  uint8_t buf[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; +  uint8_t buf[9] = { 0, 0, 0, 0, 0, 0, 0, 0 ,0};    buf[0] = (c >> 1) & 7; @@ -136,5 +152,5 @@ keyboard_test (void)    c++; -  usbd_ep_write_packet (usbd_dev, 0x81, buf, 8); +  usbd_ep_write_packet (usbd_dev, 0x81, buf, 9);  } @@ -31,7 +31,19 @@ kvm_dispatch (void)  	led_set(GPIO8);      else   	led_set(GPIO9); -    usbd_ep_write_packet (usbd_dev, endpoint, buf, len); + +    if (endpoint==0x84) { +        SET_REG(USB_CNTR_REG, USB_CNTR_RESETM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM | USB_CNTR_RESUME); +    { +  int i; +  for (i = 0; i < 0x80000; i++) +    __asm__ ("nop"); +  } + +    SET_REG(USB_CNTR_REG, USB_CNTR_RESETM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM); +    } else { +     usbd_ep_write_packet (usbd_dev, endpoint, buf, len); +    }    }  } diff --git a/app/mouse.c b/app/mouse.c index 0431349..0b90f1f 100644 --- a/app/mouse.c +++ b/app/mouse.c @@ -38,7 +38,21 @@ static const uint8_t mouse_report_descriptor[] = {    0x75, 0x06,                   /*   REPORT_SIZE (6)                    */    0x95, 0x01,                   /*   REPORT_COUNT (1)                   */    0xb1, 0x01,                   /*   FEATURE (Cnst,Ary,Abs)             */ -  0xc0                          /* END_COLLECTION                       */ +  	0x05, 0x01,		/*   USAGE_PAGE (Generic Desktop)      */ +	0x09, 0x80,		/*   USAGE (System Control)            */ +	0xA1, 0x01,		/*   COLLECTION (Application)          */ +	0x75, 0x02,		/*   REPORT_SIZE (2)                   */ +	0x95, 0x01,		/*   REPORT_COUNT (1)                  */ +	0x15, 0x01,		/*   LOGICAL_MIN (1)                   */ +	0x25, 0x03,		/*   LOGICAL_MAX (3)                   */ +	0x09, 0x82,		/*   USAGE (System Sleep)              */ +	0x09, 0x81,		/*   USAGE (System Power Down)         */ +	0x09, 0x83,		/*   USAGE (System Wake Up)            */ +	0x81, 0x60,		/*   INPUT (Data Ary Abs NPrf Null)    */ +	0x75, 0x06,		/*   REPORT_SIZE (6)                   */ +	0x81, 0x03,		/*   INPUT (Cnst Var Abs)              */ +        0xc0,                   /*   END COLLECTION                    */ +0xc0                          /* END_COLLECTION                       */  };  static const struct @@ -66,7 +80,7 @@ const struct usb_endpoint_descriptor mouse_endpoint = {    .bDescriptorType = USB_DT_ENDPOINT,    .bEndpointAddress = 0x82,    .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, -  .wMaxPacketSize = 4, +  .wMaxPacketSize = 5,    .bInterval = 0x1, //0x20,  }; @@ -79,7 +93,7 @@ const struct usb_interface_descriptor mouse_iface = {    .bInterfaceClass = USB_CLASS_HID,    .bInterfaceSubClass = 1,      /* boot */    .bInterfaceProtocol = 2,      /* mouse */ -  .iInterface = 0, +  .iInterface = 6,    .endpoint = &mouse_endpoint, @@ -101,7 +115,7 @@ void  mouse_test (void)  {    static int c = 1; -  uint8_t buf[4] = { 0, 0, 0, 0 }; +  uint8_t buf[5] = { 0, 0, 0, 0 };    buf[0] = c & 7; @@ -111,5 +125,5 @@ mouse_test (void)    c++; -  usbd_ep_write_packet (usbd_dev, 0x82, buf, 4); +  usbd_ep_write_packet (usbd_dev, 0x82, buf, 5);  } diff --git a/app/project.h b/app/project.h index a1849df..b224c78 100644 --- a/app/project.h +++ b/app/project.h @@ -2,12 +2,14 @@  #include <libopencm3/stm32/rcc.h>  #include <libopencm3/stm32/gpio.h>  #include <libopencm3/stm32/usart.h> +#include <libopencm3/stm32/usb.h>  #include <libopencm3/cm3/systick.h>  #include <libopencm3/cm3/nvic.h>  #include <libopencm3/usb/usbd.h>  #include <libopencm3/usb/hid.h>  #include <libopencm3/cm3/cortex.h> +  #define INCLUDE_DFU_INTERFACE diff --git a/app/tablet.c b/app/tablet.c index 5445c29..9fec20f 100644 --- a/app/tablet.c +++ b/app/tablet.c @@ -44,6 +44,20 @@ static const uint8_t tablet_report_descriptor[] = {    0x75, 0x06,                   //   REPORT_SIZE (6)    0x95, 0x01,                   //   REPORT_COUNT (1)    0xb1, 0x01,                   //   FEATURE (Cnst,Ary,Abs) +	0x05, 0x01,		/*   USAGE_PAGE (Generic Desktop)      */ +	0x09, 0x80,		/*   USAGE (System Control)            */ +	0xA1, 0x01,		/*   COLLECTION (Application)          */ +	0x75, 0x02,		/*   REPORT_SIZE (2)                   */ +	0x95, 0x01,		/*   REPORT_COUNT (1)                  */ +	0x15, 0x01,		/*   LOGICAL_MIN (1)                   */ +	0x25, 0x03,		/*   LOGICAL_MAX (3)                   */ +	0x09, 0x82,		/*   USAGE (System Sleep)              */ +	0x09, 0x81,		/*   USAGE (System Power Down)         */ +	0x09, 0x83,		/*   USAGE (System Wake Up)            */ +	0x81, 0x60,		/*   INPUT (Data Ary Abs NPrf Null)    */ +	0x75, 0x06,		/*   REPORT_SIZE (6)                   */ +	0x81, 0x03,		/*   INPUT (Cnst Var Abs)              */ +        0xc0,                   /*   END COLLECTION                    */    0xc0                          // END_COLLECTION  }; @@ -72,7 +86,7 @@ const struct usb_endpoint_descriptor tablet_endpoint = {    .bDescriptorType = USB_DT_ENDPOINT,    .bEndpointAddress = 0x83,    .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, -  .wMaxPacketSize = 6, +  .wMaxPacketSize = 7,    .bInterval = 0x1 //0x20,  }; @@ -85,7 +99,7 @@ const struct usb_interface_descriptor tablet_iface = {    .bInterfaceClass = USB_CLASS_HID,    .bInterfaceSubClass = 1,      /* boot */    .bInterfaceProtocol = 2,      /* tablet */ -  .iInterface = 0, +  .iInterface = 7,    .endpoint = &tablet_endpoint, @@ -107,7 +121,7 @@ void  tablet_test (void)  {    static int c = 0; -  uint8_t buf[6] = { 0, 0, 0, 0, 0 }; +  uint8_t buf[7] = { 0, 0, 0, 0, 0 ,0};    buf[0] = c & 0xff;    buf[1] = (c & 0x7fff) >> 8; @@ -118,5 +132,5 @@ tablet_test (void)    c++; -  usbd_ep_write_packet (usbd_dev, 0x83, buf, 6); +  usbd_ep_write_packet (usbd_dev, 0x83, buf, 7);  } @@ -49,9 +49,9 @@ const struct usb_config_descriptor config = {    .bNumInterfaces = 3,  #endif    .bConfigurationValue = 1, -  .iConfiguration = 0, -  .bmAttributes = 0xC0, -  .bMaxPower = 0x32, +  .iConfiguration = 4, +  .bmAttributes = 0xa0, +  .bMaxPower = 0x31,    .interface = ifaces,  }; @@ -60,6 +60,11 @@ static const char *usb_strings[] = {    "Cabbages are good for you",    "fish",    "soup", +  "kvm composite", +  "kvm keyboard", +  "kvm mouse", +  "kvm tablet", +  "kvm dfu device",  }; @@ -131,7 +136,7 @@ usb_init (void)  {    usbd_dev = -    usbd_init (&stm32f103_usb_driver, &dev, &config, usb_strings, 3, +    usbd_init (&stm32f103_usb_driver, &dev, &config, usb_strings, 8,                 usbd_control_buffer, sizeof (usbd_control_buffer));    usbd_register_set_config_callback (usbd_dev, usb_set_config); | 
