-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmain.c
More file actions
30 lines (25 loc) · 737 Bytes
/
main.c
File metadata and controls
30 lines (25 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// For information and examples see:
// https://link.wokwi.com/custom-chips-alpha
#include "wokwi-api.h"
#include <stdio.h>
#include <stdlib.h>
typedef struct {
pin_t pin_in;
pin_t pin_out;
} chip_state_t;
static void chip_pin_change(void *user_data, pin_t pin, uint32_t value) {
chip_state_t *chip = (chip_state_t*)user_data;
printf("Pin change: %d %d\n", pin, value);
pin_write(chip->pin_out, !value);
}
void chip_init(void) {
chip_state_t *chip = malloc(sizeof(chip_state_t));
chip->pin_in = pin_init("IN", INPUT);
chip->pin_out = pin_init("OUT", OUTPUT);
const pin_watch_config_t config = {
.edge = BOTH,
.pin_change = chip_pin_change,
.user_data = chip,
};
pin_watch(chip->pin_in, &config);
}