Hello Geekhack!
This topic was originally opened on the LTT forums, but I decided to move it here because it felt more appropriate.
Unfortunately, there wasn't much engagement on the thread over there, and I thought you guys, here, might be more interested in this project.
This post will bundle the two posts I made on the LTT forums into one. Shortly after this, I will post a new one with the latest updates.
(Post 1)
Hi guys!
I'm Nathan, a French back-end software engineer by day and electronics enthusiast by night. Currently, I'm in the process of reverse engineering the new Magic Keyboard 2 from Apple.
You might say:
> Yeah, but for what? That's just silly and a waste of time...Well, I want to transform the Apple Keyboard into a mechanical keyboard.
I plan to dismantle the entire keyboard, keep the main logic board, reverse engineer the matrix and other components, create my own PCB, connect it to the Apple board, and voila! A Mechanical Magic Keyboard is born. Or as I like to call it, the Magicanical Keyboard (funny, right?!).
> Ok, fine, but I still think this is silly. Couldn't you just build a Bluetooth board and call it a day?And I would answer:
> Nooo!!These new keyboards come with a built-in fingerprint sensor, known as Touch ID. As a Mac user
(you can boohoo me if you want), both at home and work, I frequently use docked Macbooks. So, having a keyboard that is seamlessly integrated into the Apple ecosystem with easy pairing, Touch ID, battery indicator built into the OS, and more would be fantastic!
Here's a rundown of the tasks that need to be done: (Done ✅, To do ❌) (Updated 2023-10-05)
- Teardown the keyboard ✅
- Figure out the functionality of each component ✅
- Determine how the keys are connected to the microcontroller (whether it's a standard scanning matrix or something else, considering it's Apple after all...) ✅
- If it's a standard scanning matrix, understand how key presses are detected (whether the matrix is resistive or capacitive) ✅
- Plot each key's row and column ✅
- Create a development board to verify the theory ✅
- Debug/test the development board to ensure everything is functioning correctly ✅
- Search for a keyboard case that can accommodate my custom board - If I can't find what I want, design one from scratch ✅
- Determine how to fit the Touch ID sensor into a keycap ✅
- If I can fit it inside a keycap:
- Reverse engineer how the button under the Touch ID sensor is connected to the main board. ✅
- If I can't fit it inside a keycap:
- Figure out where I can fit this sensor!- Create the final board and custom flex PCBs to go with it ❌
- Find macOS keycaps ❌
If I have time, here are some additional cool things I'd like to do:
- Replace the lightning connector with USB-C ❌
- Add per-key backlighting with a sleep timer
(This would require in-depth reverse engineering of the Apple board, so it may not be doable) ❌
> Okay, that seems like an interesting idea... When you're finished, could I replicate the project?Absolutely! The project will be fully open-sourced when it's completed.
So, are you pumped for this? Let's get started!
1) Tearing down this bad boiiiI got this second-hand keyboard from LeBonCoin (the french equivalent of Craigslist), for 70€.
It was essential for me not to destroy a brand new keyboard, and if you decide to replicate this project in the future, I hope you'll consider using a second-hand keyboard (ones with spilled coke and sticky keys are perfect! 😛).
I'm passionate about making the world as sustainable as possible, so repurposing broken keyboards is the way to go!
Mine came with a broken key (damaged scissor mechanism and missing a keycap).
Front of the magic keyboard:
The back:
Removing the plastic rear cover was a NIGHTMARE. It took about an hour and a half and two bloody fingers to remove it! The surface was covered with a lot of glue, so I had to use a trusty hair dryer, guitar picks, a box cutter, and an old fidelity card to remove it.
Here's the "lot of glue":
If you decide to tear down your own keyboard, be careful not to insert your prying tools between the back cover and the plastic reinforcement plate. Instead, insert them between the back cover and the plate.
Here's a picture to illustrate what I'm talking about:
After applying heat, cutting the glue, and gently pulling the cover to avoid breaking it, I thought I could proceed with the reverse engineering without damaging anything. Silly me! 😄
The backing was finally off, and I needed a coffee break at that point. 😅
Yes, I know some screws are missing in the picture, but my camera decided not to focus properly. This is the only clear shot I have of this step.
Next, I removed all the small torx screws, disconnected the battery, and the plastic frame was finally free. And boom! We finally arrived at the interesting parts—the electronics!
Let's take an overview of what's going on here:
Now, let's try to remove the logic board from the chassis, and here's where the trouble began (unfortunately, I didn't have much footage of the following parts).
While attempting to remove the sticky tape from the keyboard matrix connector, I accidentally broke the upper part of the connector. At that moment, I naively thought:
But that wasn't the end of it! The back of the ribbon that plugs into this connector was covered in double-sided tape, which I didn't know at the time. When I tried to remove it without heating up the tape, I broke a small plastic bit that locks the connector. 🤦♂️
Here's what it looked like afterward:
Well, it seems I'll need to replace this connector now. Or maybe not. We'll see. Perhaps I'll just solder a flex cable directly to the main board.
Now that all the components are extracted from the chassis, I still don't have access to my matrix. At this point, it's time to bring out the big guns!
I need to remove the little plastic film that is glued to the aluminum frame. I believe this is to prevent crumbs, water, or any other debris from entering the keyboard.
To get this structural layer out of the way, I tried to create a lever using my small flat screwdriver at the solder points.
And it worked! After peeling away all that aluminum, we finally reach our goal. Here's a reconstruction of what it looked like:
It appears to be a basic keyboard matrix with rows and columns, without any Apple shenanigans involved!
The plastic matrix!
> Yeah, this project is going somewhere!!!
2) Let's take a closer look at this matrixAs we can see in the previous picture, it appears to be a classical resistive membrane keyboard.
Here's a schematic of how it works (Courtesy of Deskauthority):
Source:
https://deskthority.net/wiki/Membrane_keyboardThe dome puts pressure on the top membrane, which deforms it and makes contact with the bottom membrane, completing the circuit. So, in theory, all I need to do to make it work is to figure out where each key connects to the 40-pin connector we saw earlier. And that's exactly what I've done!
"Thanks, Apple, for this choice. If the matrix were capacitive, I would have killed the project. In that case, I would need to delve deep into the Apple mainboard electronics and firmware to figure out what's going on and buy a fancy ESR meter to measure the precise change in capacitance when a key is pressed."3) Tracing the connectionsTo identify the location of each key on the matrix, I scanned the matrix using my printer.
There was a small problem: the area where the pins are exposed is not translucent, so I couldn't determine where each pin goes. Luckily, Apple used tape for the reinforcement, so with the tip of a razor blade, I could peel it off.
That's better!
Before proceeding with the entire process, let's test our previous theory by simulating a "1" keypress.
I traced the two pads back to their respective pin on the matrix, masked every pin that was not the two I wanted to bridge on the connector, and bridged them using a male-to-male DuPont cable. AND IT WORKED!
(Once again, a reconstruction of what I did at that point)
An army of "1"s started appearing on my screen!
Now, after letting my sanity slip away for hours on end, I traced every trace on this flex board...
And ended up with this magnificent wallpaper!
I was so proud of myself at that point... but a crucial part was still missing...
I needed to plot each matrix position on a spreadsheet.
sighSo that's what I did... and now I can attempt to replicate it on a custom development/validation board.
But that will be for next time...
(Post 2)
Welcome back!
A lot of progress has been made since the last post, and the project is still going strong!
First of all, here's a table showing the two pins for each key.
I'm including this table because I realized it was missing before.
To validate my reverse engineering work before making the final PCB, I've created a development board to reproduce the matrix.
To get a rough idea of the voltage of the CAPS lock LED, I measured it with my multimeter, and it showed around 3.2V.
This was my first time using KiCad, and I switched from Eagle due to the recent changes in Eagle's payment scheme. KiCad's free and open-source nature, along with its strong community recognition, convinced me to switch.
So here's the schematic:
I didn't connect CAPS_LOCK_LED_- to ground because it doesn't seem to be connected.
As you can see, I've done my reverse engineering work on a French Magic Keyboard, and it seems that this work will be compatible with all magic keyboards that have 88 keys—heck, even the 87-key one. After carefully examining every layout on Apple's website, I noticed that only the US and Chinese versions have one less key. It's likely that Apple initially designed the 88-key layout and then removed a key from the matrix for the US and Chinese keyboards.
What's even more intriguing is the similarity I noticed in the connectors on both motherboards—the full-size one and the ten-key-less (TKL) one. Although I haven't reverse-engineered the larger keyboard, I speculate that Apple might have taken the matrix from the bigger keyboard and removed unnecessary keys to create the TKL version.
Considering both connectors have 40 pins and look identical between the full-size and TKL versions, it's reasonable to assume that the matrices might be the same across both keyboards. On my TKL board, I observed several pins on the connector being connected to ground, indicating unused connections. This similarity and the presence of unpopulated pins support the notion that the matrices are likely the same across both the full-size and TKL versions, regardless of the regional layout.
If you closely examine both boards, you can see the same connector on both the TKL and full-size one (Picture courtesy of SnazzyLabs).
Source:
https://www.youtube.com/watch?v=hz9Ek6fxX48For the curious ones among you the connector is the FF14A -40C -R11DL-B-3H from DDK.
https://www.ddknet.co.jp/English/products/print/fpc-connectors/ff14a/FF14A-C_ENG.pdfAfter the schematic, here's the dev board layout:
For the FPC connector, I've used a random 0.5mm pitch connector from the KiCad library.
You might ask:
> Why did you put four plated holes for each key? A switch only needs two...Yeah, you're right, but I added the extra plated holes because I want to put dupont male headers on the top two pins and use a dupont cable with a diode to try to find the "direction" of the matrix.
If I can figure out which pin is the row and which pin is the column, I could add a diode to each key to prevent key ghosting from happening at the hardware level. Though I suspect Apple might have used a fancy algorithm to avoid that at the firmware level or simply limited the number of keys that can be pressed simultaneously. I haven't tested that yet before tearing down the keyboard.
Now it's time to send those boards to PCBWay and wait for them to arrive.
Stay tuned for the rest of the project!