periph 1.3.3 → 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 (41) hide show
  1. package/README.md +9 -0
  2. package/examples/adc_dac/es8311/complete.js +80 -0
  3. package/examples/adc_dac/es8311/demo.js +59 -0
  4. package/examples/adc_dac/es8311/minimal.js +18 -0
  5. package/examples/adc_dac/mcp4xxx/complete.js +97 -0
  6. package/examples/adc_dac/mcp4xxx/demo.js +76 -0
  7. package/examples/adc_dac/mcp4xxx/minimal.js +22 -0
  8. package/examples/imu/qmi8658a/complete.js +134 -0
  9. package/examples/imu/qmi8658a/demo.js +81 -0
  10. package/examples/imu/qmi8658a/minimal.js +22 -0
  11. package/examples/motor/tmc2130/complete.js +138 -0
  12. package/examples/motor/tmc2130/demo.js +96 -0
  13. package/examples/motor/tmc2130/minimal.js +30 -0
  14. package/examples/motor/tmc2208/complete.js +92 -0
  15. package/examples/motor/tmc2208/demo.js +85 -0
  16. package/examples/motor/tmc2208/minimal.js +25 -0
  17. package/examples/motor/tmc2209/complete.js +106 -0
  18. package/examples/motor/tmc2209/demo.js +97 -0
  19. package/examples/motor/tmc2209/minimal.js +25 -0
  20. package/examples/motor/tmc5160/complete.js +205 -0
  21. package/examples/motor/tmc5160/demo.js +104 -0
  22. package/examples/motor/tmc5160/minimal.js +35 -0
  23. package/examples/power/axp2101/complete.js +135 -0
  24. package/examples/power/axp2101/demo.js +68 -0
  25. package/examples/power/axp2101/minimal.js +24 -0
  26. package/examples/rtc/pcf85063a/complete.js +68 -0
  27. package/examples/rtc/pcf85063a/demo.js +76 -0
  28. package/examples/rtc/pcf85063a/minimal.js +20 -0
  29. package/package.json +1 -1
  30. package/src/chips/adc_dac/es8311.js +621 -0
  31. package/src/chips/adc_dac/mcp4xxx.js +982 -0
  32. package/src/chips/imu/qmi8658a.js +1011 -0
  33. package/src/chips/motor/tmc2130.js +537 -0
  34. package/src/chips/motor/tmc2208.js +490 -0
  35. package/src/chips/motor/tmc2209.js +565 -0
  36. package/src/chips/motor/tmc5160.js +900 -0
  37. package/src/chips/power/axp2101.js +968 -0
  38. package/src/chips/rtc/pcf85063a.js +482 -0
  39. package/src/connection/uart.js +9 -0
  40. package/src/connection/uart_mock.js +65 -0
  41. package/src/discovery/registry.js +25 -0
package/README.md CHANGED
@@ -49,6 +49,7 @@ Each chip exposes two classes:
49
49
  | APDS-9930 | Light sensor | `periph/src/chips/light/apds-9930` |
50
50
  | APDS9960 | Light sensor | `periph/src/chips/light/apds9960` |
51
51
  | AS5600 | Magnetometer | `periph/src/chips/magnetometer/as5600` |
52
+ | AXP2101 | Power monitor | `periph/src/chips/power/axp2101` |
52
53
  | BMA150 | Accelerometer | `periph/src/chips/accelerometer/bma150` |
53
54
  | BMA180 | Accelerometer | `periph/src/chips/accelerometer/bma180` |
54
55
  | BME280 | Environmental sensor | `periph/src/chips/environmental/bme280` |
@@ -63,6 +64,7 @@ Each chip exposes two classes:
63
64
  | DRV8830 | Motor driver | `periph/src/chips/motor/drv8830` |
64
65
  | DS3231 | RTC | `periph/src/chips/rtc/ds3231` |
65
66
  | ENS160 | Gas sensor | `periph/src/chips/gas/ens160` |
67
+ | ES8311 | ADC/DAC | `periph/src/chips/adc_dac/es8311` |
66
68
  | FXOS8700 | Accelerometer | `periph/src/chips/accelerometer/fxos8700` |
67
69
  | HMC5883L | Magnetometer | `periph/src/chips/magnetometer/hmc5883l` |
68
70
  | HX710A | ADC/DAC | `periph/src/chips/adc_dac/hx710a` |
@@ -87,6 +89,7 @@ Each chip exposes two classes:
87
89
  | MCP2515 | Comms | `periph/src/chips/comms/mcp2515` |
88
90
  | MCP4725 | ADC/DAC | `periph/src/chips/adc_dac/mcp4725` |
89
91
  | MCP4728 | ADC/DAC | `periph/src/chips/adc_dac/mcp4728` |
92
+ | MCP4XXX | ADC/DAC | `periph/src/chips/adc_dac/mcp4xxx` |
90
93
  | MCP9808 | Temperature sensor | `periph/src/chips/temperature/mcp9808` |
91
94
  | MFRC522 | RFID/NFC | `periph/src/chips/rfid/mfrc522` |
92
95
  | MMA8451Q | Accelerometer | `periph/src/chips/accelerometer/mma8451q` |
@@ -98,6 +101,7 @@ Each chip exposes two classes:
98
101
  | NEO6 | GNSS/GPS | `periph/src/chips/gnss/neo6` |
99
102
  | NEOPIXELRGBBASE | LED driver | `periph/src/chips/led/_NeoPixelRGBBase` |
100
103
  | NEOPIXELRGBWBASE | LED driver | `periph/src/chips/led/_NeoPixelRGBWBase` |
104
+ | PCF85063A | RTC | `periph/src/chips/rtc/pcf85063a` |
101
105
  | PCF8523 | RTC | `periph/src/chips/rtc/pcf8523` |
102
106
  | PCF8574 | IO expander | `periph/src/chips/io_expander/pcf8574` |
103
107
  | PCF8575 | IO expander | `periph/src/chips/io_expander/pcf8575` |
@@ -105,12 +109,17 @@ Each chip exposes two classes:
105
109
  | PCF8578 | Display driver | `periph/src/chips/display/pcf8578` |
106
110
  | PCF8579 | Display driver | `periph/src/chips/display/pcf8579` |
107
111
  | PCF8591 | ADC/DAC | `periph/src/chips/adc_dac/pcf8591` |
112
+ | QMI8658A | IMU | `periph/src/chips/imu/qmi8658a` |
108
113
  | RDA5807M | Comms | `periph/src/chips/comms/rda5807m` |
109
114
  | RFM9X | Comms | `periph/src/chips/comms/rfm9x` |
110
115
  | SD_SPI | Memory | `periph/src/chips/memory/sd_spi` |
111
116
  | SK6812RGBW | LED driver | `periph/src/chips/led/sk6812rgbw` |
112
117
  | SSD1331 | Display driver | `periph/src/chips/display/ssd1331` |
113
118
  | ST7036 | Display driver | `periph/src/chips/display/st7036` |
119
+ | TMC2130 | Motor driver | `periph/src/chips/motor/tmc2130` |
120
+ | TMC2208 | Motor driver | `periph/src/chips/motor/tmc2208` |
121
+ | TMC2209 | Motor driver | `periph/src/chips/motor/tmc2209` |
122
+ | TMC5160 | Motor driver | `periph/src/chips/motor/tmc5160` |
114
123
  | TMP117 | Temperature sensor | `periph/src/chips/temperature/tmp117` |
115
124
  | TPIC6B595 | IO expander | `periph/src/chips/io_expander/tpic6b595` |
116
125
  | UC1611S | Display driver | `periph/src/chips/display/uc1611s` |
@@ -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
+ })();
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { Mcp4xxxFull } = require('../../../src/chips/adc_dac/mcp4xxx');
5
+
6
+ const PART = process.env.MCP4XXX_PART || 'MCP4532'; // any of MCP4531 ... MCP4662
7
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
8
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x58', 16);
9
+
10
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
11
+ const pot = new Mcp4xxxFull(connection, PART, 10000.0, 75.0); // Create MCP4XXX driver, (connection, part='MCP4532', rAb=10000 Ω, rWiper=75 Ω, hvc=null, hvcSettleMs=1) → Mcp4xxxFull
12
+
13
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
14
+
15
+ (async () => {
16
+ await pot.init(); // Bus check, () → void
17
+
18
+ // --- Identify the family member ---
19
+ // One driver covers sixteen parts; the descriptor tells resolution, networks and memory type.
20
+ console.log(PART, pot.channels(), 'network(s)', pot.steps(), 'steps', // Part properties, () → int
21
+ pot.isPotentiometer() ? 'pot' : 'rheostat', pot.isNonvolatile() ? 'EEPROM' : 'RAM');
22
+ console.log('power-up wiper', await pot.getWiper(), await pot.getResistance(), 'ohm'); // Read wiper, (channel=0) → int
23
+
24
+ // --- Set 2.2 kΩ and report the quantisation error ---
25
+ // The wiper snaps to the nearest step of RAB / max code.
26
+ await pot.setResistance(2200.0); // Set W-B resistance, (ohms, channel=0) → void
27
+ const actual = await pot.getResistance(); // Read W-B resistance, (channel=0) → float Ω
28
+ console.log('target=2200 ohm code=%d actual=%s ohm error=%s ohm', await pot.getWiper(), actual.toFixed(1), (actual - 2200).toFixed(1));
29
+
30
+ // --- Step the wiper up and down ---
31
+ // increment / decrement send one command byte per step in a single transaction and
32
+ // saturate at full scale and zero scale.
33
+ for (const [steps, up] of [[8, true], [8, true], [4, false], [10, true]]) {
34
+ const code = up ? await pot.increment(steps) : await pot.decrement(steps); // Step wiper, (steps=1, channel=0) → int
35
+ console.log('%s%d -> code=%d R_WB=%s ohm', up ? '+' : '-', steps, code, (await pot.getResistance()).toFixed(1));
36
+ }
37
+
38
+ // --- Ratios ---
39
+ // The ratio is the fraction of RAB between W and B (the unloaded divider ratio of a potentiometer).
40
+ for (const ratio of [0.0, 0.25, 0.5, 0.75, 1.0]) {
41
+ await pot.setRatio(ratio); // Set wiper ratio, (ratio 0.0-1.0, channel=0) → void
42
+ let line = `ratio=${ratio.toFixed(2)} code=${await pot.getWiper()} R_WB=${(await pot.getResistance()).toFixed(1)}`;
43
+ if (pot.isPotentiometer()) line += ` R_WA=${(await pot.getResistanceWa()).toFixed(1)}`; // Read W-A resistance, (channel=0) → float Ω
44
+ console.log(line);
45
+ }
46
+
47
+ // --- Dual parts: drive both networks ---
48
+ if (pot.channels() === 2) {
49
+ await pot.setBoth(32, 96); // Set both wipers, (code0, code1) → void
50
+ console.log('both:', await pot.getWiper(0), await pot.getWiper(1), '->', await pot.increment(5, 1), await pot.decrement(2, 1));
51
+ }
52
+
53
+ // --- Shutdown and terminal disconnect ---
54
+ // Shutdown ties W to B and opens A without losing the wiper; setTerminals(true, false, true) floats W.
55
+ await pot.shutdown(); // Shut network down, (channel=0) → void
56
+ console.log('shutdown=%s code=%d', await pot.isShutdown(), await pot.getWiper()); // Read state, (channel=0) → bool
57
+ await sleep(1000);
58
+ await pot.resume(); // Leave shutdown, (channel=0) → void
59
+ await pot.setTerminals(true, false, true); // Disconnect the wiper, (a=true, w=true, b=true, channel=0) → void
60
+ console.log('terminals', await pot.getTerminals()); // Read terminals, (channel=0) → {a, w, b}
61
+ await pot.setTerminals(true, true, true); // Reconnect all terminals, (a=true, w=true, b=true, channel=0) → void
62
+
63
+ // --- Non-volatile parts: EEPROM wiper and data ---
64
+ // storeWiper makes the setting survive power cycles; every EEPROM write uses one of the
65
+ // 1 000 000 write cycles, so do not do this in a loop.
66
+ if (pot.isNonvolatile()) {
67
+ console.log(await pot.readStatus()); // Read STATUS, () → {eepromBusy, wiperLock, writeProtect}
68
+ console.log('stored', await pot.storeWiper()); // Store the wiper in EEPROM, (channel=0) → int
69
+ await pot.writeData(0, 0x155); // Write calibration marker, (index 0-9, value 0-0x1FF) → void
70
+ console.log('data0', (await pot.readData(0)).toString(16), 'nv wiper', await pot.getNvWiper()); // Read back, (index) → int
71
+ }
72
+
73
+ // --- Back to the power-up state ---
74
+ await pot.reset(); // Emulate power-on reset, () → void
75
+ console.log('after reset:', await pot.getWiper());
76
+ })();
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { Mcp4xxxMinimal } = 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 || '0x58', 16);
8
+
9
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
10
+ const pot = new Mcp4xxxMinimal(connection, 'MCP4532', 10000.0, 75.0); // Create MCP4XXX driver, (connection, part='MCP4532', rAb=10000 Ω, rWiper=75 Ω) → Mcp4xxxMinimal
11
+
12
+ (async () => {
13
+ await pot.init(); // Bus check, () → void
14
+ await pot.setWiper(32); // Set wiper, (code 0-128, channel=0) → void
15
+ await pot.setResistance(2200.0); // Set W-B resistance, (ohms, channel=0) → void
16
+
17
+ setInterval(async () => {
18
+ const code = await pot.getWiper(); // Read wiper, (channel=0) → int 0-128
19
+ const ohms = await pot.getResistance(); // Read W-B resistance, (channel=0) → float Ω
20
+ console.log('code=%d R_WB=%s ohm', code, ohms.toFixed(0));
21
+ }, 1000);
22
+ })();
@@ -0,0 +1,134 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { QMI8658AFull } = require('../../../src/chips/imu/qmi8658a');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x6B', 16);
8
+
9
+ const sleep = (ms) => new Promise(r => setTimeout(r, ms));
10
+
11
+ async function main() {
12
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
13
+ const imu = new QMI8658AFull(connection); // Create QMI8658A driver, (connection) → void
14
+ const [ax, ay, az] = await imu.accel(); // Read 3-axis acceleration, () → [number, number, number] m/s²
15
+ // converts raw counts at 16384 LSB/g (±2 g)
16
+ const [gx, gy, gz] = await imu.gyro(); // Read 3-axis angular rate, () → [number, number, number] rad/s
17
+ // converts raw counts at 128 LSB/dps (±256 dps)
18
+ const [rax, ray, raz] = await imu.accelRaw(); // Read raw accel counts, () → [number, number, number]
19
+ // one 6-byte burst, signed 16-bit
20
+ const [rgx, rgy, rgz] = await imu.gyroRaw(); // Read raw gyro counts, () → [number, number, number]
21
+ // one 6-byte burst, signed 16-bit
22
+ const [accel, gyro, temp] = await imu.readAll(); // Read one coherent sample, () → [[number, number, number], [number, number, number], number] m/s², rad/s, °C
23
+ // one 14-byte burst of registers 0x33…0x40
24
+ const t = await imu.temperature(); // Read die temperature, () → number °C
25
+ // signed 8.8 fixed point, raw / 256
26
+ const ts = await imu.timestamp(); // Read sample counter, () → number
27
+ // 24-bit counter, wraps at 0xFFFFFF
28
+ const ready = await imu.dataReady(); // Check for new data, () → boolean
29
+ // STATUS0 aDA / gDA
30
+ await imu.configureAccel(1, 5); // Configure accelerometer, (fullScale=0, odr=5) → void
31
+ // CTRL2: 0=±2, 1=±4, 2=±8, 3=±16 g; ODR code 5 = 224.2 Hz
32
+ await imu.configureGyro(5, 5); // Configure gyroscope, (fullScale=4, odr=5) → void
33
+ // CTRL3: 0=±16 … 7=±2048 dps
34
+ await imu.configureFilters(true, 3, true, 3); // Configure low-pass filters, (accelFilter=true, accelMode=3, gyroFilter=true, gyroMode=3) → void
35
+ // CTRL5: mode 3 = 13.37 % of ODR
36
+ await imu.setSensors(true, true, false); // Enable sensors, (accel=true, gyro=true, gyroSnooze=false) → void
37
+ // CTRL7 aEN / gEN / gSN
38
+ await imu.configureFifo(2, 1, 16); // Configure FIFO, (mode=2, size=3, watermark=0) → void
39
+ // stream mode, 32 samples, watermark 16
40
+ await sleep(500);
41
+ const fifoFlags = await imu.fifoStatus(); // Read FIFO flags, () → number
42
+ // raw FIFO_STATUS byte
43
+ const fifoBytes = await imu.fifoCount(); // Read FIFO fill, () → number bytes
44
+ // two bytes per sample word
45
+ const data = await imu.readFifo(); // Drain the FIFO, (count?) → Buffer
46
+ // REQ_FIFO, chunked FIFO_DATA reads, FIFO_RD_MODE cleared
47
+ await imu.resetFifo(); // Reset the FIFO, () → void
48
+ // CTRL9 RST_FIFO
49
+ await imu.configureFifo(0); // Back to bypass, (mode=2, size=3, watermark=0) → void
50
+ // bypass re-enables data-ready
51
+ await imu.configureAnyMotion(0.25, 3, 0b111, false); // Configure any-motion, (thresholdG=0.25, window=3, axes=0b111, logicAnd=false) → void
52
+ // two CTRL9 CONFIGURE_MOTION sets
53
+ await imu.configureNoMotion(0.125, 30, 0b111, true); // Configure no-motion, (thresholdG=0.125, window=30, axes=0b111, logicAnd=true) → void
54
+ // same command, no-motion fields
55
+ await imu.configureSignificantMotion(150, 600); // Configure significant motion, (waitWindow=150, confirmWindow=600) → void
56
+ // wait and confirm windows in samples
57
+ await imu.enableMotion(true, true, true); // Enable motion engines, (anyMotion=false, noMotion=false, significant=false) → void
58
+ // CTRL8 bits 1–3
59
+ await imu.enableMotion(); // Disable motion engines, (anyMotion=false, noMotion=false, significant=false) → void
60
+ // clears CTRL8 bits 1–3
61
+ await imu.configureTap(); // Configure tap engine, (priority=0, peakWindow=20, tapWindow=50, doubleTapWindow=250, alpha=0.0625, gamma=0.25, peakThreshold=0.8, quietThreshold=0.4) → void
62
+ // two CTRL9 CONFIGURE_TAP sets
63
+ await imu.enableTap(true); // Enable tap engine, (enabled=true) → void
64
+ // CTRL8.Tap_EN
65
+ const [taps, axis, negative] = await imu.tapStatus(); // Read tap event, () → [number, number, boolean]
66
+ // count 0/1/2, axis 0–3, polarity
67
+ await imu.enableTap(false); // Disable tap engine, (enabled=true) → void
68
+ // clears CTRL8.Tap_EN
69
+ await imu.configurePedometer(); // Configure pedometer, (sampleCount=50, peakToPeakMg=200, peakMg=100, timeUp=200, timeLow=20, entryCount=10, precision=0, reportEvery=4) → void
70
+ // two CTRL9 CONFIGURE_PEDOMETER sets (50 Hz values)
71
+ await imu.enablePedometer(true); // Enable pedometer, (enabled=true) → void
72
+ // CTRL8.Pedo_EN; 0→1 resets the count
73
+ const steps = await imu.stepCount(); // Read step count, () → number
74
+ // 24-bit count
75
+ await imu.resetStepCount(); // Clear step count, () → void
76
+ // CTRL9 RESET_PEDOMETER
77
+ await imu.enablePedometer(false); // Disable pedometer, (enabled=true) → void
78
+ // clears CTRL8.Pedo_EN
79
+ await imu.setAccelOffset(0, 0, 0); // Set accel offset, (x, y, z) m/s² → void
80
+ // signed 4.12 g via CTRL9
81
+ await imu.setGyroOffset(0, 0, 0); // Set gyro offset, (x, y, z) rad/s → void
82
+ // signed 11.5 dps via CTRL9
83
+ const [calOk, codStatus] = await imu.calibrateGyro(); // Calibrate gyroscope, () → [boolean, number]
84
+ // calibration-on-demand, ~1.5 s, keep still
85
+ const [gainX, gainY, gainZ] = await imu.getGyroGains(); // Read gyro gains, () → [number, number, number]
86
+ // raw 16-bit gains from dVX…dVZ
87
+ await imu.setGyroGains(gainX, gainY, gainZ); // Restore gyro gains, (x, y, z) → void
88
+ // CTRL9 APPLY_GYRO_GAINS
89
+ const [accelOk, accelSelf] = await imu.selfTestAccel(); // Run accel self-test, () → [boolean, [number, number, number]] m/s²
90
+ // passes when every axis exceeds 200 mg
91
+ const [gyroOk, gyroSelf] = await imu.selfTestGyro(); // Run gyro self-test, () → [boolean, [number, number, number]] rad/s
92
+ // passes when every axis exceeds 300 dps
93
+ const info = await imu.deviceInfo(); // Read device info, () → {revision, firmware, usid}
94
+ // CTRL9 COPY_USID: revision, firmware, usid
95
+ await imu.setPullups(true, true, true, true); // Control pull-ups, (aux=true, sdx=true, cs=true, i2c=true) → void
96
+ // CTRL9 SET_RPU; false disables a group
97
+ await imu.setWakeOnMotion(100, 1, 0, 0); // Arm wake-on-motion, (thresholdMg, interruptPin=1, initialLevel=0, blankingSamples=0) → void
98
+ // accel 128 Hz ±2 g, CTRL9 WRITE_WOM_SETTING
99
+ await imu.setWakeOnMotion(0); // Leave wake-on-motion, (thresholdMg, interruptPin=1, initialLevel=0, blankingSamples=0) → void
100
+ // threshold 0 exits WoM mode
101
+ await imu.setSensors(true, true); // Re-enable sensors, (accel=true, gyro=true, gyroSnooze=false) → void
102
+ // restores normal operation
103
+ await imu.setInterruptPins(2, 2); // Route interrupts, (fifoPin=2, activityPin=2) → void
104
+ // CTRL1.FIFO_INT_SEL and CTRL8.ACTIVITY_INT_SEL
105
+ await imu.enableInterrupt(QMI8658AFull.SOURCE_DATA_READY); // Enable interrupt source, (source) → void
106
+ // clears DRDY_DIS, enables INT2
107
+ const status = await imu.pollInterrupt(); // Poll interrupt status, () → number
108
+ // STATUS0, STATUS1 and FIFO_STATUS as SOURCE_* bits
109
+ await imu.onInterrupt((s) => console.log('INT status 0x%s', s.toString(16))); // Subscribe to interrupts, (callback) → void
110
+ // uses the connection's interrupt pin or a 5 ms polling timer
111
+ await sleep(200);
112
+ await imu.offInterrupt(); // Unsubscribe, () → void
113
+ // stops the callback
114
+ await imu.disableInterrupt(QMI8658AFull.SOURCE_DATA_READY); // Disable interrupt source, (source) → void
115
+ // sets DRDY_DIS, releases INT2
116
+ await imu.setSyncSample(true); // Enable SyncSample, (enabled) → void
117
+ // locks each sample; reads wait for Avail and Locked
118
+ await imu.setSyncSample(false); // Disable SyncSample, (enabled) → void
119
+ // restores the AHB clock gating
120
+ await imu.setPowerDown(true); // Power down, (down=true) → void
121
+ // CTRL1.SensorDisable after disabling the sensors
122
+ await imu.setPowerDown(false); // Wake, (down=true) → void
123
+ // clears SensorDisable
124
+ await imu.setSensors(true, true); // Re-enable sensors, (accel=true, gyro=true, gyroSnooze=false) → void
125
+ // needs 150 ms gyroscope turn-on
126
+ await sleep(200);
127
+ await imu.reset(); // Soft reset, () → void
128
+ // RESET register, waits 15 ms
129
+ console.log(accel, gyro, temp, t, ts, ready, rax, ray, raz, rgx, rgy, rgz, fifoFlags, fifoBytes, data.length,
130
+ taps, axis, negative, steps, calOk, codStatus, accelOk, gyroOk, accelSelf, gyroSelf, info, status);
131
+ console.log('Complete example done');
132
+ }
133
+
134
+ main().catch(err => { console.error(err); process.exit(1); });