ZakKemble / libmcp2221

MCP2221 HID Library
https://blog.zakkemble.net/mcp2221-hid-library/
GNU General Public License v3.0
53 stars 14 forks source link

no MCP2221s found #6

Closed anon1a1 closed 2 years ago

anon1a1 commented 2 years ago

I am trying on the examples i2c on my Raspberry-Pi. I turn on DEBUG_INFO_HID by setting it to 1

when compiled and running ./i2c, I get the following Starting! Looking for devices... Device Found type: 04d8 00dd path: /dev/hidraw0 serial_number: Manufacturer: Microchip Technology Inc. Product: MCP2221 USB-I2C/UART Combo Release: 100 Interface: 2

Device Found type: 04d8 00dd path: /dev/hidraw1 serial_number: Manufacturer: Microchip Technology Inc. Product: MCP2221 USB-I2C/UART Combo Release: 100 Interface: 2

found 2 devices Opening device... No MCP2221s found From the messages above, I would have gotten a list of devices and my devList data should not be void.

But looking at the code

` mcp2221_t* myDev = mcp2221_open();

if(!myDev) { mcp2221_exit(); puts("No MCP2221s found"); getchar(); return 0; } Checking MCP2221_open(), I see mcp2221_t* LIB_EXPORT mcp2221_open() { if(devList) return open(devList->devPath); return NULL; }

This leads to me checking int LIB_EXPORT mcp2221_find(int vid, int pid, wchar_t manufacturer, wchar_t product, wchar_t* serial) { int count = 0;

clearUsbDevList();

struct hid_device_info allDevices = hid_enumerate(vid, pid); struct hid_device_info currentDevice; currentDevice = allDevices;

while (currentDevice) { debug_printf("Device Found\n type: %04hx %04hx\n path: %s\n serial_number: %ls", currentDevice->vendor_id, currentDevice->product_id, currentDevice->path, currentDevice->serial_number ? currentDevice->serial_number : L"(NONE)"); debug_printf("\n"); debug_printf(" Manufacturer: %ls\n", currentDevice->manufacturer_string); debug_printf(" Product: %ls\n", currentDevice->product_string); debug_printf(" Release: %hx\n", currentDevice->release_number); debug_printf(" Interface: %d\n", currentDevice->interface_number); debug_printf("\n");

if(
    checkThing(currentDevice->manufacturer_string, manufacturer) &&
    checkThing(currentDevice->product_string, product) &&
    checkThing(currentDevice->serial_number, serial)
)
{
    addUsbDevList(count, currentDevice);
    count++;
}
currentDevice = currentDevice->next;

}

hid_free_enumeration(allDevices);

return count; }`

So why is devList empty based on how addUsbDevList is written. See below

`static void addUsbDevList(int id, struct hid_device_info dev2) { device_list_t dev = devList; if(dev != NULL) // Root is defined { // Find last item for(;dev->next;dev = dev->next);

// Make next item
dev->next = malloc(sizeof(device_list_t));
dev = dev->next;

} else // No root, need to make it { // Make root item devList = malloc(sizeof(device_list_t)); dev = devList; }

// Assign data dev->next = NULL;

// TODO use wcsdup and stuff here instead of malloc?

// Path dev->devPath = malloc(strlen(dev2->path) + 1); strcpy(dev->devPath, dev2->path);

// Serial if(!dev2->serial_number) dev->serial = NULL; else { int len = wcslen(dev2->serial_number); dev->serial = malloc((len * sizeof(wchar_t)) + sizeof(wchar_t)); wcsncpy(dev->serial, dev2->serial_number, len); dev->serial[len] = L'\0'; }

dev->id = id; }`

anon1a1 commented 2 years ago

I resolved it... it is a permissions problem. Thanks everyone!