@@ -29,6 +29,7 @@ | |||
#include "usb_midi.h" | |||
#include "usb_rawhid.h" | |||
#include "usb_flightsim.h" | |||
#include "usb_mtp.h" | |||
#include "usb_undef.h" // do not allow usb_desc.h stuff to leak to user programs | |||
//#include "WCharacter.h" |
@@ -379,7 +379,14 @@ static uint8_t flightsim_report_desc[] = { | |||
#define JOYSTICK_INTERFACE_DESC_SIZE 0 | |||
#endif | |||
#define CONFIG_DESC_SIZE JOYSTICK_INTERFACE_DESC_POS+JOYSTICK_INTERFACE_DESC_SIZE | |||
#define MTP_INTERFACE_DESC_POS JOYSTICK_INTERFACE_DESC_POS+JOYSTICK_INTERFACE_DESC_SIZE | |||
#ifdef MTP_INTERFACE | |||
#define MTP_INTERFACE_DESC_SIZE 9+7+7+7 | |||
#else | |||
#define MTP_INTERFACE_DESC_SIZE 0 | |||
#endif | |||
#define CONFIG_DESC_SIZE MTP_INTERFACE_DESC_POS+MTP_INTERFACE_DESC_SIZE | |||
@@ -757,6 +764,39 @@ static uint8_t config_descriptor[CONFIG_DESC_SIZE] = { | |||
JOYSTICK_INTERVAL, // bInterval | |||
#endif // JOYSTICK_INTERFACE | |||
#ifdef MTP_INTERFACE | |||
// interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12 | |||
9, // bLength | |||
4, // bDescriptorType | |||
MTP_INTERFACE, // bInterfaceNumber | |||
0, // bAlternateSetting | |||
3, // bNumEndpoints | |||
0x06, // bInterfaceClass (0x06 = still image) | |||
0x01, // bInterfaceSubClass | |||
0x01, // bInterfaceProtocol | |||
0, // iInterface | |||
// endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 | |||
7, // bLength | |||
5, // bDescriptorType | |||
MTP_TX_ENDPOINT | 0x80, // bEndpointAddress | |||
0x02, // bmAttributes (0x02=bulk) | |||
MTP_TX_SIZE, 0, // wMaxPacketSize | |||
0, // bInterval | |||
// endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 | |||
7, // bLength | |||
5, // bDescriptorType | |||
MTP_RX_ENDPOINT, // bEndpointAddress | |||
0x02, // bmAttributes (0x02=bulk) | |||
MTP_RX_SIZE, 0, // wMaxPacketSize | |||
0, // bInterval | |||
// endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 | |||
7, // bLength | |||
5, // bDescriptorType | |||
MTP_EVENT_ENDPOINT | 0x80, // bEndpointAddress | |||
0x03, // bmAttributes (0x03=intr) | |||
MTP_EVENT_SIZE, 0, // wMaxPacketSize | |||
MTP_EVENT_INTERVAL, // bInterval | |||
#endif // MTP_INTERFACE | |||
}; | |||
@@ -304,6 +304,37 @@ let me know? http://forum.pjrc.com/forums/4-Suggestions-amp-Bug-Reports | |||
#define ENDPOINT3_CONFIG ENDPOINT_TRANSIMIT_ONLY | |||
#define ENDPOINT4_CONFIG ENDPOINT_RECEIVE_ONLY | |||
#elif defined(USB_MTPDISK) | |||
#define VENDOR_ID 0x16C0 | |||
#define PRODUCT_ID 0x0489 | |||
#define MANUFACTURER_NAME {'T','e','e','n','s','y','d','u','i','n','o'} | |||
#define MANUFACTURER_NAME_LEN 11 | |||
#define PRODUCT_NAME {'T','e','e','n','s','y',' ','M','T','P',' ','D','i','s','k'} | |||
#define PRODUCT_NAME_LEN 15 | |||
#define EP0_SIZE 64 | |||
#define NUM_ENDPOINTS 4 | |||
#define NUM_USB_BUFFERS 20 | |||
#define NUM_INTERFACE 2 | |||
#define MTP_INTERFACE 0 // MTP Disk | |||
#define MTP_TX_ENDPOINT 3 | |||
#define MTP_TX_SIZE 64 | |||
#define MTP_RX_ENDPOINT 3 | |||
#define MTP_RX_SIZE 64 | |||
#define MTP_EVENT_ENDPOINT 4 | |||
#define MTP_EVENT_SIZE 16 | |||
#define MTP_EVENT_INTERVAL 10 | |||
#define SEREMU_INTERFACE 1 // Serial emulation | |||
#define SEREMU_TX_ENDPOINT 1 | |||
#define SEREMU_TX_SIZE 64 | |||
#define SEREMU_TX_INTERVAL 1 | |||
#define SEREMU_RX_ENDPOINT 2 | |||
#define SEREMU_RX_SIZE 32 | |||
#define SEREMU_RX_INTERVAL 2 | |||
#define ENDPOINT1_CONFIG ENDPOINT_TRANSIMIT_ONLY | |||
#define ENDPOINT2_CONFIG ENDPOINT_RECEIVE_ONLY | |||
#define ENDPOINT3_CONFIG ENDPOINT_TRANSMIT_AND_RECEIVE | |||
#define ENDPOINT4_CONFIG ENDPOINT_RECEIVE_ONLY | |||
#endif | |||
#ifdef USB_DESC_LIST_DEFINE |
@@ -277,7 +277,7 @@ static void usb_setup(void) | |||
endpoint0_stall(); | |||
return; | |||
} | |||
(*(uint8_t *)(&USB0_ENDPT0 + setup.wIndex * 4)) &= ~0x02; | |||
(*(uint8_t *)(&USB0_ENDPT0 + i * 4)) &= ~0x02; | |||
// TODO: do we need to clear the data toggle here? | |||
break; | |||
case 0x0302: // SET_FEATURE (endpoint) | |||
@@ -287,7 +287,7 @@ static void usb_setup(void) | |||
endpoint0_stall(); | |||
return; | |||
} | |||
(*(uint8_t *)(&USB0_ENDPT0 + setup.wIndex * 4)) |= 0x02; | |||
(*(uint8_t *)(&USB0_ENDPT0 + i * 4)) |= 0x02; | |||
// TODO: do we need to clear the data toggle here? | |||
break; | |||
case 0x0680: // GET_DESCRIPTOR | |||
@@ -341,6 +341,21 @@ static void usb_setup(void) | |||
return; | |||
#endif | |||
#if defined(MTP_INTERFACE) | |||
case 0x2164: // Cancel Request (PTP spec, 5.2.1, page 8) | |||
// TODO: required by PTP spec | |||
endpoint0_stall(); | |||
return; | |||
case 0x2166: // Device Reset (PTP spec, 5.2.3, page 10) | |||
// TODO: required by PTP spec | |||
endpoint0_stall(); | |||
return; | |||
case 0x2167: // Get Device Statis (PTP spec, 5.2.4, page 10) | |||
// TODO: required by PTP spec | |||
endpoint0_stall(); | |||
return; | |||
#endif | |||
// TODO: this does not work... why? | |||
#if defined(SEREMU_INTERFACE) || defined(KEYBOARD_INTERFACE) | |||
case 0x0921: // HID SET_REPORT |
@@ -0,0 +1,51 @@ | |||
/* Teensyduino Core Library | |||
* http://www.pjrc.com/teensy/ | |||
* Copyright (c) 2015 PJRC.COM, LLC. | |||
* | |||
* Permission is hereby granted, free of charge, to any person obtaining | |||
* a copy of this software and associated documentation files (the | |||
* "Software"), to deal in the Software without restriction, including | |||
* without limitation the rights to use, copy, modify, merge, publish, | |||
* distribute, sublicense, and/or sell copies of the Software, and to | |||
* 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 | |||
* included in all copies or substantial portions of the Software. | |||
* | |||
* 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. | |||
* | |||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | |||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||
* SOFTWARE. | |||
*/ | |||
#include "usb_dev.h" | |||
#include "usb_mtp.h" | |||
#include "core_pins.h" // for yield() | |||
#include "HardwareSerial.h" | |||
#ifdef MTP_INTERFACE // defined by usb_dev.h -> usb_desc.h | |||
#if F_CPU >= 20000000 | |||
void usb_mtp_update(void) | |||
{ | |||
serial_print("test\n"); | |||
// TODO: a lot of work here.... | |||
} | |||
#endif // F_CPU | |||
#endif // MTP_INTERFACE |
@@ -0,0 +1,73 @@ | |||
/* Teensyduino Core Library | |||
* http://www.pjrc.com/teensy/ | |||
* Copyright (c) 2013 PJRC.COM, LLC. | |||
* | |||
* Permission is hereby granted, free of charge, to any person obtaining | |||
* a copy of this software and associated documentation files (the | |||
* "Software"), to deal in the Software without restriction, including | |||
* without limitation the rights to use, copy, modify, merge, publish, | |||
* distribute, sublicense, and/or sell copies of the Software, and to | |||
* 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 | |||
* included in all copies or substantial portions of the Software. | |||
* | |||
* 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. | |||
* | |||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | |||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||
* SOFTWARE. | |||
*/ | |||
#ifndef USB_MTP_h_ | |||
#define USB_MTP_h_ | |||
#include "usb_desc.h" | |||
#if defined(MTP_INTERFACE) | |||
#include <inttypes.h> | |||
// C language implementation | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
void usb_mtp_update(void); | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
// C++ interface | |||
#ifdef __cplusplus | |||
class usb_mpt_class | |||
{ | |||
public: | |||
void begin(void) { } | |||
void end(void) { } | |||
void update() __attribute__((always_inline)) { | |||
usb_mtp_update(); | |||
} | |||
private: | |||
}; | |||
extern usb_mpt_class MTPDisk; | |||
#endif // __cplusplus | |||
#endif // MTP_INTERFACE | |||
#endif // USB_MTP_h_ | |||
@@ -185,6 +185,30 @@ | |||
#ifdef FLIGHTSIM_RX_SIZE | |||
#undef FLIGHTSIM_RX_SIZE | |||
#endif | |||
#ifdef MTP_INTERFACE | |||
#undef MTP_INTERFACE | |||
#endif | |||
#ifdef MTP_TX_ENDPOINT | |||
#undef MTP_TX_ENDPOINT | |||
#endif | |||
#ifdef MTP_TX_SIZE | |||
#undef MTP_TX_SIZE | |||
#endif | |||
#ifdef MTP_RX_ENDPOINT | |||
#undef MTP_RX_ENDPOINT | |||
#endif | |||
#ifdef MTP_RX_SIZE | |||
#undef MTP_RX_SIZE | |||
#endif | |||
#ifdef MTP_EVENT_ENDPOINT | |||
#undef MTP_EVENT_ENDPOINT | |||
#endif | |||
#ifdef MTP_EVENT_SIZE | |||
#undef MTP_EVENT_SIZE | |||
#endif | |||
#ifdef MTP_EVENT_INTERVAL | |||
#undef MTP_EVENT_INTERVAL | |||
#endif | |||
#ifdef ENDPOINT1_CONFIG | |||
#undef ENDPOINT1_CONFIG | |||
#endif |