-
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
0 parents
commit c84457b
Showing
5 changed files
with
290 additions
and
0 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,53 @@ | ||
name: Build Chip | ||
|
||
on: | ||
push: | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: write | ||
actions: read | ||
|
||
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/chip.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,21 @@ | ||
# Pressure Gauge Chip for Wokwi | ||
|
||
This custom chip for [Wokwi](https://wokwi.com/) simulates the output from a specific pressure gauge, designed to aid in the development and testing of projects requiring pressure measurements without the need for physical hardware. It emulates the behavior of the pressure gauge available at [this link](https://a.co/d/7iQsxGg), providing a convenient way to incorporate pressure sensing capabilities into your virtual projects. | ||
|
||
## Pin Names | ||
|
||
| Name | Description | | ||
| ---- | -------------------------------- | | ||
| VCC | Supply voltage | | ||
| GND | Ground | | ||
| S+ | Positive pressure signal output | | ||
| S- | Negative pressure signal output | | ||
|
||
## Usage | ||
|
||
To use the Pressure Gauge Chip in your Wokwi project, include it as a dependency in your `diagram.json` file: | ||
|
||
```json | ||
"dependencies": { | ||
"chip-pressure-gauge": "github:jisaiaha/pressure-gauge-chip@1.0.0" | ||
} |
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,29 @@ | ||
{ | ||
"name": "pressure-gauge", | ||
"version": 1, | ||
"author": "", | ||
"pins": [ | ||
"VCC", | ||
"GND", | ||
"S+", | ||
"S-" | ||
], | ||
"controls": [ | ||
{ | ||
"type": "button", | ||
"name": "powerButton", | ||
"label": "Power On/Off" | ||
}, | ||
{ | ||
"type": "slider", | ||
"name": "pressureInput", | ||
"label": "Pressure (PSI)", | ||
"min": 0, | ||
"max": 45, | ||
"step": 1, | ||
"default": 0 | ||
} | ||
], | ||
"outputs": ["S+"] | ||
} | ||
|
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 @@ | ||
#include "wokwi-api.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdbool.h> | ||
|
||
typedef struct { | ||
bool isOn; | ||
float pressurePSI; | ||
float outputVoltage; | ||
} chip_state_t; | ||
|
||
chip_state_t *chip; | ||
|
||
void chip_init() { | ||
chip = malloc(sizeof(chip_state_t)); | ||
chip->isOn = false; | ||
chip->pressurePSI = 0.0f; | ||
chip->outputVoltage = 0.0f; | ||
printf("My pressure gauge works!\n "); | ||
} | ||
|
||
// Function to calculate output voltage based on pressure | ||
float calculate_voltage_from_psi(float pressure) { | ||
return pressure * 5.0f; // Baseline calculation (modify as needed) | ||
} | ||
|
||
// Function to simulate voltage output based on pressure | ||
void update_output_voltage() { | ||
if (chip->isOn) { | ||
// Use the calculate_voltage_from_psi function | ||
chip->outputVoltage = calculate_voltage_from_psi(chip->pressurePSI); | ||
} else { | ||
chip->outputVoltage = 0.0f; | ||
} | ||
} | ||
|
||
void toggle_power() { | ||
chip->isOn = !chip->isOn; | ||
update_output_voltage(); | ||
} | ||
|
||
void set_pressure(float pressure) { | ||
chip->pressurePSI = pressure; | ||
update_output_voltage(); | ||
} | ||
|
||
void chip_free() { | ||
free(chip); | ||
} |
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,138 @@ | ||
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
#ifndef WOKWI_API_H | ||
#define WOKWI_API_H | ||
|
||
enum pin_value { | ||
LOW = 0, | ||
HIGH = 1 | ||
}; | ||
|
||
enum pin_mode { | ||
INPUT = 0, | ||
OUTPUT = 1, | ||
INPUT_PULLUP = 2, | ||
INPUT_PULLDOWN = 3, | ||
ANALOG = 4, | ||
|
||
OUTPUT_LOW = 16, | ||
OUTPUT_HIGH = 17, | ||
}; | ||
|
||
enum edge { | ||
RISING = 1, | ||
FALLING = 2, | ||
BOTH = 3, | ||
}; | ||
|
||
int __attribute__((export_name("__wokwi_api_version_1"))) __attribute__((weak)) __wokwi_api_version_1(void) { return 1; } | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef int32_t pin_t; | ||
#define NO_PIN ((pin_t)-1) | ||
|
||
typedef struct { | ||
void *user_data; | ||
uint32_t edge; | ||
void (*pin_change)(void *user_data, pin_t pin, uint32_t value); | ||
} pin_watch_config_t; | ||
|
||
extern __attribute__((export_name("chipInit"))) void chip_init(void); | ||
|
||
extern __attribute__((import_name("pinInit"))) pin_t pin_init(const char *name, uint32_t mode); | ||
|
||
extern __attribute__((import_name("pinRead"))) uint32_t pin_read(pin_t pin); | ||
extern __attribute__((import_name("pinWrite"))) void pin_write(pin_t pin, uint32_t value); | ||
extern __attribute__((import_name("pinWatch"))) bool pin_watch(pin_t pin, const pin_watch_config_t *config); | ||
extern __attribute__((import_name("pinWatchStop"))) void pin_watch_stop(pin_t pin); | ||
extern __attribute__((import_name("pinMode"))) void pin_mode(pin_t pin, uint32_t value); | ||
extern __attribute__((import_name("pinADCRead"))) float pin_adc_read(pin_t pin); | ||
extern __attribute__((import_name("pinDACWrite"))) float pin_dac_write(pin_t pin, float voltage); | ||
|
||
extern __attribute__((import_name("attrInit"))) uint32_t attr_init(const char *name, uint32_t default_value); | ||
extern __attribute__((import_name("attrInit"))) uint32_t attr_init_float(const char *name, float default_value); | ||
extern __attribute__((import_name("attrRead"))) uint32_t attr_read(uint32_t attr_id); | ||
extern __attribute__((import_name("attrReadFloat"))) float attr_read_float(uint32_t attr_id); | ||
|
||
typedef struct { | ||
void *user_data; | ||
uint32_t address; | ||
pin_t scl; | ||
pin_t sda; | ||
bool (*connect)(void *user_data, uint32_t address, bool connect); | ||
uint8_t (*read)(void *user_data); | ||
bool (*write)(void *user_data, uint8_t data); | ||
void (*disconnect)(void *user_data); | ||
uint32_t reserved[8]; | ||
} i2c_config_t; | ||
|
||
typedef uint32_t i2c_dev_t; | ||
|
||
extern __attribute__((import_name("i2cInit"))) i2c_dev_t i2c_init(const i2c_config_t *config); | ||
|
||
typedef struct { | ||
void *user_data; | ||
pin_t rx; | ||
pin_t tx; | ||
uint32_t baud_rate; | ||
void (*rx_data)(void *user_data, uint8_t byte); | ||
void (*write_done)(void *user_data); | ||
uint32_t reserved[8]; | ||
} uart_config_t; | ||
|
||
typedef uint32_t uart_dev_t; | ||
|
||
extern __attribute__((import_name("uartInit"))) uart_dev_t uart_init(const uart_config_t *config); | ||
extern __attribute__((import_name("uartWrite"))) bool uart_write(uart_dev_t uart, uint8_t *buffer, uint32_t count); | ||
|
||
typedef struct { | ||
void *user_data; | ||
pin_t sck; | ||
pin_t mosi; | ||
pin_t miso; | ||
uint32_t mode; | ||
void (*done)(void *user_data, uint8_t *buffer, uint32_t count); | ||
uint32_t reserved[8]; | ||
} spi_config_t; | ||
typedef uint32_t spi_dev_t; | ||
|
||
extern __attribute__((import_name("spiInit"))) spi_dev_t spi_init(const spi_config_t *spi_config); | ||
extern __attribute__((import_name("spiStart"))) void spi_start(const spi_dev_t spi, uint8_t *buffer, uint32_t count); | ||
extern __attribute__((import_name("spiStop"))) void spi_stop(const spi_dev_t spi); | ||
|
||
typedef struct { | ||
void *user_data; | ||
void (*callback)(void *user_data); | ||
uint32_t reserved[8]; | ||
} timer_config_t; | ||
|
||
typedef uint32_t timer_t; | ||
|
||
extern __attribute__((import_name("timerInit"))) timer_t timer_init(const timer_config_t *config); | ||
extern __attribute__((import_name("timerStart"))) void timer_start(const timer_t timer, uint32_t micros, bool repeat); | ||
extern __attribute__((import_name("timerStartNanos"))) void timer_start_ns_d(const timer_t timer, double nanos, bool repeat); | ||
static void timer_start_ns(const timer_t timer, uint64_t nanos, bool repeat) { | ||
timer_start_ns_d(timer, (double)nanos, repeat); | ||
} | ||
extern __attribute__((import_name("timerStop"))) void timer_stop(const timer_t timer); | ||
|
||
extern __attribute__((import_name("getSimNanos"))) double get_sim_nanos_d(void); | ||
|
||
static uint64_t get_sim_nanos(void) { | ||
return (uint64_t)get_sim_nanos_d(); | ||
} | ||
|
||
typedef uint32_t buffer_t; | ||
extern __attribute__((import_name("framebufferInit"))) buffer_t framebuffer_init(uint32_t *pixel_width, uint32_t *pixel_height); | ||
extern __attribute__((import_name("bufferRead"))) void buffer_read(buffer_t buffer, uint32_t offset, uint8_t *data, uint32_t data_len); | ||
extern __attribute__((import_name("bufferWrite"))) void buffer_write(buffer_t buffer, uint32_t offset, uint8_t *data, uint32_t data_len); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* WOKWI_API_H */ |