Skip to content

Commit b4b4af3

Browse files
add documentation for new format
1 parent eb44d7d commit b4b4af3

File tree

2 files changed

+96
-31
lines changed

2 files changed

+96
-31
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"clrall",
55
"clrmask",
66
"MOSFET",
7+
"nanofarads",
78
"NFET",
89
"PFET",
910
"polylinegon",

format.md

Lines changed: 95 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,120 @@ Crossed: Joined: Corner: Crossed: Crossed: Dangling en
1515
| | | |
1616
```
1717

18-
## Components
19-
20-
### Small components
18+
### Wire Tags
2119

22-
Small components are notated with their reference designator: one or more uppercase letters followed by an ID, which can either be a number, or a period followed by some text.
20+
Wire tags look like `<name=` or `=name>` and are attached to specific wires. All wires tagged with the same `name` belong to the same net. Currently this only affects rendering.
2321

24-
They are always written horizontally even if the terminals are on the top and bottom.
22+
## Components
2523

26-
IDs are allowed to be duplicated and result in the same component values.
24+
Components are notated with their reference designator: one or more uppercase letters followed by an ID (a nonnegative integer) optionally followed by a suffix (which can be composed of uppercase letters and underscores)
2725

28-
Components can be padded on either side with `#`'s to make them bigger.
26+
* They are always written horizontally even if the terminals are on the top and bottom.
27+
* IDs are allowed to be duplicated and result in the same component values.
28+
* Components can be padded (horizontally and vertically) `#`'s to make them bigger and control the shape (for components that support shapes).
2929

3030
Examples:
3131

3232
* `C33`
3333
* `Q1001`
34-
* `L.Coil`
34+
* `L5`
3535
* `F3#`
36-
* `D7#####`
37-
* `U1#####`
38-
* `####R.Heater####`
36+
* `####D7#####`
37+
* `R333A`
38+
* ```txt
39+
# ######
40+
# ########
41+
----# #########
42+
# #U1G1#####----
43+
----# #########
44+
# ########
45+
# ######
46+
```
3947

40-
Components are able to accept "flags", which are other punctuation characters and lowercase letters touching them.
48+
Components' terminals are annotated with "flags", which are other punctuation characters and lowercase letters touching them.
4149

42-
* Polarized components (caps, diodes, etc.) accept a `+` to indicate the polarity,
43-
* Transistors use lowercase letters to indicate collector/emitter/base (for BJTs) or source/gate/drain (for FETs).
50+
* Polarized components (caps, diodes, etc.) use a `+` for one terminal to indicate the polarity,
51+
* Transistors use 3 lowercase letters to indicate collector/emitter/base (for bipolar transistors) or source/gate/drain (for field-effect transistors).
4452

45-
### Big components
53+
## Annotations
4654

47-
* Big components are indicated with a box made of `~` (top and bottom), `:` (sides), and `.` (corners).
48-
* The inside of the box can contain anything you want, but it must include exactly one reference designator as to what component it is.
55+
### Text Annotations
4956

50-
## Reference designators
57+
You can include arbitrary text in the diagram by `[enclosing it in brackets like this]`.
5158

52-
To include component values, pin numbers, etc, somewhere in the drawing but not touching any wires or other components, you can write component values - these are formatted as the reference designator (same as in circuit) followed by a `:` and the value parameter (which stops at the first whitespace). *I usually put these in a "BOM section" below the circuit itself but you could also put them right next to the component.*
59+
### Line Annotations
5360

54-
For simple components, this is usually just a value rating, but *without* the units (only the Metric prefix). For more specific components (mostly semiconductor devices) this is usually the part number and/or some string to determine how to draw the component.
61+
To outline certain areas with lines (that are not wires), you can draw lines with colons/tildes (for straight lines), and periods/single quotes (for corners) like so:
5562

56-
Examples:
63+
```txt
64+
.~~~~~~~~~~.
65+
: .~~~ :
66+
: : :
67+
: : :
68+
: : .~~'~~~~.
69+
: '~~~~' :
70+
'~~~~~~~~~~~~~~~'
71+
```
72+
73+
Lines are allowed to cross wires. They are crossed the same way that wires cross each other.
74+
75+
## Data
76+
77+
Every drawing is required to have a "data section" appended after it. The data section contains mappings of values to tell Schemascii how to render each component (e.g. how thick to make the lines, what the components' values are, etc.)
78+
79+
Here is some example data:
80+
81+
```txt
82+
* {
83+
%% these are global config options
84+
color = black
85+
width = 2; padding = 20;
86+
format = symbol
87+
mystring = "hello\nworld"
88+
}
89+
90+
R* %% matches any resistor
91+
{tolerance = .05; wattage = 0.25}
92+
93+
VR1 {
94+
resistance = 0 - 10k; %% ranges on variable components
95+
%% trailing comments are allowed
96+
}
97+
```
98+
99+
In each RULE, the SELECTOR defines what components and/or drawing objects match; for the ones that match, the MAPPING (which is stored as a Python `dict`) is or'ed into the computed properties. Rules on the bottom take precedence (there is no such thing as specificity like there is in CSS).
100+
101+
Selectors can match multiple scopes by using glob matching. Schemascii currently uses [`fnmatch`][fnmatch] to determine matching selectors but I'll probably change that.
102+
103+
See [options.md][options] for what options are available in which scopes.
104+
105+
Here is a rough grammar (space ignored):
106+
107+
```ebnf
108+
DATA = RULE (eol+ RULE)* ;
109+
RULE = SELECTOR eol* MAPPING ;
110+
SELECTOR = symbol ;
111+
MAPPING = "{" ((NAME "=" VALUE)? eol)* "}" ;
112+
NAME = string | symbol ;
113+
VALUE = (number | string | symbol)* ;
114+
number = /(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?/ ;
115+
string = /"(?:\\"|[^"])+"|\s+/ ;
116+
symbol = <any sequence of printing characters that isn't another kind of token>
117+
eol = ";" | comment? "\n"+ ;
118+
comment = "%%" <everything until newline> ;
119+
```
120+
121+
### Metric values
57122

58-
* `C33:2.2u` -- "2.2 &micro;F"
59-
* `Q1001:pnp:TIP102` -- "pnp", "npn", "pfet", or "nfet" to determine what kind of transistor, plus the part number; printed verbatim
60-
* `L51:0.33` -- this is rewritten to "330 mH" so that it has no decimal point.
61-
* `F3:1500m` -- rewritten: "1.5 A"
62-
* `D7:1N4001` -- again, part number
63-
* `U1:SN74LS08N,14,1,2,7,3` -- some components let you label pins with whatever you want (in this case just numbers). They start at the top-leftmost and follow **counterclockwise** to follow with the pin-numbering of most IC's.
64-
* `R2:10,5` -- this is formatted as "10 &ohm; 5 W". The second value is the rating; for resistors, this is a wattage, for most else, this is a maximum voltage.
123+
For many small components, the value of the component is just a number and some unit -- e.g. for resistors it's ohms (&ohm;). Schemascii includes built-in Metric normalization and units, so if the "value" is a Metric number it will be re-written to be as short as possible while still observing the conventions of typical component values. If the unit symbol is not included, it will be added.
65124

66-
## Inline configuration values
125+
* `value = 0.33m` on an inductor --> "330 &micro;H" (integer values are preferred).
126+
* `value = 0.33` on a resistor --> "0.33 &ohm;" (no Metric multiplier is preferred).
127+
* `value = 1500mA` on a fuse --> "1.5 A" (using decimal point is shorter)
128+
* `value = 2.2 nF` on a capacitor --> "2200 pF" (capacitances aren't typically given in nanofarads)
129+
* `value = 10; power = 5` --> "10 &ohm; 5 W". Many components have "secondary" optional values; the name will be given in the [options][].
67130

68-
**New in 0.2.0!**
131+
Also, if the value is not even a number -- such as `L1 {value = "detector coil"}`, the Metric-normalization code will not activate, and the value written will be used verbatim -- "L1 detector coil".
69132

70-
You can specify configuration values for rendering the components inline in the document by writing `!name=value!` in your document. See the help output of the Schemascii CLI for the different options (in the README) or look at the config options at the top of [`configs.py`](https://github.com/dragoncoder047/schemascii/blob/main/schemascii/configs.py). The most common options I use are `scale` and `padding`.
133+
[fnmatch]: https://docs.python.org/3/library/fnmatch.html#fnmatch.fnmatch
134+
[options]: options.md

0 commit comments

Comments
 (0)