periph 1.3.1 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/examples/accelerometer/bma180/complete.js +83 -0
- package/examples/accelerometer/bma180/demo.js +47 -0
- package/examples/accelerometer/bma180/minimal.js +21 -0
- package/examples/accelerometer/fxos8700/complete.js +111 -0
- package/examples/accelerometer/fxos8700/demo.js +80 -0
- package/examples/accelerometer/fxos8700/minimal.js +20 -0
- package/examples/accelerometer/lis3dh/complete.js +123 -0
- package/examples/accelerometer/lis3dh/demo.js +99 -0
- package/examples/accelerometer/lis3dh/minimal.js +19 -0
- package/examples/accelerometer/lsm303/complete.js +82 -0
- package/examples/accelerometer/lsm303/demo.js +96 -0
- package/examples/accelerometer/lsm303/minimal.js +23 -0
- package/examples/accelerometer/mma8451q/complete.js +96 -0
- package/examples/accelerometer/mma8451q/demo.js +120 -0
- package/examples/accelerometer/mma8451q/minimal.js +20 -0
- package/examples/adc_dac/ad5243/complete.js +52 -0
- package/examples/adc_dac/ad5243/demo.js +50 -0
- package/examples/adc_dac/ad5243/minimal.js +23 -0
- package/examples/adc_dac/ad5248/complete.js +49 -0
- package/examples/adc_dac/ad5248/demo.js +42 -0
- package/examples/adc_dac/ad5248/minimal.js +21 -0
- package/examples/adc_dac/ads1013/complete.js +51 -0
- package/examples/adc_dac/ads1013/demo.js +51 -0
- package/examples/adc_dac/ads1013/minimal.js +21 -0
- package/examples/adc_dac/ads1014/complete.js +88 -0
- package/examples/adc_dac/ads1014/demo.js +52 -0
- package/examples/adc_dac/ads1014/minimal.js +21 -0
- package/examples/adc_dac/ads1113/complete.js +47 -0
- package/examples/adc_dac/ads1113/demo.js +39 -0
- package/examples/adc_dac/ads1113/minimal.js +20 -0
- package/examples/adc_dac/ads1114/complete.js +77 -0
- package/examples/adc_dac/ads1114/demo.js +47 -0
- package/examples/adc_dac/ads1114/minimal.js +20 -0
- package/examples/adc_dac/ads1115/complete.js +82 -0
- package/examples/adc_dac/ads1115/demo.js +55 -0
- package/examples/adc_dac/ads1115/minimal.js +20 -0
- package/examples/display/pcf8578/complete.js +58 -0
- package/examples/display/pcf8578/demo.js +62 -0
- package/examples/display/pcf8578/minimal.js +19 -0
- package/examples/display/pcf8579/complete.js +58 -0
- package/examples/display/pcf8579/demo.js +61 -0
- package/examples/display/pcf8579/minimal.js +19 -0
- package/examples/imu/icm20948/complete.js +114 -0
- package/examples/imu/icm20948/demo.js +79 -0
- package/examples/imu/icm20948/minimal.js +22 -0
- package/examples/io_expander/mcp23008/complete.js +70 -0
- package/examples/io_expander/mcp23008/demo.js +58 -0
- package/examples/io_expander/mcp23008/minimal.js +20 -0
- package/examples/memory/mb85rc/complete.js +40 -0
- package/examples/memory/mb85rc/demo.js +58 -0
- package/examples/memory/mb85rc/minimal.js +15 -0
- package/examples/motor/drv2605/complete.js +100 -0
- package/examples/motor/drv2605/demo.js +55 -0
- package/examples/motor/drv2605/minimal.js +24 -0
- package/package.json +1 -1
- package/src/chips/accelerometer/bma180.js +573 -0
- package/src/chips/accelerometer/fxos8700.js +1600 -0
- package/src/chips/accelerometer/lis3dh.js +1341 -0
- package/src/chips/accelerometer/lsm303.js +1471 -0
- package/src/chips/accelerometer/mma8451q.js +1406 -0
- package/src/chips/adc_dac/_ads111x_base.js +272 -0
- package/src/chips/adc_dac/ad5243.js +231 -0
- package/src/chips/adc_dac/ad5248.js +194 -0
- package/src/chips/adc_dac/ads1013.js +219 -0
- package/src/chips/adc_dac/ads1014.js +509 -0
- package/src/chips/adc_dac/ads1113.js +112 -0
- package/src/chips/adc_dac/ads1114.js +201 -0
- package/src/chips/adc_dac/ads1115.js +232 -0
- package/src/chips/display/pcf8578.js +452 -0
- package/src/chips/display/pcf8579.js +451 -0
- package/src/chips/imu/icm20948.js +849 -0
- package/src/chips/io_expander/mcp23008.js +558 -0
- package/src/chips/memory/mb85rc.js +166 -0
- package/src/chips/motor/drv2605.js +592 -0
- package/src/discovery/registry.js +20 -19
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const SIZE = 0x8000;
|
|
4
|
+
const DEVICE_ID_BASE = 0xA0;
|
|
5
|
+
|
|
6
|
+
function _checkAddress(address) {
|
|
7
|
+
if (!Number.isInteger(address) || address < 0 || address >= SIZE) {
|
|
8
|
+
throw new RangeError('address out of range 0-32767');
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function _checkRange(address, length) {
|
|
13
|
+
if (!Number.isInteger(address) || !Number.isInteger(length) ||
|
|
14
|
+
length < 0 || address < 0 || address + length > SIZE) {
|
|
15
|
+
throw new RangeError('range outside 0-32767');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* MB85RC256V 256 Kbit (32 KiB) I2C FRAM — minimal interface.
|
|
21
|
+
*
|
|
22
|
+
* Ferroelectric RAM: non-volatile like EEPROM, but every write completes at
|
|
23
|
+
* bus speed — no write cycle, no page buffer, no ACK polling, and at least
|
|
24
|
+
* 10^12 write cycles per byte. The chip has no configuration registers.
|
|
25
|
+
*
|
|
26
|
+
* Memory layout: 0x0000-0x7FFF, 15-bit address, big-endian on the wire.
|
|
27
|
+
*
|
|
28
|
+
* Writes are ignored by the chip while the WP pin is high (hardware only;
|
|
29
|
+
* the driver cannot detect it).
|
|
30
|
+
*/
|
|
31
|
+
class MB85RCMinimal {
|
|
32
|
+
/**
|
|
33
|
+
* @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection with regBytes=2, pointing at the device (address 0x50-0x57).
|
|
34
|
+
*/
|
|
35
|
+
constructor(connection) {
|
|
36
|
+
this._conn = connection;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Read a single byte (random read).
|
|
41
|
+
* @param {number} address - Memory address 0-32767.
|
|
42
|
+
* @returns {Promise<number>} Byte value 0-255.
|
|
43
|
+
* @throws {RangeError} If the address is outside 0-32767.
|
|
44
|
+
*/
|
|
45
|
+
async readByte(address) {
|
|
46
|
+
_checkAddress(address);
|
|
47
|
+
return (await this._conn.readReg(address, 1))[0];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Write a single byte (byte write); resolves when the transfer completes.
|
|
52
|
+
* @param {number} address - Memory address 0-32767.
|
|
53
|
+
* @param {number} value - Byte value 0-255.
|
|
54
|
+
* @returns {Promise<void>}
|
|
55
|
+
* @throws {RangeError} If the address is outside 0-32767.
|
|
56
|
+
*/
|
|
57
|
+
async writeByte(address, value) {
|
|
58
|
+
_checkAddress(address);
|
|
59
|
+
await this._conn.writeReg(address, value & 0xFF);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* MB85RC256V full interface — extends minimal with block access and Device ID.
|
|
65
|
+
*
|
|
66
|
+
* Ranges that would run past 0x7FFF are rejected instead of silently
|
|
67
|
+
* wrapping to 0x0000 as the hardware would do.
|
|
68
|
+
*/
|
|
69
|
+
class MB85RCFull extends MB85RCMinimal {
|
|
70
|
+
/**
|
|
71
|
+
* @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection with regBytes=2 (address 0x50-0x57).
|
|
72
|
+
*/
|
|
73
|
+
constructor(connection) {
|
|
74
|
+
super(connection);
|
|
75
|
+
this._maxChunk = 30;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Maximum data bytes per bus transaction (default 30; Arduino Wire limits transfers to 32 bytes including the 2 address bytes).
|
|
80
|
+
* @type {number}
|
|
81
|
+
*/
|
|
82
|
+
get maxChunk() { return this._maxChunk; }
|
|
83
|
+
|
|
84
|
+
set maxChunk(value) {
|
|
85
|
+
if (!Number.isInteger(value) || value < 1) throw new RangeError('maxChunk must be >= 1');
|
|
86
|
+
this._maxChunk = value;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Array size in bytes.
|
|
91
|
+
* @returns {number} 32768.
|
|
92
|
+
*/
|
|
93
|
+
size() { return SIZE; }
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Sequential read, split into transactions of at most maxChunk bytes.
|
|
97
|
+
* @param {number} address - Starting address 0-32767.
|
|
98
|
+
* @param {number} length - Number of bytes to read.
|
|
99
|
+
* @returns {Promise<Buffer>} `length` bytes.
|
|
100
|
+
* @throws {RangeError} If address..address+length is not inside 0x0000-0x7FFF.
|
|
101
|
+
*/
|
|
102
|
+
async read(address, length) {
|
|
103
|
+
_checkRange(address, length);
|
|
104
|
+
const parts = [];
|
|
105
|
+
while (length > 0) {
|
|
106
|
+
const n = Math.min(length, this._maxChunk);
|
|
107
|
+
parts.push(await this._conn.readReg(address, n));
|
|
108
|
+
address += n;
|
|
109
|
+
length -= n;
|
|
110
|
+
}
|
|
111
|
+
return Buffer.concat(parts);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Sequential write, split into transactions of at most maxChunk bytes; no delay between chunks.
|
|
116
|
+
* @param {number} address - Starting address 0-32767.
|
|
117
|
+
* @param {Buffer|number[]} data - Bytes to write.
|
|
118
|
+
* @returns {Promise<void>}
|
|
119
|
+
* @throws {RangeError} If address..address+data.length is not inside 0x0000-0x7FFF.
|
|
120
|
+
*/
|
|
121
|
+
async write(address, data) {
|
|
122
|
+
const buf = Buffer.from(data);
|
|
123
|
+
_checkRange(address, buf.length);
|
|
124
|
+
for (let off = 0; off < buf.length; off += this._maxChunk) {
|
|
125
|
+
const chunk = buf.subarray(off, off + this._maxChunk);
|
|
126
|
+
await this._conn.writeReg(address + off, chunk);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Write `value` over a range, in maxChunk-sized transactions.
|
|
132
|
+
* @param {number} address - Starting address 0-32767.
|
|
133
|
+
* @param {number} length - Number of bytes to fill.
|
|
134
|
+
* @param {number} [value=0] - Byte value 0-255.
|
|
135
|
+
* @returns {Promise<void>}
|
|
136
|
+
* @throws {RangeError} If address..address+length is not inside 0x0000-0x7FFF.
|
|
137
|
+
*/
|
|
138
|
+
async fill(address, length, value = 0) {
|
|
139
|
+
_checkRange(address, length);
|
|
140
|
+
while (length > 0) {
|
|
141
|
+
const n = Math.min(length, this._maxChunk);
|
|
142
|
+
await this._conn.writeReg(address, Buffer.alloc(n, value & 0xFF));
|
|
143
|
+
address += n;
|
|
144
|
+
length -= n;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Read the 3-byte Device ID via the reserved slave address 0x7C.
|
|
150
|
+
* Linux i2c-dev may refuse addresses 0x78-0x7F, in which case this rejects.
|
|
151
|
+
* @param {import('../../connection/register_connection').RegisterConnection} idConnection - regBytes=1 connection bound to I2C address 0x7C.
|
|
152
|
+
* @param {number} [address=0x50] - 7-bit address of the FRAM (0x50-0x57), used to build the device address word.
|
|
153
|
+
* @returns {Promise<{manufacturer: number, density: number, product: number}>} {0x00A, 0x5, 0x10} for the MB85RC256V.
|
|
154
|
+
*/
|
|
155
|
+
async readDeviceId(idConnection, address = 0x50) {
|
|
156
|
+
const word = DEVICE_ID_BASE + ((address & 0x07) << 1);
|
|
157
|
+
const raw = await idConnection.readReg(word, 3);
|
|
158
|
+
return {
|
|
159
|
+
manufacturer: (raw[0] << 4) | (raw[1] >> 4),
|
|
160
|
+
density: raw[1] & 0x0F,
|
|
161
|
+
product: raw[2],
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
module.exports = { MB85RCMinimal, MB85RCFull };
|