Skip to content

Commit

Permalink
working on gpio-sim
Browse files Browse the repository at this point in the history
  • Loading branch information
sombriks committed Jun 29, 2024
1 parent 64f362f commit 449631b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 12 deletions.
11 changes: 11 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

Noteworthy changes

## 2024-06-29

- acquired an [raxda rock 3c][https://radxa.com/products/rock3/3c/] so i can
test on real hardware again. my rasp collection is aging and isn't reliable
anymore.
- did a fedora38 virtual machine and to my happy surprise this version has the
gpio-sim kernel module built and offers libgpiod 1.6.4! best of two worlds.
pretty soon to tell if our testsuite will run on github actions, but at least
i can speed up things a little by coding into this vm instead of the smaller,
slower board.

## 2024-04-20

## 0.4.3
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"configure": "node-gyp configure",
"build": "node-gyp build",
"clean": "node-gyp clean",
"configure-gpio-sim": "sudo sh test/prepare-gpio-sim.sh",
"test": "mocha",
"test:coverage": "nyc npm run test"
},
Expand All @@ -30,5 +31,8 @@
"dependencies": {
"bindings": "^1.3.0",
"nan": "^2.11.1"
},
"engines": {
"node": ">=18"
}
}
}
6 changes: 3 additions & 3 deletions test/00-misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ describe("libgpiod miscellaneous bindings", function () {
done();
});

xit("should get line instant value", function (done) {
it("should get line instant value", function (done) {
gpiod.getInstantLineValue(0, 17);
done();
});

xit("should NOT get line instant value due wrong chip name", function (done) {
it("should NOT get line instant value due wrong chip name", function (done) {
try {
const ret = gpiod.getInstantLineValue("/dev/gpiochipZero", 17);
} catch (ex) {
done();
}
});

xit("should blink line with instant value", function (done) {
it("should blink line with instant value", function (done) {
let count = 7;
const interval = setInterval(() => {
gpiod.setInstantLineValue("/dev/gpiochip0", 17, count-- % 2);
Expand Down
6 changes: 3 additions & 3 deletions test/01-chip.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const gpiod = require("..");

describe("libgpiod chip bindings", function () {
xit("should 'create' a new chip by number", (done) => {
it("should 'create' a new chip by number", (done) => {
const chip0 = new gpiod.Chip("0");
done();
});

xit("should 'create' a new chip by name", (done) => {
it("should 'create' a new chip by name", (done) => {
const chip0 = new gpiod.Chip("gpiochip0");
done();
});

xit("should 'create' a new chip by path", (done) => {
it("should 'create' a new chip by path", (done) => {
const chip0 = new gpiod.Chip("/dev/gpiochip0");
done();
});
Expand Down
2 changes: 1 addition & 1 deletion test/03-pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const assert = require("assert");

describe("libgpiod Pin sugar", () => {

xit("should create a Pin fo line 10", done => {
xit("should create a Pin for line 10", done => {
const pin = new gpiod.Pin(10);
assert(pin instanceof gpiod.Line);
done();
Expand Down
28 changes: 24 additions & 4 deletions test/prepare-gpio-sim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,34 @@
#
# Without it all testcases will fail.

# for gpiod 2.x
# remember to create the udev rule:
# # /etc/udev/rules.d/85-gpiochip.rules
# KERNEL=="gpiochip*", SUBSYSTEM=="gpio", MODE="0660", GROUP="wheel"

# for gpio-sim
# see https://docs.kernel.org/admin-guide/gpio/gpio-sim.html
# mount | grep configfs # provavelmente /sys/kernel/config
# modprobe gpio-sim
# mkdir -p /sys/kernel/config/gpio-sim/fakegpio/gpio-bank0/line0
# mkdir -p /sys/kernel/config/gpio-sim/fakegpio/gpio-bank0/line1
# mkdir -p /sys/kernel/config/gpio-sim/fakegpio/gpio-bank0/line17
# mkdir -p /sys/kernel/config/gpio-sim/fakegpio/gpio-bank0/line40
# echo 1 > /sys/kernel/config/gpio-sim/fakegpio/live
# gpiodetect
# chmod a+rw /dev/gpiochip*

# for gpiod 1.x
# for gpio-mockup
# see https://docs.kernel.org/admin-guide/gpio/gpio-mockup.html
# modprobe gpio-mockup gpio_mockup_ranges=-1,40 gpio_mockup_named_lines
#
# gpiodetect
# chmod a+rw /dev/gpiochip*

modprobe gpio-sim
for i in $(seq 1 40)
do
mkdir -p /sys/kernel/config/gpio-sim/fakegpio/gpio-bank0/line$i
done
echo 1 > /sys/kernel/config/gpio-sim/fakegpio/live
gpiodetect
gpioinfo

echo "run sudo sh -c 'echo 0 > /sys/kernel/config/gpio-sim/fakegpio/live' to modify the simulator setup"

0 comments on commit 449631b

Please sign in to comment.