Skip to main content

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