On Monday, August 28, 2023 at 9:05:23 AM UTC+2, Niclas Hedhman wrote:
[SOLVED!]
The words that I found by studying the "codegenerator-m3.s" source were; call,
[']
ret,
Now I just need to get the bits in the stream in the right order, and will post the solution later...
: (neopixel) ( n -- )
#24 lshift \ move all bits up
4 0 do
rol rol \ shift in next two bits
dup 3 and ( input masked )
case
0 of $88 endof
1 of $C8 endof
2 of $8C endof
3 of $CC endof
endcase
literal, \ compile top of stack (TOS) as a literal to word being defined
['] >spi \ address of ">spi" to TOS
call, \ compile a call to the address on TOS
loop
drop
;
: split-rgb ( rgb -- b r g )
dup $FF and swap ( blue )
dup #16 rshift $FF and swap ( red )
#8 rshift $FF and ( green )
;
: rgb ( rgb -- )( -- )
<builds
split-rgb \ convert 24 bits into three 8bits in order of b r g (green on TOS)
(neopixel) \ generate bitstream for green
(neopixel) \ generate bitstream for red
(neopixel) \ generate bitstream for blue
ret, \ generate a return
does> execute
;
For those interested, the Neopixel (WS2812B) is connected to the MOSI pin on SPI1 and that is set to 4Mbits/sec and 16bit mode. ">spi" simply check that the previous transfer is complete and the write directly to the SPI1-DR register.
I don't recommend using the MOSI for interfacing with the WS2812B. In my case; if I use DMA, then the MOSI pin ends up "high" and with a small delay between DMA transfers, this "high" becomes a bit. This doesn't happen when writing directly to the SPI1-
DR register. One should instead use a Timer+DMA to get the bitstream, for more precise control.
BTW; this is done on STM32WLE5 and a Mecrisp Stellaris variant in parallel with CubeMX from ST, and FreeRTOS in place. See
https://github.com/niclash/colibri-1dp-mcu1 for full codebase (Work in progress, as LoraWAN part is still having issues, but the
Forth side feels quite solid.)
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)