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,219 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { toSigned } = require('../../connection/register');
|
|
4
|
+
|
|
5
|
+
const _REG_CONVERSION = 0x00;
|
|
6
|
+
const _REG_CONFIG = 0x01;
|
|
7
|
+
|
|
8
|
+
const _CONFIG_RESET = 0x8583;
|
|
9
|
+
|
|
10
|
+
const _OS = 0x8000;
|
|
11
|
+
const _MODE_SINGLE = 0x0100;
|
|
12
|
+
// Reserved bits written at their reset values: 000010 in 14:9, 00011 in 4:0.
|
|
13
|
+
const _RESERVED = 0x0403;
|
|
14
|
+
|
|
15
|
+
const _SPS = [128, 250, 490, 920, 1600, 2400, 3300];
|
|
16
|
+
const _LSB = 0.001;
|
|
17
|
+
|
|
18
|
+
function _sleep(ms) {
|
|
19
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* ADS1013 12-bit I²C ADC with a fixed ±2.048 V range (Texas Instruments) —
|
|
24
|
+
* minimal interface.
|
|
25
|
+
*
|
|
26
|
+
* Smallest member of the ADS101x family: one input (AIN0 − AIN1), no PGA,
|
|
27
|
+
* no multiplexer, no comparator, no ALERT/RDY pin. Registers are 16-bit,
|
|
28
|
+
* big-endian, addressed through a persistent Address Pointer. Four
|
|
29
|
+
* selectable addresses (0x48–0x4B) via the ADDR strap. The chip has no ID
|
|
30
|
+
* register, so construction performs no I²C traffic.
|
|
31
|
+
*
|
|
32
|
+
* Defaults: 1600 SPS, single-shot. The whole Config word is written for
|
|
33
|
+
* every conversion.
|
|
34
|
+
*/
|
|
35
|
+
class ADS1013Minimal {
|
|
36
|
+
/**
|
|
37
|
+
* @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection (0x48–0x4B).
|
|
38
|
+
*/
|
|
39
|
+
constructor(connection) {
|
|
40
|
+
this._conn = connection;
|
|
41
|
+
this._dr = 4;
|
|
42
|
+
this._continuous = false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async _readReg(reg) {
|
|
46
|
+
const buf = await this._conn.readReg(reg & 0xFF, 2);
|
|
47
|
+
return buf.readUInt16BE(0);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async _writeReg(reg, value) {
|
|
51
|
+
await this._conn.writeReg(reg & 0xFF, Buffer.from([(value >> 8) & 0xFF, value & 0xFF]));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
_configWord(osBit, continuous) {
|
|
55
|
+
let word = _RESERVED | (this._dr << 5);
|
|
56
|
+
if (osBit) word |= _OS;
|
|
57
|
+
if (!continuous) word |= _MODE_SINGLE;
|
|
58
|
+
return word;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async _readConversion() {
|
|
62
|
+
return toSigned(await this._readReg(_REG_CONVERSION), 16) >> 4;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Run one single-shot conversion of AIN0 − AIN1. Writes the whole Config
|
|
67
|
+
* word with OS = 1, polls OS until the chip is idle again, then reads
|
|
68
|
+
* CONVERSION.
|
|
69
|
+
* @returns {Promise<number>} 12-bit two's-complement code, −2048…2047.
|
|
70
|
+
*/
|
|
71
|
+
async readRaw() {
|
|
72
|
+
await this._writeReg(_REG_CONFIG, this._configWord(true, false));
|
|
73
|
+
this._continuous = false;
|
|
74
|
+
for (let i = 0; i < 100; i++) {
|
|
75
|
+
if ((await this._readReg(_REG_CONFIG)) & _OS) break;
|
|
76
|
+
await _sleep(1);
|
|
77
|
+
}
|
|
78
|
+
return this._readConversion();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Run one single-shot conversion and convert it to volts.
|
|
83
|
+
* @returns {Promise<number>} Voltage AIN0 − AIN1 in volts (raw × 0.001).
|
|
84
|
+
*/
|
|
85
|
+
async readVoltage() {
|
|
86
|
+
return (await this.readRaw()) * _LSB;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* ADS1013 full interface — extends Minimal with data-rate selection and
|
|
92
|
+
* continuous conversion.
|
|
93
|
+
*/
|
|
94
|
+
class ADS1013Full extends ADS1013Minimal {
|
|
95
|
+
async _writeConfig() {
|
|
96
|
+
await this._writeReg(_REG_CONFIG, this._configWord(false, this._continuous));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Fixed full-scale range.
|
|
101
|
+
* @returns {number} Always 2.048 (volts).
|
|
102
|
+
*/
|
|
103
|
+
fullScale() {
|
|
104
|
+
return 2.048;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Size of one conversion code.
|
|
109
|
+
* @returns {number} Always 0.001 (volts).
|
|
110
|
+
*/
|
|
111
|
+
lsb() {
|
|
112
|
+
return _LSB;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Select the conversion data rate.
|
|
117
|
+
* @param {number} dr - DR_128 (0) … DR_3300 (6).
|
|
118
|
+
* @returns {Promise<void>}
|
|
119
|
+
* @throws {RangeError} If dr is outside 0–6 (7 aliases 3300 SPS).
|
|
120
|
+
*/
|
|
121
|
+
async setDataRate(dr) {
|
|
122
|
+
if (!Number.isInteger(dr) || dr < 0 || dr > 6) throw new RangeError('dr must be 0-6');
|
|
123
|
+
this._dr = dr;
|
|
124
|
+
if (this._continuous) await this._writeConfig();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Read the configured data-rate code.
|
|
129
|
+
* @returns {number} DR code 0–6.
|
|
130
|
+
*/
|
|
131
|
+
getDataRate() {
|
|
132
|
+
return this._dr;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Current data rate.
|
|
137
|
+
* @returns {number} 128, 250, 490, 920, 1600, 2400 or 3300 samples per second.
|
|
138
|
+
*/
|
|
139
|
+
dataRateSps() {
|
|
140
|
+
return _SPS[this._dr];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Start continuous conversion (MODE = 0) at the current data rate.
|
|
145
|
+
* @returns {Promise<void>}
|
|
146
|
+
*/
|
|
147
|
+
async startContinuous() {
|
|
148
|
+
this._continuous = true;
|
|
149
|
+
await this._writeConfig();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Read the most recent completed result without touching Config (valid
|
|
154
|
+
* at least 1/DR after startContinuous()).
|
|
155
|
+
* @returns {Promise<number>} 12-bit two's-complement code, −2048…2047.
|
|
156
|
+
*/
|
|
157
|
+
async readContinuousRaw() {
|
|
158
|
+
return this._readConversion();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Read the most recent completed result in volts.
|
|
163
|
+
* @returns {Promise<number>} readContinuousRaw() × lsb().
|
|
164
|
+
*/
|
|
165
|
+
async readContinuous() {
|
|
166
|
+
return (await this._readConversion()) * _LSB;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Stop continuous conversion (MODE = 1, single-shot / power-down).
|
|
171
|
+
* @returns {Promise<void>}
|
|
172
|
+
*/
|
|
173
|
+
async stopContinuous() {
|
|
174
|
+
this._continuous = false;
|
|
175
|
+
await this._writeConfig();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Report whether a single-shot conversion is running (OS = 0; only
|
|
180
|
+
* meaningful in single-shot mode).
|
|
181
|
+
* @returns {Promise<boolean>} True while converting.
|
|
182
|
+
*/
|
|
183
|
+
async isConverting() {
|
|
184
|
+
return ((await this._readReg(_REG_CONFIG)) & _OS) === 0;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Read the raw CONFIG register.
|
|
189
|
+
* @returns {Promise<number>} 16-bit CONFIG value.
|
|
190
|
+
*/
|
|
191
|
+
async readConfig() {
|
|
192
|
+
return this._readReg(_REG_CONFIG);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Write CONFIG = 0x8583 back and clear the cached settings. Not an I²C
|
|
197
|
+
* general-call reset.
|
|
198
|
+
* @returns {Promise<void>}
|
|
199
|
+
*/
|
|
200
|
+
async reset() {
|
|
201
|
+
await this._writeReg(_REG_CONFIG, _CONFIG_RESET);
|
|
202
|
+
this._dr = 4;
|
|
203
|
+
this._continuous = false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Default 7-bit I²C address (ADDR = GND). Valid range 0x48–0x4B. */
|
|
208
|
+
ADS1013Minimal.I2C_ADDRESS = 0x48;
|
|
209
|
+
|
|
210
|
+
/** Data-rate codes. */
|
|
211
|
+
ADS1013Full.DR_128 = 0;
|
|
212
|
+
ADS1013Full.DR_250 = 1;
|
|
213
|
+
ADS1013Full.DR_490 = 2;
|
|
214
|
+
ADS1013Full.DR_920 = 3;
|
|
215
|
+
ADS1013Full.DR_1600 = 4;
|
|
216
|
+
ADS1013Full.DR_2400 = 5;
|
|
217
|
+
ADS1013Full.DR_3300 = 6;
|
|
218
|
+
|
|
219
|
+
module.exports = { ADS1013Minimal, ADS1013Full };
|