diff -ur microchip_solutions_v2013-06-15/Microchip/Include/TimeDelay.h microchip_solutions_v2013-06-15_usbify/Microchip/Include/TimeDelay.h
--- microchip_solutions_v2013-06-15/Microchip/Include/TimeDelay.h	2014-09-19 11:10:04.000000000 +1000
+++ microchip_solutions_v2013-06-15_usbify/Microchip/Include/TimeDelay.h	2024-10-21 21:19:17.000000000 +1000
@@ -56,8 +56,13 @@
   Remarks:
     None
   ***************************************************************************/
+#ifdef __cplusplus
+extern "C" {
+#endif
 void Delay10us( UINT32 tenMicroSecondCounter );
-
+#ifdef __cplusplus
+}
+#endif
 /****************************************************************************
   Function:
     void DelayMs( UINT16 ms )
@@ -77,4 +82,10 @@
   Remarks:
     None
   ***************************************************************************/
+#ifdef __cplusplus
+extern "C" {
+#endif
 void DelayMs( UINT16 ms );
+#ifdef __cplusplus
+}
+#endif
diff -ur microchip_solutions_v2013-06-15/Microchip/Include/USB/usb_host.h microchip_solutions_v2013-06-15_usbify/Microchip/Include/USB/usb_host.h
--- microchip_solutions_v2013-06-15/Microchip/Include/USB/usb_host.h	2014-09-19 11:09:59.000000000 +1000
+++ microchip_solutions_v2013-06-15_usbify/Microchip/Include/USB/usb_host.h	2024-10-21 21:18:59.000000000 +1000
@@ -421,7 +421,13 @@
     events are assumed to function without error.
   ***************************************************************************/
 #if defined( USB_HOST_APP_EVENT_HANDLER )
+#ifdef __cplusplus
+extern "C" {
+#endif
     BOOL USB_HOST_APP_EVENT_HANDLER ( BYTE address, USB_EVENT event, void *data, DWORD size );
+#ifdef __cplusplus
+}
+#endif
 #else
     // If the application does not provide an event handler, then we will
     // assume that all events function without error.
@@ -801,7 +807,13 @@
     application.
   ***************************************************************************/
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 BOOL USBHostInit(  unsigned long flags  );
+#ifdef __cplusplus
+}
+#endif
 
 
 /****************************************************************************
@@ -945,9 +957,15 @@
     DTS reset is done before the command is issued.
   ***************************************************************************/
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 BYTE    USBHostIssueDeviceRequest( BYTE deviceAddress, BYTE bmRequestType, BYTE bRequest,
              WORD wValue, WORD wIndex, WORD wLength, BYTE *data, BYTE dataDirection, 
              BYTE clientDriverID );
+#ifdef __cplusplus
+}
+#endif
 
 
 /****************************************************************************
@@ -1002,7 +1020,13 @@
     None
   ***************************************************************************/
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 BYTE    USBHostRead( BYTE deviceAddress, BYTE endpoint, BYTE *data, DWORD size );
+#ifdef __cplusplus
+}
+#endif
 
 
 /****************************************************************************
@@ -1210,7 +1234,13 @@
     None
   ***************************************************************************/
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 BYTE USBHostSetNAKTimeout( BYTE deviceAddress, BYTE endpoint, WORD flags, WORD timeoutCount );
+#ifdef __cplusplus
+}
+#endif
 
 
 /****************************************************************************
@@ -1305,7 +1335,13 @@
     None
   ***************************************************************************/
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 void    USBHostTasks( void );
+#ifdef __cplusplus
+}
+#endif
 
 
 /****************************************************************************
@@ -1388,7 +1424,13 @@
         * USB_ENDPOINT_ERROR              - Other error
   ***************************************************************************/
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 BOOL    USBHostTransferIsComplete( BYTE deviceAddress, BYTE endpoint, BYTE *errorCode, DWORD *byteCount );
+#ifdef __cplusplus
+}
+#endif
 
 
 /****************************************************************************
@@ -1488,7 +1530,13 @@
     None
   ***************************************************************************/
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 BYTE    USBHostWrite( BYTE deviceAddress, BYTE endpoint, BYTE *data, DWORD size );
+#ifdef __cplusplus
+}
+#endif
 
 
 /****************************************************************************
diff -ur microchip_solutions_v2013-06-15/Microchip/Include/timer.h microchip_solutions_v2013-06-15_usbify/Microchip/Include/timer.h
--- microchip_solutions_v2013-06-15/Microchip/Include/timer.h	2014-09-19 11:10:04.000000000 +1000
+++ microchip_solutions_v2013-06-15_usbify/Microchip/Include/timer.h	2024-10-21 21:19:28.000000000 +1000
@@ -63,8 +63,20 @@
 		}                           \
 	}
 #elif defined(__PIC32MX__)
+#ifdef __cplusplus
+extern "C" {
+#endif
 void Delay10us(DWORD dwCount);
+#ifdef __cplusplus
+}
+#endif
+#ifdef __cplusplus
+extern "C" {
+#endif
 void DelayMs(WORD ms);
+#ifdef __cplusplus
+}
+#endif
 #endif
 
 
diff -ur microchip_solutions_v2013-06-15/Microchip/USB/usb_host.c microchip_solutions_v2013-06-15_usbify/Microchip/USB/usb_host.c
--- microchip_solutions_v2013-06-15/Microchip/USB/usb_host.c	2014-09-19 11:10:51.000000000 +1000
+++ microchip_solutions_v2013-06-15_usbify/Microchip/USB/usb_host.c	2024-10-21 21:20:53.000000000 +1000
@@ -167,21 +167,21 @@
 
 // These should all be moved into the USB_DEVICE_INFO structure.
 static BYTE                          countConfigurations;                        // Count the Configuration Descriptors read during enumeration.
-static BYTE                          numCommandTries;                            // The number of times the current command has been tried.
+BYTE                          numCommandTries;                            // The number of times the current command has been tried.
 static BYTE                          numEnumerationTries;                        // The number of times enumeration has been attempted on the attached device.
-static volatile WORD                 numTimerInterrupts;                         // The number of milliseconds elapsed during the current waiting period.
+volatile WORD                 numTimerInterrupts;                         // The number of milliseconds elapsed during the current waiting period.
 static volatile USB_ENDPOINT_INFO   *pCurrentEndpoint;                           // Pointer to the endpoint currently performing a transfer.
 BYTE                                *pCurrentConfigurationDescriptor    = NULL;  // Pointer to the current configuration descriptor of the attached device.
 BYTE                                *pDeviceDescriptor                  = NULL;  // Pointer to the Device Descriptor of the attached device.
 static BYTE                         *pEP0Data                           = NULL;  // A data buffer for use by EP0.
-static volatile WORD                 usbHostState;                               // State machine state of the attached device.
+volatile WORD                 usbHostState;                               // State machine state of the attached device.
 volatile WORD                 usbOverrideHostState;                       // Next state machine state, when set by interrupt processing.
 #ifdef ENABLE_STATE_TRACE   // Debug trace support
     static WORD prevHostState;
 #endif
 
 static USB_BUS_INFO                  usbBusInfo;                                 // Information about the USB bus.
-static USB_DEVICE_INFO               usbDeviceInfo;                              // A collection of information about the attached device.
+USB_DEVICE_INFO               usbDeviceInfo;                              // A collection of information about the attached device.
 #if defined( USB_ENABLE_TRANSFER_EVENT )
     static USB_EVENT_QUEUE           usbEventQueue;                              // Queue of USB events used to synchronize ISR to main tasks loop.
 #endif
@@ -423,6 +423,7 @@
 
     // Initialize event queue
     #if defined( USB_ENABLE_TRANSFER_EVENT )
+	printf ("Initialising Transfer Events\n"):
         StructQueueInit(&usbEventQueue, USB_EVENT_QUEUE_DEPTH);
     #endif
 
@@ -626,11 +627,13 @@
             WORD wValue, WORD wIndex, WORD wLength, BYTE *data, BYTE dataDirection,
             BYTE clientDriverID )
 {
-    // Find the required device
-    if (deviceAddress != usbDeviceInfo.deviceAddress)
-    {
-        return USB_UNKNOWN_DEVICE;
-    }
+//     // Find the required device
+//     if (deviceAddress != usbDeviceInfo.deviceAddress)
+//     {
+//         return USB_UNKNOWN_DEVICE;
+//     }
+    // Addressing is managed upstream now
+    usbDeviceInfo.deviceAddress = deviceAddress;
 
     // If we are not in a normal user running state, we cannot do this.
     if ((usbHostState & STATE_MASK) != STATE_RUNNING)
@@ -1266,6 +1269,7 @@
     USB_INTERFACE_INFO          *pCurrentInterface;
     BYTE                        *pTemp;
     BYTE                        temp;
+    BYTE			rcode;
     USB_VBUS_POWER_EVENT_DATA   powerRequest;
 
     // The PIC32MX detach interrupt is not reliable.  If we are not in one of
@@ -1632,8 +1636,20 @@
                             // Enable USB interrupts
                             U1IE                    = USB_INTERRUPT_TRANSFER | USB_INTERRUPT_SOF | USB_INTERRUPT_ERROR | USB_INTERRUPT_DETACH;
                             U1EIE                   = 0xFF;
-
-                            _USB_SetNextSubState();
+			                                             // ###################################################################
+			    usbHostState          = STATE_RUNNING;   // !!!!!!!!!!! This skips most of the original init code !!!!!!!!!!!!!
+			                                             // ###################################################################
+			    //Configure device with host lib instead of uC USB lib
+			    rcode = usbClientDrvTable[0].Initialize(0,0,0);
+                            if (!rcode)
+			    {
+			      DEBUG_PutString( "Init error " );
+			      DEBUG_PutHexUINT8(rcode);
+			      //Reset and try again, then fail after that and go to STATE_HOLDING.
+			      numCommandTries=0;
+			      _USB_CheckCommandAndEnumerationAttempts();
+			    }
+                            //_USB_SetNextSubState();
                             break;
 
                         default:
@@ -1641,7 +1657,7 @@
                             break;
                     }
                     break;
-
+#if 0 /* big skip! */
                 case SUBSTATE_GET_DEVICE_DESCRIPTOR_SIZE:
                     // Send the GET DEVICE DESCRIPTOR command to get just the size
                     // of the descriptor and the max packet size, so we can allocate
@@ -2424,6 +2440,11 @@
                     break;
             }
             break;
+#else
+            default:
+	      break;
+            }
+#endif /* big skip! */
     }
 
 }
@@ -3048,22 +3069,29 @@
     }
 
     pInterface = usbDeviceInfo.pInterfaceList;
+    if (!pInterface) printf("no pInterface\n");
     while (pInterface)
     {
         // Look for the endpoint in the currently active setting.
+//	printf ("  look for Ep 0x%X\n", endpoint);
         if (pInterface->pCurrentSetting)
         {
             pEndpoint = pInterface->pCurrentSetting->pEndpointList;
+	    if (!pEndpoint) printf("no pEndpoint\n");
             while (pEndpoint)
             {
+//	    	printf("EP: 0x%X ", pEndpoint->bEndpointAddress);
                 if (pEndpoint->bEndpointAddress == endpoint)
                 {
                     // We have found the endpoint.
+//		    printf("Ep found\n");
                     return pEndpoint;
                 }
                 pEndpoint = pEndpoint->next;
             }
         }
+	else
+	  printf("current EP setting not found\n");
         
         // Go to the next interface.
         pInterface = pInterface->next;
@@ -4423,7 +4451,6 @@
     {
         pEndpoint->transferState            = TSTATE_BULK_READ;
     }
-
     // Set the flag last so all the parameters are set for an interrupt.
     pEndpoint->status.bfTransferComplete    = 0;
 }
@@ -5109,6 +5136,8 @@
 
     U1EP0 = temp;
 
+//    printf("Token Addr: 0x%X\n", usbDeviceInfo.deviceAddressAndSpeed & 0x7F);
+
     U1ADDR = usbDeviceInfo.deviceAddressAndSpeed;
     U1TOK = (tokenType << 4) | (endpoint & 0x7F);
 
@@ -5644,7 +5673,7 @@
             if (pBDT->STAT.PID == PID_ACK)
             {
                 // We will only get this PID from an OUT or SETUP packet.
-
+////		printf ("OUT/SETUP transfer\n");
                 // Update the count of bytes tranferred.  (If there was an error, this count will be 0.)
                 // The Byte Count is NOT 0 if a NAK occurs.  Therefore, we can only update the
                 // count when an ACK, DATA0, or DATA1 is received.
@@ -5664,6 +5693,8 @@
                     // We are doing SETUP transfers. See if we are done with the SETUP portion.
                     if (pCurrentEndpoint->dataCount >= pCurrentEndpoint->dataCountMaxSETUP)
                     {
+////		        printf ("SETUP transfer\n");
+
                         // We are done with the SETUP.  Reset the byte count and
                         // proceed to the next token.
                         pCurrentEndpoint->dataCount = 0;
@@ -5695,7 +5726,8 @@
             else if ((pBDT->STAT.PID == PID_DATA0) || (pBDT->STAT.PID == PID_DATA1))
             {
                 // We will only get these PID's from an IN packet.
-                
+////           	printf ("IN transfer\n");
+   
                 // Update the count of bytes tranferred.  (If there was an error, this count will be 0.)
                 // The Byte Count is NOT 0 if a NAK occurs.  Therefore, we can only update the
                 // count when an ACK, DATA0, or DATA1 is received.
@@ -5719,6 +5751,9 @@
                     // data when we receive a short or zero-length packet.  If the data length is a
                     // multiple of wMaxPacketSize, we will get a 0-length packet.
                     pCurrentEndpoint->status.bfTransferSuccessful = 1;
+/*		    printf ("IN transfer end:\npacketSize = %d < pCurrentEndpoint->wMaxPacketSize: %d\n"
+		    		"pCurrentEndpoint->dataCount: %d, pCurrentEndpoint->dataCountMax: %d\n",
+				packetSize, pCurrentEndpoint->wMaxPacketSize, pCurrentEndpoint->dataCount, pCurrentEndpoint->dataCountMax); */
                     _USB_SetNextTransferState();
                 }
                 else
@@ -5729,6 +5764,7 @@
             }
             else if (pBDT->STAT.PID == PID_NAK)
             {
+	    	DEBUG_PutChar( 'K' );
                 #ifndef ALLOW_MULTIPLE_NAKS_PER_FRAME
                     pCurrentEndpoint->status.bfLastTransferNAKd = 1;
                 #endif
@@ -5806,6 +5842,7 @@
             }
             else
             {
+	        DEBUG_PutChar( 'E' );
                 // Module-defined PID - Bus Timeout (0x0) or Data Error (0x0F).  Increment the error count.
                 // NOTE: If DTS is enabled and the packet has the wrong DTS value, a PID of 0x0F is
                 // returned.  The hardware, however, acknowledges the packet, so the device thinks
diff -ur microchip_solutions_v2013-06-15/Microchip/USB/usb_host_local.h microchip_solutions_v2013-06-15_usbify/Microchip/USB/usb_host_local.h
--- microchip_solutions_v2013-06-15/Microchip/USB/usb_host_local.h	2014-09-19 11:10:50.000000000 +1000
+++ microchip_solutions_v2013-06-15_usbify/Microchip/USB/usb_host_local.h	2024-10-21 21:21:03.000000000 +1000
@@ -427,6 +427,8 @@
 
 This structure contains all the needed information about an endpoint.  Multiple
 endpoints form a linked list.
+
+Modified for use in host lib. instead of EpInfo from address.h.
 */
 typedef struct _USB_ENDPOINT_INFO
 {
@@ -465,6 +467,16 @@
     volatile WORD               countNAKs;                      // Count of NAK's of current transaction.
     WORD                        timeoutNAKs;                    // Count of NAK's for a timeout, if bfNAKTimeoutEnabled.
 
+/* Extras for host shield lib */
+    volatile union {
+                     uint8_t epAttribs;
+                     struct {
+                              uint8_t bmSndToggle : 1; // Send toggle, when zero bmSNDTOG0, bmSNDTOG1 otherwise
+                              uint8_t bmRcvToggle : 1; // Send toggle, when zero bmRCVTOG0, bmRCVTOG1 otherwise
+                              uint8_t bmNakPower : 6; // Binary order for NAK_LIMIT value
+                            };
+                   };
+
 } USB_ENDPOINT_INFO;
 
 
