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"
and
#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.
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:
asm(
#include "usbdrv/usbdrvasm.S"
);
asm(
".include \"usbdrv/usbdrvasm.S\""
);
but neither worked (compiler can locate the file, but compilation fails).
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:
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?
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.
mega.build.extra_flags=-DWIFIESPAT_TCP_RX_BUFFER_SIZE=128 -DWIFIESPAT_TCP_TX_BUFFER_SIZE=128
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.