📄 i2csdk.cpp
字号:
I2C_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: I2CEnableSlave
//
// This function enables a I2C slave access from the bus. Note that after
// the I2C slave interface enabled, I2C slave driver wait for master access
// all the time.
//
// Parameters:
// hI2C
// [in] The I2C device handle retrieved from I2COpenHandle().
//
// Returns:
// Return TRUE or FALSE. If the result is TRUE, the operation is
// successful.
//
//-----------------------------------------------------------------------------
BOOL I2CEnableSlave(HANDLE hI2C)
{
I2C_FUNCTION_ENTRY();
if (!DeviceIoControl(hI2C, // file handle to the driver
I2C_IOCTL_ENABLE_SLAVE, // I/O control code
NULL, // in buffer
0, // in buffer size
NULL, // out buffer
0, // out buffer size
NULL, // pointer to number of bytes returned
NULL)) // ignored (=NULL)
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: I2C_IOCTL_ENABLE_SLAVE failed!\r\n"), __WFUNCTION__));
return FALSE;
}
I2C_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: I2CDisableSlave
//
// This function disables I2C slave access from the bus. Note that after
// the I2C slave interface disabled, I2C slave module can be turned off.
//
// Parameters:
// hI2C
// [in] The I2C device handle retrieved from I2COpenHandle().
//
// Returns:
// Return TRUE or FALSE. If the result is TRUE, the operation is
// successful.
//
//-----------------------------------------------------------------------------
BOOL I2CDisableSlave(HANDLE hI2C)
{
I2C_FUNCTION_ENTRY();
if (!DeviceIoControl(hI2C, // file handle to the driver
I2C_IOCTL_DISABLE_SLAVE, // I/O control code
NULL, // in buffer
0, // in buffer size
NULL, // out buffer
0, // out buffer size
NULL, // pointer to number of bytes returned
NULL)) // ignored (=NULL)
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: I2C_IOCTL_DISABLE_SLAVE failed!\r\n"), __WFUNCTION__));
return FALSE;
}
I2C_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: I2CGetSlaveSize
//
// This function returns I2C slave interface buffer length. Note that I2C
// slave driver directly return data to master from interface buffer.
// The interface buffer can be set at any time, even when I2C slave module
// has been turned off.
//
// Parameters:
// hI2C
// [in] The I2C device handle retrieved from I2COpenHandle().
//
// pdwSize
// [Out] Pointer to BYTE variable that retrieves interface buffer length.
//
// Returns:
// Return TRUE or FALSE. If the result is TRUE, the operation is
// successful.
//
//-----------------------------------------------------------------------------
BOOL I2CGetSlaveSize(HANDLE hI2C, PDWORD pdwSize)
{
I2C_FUNCTION_ENTRY();
if (!DeviceIoControl(hI2C, // file handle to the driver
I2C_IOCTL_GET_SLAVESIZE, // I/O control code
NULL, // in buffer
0, // in buffer size
pdwSize, // out buffer
sizeof(DWORD), // out buffer size
NULL, // pointer to number of bytes returned
NULL)) // ignored (=NULL)
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: I2C_IOCTL_GET_SLAVESIZE failed!\r\n"), __WFUNCTION__));
return FALSE;
}
I2C_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: I2CSetSlaveSize
//
// This function sets I2C slave interface buffer length. The max acceptable
// length is I2CSLAVEBUFSIZE. If input length is longer than I2CSLAVEBUFSIZE,
// the operation will fail, and origin buffer length not changed. Note that
// I2C slave driver directly return data to master from interface buffer.
// The interface buffer can be set at any time, even when I2C slave module
// has been turned off.
//
// Parameters:
// hI2C
// [in] The I2C device handle retrieved from I2COpenHandle().
//
// bySize
// [in] Slave interface buffer length.
//
// Returns:
// Return TRUE or FALSE. If the result is TRUE, the operation is
// successful.
//
//-----------------------------------------------------------------------------
BOOL I2CSetSlaveSize(HANDLE hI2C, DWORD dwSize)
{
I2C_FUNCTION_ENTRY();
if (!DeviceIoControl(hI2C, // file handle to the driver
I2C_IOCTL_SET_SLAVESIZE, // I/O control code
&dwSize, // in buffer
sizeof(DWORD), // in buffer size
NULL, // out buffer
0, // out buffer size
NULL, // pointer to number of bytes returned
NULL)) // ignored (=NULL)
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: I2C_IOCTL_SET_SLAVESIZE failed!\r\n"), __WFUNCTION__));
return FALSE;
}
I2C_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: I2CGetSlaveText
//
// This function returns I2C slave interface buffer text. Note that I2C
// slave driver directly returns data to master from interface buffer.
// The interface buffer can be accessed at any time, even when I2C slave
// module has been turned off.
//
// Parameters:
// hI2C
// [in] The I2C device handle retrieved from I2COpenHandle().
//
// pbyTextBuf
// [out] User buffer to store text returned from interface buffer.
//
// dwBufSize
// [in] User buffer size.
//
// pdwTextLen
// [out] Actual data bytes returned.
//
// Returns:
// Return TRUE or FALSE. If the result is TRUE, the operation is
// successful.
//
//-----------------------------------------------------------------------------
BOOL I2CGetSlaveText(HANDLE hI2C, PBYTE pbyTextBuf, DWORD dwBufSize, PDWORD pdwTextLen)
{
I2C_FUNCTION_ENTRY();
if (!DeviceIoControl(hI2C, // file handle to the driver
I2C_IOCTL_GET_SLAVE_TXT, // I/O control code
NULL, // in buffer
0, // in buffer size
pbyTextBuf, // out buffer
dwBufSize, // out buffer size
pdwTextLen, // pointer to number of bytes returned
NULL)) // ignored (=NULL)
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: I2C_IOCTL_GET_SLAVE_TXT failed!\r\n"), __WFUNCTION__));
return FALSE;
}
I2C_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: I2CSetSlaveText
//
// This function stores I2C slave text to interface buffer. Note that
// I2C slave driver directly return data to master from interface buffer.
// The interface buffer can be accessed at any time, even when I2C slave
// module has been turned off.
//
// Parameters:
// hI2C
// [in] The I2C device handle retrieved from I2COpenHandle().
//
// pbyTextBuf
// [out] User buffer to store text to interface buffer.
//
// dwTextLen
// [in] Text length in user buffer.
//
// Returns:
// Return TRUE or FALSE. If the result is TRUE, the operation is
// successful.
//
//-----------------------------------------------------------------------------
BOOL I2CSetSlaveText(HANDLE hI2C, PBYTE pbyTextBuf, DWORD dwTextLen)
{
I2C_FUNCTION_ENTRY();
if (!DeviceIoControl(hI2C, // file handle to the driver
I2C_IOCTL_SET_SLAVE_TXT, // I/O control code
pbyTextBuf, // in buffer
dwTextLen, // in buffer size
NULL, // out buffer
0, // out buffer size
NULL, // pointer to number of bytes returned
NULL)) // ignored (=NULL)
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: I2C_IOCTL_SET_SLAVE_TXT failed!\r\n"), __WFUNCTION__));
return FALSE;
}
I2C_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: DllEntry
//
// This is the entry and exit point for the I2C DDK module. This
// function is called when processed and threads attach and detach from this
// module.
//
// Parameters:
// hInstDll
// [in] The handle to this module.
//
// dwReason
// [in] Specifies a flag indicating why the DLL entry-point function
// is being called.
//
// lpvReserved
// [in] Specifies further aspects of DLL initialization and cleanup.
//
// Returns:
// TRUE if the I2C is initialized; FALSE if an error occurred during
// initialization.
//
//-----------------------------------------------------------------------------
extern "C"
BOOL WINAPI
DllEntry(HANDLE hInstDll, DWORD dwReason, LPVOID lpvReserved)
{
UNREFERENCED_PARAMETER(lpvReserved);
switch (dwReason) {
case DLL_PROCESS_ATTACH:
DEBUGREGISTER((HMODULE)hInstDll);
DEBUGMSG(ZONE_INIT,
(_T("***** DLL PROCESS ATTACH TO I2C SDK *****\r\n")));
DisableThreadLibraryCalls((HMODULE) hInstDll);
break;
case DLL_PROCESS_DETACH:
DEBUGMSG(ZONE_INIT,
(_T("***** DLL PROCESS DETACH FROM I2C SDK *****\r\n")));
break;
}
// return TRUE for success
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -