Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit f8d1253

Browse files
committed
Make pin and pin mapping spec consistent
Signed-off-by: Zoltan Kis <[email protected]>
1 parent c17862c commit f8d1253

File tree

4 files changed

+70
-68
lines changed

4 files changed

+70
-68
lines changed

Diff for: board/aio.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ See also the [Web IDL](./webidl.md) definition.
2222
#### The `AIO open(options)` method
2323
Configures an AIO pin using data provided by the `options` argument. It involves the following steps:
2424
- 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"`).
2929
* `precision` for the bit width of a sample (if the board supports setting the sampling rate).
3030
- 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`.
3232
- Let `aio` be the `AIOPin`](#aiopin) object that represents the hardware pin identified by `init.name`.
3333
- 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`.
3434
- Initialize the `aio.value` property with `undefined`.
@@ -39,8 +39,8 @@ Configures an AIO pin using data provided by the `options` argument. It involves
3939

4040
| Property | Type | Optional | Default value | Represents |
4141
| --- | --- | --- | --- | --- |
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"` |
4444
| `precision` | unsigned long | yes | `undefined` | bit length of digital sample |
4545

4646
| Method | Description |

Diff for: board/gpio.md

+43-41
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,57 @@ When requiring `"gpio"`, the following steps are run:
2121

2222
See also the [Web IDL](./webidl.md) definition.
2323

24+
The following dictionary is used for initializing GPIO pins and ports.
25+
<a name="gpiooptions"></a>
26+
27+
| Property | Type | Optional | Default value | Represents |
28+
| --- | --- | --- | --- | --- |
29+
| `pin ` | String or Number | no | `undefined` | pin name |
30+
| `mapping` | String | no | `"system"` | pin mapping |
31+
| `mode` | String | no | `undefined` | I/O mode |
32+
| `activeLow` | boolean | yes | `false` | whether the pin is active on logical low |
33+
| `edge` | string | yes | `"any"` | Interrupt generation mode |
34+
| `state` | string | yes | `undefined` | "pulldown", "pullup" |
35+
36+
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+
2449
<a name="open"></a>
2550
#### The `GPIO open(options)` method
2651
Configures a GPIO pin using data provided by the `options` argument, that may contain the following properties:
27-
<a name="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"`.
3452

3553
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`.
4058

4159
<a name="port"></a>
4260
#### The `GPIO port(port, options)` method
4361
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.
4462
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+
4565
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.
5175
* 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`.
5276
* 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.
5377
* 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:
5781

5882
<a name="gpio"></a>
5983
### 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 |
69-
| `edge` | string | yes | `"any"` | Interrupt generation mode |
70-
| `state` | string | yes | `undefined` | "pulldown", "pullup" |
84+
The `GPIO` interface implements the [`EventEmitter`](../README.md/#events) interface. It exposes the following methods and event.
7185

7286
| Method | Description |
7387
| --- | --- |
@@ -81,18 +95,6 @@ The `GPIO` interface extends the [`Pin`](./README.md/#pin) object and implements
8195

8296
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.
8397

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-
9698
<a name="read"></a>
9799
#### The `unsigned long read()` method
98100
Returns the value of the GPIO pin or port.
@@ -118,7 +120,7 @@ try {
118120
gpio3.write(1); // activate pin
119121
gpio3.close();
120122

121-
var gpio5 = gpio.open({ name: 5, mode: "out", activeLow: true });
123+
var gpio5 = gpio.open({ pin: 5, mode: "out", activeLow: true });
122124
gpio5.write(0); // activate pin
123125
gpio5.close();
124126

@@ -139,7 +141,7 @@ try {
139141

140142
```javascript
141143
try {
142-
var gpio = require("board").gpio();
144+
var gpio = require("gpio");
143145
// Configure a GPIO port using default configuration
144146
var gport1 = gpio.port([3,4,5,6,7,8], { mode: "in"});
145147

Diff for: board/pwm.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ See also the [Web IDL](./webidl.md) definition.
2626
Configures a PWM pin using data provided by the `options` argument. It runs the following steps:
2727
- If `options` is a string or number, create a dictionary `init` and use the value of `options` to initialize the `init.pin` property.
2828
- 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"`
3131
* `reversePolarity`, by default `false`.
3232
- 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`.
3637
- Return the `pwm` object.
3738

3839
<a name="pwm"></a>
@@ -41,8 +42,8 @@ Represents the properties and methods that expose PWM functionality.
4142

4243
| Property | Type | Optional | Default value | Represents |
4344
| --- | --- | --- | --- | --- |
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 |
4647
| `reversePolarity` | boolean | yes | `false` | PWM polarity |
4748
| `write()` | function | no | defined by implementation | set and enable PWM signal |
4849
| `stop()` | function | no | defined by implementation | stop the PWM signal |
@@ -54,9 +55,9 @@ Represents the properties and methods that expose PWM functionality.
5455
| [`stop()`](#stop) | stop the PWM signal |
5556
| [`close()`](#close) | close the pin |
5657

57-
The `name` property is an opaque number or string, representing a pin name.
58+
The `pin` property is an opaque number or string, representing a pin name.
5859

59-
The `mapping` property represents the pin namespace, either `"board"` or `"os"`.
60+
The `mapping` property represents the pin namespace, either `"board"` or `"system"`.
6061

6162
The `reversePolarity` property tells whether the PWM signal is active on 0. The default value is `false`.
6263

Diff for: board/webidl.md

+10-11
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ typedef (long or unsigned long or double or unrestricted double) Number;
1515
typedef (DOMString or USVString) String;
1616
typedef (Number or String) PinName;
1717

18-
enum PinMapping { "board", "os" };
18+
enum PinMapping { "board", "system" };
1919

2020
// AIO
2121
interface AIOObject {
2222
AIO open((PinName or AIOOptions) init);
2323
};
2424

2525
dictionary AIOOptions {
26-
PinName name;
27-
PinMapping mapping = "os";
26+
PinName pin;
27+
PinMapping mapping = "system";
2828
unsigned long precision = 10;
2929
};
3030

3131
[NoInterfaceObject]
3232
interface AIO {
33-
readonly attribute PinName name;
33+
readonly attribute PinName pin;
3434
readonly attribute unsigned long precision; // 10 or 12 bits
3535

3636
unsigned long read();
@@ -40,7 +40,7 @@ interface AIO {
4040
// GPIO
4141
interface GPIOObject {
4242
GPIO open((PinName or GPIOOptions) init);
43-
GPIO port((PinName or sequence<PinName>) port, optional GPIOOptions options);
43+
GPIO port((PinName or sequence<PinName>) port, optional GPIOOptions init);
4444
};
4545

4646
[NoInterfaceObject]
@@ -50,14 +50,13 @@ interface GPIO: {
5050
void close();
5151

5252
attribute EventHandler<unsigned long> ondata;
53-
5453
};
5554

5655
GPIO implements EventEmitter;
5756

5857
dictionary GPIOOptions {
59-
PinName name;
60-
PinMapping mapping = "os";
58+
PinName pin;
59+
PinMapping mapping = "system";
6160
GPIOMode mode = "out";
6261
boolean activeLow = false;
6362
GPIOEdge edge = "none";
@@ -74,8 +73,8 @@ interface PWMObject {
7473
};
7574

7675
dictionary PWMOptions {
77-
PinName name;
78-
PinMapping mapping = "os";
76+
PinName pin;
77+
PinMapping mapping = "system";
7978
boolean reversePolarity = false;
8079
double period;
8180
double pulseWidth;
@@ -84,7 +83,7 @@ dictionary PWMOptions {
8483

8584
[NoInterfaceObject]
8685
interface PWM {
87-
readonly attribute PinName name;
86+
readonly attribute PinName pin;
8887
readonly attribute boolean reversePolarity;
8988

9089
void write(PWMValue value);

0 commit comments

Comments
 (0)