Update repo

This commit is contained in:
2026-08-30 23:04:35 -07:00
parent 749dab5721
commit ce65a0f59a
14950 changed files with 4408250 additions and 1 deletions
@@ -0,0 +1,62 @@
//###########################################################################
//
// FILE: Resource.h
//
// TITLE: Microsoft Visual C++ generated include file.
//
//###########################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
//
//{{NO_DEPENDENCIES}}
// Used by lmusbdll.rc
//
//
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 1000
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 1000
#endif
#endif
//
// End of file
//
@@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// usbdll.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
@@ -0,0 +1,104 @@
//###########################################################################
//
// FILE: stdafx.h
//
// TITLE: include file for standard system include files
//
//###########################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#endif
//
// Modify the following defines if you have to target a platform prior to the
// ones specified below. Refer to MSDN for the latest info on corresponding
// values for different platforms.
#ifndef WINVER // Allow use of features specific to Windows XP or later.
#define WINVER 0x0501 // Change this to the appropriate value to target
// other versions of Windows.
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target
// other versions of Windows.
#endif
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target
// Windows Me or later.
#endif
#ifndef _WIN32_IE // Allow use of features specific to IE 6.0 or later.
#define _WIN32_IE 0x0600 // Change this to the appropriate value to target
// other versions of IE.
#endif
//
// some CString constructors will be explicit
//
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxole.h> // MFC OLE classes
#include <afxodlgs.h> // MFC OLE dialog classes
#include <afxdisp.h> // MFC Automation classes
#endif // _AFX_NO_OLE_SUPPORT
#ifndef _AFX_NO_DB_SUPPORT
#include <afxdb.h> // MFC ODBC database classes
#endif // _AFX_NO_DB_SUPPORT
#ifndef _AFX_NO_DAO_SUPPORT
#include <afxdao.h> // MFC DAO database classes
#endif // _AFX_NO_DAO_SUPPORT
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
//
// End of file
//
@@ -0,0 +1,964 @@
//###########################################################################
//
// FILE: tiusbdll.cpp
//
// TITLE: A thin layer over WinUSB allowing device open/close/
// read and write functionality.
//
// The WinUSB code in this example is based on information provided
// in Microsoft's white paper, "How to Use WinUSB to Communicate
// with a USB Device", WinUsb_HowTo.doc, available from URL:
//
// http://download.microsoft.com/download/9/c/5/9c5b2167-8017-4bae-9fde-
// d599bac8184a/WinUsb_HowTo.doc
//
//###########################################################################
//
// $Release Date: December 12, 2011 $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#include "stdafx.h"
#include <windows.h>
#include <setupapi.h>
#include <devguid.h>
#include <regstr.h>
#include <strsafe.h>
#include <initguid.h>
#include "winusb.h"
#include "usb100.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#include "resource.h" // main symbols
// CusbdllApp
// See usbdll.cpp for the implementation of this class
//
class CtiusbdllApp : public CWinApp
{
public:
CtiusbdllApp();
// Overrides
public:
virtual BOOL InitInstance();
DECLARE_MESSAGE_MAP()
};
// CtiusbdllApp
BEGIN_MESSAGE_MAP(CtiusbdllApp, CWinApp)
END_MESSAGE_MAP()
// CusbdllApp construction
CtiusbdllApp::CtiusbdllApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
// The one and only CusbdllApp object
CtiusbdllApp theApp;
// CusbdllApp initialization
BOOL CtiusbdllApp::InitInstance()
{
CWinApp::InitInstance();
return TRUE;
}
//****************************************************************************
//
// Buffer size definitions.
//
//****************************************************************************
#define MAX_DEVPATH_LENGTH 256
//****************************************************************************
//
// Flag indicating that a blocking read should be performed.
//
//****************************************************************************
#define TIUSB_WAIT_FOREVER 0xFFFFFFFF
//****************************************************************************
//
// Structure containing handles and information required to communicate with
// the USB bulk device.
//
//****************************************************************************
typedef struct
{
HANDLE deviceHandle;
WINUSB_INTERFACE_HANDLE winUSBHandle;
UCHAR deviceSpeed;
UCHAR bulkInPipe;
UCHAR bulkOutPipe;
HANDLE hReadEvent;
} tDeviceInfoWinUSB;
typedef void *TIUSB_HANDLE;
//****************************************************************************
//
// Returns the device path associated with a provided interface GUID.
//
// \param dwIndex is the zero-based index of the device whose path is to be
// found.
// \param InterfaceGuid is a pointer to the GUID for the interface that
// we are looking for. Assuming you installed the device using the sample
// INF file, this will be the GUID provided in the Dev_AddReg section.
// \param pcDevicePath is a pointer to a buffer into which will be written
// the path to the device if the function is successful.
// \param BufLen is the size of the buffer pointed to by \f pcDevicePath.
//
// Given an interface GUID, this function determines the path that is
// necessary to open a file handle on the USB device we are interested in
// talking to. It returns the path to the first device which is present in
// the system and which offers the required interface.
//
// \return Returns one of the following Windows system error codes.
// ERROR_SUCCESS if the operation completed successfully
// ERROR_DEV_NOT_EXIST if the interface is not found on the system. This
// implies that the driver for the USB device has not been installed.
// ERROR_DEVICE_NOT_CONNECTED if the interface has been installed but no
// device offering it is presently available. This typically indicates
// that the USB device is not currently connected.
// ERROR_NOT_ENOUGH_MEMORY if the function fails to allocate any required
// buffers.
// ERROR_INSUFFICIENT_BUFFER if the buffer passed is too small to hold
// the device path.
//****************************************************************************
static DWORD GetDevicePath(DWORD dwIndex, LPGUID InterfaceGuid,
PCHAR pcDevicePath,
size_t BufLen)
{
BOOL bResult = FALSE;
HDEVINFO deviceInfo;
SP_DEVICE_INTERFACE_DATA interfaceData;
PSP_DEVICE_INTERFACE_DETAIL_DATA detailData = NULL;
ULONG length;
ULONG requiredLength=0;
HRESULT hr;
//
// Get a handle to the device information set containing information on
// the interface GUID supplied on this PC.
//
deviceInfo = SetupDiGetClassDevs(InterfaceGuid,
NULL, NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if(deviceInfo == INVALID_HANDLE_VALUE)
{
//
// No device offering the required interface is present. Has the
// interface been installed? Ask for the information set for all
// devices and not just those that are presently installed.
//
deviceInfo = SetupDiGetClassDevs(InterfaceGuid,
NULL, NULL,
DIGCF_DEVICEINTERFACE);
if(deviceInfo == INVALID_HANDLE_VALUE)
{
return(ERROR_DEV_NOT_EXIST);
}
else
{
SetupDiDestroyDeviceInfoList(deviceInfo);
return(ERROR_DEVICE_NOT_CONNECTED);
}
}
interfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
//
// SetupDiGetClassDevs returned us a valid information set handle so we
// now query this set to find the find the first device offering the
// interface whose GUID was supplied.
//
bResult = SetupDiEnumDeviceInterfaces(deviceInfo,
NULL,
InterfaceGuid,
dwIndex,
&interfaceData);
if(bResult == FALSE)
{
//
// We failed to find the first matching device so tell the caller
// that no suitable device is connected.
//
return(ERROR_DEVICE_NOT_CONNECTED);
}
//
// Now that we have the interface information, we need to query details
// to retrieve the device path. First determine how much space we need to
// hold the detail information.
//
SetupDiGetDeviceInterfaceDetail(deviceInfo,
&interfaceData,
NULL, 0,
&requiredLength,
NULL);
//
// Allocate a buffer to hold the interface details.
//
detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LMEM_FIXED,
requiredLength);
if(NULL == detailData)
{
SetupDiDestroyDeviceInfoList(deviceInfo);
return(ERROR_NOT_ENOUGH_MEMORY);
}
detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
length = requiredLength;
//
// Now call once again to retrieve the actual interface detail information.
//
bResult = SetupDiGetDeviceInterfaceDetail(deviceInfo,
&interfaceData,
detailData,
length,
&requiredLength,
NULL);
if(FALSE == bResult)
{
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(GetLastError());
}
//
// Copy the device path string from the interface details structure into
// the caller's buffer.
//
hr = StringCchCopy((LPTSTR)pcDevicePath,
BufLen,
(LPCTSTR)detailData->DevicePath);
if(FAILED(hr))
{
//
// We failed to copy the device path string!
//
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(ERROR_INSUFFICIENT_BUFFER);
}
//
// Clean up and free locally allocated resources.
//
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(ERROR_SUCCESS);
}
//****************************************************************************
//
// Opens a given instance of the USB device and returns a file handle.
//
// \param dwIndex is the zero-based index of the device that is to be opened.
// \param lpGUID is a pointer to the GUID of the interface that is to
// be opened.
//
// This function determines whether or not the required USB device is
// available and, if so, creates a file allowing access to it. The file
// handle is returned on success.
//
// \return Returns a valid file handle on success of INVALID_HANDLE_VALUE
// on failure. In cases of failure, GetLastError() can be called to determine
// the cause.
//
//****************************************************************************
static HANDLE OpenDeviceByIndex(DWORD dwIndex, LPGUID lpGUID)
{
HANDLE hDev = NULL;
char devicePath[MAX_DEVPATH_LENGTH];
BOOL retVal;
//
// Get the path needed to open a file handle on our USB device.
//
retVal = GetDevicePath(dwIndex, lpGUID, devicePath, sizeof(devicePath));
if(retVal != ERROR_SUCCESS)
{
SetLastError(retVal);
return(INVALID_HANDLE_VALUE);
}
//
// Open the file we will use to communicate with the device.
//
hDev = CreateFile((LPCTSTR)devicePath,
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);
return(hDev);
}
//****************************************************************************
//
// Opens the first instance of a given USB device and returns a file handle.
//
// \param lpGUID is a pointer to the GUID of the interface that is to
// be opened.
//
// This function determines whether or not the required USB device is
// available and, if so, creates a file allowing access to it. The file
// handle is returned on success.
//
// \return Returns a valid file handle on success of INVALID_HANDLE_VALUE
// on failure. In cases of failure, GetLastError() can be called to determine
// the cause.
//
//****************************************************************************
static HANDLE OpenDevice(LPGUID lpGUID)
{
return(OpenDeviceByIndex(0, lpGUID));
}
//****************************************************************************
//
// Determines that the required USB device is present, opens it and gathers
// required information to allow us to read and write it.
//
// \param usVID is the vendor ID of the device to be initialized.
// \param usPID is the product ID of the device to be intialized.
// \param lpGUID is the GUID of the device interface that is to be opened.
// \param dwIndex is the zero-based index of the device to open.
// \param bOpenDataEndpoints is \e TRUE to open endpoints for bulk transfer
// of data to and from the host or \e FALSE to open the device without
// attempting to open any additional endpoints.
// \param pbDriverInstalled is written to \e TRUE if the device driver for the
// required class is installed or \e FALSE otherwise.
//
// This function is called to initialize the USB device and perform one-off
// setup required to allocate handles allowing the application to read and
// write the device endpoints. It offers a superset of the function provided
// by InitializeDevice(), allowing a caller to specify an index to differentiate
// between multiple devices of the same type and also offering the ability to
// open a device without opening endpoint handles for bulk data transfer.
//
// \return Returns a valid handle on success or NULL on failure. In failing
// cases, GetLastError() can be called to determine the cause.
//
//****************************************************************************
extern "C" TIUSB_HANDLE PASCAL EXPORT
InitializeDeviceByIndex(unsigned short usVID,
unsigned short usPID,
LPGUID lpGUID,
DWORD dwIndex,
BOOL bOpenDataEndpoints,
BOOL *pbDriverInstalled)
{
BOOL bResult;
WINUSB_INTERFACE_HANDLE usbHandle;
USB_INTERFACE_DESCRIPTOR ifaceDescriptor;
WINUSB_PIPE_INFORMATION pipeInfo;
UCHAR speed;
ULONG length;
DWORD dwError;
int i;
tDeviceInfoWinUSB *psDevInfo;
//
// Check for NULL pointer parameters.
//
if(!lpGUID || !pbDriverInstalled)
{
return(NULL);
}
//
// Allocate a new device info structure.
//
psDevInfo = (tDeviceInfoWinUSB *)LocalAlloc(LPTR, sizeof(tDeviceInfoWinUSB));
if(!psDevInfo)
{
return(NULL);
}
//
// Determine whether the USB device is present and, if so, generate a file
// handle to allow access to it.
//
psDevInfo->deviceHandle = OpenDeviceByIndex(dwIndex, lpGUID);
if(psDevInfo->deviceHandle == INVALID_HANDLE_VALUE)
{
//
// We were unable to access the device - is that because the device isn't
// connected or has the driver not been installed?
//
dwError = GetLastError();
*pbDriverInstalled = (dwError == ERROR_DEV_NOT_EXIST) ? FALSE : TRUE;
//
// Free our instance data.
//
LocalFree((HLOCAL)psDevInfo);
//
// Return an error to the caller.
//
return(NULL);
}
//
// The device is opened so we now initialize the WinUSB layer passing it
// the device handle.
//
bResult = WinUsb_Initialize(psDevInfo->deviceHandle, &usbHandle);
if(bResult)
{
//
// If we managed to initialize the WinUSB layer, we now query the
// device descriptor to determine the speed of the device.
//
psDevInfo->winUSBHandle = usbHandle;
length = sizeof(UCHAR);
bResult = WinUsb_QueryDeviceInformation(psDevInfo->winUSBHandle,
DEVICE_SPEED,
&length,
&speed);
}
//
// The device opened correctly. Do we need to also open pipes to allow us
// to send and receive data via the bulk endpoints?
//
if(bOpenDataEndpoints)
{
//
// Yes - we do need to open the endpoints for data transfer.
//
if(bResult)
{
//
// If all is well, now query the interface descriptor. We ask for the
// first interface only since, in the case of the generic bulk device,
// this is all that is available.
//
psDevInfo->deviceSpeed = speed;
bResult = WinUsb_QueryInterfaceSettings(psDevInfo->winUSBHandle,
0,
&ifaceDescriptor);
}
if(bResult)
{
//
// We got the interface descriptor so now we enumerate the endpoints
// to find the two we require - one bulk IN endpoint and one bulk OUT
// endpoint.
//
for(i=0;i<ifaceDescriptor.bNumEndpoints;i++)
{
bResult = WinUsb_QueryPipe(psDevInfo->winUSBHandle, 0, (UCHAR) i,
&pipeInfo);
if((pipeInfo.PipeType == UsbdPipeTypeBulk) &&
USB_ENDPOINT_DIRECTION_IN(pipeInfo.PipeId))
{
psDevInfo->bulkInPipe = pipeInfo.PipeId;
}
else if((pipeInfo.PipeType == UsbdPipeTypeBulk) &&
USB_ENDPOINT_DIRECTION_OUT(pipeInfo.PipeId))
{
psDevInfo->bulkOutPipe = pipeInfo.PipeId;
}
else
{
//
// Hmm... we found an endpoint that we didn't expect to see
// on this interface. This tends to imply that there is a
// mismatch between the device configuration and this
// application so we will fail the call after setting an
// appropriate error code for the caller to query.
//
SetLastError(ERROR_NOT_SAME_DEVICE);
bResult = FALSE;
break;
}
}
}
//
// Did all go well so far?
//
if(bResult)
{
//
// All is well - create the signal event we need.
//
psDevInfo->hReadEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
//
// If we created the event successfully, return a good handle.
//
if(psDevInfo->hReadEvent)
{
//
// Everything is good. Set the return code flag to indicate
// this.
//
bResult = true;
}
}
}
else
{
//
// Data transfer endpoints do not need to be opened so merely mark
// this in the device info structure.
//
psDevInfo->bulkOutPipe = 0;
psDevInfo->bulkInPipe = 0;
psDevInfo->hReadEvent = NULL;
}
//
// Did all go well?
//
if(bResult)
{
//
// All is well - return the instance data pointer as a handle to the
// caller.
//
return((TIUSB_HANDLE)psDevInfo);
}
else
{
//
// If we drop through to here, something went wrong so free the
// instance structure and return NULL.
//
LocalFree((HLOCAL)psDevInfo);
return(NULL);
}
}
//****************************************************************************
//
// Determines that the required USB device is present, opens it and gathers
// required information to allow us to read and write it.
//
// \param usVID is the vendor ID of the device to be initialized.
// \param usPID is the product ID of the device to be intialized.
// \param lpGUID is the GUID of the device interface that is to be opened.
// \param pbDriverInstalled is written to \e TRUE if the device driver for the
// required class is installed or \e FALSE otherwise.
//
// This function is called to initialize the USB device and perform one-off
// setup required to allocate handles allowing the application to read and
// write the device endpoints.
//
// InitializeDevice() always opens the first instance of a device and assumes
// that the caller will always want to open handles allowing communication via
// only IN and OUT bulk endpoints. To open an instance of a device other than
// the first or to open a device without opening handles on any endpoints other
// than the control endpoint, InitializeDeviceByIndex() may be used instead.
//
// \return Returns a valid handle on success or NULL on failure. In failing
// cases, GetLastError() can be called to determine the cause.
//
//****************************************************************************
extern "C" TIUSB_HANDLE PASCAL EXPORT
InitializeDevice(unsigned short usVID,
unsigned short usPID,
LPGUID lpGUID,
BOOL *pbDriverInstalled)
{
//
// Call our more capable cousin to open the first instance of the device
// and set up for data transfer via bulk IN and OUT endpoints.
//
return(InitializeDeviceByIndex(usVID, usPID, lpGUID, 0, true,
pbDriverInstalled));
}
//****************************************************************************
//
// Performs a control transfer on endpoint 0.
//
// \param hUSB is the device handle as returned from InitializeDevice().
// \param ucRequestType is the value to be placed in the bmRequestType field
// of the setup data as defined in table 9-2 of the USB 2.0 specification. The
// value is an ORed combination of the REQUEST_xxx flags found in tiusbdll.h.
// \param ucRequest is the specific request identifier which will be placed in
// the bRequest field of the setup data for the transaction.
// \param usValue is the request-specific value placed into the wValue field of
// the setup data for the transaction.
// \param usIndex is the value placed into the wIndex field of the setup data
// for the transaction.
// \param usLength is the number of bytes of data to transfer from or to the
// caller-supplied buffer during the transaction. This value is used to set
// the wLength field in the setup data for the transaction.
// \param pucBuffer is a pointer to a buffer containing at least usLength bytes.
// If ucRequestType contains REQUEST_TRANSFER_IN, usLength bytes of data will
// be transfered from the device and written into this buffer. If ucRequestType
// contains REQUEST_TRANSFER_OUT, usLength bytes of data will be transfered
// from this buffer to the device.
// \param pusCount will be written with the number of bytes actually written to
// or read from the device.
//
// This function performs a control transfer to the device. This transaction
// may transfer data to or from the device depending upon the value of the
// ucRequestType parameter.
//
// \return Returns \e TRUE on success or \e FALSE on failure. If \e FALSE is
// returned, GetLastError() may be called to determine the cause of the failure.
//
//****************************************************************************
extern "C" BOOL PASCAL EXPORT
Endpoint0Transfer(TIUSB_HANDLE hUSB, UCHAR ucRequestType, UCHAR ucRequest,
USHORT usValue, USHORT usIndex, USHORT usLength,
PUCHAR pucBuffer, PUSHORT pusCount)
{
tDeviceInfoWinUSB *psDevInfo = (tDeviceInfoWinUSB *)hUSB;
WINUSB_SETUP_PACKET sSetup;
ULONG ulCount;
ULONG ulError;
BOOL bRetcode;
//
// Check for invalid parameters. We require a buffer pointer if the
// transfer length is non-zero.
//
if(!hUSB || (usLength && !pucBuffer))
{
return(0);
}
//
// Fill in the setup data structure.
//
sSetup.RequestType = ucRequestType;
sSetup.Request = ucRequest;
sSetup.Value = usValue;
sSetup.Index = usIndex;
sSetup.Length = usLength;
//
// Issue the control transaction.
//
bRetcode = WinUsb_ControlTransfer(psDevInfo->winUSBHandle,
sSetup,
pucBuffer,
(ULONG)usLength,
&ulCount,
NULL);
//
// Return either the number of bytes written/read or 0 if there was an
// error.
//
if(bRetcode)
{
*pusCount = (USHORT)ulCount;
}
else
{
ulError = GetLastError();
*pusCount = 0;
}
return(bRetcode);
}
//****************************************************************************
//
// Cleans up and free resources associated with the USB device communication
// prior to exiting the application.
//
// \param hUSB is the device handle as returned from InitializeDevice().
//
// This function should be called prior to exiting the application to free
// the resources allocated during InitializeDevice().
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
extern "C" BOOL PASCAL EXPORT TerminateDevice(TIUSB_HANDLE hUSB)
{
BOOL bRetcode;
BOOL bRetcode2;
tDeviceInfoWinUSB *psDevInfo = (tDeviceInfoWinUSB *)hUSB;
//
// Check for a bad handle.
//
if(!hUSB)
{
return(false);
}
//
// Free WinUSB and Windows resources.
//
bRetcode = WinUsb_Free(psDevInfo->winUSBHandle);
bRetcode2 = CloseHandle(psDevInfo->deviceHandle);
//
// Free the device instance structure.
//
LocalFree((HLOCAL)psDevInfo);
//
// Did all go well?
//
if(bRetcode & bRetcode2)
{
return(TRUE);
}
else
{
return(FALSE);
}
}
//****************************************************************************
//
// Writes a buffer of data to the USB device via the bulk OUT endpoint.
//
// \param hUSB is the device handle as returned from InitializeDevice().
// \param pcBuffer points to the first byte of data to send.
// \param ulSize contains the number of bytes of data to send.
// \param pulWritten is a pointer which will be written with the number of
// bytes of data actually written to the device.
//
// This function is used to send data to the USB device via its bulk OUT endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
extern "C" BOOL PASCAL EXPORT
WriteUSBPacket(TIUSB_HANDLE hUSB, unsigned char *pcBuffer,
unsigned long ulSize,
unsigned long *pulWritten)
{
BOOL bResult;
tDeviceInfoWinUSB *psDevInfo = (tDeviceInfoWinUSB *)hUSB;
//
// Check for bad parameters.
//
if(!hUSB || !pcBuffer || !pulWritten || !ulSize)
{
return(false);
}
//
// Ask WinUSB to write the data for us.
//
bResult = WinUsb_WritePipe(psDevInfo->winUSBHandle,
psDevInfo->bulkOutPipe,
pcBuffer,
ulSize,
pulWritten,
NULL);
return(bResult);
}
//****************************************************************************
//
// Reads data from the USB device via the bulk IN endpoint.
//
// \param hUSB is the device handle as returned from InitializeDevice().
// \param pcBuffer points to a buffer into which the data from the device will
// be written.
// \param ulSize contains the number of bytes that are requested from the
// device.
// \param pulRead is a pointer which will be written with the number of
// bytes of data actually read from the device.
// \param ulTimeoutmS is the number of milliseconds to wait for the
// data before returning an error. To block indefinitely, set this parameter
// to INFINITE.
// \param hBreak is the handle of an event that may be used to break out of
// the read operation. If this is a valid event handle and the event is
// signalled, the read operation will return immediately. Set this to
// NULL if the additional break condition is not required.
//
// This function is used to receive data from the USB device via its bulk IN
// endpoint.
//
// \return Returns \e ERROR_SUCCESS on success, WAIT_TIMEOUT if the data as
// not received within ulTimeoutmS milliseconds, WAIT_OBJECT_0 if the break
// event was signalled or other Windows system error codes on failure.
//
//****************************************************************************
extern "C" DWORD PASCAL EXPORT
ReadUSBPacket(TIUSB_HANDLE hUSB, unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulRead, unsigned long ulTimeoutmS, HANDLE hBreak)
{
BOOL bResult;
DWORD dwError;
OVERLAPPED sOverlapped;
HANDLE phSignals[2];
tDeviceInfoWinUSB *psDevInfo = (tDeviceInfoWinUSB *)hUSB;
//
// Check for bad parameters.
//
if(!hUSB || !pcBuffer || !pulRead || !ulSize)
{
return(ERROR_INVALID_PARAMETER);
}
//
// Tell WinUSB how to signal us when reads are completed (if blocking)
//
sOverlapped.hEvent = psDevInfo->hReadEvent;
sOverlapped.Offset = 0;
sOverlapped.OffsetHigh = 0;
//
// Perform the read.
//
bResult = WinUsb_ReadPipe(psDevInfo->winUSBHandle,
psDevInfo->bulkInPipe,
pcBuffer,
ulSize,
pulRead,
&sOverlapped);
//
// A good return code indicates success regardless of whether we performed
// a blocking or non-blocking read.
//
if(bResult)
{
dwError = ERROR_SUCCESS;
}
else
{
//
// An error occurred or the read will complete asynchronously.
// Which is it?
//
dwError = GetLastError();
//
// Check for error cases other than the one we expect.
//
if(dwError == ERROR_IO_PENDING)
{
//
// The IO is pending so wait for it to complete or for a
// timeout to occur.
//
phSignals[0] = psDevInfo->hReadEvent;
phSignals[1] = hBreak;
dwError = WaitForMultipleObjects(hBreak ? 2 : 1, phSignals, FALSE,
ulTimeoutmS);
//
// At this stage, one of three things could have occurred.
// Either we read a packet or we timed out or the break
// signal was detected. Which was it?
//
if(dwError == WAIT_OBJECT_0)
{
//
// The overlapped IO request completed so check to see how
// many bytes we got.
//
bResult = GetOverlappedResult(psDevInfo->deviceHandle,
&sOverlapped,
pulRead, FALSE);
if(bResult)
{
dwError = ERROR_SUCCESS;
}
else
{
//
// Something went wrong. Return the Windows error code.
//
dwError = GetLastError();
}
}
else
{
//
// Something went wrong - abort the transfer
//
WinUsb_AbortPipe(psDevInfo->winUSBHandle,
psDevInfo->bulkInPipe);
//
// Was the break event signalled?
//
if(dwError == (WAIT_OBJECT_0 + 1))
{
//
// The break event was signalled - abort the read and return.
//
dwError = WAIT_OBJECT_0;
}
}
}
}
//
// Pass the result back to the caller.
//
return(dwError);
}
@@ -0,0 +1,14 @@
; tiusbdll.def : Declares the module parameters for the DLL.
LIBRARY "tiusbdll"
; DESCRIPTION "A simple library allowing low level access to a WinUSB device"
VERSION 1.1
EXPORTS
; Explicit exports can go here
InitializeDevice @1
TerminateDevice @2
WriteUSBPacket @3
ReadUSBPacket @4
InitializeDeviceByIndex @5
Endpoint0Transfer @6
@@ -0,0 +1,140 @@
//###########################################################################
//
// FILE: tiusbdll.h
//
// TITLE: A thin layer over WinUSB allowing device open/close/
// read and write functionality.
//
//###########################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifdef __cplusplus
#pragma once
#ifndef __AFXWIN_H__
#error "include 'stdafx.h' before including this file for PCH"
#endif
//
// Functions exported by this DLL.
//
extern "C" {
#endif
//
// A handle returned by InitializeDevice().
//
typedef void *TIUSB_HANDLE;
//
// Flags used in constructing the ucRequestType parameter to
// Endpoint0Transfer().
//
#define REQUEST_TRANSFER_IN 0x80
#define REQUEST_TRANSFER_OUT 0x00
#define REQUEST_TYPE_STANDARD 0x00
#define REQUEST_TYPE_CLASS 0x20
#define REQUEST_TYPE_VENDOR 0x40
#define REQUEST_RECIPIENT_DEVICE 0x00
#define REQUEST_RECIPIENT_INTERFACE 0x01
#define REQUEST_RECIPIENT_ENDPOINT 0x02
#define REQUEST_RECIPIENT_OTHER 0x03
//
// Function Prototypes exported by the DLL.
//
TIUSB_HANDLE __stdcall InitializeDevice(unsigned short usVID,
unsigned short usPID,
LPGUID lpGUID,
BOOL *pbDriverInstalled);
TIUSB_HANDLE __stdcall InitializeDeviceByIndex(unsigned short usVID,
unsigned short usPID,
LPGUID lpGUID,
DWORD dwIndex,
BOOL bOpenDataEndpoints,
BOOL *pbDriverInstalled);
BOOL __stdcall TerminateDevice(TIUSB_HANDLE hHandle);
BOOL __stdcall WriteUSBPacket(TIUSB_HANDLE hHandle,
unsigned char *pcBuffer,
unsigned long ulSize,
unsigned long *pulWritten);
DWORD __stdcall ReadUSBPacket(TIUSB_HANDLE hHandle,
unsigned char *pcBuffer,
unsigned long ulSize,
unsigned long *pulRead,
unsigned long ulTimeoutMs,
HANDLE hBreak);
BOOL __stdcall Endpoint0Transfer(TIUSB_HANDLE hHandle, UCHAR ucRequestType,
UCHAR ucRequest, USHORT usValue,
USHORT usIndex, USHORT usLength,
PUCHAR pucBuffer, PUSHORT pusCount);
//
// Typedefs for each of the exported functions. This helps if applications
// want to link the DLL dynamically using LoadLibrary rather than linking
// directly to the lib file.
//
typedef TIUSB_HANDLE (__stdcall *tInitializeDevice)(unsigned short usVID,
unsigned short usPID,
LPGUID lpGUID,
BOOL *pbDriverInstalled);
typedef BOOL (__stdcall *tTerminateDevice)(TIUSB_HANDLE hHandle);
typedef BOOL (__stdcall *tWriteUSBPacket)(TIUSB_HANDLE hHandle,
unsigned char *pcBuffer,
unsigned long ulSize,
unsigned long *pulWritten);
typedef DWORD (__stdcall *tReadUSBPacket)(TIUSB_HANDLE hHandle,
unsigned char *pcBuffer,
unsigned long ulSize,
unsigned long *pulRead,
unsigned long ulTimeoutMs,
HANDLE hBreak);
typedef DWORD (__stdcall *tEndpoint0Transfer)(TIUSB_HANDLE hHandle,
UCHAR ucRequestType,
UCHAR ucRequest, USHORT usValue,
USHORT usIndex, USHORT usLength,
PUCHAR pucBuffer,
PUSHORT pusCount);
#ifdef __cplusplus
}
#endif
//
// End of file
//
@@ -0,0 +1,120 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
"#define _AFX_NO_OLE_RESOURCES\r\n"
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
"\r\n"
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
"LANGUAGE 9, 1\r\n"
"#pragma code_page(1252)\r\n"
"#include ""afxres.rc"" // Standard components\r\n"
"#endif\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,6734
PRODUCTVERSION 1,0,0,6734
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904e4"
BEGIN
VALUE "CompanyName", "Texas Instruments Incorporated"
VALUE "FileDescription", "A DLL used to interface Windows example applications to the WinUSB subsystem"
VALUE "FileVersion", "6734"
VALUE "InternalName", "tiusbdll.dll"
VALUE "LegalCopyright", "Copyright (c) 2008-2010 Texas Instruments Incorporated. All rights reserved."
VALUE "OriginalFilename", "tiusbdll.dll"
VALUE "ProductName", "Texas Instruments USB DLL"
VALUE "ProductVersion", "6734"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1252
END
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE 9, 1
#pragma code_page(1252)
#include "afxres.rc" // Standard components
#endif
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
@@ -0,0 +1,275 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{25B000DF-5F76-4D5E-8C26-2C63FD2E8BA1}</ProjectGuid>
<RootNamespace>usbdll</RootNamespace>
<Keyword>MFCDLLProj</Keyword>
<ProjectName>tiusbdll</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<CustomBuildAfterTargets Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</LinkIncremental>
<CustomBuildAfterTargets Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Midl>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MkTypLibCompatible>false</MkTypLibCompatible>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\usb_bulk_example;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include\gl;C:\Program Files\Microsoft SDKs\Windows\v6.1\VC\Include;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(FrameworkSDKDir)include;$(DDKROOT)\inc\wdf\umdf\1.9;$(DDKROOT)\inc\api;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>winusb.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(DDKROOT)\lib\wlh\i386;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ModuleDefinitionFile>tiusbdll.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
</Link>
<CustomBuildStep>
<Outputs>${OutDir}\tiusbdll.lib;%(Outputs)</Outputs>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<CustomBuildStep>
<Outputs>${OutDir}\tiusbdll.lib;%(Outputs)</Outputs>
</CustomBuildStep>
<Midl>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MkTypLibCompatible>false</MkTypLibCompatible>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\usb_bulk_example;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include\gl;C:\Program Files\Microsoft SDKs\Windows\v6.1\VC\Include;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(FrameworkSDKDir)include;$(DDKROOT)\inc\wdf\umdf\1.9;$(DDKROOT)\inc\api;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>winusb.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<AdditionalLibraryDirectories>$(DDKROOT)\lib\wlh\amd64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ModuleDefinitionFile>tiusbdll.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Midl>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MkTypLibCompatible>false</MkTypLibCompatible>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>..\usb_bulk_example;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include\gl;C:\Program Files\Microsoft SDKs\Windows\v6.1\VC\Include;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(FrameworkSDKDir)include;$(DDKROOT)\inc\wdf\umdf\1.9;$(DDKROOT)\inc\api;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<ProjectReference>
<UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
</ProjectReference>
<Link>
<AdditionalDependencies>winusb.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(DDKROOT)\lib\wlh\i386;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ModuleDefinitionFile>tiusbdll.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
<CustomBuildStep>
<Outputs>${OutDir}\tiusbdll.lib;%(Outputs)</Outputs>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<CustomBuildStep>
<Command>touch $(OutDir)tiusbdll.lib
</Command>
<Outputs>$(OutDir)tiusbdll.lib;%(Outputs)</Outputs>
</CustomBuildStep>
<Midl>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MkTypLibCompatible>false</MkTypLibCompatible>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>..\usb_bulk_example;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include\gl;C:\Program Files\Microsoft SDKs\Windows\v6.1\VC\Include;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(FrameworkSDKDir)include;$(DDKROOT)\inc\wdf\umdf\1.9;$(DDKROOT)\inc\api;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<IgnoreStandardIncludePath>true</IgnoreStandardIncludePath>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>winusb.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<AdditionalLibraryDirectories>$(DDKROOT)\lib\wlh\amd64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ModuleDefinitionFile>lmusbdll.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="tiusbdll.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="tiusbdll.def" />
<None Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="tiusbdll.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="stdafx.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="tiusbdll.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,22 @@
-----------------------------------
USB Bulk Example (usb_bulk_example)
-----------------------------------
This Windows command line application is written using C for Windows
and should be built using Microsoft Visual Studio 2010. Project
file usb_bulk_example.vxcproj is provided to build the application.
USB communication with the board running the usb_dev_bulk sample application
is performed using the TIUSBDLL interface which is a thin wrapper over the
Microsoft WinUSB API. The relevant WinUSB subsystem files and the
TIUSBDLL.dll are installed when you first connect the board to a Windows
host via USB and install the drivers. Device drivers for the usb_dev_bulk
device can be found in the MWare\windows_drivers directory.
The TIUSBDLL interface is provided purely to allow the sample applications
to be compiled and run in the absence of the Windows Device Driver Kit
(DDK). The WinUSB API header and library files are not included in the
Windows SDK shipped with Visual Studio 2010 so any code which uses this
interface requires access to the DDK to build. TIUSBDLL contains all
the application code requiring WinUSB so applications may link to it
without the need for the Windows DDK.
@@ -0,0 +1,156 @@
//###########################################################################
//
// FILE: bulk_libusb.c
//
// TITLE: Implementation of the bulk_usb interface using the linusb-win32 API.
//
//###########################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef USE_WINUSB
//
// Included Files
//
#include "libusb-win32\include\usb.h"
//
// Structure containing handles and information required to communicate with
// the USB bulk device.
//
typedef struct
{
usb_dev_handle *hDevice;
} tDeviceInfo;
tDeviceInfo devInfo;
//
// Functions
//
//****************************************************************************
//
// Determines that the required USB device is present, opens it and gathers
// required information to allow us to read and write it.
//
// \param None.
//
// This function is called to initialize the USB device and perform one-off
// setup required to allocate handles allowing the application to read and
// write the device endpoints.
//
// \return Returns \e TRUE on success or \e FALSE on failure. In failing
// cases, GetLastError() can be called to determine the cause.
//
//****************************************************************************
BOOL InitializeDevice(void)
{
//
// Initialize the libusb-win32 subsystem.
//
usb_init();
return(TRUE);
}
//****************************************************************************
//
// Cleans up and free resources associated with the USB device communication
// prior to exiting the application.
//
// \param None.
//
// This function should be called prior to exiting the application to free
// the resources allocated during InitializeDevice().
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL TerminateDevice(void)
{
return(TRUE);
}
//****************************************************************************
//
// Writes a buffer of data to the USB device via the bulk OUT endpoint.
//
// \param pcBuffer points to the first byte of data to send.
// \param ulSize contains the number of bytes of data to send.
// \param pulWritten is a pointer which will be written with the number of
// bytes of data actually written to the device.
//
// This function is used to send data to the USB device via its bulk OUT endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL WriteUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulWritten)
{
return(TRUE);
}
//****************************************************************************
//
// Reads data from the USB device via the bulk IN endpoint.
//
// \param pcBuffer points to a buffer into which the data from the device will
// be written.
// \param ulSize contains the number of bytes that are requested from the
// device.
// \param pulRead is a pointer which will be written with the number of
// bytes of data actually read from the device.
//
// This function is used to receivedata from the USB device via its bulk IN
// endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL ReadUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulRead)
{
return(TRUE);
}
#endif // not defined USE_WINUSB
//
// End of file
//
@@ -0,0 +1,61 @@
//###########################################################################
//
// FILE: bulk_usb.h
//
// TITLE: Public header for the USB interface used by the usb_bulk_example
// application.
//
//###########################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef __BULK_USB_H__
#define __BULK_USB_H__
//
// Function Prototypes
//
extern BOOL InitializeDevice(void);
extern BOOL TerminateDevice(void);
extern BOOL WriteUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulWritten);
extern BOOL ReadUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulRead);
#endif
//
// End of file
//
@@ -0,0 +1,525 @@
//###########################################################################
//
// FILE: bulk_winusb.c
//
// TITLE: Implementation of the bulk_usb interface using Microsoft's
// WinUSB API.
//
//###########################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifdef USE_WINUSB
//
// Included Files
//
#include <windows.h>
#include <setupapi.h>
#include <devguid.h>
#include <regstr.h>
#include <strsafe.h>
#include <initguid.h>
#include "bulk_usb.h"
#include "luminary_guids.h"
#include "winusb.h"
#include "usb100.h"
//
// Defines
//
#define MAX_DEVPATH_LENGTH 256
//
// Globals
//
//
// Structure containing handles and information required to communicate with
// the USB bulk device.
//
typedef struct
{
HANDLE deviceHandle;
WINUSB_INTERFACE_HANDLE winUSBHandle;
UCHAR deviceSpeed;
UCHAR bulkInPipe;
UCHAR bulkOutPipe;
} tDeviceInfoWinUSB;
tDeviceInfoWinUSB devInfo;
//
// Functions
//
//****************************************************************************
//
// Returns the device path associated with a provided interface GUID.
//
// \param InterfaceGuid is a pointer to the GUID for the interface that
// we are looking for. Assuming you installed the device using the sample
// INF file, this will be the GUID provided in the Dev_AddReg section.
// \param pcDevicePath is a pointer to a buffer into which will be written
// the path to the device if the function is successful.
// \param BufLen is the size of the buffer pointed to by \f pcDevicePath.
//
// Given an interface GUID, this function determines the path that is
// necessary to open a file handle on the USB device we are interested in
// talking to. It returns the path to the first device which is present in
// the system and which offers the required interface.
//
// \return Returns one of the following Windows system error codes.
// ERROR_SUCCESS if the operation completed successfully
// ERROR_DEV_NOT_EXIST if the interface is not found on the system. This
// implies that the driver for the USB device has not been installed.
// ERROR_DEVICE_NOT_CONNECTED if the interface has been installed but no
// device offering it is presently available. This typically indicates
// that the USB device is not currently connected.
// ERROR_NOT_ENOUGH_MEMORY if the function fails to allocate any required
// buffers.
// ERROR_INSUFFICIENT_BUFFER if the buffer passed is too small to hold
// the device path.
//
//****************************************************************************
static DWORD GetDevicePath(LPGUID InterfaceGuid,
PCHAR pcDevicePath,
size_t BufLen)
{
BOOL bResult = FALSE;
HDEVINFO deviceInfo;
SP_DEVICE_INTERFACE_DATA interfaceData;
PSP_DEVICE_INTERFACE_DETAIL_DATA detailData = NULL;
ULONG length;
ULONG requiredLength=0;
HRESULT hr;
//
// Get a handle to the device information set containing information on
// the interface GUID supplied on this PC.
//
deviceInfo = SetupDiGetClassDevs(InterfaceGuid,
NULL, NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if(deviceInfo == INVALID_HANDLE_VALUE)
{
//
// No device offering the required interface is present. Has the
// interface been installed? Ask for the information set for all
// devices and not just those that are presently installed.
//
deviceInfo = SetupDiGetClassDevs(InterfaceGuid,
NULL, NULL,
DIGCF_DEVICEINTERFACE);
if(deviceInfo == INVALID_HANDLE_VALUE)
{
return(ERROR_DEV_NOT_EXIST);
}
else
{
SetupDiDestroyDeviceInfoList(deviceInfo);
return(ERROR_DEVICE_NOT_CONNECTED);
}
}
interfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
//
// SetupDiGetClassDevs returned us a valid information set handle so we
// now query this set to find the find the first device offering the
// interface whose GUID was supplied.
//
bResult = SetupDiEnumDeviceInterfaces(deviceInfo,
NULL,
InterfaceGuid,
0,
&interfaceData);
if(bResult == FALSE)
{
//
// We failed to find the first matching device so tell the caller
// that no suitable device is connected.
//
return(ERROR_DEVICE_NOT_CONNECTED);
}
//
// Now that we have the interface information, we need to query details
// to retrieve the device path. First determine how much space we need to
// hold the detail information.
//
SetupDiGetDeviceInterfaceDetail(deviceInfo,
&interfaceData,
NULL, 0,
&requiredLength,
NULL);
//
// Allocate a buffer to hold the interface details.
//
detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LMEM_FIXED,
requiredLength);
if(NULL == detailData)
{
SetupDiDestroyDeviceInfoList(deviceInfo);
return(ERROR_NOT_ENOUGH_MEMORY);
}
detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
length = requiredLength;
//
// Now call once again to retrieve the actual interface detail information.
//
bResult = SetupDiGetDeviceInterfaceDetail(deviceInfo,
&interfaceData,
detailData,
length,
&requiredLength,
NULL);
if(FALSE == bResult)
{
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(GetLastError());
}
//
// Copy the device path string from the interface details structure into
// the caller's buffer.
//
hr = StringCchCopy((LPTSTR)pcDevicePath,
BufLen,
(LPCTSTR)detailData->DevicePath);
if(FAILED(hr))
{
//
// We failed to copy the device path string!
//
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(ERROR_INSUFFICIENT_BUFFER);
}
//
// Clean up and free locally allocated resources.
//
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(ERROR_SUCCESS);
}
//****************************************************************************
//
// Opens the USB device and returns a file handle.
//
// \param None.
//
// This function determines whether or not the required USB device is
// available and, if so, creates a file allowing access to it. The file
// handle is returned on success.
//
// \return Returns a valid file handle on success of INVALID_HANDLE_VALUE
// on failure. In cases of failure, GetLastError() can be called to determine
// the cause.
//
//****************************************************************************
static HANDLE OpenDevice(void)
{
HANDLE hDev = NULL;
char devicePath[MAX_DEVPATH_LENGTH];
BOOL retVal;
//
// Get the path needed to open a file handle on our USB device.
//
retVal = GetDevicePath((LPGUID)&GUID_DEVINTERFACE_LUMINARY_BULK,
devicePath,
sizeof(devicePath));
if(retVal != ERROR_SUCCESS)
{
SetLastError(retVal);
return(INVALID_HANDLE_VALUE);
}
//
// Open the file we will use to communicate with the device.
//
hDev = CreateFile((LPCTSTR)devicePath,
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);
return(hDev);
}
//****************************************************************************
//
// Determines that the required USB device is present, opens it and gathers
// required information to allow us to read and write it.
//
// \param None.
//
// This function is called to initialize the USB device and perform one-off
// setup required to allocate handles allowing the application to read and
// write the device endpoints.
//
// \return Returns \e TRUE on success or \e FALSE on failure. In failing
// cases, GetLastError() can be called to determine the cause.
//
//****************************************************************************
BOOL InitializeDevice(void)
{
BOOL bResult;
WINUSB_INTERFACE_HANDLE usbHandle;
USB_INTERFACE_DESCRIPTOR ifaceDescriptor;
WINUSB_PIPE_INFORMATION pipeInfo;
UCHAR speed;
ULONG length;
int i;
//
// Determine whether the USB device is present and, if so, generate a file
// handle to allow access to it.
//
devInfo.deviceHandle = OpenDevice();
if(devInfo.deviceHandle == INVALID_HANDLE_VALUE)
{
//
// We were unable to access the device - return a failure.
//
return(FALSE);
}
//
// The device is opened so we now initialize the WinUSB layer passing it
// the device handle.
//
bResult = WinUsb_Initialize(devInfo.deviceHandle, &usbHandle);
if(bResult)
{
//
// If we managed to initialize the WinUSB layer, we now query the
// device descriptor to determine the speed of the device.
//
devInfo.winUSBHandle = usbHandle;
length = sizeof(UCHAR);
bResult = WinUsb_QueryDeviceInformation(devInfo.winUSBHandle,
DEVICE_SPEED,
&length,
&speed);
}
if(bResult)
{
//
// If all is well, now query the interface descriptor. We ask for the
// first interface only since, in the case of the generic bulk device,
// this is all that is available.
//
devInfo.deviceSpeed = speed;
bResult = WinUsb_QueryInterfaceSettings(devInfo.winUSBHandle,
0,
&ifaceDescriptor);
}
if(bResult)
{
//
// We got the interface descriptor so now we enumerate the endpoints
// to find the two we require - one bulk IN endpoint and one bulk OUT
// endpoint.
//
for(i=0;i<ifaceDescriptor.bNumEndpoints;i++)
{
bResult = WinUsb_QueryPipe(devInfo.winUSBHandle, 0, (UCHAR) i,
&pipeInfo);
if((pipeInfo.PipeType == UsbdPipeTypeBulk) &&
USB_ENDPOINT_DIRECTION_IN(pipeInfo.PipeId))
{
devInfo.bulkInPipe = pipeInfo.PipeId;
}
else if((pipeInfo.PipeType == UsbdPipeTypeBulk) &&
USB_ENDPOINT_DIRECTION_OUT(pipeInfo.PipeId))
{
devInfo.bulkOutPipe = pipeInfo.PipeId;
}
else
{
//
// Hmm... we found and endpoint that we didn't expect to see
// on this interface. This tends to imply that there is a
// mismatch between the device configuration and this
// application so we will fail the call after setting an
// appropriate error code for the caller to query.
//
SetLastError(ERROR_NOT_SAME_DEVICE);
bResult = FALSE;
break;
}
}
}
return(bResult);
}
//****************************************************************************
//
// Cleans up and free resources associated with the USB device communication
// prior to exiting the application.
//
// \param None.
//
// This function should be called prior to exiting the application to free
// the resources allocated during InitializeDevice().
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL TerminateDevice(void)
{
BOOL bRetcode;
BOOL bRetcode2;
bRetcode = WinUsb_Free(devInfo.winUSBHandle);
bRetcode2 = CloseHandle(devInfo.deviceHandle);
if(bRetcode & bRetcode2)
{
return(TRUE);
}
else
{
return(FALSE);
}
}
//****************************************************************************
//
// Writes a buffer of data to the USB device via the bulk OUT endpoint.
//
// \param pcBuffer points to the first byte of data to send.
// \param ulSize contains the number of bytes of data to send.
// \param pulWritten is a pointer which will be written with the number of
// bytes of data actually written to the device.
//
// This function is used to send data to the USB device via its bulk OUT
// endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL WriteUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulWritten)
{
BOOL bResult;
bResult = WinUsb_WritePipe(devInfo.winUSBHandle,
devInfo.bulkOutPipe,
pcBuffer,
ulSize,
pulWritten,
NULL);
return(bResult);
}
//****************************************************************************
//
// Reads data from the USB device via the bulk IN endpoint.
//
// \param pcBuffer points to a buffer into which the data from the device will
// be written.
// \param ulSize contains the number of bytes that are requested from the
// device.
// \param pulRead is a pointer which will be written with the number of
// bytes of data actually read from the device.
//
// This function is used to receivedata from the USB device via its bulk IN
// endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL ReadUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulRead)
{
BOOL bResult;
unsigned long ulSecondRead;
bResult = WinUsb_ReadPipe(devInfo.winUSBHandle,
devInfo.bulkInPipe,
pcBuffer,
ulSize,
pulRead,
NULL);
//
// Make sure we got the number of bytes expected. If we got less, try to
// read the remainder.
//
if(bResult && (*pulRead < ulSize))
{
bResult = WinUsb_ReadPipe(devInfo.winUSBHandle,
devInfo.bulkInPipe,
pcBuffer + *pulRead,
ulSize - *pulRead,
&ulSecondRead,
NULL);
if(bResult)
{
*pulRead += ulSecondRead;
}
}
return(bResult);
}
#endif // USE_WINUSB
//
// End of file
//
@@ -0,0 +1,70 @@
//###########################################################################
//
// FILE: ti_guids.h
//
// TITLE: GUIDs associated with TI Micro USB examples
//
//###########################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef _TI_GUIDS_
#define _TI_GUIDS_
//
// Vendor and Product IDs for the generic bulk device.
//
#define BULK_VID 0x1cbe
#define BULK_PID 0x0003
//
// TI Bulk Device Class GUID
// {F5450C06-EB58-420e-8F98-A76C5D4AFB18}
//
DEFINE_GUID(GUID_DEVCLASS_TI_BULK,
0xF5450C06, 0xEB5B, 0x420E, 0x8F, 0x98, 0xA7, 0x6C, 0x5D, 0x4A, 0xFB, 0x18);
//
// TI Bulk Device Interface GUID
// {6E45736A-2B1B-4078-B772-B3AF2B6FDE1C}
//
DEFINE_GUID(GUID_DEVINTERFACE_TI_BULK,
0x6E45736A, 0x2B1B, 0x4078, 0xB7, 0x72, 0xb3, 0xAF, 0x2B, 0x6F, 0xDE, 0x1C);
#endif
//
// End of file
//
@@ -0,0 +1,477 @@
//###########################################################################
//
// FILE: usb_bulk_example.c
//
// TITLE: A very simple command line application that attempts
// to open the TI Generic Bulk USB device and exchange data
// with it.
//
// If the device is successfully opened, the user is prompted for a string
// which is then sent to the device. The device toggles the case of any
// alphabet characters in the the data and sends it back. We receive this
// and print out the result.
//
// Communication with the device is carried out via a simple DLL, tiusbdll(64),
// which is responsible for opening and closing the device and for
// sending and receiving blocks of data. This structure allows the
// application code to be kept independent of the underlying USB driver
// in use. In this implementation, Microsoft's WinUSB interface is used
// but a switch to another stack, for example the open source libusb-win32
// interface could be made merely be replacing the tiusbdll(64).dll with
// another version writing to the different USB stack.
//
// One downside to using WinUSB is that it requires you to have the Windows
// Device Driver Kit (DDK) installed to build applications which use the
// interface. This is a very large download making it awkward for people
// with slow internet connections. The use of tiusbdll(64).dll also offers
// the advantage that applications using it can still be modified and
// rebuilt even without the DDK installed on the development system. To
// update and rebuild tiusbdll itself, however, the DDK is still required.
//
//
//###########################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
//
// Included Files
//
#include <windows.h>
#include <strsafe.h>
#include <initguid.h>
#include "tiusbdll.h"
#include "ti_guids.h"
//
// Buffer size definitions.
//
#define MAX_STRING_LEN 256
#define MAX_ENTRY_LEN 256
#define USB_BUFFER_LEN 1216
//
// Defines
//
//
// The build version number
//
#define BLDVER "7611"
//
// The number of bytes we read and write per transaction if in echo mode.
//
#define ECHO_PACKET_SIZE 64
//
// Globals
//
//
// Buffer into which error messages are written.
//
TCHAR g_pcErrorString[MAX_STRING_LEN];
//
// The number of bytes transferred in the last measurement interval.
//
ULONG g_ulByteCount = 0;
//
// The total number of packets transferred.
//
ULONG g_ulPacketCount = 0;
//
// Functions
//
//****************************************************************************
//
// Return a string describing the supplied system error code.
//
// \param dwError is a Windows system error code.
//
// This function returns a pointer to a string describing the error code
// passed in the dwError parameter. If no description string can be found
// the string "Unknown" is returned.
//
// \return Returns a pointer to a string describing the error.
//
//****************************************************************************
LPTSTR GetSystemErrorString(DWORD dwError)
{
DWORD dwRetcode;
//
// Ask Windows for the error message description.
//
dwRetcode = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, "%0", dwError, 0,
g_pcErrorString, MAX_STRING_LEN, NULL);
if(dwRetcode == 0)
{
return((LPTSTR)L"Unknown");
}
else
{
//
// Remove the trailing "\n\r" if present.
//
if(dwRetcode >= 2)
{
if(g_pcErrorString[dwRetcode - 2] == '\r')
{
g_pcErrorString[dwRetcode - 2] = '\0';
}
}
return(g_pcErrorString);
}
}
//****************************************************************************
//
// Print the throughput in terms of Kbps once per second.
//
//****************************************************************************
void UpdateThroughput(void)
{
static ULONG ulStartTime = 0;
static ULONG ulLast = 0;
ULONG ulNow;
ULONG ulElapsed;
SYSTEMTIME sSysTime;
//
// Get the current system time.
//
GetSystemTime(&sSysTime);
ulNow = (((((sSysTime.wHour * 60) +
sSysTime.wMinute) * 60) +
sSysTime.wSecond) * 1000) + sSysTime.wMilliseconds;
//
// If this is the first call, set the start time.
//
if(ulStartTime == 0)
{
ulStartTime = ulNow;
ulLast = ulNow;
return;
}
//
// How much time has elapsed since the last measurement?
//
ulElapsed = (ulNow > ulStartTime) ? (ulNow - ulStartTime) : (ulStartTime - ulNow);
//
// We dump a new measurement every second.
//
if(ulElapsed > 1000)
{
printf("\r%6dKbps Packets: %10d ", ((g_ulByteCount * 8) / ulElapsed),
g_ulPacketCount);
g_ulByteCount = 0;
ulStartTime = ulNow;
}
}
//****************************************************************************
//
// The main application entry function.
//
// \param None.
//
// This function forms the main entry point of the example application. It
// initializes the USB bulk device, prompts the user for an ASCII string,
// sends this string to the device, reads the response from the device (which
// will be the same string with the character order reversed if using the
// sample device provided) and displays the returned string.
//
// \return Set the exit code to 0 of no errors cause the application to end
// or a non-zero value otherwise.
//
//****************************************************************************
int main(int argc, char *argv[])
{
BOOL bResult;
BOOL bDriverInstalled;
BOOL bEcho;
char szBuffer[USB_BUFFER_LEN];
ULONG ulWritten;
ULONG ulRead;
ULONG ulLength;
DWORD dwError;
TIUSB_HANDLE hUSB;
//
// Are we operating in echo mode or not? The "-e" parameter tells the
// app to echo everything it receives back to the device unchanged.
//
bEcho = ((argc > 1) && (argv[1][1] == 'e')) ? TRUE : FALSE;
//
// Print a cheerful welcome.
//
printf("\nTI Bulk USB Device Example\n");
printf( "---------------------------------\n\n");
printf("Version %s\n\n", BLDVER);
if(!bEcho)
{
printf("This is a partner application to the usb_dev_bulk example\n");
printf("shipped software releases for USB-enabled boards. \n");
printf("Strings entered here are sent to the board which\n");
printf("inverts the case of the characters in the string and returns\n");
printf("them to the host.\n\n");
}
else
{
printf("If run with the \"-e\" command line switch, this application\n");
printf("echoes all data received on the bulk IN endpoint to the bulk\n");
printf("OUT endpoint. This feature may be helpful during development\n");
printf("and debug of your own USB devices. Note that this will not\n");
printf("do anything exciting if run with the usb_dev_bulk example\n");
printf("device attached since it expects the host to initiate transfers.\n\n");
}
//
// Find our USB device and prepare it for communication.
//
hUSB = InitializeDevice(BULK_VID, BULK_PID,
(LPGUID)&(GUID_DEVINTERFACE_TI_BULK),
&bDriverInstalled);
if(hUSB)
{
//
// Are we operating in echo mode or not? The "-e" parameter tells the
// app to echo everything it receives back to the device unchanged.
//
if(bEcho)
{
//
// Yes - we are in echo mode.
//
printf("Running in echo mode. Press Ctrl+C to exit.\n\n");
while(1)
{
//
// Read a block of data from the device.
//
dwError = ReadUSBPacket(hUSB, szBuffer, ECHO_PACKET_SIZE, &ulRead,
INFINITE, NULL);
if(dwError != ERROR_SUCCESS)
{
//
// We failed to read from the device.
//
printf("\n\nError %d (%S) reading from bulk IN pipe.\n", dwError,
GetSystemErrorString(dwError));
break;
}
else
{
//
// Update our byte and packet counters.
//
g_ulByteCount += ulRead;
g_ulPacketCount++;
//
// Write the data back out to the device.
//
bResult = WriteUSBPacket(hUSB, szBuffer, ulRead, &ulWritten);
if(!bResult)
{
//
// We failed to write the data for some reason.
//
dwError = GetLastError();
printf("\n\nError %d (%S) writing to bulk OUT pipe.\n",
dwError, GetSystemErrorString(dwError));
break;
}
//
// Display the throughput.
//
UpdateThroughput();
}
}
}
else
{
//
// We are running in normal mode. Keep sending and receiving
// strings until the user indicates that it is time to exit.
//
while(1)
{
//
// The device was found and successfully configured.
// Now get a string from the user...
//
do
{
printf("\nEnter a string (EXIT to exit): ");
fgets(szBuffer, MAX_ENTRY_LEN, stdin);
printf("\n");
//
// How many characters were entered
// (including the trailing '\n')?
//
ulLength = (ULONG)strlen(szBuffer);
if(ulLength <= 1)
{
//
// The string is either nothing at all or a single
// '\n' so reprompt the user.
//
printf("\nPlease enter some text.\n");
ulLength = 0;
}
else
{
//
// Get rid of the trailing '\n' if there is one there.
//
if(szBuffer[ulLength - 1] == '\n')
{
szBuffer[ulLength - 1] = '\0';
ulLength--;
}
}
}
while(ulLength == 0);
//
// Are we being asked to exit the application?
//
if(!(strcmp("EXIT", szBuffer)))
{
//
// Yes - drop out and exit.
//
printf("Exiting on user request.\n");
break;
}
//
// Write the user's string to the device.
//
bResult = WriteUSBPacket(hUSB, szBuffer, ulLength, &ulWritten);
if(!bResult)
{
//
// We failed to write the data for some reason.
//
dwError = GetLastError();
printf("Error %d (%S) writing to bulk OUT pipe.\n", dwError,
GetSystemErrorString(dwError));
}
else
{
//
// We wrote data successfully so now read it back.
//
printf("Wrote %d bytes to the device. Expected %d\n",
ulWritten, ulLength);
//
// We expect the same number of bytes as we just sent.
//
dwError = ReadUSBPacket(hUSB, szBuffer, ulWritten, &ulRead,
INFINITE, NULL);
if(dwError != ERROR_SUCCESS)
{
//
// We failed to read from the device.
//
printf("Error %d (%S) reading from bulk IN pipe.\n",
dwError, GetSystemErrorString(dwError));
}
else
{
//
// Add a string terminator to the returned data (this
// should already be there but, just in case...)
//
szBuffer[ulRead] = '\0';
printf("Read %d bytes from device. Expected %d\n",
ulRead, ulWritten);
printf("\nReturned string: \"%s\"\n", szBuffer);
}
}
}
}
}
else
{
//
// An error was reported while trying to connect to the device.
//
dwError = GetLastError();
printf("\nUnable to initialize the TI Bulk USB Device.\n");
printf("Error code is %d (%S)\n\n", dwError, GetSystemErrorString(dwError));
printf("Please make sure you have a TI USB-enabled evaluation\n");
printf("or development kit running the usb_dev_bulk example\n");
printf("application connected to this system via the \"USB OTG\" or\n");
printf("\"USB DEVICE\" connectors. Once the device is connected, run\n");
printf("this application again.\n\n");
printf("\nPress \"Enter\" to exit: ");
fgets(szBuffer, MAX_STRING_LEN, stdin);
printf("\n");
return(2);
}
TerminateDevice(hUSB);
return(0);
}
//
// End of file
//
@@ -0,0 +1,381 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="usb_bulk_example"
ProjectGUID="{603D9796-4654-4082-9322-E4FC142312FB}"
RootNamespace="usb_bulk_example"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../lmusbdll"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="$(OutDir);..\Debug"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../lmusbdll"
PreprocessorDefinitions="X64_BUILD"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
OutputFile="$(OutDir)\$(ProjectName).exe"
LinkIncremental="2"
AdditionalLibraryDirectories="$(OutDir);..\x64\Debug"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../lmusbdll"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="$(OutDir);..\Release"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../lmusbdll"
PreprocessorDefinitions="X64_BUILD"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
OutputFile="$(OutDir)\$(ProjectName).exe"
LinkIncremental="1"
AdditionalLibraryDirectories="$(OutDir);..\x64\Release"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\usb_bulk_example.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\bulk_usb.h"
>
</File>
<File
RelativePath="..\lmusbdll\lmusbdll.h"
>
</File>
<File
RelativePath=".\luminary_guids.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<File
RelativePath=".\ReadMe.txt"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
@@ -0,0 +1,206 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{603D9796-4654-4082-9322-E4FC142312FB}</ProjectGuid>
<RootNamespace>usb_bulk_example</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>11.0.50727.1</_ProjectFileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>../tiusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>tiusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir);..\tiusbdll\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>../tiusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>X64_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>tiusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).exe</OutputFile>
<AdditionalLibraryDirectories>$(OutDir);..\tiusbdll\x64\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>../tiusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>tiusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir);..\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>../lmusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>X64_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>lmusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).exe</OutputFile>
<AdditionalLibraryDirectories>$(OutDir);..\x64\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="usb_bulk_example.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="bulk_usb.h" />
<ClInclude Include="..\lmusbdll\lmusbdll.h" />
<ClInclude Include="luminary_guids.h" />
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,156 @@
//###########################################################################
//
// FILE: bulk_libusb.c
//
// TITLE: Implementation of the bulk_usb interface using the linusb-win32 API.
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
#ifndef USE_WINUSB
//
// Included Files
//
#include "libusb-win32\include\usb.h"
//
// Structure containing handles and information required to communicate with
// the USB bulk device.
//
typedef struct
{
usb_dev_handle *hDevice;
} tDeviceInfo;
tDeviceInfo devInfo;
//
// Functions
//
//****************************************************************************
//
// Determines that the required USB device is present, opens it and gathers
// required information to allow us to read and write it.
//
// \param None.
//
// This function is called to initialize the USB device and perform one-off
// setup required to allocate handles allowing the application to read and
// write the device endpoints.
//
// \return Returns \e TRUE on success or \e FALSE on failure. In failing
// cases, GetLastError() can be called to determine the cause.
//
//****************************************************************************
BOOL InitializeDevice(void)
{
//
// Initialize the libusb-win32 subsystem.
//
usb_init();
return(TRUE);
}
//****************************************************************************
//
// Cleans up and free resources associated with the USB device communication
// prior to exiting the application.
//
// \param None.
//
// This function should be called prior to exiting the application to free
// the resources allocated during InitializeDevice().
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL TerminateDevice(void)
{
return(TRUE);
}
//****************************************************************************
//
// Writes a buffer of data to the USB device via the bulk OUT endpoint.
//
// \param pcBuffer points to the first byte of data to send.
// \param ulSize contains the number of bytes of data to send.
// \param pulWritten is a pointer which will be written with the number of
// bytes of data actually written to the device.
//
// This function is used to send data to the USB device via its bulk OUT endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL WriteUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulWritten)
{
return(TRUE);
}
//****************************************************************************
//
// Reads data from the USB device via the bulk IN endpoint.
//
// \param pcBuffer points to a buffer into which the data from the device will
// be written.
// \param ulSize contains the number of bytes that are requested from the
// device.
// \param pulRead is a pointer which will be written with the number of
// bytes of data actually read from the device.
//
// This function is used to receivedata from the USB device via its bulk IN
// endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL ReadUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulRead)
{
return(TRUE);
}
#endif // not defined USE_WINUSB
//
// End of file
//
@@ -0,0 +1,61 @@
//###########################################################################
//
// FILE: bulk_usb.h
//
// TITLE: Public header for the USB interface used by the
// usb_bulk_example_throughput application.
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
#ifndef BULK_USB_H
#define BULK_USB_H
//
// Function Prototypes
//
extern BOOL InitializeDevice(void);
extern BOOL TerminateDevice(void);
extern BOOL WriteUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulWritten);
extern BOOL ReadUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulRead);
#endif
//
// End of file
//
@@ -0,0 +1,525 @@
//###########################################################################
//
// FILE: bulk_winusb.c
//
// TITLE: Implementation of the bulk_usb interface using Microsoft's
// WinUSB API.
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
#ifdef USE_WINUSB
//
// Included Files
//
#include <windows.h>
#include <setupapi.h>
#include <devguid.h>
#include <regstr.h>
#include <strsafe.h>
#include <initguid.h>
#include "bulk_usb.h"
#include "luminary_guids.h"
#include "winusb.h"
#include "usb100.h"
//
// Defines
//
#define MAX_DEVPATH_LENGTH 256
//
// Globals
//
//
// Structure containing handles and information required to communicate with
// the USB bulk device.
//
typedef struct
{
HANDLE deviceHandle;
WINUSB_INTERFACE_HANDLE winUSBHandle;
UCHAR deviceSpeed;
UCHAR bulkInPipe;
UCHAR bulkOutPipe;
} tDeviceInfoWinUSB;
tDeviceInfoWinUSB devInfo;
//
// Functions
//
//****************************************************************************
//
// Returns the device path associated with a provided interface GUID.
//
// \param InterfaceGuid is a pointer to the GUID for the interface that
// we are looking for. Assuming you installed the device using the sample
// INF file, this will be the GUID provided in the Dev_AddReg section.
// \param pcDevicePath is a pointer to a buffer into which will be written
// the path to the device if the function is successful.
// \param BufLen is the size of the buffer pointed to by \f pcDevicePath.
//
// Given an interface GUID, this function determines the path that is
// necessary to open a file handle on the USB device we are interested in
// talking to. It returns the path to the first device which is present in
// the system and which offers the required interface.
//
// \return Returns one of the following Windows system error codes.
// ERROR_SUCCESS if the operation completed successfully
// ERROR_DEV_NOT_EXIST if the interface is not found on the system. This
// implies that the driver for the USB device has not been installed.
// ERROR_DEVICE_NOT_CONNECTED if the interface has been installed but no
// device offering it is presently available. This typically indicates
// that the USB device is not currently connected.
// ERROR_NOT_ENOUGH_MEMORY if the function fails to allocate any required
// buffers.
// ERROR_INSUFFICIENT_BUFFER if the buffer passed is too small to hold
// the device path.
//
//****************************************************************************
static DWORD GetDevicePath(LPGUID InterfaceGuid,
PCHAR pcDevicePath,
size_t BufLen)
{
BOOL bResult = FALSE;
HDEVINFO deviceInfo;
SP_DEVICE_INTERFACE_DATA interfaceData;
PSP_DEVICE_INTERFACE_DETAIL_DATA detailData = NULL;
ULONG length;
ULONG requiredLength=0;
HRESULT hr;
//
// Get a handle to the device information set containing information on
// the interface GUID supplied on this PC.
//
deviceInfo = SetupDiGetClassDevs(InterfaceGuid,
NULL, NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if(deviceInfo == INVALID_HANDLE_VALUE)
{
//
// No device offering the required interface is present. Has the
// interface been installed? Ask for the information set for all
// devices and not just those that are presently installed.
//
deviceInfo = SetupDiGetClassDevs(InterfaceGuid,
NULL, NULL,
DIGCF_DEVICEINTERFACE);
if(deviceInfo == INVALID_HANDLE_VALUE)
{
return(ERROR_DEV_NOT_EXIST);
}
else
{
SetupDiDestroyDeviceInfoList(deviceInfo);
return(ERROR_DEVICE_NOT_CONNECTED);
}
}
interfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
//
// SetupDiGetClassDevs returned us a valid information set handle so we
// now query this set to find the find the first device offering the
// interface whose GUID was supplied.
//
bResult = SetupDiEnumDeviceInterfaces(deviceInfo,
NULL,
InterfaceGuid,
0,
&interfaceData);
if(bResult == FALSE)
{
//
// We failed to find the first matching device so tell the caller
// that no suitable device is connected.
//
return(ERROR_DEVICE_NOT_CONNECTED);
}
//
// Now that we have the interface information, we need to query details
// to retrieve the device path. First determine how much space we need to
// hold the detail information.
//
SetupDiGetDeviceInterfaceDetail(deviceInfo,
&interfaceData,
NULL, 0,
&requiredLength,
NULL);
//
// Allocate a buffer to hold the interface details.
//
detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LMEM_FIXED,
requiredLength);
if(NULL == detailData)
{
SetupDiDestroyDeviceInfoList(deviceInfo);
return(ERROR_NOT_ENOUGH_MEMORY);
}
detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
length = requiredLength;
//
// Now call once again to retrieve the actual interface detail information.
//
bResult = SetupDiGetDeviceInterfaceDetail(deviceInfo,
&interfaceData,
detailData,
length,
&requiredLength,
NULL);
if(FALSE == bResult)
{
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(GetLastError());
}
//
// Copy the device path string from the interface details structure into
// the caller's buffer.
//
hr = StringCchCopy((LPTSTR)pcDevicePath,
BufLen,
(LPCTSTR)detailData->DevicePath);
if(FAILED(hr))
{
//
// We failed to copy the device path string!
//
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(ERROR_INSUFFICIENT_BUFFER);
}
//
// Clean up and free locally allocated resources.
//
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(ERROR_SUCCESS);
}
//****************************************************************************
//
// Opens the USB device and returns a file handle.
//
// \param None.
//
// This function determines whether or not the required USB device is
// available and, if so, creates a file allowing access to it. The file
// handle is returned on success.
//
// \return Returns a valid file handle on success of INVALID_HANDLE_VALUE
// on failure. In cases of failure, GetLastError() can be called to determine
// the cause.
//
//****************************************************************************
static HANDLE OpenDevice(void)
{
HANDLE hDev = NULL;
char devicePath[MAX_DEVPATH_LENGTH];
BOOL retVal;
//
// Get the path needed to open a file handle on our USB device.
//
retVal = GetDevicePath((LPGUID)&GUID_DEVINTERFACE_LUMINARY_BULK,
devicePath,
sizeof(devicePath));
if(retVal != ERROR_SUCCESS)
{
SetLastError(retVal);
return(INVALID_HANDLE_VALUE);
}
//
// Open the file we will use to communicate with the device.
//
hDev = CreateFile((LPCTSTR)devicePath,
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);
return(hDev);
}
//****************************************************************************
//
// Determines that the required USB device is present, opens it and gathers
// required information to allow us to read and write it.
//
// \param None.
//
// This function is called to initialize the USB device and perform one-off
// setup required to allocate handles allowing the application to read and
// write the device endpoints.
//
// \return Returns \e TRUE on success or \e FALSE on failure. In failing
// cases, GetLastError() can be called to determine the cause.
//
//****************************************************************************
BOOL InitializeDevice(void)
{
BOOL bResult;
WINUSB_INTERFACE_HANDLE usbHandle;
USB_INTERFACE_DESCRIPTOR ifaceDescriptor;
WINUSB_PIPE_INFORMATION pipeInfo;
UCHAR speed;
ULONG length;
int i;
//
// Determine whether the USB device is present and, if so, generate a file
// handle to allow access to it.
//
devInfo.deviceHandle = OpenDevice();
if(devInfo.deviceHandle == INVALID_HANDLE_VALUE)
{
//
// We were unable to access the device - return a failure.
//
return(FALSE);
}
//
// The device is opened so we now initialize the WinUSB layer passing it
// the device handle.
//
bResult = WinUsb_Initialize(devInfo.deviceHandle, &usbHandle);
if(bResult)
{
//
// If we managed to initialize the WinUSB layer, we now query the
// device descriptor to determine the speed of the device.
//
devInfo.winUSBHandle = usbHandle;
length = sizeof(UCHAR);
bResult = WinUsb_QueryDeviceInformation(devInfo.winUSBHandle,
DEVICE_SPEED,
&length,
&speed);
}
if(bResult)
{
//
// If all is well, now query the interface descriptor. We ask for the
// first interface only since, in the case of the generic bulk device,
// this is all that is available.
//
devInfo.deviceSpeed = speed;
bResult = WinUsb_QueryInterfaceSettings(devInfo.winUSBHandle,
0,
&ifaceDescriptor);
}
if(bResult)
{
//
// We got the interface descriptor so now we enumerate the endpoints
// to find the two we require - one bulk IN endpoint and one bulk OUT
// endpoint.
//
for(i=0;i<ifaceDescriptor.bNumEndpoints;i++)
{
bResult = WinUsb_QueryPipe(devInfo.winUSBHandle, 0, (UCHAR) i,
&pipeInfo);
if((pipeInfo.PipeType == UsbdPipeTypeBulk) &&
USB_ENDPOINT_DIRECTION_IN(pipeInfo.PipeId))
{
devInfo.bulkInPipe = pipeInfo.PipeId;
}
else if((pipeInfo.PipeType == UsbdPipeTypeBulk) &&
USB_ENDPOINT_DIRECTION_OUT(pipeInfo.PipeId))
{
devInfo.bulkOutPipe = pipeInfo.PipeId;
}
else
{
//
// Hmm... we found and endpoint that we didn't expect to see
// on this interface. This tends to imply that there is a
// mismatch between the device configuration and this
// application so we will fail the call after setting an
// appropriate error code for the caller to query.
//
SetLastError(ERROR_NOT_SAME_DEVICE);
bResult = FALSE;
break;
}
}
}
return(bResult);
}
//****************************************************************************
//
// Cleans up and free resources associated with the USB device communication
// prior to exiting the application.
//
// \param None.
//
// This function should be called prior to exiting the application to free
// the resources allocated during InitializeDevice().
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL TerminateDevice(void)
{
BOOL bRetcode;
BOOL bRetcode2;
bRetcode = WinUsb_Free(devInfo.winUSBHandle);
bRetcode2 = CloseHandle(devInfo.deviceHandle);
if(bRetcode & bRetcode2)
{
return(TRUE);
}
else
{
return(FALSE);
}
}
//****************************************************************************
//
// Writes a buffer of data to the USB device via the bulk OUT endpoint.
//
// \param pcBuffer points to the first byte of data to send.
// \param ulSize contains the number of bytes of data to send.
// \param pulWritten is a pointer which will be written with the number of
// bytes of data actually written to the device.
//
// This function is used to send data to the USB device via its bulk OUT
// endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL WriteUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulWritten)
{
BOOL bResult;
bResult = WinUsb_WritePipe(devInfo.winUSBHandle,
devInfo.bulkOutPipe,
pcBuffer,
ulSize,
pulWritten,
NULL);
return(bResult);
}
//****************************************************************************
//
// Reads data from the USB device via the bulk IN endpoint.
//
// \param pcBuffer points to a buffer into which the data from the device will
// be written.
// \param ulSize contains the number of bytes that are requested from the
// device.
// \param pulRead is a pointer which will be written with the number of
// bytes of data actually read from the device.
//
// This function is used to receivedata from the USB device via its bulk IN
// endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL ReadUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulRead)
{
BOOL bResult;
unsigned long ulSecondRead;
bResult = WinUsb_ReadPipe(devInfo.winUSBHandle,
devInfo.bulkInPipe,
pcBuffer,
ulSize,
pulRead,
NULL);
//
// Make sure we got the number of bytes expected. If we got less, try to
// read the remainder.
//
if(bResult && (*pulRead < ulSize))
{
bResult = WinUsb_ReadPipe(devInfo.winUSBHandle,
devInfo.bulkInPipe,
pcBuffer + *pulRead,
ulSize - *pulRead,
&ulSecondRead,
NULL);
if(bResult)
{
*pulRead += ulSecondRead;
}
}
return(bResult);
}
#endif // USE_WINUSB
//
// End of file
//
@@ -0,0 +1,70 @@
//###########################################################################
//
// FILE: ti_guids.h
//
// TITLE: GUIDs associated with TI Micro USB examples
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
#ifndef TI_GUIDS
#define TI_GUIDS
//
// Vendor and Product IDs for the generic bulk device.
//
#define BULK_VID 0x1cbe
#define BULK_PID 0x0003
//
// TI Bulk Device Class GUID
// {F5450C06-EB58-420e-8F98-A76C5D4AFB18}
//
DEFINE_GUID(GUID_DEVCLASS_TI_BULK,
0xF5450C06, 0xEB5B, 0x420E, 0x8F, 0x98, 0xA7, 0x6C, 0x5D, 0x4A, 0xFB, 0x18);
//
// TI Bulk Device Interface GUID
// {6E45736A-2B1B-4078-B772-B3AF2B6FDE1C}
//
DEFINE_GUID(GUID_DEVINTERFACE_TI_BULK,
0x6E45736A, 0x2B1B, 0x4078, 0xB7, 0x72, 0xb3, 0xAF, 0x2B, 0x6F, 0xDE, 0x1C);
#endif
//
// End of file
//
@@ -0,0 +1,318 @@
//###########################################################################
//
// FILE: usb_bulk_example_throughput.c
//
// TITLE: A very simple command line application that attempts
// to open the TI Generic Bulk USB device and exchange data
// with it.
//
// If the device is successfully opened, then data is sent continuously.
//
// Communication with the device is carried out via a simple DLL, tiusbdll(64),
// which is responsible for opening and closing the device and for
// sending and receiving blocks of data. This structure allows the
// application code to be kept independent of the underlying USB driver
// in use. In this implementation, Microsoft's WinUSB interface is used
// but a switch to another stack, for example the open source libusb-win32
// interface could be made merely be replacing the tiusbdll(64).dll with
// another version writing to the different USB stack.
//
// One downside to using WinUSB is that it requires you to have the Windows
// Device Driver Kit (DDK) installed to build applications which use the
// interface. This is a very large download making it awkward for people
// with slow internet connections. The use of tiusbdll(64).dll also offers
// the advantage that applications using it can still be modified and
// rebuilt even without the DDK installed on the development system. To
// update and rebuild tiusbdll itself, however, the DDK is still required.
//
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
//
// Included Files
//
#include <windows.h>
#include <strsafe.h>
#include <initguid.h>
#include "tiusbdll.h"
#include "ti_guids.h"
//
// Buffer size definitions.
//
#define MAX_STRING_LEN 65535
#define MAX_ENTRY_LEN 65535
#define USB_BUFFER_LEN 65535
//
// Defines
//
//
// The build version number
//
#define BLDVER "7611"
//
// The number of bytes we read and write per transaction if in echo mode.
//
#define ECHO_PACKET_SIZE 65535
//
// Globals
//
//
// Buffer into which error messages are written.
//
TCHAR g_pcErrorString[MAX_STRING_LEN];
//
// The number of bytes transferred in the last measurement interval.
//
ULONG g_ulByteCount = 0;
//
// The total number of packets transferred.
//
ULONG g_ulPacketCount = 0;
//
// Functions
//
//****************************************************************************
//
// Return a string describing the supplied system error code.
//
// \param dwError is a Windows system error code.
//
// This function returns a pointer to a string describing the error code
// passed in the dwError parameter. If no description string can be found
// the string "Unknown" is returned.
//
// \return Returns a pointer to a string describing the error.
//
//****************************************************************************
LPTSTR GetSystemErrorString(DWORD dwError)
{
DWORD dwRetcode;
//
// Ask Windows for the error message description.
//
dwRetcode = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, "%0", dwError, 0,
g_pcErrorString, MAX_STRING_LEN, NULL);
if(dwRetcode == 0)
{
return((LPTSTR)L"Unknown");
}
else
{
//
// Remove the trailing "\n\r" if present.
//
if(dwRetcode >= 2)
{
if(g_pcErrorString[dwRetcode - 2] == '\r')
{
g_pcErrorString[dwRetcode - 2] = '\0';
}
}
return(g_pcErrorString);
}
}
//****************************************************************************
//
// Print the throughput in terms of Kbps once per second.
//
//****************************************************************************
void UpdateThroughput(void)
{
static ULONG ulStartTime = 0;
static ULONG ulLast = 0;
ULONG ulNow;
ULONG ulElapsed;
SYSTEMTIME sSysTime;
//
// Get the current system time.
//
GetSystemTime(&sSysTime);
ulNow = (((((sSysTime.wHour * 60) +
sSysTime.wMinute) * 60) +
sSysTime.wSecond) * 1000) + sSysTime.wMilliseconds;
//
// If this is the first call, set the start time.
//
if(ulStartTime == 0)
{
ulStartTime = ulNow;
ulLast = ulNow;
return;
}
//
// How much time has elapsed since the last measurement?
//
ulElapsed = (ulNow > ulStartTime) ? (ulNow - ulStartTime) : (ulStartTime - ulNow);
//
// We dump a new measurement every second.
//
if(ulElapsed > 1000)
{
printf("\r%6dKbps Packets: %10d ", ((g_ulByteCount * 8) / ulElapsed),
g_ulPacketCount);
g_ulByteCount = 0;
ulStartTime = ulNow;
}
}
//****************************************************************************
//
// The main application entry function.
//
// \param None.
//
// This function forms the main entry point of the example application. It
// initializes the USB bulk device, prompts the user for an ASCII string,
// sends this string to the device, reads the response from the device (which
// will be the same string with the character order reversed if using the
// sample device provided) and displays the returned string.
//
// \return Set the exit code to 0 of no errors cause the application to end
// or a non-zero value otherwise.
//
//****************************************************************************
int main(int argc, char *argv[])
{
BOOL bResult;
BOOL bDriverInstalled;
char szBuffer[USB_BUFFER_LEN];
ULONG ulWritten;
ULONG ulRead;
ULONG ulLength;
DWORD dwError;
TIUSB_HANDLE hUSB;
//
// Print a cheerful welcome.
//
printf("\nTI Bulk Throughput USB Device Example\n");
printf( "---------------------------------\n\n");
printf("Version %s\n\n", BLDVER);
printf("This is a partner application to the Bulk Throughput Example\n");
printf("shipped software releases for USB-enabled boards. \n");
printf("It sends data and displays the throughput and transmitted data packets\n");
//
// Find our USB device and prepare it for communication.
//
hUSB = InitializeDevice(BULK_VID, BULK_PID,
(LPGUID)&(GUID_DEVINTERFACE_TI_BULK),
&bDriverInstalled);
if(hUSB)
{
printf("Press Ctrl+C to exit.\n\n");
while(1)
{
//
// Read a block of data from the device.
//
dwError = ReadUSBPacket(hUSB, szBuffer, ECHO_PACKET_SIZE, &ulRead,
INFINITE, NULL);
if(dwError != ERROR_SUCCESS)
{
//
// We failed to read from the device.
//
printf("\n\nError %d (%S) reading from bulk IN pipe.\n", dwError,
GetSystemErrorString(dwError));
break;
}
else
{
//
// Update our byte and packet counters.
//
g_ulByteCount += ulRead;
g_ulPacketCount++;
//
// Display the throughput.
//
UpdateThroughput();
}
}
}
else
{
//
// An error was reported while trying to connect to the device.
//
dwError = GetLastError();
printf("\nUnable to initialize the TI Bulk USB Device.\n");
printf("Error code is %d (%S)\n\n", dwError, GetSystemErrorString(dwError));
printf("Please make sure you have a TI USB-enabled evaluation\n");
printf("or development kit running the USB Device Bulk Throughput example\n");
printf("application connected to this system via the \"USB OTG\" or\n");
printf("\"USB DEVICE\" connectors. Once the device is connected, run\n");
printf("this application again.\n\n");
printf("\nPress \"Enter\" to exit: ");
fgets(szBuffer, MAX_STRING_LEN, stdin);
printf("\n");
return(2);
}
TerminateDevice(hUSB);
return(0);
}
//
// End of file
//
@@ -0,0 +1,381 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="usb_bulk_example_throughput"
ProjectGUID="{603D9796-4654-4082-9322-E4FC142312FB}"
RootNamespace="usb_bulk_example_throughput"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../lmusbdll"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="$(OutDir);..\Debug"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../lmusbdll"
PreprocessorDefinitions="X64_BUILD"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
OutputFile="$(OutDir)\$(ProjectName).exe"
LinkIncremental="2"
AdditionalLibraryDirectories="$(OutDir);..\x64\Debug"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../lmusbdll"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="$(OutDir);..\Release"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../lmusbdll"
PreprocessorDefinitions="X64_BUILD"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
OutputFile="$(OutDir)\$(ProjectName).exe"
LinkIncremental="1"
AdditionalLibraryDirectories="$(OutDir);..\x64\Release"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\usb_bulk_example_throughput.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\bulk_usb.h"
>
</File>
<File
RelativePath="..\lmusbdll\lmusbdll.h"
>
</File>
<File
RelativePath=".\luminary_guids.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<File
RelativePath=".\ReadMe.txt"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
@@ -0,0 +1,205 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{603D9796-4654-4082-9322-E4FC142312FB}</ProjectGuid>
<RootNamespace>usb_bulk_example_throughput</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>11.0.50727.1</_ProjectFileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<AdditionalIncludeDirectories>../tiusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>tiusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir);..\tiusbdll\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>../tiusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>X64_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>tiusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).exe</OutputFile>
<AdditionalLibraryDirectories>$(OutDir);..\tiusbdll\x64\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>../tiusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>tiusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir);..\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>../lmusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>X64_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>lmusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).exe</OutputFile>
<AdditionalLibraryDirectories>$(OutDir);..\x64\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="usb_bulk_example_throughput.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="bulk_usb.h" />
<ClInclude Include="luminary_guids.h" />
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,214 @@
//##############################################################################
//
// FILE: cmdline.c
//
// TITLE: Functions to help with processing command lines.
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
//******************************************************************************
//
//! \addtogroup cmdline_api
//! @{
//
//******************************************************************************
//
// Included Files
//
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "cmdline.h"
//
// Defines the maximum number of arguments that can be parsed.
//
#ifndef CMDLINE_MAX_ARGS
#define CMDLINE_MAX_ARGS 8
#endif
//
// An array to hold the pointers to the command line arguments.
//
static char *g_ppcArgv[CMDLINE_MAX_ARGS + 1];
//******************************************************************************
//
//! Process a command line string into arguments and execute the command.
//!
//! \param pcCmdLine points to a string that contains a command line that was
//! obtained by an application by some means.
//!
//! This function will take the supplied command line string and break it up
//! into individual arguments. The first argument is treated as a command and
//! is searched for in the command table. If the command is found, then the
//! command function is called and all of the command line arguments are passed
//! in the normal argc, argv form.
//!
//! The command table is contained in an array named <tt>g_psCmdTable</tt>
//! containing <tt>tCmdLineEntry</tt> structures which must be provided by the
//! application. The array must be terminated with an entry whose \b pcCmd
//! field contains a NULL pointer.
//!
//! \return Returns \b CMDLINE_BAD_CMD if the command is not found,
//! \b CMDLINE_TOO_MANY_ARGS if there are more arguments than can be parsed.
//! Otherwise it returns the code that was returned by the command function.
//
//******************************************************************************
int
CmdLineProcess(char *pcCmdLine)
{
char *pcChar;
uint_fast8_t ui8Argc;
bool bFindArg = true;
tCmdLineEntry *psCmdEntry;
//
// Initialize the argument counter, and point to the beginning of the
// command line string.
//
ui8Argc = 0;
pcChar = pcCmdLine;
//
// Advance through the command line until a zero character is found.
//
while(*pcChar)
{
//
// If there is a space, then replace it with a zero, and set the flag
// to search for the next argument.
//
if(*pcChar == ' ')
{
*pcChar = 0;
bFindArg = true;
}
//
// Otherwise it is not a space, so it must be a character that is part
// of an argument.
//
else
{
//
// If bFindArg is set, then that means we are looking for the start
// of the next argument.
//
if(bFindArg)
{
//
// As long as the maximum number of arguments has not been
// reached, then save the pointer to the start of this new arg
// in the argv array, and increment the count of args, argc.
//
if(ui8Argc < CMDLINE_MAX_ARGS)
{
g_ppcArgv[ui8Argc] = pcChar;
ui8Argc++;
bFindArg = false;
}
//
// The maximum number of arguments has been reached so return
// the error.
//
else
{
return(CMDLINE_TOO_MANY_ARGS);
}
}
}
//
// Advance to the next character in the command line.
//
pcChar++;
}
//
// If one or more arguments was found, then process the command.
//
if(ui8Argc)
{
//
// Start at the beginning of the command table, to look for a matching
// command.
//
psCmdEntry = &g_psCmdTable[0];
//
// Search through the command table until a null command string is
// found, which marks the end of the table.
//
while(psCmdEntry->pcCmd)
{
//
// If this command entry command string matches argv[0], then call
// the function for this command, passing the command line
// arguments.
//
if(!strcmp(g_ppcArgv[0], psCmdEntry->pcCmd))
{
return(psCmdEntry->pfnCmd(ui8Argc, g_ppcArgv));
}
//
// Not found, so advance to the next entry.
//
psCmdEntry++;
}
}
//
// Fall through to here means that no matching command was found, so return
// an error.
//
return(CMDLINE_BAD_CMD);
}
//******************************************************************************
//
// Close the Doxygen group.
//! @}
//
//******************************************************************************
//
// End of file
//
@@ -0,0 +1,147 @@
//##############################################################################
//
// FILE: cmdline.h
//
// TITLE: Prototypes for command line processing functions.
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
#ifndef CMDLINE_H
#define CMDLINE_H
//******************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//******************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//******************************************************************************
//
//! \addtogroup cmdline_api
//! @{
//
//******************************************************************************
//
//! Defines the value that is returned if the command is not found.
//
#define CMDLINE_BAD_CMD (-1)
//
//! Defines the value that is returned if there are too many arguments.
//
#define CMDLINE_TOO_MANY_ARGS (-2)
//
//! Defines the value that is returned if there are too few arguments.
//
#define CMDLINE_TOO_FEW_ARGS (-3)
//
//! Defines the value that is returned if an argument is invalid.
//
#define CMDLINE_INVALID_ARG (-4)
//
// Command line function callback type.
//
typedef int (*pfnCmdLine)(int argc, char *argv[]);
//******************************************************************************
//
//! Structure for an entry in the command list table.
//
//******************************************************************************
typedef struct
{
//
//! A pointer to a string containing the name of the command.
//
const char *pcCmd;
//
//! A function pointer to the implementation of the command.
//
pfnCmdLine pfnCmd;
//
//! A pointer to a string of brief help text for the command.
//
const char *pcHelp;
}
tCmdLineEntry;
//******************************************************************************
//
//! This is the command table that must be provided by the application. The
//! last element of the array must be a structure whose pcCmd field contains
//! a NULL pointer.
//
//******************************************************************************
extern tCmdLineEntry g_psCmdTable[];
//******************************************************************************
//
// Close the Doxygen group.
//! @}
//
//******************************************************************************
//
// Function Prototypes
//
extern int CmdLineProcess(char *pcCmdLine);
//******************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//******************************************************************************
#ifdef __cplusplus
}
#endif
#endif // CMDLINE_H
//
// End of file
//
@@ -0,0 +1,716 @@
//##############################################################################
//
// FILE: scistdio.c
//
// TITLE: Utility driver to provide simple SCI console functions.
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
//
// Included Files
//
#include "scistdio.h"
//******************************************************************************
//
//! \addtogroup SCIstdio_api
//! @{
//
//******************************************************************************
//
// The base address of the chosen SCI.
//
static uint32_t g_ui32Base = 0;
//
// A mapping from an integer between 0 and 15 to its ASCII character
// equivalent.
//
static const char * const g_pcHex = "0123456789abcdef";
//******************************************************************************
//
//! Configures the SCI console.
//!
//! \param base is the base address of SCI.
//! \param ui32Baud is the bit rate that the SCI is to be configured to use.
//! \param ui32SrcClock is the frequency of the source clock for the SCI
//! module.
//!
//! The serial parameters are set to the baud rate specified by the
//! \e ui32Baud parameter and use 8 bit, no parity, and 1 stop
//! bit.
//!
//! This function must be called prior to using any of the other SCI console
//! functions: SCIprintf() or SCIgets(). This function assumes that the
//! caller has previously configured the relevant SCI pins for operation as a
//! SCI rather than as GPIOs.
//!
//! \return None.
//
//******************************************************************************
void
SCIStdioConfig(uint32_t base, uint32_t ui32Baud, uint32_t ui32SrcClock)
{
//
// Select the base address of the SCI.
//
g_ui32Base = base;
//
// Configure the SCI for 115200, n, 8, 1
//
SCI_setConfig(g_ui32Base, ui32SrcClock, ui32Baud,
(SCI_CONFIG_PAR_NONE | SCI_CONFIG_STOP_ONE |
SCI_CONFIG_WLEN_8));
}
//******************************************************************************
//
//! Writes a string of characters to the SCI output.
//!
//! \param pcBuf points to a buffer containing the string to transmit.
//! \param ui32Len is the length of the string to transmit.
//!
//! This function will transmit the string to the SCI output. The number of
//! characters transmitted is determined by the \e ui32Len parameter. This
//! function does no interpretation or translation of any characters. Since
//! the output is sent to a SCI, any LF (/n) characters encountered will be
//! replaced with a CRLF pair.
//!
//! Besides using the \e ui32Len parameter to stop transmitting the string, if
//! a null character (0) is encountered, then no more characters will be
//! transmitted and the function will return.
//!
//! In non-buffered mode, this function is blocking and will not return until
//! all the characters have been written to the output FIFO. In buffered mode,
//! the characters are written to the SCI transmit buffer and the call returns
//! immediately. If insufficient space remains in the transmit buffer,
//! additional characters are discarded.
//!
//! \return Returns the count of characters written.
//
//******************************************************************************
int
SCIwrite(const char *pcBuf, uint32_t ui32Len)
{
unsigned int uIdx;
//
// Check for valid SCI base address, and valid arguments.
//
ASSERT(g_ui32Base != 0);
ASSERT(pcBuf != 0);
//
// Send the characters
//
for(uIdx = 0; uIdx < ui32Len; uIdx++)
{
//
// If the character to the SCI is \n, then add a \r before it so that
// \n is translated to \n\r in the output.
//
if(pcBuf[uIdx] == '\n')
{
SCI_writeCharBlockingNonFIFO(g_ui32Base, '\r');
}
//
// Send the character to the SCI output.
//
SCI_writeCharBlockingNonFIFO(g_ui32Base, pcBuf[uIdx]);
}
//
// Return the number of characters written.
//
return(uIdx);
}
//*****************************************************************************
//
//! A simple SCI based vprintf function supporting \%c, \%d, \%p, \%s, \%u,
//! \%x, and \%X.
//!
//! \param pcString is the format string.
//! \param vaArgP is a variable argument list pointer whose content will depend
//! upon the format string passed in \e pcString.
//!
//! This function is very similar to the C library <tt>vprintf()</tt> function.
//! All of its output will be sent to the SCI. Only the following formatting
//! characters are supported:
//!
//! - \%c to print a character
//! - \%d or \%i to print a decimal value
//! - \%l to print a long decimal value
//! - \%s to print a string
//! - \%u to print an unsigned decimal value
//! - \%x to print a hexadecimal value using lower case letters
//! - \%X to print a hexadecimal value using lower case letters (not upper case
//! letters as would typically be used)
//! - \%p to print a pointer as a hexadecimal value
//! - \%\% to print out a \% character
//!
//! For \%s, \%d, \%i, \%u, \%p, \%x, and \%X, an optional number may reside
//! between the \% and the format character, which specifies the minimum number
//! of characters to use for that value; if preceded by a 0 then the extra
//! characters will be filled with zeros instead of spaces. For example,
//! ``\%8d'' will use eight characters to print the decimal value with spaces
//! added to reach eight; ``\%08d'' will use eight characters as well but will
//! add zeroes instead of spaces.
//!
//! The type of the arguments in the variable arguments list must match the
//! requirements of the format string. For example, if an integer was passed
//! where a string was expected, an error of some kind will most likely occur.
//!
//! \return None.
//
//*****************************************************************************
void
SCIvprintf(const char *pcString, va_list vaArgP)
{
uint32_t ui32Idx, ui32Value, ui32Pos, ui32Count, ui32Base, ui32Neg;
char *pcStr, pcBuf[16], cFill;
//
// Check the arguments.
//
ASSERT(pcString != 0);
//
// Loop while there are more characters in the string.
//
while(*pcString)
{
//
// Find the first non-% character, or the end of the string.
//
for(ui32Idx = 0;
(pcString[ui32Idx] != '%') && (pcString[ui32Idx] != '\0');
ui32Idx++)
{
}
//
// Write this portion of the string.
//
SCIwrite(pcString, ui32Idx);
//
// Skip the portion of the string that was written.
//
pcString += ui32Idx;
//
// See if the next character is a %.
//
if(*pcString == '%')
{
//
// Skip the %.
//
pcString++;
//
// Set the digit count to zero, and the fill character to space
// (in other words, to the defaults).
//
ui32Count = 0;
cFill = ' ';
//
// It may be necessary to get back here to process more characters.
// Goto's aren't pretty, but effective. I feel extremely dirty for
// using not one but two of the beasts.
//
again:
//
// Determine how to handle the next character.
//
switch(*pcString++)
{
//
// Handle the digit characters.
//
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
{
//
// If this is a zero, and it is the first digit, then the
// fill character is a zero instead of a space.
//
if((pcString[-1] == '0') && (ui32Count == 0))
{
cFill = '0';
}
//
// Update the digit count.
//
ui32Count *= 10;
ui32Count += pcString[-1] - '0';
//
// Get the next character.
//
goto again;
}
//
// Handle the %c command.
//
case 'c':
{
//
// Get the value from the varargs.
//
ui32Value = va_arg(vaArgP, uint32_t);
//
// Print out the character.
//
SCIwrite((char *)&ui32Value, 1);
//
// This command has been handled.
//
break;
}
//
// Handle the %d and %i commands.
//
case 'd':
case 'i':
{
//
// Get the value from the varargs.
//
ui32Value = va_arg(vaArgP, uint32_t);
//
// Reset the buffer position.
//
ui32Pos = 0;
//
// If the value is negative, make it positive and indicate
// that a minus sign is needed.
//
if((int32_t)ui32Value < 0)
{
//
// Make the value positive.
//
ui32Value = -(int32_t)ui32Value;
//
// Indicate that the value is negative.
//
ui32Neg = 1;
}
else
{
//
// Indicate that the value is positive so that a minus
// sign isn't inserted.
//
ui32Neg = 0;
}
//
// Set the base to 10.
//
ui32Base = 10;
//
// Convert the value to ASCII.
//
goto convert;
}
//
// Handle the %l command.
//
case 'l':
{
//
// Get the value from the varargs.
//
ui32Value = va_arg(vaArgP, uint32_t);
//
// Reset the buffer position.
//
ui32Pos = 0;
//
// If the value is negative, make it positive and indicate
// that a minus sign is needed.
//
if((int32_t)ui32Value < 0)
{
//
// Make the value positive.
//
ui32Value = -(int32_t)ui32Value;
//
// Indicate that the value is negative.
//
ui32Neg = 1;
}
else
{
//
// Indicate that the value is positive so that a minus
// sign isn't inserted.
//
ui32Neg = 0;
}
//
// Set the base to 10.
//
ui32Base = 10;
//
// Convert the value to ASCII.
//
goto convert;
}
//
// Handle the %s command.
//
case 's':
{
//
// Get the string pointer from the varargs.
//
pcStr = va_arg(vaArgP, char *);
//
// Determine the length of the string.
//
for(ui32Idx = 0; pcStr[ui32Idx] != '\0'; ui32Idx++)
{
}
//
// Write the string.
//
SCIwrite(pcStr, ui32Idx);
//
// Write any required padding spaces
//
if(ui32Count > ui32Idx)
{
ui32Count -= ui32Idx;
while(ui32Count--)
{
SCIwrite(" ", 1);
}
}
//
// This command has been handled.
//
break;
}
//
// Handle the %u command.
//
case 'u':
{
//
// Get the value from the varargs.
//
ui32Value = va_arg(vaArgP, uint32_t);
//
// Reset the buffer position.
//
ui32Pos = 0;
//
// Set the base to 10.
//
ui32Base = 10;
//
// Indicate that the value is positive so that a minus sign
// isn't inserted.
//
ui32Neg = 0;
//
// Convert the value to ASCII.
//
goto convert;
}
//
// Handle the %x and %X commands. Note that they are treated
// identically; in other words, %X will use lower case letters
// for a-f instead of the upper case letters it should use. We
// also alias %p to %x.
//
case 'x':
case 'X':
case 'p':
{
//
// Get the value from the varargs.
//
ui32Value = va_arg(vaArgP, uint32_t);
//
// Reset the buffer position.
//
ui32Pos = 0;
//
// Set the base to 16.
//
ui32Base = 16;
//
// Indicate that the value is positive so that a minus sign
// isn't inserted.
//
ui32Neg = 0;
//
// Determine the number of digits in the string version of
// the value.
//
convert:
for(ui32Idx = 1;
(((ui32Idx * ui32Base) <= ui32Value) &&
(((ui32Idx * ui32Base) / ui32Base) == ui32Idx));
ui32Idx *= ui32Base, ui32Count--)
{
}
//
// If the value is negative, reduce the count of padding
// characters needed.
//
if(ui32Neg)
{
ui32Count--;
}
//
// If the value is negative and the value is padded with
// zeros, then place the minus sign before the padding.
//
if(ui32Neg && (cFill == '0'))
{
//
// Place the minus sign in the output buffer.
//
pcBuf[ui32Pos++] = '-';
//
// The minus sign has been placed, so turn off the
// negative flag.
//
ui32Neg = 0;
}
//
// Provide additional padding at the beginning of the
// string conversion if needed.
//
if((ui32Count > 1) && (ui32Count < 16))
{
for(ui32Count--; ui32Count; ui32Count--)
{
pcBuf[ui32Pos++] = cFill;
}
}
//
// If the value is negative, then place the minus sign
// before the number.
//
if(ui32Neg)
{
//
// Place the minus sign in the output buffer.
//
pcBuf[ui32Pos++] = '-';
}
//
// Convert the value into a string.
//
for(; ui32Idx; ui32Idx /= ui32Base)
{
pcBuf[ui32Pos++] =
g_pcHex[(ui32Value / ui32Idx) % ui32Base];
}
//
// Write the string.
//
SCIwrite(pcBuf, ui32Pos);
//
// This command has been handled.
//
break;
}
//
// Handle the %% command.
//
case '%':
{
//
// Simply write a single %.
//
SCIwrite(pcString - 1, 1);
//
// This command has been handled.
//
break;
}
//
// Handle all other commands.
//
default:
{
//
// Indicate an error.
//
SCIwrite("ERROR", 5);
//
// This command has been handled.
//
break;
}
}
}
}
}
//*****************************************************************************
//
//! A simple SCI based printf function supporting \%c, \%d, \%p, \%s, \%u,
//! \%x, and \%X.
//!
//! \param pcString is the format string.
//! \param ... are the optional arguments, which depend on the contents of the
//! format string.
//!
//! This function is very similar to the C library <tt>fprintf()</tt> function.
//! All of its output will be sent to the SCI. Only the following formatting
//! characters are supported:
//!
//! - \%c to print a character
//! - \%d or \%i to print a decimal value
//! - \%s to print a string
//! - \%u to print an unsigned decimal value
//! - \%x to print a hexadecimal value using lower case letters
//! - \%X to print a hexadecimal value using lower case letters (not upper case
//! letters as would typically be used)
//! - \%p to print a pointer as a hexadecimal value
//! - \%\% to print out a \% character
//!
//! For \%s, \%d, \%i, \%u, \%p, \%x, and \%X, an optional number may reside
//! between the \% and the format character, which specifies the minimum number
//! of characters to use for that value; if preceded by a 0 then the extra
//! characters will be filled with zeros instead of spaces. For example,
//! ``\%8d'' will use eight characters to print the decimal value with spaces
//! added to reach eight; ``\%08d'' will use eight characters as well but will
//! add zeroes instead of spaces.
//!
//! The type of the arguments after \e pcString must match the requirements of
//! the format string. For example, if an integer was passed where a string
//! was expected, an error of some kind will most likely occur.
//!
//! \return None.
//
//*****************************************************************************
void
SCIprintf(const char *pcString, ...)
{
va_list vaArgP;
//
// Start the varargs processing.
//
va_start(vaArgP, pcString);
SCIvprintf(pcString, vaArgP);
//
// We're finished with the varargs now.
//
va_end(vaArgP);
}
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************
//
// End of file
//
@@ -0,0 +1,101 @@
//##############################################################################
//
// FILE: scistdio.h
//
// TITLE: Prototypes for the UART console functions.
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
#ifndef SCISTDIO_H
#define SCISTDIO_H
//
// Included Files
//
#include "driverlib.h"
#include "device.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdarg.h>
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//
// If built for buffered operation, the following labels define the sizes of
// the transmit and receive buffers respectively.
//
#ifdef UART_BUFFERED
#ifndef UART_RX_BUFFER_SIZE
#define UART_RX_BUFFER_SIZE 128
#endif
#ifndef UART_TX_BUFFER_SIZE
#define UART_TX_BUFFER_SIZE 1024
#endif
#endif
//
// Function Prototypes
//
extern void SCIStdioConfig(uint32_t ui32Port, uint32_t ui32Baud,
uint32_t ui32SrcClock);
extern void SCIprintf(const char *pcString, ...);
extern void SCIvprintf(const char *pcString, va_list vaArgP);
extern int SCIwrite(const char *pcBuf, uint32_t ui32Len);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif // SCISTDIO_H
//
// End of file
//
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,96 @@
//##############################################################################
//
// FILE: ustdlib.h
//
// TITLE: Prototypes for simple standard library functions.
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
#ifndef __USTDLIB_H__
#define __USTDLIB_H__
//
// Included Files
//
#include <stdarg.h>
#include <time.h>
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
#ifdef __cplusplus
extern "C"
{
#endif
//
// Function Prototypes
//
extern void ulocaltime(time_t timer, struct tm *tm);
extern time_t umktime(struct tm *timeptr);
extern int urand(void);
extern int usnprintf(char * restrict s, size_t n, const char * restrict format,
...);
extern int usprintf(char * restrict s, const char * restrict format, ...);
extern void usrand(unsigned int seed);
extern int ustrcasecmp(const char *s1, const char *s2);
extern int ustrcmp(const char *s1, const char *s2);
extern size_t ustrlen(const char *s);
extern int ustrncasecmp(const char *s1, const char *s2, size_t n);
extern int ustrncmp(const char *s1, const char *s2, size_t n);
extern char *ustrncpy(char * restrict s1, const char * restrict s2, size_t n);
extern char *ustrstr(const char *s1, const char *s2);
extern float ustrtof(const char * restrict nptr,
const char ** restrict endptr);
extern unsigned long int ustrtoul(const char * restrict nptr,
const char ** restrict endptr, int base);
extern int uvsnprintf(char * restrict s, size_t n,
const char * restrict format, va_list arg);
//
// Mark the end of the C bindings section for C++ compilers.
//
#ifdef __cplusplus
}
#endif
#endif // __USTDLIB_H__
//
// End of file
//
@@ -0,0 +1,62 @@
//###########################################################################
//
// FILE: Resource.h
//
// TITLE: Microsoft Visual C++ generated include file.
//
//###########################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
//
//{{NO_DEPENDENCIES}}
// Used by lmusbdll.rc
//
//
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 1000
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 1000
#endif
#endif
//
// End of file
//
@@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// usbdll.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
@@ -0,0 +1,104 @@
//###########################################################################
//
// FILE: stdafx.h
//
// TITLE: include file for standard system include files
//
//###########################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#endif
//
// Modify the following defines if you have to target a platform prior to the
// ones specified below. Refer to MSDN for the latest info on corresponding
// values for different platforms.
#ifndef WINVER // Allow use of features specific to Windows XP or later.
#define WINVER 0x0501 // Change this to the appropriate value to target
// other versions of Windows.
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target
// other versions of Windows.
#endif
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target
// Windows Me or later.
#endif
#ifndef _WIN32_IE // Allow use of features specific to IE 6.0 or later.
#define _WIN32_IE 0x0600 // Change this to the appropriate value to target
// other versions of IE.
#endif
//
// some CString constructors will be explicit
//
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxole.h> // MFC OLE classes
#include <afxodlgs.h> // MFC OLE dialog classes
#include <afxdisp.h> // MFC Automation classes
#endif // _AFX_NO_OLE_SUPPORT
#ifndef _AFX_NO_DB_SUPPORT
#include <afxdb.h> // MFC ODBC database classes
#endif // _AFX_NO_DB_SUPPORT
#ifndef _AFX_NO_DAO_SUPPORT
#include <afxdao.h> // MFC DAO database classes
#endif // _AFX_NO_DAO_SUPPORT
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
//
// End of file
//
@@ -0,0 +1,964 @@
//###########################################################################
//
// FILE: tiusbdll.cpp
//
// TITLE: A thin layer over WinUSB allowing device open/close/
// read and write functionality.
//
// The WinUSB code in this example is based on information provided
// in Microsoft's white paper, "How to Use WinUSB to Communicate
// with a USB Device", WinUsb_HowTo.doc, available from URL:
//
// http://download.microsoft.com/download/9/c/5/9c5b2167-8017-4bae-9fde-
// d599bac8184a/WinUsb_HowTo.doc
//
//###########################################################################
//
// $Release Date: December 12, 2011 $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#include "stdafx.h"
#include <windows.h>
#include <setupapi.h>
#include <devguid.h>
#include <regstr.h>
#include <strsafe.h>
#include <initguid.h>
#include "winusb.h"
#include "usb100.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#include "resource.h" // main symbols
// CusbdllApp
// See usbdll.cpp for the implementation of this class
//
class CtiusbdllApp : public CWinApp
{
public:
CtiusbdllApp();
// Overrides
public:
virtual BOOL InitInstance();
DECLARE_MESSAGE_MAP()
};
// CtiusbdllApp
BEGIN_MESSAGE_MAP(CtiusbdllApp, CWinApp)
END_MESSAGE_MAP()
// CusbdllApp construction
CtiusbdllApp::CtiusbdllApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
// The one and only CusbdllApp object
CtiusbdllApp theApp;
// CusbdllApp initialization
BOOL CtiusbdllApp::InitInstance()
{
CWinApp::InitInstance();
return TRUE;
}
//****************************************************************************
//
// Buffer size definitions.
//
//****************************************************************************
#define MAX_DEVPATH_LENGTH 256
//****************************************************************************
//
// Flag indicating that a blocking read should be performed.
//
//****************************************************************************
#define TIUSB_WAIT_FOREVER 0xFFFFFFFF
//****************************************************************************
//
// Structure containing handles and information required to communicate with
// the USB bulk device.
//
//****************************************************************************
typedef struct
{
HANDLE deviceHandle;
WINUSB_INTERFACE_HANDLE winUSBHandle;
UCHAR deviceSpeed;
UCHAR bulkInPipe;
UCHAR bulkOutPipe;
HANDLE hReadEvent;
} tDeviceInfoWinUSB;
typedef void *TIUSB_HANDLE;
//****************************************************************************
//
// Returns the device path associated with a provided interface GUID.
//
// \param dwIndex is the zero-based index of the device whose path is to be
// found.
// \param InterfaceGuid is a pointer to the GUID for the interface that
// we are looking for. Assuming you installed the device using the sample
// INF file, this will be the GUID provided in the Dev_AddReg section.
// \param pcDevicePath is a pointer to a buffer into which will be written
// the path to the device if the function is successful.
// \param BufLen is the size of the buffer pointed to by \f pcDevicePath.
//
// Given an interface GUID, this function determines the path that is
// necessary to open a file handle on the USB device we are interested in
// talking to. It returns the path to the first device which is present in
// the system and which offers the required interface.
//
// \return Returns one of the following Windows system error codes.
// ERROR_SUCCESS if the operation completed successfully
// ERROR_DEV_NOT_EXIST if the interface is not found on the system. This
// implies that the driver for the USB device has not been installed.
// ERROR_DEVICE_NOT_CONNECTED if the interface has been installed but no
// device offering it is presently available. This typically indicates
// that the USB device is not currently connected.
// ERROR_NOT_ENOUGH_MEMORY if the function fails to allocate any required
// buffers.
// ERROR_INSUFFICIENT_BUFFER if the buffer passed is too small to hold
// the device path.
//****************************************************************************
static DWORD GetDevicePath(DWORD dwIndex, LPGUID InterfaceGuid,
PCHAR pcDevicePath,
size_t BufLen)
{
BOOL bResult = FALSE;
HDEVINFO deviceInfo;
SP_DEVICE_INTERFACE_DATA interfaceData;
PSP_DEVICE_INTERFACE_DETAIL_DATA detailData = NULL;
ULONG length;
ULONG requiredLength=0;
HRESULT hr;
//
// Get a handle to the device information set containing information on
// the interface GUID supplied on this PC.
//
deviceInfo = SetupDiGetClassDevs(InterfaceGuid,
NULL, NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if(deviceInfo == INVALID_HANDLE_VALUE)
{
//
// No device offering the required interface is present. Has the
// interface been installed? Ask for the information set for all
// devices and not just those that are presently installed.
//
deviceInfo = SetupDiGetClassDevs(InterfaceGuid,
NULL, NULL,
DIGCF_DEVICEINTERFACE);
if(deviceInfo == INVALID_HANDLE_VALUE)
{
return(ERROR_DEV_NOT_EXIST);
}
else
{
SetupDiDestroyDeviceInfoList(deviceInfo);
return(ERROR_DEVICE_NOT_CONNECTED);
}
}
interfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
//
// SetupDiGetClassDevs returned us a valid information set handle so we
// now query this set to find the find the first device offering the
// interface whose GUID was supplied.
//
bResult = SetupDiEnumDeviceInterfaces(deviceInfo,
NULL,
InterfaceGuid,
dwIndex,
&interfaceData);
if(bResult == FALSE)
{
//
// We failed to find the first matching device so tell the caller
// that no suitable device is connected.
//
return(ERROR_DEVICE_NOT_CONNECTED);
}
//
// Now that we have the interface information, we need to query details
// to retrieve the device path. First determine how much space we need to
// hold the detail information.
//
SetupDiGetDeviceInterfaceDetail(deviceInfo,
&interfaceData,
NULL, 0,
&requiredLength,
NULL);
//
// Allocate a buffer to hold the interface details.
//
detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LMEM_FIXED,
requiredLength);
if(NULL == detailData)
{
SetupDiDestroyDeviceInfoList(deviceInfo);
return(ERROR_NOT_ENOUGH_MEMORY);
}
detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
length = requiredLength;
//
// Now call once again to retrieve the actual interface detail information.
//
bResult = SetupDiGetDeviceInterfaceDetail(deviceInfo,
&interfaceData,
detailData,
length,
&requiredLength,
NULL);
if(FALSE == bResult)
{
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(GetLastError());
}
//
// Copy the device path string from the interface details structure into
// the caller's buffer.
//
hr = StringCchCopy((LPTSTR)pcDevicePath,
BufLen,
(LPCTSTR)detailData->DevicePath);
if(FAILED(hr))
{
//
// We failed to copy the device path string!
//
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(ERROR_INSUFFICIENT_BUFFER);
}
//
// Clean up and free locally allocated resources.
//
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(ERROR_SUCCESS);
}
//****************************************************************************
//
// Opens a given instance of the USB device and returns a file handle.
//
// \param dwIndex is the zero-based index of the device that is to be opened.
// \param lpGUID is a pointer to the GUID of the interface that is to
// be opened.
//
// This function determines whether or not the required USB device is
// available and, if so, creates a file allowing access to it. The file
// handle is returned on success.
//
// \return Returns a valid file handle on success of INVALID_HANDLE_VALUE
// on failure. In cases of failure, GetLastError() can be called to determine
// the cause.
//
//****************************************************************************
static HANDLE OpenDeviceByIndex(DWORD dwIndex, LPGUID lpGUID)
{
HANDLE hDev = NULL;
char devicePath[MAX_DEVPATH_LENGTH];
BOOL retVal;
//
// Get the path needed to open a file handle on our USB device.
//
retVal = GetDevicePath(dwIndex, lpGUID, devicePath, sizeof(devicePath));
if(retVal != ERROR_SUCCESS)
{
SetLastError(retVal);
return(INVALID_HANDLE_VALUE);
}
//
// Open the file we will use to communicate with the device.
//
hDev = CreateFile((LPCTSTR)devicePath,
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);
return(hDev);
}
//****************************************************************************
//
// Opens the first instance of a given USB device and returns a file handle.
//
// \param lpGUID is a pointer to the GUID of the interface that is to
// be opened.
//
// This function determines whether or not the required USB device is
// available and, if so, creates a file allowing access to it. The file
// handle is returned on success.
//
// \return Returns a valid file handle on success of INVALID_HANDLE_VALUE
// on failure. In cases of failure, GetLastError() can be called to determine
// the cause.
//
//****************************************************************************
static HANDLE OpenDevice(LPGUID lpGUID)
{
return(OpenDeviceByIndex(0, lpGUID));
}
//****************************************************************************
//
// Determines that the required USB device is present, opens it and gathers
// required information to allow us to read and write it.
//
// \param usVID is the vendor ID of the device to be initialized.
// \param usPID is the product ID of the device to be intialized.
// \param lpGUID is the GUID of the device interface that is to be opened.
// \param dwIndex is the zero-based index of the device to open.
// \param bOpenDataEndpoints is \e TRUE to open endpoints for bulk transfer
// of data to and from the host or \e FALSE to open the device without
// attempting to open any additional endpoints.
// \param pbDriverInstalled is written to \e TRUE if the device driver for the
// required class is installed or \e FALSE otherwise.
//
// This function is called to initialize the USB device and perform one-off
// setup required to allocate handles allowing the application to read and
// write the device endpoints. It offers a superset of the function provided
// by InitializeDevice(), allowing a caller to specify an index to differentiate
// between multiple devices of the same type and also offering the ability to
// open a device without opening endpoint handles for bulk data transfer.
//
// \return Returns a valid handle on success or NULL on failure. In failing
// cases, GetLastError() can be called to determine the cause.
//
//****************************************************************************
extern "C" TIUSB_HANDLE PASCAL EXPORT
InitializeDeviceByIndex(unsigned short usVID,
unsigned short usPID,
LPGUID lpGUID,
DWORD dwIndex,
BOOL bOpenDataEndpoints,
BOOL *pbDriverInstalled)
{
BOOL bResult;
WINUSB_INTERFACE_HANDLE usbHandle;
USB_INTERFACE_DESCRIPTOR ifaceDescriptor;
WINUSB_PIPE_INFORMATION pipeInfo;
UCHAR speed;
ULONG length;
DWORD dwError;
int i;
tDeviceInfoWinUSB *psDevInfo;
//
// Check for NULL pointer parameters.
//
if(!lpGUID || !pbDriverInstalled)
{
return(NULL);
}
//
// Allocate a new device info structure.
//
psDevInfo = (tDeviceInfoWinUSB *)LocalAlloc(LPTR, sizeof(tDeviceInfoWinUSB));
if(!psDevInfo)
{
return(NULL);
}
//
// Determine whether the USB device is present and, if so, generate a file
// handle to allow access to it.
//
psDevInfo->deviceHandle = OpenDeviceByIndex(dwIndex, lpGUID);
if(psDevInfo->deviceHandle == INVALID_HANDLE_VALUE)
{
//
// We were unable to access the device - is that because the device isn't
// connected or has the driver not been installed?
//
dwError = GetLastError();
*pbDriverInstalled = (dwError == ERROR_DEV_NOT_EXIST) ? FALSE : TRUE;
//
// Free our instance data.
//
LocalFree((HLOCAL)psDevInfo);
//
// Return an error to the caller.
//
return(NULL);
}
//
// The device is opened so we now initialize the WinUSB layer passing it
// the device handle.
//
bResult = WinUsb_Initialize(psDevInfo->deviceHandle, &usbHandle);
if(bResult)
{
//
// If we managed to initialize the WinUSB layer, we now query the
// device descriptor to determine the speed of the device.
//
psDevInfo->winUSBHandle = usbHandle;
length = sizeof(UCHAR);
bResult = WinUsb_QueryDeviceInformation(psDevInfo->winUSBHandle,
DEVICE_SPEED,
&length,
&speed);
}
//
// The device opened correctly. Do we need to also open pipes to allow us
// to send and receive data via the bulk endpoints?
//
if(bOpenDataEndpoints)
{
//
// Yes - we do need to open the endpoints for data transfer.
//
if(bResult)
{
//
// If all is well, now query the interface descriptor. We ask for the
// first interface only since, in the case of the generic bulk device,
// this is all that is available.
//
psDevInfo->deviceSpeed = speed;
bResult = WinUsb_QueryInterfaceSettings(psDevInfo->winUSBHandle,
0,
&ifaceDescriptor);
}
if(bResult)
{
//
// We got the interface descriptor so now we enumerate the endpoints
// to find the two we require - one bulk IN endpoint and one bulk OUT
// endpoint.
//
for(i=0;i<ifaceDescriptor.bNumEndpoints;i++)
{
bResult = WinUsb_QueryPipe(psDevInfo->winUSBHandle, 0, (UCHAR) i,
&pipeInfo);
if((pipeInfo.PipeType == UsbdPipeTypeBulk) &&
USB_ENDPOINT_DIRECTION_IN(pipeInfo.PipeId))
{
psDevInfo->bulkInPipe = pipeInfo.PipeId;
}
else if((pipeInfo.PipeType == UsbdPipeTypeBulk) &&
USB_ENDPOINT_DIRECTION_OUT(pipeInfo.PipeId))
{
psDevInfo->bulkOutPipe = pipeInfo.PipeId;
}
else
{
//
// Hmm... we found an endpoint that we didn't expect to see
// on this interface. This tends to imply that there is a
// mismatch between the device configuration and this
// application so we will fail the call after setting an
// appropriate error code for the caller to query.
//
SetLastError(ERROR_NOT_SAME_DEVICE);
bResult = FALSE;
break;
}
}
}
//
// Did all go well so far?
//
if(bResult)
{
//
// All is well - create the signal event we need.
//
psDevInfo->hReadEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
//
// If we created the event successfully, return a good handle.
//
if(psDevInfo->hReadEvent)
{
//
// Everything is good. Set the return code flag to indicate
// this.
//
bResult = true;
}
}
}
else
{
//
// Data transfer endpoints do not need to be opened so merely mark
// this in the device info structure.
//
psDevInfo->bulkOutPipe = 0;
psDevInfo->bulkInPipe = 0;
psDevInfo->hReadEvent = NULL;
}
//
// Did all go well?
//
if(bResult)
{
//
// All is well - return the instance data pointer as a handle to the
// caller.
//
return((TIUSB_HANDLE)psDevInfo);
}
else
{
//
// If we drop through to here, something went wrong so free the
// instance structure and return NULL.
//
LocalFree((HLOCAL)psDevInfo);
return(NULL);
}
}
//****************************************************************************
//
// Determines that the required USB device is present, opens it and gathers
// required information to allow us to read and write it.
//
// \param usVID is the vendor ID of the device to be initialized.
// \param usPID is the product ID of the device to be intialized.
// \param lpGUID is the GUID of the device interface that is to be opened.
// \param pbDriverInstalled is written to \e TRUE if the device driver for the
// required class is installed or \e FALSE otherwise.
//
// This function is called to initialize the USB device and perform one-off
// setup required to allocate handles allowing the application to read and
// write the device endpoints.
//
// InitializeDevice() always opens the first instance of a device and assumes
// that the caller will always want to open handles allowing communication via
// only IN and OUT bulk endpoints. To open an instance of a device other than
// the first or to open a device without opening handles on any endpoints other
// than the control endpoint, InitializeDeviceByIndex() may be used instead.
//
// \return Returns a valid handle on success or NULL on failure. In failing
// cases, GetLastError() can be called to determine the cause.
//
//****************************************************************************
extern "C" TIUSB_HANDLE PASCAL EXPORT
InitializeDevice(unsigned short usVID,
unsigned short usPID,
LPGUID lpGUID,
BOOL *pbDriverInstalled)
{
//
// Call our more capable cousin to open the first instance of the device
// and set up for data transfer via bulk IN and OUT endpoints.
//
return(InitializeDeviceByIndex(usVID, usPID, lpGUID, 0, true,
pbDriverInstalled));
}
//****************************************************************************
//
// Performs a control transfer on endpoint 0.
//
// \param hUSB is the device handle as returned from InitializeDevice().
// \param ucRequestType is the value to be placed in the bmRequestType field
// of the setup data as defined in table 9-2 of the USB 2.0 specification. The
// value is an ORed combination of the REQUEST_xxx flags found in tiusbdll.h.
// \param ucRequest is the specific request identifier which will be placed in
// the bRequest field of the setup data for the transaction.
// \param usValue is the request-specific value placed into the wValue field of
// the setup data for the transaction.
// \param usIndex is the value placed into the wIndex field of the setup data
// for the transaction.
// \param usLength is the number of bytes of data to transfer from or to the
// caller-supplied buffer during the transaction. This value is used to set
// the wLength field in the setup data for the transaction.
// \param pucBuffer is a pointer to a buffer containing at least usLength bytes.
// If ucRequestType contains REQUEST_TRANSFER_IN, usLength bytes of data will
// be transfered from the device and written into this buffer. If ucRequestType
// contains REQUEST_TRANSFER_OUT, usLength bytes of data will be transfered
// from this buffer to the device.
// \param pusCount will be written with the number of bytes actually written to
// or read from the device.
//
// This function performs a control transfer to the device. This transaction
// may transfer data to or from the device depending upon the value of the
// ucRequestType parameter.
//
// \return Returns \e TRUE on success or \e FALSE on failure. If \e FALSE is
// returned, GetLastError() may be called to determine the cause of the failure.
//
//****************************************************************************
extern "C" BOOL PASCAL EXPORT
Endpoint0Transfer(TIUSB_HANDLE hUSB, UCHAR ucRequestType, UCHAR ucRequest,
USHORT usValue, USHORT usIndex, USHORT usLength,
PUCHAR pucBuffer, PUSHORT pusCount)
{
tDeviceInfoWinUSB *psDevInfo = (tDeviceInfoWinUSB *)hUSB;
WINUSB_SETUP_PACKET sSetup;
ULONG ulCount;
ULONG ulError;
BOOL bRetcode;
//
// Check for invalid parameters. We require a buffer pointer if the
// transfer length is non-zero.
//
if(!hUSB || (usLength && !pucBuffer))
{
return(0);
}
//
// Fill in the setup data structure.
//
sSetup.RequestType = ucRequestType;
sSetup.Request = ucRequest;
sSetup.Value = usValue;
sSetup.Index = usIndex;
sSetup.Length = usLength;
//
// Issue the control transaction.
//
bRetcode = WinUsb_ControlTransfer(psDevInfo->winUSBHandle,
sSetup,
pucBuffer,
(ULONG)usLength,
&ulCount,
NULL);
//
// Return either the number of bytes written/read or 0 if there was an
// error.
//
if(bRetcode)
{
*pusCount = (USHORT)ulCount;
}
else
{
ulError = GetLastError();
*pusCount = 0;
}
return(bRetcode);
}
//****************************************************************************
//
// Cleans up and free resources associated with the USB device communication
// prior to exiting the application.
//
// \param hUSB is the device handle as returned from InitializeDevice().
//
// This function should be called prior to exiting the application to free
// the resources allocated during InitializeDevice().
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
extern "C" BOOL PASCAL EXPORT TerminateDevice(TIUSB_HANDLE hUSB)
{
BOOL bRetcode;
BOOL bRetcode2;
tDeviceInfoWinUSB *psDevInfo = (tDeviceInfoWinUSB *)hUSB;
//
// Check for a bad handle.
//
if(!hUSB)
{
return(false);
}
//
// Free WinUSB and Windows resources.
//
bRetcode = WinUsb_Free(psDevInfo->winUSBHandle);
bRetcode2 = CloseHandle(psDevInfo->deviceHandle);
//
// Free the device instance structure.
//
LocalFree((HLOCAL)psDevInfo);
//
// Did all go well?
//
if(bRetcode & bRetcode2)
{
return(TRUE);
}
else
{
return(FALSE);
}
}
//****************************************************************************
//
// Writes a buffer of data to the USB device via the bulk OUT endpoint.
//
// \param hUSB is the device handle as returned from InitializeDevice().
// \param pcBuffer points to the first byte of data to send.
// \param ulSize contains the number of bytes of data to send.
// \param pulWritten is a pointer which will be written with the number of
// bytes of data actually written to the device.
//
// This function is used to send data to the USB device via its bulk OUT endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
extern "C" BOOL PASCAL EXPORT
WriteUSBPacket(TIUSB_HANDLE hUSB, unsigned char *pcBuffer,
unsigned long ulSize,
unsigned long *pulWritten)
{
BOOL bResult;
tDeviceInfoWinUSB *psDevInfo = (tDeviceInfoWinUSB *)hUSB;
//
// Check for bad parameters.
//
if(!hUSB || !pcBuffer || !pulWritten || !ulSize)
{
return(false);
}
//
// Ask WinUSB to write the data for us.
//
bResult = WinUsb_WritePipe(psDevInfo->winUSBHandle,
psDevInfo->bulkOutPipe,
pcBuffer,
ulSize,
pulWritten,
NULL);
return(bResult);
}
//****************************************************************************
//
// Reads data from the USB device via the bulk IN endpoint.
//
// \param hUSB is the device handle as returned from InitializeDevice().
// \param pcBuffer points to a buffer into which the data from the device will
// be written.
// \param ulSize contains the number of bytes that are requested from the
// device.
// \param pulRead is a pointer which will be written with the number of
// bytes of data actually read from the device.
// \param ulTimeoutmS is the number of milliseconds to wait for the
// data before returning an error. To block indefinitely, set this parameter
// to INFINITE.
// \param hBreak is the handle of an event that may be used to break out of
// the read operation. If this is a valid event handle and the event is
// signalled, the read operation will return immediately. Set this to
// NULL if the additional break condition is not required.
//
// This function is used to receive data from the USB device via its bulk IN
// endpoint.
//
// \return Returns \e ERROR_SUCCESS on success, WAIT_TIMEOUT if the data as
// not received within ulTimeoutmS milliseconds, WAIT_OBJECT_0 if the break
// event was signalled or other Windows system error codes on failure.
//
//****************************************************************************
extern "C" DWORD PASCAL EXPORT
ReadUSBPacket(TIUSB_HANDLE hUSB, unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulRead, unsigned long ulTimeoutmS, HANDLE hBreak)
{
BOOL bResult;
DWORD dwError;
OVERLAPPED sOverlapped;
HANDLE phSignals[2];
tDeviceInfoWinUSB *psDevInfo = (tDeviceInfoWinUSB *)hUSB;
//
// Check for bad parameters.
//
if(!hUSB || !pcBuffer || !pulRead || !ulSize)
{
return(ERROR_INVALID_PARAMETER);
}
//
// Tell WinUSB how to signal us when reads are completed (if blocking)
//
sOverlapped.hEvent = psDevInfo->hReadEvent;
sOverlapped.Offset = 0;
sOverlapped.OffsetHigh = 0;
//
// Perform the read.
//
bResult = WinUsb_ReadPipe(psDevInfo->winUSBHandle,
psDevInfo->bulkInPipe,
pcBuffer,
ulSize,
pulRead,
&sOverlapped);
//
// A good return code indicates success regardless of whether we performed
// a blocking or non-blocking read.
//
if(bResult)
{
dwError = ERROR_SUCCESS;
}
else
{
//
// An error occurred or the read will complete asynchronously.
// Which is it?
//
dwError = GetLastError();
//
// Check for error cases other than the one we expect.
//
if(dwError == ERROR_IO_PENDING)
{
//
// The IO is pending so wait for it to complete or for a
// timeout to occur.
//
phSignals[0] = psDevInfo->hReadEvent;
phSignals[1] = hBreak;
dwError = WaitForMultipleObjects(hBreak ? 2 : 1, phSignals, FALSE,
ulTimeoutmS);
//
// At this stage, one of three things could have occurred.
// Either we read a packet or we timed out or the break
// signal was detected. Which was it?
//
if(dwError == WAIT_OBJECT_0)
{
//
// The overlapped IO request completed so check to see how
// many bytes we got.
//
bResult = GetOverlappedResult(psDevInfo->deviceHandle,
&sOverlapped,
pulRead, FALSE);
if(bResult)
{
dwError = ERROR_SUCCESS;
}
else
{
//
// Something went wrong. Return the Windows error code.
//
dwError = GetLastError();
}
}
else
{
//
// Something went wrong - abort the transfer
//
WinUsb_AbortPipe(psDevInfo->winUSBHandle,
psDevInfo->bulkInPipe);
//
// Was the break event signalled?
//
if(dwError == (WAIT_OBJECT_0 + 1))
{
//
// The break event was signalled - abort the read and return.
//
dwError = WAIT_OBJECT_0;
}
}
}
}
//
// Pass the result back to the caller.
//
return(dwError);
}
@@ -0,0 +1,14 @@
; tiusbdll.def : Declares the module parameters for the DLL.
LIBRARY "tiusbdll"
; DESCRIPTION "A simple library allowing low level access to a WinUSB device"
VERSION 1.1
EXPORTS
; Explicit exports can go here
InitializeDevice @1
TerminateDevice @2
WriteUSBPacket @3
ReadUSBPacket @4
InitializeDeviceByIndex @5
Endpoint0Transfer @6
@@ -0,0 +1,140 @@
//###########################################################################
//
// FILE: tiusbdll.h
//
// TITLE: A thin layer over WinUSB allowing device open/close/
// read and write functionality.
//
//###########################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifdef __cplusplus
#pragma once
#ifndef __AFXWIN_H__
#error "include 'stdafx.h' before including this file for PCH"
#endif
//
// Functions exported by this DLL.
//
extern "C" {
#endif
//
// A handle returned by InitializeDevice().
//
typedef void *TIUSB_HANDLE;
//
// Flags used in constructing the ucRequestType parameter to
// Endpoint0Transfer().
//
#define REQUEST_TRANSFER_IN 0x80
#define REQUEST_TRANSFER_OUT 0x00
#define REQUEST_TYPE_STANDARD 0x00
#define REQUEST_TYPE_CLASS 0x20
#define REQUEST_TYPE_VENDOR 0x40
#define REQUEST_RECIPIENT_DEVICE 0x00
#define REQUEST_RECIPIENT_INTERFACE 0x01
#define REQUEST_RECIPIENT_ENDPOINT 0x02
#define REQUEST_RECIPIENT_OTHER 0x03
//
// Function Prototypes exported by the DLL.
//
TIUSB_HANDLE __stdcall InitializeDevice(unsigned short usVID,
unsigned short usPID,
LPGUID lpGUID,
BOOL *pbDriverInstalled);
TIUSB_HANDLE __stdcall InitializeDeviceByIndex(unsigned short usVID,
unsigned short usPID,
LPGUID lpGUID,
DWORD dwIndex,
BOOL bOpenDataEndpoints,
BOOL *pbDriverInstalled);
BOOL __stdcall TerminateDevice(TIUSB_HANDLE hHandle);
BOOL __stdcall WriteUSBPacket(TIUSB_HANDLE hHandle,
unsigned char *pcBuffer,
unsigned long ulSize,
unsigned long *pulWritten);
DWORD __stdcall ReadUSBPacket(TIUSB_HANDLE hHandle,
unsigned char *pcBuffer,
unsigned long ulSize,
unsigned long *pulRead,
unsigned long ulTimeoutMs,
HANDLE hBreak);
BOOL __stdcall Endpoint0Transfer(TIUSB_HANDLE hHandle, UCHAR ucRequestType,
UCHAR ucRequest, USHORT usValue,
USHORT usIndex, USHORT usLength,
PUCHAR pucBuffer, PUSHORT pusCount);
//
// Typedefs for each of the exported functions. This helps if applications
// want to link the DLL dynamically using LoadLibrary rather than linking
// directly to the lib file.
//
typedef TIUSB_HANDLE (__stdcall *tInitializeDevice)(unsigned short usVID,
unsigned short usPID,
LPGUID lpGUID,
BOOL *pbDriverInstalled);
typedef BOOL (__stdcall *tTerminateDevice)(TIUSB_HANDLE hHandle);
typedef BOOL (__stdcall *tWriteUSBPacket)(TIUSB_HANDLE hHandle,
unsigned char *pcBuffer,
unsigned long ulSize,
unsigned long *pulWritten);
typedef DWORD (__stdcall *tReadUSBPacket)(TIUSB_HANDLE hHandle,
unsigned char *pcBuffer,
unsigned long ulSize,
unsigned long *pulRead,
unsigned long ulTimeoutMs,
HANDLE hBreak);
typedef DWORD (__stdcall *tEndpoint0Transfer)(TIUSB_HANDLE hHandle,
UCHAR ucRequestType,
UCHAR ucRequest, USHORT usValue,
USHORT usIndex, USHORT usLength,
PUCHAR pucBuffer,
PUSHORT pusCount);
#ifdef __cplusplus
}
#endif
//
// End of file
//
@@ -0,0 +1,120 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
"#define _AFX_NO_OLE_RESOURCES\r\n"
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
"\r\n"
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
"LANGUAGE 9, 1\r\n"
"#pragma code_page(1252)\r\n"
"#include ""afxres.rc"" // Standard components\r\n"
"#endif\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,6734
PRODUCTVERSION 1,0,0,6734
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904e4"
BEGIN
VALUE "CompanyName", "Texas Instruments Incorporated"
VALUE "FileDescription", "A DLL used to interface Windows example applications to the WinUSB subsystem"
VALUE "FileVersion", "6734"
VALUE "InternalName", "tiusbdll.dll"
VALUE "LegalCopyright", "Copyright (c) 2008-2010 Texas Instruments Incorporated. All rights reserved."
VALUE "OriginalFilename", "tiusbdll.dll"
VALUE "ProductName", "Texas Instruments USB DLL"
VALUE "ProductVersion", "6734"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1252
END
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE 9, 1
#pragma code_page(1252)
#include "afxres.rc" // Standard components
#endif
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
@@ -0,0 +1,275 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{25B000DF-5F76-4D5E-8C26-2C63FD2E8BA1}</ProjectGuid>
<RootNamespace>usbdll</RootNamespace>
<Keyword>MFCDLLProj</Keyword>
<ProjectName>tiusbdll</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<CustomBuildAfterTargets Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</LinkIncremental>
<CustomBuildAfterTargets Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Midl>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MkTypLibCompatible>false</MkTypLibCompatible>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\usb_bulk_example;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include\gl;C:\Program Files\Microsoft SDKs\Windows\v6.1\VC\Include;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(FrameworkSDKDir)include;$(DDKROOT)\inc\wdf\umdf\1.9;$(DDKROOT)\inc\api;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>winusb.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(DDKROOT)\lib\wlh\i386;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ModuleDefinitionFile>tiusbdll.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
</Link>
<CustomBuildStep>
<Outputs>${OutDir}\tiusbdll.lib;%(Outputs)</Outputs>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<CustomBuildStep>
<Outputs>${OutDir}\tiusbdll.lib;%(Outputs)</Outputs>
</CustomBuildStep>
<Midl>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MkTypLibCompatible>false</MkTypLibCompatible>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\usb_bulk_example;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include\gl;C:\Program Files\Microsoft SDKs\Windows\v6.1\VC\Include;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(FrameworkSDKDir)include;$(DDKROOT)\inc\wdf\umdf\1.9;$(DDKROOT)\inc\api;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>winusb.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<AdditionalLibraryDirectories>$(DDKROOT)\lib\wlh\amd64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ModuleDefinitionFile>tiusbdll.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Midl>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MkTypLibCompatible>false</MkTypLibCompatible>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>..\usb_bulk_example;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include\gl;C:\Program Files\Microsoft SDKs\Windows\v6.1\VC\Include;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(FrameworkSDKDir)include;$(DDKROOT)\inc\wdf\umdf\1.9;$(DDKROOT)\inc\api;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<ProjectReference>
<UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
</ProjectReference>
<Link>
<AdditionalDependencies>winusb.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(DDKROOT)\lib\wlh\i386;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ModuleDefinitionFile>tiusbdll.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
<CustomBuildStep>
<Outputs>${OutDir}\tiusbdll.lib;%(Outputs)</Outputs>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<CustomBuildStep>
<Command>touch $(OutDir)tiusbdll.lib
</Command>
<Outputs>$(OutDir)tiusbdll.lib;%(Outputs)</Outputs>
</CustomBuildStep>
<Midl>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MkTypLibCompatible>false</MkTypLibCompatible>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>..\usb_bulk_example;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include\gl;C:\Program Files\Microsoft SDKs\Windows\v6.1\VC\Include;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(FrameworkSDKDir)include;$(DDKROOT)\inc\wdf\umdf\1.9;$(DDKROOT)\inc\api;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<IgnoreStandardIncludePath>true</IgnoreStandardIncludePath>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>winusb.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<AdditionalLibraryDirectories>$(DDKROOT)\lib\wlh\amd64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ModuleDefinitionFile>lmusbdll.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="tiusbdll.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="tiusbdll.def" />
<None Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="tiusbdll.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="stdafx.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="tiusbdll.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,22 @@
-----------------------------------
USB Bulk Example (usb_bulk_example)
-----------------------------------
This Windows command line application is written using C for Windows
and should be built using Microsoft Visual Studio 2010. Project
file usb_bulk_example.vxcproj is provided to build the application.
USB communication with the board running the usb_dev_bulk sample application
is performed using the TIUSBDLL interface which is a thin wrapper over the
Microsoft WinUSB API. The relevant WinUSB subsystem files and the
TIUSBDLL.dll are installed when you first connect the board to a Windows
host via USB and install the drivers. Device drivers for the usb_dev_bulk
device can be found in the MWare\windows_drivers directory.
The TIUSBDLL interface is provided purely to allow the sample applications
to be compiled and run in the absence of the Windows Device Driver Kit
(DDK). The WinUSB API header and library files are not included in the
Windows SDK shipped with Visual Studio 2010 so any code which uses this
interface requires access to the DDK to build. TIUSBDLL contains all
the application code requiring WinUSB so applications may link to it
without the need for the Windows DDK.
@@ -0,0 +1,156 @@
//###########################################################################
//
// FILE: bulk_libusb.c
//
// TITLE: Implementation of the bulk_usb interface using the linusb-win32 API.
//
//###########################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef USE_WINUSB
//
// Included Files
//
#include "libusb-win32\include\usb.h"
//
// Structure containing handles and information required to communicate with
// the USB bulk device.
//
typedef struct
{
usb_dev_handle *hDevice;
} tDeviceInfo;
tDeviceInfo devInfo;
//
// Functions
//
//****************************************************************************
//
// Determines that the required USB device is present, opens it and gathers
// required information to allow us to read and write it.
//
// \param None.
//
// This function is called to initialize the USB device and perform one-off
// setup required to allocate handles allowing the application to read and
// write the device endpoints.
//
// \return Returns \e TRUE on success or \e FALSE on failure. In failing
// cases, GetLastError() can be called to determine the cause.
//
//****************************************************************************
BOOL InitializeDevice(void)
{
//
// Initialize the libusb-win32 subsystem.
//
usb_init();
return(TRUE);
}
//****************************************************************************
//
// Cleans up and free resources associated with the USB device communication
// prior to exiting the application.
//
// \param None.
//
// This function should be called prior to exiting the application to free
// the resources allocated during InitializeDevice().
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL TerminateDevice(void)
{
return(TRUE);
}
//****************************************************************************
//
// Writes a buffer of data to the USB device via the bulk OUT endpoint.
//
// \param pcBuffer points to the first byte of data to send.
// \param ulSize contains the number of bytes of data to send.
// \param pulWritten is a pointer which will be written with the number of
// bytes of data actually written to the device.
//
// This function is used to send data to the USB device via its bulk OUT endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL WriteUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulWritten)
{
return(TRUE);
}
//****************************************************************************
//
// Reads data from the USB device via the bulk IN endpoint.
//
// \param pcBuffer points to a buffer into which the data from the device will
// be written.
// \param ulSize contains the number of bytes that are requested from the
// device.
// \param pulRead is a pointer which will be written with the number of
// bytes of data actually read from the device.
//
// This function is used to receivedata from the USB device via its bulk IN
// endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL ReadUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulRead)
{
return(TRUE);
}
#endif // not defined USE_WINUSB
//
// End of file
//
@@ -0,0 +1,61 @@
//###########################################################################
//
// FILE: bulk_usb.h
//
// TITLE: Public header for the USB interface used by the usb_bulk_example
// application.
//
//###########################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef __BULK_USB_H__
#define __BULK_USB_H__
//
// Function Prototypes
//
extern BOOL InitializeDevice(void);
extern BOOL TerminateDevice(void);
extern BOOL WriteUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulWritten);
extern BOOL ReadUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulRead);
#endif
//
// End of file
//
@@ -0,0 +1,525 @@
//###########################################################################
//
// FILE: bulk_winusb.c
//
// TITLE: Implementation of the bulk_usb interface using Microsoft's
// WinUSB API.
//
//###########################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifdef USE_WINUSB
//
// Included Files
//
#include <windows.h>
#include <setupapi.h>
#include <devguid.h>
#include <regstr.h>
#include <strsafe.h>
#include <initguid.h>
#include "bulk_usb.h"
#include "luminary_guids.h"
#include "winusb.h"
#include "usb100.h"
//
// Defines
//
#define MAX_DEVPATH_LENGTH 256
//
// Globals
//
//
// Structure containing handles and information required to communicate with
// the USB bulk device.
//
typedef struct
{
HANDLE deviceHandle;
WINUSB_INTERFACE_HANDLE winUSBHandle;
UCHAR deviceSpeed;
UCHAR bulkInPipe;
UCHAR bulkOutPipe;
} tDeviceInfoWinUSB;
tDeviceInfoWinUSB devInfo;
//
// Functions
//
//****************************************************************************
//
// Returns the device path associated with a provided interface GUID.
//
// \param InterfaceGuid is a pointer to the GUID for the interface that
// we are looking for. Assuming you installed the device using the sample
// INF file, this will be the GUID provided in the Dev_AddReg section.
// \param pcDevicePath is a pointer to a buffer into which will be written
// the path to the device if the function is successful.
// \param BufLen is the size of the buffer pointed to by \f pcDevicePath.
//
// Given an interface GUID, this function determines the path that is
// necessary to open a file handle on the USB device we are interested in
// talking to. It returns the path to the first device which is present in
// the system and which offers the required interface.
//
// \return Returns one of the following Windows system error codes.
// ERROR_SUCCESS if the operation completed successfully
// ERROR_DEV_NOT_EXIST if the interface is not found on the system. This
// implies that the driver for the USB device has not been installed.
// ERROR_DEVICE_NOT_CONNECTED if the interface has been installed but no
// device offering it is presently available. This typically indicates
// that the USB device is not currently connected.
// ERROR_NOT_ENOUGH_MEMORY if the function fails to allocate any required
// buffers.
// ERROR_INSUFFICIENT_BUFFER if the buffer passed is too small to hold
// the device path.
//
//****************************************************************************
static DWORD GetDevicePath(LPGUID InterfaceGuid,
PCHAR pcDevicePath,
size_t BufLen)
{
BOOL bResult = FALSE;
HDEVINFO deviceInfo;
SP_DEVICE_INTERFACE_DATA interfaceData;
PSP_DEVICE_INTERFACE_DETAIL_DATA detailData = NULL;
ULONG length;
ULONG requiredLength=0;
HRESULT hr;
//
// Get a handle to the device information set containing information on
// the interface GUID supplied on this PC.
//
deviceInfo = SetupDiGetClassDevs(InterfaceGuid,
NULL, NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if(deviceInfo == INVALID_HANDLE_VALUE)
{
//
// No device offering the required interface is present. Has the
// interface been installed? Ask for the information set for all
// devices and not just those that are presently installed.
//
deviceInfo = SetupDiGetClassDevs(InterfaceGuid,
NULL, NULL,
DIGCF_DEVICEINTERFACE);
if(deviceInfo == INVALID_HANDLE_VALUE)
{
return(ERROR_DEV_NOT_EXIST);
}
else
{
SetupDiDestroyDeviceInfoList(deviceInfo);
return(ERROR_DEVICE_NOT_CONNECTED);
}
}
interfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
//
// SetupDiGetClassDevs returned us a valid information set handle so we
// now query this set to find the find the first device offering the
// interface whose GUID was supplied.
//
bResult = SetupDiEnumDeviceInterfaces(deviceInfo,
NULL,
InterfaceGuid,
0,
&interfaceData);
if(bResult == FALSE)
{
//
// We failed to find the first matching device so tell the caller
// that no suitable device is connected.
//
return(ERROR_DEVICE_NOT_CONNECTED);
}
//
// Now that we have the interface information, we need to query details
// to retrieve the device path. First determine how much space we need to
// hold the detail information.
//
SetupDiGetDeviceInterfaceDetail(deviceInfo,
&interfaceData,
NULL, 0,
&requiredLength,
NULL);
//
// Allocate a buffer to hold the interface details.
//
detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LMEM_FIXED,
requiredLength);
if(NULL == detailData)
{
SetupDiDestroyDeviceInfoList(deviceInfo);
return(ERROR_NOT_ENOUGH_MEMORY);
}
detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
length = requiredLength;
//
// Now call once again to retrieve the actual interface detail information.
//
bResult = SetupDiGetDeviceInterfaceDetail(deviceInfo,
&interfaceData,
detailData,
length,
&requiredLength,
NULL);
if(FALSE == bResult)
{
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(GetLastError());
}
//
// Copy the device path string from the interface details structure into
// the caller's buffer.
//
hr = StringCchCopy((LPTSTR)pcDevicePath,
BufLen,
(LPCTSTR)detailData->DevicePath);
if(FAILED(hr))
{
//
// We failed to copy the device path string!
//
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(ERROR_INSUFFICIENT_BUFFER);
}
//
// Clean up and free locally allocated resources.
//
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(ERROR_SUCCESS);
}
//****************************************************************************
//
// Opens the USB device and returns a file handle.
//
// \param None.
//
// This function determines whether or not the required USB device is
// available and, if so, creates a file allowing access to it. The file
// handle is returned on success.
//
// \return Returns a valid file handle on success of INVALID_HANDLE_VALUE
// on failure. In cases of failure, GetLastError() can be called to determine
// the cause.
//
//****************************************************************************
static HANDLE OpenDevice(void)
{
HANDLE hDev = NULL;
char devicePath[MAX_DEVPATH_LENGTH];
BOOL retVal;
//
// Get the path needed to open a file handle on our USB device.
//
retVal = GetDevicePath((LPGUID)&GUID_DEVINTERFACE_LUMINARY_BULK,
devicePath,
sizeof(devicePath));
if(retVal != ERROR_SUCCESS)
{
SetLastError(retVal);
return(INVALID_HANDLE_VALUE);
}
//
// Open the file we will use to communicate with the device.
//
hDev = CreateFile((LPCTSTR)devicePath,
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);
return(hDev);
}
//****************************************************************************
//
// Determines that the required USB device is present, opens it and gathers
// required information to allow us to read and write it.
//
// \param None.
//
// This function is called to initialize the USB device and perform one-off
// setup required to allocate handles allowing the application to read and
// write the device endpoints.
//
// \return Returns \e TRUE on success or \e FALSE on failure. In failing
// cases, GetLastError() can be called to determine the cause.
//
//****************************************************************************
BOOL InitializeDevice(void)
{
BOOL bResult;
WINUSB_INTERFACE_HANDLE usbHandle;
USB_INTERFACE_DESCRIPTOR ifaceDescriptor;
WINUSB_PIPE_INFORMATION pipeInfo;
UCHAR speed;
ULONG length;
int i;
//
// Determine whether the USB device is present and, if so, generate a file
// handle to allow access to it.
//
devInfo.deviceHandle = OpenDevice();
if(devInfo.deviceHandle == INVALID_HANDLE_VALUE)
{
//
// We were unable to access the device - return a failure.
//
return(FALSE);
}
//
// The device is opened so we now initialize the WinUSB layer passing it
// the device handle.
//
bResult = WinUsb_Initialize(devInfo.deviceHandle, &usbHandle);
if(bResult)
{
//
// If we managed to initialize the WinUSB layer, we now query the
// device descriptor to determine the speed of the device.
//
devInfo.winUSBHandle = usbHandle;
length = sizeof(UCHAR);
bResult = WinUsb_QueryDeviceInformation(devInfo.winUSBHandle,
DEVICE_SPEED,
&length,
&speed);
}
if(bResult)
{
//
// If all is well, now query the interface descriptor. We ask for the
// first interface only since, in the case of the generic bulk device,
// this is all that is available.
//
devInfo.deviceSpeed = speed;
bResult = WinUsb_QueryInterfaceSettings(devInfo.winUSBHandle,
0,
&ifaceDescriptor);
}
if(bResult)
{
//
// We got the interface descriptor so now we enumerate the endpoints
// to find the two we require - one bulk IN endpoint and one bulk OUT
// endpoint.
//
for(i=0;i<ifaceDescriptor.bNumEndpoints;i++)
{
bResult = WinUsb_QueryPipe(devInfo.winUSBHandle, 0, (UCHAR) i,
&pipeInfo);
if((pipeInfo.PipeType == UsbdPipeTypeBulk) &&
USB_ENDPOINT_DIRECTION_IN(pipeInfo.PipeId))
{
devInfo.bulkInPipe = pipeInfo.PipeId;
}
else if((pipeInfo.PipeType == UsbdPipeTypeBulk) &&
USB_ENDPOINT_DIRECTION_OUT(pipeInfo.PipeId))
{
devInfo.bulkOutPipe = pipeInfo.PipeId;
}
else
{
//
// Hmm... we found and endpoint that we didn't expect to see
// on this interface. This tends to imply that there is a
// mismatch between the device configuration and this
// application so we will fail the call after setting an
// appropriate error code for the caller to query.
//
SetLastError(ERROR_NOT_SAME_DEVICE);
bResult = FALSE;
break;
}
}
}
return(bResult);
}
//****************************************************************************
//
// Cleans up and free resources associated with the USB device communication
// prior to exiting the application.
//
// \param None.
//
// This function should be called prior to exiting the application to free
// the resources allocated during InitializeDevice().
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL TerminateDevice(void)
{
BOOL bRetcode;
BOOL bRetcode2;
bRetcode = WinUsb_Free(devInfo.winUSBHandle);
bRetcode2 = CloseHandle(devInfo.deviceHandle);
if(bRetcode & bRetcode2)
{
return(TRUE);
}
else
{
return(FALSE);
}
}
//****************************************************************************
//
// Writes a buffer of data to the USB device via the bulk OUT endpoint.
//
// \param pcBuffer points to the first byte of data to send.
// \param ulSize contains the number of bytes of data to send.
// \param pulWritten is a pointer which will be written with the number of
// bytes of data actually written to the device.
//
// This function is used to send data to the USB device via its bulk OUT
// endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL WriteUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulWritten)
{
BOOL bResult;
bResult = WinUsb_WritePipe(devInfo.winUSBHandle,
devInfo.bulkOutPipe,
pcBuffer,
ulSize,
pulWritten,
NULL);
return(bResult);
}
//****************************************************************************
//
// Reads data from the USB device via the bulk IN endpoint.
//
// \param pcBuffer points to a buffer into which the data from the device will
// be written.
// \param ulSize contains the number of bytes that are requested from the
// device.
// \param pulRead is a pointer which will be written with the number of
// bytes of data actually read from the device.
//
// This function is used to receivedata from the USB device via its bulk IN
// endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL ReadUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulRead)
{
BOOL bResult;
unsigned long ulSecondRead;
bResult = WinUsb_ReadPipe(devInfo.winUSBHandle,
devInfo.bulkInPipe,
pcBuffer,
ulSize,
pulRead,
NULL);
//
// Make sure we got the number of bytes expected. If we got less, try to
// read the remainder.
//
if(bResult && (*pulRead < ulSize))
{
bResult = WinUsb_ReadPipe(devInfo.winUSBHandle,
devInfo.bulkInPipe,
pcBuffer + *pulRead,
ulSize - *pulRead,
&ulSecondRead,
NULL);
if(bResult)
{
*pulRead += ulSecondRead;
}
}
return(bResult);
}
#endif // USE_WINUSB
//
// End of file
//
@@ -0,0 +1,70 @@
//###########################################################################
//
// FILE: ti_guids.h
//
// TITLE: GUIDs associated with TI Micro USB examples
//
//###########################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef _TI_GUIDS_
#define _TI_GUIDS_
//
// Vendor and Product IDs for the generic bulk device.
//
#define BULK_VID 0x1cbe
#define BULK_PID 0x0003
//
// TI Bulk Device Class GUID
// {F5450C06-EB58-420e-8F98-A76C5D4AFB18}
//
DEFINE_GUID(GUID_DEVCLASS_TI_BULK,
0xF5450C06, 0xEB5B, 0x420E, 0x8F, 0x98, 0xA7, 0x6C, 0x5D, 0x4A, 0xFB, 0x18);
//
// TI Bulk Device Interface GUID
// {6E45736A-2B1B-4078-B772-B3AF2B6FDE1C}
//
DEFINE_GUID(GUID_DEVINTERFACE_TI_BULK,
0x6E45736A, 0x2B1B, 0x4078, 0xB7, 0x72, 0xb3, 0xAF, 0x2B, 0x6F, 0xDE, 0x1C);
#endif
//
// End of file
//
@@ -0,0 +1,477 @@
//###########################################################################
//
// FILE: usb_bulk_example.c
//
// TITLE: A very simple command line application that attempts
// to open the TI Generic Bulk USB device and exchange data
// with it.
//
// If the device is successfully opened, the user is prompted for a string
// which is then sent to the device. The device toggles the case of any
// alphabet characters in the the data and sends it back. We receive this
// and print out the result.
//
// Communication with the device is carried out via a simple DLL, tiusbdll(64),
// which is responsible for opening and closing the device and for
// sending and receiving blocks of data. This structure allows the
// application code to be kept independent of the underlying USB driver
// in use. In this implementation, Microsoft's WinUSB interface is used
// but a switch to another stack, for example the open source libusb-win32
// interface could be made merely be replacing the tiusbdll(64).dll with
// another version writing to the different USB stack.
//
// One downside to using WinUSB is that it requires you to have the Windows
// Device Driver Kit (DDK) installed to build applications which use the
// interface. This is a very large download making it awkward for people
// with slow internet connections. The use of tiusbdll(64).dll also offers
// the advantage that applications using it can still be modified and
// rebuilt even without the DDK installed on the development system. To
// update and rebuild tiusbdll itself, however, the DDK is still required.
//
//
//###########################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
//
// Included Files
//
#include <windows.h>
#include <strsafe.h>
#include <initguid.h>
#include "tiusbdll.h"
#include "ti_guids.h"
//
// Buffer size definitions.
//
#define MAX_STRING_LEN 256
#define MAX_ENTRY_LEN 256
#define USB_BUFFER_LEN 1216
//
// Defines
//
//
// The build version number
//
#define BLDVER "7611"
//
// The number of bytes we read and write per transaction if in echo mode.
//
#define ECHO_PACKET_SIZE 64
//
// Globals
//
//
// Buffer into which error messages are written.
//
TCHAR g_pcErrorString[MAX_STRING_LEN];
//
// The number of bytes transferred in the last measurement interval.
//
ULONG g_ulByteCount = 0;
//
// The total number of packets transferred.
//
ULONG g_ulPacketCount = 0;
//
// Functions
//
//****************************************************************************
//
// Return a string describing the supplied system error code.
//
// \param dwError is a Windows system error code.
//
// This function returns a pointer to a string describing the error code
// passed in the dwError parameter. If no description string can be found
// the string "Unknown" is returned.
//
// \return Returns a pointer to a string describing the error.
//
//****************************************************************************
LPTSTR GetSystemErrorString(DWORD dwError)
{
DWORD dwRetcode;
//
// Ask Windows for the error message description.
//
dwRetcode = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, "%0", dwError, 0,
g_pcErrorString, MAX_STRING_LEN, NULL);
if(dwRetcode == 0)
{
return((LPTSTR)L"Unknown");
}
else
{
//
// Remove the trailing "\n\r" if present.
//
if(dwRetcode >= 2)
{
if(g_pcErrorString[dwRetcode - 2] == '\r')
{
g_pcErrorString[dwRetcode - 2] = '\0';
}
}
return(g_pcErrorString);
}
}
//****************************************************************************
//
// Print the throughput in terms of Kbps once per second.
//
//****************************************************************************
void UpdateThroughput(void)
{
static ULONG ulStartTime = 0;
static ULONG ulLast = 0;
ULONG ulNow;
ULONG ulElapsed;
SYSTEMTIME sSysTime;
//
// Get the current system time.
//
GetSystemTime(&sSysTime);
ulNow = (((((sSysTime.wHour * 60) +
sSysTime.wMinute) * 60) +
sSysTime.wSecond) * 1000) + sSysTime.wMilliseconds;
//
// If this is the first call, set the start time.
//
if(ulStartTime == 0)
{
ulStartTime = ulNow;
ulLast = ulNow;
return;
}
//
// How much time has elapsed since the last measurement?
//
ulElapsed = (ulNow > ulStartTime) ? (ulNow - ulStartTime) : (ulStartTime - ulNow);
//
// We dump a new measurement every second.
//
if(ulElapsed > 1000)
{
printf("\r%6dKbps Packets: %10d ", ((g_ulByteCount * 8) / ulElapsed),
g_ulPacketCount);
g_ulByteCount = 0;
ulStartTime = ulNow;
}
}
//****************************************************************************
//
// The main application entry function.
//
// \param None.
//
// This function forms the main entry point of the example application. It
// initializes the USB bulk device, prompts the user for an ASCII string,
// sends this string to the device, reads the response from the device (which
// will be the same string with the character order reversed if using the
// sample device provided) and displays the returned string.
//
// \return Set the exit code to 0 of no errors cause the application to end
// or a non-zero value otherwise.
//
//****************************************************************************
int main(int argc, char *argv[])
{
BOOL bResult;
BOOL bDriverInstalled;
BOOL bEcho;
char szBuffer[USB_BUFFER_LEN];
ULONG ulWritten;
ULONG ulRead;
ULONG ulLength;
DWORD dwError;
TIUSB_HANDLE hUSB;
//
// Are we operating in echo mode or not? The "-e" parameter tells the
// app to echo everything it receives back to the device unchanged.
//
bEcho = ((argc > 1) && (argv[1][1] == 'e')) ? TRUE : FALSE;
//
// Print a cheerful welcome.
//
printf("\nTI Bulk USB Device Example\n");
printf( "---------------------------------\n\n");
printf("Version %s\n\n", BLDVER);
if(!bEcho)
{
printf("This is a partner application to the usb_dev_bulk example\n");
printf("shipped software releases for USB-enabled boards. \n");
printf("Strings entered here are sent to the board which\n");
printf("inverts the case of the characters in the string and returns\n");
printf("them to the host.\n\n");
}
else
{
printf("If run with the \"-e\" command line switch, this application\n");
printf("echoes all data received on the bulk IN endpoint to the bulk\n");
printf("OUT endpoint. This feature may be helpful during development\n");
printf("and debug of your own USB devices. Note that this will not\n");
printf("do anything exciting if run with the usb_dev_bulk example\n");
printf("device attached since it expects the host to initiate transfers.\n\n");
}
//
// Find our USB device and prepare it for communication.
//
hUSB = InitializeDevice(BULK_VID, BULK_PID,
(LPGUID)&(GUID_DEVINTERFACE_TI_BULK),
&bDriverInstalled);
if(hUSB)
{
//
// Are we operating in echo mode or not? The "-e" parameter tells the
// app to echo everything it receives back to the device unchanged.
//
if(bEcho)
{
//
// Yes - we are in echo mode.
//
printf("Running in echo mode. Press Ctrl+C to exit.\n\n");
while(1)
{
//
// Read a block of data from the device.
//
dwError = ReadUSBPacket(hUSB, szBuffer, ECHO_PACKET_SIZE, &ulRead,
INFINITE, NULL);
if(dwError != ERROR_SUCCESS)
{
//
// We failed to read from the device.
//
printf("\n\nError %d (%S) reading from bulk IN pipe.\n", dwError,
GetSystemErrorString(dwError));
break;
}
else
{
//
// Update our byte and packet counters.
//
g_ulByteCount += ulRead;
g_ulPacketCount++;
//
// Write the data back out to the device.
//
bResult = WriteUSBPacket(hUSB, szBuffer, ulRead, &ulWritten);
if(!bResult)
{
//
// We failed to write the data for some reason.
//
dwError = GetLastError();
printf("\n\nError %d (%S) writing to bulk OUT pipe.\n",
dwError, GetSystemErrorString(dwError));
break;
}
//
// Display the throughput.
//
UpdateThroughput();
}
}
}
else
{
//
// We are running in normal mode. Keep sending and receiving
// strings until the user indicates that it is time to exit.
//
while(1)
{
//
// The device was found and successfully configured.
// Now get a string from the user...
//
do
{
printf("\nEnter a string (EXIT to exit): ");
fgets(szBuffer, MAX_ENTRY_LEN, stdin);
printf("\n");
//
// How many characters were entered
// (including the trailing '\n')?
//
ulLength = (ULONG)strlen(szBuffer);
if(ulLength <= 1)
{
//
// The string is either nothing at all or a single
// '\n' so reprompt the user.
//
printf("\nPlease enter some text.\n");
ulLength = 0;
}
else
{
//
// Get rid of the trailing '\n' if there is one there.
//
if(szBuffer[ulLength - 1] == '\n')
{
szBuffer[ulLength - 1] = '\0';
ulLength--;
}
}
}
while(ulLength == 0);
//
// Are we being asked to exit the application?
//
if(!(strcmp("EXIT", szBuffer)))
{
//
// Yes - drop out and exit.
//
printf("Exiting on user request.\n");
break;
}
//
// Write the user's string to the device.
//
bResult = WriteUSBPacket(hUSB, szBuffer, ulLength, &ulWritten);
if(!bResult)
{
//
// We failed to write the data for some reason.
//
dwError = GetLastError();
printf("Error %d (%S) writing to bulk OUT pipe.\n", dwError,
GetSystemErrorString(dwError));
}
else
{
//
// We wrote data successfully so now read it back.
//
printf("Wrote %d bytes to the device. Expected %d\n",
ulWritten, ulLength);
//
// We expect the same number of bytes as we just sent.
//
dwError = ReadUSBPacket(hUSB, szBuffer, ulWritten, &ulRead,
INFINITE, NULL);
if(dwError != ERROR_SUCCESS)
{
//
// We failed to read from the device.
//
printf("Error %d (%S) reading from bulk IN pipe.\n",
dwError, GetSystemErrorString(dwError));
}
else
{
//
// Add a string terminator to the returned data (this
// should already be there but, just in case...)
//
szBuffer[ulRead] = '\0';
printf("Read %d bytes from device. Expected %d\n",
ulRead, ulWritten);
printf("\nReturned string: \"%s\"\n", szBuffer);
}
}
}
}
}
else
{
//
// An error was reported while trying to connect to the device.
//
dwError = GetLastError();
printf("\nUnable to initialize the TI Bulk USB Device.\n");
printf("Error code is %d (%S)\n\n", dwError, GetSystemErrorString(dwError));
printf("Please make sure you have a TI USB-enabled evaluation\n");
printf("or development kit running the usb_dev_bulk example\n");
printf("application connected to this system via the \"USB OTG\" or\n");
printf("\"USB DEVICE\" connectors. Once the device is connected, run\n");
printf("this application again.\n\n");
printf("\nPress \"Enter\" to exit: ");
fgets(szBuffer, MAX_STRING_LEN, stdin);
printf("\n");
return(2);
}
TerminateDevice(hUSB);
return(0);
}
//
// End of file
//
@@ -0,0 +1,381 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="usb_bulk_example"
ProjectGUID="{603D9796-4654-4082-9322-E4FC142312FB}"
RootNamespace="usb_bulk_example"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../lmusbdll"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="$(OutDir);..\Debug"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../lmusbdll"
PreprocessorDefinitions="X64_BUILD"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
OutputFile="$(OutDir)\$(ProjectName).exe"
LinkIncremental="2"
AdditionalLibraryDirectories="$(OutDir);..\x64\Debug"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../lmusbdll"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="$(OutDir);..\Release"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../lmusbdll"
PreprocessorDefinitions="X64_BUILD"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
OutputFile="$(OutDir)\$(ProjectName).exe"
LinkIncremental="1"
AdditionalLibraryDirectories="$(OutDir);..\x64\Release"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\usb_bulk_example.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\bulk_usb.h"
>
</File>
<File
RelativePath="..\lmusbdll\lmusbdll.h"
>
</File>
<File
RelativePath=".\luminary_guids.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<File
RelativePath=".\ReadMe.txt"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
@@ -0,0 +1,206 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{603D9796-4654-4082-9322-E4FC142312FB}</ProjectGuid>
<RootNamespace>usb_bulk_example</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>11.0.50727.1</_ProjectFileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>../tiusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>tiusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir);..\tiusbdll\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>../tiusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>X64_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>tiusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).exe</OutputFile>
<AdditionalLibraryDirectories>$(OutDir);..\tiusbdll\x64\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>../tiusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>tiusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir);..\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>../lmusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>X64_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>lmusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).exe</OutputFile>
<AdditionalLibraryDirectories>$(OutDir);..\x64\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="usb_bulk_example.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="bulk_usb.h" />
<ClInclude Include="..\lmusbdll\lmusbdll.h" />
<ClInclude Include="luminary_guids.h" />
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,156 @@
//###########################################################################
//
// FILE: bulk_libusb.c
//
// TITLE: Implementation of the bulk_usb interface using the linusb-win32 API.
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
#ifndef USE_WINUSB
//
// Included Files
//
#include "libusb-win32\include\usb.h"
//
// Structure containing handles and information required to communicate with
// the USB bulk device.
//
typedef struct
{
usb_dev_handle *hDevice;
} tDeviceInfo;
tDeviceInfo devInfo;
//
// Functions
//
//****************************************************************************
//
// Determines that the required USB device is present, opens it and gathers
// required information to allow us to read and write it.
//
// \param None.
//
// This function is called to initialize the USB device and perform one-off
// setup required to allocate handles allowing the application to read and
// write the device endpoints.
//
// \return Returns \e TRUE on success or \e FALSE on failure. In failing
// cases, GetLastError() can be called to determine the cause.
//
//****************************************************************************
BOOL InitializeDevice(void)
{
//
// Initialize the libusb-win32 subsystem.
//
usb_init();
return(TRUE);
}
//****************************************************************************
//
// Cleans up and free resources associated with the USB device communication
// prior to exiting the application.
//
// \param None.
//
// This function should be called prior to exiting the application to free
// the resources allocated during InitializeDevice().
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL TerminateDevice(void)
{
return(TRUE);
}
//****************************************************************************
//
// Writes a buffer of data to the USB device via the bulk OUT endpoint.
//
// \param pcBuffer points to the first byte of data to send.
// \param ulSize contains the number of bytes of data to send.
// \param pulWritten is a pointer which will be written with the number of
// bytes of data actually written to the device.
//
// This function is used to send data to the USB device via its bulk OUT endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL WriteUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulWritten)
{
return(TRUE);
}
//****************************************************************************
//
// Reads data from the USB device via the bulk IN endpoint.
//
// \param pcBuffer points to a buffer into which the data from the device will
// be written.
// \param ulSize contains the number of bytes that are requested from the
// device.
// \param pulRead is a pointer which will be written with the number of
// bytes of data actually read from the device.
//
// This function is used to receivedata from the USB device via its bulk IN
// endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL ReadUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulRead)
{
return(TRUE);
}
#endif // not defined USE_WINUSB
//
// End of file
//
@@ -0,0 +1,61 @@
//###########################################################################
//
// FILE: bulk_usb.h
//
// TITLE: Public header for the USB interface used by the
// usb_bulk_example_throughput application.
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
#ifndef BULK_USB_H
#define BULK_USB_H
//
// Function Prototypes
//
extern BOOL InitializeDevice(void);
extern BOOL TerminateDevice(void);
extern BOOL WriteUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulWritten);
extern BOOL ReadUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulRead);
#endif
//
// End of file
//
@@ -0,0 +1,525 @@
//###########################################################################
//
// FILE: bulk_winusb.c
//
// TITLE: Implementation of the bulk_usb interface using Microsoft's
// WinUSB API.
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
#ifdef USE_WINUSB
//
// Included Files
//
#include <windows.h>
#include <setupapi.h>
#include <devguid.h>
#include <regstr.h>
#include <strsafe.h>
#include <initguid.h>
#include "bulk_usb.h"
#include "luminary_guids.h"
#include "winusb.h"
#include "usb100.h"
//
// Defines
//
#define MAX_DEVPATH_LENGTH 256
//
// Globals
//
//
// Structure containing handles and information required to communicate with
// the USB bulk device.
//
typedef struct
{
HANDLE deviceHandle;
WINUSB_INTERFACE_HANDLE winUSBHandle;
UCHAR deviceSpeed;
UCHAR bulkInPipe;
UCHAR bulkOutPipe;
} tDeviceInfoWinUSB;
tDeviceInfoWinUSB devInfo;
//
// Functions
//
//****************************************************************************
//
// Returns the device path associated with a provided interface GUID.
//
// \param InterfaceGuid is a pointer to the GUID for the interface that
// we are looking for. Assuming you installed the device using the sample
// INF file, this will be the GUID provided in the Dev_AddReg section.
// \param pcDevicePath is a pointer to a buffer into which will be written
// the path to the device if the function is successful.
// \param BufLen is the size of the buffer pointed to by \f pcDevicePath.
//
// Given an interface GUID, this function determines the path that is
// necessary to open a file handle on the USB device we are interested in
// talking to. It returns the path to the first device which is present in
// the system and which offers the required interface.
//
// \return Returns one of the following Windows system error codes.
// ERROR_SUCCESS if the operation completed successfully
// ERROR_DEV_NOT_EXIST if the interface is not found on the system. This
// implies that the driver for the USB device has not been installed.
// ERROR_DEVICE_NOT_CONNECTED if the interface has been installed but no
// device offering it is presently available. This typically indicates
// that the USB device is not currently connected.
// ERROR_NOT_ENOUGH_MEMORY if the function fails to allocate any required
// buffers.
// ERROR_INSUFFICIENT_BUFFER if the buffer passed is too small to hold
// the device path.
//
//****************************************************************************
static DWORD GetDevicePath(LPGUID InterfaceGuid,
PCHAR pcDevicePath,
size_t BufLen)
{
BOOL bResult = FALSE;
HDEVINFO deviceInfo;
SP_DEVICE_INTERFACE_DATA interfaceData;
PSP_DEVICE_INTERFACE_DETAIL_DATA detailData = NULL;
ULONG length;
ULONG requiredLength=0;
HRESULT hr;
//
// Get a handle to the device information set containing information on
// the interface GUID supplied on this PC.
//
deviceInfo = SetupDiGetClassDevs(InterfaceGuid,
NULL, NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if(deviceInfo == INVALID_HANDLE_VALUE)
{
//
// No device offering the required interface is present. Has the
// interface been installed? Ask for the information set for all
// devices and not just those that are presently installed.
//
deviceInfo = SetupDiGetClassDevs(InterfaceGuid,
NULL, NULL,
DIGCF_DEVICEINTERFACE);
if(deviceInfo == INVALID_HANDLE_VALUE)
{
return(ERROR_DEV_NOT_EXIST);
}
else
{
SetupDiDestroyDeviceInfoList(deviceInfo);
return(ERROR_DEVICE_NOT_CONNECTED);
}
}
interfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
//
// SetupDiGetClassDevs returned us a valid information set handle so we
// now query this set to find the find the first device offering the
// interface whose GUID was supplied.
//
bResult = SetupDiEnumDeviceInterfaces(deviceInfo,
NULL,
InterfaceGuid,
0,
&interfaceData);
if(bResult == FALSE)
{
//
// We failed to find the first matching device so tell the caller
// that no suitable device is connected.
//
return(ERROR_DEVICE_NOT_CONNECTED);
}
//
// Now that we have the interface information, we need to query details
// to retrieve the device path. First determine how much space we need to
// hold the detail information.
//
SetupDiGetDeviceInterfaceDetail(deviceInfo,
&interfaceData,
NULL, 0,
&requiredLength,
NULL);
//
// Allocate a buffer to hold the interface details.
//
detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LMEM_FIXED,
requiredLength);
if(NULL == detailData)
{
SetupDiDestroyDeviceInfoList(deviceInfo);
return(ERROR_NOT_ENOUGH_MEMORY);
}
detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
length = requiredLength;
//
// Now call once again to retrieve the actual interface detail information.
//
bResult = SetupDiGetDeviceInterfaceDetail(deviceInfo,
&interfaceData,
detailData,
length,
&requiredLength,
NULL);
if(FALSE == bResult)
{
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(GetLastError());
}
//
// Copy the device path string from the interface details structure into
// the caller's buffer.
//
hr = StringCchCopy((LPTSTR)pcDevicePath,
BufLen,
(LPCTSTR)detailData->DevicePath);
if(FAILED(hr))
{
//
// We failed to copy the device path string!
//
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(ERROR_INSUFFICIENT_BUFFER);
}
//
// Clean up and free locally allocated resources.
//
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(ERROR_SUCCESS);
}
//****************************************************************************
//
// Opens the USB device and returns a file handle.
//
// \param None.
//
// This function determines whether or not the required USB device is
// available and, if so, creates a file allowing access to it. The file
// handle is returned on success.
//
// \return Returns a valid file handle on success of INVALID_HANDLE_VALUE
// on failure. In cases of failure, GetLastError() can be called to determine
// the cause.
//
//****************************************************************************
static HANDLE OpenDevice(void)
{
HANDLE hDev = NULL;
char devicePath[MAX_DEVPATH_LENGTH];
BOOL retVal;
//
// Get the path needed to open a file handle on our USB device.
//
retVal = GetDevicePath((LPGUID)&GUID_DEVINTERFACE_LUMINARY_BULK,
devicePath,
sizeof(devicePath));
if(retVal != ERROR_SUCCESS)
{
SetLastError(retVal);
return(INVALID_HANDLE_VALUE);
}
//
// Open the file we will use to communicate with the device.
//
hDev = CreateFile((LPCTSTR)devicePath,
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);
return(hDev);
}
//****************************************************************************
//
// Determines that the required USB device is present, opens it and gathers
// required information to allow us to read and write it.
//
// \param None.
//
// This function is called to initialize the USB device and perform one-off
// setup required to allocate handles allowing the application to read and
// write the device endpoints.
//
// \return Returns \e TRUE on success or \e FALSE on failure. In failing
// cases, GetLastError() can be called to determine the cause.
//
//****************************************************************************
BOOL InitializeDevice(void)
{
BOOL bResult;
WINUSB_INTERFACE_HANDLE usbHandle;
USB_INTERFACE_DESCRIPTOR ifaceDescriptor;
WINUSB_PIPE_INFORMATION pipeInfo;
UCHAR speed;
ULONG length;
int i;
//
// Determine whether the USB device is present and, if so, generate a file
// handle to allow access to it.
//
devInfo.deviceHandle = OpenDevice();
if(devInfo.deviceHandle == INVALID_HANDLE_VALUE)
{
//
// We were unable to access the device - return a failure.
//
return(FALSE);
}
//
// The device is opened so we now initialize the WinUSB layer passing it
// the device handle.
//
bResult = WinUsb_Initialize(devInfo.deviceHandle, &usbHandle);
if(bResult)
{
//
// If we managed to initialize the WinUSB layer, we now query the
// device descriptor to determine the speed of the device.
//
devInfo.winUSBHandle = usbHandle;
length = sizeof(UCHAR);
bResult = WinUsb_QueryDeviceInformation(devInfo.winUSBHandle,
DEVICE_SPEED,
&length,
&speed);
}
if(bResult)
{
//
// If all is well, now query the interface descriptor. We ask for the
// first interface only since, in the case of the generic bulk device,
// this is all that is available.
//
devInfo.deviceSpeed = speed;
bResult = WinUsb_QueryInterfaceSettings(devInfo.winUSBHandle,
0,
&ifaceDescriptor);
}
if(bResult)
{
//
// We got the interface descriptor so now we enumerate the endpoints
// to find the two we require - one bulk IN endpoint and one bulk OUT
// endpoint.
//
for(i=0;i<ifaceDescriptor.bNumEndpoints;i++)
{
bResult = WinUsb_QueryPipe(devInfo.winUSBHandle, 0, (UCHAR) i,
&pipeInfo);
if((pipeInfo.PipeType == UsbdPipeTypeBulk) &&
USB_ENDPOINT_DIRECTION_IN(pipeInfo.PipeId))
{
devInfo.bulkInPipe = pipeInfo.PipeId;
}
else if((pipeInfo.PipeType == UsbdPipeTypeBulk) &&
USB_ENDPOINT_DIRECTION_OUT(pipeInfo.PipeId))
{
devInfo.bulkOutPipe = pipeInfo.PipeId;
}
else
{
//
// Hmm... we found and endpoint that we didn't expect to see
// on this interface. This tends to imply that there is a
// mismatch between the device configuration and this
// application so we will fail the call after setting an
// appropriate error code for the caller to query.
//
SetLastError(ERROR_NOT_SAME_DEVICE);
bResult = FALSE;
break;
}
}
}
return(bResult);
}
//****************************************************************************
//
// Cleans up and free resources associated with the USB device communication
// prior to exiting the application.
//
// \param None.
//
// This function should be called prior to exiting the application to free
// the resources allocated during InitializeDevice().
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL TerminateDevice(void)
{
BOOL bRetcode;
BOOL bRetcode2;
bRetcode = WinUsb_Free(devInfo.winUSBHandle);
bRetcode2 = CloseHandle(devInfo.deviceHandle);
if(bRetcode & bRetcode2)
{
return(TRUE);
}
else
{
return(FALSE);
}
}
//****************************************************************************
//
// Writes a buffer of data to the USB device via the bulk OUT endpoint.
//
// \param pcBuffer points to the first byte of data to send.
// \param ulSize contains the number of bytes of data to send.
// \param pulWritten is a pointer which will be written with the number of
// bytes of data actually written to the device.
//
// This function is used to send data to the USB device via its bulk OUT
// endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL WriteUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulWritten)
{
BOOL bResult;
bResult = WinUsb_WritePipe(devInfo.winUSBHandle,
devInfo.bulkOutPipe,
pcBuffer,
ulSize,
pulWritten,
NULL);
return(bResult);
}
//****************************************************************************
//
// Reads data from the USB device via the bulk IN endpoint.
//
// \param pcBuffer points to a buffer into which the data from the device will
// be written.
// \param ulSize contains the number of bytes that are requested from the
// device.
// \param pulRead is a pointer which will be written with the number of
// bytes of data actually read from the device.
//
// This function is used to receivedata from the USB device via its bulk IN
// endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL ReadUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulRead)
{
BOOL bResult;
unsigned long ulSecondRead;
bResult = WinUsb_ReadPipe(devInfo.winUSBHandle,
devInfo.bulkInPipe,
pcBuffer,
ulSize,
pulRead,
NULL);
//
// Make sure we got the number of bytes expected. If we got less, try to
// read the remainder.
//
if(bResult && (*pulRead < ulSize))
{
bResult = WinUsb_ReadPipe(devInfo.winUSBHandle,
devInfo.bulkInPipe,
pcBuffer + *pulRead,
ulSize - *pulRead,
&ulSecondRead,
NULL);
if(bResult)
{
*pulRead += ulSecondRead;
}
}
return(bResult);
}
#endif // USE_WINUSB
//
// End of file
//
@@ -0,0 +1,70 @@
//###########################################################################
//
// FILE: ti_guids.h
//
// TITLE: GUIDs associated with TI Micro USB examples
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
#ifndef TI_GUIDS
#define TI_GUIDS
//
// Vendor and Product IDs for the generic bulk device.
//
#define BULK_VID 0x1cbe
#define BULK_PID 0x0003
//
// TI Bulk Device Class GUID
// {F5450C06-EB58-420e-8F98-A76C5D4AFB18}
//
DEFINE_GUID(GUID_DEVCLASS_TI_BULK,
0xF5450C06, 0xEB5B, 0x420E, 0x8F, 0x98, 0xA7, 0x6C, 0x5D, 0x4A, 0xFB, 0x18);
//
// TI Bulk Device Interface GUID
// {6E45736A-2B1B-4078-B772-B3AF2B6FDE1C}
//
DEFINE_GUID(GUID_DEVINTERFACE_TI_BULK,
0x6E45736A, 0x2B1B, 0x4078, 0xB7, 0x72, 0xb3, 0xAF, 0x2B, 0x6F, 0xDE, 0x1C);
#endif
//
// End of file
//
@@ -0,0 +1,318 @@
//###########################################################################
//
// FILE: usb_bulk_example_throughput.c
//
// TITLE: A very simple command line application that attempts
// to open the TI Generic Bulk USB device and exchange data
// with it.
//
// If the device is successfully opened, then data is sent continuously.
//
// Communication with the device is carried out via a simple DLL, tiusbdll(64),
// which is responsible for opening and closing the device and for
// sending and receiving blocks of data. This structure allows the
// application code to be kept independent of the underlying USB driver
// in use. In this implementation, Microsoft's WinUSB interface is used
// but a switch to another stack, for example the open source libusb-win32
// interface could be made merely be replacing the tiusbdll(64).dll with
// another version writing to the different USB stack.
//
// One downside to using WinUSB is that it requires you to have the Windows
// Device Driver Kit (DDK) installed to build applications which use the
// interface. This is a very large download making it awkward for people
// with slow internet connections. The use of tiusbdll(64).dll also offers
// the advantage that applications using it can still be modified and
// rebuilt even without the DDK installed on the development system. To
// update and rebuild tiusbdll itself, however, the DDK is still required.
//
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
//
// Included Files
//
#include <windows.h>
#include <strsafe.h>
#include <initguid.h>
#include "tiusbdll.h"
#include "ti_guids.h"
//
// Buffer size definitions.
//
#define MAX_STRING_LEN 65535
#define MAX_ENTRY_LEN 65535
#define USB_BUFFER_LEN 65535
//
// Defines
//
//
// The build version number
//
#define BLDVER "7611"
//
// The number of bytes we read and write per transaction if in echo mode.
//
#define ECHO_PACKET_SIZE 65535
//
// Globals
//
//
// Buffer into which error messages are written.
//
TCHAR g_pcErrorString[MAX_STRING_LEN];
//
// The number of bytes transferred in the last measurement interval.
//
ULONG g_ulByteCount = 0;
//
// The total number of packets transferred.
//
ULONG g_ulPacketCount = 0;
//
// Functions
//
//****************************************************************************
//
// Return a string describing the supplied system error code.
//
// \param dwError is a Windows system error code.
//
// This function returns a pointer to a string describing the error code
// passed in the dwError parameter. If no description string can be found
// the string "Unknown" is returned.
//
// \return Returns a pointer to a string describing the error.
//
//****************************************************************************
LPTSTR GetSystemErrorString(DWORD dwError)
{
DWORD dwRetcode;
//
// Ask Windows for the error message description.
//
dwRetcode = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, "%0", dwError, 0,
g_pcErrorString, MAX_STRING_LEN, NULL);
if(dwRetcode == 0)
{
return((LPTSTR)L"Unknown");
}
else
{
//
// Remove the trailing "\n\r" if present.
//
if(dwRetcode >= 2)
{
if(g_pcErrorString[dwRetcode - 2] == '\r')
{
g_pcErrorString[dwRetcode - 2] = '\0';
}
}
return(g_pcErrorString);
}
}
//****************************************************************************
//
// Print the throughput in terms of Kbps once per second.
//
//****************************************************************************
void UpdateThroughput(void)
{
static ULONG ulStartTime = 0;
static ULONG ulLast = 0;
ULONG ulNow;
ULONG ulElapsed;
SYSTEMTIME sSysTime;
//
// Get the current system time.
//
GetSystemTime(&sSysTime);
ulNow = (((((sSysTime.wHour * 60) +
sSysTime.wMinute) * 60) +
sSysTime.wSecond) * 1000) + sSysTime.wMilliseconds;
//
// If this is the first call, set the start time.
//
if(ulStartTime == 0)
{
ulStartTime = ulNow;
ulLast = ulNow;
return;
}
//
// How much time has elapsed since the last measurement?
//
ulElapsed = (ulNow > ulStartTime) ? (ulNow - ulStartTime) : (ulStartTime - ulNow);
//
// We dump a new measurement every second.
//
if(ulElapsed > 1000)
{
printf("\r%6dKbps Packets: %10d ", ((g_ulByteCount * 8) / ulElapsed),
g_ulPacketCount);
g_ulByteCount = 0;
ulStartTime = ulNow;
}
}
//****************************************************************************
//
// The main application entry function.
//
// \param None.
//
// This function forms the main entry point of the example application. It
// initializes the USB bulk device, prompts the user for an ASCII string,
// sends this string to the device, reads the response from the device (which
// will be the same string with the character order reversed if using the
// sample device provided) and displays the returned string.
//
// \return Set the exit code to 0 of no errors cause the application to end
// or a non-zero value otherwise.
//
//****************************************************************************
int main(int argc, char *argv[])
{
BOOL bResult;
BOOL bDriverInstalled;
char szBuffer[USB_BUFFER_LEN];
ULONG ulWritten;
ULONG ulRead;
ULONG ulLength;
DWORD dwError;
TIUSB_HANDLE hUSB;
//
// Print a cheerful welcome.
//
printf("\nTI Bulk Throughput USB Device Example\n");
printf( "---------------------------------\n\n");
printf("Version %s\n\n", BLDVER);
printf("This is a partner application to the Bulk Throughput Example\n");
printf("shipped software releases for USB-enabled boards. \n");
printf("It sends data and displays the throughput and transmitted data packets\n");
//
// Find our USB device and prepare it for communication.
//
hUSB = InitializeDevice(BULK_VID, BULK_PID,
(LPGUID)&(GUID_DEVINTERFACE_TI_BULK),
&bDriverInstalled);
if(hUSB)
{
printf("Press Ctrl+C to exit.\n\n");
while(1)
{
//
// Read a block of data from the device.
//
dwError = ReadUSBPacket(hUSB, szBuffer, ECHO_PACKET_SIZE, &ulRead,
INFINITE, NULL);
if(dwError != ERROR_SUCCESS)
{
//
// We failed to read from the device.
//
printf("\n\nError %d (%S) reading from bulk IN pipe.\n", dwError,
GetSystemErrorString(dwError));
break;
}
else
{
//
// Update our byte and packet counters.
//
g_ulByteCount += ulRead;
g_ulPacketCount++;
//
// Display the throughput.
//
UpdateThroughput();
}
}
}
else
{
//
// An error was reported while trying to connect to the device.
//
dwError = GetLastError();
printf("\nUnable to initialize the TI Bulk USB Device.\n");
printf("Error code is %d (%S)\n\n", dwError, GetSystemErrorString(dwError));
printf("Please make sure you have a TI USB-enabled evaluation\n");
printf("or development kit running the USB Device Bulk Throughput example\n");
printf("application connected to this system via the \"USB OTG\" or\n");
printf("\"USB DEVICE\" connectors. Once the device is connected, run\n");
printf("this application again.\n\n");
printf("\nPress \"Enter\" to exit: ");
fgets(szBuffer, MAX_STRING_LEN, stdin);
printf("\n");
return(2);
}
TerminateDevice(hUSB);
return(0);
}
//
// End of file
//
@@ -0,0 +1,381 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="usb_bulk_example_throughput"
ProjectGUID="{603D9796-4654-4082-9322-E4FC142312FB}"
RootNamespace="usb_bulk_example_throughput"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../lmusbdll"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="$(OutDir);..\Debug"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../lmusbdll"
PreprocessorDefinitions="X64_BUILD"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
OutputFile="$(OutDir)\$(ProjectName).exe"
LinkIncremental="2"
AdditionalLibraryDirectories="$(OutDir);..\x64\Debug"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../lmusbdll"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="$(OutDir);..\Release"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../lmusbdll"
PreprocessorDefinitions="X64_BUILD"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
OutputFile="$(OutDir)\$(ProjectName).exe"
LinkIncremental="1"
AdditionalLibraryDirectories="$(OutDir);..\x64\Release"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\usb_bulk_example_throughput.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\bulk_usb.h"
>
</File>
<File
RelativePath="..\lmusbdll\lmusbdll.h"
>
</File>
<File
RelativePath=".\luminary_guids.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<File
RelativePath=".\ReadMe.txt"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
@@ -0,0 +1,205 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{603D9796-4654-4082-9322-E4FC142312FB}</ProjectGuid>
<RootNamespace>usb_bulk_example_throughput</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>11.0.50727.1</_ProjectFileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<AdditionalIncludeDirectories>../tiusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>tiusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir);..\tiusbdll\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>../tiusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>X64_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>tiusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).exe</OutputFile>
<AdditionalLibraryDirectories>$(OutDir);..\tiusbdll\x64\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>../tiusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>tiusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir);..\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>../lmusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>X64_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>lmusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).exe</OutputFile>
<AdditionalLibraryDirectories>$(OutDir);..\x64\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="usb_bulk_example_throughput.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="bulk_usb.h" />
<ClInclude Include="luminary_guids.h" />
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,214 @@
//##############################################################################
//
// FILE: cmdline.c
//
// TITLE: Functions to help with processing command lines.
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
//******************************************************************************
//
//! \addtogroup cmdline_api
//! @{
//
//******************************************************************************
//
// Included Files
//
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "cmdline.h"
//
// Defines the maximum number of arguments that can be parsed.
//
#ifndef CMDLINE_MAX_ARGS
#define CMDLINE_MAX_ARGS 8
#endif
//
// An array to hold the pointers to the command line arguments.
//
static char *g_ppcArgv[CMDLINE_MAX_ARGS + 1];
//******************************************************************************
//
//! Process a command line string into arguments and execute the command.
//!
//! \param pcCmdLine points to a string that contains a command line that was
//! obtained by an application by some means.
//!
//! This function will take the supplied command line string and break it up
//! into individual arguments. The first argument is treated as a command and
//! is searched for in the command table. If the command is found, then the
//! command function is called and all of the command line arguments are passed
//! in the normal argc, argv form.
//!
//! The command table is contained in an array named <tt>g_psCmdTable</tt>
//! containing <tt>tCmdLineEntry</tt> structures which must be provided by the
//! application. The array must be terminated with an entry whose \b pcCmd
//! field contains a NULL pointer.
//!
//! \return Returns \b CMDLINE_BAD_CMD if the command is not found,
//! \b CMDLINE_TOO_MANY_ARGS if there are more arguments than can be parsed.
//! Otherwise it returns the code that was returned by the command function.
//
//******************************************************************************
int
CmdLineProcess(char *pcCmdLine)
{
char *pcChar;
uint_fast8_t ui8Argc;
bool bFindArg = true;
tCmdLineEntry *psCmdEntry;
//
// Initialize the argument counter, and point to the beginning of the
// command line string.
//
ui8Argc = 0;
pcChar = pcCmdLine;
//
// Advance through the command line until a zero character is found.
//
while(*pcChar)
{
//
// If there is a space, then replace it with a zero, and set the flag
// to search for the next argument.
//
if(*pcChar == ' ')
{
*pcChar = 0;
bFindArg = true;
}
//
// Otherwise it is not a space, so it must be a character that is part
// of an argument.
//
else
{
//
// If bFindArg is set, then that means we are looking for the start
// of the next argument.
//
if(bFindArg)
{
//
// As long as the maximum number of arguments has not been
// reached, then save the pointer to the start of this new arg
// in the argv array, and increment the count of args, argc.
//
if(ui8Argc < CMDLINE_MAX_ARGS)
{
g_ppcArgv[ui8Argc] = pcChar;
ui8Argc++;
bFindArg = false;
}
//
// The maximum number of arguments has been reached so return
// the error.
//
else
{
return(CMDLINE_TOO_MANY_ARGS);
}
}
}
//
// Advance to the next character in the command line.
//
pcChar++;
}
//
// If one or more arguments was found, then process the command.
//
if(ui8Argc)
{
//
// Start at the beginning of the command table, to look for a matching
// command.
//
psCmdEntry = &g_psCmdTable[0];
//
// Search through the command table until a null command string is
// found, which marks the end of the table.
//
while(psCmdEntry->pcCmd)
{
//
// If this command entry command string matches argv[0], then call
// the function for this command, passing the command line
// arguments.
//
if(!strcmp(g_ppcArgv[0], psCmdEntry->pcCmd))
{
return(psCmdEntry->pfnCmd(ui8Argc, g_ppcArgv));
}
//
// Not found, so advance to the next entry.
//
psCmdEntry++;
}
}
//
// Fall through to here means that no matching command was found, so return
// an error.
//
return(CMDLINE_BAD_CMD);
}
//******************************************************************************
//
// Close the Doxygen group.
//! @}
//
//******************************************************************************
//
// End of file
//
@@ -0,0 +1,147 @@
//##############################################################################
//
// FILE: cmdline.h
//
// TITLE: Prototypes for command line processing functions.
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
#ifndef CMDLINE_H
#define CMDLINE_H
//******************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//******************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//******************************************************************************
//
//! \addtogroup cmdline_api
//! @{
//
//******************************************************************************
//
//! Defines the value that is returned if the command is not found.
//
#define CMDLINE_BAD_CMD (-1)
//
//! Defines the value that is returned if there are too many arguments.
//
#define CMDLINE_TOO_MANY_ARGS (-2)
//
//! Defines the value that is returned if there are too few arguments.
//
#define CMDLINE_TOO_FEW_ARGS (-3)
//
//! Defines the value that is returned if an argument is invalid.
//
#define CMDLINE_INVALID_ARG (-4)
//
// Command line function callback type.
//
typedef int (*pfnCmdLine)(int argc, char *argv[]);
//******************************************************************************
//
//! Structure for an entry in the command list table.
//
//******************************************************************************
typedef struct
{
//
//! A pointer to a string containing the name of the command.
//
const char *pcCmd;
//
//! A function pointer to the implementation of the command.
//
pfnCmdLine pfnCmd;
//
//! A pointer to a string of brief help text for the command.
//
const char *pcHelp;
}
tCmdLineEntry;
//******************************************************************************
//
//! This is the command table that must be provided by the application. The
//! last element of the array must be a structure whose pcCmd field contains
//! a NULL pointer.
//
//******************************************************************************
extern tCmdLineEntry g_psCmdTable[];
//******************************************************************************
//
// Close the Doxygen group.
//! @}
//
//******************************************************************************
//
// Function Prototypes
//
extern int CmdLineProcess(char *pcCmdLine);
//******************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//******************************************************************************
#ifdef __cplusplus
}
#endif
#endif // CMDLINE_H
//
// End of file
//
@@ -0,0 +1,716 @@
//##############################################################################
//
// FILE: scistdio.c
//
// TITLE: Utility driver to provide simple SCI console functions.
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
//
// Included Files
//
#include "scistdio.h"
//******************************************************************************
//
//! \addtogroup SCIstdio_api
//! @{
//
//******************************************************************************
//
// The base address of the chosen SCI.
//
static uint32_t g_ui32Base = 0;
//
// A mapping from an integer between 0 and 15 to its ASCII character
// equivalent.
//
static const char * const g_pcHex = "0123456789abcdef";
//******************************************************************************
//
//! Configures the SCI console.
//!
//! \param base is the base address of SCI.
//! \param ui32Baud is the bit rate that the SCI is to be configured to use.
//! \param ui32SrcClock is the frequency of the source clock for the SCI
//! module.
//!
//! The serial parameters are set to the baud rate specified by the
//! \e ui32Baud parameter and use 8 bit, no parity, and 1 stop
//! bit.
//!
//! This function must be called prior to using any of the other SCI console
//! functions: SCIprintf() or SCIgets(). This function assumes that the
//! caller has previously configured the relevant SCI pins for operation as a
//! SCI rather than as GPIOs.
//!
//! \return None.
//
//******************************************************************************
void
SCIStdioConfig(uint32_t base, uint32_t ui32Baud, uint32_t ui32SrcClock)
{
//
// Select the base address of the SCI.
//
g_ui32Base = base;
//
// Configure the SCI for 115200, n, 8, 1
//
SCI_setConfig(g_ui32Base, ui32SrcClock, ui32Baud,
(SCI_CONFIG_PAR_NONE | SCI_CONFIG_STOP_ONE |
SCI_CONFIG_WLEN_8));
}
//******************************************************************************
//
//! Writes a string of characters to the SCI output.
//!
//! \param pcBuf points to a buffer containing the string to transmit.
//! \param ui32Len is the length of the string to transmit.
//!
//! This function will transmit the string to the SCI output. The number of
//! characters transmitted is determined by the \e ui32Len parameter. This
//! function does no interpretation or translation of any characters. Since
//! the output is sent to a SCI, any LF (/n) characters encountered will be
//! replaced with a CRLF pair.
//!
//! Besides using the \e ui32Len parameter to stop transmitting the string, if
//! a null character (0) is encountered, then no more characters will be
//! transmitted and the function will return.
//!
//! In non-buffered mode, this function is blocking and will not return until
//! all the characters have been written to the output FIFO. In buffered mode,
//! the characters are written to the SCI transmit buffer and the call returns
//! immediately. If insufficient space remains in the transmit buffer,
//! additional characters are discarded.
//!
//! \return Returns the count of characters written.
//
//******************************************************************************
int
SCIwrite(const char *pcBuf, uint32_t ui32Len)
{
unsigned int uIdx;
//
// Check for valid SCI base address, and valid arguments.
//
ASSERT(g_ui32Base != 0);
ASSERT(pcBuf != 0);
//
// Send the characters
//
for(uIdx = 0; uIdx < ui32Len; uIdx++)
{
//
// If the character to the SCI is \n, then add a \r before it so that
// \n is translated to \n\r in the output.
//
if(pcBuf[uIdx] == '\n')
{
SCI_writeCharBlockingNonFIFO(g_ui32Base, '\r');
}
//
// Send the character to the SCI output.
//
SCI_writeCharBlockingNonFIFO(g_ui32Base, pcBuf[uIdx]);
}
//
// Return the number of characters written.
//
return(uIdx);
}
//*****************************************************************************
//
//! A simple SCI based vprintf function supporting \%c, \%d, \%p, \%s, \%u,
//! \%x, and \%X.
//!
//! \param pcString is the format string.
//! \param vaArgP is a variable argument list pointer whose content will depend
//! upon the format string passed in \e pcString.
//!
//! This function is very similar to the C library <tt>vprintf()</tt> function.
//! All of its output will be sent to the SCI. Only the following formatting
//! characters are supported:
//!
//! - \%c to print a character
//! - \%d or \%i to print a decimal value
//! - \%l to print a long decimal value
//! - \%s to print a string
//! - \%u to print an unsigned decimal value
//! - \%x to print a hexadecimal value using lower case letters
//! - \%X to print a hexadecimal value using lower case letters (not upper case
//! letters as would typically be used)
//! - \%p to print a pointer as a hexadecimal value
//! - \%\% to print out a \% character
//!
//! For \%s, \%d, \%i, \%u, \%p, \%x, and \%X, an optional number may reside
//! between the \% and the format character, which specifies the minimum number
//! of characters to use for that value; if preceded by a 0 then the extra
//! characters will be filled with zeros instead of spaces. For example,
//! ``\%8d'' will use eight characters to print the decimal value with spaces
//! added to reach eight; ``\%08d'' will use eight characters as well but will
//! add zeroes instead of spaces.
//!
//! The type of the arguments in the variable arguments list must match the
//! requirements of the format string. For example, if an integer was passed
//! where a string was expected, an error of some kind will most likely occur.
//!
//! \return None.
//
//*****************************************************************************
void
SCIvprintf(const char *pcString, va_list vaArgP)
{
uint32_t ui32Idx, ui32Value, ui32Pos, ui32Count, ui32Base, ui32Neg;
char *pcStr, pcBuf[16], cFill;
//
// Check the arguments.
//
ASSERT(pcString != 0);
//
// Loop while there are more characters in the string.
//
while(*pcString)
{
//
// Find the first non-% character, or the end of the string.
//
for(ui32Idx = 0;
(pcString[ui32Idx] != '%') && (pcString[ui32Idx] != '\0');
ui32Idx++)
{
}
//
// Write this portion of the string.
//
SCIwrite(pcString, ui32Idx);
//
// Skip the portion of the string that was written.
//
pcString += ui32Idx;
//
// See if the next character is a %.
//
if(*pcString == '%')
{
//
// Skip the %.
//
pcString++;
//
// Set the digit count to zero, and the fill character to space
// (in other words, to the defaults).
//
ui32Count = 0;
cFill = ' ';
//
// It may be necessary to get back here to process more characters.
// Goto's aren't pretty, but effective. I feel extremely dirty for
// using not one but two of the beasts.
//
again:
//
// Determine how to handle the next character.
//
switch(*pcString++)
{
//
// Handle the digit characters.
//
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
{
//
// If this is a zero, and it is the first digit, then the
// fill character is a zero instead of a space.
//
if((pcString[-1] == '0') && (ui32Count == 0))
{
cFill = '0';
}
//
// Update the digit count.
//
ui32Count *= 10;
ui32Count += pcString[-1] - '0';
//
// Get the next character.
//
goto again;
}
//
// Handle the %c command.
//
case 'c':
{
//
// Get the value from the varargs.
//
ui32Value = va_arg(vaArgP, uint32_t);
//
// Print out the character.
//
SCIwrite((char *)&ui32Value, 1);
//
// This command has been handled.
//
break;
}
//
// Handle the %d and %i commands.
//
case 'd':
case 'i':
{
//
// Get the value from the varargs.
//
ui32Value = va_arg(vaArgP, uint32_t);
//
// Reset the buffer position.
//
ui32Pos = 0;
//
// If the value is negative, make it positive and indicate
// that a minus sign is needed.
//
if((int32_t)ui32Value < 0)
{
//
// Make the value positive.
//
ui32Value = -(int32_t)ui32Value;
//
// Indicate that the value is negative.
//
ui32Neg = 1;
}
else
{
//
// Indicate that the value is positive so that a minus
// sign isn't inserted.
//
ui32Neg = 0;
}
//
// Set the base to 10.
//
ui32Base = 10;
//
// Convert the value to ASCII.
//
goto convert;
}
//
// Handle the %l command.
//
case 'l':
{
//
// Get the value from the varargs.
//
ui32Value = va_arg(vaArgP, uint32_t);
//
// Reset the buffer position.
//
ui32Pos = 0;
//
// If the value is negative, make it positive and indicate
// that a minus sign is needed.
//
if((int32_t)ui32Value < 0)
{
//
// Make the value positive.
//
ui32Value = -(int32_t)ui32Value;
//
// Indicate that the value is negative.
//
ui32Neg = 1;
}
else
{
//
// Indicate that the value is positive so that a minus
// sign isn't inserted.
//
ui32Neg = 0;
}
//
// Set the base to 10.
//
ui32Base = 10;
//
// Convert the value to ASCII.
//
goto convert;
}
//
// Handle the %s command.
//
case 's':
{
//
// Get the string pointer from the varargs.
//
pcStr = va_arg(vaArgP, char *);
//
// Determine the length of the string.
//
for(ui32Idx = 0; pcStr[ui32Idx] != '\0'; ui32Idx++)
{
}
//
// Write the string.
//
SCIwrite(pcStr, ui32Idx);
//
// Write any required padding spaces
//
if(ui32Count > ui32Idx)
{
ui32Count -= ui32Idx;
while(ui32Count--)
{
SCIwrite(" ", 1);
}
}
//
// This command has been handled.
//
break;
}
//
// Handle the %u command.
//
case 'u':
{
//
// Get the value from the varargs.
//
ui32Value = va_arg(vaArgP, uint32_t);
//
// Reset the buffer position.
//
ui32Pos = 0;
//
// Set the base to 10.
//
ui32Base = 10;
//
// Indicate that the value is positive so that a minus sign
// isn't inserted.
//
ui32Neg = 0;
//
// Convert the value to ASCII.
//
goto convert;
}
//
// Handle the %x and %X commands. Note that they are treated
// identically; in other words, %X will use lower case letters
// for a-f instead of the upper case letters it should use. We
// also alias %p to %x.
//
case 'x':
case 'X':
case 'p':
{
//
// Get the value from the varargs.
//
ui32Value = va_arg(vaArgP, uint32_t);
//
// Reset the buffer position.
//
ui32Pos = 0;
//
// Set the base to 16.
//
ui32Base = 16;
//
// Indicate that the value is positive so that a minus sign
// isn't inserted.
//
ui32Neg = 0;
//
// Determine the number of digits in the string version of
// the value.
//
convert:
for(ui32Idx = 1;
(((ui32Idx * ui32Base) <= ui32Value) &&
(((ui32Idx * ui32Base) / ui32Base) == ui32Idx));
ui32Idx *= ui32Base, ui32Count--)
{
}
//
// If the value is negative, reduce the count of padding
// characters needed.
//
if(ui32Neg)
{
ui32Count--;
}
//
// If the value is negative and the value is padded with
// zeros, then place the minus sign before the padding.
//
if(ui32Neg && (cFill == '0'))
{
//
// Place the minus sign in the output buffer.
//
pcBuf[ui32Pos++] = '-';
//
// The minus sign has been placed, so turn off the
// negative flag.
//
ui32Neg = 0;
}
//
// Provide additional padding at the beginning of the
// string conversion if needed.
//
if((ui32Count > 1) && (ui32Count < 16))
{
for(ui32Count--; ui32Count; ui32Count--)
{
pcBuf[ui32Pos++] = cFill;
}
}
//
// If the value is negative, then place the minus sign
// before the number.
//
if(ui32Neg)
{
//
// Place the minus sign in the output buffer.
//
pcBuf[ui32Pos++] = '-';
}
//
// Convert the value into a string.
//
for(; ui32Idx; ui32Idx /= ui32Base)
{
pcBuf[ui32Pos++] =
g_pcHex[(ui32Value / ui32Idx) % ui32Base];
}
//
// Write the string.
//
SCIwrite(pcBuf, ui32Pos);
//
// This command has been handled.
//
break;
}
//
// Handle the %% command.
//
case '%':
{
//
// Simply write a single %.
//
SCIwrite(pcString - 1, 1);
//
// This command has been handled.
//
break;
}
//
// Handle all other commands.
//
default:
{
//
// Indicate an error.
//
SCIwrite("ERROR", 5);
//
// This command has been handled.
//
break;
}
}
}
}
}
//*****************************************************************************
//
//! A simple SCI based printf function supporting \%c, \%d, \%p, \%s, \%u,
//! \%x, and \%X.
//!
//! \param pcString is the format string.
//! \param ... are the optional arguments, which depend on the contents of the
//! format string.
//!
//! This function is very similar to the C library <tt>fprintf()</tt> function.
//! All of its output will be sent to the SCI. Only the following formatting
//! characters are supported:
//!
//! - \%c to print a character
//! - \%d or \%i to print a decimal value
//! - \%s to print a string
//! - \%u to print an unsigned decimal value
//! - \%x to print a hexadecimal value using lower case letters
//! - \%X to print a hexadecimal value using lower case letters (not upper case
//! letters as would typically be used)
//! - \%p to print a pointer as a hexadecimal value
//! - \%\% to print out a \% character
//!
//! For \%s, \%d, \%i, \%u, \%p, \%x, and \%X, an optional number may reside
//! between the \% and the format character, which specifies the minimum number
//! of characters to use for that value; if preceded by a 0 then the extra
//! characters will be filled with zeros instead of spaces. For example,
//! ``\%8d'' will use eight characters to print the decimal value with spaces
//! added to reach eight; ``\%08d'' will use eight characters as well but will
//! add zeroes instead of spaces.
//!
//! The type of the arguments after \e pcString must match the requirements of
//! the format string. For example, if an integer was passed where a string
//! was expected, an error of some kind will most likely occur.
//!
//! \return None.
//
//*****************************************************************************
void
SCIprintf(const char *pcString, ...)
{
va_list vaArgP;
//
// Start the varargs processing.
//
va_start(vaArgP, pcString);
SCIvprintf(pcString, vaArgP);
//
// We're finished with the varargs now.
//
va_end(vaArgP);
}
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************
//
// End of file
//
@@ -0,0 +1,101 @@
//##############################################################################
//
// FILE: scistdio.h
//
// TITLE: Prototypes for the UART console functions.
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
#ifndef SCISTDIO_H
#define SCISTDIO_H
//
// Included Files
//
#include "driverlib.h"
#include "device.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdarg.h>
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//
// If built for buffered operation, the following labels define the sizes of
// the transmit and receive buffers respectively.
//
#ifdef UART_BUFFERED
#ifndef UART_RX_BUFFER_SIZE
#define UART_RX_BUFFER_SIZE 128
#endif
#ifndef UART_TX_BUFFER_SIZE
#define UART_TX_BUFFER_SIZE 1024
#endif
#endif
//
// Function Prototypes
//
extern void SCIStdioConfig(uint32_t ui32Port, uint32_t ui32Baud,
uint32_t ui32SrcClock);
extern void SCIprintf(const char *pcString, ...);
extern void SCIvprintf(const char *pcString, va_list vaArgP);
extern int SCIwrite(const char *pcBuf, uint32_t ui32Len);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif // SCISTDIO_H
//
// End of file
//
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,96 @@
//##############################################################################
//
// FILE: ustdlib.h
//
// TITLE: Prototypes for simple standard library functions.
//
//##############################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2014-2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//##############################################################################
#ifndef __USTDLIB_H__
#define __USTDLIB_H__
//
// Included Files
//
#include <stdarg.h>
#include <time.h>
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
#ifdef __cplusplus
extern "C"
{
#endif
//
// Function Prototypes
//
extern void ulocaltime(time_t timer, struct tm *tm);
extern time_t umktime(struct tm *timeptr);
extern int urand(void);
extern int usnprintf(char * restrict s, size_t n, const char * restrict format,
...);
extern int usprintf(char * restrict s, const char * restrict format, ...);
extern void usrand(unsigned int seed);
extern int ustrcasecmp(const char *s1, const char *s2);
extern int ustrcmp(const char *s1, const char *s2);
extern size_t ustrlen(const char *s);
extern int ustrncasecmp(const char *s1, const char *s2, size_t n);
extern int ustrncmp(const char *s1, const char *s2, size_t n);
extern char *ustrncpy(char * restrict s1, const char * restrict s2, size_t n);
extern char *ustrstr(const char *s1, const char *s2);
extern float ustrtof(const char * restrict nptr,
const char ** restrict endptr);
extern unsigned long int ustrtoul(const char * restrict nptr,
const char ** restrict endptr, int base);
extern int uvsnprintf(char * restrict s, size_t n,
const char * restrict format, va_list arg);
//
// Mark the end of the C bindings section for C++ compilers.
//
#ifdef __cplusplus
}
#endif
#endif // __USTDLIB_H__
//
// End of file
//
@@ -0,0 +1,64 @@
//###########################################################################
//
// FILE: Resource.h
//
// TITLE: Microsoft Visual C++ generated include file.
//
//###########################################################################
//
//
//
// C2000Ware v5.04.00.00
//
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
//
//{{NO_DEPENDENCIES}}
// Used by lmusbdll.rc
//
//
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 1000
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 1000
#endif
#endif
//
// End of file
//
@@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// usbdll.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
@@ -0,0 +1,106 @@
//###########################################################################
//
// FILE: stdafx.h
//
// TITLE: include file for standard system include files
//
//###########################################################################
//
//
//
// C2000Ware v5.04.00.00
//
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#endif
//
// Modify the following defines if you have to target a platform prior to the
// ones specified below. Refer to MSDN for the latest info on corresponding
// values for different platforms.
#ifndef WINVER // Allow use of features specific to Windows XP or later.
#define WINVER 0x0501 // Change this to the appropriate value to target
// other versions of Windows.
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target
// other versions of Windows.
#endif
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target
// Windows Me or later.
#endif
#ifndef _WIN32_IE // Allow use of features specific to IE 6.0 or later.
#define _WIN32_IE 0x0600 // Change this to the appropriate value to target
// other versions of IE.
#endif
//
// some CString constructors will be explicit
//
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxole.h> // MFC OLE classes
#include <afxodlgs.h> // MFC OLE dialog classes
#include <afxdisp.h> // MFC Automation classes
#endif // _AFX_NO_OLE_SUPPORT
#ifndef _AFX_NO_DB_SUPPORT
#include <afxdb.h> // MFC ODBC database classes
#endif // _AFX_NO_DB_SUPPORT
#ifndef _AFX_NO_DAO_SUPPORT
#include <afxdao.h> // MFC DAO database classes
#endif // _AFX_NO_DAO_SUPPORT
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
//
// End of file
//
@@ -0,0 +1,964 @@
//###########################################################################
//
// FILE: tiusbdll.cpp
//
// TITLE: A thin layer over WinUSB allowing device open/close/
// read and write functionality.
//
// The WinUSB code in this example is based on information provided
// in Microsoft's white paper, "How to Use WinUSB to Communicate
// with a USB Device", WinUsb_HowTo.doc, available from URL:
//
// http://download.microsoft.com/download/9/c/5/9c5b2167-8017-4bae-9fde-
// d599bac8184a/WinUsb_HowTo.doc
//
//###########################################################################
//
// C2000Ware v5.04.00.00
//
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#include "stdafx.h"
#include <windows.h>
#include <setupapi.h>
#include <devguid.h>
#include <regstr.h>
#include <strsafe.h>
#include <initguid.h>
#include "winusb.h"
#include "usb100.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#include "resource.h" // main symbols
// CusbdllApp
// See usbdll.cpp for the implementation of this class
//
class CtiusbdllApp : public CWinApp
{
public:
CtiusbdllApp();
// Overrides
public:
virtual BOOL InitInstance();
DECLARE_MESSAGE_MAP()
};
// CtiusbdllApp
BEGIN_MESSAGE_MAP(CtiusbdllApp, CWinApp)
END_MESSAGE_MAP()
// CusbdllApp construction
CtiusbdllApp::CtiusbdllApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
// The one and only CusbdllApp object
CtiusbdllApp theApp;
// CusbdllApp initialization
BOOL CtiusbdllApp::InitInstance()
{
CWinApp::InitInstance();
return TRUE;
}
//****************************************************************************
//
// Buffer size definitions.
//
//****************************************************************************
#define MAX_DEVPATH_LENGTH 256
//****************************************************************************
//
// Flag indicating that a blocking read should be performed.
//
//****************************************************************************
#define TIUSB_WAIT_FOREVER 0xFFFFFFFF
//****************************************************************************
//
// Structure containing handles and information required to communicate with
// the USB bulk device.
//
//****************************************************************************
typedef struct
{
HANDLE deviceHandle;
WINUSB_INTERFACE_HANDLE winUSBHandle;
UCHAR deviceSpeed;
UCHAR bulkInPipe;
UCHAR bulkOutPipe;
HANDLE hReadEvent;
} tDeviceInfoWinUSB;
typedef void *TIUSB_HANDLE;
//****************************************************************************
//
// Returns the device path associated with a provided interface GUID.
//
// \param dwIndex is the zero-based index of the device whose path is to be
// found.
// \param InterfaceGuid is a pointer to the GUID for the interface that
// we are looking for. Assuming you installed the device using the sample
// INF file, this will be the GUID provided in the Dev_AddReg section.
// \param pcDevicePath is a pointer to a buffer into which will be written
// the path to the device if the function is successful.
// \param BufLen is the size of the buffer pointed to by \f pcDevicePath.
//
// Given an interface GUID, this function determines the path that is
// necessary to open a file handle on the USB device we are interested in
// talking to. It returns the path to the first device which is present in
// the system and which offers the required interface.
//
// \return Returns one of the following Windows system error codes.
// ERROR_SUCCESS if the operation completed successfully
// ERROR_DEV_NOT_EXIST if the interface is not found on the system. This
// implies that the driver for the USB device has not been installed.
// ERROR_DEVICE_NOT_CONNECTED if the interface has been installed but no
// device offering it is presently available. This typically indicates
// that the USB device is not currently connected.
// ERROR_NOT_ENOUGH_MEMORY if the function fails to allocate any required
// buffers.
// ERROR_INSUFFICIENT_BUFFER if the buffer passed is too small to hold
// the device path.
//****************************************************************************
static DWORD GetDevicePath(DWORD dwIndex, LPGUID InterfaceGuid,
PCHAR pcDevicePath,
size_t BufLen)
{
BOOL bResult = FALSE;
HDEVINFO deviceInfo;
SP_DEVICE_INTERFACE_DATA interfaceData;
PSP_DEVICE_INTERFACE_DETAIL_DATA detailData = NULL;
ULONG length;
ULONG requiredLength=0;
HRESULT hr;
//
// Get a handle to the device information set containing information on
// the interface GUID supplied on this PC.
//
deviceInfo = SetupDiGetClassDevs(InterfaceGuid,
NULL, NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if(deviceInfo == INVALID_HANDLE_VALUE)
{
//
// No device offering the required interface is present. Has the
// interface been installed? Ask for the information set for all
// devices and not just those that are presently installed.
//
deviceInfo = SetupDiGetClassDevs(InterfaceGuid,
NULL, NULL,
DIGCF_DEVICEINTERFACE);
if(deviceInfo == INVALID_HANDLE_VALUE)
{
return(ERROR_DEV_NOT_EXIST);
}
else
{
SetupDiDestroyDeviceInfoList(deviceInfo);
return(ERROR_DEVICE_NOT_CONNECTED);
}
}
interfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
//
// SetupDiGetClassDevs returned us a valid information set handle so we
// now query this set to find the find the first device offering the
// interface whose GUID was supplied.
//
bResult = SetupDiEnumDeviceInterfaces(deviceInfo,
NULL,
InterfaceGuid,
dwIndex,
&interfaceData);
if(bResult == FALSE)
{
//
// We failed to find the first matching device so tell the caller
// that no suitable device is connected.
//
return(ERROR_DEVICE_NOT_CONNECTED);
}
//
// Now that we have the interface information, we need to query details
// to retrieve the device path. First determine how much space we need to
// hold the detail information.
//
SetupDiGetDeviceInterfaceDetail(deviceInfo,
&interfaceData,
NULL, 0,
&requiredLength,
NULL);
//
// Allocate a buffer to hold the interface details.
//
detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LMEM_FIXED,
requiredLength);
if(NULL == detailData)
{
SetupDiDestroyDeviceInfoList(deviceInfo);
return(ERROR_NOT_ENOUGH_MEMORY);
}
detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
length = requiredLength;
//
// Now call once again to retrieve the actual interface detail information.
//
bResult = SetupDiGetDeviceInterfaceDetail(deviceInfo,
&interfaceData,
detailData,
length,
&requiredLength,
NULL);
if(FALSE == bResult)
{
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(GetLastError());
}
//
// Copy the device path string from the interface details structure into
// the caller's buffer.
//
hr = StringCchCopy((LPTSTR)pcDevicePath,
BufLen,
(LPCTSTR)detailData->DevicePath);
if(FAILED(hr))
{
//
// We failed to copy the device path string!
//
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(ERROR_INSUFFICIENT_BUFFER);
}
//
// Clean up and free locally allocated resources.
//
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(ERROR_SUCCESS);
}
//****************************************************************************
//
// Opens a given instance of the USB device and returns a file handle.
//
// \param dwIndex is the zero-based index of the device that is to be opened.
// \param lpGUID is a pointer to the GUID of the interface that is to
// be opened.
//
// This function determines whether or not the required USB device is
// available and, if so, creates a file allowing access to it. The file
// handle is returned on success.
//
// \return Returns a valid file handle on success of INVALID_HANDLE_VALUE
// on failure. In cases of failure, GetLastError() can be called to determine
// the cause.
//
//****************************************************************************
static HANDLE OpenDeviceByIndex(DWORD dwIndex, LPGUID lpGUID)
{
HANDLE hDev = NULL;
char devicePath[MAX_DEVPATH_LENGTH];
BOOL retVal;
//
// Get the path needed to open a file handle on our USB device.
//
retVal = GetDevicePath(dwIndex, lpGUID, devicePath, sizeof(devicePath));
if(retVal != ERROR_SUCCESS)
{
SetLastError(retVal);
return(INVALID_HANDLE_VALUE);
}
//
// Open the file we will use to communicate with the device.
//
hDev = CreateFile((LPCTSTR)devicePath,
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);
return(hDev);
}
//****************************************************************************
//
// Opens the first instance of a given USB device and returns a file handle.
//
// \param lpGUID is a pointer to the GUID of the interface that is to
// be opened.
//
// This function determines whether or not the required USB device is
// available and, if so, creates a file allowing access to it. The file
// handle is returned on success.
//
// \return Returns a valid file handle on success of INVALID_HANDLE_VALUE
// on failure. In cases of failure, GetLastError() can be called to determine
// the cause.
//
//****************************************************************************
static HANDLE OpenDevice(LPGUID lpGUID)
{
return(OpenDeviceByIndex(0, lpGUID));
}
//****************************************************************************
//
// Determines that the required USB device is present, opens it and gathers
// required information to allow us to read and write it.
//
// \param usVID is the vendor ID of the device to be initialized.
// \param usPID is the product ID of the device to be intialized.
// \param lpGUID is the GUID of the device interface that is to be opened.
// \param dwIndex is the zero-based index of the device to open.
// \param bOpenDataEndpoints is \e TRUE to open endpoints for bulk transfer
// of data to and from the host or \e FALSE to open the device without
// attempting to open any additional endpoints.
// \param pbDriverInstalled is written to \e TRUE if the device driver for the
// required class is installed or \e FALSE otherwise.
//
// This function is called to initialize the USB device and perform one-off
// setup required to allocate handles allowing the application to read and
// write the device endpoints. It offers a superset of the function provided
// by InitializeDevice(), allowing a caller to specify an index to differentiate
// between multiple devices of the same type and also offering the ability to
// open a device without opening endpoint handles for bulk data transfer.
//
// \return Returns a valid handle on success or NULL on failure. In failing
// cases, GetLastError() can be called to determine the cause.
//
//****************************************************************************
extern "C" TIUSB_HANDLE PASCAL EXPORT
InitializeDeviceByIndex(unsigned short usVID,
unsigned short usPID,
LPGUID lpGUID,
DWORD dwIndex,
BOOL bOpenDataEndpoints,
BOOL *pbDriverInstalled)
{
BOOL bResult;
WINUSB_INTERFACE_HANDLE usbHandle;
USB_INTERFACE_DESCRIPTOR ifaceDescriptor;
WINUSB_PIPE_INFORMATION pipeInfo;
UCHAR speed;
ULONG length;
DWORD dwError;
int i;
tDeviceInfoWinUSB *psDevInfo;
//
// Check for NULL pointer parameters.
//
if(!lpGUID || !pbDriverInstalled)
{
return(NULL);
}
//
// Allocate a new device info structure.
//
psDevInfo = (tDeviceInfoWinUSB *)LocalAlloc(LPTR, sizeof(tDeviceInfoWinUSB));
if(!psDevInfo)
{
return(NULL);
}
//
// Determine whether the USB device is present and, if so, generate a file
// handle to allow access to it.
//
psDevInfo->deviceHandle = OpenDeviceByIndex(dwIndex, lpGUID);
if(psDevInfo->deviceHandle == INVALID_HANDLE_VALUE)
{
//
// We were unable to access the device - is that because the device isn't
// connected or has the driver not been installed?
//
dwError = GetLastError();
*pbDriverInstalled = (dwError == ERROR_DEV_NOT_EXIST) ? FALSE : TRUE;
//
// Free our instance data.
//
LocalFree((HLOCAL)psDevInfo);
//
// Return an error to the caller.
//
return(NULL);
}
//
// The device is opened so we now initialize the WinUSB layer passing it
// the device handle.
//
bResult = WinUsb_Initialize(psDevInfo->deviceHandle, &usbHandle);
if(bResult)
{
//
// If we managed to initialize the WinUSB layer, we now query the
// device descriptor to determine the speed of the device.
//
psDevInfo->winUSBHandle = usbHandle;
length = sizeof(UCHAR);
bResult = WinUsb_QueryDeviceInformation(psDevInfo->winUSBHandle,
DEVICE_SPEED,
&length,
&speed);
}
//
// The device opened correctly. Do we need to also open pipes to allow us
// to send and receive data via the bulk endpoints?
//
if(bOpenDataEndpoints)
{
//
// Yes - we do need to open the endpoints for data transfer.
//
if(bResult)
{
//
// If all is well, now query the interface descriptor. We ask for the
// first interface only since, in the case of the generic bulk device,
// this is all that is available.
//
psDevInfo->deviceSpeed = speed;
bResult = WinUsb_QueryInterfaceSettings(psDevInfo->winUSBHandle,
0,
&ifaceDescriptor);
}
if(bResult)
{
//
// We got the interface descriptor so now we enumerate the endpoints
// to find the two we require - one bulk IN endpoint and one bulk OUT
// endpoint.
//
for(i=0;i<ifaceDescriptor.bNumEndpoints;i++)
{
bResult = WinUsb_QueryPipe(psDevInfo->winUSBHandle, 0, (UCHAR) i,
&pipeInfo);
if((pipeInfo.PipeType == UsbdPipeTypeBulk) &&
USB_ENDPOINT_DIRECTION_IN(pipeInfo.PipeId))
{
psDevInfo->bulkInPipe = pipeInfo.PipeId;
}
else if((pipeInfo.PipeType == UsbdPipeTypeBulk) &&
USB_ENDPOINT_DIRECTION_OUT(pipeInfo.PipeId))
{
psDevInfo->bulkOutPipe = pipeInfo.PipeId;
}
else
{
//
// Hmm... we found an endpoint that we didn't expect to see
// on this interface. This tends to imply that there is a
// mismatch between the device configuration and this
// application so we will fail the call after setting an
// appropriate error code for the caller to query.
//
SetLastError(ERROR_NOT_SAME_DEVICE);
bResult = FALSE;
break;
}
}
}
//
// Did all go well so far?
//
if(bResult)
{
//
// All is well - create the signal event we need.
//
psDevInfo->hReadEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
//
// If we created the event successfully, return a good handle.
//
if(psDevInfo->hReadEvent)
{
//
// Everything is good. Set the return code flag to indicate
// this.
//
bResult = true;
}
}
}
else
{
//
// Data transfer endpoints do not need to be opened so merely mark
// this in the device info structure.
//
psDevInfo->bulkOutPipe = 0;
psDevInfo->bulkInPipe = 0;
psDevInfo->hReadEvent = NULL;
}
//
// Did all go well?
//
if(bResult)
{
//
// All is well - return the instance data pointer as a handle to the
// caller.
//
return((TIUSB_HANDLE)psDevInfo);
}
else
{
//
// If we drop through to here, something went wrong so free the
// instance structure and return NULL.
//
LocalFree((HLOCAL)psDevInfo);
return(NULL);
}
}
//****************************************************************************
//
// Determines that the required USB device is present, opens it and gathers
// required information to allow us to read and write it.
//
// \param usVID is the vendor ID of the device to be initialized.
// \param usPID is the product ID of the device to be intialized.
// \param lpGUID is the GUID of the device interface that is to be opened.
// \param pbDriverInstalled is written to \e TRUE if the device driver for the
// required class is installed or \e FALSE otherwise.
//
// This function is called to initialize the USB device and perform one-off
// setup required to allocate handles allowing the application to read and
// write the device endpoints.
//
// InitializeDevice() always opens the first instance of a device and assumes
// that the caller will always want to open handles allowing communication via
// only IN and OUT bulk endpoints. To open an instance of a device other than
// the first or to open a device without opening handles on any endpoints other
// than the control endpoint, InitializeDeviceByIndex() may be used instead.
//
// \return Returns a valid handle on success or NULL on failure. In failing
// cases, GetLastError() can be called to determine the cause.
//
//****************************************************************************
extern "C" TIUSB_HANDLE PASCAL EXPORT
InitializeDevice(unsigned short usVID,
unsigned short usPID,
LPGUID lpGUID,
BOOL *pbDriverInstalled)
{
//
// Call our more capable cousin to open the first instance of the device
// and set up for data transfer via bulk IN and OUT endpoints.
//
return(InitializeDeviceByIndex(usVID, usPID, lpGUID, 0, true,
pbDriverInstalled));
}
//****************************************************************************
//
// Performs a control transfer on endpoint 0.
//
// \param hUSB is the device handle as returned from InitializeDevice().
// \param ucRequestType is the value to be placed in the bmRequestType field
// of the setup data as defined in table 9-2 of the USB 2.0 specification. The
// value is an ORed combination of the REQUEST_xxx flags found in tiusbdll.h.
// \param ucRequest is the specific request identifier which will be placed in
// the bRequest field of the setup data for the transaction.
// \param usValue is the request-specific value placed into the wValue field of
// the setup data for the transaction.
// \param usIndex is the value placed into the wIndex field of the setup data
// for the transaction.
// \param usLength is the number of bytes of data to transfer from or to the
// caller-supplied buffer during the transaction. This value is used to set
// the wLength field in the setup data for the transaction.
// \param pucBuffer is a pointer to a buffer containing at least usLength bytes.
// If ucRequestType contains REQUEST_TRANSFER_IN, usLength bytes of data will
// be transfered from the device and written into this buffer. If ucRequestType
// contains REQUEST_TRANSFER_OUT, usLength bytes of data will be transfered
// from this buffer to the device.
// \param pusCount will be written with the number of bytes actually written to
// or read from the device.
//
// This function performs a control transfer to the device. This transaction
// may transfer data to or from the device depending upon the value of the
// ucRequestType parameter.
//
// \return Returns \e TRUE on success or \e FALSE on failure. If \e FALSE is
// returned, GetLastError() may be called to determine the cause of the failure.
//
//****************************************************************************
extern "C" BOOL PASCAL EXPORT
Endpoint0Transfer(TIUSB_HANDLE hUSB, UCHAR ucRequestType, UCHAR ucRequest,
USHORT usValue, USHORT usIndex, USHORT usLength,
PUCHAR pucBuffer, PUSHORT pusCount)
{
tDeviceInfoWinUSB *psDevInfo = (tDeviceInfoWinUSB *)hUSB;
WINUSB_SETUP_PACKET sSetup;
ULONG ulCount;
ULONG ulError;
BOOL bRetcode;
//
// Check for invalid parameters. We require a buffer pointer if the
// transfer length is non-zero.
//
if(!hUSB || (usLength && !pucBuffer))
{
return(0);
}
//
// Fill in the setup data structure.
//
sSetup.RequestType = ucRequestType;
sSetup.Request = ucRequest;
sSetup.Value = usValue;
sSetup.Index = usIndex;
sSetup.Length = usLength;
//
// Issue the control transaction.
//
bRetcode = WinUsb_ControlTransfer(psDevInfo->winUSBHandle,
sSetup,
pucBuffer,
(ULONG)usLength,
&ulCount,
NULL);
//
// Return either the number of bytes written/read or 0 if there was an
// error.
//
if(bRetcode)
{
*pusCount = (USHORT)ulCount;
}
else
{
ulError = GetLastError();
*pusCount = 0;
}
return(bRetcode);
}
//****************************************************************************
//
// Cleans up and free resources associated with the USB device communication
// prior to exiting the application.
//
// \param hUSB is the device handle as returned from InitializeDevice().
//
// This function should be called prior to exiting the application to free
// the resources allocated during InitializeDevice().
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
extern "C" BOOL PASCAL EXPORT TerminateDevice(TIUSB_HANDLE hUSB)
{
BOOL bRetcode;
BOOL bRetcode2;
tDeviceInfoWinUSB *psDevInfo = (tDeviceInfoWinUSB *)hUSB;
//
// Check for a bad handle.
//
if(!hUSB)
{
return(false);
}
//
// Free WinUSB and Windows resources.
//
bRetcode = WinUsb_Free(psDevInfo->winUSBHandle);
bRetcode2 = CloseHandle(psDevInfo->deviceHandle);
//
// Free the device instance structure.
//
LocalFree((HLOCAL)psDevInfo);
//
// Did all go well?
//
if(bRetcode & bRetcode2)
{
return(TRUE);
}
else
{
return(FALSE);
}
}
//****************************************************************************
//
// Writes a buffer of data to the USB device via the bulk OUT endpoint.
//
// \param hUSB is the device handle as returned from InitializeDevice().
// \param pcBuffer points to the first byte of data to send.
// \param ulSize contains the number of bytes of data to send.
// \param pulWritten is a pointer which will be written with the number of
// bytes of data actually written to the device.
//
// This function is used to send data to the USB device via its bulk OUT endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
extern "C" BOOL PASCAL EXPORT
WriteUSBPacket(TIUSB_HANDLE hUSB, unsigned char *pcBuffer,
unsigned long ulSize,
unsigned long *pulWritten)
{
BOOL bResult;
tDeviceInfoWinUSB *psDevInfo = (tDeviceInfoWinUSB *)hUSB;
//
// Check for bad parameters.
//
if(!hUSB || !pcBuffer || !pulWritten || !ulSize)
{
return(false);
}
//
// Ask WinUSB to write the data for us.
//
bResult = WinUsb_WritePipe(psDevInfo->winUSBHandle,
psDevInfo->bulkOutPipe,
pcBuffer,
ulSize,
pulWritten,
NULL);
return(bResult);
}
//****************************************************************************
//
// Reads data from the USB device via the bulk IN endpoint.
//
// \param hUSB is the device handle as returned from InitializeDevice().
// \param pcBuffer points to a buffer into which the data from the device will
// be written.
// \param ulSize contains the number of bytes that are requested from the
// device.
// \param pulRead is a pointer which will be written with the number of
// bytes of data actually read from the device.
// \param ulTimeoutmS is the number of milliseconds to wait for the
// data before returning an error. To block indefinitely, set this parameter
// to INFINITE.
// \param hBreak is the handle of an event that may be used to break out of
// the read operation. If this is a valid event handle and the event is
// signalled, the read operation will return immediately. Set this to
// NULL if the additional break condition is not required.
//
// This function is used to receive data from the USB device via its bulk IN
// endpoint.
//
// \return Returns \e ERROR_SUCCESS on success, WAIT_TIMEOUT if the data as
// not received within ulTimeoutmS milliseconds, WAIT_OBJECT_0 if the break
// event was signalled or other Windows system error codes on failure.
//
//****************************************************************************
extern "C" DWORD PASCAL EXPORT
ReadUSBPacket(TIUSB_HANDLE hUSB, unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulRead, unsigned long ulTimeoutmS, HANDLE hBreak)
{
BOOL bResult;
DWORD dwError;
OVERLAPPED sOverlapped;
HANDLE phSignals[2];
tDeviceInfoWinUSB *psDevInfo = (tDeviceInfoWinUSB *)hUSB;
//
// Check for bad parameters.
//
if(!hUSB || !pcBuffer || !pulRead || !ulSize)
{
return(ERROR_INVALID_PARAMETER);
}
//
// Tell WinUSB how to signal us when reads are completed (if blocking)
//
sOverlapped.hEvent = psDevInfo->hReadEvent;
sOverlapped.Offset = 0;
sOverlapped.OffsetHigh = 0;
//
// Perform the read.
//
bResult = WinUsb_ReadPipe(psDevInfo->winUSBHandle,
psDevInfo->bulkInPipe,
pcBuffer,
ulSize,
pulRead,
&sOverlapped);
//
// A good return code indicates success regardless of whether we performed
// a blocking or non-blocking read.
//
if(bResult)
{
dwError = ERROR_SUCCESS;
}
else
{
//
// An error occurred or the read will complete asynchronously.
// Which is it?
//
dwError = GetLastError();
//
// Check for error cases other than the one we expect.
//
if(dwError == ERROR_IO_PENDING)
{
//
// The IO is pending so wait for it to complete or for a
// timeout to occur.
//
phSignals[0] = psDevInfo->hReadEvent;
phSignals[1] = hBreak;
dwError = WaitForMultipleObjects(hBreak ? 2 : 1, phSignals, FALSE,
ulTimeoutmS);
//
// At this stage, one of three things could have occurred.
// Either we read a packet or we timed out or the break
// signal was detected. Which was it?
//
if(dwError == WAIT_OBJECT_0)
{
//
// The overlapped IO request completed so check to see how
// many bytes we got.
//
bResult = GetOverlappedResult(psDevInfo->deviceHandle,
&sOverlapped,
pulRead, FALSE);
if(bResult)
{
dwError = ERROR_SUCCESS;
}
else
{
//
// Something went wrong. Return the Windows error code.
//
dwError = GetLastError();
}
}
else
{
//
// Something went wrong - abort the transfer
//
WinUsb_AbortPipe(psDevInfo->winUSBHandle,
psDevInfo->bulkInPipe);
//
// Was the break event signalled?
//
if(dwError == (WAIT_OBJECT_0 + 1))
{
//
// The break event was signalled - abort the read and return.
//
dwError = WAIT_OBJECT_0;
}
}
}
}
//
// Pass the result back to the caller.
//
return(dwError);
}
@@ -0,0 +1,14 @@
; tiusbdll.def : Declares the module parameters for the DLL.
LIBRARY "tiusbdll"
; DESCRIPTION "A simple library allowing low level access to a WinUSB device"
VERSION 1.1
EXPORTS
; Explicit exports can go here
InitializeDevice @1
TerminateDevice @2
WriteUSBPacket @3
ReadUSBPacket @4
InitializeDeviceByIndex @5
Endpoint0Transfer @6
@@ -0,0 +1,142 @@
//###########################################################################
//
// FILE: tiusbdll.h
//
// TITLE: A thin layer over WinUSB allowing device open/close/
// read and write functionality.
//
//###########################################################################
//
//
//
// C2000Ware v5.04.00.00
//
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifdef __cplusplus
#pragma once
#ifndef __AFXWIN_H__
#error "include 'stdafx.h' before including this file for PCH"
#endif
//
// Functions exported by this DLL.
//
extern "C" {
#endif
//
// A handle returned by InitializeDevice().
//
typedef void *TIUSB_HANDLE;
//
// Flags used in constructing the ucRequestType parameter to
// Endpoint0Transfer().
//
#define REQUEST_TRANSFER_IN 0x80
#define REQUEST_TRANSFER_OUT 0x00
#define REQUEST_TYPE_STANDARD 0x00
#define REQUEST_TYPE_CLASS 0x20
#define REQUEST_TYPE_VENDOR 0x40
#define REQUEST_RECIPIENT_DEVICE 0x00
#define REQUEST_RECIPIENT_INTERFACE 0x01
#define REQUEST_RECIPIENT_ENDPOINT 0x02
#define REQUEST_RECIPIENT_OTHER 0x03
//
// Function Prototypes exported by the DLL.
//
TIUSB_HANDLE __stdcall InitializeDevice(unsigned short usVID,
unsigned short usPID,
LPGUID lpGUID,
BOOL *pbDriverInstalled);
TIUSB_HANDLE __stdcall InitializeDeviceByIndex(unsigned short usVID,
unsigned short usPID,
LPGUID lpGUID,
DWORD dwIndex,
BOOL bOpenDataEndpoints,
BOOL *pbDriverInstalled);
BOOL __stdcall TerminateDevice(TIUSB_HANDLE hHandle);
BOOL __stdcall WriteUSBPacket(TIUSB_HANDLE hHandle,
unsigned char *pcBuffer,
unsigned long ulSize,
unsigned long *pulWritten);
DWORD __stdcall ReadUSBPacket(TIUSB_HANDLE hHandle,
unsigned char *pcBuffer,
unsigned long ulSize,
unsigned long *pulRead,
unsigned long ulTimeoutMs,
HANDLE hBreak);
BOOL __stdcall Endpoint0Transfer(TIUSB_HANDLE hHandle, UCHAR ucRequestType,
UCHAR ucRequest, USHORT usValue,
USHORT usIndex, USHORT usLength,
PUCHAR pucBuffer, PUSHORT pusCount);
//
// Typedefs for each of the exported functions. This helps if applications
// want to link the DLL dynamically using LoadLibrary rather than linking
// directly to the lib file.
//
typedef TIUSB_HANDLE (__stdcall *tInitializeDevice)(unsigned short usVID,
unsigned short usPID,
LPGUID lpGUID,
BOOL *pbDriverInstalled);
typedef BOOL (__stdcall *tTerminateDevice)(TIUSB_HANDLE hHandle);
typedef BOOL (__stdcall *tWriteUSBPacket)(TIUSB_HANDLE hHandle,
unsigned char *pcBuffer,
unsigned long ulSize,
unsigned long *pulWritten);
typedef DWORD (__stdcall *tReadUSBPacket)(TIUSB_HANDLE hHandle,
unsigned char *pcBuffer,
unsigned long ulSize,
unsigned long *pulRead,
unsigned long ulTimeoutMs,
HANDLE hBreak);
typedef DWORD (__stdcall *tEndpoint0Transfer)(TIUSB_HANDLE hHandle,
UCHAR ucRequestType,
UCHAR ucRequest, USHORT usValue,
USHORT usIndex, USHORT usLength,
PUCHAR pucBuffer,
PUSHORT pusCount);
#ifdef __cplusplus
}
#endif
//
// End of file
//
@@ -0,0 +1,120 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
"#define _AFX_NO_OLE_RESOURCES\r\n"
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
"\r\n"
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
"LANGUAGE 9, 1\r\n"
"#pragma code_page(1252)\r\n"
"#include ""afxres.rc"" // Standard components\r\n"
"#endif\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,6734
PRODUCTVERSION 1,0,0,6734
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904e4"
BEGIN
VALUE "CompanyName", "Texas Instruments Incorporated"
VALUE "FileDescription", "A DLL used to interface Windows example applications to the WinUSB subsystem"
VALUE "FileVersion", "6734"
VALUE "InternalName", "tiusbdll.dll"
VALUE "LegalCopyright", "Copyright (c) 2008-2010 Texas Instruments Incorporated. All rights reserved."
VALUE "OriginalFilename", "tiusbdll.dll"
VALUE "ProductName", "Texas Instruments USB DLL"
VALUE "ProductVersion", "6734"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1252
END
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE 9, 1
#pragma code_page(1252)
#include "afxres.rc" // Standard components
#endif
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
@@ -0,0 +1,275 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{25B000DF-5F76-4D5E-8C26-2C63FD2E8BA1}</ProjectGuid>
<RootNamespace>usbdll</RootNamespace>
<Keyword>MFCDLLProj</Keyword>
<ProjectName>tiusbdll</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<CustomBuildAfterTargets Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</LinkIncremental>
<CustomBuildAfterTargets Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Midl>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MkTypLibCompatible>false</MkTypLibCompatible>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\usb_bulk_example;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include\gl;C:\Program Files\Microsoft SDKs\Windows\v6.1\VC\Include;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(FrameworkSDKDir)include;$(DDKROOT)\inc\wdf\umdf\1.9;$(DDKROOT)\inc\api;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>winusb.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(DDKROOT)\lib\wlh\i386;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ModuleDefinitionFile>tiusbdll.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
</Link>
<CustomBuildStep>
<Outputs>${OutDir}\tiusbdll.lib;%(Outputs)</Outputs>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<CustomBuildStep>
<Outputs>${OutDir}\tiusbdll.lib;%(Outputs)</Outputs>
</CustomBuildStep>
<Midl>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MkTypLibCompatible>false</MkTypLibCompatible>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\usb_bulk_example;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include\gl;C:\Program Files\Microsoft SDKs\Windows\v6.1\VC\Include;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(FrameworkSDKDir)include;$(DDKROOT)\inc\wdf\umdf\1.9;$(DDKROOT)\inc\api;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>winusb.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<AdditionalLibraryDirectories>$(DDKROOT)\lib\wlh\amd64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ModuleDefinitionFile>tiusbdll.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Midl>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MkTypLibCompatible>false</MkTypLibCompatible>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>..\usb_bulk_example;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include\gl;C:\Program Files\Microsoft SDKs\Windows\v6.1\VC\Include;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(FrameworkSDKDir)include;$(DDKROOT)\inc\wdf\umdf\1.9;$(DDKROOT)\inc\api;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<ProjectReference>
<UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
</ProjectReference>
<Link>
<AdditionalDependencies>winusb.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(DDKROOT)\lib\wlh\i386;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ModuleDefinitionFile>tiusbdll.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
<CustomBuildStep>
<Outputs>${OutDir}\tiusbdll.lib;%(Outputs)</Outputs>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<CustomBuildStep>
<Command>touch $(OutDir)tiusbdll.lib
</Command>
<Outputs>$(OutDir)tiusbdll.lib;%(Outputs)</Outputs>
</CustomBuildStep>
<Midl>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MkTypLibCompatible>false</MkTypLibCompatible>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>..\usb_bulk_example;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include;C:\Program Files\Microsoft SDKs\Windows\v6.1\Include\gl;C:\Program Files\Microsoft SDKs\Windows\v6.1\VC\Include;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(FrameworkSDKDir)include;$(DDKROOT)\inc\wdf\umdf\1.9;$(DDKROOT)\inc\api;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<IgnoreStandardIncludePath>true</IgnoreStandardIncludePath>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>winusb.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<AdditionalLibraryDirectories>$(DDKROOT)\lib\wlh\amd64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ModuleDefinitionFile>lmusbdll.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="tiusbdll.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="tiusbdll.def" />
<None Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="tiusbdll.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="stdafx.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="tiusbdll.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,22 @@
-----------------------------------
USB Bulk Example (usb_bulk_example)
-----------------------------------
This Windows command line application is written using C for Windows
and should be built using Microsoft Visual Studio 2010. Project
file usb_bulk_example.vxcproj is provided to build the application.
USB communication with the board running the usb_dev_bulk sample application
is performed using the TIUSBDLL interface which is a thin wrapper over the
Microsoft WinUSB API. The relevant WinUSB subsystem files and the
TIUSBDLL.dll are installed when you first connect the board to a Windows
host via USB and install the drivers. Device drivers for the usb_dev_bulk
device can be found in the MWare\windows_drivers directory.
The TIUSBDLL interface is provided purely to allow the sample applications
to be compiled and run in the absence of the Windows Device Driver Kit
(DDK). The WinUSB API header and library files are not included in the
Windows SDK shipped with Visual Studio 2010 so any code which uses this
interface requires access to the DDK to build. TIUSBDLL contains all
the application code requiring WinUSB so applications may link to it
without the need for the Windows DDK.
@@ -0,0 +1,158 @@
//###########################################################################
//
// FILE: bulk_libusb.c
//
// TITLE: Implementation of the bulk_usb interface using the linusb-win32 API.
//
//###########################################################################
//
//
//
// C2000Ware v5.04.00.00
//
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef USE_WINUSB
//
// Included Files
//
#include "libusb-win32\include\usb.h"
//
// Structure containing handles and information required to communicate with
// the USB bulk device.
//
typedef struct
{
usb_dev_handle *hDevice;
} tDeviceInfo;
tDeviceInfo devInfo;
//
// Functions
//
//****************************************************************************
//
// Determines that the required USB device is present, opens it and gathers
// required information to allow us to read and write it.
//
// \param None.
//
// This function is called to initialize the USB device and perform one-off
// setup required to allocate handles allowing the application to read and
// write the device endpoints.
//
// \return Returns \e TRUE on success or \e FALSE on failure. In failing
// cases, GetLastError() can be called to determine the cause.
//
//****************************************************************************
BOOL InitializeDevice(void)
{
//
// Initialize the libusb-win32 subsystem.
//
usb_init();
return(TRUE);
}
//****************************************************************************
//
// Cleans up and free resources associated with the USB device communication
// prior to exiting the application.
//
// \param None.
//
// This function should be called prior to exiting the application to free
// the resources allocated during InitializeDevice().
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL TerminateDevice(void)
{
return(TRUE);
}
//****************************************************************************
//
// Writes a buffer of data to the USB device via the bulk OUT endpoint.
//
// \param pcBuffer points to the first byte of data to send.
// \param ulSize contains the number of bytes of data to send.
// \param pulWritten is a pointer which will be written with the number of
// bytes of data actually written to the device.
//
// This function is used to send data to the USB device via its bulk OUT endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL WriteUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulWritten)
{
return(TRUE);
}
//****************************************************************************
//
// Reads data from the USB device via the bulk IN endpoint.
//
// \param pcBuffer points to a buffer into which the data from the device will
// be written.
// \param ulSize contains the number of bytes that are requested from the
// device.
// \param pulRead is a pointer which will be written with the number of
// bytes of data actually read from the device.
//
// This function is used to receivedata from the USB device via its bulk IN
// endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL ReadUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulRead)
{
return(TRUE);
}
#endif // not defined USE_WINUSB
//
// End of file
//
@@ -0,0 +1,63 @@
//###########################################################################
//
// FILE: bulk_usb.h
//
// TITLE: Public header for the USB interface used by the usb_bulk_example
// application.
//
//###########################################################################
//
//
//
// C2000Ware v5.04.00.00
//
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef __BULK_USB_H__
#define __BULK_USB_H__
//
// Function Prototypes
//
extern BOOL InitializeDevice(void);
extern BOOL TerminateDevice(void);
extern BOOL WriteUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulWritten);
extern BOOL ReadUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulRead);
#endif
//
// End of file
//
@@ -0,0 +1,527 @@
//###########################################################################
//
// FILE: bulk_winusb.c
//
// TITLE: Implementation of the bulk_usb interface using Microsoft's
// WinUSB API.
//
//###########################################################################
//
//
//
// C2000Ware v5.04.00.00
//
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifdef USE_WINUSB
//
// Included Files
//
#include <windows.h>
#include <setupapi.h>
#include <devguid.h>
#include <regstr.h>
#include <strsafe.h>
#include <initguid.h>
#include "bulk_usb.h"
#include "luminary_guids.h"
#include "winusb.h"
#include "usb100.h"
//
// Defines
//
#define MAX_DEVPATH_LENGTH 256
//
// Globals
//
//
// Structure containing handles and information required to communicate with
// the USB bulk device.
//
typedef struct
{
HANDLE deviceHandle;
WINUSB_INTERFACE_HANDLE winUSBHandle;
UCHAR deviceSpeed;
UCHAR bulkInPipe;
UCHAR bulkOutPipe;
} tDeviceInfoWinUSB;
tDeviceInfoWinUSB devInfo;
//
// Functions
//
//****************************************************************************
//
// Returns the device path associated with a provided interface GUID.
//
// \param InterfaceGuid is a pointer to the GUID for the interface that
// we are looking for. Assuming you installed the device using the sample
// INF file, this will be the GUID provided in the Dev_AddReg section.
// \param pcDevicePath is a pointer to a buffer into which will be written
// the path to the device if the function is successful.
// \param BufLen is the size of the buffer pointed to by \f pcDevicePath.
//
// Given an interface GUID, this function determines the path that is
// necessary to open a file handle on the USB device we are interested in
// talking to. It returns the path to the first device which is present in
// the system and which offers the required interface.
//
// \return Returns one of the following Windows system error codes.
// ERROR_SUCCESS if the operation completed successfully
// ERROR_DEV_NOT_EXIST if the interface is not found on the system. This
// implies that the driver for the USB device has not been installed.
// ERROR_DEVICE_NOT_CONNECTED if the interface has been installed but no
// device offering it is presently available. This typically indicates
// that the USB device is not currently connected.
// ERROR_NOT_ENOUGH_MEMORY if the function fails to allocate any required
// buffers.
// ERROR_INSUFFICIENT_BUFFER if the buffer passed is too small to hold
// the device path.
//
//****************************************************************************
static DWORD GetDevicePath(LPGUID InterfaceGuid,
PCHAR pcDevicePath,
size_t BufLen)
{
BOOL bResult = FALSE;
HDEVINFO deviceInfo;
SP_DEVICE_INTERFACE_DATA interfaceData;
PSP_DEVICE_INTERFACE_DETAIL_DATA detailData = NULL;
ULONG length;
ULONG requiredLength=0;
HRESULT hr;
//
// Get a handle to the device information set containing information on
// the interface GUID supplied on this PC.
//
deviceInfo = SetupDiGetClassDevs(InterfaceGuid,
NULL, NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if(deviceInfo == INVALID_HANDLE_VALUE)
{
//
// No device offering the required interface is present. Has the
// interface been installed? Ask for the information set for all
// devices and not just those that are presently installed.
//
deviceInfo = SetupDiGetClassDevs(InterfaceGuid,
NULL, NULL,
DIGCF_DEVICEINTERFACE);
if(deviceInfo == INVALID_HANDLE_VALUE)
{
return(ERROR_DEV_NOT_EXIST);
}
else
{
SetupDiDestroyDeviceInfoList(deviceInfo);
return(ERROR_DEVICE_NOT_CONNECTED);
}
}
interfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
//
// SetupDiGetClassDevs returned us a valid information set handle so we
// now query this set to find the find the first device offering the
// interface whose GUID was supplied.
//
bResult = SetupDiEnumDeviceInterfaces(deviceInfo,
NULL,
InterfaceGuid,
0,
&interfaceData);
if(bResult == FALSE)
{
//
// We failed to find the first matching device so tell the caller
// that no suitable device is connected.
//
return(ERROR_DEVICE_NOT_CONNECTED);
}
//
// Now that we have the interface information, we need to query details
// to retrieve the device path. First determine how much space we need to
// hold the detail information.
//
SetupDiGetDeviceInterfaceDetail(deviceInfo,
&interfaceData,
NULL, 0,
&requiredLength,
NULL);
//
// Allocate a buffer to hold the interface details.
//
detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LMEM_FIXED,
requiredLength);
if(NULL == detailData)
{
SetupDiDestroyDeviceInfoList(deviceInfo);
return(ERROR_NOT_ENOUGH_MEMORY);
}
detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
length = requiredLength;
//
// Now call once again to retrieve the actual interface detail information.
//
bResult = SetupDiGetDeviceInterfaceDetail(deviceInfo,
&interfaceData,
detailData,
length,
&requiredLength,
NULL);
if(FALSE == bResult)
{
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(GetLastError());
}
//
// Copy the device path string from the interface details structure into
// the caller's buffer.
//
hr = StringCchCopy((LPTSTR)pcDevicePath,
BufLen,
(LPCTSTR)detailData->DevicePath);
if(FAILED(hr))
{
//
// We failed to copy the device path string!
//
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(ERROR_INSUFFICIENT_BUFFER);
}
//
// Clean up and free locally allocated resources.
//
SetupDiDestroyDeviceInfoList(deviceInfo);
LocalFree(detailData);
return(ERROR_SUCCESS);
}
//****************************************************************************
//
// Opens the USB device and returns a file handle.
//
// \param None.
//
// This function determines whether or not the required USB device is
// available and, if so, creates a file allowing access to it. The file
// handle is returned on success.
//
// \return Returns a valid file handle on success of INVALID_HANDLE_VALUE
// on failure. In cases of failure, GetLastError() can be called to determine
// the cause.
//
//****************************************************************************
static HANDLE OpenDevice(void)
{
HANDLE hDev = NULL;
char devicePath[MAX_DEVPATH_LENGTH];
BOOL retVal;
//
// Get the path needed to open a file handle on our USB device.
//
retVal = GetDevicePath((LPGUID)&GUID_DEVINTERFACE_LUMINARY_BULK,
devicePath,
sizeof(devicePath));
if(retVal != ERROR_SUCCESS)
{
SetLastError(retVal);
return(INVALID_HANDLE_VALUE);
}
//
// Open the file we will use to communicate with the device.
//
hDev = CreateFile((LPCTSTR)devicePath,
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);
return(hDev);
}
//****************************************************************************
//
// Determines that the required USB device is present, opens it and gathers
// required information to allow us to read and write it.
//
// \param None.
//
// This function is called to initialize the USB device and perform one-off
// setup required to allocate handles allowing the application to read and
// write the device endpoints.
//
// \return Returns \e TRUE on success or \e FALSE on failure. In failing
// cases, GetLastError() can be called to determine the cause.
//
//****************************************************************************
BOOL InitializeDevice(void)
{
BOOL bResult;
WINUSB_INTERFACE_HANDLE usbHandle;
USB_INTERFACE_DESCRIPTOR ifaceDescriptor;
WINUSB_PIPE_INFORMATION pipeInfo;
UCHAR speed;
ULONG length;
int i;
//
// Determine whether the USB device is present and, if so, generate a file
// handle to allow access to it.
//
devInfo.deviceHandle = OpenDevice();
if(devInfo.deviceHandle == INVALID_HANDLE_VALUE)
{
//
// We were unable to access the device - return a failure.
//
return(FALSE);
}
//
// The device is opened so we now initialize the WinUSB layer passing it
// the device handle.
//
bResult = WinUsb_Initialize(devInfo.deviceHandle, &usbHandle);
if(bResult)
{
//
// If we managed to initialize the WinUSB layer, we now query the
// device descriptor to determine the speed of the device.
//
devInfo.winUSBHandle = usbHandle;
length = sizeof(UCHAR);
bResult = WinUsb_QueryDeviceInformation(devInfo.winUSBHandle,
DEVICE_SPEED,
&length,
&speed);
}
if(bResult)
{
//
// If all is well, now query the interface descriptor. We ask for the
// first interface only since, in the case of the generic bulk device,
// this is all that is available.
//
devInfo.deviceSpeed = speed;
bResult = WinUsb_QueryInterfaceSettings(devInfo.winUSBHandle,
0,
&ifaceDescriptor);
}
if(bResult)
{
//
// We got the interface descriptor so now we enumerate the endpoints
// to find the two we require - one bulk IN endpoint and one bulk OUT
// endpoint.
//
for(i=0;i<ifaceDescriptor.bNumEndpoints;i++)
{
bResult = WinUsb_QueryPipe(devInfo.winUSBHandle, 0, (UCHAR) i,
&pipeInfo);
if((pipeInfo.PipeType == UsbdPipeTypeBulk) &&
USB_ENDPOINT_DIRECTION_IN(pipeInfo.PipeId))
{
devInfo.bulkInPipe = pipeInfo.PipeId;
}
else if((pipeInfo.PipeType == UsbdPipeTypeBulk) &&
USB_ENDPOINT_DIRECTION_OUT(pipeInfo.PipeId))
{
devInfo.bulkOutPipe = pipeInfo.PipeId;
}
else
{
//
// Hmm... we found and endpoint that we didn't expect to see
// on this interface. This tends to imply that there is a
// mismatch between the device configuration and this
// application so we will fail the call after setting an
// appropriate error code for the caller to query.
//
SetLastError(ERROR_NOT_SAME_DEVICE);
bResult = FALSE;
break;
}
}
}
return(bResult);
}
//****************************************************************************
//
// Cleans up and free resources associated with the USB device communication
// prior to exiting the application.
//
// \param None.
//
// This function should be called prior to exiting the application to free
// the resources allocated during InitializeDevice().
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL TerminateDevice(void)
{
BOOL bRetcode;
BOOL bRetcode2;
bRetcode = WinUsb_Free(devInfo.winUSBHandle);
bRetcode2 = CloseHandle(devInfo.deviceHandle);
if(bRetcode & bRetcode2)
{
return(TRUE);
}
else
{
return(FALSE);
}
}
//****************************************************************************
//
// Writes a buffer of data to the USB device via the bulk OUT endpoint.
//
// \param pcBuffer points to the first byte of data to send.
// \param ulSize contains the number of bytes of data to send.
// \param pulWritten is a pointer which will be written with the number of
// bytes of data actually written to the device.
//
// This function is used to send data to the USB device via its bulk OUT
// endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL WriteUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulWritten)
{
BOOL bResult;
bResult = WinUsb_WritePipe(devInfo.winUSBHandle,
devInfo.bulkOutPipe,
pcBuffer,
ulSize,
pulWritten,
NULL);
return(bResult);
}
//****************************************************************************
//
// Reads data from the USB device via the bulk IN endpoint.
//
// \param pcBuffer points to a buffer into which the data from the device will
// be written.
// \param ulSize contains the number of bytes that are requested from the
// device.
// \param pulRead is a pointer which will be written with the number of
// bytes of data actually read from the device.
//
// This function is used to receivedata from the USB device via its bulk IN
// endpoint.
//
// \return Returns \e TRUE on success or \e FALSE on failure.
//
//****************************************************************************
BOOL ReadUSBPacket(unsigned char *pcBuffer, unsigned long ulSize,
unsigned long *pulRead)
{
BOOL bResult;
unsigned long ulSecondRead;
bResult = WinUsb_ReadPipe(devInfo.winUSBHandle,
devInfo.bulkInPipe,
pcBuffer,
ulSize,
pulRead,
NULL);
//
// Make sure we got the number of bytes expected. If we got less, try to
// read the remainder.
//
if(bResult && (*pulRead < ulSize))
{
bResult = WinUsb_ReadPipe(devInfo.winUSBHandle,
devInfo.bulkInPipe,
pcBuffer + *pulRead,
ulSize - *pulRead,
&ulSecondRead,
NULL);
if(bResult)
{
*pulRead += ulSecondRead;
}
}
return(bResult);
}
#endif // USE_WINUSB
//
// End of file
//
@@ -0,0 +1,72 @@
//###########################################################################
//
// FILE: ti_guids.h
//
// TITLE: GUIDs associated with TI Micro USB examples
//
//###########################################################################
//
//
//
// C2000Ware v5.04.00.00
//
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef _TI_GUIDS_
#define _TI_GUIDS_
//
// Vendor and Product IDs for the generic bulk device.
//
#define BULK_VID 0x1cbe
#define BULK_PID 0x0003
//
// TI Bulk Device Class GUID
// {F5450C06-EB58-420e-8F98-A76C5D4AFB18}
//
DEFINE_GUID(GUID_DEVCLASS_TI_BULK,
0xF5450C06, 0xEB5B, 0x420E, 0x8F, 0x98, 0xA7, 0x6C, 0x5D, 0x4A, 0xFB, 0x18);
//
// TI Bulk Device Interface GUID
// {6E45736A-2B1B-4078-B772-B3AF2B6FDE1C}
//
DEFINE_GUID(GUID_DEVINTERFACE_TI_BULK,
0x6E45736A, 0x2B1B, 0x4078, 0xB7, 0x72, 0xb3, 0xAF, 0x2B, 0x6F, 0xDE, 0x1C);
#endif
//
// End of file
//
@@ -0,0 +1,479 @@
//###########################################################################
//
// FILE: usb_bulk_example.c
//
// TITLE: A very simple command line application that attempts
// to open the TI Generic Bulk USB device and exchange data
// with it.
//
// If the device is successfully opened, the user is prompted for a string
// which is then sent to the device. The device toggles the case of any
// alphabet characters in the the data and sends it back. We receive this
// and print out the result.
//
// Communication with the device is carried out via a simple DLL, tiusbdll(64),
// which is responsible for opening and closing the device and for
// sending and receiving blocks of data. This structure allows the
// application code to be kept independent of the underlying USB driver
// in use. In this implementation, Microsoft's WinUSB interface is used
// but a switch to another stack, for example the open source libusb-win32
// interface could be made merely be replacing the tiusbdll(64).dll with
// another version writing to the different USB stack.
//
// One downside to using WinUSB is that it requires you to have the Windows
// Device Driver Kit (DDK) installed to build applications which use the
// interface. This is a very large download making it awkward for people
// with slow internet connections. The use of tiusbdll(64).dll also offers
// the advantage that applications using it can still be modified and
// rebuilt even without the DDK installed on the development system. To
// update and rebuild tiusbdll itself, however, the DDK is still required.
//
//
//###########################################################################
//
//
//
// C2000Ware v5.04.00.00
//
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
//
// Included Files
//
#include <windows.h>
#include <strsafe.h>
#include <initguid.h>
#include "tiusbdll.h"
#include "ti_guids.h"
//
// Buffer size definitions.
//
#define MAX_STRING_LEN 256
#define MAX_ENTRY_LEN 256
#define USB_BUFFER_LEN 1216
//
// Defines
//
//
// The build version number
//
#define BLDVER "7611"
//
// The number of bytes we read and write per transaction if in echo mode.
//
#define ECHO_PACKET_SIZE 64
//
// Globals
//
//
// Buffer into which error messages are written.
//
TCHAR g_pcErrorString[MAX_STRING_LEN];
//
// The number of bytes transferred in the last measurement interval.
//
ULONG g_ulByteCount = 0;
//
// The total number of packets transferred.
//
ULONG g_ulPacketCount = 0;
//
// Functions
//
//****************************************************************************
//
// Return a string describing the supplied system error code.
//
// \param dwError is a Windows system error code.
//
// This function returns a pointer to a string describing the error code
// passed in the dwError parameter. If no description string can be found
// the string "Unknown" is returned.
//
// \return Returns a pointer to a string describing the error.
//
//****************************************************************************
LPTSTR GetSystemErrorString(DWORD dwError)
{
DWORD dwRetcode;
//
// Ask Windows for the error message description.
//
dwRetcode = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, "%0", dwError, 0,
g_pcErrorString, MAX_STRING_LEN, NULL);
if(dwRetcode == 0)
{
return((LPTSTR)L"Unknown");
}
else
{
//
// Remove the trailing "\n\r" if present.
//
if(dwRetcode >= 2)
{
if(g_pcErrorString[dwRetcode - 2] == '\r')
{
g_pcErrorString[dwRetcode - 2] = '\0';
}
}
return(g_pcErrorString);
}
}
//****************************************************************************
//
// Print the throughput in terms of Kbps once per second.
//
//****************************************************************************
void UpdateThroughput(void)
{
static ULONG ulStartTime = 0;
static ULONG ulLast = 0;
ULONG ulNow;
ULONG ulElapsed;
SYSTEMTIME sSysTime;
//
// Get the current system time.
//
GetSystemTime(&sSysTime);
ulNow = (((((sSysTime.wHour * 60) +
sSysTime.wMinute) * 60) +
sSysTime.wSecond) * 1000) + sSysTime.wMilliseconds;
//
// If this is the first call, set the start time.
//
if(ulStartTime == 0)
{
ulStartTime = ulNow;
ulLast = ulNow;
return;
}
//
// How much time has elapsed since the last measurement?
//
ulElapsed = (ulNow > ulStartTime) ? (ulNow - ulStartTime) : (ulStartTime - ulNow);
//
// We dump a new measurement every second.
//
if(ulElapsed > 1000)
{
printf("\r%6dKbps Packets: %10d ", ((g_ulByteCount * 8) / ulElapsed),
g_ulPacketCount);
g_ulByteCount = 0;
ulStartTime = ulNow;
}
}
//****************************************************************************
//
// The main application entry function.
//
// \param None.
//
// This function forms the main entry point of the example application. It
// initializes the USB bulk device, prompts the user for an ASCII string,
// sends this string to the device, reads the response from the device (which
// will be the same string with the character order reversed if using the
// sample device provided) and displays the returned string.
//
// \return Set the exit code to 0 of no errors cause the application to end
// or a non-zero value otherwise.
//
//****************************************************************************
int main(int argc, char *argv[])
{
BOOL bResult;
BOOL bDriverInstalled;
BOOL bEcho;
char szBuffer[USB_BUFFER_LEN];
ULONG ulWritten;
ULONG ulRead;
ULONG ulLength;
DWORD dwError;
TIUSB_HANDLE hUSB;
//
// Are we operating in echo mode or not? The "-e" parameter tells the
// app to echo everything it receives back to the device unchanged.
//
bEcho = ((argc > 1) && (argv[1][1] == 'e')) ? TRUE : FALSE;
//
// Print a cheerful welcome.
//
printf("\nTI Bulk USB Device Example\n");
printf( "---------------------------------\n\n");
printf("Version %s\n\n", BLDVER);
if(!bEcho)
{
printf("This is a partner application to the usb_dev_bulk example\n");
printf("shipped software releases for USB-enabled boards. \n");
printf("Strings entered here are sent to the board which\n");
printf("inverts the case of the characters in the string and returns\n");
printf("them to the host.\n\n");
}
else
{
printf("If run with the \"-e\" command line switch, this application\n");
printf("echoes all data received on the bulk IN endpoint to the bulk\n");
printf("OUT endpoint. This feature may be helpful during development\n");
printf("and debug of your own USB devices. Note that this will not\n");
printf("do anything exciting if run with the usb_dev_bulk example\n");
printf("device attached since it expects the host to initiate transfers.\n\n");
}
//
// Find our USB device and prepare it for communication.
//
hUSB = InitializeDevice(BULK_VID, BULK_PID,
(LPGUID)&(GUID_DEVINTERFACE_TI_BULK),
&bDriverInstalled);
if(hUSB)
{
//
// Are we operating in echo mode or not? The "-e" parameter tells the
// app to echo everything it receives back to the device unchanged.
//
if(bEcho)
{
//
// Yes - we are in echo mode.
//
printf("Running in echo mode. Press Ctrl+C to exit.\n\n");
while(1)
{
//
// Read a block of data from the device.
//
dwError = ReadUSBPacket(hUSB, szBuffer, ECHO_PACKET_SIZE, &ulRead,
INFINITE, NULL);
if(dwError != ERROR_SUCCESS)
{
//
// We failed to read from the device.
//
printf("\n\nError %d (%S) reading from bulk IN pipe.\n", dwError,
GetSystemErrorString(dwError));
break;
}
else
{
//
// Update our byte and packet counters.
//
g_ulByteCount += ulRead;
g_ulPacketCount++;
//
// Write the data back out to the device.
//
bResult = WriteUSBPacket(hUSB, szBuffer, ulRead, &ulWritten);
if(!bResult)
{
//
// We failed to write the data for some reason.
//
dwError = GetLastError();
printf("\n\nError %d (%S) writing to bulk OUT pipe.\n",
dwError, GetSystemErrorString(dwError));
break;
}
//
// Display the throughput.
//
UpdateThroughput();
}
}
}
else
{
//
// We are running in normal mode. Keep sending and receiving
// strings until the user indicates that it is time to exit.
//
while(1)
{
//
// The device was found and successfully configured.
// Now get a string from the user...
//
do
{
printf("\nEnter a string (EXIT to exit): ");
fgets(szBuffer, MAX_ENTRY_LEN, stdin);
printf("\n");
//
// How many characters were entered
// (including the trailing '\n')?
//
ulLength = (ULONG)strlen(szBuffer);
if(ulLength <= 1)
{
//
// The string is either nothing at all or a single
// '\n' so reprompt the user.
//
printf("\nPlease enter some text.\n");
ulLength = 0;
}
else
{
//
// Get rid of the trailing '\n' if there is one there.
//
if(szBuffer[ulLength - 1] == '\n')
{
szBuffer[ulLength - 1] = '\0';
ulLength--;
}
}
}
while(ulLength == 0);
//
// Are we being asked to exit the application?
//
if(!(strcmp("EXIT", szBuffer)))
{
//
// Yes - drop out and exit.
//
printf("Exiting on user request.\n");
break;
}
//
// Write the user's string to the device.
//
bResult = WriteUSBPacket(hUSB, szBuffer, ulLength, &ulWritten);
if(!bResult)
{
//
// We failed to write the data for some reason.
//
dwError = GetLastError();
printf("Error %d (%S) writing to bulk OUT pipe.\n", dwError,
GetSystemErrorString(dwError));
}
else
{
//
// We wrote data successfully so now read it back.
//
printf("Wrote %d bytes to the device. Expected %d\n",
ulWritten, ulLength);
//
// We expect the same number of bytes as we just sent.
//
dwError = ReadUSBPacket(hUSB, szBuffer, ulWritten, &ulRead,
INFINITE, NULL);
if(dwError != ERROR_SUCCESS)
{
//
// We failed to read from the device.
//
printf("Error %d (%S) reading from bulk IN pipe.\n",
dwError, GetSystemErrorString(dwError));
}
else
{
//
// Add a string terminator to the returned data (this
// should already be there but, just in case...)
//
szBuffer[ulRead] = '\0';
printf("Read %d bytes from device. Expected %d\n",
ulRead, ulWritten);
printf("\nReturned string: \"%s\"\n", szBuffer);
}
}
}
}
}
else
{
//
// An error was reported while trying to connect to the device.
//
dwError = GetLastError();
printf("\nUnable to initialize the TI Bulk USB Device.\n");
printf("Error code is %d (%S)\n\n", dwError, GetSystemErrorString(dwError));
printf("Please make sure you have a TI USB-enabled evaluation\n");
printf("or development kit running the usb_dev_bulk example\n");
printf("application connected to this system via the \"USB OTG\" or\n");
printf("\"USB DEVICE\" connectors. Once the device is connected, run\n");
printf("this application again.\n\n");
printf("\nPress \"Enter\" to exit: ");
fgets(szBuffer, MAX_STRING_LEN, stdin);
printf("\n");
return(2);
}
TerminateDevice(hUSB);
return(0);
}
//
// End of file
//
@@ -0,0 +1,381 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="usb_bulk_example"
ProjectGUID="{603D9796-4654-4082-9322-E4FC142312FB}"
RootNamespace="usb_bulk_example"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../lmusbdll"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="$(OutDir);..\Debug"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../lmusbdll"
PreprocessorDefinitions="X64_BUILD"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
OutputFile="$(OutDir)\$(ProjectName).exe"
LinkIncremental="2"
AdditionalLibraryDirectories="$(OutDir);..\x64\Debug"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../lmusbdll"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="$(OutDir);..\Release"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../lmusbdll"
PreprocessorDefinitions="X64_BUILD"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
UseLibraryDependencyInputs="true"
AdditionalDependencies="lmusbdll.lib"
OutputFile="$(OutDir)\$(ProjectName).exe"
LinkIncremental="1"
AdditionalLibraryDirectories="$(OutDir);..\x64\Release"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\usb_bulk_example.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\bulk_usb.h"
>
</File>
<File
RelativePath="..\lmusbdll\lmusbdll.h"
>
</File>
<File
RelativePath=".\luminary_guids.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<File
RelativePath=".\ReadMe.txt"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
@@ -0,0 +1,206 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{603D9796-4654-4082-9322-E4FC142312FB}</ProjectGuid>
<RootNamespace>usb_bulk_example</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>12.0.21005.1</_ProjectFileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>../tiusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>tiusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir);..\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>../tiusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>X64_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>tiusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).exe</OutputFile>
<AdditionalLibraryDirectories>$(OutDir);..\x64\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>../tiusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>tiusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir);..\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>../lmusbdll;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>X64_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
<Link>
<AdditionalDependencies>tiusbdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).exe</OutputFile>
<AdditionalLibraryDirectories>$(OutDir);..\x64\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="usb_bulk_example.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="bulk_usb.h" />
<ClInclude Include="..\tiusbdll\tiusbdll.h" />
<ClInclude Include="luminary_guids.h" />
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

Some files were not shown because too many files have changed in this diff Show More