An 496
An 496
User Application
HID Driver
(Provided by OS)
PC
USB
SMBus Devices
Mac OS X 10.5 and later [Link] SLABCP2112.h (C, C++, Obj-C) 1.0
Types.h (Compatibility)
*Note: Requires [Link] version 1.5 during runtime.
HidSmbus_SetSmbusConfig() Sets the bit rate, master address, timeouts, and transfer 17
settings
HidSmbus_GetSmbusConfig() Gets the bit rate, master address, timeouts, and transfer 18
settings
2 Rev. 0.2
AN496
Table 2. API Functions Table (Continued)
2.1. HidSmbus_GetNumDevices
Description: This function returns the number of devices connected to the host with matching vendor and
product ID (VID, PID).
Prototype: HID_SMBUS_STATUS HidSmbus_GetNumDevices (DWORD* numDevices, WORD vid,
WORD pid)
Parameters: 1. numDevices returns the number of devices connected on return.
2. vid filters device results by vendor ID. If both vid and pid are set to 0x0000, then HID devices
will not be filtered by VID/PID.
3. pid filters device results by product ID. If both vid and pid are set to 0x0000, then HID devices
will not be filtered by VID/PID.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_PARAMETER
Rev. 0.2 3
AN496
2.2. HidSmbus_GetString
Description: This function returns a null-terminated vendor ID string, product ID string, serial string, device path
string, manufacturer string, or product string for the device specified by an index passed in
deviceNum. The index for the first device is 0, and the last device is the value returned by
HidSmbus_GetNumDevices() – 1.
Prototype: HID_SMBUS_STATUS HidSmbus_GetString (DWORD deviceNum, WORD vid, WORD
pid, char* deviceString, DWORD options)
Parameters: 1. deviceNum is the index of the device for which the string is desired.
2. vid filters device results by vendor ID. If both vid and pid are set to 0x0000, then HID devices
will not be filtered by VID/PID.
3. pid filters device results by product ID. If both vid and pid are set to 0x0000, then HID devices
will not be filtered by VID/PID.
4. deviceString is a variable of type HID_SMBUS_DEVICE_STR, which will contain a null-
terminated ASCII device string on return. The string is 260 bytes on Windows and 512 bytes
on Mac OS X.
5. options determines if deviceString will contain a vendor ID string, product ID string, serial
string, device path string, manufacturer string, or product string.
4 Rev. 0.2
AN496
2.3. HidSmbus_GetOpenedString
Description: This function returns a null-terminated vendor ID string, product ID string, serial string, device path
string, manufacturer string, or product string for the device specified by device.
Prototype: HID_SMBUS_STATUS HidSmbus_GetOpenedString (HID_SMBUS_DEVICE device,
char* deviceString, DWORD options)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. deviceString is a variable of type HID_SMBUS_DEVICE_STR, which will contain a null-
terminated ASCII device string on return. The string is 260 bytes on Windows and 512 bytes
on Mac OS X.
3. options determines if deviceString will contain a vendor ID string, product ID string, serial
string, device path string, manufacturer string, or product string.
Rev. 0.2 5
AN496
2.4. HidSmbus_GetIndexedString
Description: This function returns a null-terminated USB string descriptor for the device specified by an index
passed in deviceNum (Windows Only).
Prototype: HID_SMBUS_STATUS HidSmbus_GetIndexedString (DWORD deviceNum, WORD vid,
WORD pid, DWORD stringIndex, char* deviceString)
Parameters: 1. deviceNum is the index of the device for which the string is desired.
2. vid filters device results by vendor ID. If both vid and pid are set to 0x0000, then HID devices
will not be filtered by VID/PID.
3. pid filters device results by product ID. If both vid and pid are set to 0x0000, then HID devices
will not be filtered by VID/PID.
4. stringIndex specifies the device-specific index of the USB string descriptor to return.
5. deviceString is a variable of type HID_SMBUS_DEVICE_STR (260-byte ASCII string), which
will contain a NULL terminated device descriptor string on return.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_DEVICE_NOT_FOUND
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_DEVICE_ACCESS_ERROR
2.5. HidSmbus_GetOpenedIndexedString
Description: This function returns a null-terminated USB string descriptor for the device specified by device
(Windows Only).
Prototype: HID_SMBUS_STATUS HidSmbus_GetOpenedIndexedString (HID_SMBUS_DEVICE
device, DWORD stringIndex, char* deviceString)
Parameters: 1. deviceNum is the device object pointer as returned by HidSmbus_Open().
2. stringIndex specifies the device-specific index of the USB string descriptor to return.
3. deviceString is a variable of type HID_SMBUS_DEVICE_STR (260-byte ASCII string), which
will contain a NULL terminated device descriptor string on return.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_DEVICE_ACCESS_ERROR
6 Rev. 0.2
AN496
2.6. HidSmbus_GetAttributes
Description: This function returns the device vendor ID, product ID, and release number for the device specified
by an index passed in deviceNum.
Prototype: HID_SMBUS_STATUS HidSmbus_GetAttributes (DWORD deviceNum, WORD vid, WORD
pid, WORD* deviceVid, WORD* devicePid, WORD* deviceReleaseNumber)
Parameters: 1. deviceNum is the index of the device for which the string is desired.
2. vid filters device results by vendor ID. If both vid and pid are set to 0x0000, then HID devices
will not be filtered by VID/PID.
3. pid filters device results by product ID. If both vid and pid are set to 0x0000, then HID devices
will not be filtered by VID/PID.
4. deviceVid returns the device vendor ID.
5. devicePid returns the device product ID.
6. deviceReleaseNumber returns the USB device release number in binary-coded decimal.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_DEVICE_NOT_FOUND
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_DEVICE_ACCESS_ERROR
2.7. HidSmbus_GetOpenedAttributes
Description: This function returns the device vendor ID, product ID, and release number for the device specified
by device.
Prototype: HID_SMBUS_STATUS HidSmbus_GetOpenedAttributes (HID_SMBUS_DEVICE device,
WORD* deviceVid, WORD* devicePid, WORD* deviceReleaseNumber)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. deviceVid returns the device vendor ID.
3. devicePid returns the device product ID.
4. deviceReleaseNumber returns the USB device release number in binary-coded decimal.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_DEVICE_ACCESS_ERROR
Rev. 0.2 7
AN496
2.8. HidSmbus_Open
Description: This function opens a device using a device number between 0 and HidSmbus_GetNumDevices()
– 1 and returns a device object pointer that is used for subsequent accesses.
Prototype: HID_SMBUS_STATUS HidSmbus_Open (HID_SMBUS_DEVICE* device, DWORD
deviceNum, WORD vid, WORD pid)
Parameters: 1. device returns a pointer to an HID USB-to-SMBus device object. This pointer will be used by
all subsequent accesses to the device.
2. deviceNum is a zero-based device index, between 0 and (HidSmbus_GetNumDevices() – 1).
3. vid filters device results by vendor ID. If both vid and pid are set to 0x0000, then HID devices
will not be filtered by VID/PID.
4. pid filters device results by product ID. If both vid and pid are set to 0x0000, then HID devices
will not be filtered by VID/PID.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_DEVICE_NOT_FOUND
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_DEVICE_IO_FAILED
HID_SMBUS_DEVICE_ACCESS_ERROR
HID_SMBUS_DEVICE_NOT_SUPPORTED
Remarks: Be careful when opening a device. Any HID device may be opened by this library. However, if the
device is not a CP2112, use of this library will cause undesirable results. The best course of action
is to designate a unique VID/PID for CP2112 devices only. The application should then filter
devices using this VID/PID.
2.9. HidSmbus_Close
Description: This function closes an opened device using the device object pointer provided by
HidSmbus_Open().
Prototype: HID_SMBUS_STATUS HidSmbus_Close (HID_SMBUS_DEVICE device)
Parameters: device is the device object pointer as returned by HidSmbus_Open().
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_HANDLE
HID_SMBUS_DEVICE_ACCESS_ERROR
Remarks: device is invalid after calling HidSmbus_Close(). Set device to NULL.
8 Rev. 0.2
AN496
2.10. HidSmbus_IsOpened
Description: This function returns the device opened status.
Prototype: HID_SMBUS_STATUS HidSmbus_IsOpened (HID_SMBUS_DEVICE device, BOOL*
opened)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. opened returns TRUE if the device object pointer is valid and the device has been opened
using HidSmbus_Open().
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
2.11. HidSmbus_ReadRequest
Description: This function intiates a read transfer to the specified slave device address. Read and write
timeouts as well as transfer retries can be set using HidSmbus_SetSmbusConfig() as described in
"HidSmbus_SetSmbusConfig" on page 17.
Prototype: HID_SMBUS_STATUS HidSmbus_ReadRequest (HID_SMBUS_DEVICE device, BYTE
slaveAddress, WORD numBytesToRead)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. slaveAddress is the address of the slave device to read from. This value must be between
0x02 - 0xFE. The least significant bit is the read/write bit for the SMBus transaction and must
be 0.
3. numBytesToRead is the number of bytes to read from the device (1–512).
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_INVALID_REQUEST_LENGTH
HID_SMBUS_DEVICE_IO_FAILED
Remarks: HidSmbus_ReadRequest() initiates a read transfer. SMBus is a half-duplex bus, which means that
only one read, address read, or write transfer can be active at a time. The device will attempt to
read up to transferRetries number of times and for readTimeout milliseconds before timing out.
See HidSmbus_SetSmbusConfig() for more information on configuring read timeouts. If the
autoReadRespond setting is enabled, then call HidSmbus_GetReadResponse() to return the
results of the read transfer.
Rev. 0.2 9
AN496
2.12. HidSmbus_AddressReadRequest
Description: This function intiates a read transfer to the specified slave device address and specifies the
address to read from on the device. Read and write timeouts as well as transfer retries can be set
using HidSmbus_SetSmbusConfig() as described in "HidSmbus_SetSmbusConfig" on page 17.
Prototype: HID_SMBUS_STATUS HidSmbus_AddressReadRequest (HID_SMBUS_DEVICE device,
BYTE slaveAddress, WORD numBytesToRead, BYTE targetAddressSize, BYTE
targetAddress[16])
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. slaveAddress is the address of the slave device to read from. This value must be between
0x02 - 0xFE. The least significant bit is the read/write bit for the SMBus transaction and must
be 0.
3. numBytesToRead is the number of bytes to read from the device (1–512).
4. targetAddressSize is the size of the target address in bytes (1-16).
5. targetAddress is the address to read from the slave device.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_INVALID_REQUEST_LENGTH
HID_SMBUS_DEVICE_IO_FAILED
Remarks: HidSmbus_AddressReadRequest() initiates a read transfer. SMBus is a half-duplex bus which
means that only one read, address read, or write transfer can be active at a time. The device will
attempt to read up to transferRetries number of times and for readTimeout milliseconds before
timing out. See HidSmbus_SetSmbusConfig() for more information on configuring read timeouts. If
the autoReadRespond setting is enabled, then call HidSmbus_GetReadResponse() to return the
results of the read transfer. The device will transmit the target address on the bus after the slave
device has acknowledged its address. This function is designed to read from EEPROMs with an
SMBus interface.
10 Rev. 0.2
AN496
2.13. HidSmbus_ForceReadResponse
Description: This function causes the device to send a read response to the host after a read transfer has been
issued.
Prototype: HID_SMBUS_STATUS HidSmbus_ForceReadResponse (HID_SMBUS_DEVICE device,
WORD numBytesToRead)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. numBytesToRead is the number of bytes to read from the device (1–512).
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_REQUEST_LENGTH
HID_SMBUS_DEVICE_IO_FAILED
Remarks: HidSmbus_ForceReadResponse() should only be called if autoReadRespond is disabled using
HidSmbus_SetSmbusConfig(). This allows the user to read data in a polled mode.
Call HidSmbus_ReadRequest() or HidSmbus_AddressReadRequest() first.
Next, call HidSmbus_TransferStatusRequest() and HidSmbus_TransferStatusResponse() to
check if the device has received data.
Next, call HidSmbus_ForceReadResponse().
Finally, call HidSmbus_GetReadResponse() repeatedly until all read data is returned.
Typically, this procedure is not necessary as users should enable the autoReadRespond setting.
Rev. 0.2 11
AN496
2.14. HidSmbus_GetReadResponse
Description: This function returns the read response to a read request. Read and write timeouts as well as
transfer retries can be set using HidSmbus_SetSmbusConfig() as described in
"HidSmbus_SetSmbusConfig" on page 17.
Prototype: HID_SMBUS_STATUS HidSmbus_GetReadResponse (HID_SMBUS_DEVICE device,
HID_SMBUS_S0* status, BYTE* buffer, BYTE bufferSize, BYTE* numBytesRead)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. status returns the status of the read request.
12 Rev. 0.2
AN496
2.15. HidSmbus_WriteRequest
Description: This function writes the specified number of bytes from the supplied buffer to the specified slave
device and returns immediately after sending the request to the CP2112. Read and write timeouts
can be set using HidSmbus_SetTimeouts() as described in "2.20. HidSmbus_SetTimeouts" on
page 16.
Prototype: HID_SMBUS_STATUS HidSmbus_WriteRequest (HID_SMBUS_DEVICE device, BYTE
slaveAddress, BYTE* buffer, BYTE numBytesToWrite)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. slaveAddress is the address of the slave device to write to. This value must be between 0x02
- 0xFE. The least significant bit is the read/write bit for the SMBus transaction and must be 0.
3. buffer is the address of a buffer to be sent to the device.
4. numBytesToWrite is the number of bytes to write to the device (1–61). This value must be less
than or equal to the size of buffer.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_INVALID_REQUEST_LENGTH
HID_SMBUS_DEVICE_IO_FAILED
Remarks: Call HidSmbus_TransferStatusRequest()/HidSmbus_GetTransferStatusResponse() to wait for the
write transfer to complete before issuing another transfer request. The device waits for up to
transferRetries number of retries and writeTimeout number of milliseconds before timing out.
2.16. HidSmbus_TransferStatusRequest
Description: This function requests the status of the current read or write transfer.
Prototype: HID_SMBUS_STATUS HidSmbus_TransferStatusRequest (HID_SMBUS_DEVICE
device)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_DEVICE_IO_FAILED
Remarks: Call HidSmbus_TransferStatusRequest() followed by HidSmbus_GetTransferStatusResponse() to
get the status of the current read or write transfer.
Rev. 0.2 13
AN496
2.17. HidSmbus_GetTransferStatusResponse
Description: This function returns the status of the current read or write transfer.
Prototype: HID_SMBUS_STATUS HidSmbus_GetTransferStatusResponse (HID_SMBUS_DEVICE
device, HID_SMBUS_S0* status, HID_SMBUS_S1* detailedStatus, WORD*
numRetries, WORD* bytesRead)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
14 Rev. 0.2
AN496
HID_SMBUS_S1_ERROR_TIMEOUT_BUS_ 0x01 Tranfser timeout: SMBus not free (or SCL low
NOT_FREE timeout occurred)
2.18. HidSmbus_CancelTransfer
Description: This function cancels the current read or write transfer.
Prototype: HID_SMBUS_STATUS HidSmbus_TransferStatusRequest (HID_SMBUS_DEVICE
device)
Parameters: [Link] is the device object pointer as returned by HidSmbus_Open().
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_DEVICE_IO_FAILED
Remarks: This function will clear any read responses received.
Rev. 0.2 15
AN496
2.19. HidSmbus_Cancello
Description: This function cancels any pending HID reads and writes (Windows Only).
Prototype: HID_SMBUS_STATUS HidSmbus_CancelIo (HID_SMBUS_DEVICE device)
Parameters: device is the device object pointer as returned by HidSmbus_Open().
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_DEVICE_IO_FAILED
2.20. HidSmbus_SetTimeouts
Description: This function sets the response timeouts. Response timeouts are used by
HidSmbus_GetReadResponse() and HidSmbus_GetTransferStatusResponse(). The default value
for response timeouts is 1000 ms, but timeouts can be set to wait for any number of milliseconds
between 1 and 0xFFFFFFFF. Specifying a response timeout of 0, will wait indefinitely.
Prototype: HID_SMBUS_STATUS HidSmbus_SetTimeouts (HID_SMBUS_DEVICE device, DWORD
responseTimeout)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. responseTimeout is the HidSmbus_GetReadResponse() and HidSmbus_GetTransferStatusResponse()
timeout.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
Remarks: If timeouts are set to a large value and no data is received, the application may appear
unresponsive. It is recommended to set timeouts appropriately before using the device. Typically,
users will want to specify a response timeout that is greater than the read and write timeouts.
2.21. HidSmbus_GetTimeouts
Description: This function returns the current response timeouts specified in milliseconds. A response timeout
value of 0 indicates an infinite timeout.
Prototype: HID_SMBUS_STATUS HidSmbus_GetTimeouts (HID_SMBUS_DEVICE device, DWORD*
responseTimeout)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. responseTimeout is the response operation timeout in milliseconds.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
Remarks: Timeouts are maintained for each device but are not persistent across HidSmbus_Open()/
HidSmbus_Close().
16 Rev. 0.2
AN496
2.22. HidSmbus_SetSmbusConfig
Description: This function sets the SMBus bit rate, address, and transfer settings such as timeouts and retries.
Refer to the device data sheet for a list of supported configuration settings.
Prototype: HID_SMBUS_STATUS HidSmbus_SetSmbusConfig (HID_SMBUS_DEVICE device, DWORD
bitRate, BYTE address, BOOL autoReadRespond, WORD writeTimeout, WORD
readTimeout, BOOL sclLowTimeout, WORD transferRetries)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. bitRate is the bit rate for SMBus communication. The default is 100 kHz. This value must be
non-zero.
3. address is the device’s slave address (0x02– 0xFE). The device will only acknowledge this
address. The default is 0x02. The least significant bit is the read/write bit for the SMBus
transaction and must be 0.
4. autoReadRespond controls the read response behavior of the device. If enabled, the device will
automatically send read response interrupt reports to the device after initiating a read transfer.
If disabled, the user must call HidSmbus_ForceReadResponse() before read response interrupt
reports will be sent to the host. The default is FALSE (0).
5. writeTimeout is the time limit in milliseconds (0–1000) before the device will automatically
cancel a write transfer. A value of 0 indicates an infinite timeout. In this case, a write transfer will
wait indefinitely for a write to complete or until HidSmbus_CancelTransfer() is called.
The default is 0.
6. readTimeout is the time limit in milliseconds (0 - 1000) before the device will automatically
cancel a read transfer. A value of 0 indicates an infinite timeout. In this case, a read transfer will
wait indefinitely for a read to complete or until HidSmbus_CancelTransfer() is called.
The default is 0.
7. sclLowTimeout is a timeout that will reset the SMBus if the SCL line is held low for more than 25
ms. If enabled and an SCL Low Timeout occurs, the status byte of the Transfer Status
Response command will be set appropriately. The default is FALSE (0).
8. transferRetries is the number of times to retry (0 - 1000) a failed read or write transfer. A value of
0 indicates an infinite number of retries until the specified read or write timeout has elapsed.
The default is 0.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_DEVICE_IO_FAILED
Rev. 0.2 17
AN496
2.23. HidSmbus_GetSmbusConfig
Description: This function gets the SMBus bit rate, address, and transfer settings such as timeouts and retries.
Refer to the device data sheet for a list of supported configuration settings.
Prototype: HID_SMBUS_STATUS HidSmbus_GetSmbusConfig (HID_SMBUS_DEVICE device,
DWORD* bitRate, BYTE* address, BOOL* autoReadRespond, WORD*
writeTimeout, WORD* readTimeout, BOOL* sclLowTimeout, WORD*
transferRetries)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. bitRate returns the bit rate for SMBus communication. The default is 100 kHz. This value must
be non-zero.
3. address returns the device’s slave address (0x02–0xFE). The device will only acknowledge this
address. The default is 0x02.
4. autoReadRespond returns the read response behavior of the device. If auto read respond is
enabled, then the device will automatically send read response interrupt reports to the device
after initiating a read transfer. If disabled, the user must call HidSmbus_ForceReadResponse()
before read response interrupt reports will be sent to the host. The default is FALSE (0).
5. writeTimeout returns the time limit in milliseconds (0–1000) before the device will automatically
cancel a write transfer. A value of 0 indicates an infinite timeout. In this case, a write transfer will
wait indefinitely for a write to complete or until HidSmbus_CancelTransfer() is called. The
default is 0.
6. readTimeout returns the time limit in milliseconds (0–1000) before the device will automatically
cancel a read transfer. A value of 0 indicates an infinite timeout. In this case, a read transfer will
wait indefinitely for a read to complete or until HidSmbus_CancelTransfer() is called. The default
is 0.
7. sclLowTimeout is a timeout that will reset the SMBus if the SCL line is held low for more than 25
ms. If enabled and an SCL Low Timeout occurs, the status byte of the Transfer Status
Response command will be set appropriately. The default is FALSE (0).
8. transferRetries returns the number of times to retry (0–1000) a failed read or write transfer. A
value of 0 indicates an infinite number of retries until the specified read or write timeout has
elapsed. The default is 0.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_DEVICE_IO_FAILED
2.24. HidSmbus_Reset
Description: This function initiates a full device reset. All configuration settings will be reset to their default
values after the device re-enumerates.
Prototype: HID_SMBUS_STATUS HidSmbus_Reset (HID_SMBUS_DEVICE device)
Parameters: device is the device object pointer as returned by HidSmbus_Open().
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_DEVICE_IO_FAILED
Remarks: Resetting the device will make the device’s handle stale. Users must close the device using the
old handle before proceeding to reconnect to the device. See more information on surprise
removal. See HidSmbus_SetSmbusConfig() and HidSmbus_SetGpioConfig() for default
configuration settings.
18 Rev. 0.2
AN496
2.25. HidSmbus_SetGpioConfig
Description: This function configures the GPIO pins’ directions and modes.
Prototype: HID_SMBUS_STATUS HidSmbus_SetGpioConfig (HID_SMBUS_DEVICE device, BYTE
direction, BYTE mode, BYTE special, BYTE clkDiv)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. direction is a bitmask that specifies each GPIO pin’s direction.
.
4. special is a bitmask that specifies the special behavior of GPIO.0, GPIO.1, and GPIO.7
5. clkDiv is the clock output divider value used for GPIO.7 when configured in clock output mode.
The frequency is equal to 48 MHz / (2 x clkDiv) when clkDiv is between 1 and 255 and equal to
48 MHz when clkDiv is 0.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_DEVICE_IO_FAILED
Rev. 0.2 19
AN496
2.26. HidSmbus_GetGpioConfig
Description: This function returns the GPIO pins’ directions and modes.
Prototype: HID_SMBUS_STATUS HidSmbus_GetGpioConfig (HID_SMBUS_DEVICE device, BYTE*
direction, BYTE* mode, BYTE* special, BYTE* clkDiv)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. direction returns a bitmask that specifies each GPIO pin’s direction.
3. mode returns a bitmask that specifies each GPIO pin’s mode.
HID_SMBUS_MODE_OPEN_DRAIN 0 Open-Drain
HID_SMBUS_MODE_PUSH_PULL 1 Push-Pull
4. special returns a bitmask that specifies the special behavior of GPIO.0, GPIO.1, and GPIO.7.
5. clkDiv returns the clock output divider value used for GPIO.7 when configured in clock output
mode. The frequency is equal to 48 MHz / (2 x clkDiv) when clkDiv is between 1 and 255 and
equal to 48 MHz when clkDiv is 0.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_DEVICE_IO_FAILED
20 Rev. 0.2
AN496
2.27. HidSmbus_ReadLatch
Description: This function returns the current GPIO latch value.
Prototype: HID_SMBUS_STATUS HidSmbus_ReadLatch (HID_SMBUS_DEVICE device, BYTE*
latchValue)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. latchValue returns the current GPIO latch value.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_DEVICE_IO_FAILED
Remarks: If a pin is configured as an input, then the latchValue bit represents the logical voltage level
received on the pin. If a pin is configured as an output, then the latchValue bit represents the
logical voltage level driven on the pin.
2.28. HidSmbus_WriteLatch
Description: This function sets the current GPIO latch value for the specified bits.
Prototype: HID_SMBUS_STATUS HidSmbus_WriteLatch (HID_SMBUS_DEVICE device, BYTE
latchValue, BYTE latchMask)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. latchValue is the output value to drive on GPIO pins configured as outputs.
3. latchMask is the bitmask specifying which bits to modify.
Definition Value
HID_SMBUS_MASK_GPIO_0 0x01
HID_SMBUS_MASK_GPIO_1 0x02
HID_SMBUS_MASK_GPIO_2 0x04
HID_SMBUS_MASK_GPIO_3 0x08
HID_SMBUS_MASK_GPIO_4 0x10
HID_SMBUS_MASK_GPIO_5 0x20
HID_SMBUS_MASK_GPIO_6 0x40
HID_SMBUS_MASK_GPIO_7 0x80
Rev. 0.2 21
AN496
2.29. HidSmbus_GetPartNumber
Description: This function retrieves the part number and version of the CP2112 device.
Prototype: HID_SMBUS_STATUS HidSmbus_GetPartNumber (HID_SMBUS_DEVICE device, BYTE*
partNumber, BYTE* version)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. partNumber returns the device part number.
2.30. HidSmbus_GetLibraryVersion
Description: This function returns the HID USB-to-SMBus Interface Library version.
Prototype: HID_SMBUS_STATUS HidSmbus_GetLibraryVersion (BYTE* major, BYTE* minor,
BOOL* release)
Parameters: 1. major returns the major library version number. This value ranges from 0 to 255.
2. minor returns the minor library version number. This value ranges from 0 to 255.
3. release returns TRUE if the library is a release build; otherwise, the library is a Debug build.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_PARAMETER
2.31. HidSmbus_GetHidLibraryVersion
Description: This function returns the version of the HID Device Interface Library that is currently in use.
Prototype: HID_SMBUS_STATUS HidSmbus_GetHidLibraryVersion (BYTE* major, BYTE*
minor, BOOL* release)
Parameters: 1. major returns the major library version number. This value ranges from 0 to 255.
2. minor returns the minor library version number. This value ranges from 0 to 255.
3. release returns TRUE if the library is a release build; otherwise, the library is a Debug build.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_PARAMETER
2.32. HidSmbus_GetHidGuid
Description: This function obtains the HID GUID. This can be used to register for surprise removal notifications
(Windows Only).
Prototype: HID_SMBUS_STATUS HidSmbus_GetHidGuid (void* guid)
Parameters: 1. guid returns the HID GUID.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_PARAMETER
22 Rev. 0.2
AN496
3. User Customization API Functions
The following parameters are programmable on the device. Different functions are provided to program these
parameters. Each parameter may only be programmed once and only if the parameter is not locked.
The following API functions are provided to allow user customization/one-time programming:
HidSmbus_SetUsbConfig() Sets VID, PID, power, power mode, and release version 26
HidSmbus_GetUsbConfig() Gets VID, PID, power, power mode, and release version 27
Rev. 0.2 23
AN496
3.1. HidSmbus_SetLock
Description: This function permanently locks/disables device customization.
Prototype: HID_SMBUS_STATUS HidSmbus_SetLock (HID_SMBUS_DEVICE device, BYTE lock)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. lock is the bitmask specifying which fields can be customized/programmed and which fields
are already customized.
24 Rev. 0.2
AN496
3.2. HidSmbus_GetLock
Description: This function returns the device customization lock status.
Prototype: HID_SMBUS_STATUS HidSmbus_GetLock (HID_SMBUS_DEVICE device, BYTE* lock)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. lock returns a bitmask specifying which fields are locked.
Rev. 0.2 25
AN496
3.3. HidSmbus_SetUsbConfig
Description: This function allows one-time customization of the USB configuration, which includes vendor ID,
product ID, power, power mode, and release version settings. Each field can be independently
programmed one time via the mask field.
Prototype: HID_SMBUS_STATUS HidSmbus_SetUsbConfig (HID_SMBUS_DEVICE device, WORD
vid, WORD pid, BYTE power, BYTE powerMode, WORD releaseVersion, BYTE
mask)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. vid is the vendor ID.
3. pid is the product ID.
4. power specifies the current requested by the device in milliamps/2. The maximum power
setting is 500 mA or 250 (0xFA). This value only applies when the device is configured to be
bus-powered.
5. powerMode configures the device as bus-powered or self-powered.
6. releaseVersion is the user-programmable release version. The MSB is the major revision and
the LSB is the minor revision. Both revisions can be programmed to any value from 0 to 255.
This version is not the same as the device release number described in the USB device
descriptor.
7. mask is the bitmask specifying which fields to customize.
26 Rev. 0.2
AN496
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_DEVICE_IO_FAILED
3.4. HidSmbus_GetUsbConfig
Description: This function retrieves USB configuration, which includes vendor ID, product ID, power, power
mode, release version, and flush buffers settings.
Prototype: HID_SMBUS_STATUS HidSmbus_GetUsbConfig (HID_SMBUS_DEVICE device, WORD*
vid, WORD* pid, BYTE* power, BYTE* powerMode, WORD* releaseVersion)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. vid returns the vendor ID.
3. pid returns the product ID.
4. power returns the current requested by the device in milliamps / 2. This value only applies
when the device is bus-powered.
5. powerMode returns the device power mode.
6. releaseVersion returns the user-programmable release version. The MSB is the major
revision, and the LSB is the minor revision. Both revisions can be programmed to any value
from 0 to 255. This version is not the same as the device release number described in the
USB device descriptor.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_DEVICE_IO_FAILED
Rev. 0.2 27
AN496
3.5. HidSmbus_SetManufacturingString
Description: This function allows one-time customization of the USB manufacturing string.
Prototype: HID_SMBUS_STATUS HidSmbus_SetManufacturingString (HID_SMBUS_DEVICE
device, char* manufacturingString, BYTE strlen)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. manufacturingString is a variable of type HID_SMBUS_CP2112_MFG_STR, a 30-byte
character buffer containing the ASCII manufacturing string.
3. strlen is the length of manufacturingString in bytes. The maximum string length is 30 bytes.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_DEVICE_IO_FAILED
3.6. HidSmbus_GetManufacturingString
Description: This function retrieves the USB manufacturing string.
Prototype: HID_SMBUS_STATUS HidSmbus_GetManufacturingString (HID_SMBUS_DEVICE
device, char* manufacturingString, BYTE* strlen)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. manufacturingString is a variable of type HID_SMBUS_CP2112_MFG_STR, a 30-byte
character buffer that will contain the ASCII manufacturing string.
3. strlen returns the length of the string in bytes.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_DEVICE_IO_FAILED
3.7. HidSmbus_SetProductString
Description: This function allows one-time customization of the USB product string.
Prototype: HID_SMBUS_STATUS HidSmbus_SetProductString (HID_SMBUS_DEVICE device,
char* productString, BYTE strlen)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. productString is a variable of type HID_SMBUS_CP2112_PRODUCT_STR, a 30-byte
character buffer containing the ASCII product string.
3. strlen is the length of productString in bytes. The maximum string length is 30 bytes.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_DEVICE_IO_FAILED
28 Rev. 0.2
AN496
3.8. HidSmbus_GetProductString
Description: This function retrieves the USB product string.
Prototype: HID_SMBUS_STATUS HidSmbus_GetProductString (HID_SMBUS_DEVICE device,
char* productString, BYTE* strlen)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. productString is a variable of type HID_SMBUS_CP2112_PRODUCT_STR, a 30-byte
character buffer that will contain the ASCII product string.
3. strlen returns the length of the string in bytes.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_DEVICE_IO_FAILED
3.9. HidSmbus_SetSerialString
Description: This function allows one-time customization of the USB serial string.
Prototype: HID_SMBUS_STATUS HidSmbus_SetSerialString (HID_SMBUS_DEVICE device,
char* serialString, BYTE strlen)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. serialString is a variable of type HID_SMBUS_CP2112_SERIAL_STR, a 30-byte character
buffer containing the ASCII serial string.
3. strlen is the length of serialString in bytes. The maximum string length is 30 bytes.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_DEVICE_IO_FAILED
3.10. HidSmbus_GetSerialString
Description: This function retrieves the USB product string.
Prototype: HID_SMBUS_STATUS HidSmbus_GetSerialString (HID_SMBUS_DEVICE device,
char* serialString, BYTE* strlen)
Parameters: 1. device is the device object pointer as returned by HidSmbus_Open().
2. serialString is a variable of type HID_SMBUS_CP2112_SERIAL_STR, a 30-byte character
buffer that will contain the ASCII product string.
3. strlen returns the length of the string in bytes.
Return Value: HID_SMBUS_STATUS = HID_SMBUS_SUCCESS
HID_SMBUS_INVALID_DEVICE_OBJECT
HID_SMBUS_INVALID_PARAMETER
HID_SMBUS_DEVICE_IO_FAILED
Rev. 0.2 29
AN496
4. HID_SMBUS_STATUS Returns Codes
Each library function returns an HID_SMBUS_STATUS return code to indicate that the function returned
successfully or to describe an error. Table 3 describes each error code.
30 Rev. 0.2
AN496
5. Thread Safety
The HID USB-to-SMBus library and associated functions are not thread safe. This means that calling library
functions simultaneously from multiple threads may have undesirable effects.
To use the library functions in more than one thread, the user should do the following:
1. Call library functions from within a critical section such that only a single function is being called at any given
time. If a function is being called in one thread, then the user must prevent another thread from calling any
function until the first function returns.
2. HidSmbus_GetReadResponse(), HidSmbus_GetTransferStatusResponse(),
HidSmbus_TransferStatusRequest(), and HidSmbus_CancelTransfer() issue pending read requests that cannot
be canceled from another thread. If the user calls HidSmbus_Close() in a different thread than the thread in
which the read request was created, then the device will not be accessible after calling HidSmbus_Close(). The
thread that issued the pending read request must return/terminate successfully before the device can be
accessed again. See “6. Thread Read Access Models (For Windows)” on page 32 for more information.
Rev. 0.2 31
AN496
6. Thread Read Access Models (For Windows)
There are several common read access models when using the HID USB-to-SMBus library. There are some
restrictions on the valid use of a device handle based on these models. CancelIo() can only cancel pending I/O
(reads/writes) issued in the same thread in which CancelIo() is called. Due to this limitation, the user is responsible
for cancelling pending I/O before closing the device. Failure to do so will result in an inaccessible HID USB-to-
SMBus device until the thread releases access to the device handle. The following tables describe five common
access models and the expected behavior.
Notes:
1. HidSmbus_Close() calls CancelIo() prior to calling CloseHandle().
2. QueueInterruptReports() issues a pending interrupt report read request. The request completes if at least one input
report is read. The request is still pending if the operation times out. The following functions call
QueueInterruptReports():
HidSmbus_GetReadResponse()
HidSmbus_GetTransferStatusResponse()
HidSmbus_TransferStatusRequest()
HidSmbus_CancelTransfer()
3. HidSmbus_CancelIo() forces any pending requests issued by the same thread to complete (cancelled).
4. * indicates that a read is still pending and was issued in the specified thread.
5. ? indicates that a read is still pending and was issued in one of the threads (indeterminate).
HidSmbus_Open() — —
QueueInterruptReports()* — —
HidSmbus_Close() — OK
HidSmbus_Open() — —
— QueueInterruptReports()* —
HidSmbus_Open() — —
— QueueInterruptReports()* —
— HidSmbus_CancelIo() —
HidSmbus_Close() — OK
32 Rev. 0.2
AN496
HidSmbus_Open() — —
QueueInterruptReports()? QueueInterruptReports()? —
HidSmbus_Open() — —
QueueInterruptReports()? QueueInterruptReports()? —
— HidSmbus_CancelIo() —
HidSmbus_Close() — OK
Rev. 0.2 33
AN496
7. Surprise Removal (For Windows)
HidSmbus_GetHidGuid() returns the HID GUID so that Windows applications or services can register for the
WM_DEVICECHANGE Windows message. Once registered, the application will receive device arrival and
removal notices for HID devices. The application must retrieve the device path to filter devices based on VID/PID.
Similarly, if a DBT_DEVICEREMOVECOMPLETE message is received, the application must check to see if the
device path matches the device path of any connected devices. If this is the case, then the device was removed
and the application must close the device. Also, if a DBT_DEVICEARRIVAL message is received, the application
might add the new device to a device list so that users can select any HID device matching the required VID/PID.
See accompanying example code for information on how to implement surprise removal and device arrival. Search
for Knowledge Base Article # 222649, 311158, and 311153 for programming examples for C++, Visual Basic .NET,
and Visual C#.
34 Rev. 0.2
AN496
DOCUMENT CHANGE LIST
Revision 0.1 to Revision 2
Added Table 1.
Added support for the Mac OS X dynamic library.
Removed Appendix.
Rev. 0.2 35
Simplicity Studio
One-click access to MCU and
wireless tools, documentation,
software, source code libraries &
more. Available for Windows,
Mac and Linux!
Disclaimer
Silicon Labs intends to provide customers with the latest, accurate, and in-depth documentation of all peripherals and modules available for system and software implementers using or
intending to use the Silicon Labs products. Characterization data, available modules and peripherals, memory sizes and memory addresses refer to each specific device, and "Typical"
parameters provided can and do vary in different applications. Application examples described herein are for illustrative purposes only. Silicon Labs reserves the right to make changes
without further notice and limitation to product information, specifications, and descriptions herein, and does not give warranties as to the accuracy or completeness of the included
information. Silicon Labs shall have no liability for the consequences of use of the information supplied herein. This document does not imply or express copyright licenses granted
hereunder to design or fabricate any integrated circuits. The products are not designed or authorized to be used within any Life Support System without the specific written consent of
Silicon Labs. A "Life Support System" is any product or system intended to support or sustain life and/or health, which, if it fails, can be reasonably expected to result in significant personal
injury or death. Silicon Labs products are not designed or authorized for military applications. Silicon Labs products shall under no circumstances be used in weapons of mass
destruction including (but not limited to) nuclear, biological or chemical weapons, or missiles capable of delivering such weapons.
Trademark Information
Silicon Laboratories Inc.® , Silicon Laboratories®, Silicon Labs®, SiLabs® and the Silicon Labs logo®, Bluegiga®, Bluegiga Logo®, Clockbuilder®, CMEMS®, DSPLL®, EFM®, EFM32®,
EFR, Ember®, Energy Micro, Energy Micro logo and combinations thereof, "the world’s most energy friendly microcontrollers", Ember®, EZLink®, EZRadio®, EZRadioPRO®,
Gecko®, ISOmodem®, Precision32®, ProSLIC®, Simplicity Studio®, SiPHY®, Telegesis, the Telegesis Logo®, USBXpress® and others are trademarks or registered trademarks of Silicon
Labs. ARM, CORTEX, Cortex-M3 and THUMB are trademarks or registered trademarks of ARM Holdings. Keil is a registered trademark of ARM Limited. All other products or brand
names mentioned herein are trademarks of their respective holders.
[Link]