driverge-mcp 0.0.0 → 0.0.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/README.md +275 -29
- package/dist/codegen/esp32.d.ts +11 -3
- package/dist/codegen/esp32.js +221 -10
- package/dist/codegen/esp32.js.map +1 -1
- package/dist/codegen/ident.d.ts +24 -2
- package/dist/codegen/ident.js +37 -4
- package/dist/codegen/ident.js.map +1 -1
- package/dist/codegen/index.d.ts +12 -7
- package/dist/codegen/index.js +17 -14
- package/dist/codegen/index.js.map +1 -1
- package/dist/codegen/lint.js +28 -8
- package/dist/codegen/lint.js.map +1 -1
- package/dist/codegen/portable-cpp.d.ts +8 -0
- package/dist/codegen/portable-cpp.js +281 -0
- package/dist/codegen/portable-cpp.js.map +1 -0
- package/dist/codegen/portable.d.ts +99 -3
- package/dist/codegen/portable.js +419 -99
- package/dist/codegen/portable.js.map +1 -1
- package/dist/codegen/stm32.d.ts +11 -3
- package/dist/codegen/stm32.js +156 -11
- package/dist/codegen/stm32.js.map +1 -1
- package/dist/codegen/types.d.ts +32 -0
- package/dist/codegen/types.js +27 -0
- package/dist/codegen/types.js.map +1 -1
- package/dist/mcp/cache.d.ts +15 -2
- package/dist/mcp/cache.js +32 -4
- package/dist/mcp/cache.js.map +1 -1
- package/dist/mcp/register.d.ts +17 -0
- package/dist/mcp/register.js +149 -21
- package/dist/mcp/register.js.map +1 -1
- package/dist/mcp/summary.js +8 -0
- package/dist/mcp/summary.js.map +1 -1
- package/dist/pdf/address.d.ts +4 -0
- package/dist/pdf/address.js +28 -0
- package/dist/pdf/address.js.map +1 -0
- package/dist/pdf/command.js +87 -14
- package/dist/pdf/command.js.map +1 -1
- package/dist/pdf/extract.js +23 -2
- package/dist/pdf/extract.js.map +1 -1
- package/dist/pdf/generic-register-table.d.ts +5 -0
- package/dist/pdf/generic-register-table.js +125 -0
- package/dist/pdf/generic-register-table.js.map +1 -0
- package/dist/pdf/index.d.ts +2 -0
- package/dist/pdf/index.js +2 -0
- package/dist/pdf/index.js.map +1 -1
- package/dist/pdf/interface-kind.d.ts +11 -0
- package/dist/pdf/interface-kind.js +18 -0
- package/dist/pdf/interface-kind.js.map +1 -1
- package/dist/pdf/manufacturer.js +39 -0
- package/dist/pdf/manufacturer.js.map +1 -1
- package/dist/pdf/maxim-register-map.d.ts +11 -0
- package/dist/pdf/maxim-register-map.js +544 -0
- package/dist/pdf/maxim-register-map.js.map +1 -0
- package/dist/pdf/part.js +8 -0
- package/dist/pdf/part.js.map +1 -1
- package/dist/pdf/prose-commands.d.ts +4 -0
- package/dist/pdf/prose-commands.js +90 -0
- package/dist/pdf/prose-commands.js.map +1 -0
- package/dist/pdf/st-bit-layout.d.ts +3 -0
- package/dist/pdf/st-bit-layout.js +238 -0
- package/dist/pdf/st-bit-layout.js.map +1 -0
- package/dist/pdf/ti-field-descriptions.d.ts +10 -0
- package/dist/pdf/ti-field-descriptions.js +87 -0
- package/dist/pdf/ti-field-descriptions.js.map +1 -0
- package/dist/pdf/ti-register-map.d.ts +5 -0
- package/dist/pdf/ti-register-map.js +84 -0
- package/dist/pdf/ti-register-map.js.map +1 -0
- package/dist/pdf/types.d.ts +15 -3
- package/dist/pdf/types.js +4 -1
- package/dist/pdf/types.js.map +1 -1
- package/dist/schema/assemble.d.ts +35 -3
- package/dist/schema/assemble.js +86 -13
- package/dist/schema/assemble.js.map +1 -1
- package/dist/schema/types.d.ts +21 -1
- package/dist/schema/validate.js +37 -10
- package/dist/schema/validate.js.map +1 -1
- package/dist/server.d.ts +18 -0
- package/dist/server.js +49 -3
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
- package/schemas/datasheet.schema.json +17 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esp32.js","sourceRoot":"","sources":["../../src/codegen/esp32.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,kFAAkF;AAClF,sEAAsE;AACtE,gFAAgF;AAChF,+EAA+E;AAC/E,
|
|
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M,cAAc,GAClB,GAAG,KAAK,KAAK;QACX,CAAC,CAAC,uGAAuG,IAAI,wKAAwK;QACrR,CAAC,CAAC,GAAG,KAAK,MAAM;YACd,CAAC,CAAC,uMAAuM,IAAI,iDAAiD;YAC9P,CAAC,CAAC,GAAG,KAAK,KAAK;gBACb,CAAC,CAAC,yPAAyP,IAAI,6CAA6C;gBAC5S,CAAC,CAAC,wGAAwG,IAAI,+DAA+D,MAAM,4BAA4B,CAAC;IAExN,OAAO;QACL,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC;QAC3B,aAAa,EAAE;YACb,GAAG,IAAI,CAAC,aAAa;YACrB,cAAc;SACf;KACF,CAAC;AACJ,CAAC"}
|
package/dist/codegen/ident.d.ts
CHANGED
|
@@ -3,8 +3,30 @@ export declare const HEX_ONLY: RegExp;
|
|
|
3
3
|
export declare function slug(part: string): string;
|
|
4
4
|
/** UPPER token safe for a macro fragment. */
|
|
5
5
|
export declare function macro(s: string): string;
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Mask for a [msb:lsb] field within a `regWidth`-bit register. Computed
|
|
8
|
+
* arithmetically so it is correct up to 32 bits (no 32-bit shift overflow); for
|
|
9
|
+
* valid 8-bit fields it equals the historical `& 0xff` result (e.g. 7:5 → 0xE0).
|
|
10
|
+
*/
|
|
11
|
+
export declare function fieldMask(msb: number, lsb: number, regWidth?: number): number;
|
|
8
12
|
export declare function hex2(n: number): string;
|
|
13
|
+
/** Hex literal padded to a register width's digit count (8→2, 16→4, 32→8). */
|
|
14
|
+
export declare function maskHex(n: number, regWidth?: number): string;
|
|
15
|
+
/**
|
|
16
|
+
* Neutralizes C block-comment delimiters in free text lifted verbatim from a
|
|
17
|
+
* parsed datasheet (e.g. `metadata.manufacturer`, a `Register.name`) before it
|
|
18
|
+
* is embedded inside a generated `/* ... *\/` block comment. Without this, text
|
|
19
|
+
* containing `*\/` closes the enclosing comment early and whatever follows
|
|
20
|
+
* becomes live, uncommented source — a comment-escape injection (B2). Splits
|
|
21
|
+
* both delimiters ("* /" and "/ *") so the string can neither close an
|
|
22
|
+
* existing comment nor open a bogus one; still reads fine as prose either way.
|
|
23
|
+
*/
|
|
24
|
+
export declare function commentSafe(s: string): string;
|
|
9
25
|
/** Macro prefix for a part, e.g. "BME280". */
|
|
10
26
|
export declare function prefixOf(part: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* PascalCase a lower-snake slug for a C++ class name, e.g. "bme280" -> "Bme280",
|
|
29
|
+
* "tmag5170" -> "Tmag5170". Used only by the cpp codegen flavor (Session D); the
|
|
30
|
+
* C flavor has no class, so this never touches C output.
|
|
31
|
+
*/
|
|
32
|
+
export declare function pascalCase(s: string): string;
|
package/dist/codegen/ident.js
CHANGED
|
@@ -16,16 +16,49 @@ export function macro(s) {
|
|
|
16
16
|
.replace(/[^A-Z0-9]+/g, "_")
|
|
17
17
|
.replace(/^_+|_+$/g, "");
|
|
18
18
|
}
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Mask for a [msb:lsb] field within a `regWidth`-bit register. Computed
|
|
21
|
+
* arithmetically so it is correct up to 32 bits (no 32-bit shift overflow); for
|
|
22
|
+
* valid 8-bit fields it equals the historical `& 0xff` result (e.g. 7:5 → 0xE0).
|
|
23
|
+
*/
|
|
24
|
+
export function fieldMask(msb, lsb, regWidth = 8) {
|
|
25
|
+
const bits = msb - lsb + 1;
|
|
26
|
+
const mask = (2 ** bits - 1) * 2 ** lsb;
|
|
27
|
+
return mask % 2 ** regWidth;
|
|
23
28
|
}
|
|
24
29
|
export function hex2(n) {
|
|
25
30
|
return `0x${n.toString(16).toUpperCase().padStart(2, "0")}`;
|
|
26
31
|
}
|
|
32
|
+
/** Hex literal padded to a register width's digit count (8→2, 16→4, 32→8). */
|
|
33
|
+
export function maskHex(n, regWidth = 8) {
|
|
34
|
+
return `0x${n.toString(16).toUpperCase().padStart(regWidth / 4, "0")}`;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Neutralizes C block-comment delimiters in free text lifted verbatim from a
|
|
38
|
+
* parsed datasheet (e.g. `metadata.manufacturer`, a `Register.name`) before it
|
|
39
|
+
* is embedded inside a generated `/* ... *\/` block comment. Without this, text
|
|
40
|
+
* containing `*\/` closes the enclosing comment early and whatever follows
|
|
41
|
+
* becomes live, uncommented source — a comment-escape injection (B2). Splits
|
|
42
|
+
* both delimiters ("* /" and "/ *") so the string can neither close an
|
|
43
|
+
* existing comment nor open a bogus one; still reads fine as prose either way.
|
|
44
|
+
*/
|
|
45
|
+
export function commentSafe(s) {
|
|
46
|
+
return s.replace(/\*\//g, "* /").replace(/\/\*/g, "/ *");
|
|
47
|
+
}
|
|
27
48
|
/** Macro prefix for a part, e.g. "BME280". */
|
|
28
49
|
export function prefixOf(part) {
|
|
29
50
|
return macro(slug(part));
|
|
30
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* PascalCase a lower-snake slug for a C++ class name, e.g. "bme280" -> "Bme280",
|
|
54
|
+
* "tmag5170" -> "Tmag5170". Used only by the cpp codegen flavor (Session D); the
|
|
55
|
+
* C flavor has no class, so this never touches C output.
|
|
56
|
+
*/
|
|
57
|
+
export function pascalCase(s) {
|
|
58
|
+
return s
|
|
59
|
+
.split("_")
|
|
60
|
+
.filter(Boolean)
|
|
61
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
62
|
+
.join("");
|
|
63
|
+
}
|
|
31
64
|
//# sourceMappingURL=ident.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ident.js","sourceRoot":"","sources":["../../src/codegen/ident.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,uEAAuE;AAEvE,MAAM,CAAC,MAAM,QAAQ,GAAG,gBAAgB,CAAC;AAEzC,8EAA8E;AAC9E,MAAM,UAAU,IAAI,CAAC,IAAY;IAC/B,MAAM,CAAC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IAAI,QAAQ,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,CAAS;IAC5B,OAAO,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;AAC9D,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,OAAO,CAAC,CAAS,EAAE,QAAQ,GAAG,CAAC;IAC7C,OAAO,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,QAAQ,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;AACzE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,CAAS;IACnC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAC3D,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,CAAS;IAClC,OAAO,CAAC;SACL,KAAK,CAAC,GAAG,CAAC;SACV,MAAM,CAAC,OAAO,CAAC;SACf,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SAC3D,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC"}
|
package/dist/codegen/index.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import type { DatasheetJson } from "../schema/types.js";
|
|
2
|
-
import type { CodegenTarget, DriverArtifact } from "./types.js";
|
|
2
|
+
import type { CodegenLanguage, CodegenTarget, DriverArtifact } from "./types.js";
|
|
3
3
|
export * from "./types.js";
|
|
4
4
|
export { generatePortableDriver } from "./portable.js";
|
|
5
|
+
export { generatePortableCppDriver } from "./portable-cpp.js";
|
|
5
6
|
export { generateEsp32Driver } from "./esp32.js";
|
|
6
7
|
export { generateStm32Driver } from "./stm32.js";
|
|
7
8
|
export { lintDriver } from "./lint.js";
|
|
8
9
|
export { slug, prefixOf } from "./ident.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
export interface GenerateDriverOptions {
|
|
11
|
+
/** Output language flavor; "c" (default) is byte-identical to pre-Session-D
|
|
12
|
+
* output, "cpp" renders a class wrapper — see CodegenLanguage. */
|
|
13
|
+
language?: CodegenLanguage;
|
|
13
14
|
}
|
|
14
|
-
/**
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Render a driver for a target, dispatching to the right generator/language.
|
|
17
|
+
* `opts` is optional and additive — omitted, `{}`, and `{ language: "c" }` all
|
|
18
|
+
* produce today's byte-identical C output (Session D: cpp language option).
|
|
19
|
+
*/
|
|
20
|
+
export declare function generateDriver(json: DatasheetJson, target: CodegenTarget, opts?: GenerateDriverOptions): DriverArtifact;
|
package/dist/codegen/index.js
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
// Public surface of the codegen layer.
|
|
2
2
|
import { generateEsp32Driver } from "./esp32.js";
|
|
3
|
+
import { generatePortableCppDriver } from "./portable-cpp.js";
|
|
3
4
|
import { generatePortableDriver } from "./portable.js";
|
|
4
5
|
import { generateStm32Driver } from "./stm32.js";
|
|
6
|
+
import { UnsupportedTargetError } from "./types.js";
|
|
7
|
+
// UnsupportedTargetError and UnsupportedBusError live in ./types.js (cycle-free:
|
|
8
|
+
// esp32.js/stm32.js import UnsupportedBusError from there too, and this module
|
|
9
|
+
// imports esp32.js/stm32.js) — re-exported here for the public codegen surface.
|
|
5
10
|
export * from "./types.js";
|
|
6
11
|
export { generatePortableDriver } from "./portable.js";
|
|
12
|
+
export { generatePortableCppDriver } from "./portable-cpp.js";
|
|
7
13
|
export { generateEsp32Driver } from "./esp32.js";
|
|
8
14
|
export { generateStm32Driver } from "./stm32.js";
|
|
9
15
|
export { lintDriver } from "./lint.js";
|
|
10
16
|
export { slug, prefixOf } from "./ident.js";
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Render a driver for a target, dispatching to the right generator/language.
|
|
19
|
+
* `opts` is optional and additive — omitted, `{}`, and `{ language: "c" }` all
|
|
20
|
+
* produce today's byte-identical C output (Session D: cpp language option).
|
|
21
|
+
*/
|
|
22
|
+
export function generateDriver(json, target, opts = {}) {
|
|
23
|
+
const language = opts.language ?? "c";
|
|
24
|
+
if (target === "portable") {
|
|
25
|
+
return language === "cpp" ? generatePortableCppDriver(json) : generatePortableDriver(json);
|
|
18
26
|
}
|
|
19
|
-
}
|
|
20
|
-
/** Render a driver for a target, dispatching to the right generator. */
|
|
21
|
-
export function generateDriver(json, target) {
|
|
22
|
-
if (target === "portable")
|
|
23
|
-
return generatePortableDriver(json);
|
|
24
27
|
if (target === "esp32")
|
|
25
|
-
return generateEsp32Driver(json);
|
|
28
|
+
return generateEsp32Driver(json, { language });
|
|
26
29
|
if (target === "stm32")
|
|
27
|
-
return generateStm32Driver(json);
|
|
30
|
+
return generateStm32Driver(json, { language });
|
|
28
31
|
throw new UnsupportedTargetError(target);
|
|
29
32
|
}
|
|
30
33
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/codegen/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AAGvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,mBAAmB,E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mBAAmB,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;IACvE,MAAM,IAAI,sBAAsB,CAAC,MAAM,CAAC,CAAC;AAC3C,CAAC"}
|
package/dist/codegen/lint.js
CHANGED
|
@@ -3,17 +3,27 @@
|
|
|
3
3
|
// skeleton: it confirms the host AI finished its work (no leftover TODOs), stayed
|
|
4
4
|
// on the thin-HAL seam, didn't hallucinate registers/commands, and didn't corrupt
|
|
5
5
|
// the deterministic bit-field masks. Pure/text-based — no compiler needed.
|
|
6
|
-
import {
|
|
6
|
+
import { registerWidth } from "../pdf/types.js";
|
|
7
|
+
import { fieldMask, macro, maskHex, prefixOf } from "./ident.js";
|
|
7
8
|
// Vendor peripheral APIs that must NEVER appear in a portable/thin-HAL driver —
|
|
8
9
|
// all bus access goes through the hal_* seam instead.
|
|
9
10
|
const FORBIDDEN = [
|
|
10
11
|
{ re: /\bHAL_(?:I2C|SPI|UART)_\w+/, api: "STM32 CubeHAL" },
|
|
11
12
|
{ re: /\bLL_(?:I2C|SPI)_\w+/, api: "STM32 LL" },
|
|
12
|
-
{
|
|
13
|
+
{
|
|
14
|
+
re: /\bi2c_master_\w+|\bspi_device_\w+|\bi2c_cmd_\w+|\buart_write_bytes\w*|\buart_read_bytes\w*|\btwai_\w+/,
|
|
15
|
+
api: "ESP-IDF",
|
|
16
|
+
},
|
|
13
17
|
{ re: /\bWire\.\w+|\bSPI\.(?:transfer|begin)\w*/, api: "Arduino" },
|
|
14
18
|
];
|
|
15
|
-
// Allowed thin-HAL seam functions (families).
|
|
16
|
-
|
|
19
|
+
// Allowed thin-HAL seam functions (families). SPI is a single combined
|
|
20
|
+
// hal_spi_transfer(tx, tx_len, rx, rx_len) — one call per CS-framed transaction —
|
|
21
|
+
// not a hal_spi_write/hal_spi_read pair; those are retired and must lint as
|
|
22
|
+
// unknown HAL functions (see decisions: thin-hal-non-negotiable). UART
|
|
23
|
+
// (Session B) adds hal_uart_write/hal_uart_read; CAN (Session C) adds the
|
|
24
|
+
// single combined hal_can_transfer — any other hal_uart_*/hal_can_* name (e.g.
|
|
25
|
+
// a hypothetical hal_uart_flush or hal_can_filter) must still lint as unknown.
|
|
26
|
+
const HAL_ALLOWED = /^hal_(?:i2c_(?:read|write)|spi_transfer|uart_(?:write|read)|can_transfer|delay_ms)$/;
|
|
17
27
|
function balanced(text, open, close) {
|
|
18
28
|
let depth = 0;
|
|
19
29
|
for (const ch of text) {
|
|
@@ -34,7 +44,16 @@ export function lintDriver(files, json) {
|
|
|
34
44
|
const prefix = prefixOf(json.metadata.part);
|
|
35
45
|
const all = files.map((f) => `/* ${f.path} */\n${f.content}`).join("\n\n");
|
|
36
46
|
// Comments carry the TODO markers and prose; strip them before code-shape checks.
|
|
37
|
-
|
|
47
|
+
// String/char literal BODIES are stripped too (after comments) so a stray brace
|
|
48
|
+
// or paren inside "..." or '...' never throws off the balance check — and, as a
|
|
49
|
+
// side effect, keeps the forbidden-API/hal_*/reference scans from matching text
|
|
50
|
+
// that only appears inside a literal. `all` (TODO detection, #define scans) stays
|
|
51
|
+
// unstripped on purpose.
|
|
52
|
+
const strip = (s) => s
|
|
53
|
+
.replace(/\/\*[\s\S]*?\*\//g, " ")
|
|
54
|
+
.replace(/\/\/[^\n]*/g, " ")
|
|
55
|
+
.replace(/"(?:\\.|[^"\\])*"/g, " ")
|
|
56
|
+
.replace(/'(?:\\.|[^'\\])*'/g, " ");
|
|
38
57
|
const code = strip(all);
|
|
39
58
|
// Thin-HAL purity applies to the driver CORE, not the seam implementation:
|
|
40
59
|
// a native target's <part>_hal_<target>.c is *where* platform calls belong.
|
|
@@ -57,7 +76,7 @@ export function lintDriver(files, json) {
|
|
|
57
76
|
}
|
|
58
77
|
for (const m of coreCode.matchAll(/\bhal_[a-z0-9_]+/g)) {
|
|
59
78
|
if (!HAL_ALLOWED.test(m[0])) {
|
|
60
|
-
errors.push(`unknown HAL function "${m[0]}" — thin HAL is hal_i2c_*/hal_spi_*/hal_delay_ms only`);
|
|
79
|
+
errors.push(`unknown HAL function "${m[0]}" — thin HAL is hal_i2c_*/hal_spi_*/hal_uart_*/hal_can_transfer/hal_delay_ms only`);
|
|
61
80
|
}
|
|
62
81
|
}
|
|
63
82
|
// 4. Register/command reference existence: any PREFIX_REG_* / PREFIX_CMD_* used
|
|
@@ -84,14 +103,15 @@ export function lintDriver(files, json) {
|
|
|
84
103
|
}
|
|
85
104
|
function checkMasks(registers, prefix, text, errors) {
|
|
86
105
|
for (const r of registers) {
|
|
106
|
+
const width = registerWidth(r);
|
|
87
107
|
for (const f of r.bitFields) {
|
|
88
108
|
const base = `${prefix}_${macro(r.name)}_${macro(f.name)}`;
|
|
89
109
|
const maskDef = new RegExp(`#define\\s+${base}_MASK\\s+(0x[0-9a-fA-F]+)`).exec(text);
|
|
90
110
|
if (maskDef) {
|
|
91
111
|
const got = Number.parseInt(maskDef[1], 16);
|
|
92
|
-
const want = fieldMask(f.msb, f.lsb);
|
|
112
|
+
const want = fieldMask(f.msb, f.lsb, width);
|
|
93
113
|
if (got !== want) {
|
|
94
|
-
errors.push(`${base}_MASK is ${maskDef[1]} but ${r.name}.${f.name} [${f.msb}:${f.lsb}] implies ${
|
|
114
|
+
errors.push(`${base}_MASK is ${maskDef[1]} but ${r.name}.${f.name} [${f.msb}:${f.lsb}] implies ${maskHex(want, width)}`);
|
|
95
115
|
}
|
|
96
116
|
}
|
|
97
117
|
const shiftDef = new RegExp(`#define\\s+${base}_SHIFT\\s+(\\d+)`).exec(text);
|
package/dist/codegen/lint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lint.js","sourceRoot":"","sources":["../../src/codegen/lint.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2EAA2E;AAC3E,kFAAkF;AAClF,kFAAkF;AAClF,2EAA2E;
|
|
1
|
+
{"version":3,"file":"lint.js","sourceRoot":"","sources":["../../src/codegen/lint.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2EAA2E;A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AAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC1F,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DatasheetJson } from "../schema/types.js";
|
|
2
|
+
import type { DriverArtifact } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Render the portable thin-HAL driver skeleton, cpp flavor: same dispatch rule
|
|
5
|
+
* as generatePortableDriver (register_map-first fallback), just calling the
|
|
6
|
+
* class-wrapper renderers above.
|
|
7
|
+
*/
|
|
8
|
+
export declare function generatePortableCppDriver(json: DatasheetJson): DriverArtifact;
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
// Portable thin-HAL codegen — "cpp" language flavor (Session D). Renders a
|
|
2
|
+
// CLASS WRAPPER around the exact same #define macro constants and thin-HAL
|
|
3
|
+
// seam as generatePortableDriver's C output: the same register_map/command_set
|
|
4
|
+
// constants, TODO(driverge) markers, and fill_in_brief keys, just shaped as a
|
|
5
|
+
// class (<slug>.hpp/.cpp) instead of a struct + free functions (<slug>.h/.c).
|
|
6
|
+
//
|
|
7
|
+
// Deliberately reuses portable.ts's pure #define/TODO/seam-declaration builders
|
|
8
|
+
// (registerConstants, bitFieldMacros, registerMapTodo, commandSetTodo, BUS_SEAM
|
|
9
|
+
// decl, uartFramingBody/canFramingBody, registerBrief/commandBrief) instead of
|
|
10
|
+
// re-deriving them, so the two language flavors can never drift on the
|
|
11
|
+
// macro/seam contract that validate_driver and the native _hal_<target>.c seam
|
|
12
|
+
// files depend on — see wiki: thin-hal-non-negotiable, json-schema-as-contract.
|
|
13
|
+
//
|
|
14
|
+
// What genuinely differs (and is NOT shared) is the struct-vs-class /
|
|
15
|
+
// free-function-vs-method shape: the driver handle's address state becomes a
|
|
16
|
+
// private class member, and register_map's read_register(dev, reg, *value)
|
|
17
|
+
// becomes a method readRegister(reg, uint8_t &value) with no dev pointer to
|
|
18
|
+
// null-check.
|
|
19
|
+
import { registerWidth } from "../pdf/types.js";
|
|
20
|
+
import { commentSafe, macro, pascalCase, slug } from "./ident.js";
|
|
21
|
+
import { AUTOGEN, BUS_SEAM, COMMAND_INIT_TODO, I2C_COMMAND_FRAME_NOTE, bitFieldMacros, canFramingBody, commandBrief, commandReadDataTodo, commandSetTodo, crc8Body, makeFiles, registerBrief, registerConstants, registerInitTodo, registerMapTodo, registerMapTodoText, seamBusFor, uartFramingBody, } from "./portable.js";
|
|
22
|
+
const CPP_EXT = { header: "hpp", source: "cpp" };
|
|
23
|
+
/** extern "C" wrapper note — explains why the seam stays linkable from a
|
|
24
|
+
* native target's `_hal_<target>.c` seam file (compiled as C) even though the
|
|
25
|
+
* core here is C++. */
|
|
26
|
+
const EXTERN_C_NOTE = [
|
|
27
|
+
'/* Thin-HAL seam — implement these for your platform (see thin-hal). Wrapped',
|
|
28
|
+
' * in extern "C" so the class methods below link against a plain-C',
|
|
29
|
+
' * implementation — including the native _hal_<target>.c seam file Driverge',
|
|
30
|
+
" * attaches for esp32/stm32 targets, which is compiled as C, unchanged. */",
|
|
31
|
+
];
|
|
32
|
+
function cppBusSeam(busKind, prefix) {
|
|
33
|
+
if (busKind === "I2C") {
|
|
34
|
+
return {
|
|
35
|
+
member: [" uint8_t i2c_addr_;"],
|
|
36
|
+
initMember: [` i2c_addr_ = ${prefix}_I2C_ADDR;`],
|
|
37
|
+
readBody: [" hal_i2c_read(i2c_addr_, reg, &value, 1);", " return 0;"],
|
|
38
|
+
writeBody: [" hal_i2c_write(i2c_addr_, reg, &value, 1);", " return 0;"],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (busKind === "SPI") {
|
|
42
|
+
return {
|
|
43
|
+
member: [],
|
|
44
|
+
initMember: [],
|
|
45
|
+
readBody: [" hal_spi_transfer(®, 1, &value, 1);", " return 0;"],
|
|
46
|
+
writeBody: [
|
|
47
|
+
" uint8_t frame[2];",
|
|
48
|
+
" frame[0] = reg;",
|
|
49
|
+
" frame[1] = value;",
|
|
50
|
+
" hal_spi_transfer(frame, 2, nullptr, 0);",
|
|
51
|
+
" return 0;",
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (busKind === "UART") {
|
|
56
|
+
return {
|
|
57
|
+
member: [],
|
|
58
|
+
initMember: [],
|
|
59
|
+
readBody: uartFramingBody(["reg", "value"]),
|
|
60
|
+
writeBody: uartFramingBody(["reg", "value"]),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
member: [],
|
|
65
|
+
initMember: [],
|
|
66
|
+
readBody: canFramingBody(["reg", "value"]),
|
|
67
|
+
writeBody: canFramingBody(["reg", "value"]),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
// register_map
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
function registerDriverCpp(json, registers, name, prefix) {
|
|
74
|
+
const busKind = seamBusFor(json.protocol.bus);
|
|
75
|
+
const spi = busKind === "SPI";
|
|
76
|
+
const uart = busKind === "UART";
|
|
77
|
+
const can = busKind === "CAN";
|
|
78
|
+
const seam = BUS_SEAM[busKind];
|
|
79
|
+
const cppSeam = cppBusSeam(busKind, prefix);
|
|
80
|
+
const addr = json.protocol.addresses?.[0];
|
|
81
|
+
const guard = `${prefix}_HPP`;
|
|
82
|
+
const className = pascalCase(name);
|
|
83
|
+
const hpp = [
|
|
84
|
+
AUTOGEN(json.metadata.part || name, json.metadata.manufacturer, spi
|
|
85
|
+
? "Bus: SPI"
|
|
86
|
+
: uart
|
|
87
|
+
? "Bus: UART"
|
|
88
|
+
: can
|
|
89
|
+
? "Bus: CAN"
|
|
90
|
+
: `Bus: I2C, address ${addr ?? "(unknown — see TODO)"}`),
|
|
91
|
+
"",
|
|
92
|
+
`#ifndef ${guard}`,
|
|
93
|
+
`#define ${guard}`,
|
|
94
|
+
"",
|
|
95
|
+
"#include <cstdint>",
|
|
96
|
+
"",
|
|
97
|
+
];
|
|
98
|
+
if (!spi && !uart && !can) {
|
|
99
|
+
if (addr) {
|
|
100
|
+
hpp.push("/* I2C device address. */", `#define ${prefix}_I2C_ADDR ${addr}`, "");
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
hpp.push("/* TODO(driverge): set the I2C device address (not found in the datasheet parse). */", `#define ${prefix}_I2C_ADDR 0x00`, "");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const regLines = registerConstants(prefix, registers);
|
|
107
|
+
const hasRegs = regLines.some((l) => l.startsWith("#define"));
|
|
108
|
+
hpp.push(...(hasRegs ? regLines : registerMapTodo(prefix, json.extraction?.detectedPages ?? [])));
|
|
109
|
+
if (registers.some((r) => registerWidth(r) > 8)) {
|
|
110
|
+
hpp.push("", "/* NOTE: some registers here are wider than 8 bits (see the per-register", " * annotations). Bit-field masks are register-width correct; multi-byte access", " * framing (byte order / transfer size) is device-specific and belongs on the", " * hal_* seam. */");
|
|
111
|
+
}
|
|
112
|
+
const bits = bitFieldMacros(prefix, registers);
|
|
113
|
+
if (bits.length > 0)
|
|
114
|
+
hpp.push("", "/* Bit-field mask/shift accessors. */", ...bits);
|
|
115
|
+
hpp.push("", ...EXTERN_C_NOTE, 'extern "C" {', ...seam.decl, "void hal_delay_ms (uint32_t ms);", "}", "", `class ${className} {`, "public:", " int init();", " int readRegister(uint8_t reg, uint8_t &value);", " int writeRegister(uint8_t reg, uint8_t value);");
|
|
116
|
+
if (cppSeam.member.length > 0) {
|
|
117
|
+
hpp.push("", "private:", ...cppSeam.member);
|
|
118
|
+
}
|
|
119
|
+
hpp.push("};", "", `#endif /* ${guard} */`, "");
|
|
120
|
+
const cpp = [
|
|
121
|
+
`#include "${name}.hpp"`,
|
|
122
|
+
"",
|
|
123
|
+
`int ${className}::init() {`,
|
|
124
|
+
...cppSeam.initMember,
|
|
125
|
+
...registerInitTodo(uart, can, "writeRegister()"),
|
|
126
|
+
" return 0;",
|
|
127
|
+
"}",
|
|
128
|
+
"",
|
|
129
|
+
`int ${className}::readRegister(uint8_t reg, uint8_t &value) {`,
|
|
130
|
+
...cppSeam.readBody,
|
|
131
|
+
"}",
|
|
132
|
+
"",
|
|
133
|
+
`int ${className}::writeRegister(uint8_t reg, uint8_t value) {`,
|
|
134
|
+
...cppSeam.writeBody,
|
|
135
|
+
"}",
|
|
136
|
+
"",
|
|
137
|
+
];
|
|
138
|
+
const brief = registerBrief(json, {
|
|
139
|
+
init: "init",
|
|
140
|
+
readRegister: "readRegister",
|
|
141
|
+
writeRegister: "writeRegister",
|
|
142
|
+
});
|
|
143
|
+
if (!hasRegs) {
|
|
144
|
+
brief.register_map_todo = registerMapTodoText(json, name, prefix);
|
|
145
|
+
}
|
|
146
|
+
return { files: makeFiles(name, hpp, cpp, CPP_EXT), fill_in_brief: brief };
|
|
147
|
+
}
|
|
148
|
+
// ---------------------------------------------------------------------------
|
|
149
|
+
// command_set
|
|
150
|
+
// ---------------------------------------------------------------------------
|
|
151
|
+
function commandDriverCpp(json, commands, name, prefix) {
|
|
152
|
+
const uart = json.protocol.bus === "UART";
|
|
153
|
+
const can = json.protocol.bus === "CAN";
|
|
154
|
+
const noAddrBus = uart || can;
|
|
155
|
+
const addr = json.protocol.addresses?.[0];
|
|
156
|
+
const crc = commands.find((c) => c.crc)?.crc;
|
|
157
|
+
const guard = `${prefix}_HPP`;
|
|
158
|
+
const className = pascalCase(name);
|
|
159
|
+
const hpp = [
|
|
160
|
+
AUTOGEN(json.metadata.part || name, json.metadata.manufacturer, uart
|
|
161
|
+
? "Bus: UART · command-set device"
|
|
162
|
+
: can
|
|
163
|
+
? "Bus: CAN · command-set device"
|
|
164
|
+
: `Bus: I2C, address ${addr ?? "(unknown — see TODO)"} · command-set device`),
|
|
165
|
+
"",
|
|
166
|
+
`#ifndef ${guard}`,
|
|
167
|
+
`#define ${guard}`,
|
|
168
|
+
"",
|
|
169
|
+
"#include <cstdint>",
|
|
170
|
+
"",
|
|
171
|
+
];
|
|
172
|
+
if (noAddrBus) {
|
|
173
|
+
// No bus device address on UART/CAN — see fill_in_brief.framing_todo.
|
|
174
|
+
}
|
|
175
|
+
else if (addr) {
|
|
176
|
+
hpp.push("/* I2C device address. */", `#define ${prefix}_I2C_ADDR ${addr}`, "");
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
hpp.push("/* TODO(driverge): set the I2C device address. */", `#define ${prefix}_I2C_ADDR 0x00`, "");
|
|
180
|
+
}
|
|
181
|
+
if (commands.length === 0) {
|
|
182
|
+
hpp.push(...commandSetTodo(prefix, json.extraction?.detectedPages ?? []));
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
hpp.push("/* Command codes. */");
|
|
186
|
+
const seen = new Set();
|
|
187
|
+
for (const c of commands) {
|
|
188
|
+
const macroName = `${prefix}_CMD_${macro(c.name)}`;
|
|
189
|
+
if (seen.has(macroName))
|
|
190
|
+
continue;
|
|
191
|
+
seen.add(macroName);
|
|
192
|
+
const line = `#define ${macroName} ${c.code.toUpperCase().replace("0X", "0x")}`;
|
|
193
|
+
// See the C flavor's identical comment in portable.ts commandDriver — c.params
|
|
194
|
+
// is defensively commentSafe'd even though today's only producer is hex-safe.
|
|
195
|
+
hpp.push(c.params && c.params.length > 0
|
|
196
|
+
? `${line} /* params: ${commentSafe(c.params.join(", "))} */`
|
|
197
|
+
: line);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (crc) {
|
|
201
|
+
hpp.push("", `/* CRC-${crc.width} checksum parameters. */`, `#define ${prefix}_CRC_POLY ${crc.poly}`, `#define ${prefix}_CRC_INIT ${crc.init}`);
|
|
202
|
+
}
|
|
203
|
+
hpp.push("", ...EXTERN_C_NOTE, 'extern "C" {', ...(uart
|
|
204
|
+
? BUS_SEAM.UART.decl
|
|
205
|
+
: can
|
|
206
|
+
? BUS_SEAM.CAN.decl
|
|
207
|
+
: [
|
|
208
|
+
"void hal_i2c_write(uint8_t addr, uint8_t reg, uint8_t *data, uint16_t len);",
|
|
209
|
+
"void hal_i2c_read (uint8_t addr, uint8_t reg, uint8_t *data, uint16_t len);",
|
|
210
|
+
]), "void hal_delay_ms (uint32_t ms);", "}", "", `class ${className} {`, "public:", " int init();", " int sendCommand(uint16_t command);", " int readData(uint8_t *buffer, uint16_t len);", ...(crc ? [" uint8_t crc8(const uint8_t *data, uint16_t len);"] : []));
|
|
211
|
+
if (!noAddrBus) {
|
|
212
|
+
hpp.push("", "private:", " uint8_t i2c_addr_;");
|
|
213
|
+
}
|
|
214
|
+
hpp.push("};", "", `#endif /* ${guard} */`, "");
|
|
215
|
+
const cpp = [
|
|
216
|
+
`#include "${name}.hpp"`,
|
|
217
|
+
"",
|
|
218
|
+
`int ${className}::init() {`,
|
|
219
|
+
...(noAddrBus ? [] : [` i2c_addr_ = ${prefix}_I2C_ADDR;`]),
|
|
220
|
+
...COMMAND_INIT_TODO,
|
|
221
|
+
" return 0;",
|
|
222
|
+
"}",
|
|
223
|
+
"",
|
|
224
|
+
`int ${className}::sendCommand(uint16_t command) {`,
|
|
225
|
+
...(uart
|
|
226
|
+
? uartFramingBody(["command"])
|
|
227
|
+
: can
|
|
228
|
+
? canFramingBody(["command"])
|
|
229
|
+
: [
|
|
230
|
+
" uint8_t msb;",
|
|
231
|
+
" uint8_t lsb;",
|
|
232
|
+
" msb = (uint8_t)(command >> 8);",
|
|
233
|
+
" lsb = (uint8_t)(command & 0xFF);",
|
|
234
|
+
...I2C_COMMAND_FRAME_NOTE,
|
|
235
|
+
" hal_i2c_write(i2c_addr_, msb, &lsb, 1);",
|
|
236
|
+
" return 0;",
|
|
237
|
+
]),
|
|
238
|
+
"}",
|
|
239
|
+
"",
|
|
240
|
+
`int ${className}::readData(uint8_t *buffer, uint16_t len) {`,
|
|
241
|
+
...(uart
|
|
242
|
+
? uartFramingBody(["buffer", "len"])
|
|
243
|
+
: can
|
|
244
|
+
? canFramingBody(["buffer", "len"])
|
|
245
|
+
: [
|
|
246
|
+
" if (buffer == nullptr) {",
|
|
247
|
+
" return -1;",
|
|
248
|
+
" }",
|
|
249
|
+
...commandReadDataTodo("crc8"),
|
|
250
|
+
" (void)buffer;",
|
|
251
|
+
" (void)len;",
|
|
252
|
+
" return 0;",
|
|
253
|
+
]),
|
|
254
|
+
"}",
|
|
255
|
+
"",
|
|
256
|
+
];
|
|
257
|
+
if (crc) {
|
|
258
|
+
cpp.push(...crc8Body(`${className}::crc8`, crc, prefix));
|
|
259
|
+
}
|
|
260
|
+
const brief = commandBrief(json, commands, crc, uart, can, name, prefix, {
|
|
261
|
+
sendCommand: "sendCommand",
|
|
262
|
+
readData: "readData",
|
|
263
|
+
crc8: "crc8",
|
|
264
|
+
});
|
|
265
|
+
return { files: makeFiles(name, hpp, cpp, CPP_EXT), fill_in_brief: brief };
|
|
266
|
+
}
|
|
267
|
+
// ---------------------------------------------------------------------------
|
|
268
|
+
/**
|
|
269
|
+
* Render the portable thin-HAL driver skeleton, cpp flavor: same dispatch rule
|
|
270
|
+
* as generatePortableDriver (register_map-first fallback), just calling the
|
|
271
|
+
* class-wrapper renderers above.
|
|
272
|
+
*/
|
|
273
|
+
export function generatePortableCppDriver(json) {
|
|
274
|
+
const part = json.metadata.part;
|
|
275
|
+
const name = slug(part);
|
|
276
|
+
const prefix = macro(name);
|
|
277
|
+
return json.interface.kind === "command_set"
|
|
278
|
+
? commandDriverCpp(json, json.interface.commands, name, prefix)
|
|
279
|
+
: registerDriverCpp(json, json.interface.registers, name, prefix);
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=portable-cpp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portable-cpp.js","sourceRoot":"","sources":["../../src/codegen/portable-cpp.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2EAA2E;AAC3E,+EAA+E;AAC/E,8EAA8E;AAC9E,8EAA8E;AAC9E,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF,+EAA+E;AAC/E,uEAAuE;AACvE,+EAA+E;AAC/E,gFAAgF;AAChF,EAAE;AACF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