You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • I've finally managed to add USB HID support on the Pico. An experimental binary for it should be here in an hour or two.

    It's taken most of last and this week to work my way around ST's USB drivers, and they now don't bare much relation to the originals at all :(

    So... How do you use it?

    // Simple mouse
    E.setUSBHID({
      reportDescriptor : [
      0x05,   0x01,
      0x09,   0x02,
      0xA1,   0x01,
      0x09,   0x01,
    
      0xA1,   0x00,
      0x05,   0x09,
      0x19,   0x01,
      0x29,   0x03,
    
      0x15,   0x00,
      0x25,   0x01,
      0x95,   0x03,
      0x75,   0x01,
    
      0x81,   0x02,
      0x95,   0x01,
      0x75,   0x05,
      0x81,   0x01,
    
      0x05,   0x01,
      0x09,   0x30,
      0x09,   0x31,
      0x09,   0x38,
    
      0x15,   0x81,
      0x25,   0x7F,
      0x75,   0x08,
      0x95,   0x03,
    
      0x81,   0x06,
      0xC0,   0x09,
      0x3c,   0x05,
      0xff,   0x09,
    
      0x01,   0x15,
      0x00,   0x25,
      0x01,   0x75,
      0x01,   0x95,
    
      0x02,   0xb1,
      0x22,   0x75,
      0x06,   0x95,
      0x01,   0xb1,
    
      0x01,   0xc0 ]
    });
    
    function mouse(x,y,b) {
      E.sendUSBHID([b&7,x,y,0]);
    }
    
    // Now save, unplug USB and re-plug it
    
    mouse(20,20,0); // moves mouse diagonally down
    
    // Simple Keyboard
    
    E.setUSBHID({
      reportDescriptor : [
            0x05, 0x01,          // Usage Page (Generic Desktop),
            0x09, 0x06,          // Usage (Keyboard),
            0xA1, 0x01,          // Collection (Application),
            0x75, 0x01,          //   Report Size (1),
            0x95, 0x08,          //   Report Count (8),
            0x05, 0x07,          //   Usage Page (Key Codes),
            0x19, 0xE0,          //   Usage Minimum (224),
            0x29, 0xE7,          //   Usage Maximum (231),
            0x15, 0x00,          //   Logical Minimum (0),
            0x25, 0x01,          //   Logical Maximum (1),
            0x81, 0x02,          //   Input (Data, Variable, Absolute), ;Modifier byte
            0x95, 0x01,          //   Report Count (1),
            0x75, 0x08,          //   Report Size (8),
            0x81, 0x03,          //   Input (Constant),                 ;Reserved byte
            0x95, 0x05,          //   Report Count (5),
            0x75, 0x01,          //   Report Size (1),
            0x05, 0x08,          //   Usage Page (LEDs),
            0x19, 0x01,          //   Usage Minimum (1),
            0x29, 0x05,          //   Usage Maximum (5),
            0x91, 0x02,          //   Output (Data, Variable, Absolute), ;LED report
            0x95, 0x01,          //   Report Count (1),
            0x75, 0x03,          //   Report Size (3),
            0x91, 0x03,          //   Output (Constant),                 ;LED report padding
            0x95, 0x06,          //   Report Count (6),
            0x75, 0x08,          //   Report Size (8),
            0x15, 0x00,          //   Logical Minimum (0),
            0x25, 0x68,          //   Logical Maximum(104),
            0x05, 0x07,          //   Usage Page (Key Codes),
            0x19, 0x00,          //   Usage Minimum (0),
            0x29, 0x68,          //   Usage Maximum (104),
            0x81, 0x00,          //   Input (Data, Array),
            0xc0                 // End Collection
      ]
    });
    
      // 1 = modifiers
      // 2 = ?
      // 3..8 = key codes currently down
    
    var KEY = {
      A           : 4 ,
      B           : 5 ,
      C           : 6 ,
      D           : 7 ,
      E           : 8 ,
      F           : 9 ,
      G           : 10,
      H           : 11,
      I           : 12,
      J           : 13,
      K           : 14,
      L           : 15,
      M           : 16,
      N           : 17,
      O           : 18,
      P           : 19,
      Q           : 20,
      R           : 21,
      S           : 22,
      T           : 23,
      U           : 24,
      V           : 25,
      W           : 26,
      X           : 27,
      Y           : 28,
      Z           : 29
    };
    
    function tap(key) {
      E.sendUSBHID([0,0,key,0,0,0,0,0]);
      setTimeout(function() { E.sendUSBHID([0,0,0,0,0,0,0,0]); }, 10);
    }
    
    function type(txt, callback) {
      if (!txt.length) return;
      var int = setInterval(function() {
        tap(KEY[txt[0]]);
        txt = txt.substr(1);
        if (!txt.length) clearInterval(int);
      }, 20);
    }
    
    // Now save, unplug USB and re-plug it
    
    type("HELLOWORLD");
    

    I'll make these all into libraries when it's ready for a proper release, but it's quite usable even now :)

About

Avatar for Gordon @Gordon started