Skip to content

Commit

Permalink
feat: document host provider class
Browse files Browse the repository at this point in the history
  • Loading branch information
HipsterBrown committed Aug 28, 2024
1 parent 688e558 commit eb27ec0
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 3 deletions.
123 changes: 121 additions & 2 deletions src/content/docs/api/host-provider.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,128 @@
---
title: Host Provider
description: TBD
description: The Host Provider instance aggregates data and code available to scripts from the host.

---

## TBD
The Host Provider instance aggregates data and code available to scripts from the host.

## Access

The Host Provider instance is a [singleton](https://en.wikipedia.org/wiki/Singleton_pattern) object that is created before hosted scripts are executed.

It may be imported:

```js
import device from "embedded:provider/builtin"
```

Or be made available as a [global object](https://developer.mozilla.org/en-US/docs/Glossary/Global_object) named `device`, if the host chooses to do so.

## Instance Properties

### `pin`

An object that maps pin names to [pin specifiers](/glossary/#pin-speficier). More than one pin name may map to the same [pin specifier](/glossary/#pin-speficier).

```js
console.log(device.pin.led); // logs the value for the on-board LED pin
console.log(device.pin.button); // logs the value for the on-board button pin
```

### `i2c`

[IO Bus type](/glossay/#io-bus) for [I<sup>2</sup>C](/api/io-class/i2c) communication

### `serial`

[IO Bus type](/glossay/#io-bus) for [Serial](/api/io-class/serial) communication

### `spi`

[IO Bus type](/glossay/#io-bus) for [SPI](/api/io-class/spi) communication

### `io`

Object of [IO constructors](/api/io-class/) available to the host environment, such as [`Digital`](/api/io-class/digital), [`I2C`](/api/io-class/i2c), and [`SPI`](/api/io-class/spi).

```js
console.log(device.io.Digital);
console.log(device.io.I2C);
console.log(device.io.SPI);
```

### `provider`

Object of [IO Provider constructors](/api/io-provider-class/) available to the host environment.

### `sensors`

Object of [Sensor constructors](/api/sensor-class/) available to the host environment.

### `displays`

Object of [Display constructors](/api/display-class/) available to the host environment.

### `rtc`

Object of default [Real-time clock constructor options](/api/real-time-clock-class) available to the host environment.

### `network`

Object of networking-related constructor options.

#### `dns.resolver`

Object of default [Domain Name Resolver constructor options](/api/dns-resolver-class).

#### `interface`

Object of default [Network Interface constructor options](/api/network-interface-class).

```js
console.log(device.network.interface.Ethernet0);
```

#### `ntp.client`

Object of default [NTP Client constructor options](/api/io-class/ntp-client-class).

#### `http.client`

Object of default [HTTP Client constructor options](/api/io-class/http-client-class).

#### `http.server`

Object of default [HTTP Server constructor options](/api/io-class/http-server-class).

#### `mqtt.client`

Object of default [MQTT Client constructor options](/api/io-class/mqtt-client-class).

#### `mqtts.client`

Object of default secure [MQTT Client constructor options](/api/io-class/mqtt-client-class).

#### `tls.client`

Object of default [TLS Client constructor options](/api/io-class/tls-client-socket).

#### `ws.client`

Object of default [WebSocket Client constructor options](/api/io-class/websocket-client-class).

#### `wss.client`

Object of default secure [WebSocket Client constructor options](/api/io-class/websocket-client-class).

## Examples

The following code is an example of establishing a [SPI](/api/io-class/spi) instance using the properties off the `device` Host Provider:

```js
let spi = new device.io.SPI(device.spi.default);
```

## Specifications

[Host Provider instance](https://419.ecma-international.org/#-26-host-provider-instance)
4 changes: 3 additions & 1 deletion src/content/docs/api/io-class/digital.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ An input peripheral with the default value as "pulled low", or 0, when nothing e

### `InputPullUpDown`

### 'Output'
An input peripheral with the default value as VCC/2, or half of the standard voltage (typically 3.3v).

### `Output`

The IO class accepts the [`write` method](#write) to set the configured pin in push-pull mode: low (0) or high (1).

Expand Down
32 changes: 32 additions & 0 deletions src/content/docs/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,38 @@ Provides the runtime environment for the execution of scripts, as defined by the

[Inter-Integrated Circuit](http://en.wikipedia.org/wiki/I%C2%B2C): a [controller/peripheral](https://learn.sparkfun.com/tutorials/i2c#controller-peripheral) communication protocol that allows one device to control one or more connected devices through two wires, a clock signal (SCL) to keep the components in sync and a data line (SDA).

## IO Bus

Object of two or more pins used to implement a communication protocol such as [Serial](/api/io-class/serial), [SPI](/api/io-class/spi), or [I<sup>2</sup>C](/api/io-class/i2c).

If there is more than one IO bus for a protocol, one may be designated as the `default` bus of that type.

```js
// example host implementation

const A = {
in: 12,
out: 13,
clock: 14,
select: 15,
hz: 10_000_000,
};

const B = {
in: 0,
out: 1,
clock: 2,
select: 3,
hz: 20_000_000,
};

device.spi = {
A,
B,
default: B,
};
```

## IP

[Internet Protocol](https://en.wikipedia.org/wiki/Internet_Protocol): the network layer communications protocol for sending data across networks to establish the Internet.
Expand Down

0 comments on commit eb27ec0

Please sign in to comment.