@mikrojs/native 0.8.0-pr-115.g87a99f9 → 0.8.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.8.0-pr-115.g87a99f9",
3
+ "version": "0.8.0",
4
4
  "description": "Mikro.js C++ runtime library and Node.js native addon",
5
5
  "keywords": [
6
6
  "esp32",
@@ -78,7 +78,7 @@
78
78
  "cmake-js": "^8.0.0",
79
79
  "node-addon-api": "^8.7.0",
80
80
  "node-gyp-build": "^4.8.4",
81
- "@mikrojs/quickjs": "0.8.0-pr-115.g87a99f9"
81
+ "@mikrojs/quickjs": "0.8.0"
82
82
  },
83
83
  "devDependencies": {
84
84
  "@swc/core": "^1.15.30",
@@ -128,17 +128,13 @@ declare module 'native:pin' {
128
128
  }
129
129
 
130
130
  declare module 'native:sleep' {
131
- import type {SleepError} from '@mikrojs/native/runtime/sleep/types'
132
- import type {Result} from 'mikrojs/result'
131
+ import type {DeepWakeupSources, LightWakeupSources} from '@mikrojs/native/runtime/sleep/types'
133
132
 
134
- export function deepSleep(ms: number): never
135
- export function lightSleep(ms: number): Result<void, SleepError>
133
+ export function deepSleep(sources: DeepWakeupSources): never
134
+ export function lightSleep(sources: LightWakeupSources): void
136
135
  export function getWakeupCause(): string
137
- export function enableTimerWakeup(us: number): Result<void, SleepError>
138
- export function enableGpioWakeup(pin: number, level: number): Result<void, SleepError>
139
- export function enableExt0Wakeup(pin: number, level: number): Result<void, SleepError>
140
- export function enableExt1Wakeup(pinMask: number, mode: number): Result<void, SleepError>
141
- export function disableWakeupSource(source?: string): Result<void, SleepError>
136
+ export function canWakeFromExt0(): boolean
137
+ export function canWakeFromExt1(): boolean
142
138
  }
143
139
 
144
140
  declare module 'native:http' {
@@ -1,13 +1,17 @@
1
- export {
2
- deepSleep,
3
- disableWakeupSource,
4
- enableExt0Wakeup,
5
- enableExt1Wakeup,
6
- enableGpioWakeup,
7
- enableTimerWakeup,
8
- getWakeupCause,
9
- lightSleep,
10
- } from 'native:sleep'
1
+ import {deepSleep as nativeDeepSleep, lightSleep as nativeLightSleep} from 'native:sleep'
2
+
3
+ import type {DeepWakeupSources, LightWakeupSources} from './types.js'
4
+
5
+ export type {DeepWakeupSources, LightWakeupSources, RtcGpio, WakeupLevel} from './types.js'
6
+ export {canWakeFromExt0, canWakeFromExt1} from 'native:sleep'
7
+
8
+ export function deepSleep(sources: DeepWakeupSources | number): never {
9
+ return nativeDeepSleep(typeof sources === 'number' ? {timer: sources} : sources)
10
+ }
11
+
12
+ export function lightSleep(sources: LightWakeupSources | number): void {
13
+ nativeLightSleep(typeof sources === 'number' ? {timer: sources} : sources)
14
+ }
11
15
 
12
16
  export function sleep(ms: number): Promise<void> {
13
17
  return new Promise((resolve) => setTimeout(resolve, ms))
@@ -1,44 +1,67 @@
1
- import type {Result} from '../result/types.js'
1
+ export type WakeupLevel = 'high' | 'low'
2
2
 
3
- export type SleepError =
4
- | {name: 'WakeupConfigFailed'; message: string}
5
- | {name: 'LightSleepFailed'; message: string}
6
- | {name: 'DisableWakeupFailed'; message: string}
7
-
8
- export declare function deepSleep(time: number): never
9
-
10
- export declare function lightSleep(time: number): Result<void, SleepError>
3
+ /** A GPIO pin number that must be RTC-capable for deep-sleep wake.
4
+ * Set varies per chip:
5
+ * - ESP32-C6 / H2: 0–7 (LP_GPIO0–LP_GPIO7)
6
+ * - ESP32-C3: 0–5
7
+ * - ESP32-S2 / S3: 0–21 (LP_IO0–LP_IO21)
8
+ * - ESP32: subset of 0–39 (see datasheet for RTC_GPIO mapping)
9
+ *
10
+ * Not statically validated passing a non-RTC pin throws at runtime.
11
+ */
12
+ export type RtcGpio = number
11
13
 
12
- export declare function getWakeupCause(): string
14
+ /** Sources that can wake the chip from light sleep. */
15
+ export type LightWakeupSources = {
16
+ /** Wake after this many milliseconds. Fractional values are allowed
17
+ * (e.g. `0.01` = 10 µs). */
18
+ timer?: number
19
+ /** Wake when `pin` reaches `level`. Any GPIO works — no RTC-capable
20
+ * constraint. */
21
+ gpio?: {pin: number; level: WakeupLevel}
22
+ }
13
23
 
14
- /** Configure timer wakeup source (microseconds). */
15
- export declare function enableTimerWakeup(us: number): Result<void, SleepError>
24
+ /** Sources that can wake the chip from deep sleep. */
25
+ export type DeepWakeupSources = {
26
+ /** Wake after this many milliseconds. Fractional values are allowed. */
27
+ timer?: number
28
+ /** Wake on a single RTC GPIO. ESP32 / S2 / S3 only — throws on
29
+ * C3 / C6 / H2 (use `ext1` instead). */
30
+ ext0?: {pin: RtcGpio; level: WakeupLevel}
31
+ /** Wake when any of `pins` matches `mode`. Pins must be RTC-capable.
32
+ *
33
+ * Caveat — original ESP32 chip only: the EXT1 hardware on the
34
+ * original ESP32 cannot honor "any-low" with more than one pin (the
35
+ * silicon always requires *every* selected pin to be low, not any).
36
+ * Multi-pin `{mode: 'any-low'}` throws on ESP32; single-pin works,
37
+ * and `'any-high'` works for any pin count. Every newer chip
38
+ * (C3, C5, C6, S2, S3, …) supports multi-pin `'any-low'` natively. */
39
+ ext1?: {pins: RtcGpio[]; mode: 'any-low' | 'any-high'}
40
+ }
16
41
 
17
42
  /**
18
- * Configure GPIO wakeup for light sleep.
19
- * @param pin GPIO pin number
20
- * @param level GPIO interrupt type (e.g. 4 = low, 5 = high)
43
+ * Enter deep sleep. Pass a `DeepWakeupSources` object, or a number as
44
+ * shorthand for `{timer: ms}`. The chip resets on wake.
21
45
  */
22
- export declare function enableGpioWakeup(pin: number, level: number): Result<void, SleepError>
46
+ export declare function deepSleep(ms: number): never
47
+ export declare function deepSleep(sources: DeepWakeupSources): never
23
48
 
24
49
  /**
25
- * Configure ext0 wakeup for deep sleep (ESP32, ESP32-S2, ESP32-S3 only).
26
- * @param pin RTC GPIO pin number
27
- * @param level 0 = low, 1 = high
50
+ * Enter light sleep. Pass a `LightWakeupSources` object, or a number as
51
+ * shorthand for `{timer: ms}`. Execution resumes from the call site
52
+ * after waking.
28
53
  */
29
- export declare function enableExt0Wakeup(pin: number, level: number): Result<void, SleepError>
54
+ export declare function lightSleep(ms: number): void
55
+ export declare function lightSleep(sources: LightWakeupSources): void
30
56
 
31
- /**
32
- * Configure ext1 wakeup for deep sleep.
33
- * @param pinMask Bitmask of RTC GPIO pins
34
- * @param mode 0 = ESP_EXT1_WAKEUP_ALL_LOW, 1 = ESP_EXT1_WAKEUP_ANY_HIGH
35
- */
36
- export declare function enableExt1Wakeup(pinMask: number, mode: number): Result<void, SleepError>
57
+ /** Returns `true` if the current chip supports EXT0 wakeup
58
+ * (ESP32, ESP32-S2, ESP32-S3). Use to gate `deepSleep({ext0: …})`
59
+ * calls when targeting boards across the ESP32 family. */
60
+ export declare function canWakeFromExt0(): boolean
37
61
 
38
- /**
39
- * Disable a wakeup source. If no source is specified, all sources are disabled.
40
- * @param source Optional: "timer", "ext0", "ext1", "gpio", "touchpad", "ulp"
41
- */
42
- export declare function disableWakeupSource(source?: string): Result<void, SleepError>
62
+ /** Returns `true` if the current chip supports EXT1 wakeup. Every
63
+ * chip mikrojs targets except ESP32-C3. Use to gate
64
+ * `deepSleep({ext1: …})` calls. */
65
+ export declare function canWakeFromExt1(): boolean
43
66
 
44
67
  export declare function sleep(ms: number): Promise<void>
@@ -1,4 +1,5 @@
1
1
  import {err, ok, PanicError, type Result} from 'mikrojs/result'
2
+ import {getWakeupCause as nativeGetWakeupCause} from 'native:sleep'
2
3
  import * as native from 'native:sys'
3
4
 
4
5
  export function uptime(): {boot: number; rtc: number} {
@@ -40,6 +41,10 @@ export function restart(): never {
40
41
  return native.restart() as never
41
42
  }
42
43
 
44
+ export function getWakeupCause(): string {
45
+ return nativeGetWakeupCause()
46
+ }
47
+
43
48
  export function exit(_exitCode?: number): never {
44
49
  return native.restart() as never
45
50
  }
@@ -124,6 +124,11 @@ export declare const firmware: {
124
124
 
125
125
  export declare function restart(): never
126
126
 
127
+ /** Reason the device woke up this boot. Set after deep sleep (or first
128
+ * boot). One of: `'timer'`, `'ext0'`, `'ext1'`, `'gpio'`, or `'undefined'`
129
+ * (cold boot or unknown). */
130
+ export declare function getWakeupCause(): string
131
+
127
132
  export declare function exit(exitCode?: number): never
128
133
 
129
134
  /** Immediately crash with an error message. Use for unrecoverable situations. */