You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 5, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: board/aio.md
+7-7
Original file line number
Diff line number
Diff line change
@@ -22,13 +22,13 @@ See also the [Web IDL](./webidl.md) definition.
22
22
#### The `AIO open(options)` method
23
23
Configures an AIO pin using data provided by the `options` argument. It involves the following steps:
24
24
- If `options` is a string, create a dictionary 'init' and use the value of `options` to initialize the `init.pin` property.
25
-
- Otherwise if `options` is a number, create a dictionary 'init' and let `init.name` be `options`.
26
-
- Otherwise if `options` is a dictionary, let `init` be `options`. It may contain the following [`AIO`](#aio) properties, where at least `name` MUST be specified:
27
-
*`name` for board pin name with the valid values defined by the board, or for the numeric index of the analog pin;
28
-
*`mapping` to specify if OS or board namespace is to be used with the pin (by default `"os"`).
25
+
- Otherwise if `options` is a number, create a dictionary 'init' and let `init.pin` be `options`.
26
+
- Otherwise if `options` is a dictionary, let `init` be `options`. It may contain the following [`AIO`](#aio) properties, where at least `pin` MUST be specified:
27
+
*`pin` for board pin name with the valid values defined by the board, or for the numeric index of the analog pin;
28
+
*`mapping` to specify if OS or board namespace is to be used with the pin (by default `"system"`).
29
29
*`precision` for the bit width of a sample (if the board supports setting the sampling rate).
30
30
- If any property of `init` is specified and has an invalid value, throw `TypeError`.
31
-
- Request the underlying platform to initialize AIO on the pin identified by `init.name` in the namespace specified by `init.mapping`, or if not found, then in the other namespace. In case of failure, throw `InvalidAccessError`.
31
+
- Request the underlying platform to initialize AIO on the pin identified by `init.pin` in the namespace specified by `init.mapping`if that is defined. If not found, throw `InvalidAccessError`. If `init.mapping is not defined, then search `init.pin` first in the OS namespace, then in board namespace. In case of failure, throw `InvalidAccessError`.
32
32
- Let `aio` be the `AIOPin`](#aiopin) object that represents the hardware pin identified by `init.name`.
33
33
- If `init.precision` is defined, request the board to set the precision and initialize the `aio.precision` property with the value supported by the underlying platform. If there is an error, throw `InvalidAccessError`.
34
34
- Initialize the `aio.value` property with `undefined`.
@@ -39,8 +39,8 @@ Configures an AIO pin using data provided by the `options` argument. It involves
39
39
40
40
| Property | Type | Optional | Default value | Represents |
41
41
| --- | --- | --- | --- | --- |
42
-
|`name`| String or Number | no |`undefined`| pin name |
43
-
|`mapping`| enum | no |`"os"`| pin mapping, `"os"` or `"board"`|
42
+
|`pin`| String or Number | no |`undefined`| pin name |
43
+
|`mapping`| enum | no |`"system"`| pin mapping, `"system"` or `"board"`|
44
44
|`precision`| unsigned long | yes |`undefined`| bit length of digital sample |
The `pin` property is either a number or string, with values defined by the OS or board documentation. The default valus is `undefined`.
37
+
38
+
The `mapping` property represents the pin namespace, either `"system"` or `"board"`, by default `"system"`.
39
+
40
+
The `mode` property MUST take the value `"in"` or `"out"`. The default value is `"out"`.
41
+
42
+
The `activeLow` property tells whether the pin value 0 means active. If `activeLow` is `true`, with `value` 0 the pin is active, otherwise inactive. For instance, if an actuator is attached to the (output) pin active on low, client code should write the value 0 to the pin in order to activate the actuator. The default value is `false`.
43
+
44
+
The `edge` property is used for input pins and tells whether the `data` event is emitted on the rising edge of the signal (string value `"rising"`) when `value` changes from 0 to 1, or on falling edge (string value `"falling"`) when `value` changes from 1 to 0, or both edges (string value `"any"`), or never (string value `"none`"). The default value is `"none"`.
45
+
46
+
The `state` property tells if the internal pulldown (string value `"pulldown"`) or pullup (string value `"pullup"`) resistor is used for input pins to provide a default value (0 or 1) when the input is floating. The default value is `undefined`.
47
+
48
+
24
49
<aname="open"></a>
25
50
#### The `GPIO open(options)` method
26
51
Configures a GPIO pin using data provided by the `options` argument, that may contain the following properties:
27
-
<aname="gpiooptions"></a>
28
-
*`name` for pin name, either a number or string, by default `undefined`
29
-
*`mapping` for either `"board"` or `"os"` pin mapping, by default `"os"`
30
-
*`mode` with valid values `"in"` or `"out"`, by default `"out"`
31
-
*`activeLow`, by default `false`
32
-
*`edge`, with valid values: `"rising"`, `"falling"`, `"any"`, `"none"`, by default `"none"`
33
-
*`state`, by default `undefined`, supported values: `"pull-up"`, `"pull-down"`, `"high-impedance"`.
34
52
35
53
The method runs the following steps:
36
-
- If `options` is a number or string, let `init` be a [GPIOOptions](#gpiooptions) object, let `init.name` be `options` and let the other [GPIOOptions](#gpiooptions) properties take the default values.
37
-
- If `options` is a dictionary and if `options.name` is not defined, throw `TypeError`. If any of the `options` properties has an invalid value, throw `TypeError`. Let the the missing [GPIOOptions](#gpiooptions) properties take the default values. Let `init` be `options`.
38
-
-Let `gpio` be the [`GPIO`](#gpio) object that represents the requested pin corresponding to`init.name`, by matching `init.name` in the pin namespace specified by `mapping`, then in the other pin namespace. If there is no match in either namespaces, throw `InvalidAccessError`.
39
-
-Initialize`gpio`with the properties of `init` and return `gpio`.
54
+
- If `options` is a number or string, let `init` be a [GPIOOptions](#gpiooptions) object, let `init.pin` be `options` and let the other [GPIOOptions](#gpiooptions) properties take the default values.
55
+
- If `options` is a dictionary and if `options.pin` is not defined, throw `TypeError`. If any of the `options` properties has an invalid value, throw `TypeError`. Let the the missing [GPIOOptions](#gpiooptions) properties take the default values. Let `init` be `options`.
56
+
-Request the underlying platform to initialize GPIO on the pin identified by`init.pin` in the namespace specified by `init.mapping` if that is defined. If not found, throw `InvalidAccessError`. If `init.mapping is not defined, then search `init.pin` first in the OS namespace, then in board namespace. In case of failure, throw `InvalidAccessError`.
57
+
-Let`gpio`be the [`GPIO`](#gpio) object that represents the requested pin corresponding to `init.pin` and return `gpio`.
40
58
41
59
<aname="port"></a>
42
60
#### The `GPIO port(port, options)` method
43
61
Configures a GPIO pin or port using data provided by the `options` argument that can take the same properties as in the [`open()`](#open) method.
44
62
A GPIO port can be identified either by a symbolic name defined by the OS or the board, or a sequence of pin names the implementation binds together and are written and read together.
63
+
The `port` argument is either a number or string representing a symbolic port name defined in the OS or board documentation, or an array of strings representing the pin names participating in the port in MSB order, i.e. the first element in the array represents the MSB.
64
+
45
65
The `port()` method runs the following steps:
46
-
- If `port` is not a string or an array with at least one element, throw `TypeError`.
47
-
- Let `init` be a [GPIOOptions](#gpiooptions) object with all properties not defined in `options` take default values. If any of the `init` properties has an invalid value, throw `TypeError`.
48
-
- If `port` is a string, match it to the supported GPIO port names in the pin namespace specified by `mapping`, or then in the other pin namespace. If there is no match in either namespaces, throw `InvalidAccessError`. Otherwise let `gpio` be the [`GPIO`](#gpio) object representing the requested port and initialize it with `init`. Let `gpio.name` be `port` and let `gpio.port` be `undefined`.
49
-
- Otherwise if `port` is an array, run the following sub-steps for aggregating pins in the implementation:
50
-
* Let `gpio.name` take the string value `"port"` and `gpio.port` be the sequence of pin names that form the GPIO port.
66
+
- If `options` is a defined, let `mapping` be `init.mapping`. Let `init` be `options` and let the the missing [GPIOOptions](#gpiooptions) properties take the default values.
67
+
- Otherwise if `options` is not defined, let `init` be a [GPIOOptions](#gpiooptions) dictionary with all properties taking the default value.
68
+
- If `port` is a number or string, run the following sub-steps:
69
+
* If `mapping` is defined, match `port` to the supported GPIO port names in the pin namespace specified by `mapping`. If not found, throw `InvalidAccessError`.
70
+
* Otherwise if `mapping` is not defined, search `port` first in the OS namespace, then in board namespace. If both fail, throw `InvalidAccessError`.
71
+
* Request the underlying platform to initialize the GPIO port identified by `port` and initialize it using `init`.
72
+
* Let `gpio` be the [`GPIO`](#gpio) object representing the requested port and return `gpio`.
73
+
- Otherwise if `init.port` is an array, run the following sub-steps for aggregating pins in the implementation:
74
+
* Let `gpio` be a [`GPIO`](#gpio) object.
51
75
* For each pin name in the `port` sequence, run the [`open()`](#open) method with `init` as argument, associate the returned [`GPIO`](#gpio) object with the `gpio` object and make it represent a bit in the value returned by `gpio.read()`, with the first element in the sequence representing the most significant bit. If any of the opens fail, close the other pins and throw `InvalidAccessError`.
52
76
* Initialize [`gpio.write()`](#write) with a function that obtains the corresponding bit values for each pin participating in the port and writes the pin values. Re-throw any errors.
53
77
* Initialize [`gpio.read()`](#read) with a function that reads the corresponding bit values from each pin participating in the port and returns the assembled value. Re-throw any errors.
@@ -57,17 +81,7 @@ The `port()` method runs the following steps:
57
81
58
82
<aname="gpio"></a>
59
83
### The `GPIO` interface
60
-
The `GPIO` interface extends the [`Pin`](./README.md/#pin) object and implements the [`EventEmitter`](../README.md/#events) interface. It exposes the following properties and methods.
61
-
62
-
| Property | Type | Optional | Default value | Represents |
63
-
| --- | --- | --- | --- | --- |
64
-
|`name`| String or Number | no |`undefined`| pin name |
65
-
|`mapping`| String | no |`"os"`| pin mapping |
66
-
|`mode`| String | no |`undefined`| I/O mode |
67
-
| `port` | array | yes | `undefined` | array of pin names representing the ports
68
-
|`activeLow`| boolean | yes |`false`| whether the pin is active on logical low |
The `GPIO` interface implements the [`EventEmitter`](../README.md/#events) interface. It exposes the following methods and event.
71
85
72
86
| Method | Description |
73
87
| --- | --- |
@@ -81,18 +95,6 @@ The `GPIO` interface extends the [`Pin`](./README.md/#pin) object and implements
81
95
82
96
The `data` event listener callback receives the current value of the pin (0 or 1 for single pins, and positive integer for GPIO ports). Implementations SHOULD use a platform-dependent minimum time interval between firing two consecutive events.
83
97
84
-
The `pin` property inherited from [`Pin`](./README.md/#pin) can take values defined by the board documentation, usually positive integers.
85
-
86
-
The `mode` property MUST take the value `"input"` or `"output"`. The default value is `"input"`.
87
-
88
-
The `port` property, if defined, is an array of strings that represents the ordered list of pin names that form a GPIO port, where the first element in the array represents the MSB.
89
-
90
-
The `activeLow` property tells whether the pin value 0 means active. If `activeLow` is `true`, with `value` 0 the pin is active, otherwise inactive. For instance, if an actuator is attached to the (output) pin active on low, client code should write the value 0 to the pin in order to activate the actuator.
91
-
92
-
The `edge` property is used for input pins and tells whether the `data` event is emitted on the rising edge of the signal (string value `"rising"`) when `value` changes from 0 to 1, or on falling edge (string value `"falling"`) when `value` changes from 1 to 0, or both edges (string value `"any"`), or never (string value `"none`"). The default value is `"any"`, which means the event will fire on any change.
93
-
94
-
The `state` property tells if the internal pulldown (string value `"pulldown"`) or pullup (string value `"pullup"`) resistor is used for input pins to provide a default value (0 or 1) when the input is floating. The default value is `undefined`.
95
-
96
98
<aname="read"></a>
97
99
#### The `unsigned long read()` method
98
100
Returns the value of the GPIO pin or port.
@@ -118,7 +120,7 @@ try {
118
120
gpio3.write(1); // activate pin
119
121
gpio3.close();
120
122
121
-
var gpio5 =gpio.open({ name:5, mode:"out", activeLow:true });
123
+
var gpio5 =gpio.open({ pin:5, mode:"out", activeLow:true });
122
124
gpio5.write(0); // activate pin
123
125
gpio5.close();
124
126
@@ -139,7 +141,7 @@ try {
139
141
140
142
```javascript
141
143
try {
142
-
var gpio =require("board").gpio();
144
+
var gpio =require("gpio");
143
145
// Configure a GPIO port using default configuration
144
146
var gport1 =gpio.port([3,4,5,6,7,8], { mode:"in"});
Copy file name to clipboardExpand all lines: board/pwm.md
+10-9
Original file line number
Diff line number
Diff line change
@@ -26,13 +26,14 @@ See also the [Web IDL](./webidl.md) definition.
26
26
Configures a PWM pin using data provided by the `options` argument. It runs the following steps:
27
27
- If `options` is a string or number, create a dictionary `init` and use the value of `options` to initialize the `init.pin` property.
28
28
- Otherwise if `options` is a dictionary, let `init` be `options`. It may contain the following [`PWM`](#pwm) properties, but at least `name`
29
-
*`name` for pin name
30
-
*`mapping` for pin mapping, by default `"os"`
29
+
*`pin` for pin name
30
+
*`mapping` for pin mapping, either `"system"` or `"board"`, by default `"system"`
31
31
*`reversePolarity`, by default `false`.
32
32
- If any of the `init` properties is specified, but has invalid value on the board, throw `InvalidAccessError`.
33
-
- Let `pwm` be the [`PWM`](#pwm) object representing the pin identified by the `init.name` in the `mapping` pin namespace and request the underlying platform to initialize PWM for the given pin. In case of failure, throw `InvalidAccessError`.
34
-
- Initialize the `pwm.name` property with `init.name`.
35
-
- Initialize the `pwm.reversePolarity` property with `init.reversePolarity`.
33
+
- Let `mapping` be `init.mapping`.
34
+
- Let the missing `init` properties take the default value.
35
+
- Request the underlying platform to initialize PWM on the pin identified by `init.pin` in the namespace specified by `mapping` if that is defined. If not found, throw `InvalidAccessError`. If `mapping is not defined, then search `init.pin` first in the OS namespace, then in board namespace. In case of failure, throw `InvalidAccessError`.
36
+
- Let `pwm` be the [`PWM`](#pwm) object representing the pin identified by the `init.pin` initialized by `init`.
36
37
- Return the `pwm` object.
37
38
38
39
<aname="pwm"></a>
@@ -41,8 +42,8 @@ Represents the properties and methods that expose PWM functionality.
41
42
42
43
| Property | Type | Optional | Default value | Represents |
43
44
| --- | --- | --- | --- | --- |
44
-
|`name`| String or Number | no |`undefined`| pin name |
45
-
|`mapping`| String | no |`"os"`| pin mapping |
45
+
|`pin`| String or Number | no |`undefined`| pin name |
46
+
|`mapping`| String | no |`"system"`| pin mapping |
0 commit comments