Skip to main content

esp_metadata_generated/
_generated_esp32c2.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        "esp32c2"
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-C2"
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        "esp32c2"
42    };
43    ("arch") => {
44        "riscv"
45    };
46    ("cores") => {
47        1
48    };
49    ("cores", str) => {
50        stringify!(1)
51    };
52    ("trm") => {
53        "https://www.espressif.com/sites/default/files/documentation/esp8684_technical_reference_manual_en.pdf"
54    };
55    ("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        31
72    };
73    ("gpio.constant_0_input", str) => {
74        stringify!(31)
75    };
76    ("gpio.constant_1_input") => {
77        30
78    };
79    ("gpio.constant_1_input", str) => {
80        stringify!(30)
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        128
105    };
106    ("gpio.output_signal_max", str) => {
107        stringify!(128)
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        "v3"
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        1
135    };
136    ("uart.version", str) => {
137        stringify!(1)
138    };
139    ("uart.peripheral_controls_mem_clk") => {
140        false
141    };
142    ("uart.has_sclk_divider") => {
143        true
144    };
145    ("uart.has_sclk_enable") => {
146        true
147    };
148    ("i2c_master.version") => {
149        3
150    };
151    ("i2c_master.version", str) => {
152        stringify!(3)
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        false
168    };
169    ("i2c_master.has_conf_update") => {
170        true
171    };
172    ("i2c_master.has_reliable_fsm_reset") => {
173        false
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        16
201    };
202    ("i2c_master.fifo_size", str) => {
203        stringify!(16)
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        false
231    };
232    ("spi_master.dma_can_access_flash") => {
233        false
234    };
235    ("bt.controller") => {
236        "npl"
237    };
238    ("bt.requires_fast_cpu") => {
239        false
240    };
241    ("wifi.has_wifi6") => {
242        false
243    };
244    ("wifi.mac_version") => {
245        1
246    };
247    ("wifi.mac_version", str) => {
248        stringify!(1)
249    };
250    ("wifi.has_5g") => {
251        false
252    };
253    ("wifi.csi_supported") => {
254        false
255    };
256    ("wifi.has_nan") => {
257        false
258    };
259    ("wifi.has_ftm") => {
260        true
261    };
262    ("wifi.requires_fast_cpu") => {
263        false
264    };
265    ("phy.combo_module") => {
266        true
267    };
268    ("adc.controller") => {
269        "digital"
270    };
271    ("adc.channel_count") => {
272        5
273    };
274    ("adc.channel_count", str) => {
275        stringify!(5)
276    };
277    ("adc.line_calibration") => {
278        true
279    };
280    ("adc.curve_calibration") => {
281        false
282    };
283    ("adc.basic_calibration") => {
284        true
285    };
286    ("adc.calibration_v1_scheme_supported") => {
287        true
288    };
289    ("adc.channel_compensation") => {
290        false
291    };
292    ("adc.pcr_clock") => {
293        false
294    };
295    ("adc.pcr_sar_clk_div") => {
296        false
297    };
298    ("adc.sar_power_override") => {
299        false
300    };
301    ("ledc.version") => {
302        2
303    };
304    ("ledc.version", str) => {
305        stringify!(2)
306    };
307    ("ledc.channel_count") => {
308        6
309    };
310    ("ledc.channel_count", str) => {
311        stringify!(6)
312    };
313    ("timergroup.timg_has_timer1") => {
314        false
315    };
316    ("timergroup.timg_has_divcnt_rst") => {
317        true
318    };
319    ("timergroup.wdt_has_conf_update") => {
320        true
321    };
322    ("ecc.zero_extend_writes") => {
323        true
324    };
325    ("ecc.separate_jacobian_point_memory") => {
326        false
327    };
328    ("ecc.has_memory_clock_gate") => {
329        false
330    };
331    ("ecc.supports_enhanced_security") => {
332        false
333    };
334    ("ecc.mem_block_size") => {
335        32
336    };
337    ("rng.apb_cycle_wait_num") => {
338        16
339    };
340    ("rng.apb_cycle_wait_num", str) => {
341        stringify!(16)
342    };
343    ("rng.trng_supported") => {
344        true
345    };
346    ("rng.is_lp_sys") => {
347        false
348    };
349    ("sleep.light_sleep") => {
350        true
351    };
352    ("sleep.deep_sleep") => {
353        true
354    };
355    ("sleep.rejectable_mask") => {
356        1068
357    };
358    ("sleep.pin_wakeup_version") => {
359        2
360    };
361    ("sleep.pin_wakeup_version", str) => {
362        stringify!(2)
363    };
364    ("sleep.deep_sleep_needs_gpio_isolation") => {
365        true
366    };
367    ("sleep.idle_frequency_scaling") => {
368        false
369    };
370    ("assist_debug.has_sp_monitor") => {
371        true
372    };
373    ("assist_debug.has_region_monitor") => {
374        false
375    };
376    ("dma.mem2mem_requires_peripheral") => {
377        false
378    };
379    ("dma.ext_mem_configurable_block_size") => {
380        false
381    };
382    ("dma.separate_in_out_interrupts") => {
383        false
384    };
385    ("dma.gdma_version") => {
386        1
387    };
388    ("dma.gdma_version", str) => {
389        stringify!(1)
390    };
391    ("interrupts.status_registers") => {
392        2
393    };
394    ("interrupts.status_registers", str) => {
395        stringify!(2)
396    };
397    ("interrupts.disabled_interrupt") => {
398        0
399    };
400    ("mmu.page_size") => {
401        65536
402    };
403    ("mmu.page_size", str) => {
404        stringify!(65536)
405    };
406    ("mmu.entry_num") => {
407        64
408    };
409    ("mmu.entry_num", str) => {
410        stringify!(64)
411    };
412    ("rom.has_crc_le") => {
413        true
414    };
415    ("rom.has_crc_be") => {
416        true
417    };
418    ("rom.has_md5_bsd") => {
419        false
420    };
421    ("rom.has_md5_mbedtls") => {
422        true
423    };
424    ("rom.no_libgcc") => {
425        false
426    };
427    ("soc.cpu_has_branch_predictor") => {
428        false
429    };
430    ("soc.cpu_has_csr_pc") => {
431        true
432    };
433    ("soc.cpu_has_zcmp_workaround") => {
434        false
435    };
436    ("soc.multi_core_enabled") => {
437        false
438    };
439    ("soc.cpu_pma_needs_core1_setup") => {
440        false
441    };
442    ("soc.internal_memory_cached") => {
443        false
444    };
445    ("soc.cpu_powers_down_cache") => {
446        false
447    };
448    ("soc.has_swd_watchdog") => {
449        true
450    };
451    ("soc.has_bus_clock_update") => {
452        false
453    };
454    ("soc.has_apb_frequency_reduction") => {
455        false
456    };
457    ("soc.cpu_mcause_mask") => {
458        31
459    };
460    ("soc.cpu_mcause_mask", str) => {
461        stringify!(31)
462    };
463    ("soc.cpu_pmp_granularity") => {
464        4
465    };
466    ("soc.cpu_pmp_granularity", str) => {
467        stringify!(4)
468    };
469    ("clock_tree.system_pre_div_in") => {
470        [crate ::soc::clocks::SystemPreDivInConfig::Xtal, crate
471        ::soc::clocks::SystemPreDivInConfig::RcFast]
472    };
473    ("clock_tree.system_pre_div.divisor") => {
474        (0, 1023)
475    };
476    ("clock_tree.cpu_pll_div.divisor") => {
477        [4, 6]
478    };
479    ("clock_tree.cpu_clk") => {
480        [crate ::soc::clocks::CpuClkConfig::Xtal, crate
481        ::soc::clocks::CpuClkConfig::RcFast, crate ::soc::clocks::CpuClkConfig::Pll]
482    };
483    ("clock_tree.apb_clk") => {
484        [crate ::soc::clocks::ApbClkConfig::Pll40m, crate
485        ::soc::clocks::ApbClkConfig::Cpu]
486    };
487    ("clock_tree.crypto_clk") => {
488        [crate ::soc::clocks::CryptoClkConfig::Pll80m, crate
489        ::soc::clocks::CryptoClkConfig::Cpu]
490    };
491    ("clock_tree.mspi_clk") => {
492        [crate ::soc::clocks::MspiClkConfig::CpuDiv2, crate
493        ::soc::clocks::MspiClkConfig::Cpu]
494    };
495    ("clock_tree.rc_fast_clk_div_n.divisor") => {
496        (0, 3)
497    };
498    ("clock_tree.rtc_slow_clk") => {
499        [crate ::soc::clocks::RtcSlowClkConfig::OscSlow, crate
500        ::soc::clocks::RtcSlowClkConfig::RcSlow, crate
501        ::soc::clocks::RtcSlowClkConfig::RcFast]
502    };
503    ("clock_tree.ble_lp_clk.sclk") => {
504        [crate ::soc::clocks::BleLpClkSclk::Xtal, crate
505        ::soc::clocks::BleLpClkSclk::RcSlow]
506    };
507    ("clock_tree.ble_lp_clk.divisor") => {
508        (0, 255)
509    };
510    ("clock_tree.rtc_fast_clk") => {
511        [crate ::soc::clocks::RtcFastClkConfig::Xtal, crate
512        ::soc::clocks::RtcFastClkConfig::Rc]
513    };
514    ("clock_tree.low_power_clk") => {
515        [crate ::soc::clocks::LowPowerClkConfig::Xtal, crate
516        ::soc::clocks::LowPowerClkConfig::RcFast, crate
517        ::soc::clocks::LowPowerClkConfig::OscSlow, crate
518        ::soc::clocks::LowPowerClkConfig::RtcSlow]
519    };
520    ("clock_tree.timg_calibration_clock") => {
521        [crate ::soc::clocks::TimgCalibrationClockConfig::RcSlowClk, crate
522        ::soc::clocks::TimgCalibrationClockConfig::RcFastDivClk, crate
523        ::soc::clocks::TimgCalibrationClockConfig::Osc32kClk]
524    };
525    ("clock_tree.timg.function_clock") => {
526        [crate ::soc::clocks::TimgFunctionClockConfig::XtalClk, crate
527        ::soc::clocks::TimgFunctionClockConfig::Pll40m]
528    };
529    ("clock_tree.timg.wdt_clock") => {
530        [crate ::soc::clocks::TimgWdtClockConfig::Pll40m, crate
531        ::soc::clocks::TimgWdtClockConfig::XtalClk]
532    };
533    ("clock_tree.uart.function_clock.sclk") => {
534        [crate ::soc::clocks::UartFunctionClockSclk::PllF40m, crate
535        ::soc::clocks::UartFunctionClockSclk::RcFast, crate
536        ::soc::clocks::UartFunctionClockSclk::Xtal]
537    };
538    ("clock_tree.uart.function_clock.div_num") => {
539        (0, 255)
540    };
541    ("clock_tree.uart.baud_rate_generator.fractional") => {
542        (0, 15)
543    };
544    ("clock_tree.uart.baud_rate_generator.integral") => {
545        (0, 4095)
546    };
547    ("clock_tree.i2c.function_clock.sclk") => {
548        [crate ::soc::clocks::I2cFunctionClockSclk::Xtal, crate
549        ::soc::clocks::I2cFunctionClockSclk::RcFast]
550    };
551    ("clock_tree.i2c.function_clock.div_num") => {
552        (0, 255)
553    };
554    ("clock_tree.spi.function_clock") => {
555        [crate ::soc::clocks::SpiFunctionClockConfig::Xtal, crate
556        ::soc::clocks::SpiFunctionClockConfig::Pll40m]
557    };
558}
559#[macro_export]
560#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
561macro_rules! for_each_dedicated_gpio {
562    ($($pattern:tt => $code:tt;)*) => {
563        macro_rules! _for_each_inner_dedicated_gpio { $(($pattern) => $code;)* ($other :
564        tt) => {} } _for_each_inner_dedicated_gpio!((0));
565        _for_each_inner_dedicated_gpio!((1)); _for_each_inner_dedicated_gpio!((2));
566        _for_each_inner_dedicated_gpio!((3)); _for_each_inner_dedicated_gpio!((4));
567        _for_each_inner_dedicated_gpio!((5)); _for_each_inner_dedicated_gpio!((6));
568        _for_each_inner_dedicated_gpio!((7)); _for_each_inner_dedicated_gpio!((0, 0,
569        CPU_GPIO_0)); _for_each_inner_dedicated_gpio!((0, 1, CPU_GPIO_1));
570        _for_each_inner_dedicated_gpio!((0, 2, CPU_GPIO_2));
571        _for_each_inner_dedicated_gpio!((0, 3, CPU_GPIO_3));
572        _for_each_inner_dedicated_gpio!((0, 4, CPU_GPIO_4));
573        _for_each_inner_dedicated_gpio!((0, 5, CPU_GPIO_5));
574        _for_each_inner_dedicated_gpio!((0, 6, CPU_GPIO_6));
575        _for_each_inner_dedicated_gpio!((0, 7, CPU_GPIO_7));
576        _for_each_inner_dedicated_gpio!((channels(0), (1), (2), (3), (4), (5), (6),
577        (7))); _for_each_inner_dedicated_gpio!((signals(0, 0, CPU_GPIO_0), (0, 1,
578        CPU_GPIO_1), (0, 2, CPU_GPIO_2), (0, 3, CPU_GPIO_3), (0, 4, CPU_GPIO_4), (0, 5,
579        CPU_GPIO_5), (0, 6, CPU_GPIO_6), (0, 7, CPU_GPIO_7)));
580    };
581}
582/// Defines the `LpInputSignal` and `LpOutputSignal` enums.
583///
584/// This macro is intended to be called in esp-hal only.
585#[macro_export]
586#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
587macro_rules! define_lp_io_signals {
588    () => {};
589}
590#[macro_export]
591#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
592macro_rules! for_each_ecc_working_mode {
593    ($($pattern:tt => $code:tt;)*) => {
594        macro_rules! _for_each_inner_ecc_working_mode { $(($pattern) => $code;)* ($other
595        : tt) => {} } _for_each_inner_ecc_working_mode!((0, AffinePointMultiplication));
596        _for_each_inner_ecc_working_mode!((1, FiniteFieldDivision));
597        _for_each_inner_ecc_working_mode!((2, AffinePointVerification));
598        _for_each_inner_ecc_working_mode!((3, AffinePointVerificationAndMultiplication));
599        _for_each_inner_ecc_working_mode!((4, JacobianPointMultiplication));
600        _for_each_inner_ecc_working_mode!((6, JacobianPointVerification));
601        _for_each_inner_ecc_working_mode!((7,
602        AffinePointVerificationAndJacobianPointMultiplication));
603        _for_each_inner_ecc_working_mode!((all(0, AffinePointMultiplication), (1,
604        FiniteFieldDivision), (2, AffinePointVerification), (3,
605        AffinePointVerificationAndMultiplication), (4, JacobianPointMultiplication), (6,
606        JacobianPointVerification), (7,
607        AffinePointVerificationAndJacobianPointMultiplication)));
608    };
609}
610#[macro_export]
611#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
612macro_rules! for_each_ecc_curve {
613    ($($pattern:tt => $code:tt;)*) => {
614        macro_rules! _for_each_inner_ecc_curve { $(($pattern) => $code;)* ($other : tt)
615        => {} } _for_each_inner_ecc_curve!((0, P192, 192));
616        _for_each_inner_ecc_curve!((1, P256, 256)); _for_each_inner_ecc_curve!((all(0,
617        P192, 192), (1, P256, 256)));
618    };
619}
620#[macro_export]
621#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
622macro_rules! for_each_sha_algorithm {
623    ($($pattern:tt => $code:tt;)*) => {
624        macro_rules! _for_each_inner_sha_algorithm { $(($pattern) => $code;)* ($other :
625        tt) => {} } _for_each_inner_sha_algorithm!((Sha1, "SHA-1"(sizes : 64, 20, 8)
626        (insecure_against : "collision", "length extension"), 0));
627        _for_each_inner_sha_algorithm!((Sha224, "SHA-224"(sizes : 64, 28, 8)
628        (insecure_against : "length extension"), 1));
629        _for_each_inner_sha_algorithm!((Sha256, "SHA-256"(sizes : 64, 32, 8)
630        (insecure_against : "length extension"), 2));
631        _for_each_inner_sha_algorithm!((algos(Sha1, "SHA-1"(sizes : 64, 20, 8)
632        (insecure_against : "collision", "length extension"), 0), (Sha224,
633        "SHA-224"(sizes : 64, 28, 8) (insecure_against : "length extension"), 1),
634        (Sha256, "SHA-256"(sizes : 64, 32, 8) (insecure_against : "length extension"),
635        2)));
636    };
637}
638#[macro_export]
639#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
640macro_rules! for_each_wakeup_source {
641    ($($pattern:tt => $code:tt;)*) => {
642        macro_rules! _for_each_inner_wakeup_source { $(($pattern) => $code;)* ($other :
643        tt) => {} } _for_each_inner_wakeup_source!((Gpio, 2));
644        _for_each_inner_wakeup_source!((Timer, 3)); _for_each_inner_wakeup_source!((Wifi,
645        5)); _for_each_inner_wakeup_source!((Uart0, 6));
646        _for_each_inner_wakeup_source!((Uart1, 7)); _for_each_inner_wakeup_source!((Bt,
647        10)); _for_each_inner_wakeup_source!((all(Gpio, 2), (Timer, 3), (Wifi, 5),
648        (Uart0, 6), (Uart1, 7), (Bt, 10)));
649    };
650}
651#[macro_export]
652#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
653macro_rules! for_each_dma_engine {
654    ($($pattern:tt => $code:tt;)*) => {
655        macro_rules! _for_each_inner_dma_engine { $(($pattern) => $code;)* ($other : tt)
656        => {} } _for_each_inner_dma_engine!(("AHB_GDMA"));
657        _for_each_inner_dma_engine!((all("AHB_GDMA")));
658    };
659}
660#[macro_export]
661#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
662macro_rules! for_each_dma_channel {
663    ($($pattern:tt => $code:tt;)*) => {
664        macro_rules! _for_each_inner_dma_channel { $(($pattern) => $code;)* ($other : tt)
665        => {} } _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH0));
666        _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH0, 0, interrupt = DMA_CH0,
667        compatible = [SPI2, SHA])); _for_each_inner_dma_channel!((names("AHB_GDMA",
668        DMA_CH0))); _for_each_inner_dma_channel!((separate_any_type));
669        _for_each_inner_dma_channel!((shared("AHB_GDMA", DMA_CH0, 0, interrupt = DMA_CH0,
670        compatible = [SPI2, SHA]))); _for_each_inner_dma_channel!((split));
671        _for_each_inner_dma_channel!((no_own_interrupt));
672    };
673}
674#[macro_export]
675#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
676macro_rules! for_each_dma_channel_peri_pair {
677    ($($pattern:tt => $code:tt;)*) => {
678        macro_rules! _for_each_inner_dma_channel_peri_pair { $(($pattern) => $code;)*
679        ($other : tt) => {} } _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA",
680        DMA_CH0, SPI2)); _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH0,
681        SHA)); _for_each_inner_dma_channel_peri_pair!((channels("AHB_GDMA", DMA_CH0,
682        SPI2), ("AHB_GDMA", DMA_CH0, SHA)));
683        _for_each_inner_dma_channel_peri_pair!((any_channels));
684    };
685}
686#[macro_export]
687#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
688macro_rules! for_each_mem2mem_channel {
689    ($($pattern:tt => $code:tt;)*) => {
690        macro_rules! _for_each_inner_mem2mem_channel { $(($pattern) => $code;)* ($other :
691        tt) => {} } _for_each_inner_mem2mem_channel!(("AHB_GDMA", AhbGdma,
692        AhbGdmaChannel, DMA_CH0, 2)); _for_each_inner_mem2mem_channel!(("AHB_GDMA",
693        AhbGdma, AhbGdmaChannel, 0, 2)); _for_each_inner_mem2mem_channel!(("AHB_GDMA",
694        AhbGdma, AhbGdmaChannel)); _for_each_inner_mem2mem_channel!((channels("AHB_GDMA",
695        AhbGdma, AhbGdmaChannel, DMA_CH0, 2)));
696        _for_each_inner_mem2mem_channel!((erased("AHB_GDMA", AhbGdma, AhbGdmaChannel, 0,
697        2))); _for_each_inner_mem2mem_channel!((engines("AHB_GDMA", AhbGdma,
698        AhbGdmaChannel)));
699    };
700}
701#[macro_export]
702#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
703macro_rules! with_sha_dma_engine {
704    ($($pattern:tt => $code:tt;)*) => {
705        macro_rules! _with_inner_sha_dma_engine { $(($pattern) => $code;)* ($other : tt)
706        => {} } _with_inner_sha_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
707    };
708}
709#[macro_export]
710#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
711macro_rules! with_spi_master_dma_engine {
712    ($($pattern:tt => $code:tt;)*) => {
713        macro_rules! _with_inner_spi_master_dma_engine { $(($pattern) => $code;)* ($other
714        : tt) => {} } _with_inner_spi_master_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
715    };
716}
717#[macro_export]
718#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
719macro_rules! with_spi_slave_dma_engine {
720    ($($pattern:tt => $code:tt;)*) => {
721        macro_rules! _with_inner_spi_slave_dma_engine { $(($pattern) => $code;)* ($other
722        : tt) => {} } _with_inner_spi_slave_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
723    };
724}
725#[macro_export]
726#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
727macro_rules! for_each_interrupt {
728    ($($pattern:tt => $code:tt;)*) => {
729        macro_rules! _for_each_inner_interrupt { $(($pattern) => $code;)* ($other : tt)
730        => {} } _for_each_inner_interrupt!(([disabled 0] 0));
731        _for_each_inner_interrupt!(([reserved 0] 1));
732        _for_each_inner_interrupt!(([context_switch 0] 2));
733        _for_each_inner_interrupt!(([direct_bindable 0] 3));
734        _for_each_inner_interrupt!(([direct_bindable 1] 4));
735        _for_each_inner_interrupt!(([direct_bindable 2] 5));
736        _for_each_inner_interrupt!(([direct_bindable 3] 6));
737        _for_each_inner_interrupt!(([direct_bindable 4] 7));
738        _for_each_inner_interrupt!(([direct_bindable 5] 8));
739        _for_each_inner_interrupt!(([direct_bindable 6] 9));
740        _for_each_inner_interrupt!(([direct_bindable 7] 10));
741        _for_each_inner_interrupt!(([direct_bindable 8] 11));
742        _for_each_inner_interrupt!(([direct_bindable 9] 12));
743        _for_each_inner_interrupt!(([direct_bindable 10] 13));
744        _for_each_inner_interrupt!(([direct_bindable 11] 14));
745        _for_each_inner_interrupt!(([direct_bindable 12] 15));
746        _for_each_inner_interrupt!(([direct_bindable 13] 16));
747        _for_each_inner_interrupt!(([vector 0] 17)); _for_each_inner_interrupt!(([vector
748        1] 18)); _for_each_inner_interrupt!(([vector 2] 19));
749        _for_each_inner_interrupt!(([vector 3] 20)); _for_each_inner_interrupt!(([vector
750        4] 21)); _for_each_inner_interrupt!(([vector 5] 22));
751        _for_each_inner_interrupt!(([vector 6] 23)); _for_each_inner_interrupt!(([vector
752        7] 24)); _for_each_inner_interrupt!(([vector 8] 25));
753        _for_each_inner_interrupt!(([vector 9] 26)); _for_each_inner_interrupt!(([vector
754        10] 27)); _for_each_inner_interrupt!(([vector 11] 28));
755        _for_each_inner_interrupt!(([vector 12] 29)); _for_each_inner_interrupt!(([vector
756        13] 30)); _for_each_inner_interrupt!(([vector 14] 31));
757        _for_each_inner_interrupt!((all([disabled 0] 0), ([reserved 0] 1),
758        ([context_switch 0] 2), ([direct_bindable 0] 3), ([direct_bindable 1] 4),
759        ([direct_bindable 2] 5), ([direct_bindable 3] 6), ([direct_bindable 4] 7),
760        ([direct_bindable 5] 8), ([direct_bindable 6] 9), ([direct_bindable 7] 10),
761        ([direct_bindable 8] 11), ([direct_bindable 9] 12), ([direct_bindable 10] 13),
762        ([direct_bindable 11] 14), ([direct_bindable 12] 15), ([direct_bindable 13] 16),
763        ([vector 0] 17), ([vector 1] 18), ([vector 2] 19), ([vector 3] 20), ([vector 4]
764        21), ([vector 5] 22), ([vector 6] 23), ([vector 7] 24), ([vector 8] 25), ([vector
765        9] 26), ([vector 10] 27), ([vector 11] 28), ([vector 12] 29), ([vector 13] 30),
766        ([vector 14] 31)));
767    };
768}
769#[macro_export]
770#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
771macro_rules! for_each_classified_interrupt {
772    ($($pattern:tt => $code:tt;)*) => {
773        macro_rules! _for_each_inner_classified_interrupt { $(($pattern) => $code;)*
774        ($other : tt) => {} } _for_each_inner_classified_interrupt!(([direct_bindable 0]
775        3)); _for_each_inner_classified_interrupt!(([direct_bindable 1] 4));
776        _for_each_inner_classified_interrupt!(([direct_bindable 2] 5));
777        _for_each_inner_classified_interrupt!(([direct_bindable 3] 6));
778        _for_each_inner_classified_interrupt!(([direct_bindable 4] 7));
779        _for_each_inner_classified_interrupt!(([direct_bindable 5] 8));
780        _for_each_inner_classified_interrupt!(([direct_bindable 6] 9));
781        _for_each_inner_classified_interrupt!(([direct_bindable 7] 10));
782        _for_each_inner_classified_interrupt!(([direct_bindable 8] 11));
783        _for_each_inner_classified_interrupt!(([direct_bindable 9] 12));
784        _for_each_inner_classified_interrupt!(([direct_bindable 10] 13));
785        _for_each_inner_classified_interrupt!(([direct_bindable 11] 14));
786        _for_each_inner_classified_interrupt!(([direct_bindable 12] 15));
787        _for_each_inner_classified_interrupt!(([direct_bindable 13] 16));
788        _for_each_inner_classified_interrupt!(([vector 0] 17));
789        _for_each_inner_classified_interrupt!(([vector 1] 18));
790        _for_each_inner_classified_interrupt!(([vector 2] 19));
791        _for_each_inner_classified_interrupt!(([vector 3] 20));
792        _for_each_inner_classified_interrupt!(([vector 4] 21));
793        _for_each_inner_classified_interrupt!(([vector 5] 22));
794        _for_each_inner_classified_interrupt!(([vector 6] 23));
795        _for_each_inner_classified_interrupt!(([vector 7] 24));
796        _for_each_inner_classified_interrupt!(([vector 8] 25));
797        _for_each_inner_classified_interrupt!(([vector 9] 26));
798        _for_each_inner_classified_interrupt!(([vector 10] 27));
799        _for_each_inner_classified_interrupt!(([vector 11] 28));
800        _for_each_inner_classified_interrupt!(([vector 12] 29));
801        _for_each_inner_classified_interrupt!(([vector 13] 30));
802        _for_each_inner_classified_interrupt!(([vector 14] 31));
803        _for_each_inner_classified_interrupt!(([reserved 0] 1));
804        _for_each_inner_classified_interrupt!(([context_switch 0] 2));
805        _for_each_inner_classified_interrupt!((direct_bindable([direct_bindable 0] 3),
806        ([direct_bindable 1] 4), ([direct_bindable 2] 5), ([direct_bindable 3] 6),
807        ([direct_bindable 4] 7), ([direct_bindable 5] 8), ([direct_bindable 6] 9),
808        ([direct_bindable 7] 10), ([direct_bindable 8] 11), ([direct_bindable 9] 12),
809        ([direct_bindable 10] 13), ([direct_bindable 11] 14), ([direct_bindable 12] 15),
810        ([direct_bindable 13] 16)));
811        _for_each_inner_classified_interrupt!((vector([vector 0] 17), ([vector 1] 18),
812        ([vector 2] 19), ([vector 3] 20), ([vector 4] 21), ([vector 5] 22), ([vector 6]
813        23), ([vector 7] 24), ([vector 8] 25), ([vector 9] 26), ([vector 10] 27),
814        ([vector 11] 28), ([vector 12] 29), ([vector 13] 30), ([vector 14] 31)));
815        _for_each_inner_classified_interrupt!((reserved([reserved 0] 1)));
816        _for_each_inner_classified_interrupt!((context_switch([context_switch 0] 2)));
817    };
818}
819#[macro_export]
820#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
821macro_rules! for_each_interrupt_priority {
822    ($($pattern:tt => $code:tt;)*) => {
823        macro_rules! _for_each_inner_interrupt_priority { $(($pattern) => $code;)*
824        ($other : tt) => {} } _for_each_inner_interrupt_priority!((0, 1, Priority1,
825        Level1)); _for_each_inner_interrupt_priority!((1, 2, Priority2, Level2));
826        _for_each_inner_interrupt_priority!((2, 3, Priority3, Level3));
827        _for_each_inner_interrupt_priority!((3, 4, Priority4, Level4));
828        _for_each_inner_interrupt_priority!((4, 5, Priority5, Level5));
829        _for_each_inner_interrupt_priority!((5, 6, Priority6, Level6));
830        _for_each_inner_interrupt_priority!((6, 7, Priority7, Level7));
831        _for_each_inner_interrupt_priority!((7, 8, Priority8, Level8));
832        _for_each_inner_interrupt_priority!((8, 9, Priority9, Level9));
833        _for_each_inner_interrupt_priority!((9, 10, Priority10, Level10));
834        _for_each_inner_interrupt_priority!((10, 11, Priority11, Level11));
835        _for_each_inner_interrupt_priority!((11, 12, Priority12, Level12));
836        _for_each_inner_interrupt_priority!((12, 13, Priority13, Level13));
837        _for_each_inner_interrupt_priority!((13, 14, Priority14, Level14));
838        _for_each_inner_interrupt_priority!((14, 15, Priority15, Level15));
839        _for_each_inner_interrupt_priority!((all(0, 1, Priority1, Level1), (1, 2,
840        Priority2, Level2), (2, 3, Priority3, Level3), (3, 4, Priority4, Level4), (4, 5,
841        Priority5, Level5), (5, 6, Priority6, Level6), (6, 7, Priority7, Level7), (7, 8,
842        Priority8, Level8), (8, 9, Priority9, Level9), (9, 10, Priority10, Level10), (10,
843        11, Priority11, Level11), (11, 12, Priority12, Level12), (12, 13, Priority13,
844        Level13), (13, 14, Priority14, Level14), (14, 15, Priority15, Level15)));
845    };
846}
847#[macro_export]
848#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
849macro_rules! for_each_sw_interrupt {
850    ($($pattern:tt => $code:tt;)*) => {
851        macro_rules! _for_each_inner_sw_interrupt { $(($pattern) => $code;)* ($other :
852        tt) => {} } _for_each_inner_sw_interrupt!((0, FROM_CPU_INTR0,
853        software_interrupt0)); _for_each_inner_sw_interrupt!((1, FROM_CPU_INTR1,
854        software_interrupt1)); _for_each_inner_sw_interrupt!((2, FROM_CPU_INTR2,
855        software_interrupt2)); _for_each_inner_sw_interrupt!((3, FROM_CPU_INTR3,
856        software_interrupt3)); _for_each_inner_sw_interrupt!((all(0, FROM_CPU_INTR0,
857        software_interrupt0), (1, FROM_CPU_INTR1, software_interrupt1), (2,
858        FROM_CPU_INTR2, software_interrupt2), (3, FROM_CPU_INTR3, software_interrupt3)));
859    };
860}
861#[macro_export]
862/// ESP-HAL must provide implementation for the following functions:
863/// ```rust, no_run
864/// // XTAL_CLK
865///
866/// fn configure_xtal_clk_impl(
867///     _clocks: &mut ClockTree,
868///     _old_config: Option<XtalClkConfig>,
869///     _new_config: XtalClkConfig,
870/// ) {
871///     todo!()
872/// }
873///
874/// // PLL_CLK
875///
876/// fn enable_pll_clk_impl(_clocks: &mut ClockTree, _en: bool) {
877///     todo!()
878/// }
879///
880/// // RC_FAST_CLK
881///
882/// fn enable_rc_fast_clk_impl(_clocks: &mut ClockTree, _en: bool) {
883///     todo!()
884/// }
885///
886/// // OSC_SLOW_CLK
887///
888/// fn enable_osc_slow_clk_impl(_clocks: &mut ClockTree, _en: bool) {
889///     todo!()
890/// }
891///
892/// // RC_SLOW_CLK
893///
894/// fn enable_rc_slow_clk_impl(_clocks: &mut ClockTree, _en: bool) {
895///     todo!()
896/// }
897///
898/// // RC_FAST_DIV_CLK
899///
900/// fn enable_rc_fast_div_clk_impl(_clocks: &mut ClockTree, _en: bool) {
901///     todo!()
902/// }
903///
904/// // SYSTEM_PRE_DIV_IN
905///
906/// fn enable_system_pre_div_in_impl(_clocks: &mut ClockTree, _en: bool) {
907///     todo!()
908/// }
909///
910/// fn configure_system_pre_div_in_impl(
911///     _clocks: &mut ClockTree,
912///     _old_config: Option<SystemPreDivInConfig>,
913///     _new_config: SystemPreDivInConfig,
914/// ) {
915///     todo!()
916/// }
917///
918/// // SYSTEM_PRE_DIV
919///
920/// fn enable_system_pre_div_impl(_clocks: &mut ClockTree, _en: bool) {
921///     todo!()
922/// }
923///
924/// fn configure_system_pre_div_impl(
925///     _clocks: &mut ClockTree,
926///     _old_config: Option<SystemPreDivConfig>,
927///     _new_config: SystemPreDivConfig,
928/// ) {
929///     todo!()
930/// }
931///
932/// // CPU_PLL_DIV
933///
934/// fn enable_cpu_pll_div_impl(_clocks: &mut ClockTree, _en: bool) {
935///     todo!()
936/// }
937///
938/// fn configure_cpu_pll_div_impl(
939///     _clocks: &mut ClockTree,
940///     _old_config: Option<CpuPllDivConfig>,
941///     _new_config: CpuPllDivConfig,
942/// ) {
943///     todo!()
944/// }
945///
946/// // APB_CLK
947///
948/// fn enable_apb_clk_impl(_clocks: &mut ClockTree, _en: bool) {
949///     todo!()
950/// }
951///
952/// fn configure_apb_clk_impl(
953///     _clocks: &mut ClockTree,
954///     _old_config: Option<ApbClkConfig>,
955///     _new_config: ApbClkConfig,
956/// ) {
957///     todo!()
958/// }
959///
960/// // CRYPTO_CLK
961///
962/// fn enable_crypto_clk_impl(_clocks: &mut ClockTree, _en: bool) {
963///     todo!()
964/// }
965///
966/// fn configure_crypto_clk_impl(
967///     _clocks: &mut ClockTree,
968///     _old_config: Option<CryptoClkConfig>,
969///     _new_config: CryptoClkConfig,
970/// ) {
971///     todo!()
972/// }
973///
974/// // MSPI_CLK
975///
976/// fn enable_mspi_clk_impl(_clocks: &mut ClockTree, _en: bool) {
977///     todo!()
978/// }
979///
980/// fn configure_mspi_clk_impl(
981///     _clocks: &mut ClockTree,
982///     _old_config: Option<MspiClkConfig>,
983///     _new_config: MspiClkConfig,
984/// ) {
985///     todo!()
986/// }
987///
988/// // CPU_CLK
989///
990/// fn configure_cpu_clk_impl(
991///     _clocks: &mut ClockTree,
992///     _old_config: Option<CpuClkConfig>,
993///     _new_config: CpuClkConfig,
994/// ) {
995///     todo!()
996/// }
997///
998/// // PLL_40M
999///
1000/// fn enable_pll_40m_impl(_clocks: &mut ClockTree, _en: bool) {
1001///     todo!()
1002/// }
1003///
1004/// // PLL_60M
1005///
1006/// fn enable_pll_60m_impl(_clocks: &mut ClockTree, _en: bool) {
1007///     todo!()
1008/// }
1009///
1010/// // PLL_80M
1011///
1012/// fn enable_pll_80m_impl(_clocks: &mut ClockTree, _en: bool) {
1013///     todo!()
1014/// }
1015///
1016/// // CPU_DIV2
1017///
1018/// fn enable_cpu_div2_impl(_clocks: &mut ClockTree, _en: bool) {
1019///     todo!()
1020/// }
1021///
1022/// // RC_FAST_CLK_DIV_N
1023///
1024/// fn enable_rc_fast_clk_div_n_impl(_clocks: &mut ClockTree, _en: bool) {
1025///     todo!()
1026/// }
1027///
1028/// fn configure_rc_fast_clk_div_n_impl(
1029///     _clocks: &mut ClockTree,
1030///     _old_config: Option<RcFastClkDivNConfig>,
1031///     _new_config: RcFastClkDivNConfig,
1032/// ) {
1033///     todo!()
1034/// }
1035///
1036/// // XTAL_DIV_CLK
1037///
1038/// fn enable_xtal_div_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1039///     todo!()
1040/// }
1041///
1042/// // RTC_SLOW_CLK
1043///
1044/// fn enable_rtc_slow_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1045///     todo!()
1046/// }
1047///
1048/// fn configure_rtc_slow_clk_impl(
1049///     _clocks: &mut ClockTree,
1050///     _old_config: Option<RtcSlowClkConfig>,
1051///     _new_config: RtcSlowClkConfig,
1052/// ) {
1053///     todo!()
1054/// }
1055///
1056/// // BLE_LP_XTAL_CLK
1057///
1058/// fn enable_ble_lp_xtal_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1059///     todo!()
1060/// }
1061///
1062/// // BLE_LP_RC_SLOW_CLK
1063///
1064/// fn enable_ble_lp_rc_slow_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1065///     todo!()
1066/// }
1067///
1068/// // BLE_LP_CLK
1069///
1070/// fn enable_ble_lp_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1071///     todo!()
1072/// }
1073///
1074/// fn configure_ble_lp_clk_impl(
1075///     _clocks: &mut ClockTree,
1076///     _old_config: Option<BleLpClkConfig>,
1077///     _new_config: BleLpClkConfig,
1078/// ) {
1079///     todo!()
1080/// }
1081///
1082/// // RTC_FAST_CLK
1083///
1084/// fn enable_rtc_fast_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1085///     todo!()
1086/// }
1087///
1088/// fn configure_rtc_fast_clk_impl(
1089///     _clocks: &mut ClockTree,
1090///     _old_config: Option<RtcFastClkConfig>,
1091///     _new_config: RtcFastClkConfig,
1092/// ) {
1093///     todo!()
1094/// }
1095///
1096/// // LOW_POWER_CLK
1097///
1098/// fn enable_low_power_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1099///     todo!()
1100/// }
1101///
1102/// fn configure_low_power_clk_impl(
1103///     _clocks: &mut ClockTree,
1104///     _old_config: Option<LowPowerClkConfig>,
1105///     _new_config: LowPowerClkConfig,
1106/// ) {
1107///     todo!()
1108/// }
1109///
1110/// // UART_MEM_CLK
1111///
1112/// fn enable_uart_mem_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1113///     todo!()
1114/// }
1115///
1116/// // TIMG_CALIBRATION_CLOCK
1117///
1118/// fn enable_timg_calibration_clock_impl(_clocks: &mut ClockTree, _en: bool) {
1119///     todo!()
1120/// }
1121///
1122/// fn configure_timg_calibration_clock_impl(
1123///     _clocks: &mut ClockTree,
1124///     _old_config: Option<TimgCalibrationClockConfig>,
1125///     _new_config: TimgCalibrationClockConfig,
1126/// ) {
1127///     todo!()
1128/// }
1129///
1130/// impl AdcInstance {
1131///     // ADC_FUNCTION_CLOCK
1132///
1133///     fn enable_function_clock_impl(self, _clocks: &mut ClockTree, _en: bool) {
1134///         todo!()
1135///     }
1136/// }
1137/// impl I2cInstance {
1138///     // I2C_FUNCTION_CLOCK
1139///
1140///     fn enable_function_clock_impl(self, _clocks: &mut ClockTree, _en: bool) {
1141///         todo!()
1142///     }
1143///
1144///     fn configure_function_clock_impl(
1145///         self,
1146///         _clocks: &mut ClockTree,
1147///         _old_config: Option<I2cFunctionClockConfig>,
1148///         _new_config: I2cFunctionClockConfig,
1149///     ) {
1150///         todo!()
1151///     }
1152/// }
1153/// impl SpiInstance {
1154///     // SPI_FUNCTION_CLOCK
1155///
1156///     fn enable_function_clock_impl(self, _clocks: &mut ClockTree, _en: bool) {
1157///         todo!()
1158///     }
1159///
1160///     fn configure_function_clock_impl(
1161///         self,
1162///         _clocks: &mut ClockTree,
1163///         _old_config: Option<SpiFunctionClockConfig>,
1164///         _new_config: SpiFunctionClockConfig,
1165///     ) {
1166///         todo!()
1167///     }
1168/// }
1169/// impl TimgInstance {
1170///     // TIMG_FUNCTION_CLOCK
1171///
1172///     fn enable_function_clock_impl(self, _clocks: &mut ClockTree, _en: bool) {
1173///         todo!()
1174///     }
1175///
1176///     fn configure_function_clock_impl(
1177///         self,
1178///         _clocks: &mut ClockTree,
1179///         _old_config: Option<TimgFunctionClockConfig>,
1180///         _new_config: TimgFunctionClockConfig,
1181///     ) {
1182///         todo!()
1183///     }
1184///
1185///     // TIMG_WDT_CLOCK
1186///
1187///     fn enable_wdt_clock_impl(self, _clocks: &mut ClockTree, _en: bool) {
1188///         todo!()
1189///     }
1190///
1191///     fn configure_wdt_clock_impl(
1192///         self,
1193///         _clocks: &mut ClockTree,
1194///         _old_config: Option<TimgWdtClockConfig>,
1195///         _new_config: TimgWdtClockConfig,
1196///     ) {
1197///         todo!()
1198///     }
1199/// }
1200/// impl UartInstance {
1201///     // UART_FUNCTION_CLOCK
1202///
1203///     fn enable_function_clock_impl(self, _clocks: &mut ClockTree, _en: bool) {
1204///         todo!()
1205///     }
1206///
1207///     fn configure_function_clock_impl(
1208///         self,
1209///         _clocks: &mut ClockTree,
1210///         _old_config: Option<UartFunctionClockConfig>,
1211///         _new_config: UartFunctionClockConfig,
1212///     ) {
1213///         todo!()
1214///     }
1215///
1216///     // UART_MEM_CLOCK
1217///
1218///     fn enable_mem_clock_impl(self, _clocks: &mut ClockTree, _en: bool) {
1219///         todo!()
1220///     }
1221///
1222///     // UART_BAUD_RATE_GENERATOR
1223///
1224///     fn enable_baud_rate_generator_impl(self, _clocks: &mut ClockTree, _en: bool) {
1225///         todo!()
1226///     }
1227///
1228///     fn configure_baud_rate_generator_impl(
1229///         self,
1230///         _clocks: &mut ClockTree,
1231///         _old_config: Option<UartBaudRateGeneratorConfig>,
1232///         _new_config: UartBaudRateGeneratorConfig,
1233///     ) {
1234///         todo!()
1235///     }
1236/// }
1237/// ```
1238macro_rules! define_clock_tree_types {
1239    () => {
1240        #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1241        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1242        pub enum AdcInstance {
1243            ApbSaradc = 0,
1244        }
1245        #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1246        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1247        pub enum I2cInstance {
1248            I2c0 = 0,
1249        }
1250        #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1251        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1252        pub enum SpiInstance {
1253            Spi2 = 0,
1254        }
1255        #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1256        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1257        pub enum TimgInstance {
1258            Timg0 = 0,
1259        }
1260        #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1261        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1262        pub enum UartInstance {
1263            Uart0 = 0,
1264            Uart1 = 1,
1265        }
1266        /// Selects the output frequency of `XTAL_CLK`.
1267        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1268        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1269        pub enum XtalClkConfig {
1270            /// 26 MHz
1271            _26,
1272            /// 40 MHz
1273            _40,
1274        }
1275        impl XtalClkConfig {
1276            pub fn value(&self) -> u32 {
1277                match self {
1278                    XtalClkConfig::_26 => 26000000,
1279                    XtalClkConfig::_40 => 40000000,
1280                }
1281            }
1282        }
1283        /// The list of clock signals that the `SYSTEM_PRE_DIV_IN` multiplexer can output.
1284        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1285        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1286        pub enum SystemPreDivInConfig {
1287            /// Selects `XTAL_CLK`.
1288            Xtal,
1289            /// Selects `RC_FAST_CLK`.
1290            RcFast,
1291        }
1292        /// Configures the `SYSTEM_PRE_DIV` clock node.
1293        ///
1294        /// The output is calculated as `OUTPUT = SYSTEM_PRE_DIV_IN / (divisor + 1)`.
1295        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1296        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1297        pub struct SystemPreDivConfig {
1298            divisor: u32,
1299        }
1300        impl SystemPreDivConfig {
1301            /// Creates a new configuration for the SYSTEM_PRE_DIV clock node.
1302            ///
1303            /// ## Panics
1304            ///
1305            /// Panics if the divisor value is outside the
1306            /// valid range (0 ..= 1023).
1307            pub const fn new(divisor: u32) -> Self {
1308                ::core::assert!(
1309                    divisor <= 1023,
1310                    "`SYSTEM_PRE_DIV` divisor must be between 0 and 1023 (inclusive)."
1311                );
1312                Self { divisor }
1313            }
1314            pub fn divisor(self) -> u32 {
1315                self.divisor as u32
1316            }
1317        }
1318        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1319        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1320        pub enum CpuPllDivDivisor {
1321            /// Selects `divisor = 4`.
1322            _4 = 4,
1323            /// Selects `divisor = 6`.
1324            _6 = 6,
1325        }
1326        impl CpuPllDivDivisor {
1327            /// Creates a new parameter value from a raw number.
1328            pub const fn new(raw: u32) -> Self {
1329                match raw {
1330                    4 => Self::_4,
1331                    6 => Self::_6,
1332                    _ => ::core::panic!("Invalid CPU_PLL_DIV divisor value"),
1333                }
1334            }
1335        }
1336        /// Configures the `CPU_PLL_DIV` clock node.
1337        ///
1338        /// The output is calculated as `OUTPUT = PLL_CLK / divisor`.
1339        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1340        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1341        pub struct CpuPllDivConfig {
1342            divisor: CpuPllDivDivisor,
1343        }
1344        impl CpuPllDivConfig {
1345            /// Creates a new configuration for the CPU_PLL_DIV clock node.
1346            pub const fn new(divisor: CpuPllDivDivisor) -> Self {
1347                Self { divisor }
1348            }
1349            pub fn divisor(self) -> u32 {
1350                self.divisor as u32
1351            }
1352        }
1353        /// The list of clock signals that the `APB_CLK` multiplexer can output.
1354        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1355        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1356        pub enum ApbClkConfig {
1357            /// Selects `PLL_40M`.
1358            Pll40m,
1359            /// Selects `CPU_CLK`.
1360            Cpu,
1361        }
1362        /// The list of clock signals that the `CRYPTO_CLK` multiplexer can output.
1363        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1364        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1365        pub enum CryptoClkConfig {
1366            /// Selects `PLL_80M`.
1367            Pll80m,
1368            /// Selects `CPU_CLK`.
1369            Cpu,
1370        }
1371        /// The list of clock signals that the `MSPI_CLK` multiplexer can output.
1372        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1373        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1374        pub enum MspiClkConfig {
1375            /// Selects `CPU_DIV2`.
1376            CpuDiv2,
1377            /// Selects `CPU_CLK`.
1378            Cpu,
1379        }
1380        /// The list of clock signals that the `CPU_CLK` multiplexer can output.
1381        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1382        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1383        pub enum CpuClkConfig {
1384            /// Selects `SYSTEM_PRE_DIV`.
1385            Xtal,
1386            /// Selects `SYSTEM_PRE_DIV`.
1387            RcFast,
1388            /// Selects `CPU_PLL_DIV`.
1389            Pll,
1390        }
1391        /// Configures the `RC_FAST_CLK_DIV_N` clock node.
1392        ///
1393        /// The output is calculated as `OUTPUT = RC_FAST_CLK / (divisor + 1)`.
1394        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1395        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1396        pub struct RcFastClkDivNConfig {
1397            divisor: u32,
1398        }
1399        impl RcFastClkDivNConfig {
1400            /// Creates a new configuration for the RC_FAST_CLK_DIV_N clock node.
1401            ///
1402            /// ## Panics
1403            ///
1404            /// Panics if the divisor value is outside the
1405            /// valid range (0 ..= 3).
1406            pub const fn new(divisor: u32) -> Self {
1407                ::core::assert!(
1408                    divisor <= 3,
1409                    "`RC_FAST_CLK_DIV_N` divisor must be between 0 and 3 (inclusive)."
1410                );
1411                Self { divisor }
1412            }
1413            pub fn divisor(self) -> u32 {
1414                self.divisor as u32
1415            }
1416        }
1417        /// The list of clock signals that the `RTC_SLOW_CLK` multiplexer can output.
1418        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1419        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1420        pub enum RtcSlowClkConfig {
1421            /// Selects `OSC_SLOW_CLK`.
1422            OscSlow,
1423            /// Selects `RC_SLOW_CLK`.
1424            RcSlow,
1425            /// Selects `RC_FAST_DIV_CLK`.
1426            RcFast,
1427        }
1428        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1429        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1430        pub enum BleLpClkSclk {
1431            #[default]
1432            /// Selects `BLE_LP_XTAL_CLK`.
1433            Xtal,
1434            /// Selects `BLE_LP_RC_SLOW_CLK`.
1435            RcSlow,
1436        }
1437        /// Configures the `BLE_LP_CLK` clock node.
1438        ///
1439        /// The output is calculated as `OUTPUT = sclk / (divisor + 1)`.
1440        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1441        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1442        pub struct BleLpClkConfig {
1443            sclk: BleLpClkSclk,
1444            divisor: u32,
1445        }
1446        impl BleLpClkConfig {
1447            /// Creates a new configuration for the BLE_LP_CLK clock node.
1448            ///
1449            /// ## Panics
1450            ///
1451            /// Panics if the divisor value is outside the
1452            /// valid range (0 ..= 255).
1453            pub const fn new(sclk: BleLpClkSclk, divisor: u32) -> Self {
1454                ::core::assert!(
1455                    divisor <= 255,
1456                    "`BLE_LP_CLK` divisor must be between 0 and 255 (inclusive)."
1457                );
1458                Self { sclk, divisor }
1459            }
1460            pub fn sclk(self) -> BleLpClkSclk {
1461                self.sclk
1462            }
1463            pub fn divisor(self) -> u32 {
1464                self.divisor as u32
1465            }
1466        }
1467        /// The list of clock signals that the `RTC_FAST_CLK` multiplexer can output.
1468        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1469        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1470        pub enum RtcFastClkConfig {
1471            /// Selects `XTAL_DIV_CLK`.
1472            Xtal,
1473            /// Selects `RC_FAST_CLK_DIV_N`.
1474            Rc,
1475        }
1476        /// The list of clock signals that the `LOW_POWER_CLK` multiplexer can output.
1477        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1478        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1479        pub enum LowPowerClkConfig {
1480            /// Selects `XTAL_CLK`.
1481            Xtal,
1482            /// Selects `RC_FAST_CLK`.
1483            RcFast,
1484            /// Selects `OSC_SLOW_CLK`.
1485            OscSlow,
1486            /// Selects `RTC_SLOW_CLK`.
1487            RtcSlow,
1488        }
1489        /// The list of clock signals that the `UART_MEM_CLK` multiplexer can output.
1490        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1491        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1492        pub enum UartMemClkConfig {
1493            #[default]
1494            /// Selects `XTAL_CLK`.
1495            Xtal,
1496        }
1497        /// The list of clock signals that the `TIMG_CALIBRATION_CLOCK` multiplexer can output.
1498        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1499        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1500        pub enum TimgCalibrationClockConfig {
1501            /// Selects `RC_SLOW_CLK`.
1502            RcSlowClk,
1503            /// Selects `RC_FAST_DIV_CLK`.
1504            RcFastDivClk,
1505            /// Selects `OSC_SLOW_CLK`.
1506            Osc32kClk,
1507        }
1508        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1509        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1510        pub enum I2cFunctionClockSclk {
1511            #[default]
1512            /// Selects `XTAL_CLK`.
1513            Xtal,
1514            /// Selects `RC_FAST_CLK`.
1515            RcFast,
1516        }
1517        /// Configures the `I2C0_FUNCTION_CLOCK` clock node.
1518        ///
1519        /// The output is calculated as `OUTPUT = sclk / (div_num + 1)`.
1520        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1521        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1522        pub struct I2cFunctionClockConfig {
1523            sclk: I2cFunctionClockSclk,
1524            div_num: u32,
1525        }
1526        impl I2cFunctionClockConfig {
1527            /// Creates a new configuration for the FUNCTION_CLOCK clock node.
1528            ///
1529            /// ## Panics
1530            ///
1531            /// Panics if the div_num value is outside the
1532            /// valid range (0 ..= 255).
1533            pub const fn new(sclk: I2cFunctionClockSclk, div_num: u32) -> Self {
1534                ::core::assert!(
1535                    div_num <= 255,
1536                    "`I2C0_FUNCTION_CLOCK` div_num must be between 0 and 255 (inclusive)."
1537                );
1538                Self { sclk, div_num }
1539            }
1540            pub fn sclk(self) -> I2cFunctionClockSclk {
1541                self.sclk
1542            }
1543            pub fn div_num(self) -> u32 {
1544                self.div_num as u32
1545            }
1546        }
1547        /// The list of clock signals that the `SPI2_FUNCTION_CLOCK` multiplexer can output.
1548        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1549        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1550        pub enum SpiFunctionClockConfig {
1551            /// Selects `XTAL_CLK`.
1552            Xtal,
1553            #[default]
1554            /// Selects `PLL_40M`.
1555            Pll40m,
1556        }
1557        /// The list of clock signals that the `TIMG0_FUNCTION_CLOCK` multiplexer can output.
1558        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1559        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1560        pub enum TimgFunctionClockConfig {
1561            #[default]
1562            /// Selects `XTAL_CLK`.
1563            XtalClk,
1564            /// Selects `PLL_40M`.
1565            Pll40m,
1566        }
1567        /// The list of clock signals that the `TIMG0_WDT_CLOCK` multiplexer can output.
1568        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1569        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1570        pub enum TimgWdtClockConfig {
1571            #[default]
1572            /// Selects `PLL_40M`.
1573            Pll40m,
1574            /// Selects `XTAL_CLK`.
1575            XtalClk,
1576        }
1577        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1578        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1579        pub enum UartFunctionClockSclk {
1580            /// Selects `PLL_40M`.
1581            PllF40m,
1582            /// Selects `RC_FAST_CLK`.
1583            RcFast,
1584            #[default]
1585            /// Selects `XTAL_CLK`.
1586            Xtal,
1587        }
1588        /// Configures the `UART0_FUNCTION_CLOCK` clock node.
1589        ///
1590        /// The output is calculated as `OUTPUT = sclk / (div_num + 1)`.
1591        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1592        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1593        pub struct UartFunctionClockConfig {
1594            sclk: UartFunctionClockSclk,
1595            div_num: u32,
1596        }
1597        impl UartFunctionClockConfig {
1598            /// Creates a new configuration for the FUNCTION_CLOCK clock node.
1599            ///
1600            /// ## Panics
1601            ///
1602            /// Panics if the div_num value is outside the
1603            /// valid range (0 ..= 255).
1604            pub const fn new(sclk: UartFunctionClockSclk, div_num: u32) -> Self {
1605                ::core::assert!(
1606                    div_num <= 255,
1607                    "`UART0_FUNCTION_CLOCK` div_num must be between 0 and 255 (inclusive)."
1608                );
1609                Self { sclk, div_num }
1610            }
1611            pub fn sclk(self) -> UartFunctionClockSclk {
1612                self.sclk
1613            }
1614            pub fn div_num(self) -> u32 {
1615                self.div_num as u32
1616            }
1617        }
1618        /// Configures the `UART0_BAUD_RATE_GENERATOR` clock node.
1619        ///
1620        /// The output is calculated as `OUTPUT = (FUNCTION_CLOCK * 16) / (integral * 16 +
1621        /// fractional)`.
1622        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1623        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1624        pub struct UartBaudRateGeneratorConfig {
1625            fractional: u32,
1626            integral: u32,
1627        }
1628        impl UartBaudRateGeneratorConfig {
1629            /// Creates a new configuration for the BAUD_RATE_GENERATOR clock node.
1630            ///
1631            /// ## Panics
1632            ///
1633            /// Panics if the fractional value is outside the
1634            /// valid range (0 ..= 15).
1635            ///
1636            /// Panics if the integral value is outside the
1637            /// valid range (0 ..= 4095).
1638            pub const fn new(fractional: u32, integral: u32) -> Self {
1639                ::core::assert!(
1640                    fractional <= 15,
1641                    "`UART0_BAUD_RATE_GENERATOR` fractional must be between 0 and 15 (inclusive)."
1642                );
1643                ::core::assert!(
1644                    integral <= 4095,
1645                    "`UART0_BAUD_RATE_GENERATOR` integral must be between 0 and 4095 (inclusive)."
1646                );
1647                Self {
1648                    fractional,
1649                    integral,
1650                }
1651            }
1652            pub fn fractional(self) -> u32 {
1653                self.fractional as u32
1654            }
1655            pub fn integral(self) -> u32 {
1656                self.integral as u32
1657            }
1658        }
1659        /// Represents the device's clock tree.
1660        pub struct ClockTree {
1661            xtal_clk: Option<XtalClkConfig>,
1662            system_pre_div_in: Option<SystemPreDivInConfig>,
1663            system_pre_div: Option<SystemPreDivConfig>,
1664            cpu_pll_div: Option<CpuPllDivConfig>,
1665            apb_clk: Option<ApbClkConfig>,
1666            crypto_clk: Option<CryptoClkConfig>,
1667            mspi_clk: Option<MspiClkConfig>,
1668            cpu_clk: Option<CpuClkConfig>,
1669            rc_fast_clk_div_n: Option<RcFastClkDivNConfig>,
1670            rtc_slow_clk: Option<RtcSlowClkConfig>,
1671            ble_lp_clk: Option<BleLpClkConfig>,
1672            rtc_fast_clk: Option<RtcFastClkConfig>,
1673            low_power_clk: Option<LowPowerClkConfig>,
1674            timg_calibration_clock: Option<TimgCalibrationClockConfig>,
1675            i2c_function_clock: [Option<I2cFunctionClockConfig>; 1],
1676            spi_function_clock: [Option<SpiFunctionClockConfig>; 1],
1677            timg_function_clock: [Option<TimgFunctionClockConfig>; 1],
1678            timg_wdt_clock: [Option<TimgWdtClockConfig>; 1],
1679            uart_function_clock: [Option<UartFunctionClockConfig>; 2],
1680            uart_baud_rate_generator: [Option<UartBaudRateGeneratorConfig>; 2],
1681            pub(crate) rc_fast_clk_refcount: u32,
1682            pub(crate) osc_slow_clk_refcount: u32,
1683            pub(crate) rc_slow_clk_refcount: u32,
1684            pub(crate) rc_fast_div_clk_refcount: u32,
1685            pub(crate) crypto_clk_refcount: u32,
1686            pub(crate) mspi_clk_refcount: u32,
1687            pub(crate) pll_40m_refcount: u32,
1688            pub(crate) pll_60m_refcount: u32,
1689            pub(crate) ble_lp_clk_refcount: u32,
1690            pub(crate) rtc_fast_clk_refcount: u32,
1691            pub(crate) low_power_clk_refcount: u32,
1692            pub(crate) uart_mem_clk_refcount: u32,
1693            pub(crate) timg_calibration_clock_refcount: u32,
1694            pub(crate) adc_function_clock_refcount: [u32; 1],
1695            pub(crate) i2c_function_clock_refcount: [u32; 1],
1696            pub(crate) spi_function_clock_refcount: [u32; 1],
1697            pub(crate) timg_function_clock_refcount: [u32; 1],
1698            pub(crate) timg_wdt_clock_refcount: [u32; 1],
1699            pub(crate) uart_function_clock_refcount: [u32; 2],
1700            pub(crate) uart_mem_clock_refcount: [u32; 2],
1701            pub(crate) uart_baud_rate_generator_refcount: [u32; 2],
1702        }
1703        impl ClockTree {
1704            /// Locks the clock tree for exclusive access.
1705            pub fn with<R>(f: impl FnOnce(&mut ClockTree) -> R) -> R {
1706                CLOCK_TREE.with(f)
1707            }
1708            /// Returns the current configuration of the XTAL_CLK clock tree node
1709            pub fn xtal_clk(&self) -> Option<XtalClkConfig> {
1710                self.xtal_clk
1711            }
1712            /// Returns the current configuration of the SYSTEM_PRE_DIV_IN clock tree node
1713            pub fn system_pre_div_in(&self) -> Option<SystemPreDivInConfig> {
1714                self.system_pre_div_in
1715            }
1716            /// Returns the current configuration of the SYSTEM_PRE_DIV clock tree node
1717            pub fn system_pre_div(&self) -> Option<SystemPreDivConfig> {
1718                self.system_pre_div
1719            }
1720            /// Returns the current configuration of the CPU_PLL_DIV clock tree node
1721            pub fn cpu_pll_div(&self) -> Option<CpuPllDivConfig> {
1722                self.cpu_pll_div
1723            }
1724            /// Returns the current configuration of the APB_CLK clock tree node
1725            pub fn apb_clk(&self) -> Option<ApbClkConfig> {
1726                self.apb_clk
1727            }
1728            /// Returns the current configuration of the CRYPTO_CLK clock tree node
1729            pub fn crypto_clk(&self) -> Option<CryptoClkConfig> {
1730                self.crypto_clk
1731            }
1732            /// Returns the current configuration of the MSPI_CLK clock tree node
1733            pub fn mspi_clk(&self) -> Option<MspiClkConfig> {
1734                self.mspi_clk
1735            }
1736            /// Returns the current configuration of the CPU_CLK clock tree node
1737            pub fn cpu_clk(&self) -> Option<CpuClkConfig> {
1738                self.cpu_clk
1739            }
1740            /// Returns the current configuration of the RC_FAST_CLK_DIV_N clock tree node
1741            pub fn rc_fast_clk_div_n(&self) -> Option<RcFastClkDivNConfig> {
1742                self.rc_fast_clk_div_n
1743            }
1744            /// Returns the current configuration of the RTC_SLOW_CLK clock tree node
1745            pub fn rtc_slow_clk(&self) -> Option<RtcSlowClkConfig> {
1746                self.rtc_slow_clk
1747            }
1748            /// Returns the current configuration of the BLE_LP_CLK clock tree node
1749            pub fn ble_lp_clk(&self) -> Option<BleLpClkConfig> {
1750                self.ble_lp_clk
1751            }
1752            /// Returns the current configuration of the RTC_FAST_CLK clock tree node
1753            pub fn rtc_fast_clk(&self) -> Option<RtcFastClkConfig> {
1754                self.rtc_fast_clk
1755            }
1756            /// Returns the current configuration of the LOW_POWER_CLK clock tree node
1757            pub fn low_power_clk(&self) -> Option<LowPowerClkConfig> {
1758                self.low_power_clk
1759            }
1760            /// Returns the current configuration of the TIMG_CALIBRATION_CLOCK clock tree node
1761            pub fn timg_calibration_clock(&self) -> Option<TimgCalibrationClockConfig> {
1762                self.timg_calibration_clock
1763            }
1764            /// Returns the current configuration of the I2C0_FUNCTION_CLOCK clock tree node
1765            pub fn i2c0_function_clock(&self) -> Option<I2cFunctionClockConfig> {
1766                self.i2c_function_clock[I2cInstance::I2c0 as usize]
1767            }
1768            /// Returns the current configuration of the SPI2_FUNCTION_CLOCK clock tree node
1769            pub fn spi2_function_clock(&self) -> Option<SpiFunctionClockConfig> {
1770                self.spi_function_clock[SpiInstance::Spi2 as usize]
1771            }
1772            /// Returns the current configuration of the TIMG0_FUNCTION_CLOCK clock tree node
1773            pub fn timg0_function_clock(&self) -> Option<TimgFunctionClockConfig> {
1774                self.timg_function_clock[TimgInstance::Timg0 as usize]
1775            }
1776            /// Returns the current configuration of the TIMG0_WDT_CLOCK clock tree node
1777            pub fn timg0_wdt_clock(&self) -> Option<TimgWdtClockConfig> {
1778                self.timg_wdt_clock[TimgInstance::Timg0 as usize]
1779            }
1780            /// Returns the current configuration of the UART0_FUNCTION_CLOCK clock tree node
1781            pub fn uart0_function_clock(&self) -> Option<UartFunctionClockConfig> {
1782                self.uart_function_clock[UartInstance::Uart0 as usize]
1783            }
1784            /// Returns the current configuration of the UART0_BAUD_RATE_GENERATOR clock tree node
1785            pub fn uart0_baud_rate_generator(&self) -> Option<UartBaudRateGeneratorConfig> {
1786                self.uart_baud_rate_generator[UartInstance::Uart0 as usize]
1787            }
1788            /// Returns the current configuration of the UART1_FUNCTION_CLOCK clock tree node
1789            pub fn uart1_function_clock(&self) -> Option<UartFunctionClockConfig> {
1790                self.uart_function_clock[UartInstance::Uart1 as usize]
1791            }
1792            /// Returns the current configuration of the UART1_BAUD_RATE_GENERATOR clock tree node
1793            pub fn uart1_baud_rate_generator(&self) -> Option<UartBaudRateGeneratorConfig> {
1794                self.uart_baud_rate_generator[UartInstance::Uart1 as usize]
1795            }
1796        }
1797        static CLOCK_TREE: ::esp_sync::NonReentrantMutex<ClockTree> =
1798            ::esp_sync::NonReentrantMutex::new(ClockTree {
1799                xtal_clk: None,
1800                system_pre_div_in: None,
1801                system_pre_div: None,
1802                cpu_pll_div: None,
1803                apb_clk: None,
1804                crypto_clk: None,
1805                mspi_clk: None,
1806                cpu_clk: None,
1807                rc_fast_clk_div_n: None,
1808                rtc_slow_clk: None,
1809                ble_lp_clk: None,
1810                rtc_fast_clk: None,
1811                low_power_clk: None,
1812                timg_calibration_clock: None,
1813                i2c_function_clock: [None; 1],
1814                spi_function_clock: [None; 1],
1815                timg_function_clock: [None; 1],
1816                timg_wdt_clock: [None; 1],
1817                uart_function_clock: [None; 2],
1818                uart_baud_rate_generator: [None; 2],
1819                rc_fast_clk_refcount: 0,
1820                osc_slow_clk_refcount: 0,
1821                rc_slow_clk_refcount: 0,
1822                rc_fast_div_clk_refcount: 0,
1823                crypto_clk_refcount: 0,
1824                mspi_clk_refcount: 0,
1825                pll_40m_refcount: 0,
1826                pll_60m_refcount: 0,
1827                ble_lp_clk_refcount: 0,
1828                rtc_fast_clk_refcount: 0,
1829                low_power_clk_refcount: 0,
1830                uart_mem_clk_refcount: 0,
1831                timg_calibration_clock_refcount: 0,
1832                adc_function_clock_refcount: [0; 1],
1833                i2c_function_clock_refcount: [0; 1],
1834                spi_function_clock_refcount: [0; 1],
1835                timg_function_clock_refcount: [0; 1],
1836                timg_wdt_clock_refcount: [0; 1],
1837                uart_function_clock_refcount: [0; 2],
1838                uart_mem_clock_refcount: [0; 2],
1839                uart_baud_rate_generator_refcount: [0; 2],
1840            });
1841        static XTAL_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1842            ::core::sync::atomic::AtomicU32::new(0);
1843        static SYSTEM_PRE_DIV_IN_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1844            ::core::sync::atomic::AtomicU32::new(0);
1845        static SYSTEM_PRE_DIV_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1846            ::core::sync::atomic::AtomicU32::new(0);
1847        static CPU_PLL_DIV_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1848            ::core::sync::atomic::AtomicU32::new(0);
1849        static CPU_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1850            ::core::sync::atomic::AtomicU32::new(0);
1851        static RC_FAST_CLK_DIV_N_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1852            ::core::sync::atomic::AtomicU32::new(0);
1853        static RTC_SLOW_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1854            ::core::sync::atomic::AtomicU32::new(0);
1855        static BLE_LP_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1856            ::core::sync::atomic::AtomicU32::new(0);
1857        static RTC_FAST_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1858            ::core::sync::atomic::AtomicU32::new(0);
1859        static LOW_POWER_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1860            ::core::sync::atomic::AtomicU32::new(0);
1861        static TIMG_CALIBRATION_CLOCK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1862            ::core::sync::atomic::AtomicU32::new(0);
1863        static I2C_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
1864            [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
1865        static SPI_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
1866            [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
1867        static TIMG_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
1868            [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
1869        static TIMG_WDT_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
1870            [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
1871        static UART_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 2] =
1872            [const { ::core::sync::atomic::AtomicU32::new(0) }; 2];
1873        static UART_BAUD_RATE_GENERATOR_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 2] =
1874            [const { ::core::sync::atomic::AtomicU32::new(0) }; 2];
1875        static APB_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1876            ::core::sync::atomic::AtomicU32::new(0);
1877        static CRYPTO_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1878            ::core::sync::atomic::AtomicU32::new(0);
1879        static MSPI_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1880            ::core::sync::atomic::AtomicU32::new(0);
1881        /// The clock sources of the device.
1882        ///
1883        /// A clock source is a node of the clock tree that other nodes derive their output
1884        /// from. Ask a node which source it runs on with its `..._root_source` function.
1885        #[derive(Debug, enumset::EnumSetType)]
1886        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1887        pub enum ClockSource {
1888            /// `XTAL_CLK`.
1889            XtalClk,
1890            /// `RC_FAST_CLK`.
1891            RcFastClk,
1892            /// `OSC_SLOW_CLK`.
1893            OscSlowClk,
1894            /// `RC_SLOW_CLK`.
1895            RcSlowClk,
1896        }
1897        /// Returns the clock source that `XTAL_CLK` currently runs on.
1898        pub fn xtal_clk_root_source(_clocks: &mut ClockTree) -> Option<ClockSource> {
1899            Some(ClockSource::XtalClk)
1900        }
1901        /// Returns the clock source that `PLL_CLK` currently runs on.
1902        pub fn pll_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1903            xtal_clk_root_source(clocks)
1904        }
1905        /// Returns the clock source that `RC_FAST_CLK` currently runs on.
1906        pub fn rc_fast_clk_root_source(_clocks: &mut ClockTree) -> Option<ClockSource> {
1907            Some(ClockSource::RcFastClk)
1908        }
1909        /// Returns the clock source that `OSC_SLOW_CLK` currently runs on.
1910        pub fn osc_slow_clk_root_source(_clocks: &mut ClockTree) -> Option<ClockSource> {
1911            Some(ClockSource::OscSlowClk)
1912        }
1913        /// Returns the clock source that `RC_SLOW_CLK` currently runs on.
1914        pub fn rc_slow_clk_root_source(_clocks: &mut ClockTree) -> Option<ClockSource> {
1915            Some(ClockSource::RcSlowClk)
1916        }
1917        /// Returns the clock source that `RC_FAST_DIV_CLK` currently runs on.
1918        pub fn rc_fast_div_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1919            rc_fast_clk_root_source(clocks)
1920        }
1921        /// Returns the clock source that `SYSTEM_PRE_DIV_IN` currently runs on.
1922        pub fn system_pre_div_in_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1923            let config = clocks.system_pre_div_in?;
1924            match config {
1925                SystemPreDivInConfig::Xtal => xtal_clk_root_source(clocks),
1926                SystemPreDivInConfig::RcFast => rc_fast_clk_root_source(clocks),
1927            }
1928        }
1929        /// Returns the clock source that `SYSTEM_PRE_DIV` currently runs on.
1930        pub fn system_pre_div_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1931            system_pre_div_in_root_source(clocks)
1932        }
1933        /// Returns the clock source that `CPU_PLL_DIV` currently runs on.
1934        pub fn cpu_pll_div_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1935            pll_clk_root_source(clocks)
1936        }
1937        /// Returns the clock source that `CPU_CLK` currently runs on.
1938        pub fn cpu_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1939            let config = clocks.cpu_clk?;
1940            match config {
1941                CpuClkConfig::Xtal => system_pre_div_root_source(clocks),
1942                CpuClkConfig::RcFast => system_pre_div_root_source(clocks),
1943                CpuClkConfig::Pll => cpu_pll_div_root_source(clocks),
1944            }
1945        }
1946        /// Returns the clock source that `PLL_40M` currently runs on.
1947        pub fn pll_40m_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1948            cpu_clk_root_source(clocks)
1949        }
1950        /// Returns the clock source that `PLL_60M` currently runs on.
1951        pub fn pll_60m_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1952            cpu_clk_root_source(clocks)
1953        }
1954        /// Returns the clock source that `PLL_80M` currently runs on.
1955        pub fn pll_80m_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1956            cpu_clk_root_source(clocks)
1957        }
1958        /// Returns the clock source that `CPU_DIV2` currently runs on.
1959        pub fn cpu_div2_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1960            cpu_clk_root_source(clocks)
1961        }
1962        /// Returns the clock source that `RC_FAST_CLK_DIV_N` currently runs on.
1963        pub fn rc_fast_clk_div_n_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1964            rc_fast_clk_root_source(clocks)
1965        }
1966        /// Returns the clock source that `XTAL_DIV_CLK` currently runs on.
1967        pub fn xtal_div_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1968            xtal_clk_root_source(clocks)
1969        }
1970        /// Returns the clock source that `RTC_SLOW_CLK` currently runs on.
1971        pub fn rtc_slow_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1972            let config = clocks.rtc_slow_clk?;
1973            match config {
1974                RtcSlowClkConfig::OscSlow => osc_slow_clk_root_source(clocks),
1975                RtcSlowClkConfig::RcSlow => rc_slow_clk_root_source(clocks),
1976                RtcSlowClkConfig::RcFast => rc_fast_div_clk_root_source(clocks),
1977            }
1978        }
1979        /// Returns the clock source that `BLE_LP_XTAL_CLK` currently runs on.
1980        pub fn ble_lp_xtal_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1981            xtal_clk_root_source(clocks)
1982        }
1983        /// Returns the clock source that `BLE_LP_RC_SLOW_CLK` currently runs on.
1984        pub fn ble_lp_rc_slow_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1985            rc_slow_clk_root_source(clocks)
1986        }
1987        /// Returns the clock source that `BLE_LP_CLK` currently runs on.
1988        pub fn ble_lp_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1989            let config = clocks.ble_lp_clk?;
1990            match config.sclk() {
1991                BleLpClkSclk::Xtal => ble_lp_xtal_clk_root_source(clocks),
1992                BleLpClkSclk::RcSlow => ble_lp_rc_slow_clk_root_source(clocks),
1993            }
1994        }
1995        /// Returns the clock source that `RTC_FAST_CLK` currently runs on.
1996        pub fn rtc_fast_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1997            let config = clocks.rtc_fast_clk?;
1998            match config {
1999                RtcFastClkConfig::Xtal => xtal_div_clk_root_source(clocks),
2000                RtcFastClkConfig::Rc => rc_fast_clk_div_n_root_source(clocks),
2001            }
2002        }
2003        /// Returns the clock source that `LOW_POWER_CLK` currently runs on.
2004        pub fn low_power_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2005            let config = clocks.low_power_clk?;
2006            match config {
2007                LowPowerClkConfig::Xtal => xtal_clk_root_source(clocks),
2008                LowPowerClkConfig::RcFast => rc_fast_clk_root_source(clocks),
2009                LowPowerClkConfig::OscSlow => osc_slow_clk_root_source(clocks),
2010                LowPowerClkConfig::RtcSlow => rtc_slow_clk_root_source(clocks),
2011            }
2012        }
2013        /// Returns the clock source that `UART_MEM_CLK` currently runs on.
2014        pub fn uart_mem_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2015            xtal_clk_root_source(clocks)
2016        }
2017        /// Returns the clock source that `TIMG_CALIBRATION_CLOCK` currently runs on.
2018        pub fn timg_calibration_clock_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2019            let config = clocks.timg_calibration_clock?;
2020            match config {
2021                TimgCalibrationClockConfig::RcSlowClk => rc_slow_clk_root_source(clocks),
2022                TimgCalibrationClockConfig::RcFastDivClk => rc_fast_div_clk_root_source(clocks),
2023                TimgCalibrationClockConfig::Osc32kClk => osc_slow_clk_root_source(clocks),
2024            }
2025        }
2026        /// Returns the clock source that `APB_CLK` currently runs on.
2027        pub fn apb_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2028            let config = clocks.apb_clk?;
2029            match config {
2030                ApbClkConfig::Pll40m => pll_40m_root_source(clocks),
2031                ApbClkConfig::Cpu => cpu_clk_root_source(clocks),
2032            }
2033        }
2034        /// Returns the clock source that `CRYPTO_CLK` currently runs on.
2035        pub fn crypto_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2036            let config = clocks.crypto_clk?;
2037            match config {
2038                CryptoClkConfig::Pll80m => pll_80m_root_source(clocks),
2039                CryptoClkConfig::Cpu => cpu_clk_root_source(clocks),
2040            }
2041        }
2042        /// Returns the clock source that `MSPI_CLK` currently runs on.
2043        pub fn mspi_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2044            let config = clocks.mspi_clk?;
2045            match config {
2046                MspiClkConfig::CpuDiv2 => cpu_div2_root_source(clocks),
2047                MspiClkConfig::Cpu => cpu_clk_root_source(clocks),
2048            }
2049        }
2050        pub fn configure_xtal_clk(clocks: &mut ClockTree, config: XtalClkConfig) {
2051            let old_config = clocks.xtal_clk.replace(config);
2052            refresh_xtal_clk_downstream(clocks);
2053            configure_xtal_clk_impl(clocks, old_config, config);
2054        }
2055        pub fn xtal_clk_config(clocks: &mut ClockTree) -> Option<XtalClkConfig> {
2056            clocks.xtal_clk
2057        }
2058        fn request_xtal_clk(_clocks: &mut ClockTree) {}
2059        fn release_xtal_clk(_clocks: &mut ClockTree) {}
2060        pub fn xtal_clk_config_frequency(config: XtalClkConfig) -> u32 {
2061            config.value()
2062        }
2063        pub fn xtal_clk_frequency() -> u32 {
2064            XTAL_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2065        }
2066        pub fn request_pll_clk(clocks: &mut ClockTree) {
2067            trace!("Enabling PLL_CLK");
2068            request_xtal_clk(clocks);
2069            enable_pll_clk_impl(clocks, true);
2070        }
2071        pub fn release_pll_clk(clocks: &mut ClockTree) {
2072            trace!("Disabling PLL_CLK");
2073            enable_pll_clk_impl(clocks, false);
2074            release_xtal_clk(clocks);
2075        }
2076        pub fn pll_clk_frequency() -> u32 {
2077            480000000
2078        }
2079        pub fn pll_clk_source_frequency() -> u32 {
2080            xtal_clk_frequency()
2081        }
2082        pub fn request_rc_fast_clk(clocks: &mut ClockTree) {
2083            trace!("Requesting RC_FAST_CLK");
2084            if increment_reference_count(&mut clocks.rc_fast_clk_refcount) {
2085                trace!("Enabling RC_FAST_CLK");
2086                enable_rc_fast_clk_impl(clocks, true);
2087            }
2088        }
2089        pub fn release_rc_fast_clk(clocks: &mut ClockTree) {
2090            trace!("Releasing RC_FAST_CLK");
2091            if decrement_reference_count(&mut clocks.rc_fast_clk_refcount) {
2092                trace!("Disabling RC_FAST_CLK");
2093                enable_rc_fast_clk_impl(clocks, false);
2094            }
2095        }
2096        static RC_FAST_CLK_FREQUENCY: ::core::sync::atomic::AtomicU32 =
2097            ::core::sync::atomic::AtomicU32::new(rc_fast_clk_nominal_frequency());
2098        pub const fn rc_fast_clk_nominal_frequency() -> u32 {
2099            17500000
2100        }
2101        pub fn rc_fast_clk_frequency() -> u32 {
2102            RC_FAST_CLK_FREQUENCY.load(::core::sync::atomic::Ordering::Acquire)
2103        }
2104        pub fn set_rc_fast_clk_frequency(clocks: &mut ClockTree, frequency: u32) {
2105            if !(8750000..=26250000).contains(&frequency) {
2106                warn!(
2107                    "Ignoring out-of-range RC_FAST_CLK frequency: {} Hz",
2108                    frequency
2109                );
2110                return;
2111            }
2112            debug!(
2113                "Updating RC_FAST_CLK frequency to {} Hz (nominal {} Hz)",
2114                frequency,
2115                rc_fast_clk_nominal_frequency()
2116            );
2117            RC_FAST_CLK_FREQUENCY.store(frequency, ::core::sync::atomic::Ordering::Release);
2118            refresh_rc_fast_clk_downstream(clocks);
2119        }
2120        pub fn request_osc_slow_clk(clocks: &mut ClockTree) {
2121            trace!("Requesting OSC_SLOW_CLK");
2122            if increment_reference_count(&mut clocks.osc_slow_clk_refcount) {
2123                trace!("Enabling OSC_SLOW_CLK");
2124                enable_osc_slow_clk_impl(clocks, true);
2125            }
2126        }
2127        pub fn release_osc_slow_clk(clocks: &mut ClockTree) {
2128            trace!("Releasing OSC_SLOW_CLK");
2129            if decrement_reference_count(&mut clocks.osc_slow_clk_refcount) {
2130                trace!("Disabling OSC_SLOW_CLK");
2131                enable_osc_slow_clk_impl(clocks, false);
2132            }
2133        }
2134        pub fn osc_slow_clk_frequency() -> u32 {
2135            32768
2136        }
2137        pub fn request_rc_slow_clk(clocks: &mut ClockTree) {
2138            trace!("Requesting RC_SLOW_CLK");
2139            if increment_reference_count(&mut clocks.rc_slow_clk_refcount) {
2140                trace!("Enabling RC_SLOW_CLK");
2141                enable_rc_slow_clk_impl(clocks, true);
2142            }
2143        }
2144        pub fn release_rc_slow_clk(clocks: &mut ClockTree) {
2145            trace!("Releasing RC_SLOW_CLK");
2146            if decrement_reference_count(&mut clocks.rc_slow_clk_refcount) {
2147                trace!("Disabling RC_SLOW_CLK");
2148                enable_rc_slow_clk_impl(clocks, false);
2149            }
2150        }
2151        static RC_SLOW_CLK_FREQUENCY: ::core::sync::atomic::AtomicU32 =
2152            ::core::sync::atomic::AtomicU32::new(rc_slow_clk_nominal_frequency());
2153        pub const fn rc_slow_clk_nominal_frequency() -> u32 {
2154            136000
2155        }
2156        pub fn rc_slow_clk_frequency() -> u32 {
2157            RC_SLOW_CLK_FREQUENCY.load(::core::sync::atomic::Ordering::Acquire)
2158        }
2159        pub fn set_rc_slow_clk_frequency(clocks: &mut ClockTree, frequency: u32) {
2160            if !(68000..=204000).contains(&frequency) {
2161                warn!(
2162                    "Ignoring out-of-range RC_SLOW_CLK frequency: {} Hz",
2163                    frequency
2164                );
2165                return;
2166            }
2167            debug!(
2168                "Updating RC_SLOW_CLK frequency to {} Hz (nominal {} Hz)",
2169                frequency,
2170                rc_slow_clk_nominal_frequency()
2171            );
2172            RC_SLOW_CLK_FREQUENCY.store(frequency, ::core::sync::atomic::Ordering::Release);
2173            refresh_rc_slow_clk_downstream(clocks);
2174        }
2175        pub fn request_rc_fast_div_clk(clocks: &mut ClockTree) {
2176            trace!("Requesting RC_FAST_DIV_CLK");
2177            if increment_reference_count(&mut clocks.rc_fast_div_clk_refcount) {
2178                trace!("Enabling RC_FAST_DIV_CLK");
2179                request_rc_fast_clk(clocks);
2180                enable_rc_fast_div_clk_impl(clocks, true);
2181            }
2182        }
2183        pub fn release_rc_fast_div_clk(clocks: &mut ClockTree) {
2184            trace!("Releasing RC_FAST_DIV_CLK");
2185            if decrement_reference_count(&mut clocks.rc_fast_div_clk_refcount) {
2186                trace!("Disabling RC_FAST_DIV_CLK");
2187                enable_rc_fast_div_clk_impl(clocks, false);
2188                release_rc_fast_clk(clocks);
2189            }
2190        }
2191        pub fn rc_fast_div_clk_frequency() -> u32 {
2192            (rc_fast_clk_frequency() / 256)
2193        }
2194        pub fn rc_fast_div_clk_source_frequency() -> u32 {
2195            rc_fast_clk_frequency()
2196        }
2197        pub fn configure_system_pre_div_in(
2198            clocks: &mut ClockTree,
2199            new_selector: SystemPreDivInConfig,
2200        ) {
2201            let old_selector = clocks.system_pre_div_in.replace(new_selector);
2202            refresh_system_pre_div_in_downstream(clocks);
2203            match new_selector {
2204                SystemPreDivInConfig::Xtal => request_xtal_clk(clocks),
2205                SystemPreDivInConfig::RcFast => request_rc_fast_clk(clocks),
2206            }
2207            configure_system_pre_div_in_impl(clocks, old_selector, new_selector);
2208            if let Some(old_selector) = old_selector {
2209                match old_selector {
2210                    SystemPreDivInConfig::Xtal => release_xtal_clk(clocks),
2211                    SystemPreDivInConfig::RcFast => release_rc_fast_clk(clocks),
2212                }
2213            }
2214        }
2215        pub fn system_pre_div_in_config(clocks: &mut ClockTree) -> Option<SystemPreDivInConfig> {
2216            clocks.system_pre_div_in
2217        }
2218        pub fn request_system_pre_div_in(clocks: &mut ClockTree) {
2219            trace!("Enabling SYSTEM_PRE_DIV_IN");
2220            match unwrap!(clocks.system_pre_div_in) {
2221                SystemPreDivInConfig::Xtal => request_xtal_clk(clocks),
2222                SystemPreDivInConfig::RcFast => request_rc_fast_clk(clocks),
2223            }
2224            enable_system_pre_div_in_impl(clocks, true);
2225        }
2226        pub fn release_system_pre_div_in(clocks: &mut ClockTree) {
2227            trace!("Disabling SYSTEM_PRE_DIV_IN");
2228            enable_system_pre_div_in_impl(clocks, false);
2229            match unwrap!(clocks.system_pre_div_in) {
2230                SystemPreDivInConfig::Xtal => release_xtal_clk(clocks),
2231                SystemPreDivInConfig::RcFast => release_rc_fast_clk(clocks),
2232            }
2233        }
2234        pub fn system_pre_div_in_config_frequency(config: SystemPreDivInConfig) -> u32 {
2235            match config {
2236                SystemPreDivInConfig::Xtal => xtal_clk_frequency(),
2237                SystemPreDivInConfig::RcFast => rc_fast_clk_frequency(),
2238            }
2239        }
2240        pub fn system_pre_div_in_frequency() -> u32 {
2241            SYSTEM_PRE_DIV_IN_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2242        }
2243        pub fn system_pre_div_in_source_frequency(source: SystemPreDivInConfig) -> u32 {
2244            system_pre_div_in_config_frequency(source)
2245        }
2246        pub fn configure_system_pre_div(clocks: &mut ClockTree, config: SystemPreDivConfig) {
2247            let old_config = clocks.system_pre_div.replace(config);
2248            refresh_system_pre_div_downstream(clocks);
2249            configure_system_pre_div_impl(clocks, old_config, config);
2250        }
2251        pub fn system_pre_div_config(clocks: &mut ClockTree) -> Option<SystemPreDivConfig> {
2252            clocks.system_pre_div
2253        }
2254        pub fn request_system_pre_div(clocks: &mut ClockTree) {
2255            trace!("Enabling SYSTEM_PRE_DIV");
2256            request_system_pre_div_in(clocks);
2257            enable_system_pre_div_impl(clocks, true);
2258        }
2259        pub fn release_system_pre_div(clocks: &mut ClockTree) {
2260            trace!("Disabling SYSTEM_PRE_DIV");
2261            enable_system_pre_div_impl(clocks, false);
2262            release_system_pre_div_in(clocks);
2263        }
2264        pub fn system_pre_div_config_frequency(config: SystemPreDivConfig) -> u32 {
2265            (system_pre_div_in_frequency() / (config.divisor() + 1))
2266        }
2267        pub fn system_pre_div_frequency() -> u32 {
2268            SYSTEM_PRE_DIV_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2269        }
2270        pub fn system_pre_div_source_frequency() -> u32 {
2271            system_pre_div_in_frequency()
2272        }
2273        pub fn configure_cpu_pll_div(clocks: &mut ClockTree, config: CpuPllDivConfig) {
2274            let old_config = clocks.cpu_pll_div.replace(config);
2275            refresh_cpu_pll_div_downstream(clocks);
2276            configure_cpu_pll_div_impl(clocks, old_config, config);
2277        }
2278        pub fn cpu_pll_div_config(clocks: &mut ClockTree) -> Option<CpuPllDivConfig> {
2279            clocks.cpu_pll_div
2280        }
2281        pub fn request_cpu_pll_div(clocks: &mut ClockTree) {
2282            trace!("Enabling CPU_PLL_DIV");
2283            request_pll_clk(clocks);
2284            enable_cpu_pll_div_impl(clocks, true);
2285        }
2286        pub fn release_cpu_pll_div(clocks: &mut ClockTree) {
2287            trace!("Disabling CPU_PLL_DIV");
2288            enable_cpu_pll_div_impl(clocks, false);
2289            release_pll_clk(clocks);
2290        }
2291        pub fn cpu_pll_div_config_frequency(config: CpuPllDivConfig) -> u32 {
2292            (pll_clk_frequency() / config.divisor())
2293        }
2294        pub fn cpu_pll_div_frequency() -> u32 {
2295            CPU_PLL_DIV_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2296        }
2297        pub fn cpu_pll_div_source_frequency() -> u32 {
2298            pll_clk_frequency()
2299        }
2300        pub fn configure_apb_clk(clocks: &mut ClockTree, new_selector: ApbClkConfig) {
2301            let old_selector = clocks.apb_clk.replace(new_selector);
2302            refresh_apb_clk_downstream(clocks);
2303            match new_selector {
2304                ApbClkConfig::Pll40m => request_pll_40m(clocks),
2305                ApbClkConfig::Cpu => request_cpu_clk(clocks),
2306            }
2307            configure_apb_clk_impl(clocks, old_selector, new_selector);
2308            if let Some(old_selector) = old_selector {
2309                match old_selector {
2310                    ApbClkConfig::Pll40m => release_pll_40m(clocks),
2311                    ApbClkConfig::Cpu => release_cpu_clk(clocks),
2312                }
2313            }
2314        }
2315        pub fn apb_clk_config(clocks: &mut ClockTree) -> Option<ApbClkConfig> {
2316            clocks.apb_clk
2317        }
2318        pub fn request_apb_clk(clocks: &mut ClockTree) {
2319            trace!("Enabling APB_CLK");
2320            match unwrap!(clocks.apb_clk) {
2321                ApbClkConfig::Pll40m => request_pll_40m(clocks),
2322                ApbClkConfig::Cpu => request_cpu_clk(clocks),
2323            }
2324            enable_apb_clk_impl(clocks, true);
2325        }
2326        pub fn release_apb_clk(clocks: &mut ClockTree) {
2327            trace!("Disabling APB_CLK");
2328            enable_apb_clk_impl(clocks, false);
2329            match unwrap!(clocks.apb_clk) {
2330                ApbClkConfig::Pll40m => release_pll_40m(clocks),
2331                ApbClkConfig::Cpu => release_cpu_clk(clocks),
2332            }
2333        }
2334        pub fn apb_clk_config_frequency(config: ApbClkConfig) -> u32 {
2335            match config {
2336                ApbClkConfig::Pll40m => pll_40m_frequency(),
2337                ApbClkConfig::Cpu => cpu_clk_frequency(),
2338            }
2339        }
2340        pub fn apb_clk_frequency() -> u32 {
2341            APB_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2342        }
2343        pub fn apb_clk_source_frequency(source: ApbClkConfig) -> u32 {
2344            apb_clk_config_frequency(source)
2345        }
2346        pub fn configure_crypto_clk(clocks: &mut ClockTree, new_selector: CryptoClkConfig) {
2347            let old_selector = clocks.crypto_clk.replace(new_selector);
2348            refresh_crypto_clk_downstream(clocks);
2349            let active = clocks.crypto_clk_refcount > 0;
2350            if active {
2351                match new_selector {
2352                    CryptoClkConfig::Pll80m => request_pll_80m(clocks),
2353                    CryptoClkConfig::Cpu => request_cpu_clk(clocks),
2354                }
2355            }
2356            configure_crypto_clk_impl(clocks, old_selector, new_selector);
2357            if active && let Some(old_selector) = old_selector {
2358                match old_selector {
2359                    CryptoClkConfig::Pll80m => release_pll_80m(clocks),
2360                    CryptoClkConfig::Cpu => release_cpu_clk(clocks),
2361                }
2362            }
2363        }
2364        pub fn crypto_clk_config(clocks: &mut ClockTree) -> Option<CryptoClkConfig> {
2365            clocks.crypto_clk
2366        }
2367        pub fn request_crypto_clk(clocks: &mut ClockTree) {
2368            trace!("Requesting CRYPTO_CLK");
2369            if increment_reference_count(&mut clocks.crypto_clk_refcount) {
2370                trace!("Enabling CRYPTO_CLK");
2371                match unwrap!(clocks.crypto_clk) {
2372                    CryptoClkConfig::Pll80m => request_pll_80m(clocks),
2373                    CryptoClkConfig::Cpu => request_cpu_clk(clocks),
2374                }
2375                enable_crypto_clk_impl(clocks, true);
2376            }
2377        }
2378        pub fn release_crypto_clk(clocks: &mut ClockTree) {
2379            trace!("Releasing CRYPTO_CLK");
2380            if decrement_reference_count(&mut clocks.crypto_clk_refcount) {
2381                trace!("Disabling CRYPTO_CLK");
2382                enable_crypto_clk_impl(clocks, false);
2383                match unwrap!(clocks.crypto_clk) {
2384                    CryptoClkConfig::Pll80m => release_pll_80m(clocks),
2385                    CryptoClkConfig::Cpu => release_cpu_clk(clocks),
2386                }
2387            }
2388        }
2389        pub fn crypto_clk_config_frequency(config: CryptoClkConfig) -> u32 {
2390            match config {
2391                CryptoClkConfig::Pll80m => pll_80m_frequency(),
2392                CryptoClkConfig::Cpu => cpu_clk_frequency(),
2393            }
2394        }
2395        pub fn crypto_clk_frequency() -> u32 {
2396            CRYPTO_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2397        }
2398        pub fn crypto_clk_source_frequency(source: CryptoClkConfig) -> u32 {
2399            crypto_clk_config_frequency(source)
2400        }
2401        pub fn configure_mspi_clk(clocks: &mut ClockTree, new_selector: MspiClkConfig) {
2402            let old_selector = clocks.mspi_clk.replace(new_selector);
2403            refresh_mspi_clk_downstream(clocks);
2404            let active = clocks.mspi_clk_refcount > 0;
2405            if active {
2406                match new_selector {
2407                    MspiClkConfig::CpuDiv2 => request_cpu_div2(clocks),
2408                    MspiClkConfig::Cpu => request_cpu_clk(clocks),
2409                }
2410            }
2411            configure_mspi_clk_impl(clocks, old_selector, new_selector);
2412            if active && let Some(old_selector) = old_selector {
2413                match old_selector {
2414                    MspiClkConfig::CpuDiv2 => release_cpu_div2(clocks),
2415                    MspiClkConfig::Cpu => release_cpu_clk(clocks),
2416                }
2417            }
2418        }
2419        pub fn mspi_clk_config(clocks: &mut ClockTree) -> Option<MspiClkConfig> {
2420            clocks.mspi_clk
2421        }
2422        pub fn request_mspi_clk(clocks: &mut ClockTree) {
2423            trace!("Requesting MSPI_CLK");
2424            if increment_reference_count(&mut clocks.mspi_clk_refcount) {
2425                trace!("Enabling MSPI_CLK");
2426                match unwrap!(clocks.mspi_clk) {
2427                    MspiClkConfig::CpuDiv2 => request_cpu_div2(clocks),
2428                    MspiClkConfig::Cpu => request_cpu_clk(clocks),
2429                }
2430                enable_mspi_clk_impl(clocks, true);
2431            }
2432        }
2433        pub fn release_mspi_clk(clocks: &mut ClockTree) {
2434            trace!("Releasing MSPI_CLK");
2435            if decrement_reference_count(&mut clocks.mspi_clk_refcount) {
2436                trace!("Disabling MSPI_CLK");
2437                enable_mspi_clk_impl(clocks, false);
2438                match unwrap!(clocks.mspi_clk) {
2439                    MspiClkConfig::CpuDiv2 => release_cpu_div2(clocks),
2440                    MspiClkConfig::Cpu => release_cpu_clk(clocks),
2441                }
2442            }
2443        }
2444        pub fn mspi_clk_config_frequency(config: MspiClkConfig) -> u32 {
2445            match config {
2446                MspiClkConfig::CpuDiv2 => cpu_div2_frequency(),
2447                MspiClkConfig::Cpu => cpu_clk_frequency(),
2448            }
2449        }
2450        pub fn mspi_clk_frequency() -> u32 {
2451            MSPI_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2452        }
2453        pub fn mspi_clk_source_frequency(source: MspiClkConfig) -> u32 {
2454            mspi_clk_config_frequency(source)
2455        }
2456        pub fn configure_cpu_clk(clocks: &mut ClockTree, new_selector: CpuClkConfig) {
2457            let old_selector = clocks.cpu_clk.replace(new_selector);
2458            refresh_cpu_clk_downstream(clocks);
2459            match new_selector {
2460                CpuClkConfig::Xtal => {
2461                    configure_apb_clk(clocks, ApbClkConfig::Cpu);
2462                    configure_crypto_clk(clocks, CryptoClkConfig::Cpu);
2463                    configure_mspi_clk(clocks, MspiClkConfig::Cpu);
2464                    configure_system_pre_div_in(clocks, SystemPreDivInConfig::Xtal);
2465                }
2466                CpuClkConfig::RcFast => {
2467                    configure_apb_clk(clocks, ApbClkConfig::Cpu);
2468                    configure_crypto_clk(clocks, CryptoClkConfig::Cpu);
2469                    configure_mspi_clk(clocks, MspiClkConfig::Cpu);
2470                    configure_system_pre_div_in(clocks, SystemPreDivInConfig::RcFast);
2471                }
2472                CpuClkConfig::Pll => {
2473                    configure_apb_clk(clocks, ApbClkConfig::Pll40m);
2474                    configure_crypto_clk(clocks, CryptoClkConfig::Pll80m);
2475                    configure_mspi_clk(clocks, MspiClkConfig::CpuDiv2);
2476                }
2477            }
2478            match new_selector {
2479                CpuClkConfig::Xtal => request_system_pre_div(clocks),
2480                CpuClkConfig::RcFast => request_system_pre_div(clocks),
2481                CpuClkConfig::Pll => request_cpu_pll_div(clocks),
2482            }
2483            configure_cpu_clk_impl(clocks, old_selector, new_selector);
2484            if let Some(old_selector) = old_selector {
2485                match old_selector {
2486                    CpuClkConfig::Xtal => release_system_pre_div(clocks),
2487                    CpuClkConfig::RcFast => release_system_pre_div(clocks),
2488                    CpuClkConfig::Pll => release_cpu_pll_div(clocks),
2489                }
2490            }
2491        }
2492        pub fn cpu_clk_config(clocks: &mut ClockTree) -> Option<CpuClkConfig> {
2493            clocks.cpu_clk
2494        }
2495        fn request_cpu_clk(_clocks: &mut ClockTree) {}
2496        fn release_cpu_clk(_clocks: &mut ClockTree) {}
2497        pub fn cpu_clk_config_frequency(config: CpuClkConfig) -> u32 {
2498            match config {
2499                CpuClkConfig::Xtal => system_pre_div_frequency(),
2500                CpuClkConfig::RcFast => system_pre_div_frequency(),
2501                CpuClkConfig::Pll => cpu_pll_div_frequency(),
2502            }
2503        }
2504        pub fn cpu_clk_frequency() -> u32 {
2505            CPU_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2506        }
2507        pub fn request_pll_40m(clocks: &mut ClockTree) {
2508            trace!("Requesting PLL_40M");
2509            if increment_reference_count(&mut clocks.pll_40m_refcount) {
2510                trace!("Enabling PLL_40M");
2511                request_cpu_clk(clocks);
2512                enable_pll_40m_impl(clocks, true);
2513            }
2514        }
2515        pub fn release_pll_40m(clocks: &mut ClockTree) {
2516            trace!("Releasing PLL_40M");
2517            if decrement_reference_count(&mut clocks.pll_40m_refcount) {
2518                trace!("Disabling PLL_40M");
2519                enable_pll_40m_impl(clocks, false);
2520                release_cpu_clk(clocks);
2521            }
2522        }
2523        pub fn pll_40m_frequency() -> u32 {
2524            40000000
2525        }
2526        pub fn pll_40m_source_frequency() -> u32 {
2527            cpu_clk_frequency()
2528        }
2529        pub fn request_pll_60m(clocks: &mut ClockTree) {
2530            trace!("Requesting PLL_60M");
2531            if increment_reference_count(&mut clocks.pll_60m_refcount) {
2532                trace!("Enabling PLL_60M");
2533                request_cpu_clk(clocks);
2534                enable_pll_60m_impl(clocks, true);
2535            }
2536        }
2537        pub fn release_pll_60m(clocks: &mut ClockTree) {
2538            trace!("Releasing PLL_60M");
2539            if decrement_reference_count(&mut clocks.pll_60m_refcount) {
2540                trace!("Disabling PLL_60M");
2541                enable_pll_60m_impl(clocks, false);
2542                release_cpu_clk(clocks);
2543            }
2544        }
2545        pub fn pll_60m_frequency() -> u32 {
2546            60000000
2547        }
2548        pub fn pll_60m_source_frequency() -> u32 {
2549            cpu_clk_frequency()
2550        }
2551        pub fn request_pll_80m(clocks: &mut ClockTree) {
2552            trace!("Enabling PLL_80M");
2553            request_cpu_clk(clocks);
2554            enable_pll_80m_impl(clocks, true);
2555        }
2556        pub fn release_pll_80m(clocks: &mut ClockTree) {
2557            trace!("Disabling PLL_80M");
2558            enable_pll_80m_impl(clocks, false);
2559            release_cpu_clk(clocks);
2560        }
2561        pub fn pll_80m_frequency() -> u32 {
2562            80000000
2563        }
2564        pub fn pll_80m_source_frequency() -> u32 {
2565            cpu_clk_frequency()
2566        }
2567        pub fn request_cpu_div2(clocks: &mut ClockTree) {
2568            trace!("Enabling CPU_DIV2");
2569            request_cpu_clk(clocks);
2570            enable_cpu_div2_impl(clocks, true);
2571        }
2572        pub fn release_cpu_div2(clocks: &mut ClockTree) {
2573            trace!("Disabling CPU_DIV2");
2574            enable_cpu_div2_impl(clocks, false);
2575            release_cpu_clk(clocks);
2576        }
2577        pub fn cpu_div2_frequency() -> u32 {
2578            (cpu_clk_frequency() / 2)
2579        }
2580        pub fn cpu_div2_source_frequency() -> u32 {
2581            cpu_clk_frequency()
2582        }
2583        pub fn configure_rc_fast_clk_div_n(clocks: &mut ClockTree, config: RcFastClkDivNConfig) {
2584            let old_config = clocks.rc_fast_clk_div_n.replace(config);
2585            refresh_rc_fast_clk_div_n_downstream(clocks);
2586            configure_rc_fast_clk_div_n_impl(clocks, old_config, config);
2587        }
2588        pub fn rc_fast_clk_div_n_config(clocks: &mut ClockTree) -> Option<RcFastClkDivNConfig> {
2589            clocks.rc_fast_clk_div_n
2590        }
2591        pub fn request_rc_fast_clk_div_n(clocks: &mut ClockTree) {
2592            trace!("Enabling RC_FAST_CLK_DIV_N");
2593            request_rc_fast_clk(clocks);
2594            enable_rc_fast_clk_div_n_impl(clocks, true);
2595        }
2596        pub fn release_rc_fast_clk_div_n(clocks: &mut ClockTree) {
2597            trace!("Disabling RC_FAST_CLK_DIV_N");
2598            enable_rc_fast_clk_div_n_impl(clocks, false);
2599            release_rc_fast_clk(clocks);
2600        }
2601        pub fn rc_fast_clk_div_n_config_frequency(config: RcFastClkDivNConfig) -> u32 {
2602            (rc_fast_clk_frequency() / (config.divisor() + 1))
2603        }
2604        pub fn rc_fast_clk_div_n_frequency() -> u32 {
2605            RC_FAST_CLK_DIV_N_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2606        }
2607        pub fn rc_fast_clk_div_n_source_frequency() -> u32 {
2608            rc_fast_clk_frequency()
2609        }
2610        pub fn request_xtal_div_clk(clocks: &mut ClockTree) {
2611            trace!("Enabling XTAL_DIV_CLK");
2612            request_xtal_clk(clocks);
2613            enable_xtal_div_clk_impl(clocks, true);
2614        }
2615        pub fn release_xtal_div_clk(clocks: &mut ClockTree) {
2616            trace!("Disabling XTAL_DIV_CLK");
2617            enable_xtal_div_clk_impl(clocks, false);
2618            release_xtal_clk(clocks);
2619        }
2620        pub fn xtal_div_clk_frequency() -> u32 {
2621            (xtal_clk_frequency() / 2)
2622        }
2623        pub fn xtal_div_clk_source_frequency() -> u32 {
2624            xtal_clk_frequency()
2625        }
2626        pub fn configure_rtc_slow_clk(clocks: &mut ClockTree, new_selector: RtcSlowClkConfig) {
2627            let old_selector = clocks.rtc_slow_clk.replace(new_selector);
2628            refresh_rtc_slow_clk_downstream(clocks);
2629            match new_selector {
2630                RtcSlowClkConfig::OscSlow => request_osc_slow_clk(clocks),
2631                RtcSlowClkConfig::RcSlow => request_rc_slow_clk(clocks),
2632                RtcSlowClkConfig::RcFast => request_rc_fast_div_clk(clocks),
2633            }
2634            configure_rtc_slow_clk_impl(clocks, old_selector, new_selector);
2635            if let Some(old_selector) = old_selector {
2636                match old_selector {
2637                    RtcSlowClkConfig::OscSlow => release_osc_slow_clk(clocks),
2638                    RtcSlowClkConfig::RcSlow => release_rc_slow_clk(clocks),
2639                    RtcSlowClkConfig::RcFast => release_rc_fast_div_clk(clocks),
2640                }
2641            }
2642        }
2643        pub fn rtc_slow_clk_config(clocks: &mut ClockTree) -> Option<RtcSlowClkConfig> {
2644            clocks.rtc_slow_clk
2645        }
2646        pub fn request_rtc_slow_clk(clocks: &mut ClockTree) {
2647            trace!("Enabling RTC_SLOW_CLK");
2648            match unwrap!(clocks.rtc_slow_clk) {
2649                RtcSlowClkConfig::OscSlow => request_osc_slow_clk(clocks),
2650                RtcSlowClkConfig::RcSlow => request_rc_slow_clk(clocks),
2651                RtcSlowClkConfig::RcFast => request_rc_fast_div_clk(clocks),
2652            }
2653            enable_rtc_slow_clk_impl(clocks, true);
2654        }
2655        pub fn release_rtc_slow_clk(clocks: &mut ClockTree) {
2656            trace!("Disabling RTC_SLOW_CLK");
2657            enable_rtc_slow_clk_impl(clocks, false);
2658            match unwrap!(clocks.rtc_slow_clk) {
2659                RtcSlowClkConfig::OscSlow => release_osc_slow_clk(clocks),
2660                RtcSlowClkConfig::RcSlow => release_rc_slow_clk(clocks),
2661                RtcSlowClkConfig::RcFast => release_rc_fast_div_clk(clocks),
2662            }
2663        }
2664        pub fn rtc_slow_clk_config_frequency(config: RtcSlowClkConfig) -> u32 {
2665            match config {
2666                RtcSlowClkConfig::OscSlow => osc_slow_clk_frequency(),
2667                RtcSlowClkConfig::RcSlow => rc_slow_clk_frequency(),
2668                RtcSlowClkConfig::RcFast => rc_fast_div_clk_frequency(),
2669            }
2670        }
2671        pub fn rtc_slow_clk_frequency() -> u32 {
2672            RTC_SLOW_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2673        }
2674        pub fn rtc_slow_clk_source_frequency(source: RtcSlowClkConfig) -> u32 {
2675            rtc_slow_clk_config_frequency(source)
2676        }
2677        pub fn request_ble_lp_xtal_clk(clocks: &mut ClockTree) {
2678            trace!("Enabling BLE_LP_XTAL_CLK");
2679            request_xtal_clk(clocks);
2680            enable_ble_lp_xtal_clk_impl(clocks, true);
2681        }
2682        pub fn release_ble_lp_xtal_clk(clocks: &mut ClockTree) {
2683            trace!("Disabling BLE_LP_XTAL_CLK");
2684            enable_ble_lp_xtal_clk_impl(clocks, false);
2685            release_xtal_clk(clocks);
2686        }
2687        pub fn ble_lp_xtal_clk_frequency() -> u32 {
2688            (xtal_clk_frequency() / 5)
2689        }
2690        pub fn ble_lp_xtal_clk_source_frequency() -> u32 {
2691            xtal_clk_frequency()
2692        }
2693        pub fn request_ble_lp_rc_slow_clk(clocks: &mut ClockTree) {
2694            trace!("Enabling BLE_LP_RC_SLOW_CLK");
2695            request_rc_slow_clk(clocks);
2696            enable_ble_lp_rc_slow_clk_impl(clocks, true);
2697        }
2698        pub fn release_ble_lp_rc_slow_clk(clocks: &mut ClockTree) {
2699            trace!("Disabling BLE_LP_RC_SLOW_CLK");
2700            enable_ble_lp_rc_slow_clk_impl(clocks, false);
2701            release_rc_slow_clk(clocks);
2702        }
2703        pub fn ble_lp_rc_slow_clk_frequency() -> u32 {
2704            (rc_slow_clk_frequency() / 5)
2705        }
2706        pub fn ble_lp_rc_slow_clk_source_frequency() -> u32 {
2707            rc_slow_clk_frequency()
2708        }
2709        pub fn configure_ble_lp_clk(clocks: &mut ClockTree, config: BleLpClkConfig) {
2710            let old_config = clocks.ble_lp_clk.replace(config);
2711            refresh_ble_lp_clk_downstream(clocks);
2712            let active = clocks.ble_lp_clk_refcount > 0;
2713            if active {
2714                match config.sclk {
2715                    BleLpClkSclk::Xtal => request_ble_lp_xtal_clk(clocks),
2716                    BleLpClkSclk::RcSlow => request_ble_lp_rc_slow_clk(clocks),
2717                }
2718            }
2719            configure_ble_lp_clk_impl(clocks, old_config, config);
2720            if active && let Some(old_config) = old_config {
2721                match old_config.sclk {
2722                    BleLpClkSclk::Xtal => release_ble_lp_xtal_clk(clocks),
2723                    BleLpClkSclk::RcSlow => release_ble_lp_rc_slow_clk(clocks),
2724                }
2725            }
2726        }
2727        pub fn ble_lp_clk_config(clocks: &mut ClockTree) -> Option<BleLpClkConfig> {
2728            clocks.ble_lp_clk
2729        }
2730        pub fn request_ble_lp_clk(clocks: &mut ClockTree) {
2731            trace!("Requesting BLE_LP_CLK");
2732            if increment_reference_count(&mut clocks.ble_lp_clk_refcount) {
2733                trace!("Enabling BLE_LP_CLK");
2734                match unwrap!(clocks.ble_lp_clk).sclk {
2735                    BleLpClkSclk::Xtal => request_ble_lp_xtal_clk(clocks),
2736                    BleLpClkSclk::RcSlow => request_ble_lp_rc_slow_clk(clocks),
2737                }
2738                enable_ble_lp_clk_impl(clocks, true);
2739            }
2740        }
2741        pub fn release_ble_lp_clk(clocks: &mut ClockTree) {
2742            trace!("Releasing BLE_LP_CLK");
2743            if decrement_reference_count(&mut clocks.ble_lp_clk_refcount) {
2744                trace!("Disabling BLE_LP_CLK");
2745                enable_ble_lp_clk_impl(clocks, false);
2746                match unwrap!(clocks.ble_lp_clk).sclk {
2747                    BleLpClkSclk::Xtal => release_ble_lp_xtal_clk(clocks),
2748                    BleLpClkSclk::RcSlow => release_ble_lp_rc_slow_clk(clocks),
2749                }
2750            }
2751        }
2752        pub fn ble_lp_clk_config_frequency(config: BleLpClkConfig) -> u32 {
2753            (match config.sclk {
2754                BleLpClkSclk::Xtal => ble_lp_xtal_clk_frequency(),
2755                BleLpClkSclk::RcSlow => ble_lp_rc_slow_clk_frequency(),
2756            } / (config.divisor() + 1))
2757        }
2758        pub fn ble_lp_clk_frequency() -> u32 {
2759            BLE_LP_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2760        }
2761        pub fn ble_lp_clk_source_frequency(sclk: BleLpClkSclk) -> u32 {
2762            match sclk {
2763                BleLpClkSclk::Xtal => ble_lp_xtal_clk_frequency(),
2764                BleLpClkSclk::RcSlow => ble_lp_rc_slow_clk_frequency(),
2765            }
2766        }
2767        pub fn configure_rtc_fast_clk(clocks: &mut ClockTree, new_selector: RtcFastClkConfig) {
2768            let old_selector = clocks.rtc_fast_clk.replace(new_selector);
2769            refresh_rtc_fast_clk_downstream(clocks);
2770            let active = clocks.rtc_fast_clk_refcount > 0;
2771            if active {
2772                match new_selector {
2773                    RtcFastClkConfig::Xtal => request_xtal_div_clk(clocks),
2774                    RtcFastClkConfig::Rc => request_rc_fast_clk_div_n(clocks),
2775                }
2776            }
2777            configure_rtc_fast_clk_impl(clocks, old_selector, new_selector);
2778            if active && let Some(old_selector) = old_selector {
2779                match old_selector {
2780                    RtcFastClkConfig::Xtal => release_xtal_div_clk(clocks),
2781                    RtcFastClkConfig::Rc => release_rc_fast_clk_div_n(clocks),
2782                }
2783            }
2784        }
2785        pub fn rtc_fast_clk_config(clocks: &mut ClockTree) -> Option<RtcFastClkConfig> {
2786            clocks.rtc_fast_clk
2787        }
2788        pub fn request_rtc_fast_clk(clocks: &mut ClockTree) {
2789            trace!("Requesting RTC_FAST_CLK");
2790            if increment_reference_count(&mut clocks.rtc_fast_clk_refcount) {
2791                trace!("Enabling RTC_FAST_CLK");
2792                match unwrap!(clocks.rtc_fast_clk) {
2793                    RtcFastClkConfig::Xtal => request_xtal_div_clk(clocks),
2794                    RtcFastClkConfig::Rc => request_rc_fast_clk_div_n(clocks),
2795                }
2796                enable_rtc_fast_clk_impl(clocks, true);
2797            }
2798        }
2799        pub fn release_rtc_fast_clk(clocks: &mut ClockTree) {
2800            trace!("Releasing RTC_FAST_CLK");
2801            if decrement_reference_count(&mut clocks.rtc_fast_clk_refcount) {
2802                trace!("Disabling RTC_FAST_CLK");
2803                enable_rtc_fast_clk_impl(clocks, false);
2804                match unwrap!(clocks.rtc_fast_clk) {
2805                    RtcFastClkConfig::Xtal => release_xtal_div_clk(clocks),
2806                    RtcFastClkConfig::Rc => release_rc_fast_clk_div_n(clocks),
2807                }
2808            }
2809        }
2810        pub fn rtc_fast_clk_config_frequency(config: RtcFastClkConfig) -> u32 {
2811            match config {
2812                RtcFastClkConfig::Xtal => xtal_div_clk_frequency(),
2813                RtcFastClkConfig::Rc => rc_fast_clk_div_n_frequency(),
2814            }
2815        }
2816        pub fn rtc_fast_clk_frequency() -> u32 {
2817            RTC_FAST_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2818        }
2819        pub fn rtc_fast_clk_source_frequency(source: RtcFastClkConfig) -> u32 {
2820            rtc_fast_clk_config_frequency(source)
2821        }
2822        pub fn configure_low_power_clk(clocks: &mut ClockTree, new_selector: LowPowerClkConfig) {
2823            let old_selector = clocks.low_power_clk.replace(new_selector);
2824            refresh_low_power_clk_downstream(clocks);
2825            let active = clocks.low_power_clk_refcount > 0;
2826            if active {
2827                match new_selector {
2828                    LowPowerClkConfig::Xtal => request_xtal_clk(clocks),
2829                    LowPowerClkConfig::RcFast => request_rc_fast_clk(clocks),
2830                    LowPowerClkConfig::OscSlow => request_osc_slow_clk(clocks),
2831                    LowPowerClkConfig::RtcSlow => request_rtc_slow_clk(clocks),
2832                }
2833            }
2834            configure_low_power_clk_impl(clocks, old_selector, new_selector);
2835            if active && let Some(old_selector) = old_selector {
2836                match old_selector {
2837                    LowPowerClkConfig::Xtal => release_xtal_clk(clocks),
2838                    LowPowerClkConfig::RcFast => release_rc_fast_clk(clocks),
2839                    LowPowerClkConfig::OscSlow => release_osc_slow_clk(clocks),
2840                    LowPowerClkConfig::RtcSlow => release_rtc_slow_clk(clocks),
2841                }
2842            }
2843        }
2844        pub fn low_power_clk_config(clocks: &mut ClockTree) -> Option<LowPowerClkConfig> {
2845            clocks.low_power_clk
2846        }
2847        pub fn request_low_power_clk(clocks: &mut ClockTree) {
2848            trace!("Requesting LOW_POWER_CLK");
2849            if increment_reference_count(&mut clocks.low_power_clk_refcount) {
2850                trace!("Enabling LOW_POWER_CLK");
2851                match unwrap!(clocks.low_power_clk) {
2852                    LowPowerClkConfig::Xtal => request_xtal_clk(clocks),
2853                    LowPowerClkConfig::RcFast => request_rc_fast_clk(clocks),
2854                    LowPowerClkConfig::OscSlow => request_osc_slow_clk(clocks),
2855                    LowPowerClkConfig::RtcSlow => request_rtc_slow_clk(clocks),
2856                }
2857                enable_low_power_clk_impl(clocks, true);
2858            }
2859        }
2860        pub fn release_low_power_clk(clocks: &mut ClockTree) {
2861            trace!("Releasing LOW_POWER_CLK");
2862            if decrement_reference_count(&mut clocks.low_power_clk_refcount) {
2863                trace!("Disabling LOW_POWER_CLK");
2864                enable_low_power_clk_impl(clocks, false);
2865                match unwrap!(clocks.low_power_clk) {
2866                    LowPowerClkConfig::Xtal => release_xtal_clk(clocks),
2867                    LowPowerClkConfig::RcFast => release_rc_fast_clk(clocks),
2868                    LowPowerClkConfig::OscSlow => release_osc_slow_clk(clocks),
2869                    LowPowerClkConfig::RtcSlow => release_rtc_slow_clk(clocks),
2870                }
2871            }
2872        }
2873        pub fn low_power_clk_config_frequency(config: LowPowerClkConfig) -> u32 {
2874            match config {
2875                LowPowerClkConfig::Xtal => xtal_clk_frequency(),
2876                LowPowerClkConfig::RcFast => rc_fast_clk_frequency(),
2877                LowPowerClkConfig::OscSlow => osc_slow_clk_frequency(),
2878                LowPowerClkConfig::RtcSlow => rtc_slow_clk_frequency(),
2879            }
2880        }
2881        pub fn low_power_clk_frequency() -> u32 {
2882            LOW_POWER_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2883        }
2884        pub fn low_power_clk_source_frequency(source: LowPowerClkConfig) -> u32 {
2885            low_power_clk_config_frequency(source)
2886        }
2887        pub fn request_uart_mem_clk(clocks: &mut ClockTree) {
2888            trace!("Requesting UART_MEM_CLK");
2889            if increment_reference_count(&mut clocks.uart_mem_clk_refcount) {
2890                trace!("Enabling UART_MEM_CLK");
2891                request_xtal_clk(clocks);
2892                enable_uart_mem_clk_impl(clocks, true);
2893            }
2894        }
2895        pub fn release_uart_mem_clk(clocks: &mut ClockTree) {
2896            trace!("Releasing UART_MEM_CLK");
2897            if decrement_reference_count(&mut clocks.uart_mem_clk_refcount) {
2898                trace!("Disabling UART_MEM_CLK");
2899                enable_uart_mem_clk_impl(clocks, false);
2900                release_xtal_clk(clocks);
2901            }
2902        }
2903        pub fn uart_mem_clk_frequency() -> u32 {
2904            xtal_clk_frequency()
2905        }
2906        pub fn uart_mem_clk_source_frequency(source: UartMemClkConfig) -> u32 {
2907            match source {
2908                UartMemClkConfig::Xtal => xtal_clk_frequency(),
2909            }
2910        }
2911        pub fn configure_timg_calibration_clock(
2912            clocks: &mut ClockTree,
2913            new_selector: TimgCalibrationClockConfig,
2914        ) {
2915            let old_selector = clocks.timg_calibration_clock.replace(new_selector);
2916            refresh_timg_calibration_clock_downstream(clocks);
2917            let active = clocks.timg_calibration_clock_refcount > 0;
2918            if active {
2919                match new_selector {
2920                    TimgCalibrationClockConfig::RcSlowClk => request_rc_slow_clk(clocks),
2921                    TimgCalibrationClockConfig::RcFastDivClk => request_rc_fast_div_clk(clocks),
2922                    TimgCalibrationClockConfig::Osc32kClk => request_osc_slow_clk(clocks),
2923                }
2924            }
2925            configure_timg_calibration_clock_impl(clocks, old_selector, new_selector);
2926            if active && let Some(old_selector) = old_selector {
2927                match old_selector {
2928                    TimgCalibrationClockConfig::RcSlowClk => release_rc_slow_clk(clocks),
2929                    TimgCalibrationClockConfig::RcFastDivClk => release_rc_fast_div_clk(clocks),
2930                    TimgCalibrationClockConfig::Osc32kClk => release_osc_slow_clk(clocks),
2931                }
2932            }
2933        }
2934        pub fn timg_calibration_clock_config(
2935            clocks: &mut ClockTree,
2936        ) -> Option<TimgCalibrationClockConfig> {
2937            clocks.timg_calibration_clock
2938        }
2939        pub fn request_timg_calibration_clock(clocks: &mut ClockTree) {
2940            trace!("Requesting TIMG_CALIBRATION_CLOCK");
2941            if increment_reference_count(&mut clocks.timg_calibration_clock_refcount) {
2942                trace!("Enabling TIMG_CALIBRATION_CLOCK");
2943                crate::rtc_cntl::WakeLock::acquire();
2944                match unwrap!(clocks.timg_calibration_clock) {
2945                    TimgCalibrationClockConfig::RcSlowClk => request_rc_slow_clk(clocks),
2946                    TimgCalibrationClockConfig::RcFastDivClk => request_rc_fast_div_clk(clocks),
2947                    TimgCalibrationClockConfig::Osc32kClk => request_osc_slow_clk(clocks),
2948                }
2949                enable_timg_calibration_clock_impl(clocks, true);
2950            }
2951        }
2952        pub fn release_timg_calibration_clock(clocks: &mut ClockTree) {
2953            trace!("Releasing TIMG_CALIBRATION_CLOCK");
2954            if decrement_reference_count(&mut clocks.timg_calibration_clock_refcount) {
2955                trace!("Disabling TIMG_CALIBRATION_CLOCK");
2956                crate::rtc_cntl::WakeLock::release();
2957                enable_timg_calibration_clock_impl(clocks, false);
2958                match unwrap!(clocks.timg_calibration_clock) {
2959                    TimgCalibrationClockConfig::RcSlowClk => release_rc_slow_clk(clocks),
2960                    TimgCalibrationClockConfig::RcFastDivClk => release_rc_fast_div_clk(clocks),
2961                    TimgCalibrationClockConfig::Osc32kClk => release_osc_slow_clk(clocks),
2962                }
2963            }
2964        }
2965        pub fn timg_calibration_clock_config_frequency(config: TimgCalibrationClockConfig) -> u32 {
2966            match config {
2967                TimgCalibrationClockConfig::RcSlowClk => rc_slow_clk_frequency(),
2968                TimgCalibrationClockConfig::RcFastDivClk => rc_fast_div_clk_frequency(),
2969                TimgCalibrationClockConfig::Osc32kClk => osc_slow_clk_frequency(),
2970            }
2971        }
2972        pub fn timg_calibration_clock_frequency() -> u32 {
2973            TIMG_CALIBRATION_CLOCK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2974        }
2975        pub fn timg_calibration_clock_source_frequency(source: TimgCalibrationClockConfig) -> u32 {
2976            timg_calibration_clock_config_frequency(source)
2977        }
2978        impl AdcInstance {
2979            pub fn request_function_clock(self, clocks: &mut ClockTree) {
2980                trace!("Requesting {:?}::FUNCTION_CLOCK", self);
2981                if increment_reference_count(&mut clocks.adc_function_clock_refcount[self as usize])
2982                {
2983                    trace!("Enabling {:?}::FUNCTION_CLOCK", self);
2984                    request_apb_clk(clocks);
2985                    self.enable_function_clock_impl(clocks, true);
2986                }
2987            }
2988            pub fn release_function_clock(self, clocks: &mut ClockTree) {
2989                trace!("Releasing {:?}::FUNCTION_CLOCK", self);
2990                if decrement_reference_count(&mut clocks.adc_function_clock_refcount[self as usize])
2991                {
2992                    trace!("Disabling {:?}::FUNCTION_CLOCK", self);
2993                    self.enable_function_clock_impl(clocks, false);
2994                    release_apb_clk(clocks);
2995                }
2996            }
2997            pub fn function_clock_frequency(self) -> u32 {
2998                apb_clk_frequency()
2999            }
3000            pub fn function_clock_source_frequency() -> u32 {
3001                apb_clk_frequency()
3002            }
3003        }
3004        impl I2cInstance {
3005            pub fn configure_function_clock(
3006                self,
3007                clocks: &mut ClockTree,
3008                config: I2cFunctionClockConfig,
3009            ) {
3010                let old_config = clocks.i2c_function_clock[self as usize].replace(config);
3011                refresh_i2c_function_clock_downstream(clocks, self);
3012                let active = clocks.i2c_function_clock_refcount[self as usize] > 0;
3013                if active {
3014                    match config.sclk {
3015                        I2cFunctionClockSclk::Xtal => request_xtal_clk(clocks),
3016                        I2cFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
3017                    }
3018                }
3019                self.configure_function_clock_impl(clocks, old_config, config);
3020                if active && let Some(old_config) = old_config {
3021                    match old_config.sclk {
3022                        I2cFunctionClockSclk::Xtal => release_xtal_clk(clocks),
3023                        I2cFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
3024                    }
3025                }
3026            }
3027            pub fn function_clock_config(
3028                self,
3029                clocks: &mut ClockTree,
3030            ) -> Option<I2cFunctionClockConfig> {
3031                clocks.i2c_function_clock[self as usize]
3032            }
3033            pub fn request_function_clock(self, clocks: &mut ClockTree) {
3034                trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3035                if increment_reference_count(&mut clocks.i2c_function_clock_refcount[self as usize])
3036                {
3037                    trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3038                    crate::rtc_cntl::WakeLock::acquire();
3039                    match unwrap!(clocks.i2c_function_clock[self as usize]).sclk {
3040                        I2cFunctionClockSclk::Xtal => request_xtal_clk(clocks),
3041                        I2cFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
3042                    }
3043                    self.enable_function_clock_impl(clocks, true);
3044                }
3045            }
3046            pub fn release_function_clock(self, clocks: &mut ClockTree) {
3047                trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3048                if decrement_reference_count(&mut clocks.i2c_function_clock_refcount[self as usize])
3049                {
3050                    trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3051                    crate::rtc_cntl::WakeLock::release();
3052                    self.enable_function_clock_impl(clocks, false);
3053                    match unwrap!(clocks.i2c_function_clock[self as usize]).sclk {
3054                        I2cFunctionClockSclk::Xtal => release_xtal_clk(clocks),
3055                        I2cFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
3056                    }
3057                }
3058            }
3059            pub fn function_clock_config_frequency(config: I2cFunctionClockConfig) -> u32 {
3060                (match config.sclk {
3061                    I2cFunctionClockSclk::Xtal => xtal_clk_frequency(),
3062                    I2cFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
3063                } / (config.div_num() + 1))
3064            }
3065            pub fn function_clock_frequency(self) -> u32 {
3066                I2C_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
3067                    .load(::core::sync::atomic::Ordering::Acquire)
3068            }
3069            pub fn function_clock_source_frequency(sclk: I2cFunctionClockSclk) -> u32 {
3070                match sclk {
3071                    I2cFunctionClockSclk::Xtal => xtal_clk_frequency(),
3072                    I2cFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
3073                }
3074            }
3075        }
3076        impl SpiInstance {
3077            pub fn configure_function_clock(
3078                self,
3079                clocks: &mut ClockTree,
3080                new_selector: SpiFunctionClockConfig,
3081            ) {
3082                let old_selector = clocks.spi_function_clock[self as usize].replace(new_selector);
3083                refresh_spi_function_clock_downstream(clocks, self);
3084                let active = clocks.spi_function_clock_refcount[self as usize] > 0;
3085                if active {
3086                    match new_selector {
3087                        SpiFunctionClockConfig::Xtal => request_xtal_clk(clocks),
3088                        SpiFunctionClockConfig::Pll40m => request_pll_40m(clocks),
3089                    }
3090                }
3091                self.configure_function_clock_impl(clocks, old_selector, new_selector);
3092                if active && let Some(old_selector) = old_selector {
3093                    match old_selector {
3094                        SpiFunctionClockConfig::Xtal => release_xtal_clk(clocks),
3095                        SpiFunctionClockConfig::Pll40m => release_pll_40m(clocks),
3096                    }
3097                }
3098            }
3099            pub fn function_clock_config(
3100                self,
3101                clocks: &mut ClockTree,
3102            ) -> Option<SpiFunctionClockConfig> {
3103                clocks.spi_function_clock[self as usize]
3104            }
3105            pub fn request_function_clock(self, clocks: &mut ClockTree) {
3106                trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3107                if increment_reference_count(&mut clocks.spi_function_clock_refcount[self as usize])
3108                {
3109                    trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3110                    crate::rtc_cntl::WakeLock::acquire();
3111                    match unwrap!(clocks.spi_function_clock[self as usize]) {
3112                        SpiFunctionClockConfig::Xtal => request_xtal_clk(clocks),
3113                        SpiFunctionClockConfig::Pll40m => request_pll_40m(clocks),
3114                    }
3115                    self.enable_function_clock_impl(clocks, true);
3116                }
3117            }
3118            pub fn release_function_clock(self, clocks: &mut ClockTree) {
3119                trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3120                if decrement_reference_count(&mut clocks.spi_function_clock_refcount[self as usize])
3121                {
3122                    trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3123                    crate::rtc_cntl::WakeLock::release();
3124                    self.enable_function_clock_impl(clocks, false);
3125                    match unwrap!(clocks.spi_function_clock[self as usize]) {
3126                        SpiFunctionClockConfig::Xtal => release_xtal_clk(clocks),
3127                        SpiFunctionClockConfig::Pll40m => release_pll_40m(clocks),
3128                    }
3129                }
3130            }
3131            pub fn function_clock_config_frequency(config: SpiFunctionClockConfig) -> u32 {
3132                match config {
3133                    SpiFunctionClockConfig::Xtal => xtal_clk_frequency(),
3134                    SpiFunctionClockConfig::Pll40m => pll_40m_frequency(),
3135                }
3136            }
3137            pub fn function_clock_frequency(self) -> u32 {
3138                SPI_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
3139                    .load(::core::sync::atomic::Ordering::Acquire)
3140            }
3141            pub fn function_clock_source_frequency(source: SpiFunctionClockConfig) -> u32 {
3142                Self::function_clock_config_frequency(source)
3143            }
3144        }
3145        impl TimgInstance {
3146            pub fn configure_function_clock(
3147                self,
3148                clocks: &mut ClockTree,
3149                new_selector: TimgFunctionClockConfig,
3150            ) {
3151                let old_selector = clocks.timg_function_clock[self as usize].replace(new_selector);
3152                refresh_timg_function_clock_downstream(clocks, self);
3153                let active = clocks.timg_function_clock_refcount[self as usize] > 0;
3154                if active {
3155                    match new_selector {
3156                        TimgFunctionClockConfig::XtalClk => request_xtal_clk(clocks),
3157                        TimgFunctionClockConfig::Pll40m => request_pll_40m(clocks),
3158                    }
3159                }
3160                self.configure_function_clock_impl(clocks, old_selector, new_selector);
3161                if active && let Some(old_selector) = old_selector {
3162                    match old_selector {
3163                        TimgFunctionClockConfig::XtalClk => release_xtal_clk(clocks),
3164                        TimgFunctionClockConfig::Pll40m => release_pll_40m(clocks),
3165                    }
3166                }
3167            }
3168            pub fn function_clock_config(
3169                self,
3170                clocks: &mut ClockTree,
3171            ) -> Option<TimgFunctionClockConfig> {
3172                clocks.timg_function_clock[self as usize]
3173            }
3174            pub fn request_function_clock(self, clocks: &mut ClockTree) {
3175                trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3176                if increment_reference_count(
3177                    &mut clocks.timg_function_clock_refcount[self as usize],
3178                ) {
3179                    trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3180                    match unwrap!(clocks.timg_function_clock[self as usize]) {
3181                        TimgFunctionClockConfig::XtalClk => request_xtal_clk(clocks),
3182                        TimgFunctionClockConfig::Pll40m => request_pll_40m(clocks),
3183                    }
3184                    self.enable_function_clock_impl(clocks, true);
3185                }
3186            }
3187            pub fn release_function_clock(self, clocks: &mut ClockTree) {
3188                trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3189                if decrement_reference_count(
3190                    &mut clocks.timg_function_clock_refcount[self as usize],
3191                ) {
3192                    trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3193                    self.enable_function_clock_impl(clocks, false);
3194                    match unwrap!(clocks.timg_function_clock[self as usize]) {
3195                        TimgFunctionClockConfig::XtalClk => release_xtal_clk(clocks),
3196                        TimgFunctionClockConfig::Pll40m => release_pll_40m(clocks),
3197                    }
3198                }
3199            }
3200            pub fn function_clock_config_frequency(config: TimgFunctionClockConfig) -> u32 {
3201                match config {
3202                    TimgFunctionClockConfig::XtalClk => xtal_clk_frequency(),
3203                    TimgFunctionClockConfig::Pll40m => pll_40m_frequency(),
3204                }
3205            }
3206            pub fn function_clock_frequency(self) -> u32 {
3207                TIMG_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
3208                    .load(::core::sync::atomic::Ordering::Acquire)
3209            }
3210            pub fn function_clock_source_frequency(source: TimgFunctionClockConfig) -> u32 {
3211                Self::function_clock_config_frequency(source)
3212            }
3213            pub fn configure_wdt_clock(
3214                self,
3215                clocks: &mut ClockTree,
3216                new_selector: TimgWdtClockConfig,
3217            ) {
3218                let old_selector = clocks.timg_wdt_clock[self as usize].replace(new_selector);
3219                refresh_timg_wdt_clock_downstream(clocks, self);
3220                let active = clocks.timg_wdt_clock_refcount[self as usize] > 0;
3221                if active {
3222                    match new_selector {
3223                        TimgWdtClockConfig::Pll40m => request_pll_40m(clocks),
3224                        TimgWdtClockConfig::XtalClk => request_xtal_clk(clocks),
3225                    }
3226                }
3227                self.configure_wdt_clock_impl(clocks, old_selector, new_selector);
3228                if active && let Some(old_selector) = old_selector {
3229                    match old_selector {
3230                        TimgWdtClockConfig::Pll40m => release_pll_40m(clocks),
3231                        TimgWdtClockConfig::XtalClk => release_xtal_clk(clocks),
3232                    }
3233                }
3234            }
3235            pub fn wdt_clock_config(self, clocks: &mut ClockTree) -> Option<TimgWdtClockConfig> {
3236                clocks.timg_wdt_clock[self as usize]
3237            }
3238            pub fn request_wdt_clock(self, clocks: &mut ClockTree) {
3239                trace!("Requesting {:?}::WDT_CLOCK", self);
3240                if increment_reference_count(&mut clocks.timg_wdt_clock_refcount[self as usize]) {
3241                    trace!("Enabling {:?}::WDT_CLOCK", self);
3242                    match unwrap!(clocks.timg_wdt_clock[self as usize]) {
3243                        TimgWdtClockConfig::Pll40m => request_pll_40m(clocks),
3244                        TimgWdtClockConfig::XtalClk => request_xtal_clk(clocks),
3245                    }
3246                    self.enable_wdt_clock_impl(clocks, true);
3247                }
3248            }
3249            pub fn release_wdt_clock(self, clocks: &mut ClockTree) {
3250                trace!("Releasing {:?}::WDT_CLOCK", self);
3251                if decrement_reference_count(&mut clocks.timg_wdt_clock_refcount[self as usize]) {
3252                    trace!("Disabling {:?}::WDT_CLOCK", self);
3253                    self.enable_wdt_clock_impl(clocks, false);
3254                    match unwrap!(clocks.timg_wdt_clock[self as usize]) {
3255                        TimgWdtClockConfig::Pll40m => release_pll_40m(clocks),
3256                        TimgWdtClockConfig::XtalClk => release_xtal_clk(clocks),
3257                    }
3258                }
3259            }
3260            pub fn wdt_clock_config_frequency(config: TimgWdtClockConfig) -> u32 {
3261                match config {
3262                    TimgWdtClockConfig::Pll40m => pll_40m_frequency(),
3263                    TimgWdtClockConfig::XtalClk => xtal_clk_frequency(),
3264                }
3265            }
3266            pub fn wdt_clock_frequency(self) -> u32 {
3267                TIMG_WDT_CLOCK_FREQ_CACHE[self as usize]
3268                    .load(::core::sync::atomic::Ordering::Acquire)
3269            }
3270            pub fn wdt_clock_source_frequency(source: TimgWdtClockConfig) -> u32 {
3271                Self::wdt_clock_config_frequency(source)
3272            }
3273        }
3274        impl UartInstance {
3275            pub fn configure_function_clock(
3276                self,
3277                clocks: &mut ClockTree,
3278                config: UartFunctionClockConfig,
3279            ) {
3280                let old_config = clocks.uart_function_clock[self as usize].replace(config);
3281                refresh_uart_function_clock_downstream(clocks, self);
3282                let active = clocks.uart_function_clock_refcount[self as usize] > 0;
3283                if active {
3284                    match config.sclk {
3285                        UartFunctionClockSclk::PllF40m => request_pll_40m(clocks),
3286                        UartFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
3287                        UartFunctionClockSclk::Xtal => request_xtal_clk(clocks),
3288                    }
3289                }
3290                self.configure_function_clock_impl(clocks, old_config, config);
3291                if active && let Some(old_config) = old_config {
3292                    match old_config.sclk {
3293                        UartFunctionClockSclk::PllF40m => release_pll_40m(clocks),
3294                        UartFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
3295                        UartFunctionClockSclk::Xtal => release_xtal_clk(clocks),
3296                    }
3297                }
3298            }
3299            pub fn function_clock_config(
3300                self,
3301                clocks: &mut ClockTree,
3302            ) -> Option<UartFunctionClockConfig> {
3303                clocks.uart_function_clock[self as usize]
3304            }
3305            pub fn request_function_clock(self, clocks: &mut ClockTree) {
3306                trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3307                if increment_reference_count(
3308                    &mut clocks.uart_function_clock_refcount[self as usize],
3309                ) {
3310                    trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3311                    match unwrap!(clocks.uart_function_clock[self as usize]).sclk {
3312                        UartFunctionClockSclk::PllF40m => request_pll_40m(clocks),
3313                        UartFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
3314                        UartFunctionClockSclk::Xtal => request_xtal_clk(clocks),
3315                    }
3316                    self.enable_function_clock_impl(clocks, true);
3317                }
3318            }
3319            pub fn release_function_clock(self, clocks: &mut ClockTree) {
3320                trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3321                if decrement_reference_count(
3322                    &mut clocks.uart_function_clock_refcount[self as usize],
3323                ) {
3324                    trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3325                    self.enable_function_clock_impl(clocks, false);
3326                    match unwrap!(clocks.uart_function_clock[self as usize]).sclk {
3327                        UartFunctionClockSclk::PllF40m => release_pll_40m(clocks),
3328                        UartFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
3329                        UartFunctionClockSclk::Xtal => release_xtal_clk(clocks),
3330                    }
3331                }
3332            }
3333            pub fn function_clock_config_frequency(config: UartFunctionClockConfig) -> u32 {
3334                (match config.sclk {
3335                    UartFunctionClockSclk::PllF40m => pll_40m_frequency(),
3336                    UartFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
3337                    UartFunctionClockSclk::Xtal => xtal_clk_frequency(),
3338                } / (config.div_num() + 1))
3339            }
3340            pub fn function_clock_frequency(self) -> u32 {
3341                UART_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
3342                    .load(::core::sync::atomic::Ordering::Acquire)
3343            }
3344            pub fn function_clock_source_frequency(sclk: UartFunctionClockSclk) -> u32 {
3345                match sclk {
3346                    UartFunctionClockSclk::PllF40m => pll_40m_frequency(),
3347                    UartFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
3348                    UartFunctionClockSclk::Xtal => xtal_clk_frequency(),
3349                }
3350            }
3351            pub fn request_mem_clock(self, clocks: &mut ClockTree) {
3352                trace!("Requesting {:?}::MEM_CLOCK", self);
3353                if increment_reference_count(&mut clocks.uart_mem_clock_refcount[self as usize]) {
3354                    trace!("Enabling {:?}::MEM_CLOCK", self);
3355                    request_uart_mem_clk(clocks);
3356                    self.enable_mem_clock_impl(clocks, true);
3357                }
3358            }
3359            pub fn release_mem_clock(self, clocks: &mut ClockTree) {
3360                trace!("Releasing {:?}::MEM_CLOCK", self);
3361                if decrement_reference_count(&mut clocks.uart_mem_clock_refcount[self as usize]) {
3362                    trace!("Disabling {:?}::MEM_CLOCK", self);
3363                    self.enable_mem_clock_impl(clocks, false);
3364                    release_uart_mem_clk(clocks);
3365                }
3366            }
3367            pub fn mem_clock_frequency(self) -> u32 {
3368                uart_mem_clk_frequency()
3369            }
3370            pub fn mem_clock_source_frequency() -> u32 {
3371                uart_mem_clk_frequency()
3372            }
3373            pub fn configure_baud_rate_generator(
3374                self,
3375                clocks: &mut ClockTree,
3376                config: UartBaudRateGeneratorConfig,
3377            ) {
3378                let old_config = clocks.uart_baud_rate_generator[self as usize].replace(config);
3379                refresh_uart_baud_rate_generator_downstream(clocks, self);
3380                self.configure_baud_rate_generator_impl(clocks, old_config, config);
3381            }
3382            pub fn baud_rate_generator_config(
3383                self,
3384                clocks: &mut ClockTree,
3385            ) -> Option<UartBaudRateGeneratorConfig> {
3386                clocks.uart_baud_rate_generator[self as usize]
3387            }
3388            pub fn request_baud_rate_generator(self, clocks: &mut ClockTree) {
3389                trace!("Requesting {:?}::BAUD_RATE_GENERATOR", self);
3390                if increment_reference_count(
3391                    &mut clocks.uart_baud_rate_generator_refcount[self as usize],
3392                ) {
3393                    trace!("Enabling {:?}::BAUD_RATE_GENERATOR", self);
3394                    self.request_function_clock(clocks);
3395                    self.enable_baud_rate_generator_impl(clocks, true);
3396                }
3397            }
3398            pub fn release_baud_rate_generator(self, clocks: &mut ClockTree) {
3399                trace!("Releasing {:?}::BAUD_RATE_GENERATOR", self);
3400                if decrement_reference_count(
3401                    &mut clocks.uart_baud_rate_generator_refcount[self as usize],
3402                ) {
3403                    trace!("Disabling {:?}::BAUD_RATE_GENERATOR", self);
3404                    self.enable_baud_rate_generator_impl(clocks, false);
3405                    self.release_function_clock(clocks);
3406                }
3407            }
3408            pub fn baud_rate_generator_config_frequency(
3409                self,
3410                config: UartBaudRateGeneratorConfig,
3411            ) -> u32 {
3412                ((self.function_clock_frequency() * 16)
3413                    / ((config.integral() * 16) + config.fractional()))
3414            }
3415            pub fn baud_rate_generator_frequency(self) -> u32 {
3416                UART_BAUD_RATE_GENERATOR_FREQ_CACHE[self as usize]
3417                    .load(::core::sync::atomic::Ordering::Acquire)
3418            }
3419        }
3420        /// Clock tree configuration.
3421        ///
3422        /// The fields of this struct are optional, with the following caveats:
3423        /// - If `XTAL_CLK` is not specified, the crystal frequency will be automatically detected
3424        ///   if possible.
3425        /// - The CPU and its upstream clock nodes will be set to a default configuration.
3426        /// - Other unspecified clock sources will not be useable by peripherals.
3427        #[derive(Debug, Clone, Copy, PartialEq, Eq)]
3428        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
3429        #[instability::unstable]
3430        pub struct ClockConfig {
3431            /// `XTAL_CLK` configuration.
3432            pub xtal_clk: Option<XtalClkConfig>,
3433            /// `SYSTEM_PRE_DIV` configuration.
3434            pub system_pre_div: Option<SystemPreDivConfig>,
3435            /// `CPU_PLL_DIV` configuration.
3436            pub cpu_pll_div: Option<CpuPllDivConfig>,
3437            /// `CPU_CLK` configuration.
3438            pub cpu_clk: Option<CpuClkConfig>,
3439            /// `RC_FAST_CLK_DIV_N` configuration.
3440            pub rc_fast_clk_div_n: Option<RcFastClkDivNConfig>,
3441            /// `RTC_SLOW_CLK` configuration.
3442            pub rtc_slow_clk: Option<RtcSlowClkConfig>,
3443            /// `BLE_LP_CLK` configuration.
3444            pub ble_lp_clk: Option<BleLpClkConfig>,
3445            /// `RTC_FAST_CLK` configuration.
3446            pub rtc_fast_clk: Option<RtcFastClkConfig>,
3447            /// `LOW_POWER_CLK` configuration.
3448            pub low_power_clk: Option<LowPowerClkConfig>,
3449            /// `TIMG_CALIBRATION_CLOCK` configuration.
3450            pub timg_calibration_clock: Option<TimgCalibrationClockConfig>,
3451        }
3452        impl ClockConfig {
3453            fn apply(&self, clocks: &mut ClockTree) {
3454                if let Some(config) = self.xtal_clk {
3455                    configure_xtal_clk(clocks, config);
3456                }
3457                if let Some(config) = self.system_pre_div {
3458                    configure_system_pre_div(clocks, config);
3459                }
3460                if let Some(config) = self.cpu_pll_div {
3461                    configure_cpu_pll_div(clocks, config);
3462                }
3463                if let Some(config) = self.cpu_clk {
3464                    configure_cpu_clk(clocks, config);
3465                }
3466                if let Some(config) = self.rc_fast_clk_div_n {
3467                    configure_rc_fast_clk_div_n(clocks, config);
3468                }
3469                if let Some(config) = self.rtc_slow_clk {
3470                    configure_rtc_slow_clk(clocks, config);
3471                }
3472                if let Some(config) = self.ble_lp_clk {
3473                    configure_ble_lp_clk(clocks, config);
3474                }
3475                if let Some(config) = self.rtc_fast_clk {
3476                    configure_rtc_fast_clk(clocks, config);
3477                }
3478                if let Some(config) = self.low_power_clk {
3479                    configure_low_power_clk(clocks, config);
3480                }
3481                if let Some(config) = self.timg_calibration_clock {
3482                    configure_timg_calibration_clock(clocks, config);
3483                }
3484            }
3485        }
3486        fn increment_reference_count(refcount: &mut u32) -> bool {
3487            let first = *refcount == 0;
3488            *refcount = unwrap!(refcount.checked_add(1), "Reference count overflow");
3489            first
3490        }
3491        fn decrement_reference_count(refcount: &mut u32) -> bool {
3492            *refcount = refcount.saturating_sub(1);
3493            let last = *refcount == 0;
3494            last
3495        }
3496        fn refresh_xtal_clk_downstream(clocks: &mut ClockTree) {
3497            if let Some(config) = clocks.xtal_clk {
3498                XTAL_CLK_FREQ_CACHE.store(
3499                    xtal_clk_config_frequency(config),
3500                    ::core::sync::atomic::Ordering::Release,
3501                );
3502            }
3503            refresh_system_pre_div_in_downstream(clocks);
3504            refresh_cpu_pll_div_downstream(clocks);
3505            refresh_ble_lp_clk_downstream(clocks);
3506            refresh_rtc_fast_clk_downstream(clocks);
3507            refresh_low_power_clk_downstream(clocks);
3508            for child_instance in [I2cInstance::I2c0] {
3509                refresh_i2c_function_clock_downstream(clocks, child_instance);
3510            }
3511            for child_instance in [SpiInstance::Spi2] {
3512                refresh_spi_function_clock_downstream(clocks, child_instance);
3513            }
3514            for child_instance in [TimgInstance::Timg0] {
3515                refresh_timg_function_clock_downstream(clocks, child_instance);
3516                refresh_timg_wdt_clock_downstream(clocks, child_instance);
3517            }
3518            for child_instance in [UartInstance::Uart0, UartInstance::Uart1] {
3519                refresh_uart_function_clock_downstream(clocks, child_instance);
3520            }
3521        }
3522        fn refresh_rc_fast_clk_downstream(clocks: &mut ClockTree) {
3523            refresh_system_pre_div_in_downstream(clocks);
3524            refresh_rc_fast_clk_div_n_downstream(clocks);
3525            refresh_rtc_slow_clk_downstream(clocks);
3526            refresh_low_power_clk_downstream(clocks);
3527            refresh_timg_calibration_clock_downstream(clocks);
3528            for child_instance in [I2cInstance::I2c0] {
3529                refresh_i2c_function_clock_downstream(clocks, child_instance);
3530            }
3531            for child_instance in [UartInstance::Uart0, UartInstance::Uart1] {
3532                refresh_uart_function_clock_downstream(clocks, child_instance);
3533            }
3534        }
3535        fn refresh_rc_slow_clk_downstream(clocks: &mut ClockTree) {
3536            refresh_rtc_slow_clk_downstream(clocks);
3537            refresh_ble_lp_clk_downstream(clocks);
3538            refresh_timg_calibration_clock_downstream(clocks);
3539        }
3540        fn refresh_system_pre_div_in_downstream(clocks: &mut ClockTree) {
3541            if let Some(config) = clocks.system_pre_div_in {
3542                SYSTEM_PRE_DIV_IN_FREQ_CACHE.store(
3543                    system_pre_div_in_config_frequency(config),
3544                    ::core::sync::atomic::Ordering::Release,
3545                );
3546            }
3547            refresh_system_pre_div_downstream(clocks);
3548        }
3549        fn refresh_system_pre_div_downstream(clocks: &mut ClockTree) {
3550            if let Some(config) = clocks.system_pre_div {
3551                SYSTEM_PRE_DIV_FREQ_CACHE.store(
3552                    system_pre_div_config_frequency(config),
3553                    ::core::sync::atomic::Ordering::Release,
3554                );
3555            }
3556            refresh_cpu_clk_downstream(clocks);
3557        }
3558        fn refresh_cpu_pll_div_downstream(clocks: &mut ClockTree) {
3559            if let Some(config) = clocks.cpu_pll_div {
3560                CPU_PLL_DIV_FREQ_CACHE.store(
3561                    cpu_pll_div_config_frequency(config),
3562                    ::core::sync::atomic::Ordering::Release,
3563                );
3564            }
3565            refresh_cpu_clk_downstream(clocks);
3566        }
3567        fn refresh_cpu_clk_downstream(clocks: &mut ClockTree) {
3568            if let Some(config) = clocks.cpu_clk {
3569                CPU_CLK_FREQ_CACHE.store(
3570                    cpu_clk_config_frequency(config),
3571                    ::core::sync::atomic::Ordering::Release,
3572                );
3573            }
3574            refresh_apb_clk_downstream(clocks);
3575            refresh_crypto_clk_downstream(clocks);
3576            refresh_mspi_clk_downstream(clocks);
3577            for child_instance in [SpiInstance::Spi2] {
3578                refresh_spi_function_clock_downstream(clocks, child_instance);
3579            }
3580            for child_instance in [TimgInstance::Timg0] {
3581                refresh_timg_function_clock_downstream(clocks, child_instance);
3582                refresh_timg_wdt_clock_downstream(clocks, child_instance);
3583            }
3584            for child_instance in [UartInstance::Uart0, UartInstance::Uart1] {
3585                refresh_uart_function_clock_downstream(clocks, child_instance);
3586            }
3587        }
3588        fn refresh_rc_fast_clk_div_n_downstream(clocks: &mut ClockTree) {
3589            if let Some(config) = clocks.rc_fast_clk_div_n {
3590                RC_FAST_CLK_DIV_N_FREQ_CACHE.store(
3591                    rc_fast_clk_div_n_config_frequency(config),
3592                    ::core::sync::atomic::Ordering::Release,
3593                );
3594            }
3595            refresh_rtc_fast_clk_downstream(clocks);
3596        }
3597        fn refresh_rtc_slow_clk_downstream(clocks: &mut ClockTree) {
3598            if let Some(config) = clocks.rtc_slow_clk {
3599                RTC_SLOW_CLK_FREQ_CACHE.store(
3600                    rtc_slow_clk_config_frequency(config),
3601                    ::core::sync::atomic::Ordering::Release,
3602                );
3603            }
3604            refresh_low_power_clk_downstream(clocks);
3605        }
3606        fn refresh_ble_lp_clk_downstream(clocks: &mut ClockTree) {
3607            if let Some(config) = clocks.ble_lp_clk {
3608                BLE_LP_CLK_FREQ_CACHE.store(
3609                    ble_lp_clk_config_frequency(config),
3610                    ::core::sync::atomic::Ordering::Release,
3611                );
3612            }
3613        }
3614        fn refresh_rtc_fast_clk_downstream(clocks: &mut ClockTree) {
3615            if let Some(config) = clocks.rtc_fast_clk {
3616                RTC_FAST_CLK_FREQ_CACHE.store(
3617                    rtc_fast_clk_config_frequency(config),
3618                    ::core::sync::atomic::Ordering::Release,
3619                );
3620            }
3621        }
3622        fn refresh_low_power_clk_downstream(clocks: &mut ClockTree) {
3623            if let Some(config) = clocks.low_power_clk {
3624                LOW_POWER_CLK_FREQ_CACHE.store(
3625                    low_power_clk_config_frequency(config),
3626                    ::core::sync::atomic::Ordering::Release,
3627                );
3628            }
3629        }
3630        fn refresh_timg_calibration_clock_downstream(clocks: &mut ClockTree) {
3631            if let Some(config) = clocks.timg_calibration_clock {
3632                TIMG_CALIBRATION_CLOCK_FREQ_CACHE.store(
3633                    timg_calibration_clock_config_frequency(config),
3634                    ::core::sync::atomic::Ordering::Release,
3635                );
3636            }
3637        }
3638        fn refresh_i2c_function_clock_downstream(clocks: &mut ClockTree, instance: I2cInstance) {
3639            if let Some(config) = clocks.i2c_function_clock[instance as usize] {
3640                I2C_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
3641                    I2cInstance::function_clock_config_frequency(config),
3642                    ::core::sync::atomic::Ordering::Release,
3643                );
3644            }
3645        }
3646        fn refresh_spi_function_clock_downstream(clocks: &mut ClockTree, instance: SpiInstance) {
3647            if let Some(config) = clocks.spi_function_clock[instance as usize] {
3648                SPI_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
3649                    SpiInstance::function_clock_config_frequency(config),
3650                    ::core::sync::atomic::Ordering::Release,
3651                );
3652            }
3653        }
3654        fn refresh_timg_function_clock_downstream(clocks: &mut ClockTree, instance: TimgInstance) {
3655            if let Some(config) = clocks.timg_function_clock[instance as usize] {
3656                TIMG_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
3657                    TimgInstance::function_clock_config_frequency(config),
3658                    ::core::sync::atomic::Ordering::Release,
3659                );
3660            }
3661        }
3662        fn refresh_timg_wdt_clock_downstream(clocks: &mut ClockTree, instance: TimgInstance) {
3663            if let Some(config) = clocks.timg_wdt_clock[instance as usize] {
3664                TIMG_WDT_CLOCK_FREQ_CACHE[instance as usize].store(
3665                    TimgInstance::wdt_clock_config_frequency(config),
3666                    ::core::sync::atomic::Ordering::Release,
3667                );
3668            }
3669        }
3670        fn refresh_uart_function_clock_downstream(clocks: &mut ClockTree, instance: UartInstance) {
3671            if let Some(config) = clocks.uart_function_clock[instance as usize] {
3672                UART_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
3673                    UartInstance::function_clock_config_frequency(config),
3674                    ::core::sync::atomic::Ordering::Release,
3675                );
3676            }
3677            refresh_uart_baud_rate_generator_downstream(clocks, instance);
3678        }
3679        fn refresh_uart_baud_rate_generator_downstream(
3680            clocks: &mut ClockTree,
3681            instance: UartInstance,
3682        ) {
3683            if let Some(config) = clocks.uart_baud_rate_generator[instance as usize] {
3684                UART_BAUD_RATE_GENERATOR_FREQ_CACHE[instance as usize].store(
3685                    instance.baud_rate_generator_config_frequency(config),
3686                    ::core::sync::atomic::Ordering::Release,
3687                );
3688            }
3689        }
3690        fn refresh_apb_clk_downstream(clocks: &mut ClockTree) {
3691            if let Some(config) = clocks.apb_clk {
3692                APB_CLK_FREQ_CACHE.store(
3693                    apb_clk_config_frequency(config),
3694                    ::core::sync::atomic::Ordering::Release,
3695                );
3696            }
3697        }
3698        fn refresh_crypto_clk_downstream(clocks: &mut ClockTree) {
3699            if let Some(config) = clocks.crypto_clk {
3700                CRYPTO_CLK_FREQ_CACHE.store(
3701                    crypto_clk_config_frequency(config),
3702                    ::core::sync::atomic::Ordering::Release,
3703                );
3704            }
3705        }
3706        fn refresh_mspi_clk_downstream(clocks: &mut ClockTree) {
3707            if let Some(config) = clocks.mspi_clk {
3708                MSPI_CLK_FREQ_CACHE.store(
3709                    mspi_clk_config_frequency(config),
3710                    ::core::sync::atomic::Ordering::Release,
3711                );
3712            }
3713        }
3714    };
3715}
3716/// Implement the `Peripheral` enum and enable/disable/reset functions.
3717///
3718/// This macro is intended to be placed in `esp_hal::system`.
3719#[macro_export]
3720#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3721macro_rules! implement_peripheral_clocks {
3722    () => {
3723        #[doc(hidden)]
3724        #[derive(Debug, Clone, Copy, PartialEq, Eq)]
3725        #[repr(u8)]
3726        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
3727        pub enum Peripheral {
3728            /// AHB_GDMA peripheral clock signal
3729            AhbGdma,
3730            /// APB_SAR_ADC peripheral clock signal
3731            ApbSarAdc,
3732            /// ECC peripheral clock signal
3733            Ecc,
3734            /// I2C_EXT0 peripheral clock signal
3735            I2cExt0,
3736            /// LEDC peripheral clock signal
3737            Ledc,
3738            /// SHA peripheral clock signal
3739            Sha,
3740            /// SPI2 peripheral clock signal
3741            Spi2,
3742            /// SYSTIMER peripheral clock signal
3743            Systimer,
3744            /// TIMG0 peripheral clock signal
3745            Timg0,
3746            /// TSENS peripheral clock signal
3747            Tsens,
3748            /// UART0 peripheral clock signal
3749            Uart0,
3750            /// UART1 peripheral clock signal
3751            Uart1,
3752            /// UART_MEM peripheral clock signal
3753            UartMem,
3754        }
3755        impl Peripheral {
3756            const KEEP_ENABLED: &[Peripheral] =
3757                &[Self::Systimer, Self::Timg0, Self::Uart0, Self::UartMem];
3758            const COUNT: usize = Self::ALL.len();
3759            const ALL: &[Self] = &[
3760                Self::AhbGdma,
3761                Self::ApbSarAdc,
3762                Self::Ecc,
3763                Self::I2cExt0,
3764                Self::Ledc,
3765                Self::Sha,
3766                Self::Spi2,
3767                Self::Systimer,
3768                Self::Timg0,
3769                Self::Tsens,
3770                Self::Uart0,
3771                Self::Uart1,
3772                Self::UartMem,
3773            ];
3774        }
3775        unsafe fn enable_internal_racey(peripheral: Peripheral, enable: bool) {
3776            match peripheral {
3777                Peripheral::AhbGdma => {
3778                    crate::peripherals::SYSTEM::regs()
3779                        .perip_clk_en1()
3780                        .modify(|_, w| w.dma_clk_en().bit(enable));
3781                }
3782                Peripheral::ApbSarAdc => {
3783                    crate::peripherals::SYSTEM::regs()
3784                        .perip_clk_en0()
3785                        .modify(|_, w| w.apb_saradc_clk_en().bit(enable));
3786                }
3787                Peripheral::Ecc => {
3788                    crate::peripherals::SYSTEM::regs()
3789                        .perip_clk_en1()
3790                        .modify(|_, w| w.crypto_ecc_clk_en().bit(enable));
3791                }
3792                Peripheral::I2cExt0 => {
3793                    crate::peripherals::SYSTEM::regs()
3794                        .perip_clk_en0()
3795                        .modify(|_, w| w.i2c_ext0_clk_en().bit(enable));
3796                }
3797                Peripheral::Ledc => {
3798                    crate::peripherals::SYSTEM::regs()
3799                        .perip_clk_en0()
3800                        .modify(|_, w| w.ledc_clk_en().bit(enable));
3801                }
3802                Peripheral::Sha => {
3803                    crate::peripherals::SYSTEM::regs()
3804                        .perip_clk_en1()
3805                        .modify(|_, w| w.crypto_sha_clk_en().bit(enable));
3806                }
3807                Peripheral::Spi2 => {
3808                    crate::peripherals::SYSTEM::regs()
3809                        .perip_clk_en0()
3810                        .modify(|_, w| w.spi2_clk_en().bit(enable));
3811                }
3812                Peripheral::Systimer => {
3813                    crate::peripherals::SYSTEM::regs()
3814                        .perip_clk_en0()
3815                        .modify(|_, w| w.systimer_clk_en().bit(enable));
3816                }
3817                Peripheral::Timg0 => {
3818                    crate::peripherals::SYSTEM::regs()
3819                        .perip_clk_en0()
3820                        .modify(|_, w| w.timergroup_clk_en().bit(enable));
3821                }
3822                Peripheral::Tsens => {
3823                    crate::peripherals::SYSTEM::regs()
3824                        .perip_clk_en1()
3825                        .modify(|_, w| w.tsens_clk_en().bit(enable));
3826                }
3827                Peripheral::Uart0 => {
3828                    crate::peripherals::SYSTEM::regs()
3829                        .perip_clk_en0()
3830                        .modify(|_, w| w.uart_clk_en().bit(enable));
3831                }
3832                Peripheral::Uart1 => {
3833                    crate::peripherals::SYSTEM::regs()
3834                        .perip_clk_en0()
3835                        .modify(|_, w| w.uart1_clk_en().bit(enable));
3836                }
3837                Peripheral::UartMem => {
3838                    crate::peripherals::SYSTEM::regs()
3839                        .perip_clk_en0()
3840                        .modify(|_, w| w.uart_mem_clk_en().bit(enable));
3841                }
3842            }
3843        }
3844        unsafe fn assert_peri_reset_racey(peripheral: Peripheral, reset: bool) {
3845            match peripheral {
3846                Peripheral::AhbGdma => {
3847                    crate::peripherals::SYSTEM::regs()
3848                        .perip_rst_en1()
3849                        .modify(|_, w| w.dma_rst().bit(reset));
3850                }
3851                Peripheral::ApbSarAdc => {
3852                    crate::peripherals::SYSTEM::regs()
3853                        .perip_rst_en0()
3854                        .modify(|_, w| w.apb_saradc_rst().bit(reset));
3855                }
3856                Peripheral::Ecc => {
3857                    crate::peripherals::SYSTEM::regs()
3858                        .perip_rst_en1()
3859                        .modify(|_, w| w.crypto_ecc_rst().bit(reset));
3860                }
3861                Peripheral::I2cExt0 => {
3862                    crate::peripherals::SYSTEM::regs()
3863                        .perip_rst_en0()
3864                        .modify(|_, w| w.i2c_ext0_rst().bit(reset));
3865                }
3866                Peripheral::Ledc => {
3867                    crate::peripherals::SYSTEM::regs()
3868                        .perip_rst_en0()
3869                        .modify(|_, w| w.ledc_rst().bit(reset));
3870                }
3871                Peripheral::Sha => {
3872                    crate::peripherals::SYSTEM::regs()
3873                        .perip_rst_en1()
3874                        .modify(|_, w| w.crypto_sha_rst().bit(reset));
3875                }
3876                Peripheral::Spi2 => {
3877                    crate::peripherals::SYSTEM::regs()
3878                        .perip_rst_en0()
3879                        .modify(|_, w| w.spi2_rst().bit(reset));
3880                }
3881                Peripheral::Systimer => {
3882                    crate::peripherals::SYSTEM::regs()
3883                        .perip_rst_en0()
3884                        .modify(|_, w| w.systimer_rst().bit(reset));
3885                }
3886                Peripheral::Timg0 => {
3887                    crate::peripherals::SYSTEM::regs()
3888                        .perip_rst_en0()
3889                        .modify(|_, w| w.timergroup_rst().bit(reset));
3890                }
3891                Peripheral::Tsens => {
3892                    crate::peripherals::SYSTEM::regs()
3893                        .perip_rst_en1()
3894                        .modify(|_, w| w.tsens_rst().bit(reset));
3895                }
3896                Peripheral::Uart0 => {
3897                    crate::peripherals::SYSTEM::regs()
3898                        .perip_rst_en0()
3899                        .modify(|_, w| w.uart_rst().bit(reset));
3900                }
3901                Peripheral::Uart1 => {
3902                    crate::peripherals::SYSTEM::regs()
3903                        .perip_rst_en0()
3904                        .modify(|_, w| w.uart1_rst().bit(reset));
3905                }
3906                Peripheral::UartMem => {
3907                    crate::peripherals::SYSTEM::regs()
3908                        .perip_rst_en0()
3909                        .modify(|_, w| w.uart_mem_rst().bit(reset));
3910                }
3911            }
3912        }
3913    };
3914}
3915/// Macro to get the address range of the given memory region.
3916///
3917/// This macro provides two syntax options for each memory region:
3918///
3919/// - `memory_range!("region_name")` returns the address range as a range expression (`start..end`).
3920/// - `memory_range!(size as str, "region_name")` returns the size of the region as a string
3921///   literal.
3922#[macro_export]
3923#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3924macro_rules! memory_range {
3925    ("DRAM") => {
3926        0x3FCA0000..0x3FCE0000
3927    };
3928    (size as str, "DRAM") => {
3929        "262144"
3930    };
3931    ("DRAM2_UNINIT") => {
3932        0x3FCCE800..0x3FCDEB70
3933    };
3934    (size as str, "DRAM2_UNINIT") => {
3935        "66416"
3936    };
3937    ("IROM") => {
3938        0x42000000..0x42400000
3939    };
3940    (size as str, "IROM") => {
3941        "4194304"
3942    };
3943    ("DROM") => {
3944        0x3C000000..0x3C400000
3945    };
3946    (size as str, "DROM") => {
3947        "4194304"
3948    };
3949}
3950/// This macro can be used to generate code for each peripheral instance of the I2C master driver.
3951///
3952/// For an explanation on the general syntax, as well as usage of individual/repeated
3953/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
3954///
3955/// This macro has one option for its "Individual matcher" case:
3956///
3957/// Syntax: `($id:literal, $instance:ident, $sys:ident, $scl:ident, $sda:ident)`
3958///
3959/// Macro fragments:
3960/// - `$id`: the index of the I2C instance
3961/// - `$instance`: the name of the I2C instance
3962/// - `$sys`: the name of the instance as it is in the `esp_hal::system::Peripheral` enum.
3963/// - `$scl`, `$sda`: peripheral signal names.
3964///
3965/// Example data: `(0, I2C0, I2cExt0, I2CEXT0_SCL, I2CEXT0_SDA)`
3966#[macro_export]
3967#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3968macro_rules! for_each_i2c_master {
3969    ($($pattern:tt => $code:tt;)*) => {
3970        macro_rules! _for_each_inner_i2c_master { $(($pattern) => $code;)* ($other : tt)
3971        => {} } _for_each_inner_i2c_master!((0, I2C0, I2cExt0, I2CEXT0_SCL,
3972        I2CEXT0_SDA)); _for_each_inner_i2c_master!((all(0, I2C0, I2cExt0, I2CEXT0_SCL,
3973        I2CEXT0_SDA)));
3974    };
3975}
3976/// This macro can be used to generate code for each peripheral instance of the UART driver.
3977///
3978/// For an explanation on the general syntax, as well as usage of individual/repeated
3979/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
3980///
3981/// This macro has one option for its "Individual matcher" case:
3982///
3983/// Syntax: `($id:literal, $instance:ident, $sys:ident, $rx:ident, $tx:ident, $cts:ident,
3984/// $rts:ident)`
3985///
3986/// Macro fragments:
3987///
3988/// - `$id`: the index of the UART instance
3989/// - `$instance`: the name of the UART instance
3990/// - `$sys`: the name of the instance as it is in the `esp_hal::system::Peripheral` enum.
3991/// - `$rx`, `$tx`, `$cts`, `$rts`: signal names.
3992///
3993/// Example data: `(0, UART0, Uart0, U0RXD, U0TXD, U0CTS, U0RTS)`
3994#[macro_export]
3995#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3996macro_rules! for_each_uart {
3997    ($($pattern:tt => $code:tt;)*) => {
3998        macro_rules! _for_each_inner_uart { $(($pattern) => $code;)* ($other : tt) => {}
3999        } _for_each_inner_uart!((0, UART0, Uart0, U0RXD, U0TXD, U0CTS, U0RTS,
4000        wakeup_source = true)); _for_each_inner_uart!((1, UART1, Uart1, U1RXD, U1TXD,
4001        U1CTS, U1RTS, wakeup_source = true)); _for_each_inner_uart!((all(0, UART0, Uart0,
4002        U0RXD, U0TXD, U0CTS, U0RTS, wakeup_source = true), (1, UART1, Uart1, U1RXD,
4003        U1TXD, U1CTS, U1RTS, wakeup_source = true)));
4004    };
4005}
4006/// This macro can be used to generate code for each peripheral instance of the SPI master driver.
4007///
4008/// For an explanation on the general syntax, as well as usage of individual/repeated
4009/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
4010///
4011/// This macro has one option for its "Individual matcher" case:
4012///
4013/// Syntax: `($instance:ident, $sys:ident, $sclk:ident [$($cs:ident),*] [$($sio:ident),*]
4014/// $($is_qspi:literal)?)`
4015///
4016/// Macro fragments:
4017///
4018/// - `$instance`: the name of the SPI instance
4019/// - `$sys`: the name of the instance as it is in the `esp_hal::system::Peripheral` enum.
4020/// - `$cs`, `$sio`: chip select and SIO signal names.
4021/// - `$is_qspi`: a `true` literal present if the SPI instance supports QSPI.
4022///
4023/// Example data:
4024/// - `(SPI2, Spi2, FSPICLK [FSPICS0, FSPICS1, FSPICS2, FSPICS3, FSPICS4, FSPICS5] [FSPID, FSPIQ,
4025///   FSPIWP, FSPIHD, FSPIIO4, FSPIIO5, FSPIIO6, FSPIIO7], true)`
4026/// - `(SPI3, Spi3, SPI3_CLK [SPI3_CS0, SPI3_CS1, SPI3_CS2] [SPI3_D, SPI3_Q])`
4027#[macro_export]
4028#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4029macro_rules! for_each_spi_master {
4030    ($($pattern:tt => $code:tt;)*) => {
4031        macro_rules! _for_each_inner_spi_master { $(($pattern) => $code;)* ($other : tt)
4032        => {} } _for_each_inner_spi_master!((SPI2)); _for_each_inner_spi_master!((SPI2,
4033        Spi2, FSPICLK[FSPICS0, FSPICS1, FSPICS2, FSPICS3, FSPICS4, FSPICS5] [FSPID,
4034        FSPIQ, FSPIWP, FSPIHD], true)); _for_each_inner_spi_master!((names(SPI2)));
4035        _for_each_inner_spi_master!((all(SPI2, Spi2, FSPICLK[FSPICS0, FSPICS1, FSPICS2,
4036        FSPICS3, FSPICS4, FSPICS5] [FSPID, FSPIQ, FSPIWP, FSPIHD], true)));
4037    };
4038}
4039/// This macro can be used to generate code for each peripheral instance of the SPI slave driver.
4040///
4041/// For an explanation on the general syntax, as well as usage of individual/repeated
4042/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
4043///
4044/// This macro has one option for its "Individual matcher" case:
4045///
4046/// Syntax: `($instance:ident, $sys:ident, $sclk:ident, $mosi:ident, $miso:ident, $cs:ident)`
4047///
4048/// Macro fragments:
4049///
4050/// - `$instance`: the name of the SPI instance
4051/// - `$sys`: the name of the instance as it is in the `esp_hal::system::Peripheral` enum.
4052/// - `$sclk`, `$mosi`, `$miso`, `$cs`: signal names.
4053///
4054/// Example data: `(SPI2, Spi2, FSPICLK, FSPID, FSPIQ, FSPICS0)`
4055#[macro_export]
4056#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4057macro_rules! for_each_spi_slave {
4058    ($($pattern:tt => $code:tt;)*) => {
4059        macro_rules! _for_each_inner_spi_slave { $(($pattern) => $code;)* ($other : tt)
4060        => {} } _for_each_inner_spi_slave!((SPI2)); _for_each_inner_spi_slave!((SPI2,
4061        Spi2, FSPICLK, FSPID, FSPIQ, FSPICS0));
4062        _for_each_inner_spi_slave!((names(SPI2))); _for_each_inner_spi_slave!((all(SPI2,
4063        Spi2, FSPICLK, FSPID, FSPIQ, FSPICS0)));
4064    };
4065}
4066#[macro_export]
4067#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4068macro_rules! for_each_peripheral {
4069    ($($pattern:tt => $code:tt;)*) => {
4070        macro_rules! _for_each_inner_peripheral { $(($pattern) => $code;)* ($other : tt)
4071        => {} } _for_each_inner_peripheral!((@ peri_type #[doc =
4072        "GPIO0 peripheral singleton"] GPIO0 <= virtual()));
4073        _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO1 peripheral singleton"]
4074        GPIO1 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
4075        "GPIO2 peripheral singleton"] GPIO2 <= virtual()));
4076        _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO3 peripheral singleton"]
4077        GPIO3 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
4078        "GPIO4 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4079        "<section class=\"warning\">"] #[doc =
4080        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4081        #[doc = "<ul>"] #[doc =
4082        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4083        #[doc = "</ul>"] #[doc = "</section>"] GPIO4 <= virtual()));
4084        _for_each_inner_peripheral!((@ peri_type #[doc =
4085        "GPIO5 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4086        "<section class=\"warning\">"] #[doc =
4087        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4088        #[doc = "<ul>"] #[doc =
4089        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4090        #[doc = "</ul>"] #[doc = "</section>"] GPIO5 <= virtual()));
4091        _for_each_inner_peripheral!((@ peri_type #[doc =
4092        "GPIO6 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4093        "<section class=\"warning\">"] #[doc =
4094        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4095        #[doc = "<ul>"] #[doc =
4096        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4097        #[doc = "</ul>"] #[doc = "</section>"] GPIO6 <= virtual()));
4098        _for_each_inner_peripheral!((@ peri_type #[doc =
4099        "GPIO7 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4100        "<section class=\"warning\">"] #[doc =
4101        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4102        #[doc = "<ul>"] #[doc =
4103        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4104        #[doc = "</ul>"] #[doc = "</section>"] GPIO7 <= virtual()));
4105        _for_each_inner_peripheral!((@ peri_type #[doc =
4106        "GPIO8 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4107        "<section class=\"warning\">"] #[doc =
4108        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4109        #[doc = "<ul>"] #[doc =
4110        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
4111        = "</ul>"] #[doc = "</section>"] GPIO8 <= virtual()));
4112        _for_each_inner_peripheral!((@ peri_type #[doc =
4113        "GPIO9 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4114        "<section class=\"warning\">"] #[doc =
4115        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4116        #[doc = "<ul>"] #[doc =
4117        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
4118        = "</ul>"] #[doc = "</section>"] GPIO9 <= virtual()));
4119        _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO10 peripheral singleton"]
4120        GPIO10 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
4121        "GPIO11 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4122        "<section class=\"warning\">"] #[doc =
4123        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4124        #[doc = "<ul>"] #[doc =
4125        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4126        "</ul>"] #[doc = "</section>"] GPIO11 <= virtual()));
4127        _for_each_inner_peripheral!((@ peri_type #[doc =
4128        "GPIO12 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4129        "<section class=\"warning\">"] #[doc =
4130        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4131        #[doc = "<ul>"] #[doc =
4132        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4133        "</ul>"] #[doc = "</section>"] GPIO12 <= virtual()));
4134        _for_each_inner_peripheral!((@ peri_type #[doc =
4135        "GPIO13 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4136        "<section class=\"warning\">"] #[doc =
4137        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4138        #[doc = "<ul>"] #[doc =
4139        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4140        "</ul>"] #[doc = "</section>"] GPIO13 <= virtual()));
4141        _for_each_inner_peripheral!((@ peri_type #[doc =
4142        "GPIO14 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4143        "<section class=\"warning\">"] #[doc =
4144        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4145        #[doc = "<ul>"] #[doc =
4146        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4147        "</ul>"] #[doc = "</section>"] GPIO14 <= virtual()));
4148        _for_each_inner_peripheral!((@ peri_type #[doc =
4149        "GPIO15 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4150        "<section class=\"warning\">"] #[doc =
4151        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4152        #[doc = "<ul>"] #[doc =
4153        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4154        "</ul>"] #[doc = "</section>"] GPIO15 <= virtual()));
4155        _for_each_inner_peripheral!((@ peri_type #[doc =
4156        "GPIO16 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4157        "<section class=\"warning\">"] #[doc =
4158        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4159        #[doc = "<ul>"] #[doc =
4160        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4161        "</ul>"] #[doc = "</section>"] GPIO16 <= virtual()));
4162        _for_each_inner_peripheral!((@ peri_type #[doc =
4163        "GPIO17 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4164        "<section class=\"warning\">"] #[doc =
4165        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4166        #[doc = "<ul>"] #[doc =
4167        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4168        "</ul>"] #[doc = "</section>"] GPIO17 <= virtual()));
4169        _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO18 peripheral singleton"]
4170        GPIO18 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
4171        "GPIO19 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4172        "<section class=\"warning\">"] #[doc =
4173        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4174        #[doc = "<ul>"] #[doc =
4175        "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
4176        = "</ul>"] #[doc = "</section>"] GPIO19 <= virtual()));
4177        _for_each_inner_peripheral!((@ peri_type #[doc =
4178        "GPIO20 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4179        "<section class=\"warning\">"] #[doc =
4180        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4181        #[doc = "<ul>"] #[doc =
4182        "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
4183        = "</ul>"] #[doc = "</section>"] GPIO20 <= virtual()));
4184        _for_each_inner_peripheral!((@ peri_type #[doc = "DMA_CH0 peripheral singleton"]
4185        DMA_CH0 <= virtual(DMA_CH0 : { bind_dma_interrupt, enable_dma_interrupt,
4186        disable_dma_interrupt }) (unstable))); _for_each_inner_peripheral!((@ peri_type
4187        #[doc = "APB_CTRL peripheral singleton"] APB_CTRL <= APB_CTRL() (unstable)));
4188        _for_each_inner_peripheral!((@ peri_type #[doc =
4189        "APB_SARADC peripheral singleton"] APB_SARADC <= APB_SARADC() (unstable)));
4190        _for_each_inner_peripheral!((@ peri_type #[doc = "BB peripheral singleton"] BB <=
4191        BB() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4192        "ASSIST_DEBUG peripheral singleton"] ASSIST_DEBUG <= ASSIST_DEBUG() (unstable)));
4193        _for_each_inner_peripheral!((@ peri_type #[doc = "DMA peripheral singleton"] DMA
4194        <= DMA() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4195        "ECC peripheral singleton"] ECC <= ECC() (unstable)));
4196        _for_each_inner_peripheral!((@ peri_type #[doc = "EFUSE peripheral singleton"]
4197        EFUSE <= EFUSE() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4198        "EXTMEM peripheral singleton"] EXTMEM <= EXTMEM() (unstable)));
4199        _for_each_inner_peripheral!((@ peri_type #[doc =
4200        "MMU_TABLE peripheral singleton"] MMU_TABLE <= MMU_TABLE() (unstable)));
4201        _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO peripheral singleton"]
4202        GPIO <= GPIO() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4203        "I2C_ANA_MST peripheral singleton"] I2C_ANA_MST <= I2C_ANA_MST() (unstable)));
4204        _for_each_inner_peripheral!((@ peri_type #[doc = "I2C0 peripheral singleton"]
4205        I2C0 <= I2C0(I2C_EXT0 : { bind_peri_interrupt, enable_peri_interrupt,
4206        disable_peri_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
4207        "INTERRUPT_CORE0 peripheral singleton"] INTERRUPT_CORE0 <= INTERRUPT_CORE0()
4208        (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4209        "IO_MUX peripheral singleton"] IO_MUX <= IO_MUX() (unstable)));
4210        _for_each_inner_peripheral!((@ peri_type #[doc = "LEDC peripheral singleton"]
4211        LEDC <= LEDC() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4212        "RNG peripheral singleton"] RNG <= RNG() (unstable)));
4213        _for_each_inner_peripheral!((@ peri_type #[doc = "LPWR peripheral singleton"]
4214        LPWR <= RTC_CNTL() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4215        "RTC_TIMER peripheral singleton"] RTC_TIMER <= RTC_CNTL() (unstable)));
4216        _for_each_inner_peripheral!((@ peri_type #[doc =
4217        "MODEM_CLKRST peripheral singleton"] MODEM_CLKRST <= MODEM_CLKRST() (unstable)));
4218        _for_each_inner_peripheral!((@ peri_type #[doc =
4219        "SENSITIVE peripheral singleton"] SENSITIVE <= SENSITIVE() (unstable)));
4220        _for_each_inner_peripheral!((@ peri_type #[doc = "SHA peripheral singleton"] SHA
4221        <= SHA(SHA : { bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt
4222        }) (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4223        "SPI0 peripheral singleton"] SPI0 <= SPI0() (unstable)));
4224        _for_each_inner_peripheral!((@ peri_type #[doc = "SPI1 peripheral singleton"]
4225        SPI1 <= SPI1() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4226        "SPI2 peripheral singleton"] SPI2 <= SPI2(SPI2 : { bind_peri_interrupt,
4227        enable_peri_interrupt, disable_peri_interrupt })));
4228        _for_each_inner_peripheral!((@ peri_type #[doc = "SYSTEM peripheral singleton"]
4229        SYSTEM <= SYSTEM() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4230        "SYSTIMER peripheral singleton"] SYSTIMER <= SYSTIMER() (unstable)));
4231        _for_each_inner_peripheral!((@ peri_type #[doc = "TIMG0 peripheral singleton"]
4232        TIMG0 <= TIMG0() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4233        "UART0 peripheral singleton"] UART0 <= UART0(UART0 : { bind_peri_interrupt,
4234        enable_peri_interrupt, disable_peri_interrupt })));
4235        _for_each_inner_peripheral!((@ peri_type #[doc = "UART1 peripheral singleton"]
4236        UART1 <= UART1(UART1 : { bind_peri_interrupt, enable_peri_interrupt,
4237        disable_peri_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
4238        "XTS_AES peripheral singleton"] XTS_AES <= XTS_AES() (unstable)));
4239        _for_each_inner_peripheral!((@ peri_type #[doc = "ADC1 peripheral singleton"]
4240        ADC1 <= virtual() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4241        "BT peripheral singleton"] BT <= virtual(LP_TIMER : { bind_lp_timer_interrupt,
4242        enable_lp_timer_interrupt, disable_lp_timer_interrupt }, BT_MAC : {
4243        bind_mac_interrupt, enable_mac_interrupt, disable_mac_interrupt }) (unstable)));
4244        _for_each_inner_peripheral!((@ peri_type #[doc = "FLASH peripheral singleton"]
4245        FLASH <= virtual() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4246        "GPIO_DEDICATED peripheral singleton"] GPIO_DEDICATED <= virtual() (unstable)));
4247        _for_each_inner_peripheral!((@ peri_type #[doc = "WIFI peripheral singleton"]
4248        WIFI <= virtual(WIFI_MAC : { bind_mac_interrupt, enable_mac_interrupt,
4249        disable_mac_interrupt }, WIFI_PWR : { bind_pwr_interrupt, enable_pwr_interrupt,
4250        disable_pwr_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
4251        "FROM_CPU_INTR0 peripheral singleton"] FROM_CPU_INTR0 <= virtual() (unstable)));
4252        _for_each_inner_peripheral!((@ peri_type #[doc =
4253        "FROM_CPU_INTR1 peripheral singleton"] FROM_CPU_INTR1 <= virtual() (unstable)));
4254        _for_each_inner_peripheral!((@ peri_type #[doc =
4255        "FROM_CPU_INTR2 peripheral singleton"] FROM_CPU_INTR2 <= virtual() (unstable)));
4256        _for_each_inner_peripheral!((@ peri_type #[doc =
4257        "FROM_CPU_INTR3 peripheral singleton"] FROM_CPU_INTR3 <= virtual() (unstable)));
4258        _for_each_inner_peripheral!((GPIO0)); _for_each_inner_peripheral!((GPIO1));
4259        _for_each_inner_peripheral!((GPIO2)); _for_each_inner_peripheral!((GPIO3));
4260        _for_each_inner_peripheral!((GPIO4)); _for_each_inner_peripheral!((GPIO5));
4261        _for_each_inner_peripheral!((GPIO6)); _for_each_inner_peripheral!((GPIO7));
4262        _for_each_inner_peripheral!((GPIO8)); _for_each_inner_peripheral!((GPIO9));
4263        _for_each_inner_peripheral!((GPIO10)); _for_each_inner_peripheral!((GPIO11));
4264        _for_each_inner_peripheral!((GPIO12)); _for_each_inner_peripheral!((GPIO13));
4265        _for_each_inner_peripheral!((GPIO14)); _for_each_inner_peripheral!((GPIO15));
4266        _for_each_inner_peripheral!((GPIO16)); _for_each_inner_peripheral!((GPIO17));
4267        _for_each_inner_peripheral!((GPIO18)); _for_each_inner_peripheral!((GPIO19));
4268        _for_each_inner_peripheral!((GPIO20));
4269        _for_each_inner_peripheral!((DMA_CH0(unstable)));
4270        _for_each_inner_peripheral!((APB_CTRL(unstable)));
4271        _for_each_inner_peripheral!((APB_SARADC(unstable)));
4272        _for_each_inner_peripheral!((BB(unstable)));
4273        _for_each_inner_peripheral!((ASSIST_DEBUG(unstable)));
4274        _for_each_inner_peripheral!((DMA(unstable)));
4275        _for_each_inner_peripheral!((ECC(unstable)));
4276        _for_each_inner_peripheral!((EXTMEM(unstable)));
4277        _for_each_inner_peripheral!((GPIO(unstable)));
4278        _for_each_inner_peripheral!((I2C_ANA_MST(unstable)));
4279        _for_each_inner_peripheral!((I2C0));
4280        _for_each_inner_peripheral!((INTERRUPT_CORE0(unstable)));
4281        _for_each_inner_peripheral!((IO_MUX(unstable)));
4282        _for_each_inner_peripheral!((LEDC(unstable)));
4283        _for_each_inner_peripheral!((RNG(unstable)));
4284        _for_each_inner_peripheral!((LPWR(unstable)));
4285        _for_each_inner_peripheral!((RTC_TIMER(unstable)));
4286        _for_each_inner_peripheral!((MODEM_CLKRST(unstable)));
4287        _for_each_inner_peripheral!((SENSITIVE(unstable)));
4288        _for_each_inner_peripheral!((SHA(unstable)));
4289        _for_each_inner_peripheral!((SPI0(unstable)));
4290        _for_each_inner_peripheral!((SPI1(unstable)));
4291        _for_each_inner_peripheral!((SPI2));
4292        _for_each_inner_peripheral!((SYSTEM(unstable)));
4293        _for_each_inner_peripheral!((SYSTIMER(unstable)));
4294        _for_each_inner_peripheral!((TIMG0(unstable)));
4295        _for_each_inner_peripheral!((UART0)); _for_each_inner_peripheral!((UART1));
4296        _for_each_inner_peripheral!((XTS_AES(unstable)));
4297        _for_each_inner_peripheral!((ADC1(unstable)));
4298        _for_each_inner_peripheral!((BT(unstable)));
4299        _for_each_inner_peripheral!((FLASH(unstable)));
4300        _for_each_inner_peripheral!((GPIO_DEDICATED(unstable)));
4301        _for_each_inner_peripheral!((WIFI));
4302        _for_each_inner_peripheral!((FROM_CPU_INTR1(unstable)));
4303        _for_each_inner_peripheral!((FROM_CPU_INTR2(unstable)));
4304        _for_each_inner_peripheral!((FROM_CPU_INTR3(unstable)));
4305        _for_each_inner_peripheral!((SPI2, Spi2, 0, AhbGdmaChannel));
4306        _for_each_inner_peripheral!((SHA, Sha, 7, AhbGdmaChannel));
4307        _for_each_inner_peripheral!((all(@ peri_type #[doc =
4308        "GPIO0 peripheral singleton"] GPIO0 <= virtual()), (@ peri_type #[doc =
4309        "GPIO1 peripheral singleton"] GPIO1 <= virtual()), (@ peri_type #[doc =
4310        "GPIO2 peripheral singleton"] GPIO2 <= virtual()), (@ peri_type #[doc =
4311        "GPIO3 peripheral singleton"] GPIO3 <= virtual()), (@ peri_type #[doc =
4312        "GPIO4 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4313        "<section class=\"warning\">"] #[doc =
4314        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4315        #[doc = "<ul>"] #[doc =
4316        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4317        #[doc = "</ul>"] #[doc = "</section>"] GPIO4 <= virtual()), (@ peri_type #[doc =
4318        "GPIO5 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4319        "<section class=\"warning\">"] #[doc =
4320        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4321        #[doc = "<ul>"] #[doc =
4322        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4323        #[doc = "</ul>"] #[doc = "</section>"] GPIO5 <= virtual()), (@ peri_type #[doc =
4324        "GPIO6 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4325        "<section class=\"warning\">"] #[doc =
4326        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4327        #[doc = "<ul>"] #[doc =
4328        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4329        #[doc = "</ul>"] #[doc = "</section>"] GPIO6 <= virtual()), (@ peri_type #[doc =
4330        "GPIO7 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4331        "<section class=\"warning\">"] #[doc =
4332        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4333        #[doc = "<ul>"] #[doc =
4334        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4335        #[doc = "</ul>"] #[doc = "</section>"] GPIO7 <= virtual()), (@ peri_type #[doc =
4336        "GPIO8 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4337        "<section class=\"warning\">"] #[doc =
4338        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4339        #[doc = "<ul>"] #[doc =
4340        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
4341        = "</ul>"] #[doc = "</section>"] GPIO8 <= virtual()), (@ peri_type #[doc =
4342        "GPIO9 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4343        "<section class=\"warning\">"] #[doc =
4344        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4345        #[doc = "<ul>"] #[doc =
4346        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
4347        = "</ul>"] #[doc = "</section>"] GPIO9 <= virtual()), (@ peri_type #[doc =
4348        "GPIO10 peripheral singleton"] GPIO10 <= virtual()), (@ peri_type #[doc =
4349        "GPIO11 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4350        "<section class=\"warning\">"] #[doc =
4351        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4352        #[doc = "<ul>"] #[doc =
4353        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4354        "</ul>"] #[doc = "</section>"] GPIO11 <= virtual()), (@ peri_type #[doc =
4355        "GPIO12 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4356        "<section class=\"warning\">"] #[doc =
4357        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4358        #[doc = "<ul>"] #[doc =
4359        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4360        "</ul>"] #[doc = "</section>"] GPIO12 <= virtual()), (@ peri_type #[doc =
4361        "GPIO13 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4362        "<section class=\"warning\">"] #[doc =
4363        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4364        #[doc = "<ul>"] #[doc =
4365        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4366        "</ul>"] #[doc = "</section>"] GPIO13 <= virtual()), (@ peri_type #[doc =
4367        "GPIO14 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4368        "<section class=\"warning\">"] #[doc =
4369        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4370        #[doc = "<ul>"] #[doc =
4371        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4372        "</ul>"] #[doc = "</section>"] GPIO14 <= virtual()), (@ peri_type #[doc =
4373        "GPIO15 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4374        "<section class=\"warning\">"] #[doc =
4375        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4376        #[doc = "<ul>"] #[doc =
4377        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4378        "</ul>"] #[doc = "</section>"] GPIO15 <= virtual()), (@ peri_type #[doc =
4379        "GPIO16 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4380        "<section class=\"warning\">"] #[doc =
4381        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4382        #[doc = "<ul>"] #[doc =
4383        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4384        "</ul>"] #[doc = "</section>"] GPIO16 <= virtual()), (@ peri_type #[doc =
4385        "GPIO17 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4386        "<section class=\"warning\">"] #[doc =
4387        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4388        #[doc = "<ul>"] #[doc =
4389        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4390        "</ul>"] #[doc = "</section>"] GPIO17 <= virtual()), (@ peri_type #[doc =
4391        "GPIO18 peripheral singleton"] GPIO18 <= virtual()), (@ peri_type #[doc =
4392        "GPIO19 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4393        "<section class=\"warning\">"] #[doc =
4394        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4395        #[doc = "<ul>"] #[doc =
4396        "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
4397        = "</ul>"] #[doc = "</section>"] GPIO19 <= virtual()), (@ peri_type #[doc =
4398        "GPIO20 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4399        "<section class=\"warning\">"] #[doc =
4400        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4401        #[doc = "<ul>"] #[doc =
4402        "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
4403        = "</ul>"] #[doc = "</section>"] GPIO20 <= virtual()), (@ peri_type #[doc =
4404        "DMA_CH0 peripheral singleton"] DMA_CH0 <= virtual(DMA_CH0 : {
4405        bind_dma_interrupt, enable_dma_interrupt, disable_dma_interrupt }) (unstable)),
4406        (@ peri_type #[doc = "APB_CTRL peripheral singleton"] APB_CTRL <= APB_CTRL()
4407        (unstable)), (@ peri_type #[doc = "APB_SARADC peripheral singleton"] APB_SARADC
4408        <= APB_SARADC() (unstable)), (@ peri_type #[doc = "BB peripheral singleton"] BB
4409        <= BB() (unstable)), (@ peri_type #[doc = "ASSIST_DEBUG peripheral singleton"]
4410        ASSIST_DEBUG <= ASSIST_DEBUG() (unstable)), (@ peri_type #[doc =
4411        "DMA peripheral singleton"] DMA <= DMA() (unstable)), (@ peri_type #[doc =
4412        "ECC peripheral singleton"] ECC <= ECC() (unstable)), (@ peri_type #[doc =
4413        "EFUSE peripheral singleton"] EFUSE <= EFUSE() (unstable)), (@ peri_type #[doc =
4414        "EXTMEM peripheral singleton"] EXTMEM <= EXTMEM() (unstable)), (@ peri_type #[doc
4415        = "MMU_TABLE peripheral singleton"] MMU_TABLE <= MMU_TABLE() (unstable)), (@
4416        peri_type #[doc = "GPIO peripheral singleton"] GPIO <= GPIO() (unstable)), (@
4417        peri_type #[doc = "I2C_ANA_MST peripheral singleton"] I2C_ANA_MST <=
4418        I2C_ANA_MST() (unstable)), (@ peri_type #[doc = "I2C0 peripheral singleton"] I2C0
4419        <= I2C0(I2C_EXT0 : { bind_peri_interrupt, enable_peri_interrupt,
4420        disable_peri_interrupt })), (@ peri_type #[doc =
4421        "INTERRUPT_CORE0 peripheral singleton"] INTERRUPT_CORE0 <= INTERRUPT_CORE0()
4422        (unstable)), (@ peri_type #[doc = "IO_MUX peripheral singleton"] IO_MUX <=
4423        IO_MUX() (unstable)), (@ peri_type #[doc = "LEDC peripheral singleton"] LEDC <=
4424        LEDC() (unstable)), (@ peri_type #[doc = "RNG peripheral singleton"] RNG <= RNG()
4425        (unstable)), (@ peri_type #[doc = "LPWR peripheral singleton"] LPWR <= RTC_CNTL()
4426        (unstable)), (@ peri_type #[doc = "RTC_TIMER peripheral singleton"] RTC_TIMER <=
4427        RTC_CNTL() (unstable)), (@ peri_type #[doc = "MODEM_CLKRST peripheral singleton"]
4428        MODEM_CLKRST <= MODEM_CLKRST() (unstable)), (@ peri_type #[doc =
4429        "SENSITIVE peripheral singleton"] SENSITIVE <= SENSITIVE() (unstable)), (@
4430        peri_type #[doc = "SHA peripheral singleton"] SHA <= SHA(SHA : {
4431        bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })
4432        (unstable)), (@ peri_type #[doc = "SPI0 peripheral singleton"] SPI0 <= SPI0()
4433        (unstable)), (@ peri_type #[doc = "SPI1 peripheral singleton"] SPI1 <= SPI1()
4434        (unstable)), (@ peri_type #[doc = "SPI2 peripheral singleton"] SPI2 <= SPI2(SPI2
4435        : { bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })), (@
4436        peri_type #[doc = "SYSTEM peripheral singleton"] SYSTEM <= SYSTEM() (unstable)),
4437        (@ peri_type #[doc = "SYSTIMER peripheral singleton"] SYSTIMER <= SYSTIMER()
4438        (unstable)), (@ peri_type #[doc = "TIMG0 peripheral singleton"] TIMG0 <= TIMG0()
4439        (unstable)), (@ peri_type #[doc = "UART0 peripheral singleton"] UART0 <=
4440        UART0(UART0 : { bind_peri_interrupt, enable_peri_interrupt,
4441        disable_peri_interrupt })), (@ peri_type #[doc = "UART1 peripheral singleton"]
4442        UART1 <= UART1(UART1 : { bind_peri_interrupt, enable_peri_interrupt,
4443        disable_peri_interrupt })), (@ peri_type #[doc = "XTS_AES peripheral singleton"]
4444        XTS_AES <= XTS_AES() (unstable)), (@ peri_type #[doc =
4445        "ADC1 peripheral singleton"] ADC1 <= virtual() (unstable)), (@ peri_type #[doc =
4446        "BT peripheral singleton"] BT <= virtual(LP_TIMER : { bind_lp_timer_interrupt,
4447        enable_lp_timer_interrupt, disable_lp_timer_interrupt }, BT_MAC : {
4448        bind_mac_interrupt, enable_mac_interrupt, disable_mac_interrupt }) (unstable)),
4449        (@ peri_type #[doc = "FLASH peripheral singleton"] FLASH <= virtual()
4450        (unstable)), (@ peri_type #[doc = "GPIO_DEDICATED peripheral singleton"]
4451        GPIO_DEDICATED <= virtual() (unstable)), (@ peri_type #[doc =
4452        "WIFI peripheral singleton"] WIFI <= virtual(WIFI_MAC : { bind_mac_interrupt,
4453        enable_mac_interrupt, disable_mac_interrupt }, WIFI_PWR : { bind_pwr_interrupt,
4454        enable_pwr_interrupt, disable_pwr_interrupt })), (@ peri_type #[doc =
4455        "FROM_CPU_INTR0 peripheral singleton"] FROM_CPU_INTR0 <= virtual() (unstable)),
4456        (@ peri_type #[doc = "FROM_CPU_INTR1 peripheral singleton"] FROM_CPU_INTR1 <=
4457        virtual() (unstable)), (@ peri_type #[doc =
4458        "FROM_CPU_INTR2 peripheral singleton"] FROM_CPU_INTR2 <= virtual() (unstable)),
4459        (@ peri_type #[doc = "FROM_CPU_INTR3 peripheral singleton"] FROM_CPU_INTR3 <=
4460        virtual() (unstable)))); _for_each_inner_peripheral!((singletons(GPIO0), (GPIO1),
4461        (GPIO2), (GPIO3), (GPIO4), (GPIO5), (GPIO6), (GPIO7), (GPIO8), (GPIO9), (GPIO10),
4462        (GPIO11), (GPIO12), (GPIO13), (GPIO14), (GPIO15), (GPIO16), (GPIO17), (GPIO18),
4463        (GPIO19), (GPIO20), (DMA_CH0(unstable)), (APB_CTRL(unstable)),
4464        (APB_SARADC(unstable)), (BB(unstable)), (ASSIST_DEBUG(unstable)),
4465        (DMA(unstable)), (ECC(unstable)), (EXTMEM(unstable)), (GPIO(unstable)),
4466        (I2C_ANA_MST(unstable)), (I2C0), (INTERRUPT_CORE0(unstable)), (IO_MUX(unstable)),
4467        (LEDC(unstable)), (RNG(unstable)), (LPWR(unstable)), (RTC_TIMER(unstable)),
4468        (MODEM_CLKRST(unstable)), (SENSITIVE(unstable)), (SHA(unstable)),
4469        (SPI0(unstable)), (SPI1(unstable)), (SPI2), (SYSTEM(unstable)),
4470        (SYSTIMER(unstable)), (TIMG0(unstable)), (UART0), (UART1), (XTS_AES(unstable)),
4471        (ADC1(unstable)), (BT(unstable)), (FLASH(unstable)), (GPIO_DEDICATED(unstable)),
4472        (WIFI), (FROM_CPU_INTR1(unstable)), (FROM_CPU_INTR2(unstable)),
4473        (FROM_CPU_INTR3(unstable)))); _for_each_inner_peripheral!((dma_eligible(SPI2,
4474        Spi2, 0, AhbGdmaChannel), (SHA, Sha, 7, AhbGdmaChannel)));
4475    };
4476}
4477/// This macro can be used to generate code for each `GPIOn` instance.
4478///
4479/// For an explanation on the general syntax, as well as usage of individual/repeated
4480/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
4481///
4482/// This macro has one option for its "Individual matcher" case:
4483///
4484/// Syntax: `($n:literal, $gpio:ident ($($digital_input_function:ident =>
4485/// $digital_input_signal:ident)*) ($($digital_output_function:ident =>
4486/// $digital_output_signal:ident)*) ($([$pin_attribute:ident])*))`
4487///
4488/// Macro fragments:
4489///
4490/// - `$n`: the number of the GPIO. For `GPIO0`, `$n` is 0.
4491/// - `$gpio`: the name of the GPIO.
4492/// - `$digital_input_function`: the number of the digital function, as an identifier (i.e. for
4493///   function 0 this is `_0`).
4494/// - `$digital_input_function`: the name of the digital function, as an identifier.
4495/// - `$digital_output_function`: the number of the digital function, as an identifier (i.e. for
4496///   function 0 this is `_0`).
4497/// - `$digital_output_function`: the name of the digital function, as an identifier.
4498/// - `$pin_attribute`: `Input` and/or `Output`, marks the possible directions of the GPIO.
4499///   Bracketed so that they can also be matched as optional fragments. Order is always Input first.
4500///
4501/// Example data: `(0, GPIO0 (_5 => EMAC_TX_CLK) (_1 => CLK_OUT1 _5 => EMAC_TX_CLK) ([Input]
4502/// [Output]))`
4503#[macro_export]
4504#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4505macro_rules! for_each_gpio {
4506    ($($pattern:tt => $code:tt;)*) => {
4507        macro_rules! _for_each_inner_gpio { $(($pattern) => $code;)* ($other : tt) => {}
4508        } _for_each_inner_gpio!((0, GPIO0() () ([Input] [Output])));
4509        _for_each_inner_gpio!((1, GPIO1() () ([Input] [Output])));
4510        _for_each_inner_gpio!((2, GPIO2(_2 => FSPIQ) (_2 => FSPIQ) ([Input] [Output])));
4511        _for_each_inner_gpio!((3, GPIO3() () ([Input] [Output])));
4512        _for_each_inner_gpio!((4, GPIO4(_0 => MTMS _2 => FSPIHD) (_2 => FSPIHD) ([Input]
4513        [Output]))); _for_each_inner_gpio!((5, GPIO5(_0 => MTDI _2 => FSPIWP) (_2 =>
4514        FSPIWP) ([Input] [Output]))); _for_each_inner_gpio!((6, GPIO6(_0 => MTCK _2 =>
4515        FSPICLK) (_2 => FSPICLK) ([Input] [Output]))); _for_each_inner_gpio!((7, GPIO7(_2
4516        => FSPID) (_0 => MTDO _2 => FSPID) ([Input] [Output])));
4517        _for_each_inner_gpio!((8, GPIO8() () ([Input] [Output])));
4518        _for_each_inner_gpio!((9, GPIO9() () ([Input] [Output])));
4519        _for_each_inner_gpio!((10, GPIO10(_2 => FSPICS0) (_2 => FSPICS0) ([Input]
4520        [Output]))); _for_each_inner_gpio!((11, GPIO11(_0 => SPIHD) (_0 => SPIHD)
4521        ([Input] [Output]))); _for_each_inner_gpio!((12, GPIO12(_0 => SPIHD) (_0 =>
4522        SPIHD) ([Input] [Output]))); _for_each_inner_gpio!((13, GPIO13(_0 => SPIWP) (_0
4523        => SPIWP) ([Input] [Output]))); _for_each_inner_gpio!((14, GPIO14() (_0 =>
4524        SPICS0) ([Input] [Output]))); _for_each_inner_gpio!((15, GPIO15() (_0 => SPICLK)
4525        ([Input] [Output]))); _for_each_inner_gpio!((16, GPIO16(_0 => SPID) (_0 => SPID)
4526        ([Input] [Output]))); _for_each_inner_gpio!((17, GPIO17(_0 => SPIQ) (_0 => SPIQ)
4527        ([Input] [Output]))); _for_each_inner_gpio!((18, GPIO18() () ([Input]
4528        [Output]))); _for_each_inner_gpio!((19, GPIO19(_0 => U0RXD) () ([Input]
4529        [Output]))); _for_each_inner_gpio!((20, GPIO20() (_0 => U0TXD) ([Input]
4530        [Output]))); _for_each_inner_gpio!((all(0, GPIO0() () ([Input] [Output])), (1,
4531        GPIO1() () ([Input] [Output])), (2, GPIO2(_2 => FSPIQ) (_2 => FSPIQ) ([Input]
4532        [Output])), (3, GPIO3() () ([Input] [Output])), (4, GPIO4(_0 => MTMS _2 =>
4533        FSPIHD) (_2 => FSPIHD) ([Input] [Output])), (5, GPIO5(_0 => MTDI _2 => FSPIWP)
4534        (_2 => FSPIWP) ([Input] [Output])), (6, GPIO6(_0 => MTCK _2 => FSPICLK) (_2 =>
4535        FSPICLK) ([Input] [Output])), (7, GPIO7(_2 => FSPID) (_0 => MTDO _2 => FSPID)
4536        ([Input] [Output])), (8, GPIO8() () ([Input] [Output])), (9, GPIO9() () ([Input]
4537        [Output])), (10, GPIO10(_2 => FSPICS0) (_2 => FSPICS0) ([Input] [Output])), (11,
4538        GPIO11(_0 => SPIHD) (_0 => SPIHD) ([Input] [Output])), (12, GPIO12(_0 => SPIHD)
4539        (_0 => SPIHD) ([Input] [Output])), (13, GPIO13(_0 => SPIWP) (_0 => SPIWP)
4540        ([Input] [Output])), (14, GPIO14() (_0 => SPICS0) ([Input] [Output])), (15,
4541        GPIO15() (_0 => SPICLK) ([Input] [Output])), (16, GPIO16(_0 => SPID) (_0 => SPID)
4542        ([Input] [Output])), (17, GPIO17(_0 => SPIQ) (_0 => SPIQ) ([Input] [Output])),
4543        (18, GPIO18() () ([Input] [Output])), (19, GPIO19(_0 => U0RXD) () ([Input]
4544        [Output])), (20, GPIO20() (_0 => U0TXD) ([Input] [Output]))));
4545    };
4546}
4547/// This macro can be used to generate code for each analog function of each GPIO.
4548///
4549/// For an explanation on the general syntax, as well as usage of individual/repeated
4550/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
4551///
4552/// This macro has two options for its "Individual matcher" case:
4553///
4554/// - `all`: `($signal:ident, $gpio:ident)` - simple case where you only need identifiers
4555/// - group: `(($signal:ident, $group:ident $(, $number:literal)+), $gpio:ident)` - expanded signal
4556///   case, where you need the number(s) of a signal, or the general group to which the signal
4557///   belongs. For example, in case of `ADC2_CH3` the expanded form looks like `(ADC2_CH3, ADCn_CHm,
4558///   2, 3)`.
4559///
4560/// Macro fragments:
4561///
4562/// - `$signal`: the name of the signal.
4563/// - `$group`: the name of the signal, with numbers replaced by placeholders. For `ADC2_CH3` this
4564///   is `ADCn_CHm`.
4565/// - `$number`: the numbers extracted from `$signal`.
4566/// - `$gpio`: the name of the GPIO.
4567///
4568/// Example data:
4569/// - `(ADC2_CH5, GPIO12)`
4570/// - `((ADC2_CH5, ADCn_CHm, 2, 5), GPIO12)`
4571///
4572/// The expanded syntax is only available when the signal has at least one numbered component.
4573#[macro_export]
4574#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4575macro_rules! for_each_analog_function {
4576    ($($pattern:tt => $code:tt;)*) => {
4577        macro_rules! _for_each_inner_analog_function { $(($pattern) => $code;)* ($other :
4578        tt) => {} } _for_each_inner_analog_function!((ADC1_CH0, GPIO0));
4579        _for_each_inner_analog_function!((ADC1_CH1, GPIO1));
4580        _for_each_inner_analog_function!((ADC1_CH2, GPIO2));
4581        _for_each_inner_analog_function!((ADC1_CH3, GPIO3));
4582        _for_each_inner_analog_function!((ADC1_CH4, GPIO4));
4583        _for_each_inner_analog_function!(((ADC1_CH0, ADCn_CHm, 1, 0), GPIO0));
4584        _for_each_inner_analog_function!(((ADC1_CH1, ADCn_CHm, 1, 1), GPIO1));
4585        _for_each_inner_analog_function!(((ADC1_CH2, ADCn_CHm, 1, 2), GPIO2));
4586        _for_each_inner_analog_function!(((ADC1_CH3, ADCn_CHm, 1, 3), GPIO3));
4587        _for_each_inner_analog_function!(((ADC1_CH4, ADCn_CHm, 1, 4), GPIO4));
4588        _for_each_inner_analog_function!((all(ADC1_CH0, GPIO0), (ADC1_CH1, GPIO1),
4589        (ADC1_CH2, GPIO2), (ADC1_CH3, GPIO3), (ADC1_CH4, GPIO4)));
4590        _for_each_inner_analog_function!((ADCn_CHm((ADC1_CH0, ADCn_CHm, 1, 0), GPIO0),
4591        ((ADC1_CH1, ADCn_CHm, 1, 1), GPIO1), ((ADC1_CH2, ADCn_CHm, 1, 2), GPIO2),
4592        ((ADC1_CH3, ADCn_CHm, 1, 3), GPIO3), ((ADC1_CH4, ADCn_CHm, 1, 4), GPIO4)));
4593    };
4594}
4595/// This macro can be used to generate code for each LP function of each GPIO.
4596///
4597/// For an explanation on the general syntax, as well as usage of individual/repeated
4598/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
4599///
4600/// This macro has two options for its "Individual matcher" case:
4601///
4602/// - `all`: `($signal:ident, $gpio:ident, $af:ident)` - simple case where you only need
4603///   identifiers, and maybe the function.
4604/// - group: `(($signal:ident, $group:ident $(, $number:literal)+), $gpio:ident, $af:ident, ($(
4605///   $lp_input_af:ident => $lp_input_signal:ident )*) ($( $lp_output_af:ident =>
4606///   $lp_output_signal:ident )*))` - expanded signal case, where you need the number(s) of a
4607///   signal, or the general group to which the signal belongs. Every expanded branch ends with the
4608///   pad's LP input and output function groups (empty on chips without an LP GPIO matrix).
4609///
4610/// Macro fragments:
4611///
4612/// - `$signal`: the name of the signal.
4613/// - `$group`: the name of the signal, with numbers replaced by placeholders. For `ADC2_CH3` this
4614///   is `ADCn_CHm`.
4615/// - `$number`: the numbers extracted from `$signal`.
4616/// - `$gpio`: the name of the GPIO.
4617/// - `$af`: the LP IO MUX function, as an identifier (i.e. for function 0 this is `_0`). This is
4618///   the name of an `LpFunction` variant, and its number is the value to write to the pad's
4619///   function select field.
4620/// - `$lp_input_af`: the LP IO MUX function for an LP peripheral input on this pad.
4621/// - `$lp_input_signal`: the LP peripheral input signal name.
4622/// - `$lp_output_af`: the LP IO MUX function for an LP peripheral output on this pad.
4623/// - `$lp_output_signal`: the LP peripheral output signal name.
4624///
4625/// Example data:
4626/// - `(LP_GPIO15, GPIO12, _0)`
4627/// - `((LP_GPIO15, LP_GPIOn, 15), GPIO12, _0, () ())`
4628/// - `((LP_GPIO14, LP_GPIOn, 14), GPIO14, _1, () (_0 => LP_UART_TXD))`
4629/// - `((SAR_I2C_SCL_1, SAR_I2C_SCL_n, 1), GPIO2, _3, () ())`
4630///
4631/// The expanded syntax is only available when the signal has at least one numbered component.
4632#[macro_export]
4633#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4634macro_rules! for_each_lp_function {
4635    ($($pattern:tt => $code:tt;)*) => {
4636        macro_rules! _for_each_inner_lp_function { $(($pattern) => $code;)* ($other : tt)
4637        => {} } _for_each_inner_lp_function!((LP_GPIO0, GPIO0, _0));
4638        _for_each_inner_lp_function!((LP_GPIO1, GPIO1, _0));
4639        _for_each_inner_lp_function!((LP_GPIO2, GPIO2, _0));
4640        _for_each_inner_lp_function!((LP_GPIO3, GPIO3, _0));
4641        _for_each_inner_lp_function!((LP_GPIO4, GPIO4, _0));
4642        _for_each_inner_lp_function!((LP_GPIO5, GPIO5, _0));
4643        _for_each_inner_lp_function!(((LP_GPIO0, LP_GPIOn, 0), GPIO0, _0, () ()));
4644        _for_each_inner_lp_function!(((LP_GPIO1, LP_GPIOn, 1), GPIO1, _0, () ()));
4645        _for_each_inner_lp_function!(((LP_GPIO2, LP_GPIOn, 2), GPIO2, _0, () ()));
4646        _for_each_inner_lp_function!(((LP_GPIO3, LP_GPIOn, 3), GPIO3, _0, () ()));
4647        _for_each_inner_lp_function!(((LP_GPIO4, LP_GPIOn, 4), GPIO4, _0, () ()));
4648        _for_each_inner_lp_function!(((LP_GPIO5, LP_GPIOn, 5), GPIO5, _0, () ()));
4649        _for_each_inner_lp_function!((all(LP_GPIO0, GPIO0, _0), (LP_GPIO1, GPIO1, _0),
4650        (LP_GPIO2, GPIO2, _0), (LP_GPIO3, GPIO3, _0), (LP_GPIO4, GPIO4, _0), (LP_GPIO5,
4651        GPIO5, _0))); _for_each_inner_lp_function!((LP_GPIOn((LP_GPIO0, LP_GPIOn, 0),
4652        GPIO0, _0, () ()), ((LP_GPIO1, LP_GPIOn, 1), GPIO1, _0, () ()), ((LP_GPIO2,
4653        LP_GPIOn, 2), GPIO2, _0, () ()), ((LP_GPIO3, LP_GPIOn, 3), GPIO3, _0, () ()),
4654        ((LP_GPIO4, LP_GPIOn, 4), GPIO4, _0, () ()), ((LP_GPIO5, LP_GPIOn, 5), GPIO5, _0,
4655        () ())));
4656    };
4657}
4658/// This macro can be used to generate code for each IOMUX digital function of each GPIO.
4659///
4660/// IOMUX functions are the alternate digital functions configured via the IO_MUX registers.
4661/// Use this to implement signal-specific traits for peripherals whose pins must bypass the
4662/// GPIO matrix (e.g., EMAC, USB).
4663///
4664/// For an explanation on the general syntax, as well as usage of individual/repeated
4665/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
4666///
4667/// This macro has two options for its "Individual matcher" case:
4668///
4669/// - `all`: `($signal:ident, $gpio:ident, $af:ident)` - simple case where you only need
4670///   identifiers, and maybe the alternate function.
4671/// - group: `(($signal:ident, $group:ident $(, $number:literal)+), $gpio:ident, $af:ident)` -
4672///   expanded signal case, where you need the number(s) of a signal, or the general group to which
4673///   the signal belongs.
4674///
4675/// Macro fragments:
4676///
4677/// - `$signal`: the name of the signal.
4678/// - `$group`: the name of the signal, with numbers replaced by placeholders.
4679/// - `$number`: the numbers extracted from `$signal`.
4680/// - `$gpio`: the name of the GPIO.
4681/// - `$af`: the alternate function number, as an identifier (e.g. `_5`).
4682///
4683/// Example data:
4684/// - `(EMAC_RXD0, GPIO25, _5)`
4685/// - `((EMAC_RXDn, EMAC_RXDn, 0), GPIO25, _5)`
4686///
4687/// The expanded syntax is only available when the signal has at least one numbered component.
4688#[macro_export]
4689#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4690macro_rules! for_each_iomux_function {
4691    ($($pattern:tt => $code:tt;)*) => {
4692        macro_rules! _for_each_inner_iomux_function { $(($pattern) => $code;)* ($other :
4693        tt) => {} } _for_each_inner_iomux_function!((FSPIQ, GPIO2, _2));
4694        _for_each_inner_iomux_function!((MTMS, GPIO4, _0));
4695        _for_each_inner_iomux_function!((FSPIHD, GPIO4, _2));
4696        _for_each_inner_iomux_function!((MTDI, GPIO5, _0));
4697        _for_each_inner_iomux_function!((FSPIWP, GPIO5, _2));
4698        _for_each_inner_iomux_function!((MTCK, GPIO6, _0));
4699        _for_each_inner_iomux_function!((FSPICLK, GPIO6, _2));
4700        _for_each_inner_iomux_function!((MTDO, GPIO7, _0));
4701        _for_each_inner_iomux_function!((FSPID, GPIO7, _2));
4702        _for_each_inner_iomux_function!((FSPICS0, GPIO10, _2));
4703        _for_each_inner_iomux_function!((SPIHD, GPIO11, _0));
4704        _for_each_inner_iomux_function!((SPIHD, GPIO12, _0));
4705        _for_each_inner_iomux_function!((SPIWP, GPIO13, _0));
4706        _for_each_inner_iomux_function!((SPICS0, GPIO14, _0));
4707        _for_each_inner_iomux_function!((SPICLK, GPIO15, _0));
4708        _for_each_inner_iomux_function!((SPID, GPIO16, _0));
4709        _for_each_inner_iomux_function!((SPIQ, GPIO17, _0));
4710        _for_each_inner_iomux_function!((U0RXD, GPIO19, _0));
4711        _for_each_inner_iomux_function!((U0TXD, GPIO20, _0));
4712        _for_each_inner_iomux_function!(((FSPICS0, FSPICSn, 0), GPIO10, _2));
4713        _for_each_inner_iomux_function!(((SPICS0, SPICSn, 0), GPIO14, _0));
4714        _for_each_inner_iomux_function!((all(FSPIQ, GPIO2, _2), (MTMS, GPIO4, _0),
4715        (FSPIHD, GPIO4, _2), (MTDI, GPIO5, _0), (FSPIWP, GPIO5, _2), (MTCK, GPIO6, _0),
4716        (FSPICLK, GPIO6, _2), (MTDO, GPIO7, _0), (FSPID, GPIO7, _2), (FSPICS0, GPIO10,
4717        _2), (SPIHD, GPIO11, _0), (SPIHD, GPIO12, _0), (SPIWP, GPIO13, _0), (SPICS0,
4718        GPIO14, _0), (SPICLK, GPIO15, _0), (SPID, GPIO16, _0), (SPIQ, GPIO17, _0),
4719        (U0RXD, GPIO19, _0), (U0TXD, GPIO20, _0)));
4720        _for_each_inner_iomux_function!((FSPICSn((FSPICS0, FSPICSn, 0), GPIO10, _2)));
4721        _for_each_inner_iomux_function!((SPICSn((SPICS0, SPICSn, 0), GPIO14, _0)));
4722    };
4723}
4724/// Returns the name of the GPIO that provides the given signal, as a string.
4725///
4726/// The macro takes the name of a direct function - a digital IO MUX function, an analog
4727/// function, or an LP IO MUX function - and expands to a string literal like `"GPIO4"`. It
4728/// is meant to keep documentation free of per-chip pin lists.
4729///
4730/// Signals that are not wired to a pad on this chip have to be routed through the GPIO
4731/// matrix, which can reach any pad. The macro has no pad to return for those, so it accepts
4732/// an optional fallback to expand to instead. The fallback is not validated.
4733///
4734/// If multiple pads provide the signal, the macro returns one that is not reserved for some
4735/// other purpose, such as booting or interfacing with flash.
4736///
4737/// Example usage:
4738/// - `gpio_for_signal!(ADC1_CH0)`
4739/// - `gpio_for_signal!(LP_I2C_SDA, "GPIO6")`
4740#[macro_export]
4741#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4742macro_rules! gpio_for_signal {
4743    (ADC1_CH0 $(, $_fallback:literal)?) => {
4744        "GPIO0"
4745    };
4746    (LP_GPIO0 $(, $_fallback:literal)?) => {
4747        "GPIO0"
4748    };
4749    (ADC1_CH1 $(, $_fallback:literal)?) => {
4750        "GPIO1"
4751    };
4752    (LP_GPIO1 $(, $_fallback:literal)?) => {
4753        "GPIO1"
4754    };
4755    (FSPIQ $(, $_fallback:literal)?) => {
4756        "GPIO2"
4757    };
4758    (ADC1_CH2 $(, $_fallback:literal)?) => {
4759        "GPIO2"
4760    };
4761    (LP_GPIO2 $(, $_fallback:literal)?) => {
4762        "GPIO2"
4763    };
4764    (ADC1_CH3 $(, $_fallback:literal)?) => {
4765        "GPIO3"
4766    };
4767    (LP_GPIO3 $(, $_fallback:literal)?) => {
4768        "GPIO3"
4769    };
4770    (MTMS $(, $_fallback:literal)?) => {
4771        "GPIO4"
4772    };
4773    (FSPIHD $(, $_fallback:literal)?) => {
4774        "GPIO4"
4775    };
4776    (ADC1_CH4 $(, $_fallback:literal)?) => {
4777        "GPIO4"
4778    };
4779    (LP_GPIO4 $(, $_fallback:literal)?) => {
4780        "GPIO4"
4781    };
4782    (MTDI $(, $_fallback:literal)?) => {
4783        "GPIO5"
4784    };
4785    (FSPIWP $(, $_fallback:literal)?) => {
4786        "GPIO5"
4787    };
4788    (LP_GPIO5 $(, $_fallback:literal)?) => {
4789        "GPIO5"
4790    };
4791    (MTCK $(, $_fallback:literal)?) => {
4792        "GPIO6"
4793    };
4794    (FSPICLK $(, $_fallback:literal)?) => {
4795        "GPIO6"
4796    };
4797    (MTDO $(, $_fallback:literal)?) => {
4798        "GPIO7"
4799    };
4800    (FSPID $(, $_fallback:literal)?) => {
4801        "GPIO7"
4802    };
4803    (FSPICS0 $(, $_fallback:literal)?) => {
4804        "GPIO10"
4805    };
4806    (SPIHD $(, $_fallback:literal)?) => {
4807        "GPIO11"
4808    };
4809    (SPIWP $(, $_fallback:literal)?) => {
4810        "GPIO13"
4811    };
4812    (SPICS0 $(, $_fallback:literal)?) => {
4813        "GPIO14"
4814    };
4815    (SPICLK $(, $_fallback:literal)?) => {
4816        "GPIO15"
4817    };
4818    (SPID $(, $_fallback:literal)?) => {
4819        "GPIO16"
4820    };
4821    (SPIQ $(, $_fallback:literal)?) => {
4822        "GPIO17"
4823    };
4824    (U0RXD $(, $_fallback:literal)?) => {
4825        "GPIO19"
4826    };
4827    (U0TXD $(, $_fallback:literal)?) => {
4828        "GPIO20"
4829    };
4830    ($_signal:ident, $fallback:literal) => {
4831        $fallback
4832    };
4833}
4834/// Defines the `InputSignal` and `OutputSignal` enums.
4835///
4836/// This macro is intended to be called in esp-hal only.
4837#[macro_export]
4838#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4839macro_rules! define_io_mux_signals {
4840    () => {
4841        #[allow(non_camel_case_types, clippy::upper_case_acronyms)]
4842        #[derive(Debug, PartialEq, Copy, Clone)]
4843        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
4844        #[doc(hidden)]
4845        pub enum InputSignal {
4846            SPIQ          = 0,
4847            SPID          = 1,
4848            SPIHD         = 2,
4849            SPIWP         = 3,
4850            U0RXD         = 6,
4851            U0CTS         = 7,
4852            U0DSR         = 8,
4853            U1RXD         = 9,
4854            U1CTS         = 10,
4855            U1DSR         = 11,
4856            CPU_GPIO_0    = 28,
4857            CPU_GPIO_1    = 29,
4858            CPU_GPIO_2    = 30,
4859            CPU_GPIO_3    = 31,
4860            CPU_GPIO_4    = 32,
4861            CPU_GPIO_5    = 33,
4862            CPU_GPIO_6    = 34,
4863            CPU_GPIO_7    = 35,
4864            EXT_ADC_START = 45,
4865            RMT_SIG_0     = 51,
4866            RMT_SIG_1     = 52,
4867            I2CEXT0_SCL   = 53,
4868            I2CEXT0_SDA   = 54,
4869            FSPICLK       = 63,
4870            FSPIQ         = 64,
4871            FSPID         = 65,
4872            FSPIHD        = 66,
4873            FSPIWP        = 67,
4874            FSPICS0       = 68,
4875            SIG_FUNC_97   = 97,
4876            SIG_FUNC_98   = 98,
4877            SIG_FUNC_99   = 99,
4878            SIG_FUNC_100  = 100,
4879            MTCK,
4880            MTMS,
4881            MTDI,
4882        }
4883        #[allow(non_camel_case_types, clippy::upper_case_acronyms)]
4884        #[derive(Debug, PartialEq, Copy, Clone)]
4885        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
4886        #[doc(hidden)]
4887        pub enum OutputSignal {
4888            SPIQ          = 0,
4889            SPID          = 1,
4890            SPIHD         = 2,
4891            SPIWP         = 3,
4892            SPICLK        = 4,
4893            SPICS0        = 5,
4894            U0TXD         = 6,
4895            U0RTS         = 7,
4896            U0DTR         = 8,
4897            U1TXD         = 9,
4898            U1RTS         = 10,
4899            U1DTR         = 11,
4900            SPIQ_MONITOR  = 15,
4901            SPID_MONITOR  = 16,
4902            SPIHD_MONITOR = 17,
4903            SPIWP_MONITOR = 18,
4904            SPICS1        = 19,
4905            CPU_GPIO_0    = 28,
4906            CPU_GPIO_1    = 29,
4907            CPU_GPIO_2    = 30,
4908            CPU_GPIO_3    = 31,
4909            CPU_GPIO_4    = 32,
4910            CPU_GPIO_5    = 33,
4911            CPU_GPIO_6    = 34,
4912            CPU_GPIO_7    = 35,
4913            LEDC_LS_SIG0  = 45,
4914            LEDC_LS_SIG1  = 46,
4915            LEDC_LS_SIG2  = 47,
4916            LEDC_LS_SIG3  = 48,
4917            LEDC_LS_SIG4  = 49,
4918            LEDC_LS_SIG5  = 50,
4919            RMT_SIG_0     = 51,
4920            RMT_SIG_1     = 52,
4921            I2CEXT0_SCL   = 53,
4922            I2CEXT0_SDA   = 54,
4923            FSPICLK       = 63,
4924            FSPIQ         = 64,
4925            FSPID         = 65,
4926            FSPIHD        = 66,
4927            FSPIWP        = 67,
4928            FSPICS0       = 68,
4929            FSPICS1       = 69,
4930            FSPICS3       = 70,
4931            FSPICS2       = 71,
4932            FSPICS4       = 72,
4933            FSPICS5       = 73,
4934            ANT_SEL0      = 89,
4935            ANT_SEL1      = 90,
4936            ANT_SEL2      = 91,
4937            ANT_SEL3      = 92,
4938            ANT_SEL4      = 93,
4939            ANT_SEL5      = 94,
4940            ANT_SEL6      = 95,
4941            ANT_SEL7      = 96,
4942            SIG_FUNC_97   = 97,
4943            SIG_FUNC_98   = 98,
4944            SIG_FUNC_99   = 99,
4945            SIG_FUNC_100  = 100,
4946            CLK_OUT1      = 123,
4947            CLK_OUT2      = 124,
4948            CLK_OUT3      = 125,
4949            GPIO          = 128,
4950            MTDO,
4951        }
4952    };
4953}
4954/// Defines the `LpFunction` enum.
4955///
4956/// The enum only contains the LP IO MUX functions that the chip implements. It is
4957/// empty on chips without an LP IO peripheral.
4958///
4959/// This macro is intended to be called in esp-hal only.
4960#[macro_export]
4961#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4962macro_rules! define_lp_functions {
4963    () => {
4964        /// LP IO MUX function of a pad.
4965        ///
4966        /// This is the low-power counterpart of `AlternateFunction`: it selects which function
4967        /// drives a pad while the pad belongs to the low-power domain.
4968        #[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
4969        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
4970        #[doc(hidden)]
4971        pub enum LpFunction {
4972            /// LP IO MUX function 0.
4973            _0 = 0,
4974        }
4975        impl LpFunction {
4976            /// The function that connects the pad to the LP GPIO peripheral.
4977            pub const LP_GPIO: Self = Self::_0;
4978        }
4979    };
4980}
4981/// Defines and implements the `io_mux_reg` function.
4982///
4983/// The generated function has the following signature:
4984///
4985/// ```rust,ignore
4986/// pub(crate) fn io_mux_reg(gpio_num: u8) -> &'static crate::pac::io_mux::GPIO0 {
4987///     // ...
4988/// # unimplemented!()
4989/// }
4990/// ```
4991///
4992/// This macro is intended to be called in esp-hal only.
4993#[macro_export]
4994#[expect(clippy::crate_in_macro_def)]
4995#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4996macro_rules! define_io_mux_reg {
4997    () => {
4998        pub(crate) fn io_mux_reg(gpio_num: u8) -> &'static crate::pac::io_mux::GPIO {
4999            crate::peripherals::IO_MUX::regs().gpio(gpio_num as usize)
5000        }
5001    };
5002}