periph 1.0.1 → 1.2.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 (241) hide show
  1. package/README.md +54 -12
  2. package/examples/accelerometer/adxl345/complete.js +52 -0
  3. package/examples/accelerometer/adxl345/demo.js +34 -0
  4. package/examples/accelerometer/adxl345/minimal.js +18 -0
  5. package/examples/accelerometer/adxl362/complete.js +57 -0
  6. package/examples/accelerometer/adxl362/demo.js +51 -0
  7. package/examples/accelerometer/adxl362/minimal.js +21 -0
  8. package/examples/adc_dac/ad7705/complete.js +32 -0
  9. package/examples/adc_dac/ad7705/demo.js +42 -0
  10. package/examples/adc_dac/ad7705/minimal.js +16 -0
  11. package/examples/adc_dac/ad7706/complete.js +35 -0
  12. package/examples/adc_dac/ad7706/demo.js +44 -0
  13. package/examples/adc_dac/ad7706/minimal.js +16 -0
  14. package/examples/adc_dac/hx710a/complete.js +45 -0
  15. package/examples/adc_dac/hx710a/demo.js +52 -0
  16. package/examples/adc_dac/hx710a/minimal.js +16 -0
  17. package/examples/adc_dac/hx710b/complete.js +45 -0
  18. package/examples/adc_dac/hx710b/demo.js +64 -0
  19. package/examples/adc_dac/hx710b/minimal.js +16 -0
  20. package/examples/adc_dac/hx711/complete.js +42 -0
  21. package/examples/adc_dac/hx711/demo.js +35 -0
  22. package/examples/adc_dac/hx711/minimal.js +16 -0
  23. package/examples/adc_dac/mcp4725/complete.js +19 -17
  24. package/examples/adc_dac/mcp4725/demo.js +5 -5
  25. package/examples/adc_dac/mcp4725/minimal.js +8 -6
  26. package/examples/adc_dac/mcp4728/complete.js +43 -0
  27. package/examples/adc_dac/mcp4728/demo.js +41 -0
  28. package/examples/adc_dac/mcp4728/minimal.js +13 -0
  29. package/examples/adc_dac/pcf8591/complete.js +41 -0
  30. package/examples/adc_dac/pcf8591/demo.js +39 -0
  31. package/examples/adc_dac/pcf8591/minimal.js +19 -0
  32. package/examples/comms/mcp2515/complete.js +75 -0
  33. package/examples/comms/mcp2515/demo.js +66 -0
  34. package/examples/comms/mcp2515/minimal.js +27 -0
  35. package/examples/comms/rda5807m/complete.js +55 -0
  36. package/examples/comms/rda5807m/demo.js +68 -0
  37. package/examples/comms/rda5807m/minimal.js +15 -0
  38. package/examples/comms/rfm9x/complete.js +50 -0
  39. package/examples/comms/rfm9x/demo.js +55 -0
  40. package/examples/comms/rfm9x/minimal.js +20 -0
  41. package/examples/display/pcf8576/complete.js +35 -0
  42. package/examples/display/pcf8576/demo.js +48 -0
  43. package/examples/display/pcf8576/minimal.js +20 -0
  44. package/examples/environmental/aht21/complete.js +32 -0
  45. package/examples/environmental/aht21/demo.js +46 -0
  46. package/examples/environmental/aht21/minimal.js +12 -0
  47. package/examples/environmental/bme280/complete.js +37 -0
  48. package/examples/environmental/bme280/demo.js +67 -0
  49. package/examples/environmental/bme280/minimal.js +20 -0
  50. package/examples/environmental/bme680/complete.js +40 -0
  51. package/examples/environmental/bme680/demo.js +54 -0
  52. package/examples/environmental/bme680/minimal.js +21 -0
  53. package/examples/gas/ens160/complete.js +54 -0
  54. package/examples/gas/ens160/demo.js +54 -0
  55. package/examples/gas/ens160/minimal.js +29 -0
  56. package/examples/gnss/neo6/complete.js +49 -0
  57. package/examples/gnss/neo6/demo.js +54 -0
  58. package/examples/gnss/neo6/minimal.js +30 -0
  59. package/examples/gyroscope/l3g4200d/complete.js +56 -0
  60. package/examples/gyroscope/l3g4200d/demo.js +49 -0
  61. package/examples/gyroscope/l3g4200d/minimal.js +19 -0
  62. package/examples/gyroscope/l3gd20h/complete.js +42 -0
  63. package/examples/gyroscope/l3gd20h/demo.js +29 -0
  64. package/examples/gyroscope/l3gd20h/minimal.js +13 -0
  65. package/examples/humidity/dht11/complete.js +22 -0
  66. package/examples/humidity/dht11/demo.js +38 -0
  67. package/examples/humidity/dht11/minimal.js +18 -0
  68. package/examples/imu/mpu6050/complete.js +58 -0
  69. package/examples/imu/mpu6050/demo.js +37 -0
  70. package/examples/imu/mpu6050/minimal.js +14 -0
  71. package/examples/imu/mpu9250/complete.js +65 -0
  72. package/examples/imu/mpu9250/demo.js +53 -0
  73. package/examples/imu/mpu9250/minimal.js +21 -0
  74. package/examples/imu/mpu9255/complete.js +73 -0
  75. package/examples/imu/mpu9255/demo.js +73 -0
  76. package/examples/imu/mpu9255/minimal.js +21 -0
  77. package/examples/io_expander/mcp23017/complete.js +70 -77
  78. package/examples/io_expander/mcp23017/demo.js +37 -33
  79. package/examples/io_expander/mcp23017/minimal.js +15 -11
  80. package/examples/io_expander/pcf8574/complete.js +60 -65
  81. package/examples/io_expander/pcf8574/demo.js +30 -25
  82. package/examples/io_expander/pcf8574/minimal.js +15 -11
  83. package/examples/io_expander/pcf8575/complete.js +24 -20
  84. package/examples/io_expander/pcf8575/demo.js +27 -23
  85. package/examples/io_expander/pcf8575/minimal.js +16 -12
  86. package/examples/io_expander/tpic6b595/complete.js +57 -0
  87. package/examples/io_expander/tpic6b595/demo.js +75 -0
  88. package/examples/io_expander/tpic6b595/minimal.js +26 -0
  89. package/examples/led/apa102/complete.js +72 -0
  90. package/examples/led/apa102/demo.js +92 -0
  91. package/examples/led/apa102/minimal.js +21 -0
  92. package/examples/led/sk6812rgbw/complete.js +42 -40
  93. package/examples/led/sk6812rgbw/demo.js +16 -16
  94. package/examples/led/sk6812rgbw/minimal.js +15 -17
  95. package/examples/led/ws2812b/complete.js +40 -38
  96. package/examples/led/ws2812b/demo.js +16 -16
  97. package/examples/led/ws2812b/minimal.js +13 -14
  98. package/examples/led/ws2814/complete.js +71 -0
  99. package/examples/led/ws2814/demo.js +82 -0
  100. package/examples/led/ws2814/minimal.js +23 -0
  101. package/examples/light/apds-9930/complete.js +46 -0
  102. package/examples/light/apds-9930/demo.js +31 -0
  103. package/examples/light/apds-9930/minimal.js +20 -0
  104. package/examples/light/apds9960/complete.js +64 -0
  105. package/examples/light/apds9960/demo.js +34 -0
  106. package/examples/light/apds9960/minimal.js +12 -0
  107. package/examples/magnetometer/as5600/complete.js +31 -29
  108. package/examples/magnetometer/as5600/demo.js +35 -33
  109. package/examples/magnetometer/as5600/minimal.js +7 -7
  110. package/examples/magnetometer/hmc5883l/complete.js +47 -0
  111. package/examples/magnetometer/hmc5883l/demo.js +50 -0
  112. package/examples/magnetometer/hmc5883l/minimal.js +15 -0
  113. package/examples/memory/24aa02uid/complete.js +42 -0
  114. package/examples/memory/24aa02uid/demo.js +42 -0
  115. package/examples/memory/24aa02uid/minimal.js +12 -0
  116. package/examples/other/mpr121/complete.js +50 -0
  117. package/examples/other/mpr121/demo.js +30 -0
  118. package/examples/other/mpr121/minimal.js +17 -0
  119. package/examples/power/ade7953/complete.js +44 -0
  120. package/examples/power/ade7953/demo.js +28 -0
  121. package/examples/power/ade7953/minimal.js +15 -0
  122. package/examples/power/ina219/complete.js +20 -18
  123. package/examples/power/ina219/demo.js +15 -13
  124. package/examples/power/ina219/minimal.js +8 -8
  125. package/examples/power/ina226/complete.js +24 -22
  126. package/examples/power/ina226/demo.js +22 -20
  127. package/examples/power/ina226/minimal.js +5 -5
  128. package/examples/power/ina3221/complete.js +51 -49
  129. package/examples/power/ina3221/demo.js +13 -13
  130. package/examples/power/ina3221/minimal.js +8 -8
  131. package/examples/pressure/bmp085/complete.js +29 -0
  132. package/examples/pressure/bmp085/demo.js +34 -0
  133. package/examples/pressure/bmp085/minimal.js +19 -0
  134. package/examples/pressure/bmp180/complete.js +20 -17
  135. package/examples/pressure/bmp180/demo.js +24 -22
  136. package/examples/pressure/bmp180/minimal.js +13 -11
  137. package/examples/pressure/bmp280/complete.js +29 -22
  138. package/examples/pressure/bmp280/demo.js +42 -23
  139. package/examples/pressure/bmp280/minimal.js +13 -11
  140. package/examples/pressure/bmp384/complete.js +29 -0
  141. package/examples/pressure/bmp384/demo.js +40 -0
  142. package/examples/pressure/bmp384/minimal.js +18 -0
  143. package/examples/pressure/bmp581/complete.js +34 -0
  144. package/examples/pressure/bmp581/demo.js +56 -0
  145. package/examples/pressure/bmp581/minimal.js +19 -0
  146. package/examples/pressure/lps22df/complete.js +50 -0
  147. package/examples/pressure/lps22df/demo.js +41 -0
  148. package/examples/pressure/lps22df/minimal.js +19 -0
  149. package/examples/pressure/lps28dfw/complete.js +37 -0
  150. package/examples/pressure/lps28dfw/demo.js +33 -0
  151. package/examples/pressure/lps28dfw/minimal.js +19 -0
  152. package/examples/pressure/lps33hw/complete.js +43 -0
  153. package/examples/pressure/lps33hw/demo.js +43 -0
  154. package/examples/pressure/lps33hw/minimal.js +19 -0
  155. package/examples/rfid/mfrc522/complete.js +44 -0
  156. package/examples/rfid/mfrc522/demo.js +70 -0
  157. package/examples/rfid/mfrc522/minimal.js +17 -0
  158. package/package.json +5 -1
  159. package/src/chips/accelerometer/adxl345.js +482 -0
  160. package/src/chips/accelerometer/adxl362.js +594 -0
  161. package/src/chips/adc_dac/ad7705.js +345 -0
  162. package/src/chips/adc_dac/ad7706.js +331 -0
  163. package/src/chips/adc_dac/hx710a.js +184 -0
  164. package/src/chips/adc_dac/hx710b.js +186 -0
  165. package/src/chips/adc_dac/hx711.js +165 -0
  166. package/src/chips/adc_dac/mcp4725.js +48 -40
  167. package/src/chips/adc_dac/mcp4728.js +297 -0
  168. package/src/chips/adc_dac/pcf8591.js +196 -0
  169. package/src/chips/comms/mcp2515.js +659 -0
  170. package/src/chips/comms/rda5807m.js +393 -0
  171. package/src/chips/comms/rfm9x.js +590 -0
  172. package/src/chips/display/pcf8576.js +232 -0
  173. package/src/chips/environmental/aht21.js +185 -0
  174. package/src/chips/environmental/bme280.js +385 -0
  175. package/src/chips/environmental/bme680.js +512 -0
  176. package/src/chips/gas/ens160.js +298 -0
  177. package/src/chips/gnss/neo6.js +438 -0
  178. package/src/chips/gyroscope/l3g4200d.js +366 -0
  179. package/src/chips/gyroscope/l3gd20h.js +314 -0
  180. package/src/chips/humidity/dht11.js +135 -0
  181. package/src/chips/imu/mpu6050.js +289 -0
  182. package/src/chips/imu/mpu9250.js +394 -0
  183. package/src/chips/imu/mpu9255.js +447 -0
  184. package/src/chips/io_expander/mcp23017.js +240 -157
  185. package/src/chips/io_expander/pcf8574.js +149 -124
  186. package/src/chips/io_expander/pcf8575.js +164 -135
  187. package/src/chips/io_expander/tpic6b595.js +242 -0
  188. package/src/chips/led/_NeoPixelRGBBase.js +204 -0
  189. package/src/chips/led/_NeoPixelRGBWBase.js +218 -0
  190. package/src/chips/led/apa102.js +236 -0
  191. package/src/chips/led/sk6812rgbw.js +15 -149
  192. package/src/chips/led/ws2812b.js +14 -139
  193. package/src/chips/led/ws2814.js +49 -0
  194. package/src/chips/light/apds-9930.js +342 -0
  195. package/src/chips/light/apds9960.js +499 -0
  196. package/src/chips/magnetometer/as5600.js +102 -82
  197. package/src/chips/magnetometer/hmc5883l.js +222 -0
  198. package/src/chips/memory/_24aa02uid.js +182 -0
  199. package/src/chips/other/mpr121.js +375 -0
  200. package/src/chips/power/ade7953.js +427 -0
  201. package/src/chips/power/ina219.js +45 -40
  202. package/src/chips/power/ina226.js +50 -45
  203. package/src/chips/power/ina3221.js +95 -76
  204. package/src/chips/pressure/bmp085.js +251 -0
  205. package/src/chips/pressure/bmp180.js +54 -37
  206. package/src/chips/pressure/bmp280.js +188 -206
  207. package/src/chips/pressure/bmp384.js +410 -0
  208. package/src/chips/pressure/bmp581.js +489 -0
  209. package/src/chips/pressure/lps22df.js +341 -0
  210. package/src/chips/pressure/lps28dfw.js +314 -0
  211. package/src/chips/pressure/lps33hw.js +255 -0
  212. package/src/chips/rfid/mfrc522.js +674 -0
  213. package/src/connection/connection.js +111 -0
  214. package/src/connection/dhtxx.js +138 -0
  215. package/src/connection/dhtxx_mock.js +39 -0
  216. package/src/connection/hx711.js +132 -0
  217. package/src/connection/hx711_mock.js +52 -0
  218. package/src/{transport → connection}/i2c.js +13 -9
  219. package/src/connection/i2c_mock.js +91 -0
  220. package/src/connection/input_pin.js +156 -0
  221. package/src/connection/neo6_mock.js +45 -0
  222. package/src/{transport → connection}/neopixel.js +23 -4
  223. package/src/connection/output_pin.js +41 -0
  224. package/src/connection/sipo.js +159 -0
  225. package/src/{transport → connection}/smbus.js +14 -10
  226. package/src/{transport → connection}/spi.js +12 -8
  227. package/src/connection/spi_mock.js +151 -0
  228. package/src/{transport → connection}/uart.js +33 -26
  229. package/examples/display/.gitkeep +0 -0
  230. package/examples/environmental/.gitkeep +0 -0
  231. package/examples/gnss/.gitkeep +0 -0
  232. package/examples/humidity/.gitkeep +0 -0
  233. package/examples/imu/.gitkeep +0 -0
  234. package/examples/light/.gitkeep +0 -0
  235. package/examples/pressure/.gitkeep +0 -0
  236. package/src/chips/display/.gitkeep +0 -0
  237. package/src/chips/environmental/.gitkeep +0 -0
  238. package/src/chips/gnss/.gitkeep +0 -0
  239. package/src/chips/imu/.gitkeep +0 -0
  240. package/src/chips/light/.gitkeep +0 -0
  241. package/src/chips/pressure/.gitkeep +0 -0
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { EEPROM24AA02UIDFull } = require('../../../src/chips/memory/_24aa02uid');
5
+
6
+ const connection = new I2CConnection(1, 0x50);
7
+ const eeprom = new EEPROM24AA02UIDFull(connection); // Create 24AA02UID driver, (connection, addr=0x50) → void
8
+
9
+ (async () => {
10
+ const uid = await eeprom.readUid(); // Read 32-bit unique serial number, () → Buffer
11
+ // reads 4 bytes at 0xFC-0xFF
12
+ console.log('UID bytes:', uid.toString('hex').toUpperCase());
13
+ const uidInt = uid.readUInt32BE(0);
14
+ console.log('UID int: ', uidInt);
15
+
16
+ const mfr = await eeprom.readManufacturerCode(); // Read manufacturer code, () → number
17
+ // reads 0xFA; expect 0x29 (Microchip)
18
+ const dev = await eeprom.readDeviceCode(); // Read device code, () → number
19
+ // reads 0xFB; expect 0x41
20
+ console.log('MFR: 0x' + mfr.toString(16).toUpperCase() + ' DEV: 0x' + dev.toString(16).toUpperCase());
21
+
22
+ const first = await eeprom.readByte(0x00); // Read a single byte, (address=0x00-0x7F) → number
23
+ // random read at user EEPROM address
24
+ console.log('First byte: 0x' + first.toString(16).toUpperCase());
25
+
26
+ await eeprom.writeByte(0x10, 0xA5); // Write a single byte, (address, value) → void
27
+ // byte write + ACK-poll until complete (max 5 ms)
28
+ const verify = await eeprom.readByte(0x10); // Read a single byte, (address=0x00-0x7F) → number
29
+ console.log('Wrote 0xA5, read back: 0x' + verify.toString(16).toUpperCase());
30
+
31
+ const block = await eeprom.read(0x20, 8); // Sequential read, (address, length) → Buffer
32
+ // reads 8 bytes starting at address
33
+ console.log('Block @ 0x20: ' + block.toString('hex'));
34
+
35
+ await eeprom.writePage(0x40, Buffer.from([0x01, 0x02, 0x03, 0x04])); // Page write, (address, data<=8 bytes) → void
36
+ // writes up to 8 bytes within one page; ACK-polls when done
37
+ await eeprom.write(0x44, Buffer.from([0xAA, 0xBB, 0xCC, 0xDD, 0xEE])); // Arbitrary-length write, (address, data) → void
38
+ // splits at 8-byte page boundaries; ACK-polls each chunk
39
+ console.log('Multi-page write complete');
40
+
41
+ await connection.close();
42
+ })();
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { EEPROM24AA02UIDFull } = require('../../../src/chips/memory/_24aa02uid');
5
+
6
+ const connection = new I2CConnection(1, 0x50);
7
+ const eeprom = new EEPROM24AA02UIDFull(connection); // Create 24AA02UID driver, (connection, addr=0x50) → void
8
+
9
+ (async () => {
10
+ // --- Read the chip's factory-programmed 32-bit serial number ---
11
+ // The UID at 0xFC-0xFF never changes and identifies the device
12
+ // across the entire 256-byte address space.
13
+ const uid = await eeprom.readUid(); // Read 32-bit unique serial number, () → Buffer
14
+ // reads 4 bytes at 0xFC-0xFF
15
+ console.log('Device UID: 0x' + uid.toString('hex').toUpperCase());
16
+ console.log('Device UID int:', uid.readUInt32BE(0));
17
+
18
+ // --- Maintain a 4-byte boot counter in user EEPROM at 0x00-0x03 ---
19
+ // Read the existing value (or zero on a fresh chip), increment,
20
+ // write back as 4 big-endian bytes. The user EEPROM is rewritable;
21
+ // the UID region above 0x80 is not, so the two stay independent.
22
+ const existing = await eeprom.read(0x00, 4); // Sequential read, (address, length) → Buffer
23
+ // reads 4 bytes from user EEPROM
24
+ let counter = existing.readUInt32BE(0);
25
+ counter += 1;
26
+ const updated = Buffer.alloc(4);
27
+ updated.writeUInt32BE(counter, 0);
28
+ await eeprom.write(0x00, updated); // Arbitrary-length write, (address, data) → void
29
+ // writes 4 bytes; ACK-polls when done
30
+ console.log('Boot count:', counter);
31
+
32
+ let n = 0;
33
+ setInterval(async () => {
34
+ // --- Loop reading the UID only, showing it never changes ---
35
+ // The two distinct areas of the chip (immutable identification
36
+ // above 0x80, rewritable storage below 0x80) are exercised
37
+ // independently.
38
+ const uid = await eeprom.readUid(); // Read 32-bit unique serial number, () → Buffer
39
+ console.log('[' + n + '] UID: 0x' + uid.toString('hex').toUpperCase() + ' (counter at user EEPROM 0x00-0x03)');
40
+ n++;
41
+ }, 2000);
42
+ })();
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { EEPROM24AA02UIDMinimal } = require('../../../src/chips/memory/_24aa02uid');
5
+
6
+ const connection = new I2CConnection(1, 0x50);
7
+ const eeprom = new EEPROM24AA02UIDMinimal(connection); // Create 24AA02UID driver, (connection, addr=0x50) → void
8
+
9
+ setInterval(async () => {
10
+ const uid = await eeprom.readUid(); // Read 32-bit unique serial number, () → Buffer
11
+ console.log('UID:', uid.toString('hex').toUpperCase());
12
+ }, 2000);
@@ -0,0 +1,50 @@
1
+ // Complete example for the MPR121 — exercises every Full-class method.
2
+
3
+ const { MPR121Full } = require('periph/src/chips/other/mpr121');
4
+ const { I2CConnection } = require('periph/src/connection/i2c_auto');
5
+
6
+ async function main() {
7
+ const connection = new I2CConnection(0x5A); // Create I2C connection, (addr=0x5A, bus=undefined) → I2CConnection
8
+ const mpr = new MPR121Full(connection); // Construct MPR121 Full, (connection) → MPR121Full
9
+ // runs Minimal init then exposes Full configuration methods
10
+
11
+ await mpr.stop(); // Enter Stop Mode, () → Promise<void>
12
+ // required before writing most config registers
13
+ await mpr.configureThresholds(0, 15, 8); // Set thresholds, (electrode=0, touch=15, release=8) → Promise<void>
14
+ // ELE0: touch at 15 LSBs below baseline, release at 8 LSBs
15
+ await mpr.configureAllThresholds(12, 6); // Apply thresholds to all, (touch=12, release=6) → Promise<void>
16
+ // ELE1..ELE11: same touch/release values
17
+ await mpr.configureProximityThresholds(8, 4); // Set ELEPROX thresholds, (touch=8, release=4) → Promise<void>
18
+ // ELEPROX touch at 8 LSBs, release at 4
19
+ await mpr.configureBaselineFilter(1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0); // Set baseline filter, (mhdr, nhdr, nclr, fdlr, mhdf, nhdf, nclf, fdlf, nhdt, nclt, fdlt) → Promise<void>
20
+ // baseline filter defaults; tracks capacitance drift only
21
+ await mpr.configureSampling(16, 1, 0, 0, 4); // Set AFE config, (cdc=16, cdt=1, ffi=0, sfi=0, esi=4) → Promise<void>
22
+ // 16 µA global CDC, 0.5 µs charge time, 16 ms sample interval
23
+ await mpr.configureDebounce(1, 1); // Set debounce, (touch=1, release=1) → Promise<void>
24
+ // one consecutive measurement to detect touch/release
25
+ await mpr.configureAutoconfig(3300, 0, false, true, true); // Configure autoconfig, (vdd_mv=3300, retry=0, scts=false, are=true, ace=true) → Promise<void>
26
+ // recompute USL/TL/LSL for 3.3 V supply
27
+ await mpr.start(12, 2, 0); // Enter Run Mode, (n_electrodes=12, cl=2, eleprox_en=0) → Promise<void>
28
+ // all 12 electrodes, baseline init from first measurement, proximity off
29
+
30
+ const f0 = await mpr.filtered(0); // Read ELE0 filtered, (electrode=0) → Promise<number> 0..1023
31
+ // raw 10-bit value, inversely proportional to capacitance
32
+ const b0 = await mpr.baseline(0); // Read ELE0 baseline, (electrode=0) → Promise<number> 0..1023
33
+ // 8 MSBs from baseline register, shifted left 2
34
+ const oor = await mpr.oorStatus(); // Read OOR bitmask, () → Promise<number> bitmask
35
+ // bits 0..11 = ELE0..11 out-of-range
36
+ const pt = await mpr.proximityTouched(); // Read proximity touched, () → Promise<boolean>
37
+ // False: ELEPROX not enabled in this example
38
+ console.log(`ELE0 filtered=${f0} baseline=${b0} OOR=0x${oor.toString(16).padStart(4, '0')} prox_touched=${pt}`);
39
+
40
+ await mpr.enableInterrupt(MPR121Full.SOURCE_OOR); // Enable interrupt source, (source=SOURCE_OOR) → Promise<void>
41
+ // OOR will now assert INT as well as touch/release
42
+ await mpr.disableInterrupt(MPR121Full.SOURCE_OOR); // Disable interrupt source, (source=SOURCE_OOR) → Promise<void>
43
+ // OOR no longer asserts INT
44
+ await mpr.clearOvercurrent(); // Clear OVCF, () → Promise<void>
45
+ // safe no-op when overcurrent has not occurred
46
+ await mpr.reset(); // Soft reset, () → Promise<void>
47
+ // reapplies Minimal defaults; device ready for fresh use
48
+ }
49
+
50
+ main().catch(err => { console.error(err); process.exit(1); });
@@ -0,0 +1,30 @@
1
+ // Demo for the MPR121 — 12-button musical keyboard with IRQ-driven detection.
2
+
3
+ const { MPR121Full } = require('periph/src/chips/other/mpr121');
4
+ const { I2CConnection } = require('periph/src/connection/i2c_auto');
5
+
6
+ const NOTES = ['C4', 'C#4', 'D4', 'D#4', 'E4', 'F4', 'F#4', 'G4', 'G#4', 'A4', 'A#4', 'B4'];
7
+
8
+ async function main() {
9
+ const connection = new I2CConnection(0x5A); // Create I2C connection, (addr=0x5A, bus=undefined) → I2CConnection
10
+ const mpr = new MPR121Full(connection); // Construct MPR121 Full, (connection) → MPR121Full
11
+ // defaults, all 12 electrodes enabled
12
+
13
+ let previous = 0;
14
+ setInterval(async () => {
15
+ const mask = await mpr.touched(); // Read 12-bit touch bitmask, () → Promise<number> bitmask
16
+ const newlyPressed = mask & ~previous;
17
+ const newlyReleased = (~mask) & previous;
18
+ for (let n = 0; n < 12; n++) {
19
+ if (newlyPressed & (1 << n)) {
20
+ console.log(`NOTE ON: ${NOTES[n]}`);
21
+ }
22
+ if (newlyReleased & (1 << n)) {
23
+ console.log(`NOTE OFF: ${NOTES[n]}`);
24
+ }
25
+ }
26
+ previous = mask;
27
+ }, 50);
28
+ }
29
+
30
+ main().catch(err => { console.error(err); process.exit(1); });
@@ -0,0 +1,17 @@
1
+ // Minimal example for the MPR121 capacitive touch controller.
2
+
3
+ const { MPR121Minimal } = require('periph/src/chips/other/mpr121');
4
+ const { I2CConnection } = require('periph/src/connection/i2c_auto');
5
+
6
+ async function main() {
7
+ const connection = new I2CConnection(0x5A); // Create I2C connection, (addr=0x5A, bus=undefined) → I2CConnection
8
+ const mpr = new MPR121Minimal(connection); // Construct MPR121 Minimal, (connection) → MPR121Minimal
9
+ // resets, applies default thresholds (T=12, R=6), enters Run Mode on all 12 electrodes
10
+ setInterval(async () => {
11
+ const t = await mpr.touched(); // Read 12-bit touch bitmask, () → Promise<number> bitmask
12
+ // bit n=1 means ELEn is currently touched
13
+ console.log(`touched=0x${t.toString(16).padStart(3, '0')}`);
14
+ }, 1000);
15
+ }
16
+
17
+ main().catch(err => { console.error(err); process.exit(1); });
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { ADE7953Full } = require('../../../src/chips/power/ade7953');
5
+
6
+ const connection = new I2CConnection(1, 0x38);
7
+ const ade = new ADE7953Full(connection, 251.0, 30.0); // Create ADE7953 driver, (connection, voltage_gain=V/V, current_gain=A/V, bus_type='i2c')
8
+
9
+ (async () => {
10
+ console.log('version:', (await ade.version()).toString(16)); // Read silicon version, () → int
11
+ console.log('V=', await ade.voltage()); // Read bus voltage, () → float V
12
+ // converts raw VRMS to volts using voltage_gain
13
+ console.log('I_a=', await ade.current()); // Read load current, () → float A
14
+ // converts raw IRMSA to amperes using current_gain
15
+ console.log('P_a=', await ade.activePower()); // Read active power, () → float W
16
+ // converts raw AWATT (instantaneous, 6.99 kHz) to watts
17
+ console.log('E_a=', await ade.activeEnergy()); // Read active energy, () → float Wh
18
+ // converts raw AENERGYA accumulated LSBs to watt-hours
19
+ console.log('PF=', await ade.powerFactor()); // Read power factor, () → float
20
+ // converts raw PFA (1 LSB = 2^-15) to a −1.0..+1.0 ratio
21
+ console.log('f=', await ade.lineFrequency()); // Read line frequency, () → float Hz
22
+
23
+ await ade.configureChannelB(30.0); // Set Channel B calibration, (current_gain_b) → None
24
+ console.log('I_b=', await ade.currentB()); // Read Current Channel B, () → float A
25
+
26
+ await ade.setPga('a', 1); // Write PGA Channel A, (channel, gain) → None
27
+ // gain 1..16 (+22 valid for Channel A only)
28
+ await ade.setPhaseCalibration('a', 0.0); // Write phase calibration A, (channel, delay_s) → None
29
+ // negative delay_s advances; range ±383 × 1.117 µs
30
+ await ade.setGainCalibration(0x282, 0x400000); // Write active-power gain A, (register, value) → None
31
+ // 0x400000 = unity; valid range 0x200000..0x600000
32
+ await ade.setOffsetCalibration(0x289, 0); // Write active-power offset A, (register, value) → None
33
+ // signed 24-bit offset
34
+ console.log('checksum:', (await ade.checksum()).toString(16)); // Read CRC/checksum, () → int
35
+ await ade.enableChecksum(true); // Enable CRC/checksum, (enabled) → None
36
+
37
+ await ade.configureOvervoltage(260.0); // Configure overvoltage, (threshold) → None
38
+ // threshold in volts (same scale as voltage())
39
+ await ade.configureOvercurrent(40.0); // Configure overcurrent, (threshold) → None
40
+ // threshold in amperes; applies to BOTH current channels
41
+
42
+ await ade.reset(); // Software reset, () → None
43
+ // waits 110 ms then re-runs the mandatory power-up sequence
44
+ })();
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { ADE7953Full } = require('../../../src/chips/power/ade7953');
5
+
6
+ const connection = new I2CConnection(1, 0x38);
7
+ const ade = new ADE7953Full(connection, 251.0, 30.0); // Create ADE7953 driver, (connection, voltage_gain=V/V, current_gain=A/V, bus_type='i2c')
8
+
9
+ // --- Prepare the chip: enable overcurrent interrupt and pin it to IRQ ---
10
+ // The ADE7953 exposes power-quality events via the IRQ pin. Driving
11
+ // OIA through the chip's own alert output lets the host react without
12
+ // polling every reading every cycle.
13
+ ade.configureOvercurrent(40.0); // Configure overcurrent, (threshold) → None
14
+
15
+ // --- Sample at 1 Hz and emit one structured line per cycle ---
16
+ // The energy accumulator resets on read by default (RSTREAD = 1), so
17
+ // activeEnergy() returns watt-hours accumulated since the previous
18
+ // call. Callers wanting a running total accumulate the returned deltas
19
+ // themselves (or call setReadWithReset(false) and track the 24-bit
20
+ // register's own rollovers instead).
21
+ console.log('%-10s %-10s %-10s %-12s'.replace(/%-?\d+s/g, (m) => m.padEnd(12)));
22
+ setInterval(async () => {
23
+ const v = await ade.voltage(); // Read bus voltage, () → float V
24
+ const i = await ade.current(); // Read load current, () → float A
25
+ const p = await ade.activePower(); // Read active power, () → float W
26
+ const e = await ade.activeEnergy(); // Read active energy, () → float Wh
27
+ console.log(`${v.toFixed(2).padEnd(10)} ${i.toFixed(3).padEnd(10)} ${p.toFixed(2).padEnd(10)} ${e.toFixed(5).padEnd(12)}`);
28
+ }, 1000);
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { ADE7953Minimal } = require('../../../src/chips/power/ade7953');
5
+
6
+ const connection = new I2CConnection(1, 0x38);
7
+ const ade = new ADE7953Minimal(connection, 251.0, 30.0); // Create ADE7953 driver, (connection, voltage_gain=V/V, current_gain=A/V, bus_type='i2c')
8
+
9
+ setInterval(async () => {
10
+ const v = await ade.voltage(); // Read bus voltage, () → float V
11
+ const i = await ade.current(); // Read load current, () → float A
12
+ const p = await ade.activePower(); // Read active power, () → float W
13
+ const e = await ade.activeEnergy(); // Read active energy, () → float Wh
14
+ console.log(`V=${v.toFixed(2)} I=${i.toFixed(3)} P=${p.toFixed(2)} E=${e.toFixed(4)}`);
15
+ }, 1000);
@@ -1,30 +1,32 @@
1
1
  'use strict';
2
2
 
3
- const { I2CTransport } = require('../../../src/transport/i2c');
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
4
  const { INA219Full } = require('../../../src/chips/power/ina219');
5
5
 
6
6
  const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
7
  const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x40', 16);
8
8
 
9
- const transport = new I2CTransport(I2C_BUS, I2C_ADDR);
10
- const ina = new INA219Full(transport);
9
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
10
+ const ina = new INA219Full(connection);
11
11
 
12
- console.log(ina.voltage()); // Read bus voltage, () → float V
13
- console.log(ina.shuntVoltage()); // Read shunt voltage, () → float V
14
- console.log(ina.current()); // Read load current, () → float A
15
- console.log(ina.power()); // Read power, () → float W
16
- console.log(ina.conversionReady()); // Check conversion done, () → bool
17
- console.log(ina.overflow()); // Check math overflow, () → bool
12
+ (async () => {
13
+ console.log(await ina.voltage()); // Read bus voltage, () → float V
14
+ console.log(await ina.shuntVoltage()); // Read shunt voltage, () → float V
15
+ console.log(await ina.current()); // Read load current, () → float A
16
+ console.log(await ina.power()); // Read power, () → float W
17
+ console.log(await ina.conversionReady()); // Check conversion done, () → bool
18
+ console.log(await ina.overflow()); // Check math overflow, () → bool
18
19
 
19
- ina.configure(1, 3, 0x03, 0x03, 7);
20
- // Configure ADC, (brng 0–1, pga 0–3, badc 0x0F, sadc 0x0F, mode 0–7) → None
21
- // sets bus range, PGA gain, ADC resolution, and operating mode
20
+ await ina.configure(1, 3, 0x03, 0x03, 7);
21
+ // Configure ADC, (brng 0–1, pga 0–3, badc 0x0F, sadc 0x0F, mode 0–7) → None
22
+ // sets bus range, PGA gain, ADC resolution, and operating mode
22
23
 
23
- ina.shutdown(); // Put chip into power-down mode, () → None
24
- const end = Date.now() + 1;
25
- while (Date.now() < end) {}
26
- ina.wake(); // Restore previous operating mode, () → None
24
+ await ina.shutdown(); // Put chip into power-down mode, () → None
25
+ const end = Date.now() + 1;
26
+ while (Date.now() < end) {}
27
+ await ina.wake(); // Restore previous operating mode, () → None
27
28
 
28
- ina.reset(); // Reset all registers and re-write calibration, () → None
29
+ await ina.reset(); // Reset all registers and re-write calibration, () → None
29
30
 
30
- transport.close();
31
+ await connection.close();
32
+ })();
@@ -1,26 +1,28 @@
1
1
  'use strict';
2
2
 
3
- const { I2CTransport } = require('../../../src/transport/i2c');
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
4
  const { INA219Full } = require('../../../src/chips/power/ina219');
5
5
 
6
6
  const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
7
  const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x40', 16);
8
8
 
9
- const transport = new I2CTransport(I2C_BUS, I2C_ADDR);
10
- const ina = new INA219Full(transport);
9
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
10
+ const ina = new INA219Full(connection);
11
11
 
12
12
  // --- Configure for noise-sensitive power rail monitoring ---
13
13
  // 128-sample averaging suppresses switching noise on a noisy 5 V rail;
14
14
  // continuous mode avoids re-triggering overhead between measurements.
15
- ina.configure(1, 3, 0x0F, 0x0F, 7);
16
- // Configure ADC, (brng 0–1, pga 0–3, badc 0x0F, sadc 0x0F, mode 0–7) → None
15
+ (async () => {
16
+ await ina.configure(1, 3, 0x0F, 0x0F, 7);
17
+ // Configure ADC, (brng 0–1, pga 0–3, badc 0x0F, sadc 0x0F, mode 0–7) → None
17
18
 
18
- console.log('V A W');
19
+ console.log('V A W');
19
20
 
20
- setInterval(() => {
21
- while (!ina.conversionReady()) {} // Check conversion done, () → bool
22
- const v = ina.voltage(); // Read bus voltage, () → float V
23
- const i = ina.current(); // Read load current, () → float A
24
- const p = ina.power(); // Read power, () → float W
25
- console.log(`${v.toFixed(3)} V ${i.toFixed(4)} A ${p.toFixed(4)} W`);
26
- }, 1000);
21
+ setInterval(async () => {
22
+ while (!(await ina.conversionReady())) {} // Check conversion done, () → bool
23
+ const v = await ina.voltage(); // Read bus voltage, () → float V
24
+ const i = await ina.current(); // Read load current, () → float A
25
+ const p = await ina.power(); // Read power, () → float W
26
+ console.log(`${v.toFixed(3)} V ${i.toFixed(4)} A ${p.toFixed(4)} W`);
27
+ }, 1000);
28
+ })();
@@ -1,17 +1,17 @@
1
1
  'use strict';
2
2
 
3
- const { I2CTransport } = require('../../../src/transport/i2c');
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
4
  const { INA219Minimal } = require('../../../src/chips/power/ina219');
5
5
 
6
6
  const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
7
  const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x40', 16);
8
8
 
9
- const transport = new I2CTransport(I2C_BUS, I2C_ADDR);
10
- const ina = new INA219Minimal(transport);
9
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
10
+ const ina = new INA219Minimal(connection);
11
11
 
12
- setInterval(() => {
13
- const v = ina.voltage(); // Read bus voltage, () → float V
14
- const i = ina.current(); // Read load current, () → float A
15
- const p = ina.power(); // Read power, () → float W
12
+ setInterval(async () => {
13
+ const v = await ina.voltage(); // Read bus voltage, () → float V
14
+ const i = await ina.current(); // Read load current, () → float A
15
+ const p = await ina.power(); // Read power, () → float W
16
16
  console.log(`${v.toFixed(3)} V ${i.toFixed(4)} A ${p.toFixed(4)} W`);
17
- }, 1000);
17
+ }, 1000);
@@ -1,33 +1,35 @@
1
1
  'use strict';
2
2
 
3
- const { I2CTransport } = require('../../../src/transport/i2c');
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
4
  const { INA226Full } = require('../../../src/chips/power/ina226');
5
5
 
6
- const transport = new I2CTransport(1, 0x40);
7
- const ina = new INA226Full(transport);
6
+ const connection = new I2CConnection(1, 0x40);
7
+ const ina = new INA226Full(connection);
8
8
 
9
- console.log('0x' + ina.manufacturerId().toString(16));
10
- console.log('0x' + ina.dieId().toString(16));
9
+ (async () => {
10
+ console.log('0x' + (await ina.manufacturerId()).toString(16));
11
+ console.log('0x' + (await ina.dieId()).toString(16));
11
12
 
12
- console.log(ina.voltage());
13
- console.log(ina.shuntVoltage());
14
- console.log(ina.current());
15
- console.log(ina.power());
16
- console.log(ina.conversionReady());
17
- console.log(ina.overflow());
13
+ console.log(await ina.voltage());
14
+ console.log(await ina.shuntVoltage());
15
+ console.log(await ina.current());
16
+ console.log(await ina.power());
17
+ console.log(await ina.conversionReady());
18
+ console.log(await ina.overflow());
18
19
 
19
- ina.configure(3, 4, 4, 7);
20
+ await ina.configure(3, 4, 4, 7);
20
21
 
21
- ina.setAlert(INA226Full.POL, 1.0, false, true);
22
- console.log('0x' + ina.alertFlags().toString(16));
22
+ await ina.setAlert(INA226Full.POL, 1.0, false, true);
23
+ console.log('0x' + (await ina.alertFlags()).toString(16));
23
24
 
24
- ina.setAlert(INA226Full.BOL, 5.5);
25
- ina.setAlert(INA226Full.BUL, 4.5);
26
- ina.setAlert(INA226Full.SOL, 0.05);
27
- ina.setAlert(INA226Full.CNVR);
25
+ await ina.setAlert(INA226Full.BOL, 5.5);
26
+ await ina.setAlert(INA226Full.BUL, 4.5);
27
+ await ina.setAlert(INA226Full.SOL, 0.05);
28
+ await ina.setAlert(INA226Full.CNVR);
28
29
 
29
- ina.shutdown();
30
- ina.wake();
31
- ina.reset();
30
+ await ina.shutdown();
31
+ await ina.wake();
32
+ await ina.reset();
32
33
 
33
- transport.close();
34
+ await connection.close();
35
+ })();
@@ -1,30 +1,32 @@
1
1
  'use strict';
2
2
 
3
- const { I2CTransport } = require('../../../src/transport/i2c');
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
4
  const { INA226Full } = require('../../../src/chips/power/ina226');
5
5
 
6
- const transport = new I2CTransport(1, 0x40);
7
- const ina = new INA226Full(transport);
6
+ const connection = new I2CConnection(1, 0x40);
7
+ const ina = new INA226Full(connection);
8
8
 
9
- // 64-sample averaging smooths out switching noise from DC/DC converters
10
- ina.configure(3, 4, 4, 7);
9
+ (async () => {
10
+ // 64-sample averaging smooths out switching noise from DC/DC converters
11
+ await ina.configure(3, 4, 4, 7);
11
12
 
12
- // latch the alert so a brief spike is not missed between loop iterations
13
- ina.setAlert(INA226Full.POL, 1.0, false, true);
13
+ // latch the alert so a brief spike is not missed between loop iterations
14
+ await ina.setAlert(INA226Full.POL, 1.0, false, true);
14
15
 
15
- console.log('V A W');
16
+ console.log('V A W');
16
17
 
17
- setInterval(() => {
18
- // wait for a fresh conversion to avoid reading stale register values
19
- while (!ina.conversionReady()) {}
18
+ setInterval(async () => {
19
+ // wait for a fresh conversion to avoid reading stale register values
20
+ while (!(await ina.conversionReady())) {}
20
21
 
21
- const v = ina.voltage();
22
- const i = ina.current();
23
- const p = ina.power();
24
- console.log(v.toFixed(3) + 'V ' + i.toFixed(4) + 'A ' + p.toFixed(4) + 'W');
22
+ const v = await ina.voltage();
23
+ const i = await ina.current();
24
+ const p = await ina.power();
25
+ console.log(v.toFixed(3) + 'V ' + i.toFixed(4) + 'A ' + p.toFixed(4) + 'W');
25
26
 
26
- // reading alertFlags clears the latch — do this after printing measurements
27
- if (ina.alertFlags() & INA226Full.AFF) {
28
- console.log('ALERT: power limit exceeded');
29
- }
30
- }, 1000);
27
+ // reading alertFlags clears the latch — do this after printing measurements
28
+ if ((await ina.alertFlags()) & INA226Full.AFF) {
29
+ console.log('ALERT: power limit exceeded');
30
+ }
31
+ }, 1000);
32
+ })();
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- const { I2CTransport } = require('../../../src/transport/i2c');
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
4
  const { INA226Minimal } = require('../../../src/chips/power/ina226');
5
5
 
6
- const transport = new I2CTransport(1, 0x40);
7
- const ina = new INA226Minimal(transport);
6
+ const connection = new I2CConnection(1, 0x40);
7
+ const ina = new INA226Minimal(connection);
8
8
 
9
- setInterval(() => {
10
- console.log(ina.voltage(), ina.current(), ina.power());
9
+ setInterval(async () => {
10
+ console.log(await ina.voltage(), await ina.current(), await ina.power());
11
11
  }, 1000);