Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f0785fe

Browse filesBrowse files
committed
move docs around
1 parent 81ec67a commit f0785fe
Copy full SHA for f0785fe

12 files changed

+47-85Lines changed: 47 additions & 85 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"label": "Drivers",
3+
"position": 13,
4+
"collapsible": true
5+
}
Collapse file

‎website/docs/api/drivers/index.mdx‎

Copy file name to clipboard
+12Lines changed: 12 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Drivers
2+
3+
The `@devicescript/drivers` module provides helper functions to mount service servers using I2C.
4+
5+
```ts
6+
import { startSHTC3 } from "@devicescript/drivers"
7+
8+
await startSHTC3()
9+
const t = new ds.Temperature()
10+
const h = new ds.Humidity()
11+
// ...
12+
```
Collapse file

‎website/docs/api/servers/index.md‎

Copy file name to clipboardExpand all lines: website/docs/api/servers/index.md
+3-4Lines changed: 3 additions & 4 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
The `@devicescript/servers` module provides helper functions to mount service servers on your low level hardware components. Basically, you have access to all the drivers available in the C server SDK.
44

55
```ts
6+
import { Button } from "@devicescript/core"
67
import { gpio } from "@devicescript/core"
78
import { startButton } from "@devicescript/servers"
89

9-
const buttonA = startButton({
10+
startButton({
1011
pin: gpio(2),
1112
})
13+
const buttonA = new ds.Button()
1214
```
13-
14-
The `start...` function starts a server and returns the client instance.
15-
The [service instance name](https://microsoft.github.io/jacdac-docs/services/_base/) is automatically set to the variable name. In this example, it is set to `buttonA`.
Collapse file

‎website/docs/developer/drivers/_category_.json‎

Copy file name to clipboardExpand all lines: website/docs/developer/drivers/_category_.json
-4Lines changed: 0 additions & 4 deletions
This file was deleted.
Collapse file

‎website/docs/developer/i2c.mdx‎

Copy file name to clipboardExpand all lines: website/docs/developer/i2c.mdx
-25Lines changed: 0 additions & 25 deletions
This file was deleted.
Collapse file

‎website/docs/developer/drivers/index.mdx‎ ‎…bsite/docs/developer/servers/drivers.mdx‎website/docs/developer/drivers/index.mdx renamed to website/docs/developer/servers/drivers.mdx website/docs/developer/drivers/index.mdx renamed to website/docs/developer/servers/drivers.mdx

Copy file name to clipboardExpand all lines: website/docs/developer/servers/drivers.mdx
+1-7Lines changed: 1 addition & 7 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ const h = new ds.Humidity()
1313
// ...
1414
```
1515

16-
### Builtin Drivers
17-
18-
- [AHT20](./drivers/aht20)
19-
- [SHT30](./driverse/sht30)
20-
- [SHTC3](./drivers/shtc3)
21-
2216
## Custom drivers
2317

24-
You can author and publish custom drivers using the [I2C service](./i2c) and [custom packages](./packages).
18+
You can author and publish custom drivers using the [I2C service](i2c) and [custom packages](/developer/packages).
Collapse file
+24-43Lines changed: 24 additions & 43 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,39 @@
11
---
22
title: I2C
3-
sidebar_position: 1
3+
sidebar_position: 50
44
---
55

66
# I2C
77

8-
The I2C class provides basic functions to work with I2C registers and perform raw communication over the I2C bus using DeviceScript.
9-
It is also possible to add I2C driver in the [C firmware SDK](https://github.com/microsoft/jacdac-c/tree/main/drivers).
8+
I2C [builtin package](/developer/builtin-packages) that exposes
9+
a [I2C service](/api/clients/i2c/) to interact with I2C devices.
1010

11-
## Setup
11+
Drivers [builtin package](/developer/builtin-packages) provides drivers for I2C peripherals.
1212

13-
Configure your project for testing using this command
13+
## Usage
1414

15-
```bash
16-
devs add i2c
17-
```
15+
```ts
16+
import { startSHTC3 } from "@devicescript/drivers"
1817

19-
## MMA8452Q accelerometer example
18+
await startSHTC3()
19+
const t = new ds.Temperature()
20+
const h = new ds.Humidity()
21+
// ...
22+
```
2023

21-
```ts
22-
// See https://www.nxp.com/docs/en/data-sheet/MMA8452Q.pdf for details
24+
- [I2C service](/api/clients/i2c/)
25+
- This service can be used directly or used to build [drivers](./drivers).
2326

24-
import * as devs from "@devicescript/core"
27+
```ts skip
2528
import { i2c } from "@devicescript/i2c"
2629

27-
console.log("start")
28-
29-
const addr = 0x1d
30-
const scale = 2
31-
32-
// convert signed 12-bit quantity from two I2C bytes into floating point
33-
function convert(high: number, low: number) {
34-
const raw = ((high << 24) | (low << 16)) >> 20
35-
return (raw / (1 << 11)) * scale
36-
}
37-
38-
// set up the device to be active
39-
async function init() {
40-
await i2c.writeReg(addr, 0x2a, 1) // CTRL_REG1 = 0x2a
41-
}
42-
43-
// get the X, Y, Z accelerometer values in a single call
44-
async function read() {
45-
const data = await i2c.readRegBuf(addr, 1, 6)
46-
const x = convert(data[0], data[1])
47-
const y = convert(data[2], data[3])
48-
const z = convert(data[4], data[5])
49-
return { x, y, z }
50-
}
51-
52-
await init()
53-
while (true) {
54-
const r = await read()
55-
console.data(r)
56-
await devs.sleep(500)
57-
}
30+
const address = 0x..
31+
const register = 0x..
32+
const value = 0x..
33+
34+
// highlight-next-line
35+
await i2c.writeReg(address, register, value)
36+
37+
// highlight-next-line
38+
const readValue = await i2c.readReg(address, register)
5839
```

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.