periph 1.2.1 → 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 (123) hide show
  1. package/README.md +11 -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/pressure/bmp280/complete.js +1 -1
  48. package/examples/pressure/bmp280/demo.js +1 -1
  49. package/examples/pressure/bmp280/minimal.js +1 -1
  50. package/examples/pressure/bmp581/complete.js +1 -1
  51. package/examples/pressure/bmp581/demo.js +1 -1
  52. package/examples/pressure/bmp581/minimal.js +1 -1
  53. package/examples/pressure/lps22df/complete.js +1 -1
  54. package/examples/pressure/lps22df/demo.js +1 -1
  55. package/examples/pressure/lps22df/minimal.js +1 -1
  56. package/package.json +1 -1
  57. package/src/chips/accelerometer/adxl345.js +10 -31
  58. package/src/chips/accelerometer/adxl362.js +7 -7
  59. package/src/chips/accelerometer/bma150.js +419 -0
  60. package/src/chips/adc_dac/ad7705.js +36 -9
  61. package/src/chips/adc_dac/ad7706.js +39 -9
  62. package/src/chips/adc_dac/hy3131.js +311 -0
  63. package/src/chips/display/il0373.js +607 -0
  64. package/src/chips/display/ssd1331.js +412 -0
  65. package/src/chips/display/st7036.js +401 -0
  66. package/src/chips/display/uc1611s.js +648 -0
  67. package/src/chips/display/uc8159.js +394 -0
  68. package/src/chips/display/uc8276c.js +658 -0
  69. package/src/chips/environmental/bme280.js +31 -46
  70. package/src/chips/environmental/bme680.js +38 -43
  71. package/src/chips/gas/ens160.js +18 -26
  72. package/src/chips/gyroscope/l3g4200d.js +34 -50
  73. package/src/chips/gyroscope/l3gd20h.js +24 -40
  74. package/src/chips/imu/mpu6050.js +29 -41
  75. package/src/chips/imu/mpu9250.js +42 -66
  76. package/src/chips/imu/mpu9255.js +51 -75
  77. package/src/chips/io_expander/mcp23017.js +24 -33
  78. package/src/chips/light/apds-9930.js +52 -60
  79. package/src/chips/light/apds9960.js +69 -77
  80. package/src/chips/magnetometer/as5600.js +13 -27
  81. package/src/chips/magnetometer/hmc5883l.js +32 -29
  82. package/src/chips/memory/_23x1024.js +228 -0
  83. package/src/chips/memory/_24aa02uid.js +8 -11
  84. package/src/chips/memory/mx25l12845e.js +467 -0
  85. package/src/chips/memory/sd_spi.js +486 -0
  86. package/src/chips/motor/drv8830.js +4 -4
  87. package/src/chips/other/mpr121.js +7 -7
  88. package/src/chips/power/ina219.js +5 -8
  89. package/src/chips/power/ina226.js +5 -8
  90. package/src/chips/power/ina3221.js +5 -8
  91. package/src/chips/pressure/bmp085.js +17 -11
  92. package/src/chips/pressure/bmp180.js +7 -7
  93. package/src/chips/pressure/bmp280.js +21 -33
  94. package/src/chips/pressure/bmp384.js +28 -39
  95. package/src/chips/pressure/bmp581.js +59 -70
  96. package/src/chips/pressure/lps22df.js +50 -52
  97. package/src/chips/pressure/lps28dfw.js +15 -13
  98. package/src/chips/pressure/lps33hw.js +7 -5
  99. package/src/chips/rtc/ds3231.js +8 -8
  100. package/src/chips/rtc/pcf8523.js +8 -14
  101. package/src/chips/temperature/mcp9808.js +9 -7
  102. package/src/chips/temperature/tmp117.js +4 -4
  103. package/src/connection/connection.js +6 -4
  104. package/src/connection/dhtxx.js +5 -3
  105. package/src/connection/display.js +278 -0
  106. package/src/connection/display_mock.js +77 -0
  107. package/src/connection/hx711.js +5 -3
  108. package/src/connection/i2c.js +6 -4
  109. package/src/connection/i2c_mock.js +47 -0
  110. package/src/connection/input_pin.js +36 -5
  111. package/src/connection/register.js +14 -0
  112. package/src/connection/register_connection.js +65 -0
  113. package/src/connection/sipo.js +4 -2
  114. package/src/connection/sipo_mock.js +49 -0
  115. package/src/connection/smbus.js +6 -4
  116. package/src/connection/softspi.js +73 -0
  117. package/src/connection/spi.js +110 -23
  118. package/src/connection/spi_mock.js +50 -0
  119. package/src/connection/uart.js +2 -1
  120. package/src/discovery/discovery.js +218 -0
  121. package/src/discovery/registry.js +85 -0
  122. package/src/storage/block_device.js +95 -0
  123. package/src/storage/ram_block_device.js +72 -0
package/README.md CHANGED
@@ -30,6 +30,7 @@ Each chip exposes two classes:
30
30
 
31
31
  | Chip | Category | Require path |
32
32
  |------|----------|-------------|
33
+ | 23X1024 | Memory | `periph/src/chips/memory/_23x1024` |
33
34
  | 24AA02UID | Memory | `periph/src/chips/memory/_24aa02uid` |
34
35
  | AD7705 | ADC/DAC | `periph/src/chips/adc_dac/ad7705` |
35
36
  | AD7706 | ADC/DAC | `periph/src/chips/adc_dac/ad7706` |
@@ -41,6 +42,7 @@ Each chip exposes two classes:
41
42
  | APDS-9930 | Light sensor | `periph/src/chips/light/apds-9930` |
42
43
  | APDS9960 | Light sensor | `periph/src/chips/light/apds9960` |
43
44
  | AS5600 | Magnetometer | `periph/src/chips/magnetometer/as5600` |
45
+ | BMA150 | Accelerometer | `periph/src/chips/accelerometer/bma150` |
44
46
  | BME280 | Environmental sensor | `periph/src/chips/environmental/bme280` |
45
47
  | BME680 | Environmental sensor | `periph/src/chips/environmental/bme680` |
46
48
  | BMP085 | Pressure sensor | `periph/src/chips/pressure/bmp085` |
@@ -56,6 +58,8 @@ Each chip exposes two classes:
56
58
  | HX710A | ADC/DAC | `periph/src/chips/adc_dac/hx710a` |
57
59
  | HX710B | ADC/DAC | `periph/src/chips/adc_dac/hx710b` |
58
60
  | HX711 | ADC/DAC | `periph/src/chips/adc_dac/hx711` |
61
+ | HY3131 | ADC/DAC | `periph/src/chips/adc_dac/hy3131` |
62
+ | IL0373 | Display driver | `periph/src/chips/display/il0373` |
59
63
  | INA219 | Power monitor | `periph/src/chips/power/ina219` |
60
64
  | INA226 | Power monitor | `periph/src/chips/power/ina226` |
61
65
  | INA3221 | Power monitor | `periph/src/chips/power/ina3221` |
@@ -74,6 +78,7 @@ Each chip exposes two classes:
74
78
  | MPU6050 | IMU | `periph/src/chips/imu/mpu6050` |
75
79
  | MPU9250 | IMU | `periph/src/chips/imu/mpu9250` |
76
80
  | MPU9255 | IMU | `periph/src/chips/imu/mpu9255` |
81
+ | MX25L12845E | Memory | `periph/src/chips/memory/mx25l12845e` |
77
82
  | NEO6 | GNSS/GPS | `periph/src/chips/gnss/neo6` |
78
83
  | NEOPIXELRGBBASE | LED driver | `periph/src/chips/led/_NeoPixelRGBBase` |
79
84
  | NEOPIXELRGBWBASE | LED driver | `periph/src/chips/led/_NeoPixelRGBWBase` |
@@ -84,9 +89,15 @@ Each chip exposes two classes:
84
89
  | PCF8591 | ADC/DAC | `periph/src/chips/adc_dac/pcf8591` |
85
90
  | RDA5807M | Comms | `periph/src/chips/comms/rda5807m` |
86
91
  | RFM9X | Comms | `periph/src/chips/comms/rfm9x` |
92
+ | SD_SPI | Memory | `periph/src/chips/memory/sd_spi` |
87
93
  | SK6812RGBW | LED driver | `periph/src/chips/led/sk6812rgbw` |
94
+ | SSD1331 | Display driver | `periph/src/chips/display/ssd1331` |
95
+ | ST7036 | Display driver | `periph/src/chips/display/st7036` |
88
96
  | TMP117 | Temperature sensor | `periph/src/chips/temperature/tmp117` |
89
97
  | TPIC6B595 | IO expander | `periph/src/chips/io_expander/tpic6b595` |
98
+ | UC1611S | Display driver | `periph/src/chips/display/uc1611s` |
99
+ | UC8159 | Display driver | `periph/src/chips/display/uc8159` |
100
+ | UC8276C | Display driver | `periph/src/chips/display/uc8276c` |
90
101
  | VL53L0X | Time-of-flight | `periph/src/chips/tof/vl53l0x` |
91
102
  | VL53L1X | Time-of-flight | `periph/src/chips/tof/vl53l1x` |
92
103
  | WS2812B | LED driver | `periph/src/chips/led/ws2812b` |
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('periph/src/connection/i2c');
4
+ const { BMA150Full } = require('periph/src/chips/accelerometer/bma150');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x38', 16);
8
+
9
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
10
+ const accel = new BMA150Full(connection); // Create BMA150 Full driver, (connection)
11
+
12
+ (async () => {
13
+ await accel.setRange(8); // Set measurement range, (range_g) → g
14
+ // selects ±8 g; LSB scale changes from 256 to 64 LSB/g
15
+ await accel.setBandwidth(190); // Set bandwidth, (bandwidthHz) → Hz
16
+ // picks nearest valid value (190 Hz)
17
+ const raw = await accel.readRaw(); // Read raw 10-bit counts, () → [int, int, int]
18
+ // signed 10-bit two's-complement acceleration counts
19
+ const temp = await accel.readTemperature(); // Read temperature, () → °C
20
+ // 0.5 °C/LSB, 0x00 maps to −30 °C
21
+ const ready = await accel.newDataAvailable(); // Check new data, () → bool
22
+ // True once all three new_data_X/Y/Z bits are set
23
+ await accel.setShadow(false); // Set shadow mode, (enabled) → None
24
+ // keep LSB-then-MSB ordering (shadow_dis=0)
25
+
26
+ await accel.setLowG(0.4, 40); // Configure low-g, (thresholdG, durationMs, hysteresisG=0, counter=0) → g, ms
27
+ // 0.4 g threshold, 40 ms duration; enables SOURCE_LOW_G
28
+ await accel.setHighG(4.0, 2); // Configure high-g, (thresholdG, durationMs, hysteresisG=0, counter=0) → g, ms
29
+ // 4.0 g threshold, 2 ms duration; enables SOURCE_HIGH_G
30
+ await accel.setAnyMotion(0.5, 3); // Configure any-motion, (thresholdG, samples=1) → g, samples
31
+ // 0.5 g threshold, 3 consecutive samples; enables SOURCE_ANY_MOTION
32
+ await accel.setAlert(false); // Toggle alert mode, (enabled) → None
33
+ // mutually exclusive with any-motion; not used here
34
+ await accel.setLatch(true); // Set latched interrupts, (enabled) → None
35
+ // latched until clearInterrupt(); latch_INT=1
36
+
37
+ const status = await accel.pollInterrupt(); // Read STATUS, () → bitmask
38
+ // STATUS byte; does not clear latched bits
39
+ await accel.clearInterrupt(); // Clear latched interrupts, () → None
40
+ // writes reset_INT to CTRL (cleared on next sample)
41
+ await accel.setWakeUp(true, 80); // Set self-wake-up, (enabled, pauseMs=20) → ms
42
+ // 80 ms sleep portion of the cycle
43
+
44
+ const xyz = await accel.read(); // Read 3-axis acceleration, () → [number, number, number] g
45
+ // burst read of 0x02–0x07, scale 64 LSB/g
46
+ const [al, ml] = await accel.readVersion(); // Read version, () → [int, int]
47
+ // (al_version, ml_version) from VERSION register
48
+ const c1 = await accel.readCustomer(0); // Read scratch byte, (index) → byte
49
+ // 0 → CUSTOMER_1, 1 → CUSTOMER_2
50
+ await accel.writeCustomer(0, 0xA5); // Write scratch byte, (index, value) → None
51
+ // 0xA5 into CUSTOMER_1
52
+ const st = await accel.selfTest(); // Run self-test, () → bool
53
+ // electrostatic self-test; reads STATUS.st_result
54
+ await accel.softReset(); // Soft reset, () → None
55
+ // CTRL.soft_reset=1; 30 ms wait; range/bandwidth restored
56
+ await accel.sleep(); // Enter sleep mode, () → None
57
+ await accel.wake(); // Leave sleep mode, () → None
58
+ // 1.5 ms settle wait
59
+
60
+ console.log(`raw=${JSON.stringify(raw)} temp=${temp.toFixed(1)} status=0x${status.toString(16)} al=${al} ml=${ml} c1=0x${c1.toString(16)} st=${st ? 'PASS' : 'FAIL'} xyz=[${xyz.map(v => v.toFixed(3)).join(', ')}]`);
61
+ await connection.close();
62
+ })();
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('periph/src/connection/i2c');
4
+ const { BMA150Full } = require('periph/src/chips/accelerometer/bma150');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x38', 16);
8
+
9
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
10
+ const accel = new BMA150Full(connection); // Create BMA150 driver, (connection)
11
+
12
+ // --- Configure ±8 g / 190 Hz and arm LG + HG latched interrupts ---
13
+ // ±8 g gives 64 LSB/g, plenty of headroom for shock detection. 190 Hz
14
+ // bandwidth is wide enough to capture a 2 ms high-g spike without
15
+ // aliasing. Latched interrupts free the polling loop from having to
16
+ // catch a transient.
17
+ async function setup() {
18
+ await accel.setRange(8); // Set measurement range, (rangeG=2) → g
19
+ await accel.setBandwidth(190); // Set bandwidth, (bandwidthHz=25) → Hz
20
+ await accel.setLatch(true); // Set latched interrupts, (enabled=false) → None
21
+ await accel.setLowG(0.4, 40); // Configure low-g, (thresholdG, durationMs, hysteresisG=0, counter=0) → g, ms
22
+ await accel.setHighG(4.0, 2); // Configure high-g, (thresholdG, durationMs, hysteresisG=0, counter=0) → g, ms
23
+ }
24
+
25
+ // --- 60-second free-fall / shock logger ---
26
+ // User is expected to drop or shake the board at some point during
27
+ // the 60 s window. Between events the magnitude sits at ≈1.00 g
28
+ // (gravity). Each latched interrupt is reported with a timestamp,
29
+ // the latest (x, y, z), temperature, and a free-fall or shock tag.
30
+ (async () => {
31
+ await setup();
32
+ const start = Date.now();
33
+ let lastHeartbeat = 0;
34
+ let lastPoll = 0;
35
+
36
+ while (Date.now() - start < 60000) {
37
+ const now = Date.now();
38
+ if (now - lastHeartbeat >= 1000) {
39
+ const [x, y, z] = await accel.read(); // Read 3-axis acceleration, () → [number, number, number] g
40
+ const mag = Math.sqrt(x * x + y * y + z * z);
41
+ const temp = await accel.readTemperature(); // Read temperature, () → °C
42
+ console.log(`${String(Math.floor((now - start) / 1000)).padStart(5)} x=${x.toFixed(3).padStart(7)} y=${y.toFixed(3).padStart(7)} z=${z.toFixed(3).padStart(7)} |a|=${mag.toFixed(3)} g T=${temp.toFixed(1)} C`);
43
+ lastHeartbeat = now;
44
+ }
45
+ if (now - lastPoll >= 50) {
46
+ const status = await accel.pollInterrupt(); // Read STATUS, () → bitmask
47
+ if (status & 0x08) { // STATUS_LG_LATCHED (bit 3)
48
+ const [x, y, z] = await accel.read(); // Read 3-axis acceleration, () → [number, number, number] g
49
+ const temp = await accel.readTemperature();// Read temperature, () → °C
50
+ console.log(`${String(Math.floor((now - start) / 1000)).padStart(5)} FREE FALL detected x=${x.toFixed(3)} y=${y.toFixed(3)} z=${z.toFixed(3)} T=${temp.toFixed(1)} C`);
51
+ await accel.clearInterrupt(); // Clear latched interrupts, () → None
52
+ }
53
+ if (status & 0x04) { // STATUS_HG_LATCHED (bit 2)
54
+ const [x, y, z] = await accel.read(); // Read 3-axis acceleration, () → [number, number, number] g
55
+ const temp = await accel.readTemperature();// Read temperature, () → °C
56
+ console.log(`${String(Math.floor((now - start) / 1000)).padStart(5)} SHOCK detected x=${x.toFixed(3)} y=${y.toFixed(3)} z=${z.toFixed(3)} T=${temp.toFixed(1)} C`);
57
+ await accel.clearInterrupt(); // Clear latched interrupts, () → None
58
+ }
59
+ lastPoll = now;
60
+ }
61
+ await new Promise(r => setTimeout(r, 10));
62
+ }
63
+ console.log('done');
64
+ await connection.close();
65
+ })();
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('periph/src/connection/i2c');
4
+ const { BMA150Minimal } = require('periph/src/chips/accelerometer/bma150');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x38', 16);
8
+
9
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
10
+ const accel = new BMA150Minimal(connection); // Create BMA150 driver, (connection)
11
+
12
+ (async () => {
13
+ for (let i = 0; i < 10; i++) {
14
+ const [x, y, z] = await accel.read(); // Read 3-axis acceleration, () → [number, number, number] g
15
+ console.log(`x=${x.toFixed(3)} y=${y.toFixed(3)} z=${z.toFixed(3)} g`);
16
+ }
17
+ await connection.close();
18
+ })();
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ const spi = require('spi-device');
4
+ const { SPIConnection } = require('../../../src/connection/spi');
5
+ const { HY3131Full } = require('../../../src/chips/adc_dac/hy3131');
6
+
7
+ const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
8
+ const SPI_DEV = parseInt(process.env.SPI_DEV || '0', 10);
9
+
10
+ (async () => {
11
+ const connection = new SPIConnection(SPI_BUS, SPI_DEV, { mode: spi.MODE0, maxSpeedHz: 1_000_000 });
12
+ const adc = await HY3131Full.create(connection); // Create and initialise HY3131 driver, (connection, vref=1.2 V) → HY3131Full
13
+ // resets the chip and applies the Minimal defaults (AD1 on PB2/AGND, 5 Hz)
14
+
15
+ await adc.configureAd1({ osr: 4, chop: 2, inputGain: 0, refGain: 0, offset: 0, buffers: 0 }); // Configure AD1, ({osr=7, chop=0, inputGain=0, refGain=0, offset=0, buffers=0}) → None
16
+ // OSR 4096 (~40 Hz), chopper on (offset cancelled, rate halved), gain 0.9
17
+ await adc.setAd1Input(10, 3, 2); // Select AD1 inputs, (pos=SAD1FP 0–15, neg=SAD1FN 0–7, filterR=2) → None
18
+ // PB2 vs AGND with the filter resistor bypassed
19
+ await adc.setAd1Reference(1, 1); // Select AD1 reference, (high=0–6, low=0–6) → None
20
+ // REFO (+) / AGND (−)
21
+
22
+ const raw = await adc.readRaw(); // Read AD1 code, () → int 24-bit
23
+ // waits for AD1F in INTF, returns the sign-extended code
24
+ const v = await adc.readVoltage(); // Read AD1 voltage, () → float V
25
+ // code / 2^23 · RG − DCOS, scaled by vref / input gain
26
+ console.log('raw=', raw, 'v=', v);
27
+
28
+ const tcode = await adc.readTemperatureCode(); // Read temperature code, () → int
29
+ // (AD1[TS pair 2] − AD1[TS pair 1]) / 2; note this value at 25 °C
30
+ const t = await adc.readTemperature(tcode); // Read die temperature, (tcode25) → float °C
31
+ // one-point calibrated against tcode25
32
+ console.log('temperature=', t);
33
+
34
+ await adc.enableAd2({ osr: 5, inputGain: 1, refGain: 0, chop: false, clkDiv4: false, source: 0, useAd3: false }); // Enable AD2, ({osr=5, inputGain=1, refGain=0, chop=false, clkDiv4=false, source=0, useAd3=false}) → None
35
+ // AD2 samples OP1O at gain 1.0, OSR 1024
36
+ const ad2 = await adc.readAd2Raw(); // Read AD2 code, () → int 19-bit
37
+ // waits for AD2F
38
+ await adc.enableLpf(0); // Enable low-pass filter, (bw=0) → None
39
+ // OSR4 = 128
40
+ const lpf = await adc.readLpfRaw(); // Read LPF code, () → int 19-bit
41
+ // waits for LPFF
42
+ await adc.enableRms(); // Enable RMS converter, () → None
43
+ // accumulates the squared LPF input
44
+ const rms = await adc.readRms(); // Read RMS, () → float LSB
45
+ // square root of the accumulator
46
+ await adc.enablePeakHold(0); // Enable peak hold, (source=0) → None
47
+ // tracks AD2 min/max; re-enabling resets
48
+ const pk = await adc.readPeak(); // Read peak hold, () → {min, max} 19-bit
49
+ console.log('ad2=', ad2, 'lpf=', lpf, 'rms=', rms, 'peak=', pk.min, pk.max);
50
+
51
+ await adc.startCounter(0); // Start frequency counter, (gatePreload=0) → None
52
+ // enables the CNT buffer and the counter
53
+ const ct = await adc.readCounter(); // Read counter, () → {cta, ctb, ctc, overflow}
54
+ // waits for CTF; overflow=true means the measurement is invalid
55
+ console.log('counter=', ct);
56
+
57
+ await adc.enableInterrupts(0x04); // Enable interrupts, (mask) → None
58
+ // AD1IE: DO goes high while CS is high and AD1F is set
59
+ const flags = await adc.readFlags(); // Read and clear INTF, () → int
60
+ // bit 2 = AD1F
61
+ console.log('flags=', flags);
62
+
63
+ await adc.reset(); // Software reset, () → None
64
+ // writes 0x60 to R37 and re-applies the Minimal defaults
65
+ await connection.close();
66
+ })();
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ const spi = require('spi-device');
4
+ const { SPIConnection } = require('../../../src/connection/spi');
5
+ const { HY3131Full } = require('../../../src/chips/adc_dac/hy3131');
6
+
7
+ const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
8
+ const SPI_DEV = parseInt(process.env.SPI_DEV || '0', 10);
9
+
10
+ (async () => {
11
+ const connection = new SPIConnection(SPI_BUS, SPI_DEV, { mode: spi.MODE0, maxSpeedHz: 1_000_000 }); // Create SPI connection, (bus=0, device=0, mode=0, maxSpeedHz=1_000_000) → SPIConnection
12
+
13
+ // --- Bench voltmeter with on-chip temperature and AC analysis ---
14
+ // A 0–1.2 V source sits between PB2 and AGND. AD1 runs at ~40 Hz with the chopper on
15
+ // for offset-free DC readings; AD2 + LPF + RMS + peak hold watch the same node for AC.
16
+ const adc = await HY3131Full.create(connection); // Create and initialise HY3131 driver, (connection, vref=1.2 V) → HY3131Full
17
+ await adc.configureAd1({ osr: 4, chop: 2 }); // Configure AD1, ({osr=7, chop=0, inputGain=0, refGain=0, offset=0, buffers=0}) → None
18
+
19
+ // --- One-point temperature calibration ---
20
+ // Run the board at 25 °C (or replace with a stored constant) and remember the code.
21
+ const tcode25 = await adc.readTemperatureCode(); // Read temperature code, () → int
22
+
23
+ // --- Enable AC measurement chain on the same input ---
24
+ await adc.enableAd2({ osr: 5, inputGain: 1, source: 2 }); // Enable AD2, ({osr=5, inputGain=1, refGain=0, chop=false, clkDiv4=false, source=0, useAd3=false}) → None
25
+ await adc.enableLpf(3); // Enable low-pass filter, (bw=0) → None
26
+ await adc.enableRms(); // Enable RMS converter, () → None
27
+ await adc.enablePeakHold(0); // Enable peak hold, (source=0) → None
28
+
29
+ for (;;) {
30
+ const v = await adc.readVoltage(); // Read AD1 voltage, () → float V
31
+ const t = await adc.readTemperature(tcode25); // Read die temperature, (tcode25) → float °C
32
+ const rms = await adc.readRms(); // Read RMS, () → float LSB
33
+ const pk = await adc.readPeak(); // Read peak hold, () → {min, max} 19-bit
34
+ console.log(`V=${v.toFixed(4)} V T=${t.toFixed(1)} C rms=${rms.toFixed(0)} p-p=${pk.max - pk.min}`);
35
+ await new Promise((r) => setTimeout(r, 1000));
36
+ }
37
+ })();
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ const spi = require('spi-device');
4
+ const { SPIConnection } = require('../../../src/connection/spi');
5
+ const { HY3131Minimal } = require('../../../src/chips/adc_dac/hy3131');
6
+
7
+ const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
8
+ const SPI_DEV = parseInt(process.env.SPI_DEV || '0', 10);
9
+
10
+ (async () => {
11
+ const connection = new SPIConnection(SPI_BUS, SPI_DEV, { mode: spi.MODE0, maxSpeedHz: 1_000_000 }); // Create SPI connection, (bus=0, device=0, mode=0, maxSpeedHz=1_000_000) → SPIConnection
12
+ const adc = await HY3131Minimal.create(connection); // Create and initialise HY3131 driver, (connection, vref=1.2 V) → HY3131Minimal
13
+
14
+ for (;;) {
15
+ const v = await adc.readVoltage(); // Read AD1 differential voltage, () → float V
16
+ console.log(v.toFixed(5));
17
+ }
18
+ })();
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+ const { scan, scanDetailed, discover } = require('../../src/discovery/discovery');
3
+
4
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
5
+
6
+ (async () => {
7
+ const addresses = await scan(I2C_BUS); // Scan bus, (bus=1, first=0x08, last=0x77) → number[] 7-bit addresses
8
+ // zero-length write per address, read byte on 0x30-0x37 / 0x50-0x5F; EBUSY counts as present
9
+ console.log(addresses.map(a => '0x' + a.toString(16)));
10
+
11
+ const detail = await scanDetailed(I2C_BUS); // Scan with kernel-binding info, (bus=1, first=0x08, last=0x77) → Map<number, boolean>
12
+ // value is true when a kernel driver owns the address (i2cdetect "UU")
13
+ console.log([...detail.entries()]);
14
+
15
+ let devices = await discover(I2C_BUS); // Discover chips, (bus=1, {active=false, registry}) → DiscoveredDevice[]
16
+ // identity reads confirm a chip only when exactly one candidate matches
17
+ for (const dev of devices) {
18
+ console.log(dev.address, dev.candidates, dev.identified, dev.driver, dev.inUseByKernel, dev.probeSkippedReason, dev.aliases);
19
+ }
20
+
21
+ devices = await discover(I2C_BUS, { active: true }); // Discover chips incl. write-sensitive addresses, (bus=1, {active=true}) → DiscoveredDevice[]
22
+ // also probes addresses shared with PCF8574/PCF8591/MCP4725-style chips; may change their outputs
23
+ console.log(devices.length);
24
+ console.log('===DONE: 0 passed, 0 failed===');
25
+ })();
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+ const { discover } = require('../../src/discovery/discovery');
3
+
4
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
5
+
6
+ (async () => {
7
+ // --- Take inventory of an unknown bench setup ---
8
+ // Scan /dev/i2c-1 and name everything that answers. A chip is only named when
9
+ // its identity register matches exactly one registry entry; shared addresses
10
+ // without an ID register stay as candidate lists.
11
+ const devices = await discover(I2C_BUS); // Discover chips, (bus=1, {active=false}) → DiscoveredDevice[]
12
+
13
+ // --- Report what was found ---
14
+ // identified: confirmed chip; candidates: could be any of these; [] means the
15
+ // address answers but the registry does not know it.
16
+ for (const dev of devices) {
17
+ const hex = '0x' + dev.address.toString(16).padStart(2, '0');
18
+ if (dev.identified) console.log(`${hex} ${dev.identified} (driver: ${dev.driver})`);
19
+ else if (dev.inUseByKernel) console.log(`${hex} claimed by a kernel driver, could be ${dev.candidates}`);
20
+ else if (dev.candidates.length) console.log(`${hex} one of ${dev.candidates}`);
21
+ else console.log(`${hex} unknown device`);
22
+ }
23
+
24
+ // --- Flag addresses we deliberately did not probe ---
25
+ // Some candidates (port expanders, DACs) treat a stray write as data, so the
26
+ // identity probe is skipped unless discover(bus, { active: true }) is used.
27
+ const skipped = devices.filter(d => d.probeSkippedReason === 'write_sensitive_candidate');
28
+ console.log(`${skipped.length} address(es) not probed because a candidate is write-sensitive`);
29
+ console.log('===DONE: 0 passed, 0 failed===');
30
+ })();
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+ const { discover } = require('../../src/discovery/discovery');
3
+
4
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
5
+
6
+ (async () => {
7
+ const devices = await discover(I2C_BUS); // Discover chips, (bus=1, {active=false}) → DiscoveredDevice[]
8
+ for (const dev of devices) {
9
+ console.log('0x' + dev.address.toString(16), dev.identified || dev.candidates);
10
+ }
11
+ console.log('===DONE: 0 passed, 0 failed===');
12
+ })();
@@ -0,0 +1,71 @@
1
+ // IL0373 complete example: every Full method, Waveshare 2.13inch e-Paper (D) on a Raspberry Pi.
2
+ // Wiring: DIN=GPIO10, CLK=GPIO11, CS=GPIO8, DC=GPIO25, RST=GPIO17, BUSY=GPIO24. The read* calls
3
+ // need DOUT: spi-device has no 3-wire mode, so join DIN and DOUT through a ~1 kOhm resistor to MISO
4
+ // (GPIO9) and use HALF_DUPLEX_PIN. Each refresh takes about 17 s.
5
+ 'use strict';
6
+ const { Default } = require('opengpio');
7
+ const { DisplayConnection, WireMode } = require('../../../src/connection/display');
8
+ const { GpioOutputPin } = require('../../../src/connection/output_pin');
9
+ const { PollingInputPin } = require('../../../src/connection/input_pin');
10
+ const { IL0373Full, BLACK, WHITE } = require('../../../src/chips/display/il0373');
11
+
12
+ const dc = new GpioOutputPin(Default.output({ chip: 0, line: 25 })); // Create D/C# pin, (chip, line=25) → OutputPin
13
+ const res = new GpioOutputPin(Default.output({ chip: 0, line: 17 })); // Create RES# pin, (chip, line=17) → OutputPin
14
+ const busyIn = Default.input({ chip: 0, line: 24 });
15
+ const busy = new PollingInputPin(() => (busyIn.value ? 1 : 0), 1000); // Create BUSY pin, (chip, line=24) → InputPin
16
+ const connection = new DisplayConnection({
17
+ busNumber: 0, deviceNumber: 0, maxSpeedHz: 1000000, dc, res, busy,
18
+ wireMode: WireMode.HALF_DUPLEX_PIN,
19
+ }); // Create display connection, ({busNumber, deviceNumber, maxSpeedHz, dc, res, busy, wireMode})
20
+ const epd = new IL0373Full(connection); // Create IL0373 driver, (connection, {width=104, height=212, busyTimeoutMs=30000})
21
+ // reset, BTST, PON, PSR 0x1F, TRES, CDI 0x97; panel unchanged until show()
22
+
23
+ (async () => {
24
+ await epd.ready();
25
+ epd.clear(WHITE); // Fill framebuffer, (color=WHITE)
26
+ // every pixel set to white
27
+ epd.setPixel(5, 5, BLACK); // Set one pixel, (x, y, color=BLACK)
28
+ // clears the bit for that pixel
29
+ epd.drawRect(20, 20, 60, 40, BLACK, true); // Draw rectangle, (x, y, w, h, color=BLACK, fill=false)
30
+ // filled black block
31
+ epd.drawLine(0, 0, 103, 211, BLACK); // Draw line, (x0, y0, x1, y1, color=BLACK)
32
+ // Bresenham diagonal
33
+ epd.blit(70, 20, [0xFF, 0x81, 0x81, 0xFF], 8, 4); // Copy 1-bpp bitmap, (x, y, data, w, h, color=BLACK)
34
+ // 8 x 4 box, MSB first
35
+ const colour = epd.getPixel(30, 30); // Read framebuffer pixel, (x, y) → number colour
36
+ // BLACK here
37
+ await epd.setFlip(false, false); // Mirror output, (horizontal, vertical)
38
+ // PSR.SHL / UD at power-on values
39
+ await epd.setPower(14.0, 14.0, 20.0); // Set source/gate power, (vdh V, vdl V, vgh=20 V)
40
+ // PWR: +-14 V sources, +-20 V gates (the power-on values)
41
+ await epd.setFrameRate(50); // Set frame rate, (hz 4–200)
42
+ // nearest PLL M/N entry (M7 N4)
43
+ await epd.setSoftStart(0x17, 0x17, 0x17); // Set booster soft start, (a, b, c)
44
+ // vendor BTST phases
45
+ await epd.setInterval(7); // Set VCOM/data interval, (cdi 0–15, border=2, polarity=1)
46
+ // keeps DDX = 01 so the framebuffer mapping holds
47
+ await epd.setTemperatureSensor(false, 0); // Select temperature sensor, (external, offset -8..7 °C)
48
+ // internal sensor, no offset
49
+ const status = await epd.readStatus(); // Read FLG, () → number bitfield
50
+ // needs DOUT wired (half-duplex)
51
+ const temperature = await epd.readTemperature(); // Read sensor, () → number °C
52
+ // signed internal temperature
53
+ const revision = await epd.readRevision(); // Read REV, () → number LUT_REV
54
+ // LUT revision byte
55
+ await epd.show(); // Refresh panel, () → Promise<void>
56
+ // OLD/NEW planes, DRF, border floating, POF
57
+ epd.drawRect(16, 100, 64, 40, BLACK, true); // Draw rectangle, (x, y, w, h, color=BLACK, fill=false)
58
+ await epd.showRegion(16, 100, 64, 40); // Refresh a window, (x, y, w, h)
59
+ // sends only the window's rows (RAM saving)
60
+ const ready = await epd.waitBusy(1000); // Wait for BUSY high, (timeoutMs) → boolean
61
+ // true when the controller is idle
62
+ await epd.sendCommand(0x50, [0x97]); // Send raw command, (command, data=[])
63
+ // rewrites CDI with the initialisation value
64
+ await epd.sleep(); // Enter deep sleep, () → Promise<void>
65
+ await epd.wake(); // Reset and re-initialise, () → Promise<void>
66
+ // framebuffer is kept
67
+ console.log({ colour, status, temperature, revision, ready });
68
+ connection.close();
69
+ console.log('===DONE: 0 passed, 0 failed===');
70
+ process.exit(0);
71
+ })().catch((e) => { console.error(e); process.exit(1); });
@@ -0,0 +1,49 @@
1
+ // IL0373 demo: status card on a Waveshare 2.13inch e-Paper (D), Raspberry Pi (Node.js).
2
+ // Wiring: DIN=GPIO10, CLK=GPIO11, CS=GPIO8, DC=GPIO25, RST=GPIO17, BUSY=GPIO24.
3
+ // The printed refresh time is the number the spec's Timing Constraints are missing.
4
+ 'use strict';
5
+ const { Default } = require('opengpio');
6
+ const { DisplayConnection, WireMode } = require('../../../src/connection/display');
7
+ const { GpioOutputPin } = require('../../../src/connection/output_pin');
8
+ const { PollingInputPin } = require('../../../src/connection/input_pin');
9
+ const { IL0373Full, BLACK, WHITE } = require('../../../src/chips/display/il0373');
10
+
11
+ const dc = new GpioOutputPin(Default.output({ chip: 0, line: 25 })); // Create D/C# pin, (chip, line=25) → OutputPin
12
+ const res = new GpioOutputPin(Default.output({ chip: 0, line: 17 })); // Create RES# pin, (chip, line=17) → OutputPin
13
+ const busyIn = Default.input({ chip: 0, line: 24 });
14
+ const busy = new PollingInputPin(() => (busyIn.value ? 1 : 0), 1000); // Create BUSY pin, (chip, line=24) → InputPin
15
+ const connection = new DisplayConnection({ busNumber: 0, deviceNumber: 0, dc, res, busy }); // Create display connection, (busNumber, deviceNumber, dc, res, busy)
16
+ const epd = new IL0373Full(connection); // Create IL0373 driver, (connection, {width=104, height=212, busyTimeoutMs=30000})
17
+
18
+ (async () => {
19
+ await epd.ready();
20
+
21
+ // --- Compose the status card in the framebuffer ---
22
+ // White page, a one-pixel black border inset by 2 px (a frame on the very edge is
23
+ // hidden by the panel bezel) and a black header bar across the top 24 rows.
24
+ epd.clear(WHITE); // Fill framebuffer, (color=WHITE)
25
+ epd.drawRect(2, 2, 100, 208, BLACK); // Draw rectangle, (x, y, w, h, color=BLACK, fill=false)
26
+ epd.drawRect(3, 3, 98, 24, BLACK, true); // Draw rectangle, (x, y, w, h, color=BLACK, fill=false)
27
+
28
+ // --- Bar chart of eight readings ---
29
+ // Axes first, then one filled bar per value; the tallest bar is filled and the others are outlines.
30
+ const values = [30, 55, 80, 45, 120, 90, 60, 100];
31
+ epd.drawLine(10, 190, 95, 190, BLACK); // Draw line, (x0, y0, x1, y1, color=BLACK)
32
+ epd.drawLine(10, 60, 10, 190, BLACK); // Draw line, (x0, y0, x1, y1, color=BLACK)
33
+ const peak = Math.max(...values);
34
+ values.forEach((v, i) => {
35
+ epd.drawRect(14 + i * 10, 190 - v, 8, v, BLACK, v === peak); // Draw rectangle, (x, y, w, h, color=BLACK, fill=false)
36
+ });
37
+
38
+ // --- Refresh and time it ---
39
+ // show() resolves after the whole DTM1/DTM2/DRF/POF sequence.
40
+ const start = Date.now();
41
+ await epd.show(); // Refresh panel, () → Promise<void>
42
+ console.log('refresh took', (Date.now() - start) / 1000, 's');
43
+
44
+ // --- Save the image and power down ---
45
+ // The panel keeps the picture without power; deep sleep stops the controller drawing current.
46
+ await epd.sleep(); // Enter deep sleep, () → Promise<void>
47
+ connection.close();
48
+ process.exit(0);
49
+ })().catch((e) => { console.error(e); process.exit(1); });
@@ -0,0 +1,26 @@
1
+ // IL0373 minimal example: Waveshare 2.13inch e-Paper (D) on a Raspberry Pi.
2
+ // Wiring: DIN=GPIO10 (SPI0 MOSI), CLK=GPIO11, CS=GPIO8 (CE0), DC=GPIO25, RST=GPIO17, BUSY=GPIO24.
3
+ 'use strict';
4
+ const { Default } = require('opengpio');
5
+ const { DisplayConnection, WireMode } = require('../../../src/connection/display');
6
+ const { GpioOutputPin } = require('../../../src/connection/output_pin');
7
+ const { PollingInputPin } = require('../../../src/connection/input_pin');
8
+ const { IL0373Minimal, BLACK, WHITE } = require('../../../src/chips/display/il0373');
9
+
10
+ const dc = new GpioOutputPin(Default.output({ chip: 0, line: 25 })); // Create D/C# pin, (chip, line=25) → OutputPin
11
+ const res = new GpioOutputPin(Default.output({ chip: 0, line: 17 })); // Create RES# pin, (chip, line=17) → OutputPin
12
+ const busyIn = Default.input({ chip: 0, line: 24 });
13
+ const busy = new PollingInputPin(() => (busyIn.value ? 1 : 0), 1000); // Create BUSY pin, (chip, line=24) → InputPin
14
+ const connection = new DisplayConnection({ busNumber: 0, deviceNumber: 0, dc, res, busy }); // Create display connection, (busNumber, deviceNumber, dc, res, busy)
15
+ const epd = new IL0373Minimal(connection); // Create IL0373 driver, (connection, {width=104, height=212, busyTimeoutMs=30000})
16
+
17
+ (async () => {
18
+ await epd.ready();
19
+ epd.clear(WHITE); // Fill framebuffer, (color=WHITE)
20
+ epd.setPixel(10, 10, BLACK); // Set one pixel, (x, y, color=BLACK)
21
+ for (let x = 20; x < 100; x++) epd.setPixel(x, 40, BLACK); // Set one pixel, (x, y, color=BLACK)
22
+ await epd.show(); // Refresh panel , () → Promise<void>
23
+ await epd.sleep(); // Enter deep sleep, () → Promise<void>
24
+ connection.close();
25
+ process.exit(0);
26
+ })().catch((e) => { console.error(e); process.exit(1); });