in BusTools/GpioTestTool/main.cpp [130:166]
void ListPins ()
{
auto controller = MakeDefaultController();
INT32 pinCount;
HRESULT hr = controller->get_PinCount(&pinCount);
if (FAILED(hr)) {
throw wexception(L"Failed to get pin count. (hr = 0x%x)", hr);
}
wprintf(L"The default GPIO controller has %d pins:\n", pinCount);
for (INT32 pinNumber = 0; pinNumber < pinCount; ++pinNumber) {
ComPtr<IGpioPin> pin;
hr = controller->OpenPin(pinNumber, pin.GetAddressOf());
switch (hr) {
case S_OK:
wprintf(L" Pin %d is available\n", pinNumber);
break;
case __HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION):
wprintf(L" Pin %d is currently in use\n", pinNumber);
break;
case __HRESULT_FROM_WIN32(ERROR_NOT_FOUND):
// pin is not available to applications; don't print anything
break;
case __HRESULT_FROM_WIN32(ERROR_GPIO_INCOMPATIBLE_CONNECT_MODE):
wprintf(
L" Pin %d is currently muxed to a different function\n",
pinNumber);
break;
default:
wprintf(
L" Pin %d: unexpected error occurred attempting to open. (hr = 0x%x)\n",
pinNumber,
hr);
}
}
}