-
I'm planning on a small side project that needs to use the PIO (Programmable IO) function of the RPI Pico. What's the status of PIO support? I found the .pio file used for the RGB LED, but not sure if it's been used, and there is no example as far as I can tell. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
There's no JavaScript API around the PIO support. As you noted, PIO can be in the native implementations (such as Neopixel). Given the nature of PIO. I'm not entirely clear on how it would be meaningful exposed in a JavaScript API. It is an interesting direction. Do you have some idea of what that might look like? |
Beta Was this translation helpful? Give feedback.
-
I made some progress on this project. Basically I got a Pico board running Moddable, and added a module (pins/pio) which calling the PIO functions from C SDK. Right now I'm not manipulating PIO functions from JS code, instead I implemented my logic inside the module. However, after getting familiar with PIO, I think a pure JS API is very feasible, let's look at the C code I have now: // Prepare Program
uint _pc = 0;
uint _wrapStart;
uint _wrapEnd;
uint16_t _program_instructions[32];
_wrapStart = _pc;
_program_instructions[_pc++] = pio_encode_mov_not(pio_isr, pio_null);
_program_instructions[_pc++] = pio_encode_in(pio_pins, modPio->setup.in_count);
_program_instructions[_pc++] = pio_encode_mov_not(pio_x, pio_isr) | pio_encode_delay(10);
_program_instructions[_pc++] = pio_encode_jmp_not_x(_pc + 3);
_program_instructions[_pc++] = pio_encode_set(pio_pins, 0x0);
_program_instructions[_pc++] = pio_encode_jmp(_wrapStart);
_program_instructions[_pc++] = pio_encode_set(pio_pins, 0x1);
_wrapEnd = _pc - 1;
struct pio_program _program;
_program.instructions = _program_instructions;
_program.length = _pc;
_program.origin = -1;
PRINT_PROGRAM()
// Setup program
uint offset = pio_add_program(pio, &_program);
modPio->programOffset = offset;
sm_config_set_wrap(c, offset + _wrapStart, offset + _wrapEnd);
pio_sm_init(pio, sm, offset, c);
pio_sm_set_enabled(pio, sm, true); I think all the But in my code above I've demonstrated how to construct a program without any external tools. The above code only using Or we can just forward all the After the construction, just passing a uint_16 array, plus two numbers (_wrapStart and _wrapEnd, indicating the start and end of the program loop) to the C side should be sufficient to set the PIO program. I was trying to implement the module as described above; however, I'm hesitating due to:
|
Beta Was this translation helpful? Give feedback.
Really interesting stuff.
Generating the PIO program from JavaScript definitely looks possible. I like the idea of an "instruction builder" that can help prevent errors and perhaps perform validation. It could also be organized so that it isn't necessary to statically declare the length of the instructions, for example using the new resizable array buffer (which lets you make resizable TypedArrays).
That's for certain.
It is more direct. I mean... PIO is an a…