Skip to main content

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