---
name: hw-interface
description: Keep the firmware and its board in step with a hardware-agent-kit board repo. Write the firmware's pin needs from the roadmap specs, check the board's board.json against them, and keep requirement IDs in the REQ-<AREA>-<NNN> form the board traces to. Use when a spec touches pins, buses or interrupts, or when the board repo exports a new board.json.
---

Keep the hardware interface between this firmware and its board repo. The board repo follows hardware-agent-kit:
its `trace.py --firmware` checks each `REQ-*` it cites, and its `pins.py` assigns pins from the firmware's needs.

## Files

| File | Owner | Content |
|---|---|---|
| `hardware/pin-needs.txt` | firmware | One function per line: `FUNCTION  SIGNALS  [GROUP]`. The board repo copies it to `pin-data/pin-needs.txt`. |
| `hardware/board.json` | board repo | Copy of the board repo's `pin-data/board.json` (`pins.py export`): pins, signals, peripherals, interrupt lines, rails, revision, hardware ID. Do not edit it. |

## Steps

1. Read the specs in `roadmap/` that touch hardware: their *Interfaces* (peripheral, pins, bus speed) and *Behaviour*.
2. Write one line per function in `hardware/pin-needs.txt`. Name the function as the schematic net will be named
   (`IMU_SCK`, `MOTOR_PWM_A`). Give the signals the function can use, alternatives separated by `|`:
   - an alternate-function name, with `*` and `{x}` placeholders: `SPI{n}_SCK`, `ADC1_IN*`;
   - `GPIO` (any I/O pin), `EXTI` (any pin with its own interrupt line), or an exact pin (`PA13`).
   Give the functions of one bus the same group, so one peripheral instance serves the whole bus.
3. Give `hardware/pin-needs.txt` to the board repo. Do not choose pins: the board picks them from the placement.
4. When the board repo exports a new `board.json`, copy it to `hardware/board.json`. Run
   `python3 .claude/skills/hw-interface/hw_interface.py check hardware/pin-needs.txt hardware/board.json`.
   Fix each error before you change a driver.
5. Configure each driver's pins, peripheral instance and interrupt line from `hardware/board.json`.
   Do not copy a pin by hand into a source file without a check that reads `board.json`.
6. Run `python3 .claude/skills/hw-interface/hw_interface.py ids .`. Fix each error.
7. Report changed files, the `check` and `ids` results, and each warning.

## Requirement IDs

- Each requirement has one ID: `REQ-<AREA>-<NNN>`. AREA is capital letters and digits (`MOTOR`, `BLE`, `PWR`).
  NNN is three digits.
- Define each ID once: in the first cell of its table row, or at the start of its heading.
- Never reuse or renumber an ID. A removed requirement keeps its ID, marked *Deleted*.
- The board repo cites these IDs in `docs/requirements.md`. `trace.py --firmware <this repo>` fails on an ID that
  this repository does not contain.

## Rules

- `board.json` describes one revision (`revision`, `hardware_id`). Firmware that supports several revisions
  reads the hardware ID at start-up (the board's straps or ADC ladder) and selects the pin set.
- A board function that no need names is a warning: confirm that the board repo did not add a function the firmware
  does not drive.
