Skip to content

Enum Statements

The pcb-enum statement defines an enumerated type. An enumerated type or enumeration is a user-defined type that allows a variable to have one of a predefined set of constant values.

Signature

defpackage my/package/path :
  import core

public pcb-enum my/package/path/my-enum-name :
  MY_ENUM_VALUE_1
  MY_ENUM_VALUE_2
  ...

my/package/path/ is the fully-qualified path name where the pcb-enum statement is defined. my-enum-name is the symbol name of this enumeration.

Note that each value in the enumeration must be unique - no duplicates are allowed.

Under the hood, pcb-enum expands to multiple statements and defines multiple symbols. It is different from the pcb-module, pcb-component, and other JITX statements in that it does not create circuit topologies, nets, or in general, ESIR statements.

Usage

The following example shows how we would define and use an enumeration type called Antenna in a package custom-components/esp32-wroom-32. It will have two possible values, Integrated and UMCX.

defpackage custom-components/esp32-wroom-32 :
  import core

public pcb-enum custom-components/esp32-wroom-32/Antenna :
  Integrated
  UMCX

; Using the pcb-enum as a type to define land pattern geometry
pcb-landpattern esp32-wroom (antenna-type:Antenna) :
  switch(antenna-type):
    Integrated :
      package-y = 25.5
      offset = (25.5 - 19.2) / 2.0
    UMCX :
      package-y = 19.2
      offset = 0.0

Qualified Path Requirement

When declaring a pcb-enum, make sure to prefix the enumeration name with the qualified name of the package where it is defined. If a qualified package path is not given in the enumeration's definition, JITX will error on running the design.

#use-added-syntax(jitx)
defpackage custom-components/esp32-wroom-32 :
  import core

public pcb-enum Antenna :
  Integrated
  UMCX

If we try the run the toy design above, JITX will error with the following :

Errors occurred during parsing:
  .../my_project/main.stanza:1.0: Errors occurred during parsing:
    .../my_project/main.stanza:5.16 pcb-enum name 'Antenna' is not a package-qualified name.

Using the qualified package path allows the design to run successfully.

#use-added-syntax(jitx)
defpackage custom-components/esp32-wroom-32 :
  import core

public pcb-enum custom-components/esp32-wroom-32/Antenna :
  Integrated
  UMCX

Length of an Enum

When a pcb-enum is declared, such as Antenna in our example above, JITX automatically creates a new integer which represents the length of the enumeration, called <enum-name>-length, so Antenna-length in our example. We define here to mean the number of unique values in the enumeration.

println(Antenna-length) ; prints 2