periph 1.2.0 → 1.3.0

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.
Files changed (153) hide show
  1. package/README.md +18 -0
  2. package/examples/accelerometer/bma150/complete.js +62 -0
  3. package/examples/accelerometer/bma150/demo.js +65 -0
  4. package/examples/accelerometer/bma150/minimal.js +18 -0
  5. package/examples/adc_dac/hy3131/complete.js +66 -0
  6. package/examples/adc_dac/hy3131/demo.js +37 -0
  7. package/examples/adc_dac/hy3131/minimal.js +18 -0
  8. package/examples/discovery/complete.js +25 -0
  9. package/examples/discovery/demo.js +30 -0
  10. package/examples/discovery/minimal.js +12 -0
  11. package/examples/display/il0373/complete.js +71 -0
  12. package/examples/display/il0373/demo.js +49 -0
  13. package/examples/display/il0373/minimal.js +26 -0
  14. package/examples/display/ssd1331/complete.js +83 -0
  15. package/examples/display/ssd1331/demo.js +49 -0
  16. package/examples/display/ssd1331/minimal.js +27 -0
  17. package/examples/display/st7036/complete.js +71 -0
  18. package/examples/display/st7036/demo.js +56 -0
  19. package/examples/display/st7036/minimal.js +21 -0
  20. package/examples/display/uc1611s/complete.js +135 -0
  21. package/examples/display/uc1611s/complete_spi.js +128 -0
  22. package/examples/display/uc1611s/demo.js +90 -0
  23. package/examples/display/uc1611s/demo_spi.js +91 -0
  24. package/examples/display/uc1611s/minimal.js +28 -0
  25. package/examples/display/uc1611s/minimal_spi.js +30 -0
  26. package/examples/display/uc8159/complete.js +64 -0
  27. package/examples/display/uc8159/demo.js +41 -0
  28. package/examples/display/uc8159/minimal.js +28 -0
  29. package/examples/display/uc8276c/complete.js +73 -0
  30. package/examples/display/uc8276c/demo.js +49 -0
  31. package/examples/display/uc8276c/minimal.js +26 -0
  32. package/examples/environmental/bme280/complete.js +1 -1
  33. package/examples/environmental/bme280/demo.js +1 -1
  34. package/examples/environmental/bme280/minimal.js +1 -1
  35. package/examples/gyroscope/l3g4200d/complete.js +1 -1
  36. package/examples/gyroscope/l3g4200d/demo.js +1 -1
  37. package/examples/gyroscope/l3g4200d/minimal.js +1 -1
  38. package/examples/memory/23x1024/complete.js +54 -0
  39. package/examples/memory/23x1024/demo.js +51 -0
  40. package/examples/memory/23x1024/minimal.js +22 -0
  41. package/examples/memory/mx25l12845e/complete.js +66 -0
  42. package/examples/memory/mx25l12845e/demo.js +66 -0
  43. package/examples/memory/mx25l12845e/minimal.js +27 -0
  44. package/examples/memory/sd_spi/complete.js +55 -0
  45. package/examples/memory/sd_spi/demo.js +67 -0
  46. package/examples/memory/sd_spi/minimal.js +32 -0
  47. package/examples/motor/drv8830/complete.js +50 -0
  48. package/examples/motor/drv8830/demo.js +57 -0
  49. package/examples/motor/drv8830/minimal.js +23 -0
  50. package/examples/pressure/bmp280/complete.js +1 -1
  51. package/examples/pressure/bmp280/demo.js +1 -1
  52. package/examples/pressure/bmp280/minimal.js +1 -1
  53. package/examples/pressure/bmp581/complete.js +1 -1
  54. package/examples/pressure/bmp581/demo.js +1 -1
  55. package/examples/pressure/bmp581/minimal.js +1 -1
  56. package/examples/pressure/lps22df/complete.js +1 -1
  57. package/examples/pressure/lps22df/demo.js +1 -1
  58. package/examples/pressure/lps22df/minimal.js +1 -1
  59. package/examples/rtc/ds3231/complete.js +77 -0
  60. package/examples/rtc/ds3231/demo.js +60 -0
  61. package/examples/rtc/ds3231/minimal.js +23 -0
  62. package/examples/rtc/pcf8523/complete.js +66 -0
  63. package/examples/rtc/pcf8523/demo.js +65 -0
  64. package/examples/rtc/pcf8523/minimal.js +20 -0
  65. package/examples/temperature/mcp9808/complete.js +89 -0
  66. package/examples/temperature/mcp9808/demo.js +62 -0
  67. package/examples/temperature/mcp9808/minimal.js +21 -0
  68. package/examples/temperature/tmp117/complete.js +90 -0
  69. package/examples/temperature/tmp117/demo.js +73 -0
  70. package/examples/temperature/tmp117/minimal.js +21 -0
  71. package/examples/tof/vl53l0x/complete.js +118 -0
  72. package/examples/tof/vl53l0x/demo.js +83 -0
  73. package/examples/tof/vl53l0x/minimal.js +25 -0
  74. package/examples/tof/vl53l1x/complete.js +151 -0
  75. package/examples/tof/vl53l1x/demo.js +100 -0
  76. package/examples/tof/vl53l1x/minimal.js +25 -0
  77. package/package.json +1 -1
  78. package/src/chips/accelerometer/adxl345.js +10 -31
  79. package/src/chips/accelerometer/adxl362.js +7 -7
  80. package/src/chips/accelerometer/bma150.js +419 -0
  81. package/src/chips/adc_dac/ad7705.js +36 -9
  82. package/src/chips/adc_dac/ad7706.js +39 -9
  83. package/src/chips/adc_dac/hy3131.js +311 -0
  84. package/src/chips/display/il0373.js +607 -0
  85. package/src/chips/display/ssd1331.js +412 -0
  86. package/src/chips/display/st7036.js +401 -0
  87. package/src/chips/display/uc1611s.js +648 -0
  88. package/src/chips/display/uc8159.js +394 -0
  89. package/src/chips/display/uc8276c.js +658 -0
  90. package/src/chips/environmental/bme280.js +31 -46
  91. package/src/chips/environmental/bme680.js +38 -43
  92. package/src/chips/gas/ens160.js +18 -26
  93. package/src/chips/gyroscope/l3g4200d.js +34 -50
  94. package/src/chips/gyroscope/l3gd20h.js +24 -40
  95. package/src/chips/imu/mpu6050.js +29 -41
  96. package/src/chips/imu/mpu9250.js +45 -69
  97. package/src/chips/imu/mpu9255.js +54 -78
  98. package/src/chips/io_expander/mcp23017.js +24 -33
  99. package/src/chips/light/apds-9930.js +52 -60
  100. package/src/chips/light/apds9960.js +69 -77
  101. package/src/chips/magnetometer/as5600.js +13 -27
  102. package/src/chips/magnetometer/hmc5883l.js +32 -29
  103. package/src/chips/memory/_23x1024.js +228 -0
  104. package/src/chips/memory/_24aa02uid.js +8 -11
  105. package/src/chips/memory/mx25l12845e.js +467 -0
  106. package/src/chips/memory/sd_spi.js +486 -0
  107. package/src/chips/motor/drv8830.js +239 -0
  108. package/src/chips/other/mpr121.js +7 -7
  109. package/src/chips/power/ina219.js +5 -8
  110. package/src/chips/power/ina226.js +5 -8
  111. package/src/chips/power/ina3221.js +5 -8
  112. package/src/chips/pressure/bmp085.js +17 -11
  113. package/src/chips/pressure/bmp180.js +7 -7
  114. package/src/chips/pressure/bmp280.js +21 -33
  115. package/src/chips/pressure/bmp384.js +28 -39
  116. package/src/chips/pressure/bmp581.js +59 -70
  117. package/src/chips/pressure/lps22df.js +50 -52
  118. package/src/chips/pressure/lps28dfw.js +15 -13
  119. package/src/chips/pressure/lps33hw.js +7 -5
  120. package/src/chips/rtc/ds3231.js +504 -0
  121. package/src/chips/rtc/pcf8523.js +533 -0
  122. package/src/chips/temperature/mcp9808.js +490 -0
  123. package/src/chips/temperature/tmp117.js +471 -0
  124. package/src/chips/tof/_vl53_base.js +160 -0
  125. package/src/chips/tof/vl53l0x.js +816 -0
  126. package/src/chips/tof/vl53l1x.js +816 -0
  127. package/src/connection/connection.js +6 -4
  128. package/src/connection/dhtxx.js +5 -3
  129. package/src/connection/display.js +278 -0
  130. package/src/connection/display_mock.js +77 -0
  131. package/src/connection/hx711.js +5 -3
  132. package/src/connection/i2c.js +6 -4
  133. package/src/connection/i2c_mock.js +47 -0
  134. package/src/connection/input_pin.js +36 -5
  135. package/src/connection/register.js +14 -0
  136. package/src/connection/register_connection.js +65 -0
  137. package/src/connection/sipo.js +4 -2
  138. package/src/connection/sipo_mock.js +49 -0
  139. package/src/connection/smbus.js +6 -4
  140. package/src/connection/softspi.js +73 -0
  141. package/src/connection/spi.js +110 -23
  142. package/src/connection/spi_mock.js +50 -0
  143. package/src/connection/uart.js +2 -1
  144. package/src/discovery/discovery.js +218 -0
  145. package/src/discovery/registry.js +85 -0
  146. package/src/storage/block_device.js +95 -0
  147. package/src/storage/ram_block_device.js +72 -0
  148. package/examples/motor/.gitkeep +0 -0
  149. package/examples/temperature/.gitkeep +0 -0
  150. package/examples/tof/.gitkeep +0 -0
  151. package/src/chips/motor/.gitkeep +0 -0
  152. package/src/chips/temperature/.gitkeep +0 -0
  153. package/src/chips/tof/.gitkeep +0 -0
@@ -35,13 +35,11 @@ function _delay(ms) {
35
35
  * `await sensor.temperature()` (or any other async method) once before
36
36
  * relying on calibrated readings if this matters for your use case.
37
37
  *
38
- * @param {import('../../connection/connection').Connection} connection - Configured I²C or SPI connection.
39
- * @param {string} [busType='i2c'] - Bus type: 'i2c' or 'spi'.
38
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C, SMBus, or SPI register connection (SPI: default Bosch convention, readBit 0x80, no multi-byte bit).
40
39
  */
41
40
  class BMP280Minimal {
42
- constructor(connection, busType = 'i2c') {
41
+ constructor(connection) {
43
42
  this._conn = connection;
44
- this._busType = busType;
45
43
  this._mode = 0;
46
44
  this._osrsT = 1;
47
45
  this._osrsP = 1;
@@ -53,12 +51,12 @@ class BMP280Minimal {
53
51
 
54
52
  async _init() {
55
53
  await this._readCalibration();
56
- await this._writeReg(_REG_CTRL_MEAS, (1 << 5) | (1 << 2) | 0);
57
- await this._writeReg(_REG_CONFIG, 0);
54
+ await this._conn.writeReg(_REG_CTRL_MEAS, (1 << 5) | (1 << 2) | 0);
55
+ await this._conn.writeReg(_REG_CONFIG, 0);
58
56
  }
59
57
 
60
58
  async _readCalibration() {
61
- const data = await this._conn.writeRead(Buffer.from([_REG_CAL_START]), 24);
59
+ const data = await this._conn.readReg(_REG_CAL_START, 24);
62
60
  this._digT1 = data.readUInt16LE(0);
63
61
  this._digT2 = data.readInt16LE(2);
64
62
  this._digT3 = data.readInt16LE(4);
@@ -73,22 +71,13 @@ class BMP280Minimal {
73
71
  this._digP9 = data.readInt16LE(22);
74
72
  }
75
73
 
76
- async _writeReg(reg, value) {
77
- const addr = this._busType === 'spi' ? (reg & 0x7F) : reg;
78
- await this._conn.write(Buffer.from([addr, value]));
79
- }
80
-
81
- async _readReg(reg, n) {
82
- return this._conn.writeRead(Buffer.from([reg]), n);
83
- }
84
-
85
74
  async _triggerAndRead() {
86
75
  if (this._mode !== 3) {
87
76
  const ctrl = (this._osrsT << 5) | (this._osrsP << 2) | 1;
88
- await this._writeReg(_REG_CTRL_MEAS, ctrl);
77
+ await this._conn.writeReg(_REG_CTRL_MEAS, ctrl);
89
78
  _delay(_MEAS_TIME_MS);
90
79
  }
91
- const raw = await this._readReg(_REG_DATA_START, 6);
80
+ const raw = await this._conn.readReg(_REG_DATA_START, 6);
92
81
  const adcP = (raw[0] << 12) | (raw[1] << 4) | (raw[2] >> 4);
93
82
  const adcT = (raw[3] << 12) | (raw[4] << 4) | (raw[5] >> 4);
94
83
  return { adcP, adcT };
@@ -158,8 +147,7 @@ class BMP280Minimal {
158
147
  /**
159
148
  * BMP280 full interface — extends BMP280Minimal with configuration and altitude helpers.
160
149
  *
161
- * @param {import('../../connection/connection').Connection} connection - Configured I²C or SPI connection.
162
- * @param {string} [busType='i2c'] - Bus type: 'i2c' or 'spi'.
150
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C, SMBus, or SPI register connection (SPI: default Bosch convention, readBit 0x80, no multi-byte bit).
163
151
  */
164
152
  class BMP280Full extends BMP280Minimal {
165
153
  static OSRS_SKIP = 0;
@@ -191,8 +179,8 @@ class BMP280Full extends BMP280Minimal {
191
179
  static STATUS_MEASURING = 0x08;
192
180
  static STATUS_IM_UPDATE = 0x01;
193
181
 
194
- constructor(connection, busType = 'i2c') {
195
- super(connection, busType);
182
+ constructor(connection) {
183
+ super(connection);
196
184
  }
197
185
 
198
186
  /**
@@ -210,8 +198,8 @@ class BMP280Full extends BMP280Minimal {
210
198
  this._mode = mode;
211
199
  this._filter = filter;
212
200
  this._tSb = tSb;
213
- await this._writeReg(_REG_CONFIG, (tSb << 5) | (filter << 2));
214
- await this._writeReg(_REG_CTRL_MEAS, (osrsT << 5) | (osrsP << 2) | mode);
201
+ await this._conn.writeReg(_REG_CONFIG, (tSb << 5) | (filter << 2));
202
+ await this._conn.writeReg(_REG_CTRL_MEAS, (osrsT << 5) | (osrsP << 2) | mode);
215
203
  }
216
204
 
217
205
  /**
@@ -223,7 +211,7 @@ class BMP280Full extends BMP280Minimal {
223
211
  async setOversampling(osrsT, osrsP) {
224
212
  this._osrsT = osrsT;
225
213
  this._osrsP = osrsP;
226
- await this._writeReg(_REG_CTRL_MEAS, (osrsT << 5) | (osrsP << 2) | this._mode);
214
+ await this._conn.writeReg(_REG_CTRL_MEAS, (osrsT << 5) | (osrsP << 2) | this._mode);
227
215
  }
228
216
 
229
217
  /**
@@ -233,7 +221,7 @@ class BMP280Full extends BMP280Minimal {
233
221
  */
234
222
  async setMode(mode) {
235
223
  this._mode = mode;
236
- await this._writeReg(_REG_CTRL_MEAS, (this._osrsT << 5) | (this._osrsP << 2) | mode);
224
+ await this._conn.writeReg(_REG_CTRL_MEAS, (this._osrsT << 5) | (this._osrsP << 2) | mode);
237
225
  }
238
226
 
239
227
  /**
@@ -243,7 +231,7 @@ class BMP280Full extends BMP280Minimal {
243
231
  */
244
232
  async setFilter(coeff) {
245
233
  this._filter = coeff;
246
- await this._writeReg(_REG_CONFIG, (this._tSb << 5) | (coeff << 2));
234
+ await this._conn.writeReg(_REG_CONFIG, (this._tSb << 5) | (coeff << 2));
247
235
  }
248
236
 
249
237
  /**
@@ -253,7 +241,7 @@ class BMP280Full extends BMP280Minimal {
253
241
  */
254
242
  async setStandby(tSb) {
255
243
  this._tSb = tSb;
256
- await this._writeReg(_REG_CONFIG, (tSb << 5) | (this._filter << 2));
244
+ await this._conn.writeReg(_REG_CONFIG, (tSb << 5) | (this._filter << 2));
257
245
  }
258
246
 
259
247
  /**
@@ -261,7 +249,7 @@ class BMP280Full extends BMP280Minimal {
261
249
  * @returns {Promise<number>} Status byte; bit 3 = measuring, bit 0 = im_update.
262
250
  */
263
251
  async status() {
264
- const data = await this._readReg(_REG_STATUS, 1);
252
+ const data = await this._conn.readReg(_REG_STATUS, 1);
265
253
  return data[0];
266
254
  }
267
255
 
@@ -290,7 +278,7 @@ class BMP280Full extends BMP280Minimal {
290
278
  * @returns {Promise<number>} Chip ID; expect 0x58.
291
279
  */
292
280
  async chipId() {
293
- const data = await this._readReg(_REG_ID, 1);
281
+ const data = await this._conn.readReg(_REG_ID, 1);
294
282
  return data[0];
295
283
  }
296
284
 
@@ -299,11 +287,11 @@ class BMP280Full extends BMP280Minimal {
299
287
  * @returns {Promise<void>}
300
288
  */
301
289
  async reset() {
302
- await this._writeReg(_REG_RESET, _RESET_CMD);
290
+ await this._conn.writeReg(_REG_RESET, _RESET_CMD);
303
291
  _delay(2);
304
292
  await this._readCalibration();
305
- await this._writeReg(_REG_CONFIG, (this._tSb << 5) | (this._filter << 2));
306
- await this._writeReg(_REG_CTRL_MEAS, (this._osrsT << 5) | (this._osrsP << 2) | this._mode);
293
+ await this._conn.writeReg(_REG_CONFIG, (this._tSb << 5) | (this._filter << 2));
294
+ await this._conn.writeReg(_REG_CTRL_MEAS, (this._osrsT << 5) | (this._osrsP << 2) | this._mode);
307
295
  }
308
296
  }
309
297
 
@@ -56,13 +56,11 @@ function _s8(b) {
56
56
  * `await sensor.temperature()` (or any other async method) once before
57
57
  * relying on calibrated readings if this matters for your use case.
58
58
  *
59
- * @param {import('../../connection/connection').Connection} connection - Configured I²C or SPI connection.
60
- * @param {string} [busType='i2c'] - Bus type: 'i2c' or 'spi'.
59
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C, SMBus, or SPI register connection (SPI: default Bosch convention, readBit 0x80, no multi-byte bit).
61
60
  */
62
61
  class BMP384Minimal {
63
- constructor(connection, busType = 'i2c') {
62
+ constructor(connection) {
64
63
  this._conn = connection;
65
- this._busType = busType;
66
64
  this._osrP = 4; // ×16
67
65
  this._osrT = 1; // ×2
68
66
  this._iir = 2; // coefficient 3
@@ -77,7 +75,7 @@ class BMP384Minimal {
77
75
  }
78
76
 
79
77
  async _readCalibration() {
80
- const data = await this._conn.writeRead(Buffer.from([_REG_CAL_START]), _REG_CAL_LEN);
78
+ const data = await this._conn.readReg(_REG_CAL_START, _REG_CAL_LEN);
81
79
  // NVM_PAR_T1 (u16 LE)
82
80
  this._parT1 = data.readUInt16LE(0);
83
81
  // NVM_PAR_T2 (u16 LE)
@@ -129,24 +127,15 @@ class BMP384Minimal {
129
127
  const osrReg = (this._osrT << 3) | (this._osrP << 0);
130
128
  const configReg = (this._iir << 1);
131
129
  const pwrReg = (this._mode << 4) | _PWR_TEMP_EN | _PWR_PRESS_EN;
132
- await this._writeReg(_REG_OSR, osrReg);
133
- await this._writeReg(_REG_CONFIG, configReg);
134
- await this._writeReg(_REG_ODR, this._odr);
135
- await this._writeReg(_REG_PWR_CTRL, pwrReg);
136
- }
137
-
138
- async _writeReg(reg, value) {
139
- const addr = this._busType === 'spi' ? (reg & 0x7F) : reg;
140
- await this._conn.write(Buffer.from([addr, value]));
141
- }
142
-
143
- async _readReg(reg, n) {
144
- return this._conn.writeRead(Buffer.from([reg]), n);
130
+ await this._conn.writeReg(_REG_OSR, osrReg);
131
+ await this._conn.writeReg(_REG_CONFIG, configReg);
132
+ await this._conn.writeReg(_REG_ODR, this._odr);
133
+ await this._conn.writeReg(_REG_PWR_CTRL, pwrReg);
145
134
  }
146
135
 
147
136
  async _readBurst() {
148
137
  // DATA_0..DATA_5 (0x04..0x09) = pressure XLSB/LSB/MSB, then temperature XLSB/LSB/MSB
149
- const raw = await this._readReg(_REG_DATA_0, 6);
138
+ const raw = await this._conn.readReg(_REG_DATA_0, 6);
150
139
  const uncompPress = (raw[2] << 16) | (raw[1] << 8) | raw[0];
151
140
  const uncompTemp = (raw[5] << 16) | (raw[4] << 8) | raw[3];
152
141
  return { uncompPress, uncompTemp };
@@ -188,7 +177,7 @@ class BMP384Minimal {
188
177
  async temperature() {
189
178
  if (this._mode === _MODE_FORCED) {
190
179
  const pwrReg = (_MODE_FORCED << 4) | _PWR_TEMP_EN | _PWR_PRESS_EN;
191
- await this._writeReg(_REG_PWR_CTRL, pwrReg);
180
+ await this._conn.writeReg(_REG_PWR_CTRL, pwrReg);
192
181
  _delay(_MEAS_TIME_MS);
193
182
  }
194
183
  const { uncompTemp } = await this._readBurst();
@@ -202,7 +191,7 @@ class BMP384Minimal {
202
191
  async pressure() {
203
192
  if (this._mode === _MODE_FORCED) {
204
193
  const pwrReg = (_MODE_FORCED << 4) | _PWR_TEMP_EN | _PWR_PRESS_EN;
205
- await this._writeReg(_REG_PWR_CTRL, pwrReg);
194
+ await this._conn.writeReg(_REG_PWR_CTRL, pwrReg);
206
195
  _delay(_MEAS_TIME_MS);
207
196
  }
208
197
  const { uncompPress, uncompTemp } = await this._readBurst();
@@ -214,16 +203,15 @@ class BMP384Minimal {
214
203
  /**
215
204
  * BMP384 full interface — extends BMP384Minimal with configuration, mode control, and FIFO access.
216
205
  *
217
- * @param {import('../../connection/connection').Connection} connection - Configured I²C or SPI connection.
218
- * @param {string} [busType='i2c'] - Bus type: 'i2c' or 'spi'.
206
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C, SMBus, or SPI register connection (SPI: default Bosch convention, readBit 0x80, no multi-byte bit).
219
207
  */
220
208
  class BMP384Full extends BMP384Minimal {
221
209
  static MODE_SLEEP = 0x00;
222
210
  static MODE_FORCED = 0x01;
223
211
  static MODE_NORMAL = 0x03;
224
212
 
225
- constructor(connection, busType = 'i2c') {
226
- super(connection, busType);
213
+ constructor(connection) {
214
+ super(connection);
227
215
  }
228
216
 
229
217
  /**
@@ -239,9 +227,9 @@ class BMP384Full extends BMP384Minimal {
239
227
  this._osrT = osrT;
240
228
  this._iir = iirFilter;
241
229
  this._odr = odrSel;
242
- await this._writeReg(_REG_OSR, (osrT << 3) | (osrP << 0));
243
- await this._writeReg(_REG_CONFIG, (iirFilter << 1));
244
- await this._writeReg(_REG_ODR, odrSel);
230
+ await this._conn.writeReg(_REG_OSR, (osrT << 3) | (osrP << 0));
231
+ await this._conn.writeReg(_REG_CONFIG, (iirFilter << 1));
232
+ await this._conn.writeReg(_REG_ODR, odrSel);
245
233
  }
246
234
 
247
235
  /**
@@ -251,6 +239,7 @@ class BMP384Full extends BMP384Minimal {
251
239
  async read() {
252
240
  if (this._mode === _MODE_FORCED) {
253
241
  await this._triggerForced();
242
+ _delay(BMP384Full._computeTConvMs(this._osrP, this._osrT));
254
243
  }
255
244
  const { uncompPress, uncompTemp } = await this._readBurst();
256
245
  const t = this._compensateTemperature(uncompTemp);
@@ -294,7 +283,7 @@ class BMP384Full extends BMP384Minimal {
294
283
  * @returns {Promise<boolean>}
295
284
  */
296
285
  async isDataReady() {
297
- const raw = await this._readReg(_REG_STATUS, 1);
286
+ const raw = await this._conn.readReg(_REG_STATUS, 1);
298
287
  return (raw[0] & (1 << 5)) !== 0;
299
288
  }
300
289
 
@@ -303,7 +292,7 @@ class BMP384Full extends BMP384Minimal {
303
292
  * @returns {Promise<void>}
304
293
  */
305
294
  async softreset() {
306
- await this._writeReg(_REG_CMD, _SOFT_RESET_CMD);
295
+ await this._conn.writeReg(_REG_CMD, _SOFT_RESET_CMD);
307
296
  _delay(3);
308
297
  await this._readCalibration();
309
298
  await this._applyConfig();
@@ -322,9 +311,9 @@ class BMP384Full extends BMP384Minimal {
322
311
  | ((stopOnFull ? 1 : 0) << 3)
323
312
  | ((tempEn ? 1 : 0) << 1)
324
313
  | (pressEn ? 1 : 0);
325
- await this._writeReg(0x17, cfg1);
326
- await this._writeReg(0x15, wtm & 0xFF);
327
- await this._writeReg(0x16, (wtm >> 8) & 0x01);
314
+ await this._conn.writeReg(0x17, cfg1);
315
+ await this._conn.writeReg(0x15, wtm & 0xFF);
316
+ await this._conn.writeReg(0x16, (wtm >> 8) & 0x01);
328
317
  }
329
318
 
330
319
  /**
@@ -332,11 +321,11 @@ class BMP384Full extends BMP384Minimal {
332
321
  * @returns {Promise<Array<{type:string, value:number|null}>>}
333
322
  */
334
323
  async fifoRead() {
335
- const lenLo = (await this._readReg(0x12, 1))[0];
336
- const lenHi = (await this._readReg(0x13, 1))[0];
324
+ const lenLo = (await this._conn.readReg(0x12, 1))[0];
325
+ const lenHi = (await this._conn.readReg(0x13, 1))[0];
337
326
  const length = (lenHi << 8) | lenLo;
338
327
  if (length === 0) return [];
339
- const buf = await this._readReg(0x14, length);
328
+ const buf = await this._conn.readReg(0x14, length);
340
329
  const frames = [];
341
330
  let i = 0;
342
331
  while (i < buf.length) {
@@ -371,7 +360,7 @@ class BMP384Full extends BMP384Minimal {
371
360
  * @returns {Promise<void>}
372
361
  */
373
362
  async fifoFlush() {
374
- await this._writeReg(_REG_CMD, _FIFO_FLUSH_CMD);
363
+ await this._conn.writeReg(_REG_CMD, _FIFO_FLUSH_CMD);
375
364
  }
376
365
 
377
366
  /**
@@ -387,12 +376,12 @@ class BMP384Full extends BMP384Minimal {
387
376
 
388
377
  async _triggerForced() {
389
378
  const pwrReg = (_MODE_FORCED << 4) | _PWR_TEMP_EN | _PWR_PRESS_EN;
390
- await this._writeReg(_REG_PWR_CTRL, pwrReg);
379
+ await this._conn.writeReg(_REG_PWR_CTRL, pwrReg);
391
380
  }
392
381
 
393
382
  async _applyPwr() {
394
383
  const pwrReg = (this._mode << 4) | _PWR_TEMP_EN | _PWR_PRESS_EN;
395
- await this._writeReg(_REG_PWR_CTRL, pwrReg);
384
+ await this._conn.writeReg(_REG_PWR_CTRL, pwrReg);
396
385
  }
397
386
 
398
387
  _compensatePressureWithTLin(uncompPress, tLin) {
@@ -61,13 +61,11 @@ function _u24(data, offset) {
61
61
  * `await sensor.temperature()` (or any other async method) once before
62
62
  * relying on calibrated readings if this matters.
63
63
  *
64
- * @param {import('../../connection/connection').Connection} connection - Configured I²C or SPI connection.
65
- * @param {string} [busType='i2c'] - Bus type: 'i2c' or 'spi'.
64
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C, SMBus, or SPI register connection (SPI: default Bosch convention, readBit 0x80, no multi-byte bit).
66
65
  */
67
66
  class BMP581Minimal {
68
- constructor(connection, busType = 'i2c') {
67
+ constructor(connection) {
69
68
  this._conn = connection;
70
- this._busType = busType;
71
69
  this._odr = 0x1C;
72
70
  this._pwrMode = 0x01;
73
71
  this._osrP = 0;
@@ -77,51 +75,43 @@ class BMP581Minimal {
77
75
  }
78
76
 
79
77
  async _init() {
78
+ await this._dummyRead();
80
79
  try {
81
- const cid = (await this._readReg(_REG_CHIP_ID, 1))[0];
80
+ const cid = (await this._conn.readReg(_REG_CHIP_ID, 1))[0];
82
81
  if (cid !== _CHIP_ID_EXPECTED) return;
83
82
  for (let i = 0; i < 50; i++) {
84
- const st = (await this._readReg(_REG_STATUS, 1))[0];
83
+ const st = (await this._conn.readReg(_REG_STATUS, 1))[0];
85
84
  if ((st & _STATUS_NVM_RDY) && !(st & _STATUS_NVM_ERR)) break;
86
85
  _delay(2);
87
86
  }
88
- await this._readReg(_REG_INT_STATUS, 1);
87
+ await this._conn.readReg(_REG_INT_STATUS, 1);
89
88
  try {
90
- await this._writeReg(_REG_CMD, _SOFT_RESET_CMD);
89
+ await this._conn.writeReg(_REG_CMD, _SOFT_RESET_CMD);
91
90
  } catch (e) { /* expected NACK */ }
92
91
  _delay(2);
93
92
  for (let i = 0; i < 50; i++) {
94
- const st = (await this._readReg(_REG_STATUS, 1))[0];
93
+ const st = (await this._conn.readReg(_REG_STATUS, 1))[0];
95
94
  if ((st & _STATUS_NVM_RDY) && !(st & _STATUS_NVM_ERR)) break;
96
95
  _delay(2);
97
96
  }
98
- await this._readReg(_REG_INT_STATUS, 1);
99
- await this._writeReg(_REG_OSR_CONFIG, 0x40);
100
- await this._writeReg(_REG_ODR_CONFIG, 0x71);
97
+ await this._conn.readReg(_REG_INT_STATUS, 1);
98
+ await this._conn.writeReg(_REG_OSR_CONFIG, 0x40);
99
+ await this._conn.writeReg(_REG_ODR_CONFIG, 0x71);
101
100
  } catch (e) { /* bus may be idle */ }
102
101
  }
103
102
 
104
- async _writeReg(reg, value) {
105
- const addr = this._busType === 'spi' ? (reg & 0x7F) : reg;
106
- await this._conn.write(Buffer.from([addr, value & 0xFF]));
107
- }
108
-
109
- async _readReg(reg, n) {
110
- return this._conn.writeRead(Buffer.from([reg]), n);
111
- }
112
-
113
- async _spiDummyRead() {
114
- if (this._busType !== 'spi') return;
103
+ // The first read after CSB falls on SPI returns invalid data (datasheet);
104
+ // one throwaway CHIP_ID read is harmless on I²C, so it is unconditional.
105
+ async _dummyRead() {
115
106
  try {
116
- await this._conn.write(Buffer.from([_REG_CHIP_ID | 0x80]));
117
- await this._conn.read(1);
107
+ await this._conn.readReg(_REG_CHIP_ID, 1);
118
108
  } catch (e) { /* ignore */ }
119
109
  }
120
110
 
121
111
  async _waitForced() {
122
112
  if (this._pwrMode !== 2) return;
123
113
  for (let i = 0; i < 200; i++) {
124
- const st = (await this._readReg(_REG_INT_STATUS, 1))[0];
114
+ const st = (await this._conn.readReg(_REG_INT_STATUS, 1))[0];
125
115
  if (st & _INT_STATUS_DRDY) return;
126
116
  _delay(5);
127
117
  }
@@ -133,7 +123,7 @@ class BMP581Minimal {
133
123
  */
134
124
  async pressure() {
135
125
  await this._waitForced();
136
- const buf = await this._readReg(_REG_PRESS_XLSB, 3);
126
+ const buf = await this._conn.readReg(_REG_PRESS_XLSB, 3);
137
127
  return _u24(buf, 0) / 64.0;
138
128
  }
139
129
 
@@ -143,7 +133,7 @@ class BMP581Minimal {
143
133
  */
144
134
  async temperature() {
145
135
  await this._waitForced();
146
- const buf = await this._readReg(_REG_TEMP_XLSB, 3);
136
+ const buf = await this._conn.readReg(_REG_TEMP_XLSB, 3);
147
137
  return _u24(buf, 0) / 65536.0;
148
138
  }
149
139
 
@@ -153,7 +143,7 @@ class BMP581Minimal {
153
143
  */
154
144
  async both() {
155
145
  await this._waitForced();
156
- const buf = await this._readReg(_REG_TEMP_XLSB, 6);
146
+ const buf = await this._conn.readReg(_REG_TEMP_XLSB, 6);
157
147
  return {
158
148
  pressure: _u24(buf, 3) / 64.0,
159
149
  temperature: _u24(buf, 0) / 65536.0,
@@ -165,8 +155,7 @@ class BMP581Minimal {
165
155
  * BMP581 full interface — extends BMP581Minimal with configuration, FIFO,
166
156
  * interrupts, OOR detection, and NVM access.
167
157
  *
168
- * @param {import('../../connection/connection').Connection} connection - Configured I²C or SPI connection.
169
- * @param {string} [busType='i2c'] - Bus type: 'i2c' or 'spi'.
158
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C, SMBus, or SPI register connection (SPI: default Bosch convention, readBit 0x80, no multi-byte bit).
170
159
  */
171
160
  class BMP581Full extends BMP581Minimal {
172
161
  static OSR_1X = 0;
@@ -205,8 +194,8 @@ class BMP581Full extends BMP581Minimal {
205
194
  static INT_SOURCE_FIFO_THS = 0x04;
206
195
  static INT_SOURCE_OOR_P = 0x08;
207
196
 
208
- constructor(connection, busType = 'i2c') {
209
- super(connection, busType);
197
+ constructor(connection) {
198
+ super(connection);
210
199
  }
211
200
 
212
201
  /**
@@ -223,9 +212,9 @@ class BMP581Full extends BMP581Minimal {
223
212
  this._osrT = osrT;
224
213
  this._pressEn = pressEn;
225
214
  const osr = (pressEn ? 0x40 : 0) | ((osrP & 0x7) << 3) | (osrT & 0x7);
226
- await this._writeReg(_REG_OSR_CONFIG, osr);
215
+ await this._conn.writeReg(_REG_OSR_CONFIG, osr);
227
216
  const odrByte = ((odr & 0x1F) << 2) | (this._pwrMode & 0x3);
228
- await this._writeReg(_REG_ODR_CONFIG, odrByte);
217
+ await this._conn.writeReg(_REG_ODR_CONFIG, odrByte);
229
218
  }
230
219
 
231
220
  /**
@@ -236,7 +225,7 @@ class BMP581Full extends BMP581Minimal {
236
225
  async setMode(mode) {
237
226
  this._pwrMode = mode;
238
227
  const odrByte = ((this._odr & 0x1F) << 2) | (mode & 0x3);
239
- await this._writeReg(_REG_ODR_CONFIG, odrByte);
228
+ await this._conn.writeReg(_REG_ODR_CONFIG, odrByte);
240
229
  }
241
230
 
242
231
  /**
@@ -247,11 +236,11 @@ class BMP581Full extends BMP581Minimal {
247
236
  const prev = this._pwrMode;
248
237
  if (prev !== 2) await this.setMode(2);
249
238
  for (let i = 0; i < 400; i++) {
250
- const st = (await this._readReg(_REG_INT_STATUS, 1))[0];
239
+ const st = (await this._conn.readReg(_REG_INT_STATUS, 1))[0];
251
240
  if (st & _INT_STATUS_DRDY) break;
252
241
  _delay(5);
253
242
  }
254
- const buf = await this._readReg(_REG_TEMP_XLSB, 6);
243
+ const buf = await this._conn.readReg(_REG_TEMP_XLSB, 6);
255
244
  return {
256
245
  pressure: _u24(buf, 3) / 64.0,
257
246
  temperature: _u24(buf, 0) / 65536.0,
@@ -272,7 +261,7 @@ class BMP581Full extends BMP581Minimal {
272
261
  /** Issue a soft reset and re-initialise the chip. @returns {Promise<void>} */
273
262
  async softwareReset() {
274
263
  try {
275
- await this._writeReg(_REG_CMD, _SOFT_RESET_CMD);
264
+ await this._conn.writeReg(_REG_CMD, _SOFT_RESET_CMD);
276
265
  } catch (e) { /* expected NACK */ }
277
266
  _delay(2);
278
267
  await this._init();
@@ -283,7 +272,7 @@ class BMP581Full extends BMP581Minimal {
283
272
  * @returns {Promise<number>} 0x50 for a genuine BMP581.
284
273
  */
285
274
  async chipId() {
286
- const buf = await this._readReg(_REG_CHIP_ID, 1);
275
+ const buf = await this._conn.readReg(_REG_CHIP_ID, 1);
287
276
  return buf[0];
288
277
  }
289
278
 
@@ -292,7 +281,7 @@ class BMP581Full extends BMP581Minimal {
292
281
  * @returns {Promise<number>} ASIC revision identifier.
293
282
  */
294
283
  async revId() {
295
- const buf = await this._readReg(_REG_REV_ID, 1);
284
+ const buf = await this._conn.readReg(_REG_REV_ID, 1);
296
285
  return buf[0];
297
286
  }
298
287
 
@@ -301,7 +290,7 @@ class BMP581Full extends BMP581Minimal {
301
290
  * @returns {Promise<number>} Raw status byte.
302
291
  */
303
292
  async status() {
304
- const buf = await this._readReg(_REG_STATUS, 1);
293
+ const buf = await this._conn.readReg(_REG_STATUS, 1);
305
294
  return buf[0];
306
295
  }
307
296
 
@@ -310,7 +299,7 @@ class BMP581Full extends BMP581Minimal {
310
299
  * @returns {Promise<number>} Raw interrupt status byte.
311
300
  */
312
301
  async interruptStatus() {
313
- const buf = await this._readReg(_REG_INT_STATUS, 1);
302
+ const buf = await this._conn.readReg(_REG_INT_STATUS, 1);
314
303
  return buf[0];
315
304
  }
316
305
 
@@ -335,15 +324,15 @@ class BMP581Full extends BMP581Minimal {
335
324
  if (openDrain) val |= 0x04;
336
325
  if (polarity) val |= 0x02;
337
326
  if (mode) val |= 0x01;
338
- await this._writeReg(_REG_INT_CONFIG, val);
327
+ await this._conn.writeReg(_REG_INT_CONFIG, val);
339
328
  }
340
329
 
341
330
  async _setIntSource(source, enable) {
342
- const buf = await this._readReg(_REG_INT_SOURCE, 1);
331
+ const buf = await this._conn.readReg(_REG_INT_SOURCE, 1);
343
332
  let cur = buf[0];
344
333
  if (enable) cur |= source;
345
334
  else cur &= ~source;
346
- await this._writeReg(_REG_INT_SOURCE, cur);
335
+ await this._conn.writeReg(_REG_INT_SOURCE, cur);
347
336
  }
348
337
 
349
338
  /** Enable/disable the data-ready interrupt source. @returns {Promise<void>} */
@@ -353,11 +342,11 @@ class BMP581Full extends BMP581Minimal {
353
342
 
354
343
  /** Enable/disable FIFO threshold and FIFO-full interrupt sources. @returns {Promise<void>} */
355
344
  async enableFifoInterrupt(threshold, full) {
356
- const buf = await this._readReg(_REG_INT_SOURCE, 1);
345
+ const buf = await this._conn.readReg(_REG_INT_SOURCE, 1);
357
346
  let cur = buf[0] & ~(BMP581Full.INT_SOURCE_FIFO_FULL | BMP581Full.INT_SOURCE_FIFO_THS);
358
347
  if (threshold) cur |= BMP581Full.INT_SOURCE_FIFO_THS;
359
348
  if (full) cur |= BMP581Full.INT_SOURCE_FIFO_FULL;
360
- await this._writeReg(_REG_INT_SOURCE, cur);
349
+ await this._conn.writeReg(_REG_INT_SOURCE, cur);
361
350
  }
362
351
 
363
352
  /** Enable/disable the pressure out-of-range interrupt source. @returns {Promise<void>} */
@@ -373,11 +362,11 @@ class BMP581Full extends BMP581Minimal {
373
362
  * @returns {Promise<void>}
374
363
  */
375
364
  async setIirFilter(coeffP, coeffT) {
376
- const buf = await this._readReg(_REG_DSP_CONFIG, 1);
365
+ const buf = await this._conn.readReg(_REG_DSP_CONFIG, 1);
377
366
  let dsp = buf[0] | 0x28;
378
- await this._writeReg(_REG_DSP_CONFIG, dsp);
367
+ await this._conn.writeReg(_REG_DSP_CONFIG, dsp);
379
368
  const iirVal = ((coeffP & 0x7) << 3) | (coeffT & 0x7);
380
- await this._writeReg(_REG_DSP_IIR, iirVal);
369
+ await this._conn.writeReg(_REG_DSP_IIR, iirVal);
381
370
  }
382
371
 
383
372
  /**
@@ -390,8 +379,8 @@ class BMP581Full extends BMP581Minimal {
390
379
  async configureFifo(frameSel, mode, threshold) {
391
380
  const prev = this._pwrMode;
392
381
  if (prev !== 0) await this.setMode(0);
393
- await this._writeReg(_REG_FIFO_SEL, frameSel & 0x3);
394
- await this._writeReg(_REG_FIFO_CONFIG, ((mode & 0x1) << 5) | (threshold & 0x1F));
382
+ await this._conn.writeReg(_REG_FIFO_SEL, frameSel & 0x3);
383
+ await this._conn.writeReg(_REG_FIFO_CONFIG, ((mode & 0x1) << 5) | (threshold & 0x1F));
395
384
  if (prev !== 0) await this.setMode(prev);
396
385
  }
397
386
 
@@ -400,7 +389,7 @@ class BMP581Full extends BMP581Minimal {
400
389
  * @returns {Promise<number>} Frame count 0-32.
401
390
  */
402
391
  async fifoCount() {
403
- const buf = await this._readReg(_REG_FIFO_COUNT, 1);
392
+ const buf = await this._conn.readReg(_REG_FIFO_COUNT, 1);
404
393
  return buf[0] & 0x3F;
405
394
  }
406
395
 
@@ -409,7 +398,7 @@ class BMP581Full extends BMP581Minimal {
409
398
  * @returns {Promise<{osrP: number, osrT: number}>}
410
399
  */
411
400
  async effectiveOsr() {
412
- const buf = await this._readReg(_REG_OSR_EFF, 1);
401
+ const buf = await this._conn.readReg(_REG_OSR_EFF, 1);
413
402
  return {
414
403
  osrP: (buf[0] >> 3) & 0x7,
415
404
  osrT: buf[0] & 0x7,
@@ -421,7 +410,7 @@ class BMP581Full extends BMP581Minimal {
421
410
  * @returns {Promise<boolean>}
422
411
  */
423
412
  async odrIsValid() {
424
- const buf = await this._readReg(_REG_OSR_EFF, 1);
413
+ const buf = await this._conn.readReg(_REG_OSR_EFF, 1);
425
414
  return (buf[0] & 0x80) !== 0;
426
415
  }
427
416
 
@@ -434,12 +423,12 @@ class BMP581Full extends BMP581Minimal {
434
423
  */
435
424
  async setOorThreshold(thresholdPa, rangePa, countLimit) {
436
425
  let thr17 = Math.floor(thresholdPa * 64.0) >> 7;
437
- await this._writeReg(_REG_OOR_THR_P_LSB, thr17 & 0xFF);
438
- await this._writeReg(_REG_OOR_THR_P_MSB, (thr17 >> 8) & 0xFF);
426
+ await this._conn.writeReg(_REG_OOR_THR_P_LSB, thr17 & 0xFF);
427
+ await this._conn.writeReg(_REG_OOR_THR_P_MSB, (thr17 >> 8) & 0xFF);
439
428
  const range8 = (Math.floor(rangePa * 64.0) >> 7) & 0xFF;
440
- await this._writeReg(_REG_OOR_RANGE, range8);
429
+ await this._conn.writeReg(_REG_OOR_RANGE, range8);
441
430
  const oorCfg = ((countLimit & 0x3) << 6) | ((thr17 >> 16) & 0x01);
442
- await this._writeReg(_REG_OOR_CONFIG, oorCfg);
431
+ await this._conn.writeReg(_REG_OOR_CONFIG, oorCfg);
443
432
  }
444
433
 
445
434
  /**
@@ -451,13 +440,13 @@ class BMP581Full extends BMP581Minimal {
451
440
  const prev = this._pwrMode;
452
441
  if (prev !== 0) await this.setMode(0);
453
442
  try {
454
- await this._writeReg(_REG_NVM_ADDR, 0x5D);
455
- await this._writeReg(_REG_CMD, 0xA5);
443
+ await this._conn.writeReg(_REG_NVM_ADDR, 0x5D);
444
+ await this._conn.writeReg(_REG_CMD, 0xA5);
456
445
  _delay(2);
457
- await this._writeReg(_REG_NVM_ADDR, 0x40 | (row & 0x3F));
458
- await this._writeReg(_REG_CMD, 0xA5);
446
+ await this._conn.writeReg(_REG_NVM_ADDR, 0x40 | (row & 0x3F));
447
+ await this._conn.writeReg(_REG_CMD, 0xA5);
459
448
  _delay(2);
460
- const buf = await this._readReg(_REG_NVM_DATA_LSB, 2);
449
+ const buf = await this._conn.readReg(_REG_NVM_DATA_LSB, 2);
461
450
  return (buf[1] << 8) | buf[0];
462
451
  } finally {
463
452
  if (prev !== 0) await this.setMode(prev);
@@ -474,11 +463,11 @@ class BMP581Full extends BMP581Minimal {
474
463
  const prev = this._pwrMode;
475
464
  if (prev !== 0) await this.setMode(0);
476
465
  try {
477
- await this._writeReg(_REG_NVM_ADDR, 0x40 | (row & 0x3F));
478
- await this._writeReg(_REG_NVM_DATA_LSB, value & 0xFF);
479
- await this._writeReg(_REG_NVM_DATA_MSB, (value >> 8) & 0xFF);
480
- await this._writeReg(_REG_NVM_ADDR, 0x5D);
481
- await this._writeReg(_REG_CMD, 0xA0);
466
+ await this._conn.writeReg(_REG_NVM_ADDR, 0x40 | (row & 0x3F));
467
+ await this._conn.writeReg(_REG_NVM_DATA_LSB, value & 0xFF);
468
+ await this._conn.writeReg(_REG_NVM_DATA_MSB, (value >> 8) & 0xFF);
469
+ await this._conn.writeReg(_REG_NVM_ADDR, 0x5D);
470
+ await this._conn.writeReg(_REG_CMD, 0xA0);
482
471
  _delay(5);
483
472
  } finally {
484
473
  if (prev !== 0) await this.setMode(prev);