-
• #2
Questions of understanding about buffer and lines 51, 53, and 54, and conclusion for setColor():
- buffer: buffer is buffer of bytes (8 bits) for 4 entities of 2 bits per byte
- line 51: xor-s 8 LSBits to get the 1-complement (invert)?
- line 53: uses only LSBit (with the AND) even though 32 bits are poked?
- line 54: uses only secondLSBit as LSBit (with the AND and SHIFT) even though 32 bits are poked?
Conclusion is that
.setColor(colorValue)
sets 2nd and 1st LSBit in buffer.Another question is regarding performance:
How 'expensive' is a repeated multiplication? Using a simple, incrementing, buffer pointer for accessing the buffer, how much would be gained over the repeated multiplication?
(Afaik, compiler cannot yet do ++bp).Would code below make a (time) difference?
var bp = -1,y,i,j; for (y=0;y<16;y++) { for (i=0;i<16;i++) { var b = buf[bp+=1]^255; for (j=0;j<4;j++) { poke32(nR, b&1); b>>=1; poke32(nG, b&1); b>>=1; poke32(S, 0); poke32(S, 1); } }
- buffer: buffer is buffer of bytes (8 bits) for 4 entities of 2 bits per byte
-
• #3
buffer: buffer is buffer of bytes (8 bits) for 4 entities of 2 bits per byte
line 51: xor-s 8 LSBits to get the 1-complement (invert)?Yes
line 53: uses only LSBit (with the AND) even though 32 bits are poked?
line 54: uses only secondLSBit as LSBit (with the AND and SHIFT) even though 32 bits are poked?Yes - the memory is 'bit-banded', so you just want a 1 or a 0 in there (I didn't look up exactly why, but it didn't seem to work well without it)
How 'expensive' is a repeated multiplication?
Not very, as far as I know - as long as the compiler knows that the values are all integers it'll be a simple 32 bit multiply, which I believe is done almost single-cycle on ARM.
But yes, your code would be faster.
Even faster would be to use a Uint32Array and to request 32 bits at once - the
buf[ ... ]
is by far the slowest bit of the whole thing
http://www.embeddedadventures.com/LED_matrix_display_LDP-6416.html
(datasheet here)
This module is a real pain to drive quickly, because you need to shift out data for two bits at around 50kHz absolute minimum.
In the most recent Espruino builds (so the 1v81 release when it's done), I've added the ability to get the register address of a single GPIO pin, which means you can use this to easily 'poke' data to the pin, which is very fast in 'compiled' code.
So to drive the display, you can now do something like this:
Sadly it can't be wrapped up in a module yet (which would obviously be ideal), but it's still a good start.