-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
599 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM wokwi/builder-clang-wasm | ||
|
||
USER root | ||
RUN apk add gcompat libc6-compat | ||
|
||
# Install arduino-cli: | ||
RUN wget -O /tmp/cli.tar.gz \ | ||
https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Linux_64bit.tar.gz && \ | ||
tar -C /usr/local/bin -zxvf /tmp/cli.tar.gz && \ | ||
rm /tmp/cli.tar.gz | ||
RUN arduino-cli core update-index && arduino-cli core install arduino:avr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "Wokwi-chips clang ", | ||
"dockerFile": "Dockerfile", | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"Wokwi.wokwi-vscode" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Build Chip | ||
|
||
on: | ||
push: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v3 | ||
- name: Build chip | ||
uses: wokwi/wokwi-chip-clang-action@main | ||
with: | ||
sources: "src/main.c" | ||
- name: Copy chip.json | ||
run: sudo cp chip.json dist | ||
- name: 'Upload Artifacts' | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: chip | ||
path: | | ||
dist/chip.json | ||
dist/chip.wasm | ||
# The release job only runs when you push a tag starting with "v", e.g. v1.0.0 | ||
release: | ||
name: Release | ||
needs: build | ||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Download compiled chip | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: chip | ||
path: chip | ||
- name: Create a zip archive | ||
run: cd chip && zip -9 ../chip.zip chip.* | ||
env: | ||
ZIP_VERSION: ${{ github.ref_name }} | ||
- name: Upload release | ||
uses: ncipollo/release-action@v1 | ||
with: | ||
artifacts: chip.zip | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
generateReleaseNotes: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"recommendations": [ | ||
"wokwi.wokwi-vscode", | ||
"ms-vscode.makefile-tools", | ||
"vsciot-vscode.vscode-arduino" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"makefile.launchConfigurations": [ | ||
{ | ||
"cwd": "/workspaces/cd74act00/dist", | ||
"binaryPath": "/workspaces/cd74act00/dist/chip.wasm", | ||
"binaryArgs": [] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# SPDX-FileCopyrightText: © 2022 Uri Shaked <uri@wokwi.com> | ||
# SPDX-License-Identifier: MIT | ||
|
||
SOURCES = src/main.c | ||
TARGET = dist/chip.wasm | ||
testFileName = logic | ||
testFolderName = test | ||
|
||
.PHONY: all | ||
all: $(TARGET) dist/chip.json ; \ | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf dist ; \ | ||
rm -rf $(testFolderName) ; \ | ||
|
||
|
||
dist: | ||
mkdir -p dist | ||
|
||
$(TARGET): dist $(SOURCES) src/wokwi-api.h | ||
clang --target=wasm32-unknown-wasi --sysroot /opt/wasi-libc -nostartfiles -Wl,--import-memory -Wl,--export-table -Wl,--no-entry -Werror -o $(TARGET) $(SOURCES) | ||
|
||
dist/chip.json: dist chip.json | ||
cp chip.json dist | ||
|
||
|
||
.PHONY: test | ||
test: | ||
mkdir -p $(testFolderName) ; \ | ||
cd test && arduino-cli sketch new $(testFileName) && arduino-cli compile -e -b arduino:avr:uno $(testFileName) ; \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,19 @@ | ||
# cd54hct30 | ||
# 8-Input NAND Gate Chip | ||
|
||
Example of a basic custom chip for [Wokwi](https://wokwi.com/). | ||
|
||
The actual source code for the chip lives in [src/main.c](src/main.c), and the pins are described in [chip.json](chip.json). | ||
|
||
## Building | ||
|
||
The easiest way to build the project is to open it inside a Visual Studio Code dev container, and then run the `make` command. | ||
|
||
## Testing | ||
|
||
You can test this project using the [Wokwi extension for VS Code](https://marketplace.visualstudio.com/items?itemName=wokwi.wokwi-vscode). Open the project with Visual Studio Code, press "F1" and select "Wokwi: Start Simulator". | ||
|
||
If you want to make changes to the test project firmware, edit [test/logic/sketch.ino](test/logic/sketch.ino), and then run `make test` to rebuild the .hex file. You'll need the [arduino-cli](https://arduino.github.io/arduino-cli/latest/installation/), which is already installed in the dev container. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "cd54hct30", | ||
"author": "Algovoid", | ||
"pins": [ | ||
"A", | ||
"B", | ||
"C", | ||
"D", | ||
"E", | ||
"F", | ||
"GND", | ||
"YINV", | ||
"NC", | ||
"NC", | ||
"G", | ||
"H", | ||
"NC", | ||
"VCC" | ||
], | ||
"controls": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"version": 1, | ||
"author": "Algovoid", | ||
"editor": "wokwi", | ||
"parts": [ | ||
{ "type": "chip-cd54hct30", "id": "chip1", "top": -18.18, "left": 196.8, "attrs": {} }, | ||
{ | ||
"type": "wokwi-dip-switch-8", | ||
"id": "sw1", | ||
"top": -3.7, | ||
"left": 87.9, | ||
"rotate": 90, | ||
"attrs": {} | ||
}, | ||
{ "type": "wokwi-vcc", "id": "vcc2", "top": -76.04, "left": 192, "attrs": {} }, | ||
{ "type": "wokwi-gnd", "id": "gnd1", "top": 134.4, "left": 191.4, "attrs": {} }, | ||
{ | ||
"type": "wokwi-led", | ||
"id": "led1", | ||
"top": 6, | ||
"left": 359, | ||
"attrs": { "color": "red", "flip": "1" } | ||
} | ||
], | ||
"connections": [ | ||
[ "sw1:1a", "sw1:2a", "red", [ "h-38.4", "v9.6" ] ], | ||
[ "sw1:2a", "sw1:3a", "red", [ "h-38.4", "v9.6" ] ], | ||
[ "sw1:4a", "sw1:3a", "red", [ "h-38.4", "v-9.6" ] ], | ||
[ "sw1:5a", "sw1:4a", "red", [ "h-38.4", "v-9.6" ] ], | ||
[ "sw1:8a", "sw1:7a", "red", [ "h-38.4", "v-9.6" ] ], | ||
[ "sw1:6a", "sw1:5a", "red", [ "h-38.4", "v-9.6" ] ], | ||
[ "sw1:7a", "sw1:6a", "red", [ "h-38.4", "v-9.6" ] ], | ||
[ "vcc2:VCC", "chip1:VCC", "red", [ "v0", "h144" ] ], | ||
[ "vcc2:VCC", "sw1:1a", "red", [ "v0", "h-201.6" ] ], | ||
[ "gnd1:GND", "chip1:GND", "black", [ "v0" ] ], | ||
[ "chip1:YINV", "led1:A", "green", [ "v0" ] ], | ||
[ "gnd1:GND", "led1:C", "black", [ "v0", "h182.4" ] ], | ||
[ "sw1:1b", "chip1:A", "green", [ "h0" ] ], | ||
[ "sw1:2b", "chip1:B", "green", [ "h0" ] ], | ||
[ "chip1:C", "sw1:3b", "green", [ "h0" ] ], | ||
[ "sw1:4b", "chip1:D", "green", [ "h0" ] ], | ||
[ "chip1:E", "sw1:5b", "green", [ "h0" ] ], | ||
[ "sw1:6b", "chip1:F", "green", [ "h0" ] ], | ||
[ "sw1:7b", "chip1:G", "green", [ "h38.1", "v19.2", "h124.8", "v-48" ] ], | ||
[ "chip1:H", "sw1:8b", "green", [ "h21.01", "v67.2", "h-144", "v-19.2" ] ] | ||
], | ||
"dependencies": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Wokwi cd54hct30 Chip | ||
|
||
This is a custom chip for [Wokwi](https://wokwi.com/). It implements the cd54hct30 IC. | ||
|
||
## Description | ||
|
||
The cd54hct30 contain single 2-input Positive-OR gates. Each gate performs the Boolean function | ||
of Y = NOT(A . B . C . D . E . F . G . H) in positive logic. | ||
|
||
## Truth Table | ||
| INPUTS | | | ||
| ----------------------------------------------------------------------------- | OUTPUT | | ||
| INPUT A | INPUT B | INPUT C | INPUT D | INPUT E | INPUT F | INPUT G | INPUT H | | | ||
|---------|---------|---------|---------|---------|---------|---------|---------|---------| | ||
| L | X | X | X | X | X | X | X | H | | ||
| X | L | X | X | X | X | X | X | H | | ||
| X | X | L | X | X | X | X | X | H | | ||
| X | X | X | L | X | X | X | X | H | | ||
| X | X | X | X | L | X | X | X | H | | ||
| X | X | X | X | X | L | X | X | H | | ||
| X | X | X | X | X | X | L | X | H | | ||
| X | X | X | X | X | X | X | L | H | | ||
| H | H | H | H | H | H | H | H | L | | ||
|
||
|
||
## Pin names | ||
|
||
| Name | Description | | ||
| ---- | ----------------- | | ||
| A | Input signal A | | ||
| B | Input signal B | | ||
| C | Input signal C | | ||
| D | Input signal D | | ||
| E | Input signal E | | ||
| F | Input signal F | | ||
| G | Input signal G | | ||
| H | Input signal H | | ||
| Y | Output signal | | ||
| GND | Ground | | ||
| VCC | Supply voltage | | ||
|
||
|
||
## Usage | ||
|
||
To use this chip in your project, include it as a dependency in your `diagram.json` file: | ||
|
||
```json | ||
"dependencies": { | ||
"chip-cd54hct30": "github:wokwi-custom-chips/cd54hct30@0.1.0" | ||
} | ||
``` | ||
|
||
Then, add the chip to your circuit by adding a `chip-cd54hct30` item to the `parts` section of diagram.json: | ||
|
||
```json | ||
"parts": { | ||
..., | ||
{ "type": "chip-cd54hct30", "id": "chip1" } | ||
}, | ||
``` | ||
|
||
For a complete example, see [The cd54hct30 chip test project](https://wokwi.com/projects/398977400657873921). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright 2024 Algovoid | ||
|
||
#include "wokwi-api.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
typedef struct { | ||
pin_t pin_A; | ||
pin_t pin_B; | ||
pin_t pin_C; | ||
pin_t pin_D; | ||
pin_t pin_E; | ||
pin_t pin_F; | ||
pin_t pin_G; | ||
pin_t pin_H; | ||
pin_t pin_YINV; | ||
} chip_state_t; | ||
|
||
static void set_xor(chip_state_t *chip) { | ||
pin_write(chip->pin_YINV, !( pin_read(chip->pin_A) && pin_read(chip->pin_B) && pin_read(chip->pin_C) && pin_read(chip->pin_D) && pin_read(chip->pin_E) && pin_read(chip->pin_F) && pin_read(chip->pin_G) && pin_read(chip->pin_H) ) ); | ||
} | ||
|
||
|
||
static void chip_pin_change(void *user_data, pin_t pin, uint32_t value) { | ||
chip_state_t *chip = (chip_state_t*)user_data; | ||
set_xor(chip); | ||
} | ||
|
||
void chip_init() { | ||
printf("Initialize cd54hct30 chip!\n"); | ||
chip_state_t *chip = malloc(sizeof(chip_state_t)); | ||
|
||
chip->pin_A = pin_init("A", INPUT); | ||
chip->pin_B = pin_init("B", INPUT); | ||
|
||
chip->pin_C = pin_init("C", INPUT); | ||
chip->pin_D = pin_init("D", INPUT); | ||
|
||
chip->pin_E = pin_init("E", INPUT); | ||
chip->pin_F = pin_init("F", INPUT); | ||
|
||
chip->pin_G = pin_init("G", INPUT); | ||
chip->pin_H = pin_init("H", INPUT); | ||
chip->pin_YINV = pin_init("YINV", OUTPUT); | ||
|
||
|
||
pin_write(chip->pin_A, LOW); | ||
pin_write(chip->pin_B, LOW); | ||
|
||
pin_write(chip->pin_C, LOW); | ||
pin_write(chip->pin_D, LOW); | ||
|
||
pin_write(chip->pin_E, LOW); | ||
pin_write(chip->pin_F, LOW); | ||
|
||
pin_write(chip->pin_G, LOW); | ||
pin_write(chip->pin_H, LOW); | ||
|
||
const pin_watch_config_t config = { | ||
.edge = BOTH, | ||
.pin_change = chip_pin_change, | ||
.user_data = chip, | ||
}; | ||
|
||
pin_watch(chip->pin_A, &config); | ||
pin_watch(chip->pin_B, &config); | ||
|
||
pin_watch(chip->pin_C, &config); | ||
pin_watch(chip->pin_D, &config); | ||
|
||
pin_watch(chip->pin_E, &config); | ||
pin_watch(chip->pin_F, &config); | ||
|
||
pin_watch(chip->pin_G, &config); | ||
pin_watch(chip->pin_H, &config); | ||
|
||
set_xor(chip); | ||
} |
Oops, something went wrong.