Skip to main content

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