usb: Create usb_send_in_buffer_0() to handle EP 0

Don't call usb_send_in_buffer() when using Endpoint 0.  This helps pave the
way for ping-pong buffering, since EP 0 will potentially have a different
buffer descriptor layout than the other endpoints.
usb: Use macros for all buffer descriptor accesses

The bds[] array shouldn't be accessed without using a macro.

Add the following Macros:
	BDS0OUT - EP 0 OUT
	BDS0IN  - EP 0 IN
	BDSnOUT - EP 1-n OUT
	BDSnIN  - EP 1-n IN

This will help pave the way for ping-pong buffers, where the buffer
descriptor array's layout will vary based on the ping-pong mode.
usb_hal: Add necessary parens to SET_BDN() and BDN_LENGTH() macros

Put REG in parens so that expressions like *bd will work as a parameter.
usb: Create a local pid variable for comparisons

Use a local variable for the PID instead of going to the buffer
descriptor every time.
bootloader: Enable optimization (O1)

This is so that the bootloader will fit in the space allocated for it by
the linker script once ping-pong support has been added. The size
of the USB stack should go back down once ping-pong support is complete
and all appropriate optimizations in the code have been made.
usb, usb_hal: Make SFR_EP_MGMT() macro work with variables

SFR_EP_MGMT() will need to be used inside a loop.

Also make use of a stride, as the PIC32 will have a stride between U1EPn
registers.
usb: Ping-pong support for EP's other than zero (mode 3)

This adds initial support for using the hardware ping-pong buffering in
mode 3, which does ping-pong for all EP's other than zero.  See the
datasheets and family reference manuals for more information on ping-pong
modes.

1. Add configuration items to usb_config.h and usb_hal.h.
2. Change buffer descriptor layout:
	a. Don't have a buffer_descriptor_pair struct, but just a
	   buffer_descriptor array instead.
	b. Modify the BDS*() macros to point to the correct buffer
	   descriptor. These macros will be different for each
	   ping-pong mode.
3. Change ep_buffers{} to have multiple buffers for each endpoint
   depending on ping-pong mode used.
4. Add additional pointers in ep_buf{} struct to accommodate the
   additional buffers.
5. Keep track of DTS and active ping-pong buffer (PPBI) in ep_buf{} as
   flag bits.
6. Initialize RX DTS to 1 for no ping-pong, but zero for ping-pong
   mode. This is because for RX, access is always one-buffer behind.
7. Handle Endpoint Halt feature (set and clear) with ping-pong active.
8. Fix SET_PING_PONG_MODE() macro in usb_hal.h to be correct.
9. Handle the STALL interrupt and clear the appropriate bits for
   EP > 0. This is necessary for EP halt to work properly.
10. Make use of PPBI and DTS in:
	stall_ep_in()
	stall_ep_out()
	usb_get_in_buffer()
	usb_send_in_buffer()
	usb_in_endpoint_busy()
	usb_get_out_buffer()
	usb_out_endpoint_has_data()
	usb_arm_out_endpoint()
usb: Use EP_0_LEN instead of ep_buf[0].out_len/in_len

This is an optimization, but also will help with ping-pong support
on endpoint 0.
usb: Move the endpoint 0 buffers out of ep_buf

Create a new struct ep0_buf which contains the buffers and flags for
endpoint 0, as endpoint 0 will be handled differently than the other
endpoints with respect to ping-pong buffering.
usb: Remove redundant code

This code is made redundant by the call to reset_bd0_out() in
usb_service().
usb: Add support for EP0-OUT-only ping-pong mode (mode 1)

1. Use PPB_EP0_OUT and PPB_EP0_IN defines instead of PPB_EP0.
2. Add BDS*() macros for this ping-pong mode.
3. Add EP_BUF() macros for this ping-pong mode.
4. Add buffer pointers to ep0_buf{} struct.
5. Use SFR_USB_STATUS_PPBI register bit to determine which buffer or
   buffer descriptor to use for all accesses.

Basic defines and structure related to ping-pong mode 2 (full ping-pong)
are also included in this patch.
usb_hal: Remove extraneous semicolons from macros
usb: Use start_control_return() for all setup requests

Setup requests which return only a few bytes of data (1-2) would set the
BDN directly and did not go through start_control_return().  This is fine
when ping-pong mode is not active on endpoint 0 IN, but will cause
complication when in full ping-pong mode.

Convert the following setup requests to use start_control_return():
	GET_CONFIGURATION
	GET_STATUS (device and endpoint)
	GET_INTERFACE
usb, usb_hal: Add support for full ping-pong mode (mode 2)

The ping-pong of EP 0 IN is the only thing that was missing.

1. Add macros for BDS*() for this mode.
2. Issue a ping-pong reset in usb_init(). This is so the firmware will be
   in sync with the hardware after the bus reset which follows the first
   part of the device descriptor at the beginning of enumeration.
3. Keep track of and use the EP_TX_PPBI flag for endpoint 0 IN.
4. Create copy_to_ep0_in_buf() function to remove some redundancy and use
   it where appropriate.
5. Call usb_send_in_buffer() from start_control_return() instead of
   manipulating the buffer descriptor manually. This localizes the
   accesses of the buffer descriptor.
6. Add SFR #defines in usb_hal.h

This modification makes the system operate in ping-pong mode, but it
doesn't really take full advantage of ping-pong mode to speed up IN
control transfers.  For example, for transfers containing multiple
transactions, it will still wait for the IN transaction to complete before
giving the next block of data to the SIE.  One could imagine an
optimization where the firmware could load both buffers at the beginning
of a Control IN transfer and then replace each as it was sent, keeping two
in the queue.
usb, usb_hal: Add PHYS_ADDR() macro for converting addresses

PHYS_ADDR converts virtual addresses to physical addresses.  PIC16F, 18F,
and 24F do not have a memory controller, so they always use physical
addresses, but the PIC32MX does use virtual memory (fixed-mapping
translation) and will need this macro to be something other than unity.
usb: Add Support for PIC32MX family

This adds support for the PIC32MX family of microcontrollers.

1. Add configuration items to usb_hal.h.
2. Add support for the 32-bit compiler where needed.
3. Handle virtual/physical memory spaces.
4. Force ping-pong mode to ALL for PIC32MX
5. Add interrupt handler.

This was tested on a PIC32MX460F512L MCU, on the Microchip PIC32 USB
Starter Board.

This commit does not include any of the test programs or build file
changes required for the PIC32MX configuration.
unit_test: Add code support for PIC32MX and PIC32MX460F512L

This does not include build files.
unit_test project: Add support for PIC32 USB Starter Board

Add the build files for the PIC32 USB Starter board. This is the
first-generation board, not the PIC32 Starter Kit I.  (I'm not sure how
they differ).
usb_config.h: Reword comment
gitignore: Ignore backup files commonly created by Unix tools

ignore *~