periph 1.3.2 → 1.4.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 (114) hide show
  1. package/README.md +27 -0
  2. package/examples/accelerometer/bma180/complete.js +83 -0
  3. package/examples/accelerometer/bma180/demo.js +47 -0
  4. package/examples/accelerometer/bma180/minimal.js +21 -0
  5. package/examples/accelerometer/fxos8700/complete.js +111 -0
  6. package/examples/accelerometer/fxos8700/demo.js +80 -0
  7. package/examples/accelerometer/fxos8700/minimal.js +20 -0
  8. package/examples/accelerometer/lis3dh/complete.js +123 -0
  9. package/examples/accelerometer/lis3dh/demo.js +99 -0
  10. package/examples/accelerometer/lis3dh/minimal.js +19 -0
  11. package/examples/accelerometer/lsm303/complete.js +82 -0
  12. package/examples/accelerometer/lsm303/demo.js +96 -0
  13. package/examples/accelerometer/lsm303/minimal.js +23 -0
  14. package/examples/accelerometer/mma8451q/complete.js +96 -0
  15. package/examples/accelerometer/mma8451q/demo.js +120 -0
  16. package/examples/accelerometer/mma8451q/minimal.js +20 -0
  17. package/examples/adc_dac/ad5243/complete.js +52 -0
  18. package/examples/adc_dac/ad5243/demo.js +50 -0
  19. package/examples/adc_dac/ad5243/minimal.js +23 -0
  20. package/examples/adc_dac/ad5248/complete.js +49 -0
  21. package/examples/adc_dac/ad5248/demo.js +42 -0
  22. package/examples/adc_dac/ad5248/minimal.js +21 -0
  23. package/examples/adc_dac/ads1013/complete.js +51 -0
  24. package/examples/adc_dac/ads1013/demo.js +51 -0
  25. package/examples/adc_dac/ads1013/minimal.js +21 -0
  26. package/examples/adc_dac/ads1014/complete.js +88 -0
  27. package/examples/adc_dac/ads1014/demo.js +52 -0
  28. package/examples/adc_dac/ads1014/minimal.js +21 -0
  29. package/examples/adc_dac/ads1113/complete.js +47 -0
  30. package/examples/adc_dac/ads1113/demo.js +39 -0
  31. package/examples/adc_dac/ads1113/minimal.js +20 -0
  32. package/examples/adc_dac/ads1114/complete.js +77 -0
  33. package/examples/adc_dac/ads1114/demo.js +47 -0
  34. package/examples/adc_dac/ads1114/minimal.js +20 -0
  35. package/examples/adc_dac/ads1115/complete.js +82 -0
  36. package/examples/adc_dac/ads1115/demo.js +55 -0
  37. package/examples/adc_dac/ads1115/minimal.js +20 -0
  38. package/examples/adc_dac/es8311/complete.js +80 -0
  39. package/examples/adc_dac/es8311/demo.js +59 -0
  40. package/examples/adc_dac/es8311/minimal.js +18 -0
  41. package/examples/adc_dac/mcp4xxx/complete.js +97 -0
  42. package/examples/adc_dac/mcp4xxx/demo.js +76 -0
  43. package/examples/adc_dac/mcp4xxx/minimal.js +22 -0
  44. package/examples/display/pcf8578/complete.js +58 -0
  45. package/examples/display/pcf8578/demo.js +62 -0
  46. package/examples/display/pcf8578/minimal.js +19 -0
  47. package/examples/display/pcf8579/complete.js +58 -0
  48. package/examples/display/pcf8579/demo.js +61 -0
  49. package/examples/display/pcf8579/minimal.js +19 -0
  50. package/examples/imu/icm20948/complete.js +114 -0
  51. package/examples/imu/icm20948/demo.js +79 -0
  52. package/examples/imu/icm20948/minimal.js +22 -0
  53. package/examples/imu/qmi8658a/complete.js +134 -0
  54. package/examples/imu/qmi8658a/demo.js +81 -0
  55. package/examples/imu/qmi8658a/minimal.js +22 -0
  56. package/examples/io_expander/mcp23008/complete.js +70 -0
  57. package/examples/io_expander/mcp23008/demo.js +58 -0
  58. package/examples/io_expander/mcp23008/minimal.js +20 -0
  59. package/examples/memory/mb85rc/complete.js +40 -0
  60. package/examples/memory/mb85rc/demo.js +58 -0
  61. package/examples/memory/mb85rc/minimal.js +15 -0
  62. package/examples/motor/drv2605/complete.js +100 -0
  63. package/examples/motor/drv2605/demo.js +55 -0
  64. package/examples/motor/drv2605/minimal.js +24 -0
  65. package/examples/motor/tmc2130/complete.js +138 -0
  66. package/examples/motor/tmc2130/demo.js +96 -0
  67. package/examples/motor/tmc2130/minimal.js +30 -0
  68. package/examples/motor/tmc2208/complete.js +92 -0
  69. package/examples/motor/tmc2208/demo.js +85 -0
  70. package/examples/motor/tmc2208/minimal.js +25 -0
  71. package/examples/motor/tmc2209/complete.js +106 -0
  72. package/examples/motor/tmc2209/demo.js +97 -0
  73. package/examples/motor/tmc2209/minimal.js +25 -0
  74. package/examples/motor/tmc5160/complete.js +205 -0
  75. package/examples/motor/tmc5160/demo.js +104 -0
  76. package/examples/motor/tmc5160/minimal.js +35 -0
  77. package/examples/power/axp2101/complete.js +135 -0
  78. package/examples/power/axp2101/demo.js +68 -0
  79. package/examples/power/axp2101/minimal.js +24 -0
  80. package/examples/rtc/pcf85063a/complete.js +68 -0
  81. package/examples/rtc/pcf85063a/demo.js +76 -0
  82. package/examples/rtc/pcf85063a/minimal.js +20 -0
  83. package/package.json +1 -1
  84. package/src/chips/accelerometer/bma180.js +573 -0
  85. package/src/chips/accelerometer/fxos8700.js +1600 -0
  86. package/src/chips/accelerometer/lis3dh.js +1341 -0
  87. package/src/chips/accelerometer/lsm303.js +1471 -0
  88. package/src/chips/accelerometer/mma8451q.js +1406 -0
  89. package/src/chips/adc_dac/_ads111x_base.js +272 -0
  90. package/src/chips/adc_dac/ad5243.js +231 -0
  91. package/src/chips/adc_dac/ad5248.js +194 -0
  92. package/src/chips/adc_dac/ads1013.js +219 -0
  93. package/src/chips/adc_dac/ads1014.js +509 -0
  94. package/src/chips/adc_dac/ads1113.js +112 -0
  95. package/src/chips/adc_dac/ads1114.js +201 -0
  96. package/src/chips/adc_dac/ads1115.js +232 -0
  97. package/src/chips/adc_dac/es8311.js +621 -0
  98. package/src/chips/adc_dac/mcp4xxx.js +982 -0
  99. package/src/chips/display/pcf8578.js +452 -0
  100. package/src/chips/display/pcf8579.js +451 -0
  101. package/src/chips/imu/icm20948.js +849 -0
  102. package/src/chips/imu/qmi8658a.js +1011 -0
  103. package/src/chips/io_expander/mcp23008.js +558 -0
  104. package/src/chips/memory/mb85rc.js +166 -0
  105. package/src/chips/motor/drv2605.js +592 -0
  106. package/src/chips/motor/tmc2130.js +537 -0
  107. package/src/chips/motor/tmc2208.js +490 -0
  108. package/src/chips/motor/tmc2209.js +565 -0
  109. package/src/chips/motor/tmc5160.js +900 -0
  110. package/src/chips/power/axp2101.js +968 -0
  111. package/src/chips/rtc/pcf85063a.js +482 -0
  112. package/src/connection/uart.js +9 -0
  113. package/src/connection/uart_mock.js +65 -0
  114. package/src/discovery/registry.js +45 -19
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('periph/src/connection/i2c');
4
+ const { ADS1114Full } = require('periph/src/chips/adc_dac/ads1114');
5
+
6
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
7
+
8
+ (async () => {
9
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
10
+ const connection = new I2CConnection(bus, ADS1114Full.I2C_ADDRESS);
11
+ const adc = new ADS1114Full(connection); // Create ADS1114 Full driver, (connection)
12
+ // no I²C traffic; Config word is rebuilt per conversion
13
+ const raw = await adc.readRaw(); // Read raw code, () → number
14
+ // single-shot conversion, signed 16-bit
15
+ const v = await adc.readVoltage(); // Read voltage, () → number V
16
+ // raw × lsb()
17
+ console.log(`raw ${raw} voltage ${v.toFixed(5)} V`);
18
+ await adc.setGain(ADS1114Full.PGA_4_096); // Set gain, (pga 0–5) → None
19
+ // ±4.096 V full scale
20
+ console.log(`gain ${adc.getGain()}`);
21
+ const fs = adc.fullScale(); // Full scale, () → number V
22
+ // ±FSR of the current gain
23
+ const lsb = adc.lsb(); // LSB, () → number V
24
+ // fullScale() / 32768
25
+ console.log(`full scale ${fs} V, lsb ${lsb} V`);
26
+ await adc.setDataRate(ADS1114Full.DR_250); // Set data rate, (dr 0–7) → None
27
+ // DR field of the Config word
28
+ const sps = adc.dataRateSps(); // Data rate, () → number SPS
29
+ // samples per second of the current setting
30
+ console.log(`rate ${adc.getDataRate()} = ${sps} SPS`);
31
+ await adc.startContinuous(); // Start continuous, () → None
32
+ // MODE ← 0
33
+ await sleep(50);
34
+ const craw = await adc.readContinuousRaw(); // Read continuous raw, () → number
35
+ // CONVERSION without touching Config
36
+ const cv = await adc.readContinuous(); // Read continuous, () → number V
37
+ // readContinuousRaw() × lsb()
38
+ console.log(`continuous ${craw} ${cv.toFixed(5)} V`);
39
+ await adc.stopContinuous(); // Stop continuous, () → None
40
+ // MODE ← 1
41
+ const busy = await adc.isConverting(); // Check conversion, () → boolean
42
+ // CONFIG.OS == 0
43
+ const cfg = await adc.readConfig(); // Read CONFIG, () → number
44
+ // raw 16-bit register
45
+ console.log(`converting ${busy}, config 0x${cfg.toString(16)}`);
46
+ await adc.setThresholds(0.5, 3.0); // Set thresholds, (low V, high V) → None
47
+ // converted with the current lsb(), clamped
48
+ await adc.setLowThresholdRaw(4000); // Set low threshold, (raw) → None
49
+ // LO_THRESH ← raw & 0xFFFF
50
+ await adc.setHighThresholdRaw(20000); // Set high threshold, (raw) → None
51
+ // HI_THRESH ← raw & 0xFFFF
52
+ const [lo, hi] = await adc.getThresholdsRaw(); // Get thresholds, () → [number, number]
53
+ // read back, sign-extended
54
+ console.log(`thresholds ${lo} ${hi}`);
55
+ await adc.configureComparator(ADS1114Full.COMP_WINDOW, ADS1114Full.ACTIVE_LOW, true, ADS1114Full.QUEUE_2);// Configure comparator, (mode, polarity, latch=false, queue=QUEUE_1) → None
56
+ // window mode, latching, 2-sample queue
57
+ await adc.clearAlert(); // Clear alert, () → None
58
+ // reads CONVERSION to release the latch
59
+ await adc.disableComparator(); // Disable comparator, () → None
60
+ // COMP_QUE ← 11
61
+ await adc.enableInterrupt(ADS1114Full.SOURCE_CONVERSION_READY); // Enable interrupt, (source) → None
62
+ // ALERT/RDY signals conversion-ready
63
+ const status = await adc.pollInterrupt(); // Poll interrupt, () → number source
64
+ // enabled source if ALERT/RDY is asserted
65
+ console.log(`poll ${status}`);
66
+ await adc.onInterrupt((s) => console.log(`alert ${s}`)); // Subscribe, (callback) → None
67
+ // pin edge, or a polling loop without an InputPin
68
+ await sleep(1000);
69
+ await adc.offInterrupt(); // Unsubscribe, () → None
70
+ // stops delivery
71
+ await adc.disableInterrupt(ADS1114Full.SOURCE_CONVERSION_READY); // Disable interrupt, (source) → None
72
+ // releases ALERT/RDY
73
+ await adc.reset(); // Reset, () → None
74
+ // writes the reset values back
75
+
76
+ await connection.close();
77
+ })();
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('periph/src/connection/i2c');
4
+ const { ADS1114Full } = require('periph/src/chips/adc_dac/ads1114');
5
+
6
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
7
+
8
+ (async () => {
9
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
10
+ const connection = new I2CConnection(bus, ADS1114Full.I2C_ADDRESS);
11
+ const adc = new ADS1114Full(connection); // Create ADS1114 Full driver, (connection)
12
+
13
+ // --- Configure the converter ---
14
+ // ±4.096 V covers a 3.3 V rail with headroom; 250 SPS keeps single-shot
15
+ // reads short while still averaging out most noise.
16
+ await adc.setGain(ADS1114Full.PGA_4_096); // Set gain, (pga 0–5) → None
17
+ await adc.setDataRate(ADS1114Full.DR_250); // Set data rate, (dr 0–7) → None
18
+
19
+ // --- Read the inputs ---
20
+ // Single-shot mode powers the chip down between conversions.
21
+ for (let i = 0; i < 3; i++) {
22
+ const raw = await adc.readRaw(); // Read raw code, () → number
23
+ console.log(`raw ${raw} ${(raw * adc.lsb()).toFixed(5)} V`);
24
+ await sleep(1000);
25
+ }
26
+
27
+ // --- Arm a window comparator ---
28
+ // ALERT/RDY asserts when the input leaves 0.5 V ... 3.0 V for two
29
+ // consecutive conversions; the latch holds it until clearAlert().
30
+ await adc.setThresholds(0.5, 3.0); // Set thresholds, (low V, high V) → None
31
+ await adc.configureComparator(ADS1114Full.COMP_WINDOW, ADS1114Full.ACTIVE_LOW, true, ADS1114Full.QUEUE_2);// Configure comparator, (mode, polarity, latch=false, queue=QUEUE_1) → None
32
+ await adc.startContinuous(); // Start continuous, () → None
33
+
34
+ // --- Report out-of-range events ---
35
+ // With an InputPin on ALERT/RDY the callback fires on the edge; without
36
+ // one the driver polls the register every 5 ms.
37
+ await adc.onInterrupt(async () => { // Subscribe, (callback) → None
38
+ console.log('OUT OF RANGE');
39
+ await adc.clearAlert(); // Clear alert, () → None
40
+ });
41
+ await sleep(10000);
42
+ await adc.offInterrupt(); // Unsubscribe, () → None
43
+ await adc.disableComparator(); // Disable comparator, () → None
44
+ await adc.stopContinuous(); // Stop continuous, () → None
45
+
46
+ await connection.close();
47
+ })();
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('periph/src/connection/i2c');
4
+ const { ADS1114Minimal } = require('periph/src/chips/adc_dac/ads1114');
5
+
6
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
7
+
8
+ (async () => {
9
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
10
+ const connection = new I2CConnection(bus, ADS1114Minimal.I2C_ADDRESS);
11
+ const adc = new ADS1114Minimal(connection); // Create ADS1114 driver, (connection)
12
+
13
+ for (let i = 0; i < 10; i++) {
14
+ const v = await adc.readVoltage(); // Read voltage, () → number V
15
+ console.log(`${v.toFixed(5)} V`);
16
+ await sleep(1000);
17
+ }
18
+
19
+ await connection.close();
20
+ })();
@@ -0,0 +1,82 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('periph/src/connection/i2c');
4
+ const { ADS1115Full } = require('periph/src/chips/adc_dac/ads1115');
5
+
6
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
7
+
8
+ (async () => {
9
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
10
+ const connection = new I2CConnection(bus, ADS1115Full.I2C_ADDRESS);
11
+ const adc = new ADS1115Full(connection); // Create ADS1115 Full driver, (connection)
12
+ // no I²C traffic; Config word is rebuilt per conversion
13
+ const raw = await adc.readRaw(2); // Read raw code, (channel=0) → number
14
+ // single-shot conversion, signed 16-bit
15
+ const v = await adc.readVoltage(2); // Read voltage, (channel=0) → number V
16
+ // raw × lsb()
17
+ console.log(`raw ${raw} voltage ${v.toFixed(5)} V`);
18
+ await adc.setGain(ADS1115Full.PGA_4_096); // Set gain, (pga 0–5) → None
19
+ // ±4.096 V full scale
20
+ console.log(`gain ${adc.getGain()}`);
21
+ const fs = adc.fullScale(); // Full scale, () → number V
22
+ // ±FSR of the current gain
23
+ const lsb = adc.lsb(); // LSB, () → number V
24
+ // fullScale() / 32768
25
+ console.log(`full scale ${fs} V, lsb ${lsb} V`);
26
+ await adc.setDataRate(ADS1115Full.DR_250); // Set data rate, (dr 0–7) → None
27
+ // DR field of the Config word
28
+ const sps = adc.dataRateSps(); // Data rate, () → number SPS
29
+ // samples per second of the current setting
30
+ console.log(`rate ${adc.getDataRate()} = ${sps} SPS`);
31
+ const d = await adc.readDifferential(ADS1115Full.DIFF_2_3); // Read differential, (pair 0–3) → number V
32
+ // single-shot MUX = pair
33
+ const draw = await adc.readDifferentialRaw(ADS1115Full.DIFF_0_1); // Read differential raw, (pair 0–3) → number
34
+ // signed 16-bit code
35
+ console.log(`differential ${d.toFixed(6)} V, raw ${draw}`);
36
+ await adc.startContinuous(ADS1115Full.MUX_AIN0_GND); // Start continuous, (mux=MUX_AIN0_GND 0–7) → None
37
+ // MODE ← 0
38
+ await sleep(50);
39
+ const craw = await adc.readContinuousRaw(); // Read continuous raw, () → number
40
+ // CONVERSION without touching Config
41
+ const cv = await adc.readContinuous(); // Read continuous, () → number V
42
+ // readContinuousRaw() × lsb()
43
+ console.log(`continuous ${craw} ${cv.toFixed(5)} V`);
44
+ await adc.stopContinuous(); // Stop continuous, () → None
45
+ // MODE ← 1
46
+ const busy = await adc.isConverting(); // Check conversion, () → boolean
47
+ // CONFIG.OS == 0
48
+ const cfg = await adc.readConfig(); // Read CONFIG, () → number
49
+ // raw 16-bit register
50
+ console.log(`converting ${busy}, config 0x${cfg.toString(16)}`);
51
+ await adc.setThresholds(0.5, 3.0); // Set thresholds, (low V, high V) → None
52
+ // converted with the current lsb(), clamped
53
+ await adc.setLowThresholdRaw(4000); // Set low threshold, (raw) → None
54
+ // LO_THRESH ← raw & 0xFFFF
55
+ await adc.setHighThresholdRaw(20000); // Set high threshold, (raw) → None
56
+ // HI_THRESH ← raw & 0xFFFF
57
+ const [lo, hi] = await adc.getThresholdsRaw(); // Get thresholds, () → [number, number]
58
+ // read back, sign-extended
59
+ console.log(`thresholds ${lo} ${hi}`);
60
+ await adc.configureComparator(ADS1115Full.COMP_WINDOW, ADS1115Full.ACTIVE_LOW, true, ADS1115Full.QUEUE_2);// Configure comparator, (mode, polarity, latch=false, queue=QUEUE_1) → None
61
+ // window mode, latching, 2-sample queue
62
+ await adc.clearAlert(); // Clear alert, () → None
63
+ // reads CONVERSION to release the latch
64
+ await adc.disableComparator(); // Disable comparator, () → None
65
+ // COMP_QUE ← 11
66
+ await adc.enableInterrupt(ADS1115Full.SOURCE_CONVERSION_READY); // Enable interrupt, (source) → None
67
+ // ALERT/RDY signals conversion-ready
68
+ const status = await adc.pollInterrupt(); // Poll interrupt, () → number source
69
+ // enabled source if ALERT/RDY is asserted
70
+ console.log(`poll ${status}`);
71
+ await adc.onInterrupt((s) => console.log(`alert ${s}`)); // Subscribe, (callback) → None
72
+ // pin edge, or a polling loop without an InputPin
73
+ await sleep(1000);
74
+ await adc.offInterrupt(); // Unsubscribe, () → None
75
+ // stops delivery
76
+ await adc.disableInterrupt(ADS1115Full.SOURCE_CONVERSION_READY); // Disable interrupt, (source) → None
77
+ // releases ALERT/RDY
78
+ await adc.reset(); // Reset, () → None
79
+ // writes the reset values back
80
+
81
+ await connection.close();
82
+ })();
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('periph/src/connection/i2c');
4
+ const { ADS1115Full } = require('periph/src/chips/adc_dac/ads1115');
5
+
6
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
7
+
8
+ (async () => {
9
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
10
+ const connection = new I2CConnection(bus, ADS1115Full.I2C_ADDRESS);
11
+ const adc = new ADS1115Full(connection); // Create ADS1115 Full driver, (connection)
12
+
13
+ // --- Configure the converter ---
14
+ // ±4.096 V covers a 3.3 V rail with headroom; 250 SPS keeps single-shot
15
+ // reads short while still averaging out most noise.
16
+ await adc.setGain(ADS1115Full.PGA_4_096); // Set gain, (pga 0–5) → None
17
+ await adc.setDataRate(ADS1115Full.DR_250); // Set data rate, (dr 0–7) → None
18
+
19
+ // --- Read the inputs ---
20
+ // Single-shot mode powers the chip down between conversions.
21
+ for (let i = 0; i < 3; i++) {
22
+ for (let ch = 0; ch < 4; ch++) {
23
+ const raw = await adc.readRaw(ch); // Read raw code, (channel=0) → number
24
+ console.log(`AIN${ch} raw ${raw} ${(raw * adc.lsb()).toFixed(5)} V`);
25
+ }
26
+ await sleep(1000);
27
+ }
28
+
29
+ // --- Arm a window comparator ---
30
+ // ALERT/RDY asserts when the input leaves 0.5 V ... 3.0 V for two
31
+ // consecutive conversions; the latch holds it until clearAlert().
32
+ await adc.setThresholds(0.5, 3.0); // Set thresholds, (low V, high V) → None
33
+ await adc.configureComparator(ADS1115Full.COMP_WINDOW, ADS1115Full.ACTIVE_LOW, true, ADS1115Full.QUEUE_2);// Configure comparator, (mode, polarity, latch=false, queue=QUEUE_1) → None
34
+ await adc.startContinuous(ADS1115Full.MUX_AIN0_GND); // Start continuous, (mux=MUX_AIN0_GND 0–7) → None
35
+
36
+ // --- Report out-of-range events ---
37
+ // With an InputPin on ALERT/RDY the callback fires on the edge; without
38
+ // one the driver polls the register every 5 ms.
39
+ await adc.onInterrupt(async () => { // Subscribe, (callback) → None
40
+ console.log('OUT OF RANGE');
41
+ await adc.clearAlert(); // Clear alert, () → None
42
+ });
43
+ await sleep(10000);
44
+ await adc.offInterrupt(); // Unsubscribe, () → None
45
+ await adc.disableComparator(); // Disable comparator, () → None
46
+ await adc.stopContinuous(); // Stop continuous, () → None
47
+
48
+ // --- Bridge-sensor style differential read ---
49
+ // The smallest range gives 7.8 uV per code for millivolt-level signals.
50
+ await adc.setGain(ADS1115Full.PGA_0_256); // Set gain, (pga 0–5) → None
51
+ const d = await adc.readDifferential(ADS1115Full.DIFF_2_3); // Read differential, (pair 0–3) → number V
52
+ console.log(`differential ${d.toFixed(6)} V`);
53
+
54
+ await connection.close();
55
+ })();
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('periph/src/connection/i2c');
4
+ const { ADS1115Minimal } = require('periph/src/chips/adc_dac/ads1115');
5
+
6
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
7
+
8
+ (async () => {
9
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
10
+ const connection = new I2CConnection(bus, ADS1115Minimal.I2C_ADDRESS);
11
+ const adc = new ADS1115Minimal(connection); // Create ADS1115 driver, (connection)
12
+
13
+ for (let i = 0; i < 10; i++) {
14
+ const v = await adc.readVoltage(0); // Read voltage, (channel=0) → number V
15
+ console.log(`${v.toFixed(5)} V`);
16
+ await sleep(1000);
17
+ }
18
+
19
+ await connection.close();
20
+ })();
@@ -0,0 +1,80 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { ES8311Full } = require('../../../src/chips/adc_dac/es8311');
5
+
6
+ async function main() {
7
+ const connection = new I2CConnection(1, 0x18); // Create I2C connection, (bus=1, addr=0x18)
8
+ const codec = new ES8311Full(connection, 12288000, 48000); // Create ES8311 driver and run the init sequence, (connection, mclkHz=12288000 Hz, sampleRateHz=48000 Hz)
9
+ // reset, clock dividers, I2S 16-bit slave, analog path, mic 24 dB, DAC silent
10
+
11
+ await codec.setVolume(-30.0); // Set DAC volume, (db −95.5–32 dB) → Promise<void>
12
+ // writes 0x32 = round(db / 0.5) + 191
13
+ console.log(await codec.getVolume()); // Read back DAC volume, () → Promise<float dB>
14
+ // (0x32 − 191) × 0.5
15
+ await codec.setMute(false); // Unmute the DAC, (muted=false) → Promise<void>
16
+ // clears DSM and DEM mute bits of 0x31
17
+ await codec.setMicGain(27); // Set microphone PGA gain, (db 0–30 dB) → Promise<void>
18
+ // 0x14 bits 3:0 = round(db / 3)
19
+ console.log(await codec.getMicGain()); // Read back PGA gain, () → Promise<float dB>
20
+ // 3 dB per register step
21
+ await codec.configureClock(12288000, 16000); // Program the clock tree, (mclkHz Hz, sampleRateHz Hz, mclkFromBclk=false, mclkInvert=false) → Promise<void>
22
+ // preset table first, then computed pre-divider / multiplier / OSR
23
+ await codec.configureSerial({ format: 'i2s', wordLength: 16 }); // Configure the digital audio port, ({format='i2s', wordLength=16, master=false, bclkInvert=false, lrckInvert=false, dacChannel='left', bclkDiv, lrckDiv, continuousBclk=true}) → Promise<void>
24
+ // 0x09 / 0x0A format and word length, slave mode
25
+ await codec.setTristate(false, false); // Tri-state BCLK/LRCK and ADCDAT, (bclkLrck=false, adcdat=false) → Promise<void>
26
+ // 0x07 bits 5:4
27
+ await codec.setInput('analog'); // Select microphone input, (source='analog'|'digital'|'none') → Promise<void>
28
+ // MIC1P / MIC1N differential, PGA powered
29
+ await codec.configureDmic(false); // Select PDM latch edge, (latchFallingEdge=false) → Promise<void>
30
+ // 0x15 bit 0
31
+ await codec.setAdcVolume(0); // Set ADC digital volume, (db −95.5–32 dB) → Promise<void>
32
+ // 0x17; ALC maximum gain when the ALC is on
33
+ await codec.configureAdc({ scaleDb: 24, osr: 64, hpf: true }); // Configure ADC path, ({scaleDb=24 dB, osr=64, doubleSpeed=false, hpf=true, hpfCoeffs=[0x0C, 0x0C]}) → Promise<void>
34
+ // 0x16 scale, 0x03 speed / OSR, 0x1B / 0x1C high-pass filter
35
+ await codec.setAdcRamp(0); // Set ADC soft-ramp rate, (rate 0–15) → Promise<void>
36
+ // 0 = off; n = 0.25 dB per 2^(n+1) LRCK
37
+ await codec.configureAlc(true, { maxLevelDb: -12.0, minLevelDb: -18.1, automute: true, noiseGateDb: -60 }); // Configure ALC, (enabled, {maxLevelDb, minLevelDb, window, automute, automuteWindow, noiseGateDb}) → Promise<void>
38
+ // 0x18–0x1A, levels rounded to the nearest listed value
39
+ await codec.configureAlc(false); // Disable ALC, (enabled=false) → Promise<void>
40
+ // restores defaults
41
+ await codec.setAdcEq(null); // Bypass ADC equalizer, (coefficients=null) → Promise<void>
42
+ // 0x1C bit 6; an array of five 30-bit values loads b0,a1,a2,b1,b2
43
+ await codec.setDacRamp(8); // Set DAC soft-ramp rate, (rate 0–15) → Promise<void>
44
+ // 0x37 bits 7:4
45
+ await codec.configureDrc(true, { maxLevelDb: -12.0, minLevelDb: -24.1 }); // Configure DRC, (enabled, {maxLevelDb, minLevelDb, window}) → Promise<void>
46
+ // 0x34 / 0x35; DAC volume becomes the maximum gain
47
+ await codec.configureDrc(false); // Disable DRC, (enabled=false) → Promise<void>
48
+ // clears the DRC enable bit
49
+ await codec.setDacEq(null); // Bypass DAC equalizer, (coefficients=null) → Promise<void>
50
+ // 0x37 bit 3; an array of three 30-bit values loads b0,b1,a1
51
+ await codec.setDacMuteOptions(true, true, false); // Set DAC mute bits, (dsm=true, dem=true, dsmTarget=false) → Promise<void>
52
+ // 0x31 bits 7:5 individually
53
+ await codec.setLoopback(true); // Route ADC output into the DAC, (enabled) → Promise<void>
54
+ // 0x44 bit 7
55
+ await codec.setLoopback(false); // Disable loopback, (enabled=false) → Promise<void>
56
+ // 0x44 bit 7 cleared
57
+ await codec.setAdcdatMode('dac_adc'); // Select ADCDAT content, (mode='adc_adc'|'adc_zero'|'zero_adc'|'dac_adc'|'adc_dac'|'dac_dac') → Promise<void>
58
+ // DAC + ADC: digital feedback for echo cancellation
59
+ await codec.setAdcdatMode('adc_adc'); // Restore ADCDAT content, (mode='adc_adc') → Promise<void>
60
+ // ADC data on both slots
61
+ await codec.setSdpMute(false, false); // Mute serial input / output, (input=false, output=false) → Promise<void>
62
+ // 0x09 / 0x0A bit 6
63
+ await codec.setLowPower({}); // Clear all low-power bits, ({dac, pga, pgaOut, adc, adcRef, dacRef, flash, integrator}) → Promise<void>
64
+ // 0x0F; all off = best THD+N
65
+ console.log(await codec.readRegister(0x32)); // Read raw register, (register 0x00–0xFF) → Promise<int>
66
+ // returns the byte as stored in the chip
67
+ await codec.writeRegister(0x32, 0xBF); // Write raw register, (register, value) → Promise<void>
68
+ // 0xBF = 0 dB DAC volume
69
+ await new Promise((resolve) => setTimeout(resolve, 1000));
70
+ await codec.setMute(true); // Mute the DAC, (muted=true) → Promise<void>
71
+ // sets DSM and DEM mute
72
+ await codec.powerDown(); // Enter standby, () → Promise<void>
73
+ // powers down analog blocks, resets digital, clears CSM_ON
74
+ await codec.powerUp(); // Leave standby, () → Promise<void>
75
+ // re-enables analog blocks, clocks and CSM_ON
76
+ await codec.reset(); // Software reset, () → Promise<void>
77
+ // registers return to reset values; reconfigure afterwards
78
+ }
79
+
80
+ main();
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { ES8311Full } = require('../../../src/chips/adc_dac/es8311');
5
+
6
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
7
+
8
+ async function main() {
9
+ // --- Bring up the codec for a voice assistant ---
10
+ // The control port only configures the codec; the I2S stream (MCLK, BCLK,
11
+ // LRCK, DSDIN, ASDOUT) is produced elsewhere. 16 kHz is the usual rate for
12
+ // speech recognition.
13
+ const connection = new I2CConnection(1, 0x18); // Create I2C connection, (bus=1, addr=0x18)
14
+ const codec = new ES8311Full(connection, 12288000, 48000); // Create ES8311 driver, (connection, mclkHz=12288000 Hz, sampleRateHz=48000 Hz)
15
+ await codec.configureClock(12288000, 16000); // Program the clock tree, (mclkHz Hz, sampleRateHz Hz) → Promise<void>
16
+ await codec.configureSerial({ format: 'i2s', wordLength: 16 }); // Configure the digital audio port, ({format='i2s', wordLength=16}) → Promise<void>
17
+
18
+ // --- Configure the microphone path ---
19
+ // 24 dB analog gain plus the ALC keeps quiet and loud talkers at a similar
20
+ // level; the noise gate and automute silence the line between utterances.
21
+ await codec.setMicGain(24); // Set microphone PGA gain, (db 0–30 dB) → Promise<void>
22
+ console.log('mic gain', await codec.getMicGain()); // Read back PGA gain, () → Promise<float dB>
23
+ await codec.setAdcVolume(0); // Set ADC digital volume, (db −95.5–32 dB) → Promise<void>
24
+ await codec.configureAlc(true, { maxLevelDb: -12.0, minLevelDb: -18.1, automute: true, noiseGateDb: -60 }); // Configure ALC, (enabled, {maxLevelDb, minLevelDb, automute, noiseGateDb}) → Promise<void>
25
+ await codec.configureAdc({ hpf: true }); // Configure ADC path, ({scaleDb=24 dB, osr=64, hpf=true}) → Promise<void>
26
+
27
+ // --- Configure playback ---
28
+ // The DRC compresses loud peaks so a small speaker does not clip; the soft
29
+ // ramp avoids clicks while the volume changes.
30
+ await codec.configureDrc(true, { maxLevelDb: -12.0, minLevelDb: -24.1 }); // Configure DRC, (enabled, {maxLevelDb, minLevelDb}) → Promise<void>
31
+ await codec.setDacRamp(8); // Set DAC soft-ramp rate, (rate 0–15) → Promise<void>
32
+ await codec.setMute(false); // Unmute the DAC, (muted=false) → Promise<void>
33
+
34
+ // --- Ramp the playback volume ---
35
+ // Step from -60 dB to -10 dB, reading the value back each time.
36
+ for (let vol = -60; vol <= -10; vol += 10) {
37
+ await codec.setVolume(vol); // Set DAC volume, (db −95.5–32 dB) → Promise<void>
38
+ console.log('volume', await codec.getVolume(), 'dB'); // Read back DAC volume, () → Promise<float dB>
39
+ await sleep(500);
40
+ }
41
+
42
+ // --- Echo-cancellation feedback and loopback ---
43
+ // "dac_adc" puts the DAC data next to the microphone on ADCDAT so the host
44
+ // can cancel the speaker echo; the loopback routes the microphone to the
45
+ // speaker for a quick acoustic check.
46
+ await codec.setAdcdatMode('dac_adc'); // Select ADCDAT content, (mode) → Promise<void>
47
+ await sleep(2000);
48
+ await codec.setAdcdatMode('adc_adc'); // Restore ADCDAT content, (mode) → Promise<void>
49
+ await codec.setLoopback(true); // Route ADC output into the DAC, (enabled) → Promise<void>
50
+ await sleep(2000);
51
+ await codec.setLoopback(false); // Disable loopback, (enabled) → Promise<void>
52
+
53
+ // --- Shut down ---
54
+ // Mute first so power-down does not pop, then enter standby.
55
+ await codec.setMute(true); // Mute the DAC, (muted=true) → Promise<void>
56
+ await codec.powerDown(); // Enter standby, () → Promise<void>
57
+ }
58
+
59
+ main();
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { ES8311Minimal } = require('../../../src/chips/adc_dac/es8311');
5
+
6
+ async function main() {
7
+ const connection = new I2CConnection(1, 0x18); // Create I2C connection, (bus=1, addr=0x18)
8
+ const codec = new ES8311Minimal(connection, 12288000, 48000); // Create ES8311 driver and run the init sequence, (connection, mclkHz=12288000 Hz, sampleRateHz=48000 Hz)
9
+
10
+ await codec.setMicGain(24); // Set microphone PGA gain, (db 0–30 dB, 3 dB steps) → Promise<void>
11
+ await codec.setMute(false); // Unmute the DAC, (muted=false) → Promise<void>
12
+ await codec.setVolume(-20.0); // Set DAC volume, (db −95.5–32 dB, 0.5 dB steps) → Promise<void>
13
+
14
+ await new Promise((resolve) => setTimeout(resolve, 5000));
15
+ await codec.setMute(true); // Mute the DAC, (muted=true) → Promise<void>
16
+ }
17
+
18
+ main();
@@ -0,0 +1,97 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { Mcp4xxxFull } = require('../../../src/chips/adc_dac/mcp4xxx');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x2C', 16);
8
+
9
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
10
+ // MCP4651: dual 8-bit potentiometer (volatile); the non-volatile calls at the end need e.g. an MCP4661.
11
+ const pot = new Mcp4xxxFull(connection, 'MCP4651', 10000.0, 75.0); // Create MCP4XXX driver, (connection, part='MCP4532', rAb=10000 Ω, rWiper=75 Ω, hvc=null, hvcSettleMs=1) → Mcp4xxxFull
12
+
13
+ (async () => {
14
+ await pot.init(); // Bus check, () → void
15
+ // reads wipers and TCON, no writes
16
+
17
+ // --- Part properties ---
18
+ console.log(pot.channels()); // Number of networks, () → int 1-2
19
+ // property of the selected part
20
+ console.log(pot.steps()); // Number of wiper positions, () → int 129 or 257
21
+ // max code + 1
22
+ console.log(pot.isPotentiometer()); // Terminal A on a pin, () → bool
23
+ // true for the X1 parts
24
+ console.log(pot.isNonvolatile()); // Has EEPROM, () → bool
25
+ // true for 454X / 456X / 464X / 466X
26
+
27
+ // --- Wiper position and resistance ---
28
+ await pot.setWiper(100, 0); // Set wiper, (code 0-256, channel=0) → void
29
+ // writes [(0 << 4) | D8, code & 0xFF]; code clamped
30
+ console.log(await pot.getWiper(0)); // Read wiper, (channel=0) → int 0-256
31
+ // two-byte read of the wiper register
32
+ await pot.setBoth(10, 20); // Set both wipers, (code0, code1) → void
33
+ // dual parts only; two transactions
34
+ await pot.setResistance(2200.0, 1); // Set W-B resistance, (ohms, channel=0) → void
35
+ // nearest code of R = N/max*RAB + RW, clamped
36
+ console.log(await pot.getResistance(1)); // Read W-B resistance, (channel=0) → float Ω
37
+ // N/max*RAB + RW
38
+ console.log(pot.getResistanceStep()); // Resistance of one step, () → float Ω
39
+ // RAB / max code
40
+
41
+ // --- Ratio and W-A resistance ---
42
+ await pot.setRatio(0.5, 0); // Set wiper ratio, (ratio 0.0-1.0, channel=0) → void
43
+ // code = round(ratio * max code)
44
+ console.log(await pot.getRatio(0)); // Read wiper ratio, (channel=0) → float 0.0-1.0
45
+ // code / max code
46
+ await pot.setResistanceWa(3300.0, 0); // Set W-A resistance, (ohms, channel=0) → void
47
+ // potentiometer parts only
48
+ console.log(await pot.getResistanceWa(0)); // Read W-A resistance, (channel=0) → float Ω
49
+ // (max code - N)/max*RAB + RW
50
+
51
+ // --- Increment / decrement ---
52
+ console.log(await pot.increment(8, 0)); // Step wiper up, (steps=1, channel=0) → int
53
+ // one continuous transaction of increment commands, saturating
54
+ console.log(await pot.decrement(4, 0)); // Step wiper down, (steps=1, channel=0) → int
55
+ // same with decrement commands, saturating at 0
56
+
57
+ // --- Shutdown and terminals ---
58
+ await pot.shutdown(1); // Shut network down, (channel=0) → void
59
+ // TCON.RxHW = 0: A open, W tied to B; wiper kept
60
+ console.log(await pot.isShutdown(1)); // Read shutdown state, (channel=0) → bool
61
+ // from TCON
62
+ await pot.resume(1); // Leave shutdown, (channel=0) → void
63
+ // TCON.RxHW = 1
64
+ await pot.setTerminals(true, false, true, 0); // Connect terminals, (a=true, w=true, b=true, channel=0) → void
65
+ // TCON.RxA / RxW / RxB, other bits preserved
66
+ console.log(await pot.getTerminals(0)); // Read terminals, (channel=0) → {a, w, b}
67
+ // from TCON
68
+ await pot.setTerminals(true, true, true, 0); // Reconnect all terminals, (a=true, w=true, b=true, channel=0) → void
69
+ // restores the wiper terminal
70
+ console.log(await pot.getTcon()); // Read TCON, () → int 0-0x1FF
71
+ // raw terminal control register
72
+ await pot.setGeneralCall(true); // Set General Call, (enabled) → void
73
+ // TCON.GCEN; chip answers address 0x00 commands
74
+
75
+ // --- Raw access, model, reset ---
76
+ console.log(await pot.readRegister(0x04)); // Raw read, (address 0-15) → int 0-0x1FF
77
+ // nine-bit value of any address the part has
78
+ await pot.writeRegister(0x04, 0x1FF); // Raw write, (address, value) → void
79
+ // volatile wipers, TCON (and EEPROM addresses on NV parts)
80
+ pot.setRab(10000.0, 75.0); // Set resistance model, (rAb Ω, rWiper Ω) → void
81
+ // no I²C traffic; affects conversions only
82
+ await pot.reset(); // Emulate power-on reset, () → void
83
+ // mid-scale (or EEPROM wiper) in every wiper, TCON 0x1FF
84
+
85
+ // --- Non-volatile parts only (MCP454X / 456X / 464X / 466X) ---
86
+ // console.log(await pot.readStatus()); // Read STATUS, () → {eepromBusy, wiperLock, writeProtect}
87
+ // await pot.waitReady(20); // Wait for the EEPROM write cycle, (timeoutMs=20 ms) → void
88
+ // console.log(await pot.getNvWiper(0)); // Read EEPROM wiper, (channel=0) → int
89
+ // await pot.setNvWiper(64, 0); // Write EEPROM wiper, (code, channel=0) → void
90
+ // console.log(await pot.storeWiper(0)); // Store current wiper, (channel=0) → int
91
+ // console.log(await pot.readData(0)); // Read EEPROM register, (index 0-9) → int 0-0x1FF
92
+ // await pot.writeData(0, 0x155); // Write EEPROM register, (index 0-9, value 0-0x1FF) → void
93
+ // console.log(await pot.isWiperLocked(0)); // Read WiperLock, (channel=0) → bool
94
+ // console.log(await pot.isWriteProtected()); // Read write protect, () → bool
95
+ // await pot.setWiperLock(true, 0); // High-voltage command, (locked, channel=0) → void (needs hvc pin)
96
+ // await pot.setWriteProtect(true); // High-voltage command, (enabled) → void (needs hvc pin)
97
+ })();