Created
July 12, 2025 21:40
-
-
Save wolfmanjm/196cf0542f4821d463b252f484203875 to your computer and use it in GitHub Desktop.
neopixel.fs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\ uses 4 bytes at neopixel_address.. pin# r g b | |
\ this address is monitored and when it changes the rgb is set | |
#require gpio-pins.fs | |
\ byte 0 is r, 1 is g, 2 is b, 3 is pin# | |
0 variable neopixel-address | |
\ this is launched on core1 | |
\ starts monitoring the address and does not return | |
\ NOTE that the pin should be setup as output before calling this | |
: run-neopixel ( -- ) | |
neopixel-address \ puts the address to be monitored in x8 (TOS) | |
[ | |
$aa11 h, \ j 20000176 <main> | |
$b0002373 , \ csrr t1,mcycle | |
$06830293 , \ addi t0,t1,104 | |
$b0002373 , \ csrr t1,mcycle | |
$fe536ee3 , \ bltu t1,t0,2000006c <delay800ns+0x8> | |
$8082 h, \ ret | |
$b0002373 , \ csrr t1,mcycle | |
$06330293 , \ addi t0,t1,99 | |
$b0002373 , \ csrr t1,mcycle | |
$fe536ee3 , \ bltu t1,t0,2000007e <delay850ns+0x8> | |
$8082 h, \ ret | |
$b0002373 , \ csrr t1,mcycle | |
$02930293 , \ addi t0,t1,41 | |
$b0002373 , \ csrr t1,mcycle | |
$fe536ee3 , \ bltu t1,t0,20000090 <delay450ns+0x8> | |
$8082 h, \ ret | |
$b0002373 , \ csrr t1,mcycle | |
$02d30293 , \ addi t0,t1,45 | |
$b0002373 , \ csrr t1,mcycle | |
$fe536ee3 , \ bltu t1,t0,200000a2 <delay400ns+0x8> | |
$8082 h, \ ret | |
$1171 h, \ addi sp,sp,-4 | |
$c006 h, \ sw ra,0(sp) | |
$3e800293 , \ li t0,1000 | |
$02550533 , \ mul a0,a0,t0 | |
$3775 h, \ jal 20000064 <delay800ns> | |
$ce050513 , \ addi a0,a0,-800 | |
$fea04de3 , \ bgtz a0,200000b8 <delayus+0xc> | |
$4082 h, \ lw ra,0(sp) | |
$0111 h, \ addi sp,sp,4 | |
$8082 h, \ ret | |
$1171 h, \ addi sp,sp,-4 | |
$c006 h, \ sw ra,0(sp) | |
$85aa h, \ mv a1,a0 | |
$3e800513 , \ li a0,1000 | |
$3fe9 h, \ jal 200000ac <delayus> | |
$15fd h, \ addi a1,a1,-1 | |
$feb04ce3 , \ bgtz a1,200000ce <delayms+0x6> | |
$4082 h, \ lw ra,0(sp) | |
$0111 h, \ addi sp,sp,4 | |
$8082 h, \ ret | |
$29201333 , \ bset t1,zero,s2 | |
$d00002b7 , \ lui t0,0xd0000 | |
$0062ac23 , \ sw t1,24(t0) # d0000018 <GPIO_OUT+0x8> | |
$8082 h, \ ret | |
$29201333 , \ bset t1,zero,s2 | |
$d00002b7 , \ lui t0,0xd0000 | |
$0262a023 , \ sw t1,32(t0) # d0000020 <GPIO_OUT+0x10> | |
$8082 h, \ ret | |
$1171 h, \ addi sp,sp,-4 | |
$c006 h, \ sw ra,0(sp) | |
$37c5 h, \ jal 200000e0 <pin_high> | |
$378d h, \ jal 20000064 <delay800ns> | |
$37ed h, \ jal 200000ee <pin_low> | |
$3749 h, \ jal 20000088 <delay450ns> | |
$4082 h, \ lw ra,0(sp) | |
$0111 h, \ addi sp,sp,4 | |
$8082 h, \ ret | |
$1171 h, \ addi sp,sp,-4 | |
$c006 h, \ sw ra,0(sp) | |
$37f9 h, \ jal 200000e0 <pin_high> | |
$3759 h, \ jal 2000009a <delay400ns> | |
$3fe1 h, \ jal 200000ee <pin_low> | |
$3fb9 h, \ jal 20000076 <delay850ns> | |
$4082 h, \ lw ra,0(sp) | |
$0111 h, \ addi sp,sp,4 | |
$8082 h, \ ret | |
$1171 h, \ addi sp,sp,-4 | |
$c006 h, \ sw ra,0(sp) | |
$8e2a h, \ mv t3,a0 | |
$43dd h, \ li t2,23 | |
$487e5eb3 , \ bext t4,t3,t2 | |
$000e8463 , \ beqz t4,20000134 <np_send+0x14> | |
$37f1 h, \ jal 200000fc <np_one> | |
$a011 h, \ j 20000136 <np_send+0x16> | |
$3fe9 h, \ jal 2000010e <np_zero> | |
$13fd h, \ addi t2,t2,-1 | |
$fe03d8e3 , \ bgez t2,20000128 <np_send+0x8> | |
$4082 h, \ lw ra,0(sp) | |
$0111 h, \ addi sp,sp,4 | |
$8082 h, \ ret | |
$01059293 , \ slli t0,a1,0x10 | |
$00851313 , \ slli t1,a0,0x8 | |
$0062e2b3 , \ or t0,t0,t1 | |
$00c2e2b3 , \ or t0,t0,a2 | |
$8516 h, \ mv a0,t0 | |
$8082 h, \ ret | |
$1171 h, \ addi sp,sp,-4 | |
$c006 h, \ sw ra,0(sp) | |
$37e5 h, \ jal 20000142 <np_setrgb> | |
$37d1 h, \ jal 20000120 <np_send> | |
$4082 h, \ lw ra,0(sp) | |
$0111 h, \ addi sp,sp,4 | |
$8082 h, \ ret | |
$1171 h, \ addi sp,sp,-4 | |
$c006 h, \ sw ra,0(sp) | |
$3759 h, \ jal 200000ee <pin_low> | |
$06400513 , \ li a0,100 | |
$3f3d h, \ jal 200000ac <delayus> | |
$4082 h, \ lw ra,0(sp) | |
$0111 h, \ addi sp,sp,4 | |
$8082 h, \ ret | |
$84a2 h, \ mv s1,s0 | |
$0034c903 , \ lbu s2,3(s1) | |
$8088 h, \ lbu a0,0(s1) | |
$80cc h, \ lbu a1,1(s1) | |
$80b0 h, \ lbu a2,2(s1) | |
$3fd1 h, \ jal 20000156 <np_send_rgb> | |
$37c5 h, \ jal 20000164 <np_reset> | |
$06400513 , \ li a0,100 | |
$3f3d h, \ jal 200000c8 <delayms> | |
$bfc5 h, \ j 2000017c <main+0x6> | |
] | |
\ should not get here, but if it does clean up stack | |
drop | |
; | |
\ these are called by program running on core0 | |
: init-neopixel ( pin# -- ) | |
dup neopixel-address 3 + c! | |
pin-output | |
['] run-neopixel execute-coprocessor | |
; | |
: set-neopixel ( r g b -- ) | |
neopixel-address 2 + c! | |
neopixel-address 1 + c! | |
neopixel-address c! | |
; | |
#require ticks.fs | |
: test-neopixel | |
16 init-neopixel | |
begin | |
255 0 0 set-neopixel | |
1000 delayms | |
0 255 0 set-neopixel | |
1000 delayms | |
0 0 255 set-neopixel | |
1000 delayms | |
255 255 255 set-neopixel | |
1000 delayms | |
0 0 0 set-neopixel | |
1000 delayms | |
key? until | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment