periph 1.3.3 → 1.5.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.
- package/README.md +36 -0
- package/examples/adc_dac/ad5251/complete.js +66 -0
- package/examples/adc_dac/ad5251/demo.js +69 -0
- package/examples/adc_dac/ad5251/minimal.js +23 -0
- package/examples/adc_dac/ad5252/complete.js +66 -0
- package/examples/adc_dac/ad5252/demo.js +69 -0
- package/examples/adc_dac/ad5252/minimal.js +23 -0
- package/examples/adc_dac/ads7828/complete.js +46 -0
- package/examples/adc_dac/ads7828/demo.js +45 -0
- package/examples/adc_dac/ads7828/minimal.js +17 -0
- package/examples/adc_dac/cat5171/complete.js +52 -0
- package/examples/adc_dac/cat5171/demo.js +59 -0
- package/examples/adc_dac/cat5171/minimal.js +23 -0
- package/examples/adc_dac/cs43l22/complete.js +88 -0
- package/examples/adc_dac/cs43l22/demo.js +56 -0
- package/examples/adc_dac/cs43l22/minimal.js +20 -0
- package/examples/adc_dac/ds1881/complete.js +62 -0
- package/examples/adc_dac/ds1881/demo.js +61 -0
- package/examples/adc_dac/ds1881/minimal.js +25 -0
- package/examples/adc_dac/ds3502/complete.js +46 -0
- package/examples/adc_dac/ds3502/demo.js +54 -0
- package/examples/adc_dac/ds3502/minimal.js +28 -0
- package/examples/adc_dac/es8311/complete.js +80 -0
- package/examples/adc_dac/es8311/demo.js +59 -0
- package/examples/adc_dac/es8311/minimal.js +18 -0
- package/examples/adc_dac/mcp3422/complete.js +48 -0
- package/examples/adc_dac/mcp3422/demo.js +49 -0
- package/examples/adc_dac/mcp3422/minimal.js +25 -0
- package/examples/adc_dac/mcp4xxx/complete.js +97 -0
- package/examples/adc_dac/mcp4xxx/demo.js +76 -0
- package/examples/adc_dac/mcp4xxx/minimal.js +22 -0
- package/examples/display/sh1106/complete.js +101 -0
- package/examples/display/sh1106/demo.js +68 -0
- package/examples/display/sh1106/minimal.js +25 -0
- package/examples/display/ssd1305/complete.js +129 -0
- package/examples/display/ssd1305/demo.js +71 -0
- package/examples/display/ssd1305/minimal.js +25 -0
- package/examples/display/ssd1306/complete.js +115 -0
- package/examples/display/ssd1306/demo.js +70 -0
- package/examples/display/ssd1306/minimal.js +25 -0
- package/examples/environmental/am2315/complete.js +34 -0
- package/examples/environmental/am2315/demo.js +46 -0
- package/examples/environmental/am2315/minimal.js +21 -0
- package/examples/humidity/htu21df/complete.js +49 -0
- package/examples/humidity/htu21df/demo.js +50 -0
- package/examples/humidity/htu21df/minimal.js +22 -0
- package/examples/humidity/sht31/complete.js +53 -0
- package/examples/humidity/sht31/demo.js +53 -0
- package/examples/humidity/sht31/minimal.js +21 -0
- package/examples/humidity/si7021/complete.js +55 -0
- package/examples/humidity/si7021/demo.js +58 -0
- package/examples/humidity/si7021/minimal.js +21 -0
- package/examples/imu/bno055/complete.js +85 -0
- package/examples/imu/bno055/demo.js +70 -0
- package/examples/imu/bno055/minimal.js +20 -0
- package/examples/imu/qmi8658a/complete.js +134 -0
- package/examples/imu/qmi8658a/demo.js +81 -0
- package/examples/imu/qmi8658a/minimal.js +22 -0
- package/examples/io_expander/pca6408a/complete.js +63 -0
- package/examples/io_expander/pca6408a/demo.js +58 -0
- package/examples/io_expander/pca6408a/minimal.js +20 -0
- package/examples/io_expander/pca6416a/complete.js +68 -0
- package/examples/io_expander/pca6416a/demo.js +60 -0
- package/examples/io_expander/pca6416a/minimal.js +20 -0
- package/examples/io_expander/pca9536/complete.js +63 -0
- package/examples/io_expander/pca9536/demo.js +57 -0
- package/examples/io_expander/pca9536/minimal.js +20 -0
- package/examples/io_expander/pca9539/complete.js +68 -0
- package/examples/io_expander/pca9539/demo.js +60 -0
- package/examples/io_expander/pca9539/minimal.js +20 -0
- package/examples/light/max44009/complete.js +56 -0
- package/examples/light/max44009/demo.js +49 -0
- package/examples/light/max44009/minimal.js +22 -0
- package/examples/memory/at24c02n/complete.js +39 -0
- package/examples/memory/at24c02n/demo.js +39 -0
- package/examples/memory/at24c02n/minimal.js +15 -0
- package/examples/memory/at24c64/complete.js +39 -0
- package/examples/memory/at24c64/demo.js +39 -0
- package/examples/memory/at24c64/minimal.js +15 -0
- package/examples/memory/cat24c512/complete.js +39 -0
- package/examples/memory/cat24c512/demo.js +39 -0
- package/examples/memory/cat24c512/minimal.js +15 -0
- package/examples/motor/tmc2130/complete.js +138 -0
- package/examples/motor/tmc2130/demo.js +96 -0
- package/examples/motor/tmc2130/minimal.js +30 -0
- package/examples/motor/tmc2208/complete.js +92 -0
- package/examples/motor/tmc2208/demo.js +85 -0
- package/examples/motor/tmc2208/minimal.js +25 -0
- package/examples/motor/tmc2209/complete.js +106 -0
- package/examples/motor/tmc2209/demo.js +97 -0
- package/examples/motor/tmc2209/minimal.js +25 -0
- package/examples/motor/tmc5160/complete.js +205 -0
- package/examples/motor/tmc5160/demo.js +104 -0
- package/examples/motor/tmc5160/minimal.js +35 -0
- package/examples/other/pca9541/complete.js +52 -0
- package/examples/other/pca9541/demo.js +61 -0
- package/examples/other/pca9541/minimal.js +23 -0
- package/examples/power/axp2101/complete.js +135 -0
- package/examples/power/axp2101/demo.js +68 -0
- package/examples/power/axp2101/minimal.js +24 -0
- package/examples/rtc/pcf85063a/complete.js +68 -0
- package/examples/rtc/pcf85063a/demo.js +76 -0
- package/examples/rtc/pcf85063a/minimal.js +20 -0
- package/examples/temperature/tmp102/complete.js +74 -0
- package/examples/temperature/tmp102/demo.js +71 -0
- package/examples/temperature/tmp102/minimal.js +20 -0
- package/examples/tof/vl6180x/complete.js +62 -0
- package/examples/tof/vl6180x/demo.js +77 -0
- package/examples/tof/vl6180x/minimal.js +23 -0
- package/package.json +1 -1
- package/src/chips/adc_dac/ad5251.js +345 -0
- package/src/chips/adc_dac/ad5252.js +345 -0
- package/src/chips/adc_dac/ads7828.js +225 -0
- package/src/chips/adc_dac/cat5171.js +213 -0
- package/src/chips/adc_dac/cs43l22.js +645 -0
- package/src/chips/adc_dac/ds1881.js +357 -0
- package/src/chips/adc_dac/ds3502.js +241 -0
- package/src/chips/adc_dac/es8311.js +621 -0
- package/src/chips/adc_dac/mcp3422.js +312 -0
- package/src/chips/adc_dac/mcp4xxx.js +982 -0
- package/src/chips/display/mono_oled.js +182 -0
- package/src/chips/display/sh1106.js +496 -0
- package/src/chips/display/ssd1305.js +655 -0
- package/src/chips/display/ssd1306.js +458 -0
- package/src/chips/environmental/am2315.js +237 -0
- package/src/chips/humidity/htu21df.js +222 -0
- package/src/chips/humidity/sht31.js +284 -0
- package/src/chips/humidity/si7021.js +282 -0
- package/src/chips/imu/bno055.js +496 -0
- package/src/chips/imu/qmi8658a.js +1011 -0
- package/src/chips/io_expander/pca6408a.js +407 -0
- package/src/chips/io_expander/pca6416a.js +455 -0
- package/src/chips/io_expander/pca9536.js +398 -0
- package/src/chips/io_expander/pca9539.js +457 -0
- package/src/chips/light/max44009.js +336 -0
- package/src/chips/memory/at24c02n.js +220 -0
- package/src/chips/memory/at24c64.js +220 -0
- package/src/chips/memory/cat24c512.js +221 -0
- package/src/chips/motor/tmc2130.js +537 -0
- package/src/chips/motor/tmc2208.js +490 -0
- package/src/chips/motor/tmc2209.js +565 -0
- package/src/chips/motor/tmc5160.js +900 -0
- package/src/chips/other/pca9541.js +315 -0
- package/src/chips/power/axp2101.js +968 -0
- package/src/chips/rtc/pcf85063a.js +482 -0
- package/src/chips/temperature/tmp102.js +361 -0
- package/src/chips/tof/vl6180x.js +580 -0
- package/src/connection/uart.js +9 -0
- package/src/connection/uart_mock.js +65 -0
- package/src/discovery/registry.js +85 -8
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ES8311 — low-power mono audio codec, I²C control port (Everest Semiconductor).
|
|
5
|
+
*
|
|
6
|
+
* Mono ADC (analog differential or PDM microphone, 0–30 dB PGA, ALC, equalizer)
|
|
7
|
+
* and mono DAC (digital volume, DRC, equalizer) with one I²S / left-justified /
|
|
8
|
+
* DSP digital audio port. This driver covers the I²C control port only: the audio
|
|
9
|
+
* stream itself runs over a separate I²S port that this library does not provide.
|
|
10
|
+
* Address 0x18 (CE low) or 0x19 (CE high).
|
|
11
|
+
*
|
|
12
|
+
* The user guide leaves the start-up sequence and registers 0x04, 0x0B–0x0C and
|
|
13
|
+
* 0x10–0x13 undocumented; the vendor reference-driver values are used — verify on
|
|
14
|
+
* hardware.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const _REG_RESET = 0x00;
|
|
18
|
+
const _REG_CLK1 = 0x01;
|
|
19
|
+
const _REG_CLK2 = 0x02;
|
|
20
|
+
const _REG_CLK3 = 0x03;
|
|
21
|
+
const _REG_CLK4 = 0x04;
|
|
22
|
+
const _REG_CLK5 = 0x05;
|
|
23
|
+
const _REG_CLK6 = 0x06;
|
|
24
|
+
const _REG_CLK7 = 0x07;
|
|
25
|
+
const _REG_CLK8 = 0x08;
|
|
26
|
+
const _REG_SDP_IN = 0x09;
|
|
27
|
+
const _REG_SDP_OUT = 0x0A;
|
|
28
|
+
const _REG_SYS_PWR = 0x0D;
|
|
29
|
+
const _REG_SYS_ADC = 0x0E;
|
|
30
|
+
const _REG_SYS_LP = 0x0F;
|
|
31
|
+
const _REG_SYS_MIC = 0x14;
|
|
32
|
+
const _REG_ADC_RAMP = 0x15;
|
|
33
|
+
const _REG_ADC_SCALE = 0x16;
|
|
34
|
+
const _REG_ADC_VOLUME = 0x17;
|
|
35
|
+
const _REG_ADC_ALC1 = 0x18;
|
|
36
|
+
const _REG_ADC_ALC2 = 0x19;
|
|
37
|
+
const _REG_ADC_AUTOMUTE = 0x1A;
|
|
38
|
+
const _REG_ADC_HPF1 = 0x1B;
|
|
39
|
+
const _REG_ADC_HPF2_EQ = 0x1C;
|
|
40
|
+
const _REG_ADCEQ = 0x1D;
|
|
41
|
+
const _REG_DAC_MUTE = 0x31;
|
|
42
|
+
const _REG_DAC_VOLUME = 0x32;
|
|
43
|
+
const _REG_DAC_DRC1 = 0x34;
|
|
44
|
+
const _REG_DAC_DRC2 = 0x35;
|
|
45
|
+
const _REG_DAC_RAMP_EQ = 0x37;
|
|
46
|
+
const _REG_DACEQ = 0x38;
|
|
47
|
+
const _REG_GPIO = 0x44;
|
|
48
|
+
|
|
49
|
+
// "mclk:fs" -> [0x02, 0x03, 0x04, 0x05] from the guide's clock table
|
|
50
|
+
const _CLOCK_PRESETS = {
|
|
51
|
+
'24576000:32000': [0x40, 0x10, 0x10, 0x00],
|
|
52
|
+
'24576000:48000': [0x20, 0x10, 0x10, 0x00],
|
|
53
|
+
'12288000:32000': [0x48, 0x10, 0x10, 0x00],
|
|
54
|
+
'12288000:48000': [0x00, 0x10, 0x10, 0x00],
|
|
55
|
+
'18432000:32000': [0x20, 0x12, 0x12, 0x00],
|
|
56
|
+
'18432000:48000': [0x48, 0x10, 0x10, 0x00],
|
|
57
|
+
'11289600:44100': [0x00, 0x10, 0x10, 0x00],
|
|
58
|
+
'12000000:32000': [0x00, 0x17, 0x17, 0x00],
|
|
59
|
+
'12000000:44100': [0x00, 0x11, 0x11, 0x00],
|
|
60
|
+
'12000000:48000': [0x98, 0x19, 0x19, 0x00],
|
|
61
|
+
'26000000:32000': [0x40, 0x10, 0x10, 0x00],
|
|
62
|
+
'3000000:32000': [0x18, 0x52, 0x17, 0x41],
|
|
63
|
+
'25000000:32000': [0x48, 0x55, 0x10, 0x21],
|
|
64
|
+
'25000000:48000': [0x28, 0x55, 0x10, 0x21],
|
|
65
|
+
};
|
|
66
|
+
const _PREFERRED_RATIOS = [256, 384, 512, 768, 1024, 1536];
|
|
67
|
+
const _BCLK_DIVIDERS = [22, 24, 25, 30, 32, 33, 34, 36, 44, 48, 66, 72]; // DIV_BCLK codes 20..31
|
|
68
|
+
const _FORMATS = { i2s: 0, left_justified: 1, dsp_a: 3, dsp_b: 3 };
|
|
69
|
+
const _WORD_LENGTHS = { 24: 0, 20: 1, 18: 2, 16: 3, 32: 4 };
|
|
70
|
+
const _ADCDAT_MODES = { adc_adc: 0, adc_zero: 1, zero_adc: 2, dac_adc: 4, adc_dac: 5, dac_dac: 6 };
|
|
71
|
+
|
|
72
|
+
const ALC_LEVELS_DB = [-30.1, -24.1, -20.6, -18.1, -16.1, -14.5, -13.2, -12.0,
|
|
73
|
+
-11.0, -10.1, -9.3, -8.5, -7.8, -7.2, -6.6, -6.0];
|
|
74
|
+
const NOISE_GATE_DB = [-96, -90, -84, -78, -72, -66, -60, -54, -51, -48, -45, -42, -39, -36, -33, -30];
|
|
75
|
+
|
|
76
|
+
function _nearest(table, value) {
|
|
77
|
+
let best = 0;
|
|
78
|
+
for (let i = 0; i < table.length; i++) {
|
|
79
|
+
if (Math.abs(table[i] - value) < Math.abs(table[best] - value)) best = i;
|
|
80
|
+
}
|
|
81
|
+
return best;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function _clamp(v, lo, hi) { return Math.max(lo, Math.min(hi, v)); }
|
|
85
|
+
|
|
86
|
+
// Round half away from zero (matches C++ lroundf and the Go/Java ports).
|
|
87
|
+
function _round(v) { return v < 0 ? -Math.round(-v) : Math.round(v); }
|
|
88
|
+
|
|
89
|
+
function _volumeToReg(db) { return _clamp(_round(db / 0.5) + 191, 0, 255); }
|
|
90
|
+
|
|
91
|
+
function _sleep(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); }
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Solve the clock registers 0x02–0x05 for an MCLK / sample-rate pair.
|
|
95
|
+
* Tries the guide's preset table first (3.3 V only), then searches the pre-divider,
|
|
96
|
+
* multiplier and ADC/DAC divider for an allowed MCLK:LRCK ratio.
|
|
97
|
+
* @param {number} mclkHz - Master clock in Hz.
|
|
98
|
+
* @param {number} fs - Sample rate in Hz.
|
|
99
|
+
* @param {number} dvddVolts - DVDD supply (selects the 3.3 V or 1.8 V limits).
|
|
100
|
+
* @returns {number[]} [0x02, 0x03, 0x04, 0x05] values.
|
|
101
|
+
* @throws {RangeError} If no valid divider set exists.
|
|
102
|
+
*/
|
|
103
|
+
function _solveClock(mclkHz, fs, dvddVolts) {
|
|
104
|
+
const low = dvddVolts < 2.5;
|
|
105
|
+
const preset = _CLOCK_PRESETS[mclkHz + ':' + fs];
|
|
106
|
+
if (!low && preset) return preset.slice();
|
|
107
|
+
const preLimit = low ? 4.5e6 : 10e6;
|
|
108
|
+
const clkLimit = low ? 13e6 : 35e6;
|
|
109
|
+
let best = null;
|
|
110
|
+
for (let dp = 1; dp <= 8; dp++) {
|
|
111
|
+
if (mclkHz / dp >= preLimit) continue;
|
|
112
|
+
[1, 2, 4, 8].forEach((mult, mi) => {
|
|
113
|
+
const imclk = mclkHz / dp * mult;
|
|
114
|
+
for (let div = 0; div < 16; div++) {
|
|
115
|
+
const clk = imclk / (div + 1);
|
|
116
|
+
if (clk >= clkLimit) continue;
|
|
117
|
+
const ratio = clk / fs;
|
|
118
|
+
if (!Number.isInteger(ratio) || ratio % 16 !== 0 || ratio < 256 || ratio > 1008) continue;
|
|
119
|
+
const idx = _PREFERRED_RATIOS.indexOf(ratio);
|
|
120
|
+
const key = [idx >= 0 ? idx : 99, dp, mult, div];
|
|
121
|
+
if (best === null || _cmp(key, best.key) < 0) best = { key, r02: ((dp - 1) << 5) | (mi << 3), osr: ratio / 16, div };
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (best === null) throw new RangeError('no valid ES8311 clock divider for MCLK ' + mclkHz + ' Hz / fs ' + fs + ' Hz');
|
|
126
|
+
return [best.r02, best.osr, best.osr, (best.div << 4) | best.div];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function _cmp(a, b) {
|
|
130
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return a[i] - b[i];
|
|
131
|
+
return 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* ES8311 minimal interface — bring-up for voice playback and recording.
|
|
136
|
+
*
|
|
137
|
+
* The constructor starts the initialization sequence (software reset, clock tree for
|
|
138
|
+
* the MCLK / sample rate, I²S 16-bit slave, analog path, microphone 24 dB, ADC 0 dB,
|
|
139
|
+
* DAC −95.5 dB). An invalid MCLK / sample-rate pair throws a RangeError synchronously.
|
|
140
|
+
* JS constructors cannot be async, so the register writes run in the background:
|
|
141
|
+
* every method awaits their completion first and rethrows an I²C error from the
|
|
142
|
+
* init sequence.
|
|
143
|
+
*/
|
|
144
|
+
class ES8311Minimal {
|
|
145
|
+
/**
|
|
146
|
+
* @param {import('../../connection/register_connection').RegisterConnection} connection - I²C register connection (0x18 / 0x19).
|
|
147
|
+
* @param {number} [mclkHz=12288000] - Master clock in Hz.
|
|
148
|
+
* @param {number} [sampleRateHz=48000] - Audio sample rate in Hz.
|
|
149
|
+
* @param {number} [dvddVolts=3.3] - DVDD supply, selects the 3.3 V or 1.8 V clock limits.
|
|
150
|
+
* @throws {RangeError} If the MCLK : sample-rate combination has no valid divider set.
|
|
151
|
+
*/
|
|
152
|
+
constructor(connection, mclkHz = 12288000, sampleRateHz = 48000, dvddVolts = 3.3) {
|
|
153
|
+
this._conn = connection;
|
|
154
|
+
this._mclkHz = mclkHz;
|
|
155
|
+
this._fs = sampleRateHz;
|
|
156
|
+
this._dvdd = dvddVolts;
|
|
157
|
+
const clk = _solveClock(mclkHz, sampleRateHz, dvddVolts);
|
|
158
|
+
this._ready = this._init(clk);
|
|
159
|
+
this._ready.catch(() => {});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async _init(clk) {
|
|
163
|
+
await this._softReset();
|
|
164
|
+
await this._w(_REG_CLK1, 0x3F);
|
|
165
|
+
await this._writeClock(clk);
|
|
166
|
+
await this._w(_REG_CLK6, 0x03);
|
|
167
|
+
await this._w(_REG_CLK7, 0x00);
|
|
168
|
+
await this._w(_REG_CLK8, 0xFF);
|
|
169
|
+
await this._w(_REG_SDP_IN, 0x0C);
|
|
170
|
+
await this._w(_REG_SDP_OUT, 0x0C);
|
|
171
|
+
await this._powerUpAnalog();
|
|
172
|
+
await this._w(_REG_ADC_SCALE, 0x04);
|
|
173
|
+
await this._w(_REG_SYS_MIC, 0x18);
|
|
174
|
+
await this._w(_REG_ADC_VOLUME, 0xBF);
|
|
175
|
+
await this._w(_REG_DAC_VOLUME, 0x00);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async _w(reg, value) { await this._conn.writeReg(reg, value); }
|
|
179
|
+
|
|
180
|
+
async _r(reg) { return (await this._conn.readReg(reg, 1))[0]; }
|
|
181
|
+
|
|
182
|
+
async _update(reg, mask, value) {
|
|
183
|
+
await this._w(reg, ((await this._r(reg)) & ~mask & 0xFF) | (value & mask));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async _softReset() {
|
|
187
|
+
await this._w(_REG_RESET, 0x1F);
|
|
188
|
+
await _sleep(20);
|
|
189
|
+
await this._w(_REG_RESET, 0x00);
|
|
190
|
+
await this._w(_REG_RESET, 0x80);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async _writeClock(clk) {
|
|
194
|
+
await this._w(_REG_CLK2, clk[0]);
|
|
195
|
+
await this._w(_REG_CLK3, clk[1]);
|
|
196
|
+
await this._w(_REG_CLK4, clk[2]);
|
|
197
|
+
await this._w(_REG_CLK5, clk[3]);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async _powerUpAnalog() {
|
|
201
|
+
await this._w(0x0B, 0x00);
|
|
202
|
+
await this._w(0x0C, 0x00);
|
|
203
|
+
await this._w(0x10, 0x1F);
|
|
204
|
+
await this._w(0x11, 0x7F);
|
|
205
|
+
await this._w(_REG_SYS_PWR, 0x01);
|
|
206
|
+
await this._w(_REG_SYS_ADC, 0x02);
|
|
207
|
+
await this._w(0x12, 0x00);
|
|
208
|
+
await this._w(0x13, 0x10);
|
|
209
|
+
await this._w(_REG_ADC_HPF2_EQ, 0x6A);
|
|
210
|
+
await this._w(_REG_DAC_RAMP_EQ, 0x08);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Set the DAC digital volume.
|
|
215
|
+
* @param {number} db - −95.5 … +32 dB, rounded to the nearest 0.5 dB step (clamped).
|
|
216
|
+
* @returns {Promise<void>}
|
|
217
|
+
*/
|
|
218
|
+
async setVolume(db) {
|
|
219
|
+
await this._ready;
|
|
220
|
+
await this._w(_REG_DAC_VOLUME, _volumeToReg(db));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Mute or unmute the DAC (DSM and DEM mute together, 0x31 bits 6 and 5).
|
|
225
|
+
* @param {boolean} muted - True to mute.
|
|
226
|
+
* @returns {Promise<void>}
|
|
227
|
+
*/
|
|
228
|
+
async setMute(muted) {
|
|
229
|
+
await this._ready;
|
|
230
|
+
await this._update(_REG_DAC_MUTE, 0x60, muted ? 0x60 : 0x00);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Set the analog microphone PGA gain.
|
|
235
|
+
* @param {number} db - 0 … 30 dB, rounded to the nearest 3 dB step (clamped).
|
|
236
|
+
* @returns {Promise<void>}
|
|
237
|
+
*/
|
|
238
|
+
async setMicGain(db) {
|
|
239
|
+
await this._ready;
|
|
240
|
+
await this._update(_REG_SYS_MIC, 0x0F, _clamp(_round(db / 3), 0, 10));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* ES8311 full interface — adds clock tree, serial port, microphone / ADC / DAC
|
|
246
|
+
* dynamics, equalizers, routing, power control and raw register access.
|
|
247
|
+
*/
|
|
248
|
+
class ES8311Full extends ES8311Minimal {
|
|
249
|
+
/**
|
|
250
|
+
* Read back the DAC volume.
|
|
251
|
+
* @returns {Promise<number>} dB (−95.5 … +32).
|
|
252
|
+
*/
|
|
253
|
+
async getVolume() {
|
|
254
|
+
await this._ready;
|
|
255
|
+
return ((await this._r(_REG_DAC_VOLUME)) - 191) * 0.5;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Read back the analog microphone PGA gain.
|
|
260
|
+
* @returns {Promise<number>} dB (0 … 30).
|
|
261
|
+
*/
|
|
262
|
+
async getMicGain() {
|
|
263
|
+
await this._ready;
|
|
264
|
+
return ((await this._r(_REG_SYS_MIC)) & 0x0F) * 3;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Software reset; registers return to their reset values (configure again afterwards).
|
|
269
|
+
* @returns {Promise<void>}
|
|
270
|
+
*/
|
|
271
|
+
async reset() {
|
|
272
|
+
await this._ready;
|
|
273
|
+
await this._softReset();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Re-enable the analog, reference and clock blocks (vendor values) and set CSM_ON.
|
|
278
|
+
* @returns {Promise<void>}
|
|
279
|
+
*/
|
|
280
|
+
async powerUp() {
|
|
281
|
+
await this._ready;
|
|
282
|
+
await this._update(_REG_RESET, 0x9F, 0x00);
|
|
283
|
+
await this._update(_REG_RESET, 0x80, 0x80);
|
|
284
|
+
await this._w(_REG_CLK1, 0x3F);
|
|
285
|
+
await this._powerUpAnalog();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Standby: mute the DAC, power down the analog blocks, reset all and clear CSM_ON.
|
|
290
|
+
* @returns {Promise<void>}
|
|
291
|
+
*/
|
|
292
|
+
async powerDown() {
|
|
293
|
+
await this.setMute(true);
|
|
294
|
+
await this._update(_REG_SYS_PWR, 0xFC, 0xFC);
|
|
295
|
+
await this._update(_REG_SYS_ADC, 0x70, 0x70);
|
|
296
|
+
await this._update(_REG_SYS_PWR, 0x03, 0x00);
|
|
297
|
+
await this._w(_REG_RESET, 0x1F);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Set the low-power bits of register 0x0F (slightly lower THD+N / SNR).
|
|
302
|
+
* @param {{dac?: boolean, pga?: boolean, pgaOut?: boolean, adc?: boolean, adcRef?: boolean,
|
|
303
|
+
* dacRef?: boolean, flash?: boolean, integrator?: boolean}} [opts] - Bits to set; omitted = false.
|
|
304
|
+
* @returns {Promise<void>}
|
|
305
|
+
*/
|
|
306
|
+
async setLowPower(opts = {}) {
|
|
307
|
+
await this._ready;
|
|
308
|
+
const flags = [opts.dac, opts.pga, opts.pgaOut, opts.adc, opts.adcRef, opts.dacRef, opts.flash, opts.integrator];
|
|
309
|
+
let value = 0;
|
|
310
|
+
flags.forEach((f, i) => { if (f) value |= 0x80 >> i; });
|
|
311
|
+
await this._w(_REG_SYS_LP, value);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Program the clock tree (registers 0x01–0x05) from a preset or computed dividers.
|
|
316
|
+
* @param {number} mclkHz - Master clock in Hz.
|
|
317
|
+
* @param {number} sampleRateHz - Audio sample rate in Hz.
|
|
318
|
+
* @param {boolean} [mclkFromBclk=false] - Take the master clock from the SCLK (BCLK) pin.
|
|
319
|
+
* @param {boolean} [mclkInvert=false] - Invert the master clock.
|
|
320
|
+
* @returns {Promise<void>}
|
|
321
|
+
* @throws {RangeError} If no valid divider set exists for the combination.
|
|
322
|
+
*/
|
|
323
|
+
async configureClock(mclkHz, sampleRateHz, mclkFromBclk = false, mclkInvert = false) {
|
|
324
|
+
await this._ready;
|
|
325
|
+
const clk = _solveClock(mclkHz, sampleRateHz, this._dvdd);
|
|
326
|
+
this._mclkHz = mclkHz;
|
|
327
|
+
this._fs = sampleRateHz;
|
|
328
|
+
await this._w(_REG_CLK1, 0x3F | (mclkFromBclk ? 0x80 : 0) | (mclkInvert ? 0x40 : 0));
|
|
329
|
+
await this._writeClock(clk);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
async _internalClock() {
|
|
333
|
+
const r02 = await this._r(_REG_CLK2);
|
|
334
|
+
return Math.floor(this._mclkHz / (((r02 >> 5) & 7) + 1) * [1, 2, 4, 8][(r02 >> 3) & 3]);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Configure the digital audio port (0x09, 0x0A, RESET.MSC, 0x06–0x08).
|
|
339
|
+
* @param {object} [o] - Options.
|
|
340
|
+
* @param {string} [o.format='i2s'] - 'i2s', 'left_justified', 'dsp_a' or 'dsp_b'.
|
|
341
|
+
* @param {number} [o.wordLength=16] - 16, 18, 20, 24 or 32 bit.
|
|
342
|
+
* @param {boolean} [o.master=false] - Master mode (chip drives BCLK / LRCK).
|
|
343
|
+
* @param {boolean} [o.bclkInvert=false] - Invert BCLK.
|
|
344
|
+
* @param {boolean} [o.lrckInvert=false] - Invert the LRCK polarity.
|
|
345
|
+
* @param {string} [o.dacChannel='left'] - 'left' or 'right' data to the DAC.
|
|
346
|
+
* @param {?number} [o.bclkDiv=null] - Master BCLK divider (null = computed).
|
|
347
|
+
* @param {?number} [o.lrckDiv=null] - Master LRCK divider (null = computed).
|
|
348
|
+
* @param {boolean} [o.continuousBclk=true] - Keep BCLK running when idle (master mode).
|
|
349
|
+
* @returns {Promise<void>}
|
|
350
|
+
* @throws {RangeError} For an unknown format, word length or BCLK divider.
|
|
351
|
+
*/
|
|
352
|
+
async configureSerial(o = {}) {
|
|
353
|
+
const format = o.format === undefined ? 'i2s' : o.format;
|
|
354
|
+
const wordLength = o.wordLength === undefined ? 16 : o.wordLength;
|
|
355
|
+
if (!(format in _FORMATS)) throw new RangeError('unknown format');
|
|
356
|
+
if (!(wordLength in _WORD_LENGTHS)) throw new RangeError('wordLength must be 16, 18, 20, 24 or 32');
|
|
357
|
+
await this._ready;
|
|
358
|
+
const lrp = (o.lrckInvert ? 1 : 0) ^ (format === 'dsp_b' ? 1 : 0);
|
|
359
|
+
const base = (_WORD_LENGTHS[wordLength] << 2) | _FORMATS[format] | (lrp << 5);
|
|
360
|
+
let code = 0;
|
|
361
|
+
let lrckDiv = 0;
|
|
362
|
+
if (o.master) {
|
|
363
|
+
const imclk = await this._internalClock();
|
|
364
|
+
let bclkDiv = o.bclkDiv == null ? Math.floor(imclk / (this._fs * 2 * wordLength)) : o.bclkDiv;
|
|
365
|
+
lrckDiv = o.lrckDiv == null ? Math.floor(imclk / this._fs) : o.lrckDiv;
|
|
366
|
+
if (bclkDiv <= 20) code = bclkDiv - 1;
|
|
367
|
+
else {
|
|
368
|
+
const i = _BCLK_DIVIDERS.indexOf(bclkDiv);
|
|
369
|
+
if (i < 0) throw new RangeError('unsupported BCLK divider');
|
|
370
|
+
code = 20 + i;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
await this._w(_REG_SDP_IN, base | (o.dacChannel === 'right' ? 0x80 : 0x00) | ((await this._r(_REG_SDP_IN)) & 0x40));
|
|
374
|
+
await this._w(_REG_SDP_OUT, base | ((await this._r(_REG_SDP_OUT)) & 0x40));
|
|
375
|
+
if (o.master) {
|
|
376
|
+
await this._w(_REG_CLK6, (o.continuousBclk === false ? 0x40 : 0x00) | (o.bclkInvert ? 0x20 : 0) | code);
|
|
377
|
+
await this._update(_REG_CLK7, 0x0F, ((lrckDiv - 1) >> 8) & 0x0F);
|
|
378
|
+
await this._w(_REG_CLK8, (lrckDiv - 1) & 0xFF);
|
|
379
|
+
await this._update(_REG_RESET, 0x44, 0x40);
|
|
380
|
+
} else {
|
|
381
|
+
await this._update(_REG_CLK6, 0x20, o.bclkInvert ? 0x20 : 0x00);
|
|
382
|
+
await this._update(_REG_RESET, 0x44, 0x04);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Tri-state the BCLK / LRCK pins and / or ADCDAT (0x07 bits 5:4).
|
|
388
|
+
* @param {boolean} [bclkLrck=false] - Tri-state BCLK and LRCK.
|
|
389
|
+
* @param {boolean} [adcdat=false] - Tri-state ADCDAT.
|
|
390
|
+
* @returns {Promise<void>}
|
|
391
|
+
*/
|
|
392
|
+
async setTristate(bclkLrck = false, adcdat = false) {
|
|
393
|
+
await this._ready;
|
|
394
|
+
await this._update(_REG_CLK7, 0x30, (bclkLrck ? 0x20 : 0) | (adcdat ? 0x10 : 0));
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Select the microphone input.
|
|
399
|
+
* @param {string} [source='analog'] - 'analog' (MIC1P/MIC1N), 'digital' (PDM on MIC1P) or 'none'.
|
|
400
|
+
* @returns {Promise<void>}
|
|
401
|
+
* @throws {RangeError} For an unknown source.
|
|
402
|
+
*/
|
|
403
|
+
async setInput(source = 'analog') {
|
|
404
|
+
if (!['analog', 'digital', 'none'].includes(source)) throw new RangeError('source must be analog, digital or none');
|
|
405
|
+
await this._ready;
|
|
406
|
+
await this._update(_REG_SYS_MIC, 0x70, source === 'analog' ? 0x10 : (source === 'digital' ? 0x40 : 0x00));
|
|
407
|
+
await this._update(_REG_SYS_ADC, 0x40, source === 'analog' ? 0x00 : 0x40);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Select the PDM data latch edge (0x15 bit 0).
|
|
412
|
+
* @param {boolean} [latchFallingEdge=false] - Latch on the falling clock edge.
|
|
413
|
+
* @returns {Promise<void>}
|
|
414
|
+
*/
|
|
415
|
+
async configureDmic(latchFallingEdge = false) {
|
|
416
|
+
await this._ready;
|
|
417
|
+
await this._update(_REG_ADC_RAMP, 0x01, latchFallingEdge ? 0x01 : 0x00);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Set the ADC digital volume (ALC maximum gain when the ALC is on).
|
|
422
|
+
* @param {number} db - −95.5 … +32 dB in 0.5 dB steps.
|
|
423
|
+
* @returns {Promise<void>}
|
|
424
|
+
*/
|
|
425
|
+
async setAdcVolume(db) {
|
|
426
|
+
await this._ready;
|
|
427
|
+
await this._w(_REG_ADC_VOLUME, _volumeToReg(db));
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Configure the ADC digital path.
|
|
432
|
+
* @param {object} [o] - Options.
|
|
433
|
+
* @param {number} [o.scaleDb=24] - Digital gain scale-up 0 … 42 dB in 6 dB steps.
|
|
434
|
+
* @param {number} [o.osr=64] - Oversampling ratio in × fs (single speed 60–252, double speed 32–126).
|
|
435
|
+
* @param {boolean} [o.doubleSpeed=false] - Select the double-speed ADC.
|
|
436
|
+
* @param {boolean} [o.hpf=true] - Dynamic high-pass filter (false freezes the DC offset).
|
|
437
|
+
* @param {number[]} [o.hpfCoeffs=[0x0C, 0x0C]] - [stage-1, stage-2] coefficients 0–31.
|
|
438
|
+
* @returns {Promise<void>}
|
|
439
|
+
* @throws {RangeError} If osr is out of range.
|
|
440
|
+
*/
|
|
441
|
+
async configureAdc(o = {}) {
|
|
442
|
+
const osr = o.osr === undefined ? 64 : o.osr;
|
|
443
|
+
const doubleSpeed = !!o.doubleSpeed;
|
|
444
|
+
const code = Math.floor(doubleSpeed ? osr / 2 : osr / 4);
|
|
445
|
+
if (code < 15 || code > 63 || (doubleSpeed && code < 16)) throw new RangeError('osr out of range');
|
|
446
|
+
const coeffs = o.hpfCoeffs || [0x0C, 0x0C];
|
|
447
|
+
await this._ready;
|
|
448
|
+
const scale = o.scaleDb === undefined ? 24 : o.scaleDb;
|
|
449
|
+
await this._update(_REG_ADC_SCALE, 0x07, _clamp(_round(scale / 6), 0, 7));
|
|
450
|
+
await this._w(_REG_CLK3, (doubleSpeed ? 0x40 : 0x00) | code);
|
|
451
|
+
await this._update(_REG_ADC_HPF2_EQ, 0x3F, (o.hpf === false ? 0x00 : 0x20) | (coeffs[1] & 0x1F));
|
|
452
|
+
await this._update(_REG_ADC_HPF1, 0x1F, coeffs[0] & 0x1F);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Set the ADC volume soft-ramp rate (0x15 bits 7:4).
|
|
457
|
+
* @param {number} rate - 0 = off, 1–15 = 0.25 dB per 2^(rate+1) LRCK periods.
|
|
458
|
+
* @returns {Promise<void>}
|
|
459
|
+
*/
|
|
460
|
+
async setAdcRamp(rate) {
|
|
461
|
+
await this._ready;
|
|
462
|
+
await this._update(_REG_ADC_RAMP, 0xF0, _clamp(rate, 0, 15) << 4);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Configure the automatic level control, noise gate and automute (0x18–0x1A).
|
|
467
|
+
* @param {boolean} enabled - Enable the ALC.
|
|
468
|
+
* @param {object} [o] - Options.
|
|
469
|
+
* @param {number} [o.maxLevelDb=-6.0] - Upper target level (nearest of 16 levels).
|
|
470
|
+
* @param {number} [o.minLevelDb=-30.1] - Lower target level.
|
|
471
|
+
* @param {number} [o.window=0] - ALC window size 0–15.
|
|
472
|
+
* @param {boolean} [o.automute=false] - Enable automute.
|
|
473
|
+
* @param {number} [o.automuteWindow=0] - Automute window 0–15 (2048 × (n+1) samples).
|
|
474
|
+
* @param {number} [o.noiseGateDb=-96] - Noise gate threshold (nearest of 16).
|
|
475
|
+
* @returns {Promise<void>}
|
|
476
|
+
*/
|
|
477
|
+
async configureAlc(enabled, o = {}) {
|
|
478
|
+
await this._ready;
|
|
479
|
+
const maxL = o.maxLevelDb === undefined ? -6.0 : o.maxLevelDb;
|
|
480
|
+
const minL = o.minLevelDb === undefined ? -30.1 : o.minLevelDb;
|
|
481
|
+
const gate = o.noiseGateDb === undefined ? -96 : o.noiseGateDb;
|
|
482
|
+
await this._w(_REG_ADC_ALC1, (enabled ? 0x80 : 0) | (o.automute ? 0x40 : 0) | ((o.window || 0) & 0x0F));
|
|
483
|
+
await this._w(_REG_ADC_ALC2, (_nearest(ALC_LEVELS_DB, maxL) << 4) | _nearest(ALC_LEVELS_DB, minL));
|
|
484
|
+
await this._w(_REG_ADC_AUTOMUTE, (((o.automuteWindow || 0) & 0x0F) << 4) | _nearest(NOISE_GATE_DB, gate));
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
_eqBuffer(coefficients, count) {
|
|
488
|
+
if (!coefficients || coefficients.length !== count) throw new RangeError('expected ' + count + ' coefficients');
|
|
489
|
+
const data = Buffer.alloc(4 * count);
|
|
490
|
+
coefficients.forEach((c, i) => {
|
|
491
|
+
if (!Number.isInteger(c) || c < 0 || c >= 2 ** 30) throw new RangeError('coefficient must be a 30-bit value');
|
|
492
|
+
data[4 * i] = Math.floor(c / 2 ** 24) & 0x3F;
|
|
493
|
+
data[4 * i + 1] = (c >>> 16) & 0xFF;
|
|
494
|
+
data[4 * i + 2] = (c >>> 8) & 0xFF;
|
|
495
|
+
data[4 * i + 3] = c & 0xFF;
|
|
496
|
+
});
|
|
497
|
+
return data;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Bypass the ADC equalizer or load its coefficients.
|
|
502
|
+
* @param {?number[]} [coefficients=null] - null to bypass, else [b0, a1, a2, b1, b2] as 30-bit values.
|
|
503
|
+
* @returns {Promise<void>}
|
|
504
|
+
* @throws {RangeError} If the coefficient count or range is wrong.
|
|
505
|
+
*/
|
|
506
|
+
async setAdcEq(coefficients = null) {
|
|
507
|
+
const data = coefficients === null ? null : this._eqBuffer(coefficients, 5);
|
|
508
|
+
await this._ready;
|
|
509
|
+
if (data) await this._conn.writeReg(_REG_ADCEQ, data);
|
|
510
|
+
await this._update(_REG_ADC_HPF2_EQ, 0x40, coefficients === null ? 0x40 : 0x00);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Set the DAC volume / DRC soft-ramp rate (0x37 bits 7:4).
|
|
515
|
+
* @param {number} rate - 0 = off, 1–15 = 0.25 dB per 2^(rate+1) LRCK periods.
|
|
516
|
+
* @returns {Promise<void>}
|
|
517
|
+
*/
|
|
518
|
+
async setDacRamp(rate) {
|
|
519
|
+
await this._ready;
|
|
520
|
+
await this._update(_REG_DAC_RAMP_EQ, 0xF0, _clamp(rate, 0, 15) << 4);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Configure the DAC dynamic range control (0x34, 0x35).
|
|
525
|
+
* @param {boolean} enabled - Enable the DRC (the DAC volume becomes its maximum gain).
|
|
526
|
+
* @param {object} [o] - Options.
|
|
527
|
+
* @param {number} [o.maxLevelDb=-30.1] - Upper target level.
|
|
528
|
+
* @param {number} [o.minLevelDb=-30.1] - Lower target level.
|
|
529
|
+
* @param {number} [o.window=0] - Window size 0–15.
|
|
530
|
+
* @returns {Promise<void>}
|
|
531
|
+
*/
|
|
532
|
+
async configureDrc(enabled, o = {}) {
|
|
533
|
+
await this._ready;
|
|
534
|
+
const maxL = o.maxLevelDb === undefined ? -30.1 : o.maxLevelDb;
|
|
535
|
+
const minL = o.minLevelDb === undefined ? -30.1 : o.minLevelDb;
|
|
536
|
+
await this._w(_REG_DAC_DRC1, (enabled ? 0x80 : 0) | ((o.window || 0) & 0x0F));
|
|
537
|
+
await this._w(_REG_DAC_DRC2, (_nearest(ALC_LEVELS_DB, maxL) << 4) | _nearest(ALC_LEVELS_DB, minL));
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Bypass the DAC equalizer or load its coefficients.
|
|
542
|
+
* @param {?number[]} [coefficients=null] - null to bypass, else [b0, b1, a1] as 30-bit values.
|
|
543
|
+
* @returns {Promise<void>}
|
|
544
|
+
* @throws {RangeError} If the coefficient count or range is wrong.
|
|
545
|
+
*/
|
|
546
|
+
async setDacEq(coefficients = null) {
|
|
547
|
+
const data = coefficients === null ? null : this._eqBuffer(coefficients, 3);
|
|
548
|
+
await this._ready;
|
|
549
|
+
if (data) await this._conn.writeReg(_REG_DACEQ, data);
|
|
550
|
+
await this._update(_REG_DAC_RAMP_EQ, 0x08, coefficients === null ? 0x08 : 0x00);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Set the three DAC mute bits individually (0x31 bits 7:5).
|
|
555
|
+
* @param {boolean} [dsm=true] - DSM mute (bit 6).
|
|
556
|
+
* @param {boolean} [dem=true] - DEM mute (bit 5).
|
|
557
|
+
* @param {boolean} [dsmTarget=false] - DSM mute target (bit 7).
|
|
558
|
+
* @returns {Promise<void>}
|
|
559
|
+
*/
|
|
560
|
+
async setDacMuteOptions(dsm = true, dem = true, dsmTarget = false) {
|
|
561
|
+
await this._ready;
|
|
562
|
+
await this._update(_REG_DAC_MUTE, 0xE0, (dsmTarget ? 0x80 : 0) | (dsm ? 0x40 : 0) | (dem ? 0x20 : 0));
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Feed the ADC output to the DAC (0x44 bit 7).
|
|
567
|
+
* @param {boolean} enabled - True to enable the loopback.
|
|
568
|
+
* @returns {Promise<void>}
|
|
569
|
+
*/
|
|
570
|
+
async setLoopback(enabled) {
|
|
571
|
+
await this._ready;
|
|
572
|
+
await this._update(_REG_GPIO, 0x80, enabled ? 0x80 : 0x00);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Select the ADCDAT content (0x44 bits 6:4).
|
|
577
|
+
* @param {string} mode - 'adc_adc', 'adc_zero', 'zero_adc', 'dac_adc', 'adc_dac' or 'dac_dac'.
|
|
578
|
+
* @returns {Promise<void>}
|
|
579
|
+
* @throws {RangeError} For an unknown mode.
|
|
580
|
+
*/
|
|
581
|
+
async setAdcdatMode(mode) {
|
|
582
|
+
if (!(mode in _ADCDAT_MODES)) throw new RangeError('unknown ADCDAT mode');
|
|
583
|
+
await this._ready;
|
|
584
|
+
await this._update(_REG_GPIO, 0x70, _ADCDAT_MODES[mode] << 4);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Mute the digital audio input and / or output (0x09 / 0x0A bit 6).
|
|
589
|
+
* @param {boolean} [input=false] - Mute the serial input (DAC data).
|
|
590
|
+
* @param {boolean} [output=false] - Mute the serial output (ADC data).
|
|
591
|
+
* @returns {Promise<void>}
|
|
592
|
+
*/
|
|
593
|
+
async setSdpMute(input = false, output = false) {
|
|
594
|
+
await this._ready;
|
|
595
|
+
await this._update(_REG_SDP_IN, 0x40, input ? 0x40 : 0x00);
|
|
596
|
+
await this._update(_REG_SDP_OUT, 0x40, output ? 0x40 : 0x00);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Raw register read.
|
|
601
|
+
* @param {number} register - Register address 0x00–0xFF.
|
|
602
|
+
* @returns {Promise<number>} Register value.
|
|
603
|
+
*/
|
|
604
|
+
async readRegister(register) {
|
|
605
|
+
await this._ready;
|
|
606
|
+
return this._r(register);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Raw register write.
|
|
611
|
+
* @param {number} register - Register address 0x00–0xFF.
|
|
612
|
+
* @param {number} value - Byte value.
|
|
613
|
+
* @returns {Promise<void>}
|
|
614
|
+
*/
|
|
615
|
+
async writeRegister(register, value) {
|
|
616
|
+
await this._ready;
|
|
617
|
+
await this._w(register, value & 0xFF);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
module.exports = { ES8311Minimal, ES8311Full, ALC_LEVELS_DB, NOISE_GATE_DB };
|