struct2ui 0.7.0__tar.gz → 0.9.0__tar.gz

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 (57) hide show
  1. {struct2ui-0.7.0/src/struct2ui.egg-info → struct2ui-0.9.0}/PKG-INFO +338 -51
  2. {struct2ui-0.7.0 → struct2ui-0.9.0}/README.md +794 -507
  3. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/__init__.py +1 -1
  4. struct2ui-0.9.0/src/struct2ui/compare.py +300 -0
  5. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/editor.py +937 -82
  6. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/exporters/bin_emitter.py +69 -10
  7. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/exporters/bin_reader.py +27 -7
  8. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/exporters/c_emitter.py +90 -32
  9. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/exporters/elf_verifier.py +21 -10
  10. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/schema.py +634 -59
  11. struct2ui-0.9.0/src/struct2ui/ui/__init__.py +19 -0
  12. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/ui/renderers.py +25 -166
  13. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/ui/tables.py +2 -2
  14. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/ui/widgets.py +52 -20
  15. {struct2ui-0.7.0 → struct2ui-0.9.0/src/struct2ui.egg-info}/PKG-INFO +338 -51
  16. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui.egg-info/SOURCES.txt +3 -0
  17. struct2ui-0.9.0/tests/test_bin_emitter.py +168 -0
  18. struct2ui-0.9.0/tests/test_c_emitter.py +299 -0
  19. {struct2ui-0.7.0 → struct2ui-0.9.0}/tests/test_choices.py +23 -1
  20. struct2ui-0.9.0/tests/test_compare.py +539 -0
  21. {struct2ui-0.7.0 → struct2ui-0.9.0}/tests/test_container_verify.py +84 -7
  22. {struct2ui-0.7.0 → struct2ui-0.9.0}/tests/test_elf_verifier.py +6 -5
  23. struct2ui-0.9.0/tests/test_groups.py +569 -0
  24. struct2ui-0.9.0/tests/test_load_report.py +360 -0
  25. {struct2ui-0.7.0 → struct2ui-0.9.0}/tests/test_macro_bounds.py +25 -0
  26. {struct2ui-0.7.0 → struct2ui-0.9.0}/tests/test_save.py +40 -1
  27. {struct2ui-0.7.0 → struct2ui-0.9.0}/tests/test_union.py +7 -7
  28. {struct2ui-0.7.0 → struct2ui-0.9.0}/tests/test_value_readback.py +1 -1
  29. struct2ui-0.7.0/src/struct2ui/ui/__init__.py +0 -36
  30. struct2ui-0.7.0/tests/test_bin_emitter.py +0 -71
  31. struct2ui-0.7.0/tests/test_c_emitter.py +0 -144
  32. struct2ui-0.7.0/tests/test_load_report.py +0 -140
  33. {struct2ui-0.7.0 → struct2ui-0.9.0}/LICENSE +0 -0
  34. {struct2ui-0.7.0 → struct2ui-0.9.0}/pyproject.toml +0 -0
  35. {struct2ui-0.7.0 → struct2ui-0.9.0}/setup.cfg +0 -0
  36. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/exporters/__init__.py +0 -0
  37. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/exporters/c_parser.py +0 -0
  38. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/exporters/json_format.py +0 -0
  39. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/icons/c2j.png +0 -0
  40. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/icons/elf.png +0 -0
  41. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/icons/export_notes_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  42. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/icons/flowchart_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  43. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/icons/refresh_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  44. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/icons/report_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  45. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/icons/save_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  46. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/icons/save_as_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  47. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/icons/settings_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  48. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui/icons/widgets_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  49. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui.egg-info/dependency_links.txt +0 -0
  50. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui.egg-info/requires.txt +0 -0
  51. {struct2ui-0.7.0 → struct2ui-0.9.0}/src/struct2ui.egg-info/top_level.txt +0 -0
  52. {struct2ui-0.7.0 → struct2ui-0.9.0}/tests/test_bin_reader.py +0 -0
  53. {struct2ui-0.7.0 → struct2ui-0.9.0}/tests/test_c_parser.py +0 -0
  54. {struct2ui-0.7.0 → struct2ui-0.9.0}/tests/test_editor.py +0 -0
  55. {struct2ui-0.7.0 → struct2ui-0.9.0}/tests/test_float_precision.py +0 -0
  56. {struct2ui-0.7.0 → struct2ui-0.9.0}/tests/test_int_checkbox.py +0 -0
  57. {struct2ui-0.7.0 → struct2ui-0.9.0}/tests/test_json_format.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: struct2ui
3
- Version: 0.7.0
3
+ Version: 0.9.0
4
4
  Summary: Render C struct / JSON schema as editable PySide6 UI, export to C/JSON/bin
5
5
  Author-email: Jay <huoyj0108@163.com>
6
6
  License: MIT License
@@ -61,9 +61,13 @@ Render C structs / JSON schemas as an **editable PySide6 UI**, and convert freel
61
61
  - **Embeddable**: `StructEditor` is a plain `QWidget` that drops into any PySide6 / PyQt UI.
62
62
  - **Multi-format export**: edited results export to C source, JSON, or binary; C source can also be parsed back into a schema.
63
63
  - **Read bin back**: `import_bin` loads a raw `.bin` (e.g. read back from the chip) into the UI — the byte-for-byte inverse of the binary export.
64
+ - **Compare with a chip dump**: `compare_with_bin()` diffs the current UI parameters against a `.bin` dumped from the chip — byte-level first, then field-level with float tolerance. Differences show in the Report panel with control highlighting, Apply / Undo, and a per-file-array "Save to file..." export.
64
65
  - **Validation**: keyword spell-checking (with “Did you mean X?” hints), semantic audits (`min<=max`, `step>0`), and pipeline cross-validation.
65
66
  - **ELF layout check**: optionally verify each module — and the whole pipeline against its SDK container struct — against a compiled ELF's DWARF layout, catching offset/size drift and wrong stage order.
66
- - **Pipeline note sources**: a pipeline file can pin its own Modules / ELF paths (`note` → `"Modules"` / `"ELF"`) — picking one file switches the whole setup, while the UI-picked paths keep the highest priority.
67
+ - **Pipeline note sources**: a pipeline file can pin its own Modules / ELF paths (`note` → `"Modules"` / `"ELF"`) — picking one file switches the whole setup; re-checking a Settings row hands that slot back to the UI-picked path.
68
+ - **Stage groups**: nest stages under a UI group (`"RX": {"EQ": {...}}`) for a two-level strip — one button per group, a second strip for its stages.
69
+ - **Macro-gated stages**: a `defines` table plus per-stage `ifdef` / `ifndef` selects which `#ifdef`-guarded modules the current form has; one pipeline file per macro set.
70
+ - **Field splitting**: one struct spread across adjacent stages with `fields` / `exclude` — each stage shows its own field subset, while export still writes a single complete section.
67
71
  - **Qt-binding agnostic**: built on [Qt.py](https://github.com/mottosso/Qt.py) — works with PySide6 / PyQt6 / PySide2 / PyQt5.
68
72
 
69
73
  ## Installation
@@ -105,8 +109,10 @@ app.exec_()
105
109
 
106
110
  This is the core of the library: you describe your C types in JSON and the UI is
107
111
  generated from it. Files live in the **modules directory** (`cfg_dir`), one
108
- `*.json` per logical group. Each file is a flat object whose keys are either
109
- **type names** (your structs / enums) or the reserved key `typedefs`.
112
+ `*.json` per logical group. Each file is a flat object whose keys are **type
113
+ names** (your structs / enums / unions), **`#define` constants** (a plain
114
+ number, see [count expressions](#count-expressions--multi-dimensional-arrays))
115
+ or the reserved key `typedefs`.
110
116
 
111
117
  ### File layout
112
118
 
@@ -142,7 +148,7 @@ generated from it. Files live in the **modules directory** (`cfg_dir`), one
142
148
 
143
149
  | Block type | Keys | Notes |
144
150
  | --- | --- | --- |
145
- | `struct` | `type`, `items` (list of field specs) | `items` is required |
151
+ | `struct` | `type`, `items` (list of field specs), optional `flatten` | `items` is required. `"flatten": true` marks a fake struct whose fields are loose members of the pipeline's SDK struct (see [C export](#c-export)). |
146
152
  | `enum` | `type`, `items` (object `{NAME: value}`) | reads back the enumerator name |
147
153
  | `union` | `type`, `items` (list of branch structs) | tagged union; each branch is an inline `struct` selected by its `when` (see below; a legacy `branch` key is accepted but ignored) |
148
154
  | `typedefs` | object `{alias: real_type}` | resolved before field building |
@@ -180,15 +186,23 @@ When omitted, the widget is inferred from `type` (and from `min/max`,
180
186
  | --- | --- | --- |
181
187
  | `checkbox` | int | Check box (also auto-picked when `min:0, max:1`). |
182
188
  | `toggle` | bool/int | Toggle push-button. |
183
- | `combo` | int, float, `char[N]` | Combo box; pair with `choices`. |
189
+ | `combo` | int, float, `char[N]` | Combo box over `choices` (required, unless the type is an enum). |
184
190
  | `slider` | int | Slider with min/max labels (requires `min` & `max`). |
185
191
  | `dial` | int | Rotary dial popup (requires `min` & `max`). |
186
- | `file` | array | Path label + Browse button; loads array values from a text file. |
192
+ | `file` | array | Path label + Browse button; array values load from a text file and are emitted into the exported `.bin` / `.c`. |
187
193
  | `multiline` | array | Single-line shell that pops up a multi-line editor. |
188
194
  | `table` | struct array | Express grid-layout intent (one column per struct member; a union member expands the branch inferred from the pipeline rows into columns — see the union section below). |
195
+ | `tree` | struct array | Tree layout (one item per element); forces a tree even when the automatic rule below would pick a table. |
189
196
 
190
197
  Numeric fields without an explicit `widget` become a `QSpinBox` /
191
198
  `QDoubleSpinBox`; scalar arrays become a comma-separated line edit.
199
+ A flat struct array becomes a **table** automatically when it has at least 2
200
+ rows and at most 6 columns, and a tree otherwise. `widget: "table"` forces a
201
+ table for any flat struct array (the column limit does not apply) and
202
+ `widget: "tree"` forces a tree.
203
+
204
+ A `file` array's path may be relative; it resolves against the pipeline
205
+ file's directory first, then the process working directory.
192
206
 
193
207
  ### `choices` (discrete values)
194
208
 
@@ -208,21 +222,25 @@ of the choices.
208
222
  ### `when` (conditional enable/disable)
209
223
 
210
224
  A field can be greyed out unless other fields hold specific values. `when` is an
211
- object mapping a **sibling field name** to its required value; all entries must
212
- match (logical AND):
225
+ object mapping a **sibling field name** to a condition; all entries must
226
+ match (logical AND). A condition takes one of three forms:
213
227
 
214
228
  ```jsonc
215
- { "name": "cutoff", "type": "float", "when": { "enabled": 1, "mode": "HIGH" } }
229
+ { "enabled": 1 } // equality
230
+ { "mode": ["LOW", "HIGH"] } // membership: value is one of the list
231
+ { "level": { ">=": 0, "<=": 100 } } // operators, AND-ed together
216
232
  ```
217
233
 
218
- The dependency name is matched against the dotted leaf name in scope. When a
219
- dependency is not found, the field stays enabled.
234
+ The operators are `in`, `not in`, `=`, `!=`, `>`, `>=`, `<`, `<=`; any other
235
+ key is a load-time error. The dependency name is matched against the dotted
236
+ leaf name in scope. When a dependency is not found, the field stays enabled.
220
237
 
221
238
  ### `union` (tagged union)
222
239
 
223
240
  A `union` block declares overlapping branches, each an inline `struct` in
224
- `items`. At runtime the branch whose `when` matches is the one shown / exported
225
- (first match wins); the union's `.bin` / `.c` size is always the largest branch
241
+ `items`. At runtime the tree **shows every branch** whose `when` matches, while
242
+ export (`.bin` / `.c`), `read_bin` and table rendering use the **first**
243
+ matching branch; the union's `.bin` / `.c` size is always the largest branch
226
244
  and unmatched exports are zero-padded.
227
245
 
228
246
  ```jsonc
@@ -236,10 +254,10 @@ and unmatched exports are zero-padded.
236
254
 
237
255
  #### Union inside a table-rendered struct array
238
256
 
239
- A struct array containing a union renders as a **table** when all its rows use
240
- the same union branch. The branch is **inferred from the pipeline data** —
241
- nothing is pinned in the modules file (the legacy `branch` key is accepted but
242
- silently ignored):
257
+ A struct array containing a union renders as a **table** when the automatic
258
+ rule above holds and all its written rows use the same union branch. The branch
259
+ is **inferred from the pipeline data** — nothing is pinned in the modules file
260
+ (the legacy `branch` key is accepted but silently ignored):
243
261
 
244
262
  - **Uniform rows** → the inferred branch's members expand into columns. Two
245
263
  applications can therefore share one `FilterCoeffs` and still each get a
@@ -261,22 +279,40 @@ does not apply when the intent succeeds.
261
279
  ### `count` expressions & multi-dimensional arrays
262
280
 
263
281
  `count` may be an integer, a `#define` constant name, or an integer expression
264
- of those using `+ - * / % ()` (e.g. `MAX_BAND_NUM - 1`). A list makes a
282
+ of those using `+ - * / % ()` (e.g. `MAX_BAND_NUM - 1`). A constant is declared
283
+ as a plain number at the top level of a module file
284
+ (`"MAX_BAND_NUM": 8`); `min` / `max` / `step` accept the same names. A `count`
285
+ that resolves to nothing is a load-time error. A list makes a
265
286
  multi-dimensional array that is **stored flat** to match the C ABI:
266
287
 
267
288
  ```jsonc
268
289
  { "name": "matrix", "type": "float", "count": [3, 4] } // 12 contiguous floats, shown as [3][4]
269
290
  ```
270
291
 
271
- `char[N]` is treated as a C string by default (use `widget` to override).
292
+ `char[N]` is treated as a C string — whatever `widget` it carries, e.g.
293
+ `widget: "combo"` is a combo over string `choices`. Only `widget: "multiline"`
294
+ or `widget: "file"` turns it into a **byte array** edited as numbers (one
295
+ value per element); the C export then writes each element as a char
296
+ literal when it is printable ASCII and as `0xNN` otherwise:
297
+
298
+ ```jsonc
299
+ { "name": "magic", "type": "char", "count": 4, "widget": "multiline" } // .magic = { 0x10, 'A', 'B', 0x00 }
300
+ ```
301
+
302
+ Any other `widget` on `char[N]` (slider / dial / table / …) is a load-time
303
+ error: those editors fit neither a string nor a byte array.
272
304
 
273
305
  ### Validation
274
306
 
275
- Loading runs three layers of checks, surfaced in the **load report** panel:
307
+ Loading runs four layers of checks, surfaced in the **load report** panel:
276
308
 
277
- - **Keyword spelling** — unknown keys report "Did you mean `tip`?" style hints.
309
+ - **Keyword spelling** — unknown keys report "Did you mean `tip`?" style hints,
310
+ at every nesting level (inline struct members, union branches).
278
311
  - **Semantic audits** — `min <= max`, `step > 0`, `count > 0`, choices within
279
- bounds, default is one of the choices.
312
+ bounds, default is one of the choices. Also errors: a `count` that cannot be
313
+ resolved, an unknown `when` operator, and a `widget` that is unknown or lacks
314
+ what it needs (`slider` / `dial` without `min` & `max`, `combo` without
315
+ `choices`). Inline struct members are audited like top-level ones.
280
316
  - **Pipeline cross-validation** — values in the pipeline file are checked
281
317
  against the schema (range, choices, enum membership).
282
318
  - **Duplicate type definitions** — the same struct / enum / union defined in
@@ -294,9 +330,14 @@ tuning name) whose value is the group body:
294
330
  ```jsonc
295
331
  {
296
332
  "Speech Tuning": {
297
- "note": { "Modules": "cfg_t", "ELF": "../elf/fw.elf" }, // optional sources
333
+ "note": {
334
+ "Modules": "cfg_t", // optional sources
335
+ "ELF": "../elf/fw.elf",
336
+ "C Struct": "SpeechConfig", // optional: C export + layout check
337
+ "C Variable": "speech_cfg_default",
338
+ "C Qualifier": "const"
339
+ },
298
340
  "flow": ["RX NS", "RX DRC", "RX EQ"], // stage order, optional
299
- "container": "SpeechConfig", // optional, enables layout check
300
341
 
301
342
  "RX NS": { "type": "SpeechNs2FloatConfig", "items": { /* values */ } },
302
343
  "RX DRC": { "type": "MultiCompexpConfig" }, // 'items' may be omitted
@@ -310,9 +351,10 @@ tuning name) whose value is the group body:
310
351
  | Key | Required | Notes |
311
352
  | --- | --- | --- |
312
353
  | `flow` | no | Ordered list of stage names. The flow buttons and the export order follow it. **Omit it and the stages run in the order they appear in the JSON.** When present, every listed name must have a stage block; defined stages missing from `flow` are a warning. |
313
- | `container` | no | Name of the SDK struct that holds all modules (see [Container layout check](#container-layout-check)). Omit to disable that check. |
314
- | `note` | no | Free-form metadata dict. Two keys are special — `"Modules"` / `"ELF"` pin the pipeline's companion sources (see [Source overrides via `note`](#source-overrides-via-note)); everything else in it is ignored. |
315
- | *stage name* | — | Any other key is a **stage block**; its name is the label shown on the flow button. |
354
+ | `container` | no | **Deprecated — will be removed.** Name of the SDK struct that holds all modules. Write it as `"C Struct"` in `note` instead; until then it is still read when the note has no `"C Struct"`. |
355
+ | `defines` | no | Macro table (`name → true/false`) selecting which `#ifdef`-gated stages the current form has — see [Macro-gated stages](#macro-gated-stages-ifdef-variants). |
356
+ | `note` | no | Metadata dict. These keys are read by the tool: `"Modules"` / `"ELF"` pin the pipeline's companion sources (see [Source overrides via `note`](#source-overrides-via-note)); `"C Struct"` / `"C Variable"` / `"C Qualifier"` name the C export (see [C export](#c-export)); `"C Group Prefix"` controls member names of grouped stages (see [Stage groups](#stage-groups)). A key that looks like a misspelt one of these (`"C Varible"`) gets a "Did you mean" warning; any other key is ignored. |
357
+ | *stage name* | — | Any other key is a **stage block** (or a **stage group**, see below); its name is the label shown on the flow button. |
316
358
 
317
359
  All keys are **lowercase and case-sensitive** — write `flow`, not `Flow`. A
318
360
  mistyped key (`Flow`, `flwo`, …) is reported with a "Did you mean `flow`?" hint.
@@ -336,13 +378,15 @@ and ELF by hand:
336
378
  Both keys are optional and take absolute or **pipeline-file-relative** paths.
337
379
  Selecting the pipeline applies them in Settings:
338
380
 
339
- - The matching row's checkbox is **unchecked** — exactly as if the user had —
340
- and the note's path feeds the slot. The checkbox stays clickable and the
341
- UI-picked path is kept and still displayed, so re-checking the row switches
342
- back to it at any time.
343
- - **UI settings always win**: a checked row forces the UI-picked path no
344
- matter what the note says. The note can only take over a row the user left
345
- unchecked.
381
+ - A row whose path the note provides is **unchecked** — exactly as if the user
382
+ had — and the note's path feeds the slot. The UI-picked path is kept and
383
+ still displayed, so re-checking the row switches back to it at any time.
384
+ - From then on the checkbox is the only switch: a **checked row forces the
385
+ UI-picked path** no matter what the note says; an unchecked row takes the
386
+ note's path. One exception: values passed explicitly to the same
387
+ `set_sources()` call win over the note — a path argument (`cfg_dir=` /
388
+ `elf_file=`) checks its row, and `modules_enabled=` / `elf_enabled=` are
389
+ applied last.
346
390
  - Neither side providing Modules is a load error (with a hint to enable the
347
391
  Settings row or add a note path); neither side providing an ELF simply
348
392
  skips layout verification.
@@ -355,15 +399,205 @@ Selecting the pipeline applies them in Settings:
355
399
  | --- | --- | --- |
356
400
  | `type` | yes | A struct / union type name defined in the modules directory. |
357
401
  | `items` | no | The edited values, keyed by field name. **Omitting `items` means "all defaults"** — the stage renders from the type's declared defaults. |
358
- | `member` | no | For the container layout check: the member name inside `container` this stage maps to (defaults to the stage label). |
402
+ | `member` | no | The name of the container member this stage is exported and checked as (defaults to the stage label, see [C export](#c-export)). |
403
+ | `ifdef` / `ifndef` | no | Macro name (or list) gating the stage on the `defines` table — see [Macro-gated stages](#macro-gated-stages-ifdef-variants). |
404
+ | `fields` / `exclude` | no | Split this stage's struct across adjacent stages, each showing a subset of its direct fields — see [Field splitting](#field-splitting-one-struct-across-stages). |
405
+
406
+ ### Stage groups
407
+
408
+ Stages can be grouped one level deep for display, e.g. TX / RX chains that
409
+ each have an EQ and a DRC. A group is a block whose children are stage blocks
410
+ (no `type` / `items` of its own); it may carry its own optional `flow`:
411
+
412
+ ```jsonc
413
+ {
414
+ "Speech Tuning": {
415
+ "note": { "Modules": "cfg_t" },
416
+ "flow": ["AEC", "TX", "RX"], // top-level order: stages and groups
417
+ "AEC": { "type": "AecConfig" }, // an ungrouped stage
418
+ "TX": {
419
+ "flow": ["EQ", "DRC"], // order inside the group, optional
420
+ "EQ": { "type": "EqConfig" },
421
+ "DRC": { "type": "MultiCompexpConfig" }
422
+ },
423
+ "RX": {
424
+ "EQ": { "type": "EqConfig" },
425
+ "DRC": { "type": "MultiCompexpConfig" }
426
+ }
427
+ }
428
+ }
429
+ ```
430
+
431
+ - **UI**: the flow strip shows top-level stages and groups (`AEC | TX | RX`);
432
+ selecting a group shows its stages in a second strip (a second column when
433
+ the strip is vertical). Clicking a group returns to the stage last opened in
434
+ it. A group button is shown even when it is the only group.
435
+ - **Labels**: a grouped stage is identified by its full label `TX/EQ` — in the
436
+ Report panel, error messages and compare results. Stage names only need to
437
+ be unique within their group.
438
+ - **.bin / import / compare**: unchanged — the image is every stage in expanded
439
+ flow order (`AEC, TX/EQ, TX/DRC, RX/EQ, RX/DRC`), exactly as if the pipeline
440
+ were flat. The container layout check also uses this expanded order.
441
+ - **.c export**: member names are `TX_EQ`, `RX_EQ`, … by default (see
442
+ [C export](#c-export)). Set `"C Group Prefix": false` in `note` to drop the
443
+ group (`EQ`); a resulting name collision (e.g. `TX/EQ` and `RX/EQ` both
444
+ become `EQ`) fails the export with an error naming both stages.
445
+ - **Save** writes the document back with its nesting intact.
446
+ - **Rules** (load errors): groups nest only one level; `/` is not allowed in
447
+ stage or group names once a pipeline uses groups; `container` is only
448
+ allowed at the top level.
449
+
450
+ ### Macro-gated stages (`#ifdef` variants)
451
+
452
+ The SDK header often guards members with compile macros — some projects build
453
+ with them on, others off. A pipeline can describe **all** forms at once and
454
+ pick one with a macro table:
455
+
456
+ ```jsonc
457
+ {
458
+ "ANC Tuning": {
459
+ "defines": { "ADAPTIVE_FF_IIR": true, "SERIES_FIR": false },
460
+ "flow": ["A", "IIR", "FIR"],
461
+ "A": { "type": "AncCommonConfig" },
462
+ "IIR": { "type": "AdaFfIirConfig", "ifdef": "ADAPTIVE_FF_IIR" },
463
+ "FIR": { "type": "FirLmsConfig",
464
+ "ifdef": "ADAPTIVE_FF_IIR", "ifndef": "SERIES_FIR" }
465
+ }
466
+ }
467
+ ```
468
+
469
+ - `defines` maps macro names to `true` / `false` — the form the firmware was
470
+ built with. A stage is present when all its `ifdef` macros are `true` and
471
+ all its `ifndef` macros are `false`; it is dropped from the whole pipeline
472
+ at once (no button, no `.bin` / `.c` output, no ELF check, no flow warning),
473
+ exactly like the member the compiler left out of that build.
474
+ - `ifdef` / `ifndef` take one macro name or a list (all must hold; the two
475
+ keys AND together). An undeclared macro name is an error, not a silent
476
+ drop; a non-bool `defines` value is an error too.
477
+ - Switching form = edit `defines` in the pipeline file and Reload. The `.bin`
478
+ layout of each form matches that build of the SDK struct (fewer members,
479
+ shifted offsets), so one pipeline file per macro set is the intended unit
480
+ of reuse.
481
+
482
+ ### Field splitting (one struct across stages)
483
+
484
+ A parameter page is a *logical* group; a struct's memory is a *physical* run
485
+ of fields. When the two disagree — `debug_en` sits at the head of the
486
+ struct, the counters it governs at the tail, and both belong on one "Debug"
487
+ page — split the struct across several **adjacent stages**, each narrowing
488
+ its view of the same type:
489
+
490
+ ```jsonc
491
+ {
492
+ "Speech Tuning": {
493
+ "note": { "Modules": "cfg_t" },
494
+ "flow": ["Main", "Debug", "Meter"],
495
+ "Main": { "type": "TuningConfig", "exclude": ["debug_en", "mc_max_cnt"] },
496
+ "Debug": { "type": "TuningConfig", "fields": ["debug_en", "mc_max_cnt"] },
497
+ "Meter": { "type": "MeterConfig" }
498
+ }
499
+ }
500
+ ```
501
+
502
+ - `fields` shows only the listed **direct** members of the stage's type;
503
+ `exclude` shows all but them. The two keys are mutually exclusive. A
504
+ single narrowed stage is fine too — the fields it hides simply export
505
+ with their defaults.
506
+ - The UI keeps each stage as its own button/page showing only its view
507
+ (nested structs/arrays inside a kept field are rendered whole).
508
+ - **Export merges the run into ONE section** at the first stage's position:
509
+ the `.bin` layout, the C member and the ELF container check all see a
510
+ single complete struct, as if one stage owned it. The members' values are
511
+ unioned; import and compare-apply write decoded values back into each
512
+ member's own view.
513
+ - **Rules** (load errors): split stages of one type must sit next to each
514
+ other in the flow — they merge into one section, and non-adjacent split
515
+ stages of the same type are flagged instead of silently exporting two
516
+ structs; views must not overlap (a field belongs to one view); a name in
517
+ `fields` / `exclude` must be a direct member of the type; `items` keys
518
+ must lie inside the stage's own view — a value outside it would be
519
+ dropped the first time the UI captures that page, so it is refused up
520
+ front.
521
+ - A field **no stage in the run shows** only warns: it still exports, with
522
+ its default value.
523
+
524
+ ### C export
525
+
526
+ The whole pipeline is exported as **one struct variable** — one instance of
527
+ the SDK struct that holds all modules:
528
+
529
+ ```c
530
+ /* Auto-generated by struct2ui. Do not edit by hand. */
531
+ #include <stdbool.h>
532
+ #include <stdint.h>
533
+
534
+ const SpeechConfig speech_cfg_default = {
535
+ .tx_eq = {
536
+ .bypass = false,
537
+ ...
538
+ },
539
+ .rx_eq = {
540
+ ...
541
+ }
542
+ };
543
+ ```
544
+
545
+ | `note` key | Notes |
546
+ | --- | --- |
547
+ | `"C Struct"` | The SDK struct type. Also enables the [container layout check](#container-layout-check). |
548
+ | `"C Variable"` | The variable name. |
549
+ | `"C Qualifier"` | Free text placed before the type, verbatim: `const`, `WEAK`, `static const`, … |
550
+
551
+ - **Member names**: a stage's `member` if it has one, else its label
552
+ (`RX/EQ` → `RX_EQ`). A name collision fails the export with an error naming
553
+ both stages.
554
+ - **Missing keys**: a missing `"C Struct"` or `"C Variable"` is left blank in
555
+ the output behind a `/* TODO: set ... in the pipeline note */` comment (the
556
+ braces stay valid C) and gets a warning in the Report.
557
+ - **Loose variables** (`"flatten": true`): SDK structs often hold plain
558
+ variables between the module structs. Describe them as a module whose struct
559
+ is marked `"flatten": true`; its fields are then emitted as container
560
+ members directly, and the fake struct disappears:
561
+
562
+ ```jsonc
563
+ // cfg_t/fir_lms_misc.json
564
+ { "ANC_FF_FIR_LMS_Misc": {
565
+ "type": "struct", "flatten": true,
566
+ "items": [
567
+ { "name": "bypass", "type": "uint32_t", "value": 0 },
568
+ { "name": "gain", "type": "float", "value": 0.0 }
569
+ ] } }
570
+ ```
571
+
572
+ ```c
573
+ WEAK ANC_FF_FIR_LMS_CFG_T fir_lms_cfg = {
574
+ .bypass = 0,
575
+ .gain = 0.0,
576
+ .iir_cfg = { ... } // the next stage
577
+ };
578
+ ```
579
+
580
+ This also solves "an array of structs sits directly in the container"
581
+ (`tx_2mic_ns4_preaf[6]`): wrap the array in a fake struct with that single
582
+ member and mark it `flatten`.
583
+ - `member` has no effect on a flatten stage; its fields keep their own
584
+ names (the Report warns).
585
+ - A flatten stage needs `"C Struct"` (or `container`): the C export fails
586
+ without one.
587
+ - .bin: the whole pipeline is laid out as one C struct. Every member
588
+ (stage) starts on its own alignment, a flatten stage's loose fields get
589
+ no tail padding, and the image is `sizeof` of the struct. The container
590
+ layout check compares the loose fields one by one; the per-module check
591
+ skips the fake struct.
359
592
 
360
593
  ### Container layout check
361
594
 
362
- When `container` names an SDK struct and an ELF is loaded, the whole pipeline is
363
- laid out in `flow` order — as if each stage were a member of that container —
364
- and compared member-by-member against the struct's DWARF layout (offset, size,
365
- total size). This catches stages in the **wrong order**: if the modules are all
366
- correct but reordered, you get a single "module order is wrong" error naming the
595
+ When `"C Struct"` (or the deprecated `container`) names an SDK struct and an
596
+ ELF is loaded, the whole pipeline is laid out in `flow` order — as if each
597
+ stage were a member of that container — and compared member-by-member
598
+ against the struct's DWARF layout (member names, offset, size, total size).
599
+ This catches stages in the **wrong order**: if the modules are all correct
600
+ but reordered, you get a single "module order is wrong" error naming the
367
601
  expected order, instead of a pile of misleading offset mismatches.
368
602
 
369
603
  ## Embedding into an Existing UI
@@ -481,6 +715,48 @@ btn = editor.add_custom_button(
481
715
 
482
716
  Returns the created `QPushButton`.
483
717
 
718
+ ## Compare with a Chip Dump
719
+
720
+ `compare_with_bin()` checks the current UI parameters against a `.bin`
721
+ dumped live from the chip. The host application owns the chip communication
722
+ and the dump file; struct2ui only needs its path:
723
+
724
+ ```python
725
+ def on_compare():
726
+ dump = r"D:\logs\speech_cfg_dump.bin"
727
+ ad_read_chip_to_bin(dump) # host side: read chip, save bin
728
+ editor.compare_with_bin(dump) # result goes to the Report panel
729
+
730
+ btn = editor.add_custom_button("Compare", on_compare)
731
+ ```
732
+
733
+ The comparison runs two levels:
734
+
735
+ 1. **Byte level** — the pipeline is exported in memory and compared with the
736
+ dump; equal length + equal bytes → *identical*.
737
+ 2. **Field level** — equal length but different bytes: the dump is parsed
738
+ with `read_bin` and diffed leaf-by-leaf (floats compare within tolerance),
739
+ so encoding/padding-only differences report as *semantically identical*
740
+ while real differences show as a table (path, UI value, chip value).
741
+
742
+ Results land in the Report panel: the controls behind each difference are
743
+ highlighted with an amber glow, **Apply to UI** overwrites the form with the
744
+ chip values, and **Undo** restores the pre-apply snapshot (snapshot-based,
745
+ not bin-based — a bin round-trip would lose float precision and file paths).
746
+ File-backed arrays (`widget: "file"`) diff as a whole — one aggregated row
747
+ (`n/N elements differ`) whose **Save to file...** button writes the
748
+ chip-side values to a file of your choice: overwrite the file currently in
749
+ use (re-compare shows identical) or save a new one and re-point the UI at
750
+ it. Apply never overwrites files or the UI file paths. A file-backed array
751
+ with no file selected is not compared: when the bins differ and everything
752
+ else is equal, the report says **Match not confirmed** (naming the skipped
753
+ arrays) instead of claiming a match — select the file(s) and compare again.
754
+
755
+ `compare_with_bin` returns `True` when the comparison completed (identical /
756
+ semantically identical / match not confirmed / differences shown) and `False`
757
+ on failure (no pipeline loaded, unreadable dump, length mismatch, broken
758
+ file-array source) — failures are reported in the Report panel, never raised.
759
+
484
760
  ## Programmatic API
485
761
 
486
762
  Beyond the UI, `StructEditor` exposes methods to read state and drive exports
@@ -496,6 +772,12 @@ from code (e.g. wired to a custom button):
496
772
  | `add_custom_button(text, on_click, icon=None, checkable=False) -> QPushButton` | Add a host button to the top path bar. See [Custom Toolbar Buttons](#custom-toolbar-buttons). |
497
773
  | `export_bin(path, show_dialogs=False) -> bool` | Write the current pipeline to a `.bin` at `path` — the programmatic equivalent of clicking Export → Binary. Returns `True` when there are no ELF layout errors (or ELF verification is off), `False` otherwise. |
498
774
  | `import_bin(source, show_dialogs=False) -> bool` | Load a raw `.bin` image (e.g. read back from the chip) into the UI — the inverse of `export_bin`. `source` is a path or `bytes`. The image length must match the pipeline layout **exactly**; on any mismatch the image is rejected and the UI is left unchanged. On success it overwrites every stage's values and re-renders. |
775
+ | `compare_with_bin(dump_path) -> bool` | Diff the current UI parameters against a chip-dump `.bin` (byte level first, then per-field with float tolerance). Differences, Apply / Undo and the file-array "Save to file..." export all appear in the Report panel. Returns `True` when the comparison completed, `False` on failure (reported, not raised). See [Compare with a Chip Dump](#compare-with-a-chip-dump). |
776
+
777
+ Read-only state attributes hosts save/restore alongside the paths (there are
778
+ no public setters; change them via `set_sources()` / `set_flow_orientation()`
779
+ / the Settings panel): `elf_enabled` (bool), `modules_enabled` (bool),
780
+ `flow_orientation` (`'horizontal'` / `'vertical'`).
499
781
 
500
782
  `export_bin` verifies the ELF layout first when an ELF is selected and enabled (the file is
501
783
  still written, matching the UI flow). With `show_dialogs=True` it pops the same
@@ -526,14 +808,16 @@ The low-level export functions can be used standalone, without any UI:
526
808
  ```python
527
809
  from struct2ui.schema import SchemaRegistry
528
810
  from struct2ui.exporters import (
529
- emit_c, # sections + registry -> C source string
530
- dumps_json, # -> JSON string
531
- emit_bin, # -> binary bytes
532
- read_bin, # binary bytes -> values dict (inverse of emit_bin)
533
- merge_abi, # merge ABI info
534
- verify_sections, # verify .bin layout against an ELF
535
- parse_c_source, # C source -> parse result
536
- build_schema_dict,
811
+ emit_c, # sections + registry -> C source string
812
+ dumps_json, # -> JSON string
813
+ emit_bin, # -> binary bytes
814
+ read_bin, # binary bytes -> values dict (inverse of emit_bin)
815
+ BinReadError, # raised by read_bin on a rejected image
816
+ merge_abi, # merge ABI info
817
+ verify_sections, # verify each section's layout against an ELF
818
+ verify_container_layout, # verify the whole pipeline container against an ELF
819
+ parse_c_source, # C source -> parse result
820
+ build_schema_dict, # parse result -> modules-file style dict
537
821
  )
538
822
  ```
539
823
 
@@ -542,18 +826,21 @@ from struct2ui.exporters import (
542
826
  | Layer | Module | Responsibility |
543
827
  | --- | --- | --- |
544
828
  | Schema (pure data, no Qt) | `struct2ui.schema` | Parse `*.json` into a Field tree; spell-checking, semantic audits, pipeline cross-validation |
545
- | UI rendering | `struct2ui.ui` | `WidgetFactory`, `FormRenderer`/`TreeRenderer`, array tables, `when` conditional binding |
829
+ | UI rendering | `struct2ui.ui` | `WidgetFactory`, `TreeRenderer`, array tables, `when` conditional binding |
546
830
  | Export | `struct2ui.exporters` | C / JSON / bin export, C source reverse parsing, ELF verification |
547
831
  | Top-level widget | `struct2ui.StructEditor` | Action toolbar / content area; Settings panel for source paths; load report panel |
548
832
 
549
833
  ## Development
550
834
 
551
835
  ```bash
552
- pip install -e ".[dev]" --no-build-isolation
836
+ pip install -e ".[dev,pyside6]" --no-build-isolation # [dev] ships no Qt binding
553
837
  python -m pytest
554
838
  ```
555
839
 
556
840
  Tests live under `tests/` and drive real Qt widgets headlessly on the offscreen platform.
841
+ ELF layout tests use the small firmware fixture `tests/data/test_fw.elf` (built from the adjacent `test_fw.c`) and are skipped when `pyelftools` is missing.
842
+
843
+ Examples live under `examples/`. `examples/main.py` is a demo app (custom toolbar buttons, bin import/export, chip-dump compare) wired to `examples/speech`. `examples/abc` is the guided tour — every stage's `comment` explains the feature it shows, and each has a matching `.c` file next to its JSON; `param` and `test` are further real-world pipelines. To browse one, point `StructEditor.set_sources()` at its JSON and `cfg_t` folder.
557
844
 
558
845
  ## License
559
846