@mikrojs/native 0.15.0-pr-243.20260613121220 → 0.15.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikrojs/native",
|
|
3
|
-
"version": "0.15.0
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Mikro.js C++ runtime library and Node.js native addon",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"esp32",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"./runtime/http/server-impl": "./runtime/http/server-impl.ts",
|
|
57
57
|
"./runtime/fs/types": "./runtime/fs/types.ts",
|
|
58
58
|
"./runtime/i2c/types": "./runtime/i2c/types.ts",
|
|
59
|
+
"./runtime/i2s/types": "./runtime/i2s/types.ts",
|
|
59
60
|
"./runtime/inspect/types": "./runtime/inspect/types.ts",
|
|
60
61
|
"./runtime/kv/shared": "./runtime/kv/shared.ts",
|
|
61
62
|
"./runtime/kv/types": "./runtime/kv/types.ts",
|
|
@@ -83,7 +84,7 @@
|
|
|
83
84
|
"cmake-js": "^8.0.0",
|
|
84
85
|
"node-addon-api": "^8.7.0",
|
|
85
86
|
"node-gyp-build": "^4.8.4",
|
|
86
|
-
"@mikrojs/quickjs": "0.15.0
|
|
87
|
+
"@mikrojs/quickjs": "0.15.0"
|
|
87
88
|
},
|
|
88
89
|
"devDependencies": {
|
|
89
90
|
"@swc/core": "^1.15.30",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as native from 'native:mikro/i2s'
|
|
2
|
+
|
|
3
|
+
import type {Result} from '../result/types.js'
|
|
4
|
+
import type {
|
|
5
|
+
I2sBase,
|
|
6
|
+
I2sError,
|
|
7
|
+
I2sPdmRxOptions,
|
|
8
|
+
I2sSamples,
|
|
9
|
+
I2sStdRxOptions,
|
|
10
|
+
I2sStdTxOptions,
|
|
11
|
+
I2sStdTxRxOptions,
|
|
12
|
+
} from './types.js'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export class I2s implements I2sBase {
|
|
18
|
+
#native: native.I2s
|
|
19
|
+
|
|
20
|
+
constructor(port: number, options: I2sStdTxRxOptions)
|
|
21
|
+
constructor(port: number, options: I2sStdTxOptions)
|
|
22
|
+
constructor(port: number, options: I2sStdRxOptions)
|
|
23
|
+
constructor(port: number, options: I2sPdmRxOptions)
|
|
24
|
+
constructor(
|
|
25
|
+
port: number,
|
|
26
|
+
options: I2sStdTxRxOptions | I2sStdTxOptions | I2sStdRxOptions | I2sPdmRxOptions,
|
|
27
|
+
) {
|
|
28
|
+
this.#native = new native.I2s(port, options)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
begin(): Result<void, I2sError> {
|
|
32
|
+
return this.#native.begin()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
end(): Result<void, I2sError> {
|
|
36
|
+
return this.#native.end()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
write(data: I2sSamples | Uint8Array): Promise<Result<void, I2sError>> {
|
|
40
|
+
return this.#native.write(data)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
capture(frames: number, options?: {gainBits?: number}): Result<Int16Array, I2sError> {
|
|
44
|
+
return this.#native.capture(frames, options)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type {Result} from '../result/types.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Samples crossing the I2S boundary. `Int16Array` when configured 16-bit,
|
|
5
|
+
* `Int32Array` when 32-bit. Stereo data is interleaved `L,R,L,R…`.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export type I2sSamples = Int16Array | Int32Array
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export interface I2sStdBaseOptions {
|
|
15
|
+
mode?: 'std'
|
|
16
|
+
/** Sample rate in Hz (e.g. 16000, 44100). */
|
|
17
|
+
sampleRate: number
|
|
18
|
+
/** Bits per sample. Default 16. */
|
|
19
|
+
bitsPerSample?: 16 | 32
|
|
20
|
+
/** Slot mode. Default 'stereo'. */
|
|
21
|
+
channels?: 'mono' | 'stereo'
|
|
22
|
+
/** Bit clock (SCK) pin. */
|
|
23
|
+
bclk: number
|
|
24
|
+
/** Word select / LR clock pin. */
|
|
25
|
+
ws: number
|
|
26
|
+
/** Frames per DMA buffer. Audio-tuned default; raise for fewer wakeups, lower for less latency. */
|
|
27
|
+
dmaFrames?: number
|
|
28
|
+
/** Number of DMA buffers. Audio-tuned default. */
|
|
29
|
+
dmaBuffers?: number
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export interface I2sStdTxOptions extends I2sStdBaseOptions {
|
|
36
|
+
/** Data-out pin (to an amp/DAC). */
|
|
37
|
+
dout: number
|
|
38
|
+
din?: undefined
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export interface I2sStdRxOptions extends I2sStdBaseOptions {
|
|
45
|
+
/** Data-in pin (from a mic/codec). */
|
|
46
|
+
din: number
|
|
47
|
+
dout?: undefined
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export interface I2sStdTxRxOptions extends I2sStdBaseOptions {
|
|
54
|
+
dout: number
|
|
55
|
+
din: number
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* PDM is receive-only and chip-dependent (classic ESP32 and S3 support it; some
|
|
60
|
+
* C/H-series targets do not). On unsupported chips `begin()` returns
|
|
61
|
+
* `ChannelInitFailed`.
|
|
62
|
+
*
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
export interface I2sPdmRxOptions {
|
|
66
|
+
mode: 'pdm'
|
|
67
|
+
sampleRate: number
|
|
68
|
+
bitsPerSample?: 16 | 32
|
|
69
|
+
/** Default 'mono'. */
|
|
70
|
+
channels?: 'mono' | 'stereo'
|
|
71
|
+
/** PDM clock pin. */
|
|
72
|
+
clk: number
|
|
73
|
+
/** PDM data-in pin. */
|
|
74
|
+
din: number
|
|
75
|
+
dmaFrames?: number
|
|
76
|
+
dmaBuffers?: number
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
export type I2sError =
|
|
83
|
+
| {name: 'ChannelInitFailed'; message: string}
|
|
84
|
+
| {name: 'InvalidParam'; message: string}
|
|
85
|
+
| {name: 'WriteFailed'; message: string}
|
|
86
|
+
| {name: 'ReadFailed'; message: string}
|
|
87
|
+
| {name: 'NotStarted'}
|
|
88
|
+
| {name: 'QueueFull'}
|
|
89
|
+
| {name: 'NoRxPin'}
|
|
90
|
+
| {name: 'NoTxPin'}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @public
|
|
94
|
+
*/
|
|
95
|
+
export interface I2sTx {
|
|
96
|
+
/**
|
|
97
|
+
* Queue samples for transmission. Resolves once the chunk has been handed to
|
|
98
|
+
* DMA. A small bounded queue double-buffers for gapless playback; producing
|
|
99
|
+
* faster than realtime resolves `err(QueueFull)`. Element width must match
|
|
100
|
+
* `bitsPerSample` (or be a raw `Uint8Array`); a mismatch is `err(InvalidParam)`.
|
|
101
|
+
*/
|
|
102
|
+
write(data: I2sSamples | Uint8Array): Promise<Result<void, I2sError>>
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
export interface I2sRx {
|
|
109
|
+
/**
|
|
110
|
+
* Blocking bulk capture: read exactly `frames` mono samples (from a 32-bit
|
|
111
|
+
* mono channel), converted to 16-bit PCM in C and returned as one packed
|
|
112
|
+
* `Int16Array`. `gainBits` left-shifts each sample by that many bits (clamped)
|
|
113
|
+
* for a louder result. No per-chunk allocation or async machinery, so it can
|
|
114
|
+
* sustain high sample rates. It BLOCKS the event loop for ~`frames`/sample-rate
|
|
115
|
+
* while it drains the DMA; size `frames` to trade throughput against how often
|
|
116
|
+
* the loop runs between captures, and use it only in a dedicated capture/stream
|
|
117
|
+
* loop, not where timers and other async must stay responsive.
|
|
118
|
+
*/
|
|
119
|
+
capture(frames: number, options?: {gainBits?: number}): Result<Int16Array, I2sError>
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @public
|
|
124
|
+
*/
|
|
125
|
+
export interface I2sBase {
|
|
126
|
+
begin(): Result<void, I2sError>
|
|
127
|
+
end(): Result<void, I2sError>
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @public
|
|
132
|
+
*/
|
|
133
|
+
export declare const I2s: {
|
|
134
|
+
prototype: I2sBase
|
|
135
|
+
new (port: number, options: I2sStdTxRxOptions): I2sBase & I2sTx & I2sRx
|
|
136
|
+
new (port: number, options: I2sStdTxOptions): I2sBase & I2sTx
|
|
137
|
+
new (port: number, options: I2sStdRxOptions): I2sBase & I2sRx
|
|
138
|
+
new (port: number, options: I2sPdmRxOptions): I2sBase & I2sRx
|
|
139
|
+
}
|
package/runtime/internal.d.ts
CHANGED
|
@@ -518,3 +518,37 @@ declare module 'native:mikro/udp' {
|
|
|
518
518
|
|
|
519
519
|
export function bind(opts: BindOptions): Promise<Result<NativeUdpSocket, UdpError>>
|
|
520
520
|
}
|
|
521
|
+
|
|
522
|
+
declare module 'native:mikro/i2s' {
|
|
523
|
+
import type {I2sError, I2sSamples} from '@mikrojs/native/runtime/i2s/types'
|
|
524
|
+
import type {Result} from 'mikro/result'
|
|
525
|
+
|
|
526
|
+
export interface I2sNativeOptions {
|
|
527
|
+
mode?: 'std' | 'pdm'
|
|
528
|
+
sampleRate: number
|
|
529
|
+
bitsPerSample?: 16 | 32
|
|
530
|
+
channels?: 'mono' | 'stereo'
|
|
531
|
+
bclk?: number
|
|
532
|
+
ws?: number
|
|
533
|
+
clk?: number
|
|
534
|
+
dout?: number
|
|
535
|
+
din?: number
|
|
536
|
+
dmaFrames?: number
|
|
537
|
+
dmaBuffers?: number
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
export declare const I2s: {
|
|
541
|
+
prototype: I2s
|
|
542
|
+
new (port: number, options: I2sNativeOptions): I2s
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export interface I2s {
|
|
546
|
+
begin(): Result<void, I2sError>
|
|
547
|
+
|
|
548
|
+
end(): Result<void, I2sError>
|
|
549
|
+
|
|
550
|
+
write(data: I2sSamples | Uint8Array): Promise<Result<void, I2sError>>
|
|
551
|
+
|
|
552
|
+
capture(frames: number, options?: {gainBits?: number}): Result<Int16Array, I2sError>
|
|
553
|
+
}
|
|
554
|
+
}
|