SimpleIDE program for Neopixels 2811 through 6812RGBW
Kednerpo
Posts: 46
in Propeller 1
I started with David Betz's ws2812 program that was already set up to easily support other strips and seeing that that program was based on JonnyMac's Spin code that ws recently updated to support RGBW strips I was able to get something working pretty quickly.
I'm having a couple issues with what I have so far.
If you have a strip of pixels that is longer than the quantity of pixels you are trying to run some of the pixels outside that range are turning on to a random color.
example: 24 strip of pixels, code is set to run only 10 pixels. Pixels 14 and 15 might turn green or pink and not change.
The other part is that I was hoping to be able to have the driver be able to use RGB 0xRRGGBB format or RGBW 0xRRGGBBWW format automatically so that other drivers like color pickers or color sensors wouldn't need to be changed.
It seems like older RGB programs do pack the 24bit information into 32bit longs but do it as 0x00RRGGBB format. I made a few attempts at trying to shift the bits around in programming but never got what I wanted. Even went back and studied JonnyMac's Nut and Volts article for the original code and how it moves bits around but still no luck yet.
I settled on 0xRRGGBBWW for now.
I'm having a couple issues with what I have so far.
If you have a strip of pixels that is longer than the quantity of pixels you are trying to run some of the pixels outside that range are turning on to a random color.
example: 24 strip of pixels, code is set to run only 10 pixels. Pixels 14 and 15 might turn green or pink and not change.
The other part is that I was hoping to be able to have the driver be able to use RGB 0xRRGGBB format or RGBW 0xRRGGBBWW format automatically so that other drivers like color pickers or color sensors wouldn't need to be changed.
It seems like older RGB programs do pack the 24bit information into 32bit longs but do it as 0x00RRGGBB format. I made a few attempts at trying to shift the bits around in programming but never got what I wanted. Even went back and studied JonnyMac's Nut and Volts article for the original code and how it moves bits around but still no luck yet.
I settled on 0xRRGGBBWW for now.
zip
23K
Comments
These low-cost pixels aren't perfect, and occasionally subject to "glitches," especially if you try to drive the data too fast. This is why my latest driver allows the developer to set the rest time between refresh cycles.
My latest driver uses $RRGGBBWW format for all pixel types. If you have 24-bit pixels the LSB is never shifted out, hence irrelevant. I don't know what happens to Spin/PASM when it gets translated to C, but it always looks like a train wreck. This is why I develop in Spin.
The nice thing about Spin is it's simplicity and limited features. This makes it easy for newbies to learn it, and people can master it in a month or two.
Spin really only has a couple of features that handle the multicore nature of the Prop. The multicore support basically consists of cognew/coginit and the lock instructions. The rest of Spin is really only relevant to a single core. The C libraries contain a significant amount of support for multicore and multitasking. Of course, it's harder to learn and master because of the flexibility it provides.
Are you trying to start another language war? You do know that that is an opinion, right? At best you could argue that, in a hypothetical world where no one knows either C or Spin, Spin is easier to learn. But that's a moot point because we clearly don't live in that world.
My question is (mostly) rhetorical. I know (am pretty darned sure) you weren't trying to start a language war. But you do know statements like "It would be nice if C was as easy to follow as Spin" are surefire ways to trigger such a thread...
The C crowd is just thin skinned, because of lack of support. Neither Parallax nor a lot of us Spin/Pasm users even try to use such goodies as Spin2Cpp.
I think Dave, David and Eric put a lot of effort into this 'and nobody notices, nobody cares' like Carlin used to say.
I personally really enjoy reading your code, and over the years learned a lot from you. Not just about Spin and Pasm, but the art of coding.
You are one of the lucky persons, able to use the Propeller, Spin and Pasm in your work environment, so you have gratification for what you are doing, not just financial, but also thru happy customers and customers(visitors?) of them.
But David, Dave & Co do all of this in there spare time and -hmm - seem to feel that nobody wants it and that even a strong wind is blowing against them.
Which is sad, but understandable.
My understanding is, that C/C++ was supposed to run on the P2, but got used on the P1 for the lack of a P2. And the P1 is quite restrained in Memory, so getting C/C++ running there was the second choice.
On the P2 however, C/C++ will be way more important and also way more usable. So @Ken's decision to go the PropGCC route is correct by all means, and all of us Spinners will have Spin2 to move on to the next bigger, faster, Propeller without much hassle. At least I hope so.
So please Jon, don't.
Mike
Jon: Please don't hold back on my account. I'll try to thicken my skin a bit in the future. :-)
Well, I have to admit that I am able to get Spin and Pasm out of sync, even if in one file. But the header files are something I never really got used to. Seems to be so unneeded to type the same stuff again. And -hmm- the way GCC handles Assembler is quite ugly compared to the way it is integrated into Spin.
On the other hand I was finally able to run GCC under Ubuntu on Win10 and hope to be able to get all those goodies to run in Windows. Not sure what to do with the serial port issue of this WSL thing.
Mike
And, yes, the inline assembler in GCC is quite ugly. Some of the ugliness is to allow efficient optimization of embedded code and some seems to be there for no good reason like the need to put all of the code in quotes. I believe this is mainly done to make the parser easier but it certainly results in ugly code. However, inline assembly is hardly ever used in C since the C source tends to compile efficiently enough in most cases. This may be true on P2 as well with hub exec. It isn't true on P1 because of the layer of interpretation that is required due to the tiny code space of the P1 COG.
Finally, C header files are a good place to put common definitions that are used by many source files. Something like this would be a nice addition to Spin.
David is right, that the prototypes can be extracted from the source file in a early pass of the compiler, I guess this is what happens in C#. So a separate .h file may be just needed if you want to use precompiled binary libraries without source access. But even that seems possible without .h files, I can without problems use external libraries in C# and VS extracts the needed prototypes out of the provided .dll. So there seem to be a way to do that.
Dave is also right by stating that Spin lacks types, pushing the type-checking right back to the programmer. As I started to move from VB6 to the net-framework I HATED C# but had no way around it.
VS does generate some files automagically, not prototypes, but design files containing the visual elements. Sometimes a hassle when getting out of sync, but usually it works pretty well. Same goes for the need of make files. Sure VS does it behind your back, but you do not need to care about it at all, usually.
But this is a IDE thing, some people swear on using vim and command line tools, some people like the use of IDEs, to make the life easier.
Coming from COBOL in the first place, I am not afraid of large lines of code. Source codes with 50.000 lines per file are not really rare there. Sure, the C# projects I worked on in the last 20+ years have rarely that size per file, but more files. OK COBOL is a bad example because it is the most verbose language I ever worked with and the philosophy of C was in part to get rid of that verbosity and shrink down the source code immensely.
a for (i=1;i++;i>10) in C would look like this in COBOL
PERFORM VARYING i FROM 1 TO 10...., besides you would not find any commercial COBOL program using a variable "i" in the first place. That is because COBOL does not have local variables as used in other languages, and you HAVE TO use longer and more descriptive names.
All of this is moot on a micro controller like the P1or even the P2. So a lot of features of C/C++ make - in my opinion - not much sense for small targets.
One part of the success of the Arduino was to strip down the language so far that they even do not mention it is C++. And normal people where able do combine stuff to use it without even knowing they program C++.
On the other hand, if we can get some POSIX layer on the P2, introduce dynamic loading of modules from external storage, and some minimalistic Memory Management the amount of code you could run on a P2 might extend to the need of.
we will find out.
Mike
Say in windows, I can peek into a dll, because it is a windows-specific dll and in a PExx format. Else it would not work in my actual system. VS knows that so it can do that for me.
I am pretty sure that the same goes for Linux/BSD/other. Each system has a common used convention how the binary and the entry points are defined.
Or is the type information already lost at that point?
just curious,
Mike
Headers allow name and param info for Assembler routines, or any other language that follows the param convention rules.
Way, way back, header files also meant you did not need to parse all source files - these days of GHz CPU, GB RAM and TB HDD, that's more a 'who cares'.
It could be relatively easy to have C (or variant) tolerate no header files, if someone decided that was worth the effort.
Well, yes, that's an historic kludge, and partly because GCC is so generic.
Thus a simple way to 'push code lines' into the following assembler was done, but most other languages these days have cleaner ASM..ENDASM or similar.
If you want the best performance from in-line ASM, those in-line pieces should ideally have full ASM ability, including macros.
To have the most compact run-times, the Type/Calling Checks are best done at Link time, which does mean you need at a full OBJECT file collection.
Or is P2 going to be general enough, that people will brave DLL-Hell, and allow mix-and-match binary files ?
A compiled library doesn't have any mechanism to expose this information. It could be done, but producing such a thing would require support from the compiler to produce an extra blob of information in the library, or a "sidecar" file, but that's pretty much the same as a header.
This thread seems to have gotten way off track. May I ask where you got the code you started with? I'd like to propose that I adopt your modification of the code and that we remove any reference to JonnyMac as he requested and repost it to wherever you found it. I don't recall ever posting it anywhere myself. I'd be happy to have your modified version become the official version. Thanks for adding the RGBW support!
The original was from a post you made a few years ago.
forums.parallax.com/discussion/152504/c-code-to-work-with-ws2812-neopixel-leds/p1
I started with the latest version you posted. It would be great if you could post the updated code there once the changes you proposed are made.
I will edit my original post to this thread to add a link to yours.
There is a bug in the code where additional LEDs are being lit unintentionally. I was wondering if the following code from the rgbx.h file was correct.
I wasn't sure if (r)<<32 should instead be (r)<<24
Thank you much for your work on the original code and for looking at adopting the modified version.