Shop OBEX P1 Docs P2 Docs Learn Events
P2 USB Host driver (re-)development thread - Page 15 — Parallax Forums

P2 USB Host driver (re-)development thread

191011121315»

Comments

  • Thank you for the git link. I have spent quite a bit of time learning USB (2.0) protocol for Host & Devices since I bought my P2. My goal is to learn the P2 using both spin2 (less) and pasm2 (more). My first project is to use two Logitech 3D joysticks to make it work using your USB Host libraries. This will help me to learn how other developers are coding and utilize existing libraries. I will have more questions during this journey and looking forward to get your and other developer's help. The first problem I was have is to how to connect my USB breakout board with P2 Edge. I couldn’t find any picture that shows, May be I haven’t search hard enough. I am trying to post a picture of my setup but somehow I can’t from my iPad. Anyway looking forward for some guidance. 🤓

  • If you have the official Parallax breakout you just kinda do this

    but by the fact you're asking I assume you have some sort of other contraption.

    The official board plugged in like that maps the pins as such:

    • P16: LED
    • P17: Power enable for upper port
    • P18: D- for upper port
    • P19: D+ for upper port
    • P20: LED
    • P21: Power enable for lower port
    • P22: D- for lower port
    • P23: D+ for lower port

    The usbnew driver by default is set up to use the upper port (it currently only supports one root port per instance, the lower port goes unused. Multiple devices need to go through a USB Hub)

      USB_BASE_PIN  = 16
      USB_ENABLE_OFFSET = 1 ' Set -1 if not present
      USB_DMINUS_OFFSET = 2 ' Must end up on an even pin. D+ is always this +1
    

    If you, say, just want the D-/D+ pair on P28/P29 and don't have an LED or a port protector chip, you'd use

      USB_BASE_PIN  = 28
      USB_ENABLE_OFFSET = -1
      USB_DMINUS_OFFSET = 0
    

    The only real restriction is that D- must be on an even-numbered pin and D+ must be the next pin after that.
    You could edit these values in usbnew.spin2, but the proper and elegant way that won't land you in developer hell is to use the constant override feature. See the example programs like hidpad_to_vga.spin2. That one should just work out of the box for connecting one (or up to 7 with an appropriate hub) of these Logitech sticks. Need to have a VGA breakout though to see it do anything.


  • Here is how I plugged my board in.

  • Wuerfel_21Wuerfel_21 Posts: 4,442
    edited 2023-11-25 20:43

    For this you just set USB_BASE_PIN = 0 and leave the other values as they are.

    However, DO NOT POWER IT UP LIKE THIS. DO NOT. THE 5V COULD TOUCH THE DATA PINS AND BAD THINGS WOULD HAPPEN

  • Don't jink my $7 logic analyzer ($15 for a pair) and working flawlessly with PulseView. :smiley:

  • mashaikh23mashaikh23 Posts: 23
    edited 2023-11-25 20:47

    @Wuerfel_21 said:
    For this you just set USB_BASE_PIN = 0 and leave the other values as they are.

    However, DO NOT POWER IT UP LIKE THIS. DO NOT. THE 5V COULD TOUCH THE DATA PINS AND BAD THINGS WOULD HAPPEN

    then for this board how or what pins should i use? Ok I can match the pin like you mentioned above for this board, right?

  • @mashaikh23 said:
    Don't jink my $7 logic analyzer ($15 for a pair) and working flawlessly with PulseView. :smiley:

    I have the same one, no shade. In action in another thread. However, Ubuntu's pulseview package is broken due to LTO, so I needed to install Debian's and now plasmashell thinks pulseview is touhou 10. This is completely irrelevant to anything, but the questions I have are infinite

  • Wuerfel_21Wuerfel_21 Posts: 4,442
    edited 2023-11-25 21:06

    @mashaikh23 said:
    then for this board how or what pins should i use? Ok I can match the pin like you mentioned above for this board, right?

    I mean the loose wire ends plugged into the breakout. If the 5V power pin touches any of the other pins, bad things might happen. Though this breakout has a protection chip that should tank the worst of it.

  • @Wuerfel_21 said:

    @mashaikh23 said:
    then for this board how or what pins should i use? Ok I can match the pin like you mentioned above for this board, right?

    I mean the loose wire ends plugged into the breakout. If the 5V power pin touches any of the other pins, bad things might happen. Thought this breakout has a protection chip that should tank the worst of it.

    Ok, got it. I removed it. Thanks

  • Anyways, if you can dig up a VGA breakout, I guess you should try running the example code now.

  • @Wuerfel_21 said:
    Anyways, if you can dig up a VGA breakout, I guess you should try running the example code now.

    i dont have a vga board so trying to comment out things to understand the code. what vga board do you have?

  • Wuerfel_21Wuerfel_21 Posts: 4,442
    edited 2023-11-25 21:59

    @mashaikh23 said:

    @Wuerfel_21 said:
    Anyways, if you can dig up a VGA breakout, I guess you should try running the example code now.

    i dont have a vga board so trying to comment out things to understand the code. what vga board do you have?

    I have the Parallax one with VGA and a bunch of other things on it. Though with VGA you can kinda just poke wires into the port on the monitor if need be. With the default definitions it's like this: P24 is HSync, P25 is blue, P26 is green, P27 is red and P28 is Vsync.

    If you're wondering why there's no demo that uses just the serial terminal... With the full 7 devices connected, there's quite a lot of data continuously updating and trying to print that to a scrolling terminal is slow and
    disorienting (especially when driver debug messages are also enabled).

  • @mashaikh23 said:

    @Wuerfel_21 said:
    Anyways, if you can dig up a VGA breakout, I guess you should try running the example code now.

    i dont have a vga board so trying to comment out things to understand the code. what vga board do you have?

    You can try the driver from my repository then:
    https://github.com/maccasoft/P2
    it is the pasm-only version from which usbnew is derived, and uses only the terminal and debug statements (plus there are a number of emulators using it, if you want some examples).
    It is a bit behind with the changes made to usbnew but should work more or less the same.

  • @macca said:
    It is a bit behind with the changes made to usbnew but should work more or less the same.

    For their particular application, it may not. I remember fixing a bug related to these newer Logitech sticks. 8AM brain can't remember what exactly it was.

  • @macca said:

    @mashaikh23 said:

    @Wuerfel_21 said:
    Anyways, if you can dig up a VGA breakout, I guess you should try running the example code now.

    i dont have a vga board so trying to comment out things to understand the code. what vga board do you have?

    You can try the driver from my repository then:
    https://github.com/maccasoft/P2
    it is the pasm-only version from which usbnew is derived, and uses only the terminal and debug statements (plus there are a number of emulators using it, if you want some examples).
    It is a bit behind with the changes made to usbnew but should work more or less the same.

    Great, thanks for the tip. I will check it out.

  • Ooo BTW I found this tool (USB Device Tree Viewer V3.8.9) (see link below) gives me ton of information about the USB device when connected my Windows 10. Using this I am surprised my Logitech joystick is a Low-speed but USB 1.1 device.
    https://www.uwe-sieber.de/usbtreeview_e.html#download

  • Wuerfel_21Wuerfel_21 Posts: 4,442
    edited 2023-11-26 20:19

    @mashaikh23 said:
    Using this I am surprised my Logitech joystick is a Low-speed but USB 1.1 device.

    >

    Higher USB spec version doesn't imply higher speed modes. This is a common misconception. I have some "USB 2.0 hubs" around. They indeed advertise version 2.0 in their device descriptor, but are only 12MHz full-speed devices. This is perfectly normal and allowed. But most people use "USB 2.0 Hub" to mean a high-speed hub. To be fair, they were actually advertising these as USB 1.1 hubs, to add to the confusion.

  • RaymanRayman Posts: 13,848

    Trying to recall... Have any of the USB drivers been tested with a Kb/mouse wireless combo?
    I seem to recall that previously only the kb would work, but it's been a while.

    Maybe now with hub support, they both would work?

  • Should work, yes.

Sign In or Register to comment.