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

Commit 0724928

Browse files
authored
Merge pull request #30 from zolkis/master
API spec fixes
2 parents a351649 + 1526512 commit 0724928

File tree

18 files changed

+1135
-1219
lines changed

18 files changed

+1135
-1219
lines changed

api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Examples:
7777
```
7878
var error = new SecurityError("No permissions");
7979
80-
if (SecurityError instanceof Error) { // true
80+
if ((error instanceof Error) && (error instanceof SecurityError)) { // true
8181
console.log(error.name); // "SecurityError"
8282
console.log(error.message); // "No permissions"
8383
}

api/ble/README.md

Lines changed: 89 additions & 77 deletions
Large diffs are not rendered by default.

api/board/README.md

Lines changed: 57 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
Board API
22
=========
33

4-
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:
65
- [AIO - Analog I/O](./aio.md)
6+
- [GPIO - General Purpose I/O](./gpio.md)
77
- [PWM - Pulse Width Modulation](./pwm.md)
88
- [I2C - Inter-Integrated Circuit](./i2c.md)
99
- [SPI - Serial Peripheral Interface](./spi.md)
1010
- [UART - Universal Asynchronous Receiver/Transmitter](./uart.md).
1111

12-
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).
1318

1419
The full Web IDL definition for Board and IO APIs can be found [here](./webidl.md).
1520

16-
The API object
17-
--------------
21+
The `Board` API object
22+
----------------------
1823
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.
1924

2025
In the following example, the application requires an implementation that exposed Arduino 101 values and semantics for pins.
2126
```javascript
22-
var board = require("iot-js-board-arduino101"); // example package name
27+
var board = require("board");
2328

24-
console.log("Connected to board " + board.name);
29+
console.log("Connected to board: " + board.name);
2530
```
2631

2732
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
3136

3237
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`.
3338

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-
3839
<a name="pin"></a>
3940
### The `Pin` interface
4041
Represents a hardware pin on the board.
4142

4243
| Property | Type | Optional | Default value | Represents |
4344
| --- | --- | --- | --- | --- |
4445
| `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.
5146

52-
The `pin` property is the board-specific name of a pin defined 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.
5348

54-
The `address` property is the operating-system-specific representation for that pin, usually a number.
55-
56-
<a name="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.
6650

6751
<a name="board"></a>
6852
### The `Board` interface
69-
Represents a hardware board. It contains an event handler for errors, and API methods.
53+
Represents a hardware board.
7054

7155
| Property | Type | Optional | Default value | Represents |
72-
| --- | --- | --- | --- | --- |
56+
| --- | --- | --- | --- | --- |
7357
| [`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-
<a name="name"></a>
85-
The `name` property is read-only, and provides the board name.
8658

87-
#### `Board` events
88-
The `Board` object supports the following events:
59+
| Method signature | Description |
60+
| --- | --- |
61+
| [`aio()`](#aio) | request an AIO object |
62+
| [`gpio()`](#gpio) | request a GPIO object |
63+
| [`pwm()`](#pwm) | request a PWM object |
64+
| [`i2c()`](#i2c) | request an I2C object |
65+
| [`spi()`](#spi) | request an SPI object |
66+
| [`uart()`](#uart) | request an UART object |
8967

9068
| Event name | Event callback argument |
9169
| -------------- | ----------------------- |
92-
| *error* | [`Error`](https://nodejs.org/api/errors.html#errors_class_error) object |
70+
| `error` | [`Error`](#error) object |
9371

94-
<a name="onerror"></a>
72+
<a name="name"></a>
73+
The `name` property is read-only, and provides the board name.
74+
75+
<a name="error"></a>
9576
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:
9677
- `BoardDisconnectError`
9778
- `BoardTimeoutError`
9879
- `BoardIOError`.
9980

10081
#### `Board` methods
101-
In all the descriptions of `Board` methods, `board` denotes a reference to this `Board` object.
10282

103-
<a name="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-
<a name="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+
<a name="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.
11091

11192
<a name="gpio"></a>
11293
##### 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-
<a name="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.
122100

123101
<a name="pwm"></a>
124102
##### 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.
128109

129110
<a name="i2c"></a>
130111
##### The `i2c(options)` method
131112
Configures I2C communication. The method runs the following steps:
132-
- Let `board` be the object representing this board.
133113
- Return a [`Promise`](../README.md/#promise) object `promise` and continue [in parallel](https://html.spec.whatwg.org/#in-parallel).
134114
- 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.
138118

139119
<a name="spi"></a>
140120
##### The `spi(options)` method
141121
Configures SPI communication.
142122
The method runs the following steps:
143123
- Return a [`Promise`](../README.md/#promise) object `promise` and continue [in parallel](https://html.spec.whatwg.org/#in-parallel).
144124
- 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.
149128

150129
<a name="uart"></a>
151130
##### The `uart(options)` method
152131
Configures UART communication. It takes a dictionary object as argument.
153132
The method runs the following steps:
154133
- Return a [`Promise`](../README.md/#promise) object `promise` and continue [in parallel](https://html.spec.whatwg.org/#in-parallel).
155134
- If the UART functionality is not supported, reject `promise` with `"NotSupportedError"`.
156-
- Let `board` be the object representing this board.
157135
- 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.
137+
- Resolve `promise` with the `uart` object.

0 commit comments

Comments
 (0)