Teensy 2.0 USB with Type: Mouse + Disk (SD Card) only?

Status
Not open for further replies.

MacGyver1100101

New member
Hello Paul.

I have a problem.

Is it possible to programm the Teensy 2.0 USB with Type: Mouse + Disk (SD Card) only?
Also no Serial, no Keyboard and no Joystick.
In Arduino 1.0.3 there is not such an option, i can choose.

If it is possible, please can you explain me, how to do it and send me the right files for that?

By the way, how can I implement 5 button mouse? 3 button I know is available. I mean left, middle, right button and back, forward button for example in internet browsers for sites.
 
Is it possible to programm the Teensy 2.0 USB with Type: Mouse + Disk (SD Card) only?
Also no Serial, no Keyboard and no Joystick.

It is possible, but not particularly easy. You'll need to edit the USB code.

If it is possible, please can you explain me, how to do it and send me the right files for that?

The files you need are installed inside your copy of Arduino, in hardware/teensy/cores. You'll probably work with the files in "usb_disk", and probably copy bits of the files from "usb_hid".

Unfortunately this is not quick and easy. The process basically involves 2 steps. First, you have a edit the descriptor data to tell your PC what type of device it should see. Then after your PC sees the right type of device, you edit the code to actually send that data.

The good news is the Disk type includes a keyboard. Mouse is very similar, so you'll first edit usb.c and try to replace the keyboard stuff with the equivalent mouse stuff. Most of the keyboard stuff contains "keyboard", so you can search, and then locate the similar code in usb_hid for mouse.

After you've got the descriptors built, you can probably just copy all the mouse stuff from usb_api.cpp and usb_api.h. Leaving the keyboard stuff in those files probably won't cause any trouble.


By the way, how can I implement 5 button mouse? 3 button I know is available. I mean left, middle, right button and back, forward button for example in internet browsers for sites.

Inside hardware/teensy/cores/usb_hid/usb.c, you'll find this code:

Code:
// Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
static const uint8_t PROGMEM mouse_hid_report_desc[] = {
        0x05, 0x01,                     // Usage Page (Generic Desktop)
        0x09, 0x02,                     // Usage (Mouse)
        0xA1, 0x01,                     // Collection (Application)
        0x05, 0x09,                     //   Usage Page (Button)
        0x19, 0x01,                     //   Usage Minimum (Button #1)
        0x29, 0x03,                     //   Usage Maximum (Button #3)
        0x15, 0x00,                     //   Logical Minimum (0)
        0x25, 0x01,                     //   Logical Maximum (1)
        0x95, 0x03,                     //   Report Count (3)
        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, 0x81,                     //   Logical Minimum (-127)
        0x25, 0x7F,                     //   Logical Maximum (127)
        0x75, 0x08,                     //   Report Size (8),
        0x95, 0x02,                     //   Report Count (2),
        0x81, 0x06,                     //   Input (Data, Variable, Relative)
        0x09, 0x38,                     //   Usage (Wheel)
        0x95, 0x01,                     //   Report Count (1),
        0x81, 0x06,                     //   Input (Data, Variable, Relative)
        0xC0                            // End Collection
};

Change the line with "Usage Maximum (Button #3)" to 5 (eg, change 0x03 to 0x05, and update the comment for documentation if you like). Also, change the line with "Report Size (5)" to 3. These are 5 empty bits used to pad the buttons part to 1 full byte. Because there's some extra unused bits, it's easy to expand up to 8 buttons.

This change tells your PC the mouse will send 5 buttons. Then you need to actually edit the code to put data into those other 2 bits. That code is in usb_api.cpp. Look for this:

Code:
void usb_mouse_class::click(uint8_t b)
{
        mouse_buttons = (b & 7);
        move(0, 0);
        mouse_buttons = 0;
        move(0, 0);
}

The "mouse_buttons" is the actual byte that gets transmitted. Just change the 7 to a 31, to allow 2 more bits. Then, of course, in your program add code to actually transmit the other button clicks.
 
O.K.. Thanks a lot. I try it by my self. But please help me if I do not get it to work. I see you know very much about this stuff. Respekt. I spend the whole sunday to try it.

I have still one more question.
Is it possible to program the teensy as a full mouse + Disk only and send keystrokes from keyboard. Only by the mouse driver. You know:

hidserv.dll,
hidclass.sys,
hidparse.sys,
hidusb.sys,
hid.dll,
mouclass.sys,
mouhid.sys.
 
Hi
Just came across this post & I have a similar question as I need both MIDI & Mouse support. Is the answer similar?
Right now Arduino won't let me use mouse.move commands with Teensy (only with Leonardo) :-(
Thanks
 
Yup, you need to edit the USB code to create combinations different than the ones in the menu.

The good news is usb_desc.h was recently improved (Teensy 3.x and LC) to make this much simpler. See the comments in that file for details.

On Teensy 2.0, the process is MUCH harder, and that MSC code for USB Disk is very complex. Sorry. Since then, I've learned from the errors of my earlier ways and I created an easier way for Teensy3.
 
Teensy2++ MIDI & Mouse

Yup, you need to edit the USB code to create combinations different than the ones in the menu.

The good news is usb_desc.h was recently improved (Teensy 3.x and LC) to make this much simpler. See the comments in that file for details.

On Teensy 2.0, the process is MUCH harder, and that MSC code for USB Disk is very complex. Sorry. Since then, I've learned from the errors of my earlier ways and I created an easier way for Teensy3.

Thanks. I am on Teensy2++. I have modified my usb_private.h in the hardware\teensy\cores\usb_midi directort as follow, but windows 9 doesn't recognise the USB Composite device, saying "This device cannot start. (Code 10) STATUS_DEVICE_DATA_ERROR". I guess I haven't modified usb_private.h properly?
I believe this file should make windows see a valid mouse. The usb code is a seperate issue???
Excuse my ignorance.......

File below:-
#ifndef usb_serial_h__
#define usb_serial_h__

#include <stdint.h>

#ifdef __cplusplus
extern "C"{
#endif

/**************************************************************************
*
* Configurable Options
*
**************************************************************************/

#define VENDOR_ID 0x16C0
#define PRODUCT_ID 0x0485
#define TRANSMIT_FLUSH_TIMEOUT 4 /* in milliseconds */
#define TRANSMIT_TIMEOUT 25 /* in milliseconds */


/**************************************************************************
*
* Endpoint Buffer Configuration
*
**************************************************************************/

// These buffer sizes are best for most applications, but perhaps if you
// want more buffering on some endpoint at the expense of others, this
// is where you can make such changes. The AT90USB162 has only 176 bytes
// of DPRAM (USB buffers) and only endpoints 3 & 4 can double buffer.


// 0: control
// 1: debug IN
// 2: debug OUT
// 3: midi IN
// 4: midi OUT
// 5: Mouse

#if defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)

// Some operating systems, especially Windows, may cache USB device
// info. Changes to the device name may not update on the same
// computer unless the vendor or product ID numbers change, or the
// "bcdDevice" revision code is increased.

#define STR_PRODUCT L"Teensy MIDI"
#define ENDPOINT0_SIZE 64

#define DEBUG_INTERFACE 1
#define DEBUG_TX_ENDPOINT 1
#define DEBUG_TX_SIZE 64
#define DEBUG_TX_BUFFER EP_DOUBLE_BUFFER
#define DEBUG_TX_INTERVAL 1
#define DEBUG_RX_ENDPOINT 2
#define DEBUG_RX_SIZE 32
#define DEBUG_RX_BUFFER EP_DOUBLE_BUFFER
#define DEBUG_RX_INTERVAL 2

#define MOUSE_INTERFACE 3
#define MOUSE_ENDPOINT 5
#define MOUSE_SIZE 8
#define MOUSE_BUFFER EP_DOUBLE_BUFFER
#define MOUSE_INTERVAL 1


#define MIDI_INTERFACE 0
#define MIDI_TX_ENDPOINT 3
#define MIDI_TX_SIZE 64
#define MIDI_TX_BUFFER EP_DOUBLE_BUFFER
#define MIDI_RX_ENDPOINT 4
#define MIDI_RX_SIZE 64
#define MIDI_RX_BUFFER EP_DOUBLE_BUFFER

#define NUM_ENDPOINTS 6
#define NUM_INTERFACE 3

#endif



// setup
void usb_init(void); // initialize everything
void usb_shutdown(void); // shut off USB

// variables
extern volatile uint8_t usb_configuration;
extern volatile uint8_t usb_suspended;
extern volatile uint8_t debug_flush_timer;
extern uint8_t mouse_buttons;

#ifdef __cplusplus
} // extern "C"
#endif

#endif
 
Status
Not open for further replies.
Back
Top