periph 1.1.0 → 1.2.1

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 (266) hide show
  1. package/README.md +61 -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 +7 -7
  21. package/examples/adc_dac/hx711/demo.js +6 -6
  22. package/examples/adc_dac/hx711/minimal.js +7 -7
  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 +24 -22
  27. package/examples/adc_dac/mcp4728/demo.js +22 -22
  28. package/examples/adc_dac/mcp4728/minimal.js +8 -6
  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 +18 -15
  42. package/examples/display/pcf8576/demo.js +6 -6
  43. package/examples/display/pcf8576/minimal.js +12 -10
  44. package/examples/environmental/aht21/complete.js +15 -13
  45. package/examples/environmental/aht21/demo.js +8 -6
  46. package/examples/environmental/aht21/minimal.js +5 -5
  47. package/examples/environmental/bme280/complete.js +23 -20
  48. package/examples/environmental/bme280/demo.js +14 -14
  49. package/examples/environmental/bme280/minimal.js +13 -11
  50. package/examples/environmental/bme680/complete.js +25 -22
  51. package/examples/environmental/bme680/demo.js +38 -36
  52. package/examples/environmental/bme680/minimal.js +14 -12
  53. package/examples/gas/ens160/complete.js +29 -27
  54. package/examples/gas/ens160/demo.js +39 -37
  55. package/examples/gas/ens160/minimal.js +17 -15
  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 +27 -25
  69. package/examples/imu/mpu6050/demo.js +29 -26
  70. package/examples/imu/mpu6050/minimal.js +6 -6
  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 +45 -43
  105. package/examples/light/apds9960/demo.js +11 -9
  106. package/examples/light/apds9960/minimal.js +5 -5
  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 +23 -21
  114. package/examples/memory/24aa02uid/demo.js +32 -30
  115. package/examples/memory/24aa02uid/minimal.js +5 -5
  116. package/examples/motor/drv8830/complete.js +50 -0
  117. package/examples/motor/drv8830/demo.js +57 -0
  118. package/examples/motor/drv8830/minimal.js +23 -0
  119. package/examples/other/mpr121/complete.js +50 -0
  120. package/examples/other/mpr121/demo.js +30 -0
  121. package/examples/other/mpr121/minimal.js +17 -0
  122. package/examples/power/ade7953/complete.js +44 -0
  123. package/examples/power/ade7953/demo.js +28 -0
  124. package/examples/power/ade7953/minimal.js +15 -0
  125. package/examples/power/ina219/complete.js +20 -18
  126. package/examples/power/ina219/demo.js +15 -13
  127. package/examples/power/ina219/minimal.js +8 -8
  128. package/examples/power/ina226/complete.js +24 -22
  129. package/examples/power/ina226/demo.js +22 -20
  130. package/examples/power/ina226/minimal.js +5 -5
  131. package/examples/power/ina3221/complete.js +51 -49
  132. package/examples/power/ina3221/demo.js +13 -13
  133. package/examples/power/ina3221/minimal.js +8 -8
  134. package/examples/pressure/bmp085/complete.js +29 -0
  135. package/examples/pressure/bmp085/demo.js +34 -0
  136. package/examples/pressure/bmp085/minimal.js +19 -0
  137. package/examples/pressure/bmp180/complete.js +20 -17
  138. package/examples/pressure/bmp180/demo.js +24 -22
  139. package/examples/pressure/bmp180/minimal.js +13 -11
  140. package/examples/pressure/bmp280/complete.js +23 -20
  141. package/examples/pressure/bmp280/demo.js +44 -41
  142. package/examples/pressure/bmp280/minimal.js +13 -11
  143. package/examples/pressure/bmp384/complete.js +29 -0
  144. package/examples/pressure/bmp384/demo.js +40 -0
  145. package/examples/pressure/bmp384/minimal.js +18 -0
  146. package/examples/pressure/bmp581/complete.js +34 -0
  147. package/examples/pressure/bmp581/demo.js +56 -0
  148. package/examples/pressure/bmp581/minimal.js +19 -0
  149. package/examples/pressure/lps22df/complete.js +50 -0
  150. package/examples/pressure/lps22df/demo.js +41 -0
  151. package/examples/pressure/lps22df/minimal.js +19 -0
  152. package/examples/pressure/lps28dfw/complete.js +37 -0
  153. package/examples/pressure/lps28dfw/demo.js +33 -0
  154. package/examples/pressure/lps28dfw/minimal.js +19 -0
  155. package/examples/pressure/lps33hw/complete.js +43 -0
  156. package/examples/pressure/lps33hw/demo.js +43 -0
  157. package/examples/pressure/lps33hw/minimal.js +19 -0
  158. package/examples/rfid/mfrc522/complete.js +44 -0
  159. package/examples/rfid/mfrc522/demo.js +70 -0
  160. package/examples/rfid/mfrc522/minimal.js +17 -0
  161. package/examples/rtc/ds3231/complete.js +77 -0
  162. package/examples/rtc/ds3231/demo.js +60 -0
  163. package/examples/rtc/ds3231/minimal.js +23 -0
  164. package/examples/rtc/pcf8523/complete.js +66 -0
  165. package/examples/rtc/pcf8523/demo.js +65 -0
  166. package/examples/rtc/pcf8523/minimal.js +20 -0
  167. package/examples/temperature/mcp9808/complete.js +89 -0
  168. package/examples/temperature/mcp9808/demo.js +62 -0
  169. package/examples/temperature/mcp9808/minimal.js +21 -0
  170. package/examples/temperature/tmp117/complete.js +90 -0
  171. package/examples/temperature/tmp117/demo.js +73 -0
  172. package/examples/temperature/tmp117/minimal.js +21 -0
  173. package/examples/tof/vl53l0x/complete.js +118 -0
  174. package/examples/tof/vl53l0x/demo.js +83 -0
  175. package/examples/tof/vl53l0x/minimal.js +25 -0
  176. package/examples/tof/vl53l1x/complete.js +151 -0
  177. package/examples/tof/vl53l1x/demo.js +100 -0
  178. package/examples/tof/vl53l1x/minimal.js +25 -0
  179. package/package.json +5 -1
  180. package/src/chips/accelerometer/adxl345.js +482 -0
  181. package/src/chips/accelerometer/adxl362.js +594 -0
  182. package/src/chips/adc_dac/ad7705.js +345 -0
  183. package/src/chips/adc_dac/ad7706.js +331 -0
  184. package/src/chips/adc_dac/hx710a.js +184 -0
  185. package/src/chips/adc_dac/hx710b.js +186 -0
  186. package/src/chips/adc_dac/hx711.js +15 -15
  187. package/src/chips/adc_dac/mcp4725.js +48 -40
  188. package/src/chips/adc_dac/mcp4728.js +57 -44
  189. package/src/chips/adc_dac/pcf8591.js +196 -0
  190. package/src/chips/comms/mcp2515.js +659 -0
  191. package/src/chips/comms/rda5807m.js +393 -0
  192. package/src/chips/comms/rfm9x.js +590 -0
  193. package/src/chips/display/pcf8576.js +42 -33
  194. package/src/chips/environmental/aht21.js +52 -37
  195. package/src/chips/environmental/bme280.js +85 -66
  196. package/src/chips/environmental/bme680.js +110 -87
  197. package/src/chips/gas/ens160.js +82 -64
  198. package/src/chips/gnss/neo6.js +438 -0
  199. package/src/chips/gyroscope/l3g4200d.js +366 -0
  200. package/src/chips/gyroscope/l3gd20h.js +314 -0
  201. package/src/chips/humidity/dht11.js +135 -0
  202. package/src/chips/imu/mpu6050.js +89 -66
  203. package/src/chips/imu/mpu9250.js +394 -0
  204. package/src/chips/imu/mpu9255.js +447 -0
  205. package/src/chips/io_expander/mcp23017.js +240 -157
  206. package/src/chips/io_expander/pcf8574.js +149 -124
  207. package/src/chips/io_expander/pcf8575.js +164 -135
  208. package/src/chips/io_expander/tpic6b595.js +242 -0
  209. package/src/chips/led/_NeoPixelRGBBase.js +204 -0
  210. package/src/chips/led/_NeoPixelRGBWBase.js +218 -0
  211. package/src/chips/led/apa102.js +236 -0
  212. package/src/chips/led/sk6812rgbw.js +15 -149
  213. package/src/chips/led/ws2812b.js +14 -139
  214. package/src/chips/led/ws2814.js +49 -0
  215. package/src/chips/light/apds-9930.js +342 -0
  216. package/src/chips/light/apds9960.js +158 -123
  217. package/src/chips/magnetometer/as5600.js +102 -82
  218. package/src/chips/magnetometer/hmc5883l.js +222 -0
  219. package/src/chips/memory/_24aa02uid.js +32 -29
  220. package/src/chips/motor/drv8830.js +239 -0
  221. package/src/chips/other/mpr121.js +375 -0
  222. package/src/chips/power/ade7953.js +427 -0
  223. package/src/chips/power/ina219.js +45 -40
  224. package/src/chips/power/ina226.js +50 -45
  225. package/src/chips/power/ina3221.js +95 -76
  226. package/src/chips/pressure/bmp085.js +251 -0
  227. package/src/chips/pressure/bmp180.js +54 -37
  228. package/src/chips/pressure/bmp280.js +72 -53
  229. package/src/chips/pressure/bmp384.js +410 -0
  230. package/src/chips/pressure/bmp581.js +489 -0
  231. package/src/chips/pressure/lps22df.js +341 -0
  232. package/src/chips/pressure/lps28dfw.js +314 -0
  233. package/src/chips/pressure/lps33hw.js +255 -0
  234. package/src/chips/rfid/mfrc522.js +674 -0
  235. package/src/chips/rtc/ds3231.js +504 -0
  236. package/src/chips/rtc/pcf8523.js +539 -0
  237. package/src/chips/temperature/mcp9808.js +488 -0
  238. package/src/chips/temperature/tmp117.js +471 -0
  239. package/src/chips/tof/_vl53_base.js +160 -0
  240. package/src/chips/tof/vl53l0x.js +816 -0
  241. package/src/chips/tof/vl53l1x.js +816 -0
  242. package/src/connection/connection.js +111 -0
  243. package/src/connection/dhtxx.js +138 -0
  244. package/src/connection/dhtxx_mock.js +39 -0
  245. package/src/{transport → connection}/hx711.js +49 -22
  246. package/src/connection/hx711_mock.js +52 -0
  247. package/src/{transport → connection}/i2c.js +13 -9
  248. package/src/connection/i2c_mock.js +91 -0
  249. package/src/connection/input_pin.js +156 -0
  250. package/src/connection/neo6_mock.js +45 -0
  251. package/src/{transport → connection}/neopixel.js +23 -4
  252. package/src/connection/output_pin.js +41 -0
  253. package/src/connection/sipo.js +159 -0
  254. package/src/{transport → connection}/smbus.js +14 -10
  255. package/src/{transport → connection}/spi.js +12 -8
  256. package/src/connection/spi_mock.js +151 -0
  257. package/src/{transport → connection}/uart.js +33 -26
  258. package/examples/gnss/.gitkeep +0 -0
  259. package/examples/humidity/.gitkeep +0 -0
  260. package/examples/motor/.gitkeep +0 -0
  261. package/examples/temperature/.gitkeep +0 -0
  262. package/examples/tof/.gitkeep +0 -0
  263. package/src/chips/gnss/.gitkeep +0 -0
  264. package/src/chips/motor/.gitkeep +0 -0
  265. package/src/chips/temperature/.gitkeep +0 -0
  266. package/src/chips/tof/.gitkeep +0 -0
@@ -1,80 +1,73 @@
1
1
  'use strict';
2
- const { I2CTransport } = require('periph/src/transport/i2c');
2
+ const { I2CConnection } = require('periph/src/connection/i2c');
3
3
  const { Mcp23017Minimal, Mcp23017Full } = require('periph/src/chips/io_expander/mcp23017');
4
4
 
5
- const transport = new I2CTransport(1, 0x20); // Create I2C transport, (bus, addr=0x20)
6
- const chip = new Mcp23017Full(transport); // Create MCP23017 full driver, (transport, addr=0x20)
7
-
8
- // --- Pin proxy — synchronous API ---
9
- const p0 = chip.pin(0, 'out'); // Get full pin proxy, (n, direction='out') → FullPin
10
- // GPA0 as output (GPA7/GPB7 are output-only on hardware)
11
- console.log('direction:', p0.direction); // direction property, () → string 'in'|'out'
12
-
13
- p0.writeSync(1); // Write pin synchronously, (value=0|1) → void
14
- p0.writeSync(0); // Write pin synchronously, (value=0|1) → void
15
-
16
- const v = p0.readSync(); // Read pin synchronously, () → int 0|1
17
- // reads GPIOA, extracts bit 0
18
- console.log('GPA0 level:', v);
19
-
20
- // --- Async API ---
21
- p0.read((err, val) => { // Read pin async, (callback(err,val)) → void
22
- if (!err) console.log('async read:', val);
23
- });
24
-
25
- p0.write(1, (err) => { // Write pin async, (value, callback(err)) → void
26
- if (!err) console.log('async write done');
27
- });
28
-
29
- // --- Direction change ---
30
- p0.setDirection('in', (err) => { // Set direction, (direction, callback(err)) → void
31
- if (!err) console.log('now input');
32
- });
33
-
34
- // --- Port-level bulk operations ---
35
- const porta = chip.readPort(0); // Read all 8 pins, (port=0) → int bitmask
36
- // PORTA = GPIOA register
37
- const portb = chip.readPort(1); // Read all 8 pins, (port=1) → int bitmask
38
- // PORTB = GPIOB register
39
- console.log('PORTA=0x' + porta.toString(16).padStart(2,'0') + ' PORTB=0x' + portb.toString(16).padStart(2,'0'));
40
- chip.writePort(0, 0b00001111); // Write all 8 pins, (port, mask) → void
41
- // GPA0–GPA3 as outputs low, GPA4–GPA6 inputs, GPA7 output low
42
- chip.writePort(1, 0b11110000); // Write all 8 pins, (port, mask) → void
43
- // GPB0–GPB3 outputs low, GPB4–GPB7 outputs high
44
-
45
- // --- Pull-up configuration ---
46
- chip.configurePullup(0, 0b01111111); // Configure pull-ups, (port, mask) → void
47
- // enable pull-ups on GPA0–GPA6 (inputs); GPA7 is output, pull-up has no effect
48
-
49
- // --- Polarity inversion ---
50
- chip.configurePolarity(1, 0x00); // Configure polarity, (port, mask) → void
51
- // normal polarity on PORTB
52
-
53
- // --- Interrupt-on-change ---
54
- chip.configureInterrupt(0, null, (port, changed) => { // Attach interrupt, (port, intGpioPath, callback) → void
55
- console.log('PORTA changed: 0x' + changed.toString(16).padStart(2,'0'));
56
- });
57
- // null = use 5 ms polling; INTA fires on any GPA change
58
-
59
- const flags = chip.readInterruptFlags(0); // Read interrupt flags, (port) → int
60
- // INTFA register; 1 = corresponding pin caused interrupt
61
- console.log('INT flags PORTA: 0x' + flags.toString(16).padStart(2,'0'));
62
-
63
- const changed = chip.clearInterrupt(0); // Read and clear interrupt, (port) → int
64
- // INTCAPA captured state; also returns changed bitmask
65
- console.log('changed on init:', changed);
66
-
67
- // --- Per-pin watch ---
68
- const p1 = chip.pin(1, 'in'); // Get full pin proxy, (n, direction='in') → FullPin
69
- const watcher = (err, val) => console.log('GPA1 changed:', val);
70
- p1.watch(watcher); // Attach change handler, (handler(err,val)) → void
71
- // fires when GPA1 changes; needs configureInterrupt first
72
- p1.unwatch(watcher); // Remove change handler, (handler) → void
73
- p1.unwatchAll(); // Remove all handlers for pin, () → void
74
- p1.setActiveLow(false); // Set active-low inversion, (invert) → void
75
-
76
- // --- Stop interrupt ---
77
- chip.stopInterrupt(0); // Disable interrupt, (port) → void
78
- // clears GPINTENA; stops polling
79
-
80
- process.exit(0);
5
+ async function main() {
6
+ const connection = new I2CConnection(1, 0x20); // Create I2C connection, (bus, addr=0x20)
7
+ const chip = new Mcp23017Full(connection); // Create MCP23017 full driver, (connection, addr=0x20)
8
+
9
+ // --- Pin proxy — async API ---
10
+ const p0 = chip.pin(0, 'out'); // Get full pin proxy, (n, direction='out') → FullPin
11
+ // GPA0 as output (GPA7/GPB7 are output-only on hardware)
12
+ console.log('direction:', p0.direction); // direction property, () → string 'in'|'out'
13
+
14
+ await p0.write(1); // Write pin, (value=0|1) → Promise<void>
15
+ await p0.write(0); // Write pin, (value=0|1) → Promise<void>
16
+
17
+ const v = await p0.read(); // Read pin, () → Promise<int 0|1>
18
+ // reads GPIOA, extracts bit 0
19
+ console.log('GPA0 level:', v);
20
+
21
+ // --- Direction change ---
22
+ await p0.setDirection('in'); // Set direction, (direction) → Promise<void>
23
+ console.log('now input');
24
+
25
+ // --- Port-level bulk operations ---
26
+ const porta = await chip.readPort(0); // Read all 8 pins, (port=0) → Promise<int bitmask>
27
+ // PORTA = GPIOA register
28
+ const portb = await chip.readPort(1); // Read all 8 pins, (port=1) → Promise<int bitmask>
29
+ // PORTB = GPIOB register
30
+ console.log('PORTA=0x' + porta.toString(16).padStart(2, '0') + ' PORTB=0x' + portb.toString(16).padStart(2, '0'));
31
+ await chip.writePort(0, 0b00001111); // Write all 8 pins, (port, mask) → Promise<void>
32
+ // GPA0–GPA3 as outputs low, GPA4–GPA6 inputs, GPA7 output low
33
+ await chip.writePort(1, 0b11110000); // Write all 8 pins, (port, mask) → Promise<void>
34
+ // GPB0–GPB3 outputs low, GPB4–GPB7 outputs high
35
+
36
+ // --- Pull-up configuration ---
37
+ await chip.configurePullup(0, 0b01111111); // Configure pull-ups, (port, mask) → Promise<void>
38
+ // enable pull-ups on GPA0–GPA6 (inputs); GPA7 is output, pull-up has no effect
39
+
40
+ // --- Polarity inversion ---
41
+ await chip.configurePolarity(1, 0x00); // Configure polarity, (port, mask) → Promise<void>
42
+ // normal polarity on PORTB
43
+
44
+ // --- Interrupt-on-change (single port) ---
45
+ await chip.onInterruptPort(0, (changed) => { // Subscribe to INT on one port, (port, callback, options) → Promise<void>
46
+ console.log('PORTA changed: 0x' + changed.toString(16).padStart(2, '0'));
47
+ });
48
+ // no options.intPin = 5 ms polling fallback; INTA fires on any GPA change
49
+
50
+ const changed = await chip.pollInterrupt(0); // Read and clear interrupt, (port) → Promise<int>
51
+ // INTFA flags; also reads INTCAPA to clear
52
+ console.log('changed on init:', changed);
53
+
54
+ const captured = await chip.readCapture(0); // Read INTCAP, (port) → Promise<int>
55
+ // captured PORTA state at moment of interrupt; also clears
56
+ console.log('captured PORTA: 0x' + captured.toString(16).padStart(2, '0'));
57
+
58
+ // --- Per-pin watch ---
59
+ const p1 = chip.pin(1, 'in'); // Get full pin proxy, (n, direction='in') → FullPin
60
+ const watcher = (pin) => console.log('GPA1 changed, pin:', pin);
61
+ p1.watch(watcher, 'change'); // Subscribe to pin edges, (handler, trigger) → void
62
+ // fires when GPA1 changes; needs onInterruptPort(0, ...) armed first
63
+ p1.unwatch(); // Unsubscribe pin handler, () → void
64
+ p1.setActiveLow(false); // Set active-low inversion, (invert) → void
65
+
66
+ // --- Stop interrupt ---
67
+ await chip.offInterruptPort(0); // Unsubscribe PORTA, (port) → Promise<void>
68
+ // clears GPINTENA; stops polling
69
+
70
+ process.exit(0);
71
+ }
72
+
73
+ main();
@@ -12,48 +12,52 @@
12
12
  * active-low buttons), ORs it with the scanner position unless a button is
13
13
  * pressed, then writes to OLATA.
14
14
  */
15
- const { I2CTransport } = require('periph/src/transport/i2c');
15
+ const { I2CConnection } = require('periph/src/connection/i2c');
16
16
  const { Mcp23017Full } = require('periph/src/chips/io_expander/mcp23017');
17
17
 
18
- // --- Initialise bus and driver ---
19
- const transport = new I2CTransport(1, 0x20); // Create I2C transport, (bus, addr=0x20)
20
- const chip = new Mcp23017Full(transport); // Create MCP23017 full driver, (transport, addr=0x20)
18
+ async function main() {
19
+ // --- Initialise bus and driver ---
20
+ const connection = new I2CConnection(1, 0x20); // Create I2C connection, (bus, addr=0x20)
21
+ const chip = new Mcp23017Full(connection); // Create MCP23017 full driver, (connection, addr=0x20)
21
22
 
22
- // Enable pull-ups on PORTB inputs (GPB0–GPB6) so idle buttons read high.
23
- chip.configurePullup(1, 0b01111111); // Configure pull-ups, (port=1, mask) → void
23
+ // Enable pull-ups on PORTB inputs (GPB0–GPB6) so idle buttons read high.
24
+ await chip.configurePullup(1, 0b01111111); // Configure pull-ups, (port=1, mask) → Promise<void>
24
25
 
25
- // --- Wire interrupt for responsive button detection ---
26
- chip.configureInterrupt(1, null, (port, changed) => { // Attach interrupt, (port, intGpioPath, callback) → void
27
- // handled in the polling loop below
28
- });
26
+ // --- Wire interrupt for responsive button detection ---
27
+ await chip.onInterruptPort(1, (changed) => { // Subscribe to INT on one port, (port, callback, options) → Promise<void>
28
+ // handled in the polling loop below
29
+ });
29
30
 
30
- let position = 0;
31
- let direction = 1;
31
+ let position = 0;
32
+ let direction = 1;
32
33
 
33
- // --- Main loop: Knight Rider with button override ---
34
- console.log('Running — press buttons GPB0–GPB6 to light corresponding LEDs');
35
- setInterval(() => {
36
- const portb = chip.readPort(1); // Read all 8 pins, (port=1) → int bitmask
37
- // GPB0–GPB6 buttons: pressed = 0 (active-low pull-down)
34
+ // --- Main loop: Knight Rider with button override ---
35
+ console.log('Running — press buttons GPB0–GPB6 to light corresponding LEDs');
36
+ setInterval(async () => {
37
+ const portb = await chip.readPort(1); // Read all 8 pins, (port=1) → Promise<int bitmask>
38
+ // GPB0–GPB6 buttons: pressed = 0 (active-low pull-down)
38
39
 
39
- const buttons = portb & 0x7F; // mask GPA7 (output-only)
40
- const pressed = (~buttons) & 0x7F; // invert: pressed button = bit 1
40
+ const buttons = portb & 0x7F; // mask GPA7 (output-only)
41
+ const pressed = (~buttons) & 0x7F; // invert: pressed button = bit 1
41
42
 
42
- const scanner = 1 << position;
43
+ const scanner = 1 << position;
43
44
 
44
- let output;
45
- if (pressed) {
46
- output = pressed | (1 << 7); // keep GPA7 high (output-only)
47
- } else {
48
- output = scanner | (1 << 7);
49
- }
45
+ let output;
46
+ if (pressed) {
47
+ output = pressed | (1 << 7); // keep GPA7 high (output-only)
48
+ } else {
49
+ output = scanner | (1 << 7);
50
+ }
50
51
 
51
- chip.writePort(0, output); // Write all 8 pins, (port=0, mask) → void
52
+ await chip.writePort(0, output); // Write all 8 pins, (port=0, mask) → Promise<void>
52
53
 
53
- const ledStr = [...Array(7)].map((_, i) => (output >> i) & 1 ? '*' : ' ').join('');
54
- console.log('PORTA=0x' + output.toString(16).padStart(2,'0') + ' [' + ledStr + '] buttons=0x' + buttons.toString(16).padStart(2,'0'));
54
+ const ledStr = [...Array(7)].map((_, i) => (output >> i) & 1 ? '*' : ' ').join('');
55
+ console.log('PORTA=0x' + output.toString(16).padStart(2, '0') + ' [' + ledStr + '] buttons=0x' + buttons.toString(16).padStart(2, '0'));
55
56
 
56
- position += direction;
57
- if (position === 6) direction = -1;
58
- if (position === 0) direction = 1;
59
- }, 100);
57
+ position += direction;
58
+ if (position === 6) direction = -1;
59
+ if (position === 0) direction = 1;
60
+ }, 100);
61
+ }
62
+
63
+ main();
@@ -1,16 +1,20 @@
1
1
  'use strict';
2
- const { I2CTransport } = require('periph/src/transport/i2c');
2
+ const { I2CConnection } = require('periph/src/connection/i2c');
3
3
  const { Mcp23017Minimal } = require('periph/src/chips/io_expander/mcp23017');
4
4
 
5
- const transport = new I2CTransport(1, 0x20); // Create I2C transport, (bus, addr=0x20)
6
- const chip = new Mcp23017Minimal(transport); // Create MCP23017 driver, (transport, addr=0x20)
5
+ async function main() {
6
+ const connection = new I2CConnection(1, 0x20); // Create I2C connection, (bus, addr=0x20)
7
+ const chip = new Mcp23017Minimal(connection); // Create MCP23017 driver, (connection, addr=0x20)
7
8
 
8
- const p0 = chip.pin(0, 'out'); // Get pin proxy, (n, direction='out') → Pin
9
- const p8 = chip.pin(8, 'in'); // Get pin proxy, (n, direction='in') → Pin
9
+ const p0 = chip.pin(0, 'out'); // Get pin proxy, (n, direction='out') → Pin
10
+ const p8 = chip.pin(8, 'in'); // Get pin proxy, (n, direction='in') → Pin
10
11
 
11
- setInterval(() => {
12
- const porta = chip.readPort(0); // Read all 8 pins, (port=0) → int bitmask
13
- const portb = chip.readPort(1); // Read all 8 pins, (port=1) → int bitmask
14
- p0.writeSync((porta >> 1) & 1); // Write pin, (value=0|1) → void
15
- console.log('PORTA=0x' + porta.toString(16).padStart(2,'0') + ' PORTB=0x' + portb.toString(16).padStart(2,'0'));
16
- }, 200);
12
+ setInterval(async () => {
13
+ const porta = await chip.readPort(0); // Read all 8 pins, (port=0) → Promise<int bitmask>
14
+ const portb = await chip.readPort(1); // Read all 8 pins, (port=1) → Promise<int bitmask>
15
+ await p0.write((porta >> 1) & 1); // Write pin, (value=0|1) → Promise<void>
16
+ console.log('PORTA=0x' + porta.toString(16).padStart(2, '0') + ' PORTB=0x' + portb.toString(16).padStart(2, '0'));
17
+ }, 200);
18
+ }
19
+
20
+ main();
@@ -1,68 +1,63 @@
1
1
  'use strict';
2
- const { I2CTransport } = require('periph/src/transport/i2c');
2
+ const { I2CConnection } = require('periph/src/connection/i2c');
3
3
  const { Pcf8574Minimal, Pcf8574Full } = require('periph/src/chips/io_expander/pcf8574');
4
4
 
5
- const transport = new I2CTransport(1, 0x20); // Create I2C transport, (bus, addr=0x20)
6
- const chip = new Pcf8574Full(transport); // Create PCF8574 full driver, (transport, addr=0x20)
7
- // initialises all pins as inputs; shadow = 0xFF
8
-
9
- // --- Pin proxy — synchronous API ---
10
- const p0 = chip.pin(0, 'out'); // Get full pin proxy, (n, direction='out') → FullPin
11
- // drives P0 low initially; returns FullPin
12
- console.log('direction:', p0.direction); // direction property, () → string 'in'|'out'
13
- // reflects the direction set at pin() call time
14
-
15
- p0.writeSync(1); // Write pin synchronously, (value=0|1) → void
16
- // shadow |= (1<<0); quasi-high (input mode)
17
- p0.writeSync(0); // Write pin synchronously, (value=0|1) → void
18
- // shadow &= ~(1<<0); drives low
19
-
20
- const v = p0.readSync(); // Read pin synchronously, () → int 0|1
21
- // reads full port byte, extracts bit 0
22
- console.log('P0 level:', v);
23
-
24
- // --- Async API ---
25
- p0.read((err, val) => { // Read pin async, (callback(err,val)) → void
26
- if (!err) console.log('async read:', val); // wraps readSync; fires callback immediately
27
- });
28
-
29
- p0.write(1, (err) => { // Write pin async, (value, callback(err)) → void
30
- if (!err) console.log('async write done'); // wraps writeSync; fires callback immediately
31
- });
32
-
33
- // --- Direction change ---
34
- p0.setDirection('in', (err) => { // Set direction, (direction, callback(err)) → void
35
- if (!err) console.log('now input'); // updates shadow bit to 1 (input mode)
36
- });
37
-
38
- // --- Port-level bulk operations ---
39
- const mask = chip.readPort(); // Read all 8 pins, (port=0) → int bitmask
40
- // bit 0 = P0, bit 7 = P7
41
- console.log('port:', mask.toString(16));
42
- chip.writePort(0, 0b00001111); // Write all 8 pins, (port, mask) → void
43
- // P0–P3 low (outputs), P4–P7 high (inputs)
44
-
45
- // --- Input pin ---
46
- const p4 = chip.pin(4, 'in'); // Get full pin proxy, (n, direction='in') → FullPin
47
- const state = p4.readSync(); // Read pin synchronously, () → int
48
- // 0 if button pulls P4 low, 1 if floating
49
- console.log('P4:', state);
50
-
51
- // --- Interrupt-on-change ---
52
- chip.configureInterrupt(null, (changed) => { // Attach interrupt, (intGpioPath, callback) → void
53
- console.log('changed:', changed.toString(2).padStart(8,'0')); // null = use 5 ms polling
54
- });
55
-
56
- const changed = chip.clearInterrupt(); // Read and return changed bitmask, () → int
57
- // compares current byte to previous; clears INT
58
- console.log('changed on init:', changed);
59
-
60
- // --- Per-pin watch ---
61
- const p5 = chip.pin(5, 'in'); // Get full pin proxy, (n, direction='in') → FullPin
62
- const watcher = (err, val) => console.log('P5 changed:', val);
63
- p5.watch(watcher); // Attach change handler, (handler(err,val)) → void
64
- // fires whenever P5 changes; needs configureInterrupt
65
- p5.unwatch(watcher); // Remove change handler, (handler) → void
66
- p5.unexport(); // Release pin (no-op), () → void
67
-
68
- process.exit(0);
5
+ async function main() {
6
+ const connection = new I2CConnection(1, 0x20); // Create I2C connection, (bus, addr=0x20)
7
+ const chip = new Pcf8574Full(connection); // Create PCF8574 full driver, (connection, addr=0x20)
8
+ // initialises all pins as inputs; shadow = 0xFF
9
+
10
+ // --- Pin proxy — async API ---
11
+ const p0 = chip.pin(0, 'out'); // Get full pin proxy, (n, direction='out') → FullPin
12
+ // drives P0 low initially; returns FullPin
13
+ console.log('direction:', p0.direction); // direction property, () → string 'in'|'out'
14
+ // reflects the direction set at pin() call time
15
+
16
+ await p0.write(1); // Write pin, (value=0|1) → Promise<void>
17
+ // shadow |= (1<<0); quasi-high (input mode)
18
+ await p0.write(0); // Write pin, (value=0|1) → Promise<void>
19
+ // shadow &= ~(1<<0); drives low
20
+
21
+ const v = await p0.read(); // Read pin, () → Promise<int 0|1>
22
+ // reads full port byte, extracts bit 0
23
+ console.log('P0 level:', v);
24
+
25
+ // --- Direction change ---
26
+ await p0.setDirection('in'); // Set direction, (direction) → Promise<void>
27
+ // updates shadow bit to 1 (input mode)
28
+ console.log('now input');
29
+
30
+ // --- Port-level bulk operations ---
31
+ const mask = await chip.readPort(); // Read all 8 pins, (port=0) → Promise<int bitmask>
32
+ // bit 0 = P0, bit 7 = P7
33
+ console.log('port:', mask.toString(16));
34
+ await chip.writePort(0, 0b00001111); // Write all 8 pins, (port, mask) → Promise<void>
35
+ // P0–P3 low (outputs), P4–P7 high (inputs)
36
+
37
+ // --- Input pin ---
38
+ const p4 = chip.pin(4, 'in'); // Get full pin proxy, (n, direction='in') → FullPin
39
+ const state = await p4.read(); // Read pin, () → Promise<int>
40
+ // 0 if button pulls P4 low, 1 if floating
41
+ console.log('P4:', state);
42
+
43
+ // --- Interrupt-on-change ---
44
+ await chip.onInterrupt((changed) => { // Subscribe to INT line, (callback, options) → Promise<void>
45
+ console.log('changed:', changed.toString(2).padStart(8, '0')); // no options.intPin = 5 ms polling fallback
46
+ });
47
+
48
+ const changed = await chip.pollInterrupt(); // Read and return changed bitmask, () → Promise<int>
49
+ // compares current byte to previous; clears INT
50
+ console.log('changed on init:', changed);
51
+
52
+ // --- Per-pin watch ---
53
+ const p5 = chip.pin(5, 'in'); // Get full pin proxy, (n, direction='in') → FullPin
54
+ const watcher = (pin) => console.log('P5 changed, pin:', pin);
55
+ p5.watch(watcher, 'change'); // Subscribe to pin edges, (handler, trigger) → void
56
+ // fires whenever P5 changes; needs onInterrupt armed
57
+ p5.unwatch(); // Unsubscribe pin handler, () → void
58
+ p5.unexport(); // Release pin (no-op), () → void
59
+
60
+ process.exit(0);
61
+ }
62
+
63
+ main();
@@ -8,34 +8,39 @@
8
8
  *
9
9
  * Reads button nibble every 200 ms and mirrors it inverted to the LED nibble.
10
10
  */
11
- const { I2CTransport } = require('periph/src/transport/i2c');
12
- const { Pcf8574Full } = require('periph/src/chips/io_expander/pcf8574');
11
+ const { I2CConnection } = require('periph/src/connection/i2c');
12
+ const { Pcf8574Full } = require('periph/src/chips/io_expander/pcf8574');
13
13
 
14
- // --- Initialise bus and driver ---
15
- // All pins default to inputs (shadow = 0xFF). We immediately write 0xF0
16
- // to drive P0–P3 low (LEDs on) and keep P4–P7 as inputs (buttons).
17
- const transport = new I2CTransport(1, 0x20); // Create I2C transport, (bus, addr=0x20)
18
- const chip = new Pcf8574Full(transport); // Create PCF8574 full driver, (transport, addr=0x20)
14
+ async function main() {
15
+ // --- Initialise bus and driver ---
16
+ // All pins default to inputs (shadow = 0xFF). We immediately write 0xF0
17
+ // to drive P0–P3 low (LEDs on) and keep P4–P7 as inputs (buttons).
18
+ const connection = new I2CConnection(1, 0x20); // Create I2C connection, (bus, addr=0x20)
19
+ const chip = new Pcf8574Full(connection); // Create PCF8574 full driver, (connection, addr=0x20)
19
20
 
20
- chip.writePort(0, 0xF0); // Write all 8 pins, (port, mask) → void
21
+ await chip.writePort(0, 0xF0); // Write all 8 pins, (port, mask) → Promise<void>
21
22
 
22
- // --- Wire interrupt for responsive button detection ---
23
- // Using polling (null) since no GPIO-mapped INT line in this example.
24
- // Replace null with '/sys/class/gpio/gpio5/value' for edge-based delivery.
25
- chip.configureInterrupt(null, (changed) => { // Attach interrupt, (intGpioPath, callback) → void
26
- // flag is handled in the polling interval below
27
- });
23
+ // --- Wire interrupt for responsive button detection ---
24
+ // No options.intPin wired in this example, so onInterrupt() falls back
25
+ // to a 5 ms polling loop automatically. Pass { intPin } with a real
26
+ // InputPin (e.g. EpollInputPin) for edge-based delivery instead.
27
+ await chip.onInterrupt((changed) => { // Subscribe to INT line, (callback, options) → Promise<void>
28
+ // flag is handled in the polling interval below
29
+ });
28
30
 
29
- // --- Main loop: read buttons → mirror to LEDs ---
30
- console.log('Running — press buttons on P4–P7 to mirror to LEDs on P0–P3');
31
- setInterval(() => {
32
- const port = chip.readPort(); // Read all 8 pins, (port=0) → int bitmask
31
+ // --- Main loop: read buttons → mirror to LEDs ---
32
+ console.log('Running — press buttons on P4–P7 to mirror to LEDs on P0–P3');
33
+ setInterval(async () => {
34
+ const port = await chip.readPort(); // Read all 8 pins, (port=0) → Promise<int bitmask>
33
35
 
34
- const buttons = (port >> 4) & 0x0F; // bits 4–7: pressed = 0
35
- const leds = (~buttons) & 0x0F; // active-low: pressed → LED on (bit = 0)
36
- chip.writePort(0, 0xF0 | leds); // Write all 8 pins, (port, mask) → void
36
+ const buttons = (port >> 4) & 0x0F; // bits 4–7: pressed = 0
37
+ const leds = (~buttons) & 0x0F; // active-low: pressed → LED on (bit = 0)
38
+ await chip.writePort(0, 0xF0 | leds); // Write all 8 pins, (port, mask) → Promise<void>
37
39
 
38
- const btnStr = [...Array(4)].map((_, i) => (buttons >> i) & 1 ? '.' : 'X').join('');
39
- const ledStr = [...Array(4)].map((_, i) => (leds >> i) & 1 ? '*' : ' ').join('');
40
- console.log(`port=0x${port.toString(16).padStart(2,'0')} buttons=[${btnStr}] LEDs=[${ledStr}]`);
41
- }, 200);
40
+ const btnStr = [...Array(4)].map((_, i) => (buttons >> i) & 1 ? '.' : 'X').join('');
41
+ const ledStr = [...Array(4)].map((_, i) => (leds >> i) & 1 ? '*' : ' ').join('');
42
+ console.log(`port=0x${port.toString(16).padStart(2, '0')} buttons=[${btnStr}] LEDs=[${ledStr}]`);
43
+ }, 200);
44
+ }
45
+
46
+ main();
@@ -1,16 +1,20 @@
1
1
  'use strict';
2
- const { I2CTransport } = require('periph/src/transport/i2c');
2
+ const { I2CConnection } = require('periph/src/connection/i2c');
3
3
  const { Pcf8574Minimal } = require('periph/src/chips/io_expander/pcf8574');
4
4
 
5
- const transport = new I2CTransport(1, 0x20); // Create I2C transport, (bus, addr=0x20)
6
- const chip = new Pcf8574Minimal(transport); // Create PCF8574 driver, (transport, addr=0x20)
5
+ async function main() {
6
+ const connection = new I2CConnection(1, 0x20); // Create I2C connection, (bus, addr=0x20)
7
+ const chip = new Pcf8574Minimal(connection); // Create PCF8574 driver, (connection, addr=0x20)
7
8
 
8
- const p0 = chip.pin(0, 'out'); // Get pin proxy, (n, direction='out') → Pin
9
- const p4 = chip.pin(4, 'in'); // Get pin proxy, (n, direction='in') → Pin
9
+ const p0 = chip.pin(0, 'out'); // Get pin proxy, (n, direction='out') → Pin
10
+ const p4 = chip.pin(4, 'in'); // Get pin proxy, (n, direction='in') → Pin
10
11
 
11
- setInterval(() => {
12
- const port = chip.readPort(); // Read all 8 pins, (port=0) → int bitmask
13
- const btn = (port >> 4) & 1;
14
- p0.writeSync(btn ? 1 : 0); // Write pin, (value=0|1) → void
15
- console.log('port=0x' + port.toString(16).padStart(2, '0'));
16
- }, 200);
12
+ setInterval(async () => {
13
+ const port = await chip.readPort(); // Read all 8 pins, (port=0) → Promise<int bitmask>
14
+ const btn = (port >> 4) & 1;
15
+ await p0.write(btn ? 1 : 0); // Write pin, (value=0|1) → Promise<void>
16
+ console.log('port=0x' + port.toString(16).padStart(2, '0'));
17
+ }, 200);
18
+ }
19
+
20
+ main();
@@ -1,31 +1,35 @@
1
1
  'use strict';
2
2
  const { Pcf8575Minimal, Pcf8575Full } = require('../../src/chips/io_expander/pcf8575');
3
3
 
4
- const transport = {
5
- write: (buf) => { console.log('write', buf); },
6
- read: (len) => { return Buffer.from([0xFF, 0xFF]); }
4
+ const connection = {
5
+ async write(buf) { console.log('write', buf); },
6
+ async read(len) { return Buffer.from([0xFF, 0xFF]); }
7
7
  };
8
8
 
9
- const chip = new Pcf8575Full(transport, 0x20); // Create PCF8575 full driver, (transport, addr=0x20)
9
+ async function main() {
10
+ const chip = new Pcf8575Full(connection, 0x20); // Create PCF8575 full driver, (connection, addr=0x20)
10
11
 
11
- const p0 = chip.pin(0); // Get pin proxy, (n=0) → Pin
12
- p0.writeSync(0); // Write pin, (value=0|1) → void
13
- p0.writeSync(1); // Write pin, (value=0|1) → void
14
- const v = p0.readSync(); // Read pin, () → 0|1
12
+ const p0 = chip.pin(0); // Get pin proxy, (n=0) → Pin
13
+ await p0.write(0); // Write pin, (value=0|1) → Promise<void>
14
+ await p0.write(1); // Write pin, (value=0|1) → Promise<void>
15
+ const v = await p0.read(); // Read pin, () → Promise<0|1>
15
16
 
16
- const port0 = chip.readPort(0); // Read Port 0, (port=0) → int bitmask
17
- const port1 = chip.readPort(1); // Read Port 1, (port=1) → int bitmask
17
+ const port0 = await chip.readPort(0); // Read Port 0, (port=0) → Promise<int bitmask>
18
+ const port1 = await chip.readPort(1); // Read Port 1, (port=1) → Promise<int bitmask>
18
19
 
19
- chip.writePort(0, 0b00001111); // Write Port 0, (port=0, mask=int) → void
20
- chip.writePort(1, 0b00001111); // Write Port 1, (port=1, mask=int) → void
20
+ await chip.writePort(0, 0b00001111); // Write Port 0, (port=0, mask=int) → Promise<void>
21
+ await chip.writePort(1, 0b00001111); // Write Port 1, (port=1, mask=int) → Promise<void>
21
22
 
22
- const p8 = chip.pin(8); // Get pin proxy, (n=8) → Pin
23
- p8.setDirection('in'); // Set direction, (direction='in'|'out', cb) → void
24
- const state = p8.readSync(); // Read pin, () → 0|1
23
+ const p8 = chip.pin(8); // Get pin proxy, (n=8) → Pin
24
+ await p8.setDirection('in'); // Set direction, (direction='in'|'out') → Promise<void>
25
+ const state = await p8.read(); // Read pin, () → Promise<0|1>
25
26
 
26
- chip.configureInterrupt(null, (changed) => { // Attach interrupt, (int_gpio_path|null, callback) → void
27
- console.log('changed:', changed);
28
- });
27
+ await chip.onInterrupt((changed) => { // Subscribe to INT line, (callback, options) → Promise<void>
28
+ console.log('changed:', changed);
29
+ });
29
30
 
30
- const changed = chip.clearInterrupt(); // Read port and return 16-bit changed bitmask, () → int
31
- console.log('v:', v, 'port0:', port0, 'port1:', port1, 'state:', state, 'changed:', changed);
31
+ const changed = await chip.pollInterrupt(); // Read port and return 16-bit changed bitmask, () → Promise<int>
32
+ console.log('v:', v, 'port0:', port0, 'port1:', port1, 'state:', state, 'changed:', changed);
33
+ }
34
+
35
+ main();