Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the ULP processor for LED animations #35

Open
TokenRat opened this issue Sep 10, 2024 · 1 comment
Open

Using the ULP processor for LED animations #35

TokenRat opened this issue Sep 10, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@TokenRat
Copy link
Collaborator

Your feature request

The ULP is barely too slow to bit-bang the WS2812 LEDs according to the timing specs. But who knows, how tolerant they are? With some well-timed NOPs or some other tricks, we might be able to draw patterns per GPIO from the ULP.

The main processor then would write the patterns into flash and go to sleep, while the ulp reads them and displays them, until wakeup. This would reduce the power consumption and be a pretty cool trick. I played around a bit already, but got no results so far.

Of course, any WiFi or other function would not work in this state.

@TokenRat TokenRat added the enhancement New feature or request label Sep 10, 2024
@nponsard
Copy link

nponsard commented Oct 10, 2024

I managed to control the leds from the ULP https://github.com/nponsard/ef28-badge/blob/rust-no-std/coprocessor/src/main.rs .

I made it so it generates the code to drive all the leds and then execute it so the timing is always the same.

To initialize I do

lui	a2,0x80000
lui	a1,0xa
addi    a1,a1,1024

so I can turn on and off the gpio 21 with a 2-bytes instruction instead of a 4-bytes instructions

Turn on :

sw      a2,4(a1)

Turn off :

sw      a2,8(a1)

then I use NOP instructions as delays:

  • 0 for T0H (bit 0, number of NOP to wait before turning off)
  • 2 for T1H (bit 1, number of NOP to wait before turning off)
  • 4 for T0L (bit 0, number of NOP to wait before encoding the next bit)
  • 2 for T1L (bit 1, number of NOP to wait before encoding the next bit)

Generating a program to drive the 17 leds uses 4 908 bytes.
I tried previously with loops but it messes up the timing.

For example, to send 010 it would generate:

# configure the registers once
lui	a2,0x80000
lui	a1,0xa
addi    a1,a1,1024
# send the data
sw      a2,4(a1) # turn on 
sw      a2,8(a1) # turn off
nop 
nop 
nop 
nop 
sw      a2,4(a1) # turn on 
nop 
nop 
sw      a2,8(a1) # turn off
nop 
nop 
sw      a2,4(a1) # turn on 
sw      a2,8(a1) # turn off
nop 
nop 
nop 
nop 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants