tscircuit/rv1106g2-breakout

This code defines a set of PCB components and their footprints, including connecters, chips, resistors, capacitors, and other hardware parts, for assembling a Core1106-based circuit board with detailed pinouts, footprints, and 3D models.

Version
1.0.2
License
unset
Stars
0

Use with the tscircuit CLI

tsci is the tscircuit CLI. Install it with npm install -g tscircuit.

tsci clone tscircuit/rv1106g2-breakout  # download the package files into ./rv1106g2-breakout
tsci add tscircuit/rv1106g2-breakout    # add it to your project as @tsci/tscircuit.rv1106g2-breakout

In a cloned or new (tsci init) project: tsci dev starts a local preview, tsci build outputs Circuit JSON, and tsci push publishes to tscircuit.com.

components/Core1106.tsx

import type {
  ChipProps,
  PinAttributeMap,
  PinCapability,
} from "@tscircuit/props"

const CORE1106_PIN_NAMES = [
  "MIPI_CLK1_N",
  "MIPI_CLK1_P",
  "MIPI_D3_N",
  "MIPI_D3_P",
  "MIPI_D2_N",
  "MIPI_D2_P",
  "MIPI_D1_N",
  "MIPI_D1_P",
  "MIPI_CLK0_N",
  "MIPI_CLK0_P",
  "MIPI_D0_N",
  "MIPI_D0_P",
  "CAM1_RST_GPIO3_D3",
  "CAM1_SDA_GPIO3_D2",
  "CAM1_SCL_GPIO3_D1",
  "CAM0_SCL_GPIO3_C7",
  "CAM0_SDA_GPIO3_D0",
  "CAM0_RST_GPIO3_C5",
  "CAM0_MCLK_GPIO3_C4",
  "CAM1_MCLK_GPIO3_C6",
  "GND_21",
  "USB_DM",
  "USB_DP",
  "USB_VBUSDET",
  "GND_25",
  "RECOVERY_ADC0_GPIO4_C0",
  "ADC1_GPIO4_C1",
  "GND_28",
  "GND_29",
  "CODEC_LINEOUT",
  "CODEC_MICBIAS",
  "CODEC_MIC0N",
  "CODEC_MIC0P",
  "CODEC_MIC1N",
  "CODEC_MIC1P",
  "GND_36",
  "EMMC_D0_GPIO4_A4",
  "EMMC_D1_GPIO4_A3",
  "EMMC_D2_GPIO4_A2",
  "EMMC_D3_GPIO4_A6",
  "EMMC_D4_GPIO4_A5",
  "EMMC_D5_GPIO4_A7",
  "EMMC_D6_GPIO4_A1",
  "EMMC_D7_GPIO4_A0",
  "EMMC_CMD_GPIO4_B0",
  "EMMC_CLK_GPIO4_B1",
  "GND_47",
  "SDMMC_DET_GPIO3_A1",
  "SDMMC_D0_GPIO3_A3",
  "SDMMC_D1_GPIO3_A2",
  "SDMMC_D2_GPIO3_A7",
  "SDMMC_D3_GPIO3_A6",
  "SDMMC_CMD_GPIO3_A5",
  "SDMMC_CLK_GPIO3_A4",
  "GND_55",
  "GND_56",
  "GND_57",
  "UART0_RX_GPIO0_A0",
  "UART0_TX_GPIO0_A1",
  "PWM3_GPIO0_A2",
  "GPIO0_A3_PWR_CTRL1",
  "GPIO0_A4_PWR_CTRL0",
  "I2C1_SCL_GPIO0_A5",
  "I2C1_SDA_GPIO0_A6",
  "I2C2_SCL_UART3_TX_GPIO1_A0",
  "I2C2_SDA_UART3_RX_GPIO1_A1",
  "PWM0_GPIO1_A2",
  "I2C0_SCL_UART1_TX_GPIO1_A3",
  "I2C0_SDA_UART1_RX_GPIO1_A4",
  "UART4_RX_GPIO1_B0",
  "UART4_TX_SPI1_CS1_GPIO1_B1",
  "UART2_TX_JTAG_TCK_GPIO1_B2",
  "UART2_RX_JTAG_TMS_GPIO1_B3",
  "NPOR",
  "GND_75",
  "VCC3V3_RTC",
  "VCC_1V8_OUT",
  "VCC_3V3_OUT",
  "VCC5V0_SYS_79",
  "VCC5V0_SYS_80",
  "VCC5V0_SYS_81",
  "GND_82",
  "GND_83",
  "GND_84",
  "FEPHY_RXN",
  "FEPHY_RXP",
  "FEPHY_TXN",
  "FEPHY_TXP",
  "GND_89",
  "I2C3_SCL_UART5_TX_GPIO1_D3",
  "I2C3_SDA_UART5_RX_SPI0_CS1_GPIO1_D2",
  "UART3_RX_GPIO1_D1",
  "UART3_TX_GPIO1_D0",
  "UART4_CTS_GPIO1_C7",
  "UART4_RTS_GPIO1_C6",
  "UART4_TX_SDIO_D2_GPIO1_C5",
  "UART4_RX_SDIO_D3_GPIO1_C4",
  "SPI0_MISO_SDIO_CMD_GPIO1_C3",
  "SPI0_MOSI_SDIO_CLK_GPIO1_C2",
  "SPI0_CLK_SDIO_D0_GPIO1_C1",
  "SPI0_CS0_SDIO_D1_GPIO1_C0",
  "I2C4_SDA_I2S0_SCLK_GPIO2_A0",
  "I2C4_SCL_I2S0_LRCK_GPIO2_A1",
  "I2S0_MCLK_GPIO2_A2",
  "I2S0_SDO3_GPIO2_A3",
  "I2S0_SDO0_UART1_TX_GPIO2_A4",
  "I2S0_SDI0_UART1_RX_GPIO2_A5",
  "I2C3_SCL_UART0_RTS_GPIO2_A6",
  "I2C3_SDA_UART0_CTS_GPIO2_A7",
  "I2C1_SCL_UART0_RX_GPIO2_B0",
  "I2C1_SDA_UART0_TX_GPIO2_B1",
  "GND_112",
] as const

export const CORE1106_PIN_LABELS = Object.fromEntries(
  CORE1106_PIN_NAMES.map((name, index) => [
    `pin${index + 1}`,
    `P${String(index + 1).padStart(3, "0")}_${name}`,
  ]),
) as Record<`pin${number}`, string>

const getPinCapabilities = (name: string): PinCapability[] => {
  const capabilities: PinCapability[] = []

  if (/I2C\d*_SDA/.test(name)) capabilities.push("i2c_sda")
  if (/I2C\d*_SCL/.test(name)) capabilities.push("i2c_scl")
  if (/SPI\d*_CS\d*/.test(name)) capabilities.push("spi_cs")
  if (/SPI\d*_(CLK|SCK)/.test(name)) capabilities.push("spi_sck")
  if (/SPI\d*_MOSI/.test(name)) capabilities.push("spi_mosi")
  if (/SPI\d*_MISO/.test(name)) capabilities.push("spi_miso")
  if (/UART\d*_TX/.test(name)) capabilities.push("uart_tx")
  if (/UART\d*_RX/.test(name)) capabilities.push("uart_rx")

  return capabilities
}

const getPinAttributes = (name: string): PinAttributeMap => {
  const attributes: PinAttributeMap = { includeInBoardPinout: true }
  const capabilities = getPinCapabilities(name)

  if (capabilities.length > 0) attributes.capabilities = capabilities

  if (name.startsWith("GND_")) {
    attributes.requiresGround = true
    attributes.mustBeConnected = true
    return attributes
  }

  if (name.startsWith("VCC5V0_SYS_")) {
    attributes.requiresPower = true
    attributes.requiresVoltage = "5V"
    attributes.mustBeConnected = true
    return attributes
  }

  if (name === "VCC3V3_RTC") {
    attributes.requiresPower = true
    attributes.requiresVoltage = "3.3V"
    attributes.mustBeConnected = true
    return attributes
  }

  if (name === "VCC_1V8_OUT") {
    attributes.providesPower = true
    attributes.providesVoltage = "1.8V"
    return attributes
  }

  if (name === "VCC_3V3_OUT") {
    attributes.providesPower = true
    attributes.providesVoltage = "3.3V"
    return attributes
  }

  if (name.includes("GPIO")) {
    attributes.isGpio = true
    attributes.canUsePushPull = true
    attributes.canUseInternalPullup = true
    attributes.canUseInternalPulldown = true
  }

  if (capabilities.includes("i2c_sda") || capabilities.includes("i2c_scl")) {
    attributes.canUseOpenDrain = true
  }

  if (name === "NPOR") attributes.mustBeConnected = true

  return attributes
}

export const CORE1106_PIN_ATTRIBUTES = Object.fromEntries(
  CORE1106_PIN_NAMES.map((name, index) => [
    `pin${index + 1}`,
    getPinAttributes(name),
  ]),
) as Record<`pin${number}`, PinAttributeMap>

const getPadPosition = (pin: number) => {
  if (pin <= 28) return { x: -15, y: -13.5 + (pin - 1), vertical: false }
  if (pin <= 56) return { x: -13.5 + (pin - 29), y: 15, vertical: true }
  if (pin <= 84) return { x: 15, y: 13.5 - (pin - 57), vertical: false }
  return { x: 13.5 - (pin - 85), y: -15, vertical: true }
}

const coreFootprint = (
  <footprint>
    {Array.from({ length: 112 }, (_, index) => {
      const pin = index + 1
      const { x, y, vertical } = getPadPosition(pin)
      return (
        <smtpad
          name={`PAD_${pin}`}
          shape="rect"
          width={vertical ? "0.7mm" : "1.5mm"}
          height={vertical ? "1.5mm" : "0.7mm"}
          pcbX={x}
          pcbY={y}
          solderMaskMargin="0.05mm"
          portHints={[`pin${pin}`]}
        />
      )
    })}
    <silkscreenrect width="30.4mm" height="30.4mm" />
    <silkscreencircle pcbX={-13.4} pcbY={-13.4} radius="0.65mm" />
    <silkscreentext text="CORE1106" pcbY={0} fontSize="1.5mm" />
    <courtyardrect width="31mm" height="31mm" />
  </footprint>
)

// The Core1106 is a complete 30 mm square module rather than a bare IC.  The
// installed tscircuit core does not yet implement string-valued `cadModel`
// props, so use an embedded OBJ model that works in both the static site and
// exported assembly.  Package bodies are representative; the board outline
// and carrier-board mating plane are the mechanically important dimensions.
type ModelBox = {
  name: string
  center: [number, number, number]
  size: [number, number, number]
}

const createBoxObj = (boxes: ModelBox[]) => {
  const lines: string[] = []
  let vertexOffset = 1

  for (const { name, center, size } of boxes) {
    const [cx, cy, cz] = center
    const [sx, sy, sz] = size
    const x0 = cx - sx / 2
    const x1 = cx + sx / 2
    const y0 = cy - sy / 2
    const y1 = cy + sy / 2
    const z0 = cz - sz / 2
    const z1 = cz + sz / 2

    lines.push(
      `o ${name}`,
      `v ${x0} ${y0} ${z0}`,
      `v ${x1} ${y0} ${z0}`,
      `v ${x1} ${y1} ${z0}`,
      `v ${x0} ${y1} ${z0}`,
      `v ${x0} ${y0} ${z1}`,
      `v ${x1} ${y0} ${z1}`,
      `v ${x1} ${y1} ${z1}`,
      `v ${x0} ${y1} ${z1}`,
      `f ${vertexOffset} ${vertexOffset + 3} ${vertexOffset + 2} ${vertexOffset + 1}`,
      `f ${vertexOffset + 4} ${vertexOffset + 5} ${vertexOffset + 6} ${vertexOffset + 7}`,
      `f ${vertexOffset} ${vertexOffset + 1} ${vertexOffset + 5} ${vertexOffset + 4}`,
      `f ${vertexOffset + 1} ${vertexOffset + 2} ${vertexOffset + 6} ${vertexOffset + 5}`,
      `f ${vertexOffset + 2} ${vertexOffset + 3} ${vertexOffset + 7} ${vertexOffset + 6}`,
      `f ${vertexOffset + 3} ${vertexOffset} ${vertexOffset + 4} ${vertexOffset + 7}`,
    )
    vertexOffset += 8
  }

  return lines.join("\n")
}

const core1106Obj = createBoxObj([
  { name: "module_pcb", center: [0, 0, 0.6], size: [30, 30, 1.2] },
  { name: "rv1106", center: [-4.5, 1.5, 1.7], size: [8, 8, 1] },
  { name: "memory", center: [5.5, 1.5, 1.7], size: [8, 11, 1] },
  { name: "oscillator", center: [-7.5, -8, 1.55], size: [3.2, 2.5, 0.7] },
])

const core1106CadModel = (
  <cadmodel
    modelUrl={`data:model/obj;charset=utf-8,${encodeURIComponent(core1106Obj)}#ext=obj`}
    modelUnitToMmScale={1}
    modelOriginPosition={{ x: 0, y: 0, z: 0 }}
    modelBounds={{
      min: { x: -15, y: -15, z: 0 },
      max: { x: 15, y: 15, z: 2.2 },
    }}
    size={{ x: 30, y: 30, z: 2.2 }}
  />
)

export const Core1106 = (
  props: Omit<
    ChipProps<string>,
    "cadModel" | "footprint" | "manufacturerPartNumber" | "pinAttributes"
  >,
) => (
  <chip
    {...props}
    manufacturerPartNumber="Luckfox Core11060208 / Core11061208 / Core11060408 / Core11061408"
    footprint={coreFootprint}
    cadModel={core1106CadModel}
    pinLabels={CORE1106_PIN_LABELS}
    pinAttributes={CORE1106_PIN_ATTRIBUTES}
    schPinArrangement={{
      leftSide: Array.from({ length: 56 }, (_, index) => index + 1),
      rightSide: Array.from({ length: 56 }, (_, index) => 112 - index),
    }}
    schWidth="46mm"
    schHeight="122mm"
  />
)