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

Commit 6d21e17

Browse files
t-harveygrgustaf
t-harvey
authored andcommitted
[docs] Update WebIDL and modify docs to fit new "node.js-like" style, Part 2 (#1893)
Reinserted WebIDL for buffer.md; changed the WebIDL in aio and ble to be syntactically correct and to follow the new style of buffer.md. Added a new file that explains some of the differences between WebIDL and Javascript. Signed-off-by: Timothy Harvey <[email protected]>
1 parent 3a701fb commit 6d21e17

25 files changed

+1537
-1473
lines changed

docs/Notes_on_WebIDL.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Notes on WebIDL for zephyr.js documentation:
2+
3+
The WebIDL fragments are for reference only; the description of the
4+
API should be considered correct -- please report discrepancies as
5+
soon as possible.
6+
7+
Although both WebIDL and JavaScript are aimed at web applications,
8+
numerous incompatibilities exist between the two. In general, we try
9+
to use basic (as opposed to "advanced") WebIDL to describe each
10+
API; below, we list some of our conventions.
11+
12+
We map WebIDL definitions to JavaScript objects as follows:
13+
14+
1. dictionaries -- these map to JavaScript objects that simply don't
15+
have methods attached to them.
16+
2. interfaces -- like definitions, these correspond to JavaScript
17+
objects, except that they may also include methods.
18+
3. callbacks -- these are type definitions for functions used as
19+
parameters or object fields.
20+
4. enumerations -- these are largely the same in both languages.
21+
22+
Unless a constructor is explicitly defined/denied (*e.g.*, see the
23+
note about "require", below), we assume the JavaScript model that the
24+
object can be constructed with "new" -- WebIDL specifies that the
25+
external attribute "constructor" be applied to a definition that can
26+
be new'd, but putting the attribute on every object would be
27+
cumbersome.
28+
29+
The node.js notion of "require" is subtly different from constructing
30+
an object with JavaScript's "new", but it has appealing semantics. We
31+
annotate WebIDL definitions that should be implemented with node.js's
32+
"require" semantics with the external attribute "ReturnFromRequire".
33+
34+
Similarly, many people's general model is one of separate compilation,
35+
which WebIDL does not support. WebIDL's model is to assume that all
36+
of the required files will be concatenated together and then compiled
37+
-- thus, one file can reference types that are found in another file,
38+
and there is no annotation to alert the reader that the definition of
39+
some type is to be found elsewhere. We use WebIDL attributes to
40+
specify and call attention to types that are defined in other files.

docs/aio.md

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ ZJS API for Analog I/O (AIO)
33

44
* [Introduction](#introduction)
55
* [Web IDL](#web-idl)
6-
* [API Documentation](#api-documentation)
6+
* [Class: AIO](#aio-api)
7+
* [aio.open(AIOInit)](#aioopenaioinit)
8+
* [Class: AIOPin](#aiopin-api)
9+
* [pin.read()](#pinread)
10+
* [pin.readAsync(ReadCallback)](#pinreadasyncreadcallback)
11+
* [pin.on(eventType, ReadCallback)](#pinoneventtype-readcallback)
12+
* [pin.close()](#pinclose)
713
* [Sample Apps](#sample-apps)
814

915
Introduction
@@ -23,84 +29,77 @@ not have support for this.
2329

2430
Web IDL
2531
-------
26-
This IDL provides an overview of the interface; see below for documentation of
27-
specific API functions.
2832

29-
```javascript
30-
// require returns an AIO object
31-
// var aio = require('aio');
33+
This IDL provides an overview of the interface; see below for
34+
documentation of specific API functions. We have a short document
35+
explaining [ZJS WebIDL conventions](Notes_on_WebIDL.md).
3236

33-
[NoInterfaceObject]
37+
<details>
38+
<summary>Click to show WebIDL</summary>
39+
<pre>
40+
// require returns an AIO object
41+
// var aio = require('aio');<p>[ReturnFromRequire]
3442
interface AIO {
3543
AIOPin open(AIOInit init);
36-
};
37-
38-
dictionary AIOInit {
39-
unsigned long pin;
40-
};
41-
42-
[NoInterfaceObject]
43-
interface AIOPin {
44+
};<p>dictionary AIOInit {
45+
(unsigned long or string) pin;
46+
};<p>interface AIOPin {
4447
unsigned long read();
4548
void readAsync(ReadCallback callback); // TODO: change to return a promise
4649
void on(string eventType, ReadCallback callback);
4750
void close();
48-
};
51+
};<p>callback ReadCallback = void (unsigned long value);
52+
</pre> </details>
4953

50-
callback ReadCallback = void (unsigned long value);
51-
```
52-
53-
API Documentation
54-
-----------------
55-
### AIO.open
56-
57-
`AIOPin open(AIOInit init);`
54+
AIO API
55+
-------
56+
### aio.open(init)
57+
* 'init' *AIOInit object* The AIOInit object has a single field called "pin"
58+
that represents the name of the pin (either an integer or a string,
59+
depending on the board).
60+
* Returns: an AIOPin object that may be used to read values from the pin.
5861

59-
The `init` object lets you set the pin number. You can either use a raw
62+
When setting the pin number, you can either use a raw
6063
number for your device or use the board support module such as
6164
[Arduino 101](./boards/arduino_101.md) or [K64F](./boards/frdm_k64f.md) to
6265
specify a named pin.
6366

64-
Use the AIOPin object returned to read values from the pin.
67+
AIOPin API
68+
----------
69+
### pin.read()
70+
* Returns: the latest reading from the pin (an unsigned integer). Blocks until it gets the result.
6571

66-
### AIOPin.read
72+
### pin.readAsync(callback)
73+
* 'callback' *ReadCallback* User-provided callback function that takes
74+
a single unsigned integer and has no return value.
6775

68-
`unsigned long read();`
69-
70-
Returns the latest reading from the pin. Blocks until it gets the result.
71-
72-
### AIOPin.readAsync
73-
74-
`void readAsync(ReadCallback callback);`
75-
76-
Pass a function for `callback` that will be called later when the result is
76+
Pass a function for `ReadCallback` that will be called later when the result is
7777
obtained.
7878

7979
*WARNING: Making an async call like this allocates some memory while the call
80-
is pending, so if you issue them faster than they are fulfilled, you will
80+
is pending; if async calls are issued faster than they are fulfilled,
81+
the system will
8182
eventually run out of memory - pretty soon on these small devices. So the best
82-
practice would be to make sure you only have a small, fixed number pending at
83+
practice would be to have only a small, fixed number pending at
8384
any given time.*
8485

8586
*NOTE: This function will probably be replaced with a version that instead
8687
returns a promise.*
8788

88-
### AIOPin.on
89-
90-
`void on(string eventType, ReadCallback callback);`
89+
### pin.on(eventType, callback)
90+
* 'eventType' *string* Type of event; currently, the only supported
91+
type is "change".
92+
* 'callback' *ReadCallback* User-provided callback function that takes
93+
a single, unsigned integer and has no return value; can be null.
9194

92-
Currently, the only supported `eventType` is 'change', and `callback` should
93-
be either a function or null. When a function is passed for the change event,
94-
the function will be called any time the analog voltage changes. (At the moment,
95+
The callback function is called any time the analog voltage changes. (At the moment,
9596
it actually gets called periodically even when it hasn't changed.) When null is
9697
passed for the change event, the previously registered callback will be
9798
discarded and no longer called.
9899

99-
### AIOPin.close
100-
101-
`void close();`
100+
### pin.close()
102101

103-
Closes the AIOPin. Once it is closed, all event handlers registered will no
102+
Closes the AIOPin. Once it is closed, all registered event handlers will no
104103
longer be called.
105104

106105
Sample Apps

0 commit comments

Comments
 (0)