Skip to main content

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