Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Teensy 3.1 usb change on the flight

  1. #1
    Junior Member
    Join Date
    Jan 2015
    Location
    Belgium
    Posts
    2

    Teensy 3.1 usb change on the flight

    Hi, I would like to know if it is possible to change "usb-type" on the flight: say it emulates a keyboard, and when it gets a scrollLock, it changes vid/pid and becomes a mouse. (This is just an example) Also, could one use the 'raw' usb-specs (bLenght,...) in a sketch
    Thanks, Redfast

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,169
    Possible, yes. Easy, not so much.

    However, it's easy to be a composite device with both keyboard and mouse at the same time (and joystick too). Just select it in Arduino from the Tools > USB Type menu.

    If you really want to change device types at runtime, you're going to have a lot of programming work. All the existing code is designed to be only a fixed type. Of course, it is theoretically possible. You'll need to disconnect from the USB, which looks like a cable unplug to the PC. Then reconnect, and answer the descriptor requests with different data.

    The key piece of code is probably the usb_descriptor_list array, at line 758 in usb_desc.c.

    https://github.com/PaulStoffregen/co...sb_desc.c#L758

    When the PC requests a descriptor, the USB code reads this list to figure out what data to transmit. As you can see, it's declared as a const variable, and populated with fixed data. Perhaps if you change this to not be const, and re-write it with new info, that might do most of the work. Of course, you'll need to compose the 2 sets of descriptor data.

    If you're crafty, you'll use different endpoints and just keep the existing code for doing both at the same time. If the descriptors don't mention the mouse, the PC won't access that endpoint, even if the first is implementing it. Likewise for keyboard.

  3. #3
    Junior Member
    Join Date
    Jan 2015
    Location
    Belgium
    Posts
    2
    Ok, thanks. I'll have a look at it and see what I can do.

  4. #4
    Junior Member
    Join Date
    Mar 2017
    Posts
    3
    Hey,
    I'm want to accomplish something similar. Basically I'm want to make the device-descriptor changeable at runtime.

    The idee is to override the descriptor in usb_dev.c. But I'm not really sure if it will work. So I would like to use the hardwareserial libery code (which is already used there) so i could first figure out whats going on exactly.
    But the problem is I do not get any output at the uart.

    code i want to execute in usb_dev.c so I can make my research:
    Code:
    #if 1                
                    serial_print("Desc found, ");
                    serial_phex32((uint32_t)data);
                    serial_print(",");
                    serial_phex16(datalen);
                    serial_print(",");
                    serial_phex(data[0]);
                    serial_phex(data[1]);
                    serial_phex(data[2]);
                    serial_phex(data[3]);
                    serial_phex(data[4]);
                    serial_phex(data[5]);
                    serial_print("\n");
    #endif
    I use a ftdi board to get the serial communication to a picocom console. And its working if I do e.g. serial1.print('hello world'); but nothing from inside the usb_dev.c

    Maybe someone can tell me please what I am doing wrong?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •