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 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.
12
+
Hardware pin names are usually marked on the circuit boards. However, operating systems, such as [Zephyr](https://www.zephyrproject.org/doc/) define a pin name mapping that is consistent across the boards supported by the OS. This API supports both board and OS defined namespaces. In this API, [`Pin`](#pin) names are opaque to the application. Applications can open a given pin with a pin name that is either a string or a number, in either board or OS namespace. Implementations encapsulate the pin mapping. Also, the API exposes board name, OS name (including OS version) and API version for all board APIs.
14
13
15
-
The supported board documentations are listed in [this directory](./):
14
+
The supported board namespaces are listed in [this directory](./):
16
15
-[arduino101.md](./arduino101.md)
17
16
-[frdm_k64f.md](./frdm_k64f.md).
18
17
19
-
The full Web IDL definition for Board and IO APIs can be found [here](./webidl.md).
18
+
For the supported OS pin namespace, consult the documentation of the implementation and its underlying OS documentation.
19
+
20
+
The full Web IDL definition for Board and IO APIs can be found in [webidl.md](./webidl.md).
20
21
21
22
The `Board` API object
22
23
----------------------
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.
24
+
The API entry point is a [`Board`](#board) object provided by an implementation (module).
25
+
When requiring `"board"`, the following steps are run:
26
+
- If there is no permission for using the functionality, throw `SecurityError`.
27
+
- If the [Board](#board) functionality is not supported on the board, throw `"NotSupportedError"`.
28
+
- Let `board` be the Board API object, and initialize it by fetching board name and OS name. Return `board`.
24
29
25
-
In the following example, the application requires an implementation that exposed Arduino 101 values and semantics for pins.
26
30
```javascript
27
31
var board =require("board");
28
32
29
-
console.log("Connected to board: "+board.name);
33
+
console.log("Connected to board: "+board.name+" running "+board.os);
30
34
```
31
35
32
-
On other platforms, e.g. in browsers, the API entry point can be exposed on another object, or constructed.
33
-
```javascript
34
-
var board =newBoard(); // provides an instance of the default board
35
-
```
36
-
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`.
38
-
39
-
<aname="pin"></a>
40
-
### The `Pin` interface
41
-
Represents a hardware pin on the board.
42
-
43
-
| Property | Type | Optional | Default value | Represents |
44
-
| --- | --- | --- | --- | --- |
45
-
|`pin`| String or Number | no |`undefined`| board name for the pin |
46
-
47
-
The read-only `pin` property is the board-specific name or numeric value of a pin, as defined in the board documentation.
48
-
49
-
In future versions of the API the `Pin` object may be extended.
36
+
If the functionality is not supported by the platform, `require` should throw `NotSupportedError`.
50
37
51
38
<aname="board"></a>
52
39
### The `Board` interface
53
-
Represents a hardware board.
40
+
Represents a hardware circuit board such as Arduino 101.
54
41
55
42
| Property | Type | Optional | Default value | Represents |
56
43
| --- | --- | --- | --- | --- |
57
-
|[`name`](#name)| String | no |`undefined`| board name |
58
-
|[`version`](#version)| String | no |`versions.board` in [`package.json`](../package.json)| API version |
59
-
60
-
| Method | Description |
61
-
| --- | --- |
62
-
|[`aio()`](#aio)| request an AIO object |
63
-
|[`gpio()`](#gpio)| request a GPIO object |
64
-
|[`pwm()`](#pwm)| request a PWM object |
65
-
|[`i2c()`](#i2c)| request an I2C object |
66
-
|[`spi()`](#spi)| request an SPI object |
67
-
|[`uart()`](#uart)| request an UART object |
44
+
|[`name`](#boardname)| String | no |`undefined`| board name |
45
+
|[`os`](#osname)| String | no |`undefined`| OS name |
46
+
|[`apiVersion`](#apiversion)| String | no |`versions.board` in [`package.json`](../package.json)| API version |
68
47
69
48
| Event name | Event callback argument |
70
49
| -------------- | ----------------------- |
71
50
|`error`|[`Error`](#error) object |
72
51
73
-
<aname="name"></a>
52
+
<aname="boardname"></a>
74
53
The `name` property is read-only, and provides the board name.
75
54
76
-
<aname="version"></a>
77
-
The `version` property is read-only, and provides the provides the Board API version, as specified in the `versions.board` property of [`package.json`](../package.json).
55
+
<aname="osname"></a>
56
+
The `os` property is read-only, and provides the underlying operating system name.
57
+
58
+
<aname="apiversion"></a>
59
+
The `apiVersion` property is read-only, and provides the provides the Board API version, as specified in the `versions.board` property of [`package.json`](../package.json).
78
60
79
61
<aname="error"></a>
80
62
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:
81
63
-`BoardDisconnectError`
82
64
-`BoardTimeoutError`
83
65
-`BoardIOError`.
84
-
85
-
#### `Board` methods
86
-
87
-
<aname="aio"></a>
88
-
##### The `aio()` method
89
-
Provides the AIO API object. The method runs the following steps:
90
-
- If the AIO functionality is not supported on the board, throw `"NotSupportedError"`.
91
-
- Initialize AIO functionality on the board. If it fails, throw `"SystemError"`.
92
-
- Let `aio` be the [AIO API object](./aio.md/#apiobject). Return `aio`.
93
-
94
-
<aname="gpio"></a>
95
-
##### The `gpio()` method
96
-
Provides the GPIO API object. The method runs the following steps:
97
-
- If the GPIO functionality is not supported on the board, throw `"NotSupportedError"`.
98
-
- Initialize GPIO functionality on the board. If it fails, throw `"SystemError"`.
99
-
- Let `gpio` be the [GPIO API object](./gpio.md/#apiobject). Return `gpio`.
100
-
101
-
<aname="pwm"></a>
102
-
##### The `pwm()` method
103
-
Provides the PWM API object. The method runs the following steps:
104
-
- If the PWM functionality is not supported on the board, throw `"NotSupportedError"`.
105
-
- Initialize PWM functionality on the board. If it fails, throw `"SystemError"`.
106
-
- Let `pwm` be the [PWM API object`](./pwm.md/#apiobject). Return `pwm`.
107
-
108
-
<aname="i2c"></a>
109
-
##### The `i2c()` method
110
-
Provides the I2C API object. The method runs the following steps:
111
-
- If the I2C functionality is not supported on the board, throw `"NotSupportedError"`.
112
-
- Initialize I2C functionality on the board. If it fails, throw `"SystemError"`.
113
-
- Let `i2c` be the [I2C API Object](./i2c.md/#apiobject). Return `pwm`.
114
-
115
-
<aname="spi"></a>
116
-
##### The `spi()` method
117
-
Provides the SPI API object. The method runs the following steps:
118
-
- If the SPI functionality is not supported on the board, throw `"NotSupportedError"`.
119
-
- Initialize SPI functionality on the board. If it fails, throw `"SystemError"`.
120
-
- Let `spi` be the [SPI API object](./spi.md/#apiobject). Return `spi`.
121
-
122
-
<aname="uart"></a>
123
-
##### The `uart()` method
124
-
Provides the UART API object. The method runs the following steps:
125
-
- If the UART functionality is not supported on the board, throw `"NotSupportedError"`.
126
-
- Initialize UART functionality on the board. If it fails, throw `"SystemError"`.
127
-
- Let `uart` be the [UART API object](./uart.md/#apiobject) object. Return `uart`.
Copy file name to clipboardExpand all lines: board/aio.md
+22-16
Original file line number
Diff line number
Diff line change
@@ -3,39 +3,44 @@ AIO API
3
3
4
4
The AIO API supports reading analog input pins that measure the analog voltage signal between 0 and a maximum voltage (usually 3.3 or 5 Volts), then do Analog-to-Digital Conversion (ADC) with a resolution of 10 or 12 bits on most boards, so that the result (pin value) is 0 to 1023 or 0 to 4095, inclusively.
5
5
6
-
On some boards access to AIO may be asynchronous. This API uses synchronous methods.
6
+
On some boards access to AIO may be asynchronous. This API uses synchronous methods for allowing lean implementations.
7
7
8
8
<aname="apiobject"></a>
9
9
### The AIO API object
10
-
AIO functionality is exposed by an object that can be obtained by using the [`aio()`](./README.md/#aio) method of the [`Board` API](./README.md/#board). See also the [Web IDL](./webidl.md). The API object exposes the following method:
10
+
When requiring `"aio"`, the following steps are run:
11
+
- If there is no permission for using the functionality, throw `SecurityError`.
12
+
- If the AIO functionality is not supported on the board, throw `"NotSupportedError"`.
13
+
- Return an object that implements the following method.
11
14
12
15
| Method | Description |
13
16
| --- | --- |
14
-
|[`open()`](#open)| synchronous open |
17
+
|[`open()`](#open)| open an AIO pin |
18
+
19
+
See also the [Web IDL](./webidl.md) definition.
15
20
16
21
<aname="open"></a>
17
22
#### The `AIO open(options)` method
18
23
Configures an AIO pin using data provided by the `options` argument. It involves the following steps:
19
24
- If `options` is a string, create a dictionary 'init' and use the value of `options` to initialize the `init.pin` property.
20
-
- Otherwise if `options` is a number, create a dictionary 'init' and use the value of `options` to initialize the `init.pin` property.
21
-
- 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:
22
-
*`pin` for board pin name with the valid values defined by the board, or for the numeric index of the analog pin;
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"`).
23
29
*`precision` for the bit width of a sample (if the board supports setting the sampling rate).
24
-
- If any property of `init` is specified and has an invalid value on the given board, as defined by the board documentation, throw `TypeError`.
25
-
- Request the underlying platform to initialize AIO on `init.pin` (if defined) or otherwise `init.channel`.
26
-
- In case of failure, throw `InvalidAccessError`.
27
-
- Let `aio` be the `AIOPin`](#aiopin) object that represents the hardware pin identified by `init.pin`, as defined by the board documentation.
28
-
- If `init.precision` is defined, request the board to set the precision and initialize the `aio.precision` property with the value supported by the board. If there is an error, throw `InvalidAccessError`.
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`.
32
+
- Let `aio` be the `AIOPin`](#aiopin) object that represents the hardware pin identified by `init.name`.
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`.
29
34
- Initialize the `aio.value` property with `undefined`.
30
35
- Return the `aio` object.
31
36
32
37
<aname="aio"></a>
33
38
### The `AIO` interface
34
-
The `AIO` object extends the [`Pin`](./README.md/#pin) object.
35
39
36
40
| Property | Type | Optional | Default value | Represents |
37
41
| --- | --- | --- | --- | --- |
38
-
|`pin`| String or Number | no |`undefined`| board name for the pin |
42
+
|`name`| String or Number | no |`undefined`| pin name |
43
+
|`mapping`| enum | no |`"os"`| pin mapping, `"os"` or `"board"`|
39
44
|`precision`| unsigned long | yes |`undefined`| bit length of digital sample |
40
45
41
46
| Method | Description |
@@ -58,13 +63,14 @@ Called when the application is no longer interested in the pin. Until the next [
58
63
### Examples
59
64
```javascript
60
65
try {
61
-
var aio =require("board").aio(); // initialize AIO on the board
66
+
var aio =require("aio"); // initialize AIO on the board
Copy file name to clipboardExpand all lines: board/arduino101.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
Board Support for Arduino 101
2
2
=============================
3
3
4
-
This document defines the pin values that are accepted by implementations.
4
+
This document defines the pin values that are accepted by implementations on board namespace.
5
5
6
6
The board labels are described in the [Arduino 101](https://www.arduino.cc/en/Main/ArduinoBoard101) board documentation. Also, for each board pin, the supported modes of each pin is described.
0 commit comments