Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Performs a blocking write to a WinI3C-Target immediately followed by a blocking read. This corresponds to an I3C Private Write followed by an I3C Private Read.
This is useful for the common pattern of reading a register, where the register ID is first written to the WinI3C-Target and the subsequent read returns the register value. This is faster and more efficient on the bus than calling WinI3CWrite followed by WinI3CRead.
WinI3CWriteRead is a Library-managed WinI3C API (the recommended way to use WinI3C). For an overlapped equivalent, see WinI3CWriteReadWithFileHandle.
Syntax
_Must_inspect_result_
HRESULT WINAPI WinI3CWriteRead(
_In_ WinI3CTarget target,
_In_ WINI3C_TARGET_MODE writePreferredMode,
_In_reads_opt_(1) const UINT8* writeHdrCommandCode,
_In_ UINT32 writePayloadSize,
_In_reads_bytes_(writePayloadSize) const void* writePayload,
_In_ WINI3C_TARGET_MODE readPreferredMode,
_In_reads_opt_(1) const UINT8* readHdrCommandCode,
_In_ UINT32 requestedReadPayloadSize,
_Out_writes_bytes_to_(requestedReadPayloadSize, *actualReadPayloadSize) void* readPayload,
_Deref_out_range_(0, requestedReadPayloadSize) UINT32* actualReadPayloadSize);
Parameters
[in] target
The WinI3CTarget to write to and read from.
The handle shall have been created by WinI3CInitializeTarget.
[in] writePreferredMode
The preferred WINI3C_TARGET_MODE to use for the write. This is best-effort; the actual mode may differ if the WinI3C-Target/HostController-Instance does not support the requested mode.
[in, optional] writeHdrCommandCode
If writePreferredMode is WinI3CTargetModeHdr, points to the I3C HDR Write Command Code (0x00–0x7F) to use if the transfer is sent as HDR.
Shall be NULL if writePreferredMode is not WinI3CTargetModeHdr.
[in] writePayloadSize
The number of bytes to write. The maximum write size expected by the WinI3C-Target is set with WinI3CSetMaxWriteLength.
- Shall be > 0.
- Shall be <= bufferSize(writePayload).
- Shall be <= 65535 (the maximum I3C transfer size).
- Shall be even (a multiple of 2) when writePreferredMode is WinI3CTargetModeHdr.
[in] writePayload
A client-allocated buffer that contains the payload to write.
Shall not be NULL.
[in] readPreferredMode
The preferred WINI3C_TARGET_MODE to use for the read. This is best-effort; the actual mode may differ if the WinI3C-Target/HostController-Instance does not support the requested mode.
[in, optional] readHdrCommandCode
If readPreferredMode is WinI3CTargetModeHdr, points to the I3C HDR Read Command Code (0x80–0xFF) to use if the transfer is sent as HDR.
Shall be NULL if readPreferredMode is not WinI3CTargetModeHdr.
[in] requestedReadPayloadSize
The number of bytes to read. The maximum read size expected by the WinI3C-Target is set with WinI3CSetMaxReadAndIbiLength.
- Shall be > 0.
- Shall be <= bufferSize(readPayload).
- Shall be <= 65535 (the maximum I3C transfer size).
- Shall be even (a multiple of 2) when readPreferredMode is WinI3CTargetModeHdr.
[out] readPayload
A client-allocated buffer that receives the read payload.
Shall not be NULL.
Valid only when the function returns S_OK.
[out] actualReadPayloadSize
Receives the actual number of bytes read.
This may be less than requestedReadPayloadSize, because a WinI3C-Target may respond with less payload than requested (a short read).
Valid only when the function returns S_OK.
Return value
On success this function returns S_OK.
On failure this function returns an appropriate HRESULT error code, including the following.
| Return code | Description |
|---|---|
| S_OK | Successfully completed both the write and the read. This does not imply that requestedReadPayloadSize bytes were read; see actualReadPayloadSize. |
| E_INVALIDARG | One or more parameters are invalid. |
| E_OUTOFMEMORY | Available memory is insufficient to execute this function. |
| HRESULT_FROM_WIN32(ERROR_DEVICE_NACKED) | The WinI3C-Target (passively) NACKed the write or the read. The client may retry later; consider first calling WinI3CGetStatus to validate that the WinI3C-Target is available. |
| HRESULT_FROM_WIN32(ERROR_DEVICE_NOT_CONNECTED) | The WinI3C-Target is not connected. Destroy the handle with WinI3CRelease. |
| HRESULT_FROM_WIN32(ERROR_DEVICE_HARDWARE_ERROR) | A fatal hardware error occurred (it is not known whether the write or read failed). Destroy the handle with WinI3CRelease. |
Remarks
The maximum write and read sizes expected by the WinI3C-Target are set with WinI3CSetMaxWriteLength and WinI3CSetMaxReadAndIbiLength, respectively.
The read depends on the write succeeding first. If the write fails, the read is not issued and actualReadPayloadSize is 0; if the write succeeds and the read fails, actualReadPayloadSize is also 0. It is not possible to distinguish these two cases. If the distinction matters, issue separate WinI3CWrite and WinI3CRead calls.
This function is thread-safe.
Example
#include <vector>
#include <wini3c.h>
void main()
{
...
std::vector<uint8_t> writePayload = { 0x01, 0x02, 0x03 };
const uint32_t requestedReadPayloadSize = ...;
uint8_t readPayload[requestedReadPayloadSize] = { 0 };
uint32_t actualReadPayloadSize = 0;
if (FAILED(WinI3CWriteRead(
target,
WinI3CTargetModeSdr,
nullptr,
(uint32_t)writePayload.size(),
writePayload.data(),
WinI3CTargetModeSdr,
nullptr,
requestedReadPayloadSize,
readPayload,
&actualReadPayloadSize)))
{
// Handle failure.
}
...
}
Requirements
| Requirement | Value |
|---|---|
| Minimum supported client | Windows 11 25H2 October update (build 26200) |
| Target Platform | Windows |
| Header | wini3c.h |
| DLL | wini3c.dll |