Skip to main content

esp_metadata_generated/
_generated_esp32c61.rs

1// Do NOT edit this file directly. Make your changes to esp-metadata,
2// then run `cargo update-metadata`.
3
4/// The name of the chip as `&str`
5///
6/// # Example
7///
8/// ```rust, no_run
9/// use esp_hal::chip;
10/// let chip_name = chip!();
11#[doc = concat!("assert_eq!(chip_name, ", chip!(), ")")]
12/// ```
13#[macro_export]
14#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
15macro_rules! chip {
16    () => {
17        "esp32c61"
18    };
19}
20/// The pretty name of the chip as `&str`
21///
22/// # Example
23///
24/// ```rust, no_run
25/// use esp_hal::chip;
26/// let chip_name = chip_pretty!();
27#[doc = concat!("assert_eq!(chip_name, ", chip_pretty!(), ")")]
28/// ```
29#[macro_export]
30#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
31macro_rules! chip_pretty {
32    () => {
33        "ESP32-C61"
34    };
35}
36/// The properties of this chip and its drivers.
37#[macro_export]
38#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
39macro_rules! property {
40    ("chip") => {
41        "esp32c61"
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/esp32-c61_technical_reference_manual_en.pdf"
54    };
55    ("gpio.version") => {
56        2
57    };
58    ("gpio.version", str) => {
59        stringify!(2)
60    };
61    ("gpio.has_input_sync") => {
62        true
63    };
64    ("gpio.gpio_function") => {
65        1
66    };
67    ("gpio.gpio_function", str) => {
68        stringify!(1)
69    };
70    ("gpio.constant_0_input") => {
71        96
72    };
73    ("gpio.constant_0_input", str) => {
74        stringify!(96)
75    };
76    ("gpio.constant_1_input") => {
77        64
78    };
79    ("gpio.constant_1_input", str) => {
80        stringify!(64)
81    };
82    ("gpio.remap_iomux_pin_registers") => {
83        false
84    };
85    ("gpio.func_in_sel_offset") => {
86        0
87    };
88    ("gpio.func_in_sel_offset", str) => {
89        stringify!(0)
90    };
91    ("gpio.need_soft_isolate_during_pd") => {
92        false
93    };
94    ("gpio.has_bank_1") => {
95        false
96    };
97    ("gpio.input_signal_max") => {
98        100
99    };
100    ("gpio.input_signal_max", str) => {
101        stringify!(100)
102    };
103    ("gpio.output_signal_max") => {
104        256
105    };
106    ("gpio.output_signal_max", str) => {
107        stringify!(256)
108    };
109    ("dedicated_gpio.version") => {
110        "riscv_v1"
111    };
112    ("dedicated_gpio.needs_initialization") => {
113        false
114    };
115    ("dedicated_gpio.channel_count") => {
116        8
117    };
118    ("dedicated_gpio.channel_count", str) => {
119        stringify!(8)
120    };
121    ("lp_io.version") => {
122        "v4"
123    };
124    ("lp_io.has_gpio_matrix") => {
125        false
126    };
127    ("uart.ram_size") => {
128        128
129    };
130    ("uart.ram_size", str) => {
131        stringify!(128)
132    };
133    ("uart.version") => {
134        2
135    };
136    ("uart.version", str) => {
137        stringify!(2)
138    };
139    ("uart.peripheral_controls_mem_clk") => {
140        true
141    };
142    ("uart.has_sclk_divider") => {
143        false
144    };
145    ("uart.has_sclk_enable") => {
146        true
147    };
148    ("i2c_master.version") => {
149        4
150    };
151    ("i2c_master.version", str) => {
152        stringify!(4)
153    };
154    ("i2c_master.has_fsm_timeouts") => {
155        true
156    };
157    ("i2c_master.has_hw_bus_clear") => {
158        true
159    };
160    ("i2c_master.has_bus_timeout_enable") => {
161        true
162    };
163    ("i2c_master.separate_filter_config_registers") => {
164        false
165    };
166    ("i2c_master.can_estimate_nack_reason") => {
167        true
168    };
169    ("i2c_master.has_conf_update") => {
170        true
171    };
172    ("i2c_master.has_reliable_fsm_reset") => {
173        true
174    };
175    ("i2c_master.has_arbitration_en") => {
176        true
177    };
178    ("i2c_master.has_tx_fifo_watermark") => {
179        true
180    };
181    ("i2c_master.bus_timeout_is_exponential") => {
182        true
183    };
184    ("i2c_master.has_pd_en") => {
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        32
201    };
202    ("i2c_master.fifo_size", str) => {
203        stringify!(32)
204    };
205    ("spi_master.version") => {
206        3
207    };
208    ("spi_master.version", str) => {
209        stringify!(3)
210    };
211    ("spi_master.fifo_size") => {
212        64
213    };
214    ("spi_master.fifo_size", str) => {
215        stringify!(64)
216    };
217    ("spi_master.bit_order_is_bool") => {
218        false
219    };
220    ("spi_master.has_octal") => {
221        false
222    };
223    ("spi_master.has_app_interrupts") => {
224        true
225    };
226    ("spi_master.has_dma_segmented_transfer") => {
227        true
228    };
229    ("spi_master.has_clk_pre_div") => {
230        true
231    };
232    ("spi_master.dma_can_access_flash") => {
233        true
234    };
235    ("i2s.version") => {
236        3
237    };
238    ("i2s.version", str) => {
239        stringify!(3)
240    };
241    ("i2s.mclk_divider_bit_width") => {
242        9
243    };
244    ("i2s.mclk_divider_bit_width", str) => {
245        stringify!(9)
246    };
247    ("i2s.max_ws_width") => {
248        512
249    };
250    ("i2s.max_ws_width", str) => {
251        stringify!(512)
252    };
253    ("i2s.clock_configured_by_pcr") => {
254        true
255    };
256    ("i2s.clock_configured_by_hp_sys_clkrst") => {
257        false
258    };
259    ("i2s.supports_pdm_rx_hp_filter") => {
260        false
261    };
262    ("i2s.supports_pdm_tx") => {
263        true
264    };
265    ("i2s.supports_pdm_rx") => {
266        true
267    };
268    ("i2s.supports_pcm2pdm") => {
269        true
270    };
271    ("i2s.supports_pdm2pcm") => {
272        false
273    };
274    ("bt.controller") => {
275        "npl"
276    };
277    ("bt.requires_fast_cpu") => {
278        true
279    };
280    ("wifi.has_wifi6") => {
281        true
282    };
283    ("wifi.mac_version") => {
284        3
285    };
286    ("wifi.mac_version", str) => {
287        stringify!(3)
288    };
289    ("wifi.has_5g") => {
290        false
291    };
292    ("wifi.csi_supported") => {
293        true
294    };
295    ("wifi.has_nan") => {
296        true
297    };
298    ("wifi.has_ftm") => {
299        true
300    };
301    ("wifi.requires_fast_cpu") => {
302        true
303    };
304    ("phy.combo_module") => {
305        true
306    };
307    ("adc.controller") => {
308        "digital"
309    };
310    ("adc.channel_count") => {
311        4
312    };
313    ("adc.channel_count", str) => {
314        stringify!(4)
315    };
316    ("adc.line_calibration") => {
317        true
318    };
319    ("adc.curve_calibration") => {
320        true
321    };
322    ("adc.basic_calibration") => {
323        true
324    };
325    ("adc.calibration_v1_scheme_supported") => {
326        true
327    };
328    ("adc.channel_compensation") => {
329        true
330    };
331    ("adc.pcr_clock") => {
332        true
333    };
334    ("adc.pcr_sar_clk_div") => {
335        true
336    };
337    ("adc.sar_power_override") => {
338        true
339    };
340    ("timergroup.timg_has_timer1") => {
341        false
342    };
343    ("timergroup.timg_has_divcnt_rst") => {
344        true
345    };
346    ("timergroup.wdt_has_conf_update") => {
347        true
348    };
349    ("timergroup.rc_fast_calibration_divider_min_rev") => {
350        0
351    };
352    ("timergroup.rc_fast_calibration_divider") => {
353        32
354    };
355    ("timergroup.rc_fast_calibration_tick_enable") => {
356        false
357    };
358    ("ecc.zero_extend_writes") => {
359        true
360    };
361    ("ecc.separate_jacobian_point_memory") => {
362        true
363    };
364    ("ecc.has_memory_clock_gate") => {
365        true
366    };
367    ("ecc.supports_enhanced_security") => {
368        true
369    };
370    ("ecc.mem_block_size") => {
371        32
372    };
373    ("rng.apb_cycle_wait_num") => {
374        16
375    };
376    ("rng.apb_cycle_wait_num", str) => {
377        stringify!(16)
378    };
379    ("rng.trng_supported") => {
380        true
381    };
382    ("rng.is_lp_sys") => {
383        true
384    };
385    ("sleep.light_sleep") => {
386        true
387    };
388    ("sleep.deep_sleep") => {
389        true
390    };
391    ("sleep.rejectable_mask") => {
392        4094
393    };
394    ("sleep.ext1_version") => {
395        2
396    };
397    ("sleep.ext1_version", str) => {
398        stringify!(2)
399    };
400    ("sleep.pin_wakeup_version") => {
401        3
402    };
403    ("sleep.pin_wakeup_version", str) => {
404        stringify!(3)
405    };
406    ("sleep.deep_sleep_needs_gpio_isolation") => {
407        false
408    };
409    ("sleep.idle_frequency_scaling") => {
410        true
411    };
412    ("assist_debug.has_sp_monitor") => {
413        true
414    };
415    ("assist_debug.has_region_monitor") => {
416        true
417    };
418    ("dma.mem2mem_requires_peripheral") => {
419        false
420    };
421    ("dma.ext_mem_configurable_block_size") => {
422        false
423    };
424    ("dma.separate_in_out_interrupts") => {
425        true
426    };
427    ("dma.gdma_version") => {
428        2
429    };
430    ("dma.gdma_version", str) => {
431        stringify!(2)
432    };
433    ("interrupts.status_registers") => {
434        3
435    };
436    ("interrupts.status_registers", str) => {
437        stringify!(3)
438    };
439    ("interrupts.disabled_interrupt") => {
440        0
441    };
442    ("mmu.page_size") => {
443        65536
444    };
445    ("mmu.page_size", str) => {
446        stringify!(65536)
447    };
448    ("mmu.entry_num") => {
449        512
450    };
451    ("mmu.entry_num", str) => {
452        stringify!(512)
453    };
454    ("psram.octal_spi") => {
455        false
456    };
457    ("psram.hex_spi") => {
458        false
459    };
460    ("psram.has_timing_tuning") => {
461        true
462    };
463    ("psram.extmem_origin") => {
464        1107296256
465    };
466    ("psram.extmem_origin", str) => {
467        stringify!(1107296256)
468    };
469    ("psram.idle_low_speed_switch") => {
470        false
471    };
472    ("rom.has_crc_le") => {
473        true
474    };
475    ("rom.has_crc_be") => {
476        true
477    };
478    ("rom.has_md5_bsd") => {
479        true
480    };
481    ("rom.has_md5_mbedtls") => {
482        false
483    };
484    ("rom.no_libgcc") => {
485        false
486    };
487    ("soc.cpu_has_branch_predictor") => {
488        true
489    };
490    ("soc.cpu_has_csr_pc") => {
491        false
492    };
493    ("soc.cpu_has_zcmp_workaround") => {
494        false
495    };
496    ("soc.multi_core_enabled") => {
497        false
498    };
499    ("soc.cpu_pma_needs_core1_setup") => {
500        false
501    };
502    ("soc.cpu_csr_prv_mode") => {
503        2064
504    };
505    ("soc.cpu_csr_prv_mode", str) => {
506        stringify!(2064)
507    };
508    ("soc.internal_memory_cached") => {
509        false
510    };
511    ("soc.cpu_powers_down_cache") => {
512        true
513    };
514    ("soc.has_swd_watchdog") => {
515        true
516    };
517    ("soc.has_bus_clock_update") => {
518        true
519    };
520    ("soc.has_apb_frequency_reduction") => {
521        true
522    };
523    ("soc.cpu_mcause_mask") => {
524        31
525    };
526    ("soc.cpu_mcause_mask", str) => {
527        stringify!(31)
528    };
529    ("soc.cpu_pmp_granularity") => {
530        128
531    };
532    ("soc.cpu_pmp_granularity", str) => {
533        stringify!(128)
534    };
535    ("clock_tree.hp_root_clk") => {
536        [crate ::soc::clocks::HpRootClkConfig::Xtal, crate
537        ::soc::clocks::HpRootClkConfig::RcFast, crate
538        ::soc::clocks::HpRootClkConfig::PllF160m]
539    };
540    ("clock_tree.cpu_clk.divisor") => {
541        (0, 255)
542    };
543    ("clock_tree.ahb_clk.divisor") => {
544        (0, 255)
545    };
546    ("clock_tree.apb_clk.divisor") => {
547        (0, 255)
548    };
549    ("clock_tree.lp_fast_clk") => {
550        [crate ::soc::clocks::LpFastClkConfig::RcFast, crate
551        ::soc::clocks::LpFastClkConfig::XtalD2, crate
552        ::soc::clocks::LpFastClkConfig::Xtal]
553    };
554    ("clock_tree.lp_slow_clk") => {
555        [crate ::soc::clocks::LpSlowClkConfig::RcSlow, #[cfg(use_xtal32k)] crate
556        ::soc::clocks::LpSlowClkConfig::Xtal32k, crate
557        ::soc::clocks::LpSlowClkConfig::OscSlow]
558    };
559    ("clock_tree.ble_lp_clk") => {
560        [crate ::soc::clocks::BleLpClkConfig::Xtal, crate
561        ::soc::clocks::BleLpClkConfig::RcSlow, #[cfg(use_xtal32k)] crate
562        ::soc::clocks::BleLpClkConfig::Xtal32k]
563    };
564    ("clock_tree.crypto_clk") => {
565        [crate ::soc::clocks::CryptoClkConfig::Xtal, crate
566        ::soc::clocks::CryptoClkConfig::RcFast, crate
567        ::soc::clocks::CryptoClkConfig::PllF480m]
568    };
569    ("clock_tree.timg_calibration_clock") => {
570        [crate ::soc::clocks::TimgCalibrationClockConfig::OscSlowClk, crate
571        ::soc::clocks::TimgCalibrationClockConfig::RcSlowClk, crate
572        ::soc::clocks::TimgCalibrationClockConfig::RcFastDivClk, #[cfg(use_xtal32k)]
573        crate ::soc::clocks::TimgCalibrationClockConfig::Xtal32kClk]
574    };
575    ("clock_tree.uart.function_clock.sclk") => {
576        [crate ::soc::clocks::UartFunctionClockSclk::Xtal, crate
577        ::soc::clocks::UartFunctionClockSclk::PllF80m, crate
578        ::soc::clocks::UartFunctionClockSclk::RcFast]
579    };
580    ("clock_tree.uart.function_clock.div_num") => {
581        (0, 255)
582    };
583    ("clock_tree.uart.baud_rate_generator.fractional") => {
584        (0, 15)
585    };
586    ("clock_tree.uart.baud_rate_generator.integral") => {
587        (0, 4095)
588    };
589    ("clock_tree.timg.function_clock") => {
590        [crate ::soc::clocks::TimgFunctionClockConfig::XtalClk, crate
591        ::soc::clocks::TimgFunctionClockConfig::RcFastClk, crate
592        ::soc::clocks::TimgFunctionClockConfig::PllF80m]
593    };
594    ("clock_tree.timg.wdt_clock") => {
595        [crate ::soc::clocks::TimgWdtClockConfig::XtalClk, crate
596        ::soc::clocks::TimgWdtClockConfig::RcFastClk, crate
597        ::soc::clocks::TimgWdtClockConfig::PllF80m]
598    };
599    ("clock_tree.i2c.function_clock.sclk") => {
600        [crate ::soc::clocks::I2cFunctionClockSclk::Xtal, crate
601        ::soc::clocks::I2cFunctionClockSclk::RcFast]
602    };
603    ("clock_tree.i2c.function_clock.div_num") => {
604        (0, 255)
605    };
606    ("clock_tree.spi.function_clock") => {
607        [crate ::soc::clocks::SpiFunctionClockConfig::Xtal, crate
608        ::soc::clocks::SpiFunctionClockConfig::PllF160m, crate
609        ::soc::clocks::SpiFunctionClockConfig::RcFast]
610    };
611    ("clock_tree.adc.function_clock") => {
612        [crate ::soc::clocks::AdcFunctionClockConfig::Xtal, crate
613        ::soc::clocks::AdcFunctionClockConfig::RcFast, crate
614        ::soc::clocks::AdcFunctionClockConfig::PllF80m]
615    };
616    ("clock_tree.i2s.tx_clk.sclk") => {
617        [crate ::soc::clocks::I2sClkSclk::Xtal, crate
618        ::soc::clocks::I2sClkSclk::PllF120m, crate ::soc::clocks::I2sClkSclk::PllF160m]
619    };
620    ("clock_tree.i2s.tx_clk.div_num") => {
621        (1, 255)
622    };
623    ("clock_tree.i2s.tx_clk.div_a") => {
624        (1, 511)
625    };
626    ("clock_tree.i2s.tx_clk.div_b") => {
627        (0, 511)
628    };
629    ("clock_tree.i2s.rx_clk.sclk") => {
630        [crate ::soc::clocks::I2sClkSclk::Xtal, crate
631        ::soc::clocks::I2sClkSclk::PllF120m, crate ::soc::clocks::I2sClkSclk::PllF160m]
632    };
633    ("clock_tree.i2s.rx_clk.div_num") => {
634        (1, 255)
635    };
636    ("clock_tree.i2s.rx_clk.div_a") => {
637        (1, 511)
638    };
639    ("clock_tree.i2s.rx_clk.div_b") => {
640        (0, 511)
641    };
642    ("clock_tree.i2s.mclk_out") => {
643        [crate ::soc::clocks::I2sMclkOutConfig::Tx, crate
644        ::soc::clocks::I2sMclkOutConfig::Rx]
645    };
646}
647#[macro_export]
648#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
649macro_rules! for_each_dedicated_gpio {
650    ($($pattern:tt => $code:tt;)*) => {
651        macro_rules! _for_each_inner_dedicated_gpio { $(($pattern) => $code;)* ($other :
652        tt) => {} } _for_each_inner_dedicated_gpio!((0));
653        _for_each_inner_dedicated_gpio!((1)); _for_each_inner_dedicated_gpio!((2));
654        _for_each_inner_dedicated_gpio!((3)); _for_each_inner_dedicated_gpio!((4));
655        _for_each_inner_dedicated_gpio!((5)); _for_each_inner_dedicated_gpio!((6));
656        _for_each_inner_dedicated_gpio!((7)); _for_each_inner_dedicated_gpio!((0, 0,
657        CPU_GPIO_0)); _for_each_inner_dedicated_gpio!((0, 1, CPU_GPIO_1));
658        _for_each_inner_dedicated_gpio!((0, 2, CPU_GPIO_2));
659        _for_each_inner_dedicated_gpio!((0, 3, CPU_GPIO_3));
660        _for_each_inner_dedicated_gpio!((0, 4, CPU_GPIO_4));
661        _for_each_inner_dedicated_gpio!((0, 5, CPU_GPIO_5));
662        _for_each_inner_dedicated_gpio!((0, 6, CPU_GPIO_6));
663        _for_each_inner_dedicated_gpio!((0, 7, CPU_GPIO_7));
664        _for_each_inner_dedicated_gpio!((channels(0), (1), (2), (3), (4), (5), (6),
665        (7))); _for_each_inner_dedicated_gpio!((signals(0, 0, CPU_GPIO_0), (0, 1,
666        CPU_GPIO_1), (0, 2, CPU_GPIO_2), (0, 3, CPU_GPIO_3), (0, 4, CPU_GPIO_4), (0, 5,
667        CPU_GPIO_5), (0, 6, CPU_GPIO_6), (0, 7, CPU_GPIO_7)));
668    };
669}
670/// Defines the `LpInputSignal` and `LpOutputSignal` enums.
671///
672/// This macro is intended to be called in esp-hal only.
673#[macro_export]
674#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
675macro_rules! define_lp_io_signals {
676    () => {};
677}
678#[macro_export]
679#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
680macro_rules! for_each_ecc_working_mode {
681    ($($pattern:tt => $code:tt;)*) => {
682        macro_rules! _for_each_inner_ecc_working_mode { $(($pattern) => $code;)* ($other
683        : tt) => {} } _for_each_inner_ecc_working_mode!((0, AffinePointMultiplication));
684        _for_each_inner_ecc_working_mode!((2, AffinePointVerification));
685        _for_each_inner_ecc_working_mode!((3, AffinePointVerificationAndMultiplication));
686        _for_each_inner_ecc_working_mode!((4, JacobianPointMultiplication));
687        _for_each_inner_ecc_working_mode!((5, AffinePointAddition));
688        _for_each_inner_ecc_working_mode!((6, JacobianPointVerification));
689        _for_each_inner_ecc_working_mode!((7,
690        AffinePointVerificationAndJacobianPointMultiplication));
691        _for_each_inner_ecc_working_mode!((8, ModularAddition));
692        _for_each_inner_ecc_working_mode!((9, ModularSubtraction));
693        _for_each_inner_ecc_working_mode!((10, ModularMultiplication));
694        _for_each_inner_ecc_working_mode!((11, ModularDivision));
695        _for_each_inner_ecc_working_mode!((all(0, AffinePointMultiplication), (2,
696        AffinePointVerification), (3, AffinePointVerificationAndMultiplication), (4,
697        JacobianPointMultiplication), (5, AffinePointAddition), (6,
698        JacobianPointVerification), (7,
699        AffinePointVerificationAndJacobianPointMultiplication), (8, ModularAddition), (9,
700        ModularSubtraction), (10, ModularMultiplication), (11, ModularDivision)));
701    };
702}
703#[macro_export]
704#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
705macro_rules! for_each_ecc_curve {
706    ($($pattern:tt => $code:tt;)*) => {
707        macro_rules! _for_each_inner_ecc_curve { $(($pattern) => $code;)* ($other : tt)
708        => {} } _for_each_inner_ecc_curve!((0, P192, 192));
709        _for_each_inner_ecc_curve!((1, P256, 256)); _for_each_inner_ecc_curve!((all(0,
710        P192, 192), (1, P256, 256)));
711    };
712}
713#[macro_export]
714#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
715macro_rules! for_each_sha_algorithm {
716    ($($pattern:tt => $code:tt;)*) => {
717        macro_rules! _for_each_inner_sha_algorithm { $(($pattern) => $code;)* ($other :
718        tt) => {} } _for_each_inner_sha_algorithm!((Sha1, "SHA-1"(sizes : 64, 20, 8)
719        (insecure_against : "collision", "length extension"), 0));
720        _for_each_inner_sha_algorithm!((Sha224, "SHA-224"(sizes : 64, 28, 8)
721        (insecure_against : "length extension"), 1));
722        _for_each_inner_sha_algorithm!((Sha256, "SHA-256"(sizes : 64, 32, 8)
723        (insecure_against : "length extension"), 2));
724        _for_each_inner_sha_algorithm!((algos(Sha1, "SHA-1"(sizes : 64, 20, 8)
725        (insecure_against : "collision", "length extension"), 0), (Sha224,
726        "SHA-224"(sizes : 64, 28, 8) (insecure_against : "length extension"), 1),
727        (Sha256, "SHA-256"(sizes : 64, 32, 8) (insecure_against : "length extension"),
728        2)));
729    };
730}
731#[macro_export]
732#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
733macro_rules! for_each_wakeup_source {
734    ($($pattern:tt => $code:tt;)*) => {
735        macro_rules! _for_each_inner_wakeup_source { $(($pattern) => $code;)* ($other :
736        tt) => {} } _for_each_inner_wakeup_source!((Ext1, 1));
737        _for_each_inner_wakeup_source!((Gpio, 2));
738        _for_each_inner_wakeup_source!((WifiBeacon, 3));
739        _for_each_inner_wakeup_source!((Timer, 4)); _for_each_inner_wakeup_source!((Wifi,
740        5)); _for_each_inner_wakeup_source!((Uart0, 6));
741        _for_each_inner_wakeup_source!((Uart1, 7)); _for_each_inner_wakeup_source!((Sdio,
742        8)); _for_each_inner_wakeup_source!((Uart2, 9));
743        _for_each_inner_wakeup_source!((Bt, 10)); _for_each_inner_wakeup_source!((LpCore,
744        11)); _for_each_inner_wakeup_source!((all(Ext1, 1), (Gpio, 2), (WifiBeacon, 3),
745        (Timer, 4), (Wifi, 5), (Uart0, 6), (Uart1, 7), (Sdio, 8), (Uart2, 9), (Bt, 10),
746        (LpCore, 11)));
747    };
748}
749#[macro_export]
750#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
751macro_rules! for_each_dma_engine {
752    ($($pattern:tt => $code:tt;)*) => {
753        macro_rules! _for_each_inner_dma_engine { $(($pattern) => $code;)* ($other : tt)
754        => {} } _for_each_inner_dma_engine!(("AHB_GDMA"));
755        _for_each_inner_dma_engine!((all("AHB_GDMA")));
756    };
757}
758#[macro_export]
759#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
760macro_rules! for_each_dma_channel {
761    ($($pattern:tt => $code:tt;)*) => {
762        macro_rules! _for_each_inner_dma_channel { $(($pattern) => $code;)* ($other : tt)
763        => {} } _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH0));
764        _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH1));
765        _for_each_inner_dma_channel!(("AHB_GDMA", any_channel = AhbGdmaChannel));
766        _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH0, 0, interrupt_in = DMA_IN_CH0,
767        interrupt_out = DMA_OUT_CH0, compatible = [SPI2, I2S0, SHA]));
768        _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH1, 1, interrupt_in = DMA_IN_CH1,
769        interrupt_out = DMA_OUT_CH1, compatible = [SPI2, I2S0, SHA]));
770        _for_each_inner_dma_channel!((names("AHB_GDMA", DMA_CH0), ("AHB_GDMA",
771        DMA_CH1))); _for_each_inner_dma_channel!((separate_any_type("AHB_GDMA",
772        any_channel = AhbGdmaChannel))); _for_each_inner_dma_channel!((shared));
773        _for_each_inner_dma_channel!((split("AHB_GDMA", DMA_CH0, 0, interrupt_in =
774        DMA_IN_CH0, interrupt_out = DMA_OUT_CH0, compatible = [SPI2, I2S0, SHA]),
775        ("AHB_GDMA", DMA_CH1, 1, interrupt_in = DMA_IN_CH1, interrupt_out = DMA_OUT_CH1,
776        compatible = [SPI2, I2S0, SHA])));
777        _for_each_inner_dma_channel!((no_own_interrupt));
778    };
779}
780#[macro_export]
781#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
782macro_rules! for_each_dma_channel_peri_pair {
783    ($($pattern:tt => $code:tt;)*) => {
784        macro_rules! _for_each_inner_dma_channel_peri_pair { $(($pattern) => $code;)*
785        ($other : tt) => {} } _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA",
786        DMA_CH0, SPI2)); _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH0,
787        I2S0)); _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH0, SHA));
788        _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH1, SPI2));
789        _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH1, I2S0));
790        _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH1, SHA));
791        _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", any_channel = AhbGdmaChannel,
792        SPI2)); _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", any_channel =
793        AhbGdmaChannel, I2S0)); _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA",
794        any_channel = AhbGdmaChannel, SHA));
795        _for_each_inner_dma_channel_peri_pair!((channels("AHB_GDMA", DMA_CH0, SPI2),
796        ("AHB_GDMA", DMA_CH0, I2S0), ("AHB_GDMA", DMA_CH0, SHA), ("AHB_GDMA", DMA_CH1,
797        SPI2), ("AHB_GDMA", DMA_CH1, I2S0), ("AHB_GDMA", DMA_CH1, SHA)));
798        _for_each_inner_dma_channel_peri_pair!((any_channels("AHB_GDMA", any_channel =
799        AhbGdmaChannel, SPI2), ("AHB_GDMA", any_channel = AhbGdmaChannel, I2S0),
800        ("AHB_GDMA", any_channel = AhbGdmaChannel, SHA)));
801    };
802}
803#[macro_export]
804#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
805macro_rules! for_each_mem2mem_channel {
806    ($($pattern:tt => $code:tt;)*) => {
807        macro_rules! _for_each_inner_mem2mem_channel { $(($pattern) => $code;)* ($other :
808        tt) => {} } _for_each_inner_mem2mem_channel!(("AHB_GDMA", AhbGdma,
809        AhbGdmaChannel, DMA_CH0, 4)); _for_each_inner_mem2mem_channel!(("AHB_GDMA",
810        AhbGdma, AhbGdmaChannel, DMA_CH1, 5));
811        _for_each_inner_mem2mem_channel!(("AHB_GDMA", AhbGdma, AhbGdmaChannel, 0, 4, 1,
812        5)); _for_each_inner_mem2mem_channel!(("AHB_GDMA", AhbGdma, AhbGdmaChannel));
813        _for_each_inner_mem2mem_channel!((channels("AHB_GDMA", AhbGdma, AhbGdmaChannel,
814        DMA_CH0, 4), ("AHB_GDMA", AhbGdma, AhbGdmaChannel, DMA_CH1, 5)));
815        _for_each_inner_mem2mem_channel!((erased("AHB_GDMA", AhbGdma, AhbGdmaChannel, 0,
816        4, 1, 5))); _for_each_inner_mem2mem_channel!((engines("AHB_GDMA", AhbGdma,
817        AhbGdmaChannel)));
818    };
819}
820#[macro_export]
821#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
822macro_rules! with_i2s_dma_engine {
823    ($($pattern:tt => $code:tt;)*) => {
824        macro_rules! _with_inner_i2s_dma_engine { $(($pattern) => $code;)* ($other : tt)
825        => {} } _with_inner_i2s_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
826    };
827}
828#[macro_export]
829#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
830macro_rules! with_sha_dma_engine {
831    ($($pattern:tt => $code:tt;)*) => {
832        macro_rules! _with_inner_sha_dma_engine { $(($pattern) => $code;)* ($other : tt)
833        => {} } _with_inner_sha_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
834    };
835}
836#[macro_export]
837#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
838macro_rules! with_spi_master_dma_engine {
839    ($($pattern:tt => $code:tt;)*) => {
840        macro_rules! _with_inner_spi_master_dma_engine { $(($pattern) => $code;)* ($other
841        : tt) => {} } _with_inner_spi_master_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
842    };
843}
844#[macro_export]
845#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
846macro_rules! with_spi_slave_dma_engine {
847    ($($pattern:tt => $code:tt;)*) => {
848        macro_rules! _with_inner_spi_slave_dma_engine { $(($pattern) => $code;)* ($other
849        : tt) => {} } _with_inner_spi_slave_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
850    };
851}
852#[macro_export]
853#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
854macro_rules! for_each_interrupt {
855    ($($pattern:tt => $code:tt;)*) => {
856        macro_rules! _for_each_inner_interrupt { $(($pattern) => $code;)* ($other : tt)
857        => {} } _for_each_inner_interrupt!(([disabled 0] 0));
858        _for_each_inner_interrupt!(([reserved 0] 1));
859        _for_each_inner_interrupt!(([reserved 1] 2));
860        _for_each_inner_interrupt!(([reserved 2] 3));
861        _for_each_inner_interrupt!(([reserved 3] 4));
862        _for_each_inner_interrupt!(([reserved 4] 5));
863        _for_each_inner_interrupt!(([reserved 5] 6));
864        _for_each_inner_interrupt!(([reserved 6] 7));
865        _for_each_inner_interrupt!(([reserved 7] 8));
866        _for_each_inner_interrupt!(([reserved 8] 9));
867        _for_each_inner_interrupt!(([reserved 9] 10));
868        _for_each_inner_interrupt!(([reserved 10] 11));
869        _for_each_inner_interrupt!(([reserved 11] 12));
870        _for_each_inner_interrupt!(([reserved 12] 13));
871        _for_each_inner_interrupt!(([reserved 13] 14));
872        _for_each_inner_interrupt!(([reserved 14] 15));
873        _for_each_inner_interrupt!(([vector 0] 16)); _for_each_inner_interrupt!(([vector
874        1] 17)); _for_each_inner_interrupt!(([vector 2] 18));
875        _for_each_inner_interrupt!(([vector 3] 19)); _for_each_inner_interrupt!(([vector
876        4] 20)); _for_each_inner_interrupt!(([vector 5] 21));
877        _for_each_inner_interrupt!(([vector 6] 22)); _for_each_inner_interrupt!(([vector
878        7] 23)); _for_each_inner_interrupt!(([direct_bindable 0] 24));
879        _for_each_inner_interrupt!(([direct_bindable 1] 25));
880        _for_each_inner_interrupt!(([direct_bindable 2] 26));
881        _for_each_inner_interrupt!(([direct_bindable 3] 27));
882        _for_each_inner_interrupt!(([direct_bindable 4] 28));
883        _for_each_inner_interrupt!(([direct_bindable 5] 29));
884        _for_each_inner_interrupt!(([direct_bindable 6] 30));
885        _for_each_inner_interrupt!(([direct_bindable 7] 31));
886        _for_each_inner_interrupt!((all([disabled 0] 0), ([reserved 0] 1), ([reserved 1]
887        2), ([reserved 2] 3), ([reserved 3] 4), ([reserved 4] 5), ([reserved 5] 6),
888        ([reserved 6] 7), ([reserved 7] 8), ([reserved 8] 9), ([reserved 9] 10),
889        ([reserved 10] 11), ([reserved 11] 12), ([reserved 12] 13), ([reserved 13] 14),
890        ([reserved 14] 15), ([vector 0] 16), ([vector 1] 17), ([vector 2] 18), ([vector
891        3] 19), ([vector 4] 20), ([vector 5] 21), ([vector 6] 22), ([vector 7] 23),
892        ([direct_bindable 0] 24), ([direct_bindable 1] 25), ([direct_bindable 2] 26),
893        ([direct_bindable 3] 27), ([direct_bindable 4] 28), ([direct_bindable 5] 29),
894        ([direct_bindable 6] 30), ([direct_bindable 7] 31)));
895    };
896}
897#[macro_export]
898#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
899macro_rules! for_each_classified_interrupt {
900    ($($pattern:tt => $code:tt;)*) => {
901        macro_rules! _for_each_inner_classified_interrupt { $(($pattern) => $code;)*
902        ($other : tt) => {} } _for_each_inner_classified_interrupt!(([direct_bindable 0]
903        24)); _for_each_inner_classified_interrupt!(([direct_bindable 1] 25));
904        _for_each_inner_classified_interrupt!(([direct_bindable 2] 26));
905        _for_each_inner_classified_interrupt!(([direct_bindable 3] 27));
906        _for_each_inner_classified_interrupt!(([direct_bindable 4] 28));
907        _for_each_inner_classified_interrupt!(([direct_bindable 5] 29));
908        _for_each_inner_classified_interrupt!(([direct_bindable 6] 30));
909        _for_each_inner_classified_interrupt!(([direct_bindable 7] 31));
910        _for_each_inner_classified_interrupt!(([vector 0] 16));
911        _for_each_inner_classified_interrupt!(([vector 1] 17));
912        _for_each_inner_classified_interrupt!(([vector 2] 18));
913        _for_each_inner_classified_interrupt!(([vector 3] 19));
914        _for_each_inner_classified_interrupt!(([vector 4] 20));
915        _for_each_inner_classified_interrupt!(([vector 5] 21));
916        _for_each_inner_classified_interrupt!(([vector 6] 22));
917        _for_each_inner_classified_interrupt!(([vector 7] 23));
918        _for_each_inner_classified_interrupt!(([reserved 0] 1));
919        _for_each_inner_classified_interrupt!(([reserved 1] 2));
920        _for_each_inner_classified_interrupt!(([reserved 2] 3));
921        _for_each_inner_classified_interrupt!(([reserved 3] 4));
922        _for_each_inner_classified_interrupt!(([reserved 4] 5));
923        _for_each_inner_classified_interrupt!(([reserved 5] 6));
924        _for_each_inner_classified_interrupt!(([reserved 6] 7));
925        _for_each_inner_classified_interrupt!(([reserved 7] 8));
926        _for_each_inner_classified_interrupt!(([reserved 8] 9));
927        _for_each_inner_classified_interrupt!(([reserved 9] 10));
928        _for_each_inner_classified_interrupt!(([reserved 10] 11));
929        _for_each_inner_classified_interrupt!(([reserved 11] 12));
930        _for_each_inner_classified_interrupt!(([reserved 12] 13));
931        _for_each_inner_classified_interrupt!(([reserved 13] 14));
932        _for_each_inner_classified_interrupt!(([reserved 14] 15));
933        _for_each_inner_classified_interrupt!((direct_bindable([direct_bindable 0] 24),
934        ([direct_bindable 1] 25), ([direct_bindable 2] 26), ([direct_bindable 3] 27),
935        ([direct_bindable 4] 28), ([direct_bindable 5] 29), ([direct_bindable 6] 30),
936        ([direct_bindable 7] 31))); _for_each_inner_classified_interrupt!((vector([vector
937        0] 16), ([vector 1] 17), ([vector 2] 18), ([vector 3] 19), ([vector 4] 20),
938        ([vector 5] 21), ([vector 6] 22), ([vector 7] 23)));
939        _for_each_inner_classified_interrupt!((reserved([reserved 0] 1), ([reserved 1]
940        2), ([reserved 2] 3), ([reserved 3] 4), ([reserved 4] 5), ([reserved 5] 6),
941        ([reserved 6] 7), ([reserved 7] 8), ([reserved 8] 9), ([reserved 9] 10),
942        ([reserved 10] 11), ([reserved 11] 12), ([reserved 12] 13), ([reserved 13] 14),
943        ([reserved 14] 15))); _for_each_inner_classified_interrupt!((context_switch));
944    };
945}
946#[macro_export]
947#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
948macro_rules! for_each_interrupt_priority {
949    ($($pattern:tt => $code:tt;)*) => {
950        macro_rules! _for_each_inner_interrupt_priority { $(($pattern) => $code;)*
951        ($other : tt) => {} } _for_each_inner_interrupt_priority!((0, 1, Priority1,
952        Level1)); _for_each_inner_interrupt_priority!((1, 2, Priority2, Level2));
953        _for_each_inner_interrupt_priority!((2, 3, Priority3, Level3));
954        _for_each_inner_interrupt_priority!((3, 4, Priority4, Level4));
955        _for_each_inner_interrupt_priority!((4, 5, Priority5, Level5));
956        _for_each_inner_interrupt_priority!((5, 6, Priority6, Level6));
957        _for_each_inner_interrupt_priority!((6, 7, Priority7, Level7));
958        _for_each_inner_interrupt_priority!((7, 8, Priority8, Level8));
959        _for_each_inner_interrupt_priority!((all(0, 1, Priority1, Level1), (1, 2,
960        Priority2, Level2), (2, 3, Priority3, Level3), (3, 4, Priority4, Level4), (4, 5,
961        Priority5, Level5), (5, 6, Priority6, Level6), (6, 7, Priority7, Level7), (7, 8,
962        Priority8, Level8)));
963    };
964}
965#[macro_export]
966#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
967macro_rules! for_each_sw_interrupt {
968    ($($pattern:tt => $code:tt;)*) => {
969        macro_rules! _for_each_inner_sw_interrupt { $(($pattern) => $code;)* ($other :
970        tt) => {} } _for_each_inner_sw_interrupt!((0, FROM_CPU_INTR0,
971        software_interrupt0)); _for_each_inner_sw_interrupt!((1, FROM_CPU_INTR1,
972        software_interrupt1)); _for_each_inner_sw_interrupt!((2, FROM_CPU_INTR2,
973        software_interrupt2)); _for_each_inner_sw_interrupt!((3, FROM_CPU_INTR3,
974        software_interrupt3)); _for_each_inner_sw_interrupt!((all(0, FROM_CPU_INTR0,
975        software_interrupt0), (1, FROM_CPU_INTR1, software_interrupt1), (2,
976        FROM_CPU_INTR2, software_interrupt2), (3, FROM_CPU_INTR3, software_interrupt3)));
977    };
978}
979#[macro_export]
980/// ESP-HAL must provide implementation for the following functions:
981/// ```rust, no_run
982/// // XTAL_CLK
983///
984/// fn configure_xtal_clk_impl(
985///     _clocks: &mut ClockTree,
986///     _old_config: Option<XtalClkConfig>,
987///     _new_config: XtalClkConfig,
988/// ) {
989///     todo!()
990/// }
991///
992/// // RC_FAST_CLK
993///
994/// fn enable_rc_fast_clk_impl(_clocks: &mut ClockTree, _en: bool) {
995///     todo!()
996/// }
997///
998/// // PLL_CLK
999///
1000/// fn enable_pll_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1001///     todo!()
1002/// }
1003///
1004/// // XTAL32K_CLK
1005///
1006/// #[cfg(use_xtal32k)]
1007/// fn enable_xtal32k_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1008///     todo!()
1009/// }
1010///
1011/// // OSC_SLOW_CLK
1012///
1013/// fn enable_osc_slow_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1014///     todo!()
1015/// }
1016///
1017/// // RC_SLOW_CLK
1018///
1019/// fn enable_rc_slow_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1020///     todo!()
1021/// }
1022///
1023/// // PLL_F20M
1024///
1025/// fn enable_pll_f20m_impl(_clocks: &mut ClockTree, _en: bool) {
1026///     todo!()
1027/// }
1028///
1029/// // PLL_F40M
1030///
1031/// fn enable_pll_f40m_impl(_clocks: &mut ClockTree, _en: bool) {
1032///     todo!()
1033/// }
1034///
1035/// // PLL_F48M
1036///
1037/// fn enable_pll_f48m_impl(_clocks: &mut ClockTree, _en: bool) {
1038///     todo!()
1039/// }
1040///
1041/// // PLL_F60M
1042///
1043/// fn enable_pll_f60m_impl(_clocks: &mut ClockTree, _en: bool) {
1044///     todo!()
1045/// }
1046///
1047/// // PLL_F80M
1048///
1049/// fn enable_pll_f80m_impl(_clocks: &mut ClockTree, _en: bool) {
1050///     todo!()
1051/// }
1052///
1053/// // PLL_F120M
1054///
1055/// fn enable_pll_f120m_impl(_clocks: &mut ClockTree, _en: bool) {
1056///     todo!()
1057/// }
1058///
1059/// // PLL_F160M
1060///
1061/// fn enable_pll_f160m_impl(_clocks: &mut ClockTree, _en: bool) {
1062///     todo!()
1063/// }
1064///
1065/// // HP_ROOT_CLK
1066///
1067/// fn enable_hp_root_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1068///     todo!()
1069/// }
1070///
1071/// fn configure_hp_root_clk_impl(
1072///     _clocks: &mut ClockTree,
1073///     _old_config: Option<HpRootClkConfig>,
1074///     _new_config: HpRootClkConfig,
1075/// ) {
1076///     todo!()
1077/// }
1078///
1079/// // CPU_CLK
1080///
1081/// fn configure_cpu_clk_impl(
1082///     _clocks: &mut ClockTree,
1083///     _old_config: Option<CpuClkConfig>,
1084///     _new_config: CpuClkConfig,
1085/// ) {
1086///     todo!()
1087/// }
1088///
1089/// // AHB_CLK
1090///
1091/// fn configure_ahb_clk_impl(
1092///     _clocks: &mut ClockTree,
1093///     _old_config: Option<AhbClkConfig>,
1094///     _new_config: AhbClkConfig,
1095/// ) {
1096///     todo!()
1097/// }
1098///
1099/// // APB_CLK
1100///
1101/// fn enable_apb_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1102///     todo!()
1103/// }
1104///
1105/// fn configure_apb_clk_impl(
1106///     _clocks: &mut ClockTree,
1107///     _old_config: Option<ApbClkConfig>,
1108///     _new_config: ApbClkConfig,
1109/// ) {
1110///     todo!()
1111/// }
1112///
1113/// // XTAL_D2_CLK
1114///
1115/// fn enable_xtal_d2_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1116///     todo!()
1117/// }
1118///
1119/// // LP_FAST_CLK
1120///
1121/// fn enable_lp_fast_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1122///     todo!()
1123/// }
1124///
1125/// fn configure_lp_fast_clk_impl(
1126///     _clocks: &mut ClockTree,
1127///     _old_config: Option<LpFastClkConfig>,
1128///     _new_config: LpFastClkConfig,
1129/// ) {
1130///     todo!()
1131/// }
1132///
1133/// // LP_SLOW_CLK
1134///
1135/// fn enable_lp_slow_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1136///     todo!()
1137/// }
1138///
1139/// fn configure_lp_slow_clk_impl(
1140///     _clocks: &mut ClockTree,
1141///     _old_config: Option<LpSlowClkConfig>,
1142///     _new_config: LpSlowClkConfig,
1143/// ) {
1144///     todo!()
1145/// }
1146///
1147/// // BLE_LP_XTAL_CLK
1148///
1149/// fn enable_ble_lp_xtal_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1150///     todo!()
1151/// }
1152///
1153/// // BLE_LP_RC_SLOW_CLK
1154///
1155/// fn enable_ble_lp_rc_slow_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1156///     todo!()
1157/// }
1158///
1159/// // BLE_LP_CLK
1160///
1161/// fn enable_ble_lp_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1162///     todo!()
1163/// }
1164///
1165/// fn configure_ble_lp_clk_impl(
1166///     _clocks: &mut ClockTree,
1167///     _old_config: Option<BleLpClkConfig>,
1168///     _new_config: BleLpClkConfig,
1169/// ) {
1170///     todo!()
1171/// }
1172///
1173/// // CRYPTO_PLL_DIV
1174///
1175/// fn enable_crypto_pll_div_impl(_clocks: &mut ClockTree, _en: bool) {
1176///     todo!()
1177/// }
1178///
1179/// // CRYPTO_CLK
1180///
1181/// fn enable_crypto_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1182///     todo!()
1183/// }
1184///
1185/// fn configure_crypto_clk_impl(
1186///     _clocks: &mut ClockTree,
1187///     _old_config: Option<CryptoClkConfig>,
1188///     _new_config: CryptoClkConfig,
1189/// ) {
1190///     todo!()
1191/// }
1192///
1193/// // TIMG_CALIBRATION_CLOCK
1194///
1195/// fn enable_timg_calibration_clock_impl(_clocks: &mut ClockTree, _en: bool) {
1196///     todo!()
1197/// }
1198///
1199/// fn configure_timg_calibration_clock_impl(
1200///     _clocks: &mut ClockTree,
1201///     _old_config: Option<TimgCalibrationClockConfig>,
1202///     _new_config: TimgCalibrationClockConfig,
1203/// ) {
1204///     todo!()
1205/// }
1206///
1207/// impl AdcInstance {
1208///     // ADC_FUNCTION_CLOCK
1209///
1210///     fn enable_function_clock_impl(self, _clocks: &mut ClockTree, _en: bool) {
1211///         todo!()
1212///     }
1213///
1214///     fn configure_function_clock_impl(
1215///         self,
1216///         _clocks: &mut ClockTree,
1217///         _old_config: Option<AdcFunctionClockConfig>,
1218///         _new_config: AdcFunctionClockConfig,
1219///     ) {
1220///         todo!()
1221///     }
1222/// }
1223/// impl I2cInstance {
1224///     // I2C_FUNCTION_CLOCK
1225///
1226///     fn enable_function_clock_impl(self, _clocks: &mut ClockTree, _en: bool) {
1227///         todo!()
1228///     }
1229///
1230///     fn configure_function_clock_impl(
1231///         self,
1232///         _clocks: &mut ClockTree,
1233///         _old_config: Option<I2cFunctionClockConfig>,
1234///         _new_config: I2cFunctionClockConfig,
1235///     ) {
1236///         todo!()
1237///     }
1238/// }
1239/// impl I2sInstance {
1240///     // I2S_TX_CLK
1241///
1242///     fn enable_tx_clk_impl(self, _clocks: &mut ClockTree, _en: bool) {
1243///         todo!()
1244///     }
1245///
1246///     fn configure_tx_clk_impl(
1247///         self,
1248///         _clocks: &mut ClockTree,
1249///         _old_config: Option<I2sClkConfig>,
1250///         _new_config: I2sClkConfig,
1251///     ) {
1252///         todo!()
1253///     }
1254///
1255///     // I2S_RX_CLK
1256///
1257///     fn enable_rx_clk_impl(self, _clocks: &mut ClockTree, _en: bool) {
1258///         todo!()
1259///     }
1260///
1261///     fn configure_rx_clk_impl(
1262///         self,
1263///         _clocks: &mut ClockTree,
1264///         _old_config: Option<I2sClkConfig>,
1265///         _new_config: I2sClkConfig,
1266///     ) {
1267///         todo!()
1268///     }
1269///
1270///     // I2S_MCLK_OUT
1271///
1272///     fn enable_mclk_out_impl(self, _clocks: &mut ClockTree, _en: bool) {
1273///         todo!()
1274///     }
1275///
1276///     fn configure_mclk_out_impl(
1277///         self,
1278///         _clocks: &mut ClockTree,
1279///         _old_config: Option<I2sMclkOutConfig>,
1280///         _new_config: I2sMclkOutConfig,
1281///     ) {
1282///         todo!()
1283///     }
1284/// }
1285/// impl SpiInstance {
1286///     // SPI_FUNCTION_CLOCK
1287///
1288///     fn enable_function_clock_impl(self, _clocks: &mut ClockTree, _en: bool) {
1289///         todo!()
1290///     }
1291///
1292///     fn configure_function_clock_impl(
1293///         self,
1294///         _clocks: &mut ClockTree,
1295///         _old_config: Option<SpiFunctionClockConfig>,
1296///         _new_config: SpiFunctionClockConfig,
1297///     ) {
1298///         todo!()
1299///     }
1300/// }
1301/// impl TimgInstance {
1302///     // TIMG_FUNCTION_CLOCK
1303///
1304///     fn enable_function_clock_impl(self, _clocks: &mut ClockTree, _en: bool) {
1305///         todo!()
1306///     }
1307///
1308///     fn configure_function_clock_impl(
1309///         self,
1310///         _clocks: &mut ClockTree,
1311///         _old_config: Option<TimgFunctionClockConfig>,
1312///         _new_config: TimgFunctionClockConfig,
1313///     ) {
1314///         todo!()
1315///     }
1316///
1317///     // TIMG_WDT_CLOCK
1318///
1319///     fn enable_wdt_clock_impl(self, _clocks: &mut ClockTree, _en: bool) {
1320///         todo!()
1321///     }
1322///
1323///     fn configure_wdt_clock_impl(
1324///         self,
1325///         _clocks: &mut ClockTree,
1326///         _old_config: Option<TimgWdtClockConfig>,
1327///         _new_config: TimgWdtClockConfig,
1328///     ) {
1329///         todo!()
1330///     }
1331/// }
1332/// impl UartInstance {
1333///     // UART_FUNCTION_CLOCK
1334///
1335///     fn enable_function_clock_impl(self, _clocks: &mut ClockTree, _en: bool) {
1336///         todo!()
1337///     }
1338///
1339///     fn configure_function_clock_impl(
1340///         self,
1341///         _clocks: &mut ClockTree,
1342///         _old_config: Option<UartFunctionClockConfig>,
1343///         _new_config: UartFunctionClockConfig,
1344///     ) {
1345///         todo!()
1346///     }
1347///
1348///     // UART_BAUD_RATE_GENERATOR
1349///
1350///     fn enable_baud_rate_generator_impl(self, _clocks: &mut ClockTree, _en: bool) {
1351///         todo!()
1352///     }
1353///
1354///     fn configure_baud_rate_generator_impl(
1355///         self,
1356///         _clocks: &mut ClockTree,
1357///         _old_config: Option<UartBaudRateGeneratorConfig>,
1358///         _new_config: UartBaudRateGeneratorConfig,
1359///     ) {
1360///         todo!()
1361///     }
1362/// }
1363/// ```
1364macro_rules! define_clock_tree_types {
1365    () => {
1366        #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1367        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1368        pub enum AdcInstance {
1369            ApbSaradc = 0,
1370        }
1371        #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1372        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1373        pub enum I2cInstance {
1374            I2c0 = 0,
1375        }
1376        #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1377        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1378        pub enum I2sInstance {
1379            I2s0 = 0,
1380        }
1381        #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1382        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1383        pub enum SpiInstance {
1384            Spi2 = 0,
1385        }
1386        #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1387        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1388        pub enum TimgInstance {
1389            Timg0 = 0,
1390            Timg1 = 1,
1391        }
1392        #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1393        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1394        pub enum UartInstance {
1395            Uart0 = 0,
1396            Uart1 = 1,
1397            Uart2 = 2,
1398        }
1399        /// Selects the output frequency of `XTAL_CLK`.
1400        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1401        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1402        pub enum XtalClkConfig {
1403            /// 40 MHz
1404            _40,
1405        }
1406        impl XtalClkConfig {
1407            pub fn value(&self) -> u32 {
1408                match self {
1409                    XtalClkConfig::_40 => 40000000,
1410                }
1411            }
1412        }
1413        /// The list of clock signals that the `HP_ROOT_CLK` multiplexer can output.
1414        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1415        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1416        pub enum HpRootClkConfig {
1417            /// Selects `XTAL_CLK`.
1418            Xtal,
1419            /// Selects `RC_FAST_CLK`.
1420            RcFast,
1421            /// Selects `PLL_F160M`.
1422            PllF160m,
1423        }
1424        /// Configures the `CPU_CLK` clock node.
1425        ///
1426        /// The output is calculated as `OUTPUT = HP_ROOT_CLK / (divisor + 1)`.
1427        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1428        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1429        pub struct CpuClkConfig {
1430            divisor: u32,
1431        }
1432        impl CpuClkConfig {
1433            /// Creates a new configuration for the CPU_CLK clock node.
1434            ///
1435            /// ## Panics
1436            ///
1437            /// Panics if the divisor value is outside the
1438            /// valid range (0 ..= 255).
1439            pub const fn new(divisor: u32) -> Self {
1440                ::core::assert!(
1441                    divisor <= 255,
1442                    "`CPU_CLK` divisor must be between 0 and 255 (inclusive)."
1443                );
1444                Self { divisor }
1445            }
1446            pub fn divisor(self) -> u32 {
1447                self.divisor as u32
1448            }
1449        }
1450        /// Configures the `AHB_CLK` clock node.
1451        ///
1452        /// The output is calculated as `OUTPUT = HP_ROOT_CLK / (divisor + 1)`.
1453        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1454        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1455        pub struct AhbClkConfig {
1456            divisor: u32,
1457        }
1458        impl AhbClkConfig {
1459            /// Creates a new configuration for the AHB_CLK clock node.
1460            ///
1461            /// ## Panics
1462            ///
1463            /// Panics if the divisor value is outside the
1464            /// valid range (0 ..= 255).
1465            pub const fn new(divisor: u32) -> Self {
1466                ::core::assert!(
1467                    divisor <= 255,
1468                    "`AHB_CLK` divisor must be between 0 and 255 (inclusive)."
1469                );
1470                Self { divisor }
1471            }
1472            pub fn divisor(self) -> u32 {
1473                self.divisor as u32
1474            }
1475        }
1476        /// Configures the `APB_CLK` clock node.
1477        ///
1478        /// The output is calculated as `OUTPUT = AHB_CLK / (divisor + 1)`.
1479        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1480        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1481        pub struct ApbClkConfig {
1482            divisor: u32,
1483        }
1484        impl ApbClkConfig {
1485            /// Creates a new configuration for the APB_CLK clock node.
1486            ///
1487            /// ## Panics
1488            ///
1489            /// Panics if the divisor value is outside the
1490            /// valid range (0 ..= 255).
1491            pub const fn new(divisor: u32) -> Self {
1492                ::core::assert!(
1493                    divisor <= 255,
1494                    "`APB_CLK` divisor must be between 0 and 255 (inclusive)."
1495                );
1496                Self { divisor }
1497            }
1498            pub fn divisor(self) -> u32 {
1499                self.divisor as u32
1500            }
1501        }
1502        /// The list of clock signals that the `LP_FAST_CLK` multiplexer can output.
1503        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1504        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1505        pub enum LpFastClkConfig {
1506            /// Selects `RC_FAST_CLK`.
1507            RcFast,
1508            /// Selects `XTAL_D2_CLK`.
1509            XtalD2,
1510            /// Selects `XTAL_CLK`.
1511            Xtal,
1512        }
1513        /// The list of clock signals that the `LP_SLOW_CLK` multiplexer can output.
1514        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1515        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1516        pub enum LpSlowClkConfig {
1517            /// Selects `RC_SLOW_CLK`.
1518            RcSlow,
1519            #[cfg(use_xtal32k)]
1520            /// Selects `XTAL32K_CLK`.
1521            Xtal32k,
1522            /// Selects `OSC_SLOW_CLK`.
1523            OscSlow,
1524        }
1525        /// The list of clock signals that the `BLE_LP_CLK` multiplexer can output.
1526        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1527        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1528        pub enum BleLpClkConfig {
1529            /// Selects `BLE_LP_XTAL_CLK`.
1530            Xtal,
1531            /// Selects `BLE_LP_RC_SLOW_CLK`.
1532            RcSlow,
1533            #[cfg(use_xtal32k)]
1534            /// Selects `XTAL32K_CLK`.
1535            Xtal32k,
1536        }
1537        /// The list of clock signals that the `CRYPTO_CLK` multiplexer can output.
1538        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1539        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1540        pub enum CryptoClkConfig {
1541            /// Selects `XTAL_CLK`.
1542            Xtal,
1543            /// Selects `RC_FAST_CLK`.
1544            RcFast,
1545            /// Selects `CRYPTO_PLL_DIV`.
1546            PllF480m,
1547        }
1548        /// The list of clock signals that the `TIMG_CALIBRATION_CLOCK` multiplexer can output.
1549        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1550        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1551        pub enum TimgCalibrationClockConfig {
1552            /// Selects `OSC_SLOW_CLK`.
1553            OscSlowClk,
1554            /// Selects `RC_SLOW_CLK`.
1555            RcSlowClk,
1556            /// Selects `RC_FAST_CLK`.
1557            RcFastDivClk,
1558            #[cfg(use_xtal32k)]
1559            /// Selects `XTAL32K_CLK`.
1560            Xtal32kClk,
1561        }
1562        /// The list of clock signals that the `APB_SARADC_FUNCTION_CLOCK` multiplexer can output.
1563        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1564        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1565        pub enum AdcFunctionClockConfig {
1566            /// Selects `XTAL_CLK`.
1567            Xtal,
1568            /// Selects `RC_FAST_CLK`.
1569            RcFast,
1570            #[default]
1571            /// Selects `PLL_F80M`.
1572            PllF80m,
1573        }
1574        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1575        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1576        pub enum I2cFunctionClockSclk {
1577            #[default]
1578            /// Selects `XTAL_CLK`.
1579            Xtal,
1580            /// Selects `RC_FAST_CLK`.
1581            RcFast,
1582        }
1583        /// Configures the `I2C0_FUNCTION_CLOCK` clock node.
1584        ///
1585        /// The output is calculated as `OUTPUT = sclk / (div_num + 1)`.
1586        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1587        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1588        pub struct I2cFunctionClockConfig {
1589            sclk: I2cFunctionClockSclk,
1590            div_num: u32,
1591        }
1592        impl I2cFunctionClockConfig {
1593            /// Creates a new configuration for the FUNCTION_CLOCK clock node.
1594            ///
1595            /// ## Panics
1596            ///
1597            /// Panics if the div_num value is outside the
1598            /// valid range (0 ..= 255).
1599            pub const fn new(sclk: I2cFunctionClockSclk, div_num: u32) -> Self {
1600                ::core::assert!(
1601                    div_num <= 255,
1602                    "`I2C0_FUNCTION_CLOCK` div_num must be between 0 and 255 (inclusive)."
1603                );
1604                Self { sclk, div_num }
1605            }
1606            pub fn sclk(self) -> I2cFunctionClockSclk {
1607                self.sclk
1608            }
1609            pub fn div_num(self) -> u32 {
1610                self.div_num as u32
1611            }
1612        }
1613        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1614        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1615        pub enum I2sClkSclk {
1616            /// Selects `XTAL_CLK`.
1617            Xtal,
1618            /// Selects `PLL_F120M`.
1619            PllF120m,
1620            #[default]
1621            /// Selects `PLL_F160M`.
1622            PllF160m,
1623        }
1624        /// Configures the `I2S0_TX_CLK` clock node.
1625        ///
1626        /// The output is calculated as `OUTPUT = (sclk * div_a) / (div_num * div_a + div_b)`.
1627        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1628        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1629        pub struct I2sClkConfig {
1630            sclk: I2sClkSclk,
1631            div_num: u32,
1632            div_a: u32,
1633            div_b: u32,
1634        }
1635        impl I2sClkConfig {
1636            /// Creates a new configuration for the TX_CLK clock node.
1637            ///
1638            /// ## Panics
1639            ///
1640            /// Panics if the div_num value is outside the
1641            /// valid range (1 ..= 255).
1642            ///
1643            /// Panics if the div_a value is outside the
1644            /// valid range (1 ..= 511).
1645            ///
1646            /// Panics if the div_b value is outside the
1647            /// valid range (0 ..= 511).
1648            pub const fn new(sclk: I2sClkSclk, div_num: u32, div_a: u32, div_b: u32) -> Self {
1649                ::core::assert!(
1650                    div_num >= 1 && div_num <= 255,
1651                    "`I2S0_TX_CLK` div_num must be between 1 and 255 (inclusive)."
1652                );
1653                ::core::assert!(
1654                    div_a >= 1 && div_a <= 511,
1655                    "`I2S0_TX_CLK` div_a must be between 1 and 511 (inclusive)."
1656                );
1657                ::core::assert!(
1658                    div_b <= 511,
1659                    "`I2S0_TX_CLK` div_b must be between 0 and 511 (inclusive)."
1660                );
1661                Self {
1662                    sclk,
1663                    div_num,
1664                    div_a,
1665                    div_b,
1666                }
1667            }
1668            pub fn sclk(self) -> I2sClkSclk {
1669                self.sclk
1670            }
1671            pub fn div_num(self) -> u32 {
1672                self.div_num as u32
1673            }
1674            pub fn div_a(self) -> u32 {
1675                self.div_a as u32
1676            }
1677            pub fn div_b(self) -> u32 {
1678                self.div_b as u32
1679            }
1680        }
1681        /// The list of clock signals that the `I2S0_MCLK_OUT` multiplexer can output.
1682        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1683        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1684        pub enum I2sMclkOutConfig {
1685            /// Selects `TX_CLK`.
1686            Tx,
1687            #[default]
1688            /// Selects `RX_CLK`.
1689            Rx,
1690        }
1691        /// The list of clock signals that the `SPI2_FUNCTION_CLOCK` multiplexer can output.
1692        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1693        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1694        pub enum SpiFunctionClockConfig {
1695            /// Selects `XTAL_CLK`.
1696            Xtal,
1697            #[default]
1698            /// Selects `PLL_F160M`.
1699            PllF160m,
1700            /// Selects `RC_FAST_CLK`.
1701            RcFast,
1702        }
1703        /// The list of clock signals that the `TIMG0_FUNCTION_CLOCK` multiplexer can output.
1704        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1705        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1706        pub enum TimgFunctionClockConfig {
1707            #[default]
1708            /// Selects `XTAL_CLK`.
1709            XtalClk,
1710            /// Selects `RC_FAST_CLK`.
1711            RcFastClk,
1712            /// Selects `PLL_F80M`.
1713            PllF80m,
1714        }
1715        /// The list of clock signals that the `TIMG0_WDT_CLOCK` multiplexer can output.
1716        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1717        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1718        pub enum TimgWdtClockConfig {
1719            #[default]
1720            /// Selects `XTAL_CLK`.
1721            XtalClk,
1722            /// Selects `RC_FAST_CLK`.
1723            RcFastClk,
1724            /// Selects `PLL_F80M`.
1725            PllF80m,
1726        }
1727        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1728        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1729        pub enum UartFunctionClockSclk {
1730            #[default]
1731            /// Selects `XTAL_CLK`.
1732            Xtal,
1733            /// Selects `PLL_F80M`.
1734            PllF80m,
1735            /// Selects `RC_FAST_CLK`.
1736            RcFast,
1737        }
1738        /// Configures the `UART0_FUNCTION_CLOCK` clock node.
1739        ///
1740        /// The output is calculated as `OUTPUT = sclk / (div_num + 1)`.
1741        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1742        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1743        pub struct UartFunctionClockConfig {
1744            sclk: UartFunctionClockSclk,
1745            div_num: u32,
1746        }
1747        impl UartFunctionClockConfig {
1748            /// Creates a new configuration for the FUNCTION_CLOCK clock node.
1749            ///
1750            /// ## Panics
1751            ///
1752            /// Panics if the div_num value is outside the
1753            /// valid range (0 ..= 255).
1754            pub const fn new(sclk: UartFunctionClockSclk, div_num: u32) -> Self {
1755                ::core::assert!(
1756                    div_num <= 255,
1757                    "`UART0_FUNCTION_CLOCK` div_num must be between 0 and 255 (inclusive)."
1758                );
1759                Self { sclk, div_num }
1760            }
1761            pub fn sclk(self) -> UartFunctionClockSclk {
1762                self.sclk
1763            }
1764            pub fn div_num(self) -> u32 {
1765                self.div_num as u32
1766            }
1767        }
1768        /// Configures the `UART0_BAUD_RATE_GENERATOR` clock node.
1769        ///
1770        /// The output is calculated as `OUTPUT = (FUNCTION_CLOCK * 16) / (integral * 16 +
1771        /// fractional)`.
1772        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1773        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1774        pub struct UartBaudRateGeneratorConfig {
1775            fractional: u32,
1776            integral: u32,
1777        }
1778        impl UartBaudRateGeneratorConfig {
1779            /// Creates a new configuration for the BAUD_RATE_GENERATOR clock node.
1780            ///
1781            /// ## Panics
1782            ///
1783            /// Panics if the fractional value is outside the
1784            /// valid range (0 ..= 15).
1785            ///
1786            /// Panics if the integral value is outside the
1787            /// valid range (0 ..= 4095).
1788            pub const fn new(fractional: u32, integral: u32) -> Self {
1789                ::core::assert!(
1790                    fractional <= 15,
1791                    "`UART0_BAUD_RATE_GENERATOR` fractional must be between 0 and 15 (inclusive)."
1792                );
1793                ::core::assert!(
1794                    integral <= 4095,
1795                    "`UART0_BAUD_RATE_GENERATOR` integral must be between 0 and 4095 (inclusive)."
1796                );
1797                Self {
1798                    fractional,
1799                    integral,
1800                }
1801            }
1802            pub fn fractional(self) -> u32 {
1803                self.fractional as u32
1804            }
1805            pub fn integral(self) -> u32 {
1806                self.integral as u32
1807            }
1808        }
1809        /// Represents the device's clock tree.
1810        pub struct ClockTree {
1811            xtal_clk: Option<XtalClkConfig>,
1812            hp_root_clk: Option<HpRootClkConfig>,
1813            cpu_clk: Option<CpuClkConfig>,
1814            ahb_clk: Option<AhbClkConfig>,
1815            apb_clk: Option<ApbClkConfig>,
1816            lp_fast_clk: Option<LpFastClkConfig>,
1817            lp_slow_clk: Option<LpSlowClkConfig>,
1818            ble_lp_clk: Option<BleLpClkConfig>,
1819            crypto_clk: Option<CryptoClkConfig>,
1820            timg_calibration_clock: Option<TimgCalibrationClockConfig>,
1821            adc_function_clock: [Option<AdcFunctionClockConfig>; 1],
1822            i2c_function_clock: [Option<I2cFunctionClockConfig>; 1],
1823            i2s_tx_clk: [Option<I2sClkConfig>; 1],
1824            i2s_rx_clk: [Option<I2sClkConfig>; 1],
1825            i2s_mclk_out: [Option<I2sMclkOutConfig>; 1],
1826            spi_function_clock: [Option<SpiFunctionClockConfig>; 1],
1827            timg_function_clock: [Option<TimgFunctionClockConfig>; 2],
1828            timg_wdt_clock: [Option<TimgWdtClockConfig>; 2],
1829            uart_function_clock: [Option<UartFunctionClockConfig>; 3],
1830            uart_baud_rate_generator: [Option<UartBaudRateGeneratorConfig>; 3],
1831            pub(crate) rc_fast_clk_refcount: u32,
1832            pub(crate) pll_clk_refcount: u32,
1833            #[cfg(use_xtal32k)]
1834            pub(crate) xtal32k_clk_refcount: u32,
1835            pub(crate) osc_slow_clk_refcount: u32,
1836            pub(crate) rc_slow_clk_refcount: u32,
1837            pub(crate) pll_f20m_refcount: u32,
1838            pub(crate) pll_f40m_refcount: u32,
1839            pub(crate) pll_f48m_refcount: u32,
1840            pub(crate) pll_f60m_refcount: u32,
1841            pub(crate) pll_f80m_refcount: u32,
1842            pub(crate) pll_f120m_refcount: u32,
1843            pub(crate) pll_f160m_refcount: u32,
1844            pub(crate) hp_root_clk_refcount: u32,
1845            pub(crate) apb_clk_refcount: u32,
1846            pub(crate) lp_fast_clk_refcount: u32,
1847            pub(crate) lp_slow_clk_refcount: u32,
1848            pub(crate) ble_lp_clk_refcount: u32,
1849            pub(crate) crypto_clk_refcount: u32,
1850            pub(crate) timg_calibration_clock_refcount: u32,
1851            pub(crate) adc_function_clock_refcount: [u32; 1],
1852            pub(crate) i2c_function_clock_refcount: [u32; 1],
1853            pub(crate) i2s_tx_clk_refcount: [u32; 1],
1854            pub(crate) i2s_rx_clk_refcount: [u32; 1],
1855            pub(crate) i2s_mclk_out_refcount: [u32; 1],
1856            pub(crate) spi_function_clock_refcount: [u32; 1],
1857            pub(crate) timg_function_clock_refcount: [u32; 2],
1858            pub(crate) timg_wdt_clock_refcount: [u32; 2],
1859            pub(crate) uart_function_clock_refcount: [u32; 3],
1860            pub(crate) uart_baud_rate_generator_refcount: [u32; 3],
1861        }
1862        impl ClockTree {
1863            /// Locks the clock tree for exclusive access.
1864            pub fn with<R>(f: impl FnOnce(&mut ClockTree) -> R) -> R {
1865                CLOCK_TREE.with(f)
1866            }
1867            /// Returns the current configuration of the XTAL_CLK clock tree node
1868            pub fn xtal_clk(&self) -> Option<XtalClkConfig> {
1869                self.xtal_clk
1870            }
1871            /// Returns the current configuration of the HP_ROOT_CLK clock tree node
1872            pub fn hp_root_clk(&self) -> Option<HpRootClkConfig> {
1873                self.hp_root_clk
1874            }
1875            /// Returns the current configuration of the CPU_CLK clock tree node
1876            pub fn cpu_clk(&self) -> Option<CpuClkConfig> {
1877                self.cpu_clk
1878            }
1879            /// Returns the current configuration of the AHB_CLK clock tree node
1880            pub fn ahb_clk(&self) -> Option<AhbClkConfig> {
1881                self.ahb_clk
1882            }
1883            /// Returns the current configuration of the APB_CLK clock tree node
1884            pub fn apb_clk(&self) -> Option<ApbClkConfig> {
1885                self.apb_clk
1886            }
1887            /// Returns the current configuration of the LP_FAST_CLK clock tree node
1888            pub fn lp_fast_clk(&self) -> Option<LpFastClkConfig> {
1889                self.lp_fast_clk
1890            }
1891            /// Returns the current configuration of the LP_SLOW_CLK clock tree node
1892            pub fn lp_slow_clk(&self) -> Option<LpSlowClkConfig> {
1893                self.lp_slow_clk
1894            }
1895            /// Returns the current configuration of the BLE_LP_CLK clock tree node
1896            pub fn ble_lp_clk(&self) -> Option<BleLpClkConfig> {
1897                self.ble_lp_clk
1898            }
1899            /// Returns the current configuration of the CRYPTO_CLK clock tree node
1900            pub fn crypto_clk(&self) -> Option<CryptoClkConfig> {
1901                self.crypto_clk
1902            }
1903            /// Returns the current configuration of the TIMG_CALIBRATION_CLOCK clock tree node
1904            pub fn timg_calibration_clock(&self) -> Option<TimgCalibrationClockConfig> {
1905                self.timg_calibration_clock
1906            }
1907            /// Returns the current configuration of the APB_SARADC_FUNCTION_CLOCK clock tree node
1908            pub fn apb_saradc_function_clock(&self) -> Option<AdcFunctionClockConfig> {
1909                self.adc_function_clock[AdcInstance::ApbSaradc as usize]
1910            }
1911            /// Returns the current configuration of the I2C0_FUNCTION_CLOCK clock tree node
1912            pub fn i2c0_function_clock(&self) -> Option<I2cFunctionClockConfig> {
1913                self.i2c_function_clock[I2cInstance::I2c0 as usize]
1914            }
1915            /// Returns the current configuration of the I2S0_TX_CLK clock tree node
1916            pub fn i2s0_tx_clk(&self) -> Option<I2sClkConfig> {
1917                self.i2s_tx_clk[I2sInstance::I2s0 as usize]
1918            }
1919            /// Returns the current configuration of the I2S0_RX_CLK clock tree node
1920            pub fn i2s0_rx_clk(&self) -> Option<I2sClkConfig> {
1921                self.i2s_rx_clk[I2sInstance::I2s0 as usize]
1922            }
1923            /// Returns the current configuration of the I2S0_MCLK_OUT clock tree node
1924            pub fn i2s0_mclk_out(&self) -> Option<I2sMclkOutConfig> {
1925                self.i2s_mclk_out[I2sInstance::I2s0 as usize]
1926            }
1927            /// Returns the current configuration of the SPI2_FUNCTION_CLOCK clock tree node
1928            pub fn spi2_function_clock(&self) -> Option<SpiFunctionClockConfig> {
1929                self.spi_function_clock[SpiInstance::Spi2 as usize]
1930            }
1931            /// Returns the current configuration of the TIMG0_FUNCTION_CLOCK clock tree node
1932            pub fn timg0_function_clock(&self) -> Option<TimgFunctionClockConfig> {
1933                self.timg_function_clock[TimgInstance::Timg0 as usize]
1934            }
1935            /// Returns the current configuration of the TIMG0_WDT_CLOCK clock tree node
1936            pub fn timg0_wdt_clock(&self) -> Option<TimgWdtClockConfig> {
1937                self.timg_wdt_clock[TimgInstance::Timg0 as usize]
1938            }
1939            /// Returns the current configuration of the TIMG1_FUNCTION_CLOCK clock tree node
1940            pub fn timg1_function_clock(&self) -> Option<TimgFunctionClockConfig> {
1941                self.timg_function_clock[TimgInstance::Timg1 as usize]
1942            }
1943            /// Returns the current configuration of the TIMG1_WDT_CLOCK clock tree node
1944            pub fn timg1_wdt_clock(&self) -> Option<TimgWdtClockConfig> {
1945                self.timg_wdt_clock[TimgInstance::Timg1 as usize]
1946            }
1947            /// Returns the current configuration of the UART0_FUNCTION_CLOCK clock tree node
1948            pub fn uart0_function_clock(&self) -> Option<UartFunctionClockConfig> {
1949                self.uart_function_clock[UartInstance::Uart0 as usize]
1950            }
1951            /// Returns the current configuration of the UART0_BAUD_RATE_GENERATOR clock tree node
1952            pub fn uart0_baud_rate_generator(&self) -> Option<UartBaudRateGeneratorConfig> {
1953                self.uart_baud_rate_generator[UartInstance::Uart0 as usize]
1954            }
1955            /// Returns the current configuration of the UART1_FUNCTION_CLOCK clock tree node
1956            pub fn uart1_function_clock(&self) -> Option<UartFunctionClockConfig> {
1957                self.uart_function_clock[UartInstance::Uart1 as usize]
1958            }
1959            /// Returns the current configuration of the UART1_BAUD_RATE_GENERATOR clock tree node
1960            pub fn uart1_baud_rate_generator(&self) -> Option<UartBaudRateGeneratorConfig> {
1961                self.uart_baud_rate_generator[UartInstance::Uart1 as usize]
1962            }
1963            /// Returns the current configuration of the UART2_FUNCTION_CLOCK clock tree node
1964            pub fn uart2_function_clock(&self) -> Option<UartFunctionClockConfig> {
1965                self.uart_function_clock[UartInstance::Uart2 as usize]
1966            }
1967            /// Returns the current configuration of the UART2_BAUD_RATE_GENERATOR clock tree node
1968            pub fn uart2_baud_rate_generator(&self) -> Option<UartBaudRateGeneratorConfig> {
1969                self.uart_baud_rate_generator[UartInstance::Uart2 as usize]
1970            }
1971        }
1972        static CLOCK_TREE: ::esp_sync::NonReentrantMutex<ClockTree> =
1973            ::esp_sync::NonReentrantMutex::new(ClockTree {
1974                xtal_clk: None,
1975                hp_root_clk: None,
1976                cpu_clk: None,
1977                ahb_clk: None,
1978                apb_clk: None,
1979                lp_fast_clk: None,
1980                lp_slow_clk: None,
1981                ble_lp_clk: None,
1982                crypto_clk: None,
1983                timg_calibration_clock: None,
1984                adc_function_clock: [None; 1],
1985                i2c_function_clock: [None; 1],
1986                i2s_tx_clk: [None; 1],
1987                i2s_rx_clk: [None; 1],
1988                i2s_mclk_out: [None; 1],
1989                spi_function_clock: [None; 1],
1990                timg_function_clock: [None; 2],
1991                timg_wdt_clock: [None; 2],
1992                uart_function_clock: [None; 3],
1993                uart_baud_rate_generator: [None; 3],
1994                rc_fast_clk_refcount: 0,
1995                pll_clk_refcount: 0,
1996                #[cfg(use_xtal32k)]
1997                xtal32k_clk_refcount: 0,
1998                osc_slow_clk_refcount: 0,
1999                rc_slow_clk_refcount: 0,
2000                pll_f20m_refcount: 0,
2001                pll_f40m_refcount: 0,
2002                pll_f48m_refcount: 0,
2003                pll_f60m_refcount: 0,
2004                pll_f80m_refcount: 0,
2005                pll_f120m_refcount: 0,
2006                pll_f160m_refcount: 0,
2007                hp_root_clk_refcount: 0,
2008                apb_clk_refcount: 0,
2009                lp_fast_clk_refcount: 0,
2010                lp_slow_clk_refcount: 0,
2011                ble_lp_clk_refcount: 0,
2012                crypto_clk_refcount: 0,
2013                timg_calibration_clock_refcount: 0,
2014                adc_function_clock_refcount: [0; 1],
2015                i2c_function_clock_refcount: [0; 1],
2016                i2s_tx_clk_refcount: [0; 1],
2017                i2s_rx_clk_refcount: [0; 1],
2018                i2s_mclk_out_refcount: [0; 1],
2019                spi_function_clock_refcount: [0; 1],
2020                timg_function_clock_refcount: [0; 2],
2021                timg_wdt_clock_refcount: [0; 2],
2022                uart_function_clock_refcount: [0; 3],
2023                uart_baud_rate_generator_refcount: [0; 3],
2024            });
2025        static XTAL_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2026            ::core::sync::atomic::AtomicU32::new(0);
2027        static HP_ROOT_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2028            ::core::sync::atomic::AtomicU32::new(0);
2029        static CPU_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2030            ::core::sync::atomic::AtomicU32::new(0);
2031        static AHB_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2032            ::core::sync::atomic::AtomicU32::new(0);
2033        static APB_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2034            ::core::sync::atomic::AtomicU32::new(0);
2035        static LP_FAST_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2036            ::core::sync::atomic::AtomicU32::new(0);
2037        static LP_SLOW_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2038            ::core::sync::atomic::AtomicU32::new(0);
2039        static BLE_LP_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2040            ::core::sync::atomic::AtomicU32::new(0);
2041        static CRYPTO_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2042            ::core::sync::atomic::AtomicU32::new(0);
2043        static TIMG_CALIBRATION_CLOCK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2044            ::core::sync::atomic::AtomicU32::new(0);
2045        static ADC_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
2046            [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
2047        static I2C_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
2048            [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
2049        static I2S_TX_CLK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
2050            [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
2051        static I2S_RX_CLK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
2052            [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
2053        static I2S_MCLK_OUT_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
2054            [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
2055        static SPI_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
2056            [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
2057        static TIMG_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 2] =
2058            [const { ::core::sync::atomic::AtomicU32::new(0) }; 2];
2059        static TIMG_WDT_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 2] =
2060            [const { ::core::sync::atomic::AtomicU32::new(0) }; 2];
2061        static UART_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 3] =
2062            [const { ::core::sync::atomic::AtomicU32::new(0) }; 3];
2063        static UART_BAUD_RATE_GENERATOR_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 3] =
2064            [const { ::core::sync::atomic::AtomicU32::new(0) }; 3];
2065        /// The clock sources of the device.
2066        ///
2067        /// A clock source is a node of the clock tree that other nodes derive their output
2068        /// from. Ask a node which source it runs on with its `..._root_source` function.
2069        #[derive(Debug, enumset::EnumSetType)]
2070        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
2071        pub enum ClockSource {
2072            /// `XTAL_CLK`.
2073            XtalClk,
2074            /// `RC_FAST_CLK`.
2075            RcFastClk,
2076            #[cfg(use_xtal32k)]
2077            /// `XTAL32K_CLK`.
2078            Xtal32kClk,
2079            /// `OSC_SLOW_CLK`.
2080            OscSlowClk,
2081            /// `RC_SLOW_CLK`.
2082            RcSlowClk,
2083        }
2084        /// Returns the clock source that `XTAL_CLK` currently runs on.
2085        pub fn xtal_clk_root_source(_clocks: &mut ClockTree) -> Option<ClockSource> {
2086            Some(ClockSource::XtalClk)
2087        }
2088        /// Returns the clock source that `RC_FAST_CLK` currently runs on.
2089        pub fn rc_fast_clk_root_source(_clocks: &mut ClockTree) -> Option<ClockSource> {
2090            Some(ClockSource::RcFastClk)
2091        }
2092        /// Returns the clock source that `PLL_CLK` currently runs on.
2093        pub fn pll_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2094            xtal_clk_root_source(clocks)
2095        }
2096        #[cfg(use_xtal32k)]
2097        /// Returns the clock source that `XTAL32K_CLK` currently runs on.
2098        pub fn xtal32k_clk_root_source(_clocks: &mut ClockTree) -> Option<ClockSource> {
2099            Some(ClockSource::Xtal32kClk)
2100        }
2101        /// Returns the clock source that `OSC_SLOW_CLK` currently runs on.
2102        pub fn osc_slow_clk_root_source(_clocks: &mut ClockTree) -> Option<ClockSource> {
2103            Some(ClockSource::OscSlowClk)
2104        }
2105        /// Returns the clock source that `RC_SLOW_CLK` currently runs on.
2106        pub fn rc_slow_clk_root_source(_clocks: &mut ClockTree) -> Option<ClockSource> {
2107            Some(ClockSource::RcSlowClk)
2108        }
2109        /// Returns the clock source that `PLL_F20M` currently runs on.
2110        pub fn pll_f20m_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2111            pll_clk_root_source(clocks)
2112        }
2113        /// Returns the clock source that `PLL_F40M` currently runs on.
2114        pub fn pll_f40m_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2115            pll_clk_root_source(clocks)
2116        }
2117        /// Returns the clock source that `PLL_F48M` currently runs on.
2118        pub fn pll_f48m_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2119            pll_clk_root_source(clocks)
2120        }
2121        /// Returns the clock source that `PLL_F60M` currently runs on.
2122        pub fn pll_f60m_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2123            pll_clk_root_source(clocks)
2124        }
2125        /// Returns the clock source that `PLL_F80M` currently runs on.
2126        pub fn pll_f80m_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2127            pll_clk_root_source(clocks)
2128        }
2129        /// Returns the clock source that `PLL_F120M` currently runs on.
2130        pub fn pll_f120m_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2131            pll_clk_root_source(clocks)
2132        }
2133        /// Returns the clock source that `PLL_F160M` currently runs on.
2134        pub fn pll_f160m_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2135            pll_clk_root_source(clocks)
2136        }
2137        /// Returns the clock source that `HP_ROOT_CLK` currently runs on.
2138        pub fn hp_root_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2139            let config = clocks.hp_root_clk?;
2140            match config {
2141                HpRootClkConfig::Xtal => xtal_clk_root_source(clocks),
2142                HpRootClkConfig::RcFast => rc_fast_clk_root_source(clocks),
2143                HpRootClkConfig::PllF160m => pll_f160m_root_source(clocks),
2144            }
2145        }
2146        /// Returns the clock source that `CPU_CLK` currently runs on.
2147        pub fn cpu_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2148            hp_root_clk_root_source(clocks)
2149        }
2150        /// Returns the clock source that `AHB_CLK` currently runs on.
2151        pub fn ahb_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2152            hp_root_clk_root_source(clocks)
2153        }
2154        /// Returns the clock source that `APB_CLK` currently runs on.
2155        pub fn apb_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2156            ahb_clk_root_source(clocks)
2157        }
2158        /// Returns the clock source that `XTAL_D2_CLK` currently runs on.
2159        pub fn xtal_d2_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2160            xtal_clk_root_source(clocks)
2161        }
2162        /// Returns the clock source that `LP_FAST_CLK` currently runs on.
2163        pub fn lp_fast_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2164            let config = clocks.lp_fast_clk?;
2165            match config {
2166                LpFastClkConfig::RcFast => rc_fast_clk_root_source(clocks),
2167                LpFastClkConfig::XtalD2 => xtal_d2_clk_root_source(clocks),
2168                LpFastClkConfig::Xtal => xtal_clk_root_source(clocks),
2169            }
2170        }
2171        /// Returns the clock source that `LP_SLOW_CLK` currently runs on.
2172        pub fn lp_slow_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2173            let config = clocks.lp_slow_clk?;
2174            match config {
2175                LpSlowClkConfig::RcSlow => rc_slow_clk_root_source(clocks),
2176                #[cfg(use_xtal32k)]
2177                LpSlowClkConfig::Xtal32k => xtal32k_clk_root_source(clocks),
2178                LpSlowClkConfig::OscSlow => osc_slow_clk_root_source(clocks),
2179            }
2180        }
2181        /// Returns the clock source that `BLE_LP_XTAL_CLK` currently runs on.
2182        pub fn ble_lp_xtal_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2183            xtal_clk_root_source(clocks)
2184        }
2185        /// Returns the clock source that `BLE_LP_RC_SLOW_CLK` currently runs on.
2186        pub fn ble_lp_rc_slow_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2187            rc_slow_clk_root_source(clocks)
2188        }
2189        /// Returns the clock source that `BLE_LP_CLK` currently runs on.
2190        pub fn ble_lp_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2191            let config = clocks.ble_lp_clk?;
2192            match config {
2193                BleLpClkConfig::Xtal => ble_lp_xtal_clk_root_source(clocks),
2194                BleLpClkConfig::RcSlow => ble_lp_rc_slow_clk_root_source(clocks),
2195                #[cfg(use_xtal32k)]
2196                BleLpClkConfig::Xtal32k => xtal32k_clk_root_source(clocks),
2197            }
2198        }
2199        /// Returns the clock source that `CRYPTO_PLL_DIV` currently runs on.
2200        pub fn crypto_pll_div_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2201            pll_clk_root_source(clocks)
2202        }
2203        /// Returns the clock source that `CRYPTO_CLK` currently runs on.
2204        pub fn crypto_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2205            let config = clocks.crypto_clk?;
2206            match config {
2207                CryptoClkConfig::Xtal => xtal_clk_root_source(clocks),
2208                CryptoClkConfig::RcFast => rc_fast_clk_root_source(clocks),
2209                CryptoClkConfig::PllF480m => crypto_pll_div_root_source(clocks),
2210            }
2211        }
2212        /// Returns the clock source that `TIMG_CALIBRATION_CLOCK` currently runs on.
2213        pub fn timg_calibration_clock_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2214            let config = clocks.timg_calibration_clock?;
2215            match config {
2216                TimgCalibrationClockConfig::OscSlowClk => osc_slow_clk_root_source(clocks),
2217                TimgCalibrationClockConfig::RcSlowClk => rc_slow_clk_root_source(clocks),
2218                TimgCalibrationClockConfig::RcFastDivClk => rc_fast_clk_root_source(clocks),
2219                #[cfg(use_xtal32k)]
2220                TimgCalibrationClockConfig::Xtal32kClk => xtal32k_clk_root_source(clocks),
2221            }
2222        }
2223        pub fn configure_xtal_clk(clocks: &mut ClockTree, config: XtalClkConfig) {
2224            let old_config = clocks.xtal_clk.replace(config);
2225            refresh_xtal_clk_downstream(clocks);
2226            configure_xtal_clk_impl(clocks, old_config, config);
2227        }
2228        pub fn xtal_clk_config(clocks: &mut ClockTree) -> Option<XtalClkConfig> {
2229            clocks.xtal_clk
2230        }
2231        fn request_xtal_clk(_clocks: &mut ClockTree) {}
2232        fn release_xtal_clk(_clocks: &mut ClockTree) {}
2233        pub fn xtal_clk_config_frequency(config: XtalClkConfig) -> u32 {
2234            config.value()
2235        }
2236        pub fn xtal_clk_frequency() -> u32 {
2237            XTAL_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2238        }
2239        pub fn request_rc_fast_clk(clocks: &mut ClockTree) {
2240            trace!("Requesting RC_FAST_CLK");
2241            if increment_reference_count(&mut clocks.rc_fast_clk_refcount) {
2242                trace!("Enabling RC_FAST_CLK");
2243                enable_rc_fast_clk_impl(clocks, true);
2244            }
2245        }
2246        pub fn release_rc_fast_clk(clocks: &mut ClockTree) {
2247            trace!("Releasing RC_FAST_CLK");
2248            if decrement_reference_count(&mut clocks.rc_fast_clk_refcount) {
2249                trace!("Disabling RC_FAST_CLK");
2250                enable_rc_fast_clk_impl(clocks, false);
2251            }
2252        }
2253        static RC_FAST_CLK_FREQUENCY: ::core::sync::atomic::AtomicU32 =
2254            ::core::sync::atomic::AtomicU32::new(rc_fast_clk_nominal_frequency());
2255        pub const fn rc_fast_clk_nominal_frequency() -> u32 {
2256            17500000
2257        }
2258        pub fn rc_fast_clk_frequency() -> u32 {
2259            RC_FAST_CLK_FREQUENCY.load(::core::sync::atomic::Ordering::Acquire)
2260        }
2261        pub fn set_rc_fast_clk_frequency(clocks: &mut ClockTree, frequency: u32) {
2262            if !(8750000..=26250000).contains(&frequency) {
2263                warn!(
2264                    "Ignoring out-of-range RC_FAST_CLK frequency: {} Hz",
2265                    frequency
2266                );
2267                return;
2268            }
2269            debug!(
2270                "Updating RC_FAST_CLK frequency to {} Hz (nominal {} Hz)",
2271                frequency,
2272                rc_fast_clk_nominal_frequency()
2273            );
2274            RC_FAST_CLK_FREQUENCY.store(frequency, ::core::sync::atomic::Ordering::Release);
2275            refresh_rc_fast_clk_downstream(clocks);
2276        }
2277        pub fn request_pll_clk(clocks: &mut ClockTree) {
2278            trace!("Requesting PLL_CLK");
2279            if increment_reference_count(&mut clocks.pll_clk_refcount) {
2280                trace!("Enabling PLL_CLK");
2281                request_xtal_clk(clocks);
2282                enable_pll_clk_impl(clocks, true);
2283            }
2284        }
2285        pub fn release_pll_clk(clocks: &mut ClockTree) {
2286            trace!("Releasing PLL_CLK");
2287            if decrement_reference_count(&mut clocks.pll_clk_refcount) {
2288                trace!("Disabling PLL_CLK");
2289                enable_pll_clk_impl(clocks, false);
2290                release_xtal_clk(clocks);
2291            }
2292        }
2293        pub fn pll_clk_frequency() -> u32 {
2294            480000000
2295        }
2296        pub fn pll_clk_source_frequency() -> u32 {
2297            xtal_clk_frequency()
2298        }
2299        #[cfg(use_xtal32k)]
2300        pub fn request_xtal32k_clk(clocks: &mut ClockTree) {
2301            trace!("Requesting XTAL32K_CLK");
2302            if increment_reference_count(&mut clocks.xtal32k_clk_refcount) {
2303                trace!("Enabling XTAL32K_CLK");
2304                enable_xtal32k_clk_impl(clocks, true);
2305            }
2306        }
2307        #[cfg(use_xtal32k)]
2308        pub fn release_xtal32k_clk(clocks: &mut ClockTree) {
2309            trace!("Releasing XTAL32K_CLK");
2310            if decrement_reference_count(&mut clocks.xtal32k_clk_refcount) {
2311                trace!("Disabling XTAL32K_CLK");
2312                enable_xtal32k_clk_impl(clocks, false);
2313            }
2314        }
2315        #[cfg(use_xtal32k)]
2316        pub fn xtal32k_clk_frequency() -> u32 {
2317            32768
2318        }
2319        pub fn request_osc_slow_clk(clocks: &mut ClockTree) {
2320            trace!("Requesting OSC_SLOW_CLK");
2321            if increment_reference_count(&mut clocks.osc_slow_clk_refcount) {
2322                trace!("Enabling OSC_SLOW_CLK");
2323                enable_osc_slow_clk_impl(clocks, true);
2324            }
2325        }
2326        pub fn release_osc_slow_clk(clocks: &mut ClockTree) {
2327            trace!("Releasing OSC_SLOW_CLK");
2328            if decrement_reference_count(&mut clocks.osc_slow_clk_refcount) {
2329                trace!("Disabling OSC_SLOW_CLK");
2330                enable_osc_slow_clk_impl(clocks, false);
2331            }
2332        }
2333        pub fn osc_slow_clk_frequency() -> u32 {
2334            32768
2335        }
2336        pub fn request_rc_slow_clk(clocks: &mut ClockTree) {
2337            trace!("Requesting RC_SLOW_CLK");
2338            if increment_reference_count(&mut clocks.rc_slow_clk_refcount) {
2339                trace!("Enabling RC_SLOW_CLK");
2340                enable_rc_slow_clk_impl(clocks, true);
2341            }
2342        }
2343        pub fn release_rc_slow_clk(clocks: &mut ClockTree) {
2344            trace!("Releasing RC_SLOW_CLK");
2345            if decrement_reference_count(&mut clocks.rc_slow_clk_refcount) {
2346                trace!("Disabling RC_SLOW_CLK");
2347                enable_rc_slow_clk_impl(clocks, false);
2348            }
2349        }
2350        static RC_SLOW_CLK_FREQUENCY: ::core::sync::atomic::AtomicU32 =
2351            ::core::sync::atomic::AtomicU32::new(rc_slow_clk_nominal_frequency());
2352        pub const fn rc_slow_clk_nominal_frequency() -> u32 {
2353            136000
2354        }
2355        pub fn rc_slow_clk_frequency() -> u32 {
2356            RC_SLOW_CLK_FREQUENCY.load(::core::sync::atomic::Ordering::Acquire)
2357        }
2358        pub fn set_rc_slow_clk_frequency(clocks: &mut ClockTree, frequency: u32) {
2359            if !(68000..=204000).contains(&frequency) {
2360                warn!(
2361                    "Ignoring out-of-range RC_SLOW_CLK frequency: {} Hz",
2362                    frequency
2363                );
2364                return;
2365            }
2366            debug!(
2367                "Updating RC_SLOW_CLK frequency to {} Hz (nominal {} Hz)",
2368                frequency,
2369                rc_slow_clk_nominal_frequency()
2370            );
2371            RC_SLOW_CLK_FREQUENCY.store(frequency, ::core::sync::atomic::Ordering::Release);
2372            refresh_rc_slow_clk_downstream(clocks);
2373        }
2374        pub fn request_pll_f20m(clocks: &mut ClockTree) {
2375            trace!("Requesting PLL_F20M");
2376            if increment_reference_count(&mut clocks.pll_f20m_refcount) {
2377                trace!("Enabling PLL_F20M");
2378                request_pll_clk(clocks);
2379                enable_pll_f20m_impl(clocks, true);
2380            }
2381        }
2382        pub fn release_pll_f20m(clocks: &mut ClockTree) {
2383            trace!("Releasing PLL_F20M");
2384            if decrement_reference_count(&mut clocks.pll_f20m_refcount) {
2385                trace!("Disabling PLL_F20M");
2386                enable_pll_f20m_impl(clocks, false);
2387                release_pll_clk(clocks);
2388            }
2389        }
2390        pub fn pll_f20m_frequency() -> u32 {
2391            (pll_clk_frequency() / 24)
2392        }
2393        pub fn pll_f20m_source_frequency() -> u32 {
2394            pll_clk_frequency()
2395        }
2396        pub fn request_pll_f40m(clocks: &mut ClockTree) {
2397            trace!("Requesting PLL_F40M");
2398            if increment_reference_count(&mut clocks.pll_f40m_refcount) {
2399                trace!("Enabling PLL_F40M");
2400                request_pll_clk(clocks);
2401                enable_pll_f40m_impl(clocks, true);
2402            }
2403        }
2404        pub fn release_pll_f40m(clocks: &mut ClockTree) {
2405            trace!("Releasing PLL_F40M");
2406            if decrement_reference_count(&mut clocks.pll_f40m_refcount) {
2407                trace!("Disabling PLL_F40M");
2408                enable_pll_f40m_impl(clocks, false);
2409                release_pll_clk(clocks);
2410            }
2411        }
2412        pub fn pll_f40m_frequency() -> u32 {
2413            (pll_clk_frequency() / 12)
2414        }
2415        pub fn pll_f40m_source_frequency() -> u32 {
2416            pll_clk_frequency()
2417        }
2418        pub fn request_pll_f48m(clocks: &mut ClockTree) {
2419            trace!("Requesting PLL_F48M");
2420            if increment_reference_count(&mut clocks.pll_f48m_refcount) {
2421                trace!("Enabling PLL_F48M");
2422                request_pll_clk(clocks);
2423                enable_pll_f48m_impl(clocks, true);
2424            }
2425        }
2426        pub fn release_pll_f48m(clocks: &mut ClockTree) {
2427            trace!("Releasing PLL_F48M");
2428            if decrement_reference_count(&mut clocks.pll_f48m_refcount) {
2429                trace!("Disabling PLL_F48M");
2430                enable_pll_f48m_impl(clocks, false);
2431                release_pll_clk(clocks);
2432            }
2433        }
2434        pub fn pll_f48m_frequency() -> u32 {
2435            (pll_clk_frequency() / 10)
2436        }
2437        pub fn pll_f48m_source_frequency() -> u32 {
2438            pll_clk_frequency()
2439        }
2440        pub fn request_pll_f60m(clocks: &mut ClockTree) {
2441            trace!("Requesting PLL_F60M");
2442            if increment_reference_count(&mut clocks.pll_f60m_refcount) {
2443                trace!("Enabling PLL_F60M");
2444                request_pll_clk(clocks);
2445                enable_pll_f60m_impl(clocks, true);
2446            }
2447        }
2448        pub fn release_pll_f60m(clocks: &mut ClockTree) {
2449            trace!("Releasing PLL_F60M");
2450            if decrement_reference_count(&mut clocks.pll_f60m_refcount) {
2451                trace!("Disabling PLL_F60M");
2452                enable_pll_f60m_impl(clocks, false);
2453                release_pll_clk(clocks);
2454            }
2455        }
2456        pub fn pll_f60m_frequency() -> u32 {
2457            (pll_clk_frequency() / 8)
2458        }
2459        pub fn pll_f60m_source_frequency() -> u32 {
2460            pll_clk_frequency()
2461        }
2462        pub fn request_pll_f80m(clocks: &mut ClockTree) {
2463            trace!("Requesting PLL_F80M");
2464            if increment_reference_count(&mut clocks.pll_f80m_refcount) {
2465                trace!("Enabling PLL_F80M");
2466                request_pll_clk(clocks);
2467                enable_pll_f80m_impl(clocks, true);
2468            }
2469        }
2470        pub fn release_pll_f80m(clocks: &mut ClockTree) {
2471            trace!("Releasing PLL_F80M");
2472            if decrement_reference_count(&mut clocks.pll_f80m_refcount) {
2473                trace!("Disabling PLL_F80M");
2474                enable_pll_f80m_impl(clocks, false);
2475                release_pll_clk(clocks);
2476            }
2477        }
2478        pub fn pll_f80m_frequency() -> u32 {
2479            (pll_clk_frequency() / 6)
2480        }
2481        pub fn pll_f80m_source_frequency() -> u32 {
2482            pll_clk_frequency()
2483        }
2484        pub fn request_pll_f120m(clocks: &mut ClockTree) {
2485            trace!("Requesting PLL_F120M");
2486            if increment_reference_count(&mut clocks.pll_f120m_refcount) {
2487                trace!("Enabling PLL_F120M");
2488                request_pll_clk(clocks);
2489                enable_pll_f120m_impl(clocks, true);
2490            }
2491        }
2492        pub fn release_pll_f120m(clocks: &mut ClockTree) {
2493            trace!("Releasing PLL_F120M");
2494            if decrement_reference_count(&mut clocks.pll_f120m_refcount) {
2495                trace!("Disabling PLL_F120M");
2496                enable_pll_f120m_impl(clocks, false);
2497                release_pll_clk(clocks);
2498            }
2499        }
2500        pub fn pll_f120m_frequency() -> u32 {
2501            (pll_clk_frequency() / 4)
2502        }
2503        pub fn pll_f120m_source_frequency() -> u32 {
2504            pll_clk_frequency()
2505        }
2506        pub fn request_pll_f160m(clocks: &mut ClockTree) {
2507            trace!("Requesting PLL_F160M");
2508            if increment_reference_count(&mut clocks.pll_f160m_refcount) {
2509                trace!("Enabling PLL_F160M");
2510                request_pll_clk(clocks);
2511                enable_pll_f160m_impl(clocks, true);
2512            }
2513        }
2514        pub fn release_pll_f160m(clocks: &mut ClockTree) {
2515            trace!("Releasing PLL_F160M");
2516            if decrement_reference_count(&mut clocks.pll_f160m_refcount) {
2517                trace!("Disabling PLL_F160M");
2518                enable_pll_f160m_impl(clocks, false);
2519                release_pll_clk(clocks);
2520            }
2521        }
2522        pub fn pll_f160m_frequency() -> u32 {
2523            (pll_clk_frequency() / 3)
2524        }
2525        pub fn pll_f160m_source_frequency() -> u32 {
2526            pll_clk_frequency()
2527        }
2528        pub fn configure_hp_root_clk(clocks: &mut ClockTree, new_selector: HpRootClkConfig) {
2529            let old_selector = clocks.hp_root_clk.replace(new_selector);
2530            refresh_hp_root_clk_downstream(clocks);
2531            let active = clocks.hp_root_clk_refcount > 0;
2532            if active {
2533                match new_selector {
2534                    HpRootClkConfig::Xtal => request_xtal_clk(clocks),
2535                    HpRootClkConfig::RcFast => request_rc_fast_clk(clocks),
2536                    HpRootClkConfig::PllF160m => request_pll_f160m(clocks),
2537                }
2538            }
2539            configure_hp_root_clk_impl(clocks, old_selector, new_selector);
2540            if active && let Some(old_selector) = old_selector {
2541                match old_selector {
2542                    HpRootClkConfig::Xtal => release_xtal_clk(clocks),
2543                    HpRootClkConfig::RcFast => release_rc_fast_clk(clocks),
2544                    HpRootClkConfig::PllF160m => release_pll_f160m(clocks),
2545                }
2546            }
2547        }
2548        pub fn hp_root_clk_config(clocks: &mut ClockTree) -> Option<HpRootClkConfig> {
2549            clocks.hp_root_clk
2550        }
2551        pub fn request_hp_root_clk(clocks: &mut ClockTree) {
2552            trace!("Requesting HP_ROOT_CLK");
2553            if increment_reference_count(&mut clocks.hp_root_clk_refcount) {
2554                trace!("Enabling HP_ROOT_CLK");
2555                match unwrap!(clocks.hp_root_clk) {
2556                    HpRootClkConfig::Xtal => request_xtal_clk(clocks),
2557                    HpRootClkConfig::RcFast => request_rc_fast_clk(clocks),
2558                    HpRootClkConfig::PllF160m => request_pll_f160m(clocks),
2559                }
2560                enable_hp_root_clk_impl(clocks, true);
2561            }
2562        }
2563        pub fn release_hp_root_clk(clocks: &mut ClockTree) {
2564            trace!("Releasing HP_ROOT_CLK");
2565            if decrement_reference_count(&mut clocks.hp_root_clk_refcount) {
2566                trace!("Disabling HP_ROOT_CLK");
2567                enable_hp_root_clk_impl(clocks, false);
2568                match unwrap!(clocks.hp_root_clk) {
2569                    HpRootClkConfig::Xtal => release_xtal_clk(clocks),
2570                    HpRootClkConfig::RcFast => release_rc_fast_clk(clocks),
2571                    HpRootClkConfig::PllF160m => release_pll_f160m(clocks),
2572                }
2573            }
2574        }
2575        pub fn hp_root_clk_config_frequency(config: HpRootClkConfig) -> u32 {
2576            match config {
2577                HpRootClkConfig::Xtal => xtal_clk_frequency(),
2578                HpRootClkConfig::RcFast => rc_fast_clk_frequency(),
2579                HpRootClkConfig::PllF160m => pll_f160m_frequency(),
2580            }
2581        }
2582        pub fn hp_root_clk_frequency() -> u32 {
2583            HP_ROOT_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2584        }
2585        pub fn hp_root_clk_source_frequency(source: HpRootClkConfig) -> u32 {
2586            hp_root_clk_config_frequency(source)
2587        }
2588        pub fn configure_cpu_clk(clocks: &mut ClockTree, config: CpuClkConfig) {
2589            let old_config = clocks.cpu_clk.replace(config);
2590            refresh_cpu_clk_downstream(clocks);
2591            if old_config.is_none() {
2592                request_hp_root_clk(clocks);
2593            }
2594            configure_cpu_clk_impl(clocks, old_config, config);
2595        }
2596        pub fn cpu_clk_config(clocks: &mut ClockTree) -> Option<CpuClkConfig> {
2597            clocks.cpu_clk
2598        }
2599        fn request_cpu_clk(_clocks: &mut ClockTree) {}
2600        fn release_cpu_clk(_clocks: &mut ClockTree) {}
2601        pub fn cpu_clk_config_frequency(config: CpuClkConfig) -> u32 {
2602            (hp_root_clk_frequency() / (config.divisor() + 1))
2603        }
2604        pub fn cpu_clk_frequency() -> u32 {
2605            CPU_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2606        }
2607        pub fn cpu_clk_source_frequency() -> u32 {
2608            hp_root_clk_frequency()
2609        }
2610        pub fn configure_ahb_clk(clocks: &mut ClockTree, config: AhbClkConfig) {
2611            let old_config = clocks.ahb_clk.replace(config);
2612            refresh_ahb_clk_downstream(clocks);
2613            if old_config.is_none() {
2614                request_hp_root_clk(clocks);
2615            }
2616            configure_ahb_clk_impl(clocks, old_config, config);
2617        }
2618        pub fn ahb_clk_config(clocks: &mut ClockTree) -> Option<AhbClkConfig> {
2619            clocks.ahb_clk
2620        }
2621        fn request_ahb_clk(_clocks: &mut ClockTree) {}
2622        fn release_ahb_clk(_clocks: &mut ClockTree) {}
2623        pub fn ahb_clk_config_frequency(config: AhbClkConfig) -> u32 {
2624            (hp_root_clk_frequency() / (config.divisor() + 1))
2625        }
2626        pub fn ahb_clk_frequency() -> u32 {
2627            AHB_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2628        }
2629        pub fn ahb_clk_source_frequency() -> u32 {
2630            hp_root_clk_frequency()
2631        }
2632        pub fn configure_apb_clk(clocks: &mut ClockTree, config: ApbClkConfig) {
2633            let old_config = clocks.apb_clk.replace(config);
2634            refresh_apb_clk_downstream(clocks);
2635            if old_config.is_none() {
2636                request_ahb_clk(clocks);
2637            }
2638            configure_apb_clk_impl(clocks, old_config, config);
2639        }
2640        pub fn apb_clk_config(clocks: &mut ClockTree) -> Option<ApbClkConfig> {
2641            clocks.apb_clk
2642        }
2643        pub fn request_apb_clk(clocks: &mut ClockTree) {
2644            trace!("Requesting APB_CLK");
2645            if increment_reference_count(&mut clocks.apb_clk_refcount) {
2646                enable_apb_clk_impl(clocks, true);
2647            }
2648        }
2649        pub fn release_apb_clk(clocks: &mut ClockTree) {
2650            trace!("Releasing APB_CLK");
2651            if decrement_reference_count(&mut clocks.apb_clk_refcount) {
2652                enable_apb_clk_impl(clocks, false);
2653            }
2654        }
2655        pub fn apb_clk_config_frequency(config: ApbClkConfig) -> u32 {
2656            (ahb_clk_frequency() / (config.divisor() + 1))
2657        }
2658        pub fn apb_clk_frequency() -> u32 {
2659            APB_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2660        }
2661        pub fn apb_clk_source_frequency() -> u32 {
2662            ahb_clk_frequency()
2663        }
2664        pub fn request_xtal_d2_clk(clocks: &mut ClockTree) {
2665            trace!("Enabling XTAL_D2_CLK");
2666            request_xtal_clk(clocks);
2667            enable_xtal_d2_clk_impl(clocks, true);
2668        }
2669        pub fn release_xtal_d2_clk(clocks: &mut ClockTree) {
2670            trace!("Disabling XTAL_D2_CLK");
2671            enable_xtal_d2_clk_impl(clocks, false);
2672            release_xtal_clk(clocks);
2673        }
2674        pub fn xtal_d2_clk_frequency() -> u32 {
2675            (xtal_clk_frequency() / 2)
2676        }
2677        pub fn xtal_d2_clk_source_frequency() -> u32 {
2678            xtal_clk_frequency()
2679        }
2680        pub fn configure_lp_fast_clk(clocks: &mut ClockTree, new_selector: LpFastClkConfig) {
2681            let old_selector = clocks.lp_fast_clk.replace(new_selector);
2682            refresh_lp_fast_clk_downstream(clocks);
2683            let active = clocks.lp_fast_clk_refcount > 0;
2684            if active {
2685                match new_selector {
2686                    LpFastClkConfig::RcFast => request_rc_fast_clk(clocks),
2687                    LpFastClkConfig::XtalD2 => request_xtal_d2_clk(clocks),
2688                    LpFastClkConfig::Xtal => request_xtal_clk(clocks),
2689                }
2690            }
2691            configure_lp_fast_clk_impl(clocks, old_selector, new_selector);
2692            if active && let Some(old_selector) = old_selector {
2693                match old_selector {
2694                    LpFastClkConfig::RcFast => release_rc_fast_clk(clocks),
2695                    LpFastClkConfig::XtalD2 => release_xtal_d2_clk(clocks),
2696                    LpFastClkConfig::Xtal => release_xtal_clk(clocks),
2697                }
2698            }
2699        }
2700        pub fn lp_fast_clk_config(clocks: &mut ClockTree) -> Option<LpFastClkConfig> {
2701            clocks.lp_fast_clk
2702        }
2703        pub fn request_lp_fast_clk(clocks: &mut ClockTree) {
2704            trace!("Requesting LP_FAST_CLK");
2705            if increment_reference_count(&mut clocks.lp_fast_clk_refcount) {
2706                trace!("Enabling LP_FAST_CLK");
2707                match unwrap!(clocks.lp_fast_clk) {
2708                    LpFastClkConfig::RcFast => request_rc_fast_clk(clocks),
2709                    LpFastClkConfig::XtalD2 => request_xtal_d2_clk(clocks),
2710                    LpFastClkConfig::Xtal => request_xtal_clk(clocks),
2711                }
2712                enable_lp_fast_clk_impl(clocks, true);
2713            }
2714        }
2715        pub fn release_lp_fast_clk(clocks: &mut ClockTree) {
2716            trace!("Releasing LP_FAST_CLK");
2717            if decrement_reference_count(&mut clocks.lp_fast_clk_refcount) {
2718                trace!("Disabling LP_FAST_CLK");
2719                enable_lp_fast_clk_impl(clocks, false);
2720                match unwrap!(clocks.lp_fast_clk) {
2721                    LpFastClkConfig::RcFast => release_rc_fast_clk(clocks),
2722                    LpFastClkConfig::XtalD2 => release_xtal_d2_clk(clocks),
2723                    LpFastClkConfig::Xtal => release_xtal_clk(clocks),
2724                }
2725            }
2726        }
2727        pub fn lp_fast_clk_config_frequency(config: LpFastClkConfig) -> u32 {
2728            match config {
2729                LpFastClkConfig::RcFast => rc_fast_clk_frequency(),
2730                LpFastClkConfig::XtalD2 => xtal_d2_clk_frequency(),
2731                LpFastClkConfig::Xtal => xtal_clk_frequency(),
2732            }
2733        }
2734        pub fn lp_fast_clk_frequency() -> u32 {
2735            LP_FAST_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2736        }
2737        pub fn lp_fast_clk_source_frequency(source: LpFastClkConfig) -> u32 {
2738            lp_fast_clk_config_frequency(source)
2739        }
2740        pub fn configure_lp_slow_clk(clocks: &mut ClockTree, new_selector: LpSlowClkConfig) {
2741            let old_selector = clocks.lp_slow_clk.replace(new_selector);
2742            refresh_lp_slow_clk_downstream(clocks);
2743            let active = clocks.lp_slow_clk_refcount > 0;
2744            if active {
2745                match new_selector {
2746                    LpSlowClkConfig::RcSlow => request_rc_slow_clk(clocks),
2747                    #[cfg(use_xtal32k)]
2748                    LpSlowClkConfig::Xtal32k => request_xtal32k_clk(clocks),
2749                    LpSlowClkConfig::OscSlow => request_osc_slow_clk(clocks),
2750                }
2751            }
2752            configure_lp_slow_clk_impl(clocks, old_selector, new_selector);
2753            if active && let Some(old_selector) = old_selector {
2754                match old_selector {
2755                    LpSlowClkConfig::RcSlow => release_rc_slow_clk(clocks),
2756                    #[cfg(use_xtal32k)]
2757                    LpSlowClkConfig::Xtal32k => release_xtal32k_clk(clocks),
2758                    LpSlowClkConfig::OscSlow => release_osc_slow_clk(clocks),
2759                }
2760            }
2761        }
2762        pub fn lp_slow_clk_config(clocks: &mut ClockTree) -> Option<LpSlowClkConfig> {
2763            clocks.lp_slow_clk
2764        }
2765        pub fn request_lp_slow_clk(clocks: &mut ClockTree) {
2766            trace!("Requesting LP_SLOW_CLK");
2767            if increment_reference_count(&mut clocks.lp_slow_clk_refcount) {
2768                trace!("Enabling LP_SLOW_CLK");
2769                match unwrap!(clocks.lp_slow_clk) {
2770                    LpSlowClkConfig::RcSlow => request_rc_slow_clk(clocks),
2771                    #[cfg(use_xtal32k)]
2772                    LpSlowClkConfig::Xtal32k => request_xtal32k_clk(clocks),
2773                    LpSlowClkConfig::OscSlow => request_osc_slow_clk(clocks),
2774                }
2775                enable_lp_slow_clk_impl(clocks, true);
2776            }
2777        }
2778        pub fn release_lp_slow_clk(clocks: &mut ClockTree) {
2779            trace!("Releasing LP_SLOW_CLK");
2780            if decrement_reference_count(&mut clocks.lp_slow_clk_refcount) {
2781                trace!("Disabling LP_SLOW_CLK");
2782                enable_lp_slow_clk_impl(clocks, false);
2783                match unwrap!(clocks.lp_slow_clk) {
2784                    LpSlowClkConfig::RcSlow => release_rc_slow_clk(clocks),
2785                    #[cfg(use_xtal32k)]
2786                    LpSlowClkConfig::Xtal32k => release_xtal32k_clk(clocks),
2787                    LpSlowClkConfig::OscSlow => release_osc_slow_clk(clocks),
2788                }
2789            }
2790        }
2791        pub fn lp_slow_clk_config_frequency(config: LpSlowClkConfig) -> u32 {
2792            match config {
2793                LpSlowClkConfig::RcSlow => rc_slow_clk_frequency(),
2794                #[cfg(use_xtal32k)]
2795                LpSlowClkConfig::Xtal32k => xtal32k_clk_frequency(),
2796                LpSlowClkConfig::OscSlow => osc_slow_clk_frequency(),
2797            }
2798        }
2799        pub fn lp_slow_clk_frequency() -> u32 {
2800            LP_SLOW_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2801        }
2802        pub fn lp_slow_clk_source_frequency(source: LpSlowClkConfig) -> u32 {
2803            lp_slow_clk_config_frequency(source)
2804        }
2805        pub fn request_ble_lp_xtal_clk(clocks: &mut ClockTree) {
2806            trace!("Enabling BLE_LP_XTAL_CLK");
2807            request_xtal_clk(clocks);
2808            enable_ble_lp_xtal_clk_impl(clocks, true);
2809        }
2810        pub fn release_ble_lp_xtal_clk(clocks: &mut ClockTree) {
2811            trace!("Disabling BLE_LP_XTAL_CLK");
2812            enable_ble_lp_xtal_clk_impl(clocks, false);
2813            release_xtal_clk(clocks);
2814        }
2815        pub fn ble_lp_xtal_clk_frequency() -> u32 {
2816            100000
2817        }
2818        pub fn ble_lp_xtal_clk_source_frequency() -> u32 {
2819            xtal_clk_frequency()
2820        }
2821        pub fn request_ble_lp_rc_slow_clk(clocks: &mut ClockTree) {
2822            trace!("Enabling BLE_LP_RC_SLOW_CLK");
2823            request_rc_slow_clk(clocks);
2824            enable_ble_lp_rc_slow_clk_impl(clocks, true);
2825        }
2826        pub fn release_ble_lp_rc_slow_clk(clocks: &mut ClockTree) {
2827            trace!("Disabling BLE_LP_RC_SLOW_CLK");
2828            enable_ble_lp_rc_slow_clk_impl(clocks, false);
2829            release_rc_slow_clk(clocks);
2830        }
2831        pub fn ble_lp_rc_slow_clk_frequency() -> u32 {
2832            (rc_slow_clk_frequency() / 5)
2833        }
2834        pub fn ble_lp_rc_slow_clk_source_frequency() -> u32 {
2835            rc_slow_clk_frequency()
2836        }
2837        pub fn configure_ble_lp_clk(clocks: &mut ClockTree, new_selector: BleLpClkConfig) {
2838            let old_selector = clocks.ble_lp_clk.replace(new_selector);
2839            refresh_ble_lp_clk_downstream(clocks);
2840            let active = clocks.ble_lp_clk_refcount > 0;
2841            if active {
2842                match new_selector {
2843                    BleLpClkConfig::Xtal => request_ble_lp_xtal_clk(clocks),
2844                    BleLpClkConfig::RcSlow => request_ble_lp_rc_slow_clk(clocks),
2845                    #[cfg(use_xtal32k)]
2846                    BleLpClkConfig::Xtal32k => request_xtal32k_clk(clocks),
2847                }
2848            }
2849            configure_ble_lp_clk_impl(clocks, old_selector, new_selector);
2850            if active && let Some(old_selector) = old_selector {
2851                match old_selector {
2852                    BleLpClkConfig::Xtal => release_ble_lp_xtal_clk(clocks),
2853                    BleLpClkConfig::RcSlow => release_ble_lp_rc_slow_clk(clocks),
2854                    #[cfg(use_xtal32k)]
2855                    BleLpClkConfig::Xtal32k => release_xtal32k_clk(clocks),
2856                }
2857            }
2858        }
2859        pub fn ble_lp_clk_config(clocks: &mut ClockTree) -> Option<BleLpClkConfig> {
2860            clocks.ble_lp_clk
2861        }
2862        pub fn request_ble_lp_clk(clocks: &mut ClockTree) {
2863            trace!("Requesting BLE_LP_CLK");
2864            if increment_reference_count(&mut clocks.ble_lp_clk_refcount) {
2865                trace!("Enabling BLE_LP_CLK");
2866                match unwrap!(clocks.ble_lp_clk) {
2867                    BleLpClkConfig::Xtal => request_ble_lp_xtal_clk(clocks),
2868                    BleLpClkConfig::RcSlow => request_ble_lp_rc_slow_clk(clocks),
2869                    #[cfg(use_xtal32k)]
2870                    BleLpClkConfig::Xtal32k => request_xtal32k_clk(clocks),
2871                }
2872                enable_ble_lp_clk_impl(clocks, true);
2873            }
2874        }
2875        pub fn release_ble_lp_clk(clocks: &mut ClockTree) {
2876            trace!("Releasing BLE_LP_CLK");
2877            if decrement_reference_count(&mut clocks.ble_lp_clk_refcount) {
2878                trace!("Disabling BLE_LP_CLK");
2879                enable_ble_lp_clk_impl(clocks, false);
2880                match unwrap!(clocks.ble_lp_clk) {
2881                    BleLpClkConfig::Xtal => release_ble_lp_xtal_clk(clocks),
2882                    BleLpClkConfig::RcSlow => release_ble_lp_rc_slow_clk(clocks),
2883                    #[cfg(use_xtal32k)]
2884                    BleLpClkConfig::Xtal32k => release_xtal32k_clk(clocks),
2885                }
2886            }
2887        }
2888        pub fn ble_lp_clk_config_frequency(config: BleLpClkConfig) -> u32 {
2889            match config {
2890                BleLpClkConfig::Xtal => ble_lp_xtal_clk_frequency(),
2891                BleLpClkConfig::RcSlow => ble_lp_rc_slow_clk_frequency(),
2892                #[cfg(use_xtal32k)]
2893                BleLpClkConfig::Xtal32k => xtal32k_clk_frequency(),
2894            }
2895        }
2896        pub fn ble_lp_clk_frequency() -> u32 {
2897            BLE_LP_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2898        }
2899        pub fn ble_lp_clk_source_frequency(source: BleLpClkConfig) -> u32 {
2900            ble_lp_clk_config_frequency(source)
2901        }
2902        pub fn request_crypto_pll_div(clocks: &mut ClockTree) {
2903            trace!("Enabling CRYPTO_PLL_DIV");
2904            request_pll_clk(clocks);
2905            enable_crypto_pll_div_impl(clocks, true);
2906        }
2907        pub fn release_crypto_pll_div(clocks: &mut ClockTree) {
2908            trace!("Disabling CRYPTO_PLL_DIV");
2909            enable_crypto_pll_div_impl(clocks, false);
2910            release_pll_clk(clocks);
2911        }
2912        pub fn crypto_pll_div_frequency() -> u32 {
2913            (pll_clk_frequency() / 3)
2914        }
2915        pub fn crypto_pll_div_source_frequency() -> u32 {
2916            pll_clk_frequency()
2917        }
2918        pub fn configure_crypto_clk(clocks: &mut ClockTree, new_selector: CryptoClkConfig) {
2919            let old_selector = clocks.crypto_clk.replace(new_selector);
2920            refresh_crypto_clk_downstream(clocks);
2921            let active = clocks.crypto_clk_refcount > 0;
2922            if active {
2923                match new_selector {
2924                    CryptoClkConfig::Xtal => request_xtal_clk(clocks),
2925                    CryptoClkConfig::RcFast => request_rc_fast_clk(clocks),
2926                    CryptoClkConfig::PllF480m => request_crypto_pll_div(clocks),
2927                }
2928            }
2929            configure_crypto_clk_impl(clocks, old_selector, new_selector);
2930            if active && let Some(old_selector) = old_selector {
2931                match old_selector {
2932                    CryptoClkConfig::Xtal => release_xtal_clk(clocks),
2933                    CryptoClkConfig::RcFast => release_rc_fast_clk(clocks),
2934                    CryptoClkConfig::PllF480m => release_crypto_pll_div(clocks),
2935                }
2936            }
2937        }
2938        pub fn crypto_clk_config(clocks: &mut ClockTree) -> Option<CryptoClkConfig> {
2939            clocks.crypto_clk
2940        }
2941        pub fn request_crypto_clk(clocks: &mut ClockTree) {
2942            trace!("Requesting CRYPTO_CLK");
2943            if increment_reference_count(&mut clocks.crypto_clk_refcount) {
2944                trace!("Enabling CRYPTO_CLK");
2945                match unwrap!(clocks.crypto_clk) {
2946                    CryptoClkConfig::Xtal => request_xtal_clk(clocks),
2947                    CryptoClkConfig::RcFast => request_rc_fast_clk(clocks),
2948                    CryptoClkConfig::PllF480m => request_crypto_pll_div(clocks),
2949                }
2950                enable_crypto_clk_impl(clocks, true);
2951            }
2952        }
2953        pub fn release_crypto_clk(clocks: &mut ClockTree) {
2954            trace!("Releasing CRYPTO_CLK");
2955            if decrement_reference_count(&mut clocks.crypto_clk_refcount) {
2956                trace!("Disabling CRYPTO_CLK");
2957                enable_crypto_clk_impl(clocks, false);
2958                match unwrap!(clocks.crypto_clk) {
2959                    CryptoClkConfig::Xtal => release_xtal_clk(clocks),
2960                    CryptoClkConfig::RcFast => release_rc_fast_clk(clocks),
2961                    CryptoClkConfig::PllF480m => release_crypto_pll_div(clocks),
2962                }
2963            }
2964        }
2965        pub fn crypto_clk_config_frequency(config: CryptoClkConfig) -> u32 {
2966            match config {
2967                CryptoClkConfig::Xtal => xtal_clk_frequency(),
2968                CryptoClkConfig::RcFast => rc_fast_clk_frequency(),
2969                CryptoClkConfig::PllF480m => crypto_pll_div_frequency(),
2970            }
2971        }
2972        pub fn crypto_clk_frequency() -> u32 {
2973            CRYPTO_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2974        }
2975        pub fn crypto_clk_source_frequency(source: CryptoClkConfig) -> u32 {
2976            crypto_clk_config_frequency(source)
2977        }
2978        pub fn configure_timg_calibration_clock(
2979            clocks: &mut ClockTree,
2980            new_selector: TimgCalibrationClockConfig,
2981        ) {
2982            let old_selector = clocks.timg_calibration_clock.replace(new_selector);
2983            refresh_timg_calibration_clock_downstream(clocks);
2984            let active = clocks.timg_calibration_clock_refcount > 0;
2985            if active {
2986                match new_selector {
2987                    TimgCalibrationClockConfig::OscSlowClk => request_osc_slow_clk(clocks),
2988                    TimgCalibrationClockConfig::RcSlowClk => request_rc_slow_clk(clocks),
2989                    TimgCalibrationClockConfig::RcFastDivClk => request_rc_fast_clk(clocks),
2990                    #[cfg(use_xtal32k)]
2991                    TimgCalibrationClockConfig::Xtal32kClk => request_xtal32k_clk(clocks),
2992                }
2993            }
2994            configure_timg_calibration_clock_impl(clocks, old_selector, new_selector);
2995            if active && let Some(old_selector) = old_selector {
2996                match old_selector {
2997                    TimgCalibrationClockConfig::OscSlowClk => release_osc_slow_clk(clocks),
2998                    TimgCalibrationClockConfig::RcSlowClk => release_rc_slow_clk(clocks),
2999                    TimgCalibrationClockConfig::RcFastDivClk => release_rc_fast_clk(clocks),
3000                    #[cfg(use_xtal32k)]
3001                    TimgCalibrationClockConfig::Xtal32kClk => release_xtal32k_clk(clocks),
3002                }
3003            }
3004        }
3005        pub fn timg_calibration_clock_config(
3006            clocks: &mut ClockTree,
3007        ) -> Option<TimgCalibrationClockConfig> {
3008            clocks.timg_calibration_clock
3009        }
3010        pub fn request_timg_calibration_clock(clocks: &mut ClockTree) {
3011            trace!("Requesting TIMG_CALIBRATION_CLOCK");
3012            if increment_reference_count(&mut clocks.timg_calibration_clock_refcount) {
3013                trace!("Enabling TIMG_CALIBRATION_CLOCK");
3014                crate::rtc_cntl::WakeLock::acquire();
3015                match unwrap!(clocks.timg_calibration_clock) {
3016                    TimgCalibrationClockConfig::OscSlowClk => request_osc_slow_clk(clocks),
3017                    TimgCalibrationClockConfig::RcSlowClk => request_rc_slow_clk(clocks),
3018                    TimgCalibrationClockConfig::RcFastDivClk => request_rc_fast_clk(clocks),
3019                    #[cfg(use_xtal32k)]
3020                    TimgCalibrationClockConfig::Xtal32kClk => request_xtal32k_clk(clocks),
3021                }
3022                enable_timg_calibration_clock_impl(clocks, true);
3023            }
3024        }
3025        pub fn release_timg_calibration_clock(clocks: &mut ClockTree) {
3026            trace!("Releasing TIMG_CALIBRATION_CLOCK");
3027            if decrement_reference_count(&mut clocks.timg_calibration_clock_refcount) {
3028                trace!("Disabling TIMG_CALIBRATION_CLOCK");
3029                crate::rtc_cntl::WakeLock::release();
3030                enable_timg_calibration_clock_impl(clocks, false);
3031                match unwrap!(clocks.timg_calibration_clock) {
3032                    TimgCalibrationClockConfig::OscSlowClk => release_osc_slow_clk(clocks),
3033                    TimgCalibrationClockConfig::RcSlowClk => release_rc_slow_clk(clocks),
3034                    TimgCalibrationClockConfig::RcFastDivClk => release_rc_fast_clk(clocks),
3035                    #[cfg(use_xtal32k)]
3036                    TimgCalibrationClockConfig::Xtal32kClk => release_xtal32k_clk(clocks),
3037                }
3038            }
3039        }
3040        pub fn timg_calibration_clock_config_frequency(config: TimgCalibrationClockConfig) -> u32 {
3041            match config {
3042                TimgCalibrationClockConfig::OscSlowClk => osc_slow_clk_frequency(),
3043                TimgCalibrationClockConfig::RcSlowClk => rc_slow_clk_frequency(),
3044                TimgCalibrationClockConfig::RcFastDivClk => rc_fast_clk_frequency(),
3045                #[cfg(use_xtal32k)]
3046                TimgCalibrationClockConfig::Xtal32kClk => xtal32k_clk_frequency(),
3047            }
3048        }
3049        pub fn timg_calibration_clock_frequency() -> u32 {
3050            TIMG_CALIBRATION_CLOCK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
3051        }
3052        pub fn timg_calibration_clock_source_frequency(source: TimgCalibrationClockConfig) -> u32 {
3053            timg_calibration_clock_config_frequency(source)
3054        }
3055        impl AdcInstance {
3056            pub fn configure_function_clock(
3057                self,
3058                clocks: &mut ClockTree,
3059                new_selector: AdcFunctionClockConfig,
3060            ) {
3061                let old_selector = clocks.adc_function_clock[self as usize].replace(new_selector);
3062                refresh_adc_function_clock_downstream(clocks, self);
3063                let active = clocks.adc_function_clock_refcount[self as usize] > 0;
3064                if active {
3065                    match new_selector {
3066                        AdcFunctionClockConfig::Xtal => request_xtal_clk(clocks),
3067                        AdcFunctionClockConfig::RcFast => request_rc_fast_clk(clocks),
3068                        AdcFunctionClockConfig::PllF80m => request_pll_f80m(clocks),
3069                    }
3070                }
3071                self.configure_function_clock_impl(clocks, old_selector, new_selector);
3072                if active && let Some(old_selector) = old_selector {
3073                    match old_selector {
3074                        AdcFunctionClockConfig::Xtal => release_xtal_clk(clocks),
3075                        AdcFunctionClockConfig::RcFast => release_rc_fast_clk(clocks),
3076                        AdcFunctionClockConfig::PllF80m => release_pll_f80m(clocks),
3077                    }
3078                }
3079            }
3080            pub fn function_clock_config(
3081                self,
3082                clocks: &mut ClockTree,
3083            ) -> Option<AdcFunctionClockConfig> {
3084                clocks.adc_function_clock[self as usize]
3085            }
3086            pub fn request_function_clock(self, clocks: &mut ClockTree) {
3087                trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3088                if increment_reference_count(&mut clocks.adc_function_clock_refcount[self as usize])
3089                {
3090                    trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3091                    match unwrap!(clocks.adc_function_clock[self as usize]) {
3092                        AdcFunctionClockConfig::Xtal => request_xtal_clk(clocks),
3093                        AdcFunctionClockConfig::RcFast => request_rc_fast_clk(clocks),
3094                        AdcFunctionClockConfig::PllF80m => request_pll_f80m(clocks),
3095                    }
3096                    self.enable_function_clock_impl(clocks, true);
3097                }
3098            }
3099            pub fn release_function_clock(self, clocks: &mut ClockTree) {
3100                trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3101                if decrement_reference_count(&mut clocks.adc_function_clock_refcount[self as usize])
3102                {
3103                    trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3104                    self.enable_function_clock_impl(clocks, false);
3105                    match unwrap!(clocks.adc_function_clock[self as usize]) {
3106                        AdcFunctionClockConfig::Xtal => release_xtal_clk(clocks),
3107                        AdcFunctionClockConfig::RcFast => release_rc_fast_clk(clocks),
3108                        AdcFunctionClockConfig::PllF80m => release_pll_f80m(clocks),
3109                    }
3110                }
3111            }
3112            pub fn function_clock_config_frequency(config: AdcFunctionClockConfig) -> u32 {
3113                match config {
3114                    AdcFunctionClockConfig::Xtal => xtal_clk_frequency(),
3115                    AdcFunctionClockConfig::RcFast => rc_fast_clk_frequency(),
3116                    AdcFunctionClockConfig::PllF80m => pll_f80m_frequency(),
3117                }
3118            }
3119            pub fn function_clock_frequency(self) -> u32 {
3120                ADC_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
3121                    .load(::core::sync::atomic::Ordering::Acquire)
3122            }
3123            pub fn function_clock_source_frequency(source: AdcFunctionClockConfig) -> u32 {
3124                Self::function_clock_config_frequency(source)
3125            }
3126        }
3127        impl I2cInstance {
3128            pub fn configure_function_clock(
3129                self,
3130                clocks: &mut ClockTree,
3131                config: I2cFunctionClockConfig,
3132            ) {
3133                let old_config = clocks.i2c_function_clock[self as usize].replace(config);
3134                refresh_i2c_function_clock_downstream(clocks, self);
3135                let active = clocks.i2c_function_clock_refcount[self as usize] > 0;
3136                if active {
3137                    match config.sclk {
3138                        I2cFunctionClockSclk::Xtal => request_xtal_clk(clocks),
3139                        I2cFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
3140                    }
3141                }
3142                self.configure_function_clock_impl(clocks, old_config, config);
3143                if active && let Some(old_config) = old_config {
3144                    match old_config.sclk {
3145                        I2cFunctionClockSclk::Xtal => release_xtal_clk(clocks),
3146                        I2cFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
3147                    }
3148                }
3149            }
3150            pub fn function_clock_config(
3151                self,
3152                clocks: &mut ClockTree,
3153            ) -> Option<I2cFunctionClockConfig> {
3154                clocks.i2c_function_clock[self as usize]
3155            }
3156            pub fn request_function_clock(self, clocks: &mut ClockTree) {
3157                trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3158                if increment_reference_count(&mut clocks.i2c_function_clock_refcount[self as usize])
3159                {
3160                    trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3161                    match unwrap!(clocks.i2c_function_clock[self as usize]).sclk {
3162                        I2cFunctionClockSclk::Xtal => request_xtal_clk(clocks),
3163                        I2cFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
3164                    }
3165                    self.enable_function_clock_impl(clocks, true);
3166                }
3167            }
3168            pub fn release_function_clock(self, clocks: &mut ClockTree) {
3169                trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3170                if decrement_reference_count(&mut clocks.i2c_function_clock_refcount[self as usize])
3171                {
3172                    trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3173                    self.enable_function_clock_impl(clocks, false);
3174                    match unwrap!(clocks.i2c_function_clock[self as usize]).sclk {
3175                        I2cFunctionClockSclk::Xtal => release_xtal_clk(clocks),
3176                        I2cFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
3177                    }
3178                }
3179            }
3180            pub fn function_clock_config_frequency(config: I2cFunctionClockConfig) -> u32 {
3181                (match config.sclk {
3182                    I2cFunctionClockSclk::Xtal => xtal_clk_frequency(),
3183                    I2cFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
3184                } / (config.div_num() + 1))
3185            }
3186            pub fn function_clock_frequency(self) -> u32 {
3187                I2C_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
3188                    .load(::core::sync::atomic::Ordering::Acquire)
3189            }
3190            pub fn function_clock_source_frequency(sclk: I2cFunctionClockSclk) -> u32 {
3191                match sclk {
3192                    I2cFunctionClockSclk::Xtal => xtal_clk_frequency(),
3193                    I2cFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
3194                }
3195            }
3196        }
3197        impl I2sInstance {
3198            pub fn configure_tx_clk(self, clocks: &mut ClockTree, config: I2sClkConfig) {
3199                let old_config = clocks.i2s_tx_clk[self as usize].replace(config);
3200                refresh_i2s_tx_clk_downstream(clocks, self);
3201                let active = clocks.i2s_tx_clk_refcount[self as usize] > 0;
3202                if active {
3203                    match config.sclk {
3204                        I2sClkSclk::Xtal => request_xtal_clk(clocks),
3205                        I2sClkSclk::PllF120m => request_pll_f120m(clocks),
3206                        I2sClkSclk::PllF160m => request_pll_f160m(clocks),
3207                    }
3208                }
3209                self.configure_tx_clk_impl(clocks, old_config, config);
3210                if active && let Some(old_config) = old_config {
3211                    match old_config.sclk {
3212                        I2sClkSclk::Xtal => release_xtal_clk(clocks),
3213                        I2sClkSclk::PllF120m => release_pll_f120m(clocks),
3214                        I2sClkSclk::PllF160m => release_pll_f160m(clocks),
3215                    }
3216                }
3217            }
3218            pub fn tx_clk_config(self, clocks: &mut ClockTree) -> Option<I2sClkConfig> {
3219                clocks.i2s_tx_clk[self as usize]
3220            }
3221            pub fn request_tx_clk(self, clocks: &mut ClockTree) {
3222                trace!("Requesting {:?}::TX_CLK", self);
3223                if increment_reference_count(&mut clocks.i2s_tx_clk_refcount[self as usize]) {
3224                    trace!("Enabling {:?}::TX_CLK", self);
3225                    crate::rtc_cntl::WakeLock::acquire();
3226                    match unwrap!(clocks.i2s_tx_clk[self as usize]).sclk {
3227                        I2sClkSclk::Xtal => request_xtal_clk(clocks),
3228                        I2sClkSclk::PllF120m => request_pll_f120m(clocks),
3229                        I2sClkSclk::PllF160m => request_pll_f160m(clocks),
3230                    }
3231                    self.enable_tx_clk_impl(clocks, true);
3232                }
3233            }
3234            pub fn release_tx_clk(self, clocks: &mut ClockTree) {
3235                trace!("Releasing {:?}::TX_CLK", self);
3236                if decrement_reference_count(&mut clocks.i2s_tx_clk_refcount[self as usize]) {
3237                    trace!("Disabling {:?}::TX_CLK", self);
3238                    crate::rtc_cntl::WakeLock::release();
3239                    self.enable_tx_clk_impl(clocks, false);
3240                    match unwrap!(clocks.i2s_tx_clk[self as usize]).sclk {
3241                        I2sClkSclk::Xtal => release_xtal_clk(clocks),
3242                        I2sClkSclk::PllF120m => release_pll_f120m(clocks),
3243                        I2sClkSclk::PllF160m => release_pll_f160m(clocks),
3244                    }
3245                }
3246            }
3247            pub fn tx_clk_config_frequency(config: I2sClkConfig) -> u32 {
3248                (((match config.sclk {
3249                    I2sClkSclk::Xtal => xtal_clk_frequency(),
3250                    I2sClkSclk::PllF120m => pll_f120m_frequency(),
3251                    I2sClkSclk::PllF160m => pll_f160m_frequency(),
3252                } as u64)
3253                    * (config.div_a() as u64))
3254                    / (((config.div_num() * config.div_a()) + config.div_b()) as u64))
3255                    as u32
3256            }
3257            pub fn tx_clk_frequency(self) -> u32 {
3258                I2S_TX_CLK_FREQ_CACHE[self as usize].load(::core::sync::atomic::Ordering::Acquire)
3259            }
3260            pub fn tx_clk_source_frequency(sclk: I2sClkSclk) -> u32 {
3261                match sclk {
3262                    I2sClkSclk::Xtal => xtal_clk_frequency(),
3263                    I2sClkSclk::PllF120m => pll_f120m_frequency(),
3264                    I2sClkSclk::PllF160m => pll_f160m_frequency(),
3265                }
3266            }
3267            pub fn configure_rx_clk(self, clocks: &mut ClockTree, config: I2sClkConfig) {
3268                let old_config = clocks.i2s_rx_clk[self as usize].replace(config);
3269                refresh_i2s_rx_clk_downstream(clocks, self);
3270                let active = clocks.i2s_rx_clk_refcount[self as usize] > 0;
3271                if active {
3272                    match config.sclk {
3273                        I2sClkSclk::Xtal => request_xtal_clk(clocks),
3274                        I2sClkSclk::PllF120m => request_pll_f120m(clocks),
3275                        I2sClkSclk::PllF160m => request_pll_f160m(clocks),
3276                    }
3277                }
3278                self.configure_rx_clk_impl(clocks, old_config, config);
3279                if active && let Some(old_config) = old_config {
3280                    match old_config.sclk {
3281                        I2sClkSclk::Xtal => release_xtal_clk(clocks),
3282                        I2sClkSclk::PllF120m => release_pll_f120m(clocks),
3283                        I2sClkSclk::PllF160m => release_pll_f160m(clocks),
3284                    }
3285                }
3286            }
3287            pub fn rx_clk_config(self, clocks: &mut ClockTree) -> Option<I2sClkConfig> {
3288                clocks.i2s_rx_clk[self as usize]
3289            }
3290            pub fn request_rx_clk(self, clocks: &mut ClockTree) {
3291                trace!("Requesting {:?}::RX_CLK", self);
3292                if increment_reference_count(&mut clocks.i2s_rx_clk_refcount[self as usize]) {
3293                    trace!("Enabling {:?}::RX_CLK", self);
3294                    crate::rtc_cntl::WakeLock::acquire();
3295                    match unwrap!(clocks.i2s_rx_clk[self as usize]).sclk {
3296                        I2sClkSclk::Xtal => request_xtal_clk(clocks),
3297                        I2sClkSclk::PllF120m => request_pll_f120m(clocks),
3298                        I2sClkSclk::PllF160m => request_pll_f160m(clocks),
3299                    }
3300                    self.enable_rx_clk_impl(clocks, true);
3301                }
3302            }
3303            pub fn release_rx_clk(self, clocks: &mut ClockTree) {
3304                trace!("Releasing {:?}::RX_CLK", self);
3305                if decrement_reference_count(&mut clocks.i2s_rx_clk_refcount[self as usize]) {
3306                    trace!("Disabling {:?}::RX_CLK", self);
3307                    crate::rtc_cntl::WakeLock::release();
3308                    self.enable_rx_clk_impl(clocks, false);
3309                    match unwrap!(clocks.i2s_rx_clk[self as usize]).sclk {
3310                        I2sClkSclk::Xtal => release_xtal_clk(clocks),
3311                        I2sClkSclk::PllF120m => release_pll_f120m(clocks),
3312                        I2sClkSclk::PllF160m => release_pll_f160m(clocks),
3313                    }
3314                }
3315            }
3316            pub fn rx_clk_config_frequency(config: I2sClkConfig) -> u32 {
3317                (((match config.sclk {
3318                    I2sClkSclk::Xtal => xtal_clk_frequency(),
3319                    I2sClkSclk::PllF120m => pll_f120m_frequency(),
3320                    I2sClkSclk::PllF160m => pll_f160m_frequency(),
3321                } as u64)
3322                    * (config.div_a() as u64))
3323                    / (((config.div_num() * config.div_a()) + config.div_b()) as u64))
3324                    as u32
3325            }
3326            pub fn rx_clk_frequency(self) -> u32 {
3327                I2S_RX_CLK_FREQ_CACHE[self as usize].load(::core::sync::atomic::Ordering::Acquire)
3328            }
3329            pub fn rx_clk_source_frequency(sclk: I2sClkSclk) -> u32 {
3330                match sclk {
3331                    I2sClkSclk::Xtal => xtal_clk_frequency(),
3332                    I2sClkSclk::PllF120m => pll_f120m_frequency(),
3333                    I2sClkSclk::PllF160m => pll_f160m_frequency(),
3334                }
3335            }
3336            pub fn configure_mclk_out(
3337                self,
3338                clocks: &mut ClockTree,
3339                new_selector: I2sMclkOutConfig,
3340            ) {
3341                let old_selector = clocks.i2s_mclk_out[self as usize].replace(new_selector);
3342                refresh_i2s_mclk_out_downstream(clocks, self);
3343                let active = clocks.i2s_mclk_out_refcount[self as usize] > 0;
3344                if active {
3345                    match new_selector {
3346                        I2sMclkOutConfig::Tx => self.request_tx_clk(clocks),
3347                        I2sMclkOutConfig::Rx => self.request_rx_clk(clocks),
3348                    }
3349                }
3350                self.configure_mclk_out_impl(clocks, old_selector, new_selector);
3351                if active && let Some(old_selector) = old_selector {
3352                    match old_selector {
3353                        I2sMclkOutConfig::Tx => self.release_tx_clk(clocks),
3354                        I2sMclkOutConfig::Rx => self.release_rx_clk(clocks),
3355                    }
3356                }
3357            }
3358            pub fn mclk_out_config(self, clocks: &mut ClockTree) -> Option<I2sMclkOutConfig> {
3359                clocks.i2s_mclk_out[self as usize]
3360            }
3361            pub fn request_mclk_out(self, clocks: &mut ClockTree) {
3362                trace!("Requesting {:?}::MCLK_OUT", self);
3363                if increment_reference_count(&mut clocks.i2s_mclk_out_refcount[self as usize]) {
3364                    trace!("Enabling {:?}::MCLK_OUT", self);
3365                    match unwrap!(clocks.i2s_mclk_out[self as usize]) {
3366                        I2sMclkOutConfig::Tx => self.request_tx_clk(clocks),
3367                        I2sMclkOutConfig::Rx => self.request_rx_clk(clocks),
3368                    }
3369                    self.enable_mclk_out_impl(clocks, true);
3370                }
3371            }
3372            pub fn release_mclk_out(self, clocks: &mut ClockTree) {
3373                trace!("Releasing {:?}::MCLK_OUT", self);
3374                if decrement_reference_count(&mut clocks.i2s_mclk_out_refcount[self as usize]) {
3375                    trace!("Disabling {:?}::MCLK_OUT", self);
3376                    self.enable_mclk_out_impl(clocks, false);
3377                    match unwrap!(clocks.i2s_mclk_out[self as usize]) {
3378                        I2sMclkOutConfig::Tx => self.release_tx_clk(clocks),
3379                        I2sMclkOutConfig::Rx => self.release_rx_clk(clocks),
3380                    }
3381                }
3382            }
3383            pub fn mclk_out_config_frequency(self, config: I2sMclkOutConfig) -> u32 {
3384                match config {
3385                    I2sMclkOutConfig::Tx => self.tx_clk_frequency(),
3386                    I2sMclkOutConfig::Rx => self.rx_clk_frequency(),
3387                }
3388            }
3389            pub fn mclk_out_frequency(self) -> u32 {
3390                I2S_MCLK_OUT_FREQ_CACHE[self as usize].load(::core::sync::atomic::Ordering::Acquire)
3391            }
3392        }
3393        impl SpiInstance {
3394            pub fn configure_function_clock(
3395                self,
3396                clocks: &mut ClockTree,
3397                new_selector: SpiFunctionClockConfig,
3398            ) {
3399                let old_selector = clocks.spi_function_clock[self as usize].replace(new_selector);
3400                refresh_spi_function_clock_downstream(clocks, self);
3401                let active = clocks.spi_function_clock_refcount[self as usize] > 0;
3402                if active {
3403                    match new_selector {
3404                        SpiFunctionClockConfig::Xtal => request_xtal_clk(clocks),
3405                        SpiFunctionClockConfig::PllF160m => request_pll_f160m(clocks),
3406                        SpiFunctionClockConfig::RcFast => request_rc_fast_clk(clocks),
3407                    }
3408                }
3409                self.configure_function_clock_impl(clocks, old_selector, new_selector);
3410                if active && let Some(old_selector) = old_selector {
3411                    match old_selector {
3412                        SpiFunctionClockConfig::Xtal => release_xtal_clk(clocks),
3413                        SpiFunctionClockConfig::PllF160m => release_pll_f160m(clocks),
3414                        SpiFunctionClockConfig::RcFast => release_rc_fast_clk(clocks),
3415                    }
3416                }
3417            }
3418            pub fn function_clock_config(
3419                self,
3420                clocks: &mut ClockTree,
3421            ) -> Option<SpiFunctionClockConfig> {
3422                clocks.spi_function_clock[self as usize]
3423            }
3424            pub fn request_function_clock(self, clocks: &mut ClockTree) {
3425                trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3426                if increment_reference_count(&mut clocks.spi_function_clock_refcount[self as usize])
3427                {
3428                    trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3429                    match unwrap!(clocks.spi_function_clock[self as usize]) {
3430                        SpiFunctionClockConfig::Xtal => request_xtal_clk(clocks),
3431                        SpiFunctionClockConfig::PllF160m => request_pll_f160m(clocks),
3432                        SpiFunctionClockConfig::RcFast => request_rc_fast_clk(clocks),
3433                    }
3434                    self.enable_function_clock_impl(clocks, true);
3435                }
3436            }
3437            pub fn release_function_clock(self, clocks: &mut ClockTree) {
3438                trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3439                if decrement_reference_count(&mut clocks.spi_function_clock_refcount[self as usize])
3440                {
3441                    trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3442                    self.enable_function_clock_impl(clocks, false);
3443                    match unwrap!(clocks.spi_function_clock[self as usize]) {
3444                        SpiFunctionClockConfig::Xtal => release_xtal_clk(clocks),
3445                        SpiFunctionClockConfig::PllF160m => release_pll_f160m(clocks),
3446                        SpiFunctionClockConfig::RcFast => release_rc_fast_clk(clocks),
3447                    }
3448                }
3449            }
3450            pub fn function_clock_config_frequency(config: SpiFunctionClockConfig) -> u32 {
3451                match config {
3452                    SpiFunctionClockConfig::Xtal => xtal_clk_frequency(),
3453                    SpiFunctionClockConfig::PllF160m => pll_f160m_frequency(),
3454                    SpiFunctionClockConfig::RcFast => rc_fast_clk_frequency(),
3455                }
3456            }
3457            pub fn function_clock_frequency(self) -> u32 {
3458                SPI_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
3459                    .load(::core::sync::atomic::Ordering::Acquire)
3460            }
3461            pub fn function_clock_source_frequency(source: SpiFunctionClockConfig) -> u32 {
3462                Self::function_clock_config_frequency(source)
3463            }
3464        }
3465        impl TimgInstance {
3466            pub fn configure_function_clock(
3467                self,
3468                clocks: &mut ClockTree,
3469                new_selector: TimgFunctionClockConfig,
3470            ) {
3471                let old_selector = clocks.timg_function_clock[self as usize].replace(new_selector);
3472                refresh_timg_function_clock_downstream(clocks, self);
3473                let active = clocks.timg_function_clock_refcount[self as usize] > 0;
3474                if active {
3475                    match new_selector {
3476                        TimgFunctionClockConfig::XtalClk => request_xtal_clk(clocks),
3477                        TimgFunctionClockConfig::RcFastClk => request_rc_fast_clk(clocks),
3478                        TimgFunctionClockConfig::PllF80m => request_pll_f80m(clocks),
3479                    }
3480                }
3481                self.configure_function_clock_impl(clocks, old_selector, new_selector);
3482                if active && let Some(old_selector) = old_selector {
3483                    match old_selector {
3484                        TimgFunctionClockConfig::XtalClk => release_xtal_clk(clocks),
3485                        TimgFunctionClockConfig::RcFastClk => release_rc_fast_clk(clocks),
3486                        TimgFunctionClockConfig::PllF80m => release_pll_f80m(clocks),
3487                    }
3488                }
3489            }
3490            pub fn function_clock_config(
3491                self,
3492                clocks: &mut ClockTree,
3493            ) -> Option<TimgFunctionClockConfig> {
3494                clocks.timg_function_clock[self as usize]
3495            }
3496            pub fn request_function_clock(self, clocks: &mut ClockTree) {
3497                trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3498                if increment_reference_count(
3499                    &mut clocks.timg_function_clock_refcount[self as usize],
3500                ) {
3501                    trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3502                    match unwrap!(clocks.timg_function_clock[self as usize]) {
3503                        TimgFunctionClockConfig::XtalClk => request_xtal_clk(clocks),
3504                        TimgFunctionClockConfig::RcFastClk => request_rc_fast_clk(clocks),
3505                        TimgFunctionClockConfig::PllF80m => request_pll_f80m(clocks),
3506                    }
3507                    self.enable_function_clock_impl(clocks, true);
3508                }
3509            }
3510            pub fn release_function_clock(self, clocks: &mut ClockTree) {
3511                trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3512                if decrement_reference_count(
3513                    &mut clocks.timg_function_clock_refcount[self as usize],
3514                ) {
3515                    trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3516                    self.enable_function_clock_impl(clocks, false);
3517                    match unwrap!(clocks.timg_function_clock[self as usize]) {
3518                        TimgFunctionClockConfig::XtalClk => release_xtal_clk(clocks),
3519                        TimgFunctionClockConfig::RcFastClk => release_rc_fast_clk(clocks),
3520                        TimgFunctionClockConfig::PllF80m => release_pll_f80m(clocks),
3521                    }
3522                }
3523            }
3524            pub fn function_clock_config_frequency(config: TimgFunctionClockConfig) -> u32 {
3525                match config {
3526                    TimgFunctionClockConfig::XtalClk => xtal_clk_frequency(),
3527                    TimgFunctionClockConfig::RcFastClk => rc_fast_clk_frequency(),
3528                    TimgFunctionClockConfig::PllF80m => pll_f80m_frequency(),
3529                }
3530            }
3531            pub fn function_clock_frequency(self) -> u32 {
3532                TIMG_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
3533                    .load(::core::sync::atomic::Ordering::Acquire)
3534            }
3535            pub fn function_clock_source_frequency(source: TimgFunctionClockConfig) -> u32 {
3536                Self::function_clock_config_frequency(source)
3537            }
3538            pub fn configure_wdt_clock(
3539                self,
3540                clocks: &mut ClockTree,
3541                new_selector: TimgWdtClockConfig,
3542            ) {
3543                let old_selector = clocks.timg_wdt_clock[self as usize].replace(new_selector);
3544                refresh_timg_wdt_clock_downstream(clocks, self);
3545                let active = clocks.timg_wdt_clock_refcount[self as usize] > 0;
3546                if active {
3547                    match new_selector {
3548                        TimgWdtClockConfig::XtalClk => request_xtal_clk(clocks),
3549                        TimgWdtClockConfig::RcFastClk => request_rc_fast_clk(clocks),
3550                        TimgWdtClockConfig::PllF80m => request_pll_f80m(clocks),
3551                    }
3552                }
3553                self.configure_wdt_clock_impl(clocks, old_selector, new_selector);
3554                if active && let Some(old_selector) = old_selector {
3555                    match old_selector {
3556                        TimgWdtClockConfig::XtalClk => release_xtal_clk(clocks),
3557                        TimgWdtClockConfig::RcFastClk => release_rc_fast_clk(clocks),
3558                        TimgWdtClockConfig::PllF80m => release_pll_f80m(clocks),
3559                    }
3560                }
3561            }
3562            pub fn wdt_clock_config(self, clocks: &mut ClockTree) -> Option<TimgWdtClockConfig> {
3563                clocks.timg_wdt_clock[self as usize]
3564            }
3565            pub fn request_wdt_clock(self, clocks: &mut ClockTree) {
3566                trace!("Requesting {:?}::WDT_CLOCK", self);
3567                if increment_reference_count(&mut clocks.timg_wdt_clock_refcount[self as usize]) {
3568                    trace!("Enabling {:?}::WDT_CLOCK", self);
3569                    match unwrap!(clocks.timg_wdt_clock[self as usize]) {
3570                        TimgWdtClockConfig::XtalClk => request_xtal_clk(clocks),
3571                        TimgWdtClockConfig::RcFastClk => request_rc_fast_clk(clocks),
3572                        TimgWdtClockConfig::PllF80m => request_pll_f80m(clocks),
3573                    }
3574                    self.enable_wdt_clock_impl(clocks, true);
3575                }
3576            }
3577            pub fn release_wdt_clock(self, clocks: &mut ClockTree) {
3578                trace!("Releasing {:?}::WDT_CLOCK", self);
3579                if decrement_reference_count(&mut clocks.timg_wdt_clock_refcount[self as usize]) {
3580                    trace!("Disabling {:?}::WDT_CLOCK", self);
3581                    self.enable_wdt_clock_impl(clocks, false);
3582                    match unwrap!(clocks.timg_wdt_clock[self as usize]) {
3583                        TimgWdtClockConfig::XtalClk => release_xtal_clk(clocks),
3584                        TimgWdtClockConfig::RcFastClk => release_rc_fast_clk(clocks),
3585                        TimgWdtClockConfig::PllF80m => release_pll_f80m(clocks),
3586                    }
3587                }
3588            }
3589            pub fn wdt_clock_config_frequency(config: TimgWdtClockConfig) -> u32 {
3590                match config {
3591                    TimgWdtClockConfig::XtalClk => xtal_clk_frequency(),
3592                    TimgWdtClockConfig::RcFastClk => rc_fast_clk_frequency(),
3593                    TimgWdtClockConfig::PllF80m => pll_f80m_frequency(),
3594                }
3595            }
3596            pub fn wdt_clock_frequency(self) -> u32 {
3597                TIMG_WDT_CLOCK_FREQ_CACHE[self as usize]
3598                    .load(::core::sync::atomic::Ordering::Acquire)
3599            }
3600            pub fn wdt_clock_source_frequency(source: TimgWdtClockConfig) -> u32 {
3601                Self::wdt_clock_config_frequency(source)
3602            }
3603        }
3604        impl UartInstance {
3605            pub fn configure_function_clock(
3606                self,
3607                clocks: &mut ClockTree,
3608                config: UartFunctionClockConfig,
3609            ) {
3610                let old_config = clocks.uart_function_clock[self as usize].replace(config);
3611                refresh_uart_function_clock_downstream(clocks, self);
3612                let active = clocks.uart_function_clock_refcount[self as usize] > 0;
3613                if active {
3614                    match config.sclk {
3615                        UartFunctionClockSclk::Xtal => request_xtal_clk(clocks),
3616                        UartFunctionClockSclk::PllF80m => request_pll_f80m(clocks),
3617                        UartFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
3618                    }
3619                }
3620                self.configure_function_clock_impl(clocks, old_config, config);
3621                if active && let Some(old_config) = old_config {
3622                    match old_config.sclk {
3623                        UartFunctionClockSclk::Xtal => release_xtal_clk(clocks),
3624                        UartFunctionClockSclk::PllF80m => release_pll_f80m(clocks),
3625                        UartFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
3626                    }
3627                }
3628            }
3629            pub fn function_clock_config(
3630                self,
3631                clocks: &mut ClockTree,
3632            ) -> Option<UartFunctionClockConfig> {
3633                clocks.uart_function_clock[self as usize]
3634            }
3635            pub fn request_function_clock(self, clocks: &mut ClockTree) {
3636                trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3637                if increment_reference_count(
3638                    &mut clocks.uart_function_clock_refcount[self as usize],
3639                ) {
3640                    trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3641                    match unwrap!(clocks.uart_function_clock[self as usize]).sclk {
3642                        UartFunctionClockSclk::Xtal => request_xtal_clk(clocks),
3643                        UartFunctionClockSclk::PllF80m => request_pll_f80m(clocks),
3644                        UartFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
3645                    }
3646                    self.enable_function_clock_impl(clocks, true);
3647                }
3648            }
3649            pub fn release_function_clock(self, clocks: &mut ClockTree) {
3650                trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3651                if decrement_reference_count(
3652                    &mut clocks.uart_function_clock_refcount[self as usize],
3653                ) {
3654                    trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3655                    self.enable_function_clock_impl(clocks, false);
3656                    match unwrap!(clocks.uart_function_clock[self as usize]).sclk {
3657                        UartFunctionClockSclk::Xtal => release_xtal_clk(clocks),
3658                        UartFunctionClockSclk::PllF80m => release_pll_f80m(clocks),
3659                        UartFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
3660                    }
3661                }
3662            }
3663            pub fn function_clock_config_frequency(config: UartFunctionClockConfig) -> u32 {
3664                (match config.sclk {
3665                    UartFunctionClockSclk::Xtal => xtal_clk_frequency(),
3666                    UartFunctionClockSclk::PllF80m => pll_f80m_frequency(),
3667                    UartFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
3668                } / (config.div_num() + 1))
3669            }
3670            pub fn function_clock_frequency(self) -> u32 {
3671                UART_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
3672                    .load(::core::sync::atomic::Ordering::Acquire)
3673            }
3674            pub fn function_clock_source_frequency(sclk: UartFunctionClockSclk) -> u32 {
3675                match sclk {
3676                    UartFunctionClockSclk::Xtal => xtal_clk_frequency(),
3677                    UartFunctionClockSclk::PllF80m => pll_f80m_frequency(),
3678                    UartFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
3679                }
3680            }
3681            pub fn configure_baud_rate_generator(
3682                self,
3683                clocks: &mut ClockTree,
3684                config: UartBaudRateGeneratorConfig,
3685            ) {
3686                let old_config = clocks.uart_baud_rate_generator[self as usize].replace(config);
3687                refresh_uart_baud_rate_generator_downstream(clocks, self);
3688                self.configure_baud_rate_generator_impl(clocks, old_config, config);
3689            }
3690            pub fn baud_rate_generator_config(
3691                self,
3692                clocks: &mut ClockTree,
3693            ) -> Option<UartBaudRateGeneratorConfig> {
3694                clocks.uart_baud_rate_generator[self as usize]
3695            }
3696            pub fn request_baud_rate_generator(self, clocks: &mut ClockTree) {
3697                trace!("Requesting {:?}::BAUD_RATE_GENERATOR", self);
3698                if increment_reference_count(
3699                    &mut clocks.uart_baud_rate_generator_refcount[self as usize],
3700                ) {
3701                    trace!("Enabling {:?}::BAUD_RATE_GENERATOR", self);
3702                    self.request_function_clock(clocks);
3703                    self.enable_baud_rate_generator_impl(clocks, true);
3704                }
3705            }
3706            pub fn release_baud_rate_generator(self, clocks: &mut ClockTree) {
3707                trace!("Releasing {:?}::BAUD_RATE_GENERATOR", self);
3708                if decrement_reference_count(
3709                    &mut clocks.uart_baud_rate_generator_refcount[self as usize],
3710                ) {
3711                    trace!("Disabling {:?}::BAUD_RATE_GENERATOR", self);
3712                    self.enable_baud_rate_generator_impl(clocks, false);
3713                    self.release_function_clock(clocks);
3714                }
3715            }
3716            pub fn baud_rate_generator_config_frequency(
3717                self,
3718                config: UartBaudRateGeneratorConfig,
3719            ) -> u32 {
3720                ((self.function_clock_frequency() * 16)
3721                    / ((config.integral() * 16) + config.fractional()))
3722            }
3723            pub fn baud_rate_generator_frequency(self) -> u32 {
3724                UART_BAUD_RATE_GENERATOR_FREQ_CACHE[self as usize]
3725                    .load(::core::sync::atomic::Ordering::Acquire)
3726            }
3727        }
3728        /// Clock tree configuration.
3729        ///
3730        /// The fields of this struct are optional, with the following caveats:
3731        /// - If `XTAL_CLK` is not specified, the crystal frequency will be automatically detected
3732        ///   if possible.
3733        /// - The CPU and its upstream clock nodes will be set to a default configuration.
3734        /// - Other unspecified clock sources will not be useable by peripherals.
3735        #[derive(Debug, Clone, Copy, PartialEq, Eq)]
3736        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
3737        #[instability::unstable]
3738        pub struct ClockConfig {
3739            /// `XTAL_CLK` configuration.
3740            pub xtal_clk: Option<XtalClkConfig>,
3741            /// `HP_ROOT_CLK` configuration.
3742            pub hp_root_clk: Option<HpRootClkConfig>,
3743            /// `CPU_CLK` configuration.
3744            pub cpu_clk: Option<CpuClkConfig>,
3745            /// `AHB_CLK` configuration.
3746            pub ahb_clk: Option<AhbClkConfig>,
3747            /// `APB_CLK` configuration.
3748            pub apb_clk: Option<ApbClkConfig>,
3749            /// `LP_FAST_CLK` configuration.
3750            pub lp_fast_clk: Option<LpFastClkConfig>,
3751            /// `LP_SLOW_CLK` configuration.
3752            pub lp_slow_clk: Option<LpSlowClkConfig>,
3753            /// `BLE_LP_CLK` configuration.
3754            pub ble_lp_clk: Option<BleLpClkConfig>,
3755            /// `CRYPTO_CLK` configuration.
3756            pub crypto_clk: Option<CryptoClkConfig>,
3757            /// `TIMG_CALIBRATION_CLOCK` configuration.
3758            pub timg_calibration_clock: Option<TimgCalibrationClockConfig>,
3759        }
3760        impl ClockConfig {
3761            fn apply(&self, clocks: &mut ClockTree) {
3762                if let Some(config) = self.xtal_clk {
3763                    configure_xtal_clk(clocks, config);
3764                }
3765                if let Some(config) = self.hp_root_clk {
3766                    configure_hp_root_clk(clocks, config);
3767                }
3768                if let Some(config) = self.cpu_clk {
3769                    configure_cpu_clk(clocks, config);
3770                }
3771                if let Some(config) = self.ahb_clk {
3772                    configure_ahb_clk(clocks, config);
3773                }
3774                if let Some(config) = self.apb_clk {
3775                    configure_apb_clk(clocks, config);
3776                }
3777                if let Some(config) = self.lp_fast_clk {
3778                    configure_lp_fast_clk(clocks, config);
3779                }
3780                if let Some(config) = self.lp_slow_clk {
3781                    configure_lp_slow_clk(clocks, config);
3782                }
3783                if let Some(config) = self.ble_lp_clk {
3784                    configure_ble_lp_clk(clocks, config);
3785                }
3786                if let Some(config) = self.crypto_clk {
3787                    configure_crypto_clk(clocks, config);
3788                }
3789                if let Some(config) = self.timg_calibration_clock {
3790                    configure_timg_calibration_clock(clocks, config);
3791                }
3792            }
3793        }
3794        fn increment_reference_count(refcount: &mut u32) -> bool {
3795            let first = *refcount == 0;
3796            *refcount = unwrap!(refcount.checked_add(1), "Reference count overflow");
3797            first
3798        }
3799        fn decrement_reference_count(refcount: &mut u32) -> bool {
3800            *refcount = refcount.saturating_sub(1);
3801            let last = *refcount == 0;
3802            last
3803        }
3804        fn refresh_xtal_clk_downstream(clocks: &mut ClockTree) {
3805            if let Some(config) = clocks.xtal_clk {
3806                XTAL_CLK_FREQ_CACHE.store(
3807                    xtal_clk_config_frequency(config),
3808                    ::core::sync::atomic::Ordering::Release,
3809                );
3810            }
3811            refresh_hp_root_clk_downstream(clocks);
3812            refresh_lp_fast_clk_downstream(clocks);
3813            refresh_ble_lp_clk_downstream(clocks);
3814            refresh_crypto_clk_downstream(clocks);
3815            for child_instance in [AdcInstance::ApbSaradc] {
3816                refresh_adc_function_clock_downstream(clocks, child_instance);
3817            }
3818            for child_instance in [I2cInstance::I2c0] {
3819                refresh_i2c_function_clock_downstream(clocks, child_instance);
3820            }
3821            for child_instance in [I2sInstance::I2s0] {
3822                refresh_i2s_tx_clk_downstream(clocks, child_instance);
3823                refresh_i2s_rx_clk_downstream(clocks, child_instance);
3824            }
3825            for child_instance in [SpiInstance::Spi2] {
3826                refresh_spi_function_clock_downstream(clocks, child_instance);
3827            }
3828            for child_instance in [TimgInstance::Timg0, TimgInstance::Timg1] {
3829                refresh_timg_function_clock_downstream(clocks, child_instance);
3830                refresh_timg_wdt_clock_downstream(clocks, child_instance);
3831            }
3832            for child_instance in [
3833                UartInstance::Uart0,
3834                UartInstance::Uart1,
3835                UartInstance::Uart2,
3836            ] {
3837                refresh_uart_function_clock_downstream(clocks, child_instance);
3838            }
3839        }
3840        fn refresh_rc_fast_clk_downstream(clocks: &mut ClockTree) {
3841            refresh_hp_root_clk_downstream(clocks);
3842            refresh_lp_fast_clk_downstream(clocks);
3843            refresh_crypto_clk_downstream(clocks);
3844            refresh_timg_calibration_clock_downstream(clocks);
3845            for child_instance in [AdcInstance::ApbSaradc] {
3846                refresh_adc_function_clock_downstream(clocks, child_instance);
3847            }
3848            for child_instance in [I2cInstance::I2c0] {
3849                refresh_i2c_function_clock_downstream(clocks, child_instance);
3850            }
3851            for child_instance in [SpiInstance::Spi2] {
3852                refresh_spi_function_clock_downstream(clocks, child_instance);
3853            }
3854            for child_instance in [TimgInstance::Timg0, TimgInstance::Timg1] {
3855                refresh_timg_function_clock_downstream(clocks, child_instance);
3856                refresh_timg_wdt_clock_downstream(clocks, child_instance);
3857            }
3858            for child_instance in [
3859                UartInstance::Uart0,
3860                UartInstance::Uart1,
3861                UartInstance::Uart2,
3862            ] {
3863                refresh_uart_function_clock_downstream(clocks, child_instance);
3864            }
3865        }
3866        fn refresh_rc_slow_clk_downstream(clocks: &mut ClockTree) {
3867            refresh_lp_slow_clk_downstream(clocks);
3868            refresh_ble_lp_clk_downstream(clocks);
3869            refresh_timg_calibration_clock_downstream(clocks);
3870        }
3871        fn refresh_hp_root_clk_downstream(clocks: &mut ClockTree) {
3872            if let Some(config) = clocks.hp_root_clk {
3873                HP_ROOT_CLK_FREQ_CACHE.store(
3874                    hp_root_clk_config_frequency(config),
3875                    ::core::sync::atomic::Ordering::Release,
3876                );
3877            }
3878            refresh_cpu_clk_downstream(clocks);
3879            refresh_ahb_clk_downstream(clocks);
3880        }
3881        fn refresh_cpu_clk_downstream(clocks: &mut ClockTree) {
3882            if let Some(config) = clocks.cpu_clk {
3883                CPU_CLK_FREQ_CACHE.store(
3884                    cpu_clk_config_frequency(config),
3885                    ::core::sync::atomic::Ordering::Release,
3886                );
3887            }
3888        }
3889        fn refresh_ahb_clk_downstream(clocks: &mut ClockTree) {
3890            if let Some(config) = clocks.ahb_clk {
3891                AHB_CLK_FREQ_CACHE.store(
3892                    ahb_clk_config_frequency(config),
3893                    ::core::sync::atomic::Ordering::Release,
3894                );
3895            }
3896            refresh_apb_clk_downstream(clocks);
3897        }
3898        fn refresh_apb_clk_downstream(clocks: &mut ClockTree) {
3899            if let Some(config) = clocks.apb_clk {
3900                APB_CLK_FREQ_CACHE.store(
3901                    apb_clk_config_frequency(config),
3902                    ::core::sync::atomic::Ordering::Release,
3903                );
3904            }
3905        }
3906        fn refresh_lp_fast_clk_downstream(clocks: &mut ClockTree) {
3907            if let Some(config) = clocks.lp_fast_clk {
3908                LP_FAST_CLK_FREQ_CACHE.store(
3909                    lp_fast_clk_config_frequency(config),
3910                    ::core::sync::atomic::Ordering::Release,
3911                );
3912            }
3913        }
3914        fn refresh_lp_slow_clk_downstream(clocks: &mut ClockTree) {
3915            if let Some(config) = clocks.lp_slow_clk {
3916                LP_SLOW_CLK_FREQ_CACHE.store(
3917                    lp_slow_clk_config_frequency(config),
3918                    ::core::sync::atomic::Ordering::Release,
3919                );
3920            }
3921        }
3922        fn refresh_ble_lp_clk_downstream(clocks: &mut ClockTree) {
3923            if let Some(config) = clocks.ble_lp_clk {
3924                BLE_LP_CLK_FREQ_CACHE.store(
3925                    ble_lp_clk_config_frequency(config),
3926                    ::core::sync::atomic::Ordering::Release,
3927                );
3928            }
3929        }
3930        fn refresh_crypto_clk_downstream(clocks: &mut ClockTree) {
3931            if let Some(config) = clocks.crypto_clk {
3932                CRYPTO_CLK_FREQ_CACHE.store(
3933                    crypto_clk_config_frequency(config),
3934                    ::core::sync::atomic::Ordering::Release,
3935                );
3936            }
3937        }
3938        fn refresh_timg_calibration_clock_downstream(clocks: &mut ClockTree) {
3939            if let Some(config) = clocks.timg_calibration_clock {
3940                TIMG_CALIBRATION_CLOCK_FREQ_CACHE.store(
3941                    timg_calibration_clock_config_frequency(config),
3942                    ::core::sync::atomic::Ordering::Release,
3943                );
3944            }
3945        }
3946        fn refresh_adc_function_clock_downstream(clocks: &mut ClockTree, instance: AdcInstance) {
3947            if let Some(config) = clocks.adc_function_clock[instance as usize] {
3948                ADC_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
3949                    AdcInstance::function_clock_config_frequency(config),
3950                    ::core::sync::atomic::Ordering::Release,
3951                );
3952            }
3953        }
3954        fn refresh_i2c_function_clock_downstream(clocks: &mut ClockTree, instance: I2cInstance) {
3955            if let Some(config) = clocks.i2c_function_clock[instance as usize] {
3956                I2C_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
3957                    I2cInstance::function_clock_config_frequency(config),
3958                    ::core::sync::atomic::Ordering::Release,
3959                );
3960            }
3961        }
3962        fn refresh_i2s_tx_clk_downstream(clocks: &mut ClockTree, instance: I2sInstance) {
3963            if let Some(config) = clocks.i2s_tx_clk[instance as usize] {
3964                I2S_TX_CLK_FREQ_CACHE[instance as usize].store(
3965                    I2sInstance::tx_clk_config_frequency(config),
3966                    ::core::sync::atomic::Ordering::Release,
3967                );
3968            }
3969            refresh_i2s_mclk_out_downstream(clocks, instance);
3970        }
3971        fn refresh_i2s_rx_clk_downstream(clocks: &mut ClockTree, instance: I2sInstance) {
3972            if let Some(config) = clocks.i2s_rx_clk[instance as usize] {
3973                I2S_RX_CLK_FREQ_CACHE[instance as usize].store(
3974                    I2sInstance::rx_clk_config_frequency(config),
3975                    ::core::sync::atomic::Ordering::Release,
3976                );
3977            }
3978            refresh_i2s_mclk_out_downstream(clocks, instance);
3979        }
3980        fn refresh_i2s_mclk_out_downstream(clocks: &mut ClockTree, instance: I2sInstance) {
3981            if let Some(config) = clocks.i2s_mclk_out[instance as usize] {
3982                I2S_MCLK_OUT_FREQ_CACHE[instance as usize].store(
3983                    instance.mclk_out_config_frequency(config),
3984                    ::core::sync::atomic::Ordering::Release,
3985                );
3986            }
3987        }
3988        fn refresh_spi_function_clock_downstream(clocks: &mut ClockTree, instance: SpiInstance) {
3989            if let Some(config) = clocks.spi_function_clock[instance as usize] {
3990                SPI_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
3991                    SpiInstance::function_clock_config_frequency(config),
3992                    ::core::sync::atomic::Ordering::Release,
3993                );
3994            }
3995        }
3996        fn refresh_timg_function_clock_downstream(clocks: &mut ClockTree, instance: TimgInstance) {
3997            if let Some(config) = clocks.timg_function_clock[instance as usize] {
3998                TIMG_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
3999                    TimgInstance::function_clock_config_frequency(config),
4000                    ::core::sync::atomic::Ordering::Release,
4001                );
4002            }
4003        }
4004        fn refresh_timg_wdt_clock_downstream(clocks: &mut ClockTree, instance: TimgInstance) {
4005            if let Some(config) = clocks.timg_wdt_clock[instance as usize] {
4006                TIMG_WDT_CLOCK_FREQ_CACHE[instance as usize].store(
4007                    TimgInstance::wdt_clock_config_frequency(config),
4008                    ::core::sync::atomic::Ordering::Release,
4009                );
4010            }
4011        }
4012        fn refresh_uart_function_clock_downstream(clocks: &mut ClockTree, instance: UartInstance) {
4013            if let Some(config) = clocks.uart_function_clock[instance as usize] {
4014                UART_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
4015                    UartInstance::function_clock_config_frequency(config),
4016                    ::core::sync::atomic::Ordering::Release,
4017                );
4018            }
4019            refresh_uart_baud_rate_generator_downstream(clocks, instance);
4020        }
4021        fn refresh_uart_baud_rate_generator_downstream(
4022            clocks: &mut ClockTree,
4023            instance: UartInstance,
4024        ) {
4025            if let Some(config) = clocks.uart_baud_rate_generator[instance as usize] {
4026                UART_BAUD_RATE_GENERATOR_FREQ_CACHE[instance as usize].store(
4027                    instance.baud_rate_generator_config_frequency(config),
4028                    ::core::sync::atomic::Ordering::Release,
4029                );
4030            }
4031        }
4032    };
4033}
4034/// Implement the `Peripheral` enum and enable/disable/reset functions.
4035///
4036/// This macro is intended to be placed in `esp_hal::system`.
4037#[macro_export]
4038#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4039macro_rules! implement_peripheral_clocks {
4040    () => {
4041        #[doc(hidden)]
4042        #[derive(Debug, Clone, Copy, PartialEq, Eq)]
4043        #[repr(u8)]
4044        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
4045        pub enum Peripheral {
4046            /// AHB_GDMA peripheral clock signal
4047            AhbGdma,
4048            /// APB_SAR_ADC peripheral clock signal
4049            ApbSarAdc,
4050            /// ECC peripheral clock signal
4051            Ecc,
4052            /// I2C_EXT0 peripheral clock signal
4053            I2cExt0,
4054            /// I2S0 peripheral clock signal
4055            I2s0,
4056            /// SHA peripheral clock signal
4057            Sha,
4058            /// SPI2 peripheral clock signal
4059            Spi2,
4060            /// SYSTIMER peripheral clock signal
4061            Systimer,
4062            /// TIMG0 peripheral clock signal
4063            Timg0,
4064            /// TIMG1 peripheral clock signal
4065            Timg1,
4066            /// UART0 peripheral clock signal
4067            Uart0,
4068            /// UART1 peripheral clock signal
4069            Uart1,
4070            /// UART2 peripheral clock signal
4071            Uart2,
4072            /// USB_DEVICE peripheral clock signal
4073            UsbDevice,
4074        }
4075        impl Peripheral {
4076            const KEEP_ENABLED: &[Peripheral] =
4077                &[Self::Systimer, Self::Timg0, Self::Uart0, Self::UsbDevice];
4078            const COUNT: usize = Self::ALL.len();
4079            const ALL: &[Self] = &[
4080                Self::AhbGdma,
4081                Self::ApbSarAdc,
4082                Self::Ecc,
4083                Self::I2cExt0,
4084                Self::I2s0,
4085                Self::Sha,
4086                Self::Spi2,
4087                Self::Systimer,
4088                Self::Timg0,
4089                Self::Timg1,
4090                Self::Uart0,
4091                Self::Uart1,
4092                Self::Uart2,
4093                Self::UsbDevice,
4094            ];
4095        }
4096        unsafe fn enable_internal_racey(peripheral: Peripheral, enable: bool) {
4097            match peripheral {
4098                Peripheral::AhbGdma => {
4099                    crate::peripherals::SYSTEM::regs()
4100                        .gdma_conf()
4101                        .modify(|_, w| w.gdma_clk_en().bit(enable));
4102                }
4103                Peripheral::ApbSarAdc => {
4104                    crate::peripherals::SYSTEM::regs()
4105                        .saradc_conf()
4106                        .modify(|_, w| w.saradc_reg_clk_en().bit(enable));
4107                }
4108                Peripheral::Ecc => {
4109                    crate::peripherals::SYSTEM::regs()
4110                        .ecc_conf()
4111                        .modify(|_, w| w.ecc_clk_en().bit(enable));
4112                }
4113                Peripheral::I2cExt0 => {
4114                    crate::peripherals::SYSTEM::regs()
4115                        .i2c0_conf()
4116                        .modify(|_, w| w.i2c0_clk_en().bit(enable));
4117                }
4118                Peripheral::I2s0 => {
4119                    crate::peripherals::SYSTEM::regs()
4120                        .i2s_conf()
4121                        .modify(|_, w| w.i2s_clk_en().bit(enable));
4122                }
4123                Peripheral::Sha => {
4124                    crate::peripherals::SYSTEM::regs()
4125                        .sha_conf()
4126                        .modify(|_, w| w.sha_clk_en().bit(enable));
4127                }
4128                Peripheral::Spi2 => {
4129                    crate::peripherals::SYSTEM::regs()
4130                        .spi2_conf()
4131                        .modify(|_, w| w.spi2_clk_en().bit(enable));
4132                }
4133                Peripheral::Systimer => {
4134                    crate::peripherals::SYSTEM::regs()
4135                        .systimer_conf()
4136                        .modify(|_, w| w.systimer_clk_en().bit(enable));
4137                }
4138                Peripheral::Timg0 => {
4139                    crate::peripherals::SYSTEM::regs()
4140                        .timergroup(0)
4141                        .conf()
4142                        .modify(|_, w| w.clk_en().bit(enable));
4143                }
4144                Peripheral::Timg1 => {
4145                    crate::peripherals::SYSTEM::regs()
4146                        .timergroup(1)
4147                        .conf()
4148                        .modify(|_, w| w.clk_en().bit(enable));
4149                }
4150                Peripheral::Uart0 => {
4151                    crate::peripherals::SYSTEM::regs()
4152                        .uart(0)
4153                        .conf()
4154                        .modify(|_, w| w.clk_en().bit(enable));
4155                }
4156                Peripheral::Uart1 => {
4157                    crate::peripherals::SYSTEM::regs()
4158                        .uart(1)
4159                        .conf()
4160                        .modify(|_, w| w.clk_en().bit(enable));
4161                }
4162                Peripheral::Uart2 => {
4163                    crate::peripherals::SYSTEM::regs()
4164                        .uart(2)
4165                        .conf()
4166                        .modify(|_, w| w.clk_en().bit(enable));
4167                }
4168                Peripheral::UsbDevice => {
4169                    crate::peripherals::SYSTEM::regs()
4170                        .usb_device_conf()
4171                        .modify(|_, w| w.usb_device_clk_en().bit(enable));
4172                }
4173            }
4174        }
4175        unsafe fn assert_peri_reset_racey(peripheral: Peripheral, reset: bool) {
4176            match peripheral {
4177                Peripheral::AhbGdma => {
4178                    crate::peripherals::SYSTEM::regs()
4179                        .gdma_conf()
4180                        .modify(|_, w| w.gdma_rst_en().bit(reset));
4181                }
4182                Peripheral::ApbSarAdc => {
4183                    crate::peripherals::SYSTEM::regs()
4184                        .saradc_conf()
4185                        .modify(|_, w| w.saradc_reg_rst_en().bit(reset));
4186                }
4187                Peripheral::Ecc => {
4188                    crate::peripherals::SYSTEM::regs()
4189                        .ecc_conf()
4190                        .modify(|_, w| w.ecc_rst_en().bit(reset));
4191                }
4192                Peripheral::I2cExt0 => {
4193                    crate::peripherals::SYSTEM::regs()
4194                        .i2c0_conf()
4195                        .modify(|_, w| w.i2c0_rst_en().bit(reset));
4196                }
4197                Peripheral::I2s0 => {
4198                    crate::peripherals::SYSTEM::regs()
4199                        .i2s_conf()
4200                        .modify(|_, w| w.i2s_rst_en().bit(reset));
4201                }
4202                Peripheral::Sha => {
4203                    crate::peripherals::SYSTEM::regs()
4204                        .sha_conf()
4205                        .modify(|_, w| w.sha_rst_en().bit(reset));
4206                }
4207                Peripheral::Spi2 => {
4208                    crate::peripherals::SYSTEM::regs()
4209                        .spi2_conf()
4210                        .modify(|_, w| w.spi2_rst_en().bit(reset));
4211                }
4212                Peripheral::Systimer => {
4213                    crate::peripherals::SYSTEM::regs()
4214                        .systimer_conf()
4215                        .modify(|_, w| w.systimer_rst_en().bit(reset));
4216                }
4217                Peripheral::Timg0 => {
4218                    crate::peripherals::SYSTEM::regs()
4219                        .timergroup(0)
4220                        .conf()
4221                        .modify(|_, w| w.rst_en().bit(reset));
4222                }
4223                Peripheral::Timg1 => {
4224                    crate::peripherals::SYSTEM::regs()
4225                        .timergroup(1)
4226                        .conf()
4227                        .modify(|_, w| w.rst_en().bit(reset));
4228                }
4229                Peripheral::Uart0 => {
4230                    crate::peripherals::SYSTEM::regs()
4231                        .uart(0)
4232                        .conf()
4233                        .modify(|_, w| w.rst_en().bit(reset));
4234                }
4235                Peripheral::Uart1 => {
4236                    crate::peripherals::SYSTEM::regs()
4237                        .uart(1)
4238                        .conf()
4239                        .modify(|_, w| w.rst_en().bit(reset));
4240                }
4241                Peripheral::Uart2 => {
4242                    crate::peripherals::SYSTEM::regs()
4243                        .uart(2)
4244                        .conf()
4245                        .modify(|_, w| w.rst_en().bit(reset));
4246                }
4247                Peripheral::UsbDevice => {
4248                    crate::peripherals::SYSTEM::regs()
4249                        .usb_device_conf()
4250                        .modify(|_, w| w.usb_device_rst_en().bit(reset));
4251                }
4252            }
4253        }
4254    };
4255}
4256/// Macro to get the address range of the given memory region.
4257///
4258/// This macro provides two syntax options for each memory region:
4259///
4260/// - `memory_range!("region_name")` returns the address range as a range expression (`start..end`).
4261/// - `memory_range!(size as str, "region_name")` returns the size of the region as a string
4262///   literal.
4263#[macro_export]
4264#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4265macro_rules! memory_range {
4266    ("DRAM") => {
4267        0x40800000..0x40850000
4268    };
4269    (size as str, "DRAM") => {
4270        "327680"
4271    };
4272    ("DRAM2_UNINIT") => {
4273        0x4083E670..0x4084E670
4274    };
4275    (size as str, "DRAM2_UNINIT") => {
4276        "65536"
4277    };
4278    ("IROM") => {
4279        0x42000000..0x44000000
4280    };
4281    (size as str, "IROM") => {
4282        "33554432"
4283    };
4284    ("DROM") => {
4285        0x42000000..0x44000000
4286    };
4287    (size as str, "DROM") => {
4288        "33554432"
4289    };
4290}
4291/// This macro can be used to generate code for each peripheral instance of the I2C master driver.
4292///
4293/// For an explanation on the general syntax, as well as usage of individual/repeated
4294/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
4295///
4296/// This macro has one option for its "Individual matcher" case:
4297///
4298/// Syntax: `($id:literal, $instance:ident, $sys:ident, $scl:ident, $sda:ident)`
4299///
4300/// Macro fragments:
4301/// - `$id`: the index of the I2C instance
4302/// - `$instance`: the name of the I2C instance
4303/// - `$sys`: the name of the instance as it is in the `esp_hal::system::Peripheral` enum.
4304/// - `$scl`, `$sda`: peripheral signal names.
4305///
4306/// Example data: `(0, I2C0, I2cExt0, I2CEXT0_SCL, I2CEXT0_SDA)`
4307#[macro_export]
4308#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4309macro_rules! for_each_i2c_master {
4310    ($($pattern:tt => $code:tt;)*) => {
4311        macro_rules! _for_each_inner_i2c_master { $(($pattern) => $code;)* ($other : tt)
4312        => {} } _for_each_inner_i2c_master!((0, I2C0, I2cExt0, I2CEXT0_SCL,
4313        I2CEXT0_SDA)); _for_each_inner_i2c_master!((all(0, I2C0, I2cExt0, I2CEXT0_SCL,
4314        I2CEXT0_SDA)));
4315    };
4316}
4317/// This macro can be used to generate code for each peripheral instance of the I2S driver.
4318///
4319/// For an explanation on the general syntax, as well as usage of individual/repeated
4320/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
4321///
4322/// This macro has one option for its "Individual matcher" case:
4323///
4324/// Syntax: `($instance:ident, $sys:ident, $mclk:ident, $bclk:ident, $ws:ident, $bclk_rx:ident,
4325/// $ws_rx:ident, [$($dout:ident),*], [$($din:ident),*], $pdm_tx:literal, $pdm_rx:literal,
4326/// $pcm2pdm:literal, $pdm2pcm:literal)`
4327///
4328/// Macro fragments:
4329///
4330/// - `$instance`: the name of the I2S instance
4331/// - `$sys`: the name of the instance as it is in the `esp_hal::system::Peripheral` enum.
4332/// - `$mclk`: the MCLK output signal (a placeholder on chips without a GPIO-matrix MCLK).
4333/// - `$bclk`, `$ws`: TX bit clock and word select output signals.
4334/// - `$bclk_rx`, `$ws_rx`: RX bit clock and word select output signals.
4335/// - `$dout`, `$din`: data-out and data-in signal names.
4336/// - `$pdm_tx`, `$pdm_rx`: whether the instance supports PDM TX/RX.
4337/// - `$pcm2pdm`, `$pdm2pcm`: whether the instance supports the hardware PCM<->PDM format conversion
4338///   filter on TX/RX.
4339///
4340/// Example data:
4341/// - `(I2S0, I2s0, I2S_MCLK, I2SO_BCK, I2SO_WS, I2SI_BCK, I2SI_WS, [I2SO_SD], [I2SI_SD], true,
4342///   true, true, true)`
4343#[macro_export]
4344#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4345macro_rules! for_each_i2s {
4346    ($($pattern:tt => $code:tt;)*) => {
4347        macro_rules! _for_each_inner_i2s { $(($pattern) => $code;)* ($other : tt) => {} }
4348        _for_each_inner_i2s!((I2S0)); _for_each_inner_i2s!((I2S0, I2s0, I2S_MCLK,
4349        I2SO_BCK, I2SO_WS, I2SI_BCK, I2SI_WS, [I2SO_SD], [I2SI_SD], true, true, true,
4350        false)); _for_each_inner_i2s!((names(I2S0))); _for_each_inner_i2s!((all(I2S0,
4351        I2s0, I2S_MCLK, I2SO_BCK, I2SO_WS, I2SI_BCK, I2SI_WS, [I2SO_SD], [I2SI_SD], true,
4352        true, true, false)));
4353    };
4354}
4355/// This macro can be used to generate code for each peripheral instance of the UART driver.
4356///
4357/// For an explanation on the general syntax, as well as usage of individual/repeated
4358/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
4359///
4360/// This macro has one option for its "Individual matcher" case:
4361///
4362/// Syntax: `($id:literal, $instance:ident, $sys:ident, $rx:ident, $tx:ident, $cts:ident,
4363/// $rts:ident)`
4364///
4365/// Macro fragments:
4366///
4367/// - `$id`: the index of the UART instance
4368/// - `$instance`: the name of the UART instance
4369/// - `$sys`: the name of the instance as it is in the `esp_hal::system::Peripheral` enum.
4370/// - `$rx`, `$tx`, `$cts`, `$rts`: signal names.
4371///
4372/// Example data: `(0, UART0, Uart0, U0RXD, U0TXD, U0CTS, U0RTS)`
4373#[macro_export]
4374#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4375macro_rules! for_each_uart {
4376    ($($pattern:tt => $code:tt;)*) => {
4377        macro_rules! _for_each_inner_uart { $(($pattern) => $code;)* ($other : tt) => {}
4378        } _for_each_inner_uart!((0, UART0, Uart0, U0RXD, U0TXD, U0CTS, U0RTS,
4379        wakeup_source = true)); _for_each_inner_uart!((1, UART1, Uart1, U1RXD, U1TXD,
4380        U1CTS, U1RTS, wakeup_source = true)); _for_each_inner_uart!((2, UART2, Uart2,
4381        U2RXD, U2TXD, U2CTS, U2RTS, wakeup_source = true)); _for_each_inner_uart!((all(0,
4382        UART0, Uart0, U0RXD, U0TXD, U0CTS, U0RTS, wakeup_source = true), (1, UART1,
4383        Uart1, U1RXD, U1TXD, U1CTS, U1RTS, wakeup_source = true), (2, UART2, Uart2,
4384        U2RXD, U2TXD, U2CTS, U2RTS, wakeup_source = true)));
4385    };
4386}
4387/// This macro can be used to generate code for each peripheral instance of the SPI master driver.
4388///
4389/// For an explanation on the general syntax, as well as usage of individual/repeated
4390/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
4391///
4392/// This macro has one option for its "Individual matcher" case:
4393///
4394/// Syntax: `($instance:ident, $sys:ident, $sclk:ident [$($cs:ident),*] [$($sio:ident),*]
4395/// $($is_qspi:literal)?)`
4396///
4397/// Macro fragments:
4398///
4399/// - `$instance`: the name of the SPI instance
4400/// - `$sys`: the name of the instance as it is in the `esp_hal::system::Peripheral` enum.
4401/// - `$cs`, `$sio`: chip select and SIO signal names.
4402/// - `$is_qspi`: a `true` literal present if the SPI instance supports QSPI.
4403///
4404/// Example data:
4405/// - `(SPI2, Spi2, FSPICLK [FSPICS0, FSPICS1, FSPICS2, FSPICS3, FSPICS4, FSPICS5] [FSPID, FSPIQ,
4406///   FSPIWP, FSPIHD, FSPIIO4, FSPIIO5, FSPIIO6, FSPIIO7], true)`
4407/// - `(SPI3, Spi3, SPI3_CLK [SPI3_CS0, SPI3_CS1, SPI3_CS2] [SPI3_D, SPI3_Q])`
4408#[macro_export]
4409#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4410macro_rules! for_each_spi_master {
4411    ($($pattern:tt => $code:tt;)*) => {
4412        macro_rules! _for_each_inner_spi_master { $(($pattern) => $code;)* ($other : tt)
4413        => {} } _for_each_inner_spi_master!((SPI2)); _for_each_inner_spi_master!((SPI2,
4414        Spi2, FSPICLK[FSPICS0, FSPICS1, FSPICS2, FSPICS3, FSPICS4, FSPICS5] [FSPID,
4415        FSPIQ, FSPIWP, FSPIHD], true)); _for_each_inner_spi_master!((names(SPI2)));
4416        _for_each_inner_spi_master!((all(SPI2, Spi2, FSPICLK[FSPICS0, FSPICS1, FSPICS2,
4417        FSPICS3, FSPICS4, FSPICS5] [FSPID, FSPIQ, FSPIWP, FSPIHD], true)));
4418    };
4419}
4420/// This macro can be used to generate code for each peripheral instance of the SPI slave driver.
4421///
4422/// For an explanation on the general syntax, as well as usage of individual/repeated
4423/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
4424///
4425/// This macro has one option for its "Individual matcher" case:
4426///
4427/// Syntax: `($instance:ident, $sys:ident, $sclk:ident, $mosi:ident, $miso:ident, $cs:ident)`
4428///
4429/// Macro fragments:
4430///
4431/// - `$instance`: the name of the SPI instance
4432/// - `$sys`: the name of the instance as it is in the `esp_hal::system::Peripheral` enum.
4433/// - `$sclk`, `$mosi`, `$miso`, `$cs`: signal names.
4434///
4435/// Example data: `(SPI2, Spi2, FSPICLK, FSPID, FSPIQ, FSPICS0)`
4436#[macro_export]
4437#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4438macro_rules! for_each_spi_slave {
4439    ($($pattern:tt => $code:tt;)*) => {
4440        macro_rules! _for_each_inner_spi_slave { $(($pattern) => $code;)* ($other : tt)
4441        => {} } _for_each_inner_spi_slave!((SPI2)); _for_each_inner_spi_slave!((SPI2,
4442        Spi2, FSPICLK, FSPID, FSPIQ, FSPICS0));
4443        _for_each_inner_spi_slave!((names(SPI2))); _for_each_inner_spi_slave!((all(SPI2,
4444        Spi2, FSPICLK, FSPID, FSPIQ, FSPICS0)));
4445    };
4446}
4447#[macro_export]
4448#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4449macro_rules! for_each_peripheral {
4450    ($($pattern:tt => $code:tt;)*) => {
4451        macro_rules! _for_each_inner_peripheral { $(($pattern) => $code;)* ($other : tt)
4452        => {} } _for_each_inner_peripheral!((@ peri_type #[doc =
4453        "GPIO0 peripheral singleton"] GPIO0 <= virtual()));
4454        _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO1 peripheral singleton"]
4455        GPIO1 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
4456        "GPIO2 peripheral singleton"] GPIO2 <= virtual()));
4457        _for_each_inner_peripheral!((@ peri_type #[doc =
4458        "GPIO3 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4459        "<section class=\"warning\">"] #[doc =
4460        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4461        #[doc = "<ul>"] #[doc =
4462        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
4463        =
4464        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4465        #[doc = "</ul>"] #[doc = "</section>"] GPIO3 <= virtual()));
4466        _for_each_inner_peripheral!((@ peri_type #[doc =
4467        "GPIO4 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4468        "<section class=\"warning\">"] #[doc =
4469        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4470        #[doc = "<ul>"] #[doc =
4471        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
4472        =
4473        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4474        #[doc = "</ul>"] #[doc = "</section>"] GPIO4 <= virtual()));
4475        _for_each_inner_peripheral!((@ peri_type #[doc =
4476        "GPIO5 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4477        "<section class=\"warning\">"] #[doc =
4478        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4479        #[doc = "<ul>"] #[doc =
4480        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4481        #[doc = "</ul>"] #[doc = "</section>"] GPIO5 <= virtual()));
4482        _for_each_inner_peripheral!((@ peri_type #[doc =
4483        "GPIO6 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4484        "<section class=\"warning\">"] #[doc =
4485        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4486        #[doc = "<ul>"] #[doc =
4487        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4488        #[doc = "</ul>"] #[doc = "</section>"] GPIO6 <= virtual()));
4489        _for_each_inner_peripheral!((@ peri_type #[doc =
4490        "GPIO7 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4491        "<section class=\"warning\">"] #[doc =
4492        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4493        #[doc = "<ul>"] #[doc =
4494        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
4495        = "</ul>"] #[doc = "</section>"] GPIO7 <= virtual()));
4496        _for_each_inner_peripheral!((@ peri_type #[doc =
4497        "GPIO8 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4498        "<section class=\"warning\">"] #[doc =
4499        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4500        #[doc = "<ul>"] #[doc =
4501        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
4502        = "</ul>"] #[doc = "</section>"] GPIO8 <= virtual()));
4503        _for_each_inner_peripheral!((@ peri_type #[doc =
4504        "GPIO9 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4505        "<section class=\"warning\">"] #[doc =
4506        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4507        #[doc = "<ul>"] #[doc =
4508        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
4509        = "</ul>"] #[doc = "</section>"] GPIO9 <= virtual()));
4510        _for_each_inner_peripheral!((@ peri_type #[doc =
4511        "GPIO10 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4512        "<section class=\"warning\">"] #[doc =
4513        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4514        #[doc = "<ul>"] #[doc =
4515        "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
4516        = "</ul>"] #[doc = "</section>"] GPIO10 <= virtual()));
4517        _for_each_inner_peripheral!((@ peri_type #[doc =
4518        "GPIO11 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4519        "<section class=\"warning\">"] #[doc =
4520        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4521        #[doc = "<ul>"] #[doc =
4522        "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
4523        = "</ul>"] #[doc = "</section>"] GPIO11 <= virtual()));
4524        _for_each_inner_peripheral!((@ peri_type #[doc =
4525        "GPIO12 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4526        "<section class=\"warning\">"] #[doc =
4527        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4528        #[doc = "<ul>"] #[doc =
4529        "<li>These pins may be used to debug the chip using USB.</li>"] #[doc = "</ul>"]
4530        #[doc = "</section>"] GPIO12 <= virtual())); _for_each_inner_peripheral!((@
4531        peri_type #[doc = "GPIO13 peripheral singleton (Limitations exist)"] #[doc = ""]
4532        #[doc = "<section class=\"warning\">"] #[doc =
4533        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4534        #[doc = "<ul>"] #[doc =
4535        "<li>These pins may be used to debug the chip using USB.</li>"] #[doc = "</ul>"]
4536        #[doc = "</section>"] GPIO13 <= virtual())); _for_each_inner_peripheral!((@
4537        peri_type #[doc = "GPIO14 peripheral singleton (Limitations exist)"] #[doc = ""]
4538        #[doc = "<section class=\"warning\">"] #[doc =
4539        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4540        #[doc = "<ul>"] #[doc =
4541        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
4542        "</ul>"] #[doc = "</section>"] GPIO14 <= virtual()));
4543        _for_each_inner_peripheral!((@ peri_type #[doc =
4544        "GPIO15 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4545        "<section class=\"warning\">"] #[doc =
4546        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4547        #[doc = "<ul>"] #[doc =
4548        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4549        "</ul>"] #[doc = "</section>"] GPIO15 <= virtual()));
4550        _for_each_inner_peripheral!((@ peri_type #[doc =
4551        "GPIO16 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4552        "<section class=\"warning\">"] #[doc =
4553        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4554        #[doc = "<ul>"] #[doc =
4555        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4556        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
4557        "</ul>"] #[doc = "</section>"] GPIO16 <= virtual()));
4558        _for_each_inner_peripheral!((@ peri_type #[doc =
4559        "GPIO17 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4560        "<section class=\"warning\">"] #[doc =
4561        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4562        #[doc = "<ul>"] #[doc =
4563        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4564        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
4565        "</ul>"] #[doc = "</section>"] GPIO17 <= virtual()));
4566        _for_each_inner_peripheral!((@ peri_type #[doc =
4567        "GPIO18 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4568        "<section class=\"warning\">"] #[doc =
4569        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4570        #[doc = "<ul>"] #[doc =
4571        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4572        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
4573        "</ul>"] #[doc = "</section>"] GPIO18 <= virtual()));
4574        _for_each_inner_peripheral!((@ peri_type #[doc =
4575        "GPIO19 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4576        "<section class=\"warning\">"] #[doc =
4577        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4578        #[doc = "<ul>"] #[doc =
4579        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4580        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
4581        "</ul>"] #[doc = "</section>"] GPIO19 <= virtual()));
4582        _for_each_inner_peripheral!((@ peri_type #[doc =
4583        "GPIO20 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4584        "<section class=\"warning\">"] #[doc =
4585        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4586        #[doc = "<ul>"] #[doc =
4587        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4588        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
4589        "</ul>"] #[doc = "</section>"] GPIO20 <= virtual()));
4590        _for_each_inner_peripheral!((@ peri_type #[doc =
4591        "GPIO21 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4592        "<section class=\"warning\">"] #[doc =
4593        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4594        #[doc = "<ul>"] #[doc =
4595        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4596        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
4597        "</ul>"] #[doc = "</section>"] GPIO21 <= virtual()));
4598        _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO22 peripheral singleton"]
4599        GPIO22 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
4600        "GPIO23 peripheral singleton"] GPIO23 <= virtual()));
4601        _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO24 peripheral singleton"]
4602        GPIO24 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
4603        "GPIO25 peripheral singleton"] GPIO25 <= virtual()));
4604        _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO26 peripheral singleton"]
4605        GPIO26 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
4606        "GPIO27 peripheral singleton"] GPIO27 <= virtual()));
4607        _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO28 peripheral singleton"]
4608        GPIO28 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
4609        "GPIO29 peripheral singleton"] GPIO29 <= virtual()));
4610        _for_each_inner_peripheral!((@ peri_type #[doc = "DMA_CH0 peripheral singleton"]
4611        DMA_CH0 <= virtual(DMA_IN_CH0 : { bind_dma_in_interrupt, enable_dma_in_interrupt,
4612        disable_dma_in_interrupt }, DMA_OUT_CH0 : { bind_dma_out_interrupt,
4613        enable_dma_out_interrupt, disable_dma_out_interrupt }) (unstable)));
4614        _for_each_inner_peripheral!((@ peri_type #[doc = "DMA_CH1 peripheral singleton"]
4615        DMA_CH1 <= virtual(DMA_IN_CH1 : { bind_dma_in_interrupt, enable_dma_in_interrupt,
4616        disable_dma_in_interrupt }, DMA_OUT_CH1 : { bind_dma_out_interrupt,
4617        enable_dma_out_interrupt, disable_dma_out_interrupt }) (unstable)));
4618        _for_each_inner_peripheral!((@ peri_type #[doc =
4619        "APB_SARADC peripheral singleton"] APB_SARADC <= APB_SARADC() (unstable)));
4620        _for_each_inner_peripheral!((@ peri_type #[doc =
4621        "ASSIST_DEBUG peripheral singleton"] ASSIST_DEBUG <= ASSIST_DEBUG() (unstable)));
4622        _for_each_inner_peripheral!((@ peri_type #[doc = "CACHE peripheral singleton"]
4623        CACHE <= CACHE() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4624        "CLIC peripheral singleton"] CLIC <= CLIC() (unstable)));
4625        _for_each_inner_peripheral!((@ peri_type #[doc = "CLINT peripheral singleton"]
4626        CLINT <= CLINT() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4627        "DMA peripheral singleton"] DMA <= DMA() (unstable)));
4628        _for_each_inner_peripheral!((@ peri_type #[doc = "ECC peripheral singleton"] ECC
4629        <= ECC() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4630        "ECDSA peripheral singleton"] ECDSA <= ECDSA() (unstable)));
4631        _for_each_inner_peripheral!((@ peri_type #[doc = "EFUSE peripheral singleton"]
4632        EFUSE <= EFUSE() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4633        "ETM peripheral singleton"] ETM <= SOC_ETM() (unstable)));
4634        _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO peripheral singleton"]
4635        GPIO <= GPIO() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4636        "GPIO_SD peripheral singleton"] GPIO_SD <= GPIO_EXT() (unstable)));
4637        _for_each_inner_peripheral!((@ peri_type #[doc = "HP_APM peripheral singleton"]
4638        HP_APM <= HP_APM() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4639        "HP_SYS peripheral singleton"] HP_SYS <= HP_SYS() (unstable)));
4640        _for_each_inner_peripheral!((@ peri_type #[doc =
4641        "I2C_ANA_MST peripheral singleton"] I2C_ANA_MST <= I2C_ANA_MST() (unstable)));
4642        _for_each_inner_peripheral!((@ peri_type #[doc = "I2C0 peripheral singleton"]
4643        I2C0 <= I2C0(I2C_EXT0 : { bind_peri_interrupt, enable_peri_interrupt,
4644        disable_peri_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
4645        "I2S0 peripheral singleton"] I2S0 <= I2S0(I2S0 : { bind_peri_interrupt,
4646        enable_peri_interrupt, disable_peri_interrupt }) (unstable)));
4647        _for_each_inner_peripheral!((@ peri_type #[doc =
4648        "INTERRUPT_CORE0 peripheral singleton"] INTERRUPT_CORE0 <= INTERRUPT_CORE0()
4649        (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4650        "INTPRI peripheral singleton"] INTPRI <= INTPRI() (unstable)));
4651        _for_each_inner_peripheral!((@ peri_type #[doc = "IO_MUX peripheral singleton"]
4652        IO_MUX <= IO_MUX() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4653        "LP_ANA peripheral singleton"] LP_ANA <= LP_ANA() (unstable)));
4654        _for_each_inner_peripheral!((@ peri_type #[doc = "LP_AON peripheral singleton"]
4655        LP_AON <= LP_AON() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4656        "LP_APM peripheral singleton"] LP_APM <= LP_APM() (unstable)));
4657        _for_each_inner_peripheral!((@ peri_type #[doc =
4658        "LP_CLKRST peripheral singleton"] LP_CLKRST <= LP_CLKRST() (unstable)));
4659        _for_each_inner_peripheral!((@ peri_type #[doc = "LPWR peripheral singleton"]
4660        LPWR <= LP_CLKRST() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc
4661        = "LP_GPIO peripheral singleton"] LP_GPIO <= LP_GPIO() (unstable)));
4662        _for_each_inner_peripheral!((@ peri_type #[doc =
4663        "LP_IO_MUX peripheral singleton"] LP_IO_MUX <= LP_IO_MUX() (unstable)));
4664        _for_each_inner_peripheral!((@ peri_type #[doc = "LP_PERI peripheral singleton"]
4665        LP_PERI <= LPPERI() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc
4666        = "LP_TEE peripheral singleton"] LP_TEE <= LP_TEE() (unstable)));
4667        _for_each_inner_peripheral!((@ peri_type #[doc =
4668        "RTC_TIMER peripheral singleton"] RTC_TIMER <= LP_TIMER() (unstable)));
4669        _for_each_inner_peripheral!((@ peri_type #[doc = "LP_WDT peripheral singleton"]
4670        LP_WDT <= LP_WDT() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4671        "MEM_MONITOR peripheral singleton"] MEM_MONITOR <= MEM_MONITOR() (unstable)));
4672        _for_each_inner_peripheral!((@ peri_type #[doc =
4673        "MODEM_LPCON peripheral singleton"] MODEM_LPCON <= MODEM_LPCON() (unstable)));
4674        _for_each_inner_peripheral!((@ peri_type #[doc =
4675        "MODEM_SYSCON peripheral singleton"] MODEM_SYSCON <= MODEM_SYSCON() (unstable)));
4676        _for_each_inner_peripheral!((@ peri_type #[doc = "PAU peripheral singleton"] PAU
4677        <= PAU() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4678        "PCR peripheral singleton"] PCR <= PCR() (unstable)));
4679        _for_each_inner_peripheral!((@ peri_type #[doc = "PMU peripheral singleton"] PMU
4680        <= PMU() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4681        "RNG peripheral singleton"] RNG <= LPPERI() (unstable)));
4682        _for_each_inner_peripheral!((@ peri_type #[doc = "SHA peripheral singleton"] SHA
4683        <= SHA(SHA : { bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt
4684        }) (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4685        "SLC peripheral singleton"] SLC <= SLC() (unstable)));
4686        _for_each_inner_peripheral!((@ peri_type #[doc = "SPI0 peripheral singleton"]
4687        SPI0 <= SPI0() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4688        "SPI1 peripheral singleton"] SPI1 <= SPI1() (unstable)));
4689        _for_each_inner_peripheral!((@ peri_type #[doc = "SPI2 peripheral singleton"]
4690        SPI2 <= SPI2(SPI2 : { bind_peri_interrupt, enable_peri_interrupt,
4691        disable_peri_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
4692        "SYSTEM peripheral singleton"] SYSTEM <= PCR() (unstable)));
4693        _for_each_inner_peripheral!((@ peri_type #[doc = "SYSTIMER peripheral singleton"]
4694        SYSTIMER <= SYSTIMER() (unstable))); _for_each_inner_peripheral!((@ peri_type
4695        #[doc = "TEE peripheral singleton"] TEE <= TEE() (unstable)));
4696        _for_each_inner_peripheral!((@ peri_type #[doc = "TIMG0 peripheral singleton"]
4697        TIMG0 <= TIMG0() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4698        "TIMG1 peripheral singleton"] TIMG1 <= TIMG1() (unstable)));
4699        _for_each_inner_peripheral!((@ peri_type #[doc = "UART0 peripheral singleton"]
4700        UART0 <= UART0(UART0 : { bind_peri_interrupt, enable_peri_interrupt,
4701        disable_peri_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
4702        "UART1 peripheral singleton"] UART1 <= UART1(UART1 : { bind_peri_interrupt,
4703        enable_peri_interrupt, disable_peri_interrupt })));
4704        _for_each_inner_peripheral!((@ peri_type #[doc = "UART2 peripheral singleton"]
4705        UART2 <= UART2(UART2 : { bind_peri_interrupt, enable_peri_interrupt,
4706        disable_peri_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
4707        "USB_DEVICE peripheral singleton"] USB_DEVICE <= USB_DEVICE(USB_DEVICE : {
4708        bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })
4709        (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4710        "ADC1 peripheral singleton"] ADC1 <= virtual() (unstable)));
4711        _for_each_inner_peripheral!((@ peri_type #[doc = "BT peripheral singleton"] BT <=
4712        virtual(LP_TIMER : { bind_lp_timer_interrupt, enable_lp_timer_interrupt,
4713        disable_lp_timer_interrupt }, BT_MAC : { bind_mac_interrupt,
4714        enable_mac_interrupt, disable_mac_interrupt }) (unstable)));
4715        _for_each_inner_peripheral!((@ peri_type #[doc = "FLASH peripheral singleton"]
4716        FLASH <= virtual() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4717        "GPIO_DEDICATED peripheral singleton"] GPIO_DEDICATED <= virtual() (unstable)));
4718        _for_each_inner_peripheral!((@ peri_type #[doc = "WIFI peripheral singleton"]
4719        WIFI <= virtual(WIFI_BB : { bind_bb_interrupt, enable_bb_interrupt,
4720        disable_bb_interrupt }, WIFI_MAC : { bind_mac_interrupt, enable_mac_interrupt,
4721        disable_mac_interrupt }, WIFI_PWR : { bind_pwr_interrupt, enable_pwr_interrupt,
4722        disable_pwr_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
4723        "PSRAM peripheral singleton"] PSRAM <= virtual() (unstable)));
4724        _for_each_inner_peripheral!((@ peri_type #[doc =
4725        "FROM_CPU_INTR0 peripheral singleton"] FROM_CPU_INTR0 <= virtual() (unstable)));
4726        _for_each_inner_peripheral!((@ peri_type #[doc =
4727        "FROM_CPU_INTR1 peripheral singleton"] FROM_CPU_INTR1 <= virtual() (unstable)));
4728        _for_each_inner_peripheral!((@ peri_type #[doc =
4729        "FROM_CPU_INTR2 peripheral singleton"] FROM_CPU_INTR2 <= virtual() (unstable)));
4730        _for_each_inner_peripheral!((@ peri_type #[doc =
4731        "FROM_CPU_INTR3 peripheral singleton"] FROM_CPU_INTR3 <= virtual() (unstable)));
4732        _for_each_inner_peripheral!((#[cfg(not(use_xtal32k))] GPIO0));
4733        _for_each_inner_peripheral!((#[cfg(not(use_xtal32k))] GPIO1));
4734        _for_each_inner_peripheral!((GPIO2)); _for_each_inner_peripheral!((GPIO3));
4735        _for_each_inner_peripheral!((GPIO4)); _for_each_inner_peripheral!((GPIO5));
4736        _for_each_inner_peripheral!((GPIO6)); _for_each_inner_peripheral!((GPIO7));
4737        _for_each_inner_peripheral!((GPIO8)); _for_each_inner_peripheral!((GPIO9));
4738        _for_each_inner_peripheral!((GPIO10)); _for_each_inner_peripheral!((GPIO11));
4739        _for_each_inner_peripheral!((GPIO12)); _for_each_inner_peripheral!((GPIO13));
4740        _for_each_inner_peripheral!((GPIO14)); _for_each_inner_peripheral!((GPIO15));
4741        _for_each_inner_peripheral!((GPIO16)); _for_each_inner_peripheral!((GPIO17));
4742        _for_each_inner_peripheral!((GPIO18)); _for_each_inner_peripheral!((GPIO19));
4743        _for_each_inner_peripheral!((GPIO20)); _for_each_inner_peripheral!((GPIO21));
4744        _for_each_inner_peripheral!((GPIO22)); _for_each_inner_peripheral!((GPIO23));
4745        _for_each_inner_peripheral!((GPIO24)); _for_each_inner_peripheral!((GPIO25));
4746        _for_each_inner_peripheral!((GPIO26)); _for_each_inner_peripheral!((GPIO27));
4747        _for_each_inner_peripheral!((GPIO28)); _for_each_inner_peripheral!((GPIO29));
4748        _for_each_inner_peripheral!((DMA_CH0(unstable)));
4749        _for_each_inner_peripheral!((DMA_CH1(unstable)));
4750        _for_each_inner_peripheral!((APB_SARADC(unstable)));
4751        _for_each_inner_peripheral!((ASSIST_DEBUG(unstable)));
4752        _for_each_inner_peripheral!((CACHE(unstable)));
4753        _for_each_inner_peripheral!((CLINT(unstable)));
4754        _for_each_inner_peripheral!((DMA(unstable)));
4755        _for_each_inner_peripheral!((ECC(unstable)));
4756        _for_each_inner_peripheral!((ECDSA(unstable)));
4757        _for_each_inner_peripheral!((EFUSE(unstable)));
4758        _for_each_inner_peripheral!((ETM(unstable)));
4759        _for_each_inner_peripheral!((GPIO(unstable)));
4760        _for_each_inner_peripheral!((GPIO_SD(unstable)));
4761        _for_each_inner_peripheral!((HP_APM(unstable)));
4762        _for_each_inner_peripheral!((HP_SYS(unstable)));
4763        _for_each_inner_peripheral!((I2C_ANA_MST(unstable)));
4764        _for_each_inner_peripheral!((I2C0));
4765        _for_each_inner_peripheral!((I2S0(unstable)));
4766        _for_each_inner_peripheral!((INTERRUPT_CORE0(unstable)));
4767        _for_each_inner_peripheral!((INTPRI(unstable)));
4768        _for_each_inner_peripheral!((IO_MUX(unstable)));
4769        _for_each_inner_peripheral!((LP_ANA(unstable)));
4770        _for_each_inner_peripheral!((LP_AON(unstable)));
4771        _for_each_inner_peripheral!((LP_APM(unstable)));
4772        _for_each_inner_peripheral!((LP_CLKRST(unstable)));
4773        _for_each_inner_peripheral!((LPWR(unstable)));
4774        _for_each_inner_peripheral!((LP_GPIO(unstable)));
4775        _for_each_inner_peripheral!((LP_IO_MUX(unstable)));
4776        _for_each_inner_peripheral!((LP_PERI(unstable)));
4777        _for_each_inner_peripheral!((LP_TEE(unstable)));
4778        _for_each_inner_peripheral!((RTC_TIMER(unstable)));
4779        _for_each_inner_peripheral!((LP_WDT(unstable)));
4780        _for_each_inner_peripheral!((MEM_MONITOR(unstable)));
4781        _for_each_inner_peripheral!((MODEM_LPCON(unstable)));
4782        _for_each_inner_peripheral!((MODEM_SYSCON(unstable)));
4783        _for_each_inner_peripheral!((PAU(unstable)));
4784        _for_each_inner_peripheral!((PCR(unstable)));
4785        _for_each_inner_peripheral!((PMU(unstable)));
4786        _for_each_inner_peripheral!((RNG(unstable)));
4787        _for_each_inner_peripheral!((SHA(unstable)));
4788        _for_each_inner_peripheral!((SLC(unstable)));
4789        _for_each_inner_peripheral!((SPI0(unstable)));
4790        _for_each_inner_peripheral!((SPI1(unstable)));
4791        _for_each_inner_peripheral!((SPI2));
4792        _for_each_inner_peripheral!((SYSTEM(unstable)));
4793        _for_each_inner_peripheral!((SYSTIMER(unstable)));
4794        _for_each_inner_peripheral!((TEE(unstable)));
4795        _for_each_inner_peripheral!((TIMG0(unstable)));
4796        _for_each_inner_peripheral!((TIMG1(unstable)));
4797        _for_each_inner_peripheral!((UART0)); _for_each_inner_peripheral!((UART1));
4798        _for_each_inner_peripheral!((UART2));
4799        _for_each_inner_peripheral!((USB_DEVICE(unstable)));
4800        _for_each_inner_peripheral!((ADC1(unstable)));
4801        _for_each_inner_peripheral!((BT(unstable)));
4802        _for_each_inner_peripheral!((FLASH(unstable)));
4803        _for_each_inner_peripheral!((GPIO_DEDICATED(unstable)));
4804        _for_each_inner_peripheral!((WIFI));
4805        _for_each_inner_peripheral!((PSRAM(unstable)));
4806        _for_each_inner_peripheral!((FROM_CPU_INTR0(unstable)));
4807        _for_each_inner_peripheral!((FROM_CPU_INTR1(unstable)));
4808        _for_each_inner_peripheral!((FROM_CPU_INTR2(unstable)));
4809        _for_each_inner_peripheral!((FROM_CPU_INTR3(unstable)));
4810        _for_each_inner_peripheral!((SPI2, Spi2, 1, AhbGdmaChannel));
4811        _for_each_inner_peripheral!((I2S0, I2s0, 3, AhbGdmaChannel));
4812        _for_each_inner_peripheral!((SHA, Sha, 7, AhbGdmaChannel));
4813        _for_each_inner_peripheral!((all(@ peri_type #[doc =
4814        "GPIO0 peripheral singleton"] GPIO0 <= virtual()), (@ peri_type #[doc =
4815        "GPIO1 peripheral singleton"] GPIO1 <= virtual()), (@ peri_type #[doc =
4816        "GPIO2 peripheral singleton"] GPIO2 <= virtual()), (@ peri_type #[doc =
4817        "GPIO3 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4818        "<section class=\"warning\">"] #[doc =
4819        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4820        #[doc = "<ul>"] #[doc =
4821        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
4822        =
4823        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4824        #[doc = "</ul>"] #[doc = "</section>"] GPIO3 <= virtual()), (@ peri_type #[doc =
4825        "GPIO4 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4826        "<section class=\"warning\">"] #[doc =
4827        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4828        #[doc = "<ul>"] #[doc =
4829        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
4830        =
4831        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4832        #[doc = "</ul>"] #[doc = "</section>"] GPIO4 <= virtual()), (@ peri_type #[doc =
4833        "GPIO5 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4834        "<section class=\"warning\">"] #[doc =
4835        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4836        #[doc = "<ul>"] #[doc =
4837        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4838        #[doc = "</ul>"] #[doc = "</section>"] GPIO5 <= virtual()), (@ peri_type #[doc =
4839        "GPIO6 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4840        "<section class=\"warning\">"] #[doc =
4841        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4842        #[doc = "<ul>"] #[doc =
4843        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4844        #[doc = "</ul>"] #[doc = "</section>"] GPIO6 <= virtual()), (@ peri_type #[doc =
4845        "GPIO7 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4846        "<section class=\"warning\">"] #[doc =
4847        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4848        #[doc = "<ul>"] #[doc =
4849        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
4850        = "</ul>"] #[doc = "</section>"] GPIO7 <= virtual()), (@ peri_type #[doc =
4851        "GPIO8 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4852        "<section class=\"warning\">"] #[doc =
4853        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4854        #[doc = "<ul>"] #[doc =
4855        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
4856        = "</ul>"] #[doc = "</section>"] GPIO8 <= virtual()), (@ peri_type #[doc =
4857        "GPIO9 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4858        "<section class=\"warning\">"] #[doc =
4859        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4860        #[doc = "<ul>"] #[doc =
4861        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
4862        = "</ul>"] #[doc = "</section>"] GPIO9 <= virtual()), (@ peri_type #[doc =
4863        "GPIO10 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4864        "<section class=\"warning\">"] #[doc =
4865        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4866        #[doc = "<ul>"] #[doc =
4867        "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
4868        = "</ul>"] #[doc = "</section>"] GPIO10 <= virtual()), (@ peri_type #[doc =
4869        "GPIO11 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4870        "<section class=\"warning\">"] #[doc =
4871        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4872        #[doc = "<ul>"] #[doc =
4873        "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
4874        = "</ul>"] #[doc = "</section>"] GPIO11 <= virtual()), (@ peri_type #[doc =
4875        "GPIO12 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4876        "<section class=\"warning\">"] #[doc =
4877        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4878        #[doc = "<ul>"] #[doc =
4879        "<li>These pins may be used to debug the chip using USB.</li>"] #[doc = "</ul>"]
4880        #[doc = "</section>"] GPIO12 <= virtual()), (@ peri_type #[doc =
4881        "GPIO13 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4882        "<section class=\"warning\">"] #[doc =
4883        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4884        #[doc = "<ul>"] #[doc =
4885        "<li>These pins may be used to debug the chip using USB.</li>"] #[doc = "</ul>"]
4886        #[doc = "</section>"] GPIO13 <= virtual()), (@ peri_type #[doc =
4887        "GPIO14 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4888        "<section class=\"warning\">"] #[doc =
4889        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4890        #[doc = "<ul>"] #[doc =
4891        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
4892        "</ul>"] #[doc = "</section>"] GPIO14 <= virtual()), (@ peri_type #[doc =
4893        "GPIO15 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4894        "<section class=\"warning\">"] #[doc =
4895        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4896        #[doc = "<ul>"] #[doc =
4897        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4898        "</ul>"] #[doc = "</section>"] GPIO15 <= virtual()), (@ peri_type #[doc =
4899        "GPIO16 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4900        "<section class=\"warning\">"] #[doc =
4901        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4902        #[doc = "<ul>"] #[doc =
4903        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4904        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
4905        "</ul>"] #[doc = "</section>"] GPIO16 <= virtual()), (@ peri_type #[doc =
4906        "GPIO17 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4907        "<section class=\"warning\">"] #[doc =
4908        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4909        #[doc = "<ul>"] #[doc =
4910        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4911        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
4912        "</ul>"] #[doc = "</section>"] GPIO17 <= virtual()), (@ peri_type #[doc =
4913        "GPIO18 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4914        "<section class=\"warning\">"] #[doc =
4915        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4916        #[doc = "<ul>"] #[doc =
4917        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4918        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
4919        "</ul>"] #[doc = "</section>"] GPIO18 <= virtual()), (@ peri_type #[doc =
4920        "GPIO19 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4921        "<section class=\"warning\">"] #[doc =
4922        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4923        #[doc = "<ul>"] #[doc =
4924        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4925        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
4926        "</ul>"] #[doc = "</section>"] GPIO19 <= virtual()), (@ peri_type #[doc =
4927        "GPIO20 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4928        "<section class=\"warning\">"] #[doc =
4929        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4930        #[doc = "<ul>"] #[doc =
4931        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4932        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
4933        "</ul>"] #[doc = "</section>"] GPIO20 <= virtual()), (@ peri_type #[doc =
4934        "GPIO21 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4935        "<section class=\"warning\">"] #[doc =
4936        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4937        #[doc = "<ul>"] #[doc =
4938        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4939        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
4940        "</ul>"] #[doc = "</section>"] GPIO21 <= virtual()), (@ peri_type #[doc =
4941        "GPIO22 peripheral singleton"] GPIO22 <= virtual()), (@ peri_type #[doc =
4942        "GPIO23 peripheral singleton"] GPIO23 <= virtual()), (@ peri_type #[doc =
4943        "GPIO24 peripheral singleton"] GPIO24 <= virtual()), (@ peri_type #[doc =
4944        "GPIO25 peripheral singleton"] GPIO25 <= virtual()), (@ peri_type #[doc =
4945        "GPIO26 peripheral singleton"] GPIO26 <= virtual()), (@ peri_type #[doc =
4946        "GPIO27 peripheral singleton"] GPIO27 <= virtual()), (@ peri_type #[doc =
4947        "GPIO28 peripheral singleton"] GPIO28 <= virtual()), (@ peri_type #[doc =
4948        "GPIO29 peripheral singleton"] GPIO29 <= virtual()), (@ peri_type #[doc =
4949        "DMA_CH0 peripheral singleton"] DMA_CH0 <= virtual(DMA_IN_CH0 : {
4950        bind_dma_in_interrupt, enable_dma_in_interrupt, disable_dma_in_interrupt },
4951        DMA_OUT_CH0 : { bind_dma_out_interrupt, enable_dma_out_interrupt,
4952        disable_dma_out_interrupt }) (unstable)), (@ peri_type #[doc =
4953        "DMA_CH1 peripheral singleton"] DMA_CH1 <= virtual(DMA_IN_CH1 : {
4954        bind_dma_in_interrupt, enable_dma_in_interrupt, disable_dma_in_interrupt },
4955        DMA_OUT_CH1 : { bind_dma_out_interrupt, enable_dma_out_interrupt,
4956        disable_dma_out_interrupt }) (unstable)), (@ peri_type #[doc =
4957        "APB_SARADC peripheral singleton"] APB_SARADC <= APB_SARADC() (unstable)), (@
4958        peri_type #[doc = "ASSIST_DEBUG peripheral singleton"] ASSIST_DEBUG <=
4959        ASSIST_DEBUG() (unstable)), (@ peri_type #[doc = "CACHE peripheral singleton"]
4960        CACHE <= CACHE() (unstable)), (@ peri_type #[doc = "CLIC peripheral singleton"]
4961        CLIC <= CLIC() (unstable)), (@ peri_type #[doc = "CLINT peripheral singleton"]
4962        CLINT <= CLINT() (unstable)), (@ peri_type #[doc = "DMA peripheral singleton"]
4963        DMA <= DMA() (unstable)), (@ peri_type #[doc = "ECC peripheral singleton"] ECC <=
4964        ECC() (unstable)), (@ peri_type #[doc = "ECDSA peripheral singleton"] ECDSA <=
4965        ECDSA() (unstable)), (@ peri_type #[doc = "EFUSE peripheral singleton"] EFUSE <=
4966        EFUSE() (unstable)), (@ peri_type #[doc = "ETM peripheral singleton"] ETM <=
4967        SOC_ETM() (unstable)), (@ peri_type #[doc = "GPIO peripheral singleton"] GPIO <=
4968        GPIO() (unstable)), (@ peri_type #[doc = "GPIO_SD peripheral singleton"] GPIO_SD
4969        <= GPIO_EXT() (unstable)), (@ peri_type #[doc = "HP_APM peripheral singleton"]
4970        HP_APM <= HP_APM() (unstable)), (@ peri_type #[doc =
4971        "HP_SYS peripheral singleton"] HP_SYS <= HP_SYS() (unstable)), (@ peri_type #[doc
4972        = "I2C_ANA_MST peripheral singleton"] I2C_ANA_MST <= I2C_ANA_MST() (unstable)),
4973        (@ peri_type #[doc = "I2C0 peripheral singleton"] I2C0 <= I2C0(I2C_EXT0 : {
4974        bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })), (@
4975        peri_type #[doc = "I2S0 peripheral singleton"] I2S0 <= I2S0(I2S0 : {
4976        bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })
4977        (unstable)), (@ peri_type #[doc = "INTERRUPT_CORE0 peripheral singleton"]
4978        INTERRUPT_CORE0 <= INTERRUPT_CORE0() (unstable)), (@ peri_type #[doc =
4979        "INTPRI peripheral singleton"] INTPRI <= INTPRI() (unstable)), (@ peri_type #[doc
4980        = "IO_MUX peripheral singleton"] IO_MUX <= IO_MUX() (unstable)), (@ peri_type
4981        #[doc = "LP_ANA peripheral singleton"] LP_ANA <= LP_ANA() (unstable)), (@
4982        peri_type #[doc = "LP_AON peripheral singleton"] LP_AON <= LP_AON() (unstable)),
4983        (@ peri_type #[doc = "LP_APM peripheral singleton"] LP_APM <= LP_APM()
4984        (unstable)), (@ peri_type #[doc = "LP_CLKRST peripheral singleton"] LP_CLKRST <=
4985        LP_CLKRST() (unstable)), (@ peri_type #[doc = "LPWR peripheral singleton"] LPWR
4986        <= LP_CLKRST() (unstable)), (@ peri_type #[doc = "LP_GPIO peripheral singleton"]
4987        LP_GPIO <= LP_GPIO() (unstable)), (@ peri_type #[doc =
4988        "LP_IO_MUX peripheral singleton"] LP_IO_MUX <= LP_IO_MUX() (unstable)), (@
4989        peri_type #[doc = "LP_PERI peripheral singleton"] LP_PERI <= LPPERI()
4990        (unstable)), (@ peri_type #[doc = "LP_TEE peripheral singleton"] LP_TEE <=
4991        LP_TEE() (unstable)), (@ peri_type #[doc = "RTC_TIMER peripheral singleton"]
4992        RTC_TIMER <= LP_TIMER() (unstable)), (@ peri_type #[doc =
4993        "LP_WDT peripheral singleton"] LP_WDT <= LP_WDT() (unstable)), (@ peri_type #[doc
4994        = "MEM_MONITOR peripheral singleton"] MEM_MONITOR <= MEM_MONITOR() (unstable)),
4995        (@ peri_type #[doc = "MODEM_LPCON peripheral singleton"] MODEM_LPCON <=
4996        MODEM_LPCON() (unstable)), (@ peri_type #[doc =
4997        "MODEM_SYSCON peripheral singleton"] MODEM_SYSCON <= MODEM_SYSCON() (unstable)),
4998        (@ peri_type #[doc = "PAU peripheral singleton"] PAU <= PAU() (unstable)), (@
4999        peri_type #[doc = "PCR peripheral singleton"] PCR <= PCR() (unstable)), (@
5000        peri_type #[doc = "PMU peripheral singleton"] PMU <= PMU() (unstable)), (@
5001        peri_type #[doc = "RNG peripheral singleton"] RNG <= LPPERI() (unstable)), (@
5002        peri_type #[doc = "SHA peripheral singleton"] SHA <= SHA(SHA : {
5003        bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })
5004        (unstable)), (@ peri_type #[doc = "SLC peripheral singleton"] SLC <= SLC()
5005        (unstable)), (@ peri_type #[doc = "SPI0 peripheral singleton"] SPI0 <= SPI0()
5006        (unstable)), (@ peri_type #[doc = "SPI1 peripheral singleton"] SPI1 <= SPI1()
5007        (unstable)), (@ peri_type #[doc = "SPI2 peripheral singleton"] SPI2 <= SPI2(SPI2
5008        : { bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })), (@
5009        peri_type #[doc = "SYSTEM peripheral singleton"] SYSTEM <= PCR() (unstable)), (@
5010        peri_type #[doc = "SYSTIMER peripheral singleton"] SYSTIMER <= SYSTIMER()
5011        (unstable)), (@ peri_type #[doc = "TEE peripheral singleton"] TEE <= TEE()
5012        (unstable)), (@ peri_type #[doc = "TIMG0 peripheral singleton"] TIMG0 <= TIMG0()
5013        (unstable)), (@ peri_type #[doc = "TIMG1 peripheral singleton"] TIMG1 <= TIMG1()
5014        (unstable)), (@ peri_type #[doc = "UART0 peripheral singleton"] UART0 <=
5015        UART0(UART0 : { bind_peri_interrupt, enable_peri_interrupt,
5016        disable_peri_interrupt })), (@ peri_type #[doc = "UART1 peripheral singleton"]
5017        UART1 <= UART1(UART1 : { bind_peri_interrupt, enable_peri_interrupt,
5018        disable_peri_interrupt })), (@ peri_type #[doc = "UART2 peripheral singleton"]
5019        UART2 <= UART2(UART2 : { bind_peri_interrupt, enable_peri_interrupt,
5020        disable_peri_interrupt })), (@ peri_type #[doc =
5021        "USB_DEVICE peripheral singleton"] USB_DEVICE <= USB_DEVICE(USB_DEVICE : {
5022        bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })
5023        (unstable)), (@ peri_type #[doc = "ADC1 peripheral singleton"] ADC1 <= virtual()
5024        (unstable)), (@ peri_type #[doc = "BT peripheral singleton"] BT <=
5025        virtual(LP_TIMER : { bind_lp_timer_interrupt, enable_lp_timer_interrupt,
5026        disable_lp_timer_interrupt }, BT_MAC : { bind_mac_interrupt,
5027        enable_mac_interrupt, disable_mac_interrupt }) (unstable)), (@ peri_type #[doc =
5028        "FLASH peripheral singleton"] FLASH <= virtual() (unstable)), (@ peri_type #[doc
5029        = "GPIO_DEDICATED peripheral singleton"] GPIO_DEDICATED <= virtual() (unstable)),
5030        (@ peri_type #[doc = "WIFI peripheral singleton"] WIFI <= virtual(WIFI_BB : {
5031        bind_bb_interrupt, enable_bb_interrupt, disable_bb_interrupt }, WIFI_MAC : {
5032        bind_mac_interrupt, enable_mac_interrupt, disable_mac_interrupt }, WIFI_PWR : {
5033        bind_pwr_interrupt, enable_pwr_interrupt, disable_pwr_interrupt })), (@ peri_type
5034        #[doc = "PSRAM peripheral singleton"] PSRAM <= virtual() (unstable)), (@
5035        peri_type #[doc = "FROM_CPU_INTR0 peripheral singleton"] FROM_CPU_INTR0 <=
5036        virtual() (unstable)), (@ peri_type #[doc =
5037        "FROM_CPU_INTR1 peripheral singleton"] FROM_CPU_INTR1 <= virtual() (unstable)),
5038        (@ peri_type #[doc = "FROM_CPU_INTR2 peripheral singleton"] FROM_CPU_INTR2 <=
5039        virtual() (unstable)), (@ peri_type #[doc =
5040        "FROM_CPU_INTR3 peripheral singleton"] FROM_CPU_INTR3 <= virtual() (unstable))));
5041        _for_each_inner_peripheral!((singletons(#[cfg(not(use_xtal32k))] GPIO0),
5042        (#[cfg(not(use_xtal32k))] GPIO1), (GPIO2), (GPIO3), (GPIO4), (GPIO5), (GPIO6),
5043        (GPIO7), (GPIO8), (GPIO9), (GPIO10), (GPIO11), (GPIO12), (GPIO13), (GPIO14),
5044        (GPIO15), (GPIO16), (GPIO17), (GPIO18), (GPIO19), (GPIO20), (GPIO21), (GPIO22),
5045        (GPIO23), (GPIO24), (GPIO25), (GPIO26), (GPIO27), (GPIO28), (GPIO29),
5046        (DMA_CH0(unstable)), (DMA_CH1(unstable)), (APB_SARADC(unstable)),
5047        (ASSIST_DEBUG(unstable)), (CACHE(unstable)), (CLINT(unstable)), (DMA(unstable)),
5048        (ECC(unstable)), (ECDSA(unstable)), (EFUSE(unstable)), (ETM(unstable)),
5049        (GPIO(unstable)), (GPIO_SD(unstable)), (HP_APM(unstable)), (HP_SYS(unstable)),
5050        (I2C_ANA_MST(unstable)), (I2C0), (I2S0(unstable)), (INTERRUPT_CORE0(unstable)),
5051        (INTPRI(unstable)), (IO_MUX(unstable)), (LP_ANA(unstable)), (LP_AON(unstable)),
5052        (LP_APM(unstable)), (LP_CLKRST(unstable)), (LPWR(unstable)), (LP_GPIO(unstable)),
5053        (LP_IO_MUX(unstable)), (LP_PERI(unstable)), (LP_TEE(unstable)),
5054        (RTC_TIMER(unstable)), (LP_WDT(unstable)), (MEM_MONITOR(unstable)),
5055        (MODEM_LPCON(unstable)), (MODEM_SYSCON(unstable)), (PAU(unstable)),
5056        (PCR(unstable)), (PMU(unstable)), (RNG(unstable)), (SHA(unstable)),
5057        (SLC(unstable)), (SPI0(unstable)), (SPI1(unstable)), (SPI2), (SYSTEM(unstable)),
5058        (SYSTIMER(unstable)), (TEE(unstable)), (TIMG0(unstable)), (TIMG1(unstable)),
5059        (UART0), (UART1), (UART2), (USB_DEVICE(unstable)), (ADC1(unstable)),
5060        (BT(unstable)), (FLASH(unstable)), (GPIO_DEDICATED(unstable)), (WIFI),
5061        (PSRAM(unstable)), (FROM_CPU_INTR0(unstable)), (FROM_CPU_INTR1(unstable)),
5062        (FROM_CPU_INTR2(unstable)), (FROM_CPU_INTR3(unstable))));
5063        _for_each_inner_peripheral!((dma_eligible(SPI2, Spi2, 1, AhbGdmaChannel), (I2S0,
5064        I2s0, 3, AhbGdmaChannel), (SHA, Sha, 7, AhbGdmaChannel)));
5065    };
5066}
5067/// This macro can be used to generate code for each `GPIOn` instance.
5068///
5069/// For an explanation on the general syntax, as well as usage of individual/repeated
5070/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
5071///
5072/// This macro has one option for its "Individual matcher" case:
5073///
5074/// Syntax: `($n:literal, $gpio:ident ($($digital_input_function:ident =>
5075/// $digital_input_signal:ident)*) ($($digital_output_function:ident =>
5076/// $digital_output_signal:ident)*) ($([$pin_attribute:ident])*))`
5077///
5078/// Macro fragments:
5079///
5080/// - `$n`: the number of the GPIO. For `GPIO0`, `$n` is 0.
5081/// - `$gpio`: the name of the GPIO.
5082/// - `$digital_input_function`: the number of the digital function, as an identifier (i.e. for
5083///   function 0 this is `_0`).
5084/// - `$digital_input_function`: the name of the digital function, as an identifier.
5085/// - `$digital_output_function`: the number of the digital function, as an identifier (i.e. for
5086///   function 0 this is `_0`).
5087/// - `$digital_output_function`: the name of the digital function, as an identifier.
5088/// - `$pin_attribute`: `Input` and/or `Output`, marks the possible directions of the GPIO.
5089///   Bracketed so that they can also be matched as optional fragments. Order is always Input first.
5090///
5091/// Example data: `(0, GPIO0 (_5 => EMAC_TX_CLK) (_1 => CLK_OUT1 _5 => EMAC_TX_CLK) ([Input]
5092/// [Output]))`
5093#[macro_export]
5094#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5095macro_rules! for_each_gpio {
5096    ($($pattern:tt => $code:tt;)*) => {
5097        macro_rules! _for_each_inner_gpio { $(($pattern) => $code;)* ($other : tt) => {}
5098        } _for_each_inner_gpio!((0, GPIO0() () ([Input] [Output])));
5099        _for_each_inner_gpio!((1, GPIO1() () ([Input] [Output])));
5100        _for_each_inner_gpio!((2, GPIO2(_2 => FSPIQ) (_2 => FSPIQ) ([Input] [Output])));
5101        _for_each_inner_gpio!((3, GPIO3(_0 => MTMS _2 => FSPIHD) (_2 => FSPIHD) ([Input]
5102        [Output]))); _for_each_inner_gpio!((4, GPIO4(_0 => MTDI _2 => FSPIWP) (_2 =>
5103        FSPIWP) ([Input] [Output]))); _for_each_inner_gpio!((5, GPIO5(_0 => MTCK) ()
5104        ([Input] [Output]))); _for_each_inner_gpio!((6, GPIO6(_0 => MTDO _2 => FSPICLK)
5105        (_2 => FSPICLK) ([Input] [Output]))); _for_each_inner_gpio!((7, GPIO7(_2 =>
5106        FSPID) (_2 => FSPID) ([Input] [Output]))); _for_each_inner_gpio!((8, GPIO8(_2 =>
5107        FSPICS0) (_2 => FSPICS0) ([Input] [Output]))); _for_each_inner_gpio!((9, GPIO9()
5108        () ([Input] [Output]))); _for_each_inner_gpio!((10, GPIO10(_0 => U0RXD) ()
5109        ([Input] [Output]))); _for_each_inner_gpio!((11, GPIO11() (_0 => U0TXD) ([Input]
5110        [Output]))); _for_each_inner_gpio!((12, GPIO12() () ([Input] [Output])));
5111        _for_each_inner_gpio!((13, GPIO13() () ([Input] [Output])));
5112        _for_each_inner_gpio!((14, GPIO14() (_0 => FSPICS1) ([Input] [Output])));
5113        _for_each_inner_gpio!((15, GPIO15(_0 => FSPICS0) (_0 => FSPICS0) ([Input]
5114        [Output]))); _for_each_inner_gpio!((16, GPIO16(_0 => FSPIQ) (_0 => FSPIQ)
5115        ([Input] [Output]))); _for_each_inner_gpio!((17, GPIO17(_0 => FSPIWP) (_0 =>
5116        FSPIWP) ([Input] [Output]))); _for_each_inner_gpio!((18, GPIO18() () ([Input]
5117        [Output]))); _for_each_inner_gpio!((19, GPIO19(_0 => FSPIHD) (_0 => FSPIHD)
5118        ([Input] [Output]))); _for_each_inner_gpio!((20, GPIO20(_0 => FSPICLK) (_0 =>
5119        FSPICLK) ([Input] [Output]))); _for_each_inner_gpio!((21, GPIO21(_0 => FSPID) (_0
5120        => FSPID) ([Input] [Output]))); _for_each_inner_gpio!((22, GPIO22(_0 =>
5121        SDIO_DATA2) () ([Input] [Output]))); _for_each_inner_gpio!((23, GPIO23(_0 =>
5122        SDIO_DATA3) () ([Input] [Output]))); _for_each_inner_gpio!((24, GPIO24() ()
5123        ([Input] [Output]))); _for_each_inner_gpio!((25, GPIO25(_0 => SDIO_CMD) ()
5124        ([Input] [Output]))); _for_each_inner_gpio!((26, GPIO26(_0 => SDIO_CLK) ()
5125        ([Input] [Output]))); _for_each_inner_gpio!((27, GPIO27(_0 => SDIO_DATA0) ()
5126        ([Input] [Output]))); _for_each_inner_gpio!((28, GPIO28(_0 => SDIO_DATA1) ()
5127        ([Input] [Output]))); _for_each_inner_gpio!((29, GPIO29() () ([Input]
5128        [Output]))); _for_each_inner_gpio!((all(0, GPIO0() () ([Input] [Output])), (1,
5129        GPIO1() () ([Input] [Output])), (2, GPIO2(_2 => FSPIQ) (_2 => FSPIQ) ([Input]
5130        [Output])), (3, GPIO3(_0 => MTMS _2 => FSPIHD) (_2 => FSPIHD) ([Input]
5131        [Output])), (4, GPIO4(_0 => MTDI _2 => FSPIWP) (_2 => FSPIWP) ([Input]
5132        [Output])), (5, GPIO5(_0 => MTCK) () ([Input] [Output])), (6, GPIO6(_0 => MTDO _2
5133        => FSPICLK) (_2 => FSPICLK) ([Input] [Output])), (7, GPIO7(_2 => FSPID) (_2 =>
5134        FSPID) ([Input] [Output])), (8, GPIO8(_2 => FSPICS0) (_2 => FSPICS0) ([Input]
5135        [Output])), (9, GPIO9() () ([Input] [Output])), (10, GPIO10(_0 => U0RXD) ()
5136        ([Input] [Output])), (11, GPIO11() (_0 => U0TXD) ([Input] [Output])), (12,
5137        GPIO12() () ([Input] [Output])), (13, GPIO13() () ([Input] [Output])), (14,
5138        GPIO14() (_0 => FSPICS1) ([Input] [Output])), (15, GPIO15(_0 => FSPICS0) (_0 =>
5139        FSPICS0) ([Input] [Output])), (16, GPIO16(_0 => FSPIQ) (_0 => FSPIQ) ([Input]
5140        [Output])), (17, GPIO17(_0 => FSPIWP) (_0 => FSPIWP) ([Input] [Output])), (18,
5141        GPIO18() () ([Input] [Output])), (19, GPIO19(_0 => FSPIHD) (_0 => FSPIHD)
5142        ([Input] [Output])), (20, GPIO20(_0 => FSPICLK) (_0 => FSPICLK) ([Input]
5143        [Output])), (21, GPIO21(_0 => FSPID) (_0 => FSPID) ([Input] [Output])), (22,
5144        GPIO22(_0 => SDIO_DATA2) () ([Input] [Output])), (23, GPIO23(_0 => SDIO_DATA3) ()
5145        ([Input] [Output])), (24, GPIO24() () ([Input] [Output])), (25, GPIO25(_0 =>
5146        SDIO_CMD) () ([Input] [Output])), (26, GPIO26(_0 => SDIO_CLK) () ([Input]
5147        [Output])), (27, GPIO27(_0 => SDIO_DATA0) () ([Input] [Output])), (28, GPIO28(_0
5148        => SDIO_DATA1) () ([Input] [Output])), (29, GPIO29() () ([Input] [Output]))));
5149    };
5150}
5151/// This macro can be used to generate code for each analog function of each GPIO.
5152///
5153/// For an explanation on the general syntax, as well as usage of individual/repeated
5154/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
5155///
5156/// This macro has two options for its "Individual matcher" case:
5157///
5158/// - `all`: `($signal:ident, $gpio:ident)` - simple case where you only need identifiers
5159/// - group: `(($signal:ident, $group:ident $(, $number:literal)+), $gpio:ident)` - expanded signal
5160///   case, where you need the number(s) of a signal, or the general group to which the signal
5161///   belongs. For example, in case of `ADC2_CH3` the expanded form looks like `(ADC2_CH3, ADCn_CHm,
5162///   2, 3)`.
5163///
5164/// Macro fragments:
5165///
5166/// - `$signal`: the name of the signal.
5167/// - `$group`: the name of the signal, with numbers replaced by placeholders. For `ADC2_CH3` this
5168///   is `ADCn_CHm`.
5169/// - `$number`: the numbers extracted from `$signal`.
5170/// - `$gpio`: the name of the GPIO.
5171///
5172/// Example data:
5173/// - `(ADC2_CH5, GPIO12)`
5174/// - `((ADC2_CH5, ADCn_CHm, 2, 5), GPIO12)`
5175///
5176/// The expanded syntax is only available when the signal has at least one numbered component.
5177#[macro_export]
5178#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5179macro_rules! for_each_analog_function {
5180    ($($pattern:tt => $code:tt;)*) => {
5181        macro_rules! _for_each_inner_analog_function { $(($pattern) => $code;)* ($other :
5182        tt) => {} } _for_each_inner_analog_function!((XTAL_32K_P, GPIO0));
5183        _for_each_inner_analog_function!((XTAL_32K_N, GPIO1));
5184        _for_each_inner_analog_function!((ADC1_CH0, GPIO1));
5185        _for_each_inner_analog_function!((ADC1_CH1, GPIO3));
5186        _for_each_inner_analog_function!((ADC1_CH2, GPIO4));
5187        _for_each_inner_analog_function!((ADC1_CH3, GPIO5));
5188        _for_each_inner_analog_function!((ZCD0, GPIO8));
5189        _for_each_inner_analog_function!((ZCD1, GPIO9));
5190        _for_each_inner_analog_function!((USJ_DM, GPIO12));
5191        _for_each_inner_analog_function!((USJ_DP, GPIO13));
5192        _for_each_inner_analog_function!(((ADC1_CH0, ADCn_CHm, 1, 0), GPIO1));
5193        _for_each_inner_analog_function!(((ADC1_CH1, ADCn_CHm, 1, 1), GPIO3));
5194        _for_each_inner_analog_function!(((ADC1_CH2, ADCn_CHm, 1, 2), GPIO4));
5195        _for_each_inner_analog_function!(((ADC1_CH3, ADCn_CHm, 1, 3), GPIO5));
5196        _for_each_inner_analog_function!(((ZCD0, ZCDn, 0), GPIO8));
5197        _for_each_inner_analog_function!(((ZCD1, ZCDn, 1), GPIO9));
5198        _for_each_inner_analog_function!((all(XTAL_32K_P, GPIO0), (XTAL_32K_N, GPIO1),
5199        (ADC1_CH0, GPIO1), (ADC1_CH1, GPIO3), (ADC1_CH2, GPIO4), (ADC1_CH3, GPIO5),
5200        (ZCD0, GPIO8), (ZCD1, GPIO9), (USJ_DM, GPIO12), (USJ_DP, GPIO13)));
5201        _for_each_inner_analog_function!((ADCn_CHm((ADC1_CH0, ADCn_CHm, 1, 0), GPIO1),
5202        ((ADC1_CH1, ADCn_CHm, 1, 1), GPIO3), ((ADC1_CH2, ADCn_CHm, 1, 2), GPIO4),
5203        ((ADC1_CH3, ADCn_CHm, 1, 3), GPIO5)));
5204        _for_each_inner_analog_function!((ZCDn((ZCD0, ZCDn, 0), GPIO8), ((ZCD1, ZCDn, 1),
5205        GPIO9)));
5206    };
5207}
5208/// This macro can be used to generate code for each LP function of each GPIO.
5209///
5210/// For an explanation on the general syntax, as well as usage of individual/repeated
5211/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
5212///
5213/// This macro has two options for its "Individual matcher" case:
5214///
5215/// - `all`: `($signal:ident, $gpio:ident, $af:ident)` - simple case where you only need
5216///   identifiers, and maybe the function.
5217/// - group: `(($signal:ident, $group:ident $(, $number:literal)+), $gpio:ident, $af:ident, ($(
5218///   $lp_input_af:ident => $lp_input_signal:ident )*) ($( $lp_output_af:ident =>
5219///   $lp_output_signal:ident )*))` - expanded signal case, where you need the number(s) of a
5220///   signal, or the general group to which the signal belongs. Every expanded branch ends with the
5221///   pad's LP input and output function groups (empty on chips without an LP GPIO matrix).
5222///
5223/// Macro fragments:
5224///
5225/// - `$signal`: the name of the signal.
5226/// - `$group`: the name of the signal, with numbers replaced by placeholders. For `ADC2_CH3` this
5227///   is `ADCn_CHm`.
5228/// - `$number`: the numbers extracted from `$signal`.
5229/// - `$gpio`: the name of the GPIO.
5230/// - `$af`: the LP IO MUX function, as an identifier (i.e. for function 0 this is `_0`). This is
5231///   the name of an `LpFunction` variant, and its number is the value to write to the pad's
5232///   function select field.
5233/// - `$lp_input_af`: the LP IO MUX function for an LP peripheral input on this pad.
5234/// - `$lp_input_signal`: the LP peripheral input signal name.
5235/// - `$lp_output_af`: the LP IO MUX function for an LP peripheral output on this pad.
5236/// - `$lp_output_signal`: the LP peripheral output signal name.
5237///
5238/// Example data:
5239/// - `(LP_GPIO15, GPIO12, _0)`
5240/// - `((LP_GPIO15, LP_GPIOn, 15), GPIO12, _0, () ())`
5241/// - `((LP_GPIO14, LP_GPIOn, 14), GPIO14, _1, () (_0 => LP_UART_TXD))`
5242/// - `((SAR_I2C_SCL_1, SAR_I2C_SCL_n, 1), GPIO2, _3, () ())`
5243///
5244/// The expanded syntax is only available when the signal has at least one numbered component.
5245#[macro_export]
5246#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5247macro_rules! for_each_lp_function {
5248    ($($pattern:tt => $code:tt;)*) => {
5249        macro_rules! _for_each_inner_lp_function { $(($pattern) => $code;)* ($other : tt)
5250        => {} } _for_each_inner_lp_function!((LP_GPIO0, GPIO0, _1));
5251        _for_each_inner_lp_function!((LP_GPIO1, GPIO1, _1));
5252        _for_each_inner_lp_function!((LP_GPIO2, GPIO2, _1));
5253        _for_each_inner_lp_function!((LP_GPIO3, GPIO3, _1));
5254        _for_each_inner_lp_function!((LP_GPIO4, GPIO4, _1));
5255        _for_each_inner_lp_function!((LP_GPIO5, GPIO5, _1));
5256        _for_each_inner_lp_function!((LP_GPIO6, GPIO6, _1));
5257        _for_each_inner_lp_function!(((LP_GPIO0, LP_GPIOn, 0), GPIO0, _1, () ()));
5258        _for_each_inner_lp_function!(((LP_GPIO1, LP_GPIOn, 1), GPIO1, _1, () ()));
5259        _for_each_inner_lp_function!(((LP_GPIO2, LP_GPIOn, 2), GPIO2, _1, () ()));
5260        _for_each_inner_lp_function!(((LP_GPIO3, LP_GPIOn, 3), GPIO3, _1, () ()));
5261        _for_each_inner_lp_function!(((LP_GPIO4, LP_GPIOn, 4), GPIO4, _1, () ()));
5262        _for_each_inner_lp_function!(((LP_GPIO5, LP_GPIOn, 5), GPIO5, _1, () ()));
5263        _for_each_inner_lp_function!(((LP_GPIO6, LP_GPIOn, 6), GPIO6, _1, () ()));
5264        _for_each_inner_lp_function!((all(LP_GPIO0, GPIO0, _1), (LP_GPIO1, GPIO1, _1),
5265        (LP_GPIO2, GPIO2, _1), (LP_GPIO3, GPIO3, _1), (LP_GPIO4, GPIO4, _1), (LP_GPIO5,
5266        GPIO5, _1), (LP_GPIO6, GPIO6, _1)));
5267        _for_each_inner_lp_function!((LP_GPIOn((LP_GPIO0, LP_GPIOn, 0), GPIO0, _1, ()
5268        ()), ((LP_GPIO1, LP_GPIOn, 1), GPIO1, _1, () ()), ((LP_GPIO2, LP_GPIOn, 2),
5269        GPIO2, _1, () ()), ((LP_GPIO3, LP_GPIOn, 3), GPIO3, _1, () ()), ((LP_GPIO4,
5270        LP_GPIOn, 4), GPIO4, _1, () ()), ((LP_GPIO5, LP_GPIOn, 5), GPIO5, _1, () ()),
5271        ((LP_GPIO6, LP_GPIOn, 6), GPIO6, _1, () ())));
5272    };
5273}
5274/// This macro can be used to generate code for each IOMUX digital function of each GPIO.
5275///
5276/// IOMUX functions are the alternate digital functions configured via the IO_MUX registers.
5277/// Use this to implement signal-specific traits for peripherals whose pins must bypass the
5278/// GPIO matrix (e.g., EMAC, USB).
5279///
5280/// For an explanation on the general syntax, as well as usage of individual/repeated
5281/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
5282///
5283/// This macro has two options for its "Individual matcher" case:
5284///
5285/// - `all`: `($signal:ident, $gpio:ident, $af:ident)` - simple case where you only need
5286///   identifiers, and maybe the alternate function.
5287/// - group: `(($signal:ident, $group:ident $(, $number:literal)+), $gpio:ident, $af:ident)` -
5288///   expanded signal case, where you need the number(s) of a signal, or the general group to which
5289///   the signal belongs.
5290///
5291/// Macro fragments:
5292///
5293/// - `$signal`: the name of the signal.
5294/// - `$group`: the name of the signal, with numbers replaced by placeholders.
5295/// - `$number`: the numbers extracted from `$signal`.
5296/// - `$gpio`: the name of the GPIO.
5297/// - `$af`: the alternate function number, as an identifier (e.g. `_5`).
5298///
5299/// Example data:
5300/// - `(EMAC_RXD0, GPIO25, _5)`
5301/// - `((EMAC_RXDn, EMAC_RXDn, 0), GPIO25, _5)`
5302///
5303/// The expanded syntax is only available when the signal has at least one numbered component.
5304#[macro_export]
5305#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5306macro_rules! for_each_iomux_function {
5307    ($($pattern:tt => $code:tt;)*) => {
5308        macro_rules! _for_each_inner_iomux_function { $(($pattern) => $code;)* ($other :
5309        tt) => {} } _for_each_inner_iomux_function!((FSPIQ, GPIO2, _2));
5310        _for_each_inner_iomux_function!((MTMS, GPIO3, _0));
5311        _for_each_inner_iomux_function!((FSPIHD, GPIO3, _2));
5312        _for_each_inner_iomux_function!((MTDI, GPIO4, _0));
5313        _for_each_inner_iomux_function!((FSPIWP, GPIO4, _2));
5314        _for_each_inner_iomux_function!((MTCK, GPIO5, _0));
5315        _for_each_inner_iomux_function!((MTDO, GPIO6, _0));
5316        _for_each_inner_iomux_function!((FSPICLK, GPIO6, _2));
5317        _for_each_inner_iomux_function!((FSPID, GPIO7, _2));
5318        _for_each_inner_iomux_function!((FSPICS0, GPIO8, _2));
5319        _for_each_inner_iomux_function!((U0RXD, GPIO10, _0));
5320        _for_each_inner_iomux_function!((U0TXD, GPIO11, _0));
5321        _for_each_inner_iomux_function!((FSPICS1, GPIO14, _0));
5322        _for_each_inner_iomux_function!((FSPICS0, GPIO15, _0));
5323        _for_each_inner_iomux_function!((FSPIQ, GPIO16, _0));
5324        _for_each_inner_iomux_function!((FSPIWP, GPIO17, _0));
5325        _for_each_inner_iomux_function!((FSPIHD, GPIO19, _0));
5326        _for_each_inner_iomux_function!((FSPICLK, GPIO20, _0));
5327        _for_each_inner_iomux_function!((FSPID, GPIO21, _0));
5328        _for_each_inner_iomux_function!((SDIO_DATA2, GPIO22, _0));
5329        _for_each_inner_iomux_function!((SDIO_DATA3, GPIO23, _0));
5330        _for_each_inner_iomux_function!((SDIO_CMD, GPIO25, _0));
5331        _for_each_inner_iomux_function!((SDIO_CLK, GPIO26, _0));
5332        _for_each_inner_iomux_function!((SDIO_DATA0, GPIO27, _0));
5333        _for_each_inner_iomux_function!((SDIO_DATA1, GPIO28, _0));
5334        _for_each_inner_iomux_function!(((FSPICS0, FSPICSn, 0), GPIO8, _2));
5335        _for_each_inner_iomux_function!(((FSPICS1, FSPICSn, 1), GPIO14, _0));
5336        _for_each_inner_iomux_function!(((FSPICS0, FSPICSn, 0), GPIO15, _0));
5337        _for_each_inner_iomux_function!(((SDIO_DATA2, SDIO_DATAn, 2), GPIO22, _0));
5338        _for_each_inner_iomux_function!(((SDIO_DATA3, SDIO_DATAn, 3), GPIO23, _0));
5339        _for_each_inner_iomux_function!(((SDIO_DATA0, SDIO_DATAn, 0), GPIO27, _0));
5340        _for_each_inner_iomux_function!(((SDIO_DATA1, SDIO_DATAn, 1), GPIO28, _0));
5341        _for_each_inner_iomux_function!((all(FSPIQ, GPIO2, _2), (MTMS, GPIO3, _0),
5342        (FSPIHD, GPIO3, _2), (MTDI, GPIO4, _0), (FSPIWP, GPIO4, _2), (MTCK, GPIO5, _0),
5343        (MTDO, GPIO6, _0), (FSPICLK, GPIO6, _2), (FSPID, GPIO7, _2), (FSPICS0, GPIO8,
5344        _2), (U0RXD, GPIO10, _0), (U0TXD, GPIO11, _0), (FSPICS1, GPIO14, _0), (FSPICS0,
5345        GPIO15, _0), (FSPIQ, GPIO16, _0), (FSPIWP, GPIO17, _0), (FSPIHD, GPIO19, _0),
5346        (FSPICLK, GPIO20, _0), (FSPID, GPIO21, _0), (SDIO_DATA2, GPIO22, _0),
5347        (SDIO_DATA3, GPIO23, _0), (SDIO_CMD, GPIO25, _0), (SDIO_CLK, GPIO26, _0),
5348        (SDIO_DATA0, GPIO27, _0), (SDIO_DATA1, GPIO28, _0)));
5349        _for_each_inner_iomux_function!((FSPICSn((FSPICS0, FSPICSn, 0), GPIO8, _2),
5350        ((FSPICS1, FSPICSn, 1), GPIO14, _0), ((FSPICS0, FSPICSn, 0), GPIO15, _0)));
5351        _for_each_inner_iomux_function!((SDIO_DATAn((SDIO_DATA2, SDIO_DATAn, 2), GPIO22,
5352        _0), ((SDIO_DATA3, SDIO_DATAn, 3), GPIO23, _0), ((SDIO_DATA0, SDIO_DATAn, 0),
5353        GPIO27, _0), ((SDIO_DATA1, SDIO_DATAn, 1), GPIO28, _0)));
5354    };
5355}
5356/// Returns the name of the GPIO that provides the given signal, as a string.
5357///
5358/// The macro takes the name of a direct function - a digital IO MUX function, an analog
5359/// function, or an LP IO MUX function - and expands to a string literal like `"GPIO4"`. It
5360/// is meant to keep documentation free of per-chip pin lists.
5361///
5362/// Signals that are not wired to a pad on this chip have to be routed through the GPIO
5363/// matrix, which can reach any pad. The macro has no pad to return for those, so it accepts
5364/// an optional fallback to expand to instead. The fallback is not validated.
5365///
5366/// If multiple pads provide the signal, the macro returns one that is not reserved for some
5367/// other purpose, such as booting or interfacing with flash.
5368///
5369/// Example usage:
5370/// - `gpio_for_signal!(ADC1_CH0)`
5371/// - `gpio_for_signal!(LP_I2C_SDA, "GPIO6")`
5372#[macro_export]
5373#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5374macro_rules! gpio_for_signal {
5375    (XTAL_32K_P $(, $_fallback:literal)?) => {
5376        "GPIO0"
5377    };
5378    (LP_GPIO0 $(, $_fallback:literal)?) => {
5379        "GPIO0"
5380    };
5381    (XTAL_32K_N $(, $_fallback:literal)?) => {
5382        "GPIO1"
5383    };
5384    (ADC1_CH0 $(, $_fallback:literal)?) => {
5385        "GPIO1"
5386    };
5387    (LP_GPIO1 $(, $_fallback:literal)?) => {
5388        "GPIO1"
5389    };
5390    (FSPIQ $(, $_fallback:literal)?) => {
5391        "GPIO2"
5392    };
5393    (LP_GPIO2 $(, $_fallback:literal)?) => {
5394        "GPIO2"
5395    };
5396    (MTMS $(, $_fallback:literal)?) => {
5397        "GPIO3"
5398    };
5399    (FSPIHD $(, $_fallback:literal)?) => {
5400        "GPIO3"
5401    };
5402    (ADC1_CH1 $(, $_fallback:literal)?) => {
5403        "GPIO3"
5404    };
5405    (LP_GPIO3 $(, $_fallback:literal)?) => {
5406        "GPIO3"
5407    };
5408    (MTDI $(, $_fallback:literal)?) => {
5409        "GPIO4"
5410    };
5411    (FSPIWP $(, $_fallback:literal)?) => {
5412        "GPIO4"
5413    };
5414    (ADC1_CH2 $(, $_fallback:literal)?) => {
5415        "GPIO4"
5416    };
5417    (LP_GPIO4 $(, $_fallback:literal)?) => {
5418        "GPIO4"
5419    };
5420    (MTCK $(, $_fallback:literal)?) => {
5421        "GPIO5"
5422    };
5423    (ADC1_CH3 $(, $_fallback:literal)?) => {
5424        "GPIO5"
5425    };
5426    (LP_GPIO5 $(, $_fallback:literal)?) => {
5427        "GPIO5"
5428    };
5429    (MTDO $(, $_fallback:literal)?) => {
5430        "GPIO6"
5431    };
5432    (FSPICLK $(, $_fallback:literal)?) => {
5433        "GPIO6"
5434    };
5435    (LP_GPIO6 $(, $_fallback:literal)?) => {
5436        "GPIO6"
5437    };
5438    (FSPID $(, $_fallback:literal)?) => {
5439        "GPIO7"
5440    };
5441    (FSPICS0 $(, $_fallback:literal)?) => {
5442        "GPIO8"
5443    };
5444    (ZCD0 $(, $_fallback:literal)?) => {
5445        "GPIO8"
5446    };
5447    (ZCD1 $(, $_fallback:literal)?) => {
5448        "GPIO9"
5449    };
5450    (U0RXD $(, $_fallback:literal)?) => {
5451        "GPIO10"
5452    };
5453    (U0TXD $(, $_fallback:literal)?) => {
5454        "GPIO11"
5455    };
5456    (USJ_DM $(, $_fallback:literal)?) => {
5457        "GPIO12"
5458    };
5459    (USJ_DP $(, $_fallback:literal)?) => {
5460        "GPIO13"
5461    };
5462    (FSPICS1 $(, $_fallback:literal)?) => {
5463        "GPIO14"
5464    };
5465    (SDIO_DATA2 $(, $_fallback:literal)?) => {
5466        "GPIO22"
5467    };
5468    (SDIO_DATA3 $(, $_fallback:literal)?) => {
5469        "GPIO23"
5470    };
5471    (SDIO_CMD $(, $_fallback:literal)?) => {
5472        "GPIO25"
5473    };
5474    (SDIO_CLK $(, $_fallback:literal)?) => {
5475        "GPIO26"
5476    };
5477    (SDIO_DATA0 $(, $_fallback:literal)?) => {
5478        "GPIO27"
5479    };
5480    (SDIO_DATA1 $(, $_fallback:literal)?) => {
5481        "GPIO28"
5482    };
5483    ($_signal:ident, $fallback:literal) => {
5484        $fallback
5485    };
5486}
5487/// Defines the `InputSignal` and `OutputSignal` enums.
5488///
5489/// This macro is intended to be called in esp-hal only.
5490#[macro_export]
5491#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5492macro_rules! define_io_mux_signals {
5493    () => {
5494        #[allow(non_camel_case_types, clippy::upper_case_acronyms)]
5495        #[derive(Debug, PartialEq, Copy, Clone)]
5496        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
5497        #[doc(hidden)]
5498        pub enum InputSignal {
5499            U0RXD               = 6,
5500            U0CTS               = 7,
5501            U0DSR               = 8,
5502            U1RXD               = 9,
5503            U1CTS               = 10,
5504            U1DSR               = 11,
5505            I2S_MCLK            = 12,
5506            I2SO_BCK            = 13,
5507            I2SO_WS             = 14,
5508            I2SI_SD             = 15,
5509            I2SI_BCK            = 16,
5510            I2SI_WS             = 17,
5511            CPU_GPIO_0          = 27,
5512            CPU_GPIO_1          = 28,
5513            CPU_GPIO_2          = 29,
5514            CPU_GPIO_3          = 30,
5515            CPU_GPIO_4          = 31,
5516            CPU_GPIO_5          = 32,
5517            CPU_GPIO_6          = 33,
5518            CPU_GPIO_7          = 34,
5519            USB_JTAG_TDO_BRIDGE = 35,
5520            I2CEXT0_SCL         = 46,
5521            I2CEXT0_SDA         = 47,
5522            FSPICLK             = 64,
5523            FSPIQ               = 65,
5524            FSPID               = 66,
5525            FSPIHD              = 67,
5526            FSPIWP              = 68,
5527            FSPICS0             = 69,
5528            U2RXD               = 72,
5529            U2CTS               = 73,
5530            U2DSR               = 74,
5531            SIG_IN_FUNC97       = 97,
5532            SIG_IN_FUNC98       = 98,
5533            SIG_IN_FUNC99       = 99,
5534            SIG_IN_FUNC100      = 100,
5535            SDIO_CLK,
5536            SDIO_CMD,
5537            SDIO_DATA0,
5538            SDIO_DATA1,
5539            SDIO_DATA2,
5540            SDIO_DATA3,
5541            MTDI,
5542            MTDO,
5543            MTCK,
5544            MTMS,
5545        }
5546        #[allow(non_camel_case_types, clippy::upper_case_acronyms)]
5547        #[derive(Debug, PartialEq, Copy, Clone)]
5548        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
5549        #[doc(hidden)]
5550        pub enum OutputSignal {
5551            LEDC_LS_SIG0    = 0,
5552            LEDC_LS_SIG1    = 1,
5553            LEDC_LS_SIG2    = 2,
5554            LEDC_LS_SIG3    = 3,
5555            LEDC_LS_SIG4    = 4,
5556            LEDC_LS_SIG5    = 5,
5557            U0TXD           = 6,
5558            U0RTS           = 7,
5559            U0DTR           = 8,
5560            U1TXD           = 9,
5561            U1RTS           = 10,
5562            U1DTR           = 11,
5563            I2S_MCLK        = 12,
5564            I2SO_BCK        = 13,
5565            I2SO_WS         = 14,
5566            I2SO_SD         = 15,
5567            I2SI_BCK        = 16,
5568            I2SI_WS         = 17,
5569            I2SO_SD1        = 18,
5570            CPU_GPIO_0      = 27,
5571            CPU_GPIO_1      = 28,
5572            CPU_GPIO_2      = 29,
5573            CPU_GPIO_3      = 30,
5574            CPU_GPIO_4      = 31,
5575            CPU_GPIO_5      = 32,
5576            CPU_GPIO_6      = 33,
5577            CPU_GPIO_7      = 34,
5578            I2CEXT0_SCL     = 46,
5579            I2CEXT0_SDA     = 47,
5580            FSPICLK         = 64,
5581            FSPIQ           = 65,
5582            FSPID           = 66,
5583            FSPIHD          = 67,
5584            FSPIWP          = 68,
5585            FSPICS0         = 69,
5586            U2TXD           = 72,
5587            U2RTS           = 73,
5588            U2DTR           = 74,
5589            FSPICS1         = 102,
5590            FSPICS2         = 103,
5591            FSPICS3         = 104,
5592            FSPICS4         = 105,
5593            FSPICS5         = 106,
5594            SDIO_TOHOST_INT = 124,
5595            GPIO            = 256,
5596        }
5597    };
5598}
5599/// Defines the `LpFunction` enum.
5600///
5601/// The enum only contains the LP IO MUX functions that the chip implements. It is
5602/// empty on chips without an LP IO peripheral.
5603///
5604/// This macro is intended to be called in esp-hal only.
5605#[macro_export]
5606#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5607macro_rules! define_lp_functions {
5608    () => {
5609        /// LP IO MUX function of a pad.
5610        ///
5611        /// This is the low-power counterpart of `AlternateFunction`: it selects which function
5612        /// drives a pad while the pad belongs to the low-power domain.
5613        #[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
5614        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
5615        #[doc(hidden)]
5616        pub enum LpFunction {
5617            /// LP IO MUX function 1.
5618            _1 = 1,
5619        }
5620        impl LpFunction {
5621            /// The function that connects the pad to the LP GPIO peripheral.
5622            pub const LP_GPIO: Self = Self::_1;
5623        }
5624    };
5625}
5626/// Defines and implements the `io_mux_reg` function.
5627///
5628/// The generated function has the following signature:
5629///
5630/// ```rust,ignore
5631/// pub(crate) fn io_mux_reg(gpio_num: u8) -> &'static crate::pac::io_mux::GPIO0 {
5632///     // ...
5633/// # unimplemented!()
5634/// }
5635/// ```
5636///
5637/// This macro is intended to be called in esp-hal only.
5638#[macro_export]
5639#[expect(clippy::crate_in_macro_def)]
5640#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5641macro_rules! define_io_mux_reg {
5642    () => {
5643        pub(crate) fn io_mux_reg(gpio_num: u8) -> &'static crate::pac::io_mux::GPIO {
5644            crate::peripherals::IO_MUX::regs().gpio(gpio_num as usize)
5645        }
5646    };
5647}