Skip to main content

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