Silicon Labs Host Libraries
SLABCP2112.h
1 // SLABCP2112.h
3 // For SLABHIDtoSMBus.dll
4 // and Silicon Labs CP2112 HID to SMBus
6 #ifndef HOST_LIB_SLABHIDSMBUS_INCLUDE_SLABCP2112_H_INCLUDED_QU4N7WC20W
7 #define HOST_LIB_SLABHIDSMBUS_INCLUDE_SLABCP2112_H_INCLUDED_QU4N7WC20W
8 
13 // Includes
15 
16 #include "Types.h"
17 #include "silabs_defs.h"
18 #include "silabs_sal.h"
19 
21 // Tool-chain-dependent hacks
23 #ifdef _WIN32
24 // The following ifdef block is the standard way of creating macros which make exporting
25 // from a DLL simpler. All files within this DLL are compiled with the HID_TO_SMBUS_EXPORTS
26 // symbol defined on the command line. this symbol should not be defined on any project
27 // that uses this DLL. This way any other project whose source files include this file see
28 // HID_TO_SMBUS_API functions as being imported from a DLL, whereas this DLL sees symbols
29 // defined with this macro as being exported.
30 #if defined(HID_TO_SMBUS_EXPORTS)
31 #define HID_TO_SMBUS_API
32 #else
33 #define HID_TO_SMBUS_API __declspec(dllimport)
34 #pragma comment(lib, "SLABHIDtoSMBus.lib")
35 #endif // defined(HID_TO_SMBUS_EXPORTS)
36 #else // !_WIN32
37 #define HID_TO_SMBUS_API
38 #define WINAPI
39 #endif // !_WIN32
40 
41 
43 // Return Code Definitions
45 
46 // HID_SMBUS_STATUS
47 #if defined(NOT_YET)
48 typedef enum _HID_SMBUS_STATUS {
53  , HID_SMBUS_INVALID_HANDLE = 0x02
57 
59 
60  , HID_SMBUS_READ_ERROR = 0x10
61  , HID_SMBUS_WRITE_ERROR = 0x11
67 
69 } HID_SMBUS_STATUS, *PHID_SMBUS_STATUS;
72 #else // defined(NOT_YET)
73 typedef int HID_SMBUS_STATUS;
76 
77 // HID_SMBUS_STATUS Return Codes
80 #define HID_SMBUS_SUCCESS SILABS_STATUS_SUCCESS
81 #define HID_SMBUS_DEVICE_NOT_FOUND 0x01
82 #define HID_SMBUS_INVALID_HANDLE 0x02
83 #define HID_SMBUS_INVALID_DEVICE_OBJECT 0x03
84 #define HID_SMBUS_INVALID_PARAMETER 0x04
85 #define HID_SMBUS_INVALID_REQUEST_LENGTH 0x05
86 
87 #define HID_SMBUS_DEVICE_ALREADY_OPENED SILABS_STATUS_DEVICE_ALREADY_OPENED
88 
89 #define HID_SMBUS_READ_ERROR 0x10
90 #define HID_SMBUS_WRITE_ERROR 0x11
91 #define HID_SMBUS_READ_TIMED_OUT 0x12
92 #define HID_SMBUS_WRITE_TIMED_OUT 0x13
93 #define HID_SMBUS_DEVICE_IO_FAILED 0x14
94 #define HID_SMBUS_DEVICE_ACCESS_ERROR 0x15
95 #define HID_SMBUS_DEVICE_NOT_SUPPORTED 0x16
96 
97 #define HID_SMBUS_UNKNOWN_ERROR SILABS_STATUS_UNKNOWN_ERROR
98 #endif // defined(NOT_YET)
100 typedef BYTE HID_SMBUS_S0;
103 
106 #define HID_SMBUS_S0_IDLE 0x00
107 #define HID_SMBUS_S0_BUSY 0x01
108 #define HID_SMBUS_S0_COMPLETE 0x02
109 #define HID_SMBUS_S0_ERROR 0x03
110 
112 typedef BYTE HID_SMBUS_S1;
115 
116 // HID_SMBUS_TRANSFER_S0 = HID_SMBUS_S0_BUSY
119 #define HID_SMBUS_S1_BUSY_ADDRESS_ACKED 0x00
120 #define HID_SMBUS_S1_BUSY_ADDRESS_NACKED 0x01
121 #define HID_SMBUS_S1_BUSY_READING 0x02
122 #define HID_SMBUS_S1_BUSY_WRITING 0x03
123 
125 // HID_SMBUS_TRANSFER_S0 = HID_SMBUS_S0_ERROR
128 #define HID_SMBUS_S1_ERROR_TIMEOUT_NACK 0x00
129 #define HID_SMBUS_S1_ERROR_TIMEOUT_BUS_NOT_FREE 0x01
130 #define HID_SMBUS_S1_ERROR_ARB_LOST 0x02
131 #define HID_SMBUS_S1_ERROR_READ_INCOMPLETE 0x03
132 #define HID_SMBUS_S1_ERROR_WRITE_INCOMPLETE 0x04
133 #define HID_SMBUS_S1_ERROR_SUCCESS_AFTER_RETRY 0x05
134 
136 // String Definitions
142 typedef enum _HID_SMBUS_GETSTRING {
152 _Check_return_
153 _Success_(return == TRUE)
154 __inline static bool IsValidHID_SMBUS_GETSTRING(_In_ const HID_SMBUS_GETSTRING _s) { return (HID_SMBUS_GET_VID_STR == _s) || (HID_SMBUS_GET_PID_STR == _s) || (HID_SMBUS_GET_PATH_STR == _s) || (HID_SMBUS_GET_SERIAL_STR == _s) || (HID_SMBUS_GET_MANUFACTURER_STR == _s) || (HID_SMBUS_GET_PRODUCT_STR == _s); }
155 
156 // String Lengths
157 #define HID_SMBUS_DEVICE_STRLEN 260
158 
162 
164 // SMBUS Definitions
166 
167 // SMbus Configuration Limits
170 #define HID_SMBUS_MIN_BIT_RATE 1
171 #define HID_SMBUS_MIN_TIMEOUT 0
172 #define HID_SMBUS_MAX_TIMEOUT 1000
173 #define HID_SMBUS_MAX_RETRIES 1000
174 #define HID_SMBUS_MIN_ADDRESS 0x02
175 #define HID_SMBUS_MAX_ADDRESS 0xFE
176 
178 // Read/Write Limits
181 #define HID_SMBUS_MIN_READ_REQUEST_SIZE 1
182 #define HID_SMBUS_MAX_READ_REQUEST_SIZE 512
183 #define HID_SMBUS_MIN_TARGET_ADDRESS_SIZE 1
184 #define HID_SMBUS_MAX_TARGET_ADDRESS_SIZE 16
185 #define HID_SMBUS_MAX_READ_RESPONSE_SIZE 61
186 #define HID_SMBUS_MIN_WRITE_REQUEST_SIZE 1
187 #define HID_SMBUS_MAX_WRITE_REQUEST_SIZE 61
188 
190 // GPIO Definitions
193 
194 // GPIO Pin Direction Bit Value
197 #define HID_SMBUS_DIRECTION_INPUT 0
198 #define HID_SMBUS_DIRECTION_OUTPUT 1
199 
201 // GPIO Pin Mode Bit Value
204 #define HID_SMBUS_MODE_OPEN_DRAIN 0
205 #define HID_SMBUS_MODE_PUSH_PULL 1
206 
208 // GPIO Function Bitmask
211 #define HID_SMBUS_MASK_FUNCTION_GPIO_7_CLK 0x01
212 #define HID_SMBUS_MASK_FUNCTION_GPIO_0_TXT 0x02
213 #define HID_SMBUS_MASK_FUNCTION_GPIO_1_RXT 0x04
214 
216 // GPIO Function Bit Value
219 #define HID_SMBUS_GPIO_FUNCTION 0
220 #define HID_SMBUS_SPECIAL_FUNCTION 1
221 
223 // GPIO Pin Bitmask
226 #define HID_SMBUS_MASK_GPIO_0 0x01
227 #define HID_SMBUS_MASK_GPIO_1 0x02
228 #define HID_SMBUS_MASK_GPIO_2 0x04
229 #define HID_SMBUS_MASK_GPIO_3 0x08
230 #define HID_SMBUS_MASK_GPIO_4 0x10
231 #define HID_SMBUS_MASK_GPIO_5 0x20
232 #define HID_SMBUS_MASK_GPIO_6 0x40
233 #define HID_SMBUS_MASK_GPIO_7 0x80
234 
236 // Part Number Definitions
239 
242 #define HID_SMBUS_PART_CP2112 CP210x_PARTNUM_CP2112
243 
244 // User Customization Definitions
248 //@brief User-Customizable Field Lock Bitmasks
250 typedef enum _HID_SMBUS_LOCKBITS {
251  HID_SMBUS_LOCK_VID = ((BYTE)(0xFF & 0x01))
252  , HID_SMBUS_LOCK_PID = ((BYTE)(0xFF & 0x02))
253  , HID_SMBUS_LOCK_POWER = ((BYTE)(0xFF & 0x04))
254  , HID_SMBUS_LOCK_POWER_MODE = ((BYTE)(0xFF & 0x08))
255  , HID_SMBUS_LOCK_RELEASE_VERSION = ((BYTE)(0xFF & 0x10))
256  , HID_SMBUS_LOCK_MFG_STR = ((BYTE)(0xFF & 0x20))
257  , HID_SMBUS_LOCK_PRODUCT_STR = ((BYTE)(0xFF & 0x40))
258  , HID_SMBUS_LOCK_SERIAL_STR = ((BYTE)(0xFF & 0x80))
262 _Check_return_
263 _Success_(return == TRUE)
264 __inline static bool IsValidHID_SMBUS_HID_SMBUS_LOCKBITS(_In_ const HID_SMBUS_LOCKBITS _s)
265 {
266  return (HID_SMBUS_LOCK_VID == _s) || (HID_SMBUS_LOCK_PID == _s)
267  || (HID_SMBUS_LOCK_POWER == _s) || (HID_SMBUS_LOCK_POWER_MODE == _s)
270 }
271 
272 // Field Lock Bit Values
275 #define HID_SMBUS_LOCK_UNLOCKED 1
276 #define HID_SMBUS_LOCK_LOCKED 0
277 
279 // Power Max Value (500 mA)
280 #define HID_SMBUS_BUS_POWER_MAX 0xFA
281 
282 // Power Modes
285 #define HID_SMBUS_BUS_POWER 0x00
286 #define HID_SMBUS_SELF_POWER_VREG_DIS 0x01
287 #define HID_SMBUS_SELF_POWER_VREG_EN 0x02
288 
290 // USB Config Bitmasks
293 #define HID_SMBUS_SET_VID 0x01
294 #define HID_SMBUS_SET_PID 0x02
295 #define HID_SMBUS_SET_POWER 0x04
296 #define HID_SMBUS_SET_POWER_MODE 0x08
297 #define HID_SMBUS_SET_RELEASE_VERSION 0x10
298 
300 // USB Config Bit Values
303 #define HID_SMBUS_SET_IGNORE 0
304 #define HID_SMBUS_SET_PROGRAM 1
305 
307 // String Lengths
310 #define HID_SMBUS_CP2112_MFG_STRLEN 30
311 #define HID_SMBUS_CP2112_PRODUCT_STRLEN 30
312 #define HID_SMBUS_CP2112_SERIAL_STRLEN 30
313 typedef char HID_SMBUS_CP2112_MFG_STR[HID_SMBUS_CP2112_MFG_STRLEN];
323 
325 // Typedefs
329 typedef void* HID_SMBUS_DEVICE;
330 
332 // Exported Library Functions
334 
335 #ifdef __cplusplus
336 extern "C" {
337 #endif // __cplusplus
338 
339 // HidSmbus_GetNumDevices
352 HidSmbus_GetNumDevices(_Out_writes_bytes_(sizeof(DWORD)) _Pre_defensive_ DWORD* lpdwNumDevices, _In_ _Pre_defensive_ const WORD vid, _In_ _Pre_defensive_ const WORD pid);
353 
354 // HidSmbus_GetString
380 _Check_return_
382 _Success_(HID_SMBUS_SUCCESS)
384 HidSmbus_GetString(_In_ _Pre_defensive_ const DWORD deviceNum, _In_ _Pre_defensive_ const WORD vid, _In_ _Pre_defensive_ const WORD pid, _Out_ _Pre_defensive_ char* deviceString, _In_ _Pre_defensive_ const HID_SMBUS_GETSTRING options);
385 
386 // HidSmbus_GetOpenedString
404 _Check_return_
406 _Success_(HID_SMBUS_SUCCESS)
408 HidSmbus_GetOpenedString(_In_ _Pre_defensive_ const HID_SMBUS_DEVICE device, char* deviceString, _In_ _Pre_defensive_ const HID_SMBUS_GETSTRING options);
409 
410 // HidSmbus_GetIndexedString
431 _Check_return_
433 _Success_(HID_SMBUS_SUCCESS)
435 HidSmbus_GetIndexedString(_In_ _Pre_defensive_ const DWORD deviceNum, _In_ _Pre_defensive_ const WORD vid, _In_ _Pre_defensive_ const WORD pid, _In_ _Pre_defensive_ const DWORD stringIndex, char* deviceString);
436 
437 // HidSmbus_GetOpenedIndexedString
452 _Check_return_
454 _Success_(HID_SMBUS_SUCCESS)
456 HidSmbus_GetOpenedIndexedString(_In_ _Pre_defensive_ const HID_SMBUS_DEVICE device, _In_ _Pre_defensive_ const DWORD stringIndex, char* deviceString);
457 
458 // HidSmbus_GetAttributes
478 _Check_return_
480 _Success_(HID_SMBUS_SUCCESS)
482 HidSmbus_GetAttributes(_In_ _Pre_defensive_ const DWORD deviceNum, _In_ _Pre_defensive_ const WORD vid, _In_ _Pre_defensive_ const WORD pid, _Out_writes_bytes_(sizeof(WORD)) _Pre_defensive_ WORD* deviceVid, _Out_writes_bytes_(sizeof(WORD)) _Pre_defensive_ WORD* devicePid, _Out_writes_bytes_(sizeof(WORD)) _Pre_defensive_ WORD* deviceReleaseNumber);
483 
484 // HidSmbus_GetOpenedAttributes
499 _Check_return_
501 _Success_(HID_SMBUS_SUCCESS)
503 HidSmbus_GetOpenedAttributes(_In_ _Pre_defensive_ const HID_SMBUS_DEVICE device, _Out_writes_bytes_(sizeof(WORD)) _Pre_defensive_ WORD* deviceVid, _Out_writes_bytes_(sizeof(WORD)) _Pre_defensive_ WORD* devicePid, _Out_writes_bytes_(sizeof(WORD)) _Pre_defensive_ WORD* deviceReleaseNumber);
504 
505 // HidSmbus_Open
527 _Check_return_
529 _Success_(HID_SMBUS_SUCCESS)
531 HidSmbus_Open(_Out_writes_bytes_(sizeof(HID_SMBUS_DEVICE*)) _Pre_defensive_ HID_SMBUS_DEVICE* pdevice, _In_ _Pre_defensive_ const DWORD deviceNum, _In_ _Pre_defensive_ const WORD vid, _In_ _Pre_defensive_ const WORD pid);
532 
533 // HidSmbus_Close
545 _Check_return_
547 _Success_(HID_SMBUS_SUCCESS)
549 HidSmbus_Close(_In_ _Pre_defensive_ const HID_SMBUS_DEVICE device);
550 
551 // HidSmbus_IsOpened
561 _Check_return_
563 _Success_(HID_SMBUS_SUCCESS)
565 HidSmbus_IsOpened(_In_ _Pre_defensive_ const HID_SMBUS_DEVICE device, _Out_writes_bytes_(sizeof(BOOL)) _Pre_defensive_ BOOL* bIsOpened);
566 
567 // HidSmbus_ReadRequest
588 _Check_return_
590 _Success_(HID_SMBUS_SUCCESS)
592 HidSmbus_ReadRequest(_In_ _Pre_defensive_ const HID_SMBUS_DEVICE device, _In_range_(0x02,0xFE) _Pre_defensive_ const BYTE slaveAddress, _In_range_(1, 512) _Pre_defensive_ const WORD numBytesToRead);
593 
594 // HidSmbus_AddressReadRequest
619 _Check_return_
621 _Success_(HID_SMBUS_SUCCESS)
623 HidSmbus_AddressReadRequest(_In_ _Pre_defensive_ const HID_SMBUS_DEVICE device, _In_range_(0x02, 0xFE) _Pre_defensive_ const BYTE slaveAddress, _In_range_(1, 512) _Pre_defensive_ const WORD numBytesToRead, _In_range_(1, 16) _Pre_defensive_ const BYTE targetAddressSize, BYTE targetAddress[16]);
624 
625 // HidSmbus_ForceReadResponse
645 _Check_return_
647 _Success_(HID_SMBUS_SUCCESS)
649 HidSmbus_ForceReadResponse(_In_ _Pre_defensive_ const HID_SMBUS_DEVICE device, _In_range_(1, 512) _Pre_defensive_ const WORD numBytesToRead);
650 
651 // HidSmbus_GetReadResponse
673 _Check_return_
675 _Success_(HID_SMBUS_SUCCESS)
678  _In_ _Pre_defensive_ const HID_SMBUS_DEVICE device,
679  _Out_writes_bytes_(sizeof(HID_SMBUS_S0)) _Pre_defensive_ HID_SMBUS_S0* status,
680  _Out_writes_bytes_(sizeof(bufferSize)) _Pre_defensive_ BYTE* buffer,
681  _In_ _Pre_defensive_ const BYTE bufferSize,
682  _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* numBytesRead
683 );
684 
685 // HidSmbus_WriteRequest
707 _Check_return_
709 _Success_(HID_SMBUS_SUCCESS)
712  _In_ _Pre_defensive_ const HID_SMBUS_DEVICE device,
713  _In_range_(0x02, 0xFE) _Pre_defensive_ const BYTE slaveAddress,
714  _In_reads_bytes_(numBytesToWrite) _Pre_defensive_ BYTE* buffer,
715  _In_range_(1, 61) _Pre_defensive_ const BYTE numBytesToWrite
716 );
717 
718 // HidSmbus_TransferStatusRequest
730 _Check_return_
732 _Success_(HID_SMBUS_SUCCESS)
734 HidSmbus_TransferStatusRequest(_In_ _Pre_defensive_ const HID_SMBUS_DEVICE device);
735 
736 // HidSmbus_GetTransferStatusResponse
758 _Check_return_
760 _Success_(HID_SMBUS_SUCCESS)
763  _In_ _Pre_defensive_ const HID_SMBUS_DEVICE device,
764  _Out_writes_bytes_(sizeof(HID_SMBUS_S0)) _Pre_defensive_ HID_SMBUS_S0* status,
765  _Out_writes_bytes_(sizeof(HID_SMBUS_S1)) _Pre_defensive_ HID_SMBUS_S1* detailedStatus,
766  _Out_writes_bytes_(sizeof(WORD)) _Pre_defensive_ WORD* numRetries,
767  _Out_writes_bytes_(sizeof(WORD)) _Pre_defensive_ WORD* bytesRead
768 );
769 
770 // HidSmbus_CancelTransfer
781 _Check_return_
783 _Success_(HID_SMBUS_SUCCESS)
785 HidSmbus_CancelTransfer(_In_ _Pre_defensive_ const HID_SMBUS_DEVICE device);
786 
787 // HidSmbus_CancelIo
796 _Check_return_
798 _Success_(HID_SMBUS_SUCCESS)
800 HidSmbus_CancelIo(_In_ _Pre_defensive_ const HID_SMBUS_DEVICE device);
801 
802 // HidSmbus_SetTimeouts
822 _Check_return_
824 _Success_(HID_SMBUS_SUCCESS)
826 HidSmbus_SetTimeouts(_In_ _Pre_defensive_ const HID_SMBUS_DEVICE device, _In_ _Pre_defensive_ const DWORD responseTimeout);
827 
828 // HidSmbus_GetTimeouts
843 _Check_return_
845 _Success_(HID_SMBUS_SUCCESS)
847 HidSmbus_GetTimeouts(_In_ _Pre_defensive_ const HID_SMBUS_DEVICE device, _Out_writes_bytes_(sizeof(DWORD)) _Pre_defensive_ DWORD* responseTimeout);
848 
849 // HidSmbus_SetSmbusConfig
883 _Check_return_
885 _Success_(HID_SMBUS_SUCCESS)
888  _In_ _Pre_defensive_ const HID_SMBUS_DEVICE device,
889  _In_ _Pre_defensive_ const DWORD bitRate,
890  _In_range_(HID_SMBUS_MIN_ADDRESS, HID_SMBUS_MAX_ADDRESS) _Pre_defensive_ const BYTE address,
891  _In_ _Pre_defensive_ const BOOL autoReadRespond,
892  _In_range_(HID_SMBUS_MIN_TIMEOUT, HID_SMBUS_MAX_TIMEOUT) _Pre_defensive_ const WORD writeTimeout,
893  _In_range_(HID_SMBUS_MIN_TIMEOUT, HID_SMBUS_MAX_TIMEOUT) _Pre_defensive_ const WORD readTimeout,
894  _In_ _Pre_defensive_ const BOOL sclLowTimeout,
895  _In_range_(0, HID_SMBUS_MAX_RETRIES) _Pre_defensive_ const WORD transferRetries
896 );
897 
898 // HidSmbus_GetSmbusConfig
932 _Check_return_
934 _Success_(HID_SMBUS_SUCCESS)
937  _In_ _Pre_defensive_ const HID_SMBUS_DEVICE device,
938  _Out_writes_bytes_(sizeof(DWORD)) _Pre_defensive_ DWORD* bitRate,
939  _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* address,
940  _Out_writes_bytes_(sizeof(BOOL)) _Pre_defensive_ BOOL* autoReadRespond,
941  _Out_writes_bytes_(sizeof(WORD)) _Pre_defensive_ WORD* writeTimeout,
942  _Out_writes_bytes_(sizeof(WORD)) _Pre_defensive_ WORD* readTimeout,
943  _Out_writes_bytes_(sizeof(BOOL)) _Pre_defensive_ BOOL* sclLowtimeout,
944  _Out_writes_bytes_(sizeof(WORD)) _Pre_defensive_ WORD* transferRetries
945 );
946 
947 // HidSmbus_Reset
961 _Check_return_
963 _Success_(HID_SMBUS_SUCCESS)
965 HidSmbus_Reset(_In_ _Pre_defensive_ const HID_SMBUS_DEVICE device);
966 
967 // HidSmbus_SetGpioConfig
983 _Check_return_
985 _Success_(HID_SMBUS_SUCCESS)
988  _In_ _Pre_defensive_ const HID_SMBUS_DEVICE device,
989  _In_ _Pre_defensive_ const BYTE direction,
990  _In_ _Pre_defensive_ const BYTE mode,
991  _In_ _Pre_defensive_ const BYTE function,
992  _In_ _Pre_defensive_ const BYTE clkDiv
993 );
994 
995 // HidSmbus_GetGpioConfig
1011 _Check_return_
1013 _Success_(HID_SMBUS_SUCCESS)
1016  _In_ _Pre_defensive_ const HID_SMBUS_DEVICE device,
1017  _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* direction,
1018  _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* mode,
1019  _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* function,
1020  _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* clkDiv
1021 );
1022 
1023 // HidSmbus_ReadLatch
1038 _Check_return_
1040 _Success_(HID_SMBUS_SUCCESS)
1042 HidSmbus_ReadLatch(_In_ _Pre_defensive_ const HID_SMBUS_DEVICE device, _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* latchValue);
1043 
1044 // HidSmbus_WriteLatch
1058 _Check_return_
1060 _Success_(HID_SMBUS_SUCCESS)
1063  _In_ _Pre_defensive_ const HID_SMBUS_DEVICE device,
1064  _In_ _Pre_defensive_ const BYTE latchValue,
1065  _In_ _Pre_defensive_ const BYTE latchMask
1066 );
1067 
1068 // HidSmbus_GetPartNumber
1079 _Check_return_
1081 _Success_(HID_SMBUS_SUCCESS)
1084  _In_ _Pre_defensive_ const HID_SMBUS_DEVICE device,
1085  _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* partNumber,
1086  _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* version
1087 );
1088 
1089 // HidSmbus_GetLibraryVersion
1098 _Check_return_
1100 _Success_(HID_SMBUS_SUCCESS)
1102 HidSmbus_GetLibraryVersion(_Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* major, _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* minor, _Out_writes_bytes_(sizeof(BOOL)) _Pre_defensive_ BOOL* bIsRelease);
1103 
1104 // HidSmbus_GetHidLibraryVersion
1115 HidSmbus_GetHidLibraryVersion(_Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* major, _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* minor, _Out_writes_bytes_(sizeof(BOOL)) _Pre_defensive_ BOOL* bIsRelease);
1116 
1117 // HidSmbus_GetHidGuid
1131 HidSmbus_GetHidGuid(_Out_ void* pHIDGuid);
1132 // TODO: Enstone: Implement HidSmbus_GetHidGuidSafe(_Out_ GUID *pHIDGuid);
1133 
1135 // Exported Library Functions - Device Customization
1137 
1138 // HidSmbus_SetLock
1156 _Check_return_
1158 _Success_(HID_SMBUS_SUCCESS)
1160 HidSmbus_SetLock(_In_ _Pre_defensive_ const HID_SMBUS_DEVICE device, _In_ _Pre_defensive_ const BYTE lock);
1161 
1162 // HidSmbus_GetLock
1173 _Check_return_
1175 _Success_(HID_SMBUS_SUCCESS)
1177 HidSmbus_GetLock(_In_ _Pre_defensive_ const HID_SMBUS_DEVICE device, _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* lock);
1178 
1179 // HidSmbus_SetUsbConfig
1199 _Check_return_
1201 _Success_(HID_SMBUS_SUCCESS)
1204  _In_ _Pre_defensive_ const HID_SMBUS_DEVICE device,
1205  _In_ _Pre_defensive_ const WORD vid,
1206  _In_ _Pre_defensive_ const WORD pid,
1207  _In_range_(0, HID_SMBUS_BUS_POWER_MAX) _Pre_defensive_ const BYTE power,
1208  _In_ _Pre_defensive_ const BYTE powerMode,
1209  _In_ _Pre_defensive_ const WORD releaseVersion,
1210  _In_ _Pre_defensive_ const BYTE mask
1211 );
1212 
1213 // HidSmbus_GetUsbConfig
1229 _Check_return_
1231 _Success_(HID_SMBUS_SUCCESS)
1234  _In_ _Pre_defensive_ const HID_SMBUS_DEVICE device,
1235  _Out_writes_bytes_(sizeof(WORD)) _Pre_defensive_ WORD* vid,
1236  _Out_writes_bytes_(sizeof(WORD)) _Pre_defensive_ WORD* pid,
1237  _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* power,
1238  _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* powerMode,
1239  _Out_writes_bytes_(sizeof(WORD)) _Pre_defensive_ WORD* releaseVersion
1240 );
1241 
1242 // HidSmbus_SetManufacturingString
1255 _Check_return_
1257 _Success_(HID_SMBUS_SUCCESS)
1260  _In_ _Pre_defensive_ const HID_SMBUS_DEVICE device,
1261  _In_reads_bytes_(strlen) _Pre_defensive_ char* manufacturingString,
1262  _In_range_(0, HID_SMBUS_CP2112_MFG_STRLEN) _Pre_defensive_ const BYTE strlen
1263 );
1264 
1265 // HidSmbus_GetManufacturingString
1278 _Check_return_
1280 _Success_(HID_SMBUS_SUCCESS)
1283  _In_ _Pre_defensive_ const HID_SMBUS_DEVICE device,
1284  char* manufacturingString,
1285  _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* strlen
1286 );
1287 
1288 // HidSmbus_SetProductString
1301 _Check_return_
1303 _Success_(HID_SMBUS_SUCCESS)
1306  _In_ _Pre_defensive_ const HID_SMBUS_DEVICE device,
1307  _In_reads_bytes_(strlen) _Pre_defensive_ char* productString,
1308  _In_range_(0, HID_SMBUS_CP2112_PRODUCT_STRLEN) _Pre_defensive_ const BYTE strlen
1309 );
1310 
1311 // HidSmbus_GetProductString
1324 _Check_return_
1326 _Success_(HID_SMBUS_SUCCESS)
1329  _In_ _Pre_defensive_ const HID_SMBUS_DEVICE device,
1330  char* productString,
1331  _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* strlen
1332 );
1333 
1334 // HidSmbus_SetSerialString
1347 _Check_return_
1349 _Success_(HID_SMBUS_SUCCESS)
1352  _In_ _Pre_defensive_ const HID_SMBUS_DEVICE device,
1353  _In_reads_bytes_(strlen) _Pre_defensive_ char* serialString,
1354  _In_range_(0, HID_SMBUS_CP2112_SERIAL_STRLEN) _Pre_defensive_ const BYTE strlen
1355 );
1356 
1357 // HidSmbus_GetSerialString
1370 _Check_return_
1372 _Success_(HID_SMBUS_SUCCESS)
1375  _In_ _Pre_defensive_ const HID_SMBUS_DEVICE device,
1376  char* serialString,
1377  _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* strlen
1378 );
1379 
1380 #ifdef __cplusplus
1381 }
1382 #endif // __cplusplus
1383 
1385 
1386 #endif // HOST_LIB_SLABHIDSMBUS_INCLUDE_SLABCP2112_H_INCLUDED_QU4N7WC20W
Vendor ID string.
Definition: SLABCP2112.h:143
#define HID_SMBUS_DEVICE_NOT_SUPPORTED
the current device does not support the corresponding action
Definition: SLABCP2112.h:95
Product String.
Definition: SLABCP2112.h:257
#define HID_SMBUS_DEVICE_NOT_FOUND
the specified device was not found
Definition: SLABCP2112.h:81
#define HID_SMBUS_INVALID_HANDLE
an handle parameter was not valid
Definition: SLABCP2112.h:82
#define HID_SMBUS_BUS_POWER_MAX
maximum power of 500mA, represented as a milliamps/2, I.e. 250 IFF bus-powered
Definition: SLABCP2112.h:280
Serial Number string.
Definition: SLABCP2112.h:146
#define HID_SMBUS_DEVICE_IO_FAILED
host was unable to get or set a feature report.
Definition: SLABCP2112.h:93
#define HID_SMBUS_MIN_TIMEOUT
HID SMBus min timeout.
Definition: SLABCP2112.h:171
#define HID_SMBUS_DEVICE_ACCESS_ERROR
the device or device property could not be accessed.Either the device is not opened, already opened when trying to open, or an error occurred when trying to get HID information.
Definition: SLABCP2112.h:94
HID_SMBUS_STATUS HidSmbus_SetLock(const HID_SMBUS_DEVICE device, const BYTE lock)
permanently locks/disables device customization.
HID_SMBUS_STATUS HidSmbus_GetTransferStatusResponse(const HID_SMBUS_DEVICE device, HID_SMBUS_S0 *status, HID_SMBUS_S1 *detailedStatus, WORD *numRetries, WORD *bytesRead)
returns the status of the current read or write transfer.
Product string.
Definition: SLABCP2112.h:148
no error
Definition: silabs_defs.h:262
HID_SMBUS_STATUS HidSmbus_GetOpenedAttributes(const HID_SMBUS_DEVICE device, WORD *deviceVid, WORD *devicePid, WORD *deviceReleaseNumber)
This function returns the device vendor ID, product ID, and device release number for the opened devi...
HID_SMBUS_STATUS HidSmbus_ReadRequest(const HID_SMBUS_DEVICE device, const BYTE slaveAddress, const WORD numBytesToRead)
intiates a read transfer to the specified slave device address.
HID_SMBUS_STATUS HidSmbus_GetHidGuid(void *pHIDGuid)
Return the GUID for HIDClass devices ("return the HID GUID") (Windows only)
#define HID_SMBUS_SUCCESS
Success.
Definition: SLABCP2112.h:80
#define HID_SMBUS_CP2112_SERIAL_STRLEN
HID SMBus CP2112 serial string length.
Definition: SLABCP2112.h:312
#define HID_SMBUS_WRITE_ERROR
the write was not successful.
Definition: SLABCP2112.h:90
HID_SMBUS_STATUS HidSmbus_Open(HID_SMBUS_DEVICE *pdevice, const DWORD deviceNum, const WORD vid, const WORD pid)
Opens a device using a device number between 0 and HidSmbus_GetNumDevices() - 1, enables the UART...
HID_SMBUS_STATUS HidSmbus_WriteLatch(const HID_SMBUS_DEVICE device, const BYTE latchValue, const BYTE latchMask)
sets the current GPIO latch value for the specified bits.
HID_SMBUS_STATUS HidSmbus_WriteRequest(const HID_SMBUS_DEVICE device, const BYTE slaveAddress, BYTE *buffer, const BYTE numBytesToWrite)
writes the specified number of bytes from the supplied buffer to the specified slave device and retur...
HID_SMBUS_STATUS HidSmbus_GetLibraryVersion(BYTE *major, BYTE *minor, BOOL *bIsRelease)
Reads and returns the HID USB-to-SMBus Interface Library version.
HID_SMBUS_GETSTRING
Definition: SLABCP2112.h:142
#define HID_SMBUS_READ_ERROR
the read was not successful and did not time out.
Definition: SLABCP2112.h:89
#define HID_SMBUS_INVALID_REQUEST_LENGTH
the specified number of bytes to read or write is invalid.
Definition: SLABCP2112.h:85
int HID_SMBUS_STATUS
HID SMBus status.
Definition: SLABCP2112.h:75
#define HID_SMBUS_MAX_ADDRESS
HID SMBus max address.
Definition: SLABCP2112.h:175
HID_SMBUS_STATUS HidSmbus_SetTimeouts(const HID_SMBUS_DEVICE device, const DWORD responseTimeout)
Sets the response timeouts.
#define HID_SMBUS_INVALID_PARAMETER
a parameter was not valid
Definition: SLABCP2112.h:84
VID.
Definition: SLABCP2112.h:251
HID_SMBUS_STATUS HidSmbus_GetGpioConfig(const HID_SMBUS_DEVICE device, BYTE *direction, BYTE *mode, BYTE *function, BYTE *clkDiv)
returns the GPIO pin's directions and modes.
HID_SMBUS_STATUS HidSmbus_SetGpioConfig(const HID_SMBUS_DEVICE device, const BYTE direction, const BYTE mode, const BYTE function, const BYTE clkDiv)
configures the GPIO pin's directions and modes.
Serial String.
Definition: SLABCP2112.h:258
enum _HID_SMBUS_GETSTRING * PHID_SMBUS_GETSTRING
Product String Types pointer.
#define HID_SMBUS_READ_TIMED_OUT
a read failed to return the number of bytes requested before the read timeout elapsed.
Definition: SLABCP2112.h:91
Manufacturing String.
Definition: SLABCP2112.h:256
Product ID string.
Definition: SLABCP2112.h:144
char HID_SMBUS_CP2112_PRODUCT_STR[30]
HID_SMBUS_PRODUCT_STR.
Definition: SLABCP2112.h:319
HID_SMBUS_STATUS HidSmbus_GetReadResponse(const HID_SMBUS_DEVICE device, HID_SMBUS_S0 *status, BYTE *buffer, const BYTE bufferSize, BYTE *numBytesRead)
returns the read response to a read request. Read and write timeouts as well as transfer retries can ...
HID_SMBUS_STATUS HidSmbus_Close(const HID_SMBUS_DEVICE device)
Closes an opened device using the device object pointer provided by HidUart_Open().
#define HID_SMBUS_UNKNOWN_ERROR
This value should never be returned.
Definition: SLABCP2112.h:97
#define HID_SMBUS_DEVICE_ALREADY_OPENED
the specified device is already (exclusively) opened
Definition: SLABCP2112.h:87
HID_SMBUS_STATUS HidSmbus_SetSerialString(const HID_SMBUS_DEVICE device, char *serialString, const BYTE strlen)
allows one-time customization of the USB serial string.
HID_SMBUS_STATUS HidSmbus_GetTimeouts(const HID_SMBUS_DEVICE device, DWORD *responseTimeout)
returns the current response timeouts specified in milliseconds.
void * HID_SMBUS_DEVICE
HID_SMBUS_DEVICE.
Definition: SLABCP2112.h:329
char HID_SMBUS_CP2112_SERIAL_STR[30]
HID_SMBUS_SERIAL_STR.
Definition: SLABCP2112.h:322
unsigned char BYTE
Byte definition.
Definition: silabs_defs.h:41
char HID_SMBUS_DEVICE_STR[260]
HID_SMBUS_DEVICE_STR.
Definition: SLABCP2112.h:161
HID_SMBUS_STATUS HidSmbus_GetUsbConfig(const HID_SMBUS_DEVICE device, WORD *vid, WORD *pid, BYTE *power, BYTE *powerMode, WORD *releaseVersion)
retrieves USB configuration, which includes vendor ID, product ID, power, power mode, release version, and flush buffers settings.
HID_SMBUS_STATUS HidSmbus_GetString(const DWORD deviceNum, const WORD vid, const WORD pid, char *deviceString, const HID_SMBUS_GETSTRING options)
This function returns a null-terminated vendor ID string, product ID string, serial number string...
an otherwise unclassified error occurred
Definition: silabs_defs.h:280
Path string.
Definition: SLABCP2112.h:145
Manufacturer string.
Definition: SLABCP2112.h:147
Power.
Definition: SLABCP2112.h:253
#define HID_SMBUS_MAX_RETRIES
HID SMBus max retries.
Definition: SLABCP2112.h:173
HID_SMBUS_STATUS HidSmbus_SetManufacturingString(const HID_SMBUS_DEVICE device, char *manufacturingString, const BYTE strlen)
Allows one-time customization of the USB manufacturing string.
BYTE HID_SMBUS_S1
HID_SMBUS_TRANSFER_S1.
Definition: SLABCP2112.h:114
HID_SMBUS_STATUS HidSmbus_SetProductString(const HID_SMBUS_DEVICE device, char *productString, const BYTE strlen)
allows one-time customization of the USB product string.
HID_SMBUS_STATUS HidSmbus_GetPartNumber(const HID_SMBUS_DEVICE device, BYTE *partNumber, BYTE *version)
retrieves the part number and version of the CP2112 device.
HID_SMBUS_STATUS HidSmbus_GetAttributes(const DWORD deviceNum, const WORD vid, const WORD pid, WORD *deviceVid, WORD *devicePid, WORD *deviceReleaseNumber)
This function returns the device vendor ID, product ID, and device release number for the device spec...
HID_SMBUS_STATUS HidSmbus_CancelIo(const HID_SMBUS_DEVICE device)
This function cancels any pending HID reads and writes (Windows Only).
Power Mode.
Definition: SLABCP2112.h:254
HID_SMBUS_STATUS HidSmbus_ForceReadResponse(const HID_SMBUS_DEVICE device, const WORD numBytesToRead)
cause the device to send a read response to the host after a read transfer has been issued...
HID_SMBUS_LOCKBITS
Definition: SLABCP2112.h:250
HID_SMBUS_STATUS HidSmbus_GetSmbusConfig(const HID_SMBUS_DEVICE device, DWORD *bitRate, BYTE *address, BOOL *autoReadRespond, WORD *writeTimeout, WORD *readTimeout, BOOL *sclLowtimeout, WORD *transferRetries)
gets the SMBus bit rate, address, and transfer settings such as timeouts and retries.
#define HID_SMBUS_MAX_TIMEOUT
HID SMBus max timeout.
Definition: SLABCP2112.h:172
PID.
Definition: SLABCP2112.h:252
Release Version.
Definition: SLABCP2112.h:255
HID_SMBUS_STATUS HidSmbus_GetProductString(const HID_SMBUS_DEVICE device, char *productString, BYTE *strlen)
retrieves the USB product string.
#define HID_SMBUS_CP2112_MFG_STRLEN
HID SMBus CP2112 manufacturing string length.
Definition: SLABCP2112.h:310
enum _HID_SMBUS_LOCKBITS * PHID_SMBUS_LOCKBITS
User-Customizable Field Lock Bitmasks pointer.
HID_SMBUS_STATUS HidSmbus_GetNumDevices(DWORD *lpdwNumDevices, const WORD vid, const WORD pid)
Determines the number of devices connected to the system with matching VID/PID.
HID_SMBUS_STATUS HidSmbus_CancelTransfer(const HID_SMBUS_DEVICE device)
cancels the current read or write transfer.
#define HID_SMBUS_DEVICE_STRLEN
HID SMBus device string length.
Definition: SLABCP2112.h:157
HID_SMBUS_STATUS HidSmbus_ReadLatch(const HID_SMBUS_DEVICE device, BYTE *latchValue)
returns the current GPIO latch value.
#define HID_SMBUS_MIN_ADDRESS
HID SMBus min address.
Definition: SLABCP2112.h:174
HID_SMBUS_STATUS HidSmbus_AddressReadRequest(const HID_SMBUS_DEVICE device, const BYTE slaveAddress, const WORD numBytesToRead, const BYTE targetAddressSize, BYTE targetAddress[16])
intiates a read transfer to the specified slave device address and specifies the address to read from...
#define HID_SMBUS_WRITE_TIMED_OUT
a write failed to complete sending the number of bytes requested before the write timeout elapsed...
Definition: SLABCP2112.h:92
HID_SMBUS_STATUS HidSmbus_TransferStatusRequest(const HID_SMBUS_DEVICE device)
requests the status of the current read or write transfer.
HID_SMBUS_STATUS HidSmbus_Reset(const HID_SMBUS_DEVICE device)
initiates a full device reset. All configuration settings will be reset to their default values after...
#define HID_SMBUS_INVALID_DEVICE_OBJECT
the device object pointer does not match the address of a valid HID - to - UART device ...
Definition: SLABCP2112.h:83
HID_SMBUS_STATUS HidSmbus_GetIndexedString(const DWORD deviceNum, const WORD vid, const WORD pid, const DWORD stringIndex, char *deviceString)
This function returns a null-terminated USB string descriptor for the device specified by an index pa...
HID_SMBUS_STATUS HidSmbus_GetOpenedIndexedString(const HID_SMBUS_DEVICE device, const DWORD stringIndex, char *deviceString)
This function returns a null-terminated USB string descriptor for the device specified by device...
HID_SMBUS_STATUS HidSmbus_SetSmbusConfig(const HID_SMBUS_DEVICE device, const DWORD bitRate, const BYTE address, const BOOL autoReadRespond, const WORD writeTimeout, const WORD readTimeout, const BOOL sclLowTimeout, const WORD transferRetries)
sets the SMBus bit rate, address, and transfer settings such as timeouts and retries.
#define WINAPI
Windows api definition.
Definition: SLABCP2112.h:38
HID_SMBUS_STATUS HidSmbus_GetLock(const HID_SMBUS_DEVICE device, BYTE *lock)
Get and return the device customization lock status.
HID_SMBUS_STATUS HidSmbus_GetHidLibraryVersion(BYTE *major, BYTE *minor, BOOL *bIsRelease)
Reads and returns the version of the HID Device Interface Library that is currently in use...
#define HID_TO_SMBUS_API
HID to smbus api definition.
Definition: SLABCP2112.h:37
BYTE HID_SMBUS_S0
HID_SMBUS_TRANSFER_S0.
Definition: SLABCP2112.h:102
HID_SMBUS_STATUS HidSmbus_GetManufacturingString(const HID_SMBUS_DEVICE device, char *manufacturingString, BYTE *strlen)
retrieves the USB manufacturing string.
HID_SMBUS_STATUS HidSmbus_IsOpened(const HID_SMBUS_DEVICE device, BOOL *bIsOpened)
Returns the device opened status.
HID_SMBUS_STATUS HidSmbus_SetUsbConfig(const HID_SMBUS_DEVICE device, const WORD vid, const WORD pid, const BYTE power, const BYTE powerMode, const WORD releaseVersion, const BYTE mask)
This function allows one-time customization of the USB configuration, which includes vendor ID...
#define HID_SMBUS_CP2112_PRODUCT_STRLEN
HID SMBus CP2112 product string length.
Definition: SLABCP2112.h:311
the specified device is already (exclusively) opened
Definition: silabs_defs.h:270
HID_SMBUS_STATUS HidSmbus_GetSerialString(const HID_SMBUS_DEVICE device, char *serialString, BYTE *strlen)
retrieves the USB product string.
HID_SMBUS_STATUS HidSmbus_GetOpenedString(const HID_SMBUS_DEVICE device, char *deviceString, const HID_SMBUS_GETSTRING options)
This function returns a null-terminated vendor ID string, product ID string, serial number string...