Silicon Labs Host Libraries
SLABHIDDevice.h
1 // SLABHIDDevice.h
4 
5 #ifndef HOST_LIB_SLABHIDDEVICE_INCLUDE_SLABHIDDEVICE_H_INCLUDED_MJWYLEYUPA
6 #define HOST_LIB_SLABHIDDEVICE_INCLUDE_SLABHIDDEVICE_H_INCLUDED_MJWYLEYUPA
7 
44 // Includes
46 
47 
48 #include "silabs_defs.h"
49 #include "silabs_sal.h"
50 #ifdef _WIN32
51 #include <windows.h>
52 #else // !_WIN32
53 #endif // !_WIN32
54 #include "Types.h"
55 
56 #ifdef _WIN32
57 // The following ifdef block is the standard way of creating macros which make exporting
58 // from a DLL simpler. All files within this DLL are compiled with the CP210xDLL_EXPORTS
59 // symbol defined on the command line. this symbol should not be defined on any project
60 // that uses this DLL. This way any other project whose source files include this file see
61 // CP210xDLL_API functions as being imported from a DLL, whereas this DLL sees symbols
62 // defined with this macro as being exported.
63 #ifdef SLAB_HID_DEVICE_EXPORTS
64 #define SLAB_HID_DEVICE_API
65 #elif defined(SLAB_HID_DEVICE_BUILD_SOURCE)
66 #define SLAB_HID_DEVICE_API
67 #else
68 #if defined(SILABS_STATIC_LINK)
69 #define SLAB_HID_DEVICE_API extern
70 #pragma comment (lib, "SLABHIDDevice.static.lib")
71 #else // defined(SILABS_STATIC_LINK)
72 #define SLAB_HID_DEVICE_API __declspec(dllimport)
73 #pragma comment (lib, "SLABHIDDevice.lib")
74 #endif // defined(SILABS_STATIC_LINK)
75 #endif
76 #else // !_WIN32
77 #define SLAB_HID_DEVICE_API
78 #define WINAPI
79 #endif // !_WIN32
80 
81 
83 // Definitions
85 
87 #define USE_LEGACY_SLAB_HID_DEVICE_STATUS
88 #if !defined(USE_LEGACY_SLAB_HID_DEVICE_STATUS) // TODO: Enstone: These defines are a exact duplicate values of HID_DEVICE_STATUS enums in HIDDevice.h.
89 typedef enum _SLAB_HID_DEVICE_STATUS {
90  HID_DEVICE_SUCCESS = 0x00
91  , HID_DEVICE_NOT_FOUND = 0x01
92  , HID_DEVICE_NOT_OPENED = 0x02
99  , HID_DEVICE_SYSTEM_CODE = 0x09
102 } SLAB_HID_DEVICE_STATUS, *PSLAB_HID_DEVICE_STATUS;
103 #else // defined(NOT_YET)
107 #if !defined(HID_DEVICE_H)
108 #define HID_DEVICE_SUCCESS 0x00
109 #define HID_DEVICE_NOT_FOUND 0x01
110 #define HID_DEVICE_NOT_OPENED 0x02
111 #define HID_DEVICE_ALREADY_OPENED 0x03
112 #define HID_DEVICE_TRANSFER_TIMEOUT 0x04
113 #define HID_DEVICE_TRANSFER_FAILED 0x05
114 #define HID_DEVICE_CANNOT_GET_HID_INFO 0x06
115 #define HID_DEVICE_HANDLE_ERROR 0x07
116 #define HID_DEVICE_INVALID_BUFFER_SIZE 0x08
117 #define HID_DEVICE_SYSTEM_CODE 0x09
118 #define HID_DEVICE_INVALID_PARAMETER 0x0B
119 #define HID_DEVICE_UNKNOWN_ERROR SILABS_STATUS_UNKNOWN_ERROR
120 #endif
121 #define HID_DEVICE_UNSUPPORTED_FUNCTION 0x0A
122 #endif // defined(NOT_YET)
124 
125 
127 #define MAX_USB_DEVICES 64
128 
131 #define MAX_REPORT_REQUEST_XP 512
132 #define MAX_REPORT_REQUEST_2K 200
133 
134 #define DEFAULT_REPORT_INPUT_BUFFERS 0
135 
137 #if !defined(HID_DEVICE_H)
139 #define HID_VID_STRING 0x01
140 #define HID_PID_STRING 0x02
141 #define HID_PATH_STRING 0x03
142 #define HID_SERIAL_STRING 0x04
143 #define HID_MANUFACTURER_STRING 0x05
144 #define HID_PRODUCT_STRING 0x06
145 #endif
146 #if !defined(MAX_STRING_LENGTH)
149 #define MAX_VID_LENGTH 5
150 #define MAX_PID_LENGTH 5
151 #define MAX_PATH_LENGTH 260
152 #define MAX_SERIAL_STRING_LENGTH 256
153 #define MAX_MANUFACTURER_STRING_LENGTH 256
154 #define MAX_PRODUCT_STRING_LENGTH 256
155 #define MAX_INDEXED_STRING_LENGTH 256
156 #define MAX_STRING_LENGTH 260
157 #endif
158 
161 // Typedefs
163 
164 typedef void* HID_DEVICE;
165 
167 // Exported Functions
169 
170 
171 #ifdef __cplusplus
172 extern "C" {
173 #endif // __cplusplus
174 
194 _Check_return_
195 _Ret_range_(0, MAX_USB_DEVICES-1)
197 HidDevice_GetNumHidDevices(_In_ _Pre_defensive_ const WORD Vid, _In_ _Pre_defensive_ const WORD Pid);
198 
245 _Check_return_
247 _Success_(HID_DEVICE_SUCCESS == return)
249 HidDevice_GetHidString(_In_ _Pre_defensive_ const DWORD dwDeviceIndex, _In_ _Pre_defensive_ const WORD Vid, _In_ _Pre_defensive_ const WORD Pid, _In_ _Pre_defensive_ const BYTE WhichHidStringToReturn, char* deviceString, _In_ _Pre_defensive_ const DWORD deviceStringLengthInBytes);
250 
275 _Check_return_
277 _Success_(HID_DEVICE_SUCCESS == return)
279 HidDevice_GetHidIndexedString(_In_ _Pre_defensive_ const DWORD dwDeviceIndex, _In_ _Pre_defensive_ const WORD Vid, _In_ _Pre_defensive_ const WORD Pid, _In_ _Pre_defensive_ const DWORD stringIndex, char* deviceString, _In_ _Pre_defensive_ const DWORD deviceStringLengthInBytes);
280 
303 _Check_return_
305 _Success_(HID_DEVICE_SUCCESS == return)
307 HidDevice_GetHidAttributes(_In_ _Pre_defensive_ const DWORD dwDeviceIndex, _In_ _Pre_defensive_ const WORD Vid, _In_ _Pre_defensive_ const WORD Pid, _Out_writes_bytes_(2) _Pre_defensive_ WORD* pDeviceVid, _Out_writes_bytes_(2) _Pre_defensive_ WORD* pDevicePid, _Out_writes_bytes_(2) _Pre_defensive_ WORD* pDeviceReleaseNumber);
308 
314 HidDevice_GetHidGuid(_Out_ void *pHIDGuid);
315 
325 _Check_return_
327 _Success_(HID_DEVICE_SUCCESS == return)
329 HidDevice_GetHidLibraryVersion(_Out_writes_bytes_(1) _Pre_defensive_ BYTE* pMajor, _Out_writes_bytes_(1) _Pre_defensive_ BYTE* pMinor, _Out_writes_bytes_(4) BOOL* pbIsReleaseBuild);
330 
365 _Check_return_
367 _Success_(HID_DEVICE_SUCCESS == return)
369 HidDevice_Open(_Out_ HID_DEVICE* device, _In_ _Pre_defensive_ const DWORD dwDeviceIndex, _In_ _Pre_defensive_ const WORD Vid, _In_ _Pre_defensive_ const WORD Pid, _In_ _Pre_defensive_ const DWORD numInputBuffers);
370 
376 _Ret_range_(FALSE, TRUE)
377 _Success_(return)
379 HidDevice_IsOpened(_In_ _Pre_defensive_ const HID_DEVICE device);
380 
387 _Check_return_
389 HidDevice_GetHandle(_In_ _Pre_defensive_ const HID_DEVICE device);
390 
432 _Success_(HID_DEVICE_SUCCESS == return)
434 HidDevice_GetString(_In_ _Pre_defensive_ const HID_DEVICE device, _In_ _Pre_defensive_ const BYTE WhichHidStringToReturn, char* deviceString, _In_ _Pre_defensive_ const DWORD deviceStringLengthInBytes);
435 
454 _Check_return_
456 _Success_(HID_DEVICE_SUCCESS == return)
458 HidDevice_GetIndexedString(_In_ _Pre_defensive_ const HID_DEVICE device, _In_ _Pre_defensive_ const DWORD stringIndex, char* deviceString, _In_ _Pre_defensive_ const DWORD deviceStringLengthInBytes);
459 
478 _Check_return_
480 _Success_(HID_DEVICE_SUCCESS == return)
482 HidDevice_GetAttributes(_In_ _Pre_defensive_ const HID_DEVICE device, _Out_writes_bytes_(2) _Pre_defensive_ WORD* pDeviceVid, _Out_writes_bytes_(2) _Pre_defensive_ WORD* pDevicePid, _Out_writes_bytes_(2) _Pre_defensive_ WORD* pDeviceReleaseNumber);
483 
495 _Check_return_
497 _Success_(HID_DEVICE_SUCCESS == return)
499 HidDevice_SetFeatureReport_Control(_In_ _Pre_defensive_ const HID_DEVICE device, _In_reads_bytes_(ReportBufferLengthInBytes) _Pre_defensive_ BYTE* ReportBuffer, _In_ _Pre_defensive_ const DWORD ReportBufferLengthInBytes);
500 
517 _Check_return_
519 _Success_(HID_DEVICE_SUCCESS == return)
521 HidDevice_GetFeatureReport_Control(_In_ _Pre_defensive_ const HID_DEVICE device, _Out_writes_bytes_(ReportBufferLengthInBytes) _Pre_defensive_ BYTE* ReportBuffer, _In_ _Pre_defensive_ const DWORD ReportBufferLengthInBytes);
522 
535 _Check_return_
537 _Success_(HID_DEVICE_SUCCESS == return)
539 HidDevice_SetOutputReport_Interrupt(_In_ _Pre_defensive_ const HID_DEVICE device, _In_reads_bytes_(ReportBufferLengthInBytes) _Pre_defensive_ BYTE* ReportBuffer, _In_ _Pre_defensive_ const DWORD ReportBufferLengthInBytes);
540 
566 _Check_return_
568 _Success_(HID_DEVICE_SUCCESS == return)
570 HidDevice_GetInputReport_Interrupt(_In_ _Pre_defensive_ const HID_DEVICE device, _Out_writes_bytes_(ReportBufferLengthInBytes) _Pre_defensive_ BYTE* ReportBuffer, _In_ _Pre_defensive_ const DWORD ReportBufferLengthInBytes, _In_ _Pre_defensive_ const DWORD numReports, _Out_writes_bytes_(sizeof(DWORD)) _Pre_defensive_ DWORD* bytesReturned);
571 
598 _Check_return_
600 _Success_(HID_DEVICE_SUCCESS == return)
602 HidDevice_GetInputReport_Interrupt_WithTimeout(_In_ _Pre_defensive_ const HID_DEVICE device, _Out_writes_bytes_(ReportBufferLengthInBytes) _Pre_defensive_ BYTE* ReportBuffer, _In_ _Pre_defensive_ const DWORD ReportBufferLengthInBytes, _In_ _Pre_defensive_ const DWORD numReports, _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ DWORD* bytesReturned, _In_ _Pre_defensive_ const DWORD TimeoutMSec);
603 
617 _Check_return_
619 _Success_(HID_DEVICE_SUCCESS == return)
621 HidDevice_SetOutputReport_Control(_In_ _Pre_defensive_ const HID_DEVICE device, _In_reads_bytes_(ReportBufferLengthInBytes) _Pre_defensive_ BYTE* ReportBuffer, _In_ _Pre_defensive_ const DWORD ReportBufferLengthInBytes);
622 
641 _Check_return_
643 _Success_(HID_DEVICE_SUCCESS == return)
645 HidDevice_GetInputReport_Control(_In_ _Pre_defensive_ const HID_DEVICE device, _Out_writes_bytes_(ReportBufferLengthInBytes) _Pre_defensive_ BYTE* ReportBuffer, _In_ _Pre_defensive_ const DWORD ReportBufferLengthInBytes);
646 
647 
657 HidDevice_GetInputReportBufferLength(_In_ _Pre_defensive_ const HID_DEVICE device);
658 
666 HidDevice_GetOutputReportBufferLength(_In_ _Pre_defensive_ const HID_DEVICE device);
667 
677 HidDevice_GetFeatureReportBufferLength(_In_ _Pre_defensive_ const HID_DEVICE device);
678 
688 HidDevice_GetMaxReportRequest(_In_ _Pre_defensive_ const HID_DEVICE device);
689 
701 _Check_return_
702 _Ret_range_(FALSE, TRUE)
703 _Success_(return)
705 HidDevice_FlushBuffers(_In_ _Pre_defensive_ const HID_DEVICE device);
706 
715 _Check_return_
716 _Ret_range_(FALSE, TRUE)
717 _Success_(return)
719 HidDevice_CancelIo(_In_ _Pre_defensive_ const HID_DEVICE device);
720 
745 HidDevice_GetTimeouts(_In_ _Pre_defensive_ const HID_DEVICE device, _Out_writes_bytes_(4) _Pre_defensive_ DWORD* pGetReportTimeoutInMilliSeconds, _Out_writes_bytes_(4) _Pre_defensive_ DWORD* pSetReportTimeoutInMilliSeconds);
746 
769 HidDevice_SetTimeouts(_In_ _Pre_defensive_ const HID_DEVICE device, _In_ _Pre_defensive_ const DWORD getReportTimeoutInMilliSeconds, _In_ _Pre_defensive_ const DWORD setReportTimeoutInMilliSeconds);
770 
785 _Success_(HID_DEVICE_SUCCESS == return)
787 HidDevice_Close(_In_ _Pre_defensive_ const HID_DEVICE device);
788 
789 #ifdef __cplusplus
790 }
791 #endif // __cplusplus
792 
794 
795 #endif // HOST_LIB_SLABHIDDEVICE_INCLUDE_SLABHIDDEVICE_H_INCLUDED_MJWYLEYUPA
#define HID_DEVICE_SYSTEM_CODE
Indicates that a system error occurred. Call Windows GetLastError() to retrieve the system error code...
Definition: SLABHIDDevice.h:117
SLAB_HID_DEVICE_STATUS HidDevice_SetFeatureReport_Control(const HID_DEVICE device, BYTE *ReportBuffer, const DWORD ReportBufferLengthInBytes)
This function sends an HID feature report from the host to the device over the control endpoint...
WORD HidDevice_GetFeatureReportBufferLength(const HID_DEVICE device)
Returns the maximum feature report size, including the report ID.
SLAB_HID_DEVICE_STATUS HidDevice_SetOutputReport_Interrupt(const HID_DEVICE device, BYTE *ReportBuffer, const DWORD ReportBufferLengthInBytes)
This function sends an HID output report from the host to the device over the interrupt endpoint...
SLAB_HID_DEVICE_STATUS HidDevice_GetInputReport_Control(const HID_DEVICE device, BYTE *ReportBuffer, const DWORD ReportBufferLengthInBytes)
Receives an HID input report from the device to the host over the control endpoint.
#define SLAB_HID_DEVICE_API
SLAB_HID_DEVICE_API definition.
Definition: SLABHIDDevice.h:77
BOOL HidDevice_FlushBuffers(const HID_DEVICE device)
Deletes all pending input reports in the HID driver queue and the HID library.
#define HID_DEVICE_UNSUPPORTED_FUNCTION
The function is only supported on certain (newer?) Windows versions.
Definition: SLABHIDDevice.h:121
SLAB_HID_DEVICE_STATUS HidDevice_Open(HID_DEVICE *device, const DWORD dwDeviceIndex, const WORD Vid, const WORD Pid, const DWORD numInputBuffers)
tbd
#define HID_DEVICE_NOT_OPENED
Indicates that the device must be opened prior to calling the function.
Definition: SLABHIDDevice.h:110
SLAB_HID_DEVICE_STATUS HidDevice_GetHidAttributes(const DWORD dwDeviceIndex, const WORD Vid, const WORD Pid, WORD *pDeviceVid, WORD *pDevicePid, WORD *pDeviceReleaseNumber)
Reads and returns the Vendor ID, Product ID and device Release Number.
DWORD HidDevice_GetNumHidDevices(const WORD Vid, const WORD Pid)
Determines the number of devices connected to the system with matching VID/PID.
void HidDevice_GetHidGuid(void *pHIDGuid)
Return the GUID for HIDClass devices ("return the HID GUID")
SLAB_HID_DEVICE_STATUS HidDevice_SetOutputReport_Control(const HID_DEVICE device, BYTE *ReportBuffer, const DWORD ReportBufferLengthInBytes)
Sends an HID output report from the host to the device over the control endpoint. ...
#define HID_DEVICE_ALREADY_OPENED
Indicates that the device is already opened and cannot be re-opened.
Definition: SLABHIDDevice.h:111
void HidDevice_GetTimeouts(const HID_DEVICE device, DWORD *pGetReportTimeoutInMilliSeconds, DWORD *pSetReportTimeoutInMilliSeconds)
Returns the input and output report timeouts over the interrupt endpoint.
#define WINAPI
WINAPI definition.
Definition: SLABHIDDevice.h:78
BOOL HidDevice_CancelIo(const HID_DEVICE device)
Cancels all pending input and output operations issued by the calling thread.
#define HID_DEVICE_TRANSFER_TIMEOUT
Indicates that a get or set report function returned due to a timeout. HidDevice_GetInputReport_Inter...
Definition: SLABHIDDevice.h:112
SLAB_HID_DEVICE_STATUS HidDevice_GetHidLibraryVersion(BYTE *pMajor, BYTE *pMinor, BOOL *pbIsReleaseBuild)
tbd
WORD HidDevice_GetOutputReportBufferLength(const HID_DEVICE device)
Returns the maximum output report size including the report ID.
SLAB_HID_DEVICE_STATUS HidDevice_GetAttributes(const HID_DEVICE device, WORD *pDeviceVid, WORD *pDevicePid, WORD *pDeviceReleaseNumber)
Reads and returns the Vendor ID, Product ID and device Release Number.
SLAB_HID_DEVICE_STATUS HidDevice_GetInputReport_Interrupt(const HID_DEVICE device, BYTE *ReportBuffer, const DWORD ReportBufferLengthInBytes, const DWORD numReports, DWORD *bytesReturned)
This function receives an HID input report from the host to the device over the interrupt endpoint...
SLAB_HID_DEVICE_STATUS HidDevice_GetIndexedString(const HID_DEVICE device, const DWORD stringIndex, char *deviceString, const DWORD deviceStringLengthInBytes)
Gets an indexed string from the device.
#define HID_DEVICE_NOT_FOUND
Indicates that the specified device index was invalid or the device does not exist or is inaccessible...
Definition: SLABHIDDevice.h:109
#define HID_DEVICE_UNKNOWN_ERROR
This is the default return code value. This value should never be returned.
Definition: SLABHIDDevice.h:119
SLAB_HID_DEVICE_STATUS HidDevice_GetString(const HID_DEVICE device, const BYTE WhichHidStringToReturn, char *deviceString, const DWORD deviceStringLengthInBytes)
Gets a "Product string".
unsigned char BYTE
Byte definition.
Definition: silabs_defs.h:41
an otherwise unclassified error occurred
Definition: silabs_defs.h:280
SLAB_HID_DEVICE_STATUS HidDevice_GetHidIndexedString(const DWORD dwDeviceIndex, const WORD Vid, const WORD Pid, const DWORD stringIndex, char *deviceString, const DWORD deviceStringLengthInBytes)
Gets an indexed string from the device.
#define HID_DEVICE_SUCCESS
SILABS_STATUS no error
Definition: SLABHIDDevice.h:108
WORD HidDevice_GetInputReportBufferLength(const HID_DEVICE device)
Returns the maximum input report size including the report ID.
BOOL HidDevice_IsOpened(const HID_DEVICE device)
This function returns the device opened state.
#define MAX_USB_DEVICES
Max number of USB Devices allowed.
Definition: SLABHIDDevice.h:127
BYTE SLAB_HID_DEVICE_STATUS
SLAB HID Device Status Codes.
Definition: SLABHIDDevice.h:106
#define HID_DEVICE_HANDLE_ERROR
HID CreateFile() handle is invalid.
Definition: SLABHIDDevice.h:115
void HidDevice_SetTimeouts(const HID_DEVICE device, const DWORD getReportTimeoutInMilliSeconds, const DWORD setReportTimeoutInMilliSeconds)
Sets the input and output report timeouts over the interrupt endpoint.
void * HID_DEVICE
an opaque handle object
Definition: SLABHIDDevice.h:164
#define HID_DEVICE_CANNOT_GET_HID_INFO
Cannot retrieve device path or hidStringType is invalid.
Definition: SLABHIDDevice.h:114
SLAB_HID_DEVICE_STATUS HidDevice_GetHidString(const DWORD dwDeviceIndex, const WORD Vid, const WORD Pid, const BYTE WhichHidStringToReturn, char *deviceString, const DWORD deviceStringLengthInBytes)
Gets a "Product string".
#define HID_DEVICE_INVALID_BUFFER_SIZE
Specified buffer is not large enough to return requested data.
Definition: SLABHIDDevice.h:116
#define HID_DEVICE_TRANSFER_FAILED
The host failed to communicate with the device or function parameters are incorrect.
Definition: SLABHIDDevice.h:113
SLAB_HID_DEVICE_STATUS HidDevice_Close(const HID_DEVICE device)
Closes an open handle to the device.
HANDLE HidDevice_GetHandle(const HID_DEVICE device)
This function returns the HID handle for the currently-opened device.
SLAB_HID_DEVICE_STATUS HidDevice_GetInputReport_Interrupt_WithTimeout(const HID_DEVICE device, BYTE *ReportBuffer, const DWORD ReportBufferLengthInBytes, const DWORD numReports, DWORD *bytesReturned, const DWORD TimeoutMSec)
This function receives an HID input report from the host to the device over the interrupt endpoint...
SLAB_HID_DEVICE_STATUS HidDevice_GetFeatureReport_Control(const HID_DEVICE device, BYTE *ReportBuffer, const DWORD ReportBufferLengthInBytes)
This function receives an HID feature report from the host to the device over the control endpoint...
DWORD HidDevice_GetMaxReportRequest(const HID_DEVICE device)
Returns the maximum number of input reports that can be queued in the HID driver. ...