Giter Club home page Giter Club logo

libmcp2221's Introduction

Hey there!

Twitter Blog

Languages

C C++ C#

TypeScript JavaScript PHP

Electronics & Embedded

Raspberry Pi Arduino ESP ARM

EAGLE CAD Altium Designer

Web Things

NodeJS Nginx MongoDB MySQL

AWS Heroku

libmcp2221's People

Contributors

mdenzinger avatar zakkemble avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libmcp2221's Issues

linker error using version 1.04: libmcp2221.dll: file not recognized: File format not recognized

Hi there,

I'm trying to use this precompiled dll from 30 december 2016:
https://github.com/zkemble/libmcp2221/tree/54b04e4526ef786744bde26f879aa4aa3a62b101/lib/win/libmcp2221.dll

During linking of my Qt program, I get this error messages:
/some/where/libmcp2221.dll: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status

Next I try to use this version: from 30 december 2016:
https://github.com/zkemble/libmcp2221/blob/021bcd5973a83fb58ffa8fdf020b57157c10f456/lib/win/libmcp2221.dll
Now I don't get errors during the linking of my Qt program.

My versions:
Windows 7 Enterprise SP1
Qt creator 4.7.2
Qt 5.11.1 compiled with minGW 5.3.0 32 bit
MinGW 5.3.0 32 bit compiler

To reproduce:
Start Qt creator
File->new File or Project ->Application->Qt Widgets Application->choose.
Name: MCP2221 -> next
Select kit: Desktop Qt 5.11.1 MinGW 32 bit-> next -> next
Add to version control: git -> finish
(As a sanity check, start debugging by pressing F5, an empty window called "MainWindow" should pop up)

Download libmcp2221 from here, and extract it in the same directory as the file MCP2221.pro
https://github.com/zkemble/libmcp2221/archive/54b04e4526ef786744bde26f879aa4aa3a62b101.zip

Add this line to MCP2221.pro:
win32:LIBS += "$$PWD/lib/win/libmcp2221.dll"

Add this line to main.cpp:
#include "lib/libmcp2221.h"

Press F5 to debug. This is the resulting compile output:
12:42:03: Running steps for project MCP2221... 12:42:03: Configuration unchanged, skipping qmake step. 12:42:04: Starting: "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" C:/Qt/5.11.1/mingw53_32/bin/qmake.exe -o Makefile ../MCP2221/MCP2221.pro -spec win32-g++ CONFIG+=debug CONFIG+=qml_debug C:/Qt/Tools/mingw530_32/bin/mingw32-make -f Makefile.Debug mingw32-make[1]: Entering directory 'C:/Users/crldewijs/Desktop/New folder (2)/build-MCP2221-Desktop_Qt_5_11_1_MinGW_32bit-Debug' g++ -Wl,-subsystem,windows -mthreads -o debug/MCP2221.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o -lmingw32 -LC:/Qt/5.11.1/mingw53_32/lib C:/Qt/5.11.1/mingw53_32/lib/libqtmaind.a -LC:/openssl/lib -LC:/Utils/my_sql/mysql-5.6.11-win32/lib -LC:/Utils/postgresql/pgsql/lib -lshell32 C:/Qt/5.11.1/mingw53_32/lib/libQt5Cored.a "C:/Users/crldewijs/Desktop/New folder (2)/MCP2221/lib/win/libmcp2221.dll" C:/Qt/5.11.1/mingw53_32/lib/libQt5Widgetsd.a C:/Qt/5.11.1/mingw53_32/lib/libQt5Guid.a C:/Qt/5.11.1/mingw53_32/lib/libQt5Cored.a C:/Users/crldewijs/Desktop/New folder (2)/MCP2221/lib/win/libmcp2221.dll: file not recognized: File format not recognized collect2.exe: error: ld returned 1 exit status Makefile.Debug:67: recipe for target 'debug/MCP2221.exe' failed mingw32-make[1]: Leaving directory 'C:/Users/crldewijs/Desktop/New folder (2)/build-MCP2221-Desktop_Qt_5_11_1_MinGW_32bit-Debug' mingw32-make[1]: *** [debug/MCP2221.exe] Error 1 Makefile:36: recipe for target 'debug' failed mingw32-make: *** [debug] Error 2 12:42:09: The process "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" exited with code 2. Error while building/deploying project MCP2221 (kit: Desktop Qt 5.11.1 MinGW 32bit) When executing step "Make" 12:42:09: Elapsed time: 00:05.

no MCP2221s found

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;
}`

compile with mingw

PS C:\Users\numeru55\Downloads\libmcp2221-master\libmcp2221-master\examples\gpio> mingw32-make.exe
gcc -s main.o -lmcp2221 -o gpio
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: main.o:main.c:(.text.startup+0x25): undefined reference to `mcp2221_init'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: main.o:main.c:(.text.startup+0x5d): undefined reference to `mcp2221_find'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: main.o:main.c:(.text.startup+0x7e): undefined reference to `mcp2221_open'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: main.o:main.c:(.text.startup+0xab): undefined reference to `mcp2221_GPIOConfInit'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: main.o:main.c:(.text.startup+0xe8): undefined reference to `mcp2221_setGPIOConf'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: main.o:main.c:(.text.startup+0xf7): undefined reference to `mcp2221_saveGPIOConf'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: main.o:main.c:(.text.startup+0x133): undefined reference to `mcp2221_readGPIO'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: main.o:main.c:(.text.startup+0x167): undefined reference to `mcp2221_exit'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: main.o:main.c:(.text.startup+0x1ba): undefined reference to `mcp2221_setGPIO'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: main.o:main.c:(.text.startup+0x1e9): undefined reference to `mcp2221_readGPIO'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: main.o:main.c:(.text.startup+0x22f): undefined reference to `mcp2221_setGPIO'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: main.o:main.c:(.text.startup+0x25e): undefined reference to `mcp2221_readGPIO'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: main.o:main.c:(.text.startup+0x2a4): undefined reference to `mcp2221_setGPIO'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: main.o:main.c:(.text.startup+0x2b6): undefined reference to `mcp2221_exit'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: main.o:main.c:(.text.startup+0x302): undefined reference to `hid_error'
collect2.exe: error: ld returned 1 exit status
Makefile:32: recipe for target 'gpio' failed
mingw32-make: *** [gpio] Error 1
PS C:\Users\numeru55\Downloads\libmcp2221-master\libmcp2221-master\examples\gpio>

Compiling for Mac (Ventura)

Hi,

FYI, i had to use the extra options '-framework CoreFoundation -framework IOKit' instead of '-ludev' when compiling for Mac with clang.
You may want to have a special section in the Makefile for it.

Also, '-static-gcc' is not recognized by clang, although '-static-libstdc++' is.

Thanks!

Licensing: please consider releasing your library as LGPL.

I am building programs for research purposes. My boss don't allow me to release the entire program as open source yet. Therefore I build the business logic as proprietary, and the infrastructure as LGPL. Then I statically link the proprietary program to the LGPL infrastructure.

I would like to use your mcp2221 driver, so I have a way to access i2c in windows.

Your driver is released as GPL. As far as I know the GPL license does not allow statically linking to it from LGPL code, so I can't use your driver in my LGPL code.

Would you consider to release your driver as LGPL as well, so I can integrate it into my LGPL code?

Cheers,
Cedric

Can't connect to MCP2221a - Segmentation Fault

Hello,

I have acquired an MCP2221a breakout board.
I have been able to use it successfully with their guide, and python board and digitalio libraries, which also makes use of the hidapi.
However, I need to use C/C++ for sure so I am trying to use this library.
The problem seems to come from inside the hidapi library but maybe someone has encountered this problem or there is some extra configuration I have to do with the MCP2221a.

I have been trying to use libmcp2221 and compiled the libraries as per described in the readme, but I am having a segmentation fault error when running the examples.
I am using the example (mainly gpio) but the same problem occurs in the other examples.

Problem

In the main code of libmcp2221 gpio example, mcp2221_find method is called:

int count = mcp2221_find(MCP2221_DEFAULT_VID, MCP2221_DEFAULT_PID, NULL, NULL, NULL);

This method then calls hid_enumerate() from hid.c, which in turn calls parse_uevent_info(), also from hid.c.
I have managed to trace back that the Segmentation fault (core dumped) comes from this parse_uevent_info() method.

What has been tried

Running GDB with original code

In the original hid.c code,
the method parse_uevent_info is declared as follows:

static int
parse_uevent_info(const char *uevent, int *bus_type,
	unsigned short *vendor_id, unsigned short *product_id,
	char **serial_number_utf8, char **product_name_utf8)

When this method is being called by hid_enumerate() inside hid.c, the following is obtained with gdb:

Program received signal SIGSEGV, Segmentation fault.
__GI___strtok_r (
    s=0x5556b780 <error: Cannot access memory at address 0x5556b780>, 
    delim=0x7fffffffd270 "", save_ptr=0x0) at strtok_r.c:49
49	strtok_r.c: No such file or directory.

where 0x5556b780 is the memory address of uevent passed as an argument to parse_uevent_info().
This comes from the line:
line = strtok_r(tmp, &saveptr);

The problem always seems to be in accessing tmp variable.

Running GDB with code changes

After identifying that the problem is in the call of tmp variable inside parse_uevent_info() I tried to play a bit with the code inside hid.c.

Removed constness of uevent argument just to test if I could call strtok_r with it.
and obtained a segmentation fault further along, in

Passed through: line = strtok_r(tmp, "\n", &saveptr); but (with gdb) got:

Program received signal SIGSEGV, Segmentation fault.
__strchr_avx2 () at ../sysdeps/x86_64/multiarch/strchr-avx2.S:57
57	../sysdeps/x86_64/multiarch/strchr-avx2.S: No such file or directory.
or segmentation fault at value = strchr(line, '=');

I tried other small changes like this but always reached a segmentation fault.

Assert

Tried using assert()

#include <assert.h>
assert(strcmp(uevent, tmp) == 0);

but I obtained segmentation fault in the assert() call.

MCP2221 Windows Utility

I installed MCP2221 Utility, which can be downloaded from this link under Documents.
This showed that the values of VID and PID are indeed the default defined in libmcp2221.h:

#define MCP2221_DEFAULT_VID		0x04D8	/**< Default VID */
#define MCP2221_DEFAULT_PID		0x00DD	/**< Default PID */

This two values are the two arguments sent to hid_enumerate() and I confirmed that they are correct in the Windows Utility.

Valgrind

I have also tried to use valgrind. When I launch the gpio example with valgrind, the segmentation fault does not occur. This behaviour is actually described in their FAQ.
But I obtain the following:

found 1 devices
Opening device... No MCP2221s found

I am pretty sure that device is the actual mcp2221a as when I remove it and run the program no device is detected.
This FAQ explains how valgrind may alter the memory environment of a program and why segmentation fault does not occur.

-> I am wondering if this has anything to do with some environmental setup or if someone had to do any extra step.

Some specs:

  • I am running on Ubuntu 20.
  • I have libudev-dev and libusb-1.0-0-dev up to date.

I would really appreciate any help or guidance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.