Serisium / Shinewave

Passthrough signal decoder and LED visualizer for use in Gamecube Controller mods
MIT License
39 stars 11 forks source link

Problem with hex files #7

Open Shrobo opened 6 years ago

Shrobo commented 6 years ago

Hey Garrett, When I compile the source code of the latest shinewave version (0.1.1) I dont get the hex file provided in the post. Instead the resulting hex file lets the controller flash red in random intervalls. When i compile the earlier version (0.1 - falco) I get a working hex file but not the one provided in the posts. In both releases the hex files are identical but I chant get any of the codes to result in this hex file.

How did you get to this hex file?

The reason im asking this is because I found out that even though the code is meant for gamecube and wii only this hex file suprisingly works for wii u too (but in 4x the speed). sincerely, -Shrobo

Serisium commented 6 years ago

Hey @Shrobo, thanks for the interest! There are a couple of root causes to the issue you mentioned.

Since the animations I wrote are tied to framerate, polling four times as often will actually cause the animations to run four times faster than intended, like you observed. The solution here would be to decouple animations from framerate by measuring the time passed between frames and progressing the animation in terms of that delta. This would require an increase in resolution in the animation color code(currently 8 bits per channel). Additionally, the Gamecube tends to stop polling during "lag frames", which include loading screens. Ideally, the animation would continue to progress even during lag frames.

Secondly, the slightly different period coming from the Wii U adapter is difficult to account for. As is, the ATTiny85 in the original Shinewave mod is running at 16MHz while the GCC protocol has a period of 4us. This gives a clean 64 clock cycles per signal period. Since the "critical" portion of the signal that actually reads out a "1" or "0" occurs between 1us and 3us each period, we should read the line at 2us to get a good read. This leaves only 32 clock cycles to read the signal, store it in a register, and push the register onto the stack after eight reads. Certainly doable, but difficult.

The issue arises when the period on the line differs significantly from my measured setup. I addressed this in this commit, where I replaced a hardcoded number of nop delays with a dynamic period counter and some bit-shifty math. This appeared to work for both Wii-U and Gamecube messages, but was inconsistent and failed some of the time.

As the project matured a bit, I decided to make a few changes that would allow me to support USB functionality:

Unfortunately, I decided to keep these changes in the main project instead of creating a new one, so it's difficult to see where these changes occur. In retrospect, I should've forked this repo and created a new one on the new platform. My solution to the polling rate was particularly clever, and could be ported pretty easily to work with other operating frequencies. Since it relies on the hardware clock to count cycles and abuse of the Serial peripheral to read data, it can also be tuned at runtime to different polling frequencies.

Serisium commented 6 years ago

With this situation in mind, there are a few maintenance fixes that would need to go into place to fix this issue.

Then, a couple of development changes would be needed.