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.
This API provides low level interfaces for I/O operations supported by the board and defines pin mappings between board pin names and pin values mapped by the OS.
5
-
-[GPIO - General Purpose I/O](./gpio.md)
4
+
The [Board](#board) API provides low level interfaces for I/O operations:
This API uses board pin names as defined by implementations in the [`Board.pins()`](#getpins) and the [`Board.pin()`](#getpin) methods. Implementations SHOULD list pin names, pin addresses, supported modes, and other capabilities or constraints on how the pins can be configured.
12
+
This API uses board pin names as defined in the corresponding board documentation.
13
+
The names, values and semantics related to hardware pins are owned and encapsulated by the implementation. This API uses opaque values (strings and numbers) for [`Pin`](#pin) names.
14
+
15
+
The supported board documentations are listed in [this directory](./):
16
+
-[arduino101.md](./arduino101.md)
17
+
-[frdm_k64f.md](./frdm_k64f.md).
13
18
14
19
The full Web IDL definition for Board and IO APIs can be found [here](./webidl.md).
15
20
16
-
The API object
17
-
--------------
21
+
The `Board`API object
22
+
----------------------
18
23
The API entry point is a [`Board`](./#board) object that is exposed in a platform-specific manner. As an example, on Node.js it can be obtained by requiring the package that implements this API.
19
24
20
25
In the following example, the application requires an implementation that exposed Arduino 101 values and semantics for pins.
21
26
```javascript
22
-
var board =require("iot-js-board-arduino101");// example package name
27
+
var board =require("board");
23
28
24
-
console.log("Connected to board "+board.name);
29
+
console.log("Connected to board:"+board.name);
25
30
```
26
31
27
32
On other platforms, e.g. in browsers, the API entry point can be exposed on another object, or constructed.
@@ -31,129 +36,102 @@ var board = new Board(); // provides an instance of the default board
31
36
32
37
If the functionality is not supported by the platform, `require` should throw `NotSupportedError`. If there is no permission for using the functionality, `require` should throw `SecurityError`.
33
38
34
-
The names, values and semantics related to hardware pins are owned by the implementation. This API uses opaque values for names. For instance, when requiring `"iot-js-board-arduino101"` the semantics will be board-specific, i.e. developers could expect using the same labels as the ones printed on the board.
35
-
36
-
In a different use case OS-specific mappings would need to be used for pins. For instance, when requiring `"iot-js-zephyr"`, the semantics will be defined by the mapping used in [Zephyr OS](https://wiki.zephyrproject.org/view/Arduino_/_Genuino_101#Arduino_101_Pinout) to abstract various supported boards.
37
-
38
39
<aname="pin"></a>
39
40
### The `Pin` interface
40
41
Represents a hardware pin on the board.
41
42
42
43
| Property | Type | Optional | Default value | Represents |
43
44
| --- | --- | --- | --- | --- |
44
45
|`pin`| String or Number | no |`undefined`| board name for the pin |
45
-
|`address`| Number | no |`undefined`| pin value defined by the OS |
46
-
|`value`| Number or object | no |`undefined`| value of the pin (synchronous read)|
47
-
|`mode`| String | no |`undefined`| I/O mode |
48
-
|`supportedModes`| array of String | no |`undefined`| pin value defined by the OS |
49
-
50
-
All properties are read-only.
51
46
52
-
The `pin` property is the board-specific name of a pindefined in the pin mapping of the board.
47
+
The read-only `pin` property is the board-specific name or numeric value of a pin, as defined in the board documentation.
53
48
54
-
The `address` property is the operating-system-specific representation for that pin, usually a number.
55
-
56
-
<aname="pinmode">
57
-
The `mode` property can take the following values:
58
-
-`"input"` for digital input (GPIO). The pin value can be 0 or 1.
59
-
-`"output"` for digital output (GPIO). The pin value can be 0 or 1.
60
-
-`"analog"` for analog input (AIO) that is converted to digital value.
61
-
-`"pwm"` for PWM analog output.
62
-
63
-
The `supportedModes` property is an array of modes the board supports for the given pin. Implementations are not required to implement this property, in which case its value should be `undefined`.
64
-
65
-
The `value` property is the raw value of a pin with no further interpretation (i.e. if the pin is a digital output active on low, then `1` represents inactive state).
49
+
In future versions of the API the `Pin` object may be extended.
66
50
67
51
<aname="board"></a>
68
52
### The `Board` interface
69
-
Represents a hardware board. It contains an event handler for errors, and API methods.
53
+
Represents a hardware board.
70
54
71
55
| Property | Type | Optional | Default value | Represents |
72
-
| --- | --- | --- | --- | --- |
56
+
| --- | --- | --- | --- | --- |
73
57
|[`name`](#name)| String | no |`undefined`| board name |
74
-
|[`onerror`](#onerror)| event | no |`undefined`| event for errors |
75
-
|[`pin()`](#getpin)| function | no | defined by implementation | get a Pin object |
76
-
|[`pins()`](#getpins)| function | no | defined by implementation | get an array of board pin names |
77
-
|[`aio()`](#aio)| function | no | defined by implementation | get an AIO object |
78
-
|[`gpio()`](#gpio)| function | no | defined by implementation | get a GPIO object |
79
-
|[`pwm()`](#pwm)| function | no | defined by implementation | get a PWM object |
80
-
|[`i2c()`](#i2c)| function | no | defined by implementation | request an I2C object |
81
-
|[`spi()`](#spi)| function | no | defined by implementation | request an SPI object |
82
-
|[`uart()`](#uart)| function | no | defined by implementation | request an UART object |
83
-
84
-
<aname="name"></a>
85
-
The `name` property is read-only, and provides the board name.
The `name` property is read-only, and provides the board name.
74
+
75
+
<aname="error"></a>
95
76
Board errors are represented as augmented [`Error`](https://nodejs.org/api/errors.html#errors_class_error) objects. The following [`Error` names](https://nodejs.org/api/errors.html) are used for signaling issues:
96
77
-`BoardDisconnectError`
97
78
-`BoardTimeoutError`
98
79
-`BoardIOError`.
99
80
100
81
#### `Board` methods
101
-
In all the descriptions of `Board` methods, `board` denotes a reference to this `Board` object.
102
82
103
-
<aname="getpin"></a>
104
-
##### The `pin(name)` method
105
-
Returns a [`Pin`](#pin) object associated with the pin name given in the `name` argument. The `name` argument can be a number or a string, as defined in the board pin mapping definition. The returned object describes the current state of the pin.
106
-
107
-
<aname="getpins"></a>
108
-
##### The `pins()` method
109
-
Returns an array of strings containing the board pin names supported by the board that can be used in the [`pin()`](#getpin) method.
83
+
<aname="aio"></a>
84
+
##### The `aio(options)` method
85
+
Configures an AIO pin. The method runs the following steps:
86
+
- Return a [`Promise`](../README.md/#promise) object `promise` and continue [in parallel](https://html.spec.whatwg.org/#in-parallel).
87
+
- If the AIO functionality is not supported, reject `promise` with `"NotSupportedError"`.
88
+
- Run the internal [`AIO initialization`](./aio.md/#init) algorithm with `options` as argument and let `aio` be the returned result.
89
+
- If it throws an error, reject promise with that error.
90
+
- Resolve `promise` with the `aio` object.
110
91
111
92
<aname="gpio"></a>
112
93
##### The `gpio(options)` method
113
-
Returns a [`GPIO`](./gpio.md/#gpio) object associated with the pin name or pin options given in the `options` argument. It runs the following steps:
114
-
- Let `board` be the object representing this board.
115
-
- Run the internal [`GPIO initialization`](./gpio.md/#init) algorithm with `options` and `board` as arguments, and return its result. Rethrow any errors that occur.
116
-
117
-
<aname="aio"></a>
118
-
##### The `aio(options)` method
119
-
Returns an [`AIO`](./aio.md/#aio) object associated with the pin name or pin options given in the `name` argument. It runs the following steps:
120
-
- Let `board` be the object representing this board.
121
-
- Run the internal [`AIO initialization`](./aio.md/#init) algorithm with `options` and `board` as arguments and return its result. Rethrow any errors that occur.
94
+
Configures a GPIO pin or GPIO port. The method runs the following steps:
95
+
- Return a [`Promise`](../README.md/#promise) object `promise` and continue [in parallel](https://html.spec.whatwg.org/#in-parallel).
96
+
- If the GPIO functionality is not supported, reject `promise` with `"NotSupportedError"`.
97
+
- Run the internal [`GPIO initialization`](./gpio.md/#init) algorithm with `options` as argument and let `gpio` be the returned result.
98
+
- If it throws an error, reject promise with that error.
99
+
- Resolve `promise` with the `gpio` object.
122
100
123
101
<aname="pwm"></a>
124
102
##### The `pwm(options)` method
125
-
Returns a [`PWM`](./pwm.md/#pwm) object associated with the pin name or pin options given in the [`options`](./pwm.md/#pwmoptions) argument. It runs the following steps:
126
-
- Let `board` be the object representing this board.
127
-
- Run the internal [`PWM initialization`](./pwm.md/#init) algorithm with `options` and `board` as arguments and return its result. Rethrow any errors that occur.
103
+
Configures a PWM pin. The method runs the following steps:
104
+
- Return a [`Promise`](../README.md/#promise) object `promise` and continue [in parallel](https://html.spec.whatwg.org/#in-parallel).
105
+
- If the PWM functionality is not supported, reject `promise` with `"NotSupportedError"`.
106
+
- Run the internal [`PWM initialization`](./pwm.md/#init) algorithm with `options` as argument and let `pwm` be the returned result.
107
+
- If it throws an error, reject promise with that error.
108
+
- Resolve `promise` with the `pwm` object.
128
109
129
110
<aname="i2c"></a>
130
111
##### The `i2c(options)` method
131
112
Configures I2C communication. The method runs the following steps:
132
-
- Let `board` be the object representing this board.
133
113
- Return a [`Promise`](../README.md/#promise) object `promise` and continue [in parallel](https://html.spec.whatwg.org/#in-parallel).
134
114
- If the I2C functionality is not supported, reject `promise` with `"NotSupportedError"`.
135
-
- Run the internal [`I2C initialization`](./i2c.md/#init) algorithm with `options`and `board`as arguments and let `i2c` be the returned result.
136
-
- If `i2c` is not `null`, resolve `promise` with the `i2c` object.
137
-
-Otherwise reject `promise`.
115
+
- Run the internal [`I2C initialization`](./i2c.md/#init) algorithm with `options` as argument and let `i2c` be the returned result.
116
+
- If it throws an error, reject promise with that error.
117
+
-Resolve `promise` with the `i2c` object.
138
118
139
119
<aname="spi"></a>
140
120
##### The `spi(options)` method
141
121
Configures SPI communication.
142
122
The method runs the following steps:
143
123
- Return a [`Promise`](../README.md/#promise) object `promise` and continue [in parallel](https://html.spec.whatwg.org/#in-parallel).
144
124
- If the SPI functionality is not supported, reject `promise` with `"NotSupportedError"`.
145
-
- Let `board` be the object representing this board.
146
-
- Run the [`SPI init`](./spi.md/#init) steps with `options` and `board` as arguments and let `spi` be the returned result.
147
-
- If `spi` is not `null`, resolve `promise` with the `spi` object.
148
-
- Otherwise reject `promise`.
125
+
- Run the [`SPI init`](./spi.md/#init) steps with `options` as argument and let `spi` be the returned result.
126
+
- If it throws an error, reject promise with that error.
127
+
- Resolve `promise` with the `spi` object.
149
128
150
129
<aname="uart"></a>
151
130
##### The `uart(options)` method
152
131
Configures UART communication. It takes a dictionary object as argument.
153
132
The method runs the following steps:
154
133
- Return a [`Promise`](../README.md/#promise) object `promise` and continue [in parallel](https://html.spec.whatwg.org/#in-parallel).
155
134
- If the UART functionality is not supported, reject `promise` with `"NotSupportedError"`.
156
-
- Let `board` be the object representing this board.
157
135
- Run the [`UART init`](./uart.md/#init) steps with `options` as argument and let `uart` be the returned result.
158
-
- If `uart` is not `null`, resolve `promise` with the `uart` object.
159
-
-Otherwise reject `promise`.
136
+
- If it throws an error, reject promise with that error.
0 commit comments