From 92790330f1081f3bfc1d426589688e3194ff6f02 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Fri, 19 Mar 2021 13:02:53 -0400 Subject: [PATCH] macOS: STM32: Fix device finding for newer versions of the OS --- platform/posix/darwin/stm32darwin.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/platform/posix/darwin/stm32darwin.cpp b/platform/posix/darwin/stm32darwin.cpp index 12ba134..5e429be 100644 --- a/platform/posix/darwin/stm32darwin.cpp +++ b/platform/posix/darwin/stm32darwin.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include using namespace icsneo; @@ -104,15 +105,12 @@ std::vector STM32::FindByProduct(int product) { io_object_t usb = 0; // Need to release every parent we find in the chain, but we should defer that until later std::vector releasers; - const std::string usbClass = "IOUSBDevice"; while(IORegistryEntryGetParentEntry(current, kIOServicePlane, &parent) == KERN_SUCCESS) { releasers.emplace_back(parent); current = parent; - io_name_t className; - // io_name_t does not need to be freed, it's just a stack char[128] - if(IOObjectGetClass(parent, className) != KERN_SUCCESS) - continue; - if(std::string(className) == usbClass) { + // On old macOSes, IOUSBDevice is the type of the class we want + // On newer macOSes, IOUSBDevice may further be subclassed as IOUSBHostDevice + if(IOObjectConformsTo(parent, kIOUSBDeviceClassName)) { usb = parent; break; }