I have written the following code in an attempt to use the iaioi2c.sys I2C driver on the E3800 Bay Trail. Everything appears good until I try to execute CreateFile which fails with an ERROR_FILE_NOT_FOUND code. What am I doing wrong?
HDEVINFO DeviceInfoSet;
SP_DEVINFO_DATA DeviceInfoData;
SP_DEVICE_INTERFACE_DATA DeviceInterfaceData;
PSP_DEVICE_INTERFACE_DETAIL_DATA DeviceInterfaceDetailData = NULL;
PDWORD requiredSize;
DWORD Index = 0;
HANDLE tempHandle;
WCHAR *i2cDevice = I2C_CONTROLLER_NUM;
DWORD LastError;
DWORD status = SUCCESS;
DeviceInfoSet = SetupDiGetClassDevs((GUID*)&I2C_LPSS_INTERFACE_GUID, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (DeviceInfoSet == INVALID_HANDLE_VALUE)
return status = INVALID_HANDLE;
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
SetupDiEnumDeviceInfo(DeviceInfoSet, Index, &DeviceInfoData);
while (SetupDiEnumDeviceInfo(DeviceInfoSet, Index, &DeviceInfoData))
{
DeviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
SetupDiCreateDeviceInterface(DeviceInfoSet, &DeviceInfoData, &DeviceInfoData.ClassGuid, NULL, 0, &DeviceInterfaceData);
// call the first time to get required buffer size
requiredSize = (PDWORD)malloc(sizeof(DWORD));
status = SetupDiGetDeviceInterfaceDetail(DeviceInfoSet, &DeviceInterfaceData, NULL, 0, requiredSize, NULL);
LastError = GetLastError();
if (status == FALSE && LastError != ERROR_INSUFFICIENT_BUFFER)
{
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
return LastError;
}
// allocate required buffer
if (requiredSize)
DeviceInterfaceDetailData = (PSP_INTERFACE_DEVICE_DETAIL_DATA)malloc(*requiredSize);
if (DeviceInterfaceDetailData == NULL)
{
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
return status = INSUFFICIENT_MEMORY;
}
// call the second time to get detailed info
DeviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
status = SetupDiGetDeviceInterfaceDetail(DeviceInfoSet, &DeviceInterfaceData, DeviceInterfaceDetailData, *requiredSize, NULL, &DeviceInfoData);
if (status == FALSE)
{
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
return GetLastError();
}
// check for i2c controller #1
if (wcsstr(DeviceInterfaceDetailData->DevicePath, i2cDevice) != NULL)
break;
Index++;
}
tempHandle = CreateFile(DeviceInterfaceDetailData->DevicePath,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);