SPI Library??
mindrobots
Posts: 6,506
I'm sitting in front of a PropBOE that has a MAX3421E USB Host breakout board wired up on it's breadboard. The board was developed for the Arduino and has a robust and growing library of USB devices that it supports allowing the Arduino to act as a USB Host to a device (it also allows the Arduino to act as a USB peripheral to another USB host). We want to make this board usable on the Propeller.
My choices are:
1) SPIN/PASM using the SPI library in the OBEX which provides basic SHIFTIN/SHIFTOUT for SPI devices. This looks pretty doable once I read through the data sheet but this will be a lot of rewriting of the existing Arduino(C++) code to SPIN. The end product would be useful to many.
2) PropForth or Tachyon which have SPI support. Again doable but a lot of rewriting from C++ to Forth....and the end product would be of interest to about 7 people.
....OR....
3) PropGCC...except, I can't find a general purpose SPI library anywhere. Is there one hidden some place? I haven't seen it on the Beta website or out in the code repository. This seems like a GREAT opportunity for a PropGCC project in light of all the hoopla going on recently but I really don't want to start from ground zero with writing an SPI library unless I really, really have to. If it's part of the educational "secret sauce" that's coming out in the near future, then I can wait and find other things to work on.
Any help, guidance, words of wisdom from the PropGCC camp?
Thanks!
My choices are:
1) SPIN/PASM using the SPI library in the OBEX which provides basic SHIFTIN/SHIFTOUT for SPI devices. This looks pretty doable once I read through the data sheet but this will be a lot of rewriting of the existing Arduino(C++) code to SPIN. The end product would be useful to many.
2) PropForth or Tachyon which have SPI support. Again doable but a lot of rewriting from C++ to Forth....and the end product would be of interest to about 7 people.
....OR....
3) PropGCC...except, I can't find a general purpose SPI library anywhere. Is there one hidden some place? I haven't seen it on the Beta website or out in the code repository. This seems like a GREAT opportunity for a PropGCC project in light of all the hoopla going on recently but I really don't want to start from ground zero with writing an SPI library unless I really, really have to. If it's part of the educational "secret sauce" that's coming out in the near future, then I can wait and find other things to work on.
Any help, guidance, words of wisdom from the PropGCC camp?
Thanks!
Comments
I'm happy to help if you want to write this library. I have SPI code that can be used.
That sounds like a plan.
I'm looking the PropGCC sd_driver.s code now. Would we want it at that level (ASM) or is there C code that might be better suited (the code you have)?
I'd probably hook up a better understood device (known working under SPIN/PASM) to write and test code against before trying unknown code against an unknown device.
I'll be floundering, hacking and guessing most of my through this, so any help would be appreciated. If I use P2 GCC and can write it in LMM, then we can have a USB Host application for my DE0-Nano too!
Thanks,
David
I haven't dug any further, yet.
http://www.circuitsathome.com/products-page/breakout-boards/usb-host-shield-for-arduino-pro-mini
In theory, this should mean that any obex code can be parsed through this program and so all the SPI spin drivers in the obex would be available to C.
In practice, I think we ran up against a problem with the spin \ abort directive. I don't recall all the details, but I don't think it is so easy to code the same sort of thing in C?
There is a possibility of course that the SPI code in the obex will pass through Spin2C ok - and if so, this might be far easier than recoding something from scratch.
Yes, these are the boards we are playing with. We're using the mini shields as breakout boards. When we get it working with the Prop, I think Jeff(OBC) might spin a QuickStart board for PropellerPowered incorporating anything we learn along the way.
I think a linkable C SPI library would be a great idea.
spin2cpp can be used to compile individual modules -- it won't do a single function, but it will do a .spin object, which can then be called from C++ (or from C if you use the appropriate options, although that's a little bit harder).
And Drac, the Spin \ abort issue was fixed a while ago. I won't guarantee that spin2cpp is bug free (I'm sure it isn't!) but it's still making progress.
Eric
mindrobots: Let me know if you plan to use Eric's suggestion to convert one of the Spin SPI modules so I don't waste time making a native C library when it isn't needed.
David,
Let me try Eric's suggestion and see what I can come up with. I'm supposed to be contributing around here instead of taking up resources! You have other things (many) that are more important right now to work on.
When I get to the point where I have something working, I'll get back with you to turn it into a REAL library - that's something I'll certainly need help on.
Thanks for helping getting me started and pointed in the right direction.
Thanks, Eric! As above, I'll head off down the spin2cpp road and see what I can get to work.
I'll be headed in both directions. In the medium term (3-9 months) PropGCC MUST have it's own libraries to talk to ANY product Parallax wishes to sell. (in my never wavering, not so humble opinion!!)
I checked back through the version listings. The version that wasn't working was 28th November 2012, and my apologies because I haven't checked the wiki since then. So just now I downloaded the version from 13th December 2012 and woot! This works.
I just ran the entire Kyedos program through it and it instantly produced eight .c and eight .h files with no errors at all.
This is *very* exciting. Kyedos has a large amount of complex code written by a number of authors in different coding styles. I think it is extremely likely that if Kyedos produces no errors, then pretty much all the Obex is going to work fine too.
So... how would one go about translating the obex into c? And as an example, the SPI driver?
For something like Kyedos, the entire program starts as Spin. But for a 'library', some of the code already will be c. In a Top Down Programming methodology, we might start off with a 'main' and then we decide to add a SPI library.
For Spin maybe we can think about the different parts to an object. The local constants. The PUB methods, the PRI methods and the pasm code.
The pasm code is maybe the simplest as many users don't need to look at this much. Spin2cpp will translate this to a block of data with the code to load it into a cog.
The PUB and PRI methods end up in the .c part of the code.
The 'handles' for all the PUB methods are nicely summarised in the .h part of the code, and then ten lines up from the bottom are the PRI methods, listed as 'private'.
eg this is Kye's string driver
So that makes it possibly even easier than Spin to quickly scan through an object and see if it has useful routines.
So in a way, all that would be needed to produce libraries is to run each object through the Spin2cpp program, and then just add a little reminder note to say 'look at the .h file for the methods in this object'.
and the demo code to use this is
Dr. A, thanks for leaving some code to try!
I'll have to settle own with this and see if I can get anything working for as long as my Sunday stays quiet and mine!
I wonder if I have a DS1620 lying around someplace where it can be found???
My results have so far been very successful and the source can be found in my git repo here: https://github.com/SwimDude0614/PropWare