An496 Hid Usb To Smbus Api Specification
An496 Hid Usb To Smbus Api Specification
Specification
The library provides interface abstraction so that users can develop their application • The CP2112 library enables application
without writing any USB HID Code. C libraries implementing the CP2112 Interface development and device configuration on
Specification are provided for Windows 2000 and later and Mac OS X 10.5 and later. multiple platforms and operating systems.
Similarly, various include files are provided to import library functions into C# .NET, and
Visual Basic .NET. Refer to the table in 1. Include Files for complete details.
User Application
HID Driver
(Provided by OS)
USB
SMBus Devices
silabs.com | Building a more connected world. Copyright © 2023 by Silicon Laboratories Rev. 0.4
AN496: HID USB-to-SMBus API Specification
Include Files
1. Include Files
The files required for application development using the CP2112 API are listed in the following table:
SLABCP2112.h (C/C++)
SLABCP2112.vb(VB .NET)
Note:
1. Requires SLABHIDDevice.dll version 1.5 during runtime.
2. Library binaries are provided for Ubuntu 16.x for i386 and amd64 (32-bit and 64-bit x86 processors). Source packages are availa-
ble in the CP2112 Software Development Kit (www.silabs.com/interface-software), which can be modified and compiled for addi-
tional platforms.
3. Requires the libslabhiddevice.so.1.0 HID library during runtime.
2. API Functions
Definition Description
HidSmbus_GetAttributes() Returns the VID, PID, and release number for a device by index
HidSmbus_GetOpenedAttributes() Returns the VID, PID and release number for a device by device object pointer
HidSmbus_ReadRequest() Initiates a fixed length read request to the desired slave device
Initiates a fixed length read request to the desired slave device specifying the memo-
HidSmbus_AddressReadRequest()
ry address to read
HidSmbus_SetSmbusConfig() Sets the bit rate, master address, timeouts, and transfer settings
HidSmbus_GetSmbusConfig() Gets the bit rate, master address, timeouts, and transfer settings
2.1 HidSmbus_GetNumDevices
Description : This function returns the number of devices connected to the host with matching vendor and product
ID (VID, PID).
WORD pid)
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.
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 devi-
ces will not be filtered by VID/PID.
4. deviceString—is a variable of type HID_SMBUS_DEVICE_STR, which will contain a null-termina-
ted ASCII device string on return. The string is 260 bytes on Windows and Linux 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.
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.
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).
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 devi-
ces 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.
2.5 HidSmbus_GetOpenedIndexedString
Description : This function returns a null-terminated USB string descriptor for the device specified by device (Win-
dows Only).
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.
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 devi-
ces 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.
2.7 HidSmbus_GetOpenedAttributes
Description : This function returns the device vendor ID, product ID, and release number for the device specified
by device.
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.
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 devi-
ces will not be filtered by VID/PID.
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().
2.10 HidSmbus_IsOpened
BOOL* opened)
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
2.22 HidSmbus_SetSmbusConfig.
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.
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 2.22 HidSmbus_SetSmbusConfig.
BYTE targetAddress[16])
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.
WORD numBytesToRead)
2.14 HidSmbus_GetReadResponse
Description : This function returns the read response to a read request. Read and write timeouts as well as trans-
fer retries can be set using HidSmbus_SetSmbusConfig() as described in 2.22 HidSmbus_SetSm-
busConfig.
BYTE* numBytesRead)
Remarks : HidSmbus_GetReadResponse() waits for up to readTimeout milliseconds for the device to send a
read response interrupt report to the host. This function should be called repeatedly until all read data
has been received or an error occurs. Call HidSmbus_ReadRequest() or
HidSmbus_AddressReadRequest() followed by HidSmbus_GetReadResponse() to read data when
autoReadResponse is enabled using HidSmbus_SetSmbusConfig(). HidSmbus_GetReadResponse()
will wait for up to responseTimeout milliseconds before returning HID_SMBUS_READ_TIMED_OUT.
2.15 HidSmbus_WriteRequest
Description : This function writes the specified number of bytes from the supplied buffer to the specified slave de-
vice 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.
2.16 HidSmbus_TransferStatusRequest
Description : This function requests the status of the current read or write transfer.
2.17 HidSmbus_GetTransferStatusResponse
Description : This function returns the status of the current read or write transfer.
WORD* bytesRead)
During initialization, the CP2112-F03 device tests for SCL and/or SDA being stuck low. For more
information, see AN495: CP2112 Interface Specification.
Initial (first) Transfer Status Request 1xxx xxxx SDA line is stuck low.
HID_SMBUS_S1_ERROR_TIMEOUT_BUS_NOT_FREE 0x01 Tranfser timeout: SMBus not free (or SCL low
timeout occurred)
2.18 HidSmbus_CancelTransfer
2.19 HidSmbus_Cancello
Description : This function cancels any pending HID reads and writes (Windows Only).
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 be-
tween 1 and 0xFFFFFFFF. Specifying a response timeout of 0, will wait indefinitely.
DWORD responseTimeout)
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 val-
ue of 0 indicates an infinite timeout.
DWORD* responseTimeout)
Remarks : Timeouts are maintained for each device but are not persistent across HidSmbus_Open()/
HidSmbus_Close().
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.
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.
WORD* transferRetries)
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.
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.
2.25 HidSmbus_SetGpioConfig
Description : This function configures the GPIO pins’ directions and modes.
HID_SMBUS_DIRECTION_INPUT 0 Input
HID_SMBUS_DIRECTION_OUTPUT 1 Output
3. mode—is 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—is a bitmask that specifies the special behavior of GPIO.0, GPIO.1, and GPIO.7.
GPIO.0 - TX Toggle
(push-pull output)
GPIO.1 - RX Toggle
(push-pull output)
2.26 HidSmbus_GetGpioConfig
Description : This function returns the GPIO pins’ directions and modes.
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.
GPIO.0 - TX Toggle
(push-pull output)
GPIO.1 - RX Toggle
(push-pull output)
2.27 HidSmbus_ReadLatch
BYTE* latchValue)
Remarks : If a pin is configured as an input, then the latchValue bit represents the logical voltage level re-
ceived 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.
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
Remarks : Only GPIO pins configured as outputs with their corresponding latchMask bits set can be written to.
2.29 HidSmbus_GetPartNumber
Description : This function retrieves the part number and version of the CP2112 device.
2.30 HidSmbus_GetLibraryVersion
Description : This function returns the HID USB-to-SMBus Interface Library version.
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.
2.31 HidSmbus_GetHidLibraryVersion
Description : This function returns the version of the HID Device Interface Library that is currently in use.
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.
2.32 HidSmbus_GetHidGuid
Description : This function obtains the HID GUID. This can be used to register for surprise removal notifications
(Windows Only).
The following parameters are programmable on the device. Different functions are provided to program these parameters. Each param-
eter may only be programmed once and only if the parameter is not locked.
Bus Powered
The following API functions are provided to allow user customization/one-time programming:
Definition Description
HidSmbus_SetUsbConfig() Sets VID, PID, power, power mode, and release version
HidSmbus_GetUsbConfig() Gets VID, PID, power, power mode, and release version
3.1 HidSmbus_SetLock
Remarks : When this function is successfully called, the specified fields are fully locked and cannot be further
customized. The user customization functions can be called and may return HID_SMBUS_SUCCESS
even though the device was not programmed. Call the function’s corresponding get function to verify
that customization was successful. Each field is stored in one time programmable memory (OTP) and
can only be customized once. After a field is customized, the corresponding lock bits are set to 0.
3.2 HidSmbus_GetLock
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 pro-
grammed one time via the mask field.
WORD vid, WORD pid, BYTE power, BYTE powerMode, WORD releaseVersion,
BYTE mask)
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.
WORD* releaseVersion)
3.5 HidSmbus_SetManufacturingString
Description : This function allows one-time customization of the USB manufacturing string.
3.6 HidSmbus_GetManufacturingString
3.7 HidSmbus_SetProductString
Description : This function allows one-time customization of the USB product string.
3.8 HidSmbus_GetProductString
3.9 HidSmbus_SetSerialString
Description : This function allows one-time customization of the USB serial string.
3.10 HidSmbus_GetSerialString
Each library function returns an HID_SMBUS_STATUS return code to indicate that the function returned successfully or to describe an er-
ror. The following table describes each error code.
Indicates that the device object pointer does not match the
HID_SMBUS_INVALID_DEVICE_OBJECT 0x03
address of a valid HID USB-to-SMBus device.
Indicates that the read was not successful and did not time
HID_SMBUS_READ_ERROR 0x10 out. This means that the host could not get an input inter-
rupt report.
Indicates that the current device does not support the cor-
HID_SMBUS_DEVICE_NOT_SUPPORTED 0x16 responding action. Functions listed in this document are
for the CP2112 only.
Note:
1. Set functions may return success, indicating that the device received the request; however, there is no indication that the device
actually performed the request (i.e., the setting was invalid). The user must call the corresponding get function to verify that the
settings were properly configured.
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 accessi-
ble 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 for more information.
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 ta-
bles describe five common access models and the expected behavior.
Note:
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
HidSmbus_Open() — —
QueueInterruptReports()? QueueInterruptReports()? —
QueueInterruptReports()* Thread B:
HidSmbus_Open() — —
QueueInterruptReports()? QueueInterruptReports()? —
— HidSmbus_CancelIo() —
HidSmbus_Close() — OK
HidSmbus_GetHidGuid() returns the HID GUID so that Windows applications or services can register for the WM_DEVICECHANGE Win-
dows 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 appli-
cation 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. The following KnowledgeBase articles include programming
examples for C++, Visual Basic .NET, and Visual C#:
• C++—
• https://community.silabs.com/s/article/Obtaining-Device-Notification-for-USB-Device-Arrival-and-Surprise-Removal-for-C-MFC
• Visual Basic .NET—
• https://community.silabs.com/s/article/obtaining-device-notification-for-usb-device-arrival-and-surprise-removal-for-vi
• Visual C#—
• https://community.silabs.com/s/article/obtaining-device-notification-for-usb-device-arrival-and-surprise-removal-for-c-1
• https://community.silabs.com/s/article/obtaining-device-notification-for-usb-device-arrival-and-surprise-removal-for-c-x
December, 2022
• Updated 2.13 HidSmbus_ForceReadResponse in Remark section: change HidSmbus_TransferStatusResponse to HidSmbus_Get-
TransferStatusResponse.
• Updated 2.18 HidSmbus_CancelTransfer in Prototype section: change HidSmbus_TransferStatusRequest to HidSmbus_Cancel-
Transfer.
• Updated the links to the Knowledge Base Articles discussing Surprise Removal in 7. Surprise Removal (For Windows).
Updated formatting.
Updated the links to the KnowledgeBase articles discussing Surprise Removal in 7. Surprise Removal (For Windows).
November 2010
Removed Appendix.
May 2010
Initial release.
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 imple-
menters 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 to the product information, specifications, and descriptions herein, and does not give warranties as to the
accuracy or completeness of the included information. Without prior notification, Silicon Labs may update product firmware during the manufacturing process for security or
reliability reasons. Such changes will not alter the specifications or the performance of the product. Silicon Labs shall have no liability for the consequences of use of the infor-
mation supplied in this document. This document does not imply or expressly grant any license to design or fabricate any integrated circuits. The products are not designed or
authorized to be used within any FDA Class III devices, applications for which FDA premarket approval is required or Life Support Systems 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. Silicon Labs disclaims
all express and implied warranties and shall not be responsible or liable for any injuries or damages related to use of a Silicon Labs product in such unauthorized applications.
Note: This content may contain offensive terminology that is now obsolete. Silicon Labs is replacing these terms with inclusive language wherever possible. For more
information, visit www.silabs.com/about-us/inclusive-lexicon-project
Trademark Information
Silicon Laboratories Inc. ® , Silicon Laboratories ® , Silicon Labs ® , SiLabs ® and the Silicon Labs logo ® , Bluegiga ® , Bluegiga Logo ® , EFM ® , EFM32 ® , EFR, Ember® , Energy Micro, Energy
Micro logo and combinations thereof, “the world’s most energy friendly microcontrollers”, Redpine Signals ® , WiSeConnect , n-Link, ThreadArch ® , EZLink® , EZRadio ® , EZRadioPRO ® ,
Gecko ® , Gecko OS, Gecko OS Studio, Precision32 ® , Simplicity Studio ® , Telegesis, the Telegesis Logo ® , USBXpress ® , Zentri, the Zentri logo and Zentri DMS, Z-Wave ® , 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. Wi-Fi is a registered trademark of the Wi-Fi Alliance. All other products or brand names mentioned herein are trademarks of their respective holders.
35
Silicon Laboratories Inc.
400 West Cesar Chavez