# Xiongmai JZC-N51813L — 18x zoom block module, supported by OpenIPC

## Hardware

- SoC HiSilicon Hi3518CV100 (ARM926EJ-S), 128 MB DDR, 16 MB NOR (3-byte), MII Ethernet (PHY 0x02430c54).
- Sensor Aptina/onsemi AR0130 (1280x960, 12-bit DC parallel). The zoom block's own
  MCU configures it, so the SoC sees nothing on I2C. The sensor comes from the factory
  U-Boot `HWID` (`8043420002748439`: product 25 = N51813, sensor 7 = AR0130,
  DSP 2 = HI3518C), which ipctool reads (`source: xm-hwid`).
- Stock: firmware V4.02.R11.00001905.10010.230800.00000 (2016-09-28), DEVID 00001905,
  U-Boot 2010.06, Linux 3.0.8, Hi3518_MPP_V1.0.8.0. Two units read; every partition
  except the env (MAC) and the jffs2 settings partition is identical.
- Lens: a separate lens/camera MCU on UART0 (/dev/ttyAMA0, 9600 8N1), Sony VISCA at
  camera address 1. Zoom (continuous and CAM_Zoom Direct), focus (continuous; manual or
  auto), CAM_ZoomPosInq and CAM_FocusPosInq replies. The MCU streams `BB 82 … FF`
  status frames, with the integer magnification (1–18) in bytes 6–7.
- External PTZ port: **3.3 V TTL UART1, not RS-485.** It is on CN2 pin 3 (RXD1) and pin 4
  (TXD1), with GND on pin 2, at PELCO-D 9600 8N1, address 1. The module manual says
  "TTL串口 (原来的485接口)", a TTL serial port that *used to be* a 485 interface. It is meant
  for a dome base that takes TTL. Plain `/dev/ttyAMA1` works both ways on both stock and
  OpenIPC, with no GPIO needed. Stock libdvr toggles GPIO2_2 as a "DE", but nothing on the
  board uses it.
- **Do not wire an RS-485 bus or a USB-RS485 adapter directly to CN2.** A 5 V RS-485 driver
  on these bare 3.3 V SoC pins can kill them: one bench unit lost its UART1 TX this way.
  For an RS-485 PTZ head, put a 3.3 V auto-direction TTL↔RS-485 module (SP3485-class, e.g.
  XY-K485) between CN2 and the bus: camera TXD to module TXD, plus GND, with VCC from
  CN2 pin 1 (9–12 V) if the module takes it.
- Stock Sofia also sends the dome base the day/night mode as PELCO-D `FF 01 29 75 00 MM`
  (MM = 00, 01, 02 for DVRIP `DayNightColor` 0x0, 0x2, 0x1). The lens MCU gets VISCA on UART0.
- Camera-block lines: GPIO4_2 must be driven high (block enable); GPIO5_2 is the MCU
  reset (held low).

## OpenIPC

- Builder profile `hi3518cv100_lite_xm-n51813l` (OpenIPC/builder#235):
  `https://github.com/OpenIPC/builder/releases/download/latest/hi3518cv100_lite_xm-n51813l-nor.tgz`.
  - `/etc/init.d/S90lens-mcu` sets the two GPIOs and sends the MCU its "init camera"
    frame `BB 01 00 28 00 02 FF`, acknowledged with `BB 81 00 28 …`. Without it no frames
    reach VI. Mode 02 = 25 fps; mode 03 (`fw_setenv lens_mode 03`) is about 30 fps.
  - First boot sets `sensor=ar0130`, `osmem=64M` (32M starves Linux), majestic-af's `visca`
    actuator on /dev/ttyAMA0, and `video0.crop 0x2x1280x958` (the MCU leaves two junk lines
    at the top of the frame). It also removes getty from the MCU's UART.
- From stock firmware: coupler's `00001905_OpenIPC_N51813L.bin` (OpenIPC/coupler#65) over
  the vendor upgrade gives generic OpenIPC with the right env layout (env at 0x40000, 256K).
  Then sysupgrade to the builder image.
- Verified on hardware: video 1280x958, snapshots 1280x944, zoom/focus from the WebUI/API,
  and magnification readback 1–18x.
- One caveat: on one first install the camera hung at the customizer's reboot and needed a
  power cycle. That has not reproduced since.
