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
// Copyright 2026 Ethan Wu
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
//! Shared HAL vocabulary for Consortium chip support crates: the peripheral
//! singleton machinery, a handful of narrow traits, and NVIC helpers.
//!
//! This crate is deliberately small. It holds only what the chip HALs
//! (`consortium-hal-imx9`, `consortium-hal-stm32mp2`) and their generated code need
//! to *agree* on. Every register layout, clock tree, and driver lives in a chip HAL,
//! because that is where the differences are and a shared trait that tried to
//! abstract them would either leak or lie.
//!
//! # Peripherals are owned, not addressed
//!
//! The load-bearing idea here is that a driver takes ownership of a peripheral
//! rather than an address. [`peripherals!`] declares a chip's zero-sized singleton
//! markers and the `Peripherals` struct that hands them out **once**; a driver
//! constructor consumes the one it drives:
//!
//! ```rust,ignore
//! let p = consortium_hal_imx9::init();
//! let i2c = consortium_hal_imx9::i2c::I2c::new(p.LPI2C1, 24_000_000, 400_000);
//! ```
//!
//! Because the base address and NVIC line travel with the singleton, no driver takes
//! an MMIO pointer and no constructor is `unsafe` — the aliasing question is settled
//! by the type system instead of by a comment. `peripherals::<NAME>::steal()` is the
//! escape hatch for bring-up outside `init()`, and it carries the exclusivity
//! obligation the safe path discharges.
//!
//! Per-instance driver state hangs off the marker rather than a named `static`, so an
//! application forwards an interrupt as
//! `<hal>::i2c::on_interrupt::<peripherals::LPI2C1>()`.
//!
//! # Traits
//!
//! | Trait | Answers |
//! | ------------------- | ---------------------------------------------------- |
//! | [`Peripheral`] | What is this instance called in generated metadata? |
//! | [`ClockControl`] | Enable and reset the peripheral clock. |
//! | [`InterruptSource`] | Which interrupt line does it raise? |
//! | [`MonotonicTimer`] | Read ticks and program the next alarm. |
//!
//! [`MonotonicTimer`] is what a chip HAL's Embassy time driver is built on
//! (STM32MP2 TIM2, i.MX9 LPIT1); `consortium-cfg` emits its bring-up into the
//! generated `init()` unless `[profile] time_driver = false`.
//!
//! The [`nvic`] module adds interrupt masking for lines known only at runtime, which
//! typed PAC `Interrupt` enums cannot express. The [`timeout`] module bounds the
//! drivers' blocking status polls so a stuck bus surfaces as an error.
//!
//! # `Peri` and `PeripheralType`
//!
//! Both are re-exported from `embassy_hal_internal`, so chip HALs and their
//! dependents (the doorbell crates, the UART transport glue) can name a singleton
//! handle without taking an Embassy dependency of their own.
//!
//! `no_std`, no features.
/// Ownership handle and marker trait for peripheral singletons, re-exported so
/// chip HALs and their dependents can name them without depending on Embassy
/// directly.
pub use ;
/// Declare a chip's peripheral singletons and the `Peripherals` struct that
/// hands them out once.
///
/// This is `embassy_hal_internal::peripherals!` with two deliberate changes:
///
/// - **No per-type `defmt::Format` derive.** Consortium's chips have hundreds of
/// peripherals, and the derive emits a `.defmt.*` link section per type; on a
/// `defmt`-enabled host build that overruns the Mach-O section limit and the
/// HAL stops compiling on macOS. The markers are zero-sized and never
/// formatted, so nothing is lost.
/// - **No `#[unsafe(no_mangle)]` on the once-guard.** Two chip HALs can end up in
/// one binary (the `consortium-cfg` UI tests link both), and an unmangled
/// guard symbol would collide between them.
///
/// Invoke it at the chip HAL's crate root; `scripts/pac/gen_peripherals.py`
/// emits the invocation.
$?
$?
$?
$?
)*
}
/// Every peripheral singleton this chip exposes to the running core.
///
/// Obtained once from the HAL's `init()`.
};
}
/// Marker for a concrete peripheral instance.
/// Minimal clock/reset hooks for chip-specific peripheral drivers.
/// Interrupt source that can be bound by board startup code.
/// Minimal monotonic timer abstraction shared by chip HAL time drivers.