user600: I'm working on a custom Arduino core based on the teensy code and want to be able to get the board USB VID/PID from boards.txt, as in .board.vid and .board.pid
From what I can tell, Arduino already does this for the Leonardo and similar since if I change the VID/PID in boards.txt then the sketch will run with those values.
But how do I actually get at them? Right now the code I have has hard coded values, but it would be great to make them dynamic.

user1585: The preprocessor will sub in the values for the names "USB_PID" and "USB_VID"
this line in "platform.txt" grabs them and makes build flags for them: 
build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'

the -D* option in the build is equivalent to the following lines being in the code
#define USB_VID /*value of build.vid*/
#define USB_PID /*value of build.pid*/
#define USB_MANUFACTURER /*value of build.usb_manufacturer*/
#define USB_PRODUCT /*value of build.usb_product*/

If you are curious, they are used by the libraries in "USBCore.cpp". Also, they will never be defined for devices they don't apply to.

600: <p>I'm working on a custom Arduino core based on the teensy code and want to be able to get the board USB VID/PID from boards.txt, as in .board.vid and .board.pid</p>

<p>From what I can tell, Arduino already does this for the Leonardo and similar since if I change the VID/PID in boards.txt then the sketch will run with those values.</p>

<p>But how do I actually get at them? Right now the code I have has hard coded values, but it would be great to make them dynamic.</p>
 1585: <p>The preprocessor will sub in the values for the names "USB_PID" and "USB_VID"</p>

<p>this line in "platform.txt" grabs them and makes build flags for them: </p>

<pre><code>build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'
</code></pre>

<p>the -D* option in the build is equivalent to the following lines being in the code</p>

<pre><code>#define USB_VID /*value of build.vid*/
#define USB_PID /*value of build.pid*/
#define USB_MANUFACTURER /*value of build.usb_manufacturer*/
#define USB_PRODUCT /*value of build.usb_product*/
</code></pre>

<p>If you are curious, they are used by the libraries in "USBCore.cpp". Also, they will never be defined for devices they don't apply to.</p>
