1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
//! DPR-01 Frame Scheduler — owns per-frame DSI / LTDC writes.
//!
//! Per [DPR-00 §6 INV-DPR-3][dpr00] and [DPR-01 §5.4][dpr01]: after
//! Board Runtime initialization, the four per-frame display registers
//! (`DSI_WCR`, `DSI_WIER`, `DSI_WIFCR`, `LTDC_L1CFBAR`, `LTDC_SRCR`)
//! MUST be written only by the [`FrameScheduler`]. This module
//! introduces the types; the call-site migration lands incrementally
//! under DPR-01a per [`DPR-01-A.md`][dpr01a] §4.
//!
//! This is **scaffold code** as of DPR-01 ratification: the types
//! compile and self-test, but no consumer routes through them yet.
//! `Stm32h747iDiscoDisplay::{swap, present, wait_frame_done}` migrate
//! under DPR-01a; `freertos_entry` writers migrate under DPR-01b.
//!
//! ## Sealed traits
//!
//! Both [`ScanMode`] and [`Pacing`] are sealed. Extending either is a
//! Standards-Action change per DPR-00 §5.1 / §5.2 — new impls require
//! a §15 amendment with first-app and second-app impact analysis.
//!
//! [dpr00]: https://github.com/softoboros/rlvgl/blob/main/docs/concepts/DPR-00-CONCEPTS.md
//! [dpr01]: https://github.com/softoboros/rlvgl/blob/main/docs/concepts/DPR-01-CONCEPTS.md
//! [dpr01a]: https://github.com/softoboros/rlvgl/blob/main/docs/concepts/DPR-01-A.md
use PhantomData;
use ;
use cratePhysAddr;
use crate;
use crateDsiWrapper;
use crateLtdc;
pub
// ── Module-level typed singletons ───────────────────────────────────────
//
// Mirrors the [`crate::dsi_cmd_mode`] precedent (its lines 33..36
// declare parallel `DSI_HOST`, `DSI_W`, `LTDC_PERIPH`, `GPIOJ`
// singletons). DPR-01-A-migration-outline.md Step 1 promotes the
// pattern into `frame_scheduler` so the bare-metal DSI ERIF ISR has a
// typed-handle path into `WIFCR` without taking a `&FrameScheduler`
// reference at ISR-context.
//
// SAFETY (shared by both statics): the bare-metal demo and the Zephyr
// demo are mutually exclusive at build time via cargo features
// (`feature = "freertos"` / `feature = "zephyr"` vs. the bare-metal
// default), so at most one binary's set of singletons is reachable in
// a given build. `dsi_cmd_mode`'s parallel statics remain live for
// the Zephyr path (DPR-01b scope); `frame_scheduler`'s land for
// bare-metal (DPR-01a scope). After `Stm32h747iDiscoDisplay::new`
// returns, MMIO ownership of the DSI wrapper + LTDC block is held by
// this module (and the by-value scheduler held by the display); no
// other code path may construct its own `DsiWrapper` / `Ltdc` handle.
/// Module-level typed handle on the DSI wrapper. Used by
/// [`consume_erif_static`] and (transitively) by the per-binary
/// [`FrameScheduler`]'s by-value handle.
pub static DSI_W: DsiWrapper = unsafe ;
/// Module-level typed handle on the LTDC peripheral. Pairs with
/// [`DSI_W`] for the same SAFETY contract — see the module comment
/// immediately above.
///
/// Currently `dead_code` — first consumer lands in DPR-01a Step 4
/// (Op A swap migration), which retargets
/// `Stm32h747iDiscoDisplay::swap` through `LTDC.layer1().cfbar` +
/// `LTDC.regs().srcr`. Remove the allow when Step 4 commits.
pub static LTDC: Ltdc = unsafe ;
/// ISR-context shim: clear `DSI_WIFCR.CERIF` via the typed singleton.
///
/// Called from the bare-metal `#[interrupt] fn DSI()` body to
/// acknowledge an ERIF edge before the main loop's
/// [`Pacing::wait_erif`] consumes the wake. Matches Op C in
/// `DPR-01-A.md` §3.
///
/// # Safety
///
/// MUST be called from the DSI ISR or with DSI interrupts masked.
/// Concurrent calls from multiple contexts race the wrapper's
/// internal flag-latch; the wrapper hardware does not provide
/// atomic clear-and-readback semantics.
pub unsafe
// ── ScanMode ────────────────────────────────────────────────────────────
/// Scan-mode axis decomposition per DPR-00 §5.1.
///
/// Two named presets — [`AdaptedCommand`] and [`VideoMode`] — inhabit
/// this trait. Each carries const-generic axis values that drive the
/// per-frame writer specialization in [`FrameScheduler::present`].
/// Adapted-command scan mode — LTDCEN pulsed per frame, TE GPIO armed,
/// optional holdoff timer phases present writes after the ERIF edge.
///
/// This is the demo's current mode for both bare-metal and FreeRTOS
/// builds. The FreeRTOS variant additionally configures a TIM7 one-pulse
/// holdoff (32 ms by default) via [`Holdoff::FixedDelay`].
/// Video-mode scan — LTDC scans continuously, TE GPIO unused, shadow
/// reload via `SRCR.IMR` retargets the framebuffer at the next frame
/// boundary without disturbing the running scan.
///
/// This is the disco-analyzer's current mode (CM7+CM4 dual-core
/// builds). DPR-01 publishes the type; DPR-03 ratifies analyzer
/// adoption via DAA-01-B-2 §15.
// ── Holdoff ─────────────────────────────────────────────────────────────
/// Holdoff policy — how long to wait after the ERIF edge before
/// committing the present writes.
///
/// `BareMetalLoopPacing` uses `None`; `FreeRtosPacing` uses
/// `FixedDelay { us: 32_000 }` by default per the demo's existing
/// `freertos_entry.rs` TIM7 configuration.
// ── ErifInfo ────────────────────────────────────────────────────────────
/// Snapshot captured by the DSI ERIF ISR, consumed by pacing impls.
///
/// `cyccnt` carries the DWT cycle counter at the ERIF edge for holdoff
/// math; `erif_count` is a monotonic counter for telemetry and missed-
/// frame detection.
// ── Pacing ──────────────────────────────────────────────────────────────
/// OS-axis dispatch per DPR-00 §5.2 — selects between bare-metal-loop,
/// FreeRTOS, and Zephyr backends. Each impl owns its own synchronization
/// primitives (atomic flag / semaphore / k_sem); the trait is the seam
/// the FrameScheduler uses to remain OS-agnostic on the hot path.
/// Static ERIF signal triple consumed by [`BareMetalLoopPacing`] per
/// PCDN-DPR-006 (resolved 2026-05-19).
///
/// Three `&'static` references to typed ISR primitives from
/// [`crate::hwcore::isr`]: a one-bit flag for the wake edge, an
/// atomic for the DWT cycle snapshot, and a counter for the
/// monotonic event index. The bare-metal demo's `#[interrupt] fn
/// DSI()` body stores the cycle snapshot, bumps the counter, and
/// sets the flag; [`Pacing::wait_erif`] consumes them.
///
/// `Copy` so a single triple constructed at boot can be embedded in
/// multiple consumers (e.g. logging hooks) without cloning the
/// `&'static` references.
/// Bare-metal pacing — `IsrFlag` + `IsrCounter` + `AtomicU32`-based
/// ERIF signaling per PCDN-DPR-006.
///
/// Two constructors:
///
/// - [`Self::new`] — scaffold-only, no signal triple wired. Used by
/// host unit tests and by callers that just want the pacing type to
/// compile in isolation. [`Pacing::wait_erif`] returns a stub
/// ([`ErifInfo`] with `cyccnt: 0` and a wrapping counter) — does NOT
/// block.
/// - [`Self::with_signals`] — production constructor. Caller supplies
/// the three `&'static` references; [`Pacing::wait_erif`] busy-spins
/// on the flag and returns a real [`ErifInfo`] snapshot.
///
/// DPR-01a Step 6 wires the bare-metal demo's `#[interrupt] fn DSI()`
/// to the matching `static IsrFlag` / `AtomicU32` / `IsrCounter`
/// declarations in `examples/stm32h747i-disco/src/main.rs` and
/// constructs the pacing via `with_signals`.
// ── FrameScheduler ──────────────────────────────────────────────────────
/// Per-frame display register owner, generic over scan mode and pacing.
///
/// Holds the typed [`DsiWrapper`] and [`Ltdc`] handles. Every per-frame
/// write to `DSI_WCR`, `DSI_WIER`, `DSI_WIFCR`, `LTDC_L1CFBAR`, and
/// `LTDC_SRCR` is expected to flow through methods on this type
/// (DPR-01a / DPR-01b migration).
///
/// The scheduler does not own init-time writes — `Stm32h747iDiscoDisplay::new`
/// continues to program LTDC/DSI registers at boot. Per DPR-00 §6
/// INV-DPR-3, scheduler ownership begins *after* Board Runtime
/// initialization.
// ── Tests ───────────────────────────────────────────────────────────────