@pamoja/gpio 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-MIT +21 -0
- package/README.md +80 -0
- package/package.json +39 -0
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Anthony Wiedman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# @pamoja/gpio
|
|
2
|
+
|
|
3
|
+
I2C address frames with reserved-range checks, the four SPI clock modes, and active-high or active-low pins. One capability of [pamoja](https://github.com/molexxxx/pamoja), one memory-safe Rust core with bindings for TypeScript, Python, and C#.
|
|
4
|
+
|
|
5
|
+
[](https://pamoja.molex.cloud/docs/reference/node/modules/_pamoja_gpio.html)
|
|
6
|
+
[](https://pamoja.molex.cloud/docs/guides/gpio.html)
|
|
7
|
+
[](https://pamoja.molex.cloud/docs/)
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @pamoja/gpio
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
This pulls in `@pamoja/native`, the compiled engine. `npm install pamoja` is the whole framework in one package.
|
|
16
|
+
|
|
17
|
+
## Example
|
|
18
|
+
|
|
19
|
+
The test that runs in CI, spliced here as it ran.
|
|
20
|
+
|
|
21
|
+
From [`bindings/node/guides/gpio.ts`](https://github.com/molexxxx/pamoja/blob/main/bindings/node/guides/gpio.ts):
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { PinEdge, PinLevel, PinPolarity, i2c, pin, spi } from '@pamoja/gpio'
|
|
25
|
+
|
|
26
|
+
// A BME280 answers at the 7-bit address its datasheet gives. That is not the byte that
|
|
27
|
+
// goes on the wire: the address shifts up one and the low bit says whether this
|
|
28
|
+
// transaction reads or writes, which is the step easiest to get wrong by hand.
|
|
29
|
+
const BME280 = 0x76
|
|
30
|
+
const hex = (byte: number) => `0x${byte.toString(16).toUpperCase()}`
|
|
31
|
+
console.log(`write to ${hex(i2c.addressFrame(BME280)[0]!)}`)
|
|
32
|
+
console.log(`read from ${hex(i2c.addressFrame(BME280, { read: true })[0]!)}`)
|
|
33
|
+
|
|
34
|
+
// The I2C specification keeps two ranges of addresses for itself, so a part answering in
|
|
35
|
+
// either is a wiring mistake rather than a device.
|
|
36
|
+
console.log(
|
|
37
|
+
`${hex(BME280)} reserved: ${i2c.isReserved(BME280)}, ` +
|
|
38
|
+
`${hex(i2c.RESERVED_FROM)} reserved: ${i2c.isReserved(i2c.RESERVED_FROM)}`,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
// A 10-bit address spends a reserved prefix over two bytes rather than one, so a bus
|
|
42
|
+
// driver has to send a different number of bytes depending on the address it holds.
|
|
43
|
+
// This is the worked example UM10204 itself prints.
|
|
44
|
+
const TEN_BIT_DEVICE = 0x2a5
|
|
45
|
+
console.log(`a 10-bit address takes ${i2c.frameLen(TEN_BIT_DEVICE, true)} bytes`)
|
|
46
|
+
|
|
47
|
+
// Datasheets quote clock polarity and phase as one mode number. Mode 3 idles the clock
|
|
48
|
+
// high and samples on the trailing edge.
|
|
49
|
+
const clock = spi.clockFor(3)
|
|
50
|
+
console.log(`spi mode 3: idles high ${clock.cpol}, samples on the trailing edge ${clock.cpha}`)
|
|
51
|
+
|
|
52
|
+
// A relay board sold as active low energises when its pin is driven low. The polarity
|
|
53
|
+
// carries that inversion, so no call site has to remember which way round it is.
|
|
54
|
+
const energise = pin.levelFor(PinPolarity.ActiveLow, true)
|
|
55
|
+
console.log(`to energise an active-low relay, drive the pin ${energise}`)
|
|
56
|
+
|
|
57
|
+
// Releasing it drives the line back high, an edge a falling trigger ignores.
|
|
58
|
+
const rising = pin.triggers(PinEdge.Rising, PinLevel.Low, PinLevel.High)
|
|
59
|
+
const falling = pin.triggers(PinEdge.Falling, PinLevel.Low, PinLevel.High)
|
|
60
|
+
console.log(`release seen by a rising trigger: ${rising}, by a falling trigger: ${falling}`)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## The same capability in every language
|
|
64
|
+
|
|
65
|
+
| Language | Package | Reference |
|
|
66
|
+
| --- | --- | --- |
|
|
67
|
+
| Rust | [`pamoja-gpio`](https://crates.io/crates/pamoja-gpio) | [reference](https://pamoja.molex.cloud/docs/reference/rust/pamoja_gpio/index.html), [docs.rs](https://docs.rs/pamoja-gpio) |
|
|
68
|
+
| TypeScript | [`@pamoja/gpio`](https://www.npmjs.com/package/@pamoja/gpio) | [reference](https://pamoja.molex.cloud/docs/reference/node/modules/_pamoja_gpio.html) |
|
|
69
|
+
| Python | [`pamoja-gpio`](https://pypi.org/project/pamoja-gpio/) | [reference](https://pamoja.molex.cloud/docs/reference/python/pamoja/gpio.html) |
|
|
70
|
+
| C# | [`Pamoja.Gpio`](https://www.nuget.org/packages/Pamoja.Gpio) | [reference](https://pamoja.molex.cloud/docs/reference/dotnet/api/Pamoja.Gpio.html) |
|
|
71
|
+
|
|
72
|
+
## Documentation
|
|
73
|
+
|
|
74
|
+
- [`@pamoja/gpio` reference](https://pamoja.molex.cloud/docs/reference/node/modules/_pamoja_gpio.html), every class, function, and type this package exports.
|
|
75
|
+
- [The I2C, SPI, and GPIO guide](https://pamoja.molex.cloud/docs/guides/gpio.html), with the same example in Rust, Python, and C#.
|
|
76
|
+
- [Every capability](https://pamoja.molex.cloud/docs/), and the [install page](https://pamoja.molex.cloud/docs/install.html).
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pamoja/gpio",
|
|
3
|
+
"version": "0.1.15",
|
|
4
|
+
"description": "I2C address frames with reserved-range checks, the four SPI clock modes, and active-high or active-low pins.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/molexxxx/pamoja.git",
|
|
12
|
+
"directory": "bindings/node/packages/gpio"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://pamoja.molex.cloud/docs/guides/gpio.html",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"pamoja",
|
|
17
|
+
"iot",
|
|
18
|
+
"robotics",
|
|
19
|
+
"gpio"
|
|
20
|
+
],
|
|
21
|
+
"main": "dist/index.js",
|
|
22
|
+
"types": "dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist/",
|
|
31
|
+
"LICENSE-MIT"
|
|
32
|
+
],
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">= 16"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@pamoja/native": "0.1.15"
|
|
38
|
+
}
|
|
39
|
+
}
|