rushabhcodes/ESP32-E-Reader

This code defines the hardware layout and schematic connections for an ESP32-based e-reader device, including microcontroller, USB, display, power management, connectors, passives, switches, and associated PCB footprints, placements, and net connections.

Version
1.0.6
License
unset
Stars
0

circuit-sections.tsx

import { Fragment } from "react";
import { DM3AT_SF_PEJM5 } from "./imports/DM3AT_SF_PEJM5";
import { ESP32_C3_WROOM_02_N4 } from "./imports/ESP32_C3_WROOM_02_N4";
import { EVQP7C01P } from "./imports/EVQP7C01P";
import { FH12_24S_0_5SH_55_ } from "./imports/FH12_24S_0_5SH_55_";
import { FPC_05FB_6PH20 } from "./imports/FPC_05FB_6PH20";
import { FXL0420_100_M } from "./imports/FXL0420_100_M";
import { JS102011SAQN } from "./imports/JS102011SAQN";
import { ME6211C33M5G_N } from "./imports/ME6211C33M5G_N";
import { SKRPACE010 } from "./imports/SKRPACE010";
import { TPS61169DCKR } from "./imports/TPS61169DCKR";
import {
	type ChipSpec,
	aliasForPin,
	capacitors,
	chips,
	diodes,
	inductors,
	noConnectAliases,
	pinLabelsFor,
	polarizedPinLabels,
	resistors,
	schematicHeights,
	schematicPlacementFor,
	supplierPartNumbersFor,
	testpoints,
} from "./design-data";

const renderChip = (spec: ChipSpec) => {
	const half = Math.ceil(spec.pins.length / 2);
	const schematicPlacement = schematicPlacementFor(spec.name);
	const importedCommon = {
		name: spec.name,
		pcbX: spec.pcbX,
		pcbY: spec.pcbY,
		pcbRotation: spec.pcbRotation,
		layer: spec.layer,
		supplierPartNumbers: supplierPartNumbersFor(spec.name),
		schHeight: schematicHeights[spec.name],
		...schematicPlacement,
	};

	if (spec.name === "J2")
		return (
			<FH12_24S_0_5SH_55_
				key={spec.name}
				{...importedCommon}
				pcbY={spec.pcbY + 0.03723375}
				noConnect={["pin1", "pin4", "pin6", "pin7", "pin19", "pin25", "pin26"]}
			/>
		);
	if (spec.name === "J3")
		return (
			<FPC_05FB_6PH20
				key={spec.name}
				{...importedCommon}
				pcbY={spec.pcbY + 0.0750353}
				noConnect={["pin1", "pin2", "pin3", "pin4", "pin7", "pin8"]}
			/>
		);
	if (spec.name === "J4")
		return (
			<DM3AT_SF_PEJM5
				key={spec.name}
				{...importedCommon}
				noConnect={["pin10", "pin11", "pin12", "pin13", "pin14"]}
			/>
		);
	if (spec.name === "U4")
		return <ESP32_C3_WROOM_02_N4 key={spec.name} {...importedCommon} />;
	if (spec.name === "U5")
		return (
			<ME6211C33M5G_N
				key={spec.name}
				{...importedCommon}
				pcbRotation={(spec.pcbRotation ?? 0) - 90}
				noConnect={["pin4"]}
			/>
		);
	if (spec.name === "U6")
		return (
			<TPS61169DCKR
				key={spec.name}
				{...importedCommon}
				pcbRotation={(spec.pcbRotation ?? 0) + 180}
			/>
		);
	if (spec.name === "S1" || spec.name === "S2")
		return <EVQP7C01P key={spec.name} {...importedCommon} />;
	if (["SW2", "SW3", "SW4", "SW6"].includes(spec.name))
		return (
			<SKRPACE010
				key={spec.name}
				{...importedCommon}
				noConnect={["pin2", "pin3"]}
			/>
		);
	if (spec.name === "SW7")
		return (
			<JS102011SAQN
				key={spec.name}
				{...importedCommon}
				pcbX={spec.pcbX - 1.75}
			/>
		);

	const common = {
		name: spec.name,
		manufacturerPartNumber: spec.value,
		footprint: spec.footprint,
		pinLabels: pinLabelsFor(spec.pins),
		noConnect: noConnectAliases(spec),
		pcbX: spec.pcbX,
		pcbY: spec.pcbY,
		pcbRotation: spec.pcbRotation,
		layer: spec.layer,
		supplierPartNumbers: supplierPartNumbersFor(spec.name),
		schPinArrangement: {
			leftSide: spec.pins.slice(0, half).map(aliasForPin),
			rightSide: spec.pins.slice(half).map(aliasForPin),
		},
		schHeight: schematicHeights[spec.name],
		...schematicPlacement,
	};

	if (spec.name === "J1")
		return (
			<connector
				key={spec.name}
				name="J1"
				manufacturerPartNumber="USB4105-xx-A"
				standard="usb_c"
				pinCount={16}
				pinLabels={pinLabelsFor(spec.pins)}
				noConnect={noConnectAliases(spec)}
				pcbX={spec.pcbX}
				pcbY={spec.pcbY}
				pcbRotation={-90}
				schPinArrangement={{
					leftSide: ["P_1", "P_2", "P_3", "P_4", "P_5", "P_6", "P_7", "P_8"],
					rightSide: [
						"P_16",
						"P_15",
						"P_14",
						"P_13",
						"P_12",
						"P_11",
						"P_10",
						"P_9",
					],
				}}
				schHeight={1.4}
				{...schematicPlacement}
				footprint={
					<footprint insertionDirection="from_top">
						<smtpad
							shape="rect"
							width="0.6mm"
							height="1.15mm"
							pcbX={-3.2}
							pcbY={-3.68}
							portHints={["pin1"]}
						/>
						<smtpad
							shape="rect"
							width="0.6mm"
							height="1.15mm"
							pcbX={-2.4}
							pcbY={-3.68}
							portHints={["pin2"]}
						/>
						<smtpad
							shape="rect"
							width="0.3mm"
							height="1.15mm"
							pcbX={-1.25}
							pcbY={-3.68}
							portHints={["pin6"]}
						/>
						<smtpad
							shape="rect"
							width="0.3mm"
							height="1.15mm"
							pcbX={-0.25}
							pcbY={-3.68}
							portHints={["pin5"]}
						/>
						<smtpad
							shape="rect"
							width="0.3mm"
							height="1.15mm"
							pcbX={0.25}
							pcbY={-3.68}
							portHints={["pin4"]}
						/>
						<smtpad
							shape="rect"
							width="0.3mm"
							height="1.15mm"
							pcbX={1.25}
							pcbY={-3.68}
							portHints={["pin3"]}
						/>
						<smtpad
							shape="rect"
							width="0.3mm"
							height="1.15mm"
							pcbX={-1.75}
							pcbY={-3.68}
							portHints={["pin10"]}
						/>
						<smtpad
							shape="rect"
							width="0.3mm"
							height="1.15mm"
							pcbX={-0.75}
							pcbY={-3.68}
							portHints={["pin9"]}
						/>
						<smtpad
							shape="rect"
							width="0.3mm"
							height="1.15mm"
							pcbX={0.75}
							pcbY={-3.68}
							portHints={["pin8"]}
						/>
						<smtpad
							shape="rect"
							width="0.3mm"
							height="1.15mm"
							pcbX={1.75}
							pcbY={-3.68}
							portHints={["pin7"]}
						/>
						<smtpad
							shape="rect"
							width="0.6mm"
							height="1.15mm"
							pcbX={2.4}
							pcbY={-3.68}
							portHints={["pin11"]}
						/>
						<smtpad
							shape="rect"
							width="0.6mm"
							height="1.15mm"
							pcbX={3.2}
							pcbY={-3.68}
							portHints={["pin12"]}
						/>
						<platedhole
							shape="pill"
							outerWidth="1mm"
							outerHeight="2.1mm"
							holeWidth="0.6mm"
							holeHeight="1.7mm"
							pcbX={-4.32}
							pcbY={-3.105}
							portHints={["pin13"]}
						/>
						<platedhole
							shape="pill"
							outerWidth="1mm"
							outerHeight="1.8mm"
							holeWidth="0.6mm"
							holeHeight="1.4mm"
							pcbX={-4.32}
							pcbY={1.075}
							portHints={["pin14"]}
						/>
						<platedhole
							shape="pill"
							outerWidth="1mm"
							outerHeight="2.1mm"
							holeWidth="0.6mm"
							holeHeight="1.7mm"
							pcbX={4.32}
							pcbY={-3.105}
							portHints={["pin15"]}
						/>
						<platedhole
							shape="pill"
							outerWidth="1mm"
							outerHeight="1.8mm"
							holeWidth="0.6mm"
							holeHeight="1.4mm"
							pcbX={4.32}
							pcbY={1.075}
							portHints={["pin16"]}
						/>
						<hole diameter="0.65mm" pcbX={-2.89} pcbY={-2.605} />
						<hole diameter="0.65mm" pcbX={2.89} pcbY={-2.605} />
						<silkscreenrect width="9.4mm" height="7.2mm" pcbY="-0.25mm" />
						<courtyardrect width="10.64mm" height="8.94mm" pcbY="-0.29mm" />
					</footprint>
				}
			/>
		);
	if (spec.kind === "connector")
		return <connector key={spec.name} {...common} />;
	if (spec.kind === "pushbutton")
		return <pushbutton key={spec.name} {...common} />;
	return <chip key={spec.name} {...common} />;
};

export const BatteryUsbSection = () => (
	<schematicsection
		name="battery_usb"
		displayName="Battery, Protection, USB & Charging"
	/>
);

export const McuPowerSection = () => (
	<schematicsection name="mcu_power" displayName="3.3 V Rail & ESP32-C3" />
);

export const DisplayPowerSection = () => (
	<schematicsection
		name="display_power"
		displayName="E-Paper Interface & Bias Rails"
	/>
);

export const FrontlightSection = () => (
	<schematicsection name="frontlight" displayName="15 V Frontlight Driver" />
);

export const StorageSection = () => (
	<schematicsection name="storage" displayName="Micro SD Storage" />
);

export const ControlsSection = () => (
	<schematicsection name="controls" displayName="User Controls" />
);

export const CircuitSections = () => (
	<Fragment>
		<BatteryUsbSection />
		<McuPowerSection />
		<DisplayPowerSection />
		<FrontlightSection />
		<StorageSection />
		<ControlsSection />

		{capacitors.map((spec) => (
			<capacitor
				key={spec.name}
				name={spec.name}
				capacitance={spec.value}
				footprint={spec.footprint}
				supplierPartNumbers={supplierPartNumbersFor(spec.name)}
				pcbX={spec.pcbX}
				pcbY={spec.pcbY}
				pcbRotation={spec.pcbRotation}
				layer={spec.layer}
				schOrientation="vertical"
				{...schematicPlacementFor(spec.name)}
			/>
		))}
		{resistors.map((spec) => (
			<resistor
				key={spec.name}
				name={spec.name}
				resistance={spec.value}
				footprint={spec.footprint}
				supplierPartNumbers={supplierPartNumbersFor(spec.name)}
				pcbX={spec.pcbX}
				pcbY={spec.pcbY}
				pcbRotation={spec.pcbRotation}
				layer={spec.layer}
				{...schematicPlacementFor(spec.name)}
			/>
		))}
		{inductors.map((spec) =>
			spec.name === "L2" ? (
				<FXL0420_100_M
					key={spec.name}
					name={spec.name}
					pcbX={spec.pcbX}
					pcbY={spec.pcbY}
					pcbRotation={spec.pcbRotation}
					layer={spec.layer}
					supplierPartNumbers={supplierPartNumbersFor(spec.name)}
					{...schematicPlacementFor(spec.name)}
				/>
			) : (
				<inductor
					key={spec.name}
					name={spec.name}
					inductance={spec.value}
					footprint={spec.footprint}
					supplierPartNumbers={supplierPartNumbersFor(spec.name)}
					pcbX={spec.pcbX}
					pcbY={spec.pcbY}
					pcbRotation={spec.pcbRotation}
					layer={spec.layer}
					{...schematicPlacementFor(spec.name)}
				/>
			),
		)}

		<led
			name="D1"
			color="red"
			pinLabels={polarizedPinLabels}
			footprint="0805"
			pcbX={-29.62440000000001}
			pcbY={34.475}
			pcbRotation={90}
			layer="top"
			{...schematicPlacementFor("D1")}
		/>

		{diodes.map((spec) => (
			<diode
				key={spec.name}
				name={spec.name}
				pinLabels={polarizedPinLabels}
				footprint={spec.footprint}
				supplierPartNumbers={supplierPartNumbersFor(spec.name)}
				pcbX={spec.pcbX}
				pcbY={spec.pcbY}
				pcbRotation={spec.pcbRotation}
				layer={spec.layer}
				{...schematicPlacementFor(spec.name)}
			/>
		))}

		{chips.map(renderChip)}

		{testpoints.map((testpoint) => (
			<testpoint
				key={testpoint.name}
				name={testpoint.name}
				footprintVariant="pad"
				padShape="circle"
				padDiameter="1.5mm"
				pcbX={testpoint.pcbX}
				pcbY={testpoint.pcbY}
				{...schematicPlacementFor(testpoint.name)}
			/>
		))}
	</Fragment>
);