@typecad/hal 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +127 -0
- package/dist/adc.d.ts +13 -0
- package/dist/adc.js +22 -0
- package/dist/async.d.ts +30 -0
- package/dist/async.js +56 -0
- package/dist/board.d.ts +3 -0
- package/dist/board.js +5 -0
- package/dist/callback.d.ts +4 -0
- package/dist/callback.js +6 -0
- package/dist/constants.d.ts +21 -0
- package/dist/constants.js +23 -0
- package/dist/dac.d.ts +12 -0
- package/dist/dac.js +17 -0
- package/dist/eeprom.d.ts +16 -0
- package/dist/eeprom.js +21 -0
- package/dist/emit.d.ts +121 -0
- package/dist/emit.js +177 -0
- package/dist/fs.d.ts +13 -0
- package/dist/fs.js +39 -0
- package/dist/gpio.d.ts +108 -0
- package/dist/gpio.js +230 -0
- package/dist/i2c.d.ts +40 -0
- package/dist/i2c.js +126 -0
- package/dist/include.d.ts +5 -0
- package/dist/include.js +5 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +30 -0
- package/dist/interrupts.d.ts +17 -0
- package/dist/interrupts.js +25 -0
- package/dist/math.d.ts +22 -0
- package/dist/math.js +28 -0
- package/dist/power.d.ts +14 -0
- package/dist/power.js +21 -0
- package/dist/preferences.d.ts +18 -0
- package/dist/preferences.js +55 -0
- package/dist/pulse.d.ts +24 -0
- package/dist/pulse.js +53 -0
- package/dist/random.d.ts +12 -0
- package/dist/random.js +26 -0
- package/dist/register.d.ts +11 -0
- package/dist/register.js +21 -0
- package/dist/shift.d.ts +31 -0
- package/dist/shift.js +71 -0
- package/dist/spi.d.ts +31 -0
- package/dist/spi.js +90 -0
- package/dist/timer.d.ts +35 -0
- package/dist/timer.js +50 -0
- package/dist/timing.d.ts +29 -0
- package/dist/timing.js +53 -0
- package/dist/types.d.ts +48 -0
- package/dist/types.js +67 -0
- package/dist/uart.d.ts +21 -0
- package/dist/uart.js +58 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.js +14 -0
- package/dist/wdt.d.ts +7 -0
- package/dist/wdt.js +14 -0
- package/package.json +64 -0
- package/src/adc.ts +30 -0
- package/src/async.ts +63 -0
- package/src/board.ts +5 -0
- package/src/callback.ts +6 -0
- package/src/constants.ts +23 -0
- package/src/dac.ts +21 -0
- package/src/eeprom.ts +26 -0
- package/src/emit.ts +210 -0
- package/src/fs.ts +46 -0
- package/src/gpio.ts +298 -0
- package/src/i2c.ts +155 -0
- package/src/include.ts +5 -0
- package/src/index.ts +48 -0
- package/src/interrupts.ts +35 -0
- package/src/math.ts +32 -0
- package/src/power.ts +26 -0
- package/src/preferences.ts +58 -0
- package/src/pulse.ts +63 -0
- package/src/random.ts +31 -0
- package/src/register.ts +35 -0
- package/src/shift.ts +88 -0
- package/src/spi.ts +118 -0
- package/src/timer.ts +59 -0
- package/src/timing.ts +67 -0
- package/src/types.ts +144 -0
- package/src/uart.ts +77 -0
- package/src/utils.ts +17 -0
- package/src/wdt.ts +17 -0
package/src/adc.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { adcRead, adcSetReference, boardResolve } from './emit.js';
|
|
2
|
+
|
|
3
|
+
export class ADCClass {
|
|
4
|
+
static readonly __instance_name = "ADC";
|
|
5
|
+
static readonly __default_fields = { _reference: "DEFAULT" };
|
|
6
|
+
_reference: string;
|
|
7
|
+
|
|
8
|
+
constructor() {
|
|
9
|
+
this._reference = "DEFAULT";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
getAnalogResolution(): number {
|
|
13
|
+
return boardResolve("peripherals.adc.0.resolution");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
setAnalogReference(ref: string): void {
|
|
17
|
+
this._reference = ref;
|
|
18
|
+
adcSetReference(ref);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getAnalogReference(): number {
|
|
22
|
+
return boardResolve("peripherals.adc.0.referenceVoltages." + this._reference);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
read(pin: number): number {
|
|
26
|
+
return adcRead(pin);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const ADC = new ADCClass();
|
package/src/async.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Async — Top-level cooperative async / scheduling abstraction for TypeCAD
|
|
3
|
+
//
|
|
4
|
+
// Provides a platform-independent API for:
|
|
5
|
+
// - sleep(ms) — non-blocking delay via Promise + microtask
|
|
6
|
+
// - yield() — cooperative yield to other tasks
|
|
7
|
+
// - sleepUntil(condition) — await a condition (promise-based)
|
|
8
|
+
// - currentTask() — return a description of the currently executing task
|
|
9
|
+
//
|
|
10
|
+
// Framework packages (Arduino, Native, etc.) provide the C++ runtime behind
|
|
11
|
+
// the rawCpp() markers; the transpiler resolves these to the correct platform
|
|
12
|
+
// implementation at compile time.
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
import { rawCpp } from './emit.js';
|
|
16
|
+
|
|
17
|
+
export class AsyncClass {
|
|
18
|
+
static readonly __instance_name = "Async";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Non-blocking sleep for `ms` milliseconds.
|
|
22
|
+
* Returns a Promise<void> that resolves after the given delay.
|
|
23
|
+
* The underlying C++ implementation uses the platform's timer/microtask
|
|
24
|
+
* mechanism (e.g. millis-based polling on Arduino, std::this_thread::sleep_for
|
|
25
|
+
* on native, or a FreeRTOS vTaskDelay in the future).
|
|
26
|
+
*/
|
|
27
|
+
sleep(ms: number): Promise<void> {
|
|
28
|
+
rawCpp(`__cuttlefish_async_sleep(${ms});`);
|
|
29
|
+
return Promise.resolve();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Cooperative yield — suspend the current task and allow other tasks
|
|
34
|
+
* (microtasks, timers) to run. Resumes on the next microtask pump cycle.
|
|
35
|
+
*/
|
|
36
|
+
yield(): Promise<void> {
|
|
37
|
+
rawCpp(`__cuttlefish_async_yield();`);
|
|
38
|
+
return Promise.resolve();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Await a polling condition.
|
|
43
|
+
* Repeatedly checks `condition()` every `pollIntervalMs` milliseconds
|
|
44
|
+
* until it returns true, then resolves.
|
|
45
|
+
* The underlying implementation uses the platform's timer mechanism.
|
|
46
|
+
*/
|
|
47
|
+
sleepUntil(condition: () => boolean, pollIntervalMs: number = 10): Promise<void> {
|
|
48
|
+
rawCpp(`__cuttlefish_async_sleep_until(${pollIntervalMs});`);
|
|
49
|
+
return Promise.resolve();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Return a human-readable description of the currently executing async task.
|
|
54
|
+
* Useful for debugging / logging in cooperative multitasking environments.
|
|
55
|
+
*/
|
|
56
|
+
currentTask(): string {
|
|
57
|
+
rawCpp(`return __cuttlefish_async_current_task();`);
|
|
58
|
+
return "";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Singleton instance — consumers use `Async.sleep(...)` directly. */
|
|
63
|
+
export const Async = new AsyncClass();
|
package/src/board.ts
ADDED
package/src/callback.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Compile-time function: registers a function argument as a standalone C++ callback.
|
|
2
|
+
* Returns the generated function name for use in rawCpp() templates.
|
|
3
|
+
* At runtime (tests, type-checking) this is a no-op. */
|
|
4
|
+
export function callback<T extends (...args: any[]) => any>(_fn: T): string {
|
|
5
|
+
return "";
|
|
6
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// These constants are resolved from the board definition at compile time by the
|
|
2
|
+
// transpiler. At runtime (tests, type-checking) they default to 0.
|
|
3
|
+
export const INPUT: number = 0;
|
|
4
|
+
export const OUTPUT: number = 0;
|
|
5
|
+
export const INPUT_PULLUP: number = 0;
|
|
6
|
+
export const INPUT_PULLDOWN: number = 0;
|
|
7
|
+
export const OUTPUT_OPEN_DRAIN: number = 0;
|
|
8
|
+
export const ANALOG: number = 0;
|
|
9
|
+
export const HIGH: number = 0;
|
|
10
|
+
export const LOW: number = 0;
|
|
11
|
+
export const LED_BUILTIN: number = 0;
|
|
12
|
+
export const LSBFIRST: number = 0;
|
|
13
|
+
export const MSBFIRST: number = 0;
|
|
14
|
+
export const WDTO_15MS: number = 0;
|
|
15
|
+
export const WDTO_30MS: number = 0;
|
|
16
|
+
export const WDTO_60MS: number = 0;
|
|
17
|
+
export const WDTO_120MS: number = 0;
|
|
18
|
+
export const WDTO_250MS: number = 0;
|
|
19
|
+
export const WDTO_500MS: number = 0;
|
|
20
|
+
export const WDTO_1S: number = 0;
|
|
21
|
+
export const WDTO_2S: number = 0;
|
|
22
|
+
export const WDTO_4S: number = 0;
|
|
23
|
+
export const WDTO_8S: number = 0;
|
package/src/dac.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { dacWrite, boardResolve } from './emit.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* DACClass provides access to true digital-to-analog converters.
|
|
5
|
+
*
|
|
6
|
+
* Note: This is for true analog output (DAC), distinct from PWM-based
|
|
7
|
+
* analog simulation provided by Pin.pwm().
|
|
8
|
+
*/
|
|
9
|
+
export class DACClass {
|
|
10
|
+
static readonly __instance_name = "DAC";
|
|
11
|
+
|
|
12
|
+
write(pin: number, value: number): void {
|
|
13
|
+
dacWrite(pin, value);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getResolution(): number {
|
|
17
|
+
return boardResolve("peripherals.dac.0.resolution");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const DAC = new DACClass();
|
package/src/eeprom.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { rawCpp } from './emit.js';
|
|
2
|
+
import { include } from './include.js';
|
|
3
|
+
|
|
4
|
+
export class EEPROMClass {
|
|
5
|
+
static readonly __instance_name = "EEPROM";
|
|
6
|
+
static readonly __includes = ["<EEPROM.h>"];
|
|
7
|
+
static readonly __default_fields = { _name: "EEPROM" };
|
|
8
|
+
|
|
9
|
+
private _name: string;
|
|
10
|
+
constructor(name: string) {
|
|
11
|
+
include("<EEPROM.h>");
|
|
12
|
+
this._name = name;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
read(address: number): number { return 0; }
|
|
16
|
+
write(address: number, value: number): void { rawCpp(`${this._name}.write(${address}, ${value});`); }
|
|
17
|
+
update(address: number, value: number): void { rawCpp(`${this._name}.update(${address}, ${value});`); }
|
|
18
|
+
length(): number { return 0; }
|
|
19
|
+
get<T>(address: number, ref: T): T {
|
|
20
|
+
rawCpp(`${this._name}.get(${address}, ${ref});`);
|
|
21
|
+
return ref;
|
|
22
|
+
}
|
|
23
|
+
put<T>(address: number, value: T): void { rawCpp(`${this._name}.put(${address}, ${value});`); }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const EEPROM = new EEPROMClass("EEPROM");
|
package/src/emit.ts
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// HAL compile-time semantic functions
|
|
3
|
+
//
|
|
4
|
+
// These functions are resolved to HALOpIR nodes by the transpiler's HAL
|
|
5
|
+
// resolver. The framework strategy translates each operation into
|
|
6
|
+
// framework-specific C++ at code generation time.
|
|
7
|
+
//
|
|
8
|
+
// Pin parameters accept both `number` (legacy framework pin number) and
|
|
9
|
+
// `string` (MCU port name like "PB5"). The transpiler resolves port names
|
|
10
|
+
// to framework pin numbers via the MCU package's pin mapping.
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// GPIO — digital pin control
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
/** Set a digital pin HIGH or LOW. */
|
|
18
|
+
export function gpioWrite(pin: number | string, value: number | boolean): void {}
|
|
19
|
+
/** Read a digital pin. Returns HIGH (1) or LOW (0). */
|
|
20
|
+
export function gpioRead(pin: number | string): number { return 0; }
|
|
21
|
+
/** Toggle a digital pin. */
|
|
22
|
+
export function gpioToggle(pin: number | string): void {}
|
|
23
|
+
/** Set pin mode: "output" | "input" | "input_pullup" | "input_pulldown". */
|
|
24
|
+
export function gpioSetMode(pin: number | string, mode: string): void {}
|
|
25
|
+
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
// PWM — pulse-width modulation
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
/** Write PWM duty cycle to a pin. */
|
|
31
|
+
export function pwmWrite(pin: number | string, duty: number): void {}
|
|
32
|
+
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// ADC — analog-to-digital conversion
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
/** Read analog value from a pin. */
|
|
38
|
+
export function adcRead(pin: number | string): number { return 0; }
|
|
39
|
+
/** Read analog voltage from a pin (ADC value converted to voltage). */
|
|
40
|
+
export function adcReadVoltage(pin: number | string): number { return 0; }
|
|
41
|
+
/** Set the analog reference. */
|
|
42
|
+
export function adcSetReference(ref: string | number): void {}
|
|
43
|
+
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
// Interrupts
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
|
|
48
|
+
/** Attach an interrupt handler to a pin. */
|
|
49
|
+
export function interruptAttach(pin: number | string, handler: string, mode: string): void {}
|
|
50
|
+
/** Detach an interrupt from a pin. */
|
|
51
|
+
export function interruptDetach(pin: number | string): void {}
|
|
52
|
+
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Tone / audio output
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
/** Play a tone on a pin at the given frequency, optionally for a duration. */
|
|
58
|
+
export function tonePlay(pin: number | string, frequency: number, duration?: number): void {}
|
|
59
|
+
/** Stop tone playback on a pin. */
|
|
60
|
+
export function toneStop(pin: number | string): void {}
|
|
61
|
+
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
// Timing
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
|
|
66
|
+
/** Delay for the given number of milliseconds. */
|
|
67
|
+
export function delayMs(ms: number): void {}
|
|
68
|
+
/** Delay for the given number of microseconds. */
|
|
69
|
+
export function delayMicro(us: number): void {}
|
|
70
|
+
/** Get milliseconds since boot. */
|
|
71
|
+
export function getMillis(): number { return 0; }
|
|
72
|
+
/** Get microseconds since boot. */
|
|
73
|
+
export function getMicros(): number { return 0; }
|
|
74
|
+
/** Get free heap bytes. Architecture-aware: the strategy maps this to the right
|
|
75
|
+
* symbol per target (ESP.getFreeHeap() on ESP32, __heap_start trick on AVR). */
|
|
76
|
+
export function getFreeHeap(): number { return 0; }
|
|
77
|
+
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
// I2C — inter-integrated circuit bus
|
|
80
|
+
// ---------------------------------------------------------------------------
|
|
81
|
+
|
|
82
|
+
/** Initialize I2C bus (master mode if no address, slave mode with address). */
|
|
83
|
+
export function i2cBegin(bus: string, address?: number): void {}
|
|
84
|
+
/** Disable I2C bus. */
|
|
85
|
+
export function i2cEnd(bus: string): void {}
|
|
86
|
+
/** Set I2C bus clock speed. */
|
|
87
|
+
export function i2cSetClock(bus: string, hz: number): void {}
|
|
88
|
+
/** Begin I2C transmission to a slave address. */
|
|
89
|
+
export function i2cBeginTx(bus: string, address: number): void {}
|
|
90
|
+
/** Write data to I2C bus. */
|
|
91
|
+
export function i2cWrite(bus: string, data: string | number | number[] | Uint8Array): void {}
|
|
92
|
+
/** Write a byte buffer to I2C bus (expands array literals to per-byte writes). */
|
|
93
|
+
export function i2cWriteBuffer(bus: string, data: number[] | Uint8Array): void {}
|
|
94
|
+
/** End I2C transmission. Returns status. */
|
|
95
|
+
export function i2cEndTx(bus: string, stop: boolean): number { return 0; }
|
|
96
|
+
/** Request bytes from I2C slave. */
|
|
97
|
+
export function i2cRequestFrom(bus: string, address: number, quantity: number, stop?: boolean): number { return 0; }
|
|
98
|
+
/** Check if bytes are available from I2C. */
|
|
99
|
+
export function i2cAvailable(bus: string): number { return 0; }
|
|
100
|
+
/** Read a byte from I2C. */
|
|
101
|
+
export function i2cRead(bus: string): number { return 0; }
|
|
102
|
+
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
// SPI — serial peripheral interface
|
|
105
|
+
// ---------------------------------------------------------------------------
|
|
106
|
+
|
|
107
|
+
/** Initialize SPI bus. */
|
|
108
|
+
export function spiBegin(bus: string): void {}
|
|
109
|
+
/** Disable SPI bus. */
|
|
110
|
+
export function spiEnd(bus: string): void {}
|
|
111
|
+
/** Transfer data on SPI bus. */
|
|
112
|
+
export function spiTransfer(bus: string, data: string | number | Uint8Array): number { return 0; }
|
|
113
|
+
/** Begin SPI transaction with settings. */
|
|
114
|
+
export function spiBeginTx(bus: string, settings: string | any): void {}
|
|
115
|
+
/** End SPI transaction. */
|
|
116
|
+
export function spiEndTx(bus: string): void {}
|
|
117
|
+
/** Set SPI chip-select pin LOW. */
|
|
118
|
+
export function spiCsLow(pin: number | string): void {}
|
|
119
|
+
/** Set SPI chip-select pin HIGH. */
|
|
120
|
+
export function spiCsHigh(pin: number | string): void {}
|
|
121
|
+
/** Set SPI data mode. */
|
|
122
|
+
export function spiSetMode(bus: string, mode: number): void {}
|
|
123
|
+
/** Set SPI bit order. */
|
|
124
|
+
export function spiSetBitOrder(bus: string, order: string): void {}
|
|
125
|
+
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
// UART — serial communication
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
|
|
130
|
+
/** Initialize serial port with baud rate. */
|
|
131
|
+
export function uartBegin(port: string, baud: number): void {}
|
|
132
|
+
/** Disable serial port. */
|
|
133
|
+
export function uartEnd(port: string): void {}
|
|
134
|
+
/** Print value to serial. */
|
|
135
|
+
export function uartPrint(port: string, value: any): void {}
|
|
136
|
+
/** Print value with newline to serial. */
|
|
137
|
+
export function uartPrintln(port: string, value: any): void {}
|
|
138
|
+
/** printf-style formatted print to serial. */
|
|
139
|
+
export function uartPrintf(port: string, format: any, args: any[]): void {}
|
|
140
|
+
/** Write raw data to serial. */
|
|
141
|
+
export function uartWrite(port: string, data: any): void {}
|
|
142
|
+
/** Read a byte from serial. */
|
|
143
|
+
export function uartRead(port: string): number { return 0; }
|
|
144
|
+
/** Peek at next byte from serial without consuming. */
|
|
145
|
+
export function uartPeek(port: string): number { return 0; }
|
|
146
|
+
/** Check if bytes are available from serial. */
|
|
147
|
+
export function uartAvailable(port: string): number { return 0; }
|
|
148
|
+
/** Flush serial output. */
|
|
149
|
+
export function uartFlush(port: string): void {}
|
|
150
|
+
|
|
151
|
+
// ---------------------------------------------------------------------------
|
|
152
|
+
// Pulse measurement
|
|
153
|
+
// ---------------------------------------------------------------------------
|
|
154
|
+
|
|
155
|
+
/** Measure pulse duration on a pin. */
|
|
156
|
+
export function pulseIn_(pin: number | string, value: number, timeout?: number): number { return 0; }
|
|
157
|
+
/** Measure long pulse using high-precision timer. */
|
|
158
|
+
export function pulseInLong_(pin: number | string, value: number): number { return 0; }
|
|
159
|
+
|
|
160
|
+
// ---------------------------------------------------------------------------
|
|
161
|
+
// Shift register
|
|
162
|
+
// ---------------------------------------------------------------------------
|
|
163
|
+
|
|
164
|
+
/** Shift a byte out to a pin. */
|
|
165
|
+
export function shiftOut_(dataPin: number | string, clockPin: number | string, bitOrder: number, value: number): void {}
|
|
166
|
+
/** Shift a byte in from a pin. */
|
|
167
|
+
export function shiftIn_(dataPin: number | string, clockPin: number | string, bitOrder: number): number { return 0; }
|
|
168
|
+
|
|
169
|
+
// ---------------------------------------------------------------------------
|
|
170
|
+
// Board constant resolution
|
|
171
|
+
// ---------------------------------------------------------------------------
|
|
172
|
+
|
|
173
|
+
/** Write a value to a DAC pin. */
|
|
174
|
+
export function dacWrite(pin: number | string, value: number): void {}
|
|
175
|
+
|
|
176
|
+
// ---------------------------------------------------------------------------
|
|
177
|
+
// Watchdog timer (WDT)
|
|
178
|
+
// ---------------------------------------------------------------------------
|
|
179
|
+
|
|
180
|
+
/** Enable the watchdog timer with the given timeout (string preset or number). */
|
|
181
|
+
export function wdtEnable(timeout: string | number): void {}
|
|
182
|
+
|
|
183
|
+
/** Reset (kick) the watchdog timer. */
|
|
184
|
+
export function wdtReset(): void {}
|
|
185
|
+
|
|
186
|
+
/** Disable the watchdog timer. */
|
|
187
|
+
export function wdtDisable(): void {}
|
|
188
|
+
|
|
189
|
+
/** Resolve a board definition path to a compile-time constant. */
|
|
190
|
+
export function boardResolve(path: string): any { return undefined as any; }
|
|
191
|
+
|
|
192
|
+
// ---------------------------------------------------------------------------
|
|
193
|
+
// Power — MCU power states and clock frequency
|
|
194
|
+
// ---------------------------------------------------------------------------
|
|
195
|
+
|
|
196
|
+
/** Enter deep sleep for the given duration (ms). Architecture-aware: the
|
|
197
|
+
* strategy emits the right call per target (esp_deep_sleep on ESP32, a
|
|
198
|
+
* not-supported comment elsewhere). */
|
|
199
|
+
export function powerDeepSleep(ms: number): void {}
|
|
200
|
+
/** Enter light sleep. Architecture-aware. */
|
|
201
|
+
export function powerLightSleep(): void {}
|
|
202
|
+
/** Set the CPU frequency (MHz). */
|
|
203
|
+
export function powerSetCpuFrequency(mhz: number): void {}
|
|
204
|
+
|
|
205
|
+
// ---------------------------------------------------------------------------
|
|
206
|
+
// Raw C++ escape hatch
|
|
207
|
+
// ---------------------------------------------------------------------------
|
|
208
|
+
|
|
209
|
+
/** Emit raw C++ code (escape hatch for unsupported operations). */
|
|
210
|
+
export function rawCpp(code: string): void {}
|
package/src/fs.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { rawCpp } from './emit.js';
|
|
2
|
+
import { include } from './include.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* FSClass provides a high-level abstraction for filesystem operations.
|
|
6
|
+
* Maps to SD.h or LittleFS depending on the board configuration.
|
|
7
|
+
*/
|
|
8
|
+
export class FSClass {
|
|
9
|
+
static readonly __instance_name = "FS";
|
|
10
|
+
|
|
11
|
+
begin(): boolean {
|
|
12
|
+
include("<FS.h>");
|
|
13
|
+
rawCpp(`return FS.begin();`);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
readText(path: string): string {
|
|
18
|
+
include("<FS.h>");
|
|
19
|
+
rawCpp(`File f = FS.open(${path}.c_str(), "r");`);
|
|
20
|
+
rawCpp(`if (!f) return "";`);
|
|
21
|
+
rawCpp(`String s = f.readString();`);
|
|
22
|
+
rawCpp(`f.close();`);
|
|
23
|
+
rawCpp(`return s.c_str();`);
|
|
24
|
+
return "";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
writeText(path: string, content: string): void {
|
|
28
|
+
include("<FS.h>");
|
|
29
|
+
rawCpp(`File f = FS.open(${path}.c_str(), "w");`);
|
|
30
|
+
rawCpp(`if (f) { f.print(${content}.c_str()); f.close(); }`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
exists(path: string): boolean {
|
|
34
|
+
include("<FS.h>");
|
|
35
|
+
rawCpp(`return FS.exists(${path}.c_str());`);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
remove(path: string): boolean {
|
|
40
|
+
include("<FS.h>");
|
|
41
|
+
rawCpp(`return FS.remove(${path}.c_str());`);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const FS = new FSClass();
|