Migration from Arduino IDE to VSCode/PlatformIO with Custom HID Implementation Issue

alcnonl42

Member
Hello, I want to switch from Arduino IDE to Visual Studio Code. I installed Platform IO but I have a problem.

I have a custom HID setup that I defined in Arduino IDE.

Code:
#elif defined(USB_KEYBOARD_RAWHID)
  #define VENDOR_ID               0x1209
  #define PRODUCT_ID              0x45AF
  #define RAWHID_USAGE_PAGE       0xFFAB
  #define RAWHID_USAGE            0x0200
  #define MANUFACTURER_NAME       {'T','e','e','n','s','y','d','u','i','n','o'}
  #define MANUFACTURER_NAME_LEN   11
  #define PRODUCT_NAME            {'K','e','y','b','o','a','r','d','R','M'}
  #define PRODUCT_NAME_LEN        10
  #define EP0_SIZE                64
  #define NUM_ENDPOINTS           6
  #define NUM_USB_BUFFERS         20
  #define NUM_INTERFACE           4
                                  
  #define KEYBOARD_INTERFACE      0
  #define MOUSE_INTERFACE         3
  #define RAWHID_INTERFACE        1
  #define SEREMU_INTERFACE        2
                                  
  #define KEYBOARD_ENDPOINT       5
  #define KEYBOARD_SIZE           16
  #define KEYBOARD_INTERVAL       1
                                  
  #define MOUSE_ENDPOINT          6
  #define MOUSE_SIZE              8
  #define MOUSE_INTERVAL          1
                                  
  #define RAWHID_TX_ENDPOINT      3
  #define RAWHID_TX_SIZE          64
  #define RAWHID_TX_INTERVAL      1
  #define RAWHID_RX_ENDPOINT      4
  #define RAWHID_RX_SIZE          64
  #define RAWHID_RX_INTERVAL      1
                                  
  #define SEREMU_TX_ENDPOINT      2
  #define SEREMU_TX_SIZE          64
  #define SEREMU_TX_INTERVAL      1
  #define SEREMU_RX_ENDPOINT      2
  #define SEREMU_RX_SIZE          32
  #define SEREMU_RX_INTERVAL      2
                                  
  #define KEYBOARD_DESC_OFFSET    (9 + 9)                                 // Config + Interface
  #define RAWHID_DESC_OFFSET      (KEYBOARD_DESC_OFFSET + 9 + 9 + 7)      // Keyboard: Interface + HID + 1 Endpoint
  #define SEREMU_DESC_OFFSET      (RAWHID_DESC_OFFSET + 9 + 9 + 7 + 7)    // RawHID: Interface + HID + 2 Endpoints
  #define MOUSE_DESC_OFFSET       (SEREMU_DESC_OFFSET + 9 + 9 + 7 + 7)    // SEREMU: Interface + HID + 2 Endpoints
 
  #define ENDPOINT2_CONFIG        ENDPOINT_RECEIVE_INTERRUPT + ENDPOINT_TRANSMIT_INTERRUPT
  #define ENDPOINT3_CONFIG        ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT
  #define ENDPOINT4_CONFIG        ENDPOINT_RECEIVE_INTERRUPT + ENDPOINT_TRANSMIT_UNUSED
  #define ENDPOINT5_CONFIG        ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT
  #define ENDPOINT6_CONFIG        ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT


It works well in Arduino IDE. I also made changes in areas like the board and in the usb_inst.cpp file.

Code:
#ifdef USB_KEYBOARD_RAWHID
usb_keyboard_class Keyboard;
usb_rawhid_class RawHID;
usb_seremu_class Serial;
#endif

However, I can't use this in Platform IO. I added this definition to the usb_desc.h file.I also added:

Code:
build_flags =  
     -D USB_KEYBOARD_RAWHID

and

Code:
#include <usb_keyboard.h>

However, Keyboard appears undefined. Is there another area where I need to import this special desc definition in this structure, or am I missing something?
 
Last edited:
People have quite a lot of problems with PlatformIO.
If you want to get away from the Arduino IDE to something better. Consider using VisualMicro with VisualStudio.
Visual micro sits on top of the Arduino and maintains it's structure. This ensures compatibility. It also has built in debugging capability.
I have been using it for years and wouldn't go back.
 
I’m already actively using Visual Studio for software development, this information will be very useful for me, thank you. I started the trial membership and it’s really impressive, I liked it, but will I not be able to use it when my trial period ends?
 
I’m already actively using Visual Studio for software development, this information will be very useful for me, thank you. I started the trial membership and it’s really impressive, I liked it, but will I not be able to use it when my trial period ends?
Yes, but it's not very expensive to buy a licence. $65 for perpetual licence or $19 per year. I bought a perpetual licence for 3 computers.
 
I’ve been using platformIO for a few years with different Serial configurations. I’d be happy to execute a test case if you can post a simple codebase that demonstrates the problem
 
Back
Top