-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix SPIDEV interface #315
fix SPIDEV interface #315
Conversation
struct spi_ioc_transfer tr; | ||
memset(&tr, 0, sizeof(tr)); | ||
tr.tx_buf = (unsigned long)&tx; | ||
tr.rx_buf = (unsigned long)&tx; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of tx for output and input buffers is innecessarily grubby - why not leave rx as a separate entity?
|
||
struct spi_ioc_transfer tr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's polite to stick to the indentation style of the existing code, so you should be using tabs not spaces.
This commit doesn't fix anything that was strictly wrong, but gets rid of some code that looks complicated and unnecessary. In particular, I removed many includes from the header since they weren't needed by the header. The includes needed in the C file are included there. This way, client code doesn't get all of those things. Admittedly, this could break client code that relied on those includes being there. I also moved member variables to stack variables, and removed the virtual declaration for the destructor. In the C code, I removed the use of the mutex since I couldn't see what purpose it served. I don't think these changes will affect anyone since the code didn't work before the cs fix. @pelwell I made the stylistic fixes you mentioned, but in the process I noticed that the previous code wasn't consistent in it's use of tabs vs spaces or whether lines were indented by 4 or 2 spaces. I also removed trailing whitespace from all lines that contained that since that's something that bugs me. |
Seems that this commit breaks ability to use spidev, at least on a beaglebone black with /dev/spidev0.0 - /dev/spidev0.1 enabled EDIT : I confirm issue is related to this commit. I try to use spi.h and spi.cpp from lemariva fork, rebuild, and it's working as before |
@razerraz The error is rather verbose. It can't find the interface. Make it print out the device it tries to open and see if the user you're executing the program has permissions to access it. |
I've tried it as root |
@razerraz more information would help. I take it you are calling this from python, how? Can get debug output from the C code? The code in question is in spi.cpp: `
` Also, it could help to know what tools you are using for the build: As a possible fix, would you try ` ` in place of the line This spells out explicitly the initialization of the device variable, and may work better on your compiler. |
I'll try your fix & debug stuff this weekend. Feedback soon |
So, seems it's time spend for nothing |
I agree it's disconcerting when the diagnostic doesn't make any sense. However, if adding a function call (the printf) changes the operation of the code, I'd say that points to an optimization bug in the compiler. Since you've already spent the time to set up this test, would you try the fix I recommended before? In my experience, compiler bugs can be worked around by changing the form, but not the function of the code. I think that explicitly initializing the device variable as I suggested above is worth a try. |
I was not clear in my post : it's working now without any changes, building directly from the git repo. |
Ok, thanks for clearing that up. |
fix several errors:
struct spi_ioc_transfer tr; was not initialized to zero.
initializer did not set the proper members.
cs_change = 0 causes incorrect csn behaviour.
using namespace std; can cause name conflicts in client code.