Yes, below 23 bytes it's more efficient to not use flat strings to back the arrays, so Espruino does that. Also for Uint8Array it'll try once to make a flat string, but if it doesn't succeed it'll just back it with a sparse one.
In the latest builds (post 1v95) of Espruino you'll find E.toString is much more reliable at creating flat strings. I'd suggest the little known hack of E.toString({data : 0, count : NUM_BYTES}).
var flat_str = E.toString({data : 0, count : NUM_BYTES});
var arr = new Uint8Array(E.toArrayBuffer(flat_str));
var addr = E.getAddressOf(flat_str);
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Nice - are you trying to set up DMA using JavaScript to do SPI sends? There's a tool at https://github.com/espruino/Espruino/blob/master/scripts/build_js_hardware.js that'll generate JS for the registers in bits of hardware so you can access it more easily.
Yes, below 23 bytes it's more efficient to not use flat strings to back the arrays, so Espruino does that. Also for Uint8Array it'll try once to make a flat string, but if it doesn't succeed it'll just back it with a sparse one.
Have you seen http://www.espruino.com/Reference#l_E_getAddressOf ? You can at least run that with the second argument as true, and it'll return 0 if there isn't a flat array.
In the latest builds (post 1v95) of Espruino you'll find
E.toString
is much more reliable at creating flat strings. I'd suggest the little known hack ofE.toString({data : 0, count : NUM_BYTES})
.Hope that helps!