Hi,
I want to interface with a WS2812, and I have set up the MCU so that I can simply send $88, $8C, $C8, $CC (for 00,01,10,11) twelve times to get the 24 bits in the RGB LED wire "protocol".
So, if I do;
: off $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi $88 >spi ;
I can set the LED to off. There is not enough time to keep that in an array, loop and read out each on the fly, and DMA has a side-effect that makes it not possible to use for this LED on this MCU, so I thought I should just generate the code;
: rgb ( rgb -- )( -- )
create split-rgb (ws2812b) (ws2812b) (ws2812b)
does> execute ;
;
where "split-rgb" breaks the rgb into r g b and then "(ws2812b)" loops through the 8 bits to generate the word. So, usage would be
$0 rgb off
$FFFF rgb warning
and in the background the "off" word executes the same way as the defined word above.
This is nothing I have done before and don't grok how I inject "call this particular word" into the dictionary body.
I think that I can "literal," to pop the computed byte from TOS into the dictionary so that when it is executed it pushes that value onto stack. But how do I do the same for a word to execute?
Any help/pointer would be greatly appreciated.
Niclas
P.S. for reference, I the (ws2812b) will look something like;
: (ws2812b) ( n -- )
#24 lshift \ move all bits up
4 0 do
rol rol \ shift in next two bits
dup 3 and
case
0 of $88 endof
1 of $C8 endof
2 of $8C endof
3 of $CC endof
endcase
literal, \ <-- I need a "add execute '>spi' to dictionary" here
loop
drop
;
[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...
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 399 |
Nodes: | 16 (2 / 14) |
Uptime: | 39:51:27 |
Calls: | 8,336 |
Calls today: | 13 |
Files: | 13,155 |
Messages: | 5,891,348 |
Posted today: | 1 |