@typecad/framework-arduino 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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +192 -0
  3. package/dist/arduino/i2c-arduino.d.ts +47 -0
  4. package/dist/arduino/i2c-arduino.js +6 -0
  5. package/dist/arduino/index.d.ts +6 -0
  6. package/dist/arduino/index.js +8 -0
  7. package/dist/arduino/spi-arduino.d.ts +42 -0
  8. package/dist/arduino/spi-arduino.js +6 -0
  9. package/dist/arduino/stubs-uno.d.ts +9 -0
  10. package/dist/arduino/stubs-uno.js +65 -0
  11. package/dist/arduino/uart-arduino.d.ts +41 -0
  12. package/dist/arduino/uart-arduino.js +6 -0
  13. package/dist/arduino-class-map.d.ts +5 -0
  14. package/dist/arduino-class-map.js +21 -0
  15. package/dist/arduino-compile.d.ts +24 -0
  16. package/dist/arduino-compile.js +316 -0
  17. package/dist/arduino-libs.d.ts +6 -0
  18. package/dist/arduino-libs.js +11 -0
  19. package/dist/cli-metadata.d.ts +12 -0
  20. package/dist/cli-metadata.js +196 -0
  21. package/dist/cpp-parser.d.ts +47 -0
  22. package/dist/cpp-parser.js +292 -0
  23. package/dist/debug-codegen.d.ts +20 -0
  24. package/dist/debug-codegen.js +115 -0
  25. package/dist/displays/ili9341-spi.d.ts +6 -0
  26. package/dist/displays/ili9341-spi.js +28 -0
  27. package/dist/displays/ssd1309-i2c.d.ts +2 -0
  28. package/dist/displays/ssd1309-i2c.js +16 -0
  29. package/dist/displays/st7796-spi.d.ts +2 -0
  30. package/dist/displays/st7796-spi.js +20 -0
  31. package/dist/graphics/ili9341.d.ts +24 -0
  32. package/dist/graphics/ili9341.js +59 -0
  33. package/dist/index.d.ts +13 -0
  34. package/dist/index.js +27 -0
  35. package/dist/lib-declaration.d.ts +35 -0
  36. package/dist/lib-declaration.js +399 -0
  37. package/dist/lib-discovery.d.ts +38 -0
  38. package/dist/lib-discovery.js +189 -0
  39. package/dist/profile.d.ts +8 -0
  40. package/dist/profile.js +584 -0
  41. package/dist/strategy.d.ts +174 -0
  42. package/dist/strategy.js +2032 -0
  43. package/package.json +73 -0
  44. package/src/arduino/i2c-arduino.ts +72 -0
  45. package/src/arduino/index.ts +18 -0
  46. package/src/arduino/spi-arduino.ts +63 -0
  47. package/src/arduino/stubs-uno.ts +80 -0
  48. package/src/arduino/uart-arduino.ts +59 -0
  49. package/src/arduino-class-map.ts +32 -0
  50. package/src/arduino-compile.ts +359 -0
  51. package/src/arduino-libs.ts +33 -0
  52. package/src/cli-metadata.ts +250 -0
  53. package/src/cpp-parser.ts +361 -0
  54. package/src/debug-codegen.ts +155 -0
  55. package/src/displays/ili9341-spi.ts +33 -0
  56. package/src/displays/ssd1309-i2c.ts +19 -0
  57. package/src/displays/st7796-spi.ts +23 -0
  58. package/src/graphics/ili9341.ts +80 -0
  59. package/src/index.ts +37 -0
  60. package/src/lib-declaration.ts +493 -0
  61. package/src/lib-discovery.ts +267 -0
  62. package/src/profile.ts +676 -0
  63. package/src/strategy.ts +2126 -0
@@ -0,0 +1,174 @@
1
+ import type { PlatformStrategy, ExpressionIR, ProgramIR, Diagnostic, PlatformContext, BoardConstants, RuntimePolyfillIR, StdLibSupport, AsyncRuntimeConfig, GraphicsCapacity, DisplayHALOp } from "@typecad/cuttlefish/api/shared";
2
+ import type { HALOpIR } from "@typecad/cuttlefish/api/shared";
3
+ /**
4
+ * Arduino-specific platform context.
5
+ * Accessed via `PlatformContext` index signature: `arduinoCtx(ctx)`.
6
+ */
7
+ export interface ArduinoPlatformContext {
8
+ buildTarget?: string;
9
+ }
10
+ export declare class ArduinoStrategy implements PlatformStrategy {
11
+ readonly id = "arduino";
12
+ private _cachedProfile;
13
+ private _cachedProfileKey;
14
+ /** Architecture extracted from FQBN, used for ISR attribute emission. */
15
+ private _cachedArch;
16
+ /** Track whether the current program uses createPinGroup() */
17
+ private _usesPinGroup;
18
+ /**
19
+ * Allows the emitter to inform this strategy which enums have large values
20
+ * so that static_cast uses `long` instead of `int`.
21
+ */
22
+ setLargeEnumNames(names: ReadonlySet<string>): void;
23
+ /**
24
+ * Clears the cached profile. Should be called between transpilations.
25
+ */
26
+ clearProfileCache(): void;
27
+ /**
28
+ * Gets or resolves the Arduino profile, caching the result.
29
+ */
30
+ private getOrResolveProfile;
31
+ forcedIncludes(program: ProgramIR, ctx?: PlatformContext): string[];
32
+ symbolAliases(program: ProgramIR, ctx?: PlatformContext): Record<string, string>;
33
+ shimLines(program: ProgramIR, ctx?: PlatformContext): string[];
34
+ profileDiagnostics(program: ProgramIR, ctx?: PlatformContext): Diagnostic[];
35
+ /**
36
+ * Default implementation returns empty set.
37
+ * Board packages can override to provide native implementations.
38
+ */
39
+ nativePolyfills(): Set<string>;
40
+ /**
41
+ * Generate native helpers: cuttlefish_halt macro, Arduino string helpers,
42
+ * and (when stdlib supports it) the cooperative async Promise runtime.
43
+ */
44
+ generateNativePolyfills(program: ProgramIR, ctx?: PlatformContext): RuntimePolyfillIR[];
45
+ /**
46
+ * Injects Serial.begin(baudRate) at the top of setup() when the program uses
47
+ * console.* calls and has a baudRate configured, and no explicit .begin() call
48
+ * is already present.
49
+ */
50
+ setupInitCode(program: ProgramIR, ctx?: PlatformContext): string[];
51
+ sourceExtension(isEntryFile: boolean, isNpmPackage: boolean): string;
52
+ entrypointFunctionName(): string;
53
+ requiresLoopFunction(): boolean;
54
+ overrideBaseName(originalBaseName: string, outDirBaseName: string, isEntryFile: boolean, isNpmPackage: boolean): string;
55
+ effectiveEmitMode(_requestedMode: string, isNpmPackage: boolean): string;
56
+ defaultNumericType(): string;
57
+ normalizeCppType(typeName: string): string;
58
+ mapReturnType(functionName: string, returnType: string): string;
59
+ isStringLikeType(cppType: string): boolean;
60
+ isPointerType(cppType: string): boolean;
61
+ mapFunctionName(originalName: string): string;
62
+ currentTimeMillis(): string;
63
+ normalizeRawExpression(value: string): string;
64
+ nullValue(): string;
65
+ wrapStringConcat(leftRendered: string, rightRendered: string, leftIsString: boolean): string | undefined;
66
+ wrapStringObject(value: string): string;
67
+ useSnprintfForStrings(): boolean;
68
+ floatToSnprintfArg(renderedExpr: string, precision: number | undefined, tempId: number): {
69
+ format: string;
70
+ arg: string;
71
+ estimatedLength: number;
72
+ preludeLines: string[];
73
+ } | undefined;
74
+ renameEnumMember(_enumName: string, memberName: string): string;
75
+ enumCastType(enumName: string): string | undefined;
76
+ private static readonly _passthroughEnumNames;
77
+ passthroughEnumNames(): ReadonlySet<string>;
78
+ renderBoardDefinitionAccess(chain: string[], boardConstants?: BoardConstants): string | undefined;
79
+ mapPeripheralIdentifier(name: string): string | undefined;
80
+ resolvePinType(objectName: string, fieldName: string): string | undefined;
81
+ renderThrow(_valueExpr: string): string;
82
+ isConsoleCall(callee: string): boolean;
83
+ transformConsoleCall(method: string, renderedArgs: string, forHeader: boolean): string;
84
+ transformConsoleExpression(_method: string, _renderedArgs: string): string | undefined;
85
+ objectFieldInitializer(fieldValue: ExpressionIR, _renderExpr: (e: ExpressionIR) => string): string | undefined;
86
+ overrideClassFieldType(fieldName: string, normalizedType: string): string;
87
+ renderSerialPrintWithSnprintf(params: {
88
+ receiver: string;
89
+ method: string;
90
+ bufferName: string;
91
+ }): {
92
+ finalLine: string;
93
+ } | undefined;
94
+ forwardDeclarationExclusions(): string[];
95
+ ambientTypeDeclarations(): string[];
96
+ reservedNames(): ReadonlySet<string>;
97
+ passthroughMacroNames(): ReadonlySet<string>;
98
+ apiReservedEnumNames(): ReadonlySet<string>;
99
+ apiReservedEnumGuard(): string;
100
+ isHeapAllocationUnsafe(architecture: string): boolean;
101
+ isExceptionSupportDisabled(architecture: string): boolean;
102
+ needsIostream(): boolean;
103
+ needsStdString(): boolean;
104
+ needsStdVector(): boolean;
105
+ needsStdExcept(): boolean;
106
+ needsStdFunction(): boolean;
107
+ mathHeader(): string;
108
+ cstringHeader(): string;
109
+ needsVectorOverload(): boolean;
110
+ needsLargeEnumUnderlying(): boolean;
111
+ renameStructField(fieldName: string): string;
112
+ structFieldInitializer(fieldValue: ExpressionIR, compiletimeVarNames: Set<string>, _renderExpr: (e: ExpressionIR) => string): string | undefined;
113
+ getAsyncRuntimeConfig(): AsyncRuntimeConfig;
114
+ asyncLoopInjection(taskVarNames: string[], config: AsyncRuntimeConfig): string[];
115
+ asyncLoopInjection(taskVarNames: string[], hasPromiseRuntime: boolean, hasTimers: boolean): string[];
116
+ asyncDriverFunctionName(): string;
117
+ /**
118
+ * On ESP32 (Xtensa LX6/LX7), ISR functions must be placed in IRAM so they
119
+ * can execute while the SPI flash cache is busy. Other architectures don't
120
+ * need this attribute.
121
+ */
122
+ isrFunctionAttribute(): string;
123
+ shouldSkipTypeAlias(cppType: string): boolean;
124
+ emitDiagnostics(_emitMode: string): Diagnostic[];
125
+ isrUnsafeOperations(): Map<string, {
126
+ reason: string;
127
+ severity: 'warning' | 'info';
128
+ }>;
129
+ asyncQueueCapacity(): number;
130
+ outputSubdirectory(baseName: string): string;
131
+ generateHeaderFile(): boolean;
132
+ enumApiGuard(_enumName: string): {
133
+ open: string;
134
+ close: string;
135
+ } | undefined;
136
+ private static readonly STDLIB_SUPPORT;
137
+ getStdLibSupport(architecture?: string): StdLibSupport;
138
+ private static readonly DEFAULT_STDLIB;
139
+ generateDebugInitCode(): string[];
140
+ generateDebugBreakpointCode(params: {
141
+ fileName: string;
142
+ lineNum: number;
143
+ originalLine: string;
144
+ variables: Array<{
145
+ name: string;
146
+ isFunction?: boolean;
147
+ }>;
148
+ normalizedCondition?: string;
149
+ }): string[];
150
+ generateDebugLogpointCode(params: {
151
+ fileName: string;
152
+ lineNum: number;
153
+ parts: Array<{
154
+ type: 'text' | 'variable';
155
+ value: string;
156
+ }>;
157
+ variables: Array<{
158
+ name: string;
159
+ isFunction?: boolean;
160
+ }>;
161
+ }): string[];
162
+ resolveHALOperation(op: HALOpIR): {
163
+ code?: string;
164
+ expression?: string;
165
+ } | undefined;
166
+ private _displayCtx;
167
+ resolveDisplayOp(op: DisplayHALOp): {
168
+ code?: string;
169
+ expression?: string;
170
+ } | undefined;
171
+ supportedDisplayDrivers(): ReadonlySet<string>;
172
+ colorFormat(): "rgb565" | "mono";
173
+ graphicsCapacity(): GraphicsCapacity;
174
+ }