periph 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -12
- package/examples/accelerometer/adxl345/complete.js +52 -0
- package/examples/accelerometer/adxl345/demo.js +34 -0
- package/examples/accelerometer/adxl345/minimal.js +18 -0
- package/examples/accelerometer/adxl362/complete.js +57 -0
- package/examples/accelerometer/adxl362/demo.js +51 -0
- package/examples/accelerometer/adxl362/minimal.js +21 -0
- package/examples/adc_dac/ad7705/complete.js +32 -0
- package/examples/adc_dac/ad7705/demo.js +42 -0
- package/examples/adc_dac/ad7705/minimal.js +16 -0
- package/examples/adc_dac/ad7706/complete.js +35 -0
- package/examples/adc_dac/ad7706/demo.js +44 -0
- package/examples/adc_dac/ad7706/minimal.js +16 -0
- package/examples/adc_dac/hx710a/complete.js +45 -0
- package/examples/adc_dac/hx710a/demo.js +52 -0
- package/examples/adc_dac/hx710a/minimal.js +16 -0
- package/examples/adc_dac/hx710b/complete.js +45 -0
- package/examples/adc_dac/hx710b/demo.js +64 -0
- package/examples/adc_dac/hx710b/minimal.js +16 -0
- package/examples/adc_dac/hx711/complete.js +7 -7
- package/examples/adc_dac/hx711/demo.js +6 -6
- package/examples/adc_dac/hx711/minimal.js +7 -7
- package/examples/adc_dac/mcp4725/complete.js +19 -17
- package/examples/adc_dac/mcp4725/demo.js +5 -5
- package/examples/adc_dac/mcp4725/minimal.js +8 -6
- package/examples/adc_dac/mcp4728/complete.js +24 -22
- package/examples/adc_dac/mcp4728/demo.js +22 -22
- package/examples/adc_dac/mcp4728/minimal.js +8 -6
- package/examples/adc_dac/pcf8591/complete.js +41 -0
- package/examples/adc_dac/pcf8591/demo.js +39 -0
- package/examples/adc_dac/pcf8591/minimal.js +19 -0
- package/examples/comms/mcp2515/complete.js +75 -0
- package/examples/comms/mcp2515/demo.js +66 -0
- package/examples/comms/mcp2515/minimal.js +27 -0
- package/examples/comms/rda5807m/complete.js +55 -0
- package/examples/comms/rda5807m/demo.js +68 -0
- package/examples/comms/rda5807m/minimal.js +15 -0
- package/examples/comms/rfm9x/complete.js +50 -0
- package/examples/comms/rfm9x/demo.js +55 -0
- package/examples/comms/rfm9x/minimal.js +20 -0
- package/examples/display/pcf8576/complete.js +18 -15
- package/examples/display/pcf8576/demo.js +6 -6
- package/examples/display/pcf8576/minimal.js +12 -10
- package/examples/environmental/aht21/complete.js +15 -13
- package/examples/environmental/aht21/demo.js +8 -6
- package/examples/environmental/aht21/minimal.js +5 -5
- package/examples/environmental/bme280/complete.js +23 -20
- package/examples/environmental/bme280/demo.js +14 -14
- package/examples/environmental/bme280/minimal.js +13 -11
- package/examples/environmental/bme680/complete.js +25 -22
- package/examples/environmental/bme680/demo.js +38 -36
- package/examples/environmental/bme680/minimal.js +14 -12
- package/examples/gas/ens160/complete.js +29 -27
- package/examples/gas/ens160/demo.js +39 -37
- package/examples/gas/ens160/minimal.js +17 -15
- package/examples/gnss/neo6/complete.js +49 -0
- package/examples/gnss/neo6/demo.js +54 -0
- package/examples/gnss/neo6/minimal.js +30 -0
- package/examples/gyroscope/l3g4200d/complete.js +56 -0
- package/examples/gyroscope/l3g4200d/demo.js +49 -0
- package/examples/gyroscope/l3g4200d/minimal.js +19 -0
- package/examples/gyroscope/l3gd20h/complete.js +42 -0
- package/examples/gyroscope/l3gd20h/demo.js +29 -0
- package/examples/gyroscope/l3gd20h/minimal.js +13 -0
- package/examples/humidity/dht11/complete.js +22 -0
- package/examples/humidity/dht11/demo.js +38 -0
- package/examples/humidity/dht11/minimal.js +18 -0
- package/examples/imu/mpu6050/complete.js +27 -25
- package/examples/imu/mpu6050/demo.js +29 -26
- package/examples/imu/mpu6050/minimal.js +6 -6
- package/examples/imu/mpu9250/complete.js +65 -0
- package/examples/imu/mpu9250/demo.js +53 -0
- package/examples/imu/mpu9250/minimal.js +21 -0
- package/examples/imu/mpu9255/complete.js +73 -0
- package/examples/imu/mpu9255/demo.js +73 -0
- package/examples/imu/mpu9255/minimal.js +21 -0
- package/examples/io_expander/mcp23017/complete.js +70 -77
- package/examples/io_expander/mcp23017/demo.js +37 -33
- package/examples/io_expander/mcp23017/minimal.js +15 -11
- package/examples/io_expander/pcf8574/complete.js +60 -65
- package/examples/io_expander/pcf8574/demo.js +30 -25
- package/examples/io_expander/pcf8574/minimal.js +15 -11
- package/examples/io_expander/pcf8575/complete.js +24 -20
- package/examples/io_expander/pcf8575/demo.js +27 -23
- package/examples/io_expander/pcf8575/minimal.js +16 -12
- package/examples/io_expander/tpic6b595/complete.js +57 -0
- package/examples/io_expander/tpic6b595/demo.js +75 -0
- package/examples/io_expander/tpic6b595/minimal.js +26 -0
- package/examples/led/apa102/complete.js +72 -0
- package/examples/led/apa102/demo.js +92 -0
- package/examples/led/apa102/minimal.js +21 -0
- package/examples/led/sk6812rgbw/complete.js +42 -40
- package/examples/led/sk6812rgbw/demo.js +16 -16
- package/examples/led/sk6812rgbw/minimal.js +15 -17
- package/examples/led/ws2812b/complete.js +40 -38
- package/examples/led/ws2812b/demo.js +16 -16
- package/examples/led/ws2812b/minimal.js +13 -14
- package/examples/led/ws2814/complete.js +71 -0
- package/examples/led/ws2814/demo.js +82 -0
- package/examples/led/ws2814/minimal.js +23 -0
- package/examples/light/apds-9930/complete.js +46 -0
- package/examples/light/apds-9930/demo.js +31 -0
- package/examples/light/apds-9930/minimal.js +20 -0
- package/examples/light/apds9960/complete.js +45 -43
- package/examples/light/apds9960/demo.js +11 -9
- package/examples/light/apds9960/minimal.js +5 -5
- package/examples/magnetometer/as5600/complete.js +31 -29
- package/examples/magnetometer/as5600/demo.js +35 -33
- package/examples/magnetometer/as5600/minimal.js +7 -7
- package/examples/magnetometer/hmc5883l/complete.js +47 -0
- package/examples/magnetometer/hmc5883l/demo.js +50 -0
- package/examples/magnetometer/hmc5883l/minimal.js +15 -0
- package/examples/memory/24aa02uid/complete.js +23 -21
- package/examples/memory/24aa02uid/demo.js +32 -30
- package/examples/memory/24aa02uid/minimal.js +5 -5
- package/examples/motor/drv8830/complete.js +50 -0
- package/examples/motor/drv8830/demo.js +57 -0
- package/examples/motor/drv8830/minimal.js +23 -0
- package/examples/other/mpr121/complete.js +50 -0
- package/examples/other/mpr121/demo.js +30 -0
- package/examples/other/mpr121/minimal.js +17 -0
- package/examples/power/ade7953/complete.js +44 -0
- package/examples/power/ade7953/demo.js +28 -0
- package/examples/power/ade7953/minimal.js +15 -0
- package/examples/power/ina219/complete.js +20 -18
- package/examples/power/ina219/demo.js +15 -13
- package/examples/power/ina219/minimal.js +8 -8
- package/examples/power/ina226/complete.js +24 -22
- package/examples/power/ina226/demo.js +22 -20
- package/examples/power/ina226/minimal.js +5 -5
- package/examples/power/ina3221/complete.js +51 -49
- package/examples/power/ina3221/demo.js +13 -13
- package/examples/power/ina3221/minimal.js +8 -8
- package/examples/pressure/bmp085/complete.js +29 -0
- package/examples/pressure/bmp085/demo.js +34 -0
- package/examples/pressure/bmp085/minimal.js +19 -0
- package/examples/pressure/bmp180/complete.js +20 -17
- package/examples/pressure/bmp180/demo.js +24 -22
- package/examples/pressure/bmp180/minimal.js +13 -11
- package/examples/pressure/bmp280/complete.js +23 -20
- package/examples/pressure/bmp280/demo.js +44 -41
- package/examples/pressure/bmp280/minimal.js +13 -11
- package/examples/pressure/bmp384/complete.js +29 -0
- package/examples/pressure/bmp384/demo.js +40 -0
- package/examples/pressure/bmp384/minimal.js +18 -0
- package/examples/pressure/bmp581/complete.js +34 -0
- package/examples/pressure/bmp581/demo.js +56 -0
- package/examples/pressure/bmp581/minimal.js +19 -0
- package/examples/pressure/lps22df/complete.js +50 -0
- package/examples/pressure/lps22df/demo.js +41 -0
- package/examples/pressure/lps22df/minimal.js +19 -0
- package/examples/pressure/lps28dfw/complete.js +37 -0
- package/examples/pressure/lps28dfw/demo.js +33 -0
- package/examples/pressure/lps28dfw/minimal.js +19 -0
- package/examples/pressure/lps33hw/complete.js +43 -0
- package/examples/pressure/lps33hw/demo.js +43 -0
- package/examples/pressure/lps33hw/minimal.js +19 -0
- package/examples/rfid/mfrc522/complete.js +44 -0
- package/examples/rfid/mfrc522/demo.js +70 -0
- package/examples/rfid/mfrc522/minimal.js +17 -0
- package/examples/rtc/ds3231/complete.js +77 -0
- package/examples/rtc/ds3231/demo.js +60 -0
- package/examples/rtc/ds3231/minimal.js +23 -0
- package/examples/rtc/pcf8523/complete.js +66 -0
- package/examples/rtc/pcf8523/demo.js +65 -0
- package/examples/rtc/pcf8523/minimal.js +20 -0
- package/examples/temperature/mcp9808/complete.js +89 -0
- package/examples/temperature/mcp9808/demo.js +62 -0
- package/examples/temperature/mcp9808/minimal.js +21 -0
- package/examples/temperature/tmp117/complete.js +90 -0
- package/examples/temperature/tmp117/demo.js +73 -0
- package/examples/temperature/tmp117/minimal.js +21 -0
- package/examples/tof/vl53l0x/complete.js +118 -0
- package/examples/tof/vl53l0x/demo.js +83 -0
- package/examples/tof/vl53l0x/minimal.js +25 -0
- package/examples/tof/vl53l1x/complete.js +151 -0
- package/examples/tof/vl53l1x/demo.js +100 -0
- package/examples/tof/vl53l1x/minimal.js +25 -0
- package/package.json +5 -1
- package/src/chips/accelerometer/adxl345.js +482 -0
- package/src/chips/accelerometer/adxl362.js +594 -0
- package/src/chips/adc_dac/ad7705.js +345 -0
- package/src/chips/adc_dac/ad7706.js +331 -0
- package/src/chips/adc_dac/hx710a.js +184 -0
- package/src/chips/adc_dac/hx710b.js +186 -0
- package/src/chips/adc_dac/hx711.js +15 -15
- package/src/chips/adc_dac/mcp4725.js +48 -40
- package/src/chips/adc_dac/mcp4728.js +57 -44
- package/src/chips/adc_dac/pcf8591.js +196 -0
- package/src/chips/comms/mcp2515.js +659 -0
- package/src/chips/comms/rda5807m.js +393 -0
- package/src/chips/comms/rfm9x.js +590 -0
- package/src/chips/display/pcf8576.js +42 -33
- package/src/chips/environmental/aht21.js +52 -37
- package/src/chips/environmental/bme280.js +85 -66
- package/src/chips/environmental/bme680.js +110 -87
- package/src/chips/gas/ens160.js +82 -64
- package/src/chips/gnss/neo6.js +438 -0
- package/src/chips/gyroscope/l3g4200d.js +366 -0
- package/src/chips/gyroscope/l3gd20h.js +314 -0
- package/src/chips/humidity/dht11.js +135 -0
- package/src/chips/imu/mpu6050.js +89 -66
- package/src/chips/imu/mpu9250.js +394 -0
- package/src/chips/imu/mpu9255.js +447 -0
- package/src/chips/io_expander/mcp23017.js +240 -157
- package/src/chips/io_expander/pcf8574.js +149 -124
- package/src/chips/io_expander/pcf8575.js +164 -135
- package/src/chips/io_expander/tpic6b595.js +242 -0
- package/src/chips/led/_NeoPixelRGBBase.js +204 -0
- package/src/chips/led/_NeoPixelRGBWBase.js +218 -0
- package/src/chips/led/apa102.js +236 -0
- package/src/chips/led/sk6812rgbw.js +15 -149
- package/src/chips/led/ws2812b.js +14 -139
- package/src/chips/led/ws2814.js +49 -0
- package/src/chips/light/apds-9930.js +342 -0
- package/src/chips/light/apds9960.js +158 -123
- package/src/chips/magnetometer/as5600.js +102 -82
- package/src/chips/magnetometer/hmc5883l.js +222 -0
- package/src/chips/memory/_24aa02uid.js +32 -29
- package/src/chips/motor/drv8830.js +239 -0
- package/src/chips/other/mpr121.js +375 -0
- package/src/chips/power/ade7953.js +427 -0
- package/src/chips/power/ina219.js +45 -40
- package/src/chips/power/ina226.js +50 -45
- package/src/chips/power/ina3221.js +95 -76
- package/src/chips/pressure/bmp085.js +251 -0
- package/src/chips/pressure/bmp180.js +54 -37
- package/src/chips/pressure/bmp280.js +72 -53
- package/src/chips/pressure/bmp384.js +410 -0
- package/src/chips/pressure/bmp581.js +489 -0
- package/src/chips/pressure/lps22df.js +341 -0
- package/src/chips/pressure/lps28dfw.js +314 -0
- package/src/chips/pressure/lps33hw.js +255 -0
- package/src/chips/rfid/mfrc522.js +674 -0
- package/src/chips/rtc/ds3231.js +504 -0
- package/src/chips/rtc/pcf8523.js +539 -0
- package/src/chips/temperature/mcp9808.js +488 -0
- package/src/chips/temperature/tmp117.js +471 -0
- package/src/chips/tof/_vl53_base.js +160 -0
- package/src/chips/tof/vl53l0x.js +816 -0
- package/src/chips/tof/vl53l1x.js +816 -0
- package/src/connection/connection.js +111 -0
- package/src/connection/dhtxx.js +138 -0
- package/src/connection/dhtxx_mock.js +39 -0
- package/src/{transport → connection}/hx711.js +49 -22
- package/src/connection/hx711_mock.js +52 -0
- package/src/{transport → connection}/i2c.js +13 -9
- package/src/connection/i2c_mock.js +91 -0
- package/src/connection/input_pin.js +156 -0
- package/src/connection/neo6_mock.js +45 -0
- package/src/{transport → connection}/neopixel.js +23 -4
- package/src/connection/output_pin.js +41 -0
- package/src/connection/sipo.js +159 -0
- package/src/{transport → connection}/smbus.js +14 -10
- package/src/{transport → connection}/spi.js +12 -8
- package/src/connection/spi_mock.js +151 -0
- package/src/{transport → connection}/uart.js +33 -26
- package/examples/gnss/.gitkeep +0 -0
- package/examples/humidity/.gitkeep +0 -0
- package/examples/motor/.gitkeep +0 -0
- package/examples/temperature/.gitkeep +0 -0
- package/examples/tof/.gitkeep +0 -0
- package/src/chips/gnss/.gitkeep +0 -0
- package/src/chips/motor/.gitkeep +0 -0
- package/src/chips/temperature/.gitkeep +0 -0
- package/src/chips/tof/.gitkeep +0 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const _REG_ELE0_7_TOUCH = 0x00;
|
|
4
|
+
const _REG_ELE8_PROX_TCH = 0x01;
|
|
5
|
+
const _REG_ELE0_7_OOR = 0x02;
|
|
6
|
+
const _REG_MHDR = 0x2B;
|
|
7
|
+
const _REG_NHDR = 0x2C;
|
|
8
|
+
const _REG_MHDF = 0x2F;
|
|
9
|
+
const _REG_NHDF = 0x30;
|
|
10
|
+
const _REG_E0TTH = 0x41;
|
|
11
|
+
const _REG_E0RTH = 0x42;
|
|
12
|
+
const _REG_EPROXTTH = 0x59;
|
|
13
|
+
const _REG_EPROXRTH = 0x5A;
|
|
14
|
+
const _REG_DEBOUNCE = 0x5B;
|
|
15
|
+
const _REG_CDC_CONFIG = 0x5C;
|
|
16
|
+
const _REG_CDT_CONFIG = 0x5D;
|
|
17
|
+
const _REG_ECR = 0x5E;
|
|
18
|
+
const _REG_AUTOCONFIG0 = 0x7B;
|
|
19
|
+
const _REG_AUTOCONFIG1 = 0x7C;
|
|
20
|
+
const _REG_USL = 0x7D;
|
|
21
|
+
const _REG_LSL = 0x7E;
|
|
22
|
+
const _REG_TL = 0x7F;
|
|
23
|
+
const _REG_SRST = 0x80;
|
|
24
|
+
|
|
25
|
+
const _SOFT_RESET_KEY = 0x63;
|
|
26
|
+
const _TOUCH_DEFAULT = 12;
|
|
27
|
+
const _RELEASE_DEFAULT = 6;
|
|
28
|
+
const _CDC_CONFIG_DEFAULT = 0x10;
|
|
29
|
+
const _CDT_CONFIG_DEFAULT = 0x24;
|
|
30
|
+
const _AUTOCONFIG0_DEFAULT = 0x0B;
|
|
31
|
+
const _ECR_DEFAULT = 0x8C;
|
|
32
|
+
const _USL_3V3 = 0xC9;
|
|
33
|
+
const _TL_3V3 = 0xB4;
|
|
34
|
+
const _LSL_3V3 = 0x82;
|
|
35
|
+
|
|
36
|
+
function _sleep(ms) {
|
|
37
|
+
const end = Date.now() + ms;
|
|
38
|
+
while (Date.now() < end) {}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* MPR121 proximity capacitive touch sensor controller — minimal interface.
|
|
43
|
+
*
|
|
44
|
+
* Provides 12-electrode touch/release detection with no configuration
|
|
45
|
+
* beyond the connection. Performs soft reset, applies default
|
|
46
|
+
* touch/release thresholds, enables the chip's automatic CDC/CDT
|
|
47
|
+
* configuration, and enters Run Mode on all 12 electrodes at
|
|
48
|
+
* construction.
|
|
49
|
+
*
|
|
50
|
+
* Default configuration (written at construction):
|
|
51
|
+
* - Touch threshold = 12 for each of ELE0..ELE11
|
|
52
|
+
* - Release threshold = 6 for each of ELE0..ELE11
|
|
53
|
+
* - MHDR = NHDR = MHDF = NHDF = 1
|
|
54
|
+
* - CDC_CONFIG = 0x10 (16 µA global CDC; FFI = 6 samples)
|
|
55
|
+
* - CDT_CONFIG = 0x24 (CDT = 1 µS, ESI = 16 ms sample interval)
|
|
56
|
+
* - AUTOCONFIG0 = 0x0B
|
|
57
|
+
* - USL = 0xC9, TL = 0xB4, LSL = 0x82 (3.3 V VDD)
|
|
58
|
+
* - ECR = 0x8C (all 12 electrodes enabled)
|
|
59
|
+
*
|
|
60
|
+
* @param {import('../../connection/connection').Connection} connection - Configured I2C connection pointing at the device (address 0x5A by default).
|
|
61
|
+
*/
|
|
62
|
+
class MPR121Minimal {
|
|
63
|
+
constructor(connection) {
|
|
64
|
+
this._conn = connection;
|
|
65
|
+
this._init();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async _init() {
|
|
69
|
+
await this._reset();
|
|
70
|
+
await this._writeReg(_REG_MHDR, 0x01);
|
|
71
|
+
await this._writeReg(_REG_NHDR, 0x01);
|
|
72
|
+
await this._writeReg(_REG_MHDF, 0x01);
|
|
73
|
+
await this._writeReg(_REG_NHDF, 0x01);
|
|
74
|
+
await this._writeReg(_REG_CDC_CONFIG, _CDC_CONFIG_DEFAULT);
|
|
75
|
+
await this._writeReg(_REG_CDT_CONFIG, _CDT_CONFIG_DEFAULT);
|
|
76
|
+
await this._writeReg(_REG_USL, _USL_3V3);
|
|
77
|
+
await this._writeReg(_REG_TL, _TL_3V3);
|
|
78
|
+
await this._writeReg(_REG_LSL, _LSL_3V3);
|
|
79
|
+
await this._writeReg(_REG_AUTOCONFIG0, _AUTOCONFIG0_DEFAULT);
|
|
80
|
+
for (let n = 0; n < 12; n++) {
|
|
81
|
+
await this._writeReg(_REG_E0TTH + 2 * n, _TOUCH_DEFAULT);
|
|
82
|
+
await this._writeReg(_REG_E0RTH + 2 * n, _RELEASE_DEFAULT);
|
|
83
|
+
}
|
|
84
|
+
await this._writeReg(_REG_ECR, _ECR_DEFAULT);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async _reset() {
|
|
88
|
+
await this._writeReg(_REG_SRST, _SOFT_RESET_KEY);
|
|
89
|
+
_sleep(1);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async _writeReg(reg, value) {
|
|
93
|
+
await this._conn.write(Buffer.from([reg & 0xFF, value & 0xFF]));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async _readReg(reg) {
|
|
97
|
+
return (await this._conn.writeRead(Buffer.from([reg & 0xFF]), 1))[0];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async _readReg16(reg) {
|
|
101
|
+
const buf = await this._conn.writeRead(Buffer.from([reg & 0xFF]), 2);
|
|
102
|
+
return (buf[0]) | ((buf[1] & 0x03) << 8);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Read the 12-bit electrode touch bitmask.
|
|
107
|
+
*
|
|
108
|
+
* Reads ELE0_7_TOUCH and ELE8_PROX_TOUCH as a coherent two-byte
|
|
109
|
+
* snapshot from register 0x00; ELEPROX is masked out.
|
|
110
|
+
*
|
|
111
|
+
* @returns {Promise<number>} 12-bit bitmask; bit n = 1 if ELEn is touched.
|
|
112
|
+
*/
|
|
113
|
+
async touched() {
|
|
114
|
+
const buf = await this._conn.writeRead(Buffer.from([_REG_ELE0_7_TOUCH]), 2);
|
|
115
|
+
return buf[0] | ((buf[1] & 0x0F) << 8);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Check whether a single electrode is currently touched.
|
|
120
|
+
* @param {number} electrode Electrode index 0-11.
|
|
121
|
+
* @returns {Promise<boolean>} True if ELE_electrode is currently touched.
|
|
122
|
+
*/
|
|
123
|
+
async isTouched(electrode) {
|
|
124
|
+
if (electrode < 0 || electrode > 11) throw new Error('electrode must be in 0..11');
|
|
125
|
+
return ((await this.touched()) & (1 << electrode)) !== 0;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* MPR121 full interface — extends MPR121Minimal.
|
|
131
|
+
*
|
|
132
|
+
* Adds explicit Stop/Run control, per-electrode and per-proximity
|
|
133
|
+
* threshold configuration, filtered-data and baseline access, baseline
|
|
134
|
+
* filter and AFE (sampling) configuration, debounce, autoconfig
|
|
135
|
+
* recomputation, OOR status, and over-current flag clear.
|
|
136
|
+
*/
|
|
137
|
+
class MPR121Full extends MPR121Minimal {
|
|
138
|
+
static get SOURCE_OOR() { return 0x04; }
|
|
139
|
+
static get SOURCE_ARF() { return 0x02; }
|
|
140
|
+
static get SOURCE_ACF() { return 0x01; }
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @param {import('../../connection/connection').Connection} connection - Configured I2C connection pointing at the device.
|
|
144
|
+
*/
|
|
145
|
+
constructor(connection) {
|
|
146
|
+
super(connection);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Software-reset the chip and re-apply Minimal defaults.
|
|
151
|
+
* @returns {Promise<void>}
|
|
152
|
+
*/
|
|
153
|
+
async reset() {
|
|
154
|
+
await this._reset();
|
|
155
|
+
await this._writeReg(_REG_MHDR, 0x01);
|
|
156
|
+
await this._writeReg(_REG_NHDR, 0x01);
|
|
157
|
+
await this._writeReg(_REG_MHDF, 0x01);
|
|
158
|
+
await this._writeReg(_REG_NHDF, 0x01);
|
|
159
|
+
await this._writeReg(_REG_CDC_CONFIG, _CDC_CONFIG_DEFAULT);
|
|
160
|
+
await this._writeReg(_REG_CDT_CONFIG, _CDT_CONFIG_DEFAULT);
|
|
161
|
+
await this._writeReg(_REG_USL, _USL_3V3);
|
|
162
|
+
await this._writeReg(_REG_TL, _TL_3V3);
|
|
163
|
+
await this._writeReg(_REG_LSL, _LSL_3V3);
|
|
164
|
+
await this._writeReg(_REG_AUTOCONFIG0, _AUTOCONFIG0_DEFAULT);
|
|
165
|
+
for (let n = 0; n < 12; n++) {
|
|
166
|
+
await this._writeReg(_REG_E0TTH + 2 * n, _TOUCH_DEFAULT);
|
|
167
|
+
await this._writeReg(_REG_E0RTH + 2 * n, _RELEASE_DEFAULT);
|
|
168
|
+
}
|
|
169
|
+
await this._writeReg(_REG_ECR, _ECR_DEFAULT);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Enter Stop Mode (ECR=0x00).
|
|
174
|
+
* @returns {Promise<void>}
|
|
175
|
+
*/
|
|
176
|
+
async stop() {
|
|
177
|
+
await this._writeReg(_REG_ECR, 0x00);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Enter Run Mode with the given electrode configuration.
|
|
182
|
+
* @param {number} [nElectrodes=12] Number of electrodes 1-12.
|
|
183
|
+
* @param {number} [cl=2] Calibration lock / baseline init 0-3.
|
|
184
|
+
* @param {number} [eleproxEn=0] Proximity enable 0-3.
|
|
185
|
+
* @returns {Promise<void>}
|
|
186
|
+
*/
|
|
187
|
+
async start(nElectrodes = 12, cl = 2, eleproxEn = 0) {
|
|
188
|
+
if (nElectrodes < 1 || nElectrodes > 12) throw new Error('n_electrodes must be in 1..12');
|
|
189
|
+
if (cl < 0 || cl > 3) throw new Error('cl must be in 0..3');
|
|
190
|
+
if (eleproxEn < 0 || eleproxEn > 3) throw new Error('eleprox_en must be in 0..3');
|
|
191
|
+
const ecr = ((cl & 0x03) << 6) | ((eleproxEn & 0x03) << 4) | (nElectrodes & 0x0F);
|
|
192
|
+
await this._writeReg(_REG_ECR, ecr);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Set touch and release thresholds for a single electrode.
|
|
197
|
+
* @param {number} electrode Electrode index 0-11.
|
|
198
|
+
* @param {number} touch Touch threshold 0-255.
|
|
199
|
+
* @param {number} release Release threshold 0-255.
|
|
200
|
+
* @returns {Promise<void>}
|
|
201
|
+
*/
|
|
202
|
+
async configureThresholds(electrode, touch, release) {
|
|
203
|
+
if (electrode < 0 || electrode > 11) throw new Error('electrode must be in 0..11');
|
|
204
|
+
await this._writeReg(_REG_E0TTH + 2 * electrode, touch & 0xFF);
|
|
205
|
+
await this._writeReg(_REG_E0RTH + 2 * electrode, release & 0xFF);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Apply the same touch and release thresholds to all 12 electrodes.
|
|
210
|
+
* @param {number} touch Touch threshold 0-255.
|
|
211
|
+
* @param {number} release Release threshold 0-255.
|
|
212
|
+
* @returns {Promise<void>}
|
|
213
|
+
*/
|
|
214
|
+
async configureAllThresholds(touch, release) {
|
|
215
|
+
for (let n = 0; n < 12; n++) {
|
|
216
|
+
await this.configureThresholds(n, touch, release);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Set ELEPROX touch and release thresholds.
|
|
222
|
+
* @param {number} touch ELEPROX touch threshold 0-255.
|
|
223
|
+
* @param {number} release ELEPROX release threshold 0-255.
|
|
224
|
+
* @returns {Promise<void>}
|
|
225
|
+
*/
|
|
226
|
+
async configureProximityThresholds(touch, release) {
|
|
227
|
+
await this._writeReg(_REG_EPROXTTH, touch & 0xFF);
|
|
228
|
+
await this._writeReg(_REG_EPROXRTH, release & 0xFF);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Read the 10-bit filtered capacitance data for an electrode.
|
|
233
|
+
* @param {number} electrode 0-11 for ELE0-ELE11, 12 for ELEPROX.
|
|
234
|
+
* @returns {Promise<number>} 10-bit value.
|
|
235
|
+
*/
|
|
236
|
+
async filtered(electrode) {
|
|
237
|
+
if (electrode < 0 || electrode > 12) throw new Error('electrode must be in 0..12');
|
|
238
|
+
const addr = (electrode === 12) ? 0x1C : (0x04 + 2 * electrode);
|
|
239
|
+
return this._readReg16(addr);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Read the 10-bit baseline for an electrode.
|
|
244
|
+
* @param {number} electrode 0-11 for ELE0-ELE11, 12 for ELEPROX.
|
|
245
|
+
* @returns {Promise<number>} 10-bit baseline value.
|
|
246
|
+
*/
|
|
247
|
+
async baseline(electrode) {
|
|
248
|
+
if (electrode < 0 || electrode > 12) throw new Error('electrode must be in 0..12');
|
|
249
|
+
const addr = (electrode === 12) ? 0x2A : (0x1E + electrode);
|
|
250
|
+
return (await this._readReg(addr)) << 2;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Write a baseline value (Stop Mode only).
|
|
255
|
+
* @param {number} electrode 0-11 for ELE0-ELE11, 12 for ELEPROX.
|
|
256
|
+
* @param {number} value 10-bit value 0-1023.
|
|
257
|
+
* @returns {Promise<void>}
|
|
258
|
+
*/
|
|
259
|
+
async setBaseline(electrode, value) {
|
|
260
|
+
if (electrode < 0 || electrode > 12) throw new Error('electrode must be in 0..12');
|
|
261
|
+
const addr = (electrode === 12) ? 0x2A : (0x1E + electrode);
|
|
262
|
+
await this._writeReg(addr, (value >> 2) & 0xFF);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Read the 13-bit out-of-range bitmask.
|
|
267
|
+
* @returns {Promise<number>} bits 0-11 = ELE0-ELE11 OOR, bit 12 = ELEPROX OOR.
|
|
268
|
+
*/
|
|
269
|
+
async oorStatus() {
|
|
270
|
+
const buf = await this._conn.writeRead(Buffer.from([_REG_ELE0_7_OOR]), 2);
|
|
271
|
+
return buf[0] | ((buf[1] & 0x1F) << 8);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Set the global baseline filter parameters (Stop Mode).
|
|
276
|
+
* @returns {Promise<void>}
|
|
277
|
+
*/
|
|
278
|
+
async configureBaselineFilter(mhdr, nhdr, nclr, fdlr, mhdf, nhdf, nclf, fdlf, nhdt, nclt, fdlt) {
|
|
279
|
+
await this._writeReg(_REG_MHDR, mhdr & 0x3F);
|
|
280
|
+
await this._writeReg(_REG_NHDR, nhdr & 0x3F);
|
|
281
|
+
await this._writeReg(0x2D, nclr & 0xFF);
|
|
282
|
+
await this._writeReg(0x2E, fdlr & 0xFF);
|
|
283
|
+
await this._writeReg(_REG_MHDF, mhdf & 0x3F);
|
|
284
|
+
await this._writeReg(_REG_NHDF, nhdf & 0x3F);
|
|
285
|
+
await this._writeReg(0x31, nclf & 0xFF);
|
|
286
|
+
await this._writeReg(0x32, fdlf & 0xFF);
|
|
287
|
+
await this._writeReg(0x33, nhdt & 0x3F);
|
|
288
|
+
await this._writeReg(0x34, nclt & 0xFF);
|
|
289
|
+
await this._writeReg(0x35, fdlt & 0xFF);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Set global AFE (sampling) configuration (Stop Mode).
|
|
294
|
+
* @returns {Promise<void>}
|
|
295
|
+
*/
|
|
296
|
+
async configureSampling(cdc, cdt, ffi, sfi, esi) {
|
|
297
|
+
const cdcCfg = ((ffi & 0x03) << 6) | (cdc & 0x3F);
|
|
298
|
+
const cdtCfg = ((cdt & 0x07) << 5) | ((sfi & 0x03) << 2) | (esi & 0x07);
|
|
299
|
+
await this._writeReg(_REG_CDC_CONFIG, cdcCfg);
|
|
300
|
+
await this._writeReg(_REG_CDT_CONFIG, cdtCfg);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Set debounce counts (Stop Mode).
|
|
305
|
+
* @param {number} touch Debounce count for touch 0-7.
|
|
306
|
+
* @param {number} release Debounce count for release 0-7.
|
|
307
|
+
* @returns {Promise<void>}
|
|
308
|
+
*/
|
|
309
|
+
async configureDebounce(touch, release) {
|
|
310
|
+
const deb = ((release & 0x07) << 4) | (touch & 0x07);
|
|
311
|
+
await this._writeReg(_REG_DEBOUNCE, deb);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Compute USL/TL/LSL from VDD and write autoconfig registers (Stop Mode).
|
|
316
|
+
* @param {number} [vddMv=3300] VDD supply in millivolts.
|
|
317
|
+
* @param {number} [retry=0] Auto-retry on autoconfig failure 0-3.
|
|
318
|
+
* @param {boolean} [scts=false] Skip Charge Time Search.
|
|
319
|
+
* @param {boolean} [are=true] Auto-Reconfiguration Enable.
|
|
320
|
+
* @param {boolean} [ace=true] Auto-Configuration Enable.
|
|
321
|
+
* @returns {Promise<void>}
|
|
322
|
+
*/
|
|
323
|
+
async configureAutoconfig(vddMv = 3300, retry = 0, scts = false, are = true, ace = true) {
|
|
324
|
+
const usl = Math.floor(((vddMv - 700) * 256) / vddMv);
|
|
325
|
+
const tl = Math.floor(usl * 0.9);
|
|
326
|
+
const lsl = Math.floor(usl * 0.65);
|
|
327
|
+
await this._writeReg(_REG_USL, usl & 0xFF);
|
|
328
|
+
await this._writeReg(_REG_TL, tl & 0xFF);
|
|
329
|
+
await this._writeReg(_REG_LSL, lsl & 0xFF);
|
|
330
|
+
const ffi = (await this._readReg(_REG_CDC_CONFIG) >> 6) & 0x03;
|
|
331
|
+
const autoconfig0 = ((ffi & 0x03) << 6) | ((retry & 0x03) << 4) | (are ? 0x08 : 0) | (ace ? 0x01 : 0);
|
|
332
|
+
await this._writeReg(_REG_AUTOCONFIG0, autoconfig0);
|
|
333
|
+
const autoconfig1 = scts ? 0x80 : 0x00;
|
|
334
|
+
await this._writeReg(_REG_AUTOCONFIG1, autoconfig1);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Return True if the ELEPROX virtual electrode is touched.
|
|
339
|
+
* @returns {Promise<boolean>}
|
|
340
|
+
*/
|
|
341
|
+
async proximityTouched() {
|
|
342
|
+
return ((await this._readReg(_REG_ELE8_PROX_TCH)) & 0x10) !== 0;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Clear the OVCF bit in register 0x01.
|
|
347
|
+
* @returns {Promise<void>}
|
|
348
|
+
*/
|
|
349
|
+
async clearOvercurrent() {
|
|
350
|
+
const raw = await this._readReg(_REG_ELE8_PROX_TCH);
|
|
351
|
+
await this._writeReg(_REG_ELE8_PROX_TCH, raw & 0x7F);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Enable one of the AUTOCONFIG1-based interrupt sources.
|
|
356
|
+
* @param {number} source One of MPR121Full.SOURCE_OOR, SOURCE_ARF, SOURCE_ACF.
|
|
357
|
+
* @returns {Promise<void>}
|
|
358
|
+
*/
|
|
359
|
+
async enableInterrupt(source) {
|
|
360
|
+
const cur = (await this._readReg(_REG_AUTOCONFIG1)) & 0x00;
|
|
361
|
+
await this._writeReg(_REG_AUTOCONFIG1, cur | (source & 0x07));
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Disable one of the AUTOCONFIG1-based interrupt sources.
|
|
366
|
+
* @param {number} source One of MPR121Full.SOURCE_OOR, SOURCE_ARF, SOURCE_ACF.
|
|
367
|
+
* @returns {Promise<void>}
|
|
368
|
+
*/
|
|
369
|
+
async disableInterrupt(source) {
|
|
370
|
+
const cur = await this._readReg(_REG_AUTOCONFIG1);
|
|
371
|
+
await this._writeReg(_REG_AUTOCONFIG1, cur & ~(source & 0x07));
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
module.exports = { MPR121Minimal, MPR121Full };
|