-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
SPI.h: remove unused variable warnings #414
Conversation
Thumbs up for building with warnings enabled 👍 About those variables, are they used anywhere? Can they be outright deleted? |
Yes they are used so they can't be deleted (otherwise I'll have proposed so). |
Wait: they are used but you have to mark them as "unused"? |
It's directly used in SPI.cpp: |
I think the solution for this warning should look different. |
If you are open to that then I'll fix the root cause. |
Ok done. I've moved the variables declaration where they should be. |
Now it looks fine to me, but I think it should be first tested if it still works as expected. |
That's why I was proposing the first option to just get rid of the warnings without touching the code... There was no testing needed and no brainer to merge. |
The corrections look right to me. It was always my intention to move them within the class, but I forgot. @stevstrong about the ff variable. Since the port can be configured in 16bit mode, I have been thinking for a while that we should perhaps declare that as ffff = 0xFFFF so it can be used to see FF repeatedly when in 16 bit mode. Otherwise we may be sending a random byte. |
yepp, it was also once a concern of mine, as I reviewed your changes. |
Hold on this, Seems like you are just moving them to the cpp file but keeping them outside the class.
Let me test this out. I remember during development of the callback part I had some problem that prompted me to move them out of the class and declared as void*, but the problem was likely caused by something else and I should have moved them back to the class after resolving it, that's why I put a note on them. |
@stevstrong which added functions are you referring to? the ones I added a while back, to be able to use callbacks and return inmediately, they work as the ones before, only I split them in 2 parts, one part does the DMA setup that doesn't change between calls if the buffer doesn't change, and the other part just sets the count of bytes/in16 to send, and fires DMA, but as far as 16 bit compatibility they are like they used to be, can send both 8bit or 16bit depending on which mode the SPI peripheral is. |
Today I made the changes to move spi1_this etc to inside the class, not just to the cpp file, but to be part of the class. Also used 0xFFFF for the ff variable, and tested all with a display in spi2 and sdfat in spi1, the display using 16bit mode, and both using callbacks. The display does not ever send FFFF, since it doesn't read anything only writes. SDFat sends FF to read data, but uses only 8bit mode, so the only bit I have not tested is to send FFFF in 16bit mode, but can't think that I have any use case or example for that. |
I think it would be safe to have the variable "ff" 16 bit width. |
I think the spi ones should be private and part of the class, because there is no reason anything else should use or modify them, they are for private use, so the fit the bill. |
I've tried to move static SPIClass *_spi1_this in the class but it then generated other warnings that I haven't been able to get rid off... This is why I left them in the cpp. |
Pascal I have a version with those as part of the class, I'll share it in a bit, I was trying so see if 0xFFFF was anywhere as part of the core that we could use it. |
Is this still a work-in-progress ? It looks like you guys are still testing and amending this PR. Or is it now stable, and if so how should it be tested, e.g. before and after ? |
Just checked to compare before and after, and the [-Wunused-variable] warnings are gone 👍 |
Not good. |
Someway I overwrote my local copy where I modified it to work fine and without errors, so I just had to go and redo it again, and tested with SDFat and ILI0163 versions that use the callbacks with RTOS to switch tasks while waiting for the callback to be called. So confirmed 100% they work for SPI1 and SPI2. I do not have anything around using SPI3, but should work just as well for it. Please do this changes and test:
Then in SPI.cpp, define them as class variables. I placed them right above the constructor:
I compiled in Sloeber, it works fine and doesn't give any warning. |
@pascallanger did you see my comment above? if you want to test that solution, it works fine for me and removes the warnings, at the samee time that keeps them within the class. |
I think there is a reasonable chance this may be superseded. There seems to be multiple ongoing investigations into SPI problems, so I'm not sure if I'll need to park this one until the dust settles ???? |
I think that by moving |
The change I suggested works fine, removes the warnings, and it keeps those variables inside the class and away from any other code trying to use a variable with the same names. I have not seen any update from the OP on whether he tested my suggestion, but I have tested it extensively. @stevstrong can you test the changes I suggested I couple of posts above? just to doublecheck, since the work for me. In that case I will send a PR with the corrections. |
I know I said before that the SPI class pointers should be class members, same as you (@victor) suggested, but now I am not so sure about that anymore. Because one instance should have only one pointer to himself, not three (for other instances, too) which happens if we have three pointers for each port. Same for current_settings[], it does not make much sense to have it for each instance in part, as the current class is selected by the index, and this should be global. Or am I missing something? I think both ways (inside and outside of class) would work, but not sure about which way makes sense. |
If they are static in the class, there is only 1 copy of them, not one per instance, so being outside or being static inside, there is the same number of them. Being inside the class though keeps their scope local to the class, which I think makes the most sense. I think the issue with the callbacks and currentSetttings is a different and separate problem, that will have to deal with in a different way. |
Now, if instead of making them static within the class, we made them normal class members, then there could be only 1 per instance, but then you can't do the proper callback form the core ISR driver. It can not call a member function that is not static. That's the whole reason of having the pointers. We can rethink all that and find another way to do it, but the way it is, having the spiN_this pointers as statics outside or inside the class doesn't make any difference in the memory used, only 3 pointers for the class, no matter the number of instances, so I think we should apply that change, then we keep working on the subject of setModule and callbacks. |
I forgot about C++ not being able to call a pointer from a class instance :-( So I agree, we'd need a static array of pointers |
made a new one in PR #653 which also fix the other warnings |
Overruled by #653 . |
Small change to get rid of the annoying false positive unused warnings.