1#[doc = concat!("assert_eq!(chip_name, ", chip!(), ")")]
12#[macro_export]
14#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
15macro_rules! chip {
16 () => {
17 "esp32c2"
18 };
19}
20#[doc = concat!("assert_eq!(chip_name, ", chip_pretty!(), ")")]
28#[macro_export]
30#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
31macro_rules! chip_pretty {
32 () => {
33 "ESP32-C2"
34 };
35}
36#[macro_export]
38#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
39macro_rules! property {
40 ("chip") => {
41 "esp32c2"
42 };
43 ("arch") => {
44 "riscv"
45 };
46 ("cores") => {
47 1
48 };
49 ("cores", str) => {
50 stringify!(1)
51 };
52 ("trm") => {
53 "https://www.espressif.com/sites/default/files/documentation/esp8684_technical_reference_manual_en.pdf"
54 };
55 ("assist_debug.has_sp_monitor") => {
56 true
57 };
58 ("assist_debug.has_region_monitor") => {
59 false
60 };
61 ("bt.controller") => {
62 "npl"
63 };
64 ("dedicated_gpio.needs_initialization") => {
65 false
66 };
67 ("dedicated_gpio.channel_count") => {
68 8
69 };
70 ("dedicated_gpio.channel_count", str) => {
71 stringify!(8)
72 };
73 ("dma.kind") => {
74 "gdma"
75 };
76 ("dma.supports_mem2mem") => {
77 true
78 };
79 ("dma.can_access_psram") => {
80 false
81 };
82 ("dma.ext_mem_configurable_block_size") => {
83 false
84 };
85 ("dma.separate_in_out_interrupts") => {
86 false
87 };
88 ("dma.max_priority") => {
89 9
90 };
91 ("dma.max_priority", str) => {
92 stringify!(9)
93 };
94 ("dma.gdma_version") => {
95 1
96 };
97 ("dma.gdma_version", str) => {
98 stringify!(1)
99 };
100 ("ecc.zero_extend_writes") => {
101 true
102 };
103 ("ecc.separate_jacobian_point_memory") => {
104 false
105 };
106 ("ecc.has_memory_clock_gate") => {
107 false
108 };
109 ("ecc.supports_enhanced_security") => {
110 false
111 };
112 ("ecc.mem_block_size") => {
113 32
114 };
115 ("gpio.has_bank_1") => {
116 false
117 };
118 ("gpio.gpio_function") => {
119 1
120 };
121 ("gpio.gpio_function", str) => {
122 stringify!(1)
123 };
124 ("gpio.constant_0_input") => {
125 31
126 };
127 ("gpio.constant_0_input", str) => {
128 stringify!(31)
129 };
130 ("gpio.constant_1_input") => {
131 30
132 };
133 ("gpio.constant_1_input", str) => {
134 stringify!(30)
135 };
136 ("gpio.remap_iomux_pin_registers") => {
137 false
138 };
139 ("gpio.func_in_sel_offset") => {
140 0
141 };
142 ("gpio.func_in_sel_offset", str) => {
143 stringify!(0)
144 };
145 ("gpio.input_signal_max") => {
146 100
147 };
148 ("gpio.input_signal_max", str) => {
149 stringify!(100)
150 };
151 ("gpio.output_signal_max") => {
152 128
153 };
154 ("gpio.output_signal_max", str) => {
155 stringify!(128)
156 };
157 ("i2c_master.has_fsm_timeouts") => {
158 true
159 };
160 ("i2c_master.has_hw_bus_clear") => {
161 true
162 };
163 ("i2c_master.has_bus_timeout_enable") => {
164 true
165 };
166 ("i2c_master.separate_filter_config_registers") => {
167 false
168 };
169 ("i2c_master.can_estimate_nack_reason") => {
170 false
171 };
172 ("i2c_master.has_conf_update") => {
173 true
174 };
175 ("i2c_master.has_reliable_fsm_reset") => {
176 false
177 };
178 ("i2c_master.has_arbitration_en") => {
179 true
180 };
181 ("i2c_master.has_tx_fifo_watermark") => {
182 true
183 };
184 ("i2c_master.bus_timeout_is_exponential") => {
185 true
186 };
187 ("i2c_master.max_bus_timeout") => {
188 31
189 };
190 ("i2c_master.max_bus_timeout", str) => {
191 stringify!(31)
192 };
193 ("i2c_master.ll_intr_mask") => {
194 262143
195 };
196 ("i2c_master.ll_intr_mask", str) => {
197 stringify!(262143)
198 };
199 ("i2c_master.fifo_size") => {
200 16
201 };
202 ("i2c_master.fifo_size", str) => {
203 stringify!(16)
204 };
205 ("interrupts.status_registers") => {
206 2
207 };
208 ("interrupts.status_registers", str) => {
209 stringify!(2)
210 };
211 ("interrupts.disabled_interrupt") => {
212 0
213 };
214 ("phy.combo_module") => {
215 true
216 };
217 ("rng.apb_cycle_wait_num") => {
218 16
219 };
220 ("rng.apb_cycle_wait_num", str) => {
221 stringify!(16)
222 };
223 ("rng.trng_supported") => {
224 true
225 };
226 ("sha.dma") => {
227 true
228 };
229 ("sleep.light_sleep") => {
230 true
231 };
232 ("sleep.deep_sleep") => {
233 true
234 };
235 ("soc.cpu_has_branch_predictor") => {
236 false
237 };
238 ("soc.cpu_has_csr_pc") => {
239 true
240 };
241 ("soc.multi_core_enabled") => {
242 false
243 };
244 ("soc.rc_fast_clk_default") => {
245 17500000
246 };
247 ("soc.rc_fast_clk_default", str) => {
248 stringify!(17500000)
249 };
250 ("clock_tree.system_pre_div.divisor") => {
251 (0, 1023)
252 };
253 ("clock_tree.rc_fast_clk_div_n.divisor") => {
254 (0, 3)
255 };
256 ("clock_tree.uart.function_clock.div_num") => {
257 (0, 255)
258 };
259 ("clock_tree.uart.baud_rate_generator.fractional") => {
260 (0, 15)
261 };
262 ("clock_tree.uart.baud_rate_generator.integral") => {
263 (0, 4095)
264 };
265 ("spi_master.supports_dma") => {
266 true
267 };
268 ("spi_master.has_octal") => {
269 false
270 };
271 ("spi_master.has_app_interrupts") => {
272 true
273 };
274 ("spi_master.has_dma_segmented_transfer") => {
275 true
276 };
277 ("spi_master.has_clk_pre_div") => {
278 false
279 };
280 ("spi_slave.supports_dma") => {
281 true
282 };
283 ("timergroup.timg_has_timer1") => {
284 false
285 };
286 ("timergroup.timg_has_divcnt_rst") => {
287 true
288 };
289 ("uart.ram_size") => {
290 128
291 };
292 ("uart.ram_size", str) => {
293 stringify!(128)
294 };
295 ("uart.peripheral_controls_mem_clk") => {
296 false
297 };
298 ("uart.has_sclk_divider") => {
299 true
300 };
301 ("wifi.has_wifi6") => {
302 false
303 };
304 ("wifi.mac_version") => {
305 1
306 };
307 ("wifi.mac_version", str) => {
308 stringify!(1)
309 };
310 ("wifi.has_5g") => {
311 false
312 };
313 ("wifi.csi_supported") => {
314 false
315 };
316}
317#[macro_export]
318#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
319macro_rules! for_each_dedicated_gpio {
320 ($($pattern:tt => $code:tt;)*) => {
321 macro_rules! _for_each_inner_dedicated_gpio { $(($pattern) => $code;)* ($other :
322 tt) => {} } _for_each_inner_dedicated_gpio!((0));
323 _for_each_inner_dedicated_gpio!((1)); _for_each_inner_dedicated_gpio!((2));
324 _for_each_inner_dedicated_gpio!((3)); _for_each_inner_dedicated_gpio!((4));
325 _for_each_inner_dedicated_gpio!((5)); _for_each_inner_dedicated_gpio!((6));
326 _for_each_inner_dedicated_gpio!((7)); _for_each_inner_dedicated_gpio!((0, 0,
327 CPU_GPIO_0)); _for_each_inner_dedicated_gpio!((0, 1, CPU_GPIO_1));
328 _for_each_inner_dedicated_gpio!((0, 2, CPU_GPIO_2));
329 _for_each_inner_dedicated_gpio!((0, 3, CPU_GPIO_3));
330 _for_each_inner_dedicated_gpio!((0, 4, CPU_GPIO_4));
331 _for_each_inner_dedicated_gpio!((0, 5, CPU_GPIO_5));
332 _for_each_inner_dedicated_gpio!((0, 6, CPU_GPIO_6));
333 _for_each_inner_dedicated_gpio!((0, 7, CPU_GPIO_7));
334 _for_each_inner_dedicated_gpio!((channels(0), (1), (2), (3), (4), (5), (6),
335 (7))); _for_each_inner_dedicated_gpio!((signals(0, 0, CPU_GPIO_0), (0, 1,
336 CPU_GPIO_1), (0, 2, CPU_GPIO_2), (0, 3, CPU_GPIO_3), (0, 4, CPU_GPIO_4), (0, 5,
337 CPU_GPIO_5), (0, 6, CPU_GPIO_6), (0, 7, CPU_GPIO_7)));
338 };
339}
340#[macro_export]
341#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
342macro_rules! for_each_ecc_working_mode {
343 ($($pattern:tt => $code:tt;)*) => {
344 macro_rules! _for_each_inner_ecc_working_mode { $(($pattern) => $code;)* ($other
345 : tt) => {} } _for_each_inner_ecc_working_mode!((0, AffinePointMultiplication));
346 _for_each_inner_ecc_working_mode!((1, FiniteFieldDivision));
347 _for_each_inner_ecc_working_mode!((2, AffinePointVerification));
348 _for_each_inner_ecc_working_mode!((3, AffinePointVerificationAndMultiplication));
349 _for_each_inner_ecc_working_mode!((4, JacobianPointMultiplication));
350 _for_each_inner_ecc_working_mode!((6, JacobianPointVerification));
351 _for_each_inner_ecc_working_mode!((7,
352 AffinePointVerificationAndJacobianPointMultiplication));
353 _for_each_inner_ecc_working_mode!((all(0, AffinePointMultiplication), (1,
354 FiniteFieldDivision), (2, AffinePointVerification), (3,
355 AffinePointVerificationAndMultiplication), (4, JacobianPointMultiplication), (6,
356 JacobianPointVerification), (7,
357 AffinePointVerificationAndJacobianPointMultiplication)));
358 };
359}
360#[macro_export]
361#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
362macro_rules! for_each_ecc_curve {
363 ($($pattern:tt => $code:tt;)*) => {
364 macro_rules! _for_each_inner_ecc_curve { $(($pattern) => $code;)* ($other : tt)
365 => {} } _for_each_inner_ecc_curve!((0, P192, 192));
366 _for_each_inner_ecc_curve!((1, P256, 256)); _for_each_inner_ecc_curve!((all(0,
367 P192, 192), (1, P256, 256)));
368 };
369}
370#[macro_export]
371#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
372macro_rules! for_each_interrupt {
373 ($($pattern:tt => $code:tt;)*) => {
374 macro_rules! _for_each_inner_interrupt { $(($pattern) => $code;)* ($other : tt)
375 => {} } _for_each_inner_interrupt!(([disabled 0] 0));
376 _for_each_inner_interrupt!(([reserved 0] 1));
377 _for_each_inner_interrupt!(([direct_bindable 0] 2));
378 _for_each_inner_interrupt!(([direct_bindable 1] 3));
379 _for_each_inner_interrupt!(([direct_bindable 2] 4));
380 _for_each_inner_interrupt!(([direct_bindable 3] 5));
381 _for_each_inner_interrupt!(([direct_bindable 4] 6));
382 _for_each_inner_interrupt!(([direct_bindable 5] 7));
383 _for_each_inner_interrupt!(([direct_bindable 6] 8));
384 _for_each_inner_interrupt!(([direct_bindable 7] 9));
385 _for_each_inner_interrupt!(([direct_bindable 8] 10));
386 _for_each_inner_interrupt!(([direct_bindable 9] 11));
387 _for_each_inner_interrupt!(([direct_bindable 10] 12));
388 _for_each_inner_interrupt!(([direct_bindable 11] 13));
389 _for_each_inner_interrupt!(([direct_bindable 12] 14));
390 _for_each_inner_interrupt!(([direct_bindable 13] 15));
391 _for_each_inner_interrupt!(([direct_bindable 14] 16));
392 _for_each_inner_interrupt!(([vector 0] 17)); _for_each_inner_interrupt!(([vector
393 1] 18)); _for_each_inner_interrupt!(([vector 2] 19));
394 _for_each_inner_interrupt!(([vector 3] 20)); _for_each_inner_interrupt!(([vector
395 4] 21)); _for_each_inner_interrupt!(([vector 5] 22));
396 _for_each_inner_interrupt!(([vector 6] 23)); _for_each_inner_interrupt!(([vector
397 7] 24)); _for_each_inner_interrupt!(([vector 8] 25));
398 _for_each_inner_interrupt!(([vector 9] 26)); _for_each_inner_interrupt!(([vector
399 10] 27)); _for_each_inner_interrupt!(([vector 11] 28));
400 _for_each_inner_interrupt!(([vector 12] 29)); _for_each_inner_interrupt!(([vector
401 13] 30)); _for_each_inner_interrupt!(([vector 14] 31));
402 _for_each_inner_interrupt!((all([disabled 0] 0), ([reserved 0] 1),
403 ([direct_bindable 0] 2), ([direct_bindable 1] 3), ([direct_bindable 2] 4),
404 ([direct_bindable 3] 5), ([direct_bindable 4] 6), ([direct_bindable 5] 7),
405 ([direct_bindable 6] 8), ([direct_bindable 7] 9), ([direct_bindable 8] 10),
406 ([direct_bindable 9] 11), ([direct_bindable 10] 12), ([direct_bindable 11] 13),
407 ([direct_bindable 12] 14), ([direct_bindable 13] 15), ([direct_bindable 14] 16),
408 ([vector 0] 17), ([vector 1] 18), ([vector 2] 19), ([vector 3] 20), ([vector 4]
409 21), ([vector 5] 22), ([vector 6] 23), ([vector 7] 24), ([vector 8] 25), ([vector
410 9] 26), ([vector 10] 27), ([vector 11] 28), ([vector 12] 29), ([vector 13] 30),
411 ([vector 14] 31)));
412 };
413}
414#[macro_export]
415#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
416macro_rules! for_each_classified_interrupt {
417 ($($pattern:tt => $code:tt;)*) => {
418 macro_rules! _for_each_inner_classified_interrupt { $(($pattern) => $code;)*
419 ($other : tt) => {} } _for_each_inner_classified_interrupt!(([direct_bindable 0]
420 2)); _for_each_inner_classified_interrupt!(([direct_bindable 1] 3));
421 _for_each_inner_classified_interrupt!(([direct_bindable 2] 4));
422 _for_each_inner_classified_interrupt!(([direct_bindable 3] 5));
423 _for_each_inner_classified_interrupt!(([direct_bindable 4] 6));
424 _for_each_inner_classified_interrupt!(([direct_bindable 5] 7));
425 _for_each_inner_classified_interrupt!(([direct_bindable 6] 8));
426 _for_each_inner_classified_interrupt!(([direct_bindable 7] 9));
427 _for_each_inner_classified_interrupt!(([direct_bindable 8] 10));
428 _for_each_inner_classified_interrupt!(([direct_bindable 9] 11));
429 _for_each_inner_classified_interrupt!(([direct_bindable 10] 12));
430 _for_each_inner_classified_interrupt!(([direct_bindable 11] 13));
431 _for_each_inner_classified_interrupt!(([direct_bindable 12] 14));
432 _for_each_inner_classified_interrupt!(([direct_bindable 13] 15));
433 _for_each_inner_classified_interrupt!(([direct_bindable 14] 16));
434 _for_each_inner_classified_interrupt!(([vector 0] 17));
435 _for_each_inner_classified_interrupt!(([vector 1] 18));
436 _for_each_inner_classified_interrupt!(([vector 2] 19));
437 _for_each_inner_classified_interrupt!(([vector 3] 20));
438 _for_each_inner_classified_interrupt!(([vector 4] 21));
439 _for_each_inner_classified_interrupt!(([vector 5] 22));
440 _for_each_inner_classified_interrupt!(([vector 6] 23));
441 _for_each_inner_classified_interrupt!(([vector 7] 24));
442 _for_each_inner_classified_interrupt!(([vector 8] 25));
443 _for_each_inner_classified_interrupt!(([vector 9] 26));
444 _for_each_inner_classified_interrupt!(([vector 10] 27));
445 _for_each_inner_classified_interrupt!(([vector 11] 28));
446 _for_each_inner_classified_interrupt!(([vector 12] 29));
447 _for_each_inner_classified_interrupt!(([vector 13] 30));
448 _for_each_inner_classified_interrupt!(([vector 14] 31));
449 _for_each_inner_classified_interrupt!(([reserved 0] 1));
450 _for_each_inner_classified_interrupt!((direct_bindable([direct_bindable 0] 2),
451 ([direct_bindable 1] 3), ([direct_bindable 2] 4), ([direct_bindable 3] 5),
452 ([direct_bindable 4] 6), ([direct_bindable 5] 7), ([direct_bindable 6] 8),
453 ([direct_bindable 7] 9), ([direct_bindable 8] 10), ([direct_bindable 9] 11),
454 ([direct_bindable 10] 12), ([direct_bindable 11] 13), ([direct_bindable 12] 14),
455 ([direct_bindable 13] 15), ([direct_bindable 14] 16)));
456 _for_each_inner_classified_interrupt!((vector([vector 0] 17), ([vector 1] 18),
457 ([vector 2] 19), ([vector 3] 20), ([vector 4] 21), ([vector 5] 22), ([vector 6]
458 23), ([vector 7] 24), ([vector 8] 25), ([vector 9] 26), ([vector 10] 27),
459 ([vector 11] 28), ([vector 12] 29), ([vector 13] 30), ([vector 14] 31)));
460 _for_each_inner_classified_interrupt!((reserved([reserved 0] 1)));
461 };
462}
463#[macro_export]
464#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
465macro_rules! for_each_interrupt_priority {
466 ($($pattern:tt => $code:tt;)*) => {
467 macro_rules! _for_each_inner_interrupt_priority { $(($pattern) => $code;)*
468 ($other : tt) => {} } _for_each_inner_interrupt_priority!((0, 1, Priority1,
469 Level1)); _for_each_inner_interrupt_priority!((1, 2, Priority2, Level2));
470 _for_each_inner_interrupt_priority!((2, 3, Priority3, Level3));
471 _for_each_inner_interrupt_priority!((3, 4, Priority4, Level4));
472 _for_each_inner_interrupt_priority!((4, 5, Priority5, Level5));
473 _for_each_inner_interrupt_priority!((5, 6, Priority6, Level6));
474 _for_each_inner_interrupt_priority!((6, 7, Priority7, Level7));
475 _for_each_inner_interrupt_priority!((7, 8, Priority8, Level8));
476 _for_each_inner_interrupt_priority!((8, 9, Priority9, Level9));
477 _for_each_inner_interrupt_priority!((9, 10, Priority10, Level10));
478 _for_each_inner_interrupt_priority!((10, 11, Priority11, Level11));
479 _for_each_inner_interrupt_priority!((11, 12, Priority12, Level12));
480 _for_each_inner_interrupt_priority!((12, 13, Priority13, Level13));
481 _for_each_inner_interrupt_priority!((13, 14, Priority14, Level14));
482 _for_each_inner_interrupt_priority!((14, 15, Priority15, Level15));
483 _for_each_inner_interrupt_priority!((all(0, 1, Priority1, Level1), (1, 2,
484 Priority2, Level2), (2, 3, Priority3, Level3), (3, 4, Priority4, Level4), (4, 5,
485 Priority5, Level5), (5, 6, Priority6, Level6), (6, 7, Priority7, Level7), (7, 8,
486 Priority8, Level8), (8, 9, Priority9, Level9), (9, 10, Priority10, Level10), (10,
487 11, Priority11, Level11), (11, 12, Priority12, Level12), (12, 13, Priority13,
488 Level13), (13, 14, Priority14, Level14), (14, 15, Priority15, Level15)));
489 };
490}
491#[macro_export]
492#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
493macro_rules! for_each_sw_interrupt {
494 ($($pattern:tt => $code:tt;)*) => {
495 macro_rules! _for_each_inner_sw_interrupt { $(($pattern) => $code;)* ($other :
496 tt) => {} } _for_each_inner_sw_interrupt!((0, FROM_CPU_INTR0,
497 software_interrupt0)); _for_each_inner_sw_interrupt!((1, FROM_CPU_INTR1,
498 software_interrupt1)); _for_each_inner_sw_interrupt!((2, FROM_CPU_INTR2,
499 software_interrupt2)); _for_each_inner_sw_interrupt!((3, FROM_CPU_INTR3,
500 software_interrupt3)); _for_each_inner_sw_interrupt!((all(0, FROM_CPU_INTR0,
501 software_interrupt0), (1, FROM_CPU_INTR1, software_interrupt1), (2,
502 FROM_CPU_INTR2, software_interrupt2), (3, FROM_CPU_INTR3, software_interrupt3)));
503 };
504}
505#[macro_export]
506macro_rules! sw_interrupt_delay {
507 () => {
508 unsafe {
509 ::core::arch::asm!("nop");
510 ::core::arch::asm!("nop");
511 ::core::arch::asm!("nop");
512 ::core::arch::asm!("nop");
513 ::core::arch::asm!("nop");
514 }
515 };
516}
517#[macro_export]
518#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
519macro_rules! for_each_sha_algorithm {
520 ($($pattern:tt => $code:tt;)*) => {
521 macro_rules! _for_each_inner_sha_algorithm { $(($pattern) => $code;)* ($other :
522 tt) => {} } _for_each_inner_sha_algorithm!((Sha1, "SHA-1"(sizes : 64, 20, 8)
523 (insecure_against : "collision", "length extension"), 0));
524 _for_each_inner_sha_algorithm!((Sha224, "SHA-224"(sizes : 64, 28, 8)
525 (insecure_against : "length extension"), 1));
526 _for_each_inner_sha_algorithm!((Sha256, "SHA-256"(sizes : 64, 32, 8)
527 (insecure_against : "length extension"), 2));
528 _for_each_inner_sha_algorithm!((algos(Sha1, "SHA-1"(sizes : 64, 20, 8)
529 (insecure_against : "collision", "length extension"), 0), (Sha224,
530 "SHA-224"(sizes : 64, 28, 8) (insecure_against : "length extension"), 1),
531 (Sha256, "SHA-256"(sizes : 64, 32, 8) (insecure_against : "length extension"),
532 2)));
533 };
534}
535#[macro_export]
536macro_rules! define_clock_tree_types {
857 () => {
858 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
859 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
860 pub enum TimgInstance {
861 Timg0 = 0,
862 }
863 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
864 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
865 pub enum UartInstance {
866 Uart0 = 0,
867 Uart1 = 1,
868 }
869 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
871 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
872 pub enum XtalClkConfig {
873 _26,
875 _40,
877 }
878 impl XtalClkConfig {
879 pub fn value(&self) -> u32 {
880 match self {
881 XtalClkConfig::_26 => 26000000,
882 XtalClkConfig::_40 => 40000000,
883 }
884 }
885 }
886 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
888 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
889 pub enum SystemPreDivInConfig {
890 Xtal,
892 RcFast,
894 }
895 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
899 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
900 pub struct SystemPreDivConfig {
901 divisor: u32,
902 }
903 impl SystemPreDivConfig {
904 pub const fn new(divisor: u32) -> Self {
911 ::core::assert!(
912 divisor <= 1023,
913 "`SYSTEM_PRE_DIV` divisor must be between 0 and 1023 (inclusive)."
914 );
915 Self { divisor }
916 }
917 fn divisor(self) -> u32 {
918 self.divisor as u32
919 }
920 }
921 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
922 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
923 pub enum CpuPllDivDivisor {
924 _4 = 4,
926 _6 = 6,
928 }
929 impl CpuPllDivDivisor {
930 pub const fn new(raw: u32) -> Self {
932 match raw {
933 4 => Self::_4,
934 6 => Self::_6,
935 _ => ::core::panic!("Invalid CPU_PLL_DIV divisor value"),
936 }
937 }
938 }
939 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
943 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
944 pub struct CpuPllDivConfig {
945 divisor: CpuPllDivDivisor,
946 }
947 impl CpuPllDivConfig {
948 pub const fn new(divisor: CpuPllDivDivisor) -> Self {
950 Self { divisor }
951 }
952 fn divisor(self) -> u32 {
953 self.divisor as u32
954 }
955 }
956 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
958 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
959 pub enum ApbClkConfig {
960 Pll40m,
962 Cpu,
964 }
965 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
967 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
968 pub enum CryptoClkConfig {
969 Pll80m,
971 Cpu,
973 }
974 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
976 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
977 pub enum MspiClkConfig {
978 CpuDiv2,
980 Cpu,
982 }
983 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
985 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
986 pub enum CpuClkConfig {
987 Xtal,
989 RcFast,
991 Pll,
993 }
994 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
998 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
999 pub struct RcFastClkDivNConfig {
1000 divisor: u32,
1001 }
1002 impl RcFastClkDivNConfig {
1003 pub const fn new(divisor: u32) -> Self {
1010 ::core::assert!(
1011 divisor <= 3,
1012 "`RC_FAST_CLK_DIV_N` divisor must be between 0 and 3 (inclusive)."
1013 );
1014 Self { divisor }
1015 }
1016 fn divisor(self) -> u32 {
1017 self.divisor as u32
1018 }
1019 }
1020 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1022 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1023 pub enum RtcSlowClkConfig {
1024 OscSlow,
1026 RcSlow,
1028 RcFast,
1030 }
1031 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1033 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1034 pub enum RtcFastClkConfig {
1035 Xtal,
1037 Rc,
1039 }
1040 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1042 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1043 pub enum LowPowerClkConfig {
1044 Xtal,
1046 RcFast,
1048 OscSlow,
1050 RtcSlow,
1052 }
1053 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1055 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1056 pub enum TimgCalibrationClockConfig {
1057 RcSlowClk,
1059 RcFastDivClk,
1061 Osc32kClk,
1063 }
1064 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1066 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1067 pub enum TimgFunctionClockConfig {
1068 #[default]
1069 XtalClk,
1071 Pll40m,
1073 }
1074 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1076 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1077 pub enum TimgWdtClockConfig {
1078 #[default]
1079 Pll40m,
1081 XtalClk,
1083 }
1084 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1085 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1086 pub enum UartFunctionClockSclk {
1087 PllF40m,
1089 RcFast,
1091 #[default]
1092 Xtal,
1094 }
1095 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1099 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1100 pub struct UartFunctionClockConfig {
1101 sclk: UartFunctionClockSclk,
1102 div_num: u32,
1103 }
1104 impl UartFunctionClockConfig {
1105 pub const fn new(sclk: UartFunctionClockSclk, div_num: u32) -> Self {
1112 ::core::assert!(
1113 div_num <= 255,
1114 "`UART0_FUNCTION_CLOCK` div_num must be between 0 and 255 (inclusive)."
1115 );
1116 Self { sclk, div_num }
1117 }
1118 fn sclk(self) -> UartFunctionClockSclk {
1119 self.sclk
1120 }
1121 fn div_num(self) -> u32 {
1122 self.div_num as u32
1123 }
1124 }
1125 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1129 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1130 pub struct UartMemClockConfig {}
1131 impl UartMemClockConfig {
1132 pub const fn new() -> Self {
1134 Self {}
1135 }
1136 }
1137 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1142 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1143 pub struct UartBaudRateGeneratorConfig {
1144 fractional: u32,
1145 integral: u32,
1146 }
1147 impl UartBaudRateGeneratorConfig {
1148 pub const fn new(fractional: u32, integral: u32) -> Self {
1158 ::core::assert!(
1159 fractional <= 15,
1160 "`UART0_BAUD_RATE_GENERATOR` fractional must be between 0 and 15 (inclusive)."
1161 );
1162 ::core::assert!(
1163 integral <= 4095,
1164 "`UART0_BAUD_RATE_GENERATOR` integral must be between 0 and 4095 (inclusive)."
1165 );
1166 Self {
1167 fractional,
1168 integral,
1169 }
1170 }
1171 fn fractional(self) -> u32 {
1172 self.fractional as u32
1173 }
1174 fn integral(self) -> u32 {
1175 self.integral as u32
1176 }
1177 }
1178 pub struct ClockTree {
1180 xtal_clk: Option<XtalClkConfig>,
1181 system_pre_div_in: Option<SystemPreDivInConfig>,
1182 system_pre_div: Option<SystemPreDivConfig>,
1183 cpu_pll_div: Option<CpuPllDivConfig>,
1184 apb_clk: Option<ApbClkConfig>,
1185 crypto_clk: Option<CryptoClkConfig>,
1186 mspi_clk: Option<MspiClkConfig>,
1187 cpu_clk: Option<CpuClkConfig>,
1188 rc_fast_clk_div_n: Option<RcFastClkDivNConfig>,
1189 rtc_slow_clk: Option<RtcSlowClkConfig>,
1190 rtc_fast_clk: Option<RtcFastClkConfig>,
1191 low_power_clk: Option<LowPowerClkConfig>,
1192 timg_calibration_clock: Option<TimgCalibrationClockConfig>,
1193 timg_function_clock: [Option<TimgFunctionClockConfig>; 1],
1194 timg_wdt_clock: [Option<TimgWdtClockConfig>; 1],
1195 uart_function_clock: [Option<UartFunctionClockConfig>; 2],
1196 uart_mem_clock: [Option<UartMemClockConfig>; 2],
1197 uart_baud_rate_generator: [Option<UartBaudRateGeneratorConfig>; 2],
1198 rc_fast_clk_refcount: u32,
1199 osc_slow_clk_refcount: u32,
1200 rc_slow_clk_refcount: u32,
1201 rc_fast_div_clk_refcount: u32,
1202 apb_clk_refcount: u32,
1203 crypto_clk_refcount: u32,
1204 mspi_clk_refcount: u32,
1205 pll_40m_refcount: u32,
1206 pll_60m_refcount: u32,
1207 rtc_fast_clk_refcount: u32,
1208 low_power_clk_refcount: u32,
1209 uart_mem_clk_refcount: u32,
1210 timg_calibration_clock_refcount: u32,
1211 timg_function_clock_refcount: [u32; 1],
1212 timg_wdt_clock_refcount: [u32; 1],
1213 uart_function_clock_refcount: [u32; 2],
1214 uart_mem_clock_refcount: [u32; 2],
1215 uart_baud_rate_generator_refcount: [u32; 2],
1216 }
1217 impl ClockTree {
1218 pub fn with<R>(f: impl FnOnce(&mut ClockTree) -> R) -> R {
1220 CLOCK_TREE.with(f)
1221 }
1222 pub fn xtal_clk(&self) -> Option<XtalClkConfig> {
1224 self.xtal_clk
1225 }
1226 pub fn system_pre_div_in(&self) -> Option<SystemPreDivInConfig> {
1228 self.system_pre_div_in
1229 }
1230 pub fn system_pre_div(&self) -> Option<SystemPreDivConfig> {
1232 self.system_pre_div
1233 }
1234 pub fn cpu_pll_div(&self) -> Option<CpuPllDivConfig> {
1236 self.cpu_pll_div
1237 }
1238 pub fn apb_clk(&self) -> Option<ApbClkConfig> {
1240 self.apb_clk
1241 }
1242 pub fn crypto_clk(&self) -> Option<CryptoClkConfig> {
1244 self.crypto_clk
1245 }
1246 pub fn mspi_clk(&self) -> Option<MspiClkConfig> {
1248 self.mspi_clk
1249 }
1250 pub fn cpu_clk(&self) -> Option<CpuClkConfig> {
1252 self.cpu_clk
1253 }
1254 pub fn rc_fast_clk_div_n(&self) -> Option<RcFastClkDivNConfig> {
1256 self.rc_fast_clk_div_n
1257 }
1258 pub fn rtc_slow_clk(&self) -> Option<RtcSlowClkConfig> {
1260 self.rtc_slow_clk
1261 }
1262 pub fn rtc_fast_clk(&self) -> Option<RtcFastClkConfig> {
1264 self.rtc_fast_clk
1265 }
1266 pub fn low_power_clk(&self) -> Option<LowPowerClkConfig> {
1268 self.low_power_clk
1269 }
1270 pub fn timg_calibration_clock(&self) -> Option<TimgCalibrationClockConfig> {
1272 self.timg_calibration_clock
1273 }
1274 pub fn timg0_function_clock(&self) -> Option<TimgFunctionClockConfig> {
1276 self.timg_function_clock[TimgInstance::Timg0 as usize]
1277 }
1278 pub fn timg0_wdt_clock(&self) -> Option<TimgWdtClockConfig> {
1280 self.timg_wdt_clock[TimgInstance::Timg0 as usize]
1281 }
1282 pub fn uart0_function_clock(&self) -> Option<UartFunctionClockConfig> {
1284 self.uart_function_clock[UartInstance::Uart0 as usize]
1285 }
1286 pub fn uart0_mem_clock(&self) -> Option<UartMemClockConfig> {
1288 self.uart_mem_clock[UartInstance::Uart0 as usize]
1289 }
1290 pub fn uart0_baud_rate_generator(&self) -> Option<UartBaudRateGeneratorConfig> {
1292 self.uart_baud_rate_generator[UartInstance::Uart0 as usize]
1293 }
1294 pub fn uart1_function_clock(&self) -> Option<UartFunctionClockConfig> {
1296 self.uart_function_clock[UartInstance::Uart1 as usize]
1297 }
1298 pub fn uart1_mem_clock(&self) -> Option<UartMemClockConfig> {
1300 self.uart_mem_clock[UartInstance::Uart1 as usize]
1301 }
1302 pub fn uart1_baud_rate_generator(&self) -> Option<UartBaudRateGeneratorConfig> {
1304 self.uart_baud_rate_generator[UartInstance::Uart1 as usize]
1305 }
1306 }
1307 static CLOCK_TREE: ::esp_sync::NonReentrantMutex<ClockTree> =
1308 ::esp_sync::NonReentrantMutex::new(ClockTree {
1309 xtal_clk: None,
1310 system_pre_div_in: None,
1311 system_pre_div: None,
1312 cpu_pll_div: None,
1313 apb_clk: None,
1314 crypto_clk: None,
1315 mspi_clk: None,
1316 cpu_clk: None,
1317 rc_fast_clk_div_n: None,
1318 rtc_slow_clk: None,
1319 rtc_fast_clk: None,
1320 low_power_clk: None,
1321 timg_calibration_clock: None,
1322 timg_function_clock: [None; 1],
1323 timg_wdt_clock: [None; 1],
1324 uart_function_clock: [None; 2],
1325 uart_mem_clock: [None; 2],
1326 uart_baud_rate_generator: [None; 2],
1327 rc_fast_clk_refcount: 0,
1328 osc_slow_clk_refcount: 0,
1329 rc_slow_clk_refcount: 0,
1330 rc_fast_div_clk_refcount: 0,
1331 apb_clk_refcount: 0,
1332 crypto_clk_refcount: 0,
1333 mspi_clk_refcount: 0,
1334 pll_40m_refcount: 0,
1335 pll_60m_refcount: 0,
1336 rtc_fast_clk_refcount: 0,
1337 low_power_clk_refcount: 0,
1338 uart_mem_clk_refcount: 0,
1339 timg_calibration_clock_refcount: 0,
1340 timg_function_clock_refcount: [0; 1],
1341 timg_wdt_clock_refcount: [0; 1],
1342 uart_function_clock_refcount: [0; 2],
1343 uart_mem_clock_refcount: [0; 2],
1344 uart_baud_rate_generator_refcount: [0; 2],
1345 });
1346 pub fn configure_xtal_clk(clocks: &mut ClockTree, config: XtalClkConfig) {
1347 let old_config = clocks.xtal_clk.replace(config);
1348 configure_xtal_clk_impl(clocks, old_config, config);
1349 }
1350 pub fn xtal_clk_config(clocks: &mut ClockTree) -> Option<XtalClkConfig> {
1351 clocks.xtal_clk
1352 }
1353 fn request_xtal_clk(_clocks: &mut ClockTree) {}
1354 fn release_xtal_clk(_clocks: &mut ClockTree) {}
1355 #[allow(unused_variables)]
1356 pub fn xtal_clk_config_frequency(clocks: &mut ClockTree, config: XtalClkConfig) -> u32 {
1357 config.value()
1358 }
1359 pub fn xtal_clk_frequency(clocks: &mut ClockTree) -> u32 {
1360 if let Some(config) = clocks.xtal_clk {
1361 xtal_clk_config_frequency(clocks, config)
1362 } else {
1363 0
1364 }
1365 }
1366 pub fn request_pll_clk(clocks: &mut ClockTree) {
1367 trace!("Requesting PLL_CLK");
1368 trace!("Enabling PLL_CLK");
1369 request_xtal_clk(clocks);
1370 enable_pll_clk_impl(clocks, true);
1371 }
1372 pub fn release_pll_clk(clocks: &mut ClockTree) {
1373 trace!("Releasing PLL_CLK");
1374 trace!("Disabling PLL_CLK");
1375 enable_pll_clk_impl(clocks, false);
1376 release_xtal_clk(clocks);
1377 }
1378 pub fn pll_clk_frequency(clocks: &mut ClockTree) -> u32 {
1379 480000000
1380 }
1381 pub fn request_rc_fast_clk(clocks: &mut ClockTree) {
1382 trace!("Requesting RC_FAST_CLK");
1383 if increment_reference_count(&mut clocks.rc_fast_clk_refcount) {
1384 trace!("Enabling RC_FAST_CLK");
1385 enable_rc_fast_clk_impl(clocks, true);
1386 }
1387 }
1388 pub fn release_rc_fast_clk(clocks: &mut ClockTree) {
1389 trace!("Releasing RC_FAST_CLK");
1390 if decrement_reference_count(&mut clocks.rc_fast_clk_refcount) {
1391 trace!("Disabling RC_FAST_CLK");
1392 enable_rc_fast_clk_impl(clocks, false);
1393 }
1394 }
1395 pub fn rc_fast_clk_frequency(clocks: &mut ClockTree) -> u32 {
1396 17500000
1397 }
1398 pub fn request_osc_slow_clk(clocks: &mut ClockTree) {
1399 trace!("Requesting OSC_SLOW_CLK");
1400 if increment_reference_count(&mut clocks.osc_slow_clk_refcount) {
1401 trace!("Enabling OSC_SLOW_CLK");
1402 enable_osc_slow_clk_impl(clocks, true);
1403 }
1404 }
1405 pub fn release_osc_slow_clk(clocks: &mut ClockTree) {
1406 trace!("Releasing OSC_SLOW_CLK");
1407 if decrement_reference_count(&mut clocks.osc_slow_clk_refcount) {
1408 trace!("Disabling OSC_SLOW_CLK");
1409 enable_osc_slow_clk_impl(clocks, false);
1410 }
1411 }
1412 pub fn osc_slow_clk_frequency(clocks: &mut ClockTree) -> u32 {
1413 32768
1414 }
1415 pub fn request_rc_slow_clk(clocks: &mut ClockTree) {
1416 trace!("Requesting RC_SLOW_CLK");
1417 if increment_reference_count(&mut clocks.rc_slow_clk_refcount) {
1418 trace!("Enabling RC_SLOW_CLK");
1419 enable_rc_slow_clk_impl(clocks, true);
1420 }
1421 }
1422 pub fn release_rc_slow_clk(clocks: &mut ClockTree) {
1423 trace!("Releasing RC_SLOW_CLK");
1424 if decrement_reference_count(&mut clocks.rc_slow_clk_refcount) {
1425 trace!("Disabling RC_SLOW_CLK");
1426 enable_rc_slow_clk_impl(clocks, false);
1427 }
1428 }
1429 pub fn rc_slow_clk_frequency(clocks: &mut ClockTree) -> u32 {
1430 136000
1431 }
1432 pub fn request_rc_fast_div_clk(clocks: &mut ClockTree) {
1433 trace!("Requesting RC_FAST_DIV_CLK");
1434 if increment_reference_count(&mut clocks.rc_fast_div_clk_refcount) {
1435 trace!("Enabling RC_FAST_DIV_CLK");
1436 request_rc_fast_clk(clocks);
1437 enable_rc_fast_div_clk_impl(clocks, true);
1438 }
1439 }
1440 pub fn release_rc_fast_div_clk(clocks: &mut ClockTree) {
1441 trace!("Releasing RC_FAST_DIV_CLK");
1442 if decrement_reference_count(&mut clocks.rc_fast_div_clk_refcount) {
1443 trace!("Disabling RC_FAST_DIV_CLK");
1444 enable_rc_fast_div_clk_impl(clocks, false);
1445 release_rc_fast_clk(clocks);
1446 }
1447 }
1448 pub fn rc_fast_div_clk_frequency(clocks: &mut ClockTree) -> u32 {
1449 (rc_fast_clk_frequency(clocks) / 256)
1450 }
1451 pub fn configure_system_pre_div_in(
1452 clocks: &mut ClockTree,
1453 new_selector: SystemPreDivInConfig,
1454 ) {
1455 let old_selector = clocks.system_pre_div_in.replace(new_selector);
1456 match new_selector {
1457 SystemPreDivInConfig::Xtal => request_xtal_clk(clocks),
1458 SystemPreDivInConfig::RcFast => request_rc_fast_clk(clocks),
1459 }
1460 configure_system_pre_div_in_impl(clocks, old_selector, new_selector);
1461 if let Some(old_selector) = old_selector {
1462 match old_selector {
1463 SystemPreDivInConfig::Xtal => release_xtal_clk(clocks),
1464 SystemPreDivInConfig::RcFast => release_rc_fast_clk(clocks),
1465 }
1466 }
1467 }
1468 pub fn system_pre_div_in_config(clocks: &mut ClockTree) -> Option<SystemPreDivInConfig> {
1469 clocks.system_pre_div_in
1470 }
1471 pub fn request_system_pre_div_in(clocks: &mut ClockTree) {
1472 trace!("Requesting SYSTEM_PRE_DIV_IN");
1473 trace!("Enabling SYSTEM_PRE_DIV_IN");
1474 match unwrap!(clocks.system_pre_div_in) {
1475 SystemPreDivInConfig::Xtal => request_xtal_clk(clocks),
1476 SystemPreDivInConfig::RcFast => request_rc_fast_clk(clocks),
1477 }
1478 enable_system_pre_div_in_impl(clocks, true);
1479 }
1480 pub fn release_system_pre_div_in(clocks: &mut ClockTree) {
1481 trace!("Releasing SYSTEM_PRE_DIV_IN");
1482 trace!("Disabling SYSTEM_PRE_DIV_IN");
1483 enable_system_pre_div_in_impl(clocks, false);
1484 match unwrap!(clocks.system_pre_div_in) {
1485 SystemPreDivInConfig::Xtal => release_xtal_clk(clocks),
1486 SystemPreDivInConfig::RcFast => release_rc_fast_clk(clocks),
1487 }
1488 }
1489 #[allow(unused_variables)]
1490 pub fn system_pre_div_in_config_frequency(
1491 clocks: &mut ClockTree,
1492 config: SystemPreDivInConfig,
1493 ) -> u32 {
1494 match config {
1495 SystemPreDivInConfig::Xtal => xtal_clk_frequency(clocks),
1496 SystemPreDivInConfig::RcFast => rc_fast_clk_frequency(clocks),
1497 }
1498 }
1499 pub fn system_pre_div_in_frequency(clocks: &mut ClockTree) -> u32 {
1500 if let Some(config) = clocks.system_pre_div_in {
1501 system_pre_div_in_config_frequency(clocks, config)
1502 } else {
1503 0
1504 }
1505 }
1506 pub fn configure_system_pre_div(clocks: &mut ClockTree, config: SystemPreDivConfig) {
1507 let old_config = clocks.system_pre_div.replace(config);
1508 configure_system_pre_div_impl(clocks, old_config, config);
1509 }
1510 pub fn system_pre_div_config(clocks: &mut ClockTree) -> Option<SystemPreDivConfig> {
1511 clocks.system_pre_div
1512 }
1513 pub fn request_system_pre_div(clocks: &mut ClockTree) {
1514 trace!("Requesting SYSTEM_PRE_DIV");
1515 trace!("Enabling SYSTEM_PRE_DIV");
1516 request_system_pre_div_in(clocks);
1517 enable_system_pre_div_impl(clocks, true);
1518 }
1519 pub fn release_system_pre_div(clocks: &mut ClockTree) {
1520 trace!("Releasing SYSTEM_PRE_DIV");
1521 trace!("Disabling SYSTEM_PRE_DIV");
1522 enable_system_pre_div_impl(clocks, false);
1523 release_system_pre_div_in(clocks);
1524 }
1525 #[allow(unused_variables)]
1526 pub fn system_pre_div_config_frequency(
1527 clocks: &mut ClockTree,
1528 config: SystemPreDivConfig,
1529 ) -> u32 {
1530 (system_pre_div_in_frequency(clocks) / (config.divisor() + 1))
1531 }
1532 pub fn system_pre_div_frequency(clocks: &mut ClockTree) -> u32 {
1533 if let Some(config) = clocks.system_pre_div {
1534 system_pre_div_config_frequency(clocks, config)
1535 } else {
1536 0
1537 }
1538 }
1539 pub fn configure_cpu_pll_div(clocks: &mut ClockTree, config: CpuPllDivConfig) {
1540 let old_config = clocks.cpu_pll_div.replace(config);
1541 configure_cpu_pll_div_impl(clocks, old_config, config);
1542 }
1543 pub fn cpu_pll_div_config(clocks: &mut ClockTree) -> Option<CpuPllDivConfig> {
1544 clocks.cpu_pll_div
1545 }
1546 pub fn request_cpu_pll_div(clocks: &mut ClockTree) {
1547 trace!("Requesting CPU_PLL_DIV");
1548 trace!("Enabling CPU_PLL_DIV");
1549 request_pll_clk(clocks);
1550 enable_cpu_pll_div_impl(clocks, true);
1551 }
1552 pub fn release_cpu_pll_div(clocks: &mut ClockTree) {
1553 trace!("Releasing CPU_PLL_DIV");
1554 trace!("Disabling CPU_PLL_DIV");
1555 enable_cpu_pll_div_impl(clocks, false);
1556 release_pll_clk(clocks);
1557 }
1558 #[allow(unused_variables)]
1559 pub fn cpu_pll_div_config_frequency(
1560 clocks: &mut ClockTree,
1561 config: CpuPllDivConfig,
1562 ) -> u32 {
1563 (pll_clk_frequency(clocks) / config.divisor())
1564 }
1565 pub fn cpu_pll_div_frequency(clocks: &mut ClockTree) -> u32 {
1566 if let Some(config) = clocks.cpu_pll_div {
1567 cpu_pll_div_config_frequency(clocks, config)
1568 } else {
1569 0
1570 }
1571 }
1572 pub fn configure_apb_clk(clocks: &mut ClockTree, new_selector: ApbClkConfig) {
1573 let old_selector = clocks.apb_clk.replace(new_selector);
1574 if clocks.apb_clk_refcount > 0 {
1575 match new_selector {
1576 ApbClkConfig::Pll40m => request_pll_40m(clocks),
1577 ApbClkConfig::Cpu => request_cpu_clk(clocks),
1578 }
1579 configure_apb_clk_impl(clocks, old_selector, new_selector);
1580 if let Some(old_selector) = old_selector {
1581 match old_selector {
1582 ApbClkConfig::Pll40m => release_pll_40m(clocks),
1583 ApbClkConfig::Cpu => release_cpu_clk(clocks),
1584 }
1585 }
1586 } else {
1587 configure_apb_clk_impl(clocks, old_selector, new_selector);
1588 }
1589 }
1590 pub fn apb_clk_config(clocks: &mut ClockTree) -> Option<ApbClkConfig> {
1591 clocks.apb_clk
1592 }
1593 pub fn request_apb_clk(clocks: &mut ClockTree) {
1594 trace!("Requesting APB_CLK");
1595 if increment_reference_count(&mut clocks.apb_clk_refcount) {
1596 trace!("Enabling APB_CLK");
1597 match unwrap!(clocks.apb_clk) {
1598 ApbClkConfig::Pll40m => request_pll_40m(clocks),
1599 ApbClkConfig::Cpu => request_cpu_clk(clocks),
1600 }
1601 enable_apb_clk_impl(clocks, true);
1602 }
1603 }
1604 pub fn release_apb_clk(clocks: &mut ClockTree) {
1605 trace!("Releasing APB_CLK");
1606 if decrement_reference_count(&mut clocks.apb_clk_refcount) {
1607 trace!("Disabling APB_CLK");
1608 enable_apb_clk_impl(clocks, false);
1609 match unwrap!(clocks.apb_clk) {
1610 ApbClkConfig::Pll40m => release_pll_40m(clocks),
1611 ApbClkConfig::Cpu => release_cpu_clk(clocks),
1612 }
1613 }
1614 }
1615 #[allow(unused_variables)]
1616 pub fn apb_clk_config_frequency(clocks: &mut ClockTree, config: ApbClkConfig) -> u32 {
1617 match config {
1618 ApbClkConfig::Pll40m => pll_40m_frequency(clocks),
1619 ApbClkConfig::Cpu => cpu_clk_frequency(clocks),
1620 }
1621 }
1622 pub fn apb_clk_frequency(clocks: &mut ClockTree) -> u32 {
1623 if let Some(config) = clocks.apb_clk {
1624 apb_clk_config_frequency(clocks, config)
1625 } else {
1626 0
1627 }
1628 }
1629 pub fn configure_crypto_clk(clocks: &mut ClockTree, new_selector: CryptoClkConfig) {
1630 let old_selector = clocks.crypto_clk.replace(new_selector);
1631 if clocks.crypto_clk_refcount > 0 {
1632 match new_selector {
1633 CryptoClkConfig::Pll80m => request_pll_80m(clocks),
1634 CryptoClkConfig::Cpu => request_cpu_clk(clocks),
1635 }
1636 configure_crypto_clk_impl(clocks, old_selector, new_selector);
1637 if let Some(old_selector) = old_selector {
1638 match old_selector {
1639 CryptoClkConfig::Pll80m => release_pll_80m(clocks),
1640 CryptoClkConfig::Cpu => release_cpu_clk(clocks),
1641 }
1642 }
1643 } else {
1644 configure_crypto_clk_impl(clocks, old_selector, new_selector);
1645 }
1646 }
1647 pub fn crypto_clk_config(clocks: &mut ClockTree) -> Option<CryptoClkConfig> {
1648 clocks.crypto_clk
1649 }
1650 pub fn request_crypto_clk(clocks: &mut ClockTree) {
1651 trace!("Requesting CRYPTO_CLK");
1652 if increment_reference_count(&mut clocks.crypto_clk_refcount) {
1653 trace!("Enabling CRYPTO_CLK");
1654 match unwrap!(clocks.crypto_clk) {
1655 CryptoClkConfig::Pll80m => request_pll_80m(clocks),
1656 CryptoClkConfig::Cpu => request_cpu_clk(clocks),
1657 }
1658 enable_crypto_clk_impl(clocks, true);
1659 }
1660 }
1661 pub fn release_crypto_clk(clocks: &mut ClockTree) {
1662 trace!("Releasing CRYPTO_CLK");
1663 if decrement_reference_count(&mut clocks.crypto_clk_refcount) {
1664 trace!("Disabling CRYPTO_CLK");
1665 enable_crypto_clk_impl(clocks, false);
1666 match unwrap!(clocks.crypto_clk) {
1667 CryptoClkConfig::Pll80m => release_pll_80m(clocks),
1668 CryptoClkConfig::Cpu => release_cpu_clk(clocks),
1669 }
1670 }
1671 }
1672 #[allow(unused_variables)]
1673 pub fn crypto_clk_config_frequency(clocks: &mut ClockTree, config: CryptoClkConfig) -> u32 {
1674 match config {
1675 CryptoClkConfig::Pll80m => pll_80m_frequency(clocks),
1676 CryptoClkConfig::Cpu => cpu_clk_frequency(clocks),
1677 }
1678 }
1679 pub fn crypto_clk_frequency(clocks: &mut ClockTree) -> u32 {
1680 if let Some(config) = clocks.crypto_clk {
1681 crypto_clk_config_frequency(clocks, config)
1682 } else {
1683 0
1684 }
1685 }
1686 pub fn configure_mspi_clk(clocks: &mut ClockTree, new_selector: MspiClkConfig) {
1687 let old_selector = clocks.mspi_clk.replace(new_selector);
1688 if clocks.mspi_clk_refcount > 0 {
1689 match new_selector {
1690 MspiClkConfig::CpuDiv2 => request_cpu_div2(clocks),
1691 MspiClkConfig::Cpu => request_cpu_clk(clocks),
1692 }
1693 configure_mspi_clk_impl(clocks, old_selector, new_selector);
1694 if let Some(old_selector) = old_selector {
1695 match old_selector {
1696 MspiClkConfig::CpuDiv2 => release_cpu_div2(clocks),
1697 MspiClkConfig::Cpu => release_cpu_clk(clocks),
1698 }
1699 }
1700 } else {
1701 configure_mspi_clk_impl(clocks, old_selector, new_selector);
1702 }
1703 }
1704 pub fn mspi_clk_config(clocks: &mut ClockTree) -> Option<MspiClkConfig> {
1705 clocks.mspi_clk
1706 }
1707 pub fn request_mspi_clk(clocks: &mut ClockTree) {
1708 trace!("Requesting MSPI_CLK");
1709 if increment_reference_count(&mut clocks.mspi_clk_refcount) {
1710 trace!("Enabling MSPI_CLK");
1711 match unwrap!(clocks.mspi_clk) {
1712 MspiClkConfig::CpuDiv2 => request_cpu_div2(clocks),
1713 MspiClkConfig::Cpu => request_cpu_clk(clocks),
1714 }
1715 enable_mspi_clk_impl(clocks, true);
1716 }
1717 }
1718 pub fn release_mspi_clk(clocks: &mut ClockTree) {
1719 trace!("Releasing MSPI_CLK");
1720 if decrement_reference_count(&mut clocks.mspi_clk_refcount) {
1721 trace!("Disabling MSPI_CLK");
1722 enable_mspi_clk_impl(clocks, false);
1723 match unwrap!(clocks.mspi_clk) {
1724 MspiClkConfig::CpuDiv2 => release_cpu_div2(clocks),
1725 MspiClkConfig::Cpu => release_cpu_clk(clocks),
1726 }
1727 }
1728 }
1729 #[allow(unused_variables)]
1730 pub fn mspi_clk_config_frequency(clocks: &mut ClockTree, config: MspiClkConfig) -> u32 {
1731 match config {
1732 MspiClkConfig::CpuDiv2 => cpu_div2_frequency(clocks),
1733 MspiClkConfig::Cpu => cpu_clk_frequency(clocks),
1734 }
1735 }
1736 pub fn mspi_clk_frequency(clocks: &mut ClockTree) -> u32 {
1737 if let Some(config) = clocks.mspi_clk {
1738 mspi_clk_config_frequency(clocks, config)
1739 } else {
1740 0
1741 }
1742 }
1743 pub fn configure_cpu_clk(clocks: &mut ClockTree, new_selector: CpuClkConfig) {
1744 let old_selector = clocks.cpu_clk.replace(new_selector);
1745 match new_selector {
1746 CpuClkConfig::Xtal => {
1747 configure_apb_clk(clocks, ApbClkConfig::Cpu);
1748 configure_crypto_clk(clocks, CryptoClkConfig::Cpu);
1749 configure_mspi_clk(clocks, MspiClkConfig::Cpu);
1750 configure_system_pre_div_in(clocks, SystemPreDivInConfig::Xtal);
1751 }
1752 CpuClkConfig::RcFast => {
1753 configure_apb_clk(clocks, ApbClkConfig::Cpu);
1754 configure_crypto_clk(clocks, CryptoClkConfig::Cpu);
1755 configure_mspi_clk(clocks, MspiClkConfig::Cpu);
1756 configure_system_pre_div_in(clocks, SystemPreDivInConfig::RcFast);
1757 }
1758 CpuClkConfig::Pll => {
1759 configure_apb_clk(clocks, ApbClkConfig::Pll40m);
1760 configure_crypto_clk(clocks, CryptoClkConfig::Pll80m);
1761 configure_mspi_clk(clocks, MspiClkConfig::CpuDiv2);
1762 }
1763 }
1764 match new_selector {
1765 CpuClkConfig::Xtal => request_system_pre_div(clocks),
1766 CpuClkConfig::RcFast => request_system_pre_div(clocks),
1767 CpuClkConfig::Pll => request_cpu_pll_div(clocks),
1768 }
1769 configure_cpu_clk_impl(clocks, old_selector, new_selector);
1770 if let Some(old_selector) = old_selector {
1771 match old_selector {
1772 CpuClkConfig::Xtal => release_system_pre_div(clocks),
1773 CpuClkConfig::RcFast => release_system_pre_div(clocks),
1774 CpuClkConfig::Pll => release_cpu_pll_div(clocks),
1775 }
1776 }
1777 }
1778 pub fn cpu_clk_config(clocks: &mut ClockTree) -> Option<CpuClkConfig> {
1779 clocks.cpu_clk
1780 }
1781 fn request_cpu_clk(_clocks: &mut ClockTree) {}
1782 fn release_cpu_clk(_clocks: &mut ClockTree) {}
1783 #[allow(unused_variables)]
1784 pub fn cpu_clk_config_frequency(clocks: &mut ClockTree, config: CpuClkConfig) -> u32 {
1785 match config {
1786 CpuClkConfig::Xtal => system_pre_div_frequency(clocks),
1787 CpuClkConfig::RcFast => system_pre_div_frequency(clocks),
1788 CpuClkConfig::Pll => cpu_pll_div_frequency(clocks),
1789 }
1790 }
1791 pub fn cpu_clk_frequency(clocks: &mut ClockTree) -> u32 {
1792 if let Some(config) = clocks.cpu_clk {
1793 cpu_clk_config_frequency(clocks, config)
1794 } else {
1795 0
1796 }
1797 }
1798 pub fn request_pll_40m(clocks: &mut ClockTree) {
1799 trace!("Requesting PLL_40M");
1800 if increment_reference_count(&mut clocks.pll_40m_refcount) {
1801 trace!("Enabling PLL_40M");
1802 request_cpu_clk(clocks);
1803 enable_pll_40m_impl(clocks, true);
1804 }
1805 }
1806 pub fn release_pll_40m(clocks: &mut ClockTree) {
1807 trace!("Releasing PLL_40M");
1808 if decrement_reference_count(&mut clocks.pll_40m_refcount) {
1809 trace!("Disabling PLL_40M");
1810 enable_pll_40m_impl(clocks, false);
1811 release_cpu_clk(clocks);
1812 }
1813 }
1814 pub fn pll_40m_frequency(clocks: &mut ClockTree) -> u32 {
1815 40000000
1816 }
1817 pub fn request_pll_60m(clocks: &mut ClockTree) {
1818 trace!("Requesting PLL_60M");
1819 if increment_reference_count(&mut clocks.pll_60m_refcount) {
1820 trace!("Enabling PLL_60M");
1821 request_cpu_clk(clocks);
1822 enable_pll_60m_impl(clocks, true);
1823 }
1824 }
1825 pub fn release_pll_60m(clocks: &mut ClockTree) {
1826 trace!("Releasing PLL_60M");
1827 if decrement_reference_count(&mut clocks.pll_60m_refcount) {
1828 trace!("Disabling PLL_60M");
1829 enable_pll_60m_impl(clocks, false);
1830 release_cpu_clk(clocks);
1831 }
1832 }
1833 pub fn pll_60m_frequency(clocks: &mut ClockTree) -> u32 {
1834 60000000
1835 }
1836 pub fn request_pll_80m(clocks: &mut ClockTree) {
1837 trace!("Requesting PLL_80M");
1838 trace!("Enabling PLL_80M");
1839 request_cpu_clk(clocks);
1840 enable_pll_80m_impl(clocks, true);
1841 }
1842 pub fn release_pll_80m(clocks: &mut ClockTree) {
1843 trace!("Releasing PLL_80M");
1844 trace!("Disabling PLL_80M");
1845 enable_pll_80m_impl(clocks, false);
1846 release_cpu_clk(clocks);
1847 }
1848 pub fn pll_80m_frequency(clocks: &mut ClockTree) -> u32 {
1849 80000000
1850 }
1851 pub fn request_cpu_div2(clocks: &mut ClockTree) {
1852 trace!("Requesting CPU_DIV2");
1853 trace!("Enabling CPU_DIV2");
1854 request_cpu_clk(clocks);
1855 enable_cpu_div2_impl(clocks, true);
1856 }
1857 pub fn release_cpu_div2(clocks: &mut ClockTree) {
1858 trace!("Releasing CPU_DIV2");
1859 trace!("Disabling CPU_DIV2");
1860 enable_cpu_div2_impl(clocks, false);
1861 release_cpu_clk(clocks);
1862 }
1863 pub fn cpu_div2_frequency(clocks: &mut ClockTree) -> u32 {
1864 (cpu_clk_frequency(clocks) / 2)
1865 }
1866 pub fn configure_rc_fast_clk_div_n(clocks: &mut ClockTree, config: RcFastClkDivNConfig) {
1867 let old_config = clocks.rc_fast_clk_div_n.replace(config);
1868 configure_rc_fast_clk_div_n_impl(clocks, old_config, config);
1869 }
1870 pub fn rc_fast_clk_div_n_config(clocks: &mut ClockTree) -> Option<RcFastClkDivNConfig> {
1871 clocks.rc_fast_clk_div_n
1872 }
1873 pub fn request_rc_fast_clk_div_n(clocks: &mut ClockTree) {
1874 trace!("Requesting RC_FAST_CLK_DIV_N");
1875 trace!("Enabling RC_FAST_CLK_DIV_N");
1876 request_rc_fast_clk(clocks);
1877 enable_rc_fast_clk_div_n_impl(clocks, true);
1878 }
1879 pub fn release_rc_fast_clk_div_n(clocks: &mut ClockTree) {
1880 trace!("Releasing RC_FAST_CLK_DIV_N");
1881 trace!("Disabling RC_FAST_CLK_DIV_N");
1882 enable_rc_fast_clk_div_n_impl(clocks, false);
1883 release_rc_fast_clk(clocks);
1884 }
1885 #[allow(unused_variables)]
1886 pub fn rc_fast_clk_div_n_config_frequency(
1887 clocks: &mut ClockTree,
1888 config: RcFastClkDivNConfig,
1889 ) -> u32 {
1890 (rc_fast_clk_frequency(clocks) / (config.divisor() + 1))
1891 }
1892 pub fn rc_fast_clk_div_n_frequency(clocks: &mut ClockTree) -> u32 {
1893 if let Some(config) = clocks.rc_fast_clk_div_n {
1894 rc_fast_clk_div_n_config_frequency(clocks, config)
1895 } else {
1896 0
1897 }
1898 }
1899 pub fn request_xtal_div_clk(clocks: &mut ClockTree) {
1900 trace!("Requesting XTAL_DIV_CLK");
1901 trace!("Enabling XTAL_DIV_CLK");
1902 request_xtal_clk(clocks);
1903 enable_xtal_div_clk_impl(clocks, true);
1904 }
1905 pub fn release_xtal_div_clk(clocks: &mut ClockTree) {
1906 trace!("Releasing XTAL_DIV_CLK");
1907 trace!("Disabling XTAL_DIV_CLK");
1908 enable_xtal_div_clk_impl(clocks, false);
1909 release_xtal_clk(clocks);
1910 }
1911 pub fn xtal_div_clk_frequency(clocks: &mut ClockTree) -> u32 {
1912 (xtal_clk_frequency(clocks) / 2)
1913 }
1914 pub fn configure_rtc_slow_clk(clocks: &mut ClockTree, new_selector: RtcSlowClkConfig) {
1915 let old_selector = clocks.rtc_slow_clk.replace(new_selector);
1916 match new_selector {
1917 RtcSlowClkConfig::OscSlow => request_osc_slow_clk(clocks),
1918 RtcSlowClkConfig::RcSlow => request_rc_slow_clk(clocks),
1919 RtcSlowClkConfig::RcFast => request_rc_fast_div_clk(clocks),
1920 }
1921 configure_rtc_slow_clk_impl(clocks, old_selector, new_selector);
1922 if let Some(old_selector) = old_selector {
1923 match old_selector {
1924 RtcSlowClkConfig::OscSlow => release_osc_slow_clk(clocks),
1925 RtcSlowClkConfig::RcSlow => release_rc_slow_clk(clocks),
1926 RtcSlowClkConfig::RcFast => release_rc_fast_div_clk(clocks),
1927 }
1928 }
1929 }
1930 pub fn rtc_slow_clk_config(clocks: &mut ClockTree) -> Option<RtcSlowClkConfig> {
1931 clocks.rtc_slow_clk
1932 }
1933 pub fn request_rtc_slow_clk(clocks: &mut ClockTree) {
1934 trace!("Requesting RTC_SLOW_CLK");
1935 trace!("Enabling RTC_SLOW_CLK");
1936 match unwrap!(clocks.rtc_slow_clk) {
1937 RtcSlowClkConfig::OscSlow => request_osc_slow_clk(clocks),
1938 RtcSlowClkConfig::RcSlow => request_rc_slow_clk(clocks),
1939 RtcSlowClkConfig::RcFast => request_rc_fast_div_clk(clocks),
1940 }
1941 enable_rtc_slow_clk_impl(clocks, true);
1942 }
1943 pub fn release_rtc_slow_clk(clocks: &mut ClockTree) {
1944 trace!("Releasing RTC_SLOW_CLK");
1945 trace!("Disabling RTC_SLOW_CLK");
1946 enable_rtc_slow_clk_impl(clocks, false);
1947 match unwrap!(clocks.rtc_slow_clk) {
1948 RtcSlowClkConfig::OscSlow => release_osc_slow_clk(clocks),
1949 RtcSlowClkConfig::RcSlow => release_rc_slow_clk(clocks),
1950 RtcSlowClkConfig::RcFast => release_rc_fast_div_clk(clocks),
1951 }
1952 }
1953 #[allow(unused_variables)]
1954 pub fn rtc_slow_clk_config_frequency(
1955 clocks: &mut ClockTree,
1956 config: RtcSlowClkConfig,
1957 ) -> u32 {
1958 match config {
1959 RtcSlowClkConfig::OscSlow => osc_slow_clk_frequency(clocks),
1960 RtcSlowClkConfig::RcSlow => rc_slow_clk_frequency(clocks),
1961 RtcSlowClkConfig::RcFast => rc_fast_div_clk_frequency(clocks),
1962 }
1963 }
1964 pub fn rtc_slow_clk_frequency(clocks: &mut ClockTree) -> u32 {
1965 if let Some(config) = clocks.rtc_slow_clk {
1966 rtc_slow_clk_config_frequency(clocks, config)
1967 } else {
1968 0
1969 }
1970 }
1971 pub fn configure_rtc_fast_clk(clocks: &mut ClockTree, new_selector: RtcFastClkConfig) {
1972 let old_selector = clocks.rtc_fast_clk.replace(new_selector);
1973 if clocks.rtc_fast_clk_refcount > 0 {
1974 match new_selector {
1975 RtcFastClkConfig::Xtal => request_xtal_div_clk(clocks),
1976 RtcFastClkConfig::Rc => request_rc_fast_clk_div_n(clocks),
1977 }
1978 configure_rtc_fast_clk_impl(clocks, old_selector, new_selector);
1979 if let Some(old_selector) = old_selector {
1980 match old_selector {
1981 RtcFastClkConfig::Xtal => release_xtal_div_clk(clocks),
1982 RtcFastClkConfig::Rc => release_rc_fast_clk_div_n(clocks),
1983 }
1984 }
1985 } else {
1986 configure_rtc_fast_clk_impl(clocks, old_selector, new_selector);
1987 }
1988 }
1989 pub fn rtc_fast_clk_config(clocks: &mut ClockTree) -> Option<RtcFastClkConfig> {
1990 clocks.rtc_fast_clk
1991 }
1992 pub fn request_rtc_fast_clk(clocks: &mut ClockTree) {
1993 trace!("Requesting RTC_FAST_CLK");
1994 if increment_reference_count(&mut clocks.rtc_fast_clk_refcount) {
1995 trace!("Enabling RTC_FAST_CLK");
1996 match unwrap!(clocks.rtc_fast_clk) {
1997 RtcFastClkConfig::Xtal => request_xtal_div_clk(clocks),
1998 RtcFastClkConfig::Rc => request_rc_fast_clk_div_n(clocks),
1999 }
2000 enable_rtc_fast_clk_impl(clocks, true);
2001 }
2002 }
2003 pub fn release_rtc_fast_clk(clocks: &mut ClockTree) {
2004 trace!("Releasing RTC_FAST_CLK");
2005 if decrement_reference_count(&mut clocks.rtc_fast_clk_refcount) {
2006 trace!("Disabling RTC_FAST_CLK");
2007 enable_rtc_fast_clk_impl(clocks, false);
2008 match unwrap!(clocks.rtc_fast_clk) {
2009 RtcFastClkConfig::Xtal => release_xtal_div_clk(clocks),
2010 RtcFastClkConfig::Rc => release_rc_fast_clk_div_n(clocks),
2011 }
2012 }
2013 }
2014 #[allow(unused_variables)]
2015 pub fn rtc_fast_clk_config_frequency(
2016 clocks: &mut ClockTree,
2017 config: RtcFastClkConfig,
2018 ) -> u32 {
2019 match config {
2020 RtcFastClkConfig::Xtal => xtal_div_clk_frequency(clocks),
2021 RtcFastClkConfig::Rc => rc_fast_clk_div_n_frequency(clocks),
2022 }
2023 }
2024 pub fn rtc_fast_clk_frequency(clocks: &mut ClockTree) -> u32 {
2025 if let Some(config) = clocks.rtc_fast_clk {
2026 rtc_fast_clk_config_frequency(clocks, config)
2027 } else {
2028 0
2029 }
2030 }
2031 pub fn configure_low_power_clk(clocks: &mut ClockTree, new_selector: LowPowerClkConfig) {
2032 let old_selector = clocks.low_power_clk.replace(new_selector);
2033 if clocks.low_power_clk_refcount > 0 {
2034 match new_selector {
2035 LowPowerClkConfig::Xtal => request_xtal_clk(clocks),
2036 LowPowerClkConfig::RcFast => request_rc_fast_clk(clocks),
2037 LowPowerClkConfig::OscSlow => request_osc_slow_clk(clocks),
2038 LowPowerClkConfig::RtcSlow => request_rtc_slow_clk(clocks),
2039 }
2040 configure_low_power_clk_impl(clocks, old_selector, new_selector);
2041 if let Some(old_selector) = old_selector {
2042 match old_selector {
2043 LowPowerClkConfig::Xtal => release_xtal_clk(clocks),
2044 LowPowerClkConfig::RcFast => release_rc_fast_clk(clocks),
2045 LowPowerClkConfig::OscSlow => release_osc_slow_clk(clocks),
2046 LowPowerClkConfig::RtcSlow => release_rtc_slow_clk(clocks),
2047 }
2048 }
2049 } else {
2050 configure_low_power_clk_impl(clocks, old_selector, new_selector);
2051 }
2052 }
2053 pub fn low_power_clk_config(clocks: &mut ClockTree) -> Option<LowPowerClkConfig> {
2054 clocks.low_power_clk
2055 }
2056 pub fn request_low_power_clk(clocks: &mut ClockTree) {
2057 trace!("Requesting LOW_POWER_CLK");
2058 if increment_reference_count(&mut clocks.low_power_clk_refcount) {
2059 trace!("Enabling LOW_POWER_CLK");
2060 match unwrap!(clocks.low_power_clk) {
2061 LowPowerClkConfig::Xtal => request_xtal_clk(clocks),
2062 LowPowerClkConfig::RcFast => request_rc_fast_clk(clocks),
2063 LowPowerClkConfig::OscSlow => request_osc_slow_clk(clocks),
2064 LowPowerClkConfig::RtcSlow => request_rtc_slow_clk(clocks),
2065 }
2066 enable_low_power_clk_impl(clocks, true);
2067 }
2068 }
2069 pub fn release_low_power_clk(clocks: &mut ClockTree) {
2070 trace!("Releasing LOW_POWER_CLK");
2071 if decrement_reference_count(&mut clocks.low_power_clk_refcount) {
2072 trace!("Disabling LOW_POWER_CLK");
2073 enable_low_power_clk_impl(clocks, false);
2074 match unwrap!(clocks.low_power_clk) {
2075 LowPowerClkConfig::Xtal => release_xtal_clk(clocks),
2076 LowPowerClkConfig::RcFast => release_rc_fast_clk(clocks),
2077 LowPowerClkConfig::OscSlow => release_osc_slow_clk(clocks),
2078 LowPowerClkConfig::RtcSlow => release_rtc_slow_clk(clocks),
2079 }
2080 }
2081 }
2082 #[allow(unused_variables)]
2083 pub fn low_power_clk_config_frequency(
2084 clocks: &mut ClockTree,
2085 config: LowPowerClkConfig,
2086 ) -> u32 {
2087 match config {
2088 LowPowerClkConfig::Xtal => xtal_clk_frequency(clocks),
2089 LowPowerClkConfig::RcFast => rc_fast_clk_frequency(clocks),
2090 LowPowerClkConfig::OscSlow => osc_slow_clk_frequency(clocks),
2091 LowPowerClkConfig::RtcSlow => rtc_slow_clk_frequency(clocks),
2092 }
2093 }
2094 pub fn low_power_clk_frequency(clocks: &mut ClockTree) -> u32 {
2095 if let Some(config) = clocks.low_power_clk {
2096 low_power_clk_config_frequency(clocks, config)
2097 } else {
2098 0
2099 }
2100 }
2101 pub fn request_uart_mem_clk(clocks: &mut ClockTree) {
2102 trace!("Requesting UART_MEM_CLK");
2103 if increment_reference_count(&mut clocks.uart_mem_clk_refcount) {
2104 trace!("Enabling UART_MEM_CLK");
2105 request_xtal_clk(clocks);
2106 enable_uart_mem_clk_impl(clocks, true);
2107 }
2108 }
2109 pub fn release_uart_mem_clk(clocks: &mut ClockTree) {
2110 trace!("Releasing UART_MEM_CLK");
2111 if decrement_reference_count(&mut clocks.uart_mem_clk_refcount) {
2112 trace!("Disabling UART_MEM_CLK");
2113 enable_uart_mem_clk_impl(clocks, false);
2114 release_xtal_clk(clocks);
2115 }
2116 }
2117 pub fn uart_mem_clk_frequency(clocks: &mut ClockTree) -> u32 {
2118 xtal_clk_frequency(clocks)
2119 }
2120 pub fn configure_timg_calibration_clock(
2121 clocks: &mut ClockTree,
2122 new_selector: TimgCalibrationClockConfig,
2123 ) {
2124 let old_selector = clocks.timg_calibration_clock.replace(new_selector);
2125 if clocks.timg_calibration_clock_refcount > 0 {
2126 match new_selector {
2127 TimgCalibrationClockConfig::RcSlowClk => request_rc_slow_clk(clocks),
2128 TimgCalibrationClockConfig::RcFastDivClk => request_rc_fast_div_clk(clocks),
2129 TimgCalibrationClockConfig::Osc32kClk => request_osc_slow_clk(clocks),
2130 }
2131 configure_timg_calibration_clock_impl(clocks, old_selector, new_selector);
2132 if let Some(old_selector) = old_selector {
2133 match old_selector {
2134 TimgCalibrationClockConfig::RcSlowClk => release_rc_slow_clk(clocks),
2135 TimgCalibrationClockConfig::RcFastDivClk => release_rc_fast_div_clk(clocks),
2136 TimgCalibrationClockConfig::Osc32kClk => release_osc_slow_clk(clocks),
2137 }
2138 }
2139 } else {
2140 configure_timg_calibration_clock_impl(clocks, old_selector, new_selector);
2141 }
2142 }
2143 pub fn timg_calibration_clock_config(
2144 clocks: &mut ClockTree,
2145 ) -> Option<TimgCalibrationClockConfig> {
2146 clocks.timg_calibration_clock
2147 }
2148 pub fn request_timg_calibration_clock(clocks: &mut ClockTree) {
2149 trace!("Requesting TIMG_CALIBRATION_CLOCK");
2150 if increment_reference_count(&mut clocks.timg_calibration_clock_refcount) {
2151 trace!("Enabling TIMG_CALIBRATION_CLOCK");
2152 match unwrap!(clocks.timg_calibration_clock) {
2153 TimgCalibrationClockConfig::RcSlowClk => request_rc_slow_clk(clocks),
2154 TimgCalibrationClockConfig::RcFastDivClk => request_rc_fast_div_clk(clocks),
2155 TimgCalibrationClockConfig::Osc32kClk => request_osc_slow_clk(clocks),
2156 }
2157 enable_timg_calibration_clock_impl(clocks, true);
2158 }
2159 }
2160 pub fn release_timg_calibration_clock(clocks: &mut ClockTree) {
2161 trace!("Releasing TIMG_CALIBRATION_CLOCK");
2162 if decrement_reference_count(&mut clocks.timg_calibration_clock_refcount) {
2163 trace!("Disabling TIMG_CALIBRATION_CLOCK");
2164 enable_timg_calibration_clock_impl(clocks, false);
2165 match unwrap!(clocks.timg_calibration_clock) {
2166 TimgCalibrationClockConfig::RcSlowClk => release_rc_slow_clk(clocks),
2167 TimgCalibrationClockConfig::RcFastDivClk => release_rc_fast_div_clk(clocks),
2168 TimgCalibrationClockConfig::Osc32kClk => release_osc_slow_clk(clocks),
2169 }
2170 }
2171 }
2172 #[allow(unused_variables)]
2173 pub fn timg_calibration_clock_config_frequency(
2174 clocks: &mut ClockTree,
2175 config: TimgCalibrationClockConfig,
2176 ) -> u32 {
2177 match config {
2178 TimgCalibrationClockConfig::RcSlowClk => rc_slow_clk_frequency(clocks),
2179 TimgCalibrationClockConfig::RcFastDivClk => rc_fast_div_clk_frequency(clocks),
2180 TimgCalibrationClockConfig::Osc32kClk => osc_slow_clk_frequency(clocks),
2181 }
2182 }
2183 pub fn timg_calibration_clock_frequency(clocks: &mut ClockTree) -> u32 {
2184 if let Some(config) = clocks.timg_calibration_clock {
2185 timg_calibration_clock_config_frequency(clocks, config)
2186 } else {
2187 0
2188 }
2189 }
2190 impl TimgInstance {
2191 pub fn configure_function_clock(
2192 self,
2193 clocks: &mut ClockTree,
2194 new_selector: TimgFunctionClockConfig,
2195 ) {
2196 let old_selector = clocks.timg_function_clock[self as usize].replace(new_selector);
2197 if clocks.timg_function_clock_refcount[self as usize] > 0 {
2198 match new_selector {
2199 TimgFunctionClockConfig::XtalClk => request_xtal_clk(clocks),
2200 TimgFunctionClockConfig::Pll40m => request_pll_40m(clocks),
2201 }
2202 self.configure_function_clock_impl(clocks, old_selector, new_selector);
2203 if let Some(old_selector) = old_selector {
2204 match old_selector {
2205 TimgFunctionClockConfig::XtalClk => release_xtal_clk(clocks),
2206 TimgFunctionClockConfig::Pll40m => release_pll_40m(clocks),
2207 }
2208 }
2209 } else {
2210 self.configure_function_clock_impl(clocks, old_selector, new_selector);
2211 }
2212 }
2213 pub fn function_clock_config(
2214 self,
2215 clocks: &mut ClockTree,
2216 ) -> Option<TimgFunctionClockConfig> {
2217 clocks.timg_function_clock[self as usize]
2218 }
2219 pub fn request_function_clock(self, clocks: &mut ClockTree) {
2220 trace!("Requesting {:?}::FUNCTION_CLOCK", self);
2221 if increment_reference_count(
2222 &mut clocks.timg_function_clock_refcount[self as usize],
2223 ) {
2224 trace!("Enabling {:?}::FUNCTION_CLOCK", self);
2225 match unwrap!(clocks.timg_function_clock[self as usize]) {
2226 TimgFunctionClockConfig::XtalClk => request_xtal_clk(clocks),
2227 TimgFunctionClockConfig::Pll40m => request_pll_40m(clocks),
2228 }
2229 self.enable_function_clock_impl(clocks, true);
2230 }
2231 }
2232 pub fn release_function_clock(self, clocks: &mut ClockTree) {
2233 trace!("Releasing {:?}::FUNCTION_CLOCK", self);
2234 if decrement_reference_count(
2235 &mut clocks.timg_function_clock_refcount[self as usize],
2236 ) {
2237 trace!("Disabling {:?}::FUNCTION_CLOCK", self);
2238 self.enable_function_clock_impl(clocks, false);
2239 match unwrap!(clocks.timg_function_clock[self as usize]) {
2240 TimgFunctionClockConfig::XtalClk => release_xtal_clk(clocks),
2241 TimgFunctionClockConfig::Pll40m => release_pll_40m(clocks),
2242 }
2243 }
2244 }
2245 #[allow(unused_variables)]
2246 pub fn function_clock_config_frequency(
2247 self,
2248 clocks: &mut ClockTree,
2249 config: TimgFunctionClockConfig,
2250 ) -> u32 {
2251 match config {
2252 TimgFunctionClockConfig::XtalClk => xtal_clk_frequency(clocks),
2253 TimgFunctionClockConfig::Pll40m => pll_40m_frequency(clocks),
2254 }
2255 }
2256 pub fn function_clock_frequency(self, clocks: &mut ClockTree) -> u32 {
2257 if let Some(config) = clocks.timg_function_clock[self as usize] {
2258 self.function_clock_config_frequency(clocks, config)
2259 } else {
2260 0
2261 }
2262 }
2263 pub fn configure_wdt_clock(
2264 self,
2265 clocks: &mut ClockTree,
2266 new_selector: TimgWdtClockConfig,
2267 ) {
2268 let old_selector = clocks.timg_wdt_clock[self as usize].replace(new_selector);
2269 if clocks.timg_wdt_clock_refcount[self as usize] > 0 {
2270 match new_selector {
2271 TimgWdtClockConfig::Pll40m => request_pll_40m(clocks),
2272 TimgWdtClockConfig::XtalClk => request_xtal_clk(clocks),
2273 }
2274 self.configure_wdt_clock_impl(clocks, old_selector, new_selector);
2275 if let Some(old_selector) = old_selector {
2276 match old_selector {
2277 TimgWdtClockConfig::Pll40m => release_pll_40m(clocks),
2278 TimgWdtClockConfig::XtalClk => release_xtal_clk(clocks),
2279 }
2280 }
2281 } else {
2282 self.configure_wdt_clock_impl(clocks, old_selector, new_selector);
2283 }
2284 }
2285 pub fn wdt_clock_config(self, clocks: &mut ClockTree) -> Option<TimgWdtClockConfig> {
2286 clocks.timg_wdt_clock[self as usize]
2287 }
2288 pub fn request_wdt_clock(self, clocks: &mut ClockTree) {
2289 trace!("Requesting {:?}::WDT_CLOCK", self);
2290 if increment_reference_count(&mut clocks.timg_wdt_clock_refcount[self as usize]) {
2291 trace!("Enabling {:?}::WDT_CLOCK", self);
2292 match unwrap!(clocks.timg_wdt_clock[self as usize]) {
2293 TimgWdtClockConfig::Pll40m => request_pll_40m(clocks),
2294 TimgWdtClockConfig::XtalClk => request_xtal_clk(clocks),
2295 }
2296 self.enable_wdt_clock_impl(clocks, true);
2297 }
2298 }
2299 pub fn release_wdt_clock(self, clocks: &mut ClockTree) {
2300 trace!("Releasing {:?}::WDT_CLOCK", self);
2301 if decrement_reference_count(&mut clocks.timg_wdt_clock_refcount[self as usize]) {
2302 trace!("Disabling {:?}::WDT_CLOCK", self);
2303 self.enable_wdt_clock_impl(clocks, false);
2304 match unwrap!(clocks.timg_wdt_clock[self as usize]) {
2305 TimgWdtClockConfig::Pll40m => release_pll_40m(clocks),
2306 TimgWdtClockConfig::XtalClk => release_xtal_clk(clocks),
2307 }
2308 }
2309 }
2310 #[allow(unused_variables)]
2311 pub fn wdt_clock_config_frequency(
2312 self,
2313 clocks: &mut ClockTree,
2314 config: TimgWdtClockConfig,
2315 ) -> u32 {
2316 match config {
2317 TimgWdtClockConfig::Pll40m => pll_40m_frequency(clocks),
2318 TimgWdtClockConfig::XtalClk => xtal_clk_frequency(clocks),
2319 }
2320 }
2321 pub fn wdt_clock_frequency(self, clocks: &mut ClockTree) -> u32 {
2322 if let Some(config) = clocks.timg_wdt_clock[self as usize] {
2323 self.wdt_clock_config_frequency(clocks, config)
2324 } else {
2325 0
2326 }
2327 }
2328 }
2329 impl UartInstance {
2330 pub fn configure_function_clock(
2331 self,
2332 clocks: &mut ClockTree,
2333 config: UartFunctionClockConfig,
2334 ) {
2335 let old_config = clocks.uart_function_clock[self as usize].replace(config);
2336 if clocks.uart_function_clock_refcount[self as usize] > 0 {
2337 match config.sclk {
2338 UartFunctionClockSclk::PllF40m => request_pll_40m(clocks),
2339 UartFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
2340 UartFunctionClockSclk::Xtal => request_xtal_clk(clocks),
2341 }
2342 self.configure_function_clock_impl(clocks, old_config, config);
2343 if let Some(old_config) = old_config {
2344 match old_config.sclk {
2345 UartFunctionClockSclk::PllF40m => release_pll_40m(clocks),
2346 UartFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
2347 UartFunctionClockSclk::Xtal => release_xtal_clk(clocks),
2348 }
2349 }
2350 } else {
2351 self.configure_function_clock_impl(clocks, old_config, config);
2352 }
2353 }
2354 pub fn function_clock_config(
2355 self,
2356 clocks: &mut ClockTree,
2357 ) -> Option<UartFunctionClockConfig> {
2358 clocks.uart_function_clock[self as usize]
2359 }
2360 pub fn request_function_clock(self, clocks: &mut ClockTree) {
2361 trace!("Requesting {:?}::FUNCTION_CLOCK", self);
2362 if increment_reference_count(
2363 &mut clocks.uart_function_clock_refcount[self as usize],
2364 ) {
2365 trace!("Enabling {:?}::FUNCTION_CLOCK", self);
2366 match unwrap!(clocks.uart_function_clock[self as usize]).sclk {
2367 UartFunctionClockSclk::PllF40m => request_pll_40m(clocks),
2368 UartFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
2369 UartFunctionClockSclk::Xtal => request_xtal_clk(clocks),
2370 }
2371 self.enable_function_clock_impl(clocks, true);
2372 }
2373 }
2374 pub fn release_function_clock(self, clocks: &mut ClockTree) {
2375 trace!("Releasing {:?}::FUNCTION_CLOCK", self);
2376 if decrement_reference_count(
2377 &mut clocks.uart_function_clock_refcount[self as usize],
2378 ) {
2379 trace!("Disabling {:?}::FUNCTION_CLOCK", self);
2380 self.enable_function_clock_impl(clocks, false);
2381 match unwrap!(clocks.uart_function_clock[self as usize]).sclk {
2382 UartFunctionClockSclk::PllF40m => release_pll_40m(clocks),
2383 UartFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
2384 UartFunctionClockSclk::Xtal => release_xtal_clk(clocks),
2385 }
2386 }
2387 }
2388 #[allow(unused_variables)]
2389 pub fn function_clock_config_frequency(
2390 self,
2391 clocks: &mut ClockTree,
2392 config: UartFunctionClockConfig,
2393 ) -> u32 {
2394 (match config.sclk {
2395 UartFunctionClockSclk::PllF40m => pll_40m_frequency(clocks),
2396 UartFunctionClockSclk::RcFast => rc_fast_clk_frequency(clocks),
2397 UartFunctionClockSclk::Xtal => xtal_clk_frequency(clocks),
2398 } / (config.div_num() + 1))
2399 }
2400 pub fn function_clock_frequency(self, clocks: &mut ClockTree) -> u32 {
2401 if let Some(config) = clocks.uart_function_clock[self as usize] {
2402 self.function_clock_config_frequency(clocks, config)
2403 } else {
2404 0
2405 }
2406 }
2407 pub fn configure_mem_clock(self, clocks: &mut ClockTree, config: UartMemClockConfig) {
2408 let old_config = clocks.uart_mem_clock[self as usize].replace(config);
2409 self.configure_mem_clock_impl(clocks, old_config, config);
2410 }
2411 pub fn mem_clock_config(self, clocks: &mut ClockTree) -> Option<UartMemClockConfig> {
2412 clocks.uart_mem_clock[self as usize]
2413 }
2414 pub fn request_mem_clock(self, clocks: &mut ClockTree) {
2415 trace!("Requesting {:?}::MEM_CLOCK", self);
2416 if increment_reference_count(&mut clocks.uart_mem_clock_refcount[self as usize]) {
2417 trace!("Enabling {:?}::MEM_CLOCK", self);
2418 request_uart_mem_clk(clocks);
2419 self.enable_mem_clock_impl(clocks, true);
2420 }
2421 }
2422 pub fn release_mem_clock(self, clocks: &mut ClockTree) {
2423 trace!("Releasing {:?}::MEM_CLOCK", self);
2424 if decrement_reference_count(&mut clocks.uart_mem_clock_refcount[self as usize]) {
2425 trace!("Disabling {:?}::MEM_CLOCK", self);
2426 self.enable_mem_clock_impl(clocks, false);
2427 release_uart_mem_clk(clocks);
2428 }
2429 }
2430 #[allow(unused_variables)]
2431 pub fn mem_clock_config_frequency(
2432 self,
2433 clocks: &mut ClockTree,
2434 config: UartMemClockConfig,
2435 ) -> u32 {
2436 uart_mem_clk_frequency(clocks)
2437 }
2438 pub fn mem_clock_frequency(self, clocks: &mut ClockTree) -> u32 {
2439 if let Some(config) = clocks.uart_mem_clock[self as usize] {
2440 self.mem_clock_config_frequency(clocks, config)
2441 } else {
2442 0
2443 }
2444 }
2445 pub fn configure_baud_rate_generator(
2446 self,
2447 clocks: &mut ClockTree,
2448 config: UartBaudRateGeneratorConfig,
2449 ) {
2450 let old_config = clocks.uart_baud_rate_generator[self as usize].replace(config);
2451 self.configure_baud_rate_generator_impl(clocks, old_config, config);
2452 }
2453 pub fn baud_rate_generator_config(
2454 self,
2455 clocks: &mut ClockTree,
2456 ) -> Option<UartBaudRateGeneratorConfig> {
2457 clocks.uart_baud_rate_generator[self as usize]
2458 }
2459 pub fn request_baud_rate_generator(self, clocks: &mut ClockTree) {
2460 trace!("Requesting {:?}::BAUD_RATE_GENERATOR", self);
2461 if increment_reference_count(
2462 &mut clocks.uart_baud_rate_generator_refcount[self as usize],
2463 ) {
2464 trace!("Enabling {:?}::BAUD_RATE_GENERATOR", self);
2465 self.request_function_clock(clocks);
2466 self.enable_baud_rate_generator_impl(clocks, true);
2467 }
2468 }
2469 pub fn release_baud_rate_generator(self, clocks: &mut ClockTree) {
2470 trace!("Releasing {:?}::BAUD_RATE_GENERATOR", self);
2471 if decrement_reference_count(
2472 &mut clocks.uart_baud_rate_generator_refcount[self as usize],
2473 ) {
2474 trace!("Disabling {:?}::BAUD_RATE_GENERATOR", self);
2475 self.enable_baud_rate_generator_impl(clocks, false);
2476 self.release_function_clock(clocks);
2477 }
2478 }
2479 #[allow(unused_variables)]
2480 pub fn baud_rate_generator_config_frequency(
2481 self,
2482 clocks: &mut ClockTree,
2483 config: UartBaudRateGeneratorConfig,
2484 ) -> u32 {
2485 ((self.function_clock_frequency(clocks) * 16)
2486 / ((config.integral() * 16) + config.fractional()))
2487 }
2488 pub fn baud_rate_generator_frequency(self, clocks: &mut ClockTree) -> u32 {
2489 if let Some(config) = clocks.uart_baud_rate_generator[self as usize] {
2490 self.baud_rate_generator_config_frequency(clocks, config)
2491 } else {
2492 0
2493 }
2494 }
2495 }
2496 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2504 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
2505 #[instability::unstable]
2506 pub struct ClockConfig {
2507 pub xtal_clk: Option<XtalClkConfig>,
2509 pub system_pre_div: Option<SystemPreDivConfig>,
2511 pub cpu_pll_div: Option<CpuPllDivConfig>,
2513 pub cpu_clk: Option<CpuClkConfig>,
2515 pub rc_fast_clk_div_n: Option<RcFastClkDivNConfig>,
2517 pub rtc_slow_clk: Option<RtcSlowClkConfig>,
2519 pub rtc_fast_clk: Option<RtcFastClkConfig>,
2521 pub low_power_clk: Option<LowPowerClkConfig>,
2523 pub timg_calibration_clock: Option<TimgCalibrationClockConfig>,
2525 }
2526 impl ClockConfig {
2527 fn apply(&self) {
2528 ClockTree::with(|clocks| {
2529 if let Some(config) = self.xtal_clk {
2530 configure_xtal_clk(clocks, config);
2531 }
2532 if let Some(config) = self.system_pre_div {
2533 configure_system_pre_div(clocks, config);
2534 }
2535 if let Some(config) = self.cpu_pll_div {
2536 configure_cpu_pll_div(clocks, config);
2537 }
2538 if let Some(config) = self.cpu_clk {
2539 configure_cpu_clk(clocks, config);
2540 }
2541 if let Some(config) = self.rc_fast_clk_div_n {
2542 configure_rc_fast_clk_div_n(clocks, config);
2543 }
2544 if let Some(config) = self.rtc_slow_clk {
2545 configure_rtc_slow_clk(clocks, config);
2546 }
2547 if let Some(config) = self.rtc_fast_clk {
2548 configure_rtc_fast_clk(clocks, config);
2549 }
2550 if let Some(config) = self.low_power_clk {
2551 configure_low_power_clk(clocks, config);
2552 }
2553 if let Some(config) = self.timg_calibration_clock {
2554 configure_timg_calibration_clock(clocks, config);
2555 }
2556 });
2557 }
2558 }
2559 fn increment_reference_count(refcount: &mut u32) -> bool {
2560 let first = *refcount == 0;
2561 *refcount = unwrap!(refcount.checked_add(1), "Reference count overflow");
2562 first
2563 }
2564 fn decrement_reference_count(refcount: &mut u32) -> bool {
2565 *refcount = refcount.saturating_sub(1);
2566 let last = *refcount == 0;
2567 last
2568 }
2569 };
2570}
2571#[macro_export]
2575#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
2576macro_rules! implement_peripheral_clocks {
2577 () => {
2578 #[doc(hidden)]
2579 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2580 #[repr(u8)]
2581 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
2582 pub enum Peripheral {
2583 ApbSarAdc,
2585 Dma,
2587 Ecc,
2589 I2cExt0,
2591 Ledc,
2593 Sha,
2595 Spi2,
2597 Systimer,
2599 Timg0,
2601 Tsens,
2603 Uart0,
2605 Uart1,
2607 UartMem,
2609 }
2610 impl Peripheral {
2611 const KEEP_ENABLED: &[Peripheral] =
2612 &[Self::Systimer, Self::Timg0, Self::Uart0, Self::UartMem];
2613 const COUNT: usize = Self::ALL.len();
2614 const ALL: &[Self] = &[
2615 Self::ApbSarAdc,
2616 Self::Dma,
2617 Self::Ecc,
2618 Self::I2cExt0,
2619 Self::Ledc,
2620 Self::Sha,
2621 Self::Spi2,
2622 Self::Systimer,
2623 Self::Timg0,
2624 Self::Tsens,
2625 Self::Uart0,
2626 Self::Uart1,
2627 Self::UartMem,
2628 ];
2629 }
2630 unsafe fn enable_internal_racey(peripheral: Peripheral, enable: bool) {
2631 match peripheral {
2632 Peripheral::ApbSarAdc => {
2633 crate::peripherals::SYSTEM::regs()
2634 .perip_clk_en0()
2635 .modify(|_, w| w.apb_saradc_clk_en().bit(enable));
2636 }
2637 Peripheral::Dma => {
2638 crate::peripherals::SYSTEM::regs()
2639 .perip_clk_en1()
2640 .modify(|_, w| w.dma_clk_en().bit(enable));
2641 }
2642 Peripheral::Ecc => {
2643 crate::peripherals::SYSTEM::regs()
2644 .perip_clk_en1()
2645 .modify(|_, w| w.crypto_ecc_clk_en().bit(enable));
2646 }
2647 Peripheral::I2cExt0 => {
2648 crate::peripherals::SYSTEM::regs()
2649 .perip_clk_en0()
2650 .modify(|_, w| w.i2c_ext0_clk_en().bit(enable));
2651 }
2652 Peripheral::Ledc => {
2653 crate::peripherals::SYSTEM::regs()
2654 .perip_clk_en0()
2655 .modify(|_, w| w.ledc_clk_en().bit(enable));
2656 }
2657 Peripheral::Sha => {
2658 crate::peripherals::SYSTEM::regs()
2659 .perip_clk_en1()
2660 .modify(|_, w| w.crypto_sha_clk_en().bit(enable));
2661 }
2662 Peripheral::Spi2 => {
2663 crate::peripherals::SYSTEM::regs()
2664 .perip_clk_en0()
2665 .modify(|_, w| w.spi2_clk_en().bit(enable));
2666 }
2667 Peripheral::Systimer => {
2668 crate::peripherals::SYSTEM::regs()
2669 .perip_clk_en0()
2670 .modify(|_, w| w.systimer_clk_en().bit(enable));
2671 }
2672 Peripheral::Timg0 => {
2673 crate::peripherals::SYSTEM::regs()
2674 .perip_clk_en0()
2675 .modify(|_, w| w.timergroup_clk_en().bit(enable));
2676 }
2677 Peripheral::Tsens => {
2678 crate::peripherals::SYSTEM::regs()
2679 .perip_clk_en1()
2680 .modify(|_, w| w.tsens_clk_en().bit(enable));
2681 }
2682 Peripheral::Uart0 => {
2683 crate::peripherals::SYSTEM::regs()
2684 .perip_clk_en0()
2685 .modify(|_, w| w.uart_clk_en().bit(enable));
2686 }
2687 Peripheral::Uart1 => {
2688 crate::peripherals::SYSTEM::regs()
2689 .perip_clk_en0()
2690 .modify(|_, w| w.uart1_clk_en().bit(enable));
2691 }
2692 Peripheral::UartMem => {
2693 crate::peripherals::SYSTEM::regs()
2694 .perip_clk_en0()
2695 .modify(|_, w| w.uart_mem_clk_en().bit(enable));
2696 }
2697 }
2698 }
2699 unsafe fn assert_peri_reset_racey(peripheral: Peripheral, reset: bool) {
2700 match peripheral {
2701 Peripheral::ApbSarAdc => {
2702 crate::peripherals::SYSTEM::regs()
2703 .perip_rst_en0()
2704 .modify(|_, w| w.apb_saradc_rst().bit(reset));
2705 }
2706 Peripheral::Dma => {
2707 crate::peripherals::SYSTEM::regs()
2708 .perip_rst_en1()
2709 .modify(|_, w| w.dma_rst().bit(reset));
2710 }
2711 Peripheral::Ecc => {
2712 crate::peripherals::SYSTEM::regs()
2713 .perip_rst_en1()
2714 .modify(|_, w| w.crypto_ecc_rst().bit(reset));
2715 }
2716 Peripheral::I2cExt0 => {
2717 crate::peripherals::SYSTEM::regs()
2718 .perip_rst_en0()
2719 .modify(|_, w| w.i2c_ext0_rst().bit(reset));
2720 }
2721 Peripheral::Ledc => {
2722 crate::peripherals::SYSTEM::regs()
2723 .perip_rst_en0()
2724 .modify(|_, w| w.ledc_rst().bit(reset));
2725 }
2726 Peripheral::Sha => {
2727 crate::peripherals::SYSTEM::regs()
2728 .perip_rst_en1()
2729 .modify(|_, w| w.crypto_sha_rst().bit(reset));
2730 }
2731 Peripheral::Spi2 => {
2732 crate::peripherals::SYSTEM::regs()
2733 .perip_rst_en0()
2734 .modify(|_, w| w.spi2_rst().bit(reset));
2735 }
2736 Peripheral::Systimer => {
2737 crate::peripherals::SYSTEM::regs()
2738 .perip_rst_en0()
2739 .modify(|_, w| w.systimer_rst().bit(reset));
2740 }
2741 Peripheral::Timg0 => {
2742 crate::peripherals::SYSTEM::regs()
2743 .perip_rst_en0()
2744 .modify(|_, w| w.timergroup_rst().bit(reset));
2745 }
2746 Peripheral::Tsens => {
2747 crate::peripherals::SYSTEM::regs()
2748 .perip_rst_en1()
2749 .modify(|_, w| w.tsens_rst().bit(reset));
2750 }
2751 Peripheral::Uart0 => {
2752 crate::peripherals::SYSTEM::regs()
2753 .perip_rst_en0()
2754 .modify(|_, w| w.uart_rst().bit(reset));
2755 }
2756 Peripheral::Uart1 => {
2757 crate::peripherals::SYSTEM::regs()
2758 .perip_rst_en0()
2759 .modify(|_, w| w.uart1_rst().bit(reset));
2760 }
2761 Peripheral::UartMem => {
2762 crate::peripherals::SYSTEM::regs()
2763 .perip_rst_en0()
2764 .modify(|_, w| w.uart_mem_rst().bit(reset));
2765 }
2766 }
2767 }
2768 };
2769}
2770#[macro_export]
2778#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
2779macro_rules! memory_range {
2780 ("DRAM") => {
2781 0x3FCA0000..0x3FCE0000
2782 };
2783 (size as str, "DRAM") => {
2784 "262144"
2785 };
2786 ("DRAM2_UNINIT") => {
2787 0x3FCCE800..0x3FCDEB70
2788 };
2789 (size as str, "DRAM2_UNINIT") => {
2790 "66416"
2791 };
2792}
2793#[macro_export]
2810#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
2811macro_rules! for_each_i2c_master {
2812 ($($pattern:tt => $code:tt;)*) => {
2813 macro_rules! _for_each_inner_i2c_master { $(($pattern) => $code;)* ($other : tt)
2814 => {} } _for_each_inner_i2c_master!((0, I2C0, I2cExt0, I2CEXT0_SCL,
2815 I2CEXT0_SDA)); _for_each_inner_i2c_master!((all(0, I2C0, I2cExt0, I2CEXT0_SCL,
2816 I2CEXT0_SDA)));
2817 };
2818}
2819#[macro_export]
2838#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
2839macro_rules! for_each_uart {
2840 ($($pattern:tt => $code:tt;)*) => {
2841 macro_rules! _for_each_inner_uart { $(($pattern) => $code;)* ($other : tt) => {}
2842 } _for_each_inner_uart!((0, UART0, Uart0, U0RXD, U0TXD, U0CTS, U0RTS));
2843 _for_each_inner_uart!((1, UART1, Uart1, U1RXD, U1TXD, U1CTS, U1RTS));
2844 _for_each_inner_uart!((all(0, UART0, Uart0, U0RXD, U0TXD, U0CTS, U0RTS), (1,
2845 UART1, Uart1, U1RXD, U1TXD, U1CTS, U1RTS)));
2846 };
2847}
2848#[macro_export]
2870#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
2871macro_rules! for_each_spi_master {
2872 ($($pattern:tt => $code:tt;)*) => {
2873 macro_rules! _for_each_inner_spi_master { $(($pattern) => $code;)* ($other : tt)
2874 => {} } _for_each_inner_spi_master!((SPI2, Spi2, FSPICLK[FSPICS0, FSPICS1,
2875 FSPICS2, FSPICS3, FSPICS4, FSPICS5] [FSPID, FSPIQ, FSPIWP, FSPIHD], true));
2876 _for_each_inner_spi_master!((all(SPI2, Spi2, FSPICLK[FSPICS0, FSPICS1, FSPICS2,
2877 FSPICS3, FSPICS4, FSPICS5] [FSPID, FSPIQ, FSPIWP, FSPIHD], true)));
2878 };
2879}
2880#[macro_export]
2897#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
2898macro_rules! for_each_spi_slave {
2899 ($($pattern:tt => $code:tt;)*) => {
2900 macro_rules! _for_each_inner_spi_slave { $(($pattern) => $code;)* ($other : tt)
2901 => {} } _for_each_inner_spi_slave!((SPI2, Spi2, FSPICLK, FSPID, FSPIQ, FSPICS0));
2902 _for_each_inner_spi_slave!((all(SPI2, Spi2, FSPICLK, FSPID, FSPIQ, FSPICS0)));
2903 };
2904}
2905#[macro_export]
2906#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
2907macro_rules! for_each_peripheral {
2908 ($($pattern:tt => $code:tt;)*) => {
2909 macro_rules! _for_each_inner_peripheral { $(($pattern) => $code;)* ($other : tt)
2910 => {} } _for_each_inner_peripheral!((@ peri_type #[doc =
2911 "GPIO0 peripheral singleton"] GPIO0 <= virtual()));
2912 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO1 peripheral singleton"]
2913 GPIO1 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
2914 "GPIO2 peripheral singleton"] GPIO2 <= virtual()));
2915 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO3 peripheral singleton"]
2916 GPIO3 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
2917 "GPIO4 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
2918 "<section class=\"warning\">"] #[doc =
2919 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
2920 #[doc = "<ul>"] #[doc =
2921 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
2922 #[doc = "</ul>"] #[doc = "</section>"] GPIO4 <= virtual()));
2923 _for_each_inner_peripheral!((@ peri_type #[doc =
2924 "GPIO5 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
2925 "<section class=\"warning\">"] #[doc =
2926 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
2927 #[doc = "<ul>"] #[doc =
2928 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
2929 #[doc = "</ul>"] #[doc = "</section>"] GPIO5 <= virtual()));
2930 _for_each_inner_peripheral!((@ peri_type #[doc =
2931 "GPIO6 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
2932 "<section class=\"warning\">"] #[doc =
2933 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
2934 #[doc = "<ul>"] #[doc =
2935 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
2936 #[doc = "</ul>"] #[doc = "</section>"] GPIO6 <= virtual()));
2937 _for_each_inner_peripheral!((@ peri_type #[doc =
2938 "GPIO7 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
2939 "<section class=\"warning\">"] #[doc =
2940 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
2941 #[doc = "<ul>"] #[doc =
2942 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
2943 #[doc = "</ul>"] #[doc = "</section>"] GPIO7 <= virtual()));
2944 _for_each_inner_peripheral!((@ peri_type #[doc =
2945 "GPIO8 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
2946 "<section class=\"warning\">"] #[doc =
2947 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
2948 #[doc = "<ul>"] #[doc =
2949 "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
2950 = "</ul>"] #[doc = "</section>"] GPIO8 <= virtual()));
2951 _for_each_inner_peripheral!((@ peri_type #[doc =
2952 "GPIO9 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
2953 "<section class=\"warning\">"] #[doc =
2954 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
2955 #[doc = "<ul>"] #[doc =
2956 "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
2957 = "</ul>"] #[doc = "</section>"] GPIO9 <= virtual()));
2958 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO10 peripheral singleton"]
2959 GPIO10 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
2960 "GPIO11 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
2961 "<section class=\"warning\">"] #[doc =
2962 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
2963 #[doc = "<ul>"] #[doc =
2964 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
2965 "</ul>"] #[doc = "</section>"] GPIO11 <= virtual()));
2966 _for_each_inner_peripheral!((@ peri_type #[doc =
2967 "GPIO12 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
2968 "<section class=\"warning\">"] #[doc =
2969 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
2970 #[doc = "<ul>"] #[doc =
2971 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
2972 "</ul>"] #[doc = "</section>"] GPIO12 <= virtual()));
2973 _for_each_inner_peripheral!((@ peri_type #[doc =
2974 "GPIO13 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
2975 "<section class=\"warning\">"] #[doc =
2976 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
2977 #[doc = "<ul>"] #[doc =
2978 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
2979 "</ul>"] #[doc = "</section>"] GPIO13 <= virtual()));
2980 _for_each_inner_peripheral!((@ peri_type #[doc =
2981 "GPIO14 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
2982 "<section class=\"warning\">"] #[doc =
2983 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
2984 #[doc = "<ul>"] #[doc =
2985 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
2986 "</ul>"] #[doc = "</section>"] GPIO14 <= virtual()));
2987 _for_each_inner_peripheral!((@ peri_type #[doc =
2988 "GPIO15 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
2989 "<section class=\"warning\">"] #[doc =
2990 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
2991 #[doc = "<ul>"] #[doc =
2992 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
2993 "</ul>"] #[doc = "</section>"] GPIO15 <= virtual()));
2994 _for_each_inner_peripheral!((@ peri_type #[doc =
2995 "GPIO16 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
2996 "<section class=\"warning\">"] #[doc =
2997 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
2998 #[doc = "<ul>"] #[doc =
2999 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3000 "</ul>"] #[doc = "</section>"] GPIO16 <= virtual()));
3001 _for_each_inner_peripheral!((@ peri_type #[doc =
3002 "GPIO17 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3003 "<section class=\"warning\">"] #[doc =
3004 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3005 #[doc = "<ul>"] #[doc =
3006 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3007 "</ul>"] #[doc = "</section>"] GPIO17 <= virtual()));
3008 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO18 peripheral singleton"]
3009 GPIO18 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
3010 "GPIO19 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3011 "<section class=\"warning\">"] #[doc =
3012 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3013 #[doc = "<ul>"] #[doc =
3014 "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
3015 = "</ul>"] #[doc = "</section>"] GPIO19 <= virtual()));
3016 _for_each_inner_peripheral!((@ peri_type #[doc =
3017 "GPIO20 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3018 "<section class=\"warning\">"] #[doc =
3019 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3020 #[doc = "<ul>"] #[doc =
3021 "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
3022 = "</ul>"] #[doc = "</section>"] GPIO20 <= virtual()));
3023 _for_each_inner_peripheral!((@ peri_type #[doc = "APB_CTRL peripheral singleton"]
3024 APB_CTRL <= APB_CTRL() (unstable))); _for_each_inner_peripheral!((@ peri_type
3025 #[doc = "APB_SARADC peripheral singleton"] APB_SARADC <= APB_SARADC()
3026 (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3027 "BB peripheral singleton"] BB <= BB() (unstable)));
3028 _for_each_inner_peripheral!((@ peri_type #[doc =
3029 "ASSIST_DEBUG peripheral singleton"] ASSIST_DEBUG <= ASSIST_DEBUG() (unstable)));
3030 _for_each_inner_peripheral!((@ peri_type #[doc = "DMA peripheral singleton"] DMA
3031 <= DMA() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3032 "ECC peripheral singleton"] ECC <= ECC() (unstable)));
3033 _for_each_inner_peripheral!((@ peri_type #[doc = "EFUSE peripheral singleton"]
3034 EFUSE <= EFUSE() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3035 "EXTMEM peripheral singleton"] EXTMEM <= EXTMEM() (unstable)));
3036 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO peripheral singleton"]
3037 GPIO <= GPIO() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3038 "I2C_ANA_MST peripheral singleton"] I2C_ANA_MST <= I2C_ANA_MST() (unstable)));
3039 _for_each_inner_peripheral!((@ peri_type #[doc = "I2C0 peripheral singleton"]
3040 I2C0 <= I2C0(I2C_EXT0 : { bind_peri_interrupt, enable_peri_interrupt,
3041 disable_peri_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
3042 "INTERRUPT_CORE0 peripheral singleton"] INTERRUPT_CORE0 <= INTERRUPT_CORE0()
3043 (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3044 "IO_MUX peripheral singleton"] IO_MUX <= IO_MUX() (unstable)));
3045 _for_each_inner_peripheral!((@ peri_type #[doc = "LEDC peripheral singleton"]
3046 LEDC <= LEDC() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3047 "RNG peripheral singleton"] RNG <= RNG() (unstable)));
3048 _for_each_inner_peripheral!((@ peri_type #[doc = "LPWR peripheral singleton"]
3049 LPWR <= RTC_CNTL() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3050 "MODEM_CLKRST peripheral singleton"] MODEM_CLKRST <= MODEM_CLKRST() (unstable)));
3051 _for_each_inner_peripheral!((@ peri_type #[doc =
3052 "SENSITIVE peripheral singleton"] SENSITIVE <= SENSITIVE() (unstable)));
3053 _for_each_inner_peripheral!((@ peri_type #[doc = "SHA peripheral singleton"] SHA
3054 <= SHA(SHA : { bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt
3055 }) (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3056 "SPI0 peripheral singleton"] SPI0 <= SPI0() (unstable)));
3057 _for_each_inner_peripheral!((@ peri_type #[doc = "SPI1 peripheral singleton"]
3058 SPI1 <= SPI1() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3059 "SPI2 peripheral singleton"] SPI2 <= SPI2(SPI2 : { bind_peri_interrupt,
3060 enable_peri_interrupt, disable_peri_interrupt })));
3061 _for_each_inner_peripheral!((@ peri_type #[doc = "SYSTEM peripheral singleton"]
3062 SYSTEM <= SYSTEM() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3063 "SYSTIMER peripheral singleton"] SYSTIMER <= SYSTIMER() (unstable)));
3064 _for_each_inner_peripheral!((@ peri_type #[doc = "TIMG0 peripheral singleton"]
3065 TIMG0 <= TIMG0() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3066 "UART0 peripheral singleton"] UART0 <= UART0(UART0 : { bind_peri_interrupt,
3067 enable_peri_interrupt, disable_peri_interrupt })));
3068 _for_each_inner_peripheral!((@ peri_type #[doc = "UART1 peripheral singleton"]
3069 UART1 <= UART1(UART1 : { bind_peri_interrupt, enable_peri_interrupt,
3070 disable_peri_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
3071 "XTS_AES peripheral singleton"] XTS_AES <= XTS_AES() (unstable)));
3072 _for_each_inner_peripheral!((@ peri_type #[doc = "DMA_CH0 peripheral singleton"]
3073 DMA_CH0 <= virtual() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc
3074 = "ADC1 peripheral singleton"] ADC1 <= virtual() (unstable)));
3075 _for_each_inner_peripheral!((@ peri_type #[doc = "BT peripheral singleton"] BT <=
3076 virtual(LP_TIMER : { bind_lp_timer_interrupt, enable_lp_timer_interrupt,
3077 disable_lp_timer_interrupt }, BT_MAC : { bind_mac_interrupt,
3078 enable_mac_interrupt, disable_mac_interrupt }) (unstable)));
3079 _for_each_inner_peripheral!((@ peri_type #[doc = "FLASH peripheral singleton"]
3080 FLASH <= virtual() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3081 "GPIO_DEDICATED peripheral singleton"] GPIO_DEDICATED <= virtual() (unstable)));
3082 _for_each_inner_peripheral!((@ peri_type #[doc =
3083 "SW_INTERRUPT peripheral singleton"] SW_INTERRUPT <= virtual() (unstable)));
3084 _for_each_inner_peripheral!((@ peri_type #[doc = "WIFI peripheral singleton"]
3085 WIFI <= virtual(WIFI_MAC : { bind_mac_interrupt, enable_mac_interrupt,
3086 disable_mac_interrupt }, WIFI_PWR : { bind_pwr_interrupt, enable_pwr_interrupt,
3087 disable_pwr_interrupt }))); _for_each_inner_peripheral!((GPIO0));
3088 _for_each_inner_peripheral!((GPIO1)); _for_each_inner_peripheral!((GPIO2));
3089 _for_each_inner_peripheral!((GPIO3)); _for_each_inner_peripheral!((GPIO4));
3090 _for_each_inner_peripheral!((GPIO5)); _for_each_inner_peripheral!((GPIO6));
3091 _for_each_inner_peripheral!((GPIO7)); _for_each_inner_peripheral!((GPIO8));
3092 _for_each_inner_peripheral!((GPIO9)); _for_each_inner_peripheral!((GPIO10));
3093 _for_each_inner_peripheral!((GPIO11)); _for_each_inner_peripheral!((GPIO12));
3094 _for_each_inner_peripheral!((GPIO13)); _for_each_inner_peripheral!((GPIO14));
3095 _for_each_inner_peripheral!((GPIO15)); _for_each_inner_peripheral!((GPIO16));
3096 _for_each_inner_peripheral!((GPIO17)); _for_each_inner_peripheral!((GPIO18));
3097 _for_each_inner_peripheral!((GPIO19)); _for_each_inner_peripheral!((GPIO20));
3098 _for_each_inner_peripheral!((APB_CTRL(unstable)));
3099 _for_each_inner_peripheral!((APB_SARADC(unstable)));
3100 _for_each_inner_peripheral!((BB(unstable)));
3101 _for_each_inner_peripheral!((ASSIST_DEBUG(unstable)));
3102 _for_each_inner_peripheral!((DMA(unstable)));
3103 _for_each_inner_peripheral!((ECC(unstable)));
3104 _for_each_inner_peripheral!((EXTMEM(unstable)));
3105 _for_each_inner_peripheral!((GPIO(unstable)));
3106 _for_each_inner_peripheral!((I2C_ANA_MST(unstable)));
3107 _for_each_inner_peripheral!((I2C0));
3108 _for_each_inner_peripheral!((INTERRUPT_CORE0(unstable)));
3109 _for_each_inner_peripheral!((IO_MUX(unstable)));
3110 _for_each_inner_peripheral!((LEDC(unstable)));
3111 _for_each_inner_peripheral!((RNG(unstable)));
3112 _for_each_inner_peripheral!((LPWR(unstable)));
3113 _for_each_inner_peripheral!((MODEM_CLKRST(unstable)));
3114 _for_each_inner_peripheral!((SENSITIVE(unstable)));
3115 _for_each_inner_peripheral!((SHA(unstable)));
3116 _for_each_inner_peripheral!((SPI0(unstable)));
3117 _for_each_inner_peripheral!((SPI1(unstable)));
3118 _for_each_inner_peripheral!((SPI2));
3119 _for_each_inner_peripheral!((SYSTEM(unstable)));
3120 _for_each_inner_peripheral!((SYSTIMER(unstable)));
3121 _for_each_inner_peripheral!((TIMG0(unstable)));
3122 _for_each_inner_peripheral!((UART0)); _for_each_inner_peripheral!((UART1));
3123 _for_each_inner_peripheral!((XTS_AES(unstable)));
3124 _for_each_inner_peripheral!((DMA_CH0(unstable)));
3125 _for_each_inner_peripheral!((ADC1(unstable)));
3126 _for_each_inner_peripheral!((BT(unstable)));
3127 _for_each_inner_peripheral!((FLASH(unstable)));
3128 _for_each_inner_peripheral!((GPIO_DEDICATED(unstable)));
3129 _for_each_inner_peripheral!((SW_INTERRUPT(unstable)));
3130 _for_each_inner_peripheral!((WIFI)); _for_each_inner_peripheral!((SPI2, Spi2,
3131 0)); _for_each_inner_peripheral!((SHA, Sha, 7));
3132 _for_each_inner_peripheral!((all(@ peri_type #[doc =
3133 "GPIO0 peripheral singleton"] GPIO0 <= virtual()), (@ peri_type #[doc =
3134 "GPIO1 peripheral singleton"] GPIO1 <= virtual()), (@ peri_type #[doc =
3135 "GPIO2 peripheral singleton"] GPIO2 <= virtual()), (@ peri_type #[doc =
3136 "GPIO3 peripheral singleton"] GPIO3 <= virtual()), (@ peri_type #[doc =
3137 "GPIO4 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3138 "<section class=\"warning\">"] #[doc =
3139 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3140 #[doc = "<ul>"] #[doc =
3141 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3142 #[doc = "</ul>"] #[doc = "</section>"] GPIO4 <= virtual()), (@ peri_type #[doc =
3143 "GPIO5 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3144 "<section class=\"warning\">"] #[doc =
3145 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3146 #[doc = "<ul>"] #[doc =
3147 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3148 #[doc = "</ul>"] #[doc = "</section>"] GPIO5 <= virtual()), (@ peri_type #[doc =
3149 "GPIO6 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3150 "<section class=\"warning\">"] #[doc =
3151 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3152 #[doc = "<ul>"] #[doc =
3153 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3154 #[doc = "</ul>"] #[doc = "</section>"] GPIO6 <= virtual()), (@ peri_type #[doc =
3155 "GPIO7 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3156 "<section class=\"warning\">"] #[doc =
3157 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3158 #[doc = "<ul>"] #[doc =
3159 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3160 #[doc = "</ul>"] #[doc = "</section>"] GPIO7 <= virtual()), (@ peri_type #[doc =
3161 "GPIO8 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3162 "<section class=\"warning\">"] #[doc =
3163 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3164 #[doc = "<ul>"] #[doc =
3165 "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
3166 = "</ul>"] #[doc = "</section>"] GPIO8 <= virtual()), (@ peri_type #[doc =
3167 "GPIO9 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3168 "<section class=\"warning\">"] #[doc =
3169 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3170 #[doc = "<ul>"] #[doc =
3171 "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
3172 = "</ul>"] #[doc = "</section>"] GPIO9 <= virtual()), (@ peri_type #[doc =
3173 "GPIO10 peripheral singleton"] GPIO10 <= virtual()), (@ peri_type #[doc =
3174 "GPIO11 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3175 "<section class=\"warning\">"] #[doc =
3176 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3177 #[doc = "<ul>"] #[doc =
3178 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3179 "</ul>"] #[doc = "</section>"] GPIO11 <= virtual()), (@ peri_type #[doc =
3180 "GPIO12 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3181 "<section class=\"warning\">"] #[doc =
3182 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3183 #[doc = "<ul>"] #[doc =
3184 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3185 "</ul>"] #[doc = "</section>"] GPIO12 <= virtual()), (@ peri_type #[doc =
3186 "GPIO13 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3187 "<section class=\"warning\">"] #[doc =
3188 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3189 #[doc = "<ul>"] #[doc =
3190 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3191 "</ul>"] #[doc = "</section>"] GPIO13 <= virtual()), (@ peri_type #[doc =
3192 "GPIO14 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3193 "<section class=\"warning\">"] #[doc =
3194 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3195 #[doc = "<ul>"] #[doc =
3196 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3197 "</ul>"] #[doc = "</section>"] GPIO14 <= virtual()), (@ peri_type #[doc =
3198 "GPIO15 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3199 "<section class=\"warning\">"] #[doc =
3200 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3201 #[doc = "<ul>"] #[doc =
3202 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3203 "</ul>"] #[doc = "</section>"] GPIO15 <= virtual()), (@ peri_type #[doc =
3204 "GPIO16 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3205 "<section class=\"warning\">"] #[doc =
3206 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3207 #[doc = "<ul>"] #[doc =
3208 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3209 "</ul>"] #[doc = "</section>"] GPIO16 <= virtual()), (@ peri_type #[doc =
3210 "GPIO17 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3211 "<section class=\"warning\">"] #[doc =
3212 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3213 #[doc = "<ul>"] #[doc =
3214 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3215 "</ul>"] #[doc = "</section>"] GPIO17 <= virtual()), (@ peri_type #[doc =
3216 "GPIO18 peripheral singleton"] GPIO18 <= virtual()), (@ peri_type #[doc =
3217 "GPIO19 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3218 "<section class=\"warning\">"] #[doc =
3219 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3220 #[doc = "<ul>"] #[doc =
3221 "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
3222 = "</ul>"] #[doc = "</section>"] GPIO19 <= virtual()), (@ peri_type #[doc =
3223 "GPIO20 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3224 "<section class=\"warning\">"] #[doc =
3225 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3226 #[doc = "<ul>"] #[doc =
3227 "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
3228 = "</ul>"] #[doc = "</section>"] GPIO20 <= virtual()), (@ peri_type #[doc =
3229 "APB_CTRL peripheral singleton"] APB_CTRL <= APB_CTRL() (unstable)), (@ peri_type
3230 #[doc = "APB_SARADC peripheral singleton"] APB_SARADC <= APB_SARADC()
3231 (unstable)), (@ peri_type #[doc = "BB peripheral singleton"] BB <= BB()
3232 (unstable)), (@ peri_type #[doc = "ASSIST_DEBUG peripheral singleton"]
3233 ASSIST_DEBUG <= ASSIST_DEBUG() (unstable)), (@ peri_type #[doc =
3234 "DMA peripheral singleton"] DMA <= DMA() (unstable)), (@ peri_type #[doc =
3235 "ECC peripheral singleton"] ECC <= ECC() (unstable)), (@ peri_type #[doc =
3236 "EFUSE peripheral singleton"] EFUSE <= EFUSE() (unstable)), (@ peri_type #[doc =
3237 "EXTMEM peripheral singleton"] EXTMEM <= EXTMEM() (unstable)), (@ peri_type #[doc
3238 = "GPIO peripheral singleton"] GPIO <= GPIO() (unstable)), (@ peri_type #[doc =
3239 "I2C_ANA_MST peripheral singleton"] I2C_ANA_MST <= I2C_ANA_MST() (unstable)), (@
3240 peri_type #[doc = "I2C0 peripheral singleton"] I2C0 <= I2C0(I2C_EXT0 : {
3241 bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })), (@
3242 peri_type #[doc = "INTERRUPT_CORE0 peripheral singleton"] INTERRUPT_CORE0 <=
3243 INTERRUPT_CORE0() (unstable)), (@ peri_type #[doc =
3244 "IO_MUX peripheral singleton"] IO_MUX <= IO_MUX() (unstable)), (@ peri_type #[doc
3245 = "LEDC peripheral singleton"] LEDC <= LEDC() (unstable)), (@ peri_type #[doc =
3246 "RNG peripheral singleton"] RNG <= RNG() (unstable)), (@ peri_type #[doc =
3247 "LPWR peripheral singleton"] LPWR <= RTC_CNTL() (unstable)), (@ peri_type #[doc =
3248 "MODEM_CLKRST peripheral singleton"] MODEM_CLKRST <= MODEM_CLKRST() (unstable)),
3249 (@ peri_type #[doc = "SENSITIVE peripheral singleton"] SENSITIVE <= SENSITIVE()
3250 (unstable)), (@ peri_type #[doc = "SHA peripheral singleton"] SHA <= SHA(SHA : {
3251 bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })
3252 (unstable)), (@ peri_type #[doc = "SPI0 peripheral singleton"] SPI0 <= SPI0()
3253 (unstable)), (@ peri_type #[doc = "SPI1 peripheral singleton"] SPI1 <= SPI1()
3254 (unstable)), (@ peri_type #[doc = "SPI2 peripheral singleton"] SPI2 <= SPI2(SPI2
3255 : { bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })), (@
3256 peri_type #[doc = "SYSTEM peripheral singleton"] SYSTEM <= SYSTEM() (unstable)),
3257 (@ peri_type #[doc = "SYSTIMER peripheral singleton"] SYSTIMER <= SYSTIMER()
3258 (unstable)), (@ peri_type #[doc = "TIMG0 peripheral singleton"] TIMG0 <= TIMG0()
3259 (unstable)), (@ peri_type #[doc = "UART0 peripheral singleton"] UART0 <=
3260 UART0(UART0 : { bind_peri_interrupt, enable_peri_interrupt,
3261 disable_peri_interrupt })), (@ peri_type #[doc = "UART1 peripheral singleton"]
3262 UART1 <= UART1(UART1 : { bind_peri_interrupt, enable_peri_interrupt,
3263 disable_peri_interrupt })), (@ peri_type #[doc = "XTS_AES peripheral singleton"]
3264 XTS_AES <= XTS_AES() (unstable)), (@ peri_type #[doc =
3265 "DMA_CH0 peripheral singleton"] DMA_CH0 <= virtual() (unstable)), (@ peri_type
3266 #[doc = "ADC1 peripheral singleton"] ADC1 <= virtual() (unstable)), (@ peri_type
3267 #[doc = "BT peripheral singleton"] BT <= virtual(LP_TIMER : {
3268 bind_lp_timer_interrupt, enable_lp_timer_interrupt, disable_lp_timer_interrupt },
3269 BT_MAC : { bind_mac_interrupt, enable_mac_interrupt, disable_mac_interrupt })
3270 (unstable)), (@ peri_type #[doc = "FLASH peripheral singleton"] FLASH <=
3271 virtual() (unstable)), (@ peri_type #[doc =
3272 "GPIO_DEDICATED peripheral singleton"] GPIO_DEDICATED <= virtual() (unstable)),
3273 (@ peri_type #[doc = "SW_INTERRUPT peripheral singleton"] SW_INTERRUPT <=
3274 virtual() (unstable)), (@ peri_type #[doc = "WIFI peripheral singleton"] WIFI <=
3275 virtual(WIFI_MAC : { bind_mac_interrupt, enable_mac_interrupt,
3276 disable_mac_interrupt }, WIFI_PWR : { bind_pwr_interrupt, enable_pwr_interrupt,
3277 disable_pwr_interrupt })))); _for_each_inner_peripheral!((singletons(GPIO0),
3278 (GPIO1), (GPIO2), (GPIO3), (GPIO4), (GPIO5), (GPIO6), (GPIO7), (GPIO8), (GPIO9),
3279 (GPIO10), (GPIO11), (GPIO12), (GPIO13), (GPIO14), (GPIO15), (GPIO16), (GPIO17),
3280 (GPIO18), (GPIO19), (GPIO20), (APB_CTRL(unstable)), (APB_SARADC(unstable)),
3281 (BB(unstable)), (ASSIST_DEBUG(unstable)), (DMA(unstable)), (ECC(unstable)),
3282 (EXTMEM(unstable)), (GPIO(unstable)), (I2C_ANA_MST(unstable)), (I2C0),
3283 (INTERRUPT_CORE0(unstable)), (IO_MUX(unstable)), (LEDC(unstable)),
3284 (RNG(unstable)), (LPWR(unstable)), (MODEM_CLKRST(unstable)),
3285 (SENSITIVE(unstable)), (SHA(unstable)), (SPI0(unstable)), (SPI1(unstable)),
3286 (SPI2), (SYSTEM(unstable)), (SYSTIMER(unstable)), (TIMG0(unstable)), (UART0),
3287 (UART1), (XTS_AES(unstable)), (DMA_CH0(unstable)), (ADC1(unstable)),
3288 (BT(unstable)), (FLASH(unstable)), (GPIO_DEDICATED(unstable)),
3289 (SW_INTERRUPT(unstable)), (WIFI)));
3290 _for_each_inner_peripheral!((dma_eligible(SPI2, Spi2, 0), (SHA, Sha, 7)));
3291 };
3292}
3293#[macro_export]
3320#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3321macro_rules! for_each_gpio {
3322 ($($pattern:tt => $code:tt;)*) => {
3323 macro_rules! _for_each_inner_gpio { $(($pattern) => $code;)* ($other : tt) => {}
3324 } _for_each_inner_gpio!((0, GPIO0() () ([Input] [Output])));
3325 _for_each_inner_gpio!((1, GPIO1() () ([Input] [Output])));
3326 _for_each_inner_gpio!((2, GPIO2(_2 => FSPIQ) (_2 => FSPIQ) ([Input] [Output])));
3327 _for_each_inner_gpio!((3, GPIO3() () ([Input] [Output])));
3328 _for_each_inner_gpio!((4, GPIO4(_0 => MTMS _2 => FSPIHD) (_2 => FSPIHD) ([Input]
3329 [Output]))); _for_each_inner_gpio!((5, GPIO5(_0 => MTDI _2 => FSPIWP) (_2 =>
3330 FSPIWP) ([Input] [Output]))); _for_each_inner_gpio!((6, GPIO6(_0 => MTCK _2 =>
3331 FSPICLK) (_2 => FSPICLK) ([Input] [Output]))); _for_each_inner_gpio!((7, GPIO7(_2
3332 => FSPID) (_0 => MTDO _2 => FSPID) ([Input] [Output])));
3333 _for_each_inner_gpio!((8, GPIO8() () ([Input] [Output])));
3334 _for_each_inner_gpio!((9, GPIO9() () ([Input] [Output])));
3335 _for_each_inner_gpio!((10, GPIO10(_2 => FSPICS0) (_2 => FSPICS0) ([Input]
3336 [Output]))); _for_each_inner_gpio!((11, GPIO11(_0 => SPIHD) (_0 => SPIHD)
3337 ([Input] [Output]))); _for_each_inner_gpio!((12, GPIO12(_0 => SPIHD) (_0 =>
3338 SPIHD) ([Input] [Output]))); _for_each_inner_gpio!((13, GPIO13(_0 => SPIWP) (_0
3339 => SPIWP) ([Input] [Output]))); _for_each_inner_gpio!((14, GPIO14() (_0 =>
3340 SPICS0) ([Input] [Output]))); _for_each_inner_gpio!((15, GPIO15() (_0 => SPICLK)
3341 ([Input] [Output]))); _for_each_inner_gpio!((16, GPIO16(_0 => SPID) (_0 => SPID)
3342 ([Input] [Output]))); _for_each_inner_gpio!((17, GPIO17(_0 => SPIQ) (_0 => SPIQ)
3343 ([Input] [Output]))); _for_each_inner_gpio!((18, GPIO18() () ([Input]
3344 [Output]))); _for_each_inner_gpio!((19, GPIO19(_0 => U0RXD) () ([Input]
3345 [Output]))); _for_each_inner_gpio!((20, GPIO20() (_0 => U0TXD) ([Input]
3346 [Output]))); _for_each_inner_gpio!((all(0, GPIO0() () ([Input] [Output])), (1,
3347 GPIO1() () ([Input] [Output])), (2, GPIO2(_2 => FSPIQ) (_2 => FSPIQ) ([Input]
3348 [Output])), (3, GPIO3() () ([Input] [Output])), (4, GPIO4(_0 => MTMS _2 =>
3349 FSPIHD) (_2 => FSPIHD) ([Input] [Output])), (5, GPIO5(_0 => MTDI _2 => FSPIWP)
3350 (_2 => FSPIWP) ([Input] [Output])), (6, GPIO6(_0 => MTCK _2 => FSPICLK) (_2 =>
3351 FSPICLK) ([Input] [Output])), (7, GPIO7(_2 => FSPID) (_0 => MTDO _2 => FSPID)
3352 ([Input] [Output])), (8, GPIO8() () ([Input] [Output])), (9, GPIO9() () ([Input]
3353 [Output])), (10, GPIO10(_2 => FSPICS0) (_2 => FSPICS0) ([Input] [Output])), (11,
3354 GPIO11(_0 => SPIHD) (_0 => SPIHD) ([Input] [Output])), (12, GPIO12(_0 => SPIHD)
3355 (_0 => SPIHD) ([Input] [Output])), (13, GPIO13(_0 => SPIWP) (_0 => SPIWP)
3356 ([Input] [Output])), (14, GPIO14() (_0 => SPICS0) ([Input] [Output])), (15,
3357 GPIO15() (_0 => SPICLK) ([Input] [Output])), (16, GPIO16(_0 => SPID) (_0 => SPID)
3358 ([Input] [Output])), (17, GPIO17(_0 => SPIQ) (_0 => SPIQ) ([Input] [Output])),
3359 (18, GPIO18() () ([Input] [Output])), (19, GPIO19(_0 => U0RXD) () ([Input]
3360 [Output])), (20, GPIO20() (_0 => U0TXD) ([Input] [Output]))));
3361 };
3362}
3363#[macro_export]
3390#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3391macro_rules! for_each_analog_function {
3392 ($($pattern:tt => $code:tt;)*) => {
3393 macro_rules! _for_each_inner_analog_function { $(($pattern) => $code;)* ($other :
3394 tt) => {} } _for_each_inner_analog_function!((ADC1_CH0, GPIO0));
3395 _for_each_inner_analog_function!((ADC1_CH1, GPIO1));
3396 _for_each_inner_analog_function!((ADC1_CH2, GPIO2));
3397 _for_each_inner_analog_function!((ADC1_CH3, GPIO3));
3398 _for_each_inner_analog_function!((ADC1_CH4, GPIO4));
3399 _for_each_inner_analog_function!(((ADC1_CH0, ADCn_CHm, 1, 0), GPIO0));
3400 _for_each_inner_analog_function!(((ADC1_CH1, ADCn_CHm, 1, 1), GPIO1));
3401 _for_each_inner_analog_function!(((ADC1_CH2, ADCn_CHm, 1, 2), GPIO2));
3402 _for_each_inner_analog_function!(((ADC1_CH3, ADCn_CHm, 1, 3), GPIO3));
3403 _for_each_inner_analog_function!(((ADC1_CH4, ADCn_CHm, 1, 4), GPIO4));
3404 _for_each_inner_analog_function!((all(ADC1_CH0, GPIO0), (ADC1_CH1, GPIO1),
3405 (ADC1_CH2, GPIO2), (ADC1_CH3, GPIO3), (ADC1_CH4, GPIO4)));
3406 _for_each_inner_analog_function!((all_expanded((ADC1_CH0, ADCn_CHm, 1, 0),
3407 GPIO0), ((ADC1_CH1, ADCn_CHm, 1, 1), GPIO1), ((ADC1_CH2, ADCn_CHm, 1, 2), GPIO2),
3408 ((ADC1_CH3, ADCn_CHm, 1, 3), GPIO3), ((ADC1_CH4, ADCn_CHm, 1, 4), GPIO4)));
3409 };
3410}
3411#[macro_export]
3438#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3439macro_rules! for_each_lp_function {
3440 ($($pattern:tt => $code:tt;)*) => {
3441 macro_rules! _for_each_inner_lp_function { $(($pattern) => $code;)* ($other : tt)
3442 => {} } _for_each_inner_lp_function!((RTC_GPIO0, GPIO0));
3443 _for_each_inner_lp_function!((RTC_GPIO1, GPIO1));
3444 _for_each_inner_lp_function!((RTC_GPIO2, GPIO2));
3445 _for_each_inner_lp_function!((RTC_GPIO3, GPIO3));
3446 _for_each_inner_lp_function!((RTC_GPIO4, GPIO4));
3447 _for_each_inner_lp_function!((RTC_GPIO5, GPIO5));
3448 _for_each_inner_lp_function!(((RTC_GPIO0, RTC_GPIOn, 0), GPIO0));
3449 _for_each_inner_lp_function!(((RTC_GPIO1, RTC_GPIOn, 1), GPIO1));
3450 _for_each_inner_lp_function!(((RTC_GPIO2, RTC_GPIOn, 2), GPIO2));
3451 _for_each_inner_lp_function!(((RTC_GPIO3, RTC_GPIOn, 3), GPIO3));
3452 _for_each_inner_lp_function!(((RTC_GPIO4, RTC_GPIOn, 4), GPIO4));
3453 _for_each_inner_lp_function!(((RTC_GPIO5, RTC_GPIOn, 5), GPIO5));
3454 _for_each_inner_lp_function!((all(RTC_GPIO0, GPIO0), (RTC_GPIO1, GPIO1),
3455 (RTC_GPIO2, GPIO2), (RTC_GPIO3, GPIO3), (RTC_GPIO4, GPIO4), (RTC_GPIO5, GPIO5)));
3456 _for_each_inner_lp_function!((all_expanded((RTC_GPIO0, RTC_GPIOn, 0), GPIO0),
3457 ((RTC_GPIO1, RTC_GPIOn, 1), GPIO1), ((RTC_GPIO2, RTC_GPIOn, 2), GPIO2),
3458 ((RTC_GPIO3, RTC_GPIOn, 3), GPIO3), ((RTC_GPIO4, RTC_GPIOn, 4), GPIO4),
3459 ((RTC_GPIO5, RTC_GPIOn, 5), GPIO5)));
3460 };
3461}
3462#[macro_export]
3466#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3467macro_rules! define_io_mux_signals {
3468 () => {
3469 #[allow(non_camel_case_types, clippy::upper_case_acronyms)]
3470 #[derive(Debug, PartialEq, Copy, Clone)]
3471 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
3472 #[doc(hidden)]
3473 pub enum InputSignal {
3474 SPIQ = 0,
3475 SPID = 1,
3476 SPIHD = 2,
3477 SPIWP = 3,
3478 U0RXD = 6,
3479 U0CTS = 7,
3480 U0DSR = 8,
3481 U1RXD = 9,
3482 U1CTS = 10,
3483 U1DSR = 11,
3484 CPU_GPIO_0 = 28,
3485 CPU_GPIO_1 = 29,
3486 CPU_GPIO_2 = 30,
3487 CPU_GPIO_3 = 31,
3488 CPU_GPIO_4 = 32,
3489 CPU_GPIO_5 = 33,
3490 CPU_GPIO_6 = 34,
3491 CPU_GPIO_7 = 35,
3492 EXT_ADC_START = 45,
3493 RMT_SIG_0 = 51,
3494 RMT_SIG_1 = 52,
3495 I2CEXT0_SCL = 53,
3496 I2CEXT0_SDA = 54,
3497 FSPICLK = 63,
3498 FSPIQ = 64,
3499 FSPID = 65,
3500 FSPIHD = 66,
3501 FSPIWP = 67,
3502 FSPICS0 = 68,
3503 SIG_FUNC_97 = 97,
3504 SIG_FUNC_98 = 98,
3505 SIG_FUNC_99 = 99,
3506 SIG_FUNC_100 = 100,
3507 MTCK,
3508 MTMS,
3509 MTDI,
3510 }
3511 #[allow(non_camel_case_types, clippy::upper_case_acronyms)]
3512 #[derive(Debug, PartialEq, Copy, Clone)]
3513 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
3514 #[doc(hidden)]
3515 pub enum OutputSignal {
3516 SPIQ = 0,
3517 SPID = 1,
3518 SPIHD = 2,
3519 SPIWP = 3,
3520 SPICLK = 4,
3521 SPICS0 = 5,
3522 U0TXD = 6,
3523 U0RTS = 7,
3524 U0DTR = 8,
3525 U1TXD = 9,
3526 U1RTS = 10,
3527 U1DTR = 11,
3528 SPIQ_MONITOR = 15,
3529 SPID_MONITOR = 16,
3530 SPIHD_MONITOR = 17,
3531 SPIWP_MONITOR = 18,
3532 SPICS1 = 19,
3533 CPU_GPIO_0 = 28,
3534 CPU_GPIO_1 = 29,
3535 CPU_GPIO_2 = 30,
3536 CPU_GPIO_3 = 31,
3537 CPU_GPIO_4 = 32,
3538 CPU_GPIO_5 = 33,
3539 CPU_GPIO_6 = 34,
3540 CPU_GPIO_7 = 35,
3541 LEDC_LS_SIG0 = 45,
3542 LEDC_LS_SIG1 = 46,
3543 LEDC_LS_SIG2 = 47,
3544 LEDC_LS_SIG3 = 48,
3545 LEDC_LS_SIG4 = 49,
3546 LEDC_LS_SIG5 = 50,
3547 RMT_SIG_0 = 51,
3548 RMT_SIG_1 = 52,
3549 I2CEXT0_SCL = 53,
3550 I2CEXT0_SDA = 54,
3551 FSPICLK = 63,
3552 FSPIQ = 64,
3553 FSPID = 65,
3554 FSPIHD = 66,
3555 FSPIWP = 67,
3556 FSPICS0 = 68,
3557 FSPICS1 = 69,
3558 FSPICS3 = 70,
3559 FSPICS2 = 71,
3560 FSPICS4 = 72,
3561 FSPICS5 = 73,
3562 ANT_SEL0 = 89,
3563 ANT_SEL1 = 90,
3564 ANT_SEL2 = 91,
3565 ANT_SEL3 = 92,
3566 ANT_SEL4 = 93,
3567 ANT_SEL5 = 94,
3568 ANT_SEL6 = 95,
3569 ANT_SEL7 = 96,
3570 SIG_FUNC_97 = 97,
3571 SIG_FUNC_98 = 98,
3572 SIG_FUNC_99 = 99,
3573 SIG_FUNC_100 = 100,
3574 CLK_OUT1 = 123,
3575 CLK_OUT2 = 124,
3576 CLK_OUT3 = 125,
3577 GPIO = 128,
3578 MTDO,
3579 }
3580 };
3581}
3582#[macro_export]
3595#[expect(clippy::crate_in_macro_def)]
3596#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3597macro_rules! define_io_mux_reg {
3598 () => {
3599 pub(crate) fn io_mux_reg(gpio_num: u8) -> &'static crate::pac::io_mux::GPIO {
3600 crate::peripherals::IO_MUX::regs().gpio(gpio_num as usize)
3601 }
3602 };
3603}