update teensy3 lib to latest, use new vector change mechanism
[megadrive.git] / teensy3 / usb_desc.c
index dba582d..0b1049e 100644 (file)
  * permit persons to whom the Software is furnished to do so, subject to
  * the following conditions:
  *
- * 1. The above copyright notice and this permission notice shall be 
+ * 1. The above copyright notice and this permission notice shall be
  * included in all copies or substantial portions of the Software.
  *
- * 2. If the Software is incorporated into a build system that allows 
+ * 2. If the Software is incorporated into a build system that allows
  * selection among a list of target devices, then similar target
  * devices manufactured by PJRC.COM must be included in the list of
  * target devices and selectable in the same manner.
  * SOFTWARE.
  */
 
+#if F_CPU >= 20000000
+
 #include "usb_desc.h"
+#ifdef NUM_ENDPOINTS
 #include "usb_names.h"
-#include "mk20dx128.h"
+#include "kinetis.h"
 #include "avr_functions.h"
 
 // USB Descriptors are binary data which the USB host reads to
@@ -158,31 +161,37 @@ static uint8_t mouse_report_desc[] = {
         0x05, 0x01,                     // Usage Page (Generic Desktop)
         0x09, 0x02,                     // Usage (Mouse)
         0xA1, 0x01,                     // Collection (Application)
+        0x85, 0x01,                     //   REPORT_ID (1)
         0x05, 0x09,                     //   Usage Page (Button)
         0x19, 0x01,                     //   Usage Minimum (Button #1)
-        0x29, 0x03,                     //   Usage Maximum (Button #3)
+        0x29, 0x08,                     //   Usage Maximum (Button #8)
         0x15, 0x00,                     //   Logical Minimum (0)
         0x25, 0x01,                     //   Logical Maximum (1)
-        0x95, 0x03,                     //   Report Count (3)
+        0x95, 0x08,                     //   Report Count (8)
         0x75, 0x01,                     //   Report Size (1)
         0x81, 0x02,                     //   Input (Data, Variable, Absolute)
-        0x95, 0x01,                     //   Report Count (1)
-        0x75, 0x05,                     //   Report Size (5)
-        0x81, 0x03,                     //   Input (Constant)
         0x05, 0x01,                     //   Usage Page (Generic Desktop)
         0x09, 0x30,                     //   Usage (X)
         0x09, 0x31,                     //   Usage (Y)
-        0x15, 0x00,                     //   Logical Minimum (0)
-        0x26, 0xFF, 0x7F,               //   Logical Maximum (32767)
-        0x75, 0x10,                     //   Report Size (16),
-        0x95, 0x02,                     //   Report Count (2),
-        0x81, 0x02,                     //   Input (Data, Variable, Absolute)
         0x09, 0x38,                     //   Usage (Wheel)
         0x15, 0x81,                     //   Logical Minimum (-127)
         0x25, 0x7F,                     //   Logical Maximum (127)
         0x75, 0x08,                     //   Report Size (8),
-        0x95, 0x01,                     //   Report Count (1),
+        0x95, 0x03,                     //   Report Count (3),
         0x81, 0x06,                     //   Input (Data, Variable, Relative)
+        0xC0,                           // End Collection
+        0x05, 0x01,                     // Usage Page (Generic Desktop)
+        0x09, 0x02,                     // Usage (Mouse)
+        0xA1, 0x01,                     // Collection (Application)
+        0x85, 0x02,                     //   REPORT_ID (2)
+        0x05, 0x01,                     //   Usage Page (Generic Desktop)
+        0x09, 0x30,                     //   Usage (X)
+        0x09, 0x31,                     //   Usage (Y)
+        0x15, 0x00,                     //   Logical Minimum (0)
+        0x26, 0xFF, 0x7F,               //   Logical Maximum (32767)
+        0x75, 0x10,                     //   Report Size (16),
+        0x95, 0x02,                     //   Report Count (2),
+        0x81, 0x02,                     //   Input (Data, Variable, Absolute)
         0xC0                            // End Collection
 };
 #endif
@@ -403,7 +412,7 @@ static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
         // MIDI MS Interface Header, USB MIDI 6.1.2.1, page 21, Table 6-2
         7,                                      // bLength
         0x24,                                   // bDescriptorType = CS_INTERFACE
-        0x01,                                   // bDescriptorSubtype = MS_HEADER 
+        0x01,                                   // bDescriptorSubtype = MS_HEADER
         0x00, 0x01,                             // bcdMSC = revision 01.00
         0x41, 0x00,                             // wTotalLength
         // MIDI IN Jack Descriptor, B.4.3, Table B-7 (embedded), page 40
@@ -442,7 +451,7 @@ static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
         0,                                      // iJack
         // Standard Bulk OUT Endpoint Descriptor, B.5.1, Table B-11, pae 42
         9,                                      // bLength
-        5,                                      // bDescriptorType = ENDPOINT 
+        5,                                      // bDescriptorType = ENDPOINT
         MIDI_RX_ENDPOINT,                       // bEndpointAddress
         0x02,                                   // bmAttributes (0x02=bulk)
         MIDI_RX_SIZE, 0,                        // wMaxPacketSize
@@ -457,7 +466,7 @@ static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
         1,                                      // BaAssocJackID(1) = jack ID #1
         // Standard Bulk IN Endpoint Descriptor, B.5.1, Table B-11, pae 42
         9,                                      // bLength
-        5,                                      // bDescriptorType = ENDPOINT 
+        5,                                      // bDescriptorType = ENDPOINT
         MIDI_TX_ENDPOINT | 0x80,                // bEndpointAddress
         0x02,                                   // bmAttributes (0x02=bulk)
         MIDI_TX_SIZE, 0,                        // wMaxPacketSize
@@ -728,6 +737,8 @@ void usb_init_serialnumber(void)
        while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
        num = *(uint32_t *)&FTFL_FCCOB7;
        __enable_irq();
+       // add extra zero to work around OS-X CDC-ACM driver bug
+       if (num < 10000000) num = num * 10;
        ultoa(num, buf, 10);
        for (i=0; i<10; i++) {
                char c = buf[i];
@@ -792,16 +803,16 @@ const usb_descriptor_list_t usb_descriptor_list[] = {
 // 0x19 = Recieve only
 // 0x15 = Transmit only
 // 0x1D = Transmit & Recieve
-// 
-const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] = 
+//
+const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
 {
-       0x00, 0x15, 0x19, 0x15, 0x00, 0x00, 0x00, 0x00, 
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+       0x00, 0x15, 0x19, 0x15, 0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 };
 #endif
 
 
-const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] = 
+const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
 {
 #if (defined(ENDPOINT1_CONFIG) && NUM_ENDPOINTS >= 1)
        ENDPOINT1_CONFIG,
@@ -881,5 +892,5 @@ const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
 };
 
 
-
-
+#endif // NUM_ENDPOINTS
+#endif // F_CPU >= 20 MHz