pi-topUtils 1.05

Keyboard/HID driver and battery indicator for pi-top laptops
Vanfanel
Posts: 576
Joined: Mon Sep 16, 2013 12:01 am

Re: pi-top utilities

Post by Vanfanel »

@Jon: I have no USB4, but USB7, where the keyboard seems to live. This is what USBDescriptors says about it (Maybe I had it connected to a different USB port last time!):

Code: Select all

USBDescriptors v1.06 (29-Mar-2018)

Computer
  |
  +-1.USB1: , Synopsys DWC OTG root hub
      |
      +-1.USB2: Hub
          |
          +-1.USB3: Hub
              |
              +-1.USB5:
              |
              +-3.USB7: SINO WEALTH, USB KEYBOARD


=============================================
 Device USB7
=============================================
:  0 :  2 : total size of ServiceCall block : 111
:  2 :  2 : offset to descriptor list       : 0x20
:  4 : 20 : name                            : USB7
: 24 :  1 : bus number                      : 1
: 25 :  1 : device address                  : 4
: 26 :  1 : host address                    : 3
: 27 :  1 : host port                       : 3
: 28 :  1 : speed                           : 1 low speed
---------------------------------------------

 Standard Device Descriptor
+----+----+---------------------------+----------+------------+
:Off :Sz  :Name                       :Value hex :Value dec   :
+----+----+---------------------------+----------+------------+
:  0 :  1 : bLength                   :       12 :         18 :
:  1 :  1 : bDescriptorType           :        1 :          1 :
:  2 :  2 : bcdUSB                    :      110 :        272 :
:  4 :  1 : bDeviceClass              :        0 :          0 :
:  5 :  1 : bDeviceSubClass           :        0 :          0 :
:  6 :  1 : bDeviceProtocol           :        0 :          0 :
:  7 :  1 : bMaxPacketSize            :        8 :          8 :
:  8 :  2 : idVendor                  :     258a :       9610 :
: 10 :  2 : idProduct                 :     6a88 :      27272 :
: 12 :  2 : bcdDevice                 :      100 :        256 :
: 14 :  1 : iManufacturer             :        1 :          1 : 'SINO WEALTH'
: 15 :  1 : iProduct                  :        2 :          2 : 'USB KEYBOARD'
: 16 :  1 : iSerialNumber             :        0 :          0 : ''
: 17 :  1 : bNumConfigurations        :        1 :          1 :
+----+----+---------------------------+----------+------------+

Regarding the USB drives hanging the computer while Pitop-Utils is loaded: Commenting out the pitopUtils Module RMLoad line, there's no more hanging...
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: pi-top utilities

Post by JonAbbott »

You're missing the key bit that follows, that describes the interface. I'll need everything up to the next Device, or to the end of the file if its the last USB device.
Vanfanel
Posts: 576
Joined: Mon Sep 16, 2013 12:01 am

Re: pi-top utilities

Post by Vanfanel »

@Jon: Tell me if this is what you need. This is all I get for USB7...

Code: Select all

=============================================
 Device USB7
=============================================
:  0 :  2 : total size of ServiceCall block : 111
:  2 :  2 : offset to descriptor list       : 0x20
:  4 : 20 : name                            : USB7
: 24 :  1 : bus number                      : 1
: 25 :  1 : device address                  : 4
: 26 :  1 : host address                    : 3
: 27 :  1 : host port                       : 3
: 28 :  1 : speed                           : 1 low speed
---------------------------------------------

 Standard Device Descriptor
+----+----+---------------------------+----------+------------+
:Off :Sz  :Name                       :Value hex :Value dec   :
+----+----+---------------------------+----------+------------+
:  0 :  1 : bLength                   :       12 :         18 :
:  1 :  1 : bDescriptorType           :        1 :          1 :
:  2 :  2 : bcdUSB                    :      110 :        272 :
:  4 :  1 : bDeviceClass              :        0 :          0 :
:  5 :  1 : bDeviceSubClass           :        0 :          0 :
:  6 :  1 : bDeviceProtocol           :        0 :          0 :
:  7 :  1 : bMaxPacketSize            :        8 :          8 :
:  8 :  2 : idVendor                  :     258a :       9610 :
: 10 :  2 : idProduct                 :     6a88 :      27272 :
: 12 :  2 : bcdDevice                 :      100 :        256 :
: 14 :  1 : iManufacturer             :        1 :          1 : 'SINO WEALTH'
: 15 :  1 : iProduct                  :        2 :          2 : 'USB KEYBOARD'
: 16 :  1 : iSerialNumber             :        0 :          0 : ''
: 17 :  1 : bNumConfigurations        :        1 :          1 :
+----+----+---------------------------+----------+------------+

 Standard Configuration Descriptor
+----+----+---------------------------+----------+------------+
:Off :Sz  :Name                       :Value hex :Value dec   :
+----+----+---------------------------+----------+------------+
:  0 :  1 : bLength                   :        9 :          9 :
:  1 :  1 : bDescriptorType           :        2 :          2 :
:  2 :  2 : wTotalLength              :       3b :         59 :
:  4 :  1 : bNumInterfaces            :        2 :          2 :
:  5 :  1 : bConfigurationValue       :        1 :          1 :
:  6 :  1 : iConfiguration            :        0 :          0 : ''
:  7 :  1 : bmAttributes              :       a0 :        160 : (bit7) USB 1.0 bus powered (bit6) Bus powered, (bit5) Remote wakeup
:  8 :  1 : bMaxPower                 :       32 :         50 : 100mA
+----+----+---------------------------+----------+------------+

     Standard Interface Descriptor
    +----+----+---------------------------+----------+------------+
    :Off :Sz  :Name                       :Value hex :Value dec   :
    +----+----+---------------------------+----------+------------+
    :  0 :  1 : bLength                   :        9 :          9 :
    :  1 :  1 : bDescriptorType           :        4 :          4 :
    :  2 :  1 : bInterfaceNumber          :        0 :          0 :
    :  3 :  1 : bAlternateSetting         :        0 :          0 :
    :  4 :  1 : bNumEndpoints             :        1 :          1 :
    :  5 :  1 : bInterfaceClass           :        3 :          3 : HID
    :  6 :  1 : bInterfaceSubClass        :        1 :          1 : Boot interface
    :  7 :  1 : bInterfaceProtocol        :        1 :          1 : Keyboard
    :  8 :  1 : iInterface                :        0 :          0 : ''
    +----+----+---------------------------+----------+------------+

         HID Device Descriptor
        +----+----+---------------------------+----------+------------+
        :Off :Sz  :Name                       :Value hex :Value dec   :
        +----+----+---------------------------+----------+------------+
        :  0 :  1 : bLength                   :        9 :          9 :
        :  1 :  1 : bDescriptorType           :       21 :         33 :
        :  2 :  2 : bcdHID                    :      110 :        272 :
        :  4 :  1 : bCountryCode              :        0 :          0 :
        :  5 :  1 : bNumDescriptors           :        1 :          1 :
        :  6 :  1 : bReportDescType           :       22 :         34 :
        :  7 :  2 : wReportDescLength         :       41 :         65 :
        +----+----+---------------------------+----------+------------+

         Usage Page (Generic Desktop Controls)         :05 01
         Usage (Keyboard)                              :09 06
         Collection (Application)                      :a1 01
           Usage Page (Keyboard/Keypad)                  :05 07
           Usage Minimum                                 :19 e0
           Usage Maximum                                 :29 e7
           Logical Minimum                               :15 00
           Logical Maximum                               :25 01
           Report Size (1)                               :75 01
           Report Count (8)                              :95 08
           ...Input                                      :81 02
           Report Count (1)                              :95 01
           Report Size (8)                               :75 08
           ...Input                                      :81 01
           Report Count (3)                              :95 03
           Report Size (1)                               :75 01
           Usage Page (LEDs)                             :05 08
           Usage Minimum                                 :19 01
           Usage Maximum                                 :29 03
           ...Output                                     :91 02
           Report Count (5)                              :95 05
           Report Size (1)                               :75 01
           ...Output                                     :91 01
           Report Count (6)                              :95 06
           Report Size (8)                               :75 08
           Logical Minimum                               :15 00
           Logical Maximum                               :26 ff 00
           Usage Page (Keyboard/Keypad)                  :05 07
           Usage Minimum                                 :19 00
           Usage Maximum                                 :2a ff 00
           ...Input                                      :81 00
         End Collection                                :c0

         Standard Endpoint Descriptor
        +----+----+---------------------------+----------+------------+
        :Off :Sz  :Name                       :Value hex :Value dec   :
        +----+----+---------------------------+----------+------------+
        :  0 :  1 : bLength                   :        7 :          7 :
        :  1 :  1 : bDescriptorType           :        5 :          5 :
        :  2 :  1 : bEndpointAddress          :       81 :        129 : Endpoint 1 - IN
        :  3 :  1 : bmAttributes              :        3 :          3 : Interrupt
        :  4 :  2 : wMaxPacketSize            :        8 :          8 : 1 x 8 byte max packets
        :  6 :  1 : bInterval                 :        a :         10 :
        +----+----+---------------------------+----------+------------+

     Standard Interface Descriptor
    +----+----+---------------------------+----------+------------+
    :Off :Sz  :Name                       :Value hex :Value dec   :
    +----+----+---------------------------+----------+------------+
    :  0 :  1 : bLength                   :        9 :          9 :
    :  1 :  1 : bDescriptorType           :        4 :          4 :
    :  2 :  1 : bInterfaceNumber          :        1 :          1 :
    :  3 :  1 : bAlternateSetting         :        0 :          0 :
    :  4 :  1 : bNumEndpoints             :        1 :          1 :
    :  5 :  1 : bInterfaceClass           :        3 :          3 : HID
    :  6 :  1 : bInterfaceSubClass        :        0 :          0 :
    :  7 :  1 : bInterfaceProtocol        :        0 :          0 :
    :  8 :  1 : iInterface                :        0 :          0 : ''
    +----+----+---------------------------+----------+------------+

         HID Device Descriptor
        +----+----+---------------------------+----------+------------+
        :Off :Sz  :Name                       :Value hex :Value dec   :
        +----+----+---------------------------+----------+------------+
        :  0 :  1 : bLength                   :        9 :          9 :
        :  1 :  1 : bDescriptorType           :       21 :         33 :
        :  2 :  2 : bcdHID                    :      110 :        272 :
        :  4 :  1 : bCountryCode              :        0 :          0 :
        :  5 :  1 : bNumDescriptors           :        1 :          1 :
        :  6 :  1 : bReportDescType           :       22 :         34 :
        :  7 :  2 : wReportDescLength         :      111 :        273 :
        +----+----+---------------------------+----------+------------+

         Usage Page (Generic Desktop Controls)         :05 01
         Usage (Mouse)                                 :09 02
         Collection (Application)                      :a1 01
           Report ID (1)                                 :85 01
           Usage (Pointer)                               :09 01
           Collection (Physical)                         :a1 00
             Usage Page (Button)                           :05 09
             Usage Minimum                                 :19 01
             Usage Maximum                                 :29 05
             Logical Minimum                               :15 00
             Logical Maximum                               :25 01
             Report Size (1)                               :75 01
             Report Count (5)                              :95 05
             ...Input                                      :81 02
             Report Size (3)                               :75 03
             Report Count (1)                              :95 01
             ...Input                                      :81 03
             Usage Page (Generic Desktop Controls)         :05 01
             Usage (X)                                     :09 30
             Usage (Y)                                     :09 31
             Logical Minimum                               :15 81
             Logical Maximum                               :25 7f
             Report Size (8)                               :75 08
             Report Count (2)                              :95 02
             ...Input                                      :81 06
             Collection (Logical)                          :a1 02
               Usage (Resolution Multiplier)                 :09 48
               Logical Minimum                               :15 00
               Logical Maximum                               :25 01
               Physical Minimum                              :35 01
               Physical Maximum                              :45 04
               Report Size (2)                               :75 02
               Report Count (1)                              :95 01
               Push                                          :a4
               ...Feature                                    :b1 02
               Usage (Wheel)                                 :09 38
               Logical Minimum                               :15 81
               Logical Maximum                               :25 7f
               Physical Minimum                              :35 00
               Physical Maximum                              :45 00
               Report Size (8)                               :75 08
               ...Input                                      :81 06
             End Collection                                :c0
             Collection (Logical)                          :a1 02
               Usage (Resolution Multiplier)                 :09 48
               Pop                                           :b4
               ...Feature                                    :b1 02
               Physical Minimum                              :35 00
               Physical Maximum                              :45 00
               Report Size (4)                               :75 04
               ...Feature                                    :b1 03
               Usage Page (Consumer)                         :05 0c
               Usage (Reserved)                              :0a 38 02
               Logical Minimum                               :15 81
               Logical Maximum                               :25 7f
               Report Size (8)                               :75 08
               ...Input                                      :81 06
             End Collection                                :c0
           End Collection                                :c0
         End Collection                                :c0
         Usage Page (Generic Desktop Controls)         :06 01 00
         Usage (System Control)                        :09 80
         Collection (Application)                      :a1 01
           Report ID (2)                                 :85 02
           Logical Maximum                               :25 01
           Logical Minimum                               :15 00
           Report Size (1)                               :75 01
           Usage (System Power Down)                     :0a 81 00
           Usage (System Sleep)                          :0a 82 00
           Usage (System Wakeup)                         :0a 83 00
           Report Count (3)                              :95 03
           ...Input                                      :81 06
           Report Count (5)                              :95 05
           ...Input                                      :81 01
         End Collection                                :c0
         Usage Page (Consumer)                         :06 0c 00
         Usage (Consumer Control)                      :09 01
         Collection (Application)                      :a1 01
           Report ID (3)                                 :85 03
           Logical Maximum                               :25 01
           Logical Minimum                               :15 00
           Report Size (1)                               :75 01
           Usage (Scan Next Track)                       :0a b5 00
           Usage (Scan Previous Track)                   :0a b6 00
           Usage (Reserved)                              :0a 6f 00
           Usage (Reserved)                              :0a 70 00
           Usage (Mute)                                  :0a e2 00
           Usage (Daily)                                 :0a a2 00
           Usage (Volume Increment)                      :0a e9 00
           Usage (Volume Decrement)                      :0a ea 00
           Report Count (8)                              :95 08
           ...Input                                      :81 02
           Usage (Reserved)                              :0a 83 01
           Usage (Reserved)                              :0a 94 01
           Usage (Reserved)                              :0a 86 01
           Usage (Reserved)                              :0a 88 01
           Usage (Reserved)                              :0a 8a 01
           Usage (Reserved)                              :0a 92 01
           Usage (Stop)                                  :0a b7 00
           Usage (Play/Pause)                            :0a cd 00
           Report Count (8)                              :95 08
           ...Input                                      :81 02
           Usage (Reserved)                              :0a 21 02
           Usage (Reserved)                              :0a 23 02
           Usage (Reserved)                              :0a 24 02
           Usage (Reserved)                              :0a 25 02
           Usage (Reserved)                              :0a 26 02
           Usage (Reserved)                              :0a 27 02
           Usage (Reserved)                              :0a 2a 02
           Usage (Reserved)                              :0a b1 02
           Report Count (8)                              :95 08
           ...Input                                      :81 02
         End Collection                                :c0
         Usage Page (Vendor Defined)                   :06 00 ff
         Usage ()                                      :09 01
         Collection (Application)                      :a1 01
           Report ID (5)                                 :85 05
           Logical Minimum                               :15 00
           Logical Maximum                               :26 ff 00
           Usage Minimum                                 :19 01
           Usage Maximum                                 :29 02
           Report Size (8)                               :75 08
           Report Count (5)                              :95 05
           ...Feature                                    :b1 02
         End Collection                                :c0

         Standard Endpoint Descriptor
        +----+----+---------------------------+----------+------------+
        :Off :Sz  :Name                       :Value hex :Value dec   :
        +----+----+---------------------------+----------+------------+
        :  0 :  1 : bLength                   :        7 :          7 :
        :  1 :  1 : bDescriptorType           :        5 :          5 :
        :  2 :  1 : bEndpointAddress          :       82 :        130 : Endpoint 2 - IN
        :  3 :  1 : bmAttributes              :        3 :          3 : Interrupt
        :  4 :  2 : wMaxPacketSize            :        8 :          8 : 1 x 8 byte max packets
        :  6 :  1 : bInterval                 :        a :         10 :
        +----+----+---------------------------+----------+------------+

JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: pi-top utilities

Post by JonAbbott »

Thanks, I'll need to compare it to my keyboard to see what differences there are beyond it being a different VID/PID.
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: pi-top utilities

Post by JonAbbott »

Endpoint 1 is the keyboard and it does return 8 bytes, so this code should definitely print 8 bytes every time a key is pressed:

Code: Select all

DIM data% 256
PRINT "Press ESC to quit"
quit%=FALSE
H%=FNfind_HID("USB$Device_00_00_00_258A_6A88_*")
IF H%=0 THEN END
P%=OPENIN("devices#endpoint1:USB"+CHR$(H%))
REPEAT
  PRINT
  FOR A%=0 TO 7
    B%=BGET#P%:IF B%=&29 quit%=TRUE
    PRINT ;RIGHT$(STR$~(B%+&100),2);" ";
  NEXT
UNTIL quit%
CLOSE #P%
OSCLI "USBReset "+CHR$(H%)
END

DEF FNfind_HID(HID$)
  SYS "XOS_ReadVarVal", HID$, data%, &100, 0, 3 TO ; E%
  IF (E% AND 1)=1 THEN =0
=?data%
Vanfanel
Posts: 576
Joined: Mon Sep 16, 2013 12:01 am

Re: pi-top utilities

Post by Vanfanel »

@Jon: Great! Now it works!

When I press the only Pi-Top labeled key on my keyboard, I get:

08 00 00 00 00 00 00
00 00 00 00 00 00 00

Do you need any other codes?

Also, note that I had to comment out the PiTop utils module loading as you said, in order to "fix" system hanging when accessing USB drives. I said it previously, I am saying it again in case you didn't see it.
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: pi-top utilities

Post by JonAbbott »

Vanfanel wrote: Thu Sep 20, 2018 6:28 pm 08 00 00 00 00 00 00
Great. That's the left pi-top key, so I'll make both left and right pi-top keys act at the middle mouse button and add support for the VID/PID.
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: pi-top utilities

Post by JonAbbott »

Try the attached test build (now removed), the device ID can now be changed in the !Run, so switch it to your keyboard device ID before you load it.

Left and Right pi-top keys now both act at the middle mouse button, I'll change this at some point to be configurable as I use the left pi-top key for other things.
Vanfanel wrote: Thu Sep 20, 2018 6:28 pm Also, note that I had to comment out the PiTop utils module loading as you said, in order to "fix" system hanging when accessing USB drives.
I've been unable to reproduce this. RISC OS will appear to hang if you plug in a USB memory device it doesn't understand, but it should spring back to life when unplugged.
Vanfanel
Posts: 576
Joined: Mon Sep 16, 2013 12:01 am

Re: pi-top utilities

Post by Vanfanel »

@Jon: I have been trying this new version today. I adjusted the keuyboard device ID on the !Run (I uncommented the german/US line, as it matches my device ID), and now all that happens when I press the pi-top key is that the whole system seems to hang.
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: pi-top utilities

Post by JonAbbott »

Is it actually hanging? Does the mouse still work or is the keyboard simply not responding? Does it only hang when you press the pi-top key?

The Module takes over the keyboard driver whilst loaded and the pi-top key is handled no differently from any other key - it simply translates the USB keycode to an internal keycode and raises the relevant key up/down event. If there's a generic problem, the keyboard will stop responding when the Module is loaded.

If the keyboard appears to be working after loading the Module, do the Fn+volume keys alter the pi-top speaker volume whilst playing audio?

Do you have any other software loaded that will try to attach to HID devices, like !HID?
Post Reply