Components
A component is anything that has a KiCAD symbol or footprint, ie. resistors, MCUs, vias, mounting holes or regulatory images.
Component
The Component class is the base class for all components in typeCAD. In KiCAD, it would be anything that has a footprint file associated with it.
import { Component } from '@typecad/typecad';
let u1 = new Component({ footprint: 'Package_SO:SOIC-8_5.3x5.3mm_P1.27mm' });The above creates a SOIC-8 component. footprint is the KiCAD footprint path and split into two strings.
That method works well for simple components, but there is a better way using the typecad add component tool.
typecad add component
typeCAD has a command line tool that can be used to create a component. Run typecad add component from the ./hw directory, or click the add_component button in the VSCode GUI under NPM Scripts.
The script will ask where the component is coming from, either the KiCAD library, a local file, or an EasyEDA/JLCPCB component.
If you’re using the KiCAD library, you’ll be asked for the symbol library and name. Paste it in, press enter and it should automatically figure out which footprint to use. If it can’t, it will ask you for a footprint library name and footprint name (library.kicad_mod:footprint).
If you’re using a local file, you’ll be asked for the path to the symbol file and footprint file.
If it’s an EasyEDA/JLCPCB component, you’ll be asked for the C### number.
KiCAD Library Components
To find the symbol and footprint for a KiCAD library component, use typecad search:
typecad search "voltage regulator"
typecad search LM358
typecad search "op amp" --format=json --limit=10It fuzzy-matches against the KiCAD symbol libraries and returns the symbol name, footprint, and description. The symbol name is in LibraryName:SymbolName format (e.g. MCU_Microchip_ATtiny:ATtiny85-20S).
Without a query, it prompts for search terms interactively. Available options:
--format— output format:detailed,compact,table,json(default: detailed)--sort— sort by:score,id,manufacturer,package(default: score)--limit— maximum number of results (default: 5)
EasyEDA/JLCPCB Component
If you are working within JLC’s ecosystem for design or assembly, you can use the C### numbers of their parts to create a component. The footprint and 3d model will be downloaded and a typeCAD component will be created.
The parts are converted from EasyEDA’s format to KiCAD’s footprint. The conversion isn’t always perfect. The most common issue is pin types being unspecified rather than what they should actually be. Not all parts have associated symbols or footprints.
Component Use
After the component is created, they’ll be some code in the terminal that tells you how to import it and declare a new instance of it. For the ATtiny85, it will look like this:
🧩 typeCAD Create Component
✔ Component source? KiCAD
✔ Symbol name? MCU_Microchip_ATtiny:ATtiny3227-M
✔ Footprint name? Package_DFN_QFN:QFN-24-1EP_4x4mm_P0.5mm_EP2.6x2.6mm
Finished component creation, use it with:
import { ATtiny85_20S } from './ATtiny85_20S';
let u1 = new ATtiny85_20S();Let’s look at what’s in the ATtiny85_20S.ts file that was created to get a better idea of what is going on.
ATtiny85_20S.ts
import { Component } from '@typecad/typecad';
/**
| Pin # | Name | Type |
| --: | :-- | :-- |
| 8 | VCC | power_in |
| 4 | GND | power_in |
| 5 | AREF_PB0 | bidirectional |
| 6 | PB1 | bidirectional |
| 7 | PB2 | bidirectional |
| 2 | XTAL1_PB3 | bidirectional |
| 3 | XTAL2_PB4 | bidirectional |
| 1 | _RESET_PB5 | bidirectional |
*/
export class ATtiny85_20S extends Component {
VCC = this.pin(8, { type: 'power_in' });
GND = this.pin(4, { type: 'power_in' });
AREF_PB0 = this.pin(5, { type: 'bidirectional' });
PB1 = this.pin(6, { type: 'bidirectional' });
PB2 = this.pin(7, { type: 'bidirectional' });
XTAL1_PB3 = this.pin(2, { type: 'bidirectional' });
XTAL2_PB4 = this.pin(3, { type: 'bidirectional' });
_RESET_PB5 = this.pin(1, { type: 'bidirectional' });
constructor(reference?: string | undefined) {
super("Package_SO:SOIC-8_5.3x5.3mm_P1.27mm");
this.symbol = "MCU_Microchip_ATtiny:ATtiny85-20S";
if (reference) this.reference = reference;
}
}It is a bit more involved than the simple TypeScript we’ve been using so far (that’s why it was auto-generated). But it helps to explain what is going on.
The file extends the Component by adding some extras to it. In particular, it adds Pin objects to the component. Rather than using the pins like u1.pin(1), we can use u1.VCC for the VCC pin, or u1.GND for the GND pin. This makes the code much easier to read and understand.
minimum_voltage, maximum_voltage, and current are optional and provide additional information for the power-aware system to check trace widths, and ensure voltage/current restrictions are met.
create
After a Component has been created and modified, call create to include it in the PCB, schematic and netlist.
import { PCB } from '@typecad/typecad';
import { ATtiny85_20S } from './ATtiny85_20S';
let typecad = new PCB('typecad_docs');
let u1 = new ATtiny85_20S();
typecad.create(u1);On This Page