Skip to content

Add description of Packaged Custom Chips #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/chips-api/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ In addition, you can use the [Wokwi Logic Analyzer](../guides/logic-analyzer) to
Make sure to include a newline ("\n") at the end of your `printf()` messages. The simulator shows the messages only when it reaches a newline character.
:::

## Packaged custom chips, at Github repositories

Once you consider your custom chip stable enough, you can package it and publish it as a separate Github repository, with releases. WokWi is able to fetch the releases from Github and include them into other designs. Each release must include a `chip.zip` file containing exactly one `chip.json` and one `chip.wasm` file, describing the chip. For more information, see [Packaged Chips](./packaged-chip) or see the [Inverter chip example](https://github.com/wokwi/inverter-chip/releases) in Github.

To use such a packaged custom chip in your design, use the [`"dependencies"` tag in your `diagram.json`](/diagram-format#connections) file.

## Chips API reference 📖

- [GPIO pins API](gpio)
Expand Down
48 changes: 48 additions & 0 deletions docs/chips-api/packaged-chip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: Packaged Wokwi Custom Chips
sidebar_label: Packaged Chips
---

# Packaged Custom Chips

A packaged Custom Chip is a Wokwi Custom Chip that can be used in other design but that has not been (yet) included into the Wokwi proper. While the GUI does not currently include a direct way to add such chips into a design, you can add them by manually editing your `diagram.json` file.

You can also create your own Packaged Custom Chips and make them available for others to be used. To do so, once your chip is ready (enough), you can publish it as a
[Github repository release](https://docs.github.com/en/repositories/releasing-projects-on-github).
In the future, there may be alternative ways to make chips available.

## Introduction

Essentially, a custom chip consists of two files, `chip.json` and `chip.wasm`. The former contains a [chip description](./chip-json) in JSON, defining the properties of the chip. The `chip.wasm` contains the Webassembly definition of the chip functionality. It is usually produced by compiling a C source code file that describes the chip functionality.

Any custom chip may be packaged into a Packaged Custom Chip by creating a `chip.zip` package and publishing it in a release in a Github repository. Correspondingly, any Github repository release[^1] with a `chip.zip` package that contains a `chip.json` and a `chip.wasm` file is understood to be a custom chip by the Wokwi Diagram Editor.

[^1]: Currently the release name must start with the letter `v`, see below.

## Using a Packaged Custom Chip

Let's imagine that you need an inverter in your design and there aren't one directly available. Consider the https://github.com/wokwi/inverter-chip/ repository. It contains a definition of a very simple Custom Chip, an inverter. The repository also contains a release named `v1.0.0`: https://github.com/wokwi/inverter-chip/releases/tag/v1.0.0

That release contains the `chip.zip` file as required, containing the required files.

To use the Packaged Custom Chip inverter in your design, first include a dependency into your `diagram.json`:
```
"dependencies": { "chip-inverter": "github.com/wokwi/[email protected]" }
```

:::note

Note that the release name in Github is `v1.0.0`, beginning with a letter `v`, but the dependency in the `diagram.json` lists it as `@1.0.0`, without the letter `v`.

Once you have included it as a dependency, you can use it normally, by adding it to `"parts"`:
```
"parts": [
{
"type": "chip-inverter",
"id": "inverter1",
...
```

## Creating a Packaged Custom Chip

To create a Packaged Custom Chip, publish your chip design in Github as a repository and make there a release. Further documentation for this remains to be written.
5 changes: 5 additions & 0 deletions docs/diagram-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ follows:
"author": "Uri Shaked",
"editor": "wokwi",
"parts": [],
"dependencies": [],
"connections": []
}
```
Expand Down Expand Up @@ -113,6 +114,10 @@ to pin 13 of the `uno` part:

You can find the name of a component pin by moving the mouse over it.

### Dependencies

The `"dependencies"` section currently defines custom chips that are not yet included into the WokWi itself but that are available as separate Github repositories. For more details, see [Packaged Chips](./packaged-chip).

### Wire placement mini-language

Each item in the `"connections"` section can specify a list of instructions
Expand Down