// The Nano, CH340 clone. Seated frame: z = 0 is the header plastic's underside.
// The plastic is 2.54 mm, so the board's underside is at z = 2.54 and its top at z = 4.14.
// Child values with a schematic source are the engine's board example values by role, from
// packages/engine/tests/circuits/atmega-board-button/netlist.json.
{
  "format": 1,
  "part": "nano-board",
  "version": "0.2.1",
  "title": "Nano (CH340 clone)",
  "summary": "ATmega328P board, 18 x 43.2 mm, 30 pins on two rows 15.24 mm apart. D13 drives the L LED. Powered from USB.",
  "tags": ["board", "microcontroller", "avr", "atmega328p", "usb"],
  "license": "MIT OR Apache-2.0",
  "docs": {
    "Arduino Nano A000005 datasheet": "https://docs.arduino.cc/resources/datasheets/A000005-datasheet.pdf",
    "Arduino Nano A000005 full pinout": "https://docs.arduino.cc/resources/pinouts/A000005-full-pinout.pdf",
    "Arduino Nano schematic, revision 3.0": "https://www.arduino.cc/en/uploads/Main/ArduinoNano30Schematic.pdf",
    // The CH340 clone's resistor values cite this name. It is not the official schematic above.
    "development board schematic, revision 3": null,
  },
  // A clone has no maker's sheet. The official board is the representative for size and pinout.
  "real": { "generic": true, "maker": "Arduino", "number": "A000005", "datasheet": "Arduino Nano A000005 datasheet" },
  "uses": {
    "ams1117-sot223": "0.2.0", "atmega328p-tqfp32": "0.2.0", "capacitor-0603": "0.2.0",
    "capacitor-tantalum-3216": "0.2.1", "ch340g": "0.2.0", "crystal-3215": "0.2.0",
    "diode-sod123": "0.2.0", "led-0603": "0.2.0", "pin-header-1x15": "0.2.0", "pin-header-2x3": "0.2.0",
    "resistor-0603": "0.2.0", "resonator-cstce": "0.2.0", "tactile-switch-smd": "0.2.0", "usb-mini-b": "0.2.0",
  },
  "params": {
    "firmware": {}, // the scene must set it, as `"firmware": "build/button.ino.hex"`
  },
  "ground": "usb.GND",
  "parts": {
    "usb": { "type": "usb-mini-b" },
    "j1": { "type": "pin-header-1x15" }, // right row, Nano leads 1 to 15
    "j2": { "type": "pin-header-1x15" }, // left row, Nano leads 16 to 30
    "icsp": { "type": "pin-header-2x3" },
    "mcu": { "type": "atmega328p-tqfp32", "firmware": { "param": "firmware" } }, // the Nano's firmware reaches the 328P
    "usb_serial": { "type": "ch340g" },
    "regulator": { "type": "ams1117-sot223" },
    "sw_reset": { "type": "tactile-switch-smd" },
    "resonator": { "type": "resonator-cstce" },
    "r_l": { "type": "resistor-0603", "resistance": { "value": 1000, "unit": "ohm", "source": { "datasheet": { "doc": "development board schematic, revision 3", "at": "RN2A, 1K", "basis": "nominal" } } } },
    "r_pwr": { "type": "resistor-0603", "resistance": { "value": 1000, "unit": "ohm", "source": { "datasheet": { "doc": "development board schematic, revision 3", "at": "RN4D, 1K", "basis": "nominal" } } } },
    "r_tx": { "type": "resistor-0603", "resistance": "1k", "not_simulated": "It feeds the TX LED, which follows the CH340G." },
    "r_rx": { "type": "resistor-0603", "resistance": "1k", "not_simulated": "It feeds the RX LED, which follows the CH340G." },
    "led_l": { "type": "led-0603", "color": "yellow" },
    "led_pwr": { "type": "led-0603", "color": "red" },
    "led_tx": { "type": "led-0603", "color": "green", "not_simulated": "The CH340G drives it, and its model covers only TXD and DTR." },
    "led_rx": { "type": "led-0603", "color": "red", "not_simulated": "The CH340G drives it, and its model covers only TXD and DTR." },
    "crystal": { "type": "crystal-3215" },
    "diode": { "type": "diode-sod123" }, // D1, MBR0520 in Arduino Nano schematic revision 3.0, "+5V AUTO SELECTOR"
    "c_usb_a": { "type": "capacitor-0603", "capacitance": "100n", "not_simulated": "The clone's schematic is not cited, so its value and net are unknown." },
    "c_usb_b": { "type": "capacitor-0603", "capacitance": "100n", "not_simulated": "The clone's schematic is not cited, so its value and net are unknown." },
    "c_bulk_usb": { "type": "capacitor-tantalum-3216", "capacitance": "10u", "not_simulated": "A rail capacitor. The engine's board example leaves rail capacitors out." },
    "r_txd": { "type": "resistor-0603", "resistance": { "value": 1000, "unit": "ohm", "source": { "datasheet": { "doc": "development board schematic, revision 3", "at": "RN4B, 1K", "basis": "nominal" } } } },
    "r_rxd": { "type": "resistor-0603", "resistance": "1k", "not_simulated": "Its far end is the CH340G's RXD, which its model does not cover." },
    "c_reset": { "type": "capacitor-0603", "not_simulated": "It carries the CH340G's DTR pulse to RESET for an upload, and upload is not simulated, so DTR never moves. Left in, it would only settle RESET by microvolts after each move of the 5V rail.", "capacitance": { "value": 1e-7, "unit": "F", "source": { "datasheet": { "doc": "development board schematic, revision 3", "at": "C5, 100 nF", "basis": "nominal" } } } },
    "r_reset": { "type": "resistor-0603", "resistance": { "value": 10000, "unit": "ohm", "source": { "datasheet": { "doc": "development board schematic, revision 3", "at": "RN1D, 10K", "basis": "nominal" } } } },
    "c_bulk_reg": { "type": "capacitor-tantalum-3216", "capacitance": "10u", "not_simulated": "A rail capacitor. The engine's board example leaves rail capacitors out." },
    "c_reg": { "type": "capacitor-0603", "capacitance": "100n", "not_simulated": "A rail capacitor. The engine's board example leaves rail capacitors out." },
  },
  // Every wire is copper on the board, so each is a trace, which the viewer does not draw.
  "wires": [
    // GND
    ["usb.GND", "j1.4", { "kind": "trace" }],
    ["usb.GND", "j2.14", { "kind": "trace" }],
    ["usb.GND", "mcu.GND", { "kind": "trace" }],
    ["usb.GND", "usb_serial.GND", { "kind": "trace" }],
    ["usb.GND", "resonator.GND", { "kind": "trace" }],
    ["usb.GND", "led_l.cathode", { "kind": "trace" }],
    ["usb.GND", "led_pwr.cathode", { "kind": "trace" }],
    ["usb.GND", "sw_reset.b", { "kind": "trace" }],
    ["usb.GND", "regulator.GND", { "kind": "trace" }],
    ["usb.GND", "icsp.6", { "kind": "trace" }],
    // USB 5 V through the Schottky onto the 5V rail
    ["usb.VBUS", "diode.anode", { "kind": "trace" }],
    ["diode.cathode", "j2.12", { "kind": "trace" }],
    ["diode.cathode", "mcu.VCC", { "kind": "trace" }],
    ["diode.cathode", "mcu.AVCC", { "kind": "trace" }],
    ["diode.cathode", "r_reset.b", { "kind": "trace" }],
    ["diode.cathode", "r_pwr.a", { "kind": "trace" }],
    ["diode.cathode", "usb_serial.VCC", { "kind": "trace" }],
    ["diode.cathode", "regulator.OUT", { "kind": "trace" }],
    ["diode.cathode", "icsp.2", { "kind": "trace" }],
    // RESET, with the auto-reset from DTR
    ["mcu.PC6", "j1.3", { "kind": "trace" }],
    ["mcu.PC6", "j2.13", { "kind": "trace" }],
    ["mcu.PC6", "sw_reset.a", { "kind": "trace" }],
    ["mcu.PC6", "r_reset.a", { "kind": "trace" }],
    ["mcu.PC6", "c_reset.b", { "kind": "trace" }],
    ["mcu.PC6", "icsp.5", { "kind": "trace" }],
    ["usb_serial.DTR", "c_reset.a", { "kind": "trace" }],
    // Serial between the CH340G and D0, D1
    ["usb_serial.TXD", "r_txd.a", { "kind": "trace" }],
    ["mcu.PD0", "r_txd.b", { "kind": "trace" }],
    ["mcu.PD0", "j1.2", { "kind": "trace" }],
    ["mcu.PD1", "j1.1", { "kind": "trace" }],
    ["mcu.PD1", "r_rxd.a", { "kind": "trace" }],
    ["r_rxd.b", "usb_serial.RXD", { "kind": "trace" }],
    // D13 and the L LED, PWR LED
    ["mcu.PB5", "j2.1", { "kind": "trace" }],
    ["mcu.PB5", "r_l.a", { "kind": "trace" }],
    ["mcu.PB5", "icsp.3", { "kind": "trace" }],
    ["r_l.b", "led_l.anode", { "kind": "trace" }],
    ["r_pwr.b", "led_pwr.anode", { "kind": "trace" }],
    // Header pins to the chip
    ["mcu.PD2", "j1.5", { "kind": "trace" }],
    ["mcu.PD3", "j1.6", { "kind": "trace" }],
    ["mcu.PD4", "j1.7", { "kind": "trace" }],
    ["mcu.PD5", "j1.8", { "kind": "trace" }],
    ["mcu.PD6", "j1.9", { "kind": "trace" }],
    ["mcu.PD7", "j1.10", { "kind": "trace" }],
    ["mcu.PB0", "j1.11", { "kind": "trace" }],
    ["mcu.PB1", "j1.12", { "kind": "trace" }],
    ["mcu.PB2", "j1.13", { "kind": "trace" }],
    ["mcu.PB3", "j1.14", { "kind": "trace" }],
    ["mcu.PB3", "icsp.4", { "kind": "trace" }],
    ["mcu.PB4", "j1.15", { "kind": "trace" }],
    ["mcu.PB4", "icsp.1", { "kind": "trace" }],
    ["mcu.AREF", "j2.3", { "kind": "trace" }],
    ["mcu.PC0", "j2.4", { "kind": "trace" }],
    ["mcu.PC1", "j2.5", { "kind": "trace" }],
    ["mcu.PC2", "j2.6", { "kind": "trace" }],
    ["mcu.PC3", "j2.7", { "kind": "trace" }],
    ["mcu.PC4", "j2.8", { "kind": "trace" }],
    ["mcu.PC5", "j2.9", { "kind": "trace" }],
    ["mcu.ADC6", "j2.10", { "kind": "trace" }],
    ["mcu.ADC7", "j2.11", { "kind": "trace" }],
    ["usb_serial.V3", "j2.2", { "kind": "trace" }],
    ["regulator.IN", "j2.15", { "kind": "trace" }],
    // Clocks and USB data
    ["mcu.PB6", "resonator.IN", { "kind": "trace" }],
    ["mcu.PB7", "resonator.OUT", { "kind": "trace" }],
    ["usb_serial.XI", "crystal.1", { "kind": "trace" }],
    ["usb_serial.XO", "crystal.2", { "kind": "trace" }],
    ["usb.DP", "usb_serial.UDP", { "kind": "trace" }],
    ["usb.DM", "usb_serial.UDM", { "kind": "trace" }],
  ],
  "layout": {
    "j1": { "at": [0, 7.62, 0], "rotate": [0, 0, 180] },
    "j2": { "at": [0, -7.62, 0] },
    "usb": { "at": [-19.4, 0, 4.14] },
    "icsp": { "at": [18.4, 2.2, 4.14] },
    "mcu": { "at": [-6.03, 0, 4.14], "rotate": [0, 0, 45] },
    "sw_reset": { "at": [4.76, 0, 4.14] },
    "resonator": { "at": [0.32, -4.76, 4.14] },
    "r_l": { "at": [8.5, 3.3, 4.14] }, "r_pwr": { "at": [8.5, 1.1, 4.14] },
    "r_tx": { "at": [8.5, -1.1, 4.14] }, "r_rx": { "at": [8.5, -3.3, 4.14] },
    "led_l": { "at": [11.3, 3.3, 4.14] }, "led_pwr": { "at": [11.3, 1.1, 4.14] },
    "led_tx": { "at": [11.3, -1.1, 4.14] }, "led_rx": { "at": [11.3, -3.3, 4.14] },
    // Underside: a half turn about X hangs each child from the board's underside.
    "usb_serial": { "at": [-10.48, 0, 2.54], "rotate": [180, 0, 0] },
    "regulator": { "at": [11.4, 2.3, 2.54], "rotate": [180, 0, 0] },
    "crystal": { "at": [-14.3, 4.7, 2.54], "rotate": [180, 0, 0] },
    "diode": { "at": [-14.6, -4.4, 2.54], "rotate": [180, 0, 0] },
    "c_usb_a": { "at": [-18.0, 6.55, 2.54], "rotate": [180, 0, 0] },
    "c_usb_b": { "at": [-18.2, -6.55, 2.54], "rotate": [180, 0, 0] },
    "c_bulk_usb": { "at": [-6.2, -5.5, 2.54], "rotate": [180, 0, 90] },
    "r_txd": { "at": [-2.86, 2.6, 2.54], "rotate": [180, 0, 0] },
    "r_rxd": { "at": [-2.86, 1.08, 2.54], "rotate": [180, 0, 0] },
    "c_reset": { "at": [-2.86, -0.95, 2.54], "rotate": [180, 0, 0] },
    "r_reset": { "at": [7.3, 5.15, 2.54], "rotate": [180, 0, 90] },
    "c_bulk_reg": { "at": [10.7, -3.3, 2.54], "rotate": [180, 0, 0] },
    "c_reg": { "at": [13.6, -4.6, 2.54], "rotate": [180, 0, 0] },
  },
  "pins": {
    "D1": "j1.1", "D0": "j1.2", "RESET": ["j1.3", "j2.13"], "GND": ["j1.4", "j2.14"],
    "D2": "j1.5", "D3": "j1.6", "D4": "j1.7", "D5": "j1.8", "D6": "j1.9", "D7": "j1.10",
    "D8": "j1.11", "D9": "j1.12", "D10": "j1.13", "D11": "j1.14", "D12": "j1.15",
    "D13": "j2.1", "3V3": "j2.2", "AREF": "j2.3",
    "A0": "j2.4", "A1": "j2.5", "A2": "j2.6", "A3": "j2.7", "A4": "j2.8", "A5": "j2.9", "A6": "j2.10", "A7": "j2.11",
    "5V": "j2.12", "VIN": "j2.15",
  },
  // Nothing on the board drives AREF, A6 or A7. A scene that leaves one open is the board as
  // designed.
  "open": ["AREF", "A6", "A7"],
  "not_simulated": [
    { "what": "3V3", "pins": ["3V3"], "why": "It is the CH340G's 3.3 V output. The engine has no USB-serial chip, so the pin supplies nothing." },
    { "what": "a measured USB rail", "pins": ["5V"], "why": "The 5V pin sits one MBR0520 drop under the host's ideal 5.0 V, about 4.76 V at the board's own 26 mA. The drop is a fit to the diode's typical datasheet curve and the draw is the chips' datasheet typicals, not a reading off a real board. A USB port may give 4.75 V to 5.25 V and a clone may fit another Schottky, so a real board's 5V pin can read anywhere from about 4.5 V to 5.0 V." },
    { "what": "the regulator's input diode", "pins": ["VIN"], "why": "The AMS1117 has an internal diode from OUT to IN. The model blocks reverse current, so with USB only VIN reads about 0 V and a load from VIN to GND gets nothing. A real board shows about 4 V there, one diode drop under the 5V rail, and VIN can source a little current from USB." },
  ],
}
