wokwi / rp2040js

A Raspberry Pi Pico Emulator in JavaScript
MIT License
384 stars 40 forks source link

feat(sio): Implement Interpolator #96

Closed Ferdi265 closed 2 years ago

Ferdi265 commented 2 years ago

This PR implements the "Interpolator" peripheral in the SIO block.

The implementation of the Interpolator is ported from my rp2040-interpolator implementation, which I tested against a real PICO.

This initial implementation should work, though I have not tested it thoroughly yet, since my nice automated test case generation tool for testing this is not working yet.

I have tested the examples from the datasheet, and those work as expected.

As the Interpolator is quite a chunk of code, it might maybe also be a good idea to put it into its own file.

This PR is currently a bit WIP, and I'm open to feedback and suggestions regarding implementation and code style.

Ferdi265 commented 2 years ago

Hi! Thanks for the quick answer on the PR!

The Review comments all make perfect sense, will address them once I get to my laptop :)

I mainly looked at the Interpolator because I want to write a demo for the Raspberry Pi Pico, and while reading the datasheet I noticed some very tongue-in-cheek notes about the interpolator being able to do some things "by sheer coincidence". That led me to experimenting with it and the best way to understand it is to implement a software simulation of it.

Ferdi265 commented 2 years ago

Also, another small question I had while reading sio.ts: Is there a separate instance of SIO for each Cortex M0, or do we need to implement the doubled up Hardware Divider / Interpolator manually? (so each CPU sees their own ones as documented in the datasheet)

Or is the second core not implemented yet? (I don't quite see it at first glance)

Ferdi265 commented 2 years ago

All of your issue comments should be addressed as of 636ac2d.

As for tests: I intend to add an interpolator.spec.ts once I have exported a reasonable set of test cases from real hardware (and I'll use these same tests to verify against my other implementations of the interpolator).

urish commented 2 years ago

Or is the second core not implemented yet? (I don't quite see it at first glance)

It's not implemented yet (and so far, no one complained!). But once it will be, we'll probably have a different SIO instance per core. We would also need to implement the SIO Inter-processor FIFOs at that point.

urish commented 2 years ago

Released as rp2040js 0.16.0, and also updated wokwi.com with the latest code. Here's the interp example from the SDK examples repository:

https://wokwi.com/projects/330747140148036178

I don't have the real hardware with me, so I can't compare the output to the real hardware.

Ferdi265 commented 2 years ago

Hardware Test results:

Looks Like I have a small bug in the precision of the blend mode implementation; I'll look into that ASAP.

Ferdi265 commented 2 years ago

Looks like the bug is that my rounding is incorrect

urish commented 2 years ago

Thanks! Most of the tests are passing on the first attempt, that's very impressive.

Ferdi265 commented 2 years ago

Well, for the initial implementation in C++, I had to tinker with it for about a day to get it to work, so for the JS port I mostly had everything done, so the bugs here are just from porting to JS's limited bit operations.