Configure VUSB library from sketch


I'm trying to wrap V-USB into a Library for Arduino IDE. I've got it working, but I can't configure it from the sketch. The code is quite old and using defines to configure most of the parameters, such as pin numbers, VID, PID, various USB descriptions, additional API/callback calls.

One idea is to have vusbconfig.h file in the sketch folder that is used when the library is compiled, but apparently the working directory is different from the sketch folder itself and compiler can't locate the file. The sketch directory is not listed during the building process (-I flag) either so I can't make it working. I tried both:

#include "vusbconfig.h"


#include <vusbconfig.h>

It works just fine when the full path is used from the library, but this will work only for a single sketch.

#include "/Users/zont/Documents/Arduino/vusb/vusbconfig.h"

Another idea is to have dummy header-only library that includes all code in the .h file. The problem with this approach is that I can't compile ASM code this way. I tried C-include and ASM-include:

#include "usbdrv/usbdrvasm.S"
".include \"usbdrv/usbdrvasm.S\""

but neither worked (compiler can locate the file, but compilation fails).

Please advise.

That is correct. There is currently no way to do this out of the box with the official Arduino platforms.

The capability has been requested several times over the years, for example:

It has not been very well received by Arduino, since they are concerned that it will result in library authors providing less user friendly interfaces.

I think there is some renewed interest in the subject, for example:

Did you try putting the code itself inline?

you can put build.extra_flags in boards.local.txt

Yes, it works just fine.

    mov     XL, r24
    mov     XH, r25
    ldi     r24, 0
    ldi     r25, 0

The problem is that usbdrvasm.S file needs preprocessing first, because it uses includes to include other ASM files and bunch of defines to make code more readable. So I can't just copy/paste.

boards.local.txt is part of the platform specification. I don't immediately see how it can help with the library that I'm building. Can you elaborate please?

1 Like

from readme from my WiFiEspAT library:

To set different custom sizes of buffers for different boards, you can create a file boards.local.txt next to boards.txt file in hardware package. Set build.extra_flags for individual boards. For example for Mega you can add to boards.local.txt a line with -D options to define the macros. -DWIFIESPAT_TCP_TX_BUFFER_SIZE=128

Thanks for the tip!

This is what I ended up doing. Created platform.local.txt and added this line:


This is adding sketch folder to the include list. Then added this to VUSB library into the src/usbconfig.h file:

#if __has_include(<vusbconfig.h>)
#include <vusbconfig.h>

Now, whenever I add vusbconfig.h to the sketch it is automatically picked up by the library.

Very interesting.
I have done lots with V-USB in the past and RancidBacon had a working methodology but it never evolved beyond Arduino 1.0.x

Going to share on Github?


Please note that any references to are no longer valid ... sadly, they went to the darkside and required registering.

V-USB and the tiny85:

Sure. Here is my initial version. Example sketch Basic builds and runs fine on Arduino Nano. Currently working on few more examples, in particular Mouse, Joystick and Keyboard. Stay tuned.