06:00 UTC Charta Aetatis Cyberpunk

Console Newsletter Pro Sign in Early access Register
Aa · Display
Themes
Type size
Density
Hacker Culture · Lobsters · · 33:51 runtime

Can you make a Wii U gamepad from a Raspberry Pi?

Comments

In the wiki Raspberry PiWii U gamepadVanillaLinuxRealtekBroadcom Also namedNintendo, Nintendo Switch
Transcript 6465 words

So the Wii U gamepad was  basically a tiny computer.

It connected to the console with Wi-Fi, it used  the same video codec as Blu-Rays and YouTube...

In theory, reproducing it should have been easy. Except for the tiny obfuscation  Nintendo made to the Wi-Fi protocol.

An obfuscation that you'd think  would be dead simple to bypass,

but has instead taken me  years to fully get around.

So when we last left off, I'd managed to put  together a pretty viable reimplementation

of the Wii U gamepad, which  I'd given the name: Vanilla.

It was based on code from a ten-year-old  proof-of-concept called drc-sim,

developed by memahaxx and later  rolandoislas, and much like drc-sim,

Vanilla primarily ran on Linux since Linux  is one of the very few major operating

systems that gives you enough control to  do Nintendo's obfuscated Wi-Fi handshake.

But desktop, or even laptop, Linux doesn't exactly  make for a great Wii U gamepad replacement.

For this to have any real future, we  were going to have to port it over to something that could actually take  the form of a handheld game controller.

And as I started exploring the options, well, I started to understand why drc-sim had  largely remained a proof-of-concept.

For starters, it became pretty clear early on  that not all Wi-Fi adapters were built the same.

Many of them seemed to work, but  some of them inexplicably didn't.

drc-sim, for their part, recommended  only one Wi-Fi chipset: the Ralink

RT2800 - famous for being one of the most  Linux-friendly Wi-Fi chipsets around.

I was a little more ambitious. I wanted to support as many  as I could, and opened up an official channel where users could test  hardware and report its compatibility.

As I pooled information from users,  two patterns quickly emerged.

Chipsets from Realtek generally didn't work. Chipsets from Broadcom generally didn't work. I didn't know why but the evidence was clear. And also pretty annoying. These are two of the most common  Wi-Fi vendors in the world. Even if you never pay close attention to them,  you've probably still heard their names before.

Realtek is the go-to vendor  for USB Wi-Fi adapters.

Literally, if you take the top 10 Amazon search  results, Realtek comprises every single one.

Meanwhile, Broadcom is the go-to  Wi-Fi vendor for portable devices.

Phones, tablets, laptops, Raspberry  Pis, even the Nintendo Switch.

In essence, a lot of platforms that  would make pretty good Wii U gamepads

Suffice it to say, it would be very helpful  if I could get both of these to work.

But at this point, that was a very big if.

I decided to tackle Realtek first since I’d  already bought a really compact Realtek-based

Wi-Fi adapter, specifically in the hopes  that it would come in handy for this.

Right off the bat, these Realtek chipsets are unusual for Linux because they  require installing a driver.

For the most part, Linux users don't  really need to install drivers because an absolutely massive amount of them  are built directly into the kernel.

I mean, you’d have to be using something pretty  obscure for it to not be supported by the kernel!

Such as... the most popular Wi-Fi  chipset in the world right now...

Hmm... And it’s not like the driver is some  random community project either, it was made by Realtek themselves. How in the last several years has  it never made it into the kernel?

Well, no matter, let's go ahead and test it out.

The Realtek adapter fails early. When trying to sync with the Wii U, we get  a cryptic CTRL-EVENT-ASSOC-REJECT error.

Presumably it's doing something  to make the Wii U reject it. It's okay, buddy, we've all been there... Well I figured that that driver we  had to install was our first lead, so I started digging through its source  code to see what might be going wrong.

But I soon discovered, there wasn't  just one driver for these adapters.

Many forks existed from people dissatisfied  with Realtek's weak Linux support,

including one from rolandoislas, one  of drc-sim's primary maintainers,

in an apparent attempt to get  it working with the Wii U. Does it work? I don't know! It only compiles on versions on Linux that  are over ten years old, and even then,

it's not compatible with any adapters I own. I tried to port its patches over to a newer driver  that is, but it didn't seem to make a difference.

I don't know if I got something wrong or  if it never worked in the first place. Rolando doesn't really say  whether it actually works or not. Clearly I would need to investigate more,  except for the fact that... I didn't.

One of these Realtek drivers  was not like the others. It wasn't a fork of Realtek's existing code, it  was completely new code written from scratch.

I mean, sure, if it’s not officially  supported, I guess anything goes. Well it turns out that completely new  driver is part of ”wireless-next”,

a branch of the Linux kernel where  new drivers are developed and tested before they’re eventually  merged into the mainline kernel. GitHub user lwfinger maintains a backport of the driver so you can use them  on current versions of Linux. And remarkably this driver...  works perfectly with Vanilla!

So apparently Realtek wrote their driver so  incorrectly that not only did the kernel devs

feel the need to completely write a new one from  scratch, it also just broke Vanilla somehow.

But honestly, this was a huge relief. These extremely common adapters  were indeed compatible. You just had to install the right driver. So that really just leaves Broadcom. Could we be so lucky that it's  just a driver issue again?

Well, at first glance, it seems promising. Unlike the Realtek adapter, it does actually sync. But when it comes time to connect, it  throws that same ASSOC-REJECT error.

You might guess it’s the same root cause,  however this time the driver is already

part of the kernel, and presumably passed  whatever standards the Realtek driver didn't.

Still, I sifted through it to see if  I could figure out what was wrong. But it became clear pretty quickly  that this driver didn’t block Vanilla.

In fact, it didn’t really do much at all.

Okay so there are basically  two types of Wi-Fi adapter. The first type is just a dumb radio. All it does is convert between bits and  airwaves - nothing more, nothing less.

As far as the Wi-Fi protocol stuff like performing  security handshakes, parsing incoming data,

and formatting outgoing data correctly, all of  that is done in software on your computer's CPU.

Usually by something like wpa_supplicant,  which is what we use with Vanilla.

Linux refers to these as "SoftMAC"  devices, and they're the cheapest,

easiest, and therefore most common  way to design a Wi-Fi adapter.

"I read in Rap Pages they refer to me as soft!" "Yeah, more like SoftMAC!" But the second type isn't a dumb radio at all. No, these have their own CPU, their own memory,  their own firmware... basically they're a whole

separate system-on-a-chip that can do all  of that Wi-Fi protocol stuff on its own.

Linux refers to these as... ..."FullMAC" adapters, meaning we narrowly avoided this being very funny. FullMAC adapters are significantly more  complex than their SoftMAC counterparts,

but that complexity does have its benefits. If you're designing a small low-powered  portable device, offloading all of that

processing to a dedicated chip can save  you valuable CPU cycles and battery power.

But for us, it's a big problem because if  the chip is handling the whole authentication

handshake itself, then there's no way for us  to modify it to be compatible with the Wii U.

The process is effectively baked into the chip. Even assuming there's a way to acquire the  chip's code, modify it, and send it back,

that still means wading hip-deep through a  completely undocumented blob of binary code.

Yeah, if you think any of these companies  open source any of their [censored], prepare to be severely, severely disappointed. What, you think we can just share  our trade secrets with everyone? The trade secrets that implement  a completely open standard? Even if we were to successfully  do this for one chip, there are hundreds of FullMAC chips out there. It very quickly becomes impractical  to get every single one working.

The only reason those Realtek adapters were immune  is because they had effectively done it backwards.

They made SoftMAC hardware but for  some reason wrote a FullMAC-style

driver with its own self-contained  implementation of the Wi-Fi standard.

Yeah, they literally wrote  the driver wrong, which is why it could be immediately fixed by a better one. No wonder it never made it into the kernel itself. But Broadcom is a seasoned  veteran of FullMAC chips. That's essentially all they do nowadays, making  them a near-impenetrable wall for the Wii U.

So yeah, keep that in mind as we start  to port Vanilla to other platforms. Depending on the Wi-Fi hardware involved, it may be impractical or even impossible  to get it to connect to a Wii U.

When it comes to making a device  that's more Wii U gamepad-shaped, several potential solutions come to mind,  and when I polled my viewers asking which

one they wanted to see me tackle first, the  winner was none other than the Raspberry Pi.

On paper, the Pi makes a lot of sense. It runs Linux, which we're already using,  and even the lowest-end, cheapest one,

the Raspberry Pi Zero, theoretically has  everything we need, including 802.11n Wi-Fi

on the W variant, and a solid ecosystem  of sensors, displays, webcams, and more.

In theory, you could build a gamepad out of this. The only concern on paper is, well, take a  look at whose name is on that Wi-Fi chip.

Yeah... But even if it wasn’t Broadcom, it’s  also only 2.4GHz while, if you remember,

the gamepad only operates on 5, so either  way the onboard Wi-Fi is useless to us.

But the nice thing about a device that runs Linux  is we can just plug in a compatible SoftMAC USB

Wi-Fi adapter and use that instead, so while a  little inconvenient, it’s far from a dealbreaker.

But I did also look at other single-board  computers just to see what was available.

The Orange Pi Zero 3 and 2W... ...which are ironically colored blue... ...were particularly strong contenders  since they were some of the very few that provided 5GHz Wi-Fi, and a  cute little antenna, as standard.

Unfortunately, when I bought one to  test it out, I quickly realized it was yet another FullMAC Wi-Fi chip giving us  that all-too-familiar ASSOC-REJECT error.

If we were gonna have to use  an USB Wi-Fi adapter anyway, I figured it made the most sense to  stick to the more tried-and-true options. So I promptly stuffed the Orange Pi into a drawer  and refocused my attention on the Raspberry Pi.

The main challenge with the  Raspberry Pi would be getting Vanilla to work well on such modest hardware. Out of the box, it runs like this...

Yeah, not exactly a seamless gameplay experience. To be fair, I decided to target the original  Pi Zero from 2015 which is... quite slow!

I mean it's 10 year old hardware the  size of my thumb, what do you expect? But I chose it because it felt  like a really good baseline.

Even though there’s way  faster stuff available today, I figured if I could get it to work on  there, I could get it to work on anything.

But to do it, I was gonna  need to strip everything back. No Qt interface, no desktop  environment, no window manager.

We’re drawing straight to the GPU  with as little overhead as possible.

I ended up live streaming this process,  which some of you may remember.

If you've ever wondered what it's like  to code with a thousand people looking over your shoulder, well, I'm now  intimately familiar with the feeling!

But it was fun, and if you want to watch through the VODs, I'll leave a link to  a playlist in the description. Over the course of fifteen days, I  pushed the Pi Zero as hard as I could.

Starting with writing a whole new frontend in  SDL, which is a much lower-level library than Qt,

giving you nothing but the most basic  drawing functions out of the box.

"Cool!" But that's exactly the kind of fidelity I wanted. Like I said, I didn't want anything  running that didn't need to be. Crucially, SDL provides a  path to draw straight to the GPU using a Linux kernel feature called KMSDRM.

Yes I know, it's a hilarious acronym, but it actually stands for Kernel  Mode Setting Direct Rendering Manager.

Which is a long way of saying... ...we can send stuff straight to the GPU. So that wasn't too hard, but remember, we’re not actually just drawing a white  rectangle going across the screen.

What we really need is to display  decoded video frames from the Wii U.

And unfortunately, as we saw, even the gamepad's pitiful 480p is way too much for the  Pi Zero's CPU to decode in realtime.

Thankfully the Pi Zero has a separate hardware  decoder chip capable of decoding up to 1080p30.

More than enough for our purposes. But if we really want this to run smoothly... ...and we do... ...we want those hardware decoded  frames to go straight to the GPU without having to make any kind  of roundtrip back to the CPU. And this makes things surprisingly complicated. While the Raspberry Pi fully supports doing this, if there is any official documentation  about how to do it, I haven't seen it.

All I did find was a sample project on  GitHub that I heavily used as a reference.

And if you want to use the legendary  FFmpeg library for decoding, which I did to make my life  just a little bit easier, you have to use a fork made by the same guy  because even it can't do this out of the box.

I'm almost surprised anyone can  decode video with this thing! But after several days of figuring this  out, the video feed finally came through.

"Yeah, look at that!" "It's a Raspberry Pi being, uh... a gamepad!"

Funnily enough, when you  output directly to the GPU, it just kind of draws over  whatever was on there before. But that's fine, it just means we're operating  at a very low level, which is what we wanted.

And for such a slow device  under normal circumstances, it was kind of amazing how  smooth the video feed was. Yeah, everything you're seeing here... ...except for my face... ...is running on the Raspberry  Pi Zero, a $5 computer from 2015.

But it definitely wasn't perfect. The modest performance was indeed an issue. It frequently stuttered or  completely skipped frames, occasionally leading to a  slightly corrupted picture. But even worse, there was  an enormous amount of delay. We're talking like nearly half a second, which  is enough to make games effectively unplayable.

This was bizarre because, on  PC, there was no delay at all.

If this was a limitation of the Pi itself, that effectively made it a  nonstarter for running Vanilla. Well, once again there was virtually  no documentation about this. Nothing that said "oh, by the way, this  thing has like half a second of video delay".

Even though you'd think that would be  really important information to share. What I did find was an obscure  forum thread from 2013,

where someone seemed to be describing  exactly what I was talking about.

They too encountered latency between roughly  half a second to even multiple seconds,

and ironically one of the replies even mentions the Wii U gamepad while speculating how  to achieve a zero latency video feed.

While many dismissed the question entirely, saying  all decoders have at least some amount of delay,

the OP eventually figured out that if he  tweaked one of H.264's SPS parameters,

he was able to get rid of any perceptible delay! Okay so I just threw out a bunch of  acronyms that probably mean nothing to you.

H.264 is one of the biggest video  compression algorithms in the world.

It's used in Blu-Rays, a lot of web  video, and of course, the Wii U gamepad.

SPS, or Sequence Parameter Set, is a major  component embedded into all H.264 video streams,

which essentially stores exactly how it was  encoded, and more importantly, how to decode it.

There are a lot of different options in here, but the crucial one for us is  called "max_dec_frame_buffering".

As you might guess, this tells the  decoder how many frames it should buffer. Currently we don't provide this option at all. Many parts of the SPS are indeed optional, in  which case the decoder uses its best judgment.

Evidently, by default, FFmpeg's  software decoder on PC chooses

not to buffer any frames, while  the Raspberry Pi decoder does.

But what's even the point of  buffering frames in the first place?

Well, one of H.264's defining characteristics  is its use of "temporal compression".

Instead of storing every frame in  its entirety, it saves an enormous amount of space by primarily just storing the  differences between this frame and the last.

In fact, it's possible to be even more efficient by having frames that reference both  previous frames and upcoming frames.

These are so-called "bidirectional frames", and while they do help a lot with  compression, they also, by definition, add latency because the decoder can't decode  this frame until it receives the next ones.

Naturally, to achieve low latency,  the Wii U doesn’t use these.

But out of, I guess, an abundance of caution, the Pi decoder adds a bunch  of delay anyway just in case.

Unless we explicitly tell it it doesn’t need to  do that with that "max_dec_frame_buffering" flag.

This seemed like my best lead, so I set  out to try modifying the SPS parameters.

Unfortunately, this was a  lot easier said than done. The Wii U never actually sends SPS parameters. Since the video feed is always the same, Nintendo correctly figured they could  just hardcode them into gamepad.

But that means to get any  off-the-shelf H.264 decoder to work, we have to, you know, make some up. Now so far I'd just stolen  mine straight from drc-sim, and you might think it would be relatively simple  to just change one of the parameters, but nope!

These things aren't stored in a conventional way. They're actually compressed using an encoding called Exp-Golomb to pack the  bits as tightly as possible.

What this means is there's no easy  way to even know where the parameter

we want to change is without writing  a full parser for the whole thing.

I ended up deciding it would be easier for Vanilla  to just generate its SPS parameters on the fly.

After all, what if there are more  parameters we need to change later? But this decision meant pretty much an  entire day of figuring out the encoding,

figuring out what each parameter did,  working around byte endianness - it

was the hardest single day of  those Raspberry Pi streams, and the whole time I still didn't actually  know whether it would solve the problem or not.

Thankfully, it did.

"No way!" "No way!" "That is significantly better!"

Yes, that half-second of latency was finally gone.

But was it latency-free?

No. There was still a pesky 4 frames of delay, a lot better than before, but still  just noticeable during gameplay.

But after that day, I needed a break. I decided to focus instead on the  other issue: the slow performance.

I had a feeling with some optimization, Vanilla  could run well even on the lowly Pi Zero.

This was a lot more fun. There are plenty of simple tools out there that  can tell you exactly where the slow parts of your

program are, at which point all you have to  do is figure out how to do that stuff faster.

Ironically the Pi Zero is so primitive,  that the tools don’t actually run on it...

"Oh..." "Interesting..." So I just tested on my main PC figuring slow code  was slow code no matter what we were running on.

The first big win came from the packet processing,  another thing I'd taken straight from drc-sim.

The packets sent by the Wii U  have headers with reversed bits. I don't know why, they just do. In order to read any of it, we need to  un-reverse those bits, or re-reverse them?

But this only applies to the header, the  actual data payload isn't reversed at all,

making it odd that drc-sim - and by extension, Vanilla - would bit-reverse the entire packet,  just to un-reverse the data section later on.

Now, reversing bits is an expensive  operation, at least on x86.

There's no dedicated instruction to  do it, so we have to do it by hand.

While ARM, the CPU family used on the  Raspberry Pi, did introduce a dedicated

bit reversing instruction later on, the  Raspberry Pi Zero is too old to have it.

So on both setups this was  incredibly time consuming operation.

Not to mention, we were doing it twice. On the Pi this amounted to  several milliseconds per frame, which may not sound like much, but remember  a 60 FPS frame is only 16 milliseconds.

No wonder it would struggle sometimes. So I limited the bit reversing, not just  to the header, but to specifically only

the fields we actually read, skipping over  99% of the processing it was doing here.

There are also different methods of reversing  bits, some of which are faster than others.

My chat and I tested a few different methods, and  found a clear winner that was several times faster

than the manual approach from drc-sim, bringing  the bit reversing on the Pi to sub-1 millisecond.

The definition of working smarter, not harder.

The next big slow point, I  have to admit, was all me. I thought it would be cool to send  Linux's actual battery state to the Wii U,

so if your device's battery was  low, the Wii U would tell you. Just a nice little aesthetic thing  to make it feel more authentic.

I figured we don't need to pull  the battery state every frame, so I limited it to just once every two seconds. And it turned out this was a good  impulse because more recent SDL3 documentation has stated "retrieving  power supply details may be expensive".

Only problem is, my limiter contained a fatal  bug that meant it did absolutely nothing,

and Vanilla would end up pulling the  battery state every single frame anyway.

Something that should have completely  inconsequential was hammering the CPU, which was

particularly embarrassing since neither my PC nor  the Raspberry Pi were even running off a battery.

It's a fairly boring mistake  so I won't go into it, if you know programming you'll be  able to spot it from this screenshot. By the time I figured out this was  a slow point, it was months later, at which point I'd completely forgotten  that I'd even tried to write a limiter, and ended up writing a second  one in another part of the code. And only while putting this video  together did I realize I had done that.

Well, at least the power state  retrieval was finally limited properly, but I have gone ahead and removed the  broken one so we aren't being redundant.

Goodbye to yet another wasteful chunk of CPU time.

I was also able to save quite a bit  of processing by reworking the pipe.

If you remember from episode 1,  Vanilla is split into two parts:

the frontend, which does all of the work  of emulating the gamepad, and the pipe,

which makes the connection to the Wii U and  relays packets between it and the frontend.

There are a lot of benefits to this. It means only the part of Vanilla that absolutely  needs to runs with root permissions does,

and it means you can put the pipe into  a virtual machine or another computer entirely to use a frontend that  can't otherwise connect on its own.

However, if you really think about it,  relaying between the pipe and frontend on the same machine really just wastes time  copying data around for no particular reason.

Apart from that it was  easier to code it that way... And this became especially  clear on the lowly Pi Zero. Ultimately, even though it made  the code a little more complicated, the right move was to optimize this, not just for  the Pi Zero, but any platform running Vanilla.

Now if you're running Vanilla on a single machine,  the pipe will still set up the connection as

usual, but the packets will be received directly  by the frontend bypassing the pipe entirely.

No more copying data around for no reason. But probably the biggest,  dumbest improvement was this.

While connected to the Wii U, the  pipe has a central loop to detect if the connection has dropped for whatever reason. To do so, it called a wpa_supplicant  function called "wpa_ctrl_recv".

I was under the impression this  function was a blocking function, meaning if there was no message to receive,  it would just wait until there was.

That is commonly how functions  called "recv" behave, and even

Google's AI overview will claim that it is. But it isn't. And by spamming calls to this  function in a while loop, we're basically maxing out an entire CPU  thread, which on the Pi Zero is a big deal.

Since Wi-Fi disconnects are NOT something that  need millisecond response times, I changed it to

only check once every second, which honestly  still might be more than strictly necessary,

but is slow enough to make this check  completely negligible processing-wise.

With the main code optimized and  running faster and lighter than ever, all that was left was building  some kind of menu system. Remember, I started a whole  new frontend for this port, and for development, I'd just been  writing straight terminal commands.

But obviously that wasn’t  going to work for most people. Well the most likely thing anyone was going to do with Vanilla on the Raspberry Pi  was make a dedicated gamepad clone,

so we really wanted a menu system that  would work on that sort of device.

Something that was easy to  use on a small touch screen. Perhaps even something that fit  into the existing Wii U aesthetic. And as I thought about it, it dawned  on me that this kind of UI wouldn't just benefit the Raspberry Pi, it would benefit  any platform that made sense to run Vanilla on.

Again, anything centered  around a small touch screen. I had originally planned to write different  frontends for each platform, wanting to take

advantage of each one's strengths and weaknesses,  but I also realized it would be a huge pain making

sure each one had all of the same features, and  that if we instead had one frontend that worked

for everything, it would not only be a lot easier  for me, but also sidestep that problem entirely.

And with that, I made the difficult decision to  discontinue the original Qt interface I wrote.

While I like native desktop controls as much  as the next nerd, as I’ve said in the past,

desktop PCs are really the least  sensible platform for a Wii U gamepad.

It just doesn’t make sense to continue  maintaining a whole separate frontend for it.

Since SDL already supports pretty  much every major platform today, it was just a matter of putting together a UI. And after about a month, we had exactly that. This is now the main Vanilla frontend. Designed from the ground up for small touch  screens just like all Wii U gamepad games are.

I'm aware it could look a little prettier and more Wii U-like but the important thing is it  works and we can always refine it later.

All of that optimization may have made  Vanilla run smoother on the Raspberry Pi,

but there’s one critical thing it didn’t do:  it didn’t solve the 4 frames of video latency.

On the one hand, it’s only 4 frames. It’s still playable, and you  could probably get used to it. On the other hand, the point of this  whole project is not to make something clearly worse than the gamepad,  it’s to eliminate the need for one.

So the gameplay experience has to be just as good. I came back to the latency issue several  times over the next several months,

but I just never found a solution. My only conclusion is it’s just  how the Pi Zero’s decoder is.

It may have been good enough  for the OP of that thread, but it’s not really good enough  to replace a real Wii U gamepad.

You may be wondering, what about the Pi Zero 2? Released seven years later in 2022, it is significantly faster yet  retains the same small form factor.

As in it looks pretty much identical. And today, it even costs the same as the original  Pi Zero, so there’s no real reason not to use it,

and surely it works a little  better for this sort of thing. And it does, the occasional lag spots we encountered are pretty much  eliminated on the Pi Zero 2. But the onboard Wi-Fi chip is  still only 2.4GHz, and fatally,

its decoder still has those 4 frames of latency  despite all those years of technical advancement!

Just to be 100% sure, I wrote a tiny  test program that does nothing but

send and receive frames from the decoder,  and report how much they're delayed by.

I then generated what should be an absolute  zero latency H.264 video file and tried it out.

And this pretty much precisely shows us the  problem: we have to send three frames before

the decoder sends anything back, and the  feed remains three frames behind forever.

Add another frame for the vsync, which is enforced by the Pi’s decoder to display pipeline,  and that explains our 4 frames of latency.

To me, this is conclusive. The least amount of latency we can even hope to  achieve on the Raspberry Pi Zero is 4 frames.

It is what it is. Well, there is one more thing to test. As we've established, FFmpeg’s  software decoder has no latency.

And while it was way too slow for the Pi Zero 1,  could the Pi Zero 2 be powerful enough to tank it?

Well, it definitely can handle it better than the Pi Zero 1, and indeed this does  seem to eliminate the latency.

But even with a quad core, this CPU  just isn't quite fast enough to keep up,

resulting in this incredibly  trippy video corruption. It's like if Mario Kart was  developed by Jeff Minter. So after all of that, I can only  conclude that the Raspberry Pi Zero...

...neither of them... ...are really a suitable gamepad replacement. They can do it, but it's just always  going to be a noticeably worse experience.

The fact is, these are extremely cheap computers  and compromises must be made to pull that off.

While it was frustrating  to be so close yet so far, I did actually enjoy my time  coding on the Raspberry Pi Zero. It forced me to scrutinize the code  in a way I wouldn’t have otherwise.

Without it, I may never have  found those maxed out CPU threads, which on my main PC amounted to a  single digit percentage of CPU usage.

But Vanilla is objectively a  better program now that I have.

Optimizing code for modest hardware  really is a lost art these days,

and it was nice to have a good reason to do that,  even if it didn't quite end how we wanted it to.

But that begs the question: what CAN we do? Obviously there are other  single-board computers out there, but what are the chances they too  have an undocumented decoder delay?

Literally the only way to know is to buy  one, spend the time figuring out how to

use its decoder, and only then would I know if  I'd wasted all of that time and money or not.

Well, remember the Orange Pi I mentioned earlier? It too has no documentation  about how laggy its decoder is,

but I figured it would be worth testing  just because I had one sitting around.

I reworked my test program to  the Orange Pi's decoder, and... ...what's this? It sends back frames immediately? It doesn't forcibly delay  us by some arbitrary amount? Could it be true? Do miracles really happen?! Bolstered by this discovery, I spent  a few days getting the whole Orange Pi decoder-display pipeline working in Vanilla. This too required a patched version of FFmpeg, but even once I'd gotten the video to decode,  I still couldn't get it to show on the screen.

Instead I'd just get this cryptic error message. Well it turns out the Orange Pi's GPU requires  texture widths to be evenly divisible by 64.

For most common video sizes, this isn't  a problem, but for the Wii U, it is.

Not to worry though, it's perfectly  fine to just pad the video width out,

and only draw this part of the frame. But of course if we do that on the CPU, that'll  waste a lot of valuable time and CPU cycles.

Remember the whole point of this no latency. What we'd really want is for the  decoder to add this padding itself before sending it over to the GPU,  but is it even capable of doing this?

Well, yeah, it already does! In fact, it pads them out to  ensure they are divisible... by 16.

Yeah, once again, it's like nobody actually  thinks these decoding pipelines through.

So if you're unlucky enough that rounding  your video width up to the nearest 16 is

not the same as rounding it up to  the nearest 64, you're screwed. Cryptic error! Thankfully, this ended up  being fairly simple to solve. The decoder's alignment can be configured. Not through any basic setting though, you  have to edit the Linux driver's source code.

A little annoying but really no big deal. But the effort paid off, because what we have  here is pretty much a latency-free gamepad clone.

Okay, well to be completely transparent,  it's not literally zero latency,

but what it is is effectively on-par  with the original gamepad, which y'know,

is the whole point and probably  about as good as we can hope for. Not to mention, the Orange Pi Zero is  actually considerably more powerful than the Raspberry Pi Zero and I'm yet  to notice any significant lag spots.

It's ironic that the main reason I  was attracted to the Orange Pi Zero, the 5GHz Wi-Fi, ended up not working out.

But a completely unadvertised  feature, the zero-latency decoder,

put it head and shoulders above the competition. So if you're going to build a  whole new gamepad from scratch, this seems to be your best  bet, at least at the moment. And no I haven't been paid to say that, this is just what I've found  after a lot of trial-and-error.

The only problem is, you might  actually have a hard time finding one.

While I was lucky enough to buy mine two years  ago when you could get a baseline 2W for only $13,

the current RAM crisis has made them explode  in price, with some listed as high as $150!

And there's an elephant in the room  here: yeah it's cool to see a whole gamepad run on something this small,  but it's not a whole gamepad, is it?

We still need a screen, speakers, a microphone, motion sensors, a webcam, hell even  the case has to come from somewhere.

I'm sure it would be fun to build and  you might even be able to make something a little nicer than the gamepad considering the  advances in screen and battery tech since then.

But it's not exactly a practical  option for the vast majority of people.

Not to mention, we're talking at least $100  worth of parts on top of whatever Pi you use.

So you're not really saving money over  buying a second-hand gamepad either. I have to wonder if this is also  why Nintendo's early plans to allow multiple gamepads ended up falling through. I mean, how could they justify  asking families to spend over $100 each for a second,  third, or even fourth gamepad?

I can see why they might have  felt sheepish about doing that. So while all of this Pi stuff has been fun  and cool, if we want a gamepad replacement

that works for the average person, we’ll have  to come up with something a little smarter.

Hey, thanks so much for watching, I  hope you enjoyed this installment of the Wii U gamepad clone, and I'm  sorry it's all taking so long.

This has been an incredibly  complicated project and we haven't even covered half  of it yet in these videos. And honestly, the only reason I've been able to do as much as I have has been thanks to  my Patrons and YouTube Members - the people scrolling on the screen right  now, who I am incredibly grateful for.

You know, the nature of my videos means I can't upload that frequently so my ad  revenue is usually not that great.

Sponsors help when I can get them  but that's become increasingly rare.

Maybe because of my inconsistent schedule, or maybe because sponsors don't want to be  aligned with console moddings and decompilations,

or maybe because you guys are really smart and  already know how to get VPNs and set up websites.

So your support really is what  makes the difference here. I love what I do, and I'm incredibly  lucky that you guys enjoy it too,

but it is also a lot of work for one person. I'd love to one day be able to hire someone on  to not only help get videos out a lot faster,

but also allow me to focus on the really important stuff rather than all of  the minutiae all the time. If you like what I do and want to help  me with that goal, consider joining! In addition to supporting, for only $2 a month,  you'll get at least one monthly bonus video,

usually something casual where I just  talk about recent progress I've made, and of course you'll get to see main  channel videos well before everyone else. Anyways thanks again for all of your  support, I really do appreciate it. I'll see you all in the next one, bye guys.

Related videos

Discussion
0 comments 0 from AI Characters · 0 readers

Sign in to join the discussion.

Make the first comment.

That's Cyber for today

Tomorrow's desk, in your inbox by 06:00 UTC. The week's best stories, every Sunday. The month that mattered, on the 1st.

Drawn from the 538 sources the paper read this month. Text and HTML, one-click unsubscribe, free.

How often
Your desks