# X100e keyboard → USB (Teensy 4.1)

Two sketches:

| sketch | what it does |
| --- | --- |
| `x100e_mapper/` | Learns which ribbon contacts each key connects, then prints a finished `keymap.h`. |
| `x100e_usb/` | The actual firmware: key matrix + Fn layer + TrackPoint, all over USB. |

The X100e's matrix isn't published anywhere, so the mapper step is required.
The firmware won't scan until `keymap.h` has been replaced.

## 1. Wire it

* Put every keyboard FPC contact on its own Teensy pin (an FPC breakout board helps).
  List those pins, in ribbon order, in `FPC_PINS` at the top of `x100e_mapper.ino`.
* Skip pin 13. The onboard LED pulls it low.
* **The Teensy 4.1 is 3.3 V only and NOT 5 V tolerant.** Power the TrackPoint from 3.3 V,
  and pull its CLK and DATA lines up to 3.3 V (4.7 kΩ is a good value).

## 2. Map the matrix

1. Arduino IDE + Teensyduino. Board: **Teensy 4.1**. USB Type: **Serial**.
2. Leave the TrackPoint unpowered. Flash `x100e_mapper`.
3. Open the Serial Monitor at 115200 baud.
4. Press each key it asks for. Type `s` + Enter to skip a key, `b` + Enter to go back one.
5. Copy the printed block over `x100e_usb/keymap.h`.

The mapper also lists contacts that no key used. Those are the TrackPoint, power and
ground candidates. Check them with a multimeter against the TrackPoint board to find
CLK, DATA, RESET, VCC and GND.

## 3. Flash the firmware

1. In `x100e_usb.ino` set `TP_CLK`, `TP_DATA` and `TP_RESET` (use `-1` if there's no reset
   line). Set `USE_TRACKPOINT 0` to skip the TrackPoint entirely.
2. USB Type: **Keyboard + Mouse + Joystick** (or **Serial + Keyboard + Mouse + Joystick**
   to see debug prints).
3. Flash it.

## Behaviour

* **Fn layer:** Esc = mute, F1/F2 = volume down/up, F9/F10/F11 = prev/play-pause/next,
  Insert = PrtSc, Delete = Scroll Lock. Edit the `fn` column in `keymap.h` to change these.
* **Ghost blocking:** the matrix has no diodes, so when three held keys form the corners
  of a rectangle, the fourth corner is ignored.
* **TrackPoint:** hold the middle button and push to scroll (vertical and horizontal).
  Tapping the middle button sends a middle click.
  Tune `TP_SPEED` and `SCROLL_DIV` to taste.

## Troubleshooting

* **Nothing types:** is `keymap.h` still the placeholder? Is the USB Type right?
* **Random extra keys:** raise `SETTLE_US`, or check for a loose FPC contact.
* **TrackPoint not responding:** check the 3.3 V supply and the pull-ups, then try
  flipping `TP_RESET_ACTIVE_HIGH`. The Serial Monitor shows the init result.
