Skip to content

Instantly share code, notes, and snippets.

@esden
Last active August 5, 2020 12:36
Show Gist options
  • Save esden/2a5d3d811ca19f6360c0f01fdf31b679 to your computer and use it in GitHub Desktop.
Save esden/2a5d3d811ca19f6360c0f01fdf31b679 to your computer and use it in GitHub Desktop.
Starting a new KiCad Project esden style.

Create a new directory:

mkdir myhardware-git
cd myhardware-git

Initialize git:

git init

Create library submodule:

git submodule add https://github.com/esden/pretty-kicad-libs.git lib/pkl

Create project directory:

mkdir -p hardware/myproject/v0.1a

Now open kicad create a new project in the hardware/myproject/v0.1a directory. Make sure to uncheck the Create a new directory for the project checkmark, so that KiCad does not create an additional subdirectory.

Now you can copy the two library path files from another project. The fp-lib-table contains paths to footprint libraries, and sym-lib-table contains paths to the symbol libraries.

For the above project the fp-lib-table file content can for example be:

(fp_lib_table
  (lib (name pkl_allegro)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_allegro.pretty)(options "")(descr ""))
  (lib (name pkl_beaglebone)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_beaglebone.pretty)(options "")(descr ""))
  (lib (name pkl_buttons_switches)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_buttons_switches.pretty)(options "")(descr ""))
  (lib (name pkl_connectors)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_connectors.pretty)(options "")(descr ""))
  (lib (name pkl_dipol)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_dipol.pretty)(options "")(descr ""))
  (lib (name pkl_fiducials)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_fiducials.pretty)(options "")(descr ""))
  (lib (name pkl_housings_bga)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_housings_bga.pretty)(options "")(descr ""))
  (lib (name pkl_housings_dfn_qfn)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_housings_dfn_qfn.pretty)(options "")(descr ""))
  (lib (name pkl_housings_power)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_housings_power.pretty)(options "")(descr ""))
  (lib (name pkl_housings_qfp)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_housings_qfp.pretty)(options "")(descr ""))
  (lib (name pkl_housings_soic)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_housings_soic.pretty)(options "")(descr ""))
  (lib (name pkl_housings_sop)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_housings_sop.pretty)(options "")(descr ""))
  (lib (name pkl_housings_sot)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_housings_sot.pretty)(options "")(descr ""))
  (lib (name pkl_jst)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_jst.pretty)(options "")(descr ""))
  (lib (name pkl_jumpers)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_jumpers.pretty)(options "")(descr ""))
  (lib (name pkl_led)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_led.pretty)(options "")(descr ""))
  (lib (name pkl_logos)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_logos.pretty)(options "")(descr ""))
  (lib (name pkl_mechanical)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_mechanical.pretty)(options "")(descr ""))
  (lib (name pkl_misc)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_misc.pretty)(options "")(descr ""))
  (lib (name pkl_ms)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_ms.pretty)(options "")(descr ""))
  (lib (name pkl_murata)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_murata.pretty)(options "")(descr ""))
  (lib (name pkl_pads)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_pads.pretty)(options "")(descr ""))
  (lib (name pkl_pin_headers)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_pin_headers.pretty)(options "")(descr ""))
  (lib (name pkl_samtec)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_samtec.pretty)(options "")(descr ""))
  (lib (name pkl_st)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_st.pretty)(options "")(descr ""))
  (lib (name pkl_tag_connect)(type KiCad)(uri ${KIPRJMOD}/../../lib/pkl/pkl_tag_connect.pretty)(options "")(descr ""))
)

And the sym-lib-table can contain the following:

(sym_lib_table
  (lib (name pkl_texas)(type Legacy)(uri ${KIPRJMOD}/../../lib/pkl/pkl_texas.lib)(options "")(descr ""))
  (lib (name pkl_tag_connect)(type Legacy)(uri ${KIPRJMOD}/../../lib/pkl/pkl_tag_connect.lib)(options "")(descr ""))
  (lib (name pkl_silabs)(type Legacy)(uri ${KIPRJMOD}/../../lib/pkl/pkl_silabs.lib)(options "")(descr ""))
  (lib (name pkl_sensor)(type Legacy)(uri ${KIPRJMOD}/../../lib/pkl/pkl_sensor.lib)(options "")(descr ""))
  (lib (name pkl_power)(type Legacy)(uri ${KIPRJMOD}/../../lib/pkl/pkl_power.lib)(options "")(descr ""))
  (lib (name pkl_molex)(type Legacy)(uri ${KIPRJMOD}/../../lib/pkl/pkl_molex.lib)(options "")(descr ""))
  (lib (name pkl_misc)(type Legacy)(uri ${KIPRJMOD}/../../lib/pkl/pkl_misc.lib)(options "")(descr ""))
  (lib (name pkl_memory)(type Legacy)(uri ${KIPRJMOD}/../../lib/pkl/pkl_memory.lib)(options "")(descr ""))
  (lib (name pkl_maxim)(type Legacy)(uri ${KIPRJMOD}/../../lib/pkl/pkl_maxim.lib)(options "")(descr ""))
  (lib (name pkl_logos)(type Legacy)(uri ${KIPRJMOD}/../../lib/pkl/pkl_logos.lib)(options "")(descr ""))
  (lib (name pkl_linear)(type Legacy)(uri ${KIPRJMOD}/../../lib/pkl/pkl_linear.lib)(options "")(descr ""))
  (lib (name pkl_lattice)(type Legacy)(uri ${KIPRJMOD}/../../lib/pkl/pkl_lattice.lib)(options "")(descr ""))
  (lib (name pkl_ftdi)(type Legacy)(uri ${KIPRJMOD}/../../lib/pkl/pkl_ftdi.lib)(options "")(descr ""))
  (lib (name pkl_device)(type Legacy)(uri ${KIPRJMOD}/../../lib/pkl/pkl_device.lib)(options "")(descr ""))
  (lib (name pkl_cypress)(type Legacy)(uri ${KIPRJMOD}/../../lib/pkl/pkl_cypress.lib)(options "")(descr ""))
  (lib (name pkl_conn)(type Legacy)(uri ${KIPRJMOD}/../../lib/pkl/pkl_conn.lib)(options "")(descr ""))
  (lib (name pkl_analog_devices)(type Legacy)(uri ${KIPRJMOD}/../../lib/pkl/pkl_analog_devices.lib)(options "")(descr ""))
)

All the paths are relative to the location of your kicad project .pro file. This is what the ${KIPRJMOD} variable represents. This means you have to go up two levels ../.. to reach the toplevel git repository directory and then descend into lib/pkl to reach the library file in question.

The rest should be self explanatory. You git add the *.pro, *-cache.lib, *.sch, *.kicad_pcb, fp-lib-table and sym-lib-table to your git project and commit. You can also create a .gitignore at the toplevel to deal with backup files.

My KiCad .gitignore usually just contains the following:

*.bak
*-bak
*.zip
*gerber*
_autosave-*

After everything is said and done you should end up with a directory and file tree that looks similar to the following:

kicad-project-git
├── .git
│   │
│   .
│   .
│   .
│
├── .gitmodules
├── hardware
│   └── v0.1a
│       ├── fp-info-cache
│       ├── fp-lib-table
│       ├── <project>-cache.lib
│       ├── <project>.kicad_pcb
│       ├── <project>.pro
│       ├── <project>.sch
│       └── sym-lib-table
├── lib
│   └── pkl
│       │
│       .
│       .
│       .
│
└── README.md

I hope this helps, if you have suggestions to make this tutorial clearer let me know in the Gitter chat. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment