Skip to main content

esp_metadata_generated/
_generated_esp32c61.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        "esp32c61"
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-C61"
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        "esp32c61"
42    };
43    ("arch") => {
44        "riscv"
45    };
46    ("cores") => {
47        1
48    };
49    ("cores", str) => {
50        stringify!(1)
51    };
52    ("trm") => {
53        "https://www.espressif.com/sites/default/files/documentation/esp32-c61_technical_reference_manual_en.pdf"
54    };
55    ("gpio.version") => {
56        2
57    };
58    ("gpio.version", str) => {
59        stringify!(2)
60    };
61    ("gpio.has_input_sync") => {
62        true
63    };
64    ("gpio.gpio_function") => {
65        1
66    };
67    ("gpio.gpio_function", str) => {
68        stringify!(1)
69    };
70    ("gpio.constant_0_input") => {
71        96
72    };
73    ("gpio.constant_0_input", str) => {
74        stringify!(96)
75    };
76    ("gpio.constant_1_input") => {
77        64
78    };
79    ("gpio.constant_1_input", str) => {
80        stringify!(64)
81    };
82    ("gpio.remap_iomux_pin_registers") => {
83        false
84    };
85    ("gpio.func_in_sel_offset") => {
86        0
87    };
88    ("gpio.func_in_sel_offset", str) => {
89        stringify!(0)
90    };
91    ("gpio.has_bank_1") => {
92        false
93    };
94    ("gpio.input_signal_max") => {
95        100
96    };
97    ("gpio.input_signal_max", str) => {
98        stringify!(100)
99    };
100    ("gpio.output_signal_max") => {
101        256
102    };
103    ("gpio.output_signal_max", str) => {
104        stringify!(256)
105    };
106    ("dedicated_gpio.version") => {
107        "riscv_v1"
108    };
109    ("dedicated_gpio.needs_initialization") => {
110        false
111    };
112    ("dedicated_gpio.channel_count") => {
113        8
114    };
115    ("dedicated_gpio.channel_count", str) => {
116        stringify!(8)
117    };
118    ("lp_io.version") => {
119        "v4"
120    };
121    ("lp_io.has_gpio_matrix") => {
122        false
123    };
124    ("uart.ram_size") => {
125        128
126    };
127    ("uart.ram_size", str) => {
128        stringify!(128)
129    };
130    ("uart.version") => {
131        2
132    };
133    ("uart.version", str) => {
134        stringify!(2)
135    };
136    ("uart.peripheral_controls_mem_clk") => {
137        true
138    };
139    ("uart.has_sclk_divider") => {
140        false
141    };
142    ("uart.has_sclk_enable") => {
143        true
144    };
145    ("i2c_master.version") => {
146        4
147    };
148    ("i2c_master.version", str) => {
149        stringify!(4)
150    };
151    ("i2c_master.has_fsm_timeouts") => {
152        true
153    };
154    ("i2c_master.has_hw_bus_clear") => {
155        true
156    };
157    ("i2c_master.has_bus_timeout_enable") => {
158        true
159    };
160    ("i2c_master.separate_filter_config_registers") => {
161        false
162    };
163    ("i2c_master.can_estimate_nack_reason") => {
164        true
165    };
166    ("i2c_master.has_conf_update") => {
167        true
168    };
169    ("i2c_master.has_reliable_fsm_reset") => {
170        true
171    };
172    ("i2c_master.has_arbitration_en") => {
173        true
174    };
175    ("i2c_master.has_tx_fifo_watermark") => {
176        true
177    };
178    ("i2c_master.bus_timeout_is_exponential") => {
179        true
180    };
181    ("i2c_master.has_pd_en") => {
182        true
183    };
184    ("i2c_master.max_bus_timeout") => {
185        31
186    };
187    ("i2c_master.max_bus_timeout", str) => {
188        stringify!(31)
189    };
190    ("i2c_master.ll_intr_mask") => {
191        262143
192    };
193    ("i2c_master.ll_intr_mask", str) => {
194        stringify!(262143)
195    };
196    ("i2c_master.fifo_size") => {
197        32
198    };
199    ("i2c_master.fifo_size", str) => {
200        stringify!(32)
201    };
202    ("spi_master.version") => {
203        3
204    };
205    ("spi_master.version", str) => {
206        stringify!(3)
207    };
208    ("spi_master.fifo_size") => {
209        64
210    };
211    ("spi_master.fifo_size", str) => {
212        stringify!(64)
213    };
214    ("spi_master.bit_order_is_bool") => {
215        false
216    };
217    ("spi_master.has_octal") => {
218        false
219    };
220    ("spi_master.has_app_interrupts") => {
221        true
222    };
223    ("spi_master.has_dma_segmented_transfer") => {
224        true
225    };
226    ("spi_master.has_clk_pre_div") => {
227        true
228    };
229    ("spi_master.dma_can_access_flash") => {
230        true
231    };
232    ("i2s.version") => {
233        3
234    };
235    ("i2s.version", str) => {
236        stringify!(3)
237    };
238    ("i2s.default_clock_source") => {
239        2
240    };
241    ("i2s.default_clock_source", str) => {
242        stringify!(2)
243    };
244    ("i2s.mclk_divider_bit_width") => {
245        9
246    };
247    ("i2s.mclk_divider_bit_width", str) => {
248        stringify!(9)
249    };
250    ("i2s.max_ws_width") => {
251        512
252    };
253    ("i2s.max_ws_width", str) => {
254        stringify!(512)
255    };
256    ("i2s.clock_configured_by_pcr") => {
257        true
258    };
259    ("i2s.clock_configured_by_hp_sys_clkrst") => {
260        false
261    };
262    ("i2s.supports_pdm_rx_hp_filter") => {
263        false
264    };
265    ("i2s.supports_pdm_tx") => {
266        true
267    };
268    ("i2s.supports_pdm_rx") => {
269        true
270    };
271    ("i2s.supports_pcm2pdm") => {
272        true
273    };
274    ("i2s.supports_pdm2pcm") => {
275        false
276    };
277    ("bt.controller") => {
278        "npl"
279    };
280    ("wifi.has_wifi6") => {
281        true
282    };
283    ("wifi.mac_version") => {
284        3
285    };
286    ("wifi.mac_version", str) => {
287        stringify!(3)
288    };
289    ("wifi.has_5g") => {
290        false
291    };
292    ("wifi.csi_supported") => {
293        true
294    };
295    ("phy.combo_module") => {
296        true
297    };
298    ("timergroup.timg_has_timer1") => {
299        false
300    };
301    ("timergroup.timg_has_divcnt_rst") => {
302        true
303    };
304    ("timergroup.rc_fast_calibration_divider_min_rev") => {
305        0
306    };
307    ("timergroup.rc_fast_calibration_divider") => {
308        32
309    };
310    ("timergroup.rc_fast_calibration_tick_enable") => {
311        false
312    };
313    ("ecc.zero_extend_writes") => {
314        true
315    };
316    ("ecc.separate_jacobian_point_memory") => {
317        true
318    };
319    ("ecc.has_memory_clock_gate") => {
320        true
321    };
322    ("ecc.supports_enhanced_security") => {
323        true
324    };
325    ("ecc.mem_block_size") => {
326        32
327    };
328    ("rng.apb_cycle_wait_num") => {
329        16
330    };
331    ("rng.apb_cycle_wait_num", str) => {
332        stringify!(16)
333    };
334    ("rng.trng_supported") => {
335        false
336    };
337    ("rng.is_lp_sys") => {
338        true
339    };
340    ("sleep.light_sleep") => {
341        true
342    };
343    ("sleep.deep_sleep") => {
344        true
345    };
346    ("sleep.rejectable_mask") => {
347        4094
348    };
349    ("sleep.ext1_version") => {
350        2
351    };
352    ("sleep.ext1_version", str) => {
353        stringify!(2)
354    };
355    ("sleep.pin_wakeup_version") => {
356        3
357    };
358    ("sleep.pin_wakeup_version", str) => {
359        stringify!(3)
360    };
361    ("sleep.deep_sleep_needs_gpio_isolation") => {
362        false
363    };
364    ("assist_debug.has_sp_monitor") => {
365        true
366    };
367    ("assist_debug.has_region_monitor") => {
368        true
369    };
370    ("dma.mem2mem_requires_peripheral") => {
371        false
372    };
373    ("dma.ext_mem_configurable_block_size") => {
374        false
375    };
376    ("dma.separate_in_out_interrupts") => {
377        true
378    };
379    ("dma.gdma_version") => {
380        2
381    };
382    ("dma.gdma_version", str) => {
383        stringify!(2)
384    };
385    ("interrupts.status_registers") => {
386        3
387    };
388    ("interrupts.status_registers", str) => {
389        stringify!(3)
390    };
391    ("interrupts.disabled_interrupt") => {
392        0
393    };
394    ("mmu.page_size") => {
395        65536
396    };
397    ("mmu.page_size", str) => {
398        stringify!(65536)
399    };
400    ("mmu.entry_num") => {
401        512
402    };
403    ("mmu.entry_num", str) => {
404        stringify!(512)
405    };
406    ("psram.octal_spi") => {
407        false
408    };
409    ("psram.hex_spi") => {
410        false
411    };
412    ("psram.extmem_origin") => {
413        1107296256
414    };
415    ("psram.extmem_origin", str) => {
416        stringify!(1107296256)
417    };
418    ("rom.has_crc_le") => {
419        true
420    };
421    ("rom.has_crc_be") => {
422        true
423    };
424    ("rom.has_md5_bsd") => {
425        true
426    };
427    ("rom.has_md5_mbedtls") => {
428        false
429    };
430    ("soc.cpu_has_branch_predictor") => {
431        true
432    };
433    ("soc.cpu_has_csr_pc") => {
434        false
435    };
436    ("soc.multi_core_enabled") => {
437        false
438    };
439    ("soc.cpu_csr_prv_mode") => {
440        2064
441    };
442    ("soc.cpu_csr_prv_mode", str) => {
443        stringify!(2064)
444    };
445    ("soc.internal_memory_cached") => {
446        false
447    };
448    ("soc.has_swd_watchdog") => {
449        true
450    };
451    ("soc.cpu_mcause_mask") => {
452        31
453    };
454    ("soc.cpu_mcause_mask", str) => {
455        stringify!(31)
456    };
457    ("clock_tree.hp_root_clk") => {
458        [crate ::soc::clocks::HpRootClkConfig::Xtal, crate
459        ::soc::clocks::HpRootClkConfig::RcFast, crate
460        ::soc::clocks::HpRootClkConfig::PllF160m]
461    };
462    ("clock_tree.cpu_clk.divisor") => {
463        (0, 255)
464    };
465    ("clock_tree.ahb_clk.divisor") => {
466        (0, 255)
467    };
468    ("clock_tree.apb_clk.divisor") => {
469        (0, 255)
470    };
471    ("clock_tree.lp_fast_clk") => {
472        [crate ::soc::clocks::LpFastClkConfig::RcFast, crate
473        ::soc::clocks::LpFastClkConfig::XtalD2, crate
474        ::soc::clocks::LpFastClkConfig::Xtal]
475    };
476    ("clock_tree.lp_slow_clk") => {
477        [crate ::soc::clocks::LpSlowClkConfig::RcSlow, crate
478        ::soc::clocks::LpSlowClkConfig::Xtal32k, crate
479        ::soc::clocks::LpSlowClkConfig::OscSlow]
480    };
481    ("clock_tree.timg_calibration_clock") => {
482        [crate ::soc::clocks::TimgCalibrationClockConfig::OscSlowClk, crate
483        ::soc::clocks::TimgCalibrationClockConfig::RcSlowClk, crate
484        ::soc::clocks::TimgCalibrationClockConfig::RcFastDivClk, crate
485        ::soc::clocks::TimgCalibrationClockConfig::Xtal32kClk]
486    };
487    ("clock_tree.uart.function_clock.sclk") => {
488        [crate ::soc::clocks::UartFunctionClockSclk::Xtal, crate
489        ::soc::clocks::UartFunctionClockSclk::PllF80m, crate
490        ::soc::clocks::UartFunctionClockSclk::RcFast]
491    };
492    ("clock_tree.uart.function_clock.div_num") => {
493        (0, 255)
494    };
495    ("clock_tree.uart.baud_rate_generator.fractional") => {
496        (0, 15)
497    };
498    ("clock_tree.uart.baud_rate_generator.integral") => {
499        (0, 4095)
500    };
501    ("clock_tree.timg.function_clock") => {
502        [crate ::soc::clocks::TimgFunctionClockConfig::XtalClk, crate
503        ::soc::clocks::TimgFunctionClockConfig::RcFastClk, crate
504        ::soc::clocks::TimgFunctionClockConfig::PllF80m]
505    };
506    ("clock_tree.timg.wdt_clock") => {
507        [crate ::soc::clocks::TimgWdtClockConfig::XtalClk, crate
508        ::soc::clocks::TimgWdtClockConfig::RcFastClk, crate
509        ::soc::clocks::TimgWdtClockConfig::PllF80m]
510    };
511    ("clock_tree.i2c.function_clock.sclk") => {
512        [crate ::soc::clocks::I2cFunctionClockSclk::Xtal, crate
513        ::soc::clocks::I2cFunctionClockSclk::RcFast]
514    };
515    ("clock_tree.i2c.function_clock.div_num") => {
516        (0, 255)
517    };
518    ("clock_tree.spi.function_clock") => {
519        [crate ::soc::clocks::SpiFunctionClockConfig::Xtal, crate
520        ::soc::clocks::SpiFunctionClockConfig::PllF160m, crate
521        ::soc::clocks::SpiFunctionClockConfig::RcFast]
522    };
523}
524#[macro_export]
525#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
526macro_rules! for_each_dedicated_gpio {
527    ($($pattern:tt => $code:tt;)*) => {
528        macro_rules! _for_each_inner_dedicated_gpio { $(($pattern) => $code;)* ($other :
529        tt) => {} } _for_each_inner_dedicated_gpio!((0));
530        _for_each_inner_dedicated_gpio!((1)); _for_each_inner_dedicated_gpio!((2));
531        _for_each_inner_dedicated_gpio!((3)); _for_each_inner_dedicated_gpio!((4));
532        _for_each_inner_dedicated_gpio!((5)); _for_each_inner_dedicated_gpio!((6));
533        _for_each_inner_dedicated_gpio!((7)); _for_each_inner_dedicated_gpio!((0, 0,
534        CPU_GPIO_0)); _for_each_inner_dedicated_gpio!((0, 1, CPU_GPIO_1));
535        _for_each_inner_dedicated_gpio!((0, 2, CPU_GPIO_2));
536        _for_each_inner_dedicated_gpio!((0, 3, CPU_GPIO_3));
537        _for_each_inner_dedicated_gpio!((0, 4, CPU_GPIO_4));
538        _for_each_inner_dedicated_gpio!((0, 5, CPU_GPIO_5));
539        _for_each_inner_dedicated_gpio!((0, 6, CPU_GPIO_6));
540        _for_each_inner_dedicated_gpio!((0, 7, CPU_GPIO_7));
541        _for_each_inner_dedicated_gpio!((channels(0), (1), (2), (3), (4), (5), (6),
542        (7))); _for_each_inner_dedicated_gpio!((signals(0, 0, CPU_GPIO_0), (0, 1,
543        CPU_GPIO_1), (0, 2, CPU_GPIO_2), (0, 3, CPU_GPIO_3), (0, 4, CPU_GPIO_4), (0, 5,
544        CPU_GPIO_5), (0, 6, CPU_GPIO_6), (0, 7, CPU_GPIO_7)));
545    };
546}
547/// Defines the `LpInputSignal` and `LpOutputSignal` enums.
548///
549/// This macro is intended to be called in esp-hal only.
550#[macro_export]
551#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
552macro_rules! define_lp_io_signals {
553    () => {};
554}
555#[macro_export]
556#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
557macro_rules! for_each_ecc_working_mode {
558    ($($pattern:tt => $code:tt;)*) => {
559        macro_rules! _for_each_inner_ecc_working_mode { $(($pattern) => $code;)* ($other
560        : tt) => {} } _for_each_inner_ecc_working_mode!((0, AffinePointMultiplication));
561        _for_each_inner_ecc_working_mode!((2, AffinePointVerification));
562        _for_each_inner_ecc_working_mode!((3, AffinePointVerificationAndMultiplication));
563        _for_each_inner_ecc_working_mode!((4, JacobianPointMultiplication));
564        _for_each_inner_ecc_working_mode!((5, AffinePointAddition));
565        _for_each_inner_ecc_working_mode!((6, JacobianPointVerification));
566        _for_each_inner_ecc_working_mode!((7,
567        AffinePointVerificationAndJacobianPointMultiplication));
568        _for_each_inner_ecc_working_mode!((8, ModularAddition));
569        _for_each_inner_ecc_working_mode!((9, ModularSubtraction));
570        _for_each_inner_ecc_working_mode!((10, ModularMultiplication));
571        _for_each_inner_ecc_working_mode!((11, ModularDivision));
572        _for_each_inner_ecc_working_mode!((all(0, AffinePointMultiplication), (2,
573        AffinePointVerification), (3, AffinePointVerificationAndMultiplication), (4,
574        JacobianPointMultiplication), (5, AffinePointAddition), (6,
575        JacobianPointVerification), (7,
576        AffinePointVerificationAndJacobianPointMultiplication), (8, ModularAddition), (9,
577        ModularSubtraction), (10, ModularMultiplication), (11, ModularDivision)));
578    };
579}
580#[macro_export]
581#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
582macro_rules! for_each_ecc_curve {
583    ($($pattern:tt => $code:tt;)*) => {
584        macro_rules! _for_each_inner_ecc_curve { $(($pattern) => $code;)* ($other : tt)
585        => {} } _for_each_inner_ecc_curve!((0, P192, 192));
586        _for_each_inner_ecc_curve!((1, P256, 256)); _for_each_inner_ecc_curve!((all(0,
587        P192, 192), (1, P256, 256)));
588    };
589}
590#[macro_export]
591#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
592macro_rules! for_each_sha_algorithm {
593    ($($pattern:tt => $code:tt;)*) => {
594        macro_rules! _for_each_inner_sha_algorithm { $(($pattern) => $code;)* ($other :
595        tt) => {} } _for_each_inner_sha_algorithm!((Sha1, "SHA-1"(sizes : 64, 20, 8)
596        (insecure_against : "collision", "length extension"), 0));
597        _for_each_inner_sha_algorithm!((Sha224, "SHA-224"(sizes : 64, 28, 8)
598        (insecure_against : "length extension"), 1));
599        _for_each_inner_sha_algorithm!((Sha256, "SHA-256"(sizes : 64, 32, 8)
600        (insecure_against : "length extension"), 2));
601        _for_each_inner_sha_algorithm!((algos(Sha1, "SHA-1"(sizes : 64, 20, 8)
602        (insecure_against : "collision", "length extension"), 0), (Sha224,
603        "SHA-224"(sizes : 64, 28, 8) (insecure_against : "length extension"), 1),
604        (Sha256, "SHA-256"(sizes : 64, 32, 8) (insecure_against : "length extension"),
605        2)));
606    };
607}
608#[macro_export]
609#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
610macro_rules! for_each_wakeup_source {
611    ($($pattern:tt => $code:tt;)*) => {
612        macro_rules! _for_each_inner_wakeup_source { $(($pattern) => $code;)* ($other :
613        tt) => {} } _for_each_inner_wakeup_source!((Ext1, 1));
614        _for_each_inner_wakeup_source!((Gpio, 2));
615        _for_each_inner_wakeup_source!((WifiBeacon, 3));
616        _for_each_inner_wakeup_source!((Timer, 4)); _for_each_inner_wakeup_source!((Wifi,
617        5)); _for_each_inner_wakeup_source!((Uart0, 6));
618        _for_each_inner_wakeup_source!((Uart1, 7)); _for_each_inner_wakeup_source!((Sdio,
619        8)); _for_each_inner_wakeup_source!((Uart2, 9));
620        _for_each_inner_wakeup_source!((Bt, 10)); _for_each_inner_wakeup_source!((LpCore,
621        11)); _for_each_inner_wakeup_source!((all(Ext1, 1), (Gpio, 2), (WifiBeacon, 3),
622        (Timer, 4), (Wifi, 5), (Uart0, 6), (Uart1, 7), (Sdio, 8), (Uart2, 9), (Bt, 10),
623        (LpCore, 11)));
624    };
625}
626#[macro_export]
627#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
628macro_rules! for_each_dma_engine {
629    ($($pattern:tt => $code:tt;)*) => {
630        macro_rules! _for_each_inner_dma_engine { $(($pattern) => $code;)* ($other : tt)
631        => {} } _for_each_inner_dma_engine!(("AHB_GDMA"));
632        _for_each_inner_dma_engine!((all("AHB_GDMA")));
633    };
634}
635#[macro_export]
636#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
637macro_rules! for_each_dma_channel {
638    ($($pattern:tt => $code:tt;)*) => {
639        macro_rules! _for_each_inner_dma_channel { $(($pattern) => $code;)* ($other : tt)
640        => {} } _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH0));
641        _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH1));
642        _for_each_inner_dma_channel!(("AHB_GDMA", any_channel = AhbGdmaChannel));
643        _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH0, 0, interrupt_in = DMA_IN_CH0,
644        interrupt_out = DMA_OUT_CH0, compatible = [SPI2, I2S0, SHA]));
645        _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH1, 1, interrupt_in = DMA_IN_CH1,
646        interrupt_out = DMA_OUT_CH1, compatible = [SPI2, I2S0, SHA]));
647        _for_each_inner_dma_channel!((names("AHB_GDMA", DMA_CH0), ("AHB_GDMA",
648        DMA_CH1))); _for_each_inner_dma_channel!((separate_any_type("AHB_GDMA",
649        any_channel = AhbGdmaChannel))); _for_each_inner_dma_channel!((shared));
650        _for_each_inner_dma_channel!((split("AHB_GDMA", DMA_CH0, 0, interrupt_in =
651        DMA_IN_CH0, interrupt_out = DMA_OUT_CH0, compatible = [SPI2, I2S0, SHA]),
652        ("AHB_GDMA", DMA_CH1, 1, interrupt_in = DMA_IN_CH1, interrupt_out = DMA_OUT_CH1,
653        compatible = [SPI2, I2S0, SHA])));
654        _for_each_inner_dma_channel!((no_own_interrupt));
655    };
656}
657#[macro_export]
658#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
659macro_rules! for_each_dma_channel_peri_pair {
660    ($($pattern:tt => $code:tt;)*) => {
661        macro_rules! _for_each_inner_dma_channel_peri_pair { $(($pattern) => $code;)*
662        ($other : tt) => {} } _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA",
663        DMA_CH0, SPI2)); _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH0,
664        I2S0)); _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH0, SHA));
665        _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH1, SPI2));
666        _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH1, I2S0));
667        _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH1, SHA));
668        _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", any_channel = AhbGdmaChannel,
669        SPI2)); _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", any_channel =
670        AhbGdmaChannel, I2S0)); _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA",
671        any_channel = AhbGdmaChannel, SHA));
672        _for_each_inner_dma_channel_peri_pair!((channels("AHB_GDMA", DMA_CH0, SPI2),
673        ("AHB_GDMA", DMA_CH0, I2S0), ("AHB_GDMA", DMA_CH0, SHA), ("AHB_GDMA", DMA_CH1,
674        SPI2), ("AHB_GDMA", DMA_CH1, I2S0), ("AHB_GDMA", DMA_CH1, SHA)));
675        _for_each_inner_dma_channel_peri_pair!((any_channels("AHB_GDMA", any_channel =
676        AhbGdmaChannel, SPI2), ("AHB_GDMA", any_channel = AhbGdmaChannel, I2S0),
677        ("AHB_GDMA", any_channel = AhbGdmaChannel, SHA)));
678    };
679}
680#[macro_export]
681#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
682macro_rules! for_each_mem2mem_channel {
683    ($($pattern:tt => $code:tt;)*) => {
684        macro_rules! _for_each_inner_mem2mem_channel { $(($pattern) => $code;)* ($other :
685        tt) => {} } _for_each_inner_mem2mem_channel!(("AHB_GDMA", AhbGdma,
686        AhbGdmaChannel, DMA_CH0, 4)); _for_each_inner_mem2mem_channel!(("AHB_GDMA",
687        AhbGdma, AhbGdmaChannel, DMA_CH1, 5));
688        _for_each_inner_mem2mem_channel!(("AHB_GDMA", AhbGdma, AhbGdmaChannel, 0, 4, 1,
689        5)); _for_each_inner_mem2mem_channel!(("AHB_GDMA", AhbGdma, AhbGdmaChannel));
690        _for_each_inner_mem2mem_channel!((channels("AHB_GDMA", AhbGdma, AhbGdmaChannel,
691        DMA_CH0, 4), ("AHB_GDMA", AhbGdma, AhbGdmaChannel, DMA_CH1, 5)));
692        _for_each_inner_mem2mem_channel!((erased("AHB_GDMA", AhbGdma, AhbGdmaChannel, 0,
693        4, 1, 5))); _for_each_inner_mem2mem_channel!((engines("AHB_GDMA", AhbGdma,
694        AhbGdmaChannel)));
695    };
696}
697#[macro_export]
698#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
699macro_rules! with_i2s_dma_engine {
700    ($($pattern:tt => $code:tt;)*) => {
701        macro_rules! _with_inner_i2s_dma_engine { $(($pattern) => $code;)* ($other : tt)
702        => {} } _with_inner_i2s_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
703    };
704}
705#[macro_export]
706#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
707macro_rules! with_sha_dma_engine {
708    ($($pattern:tt => $code:tt;)*) => {
709        macro_rules! _with_inner_sha_dma_engine { $(($pattern) => $code;)* ($other : tt)
710        => {} } _with_inner_sha_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
711    };
712}
713#[macro_export]
714#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
715macro_rules! with_spi_master_dma_engine {
716    ($($pattern:tt => $code:tt;)*) => {
717        macro_rules! _with_inner_spi_master_dma_engine { $(($pattern) => $code;)* ($other
718        : tt) => {} } _with_inner_spi_master_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
719    };
720}
721#[macro_export]
722#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
723macro_rules! with_spi_slave_dma_engine {
724    ($($pattern:tt => $code:tt;)*) => {
725        macro_rules! _with_inner_spi_slave_dma_engine { $(($pattern) => $code;)* ($other
726        : tt) => {} } _with_inner_spi_slave_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
727    };
728}
729#[macro_export]
730#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
731macro_rules! for_each_interrupt {
732    ($($pattern:tt => $code:tt;)*) => {
733        macro_rules! _for_each_inner_interrupt { $(($pattern) => $code;)* ($other : tt)
734        => {} } _for_each_inner_interrupt!(([disabled 0] 0));
735        _for_each_inner_interrupt!(([reserved 0] 1));
736        _for_each_inner_interrupt!(([reserved 1] 2));
737        _for_each_inner_interrupt!(([reserved 2] 3));
738        _for_each_inner_interrupt!(([reserved 3] 4));
739        _for_each_inner_interrupt!(([reserved 4] 5));
740        _for_each_inner_interrupt!(([reserved 5] 6));
741        _for_each_inner_interrupt!(([reserved 6] 7));
742        _for_each_inner_interrupt!(([reserved 7] 8));
743        _for_each_inner_interrupt!(([reserved 8] 9));
744        _for_each_inner_interrupt!(([reserved 9] 10));
745        _for_each_inner_interrupt!(([reserved 10] 11));
746        _for_each_inner_interrupt!(([reserved 11] 12));
747        _for_each_inner_interrupt!(([reserved 12] 13));
748        _for_each_inner_interrupt!(([reserved 13] 14));
749        _for_each_inner_interrupt!(([reserved 14] 15));
750        _for_each_inner_interrupt!(([vector 0] 16)); _for_each_inner_interrupt!(([vector
751        1] 17)); _for_each_inner_interrupt!(([vector 2] 18));
752        _for_each_inner_interrupt!(([vector 3] 19)); _for_each_inner_interrupt!(([vector
753        4] 20)); _for_each_inner_interrupt!(([vector 5] 21));
754        _for_each_inner_interrupt!(([vector 6] 22)); _for_each_inner_interrupt!(([vector
755        7] 23)); _for_each_inner_interrupt!(([direct_bindable 0] 24));
756        _for_each_inner_interrupt!(([direct_bindable 1] 25));
757        _for_each_inner_interrupt!(([direct_bindable 2] 26));
758        _for_each_inner_interrupt!(([direct_bindable 3] 27));
759        _for_each_inner_interrupt!(([direct_bindable 4] 28));
760        _for_each_inner_interrupt!(([direct_bindable 5] 29));
761        _for_each_inner_interrupt!(([direct_bindable 6] 30));
762        _for_each_inner_interrupt!(([direct_bindable 7] 31));
763        _for_each_inner_interrupt!((all([disabled 0] 0), ([reserved 0] 1), ([reserved 1]
764        2), ([reserved 2] 3), ([reserved 3] 4), ([reserved 4] 5), ([reserved 5] 6),
765        ([reserved 6] 7), ([reserved 7] 8), ([reserved 8] 9), ([reserved 9] 10),
766        ([reserved 10] 11), ([reserved 11] 12), ([reserved 12] 13), ([reserved 13] 14),
767        ([reserved 14] 15), ([vector 0] 16), ([vector 1] 17), ([vector 2] 18), ([vector
768        3] 19), ([vector 4] 20), ([vector 5] 21), ([vector 6] 22), ([vector 7] 23),
769        ([direct_bindable 0] 24), ([direct_bindable 1] 25), ([direct_bindable 2] 26),
770        ([direct_bindable 3] 27), ([direct_bindable 4] 28), ([direct_bindable 5] 29),
771        ([direct_bindable 6] 30), ([direct_bindable 7] 31)));
772    };
773}
774#[macro_export]
775#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
776macro_rules! for_each_classified_interrupt {
777    ($($pattern:tt => $code:tt;)*) => {
778        macro_rules! _for_each_inner_classified_interrupt { $(($pattern) => $code;)*
779        ($other : tt) => {} } _for_each_inner_classified_interrupt!(([direct_bindable 0]
780        24)); _for_each_inner_classified_interrupt!(([direct_bindable 1] 25));
781        _for_each_inner_classified_interrupt!(([direct_bindable 2] 26));
782        _for_each_inner_classified_interrupt!(([direct_bindable 3] 27));
783        _for_each_inner_classified_interrupt!(([direct_bindable 4] 28));
784        _for_each_inner_classified_interrupt!(([direct_bindable 5] 29));
785        _for_each_inner_classified_interrupt!(([direct_bindable 6] 30));
786        _for_each_inner_classified_interrupt!(([direct_bindable 7] 31));
787        _for_each_inner_classified_interrupt!(([vector 0] 16));
788        _for_each_inner_classified_interrupt!(([vector 1] 17));
789        _for_each_inner_classified_interrupt!(([vector 2] 18));
790        _for_each_inner_classified_interrupt!(([vector 3] 19));
791        _for_each_inner_classified_interrupt!(([vector 4] 20));
792        _for_each_inner_classified_interrupt!(([vector 5] 21));
793        _for_each_inner_classified_interrupt!(([vector 6] 22));
794        _for_each_inner_classified_interrupt!(([vector 7] 23));
795        _for_each_inner_classified_interrupt!(([reserved 0] 1));
796        _for_each_inner_classified_interrupt!(([reserved 1] 2));
797        _for_each_inner_classified_interrupt!(([reserved 2] 3));
798        _for_each_inner_classified_interrupt!(([reserved 3] 4));
799        _for_each_inner_classified_interrupt!(([reserved 4] 5));
800        _for_each_inner_classified_interrupt!(([reserved 5] 6));
801        _for_each_inner_classified_interrupt!(([reserved 6] 7));
802        _for_each_inner_classified_interrupt!(([reserved 7] 8));
803        _for_each_inner_classified_interrupt!(([reserved 8] 9));
804        _for_each_inner_classified_interrupt!(([reserved 9] 10));
805        _for_each_inner_classified_interrupt!(([reserved 10] 11));
806        _for_each_inner_classified_interrupt!(([reserved 11] 12));
807        _for_each_inner_classified_interrupt!(([reserved 12] 13));
808        _for_each_inner_classified_interrupt!(([reserved 13] 14));
809        _for_each_inner_classified_interrupt!(([reserved 14] 15));
810        _for_each_inner_classified_interrupt!((direct_bindable([direct_bindable 0] 24),
811        ([direct_bindable 1] 25), ([direct_bindable 2] 26), ([direct_bindable 3] 27),
812        ([direct_bindable 4] 28), ([direct_bindable 5] 29), ([direct_bindable 6] 30),
813        ([direct_bindable 7] 31))); _for_each_inner_classified_interrupt!((vector([vector
814        0] 16), ([vector 1] 17), ([vector 2] 18), ([vector 3] 19), ([vector 4] 20),
815        ([vector 5] 21), ([vector 6] 22), ([vector 7] 23)));
816        _for_each_inner_classified_interrupt!((reserved([reserved 0] 1), ([reserved 1]
817        2), ([reserved 2] 3), ([reserved 3] 4), ([reserved 4] 5), ([reserved 5] 6),
818        ([reserved 6] 7), ([reserved 7] 8), ([reserved 8] 9), ([reserved 9] 10),
819        ([reserved 10] 11), ([reserved 11] 12), ([reserved 12] 13), ([reserved 13] 14),
820        ([reserved 14] 15)));
821    };
822}
823#[macro_export]
824#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
825macro_rules! for_each_interrupt_priority {
826    ($($pattern:tt => $code:tt;)*) => {
827        macro_rules! _for_each_inner_interrupt_priority { $(($pattern) => $code;)*
828        ($other : tt) => {} } _for_each_inner_interrupt_priority!((0, 1, Priority1,
829        Level1)); _for_each_inner_interrupt_priority!((1, 2, Priority2, Level2));
830        _for_each_inner_interrupt_priority!((2, 3, Priority3, Level3));
831        _for_each_inner_interrupt_priority!((3, 4, Priority4, Level4));
832        _for_each_inner_interrupt_priority!((4, 5, Priority5, Level5));
833        _for_each_inner_interrupt_priority!((5, 6, Priority6, Level6));
834        _for_each_inner_interrupt_priority!((6, 7, Priority7, Level7));
835        _for_each_inner_interrupt_priority!((7, 8, Priority8, Level8));
836        _for_each_inner_interrupt_priority!((all(0, 1, Priority1, Level1), (1, 2,
837        Priority2, Level2), (2, 3, Priority3, Level3), (3, 4, Priority4, Level4), (4, 5,
838        Priority5, Level5), (5, 6, Priority6, Level6), (6, 7, Priority7, Level7), (7, 8,
839        Priority8, Level8)));
840    };
841}
842#[macro_export]
843#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
844macro_rules! for_each_sw_interrupt {
845    ($($pattern:tt => $code:tt;)*) => {
846        macro_rules! _for_each_inner_sw_interrupt { $(($pattern) => $code;)* ($other :
847        tt) => {} } _for_each_inner_sw_interrupt!((0, FROM_CPU_INTR0,
848        software_interrupt0)); _for_each_inner_sw_interrupt!((1, FROM_CPU_INTR1,
849        software_interrupt1)); _for_each_inner_sw_interrupt!((2, FROM_CPU_INTR2,
850        software_interrupt2)); _for_each_inner_sw_interrupt!((3, FROM_CPU_INTR3,
851        software_interrupt3)); _for_each_inner_sw_interrupt!((all(0, FROM_CPU_INTR0,
852        software_interrupt0), (1, FROM_CPU_INTR1, software_interrupt1), (2,
853        FROM_CPU_INTR2, software_interrupt2), (3, FROM_CPU_INTR3, software_interrupt3)));
854    };
855}
856#[macro_export]
857/// ESP-HAL must provide implementation for the following functions:
858/// ```rust, no_run
859/// // XTAL_CLK
860///
861/// fn configure_xtal_clk_impl(
862///     _clocks: &mut ClockTree,
863///     _old_config: Option<XtalClkConfig>,
864///     _new_config: XtalClkConfig,
865/// ) {
866///     todo!()
867/// }
868///
869/// // RC_FAST_CLK
870///
871/// fn enable_rc_fast_clk_impl(_clocks: &mut ClockTree, _en: bool) {
872///     todo!()
873/// }
874///
875/// // PLL_CLK
876///
877/// fn enable_pll_clk_impl(_clocks: &mut ClockTree, _en: bool) {
878///     todo!()
879/// }
880///
881/// // XTAL32K_CLK
882///
883/// fn enable_xtal32k_clk_impl(_clocks: &mut ClockTree, _en: bool) {
884///     todo!()
885/// }
886///
887/// // OSC_SLOW_CLK
888///
889/// fn enable_osc_slow_clk_impl(_clocks: &mut ClockTree, _en: bool) {
890///     todo!()
891/// }
892///
893/// // RC_SLOW_CLK
894///
895/// fn enable_rc_slow_clk_impl(_clocks: &mut ClockTree, _en: bool) {
896///     todo!()
897/// }
898///
899/// // PLL_F20M
900///
901/// fn enable_pll_f20m_impl(_clocks: &mut ClockTree, _en: bool) {
902///     todo!()
903/// }
904///
905/// // PLL_F40M
906///
907/// fn enable_pll_f40m_impl(_clocks: &mut ClockTree, _en: bool) {
908///     todo!()
909/// }
910///
911/// // PLL_F48M
912///
913/// fn enable_pll_f48m_impl(_clocks: &mut ClockTree, _en: bool) {
914///     todo!()
915/// }
916///
917/// // PLL_F60M
918///
919/// fn enable_pll_f60m_impl(_clocks: &mut ClockTree, _en: bool) {
920///     todo!()
921/// }
922///
923/// // PLL_F80M
924///
925/// fn enable_pll_f80m_impl(_clocks: &mut ClockTree, _en: bool) {
926///     todo!()
927/// }
928///
929/// // PLL_F120M
930///
931/// fn enable_pll_f120m_impl(_clocks: &mut ClockTree, _en: bool) {
932///     todo!()
933/// }
934///
935/// // PLL_F160M
936///
937/// fn enable_pll_f160m_impl(_clocks: &mut ClockTree, _en: bool) {
938///     todo!()
939/// }
940///
941/// // HP_ROOT_CLK
942///
943/// fn enable_hp_root_clk_impl(_clocks: &mut ClockTree, _en: bool) {
944///     todo!()
945/// }
946///
947/// fn configure_hp_root_clk_impl(
948///     _clocks: &mut ClockTree,
949///     _old_config: Option<HpRootClkConfig>,
950///     _new_config: HpRootClkConfig,
951/// ) {
952///     todo!()
953/// }
954///
955/// // CPU_CLK
956///
957/// fn enable_cpu_clk_impl(_clocks: &mut ClockTree, _en: bool) {
958///     todo!()
959/// }
960///
961/// fn configure_cpu_clk_impl(
962///     _clocks: &mut ClockTree,
963///     _old_config: Option<CpuClkConfig>,
964///     _new_config: CpuClkConfig,
965/// ) {
966///     todo!()
967/// }
968///
969/// // AHB_CLK
970///
971/// fn enable_ahb_clk_impl(_clocks: &mut ClockTree, _en: bool) {
972///     todo!()
973/// }
974///
975/// fn configure_ahb_clk_impl(
976///     _clocks: &mut ClockTree,
977///     _old_config: Option<AhbClkConfig>,
978///     _new_config: AhbClkConfig,
979/// ) {
980///     todo!()
981/// }
982///
983/// // APB_CLK
984///
985/// fn enable_apb_clk_impl(_clocks: &mut ClockTree, _en: bool) {
986///     todo!()
987/// }
988///
989/// fn configure_apb_clk_impl(
990///     _clocks: &mut ClockTree,
991///     _old_config: Option<ApbClkConfig>,
992///     _new_config: ApbClkConfig,
993/// ) {
994///     todo!()
995/// }
996///
997/// // XTAL_D2_CLK
998///
999/// fn enable_xtal_d2_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1000///     todo!()
1001/// }
1002///
1003/// // LP_FAST_CLK
1004///
1005/// fn enable_lp_fast_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1006///     todo!()
1007/// }
1008///
1009/// fn configure_lp_fast_clk_impl(
1010///     _clocks: &mut ClockTree,
1011///     _old_config: Option<LpFastClkConfig>,
1012///     _new_config: LpFastClkConfig,
1013/// ) {
1014///     todo!()
1015/// }
1016///
1017/// // LP_SLOW_CLK
1018///
1019/// fn enable_lp_slow_clk_impl(_clocks: &mut ClockTree, _en: bool) {
1020///     todo!()
1021/// }
1022///
1023/// fn configure_lp_slow_clk_impl(
1024///     _clocks: &mut ClockTree,
1025///     _old_config: Option<LpSlowClkConfig>,
1026///     _new_config: LpSlowClkConfig,
1027/// ) {
1028///     todo!()
1029/// }
1030///
1031/// // TIMG_CALIBRATION_CLOCK
1032///
1033/// fn enable_timg_calibration_clock_impl(_clocks: &mut ClockTree, _en: bool) {
1034///     todo!()
1035/// }
1036///
1037/// fn configure_timg_calibration_clock_impl(
1038///     _clocks: &mut ClockTree,
1039///     _old_config: Option<TimgCalibrationClockConfig>,
1040///     _new_config: TimgCalibrationClockConfig,
1041/// ) {
1042///     todo!()
1043/// }
1044///
1045/// impl I2cInstance {
1046///     // I2C_FUNCTION_CLOCK
1047///
1048///     fn enable_function_clock_impl(self, _clocks: &mut ClockTree, _en: bool) {
1049///         todo!()
1050///     }
1051///
1052///     fn configure_function_clock_impl(
1053///         self,
1054///         _clocks: &mut ClockTree,
1055///         _old_config: Option<I2cFunctionClockConfig>,
1056///         _new_config: I2cFunctionClockConfig,
1057///     ) {
1058///         todo!()
1059///     }
1060/// }
1061/// impl SpiInstance {
1062///     // SPI_FUNCTION_CLOCK
1063///
1064///     fn enable_function_clock_impl(self, _clocks: &mut ClockTree, _en: bool) {
1065///         todo!()
1066///     }
1067///
1068///     fn configure_function_clock_impl(
1069///         self,
1070///         _clocks: &mut ClockTree,
1071///         _old_config: Option<SpiFunctionClockConfig>,
1072///         _new_config: SpiFunctionClockConfig,
1073///     ) {
1074///         todo!()
1075///     }
1076/// }
1077/// impl TimgInstance {
1078///     // TIMG_FUNCTION_CLOCK
1079///
1080///     fn enable_function_clock_impl(self, _clocks: &mut ClockTree, _en: bool) {
1081///         todo!()
1082///     }
1083///
1084///     fn configure_function_clock_impl(
1085///         self,
1086///         _clocks: &mut ClockTree,
1087///         _old_config: Option<TimgFunctionClockConfig>,
1088///         _new_config: TimgFunctionClockConfig,
1089///     ) {
1090///         todo!()
1091///     }
1092///
1093///     // TIMG_WDT_CLOCK
1094///
1095///     fn enable_wdt_clock_impl(self, _clocks: &mut ClockTree, _en: bool) {
1096///         todo!()
1097///     }
1098///
1099///     fn configure_wdt_clock_impl(
1100///         self,
1101///         _clocks: &mut ClockTree,
1102///         _old_config: Option<TimgWdtClockConfig>,
1103///         _new_config: TimgWdtClockConfig,
1104///     ) {
1105///         todo!()
1106///     }
1107/// }
1108/// impl UartInstance {
1109///     // UART_FUNCTION_CLOCK
1110///
1111///     fn enable_function_clock_impl(self, _clocks: &mut ClockTree, _en: bool) {
1112///         todo!()
1113///     }
1114///
1115///     fn configure_function_clock_impl(
1116///         self,
1117///         _clocks: &mut ClockTree,
1118///         _old_config: Option<UartFunctionClockConfig>,
1119///         _new_config: UartFunctionClockConfig,
1120///     ) {
1121///         todo!()
1122///     }
1123///
1124///     // UART_BAUD_RATE_GENERATOR
1125///
1126///     fn enable_baud_rate_generator_impl(self, _clocks: &mut ClockTree, _en: bool) {
1127///         todo!()
1128///     }
1129///
1130///     fn configure_baud_rate_generator_impl(
1131///         self,
1132///         _clocks: &mut ClockTree,
1133///         _old_config: Option<UartBaudRateGeneratorConfig>,
1134///         _new_config: UartBaudRateGeneratorConfig,
1135///     ) {
1136///         todo!()
1137///     }
1138/// }
1139/// ```
1140macro_rules! define_clock_tree_types {
1141    () => {
1142        #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1143        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1144        pub enum I2cInstance {
1145            I2c0 = 0,
1146        }
1147        #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1148        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1149        pub enum SpiInstance {
1150            Spi2 = 0,
1151        }
1152        #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1153        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1154        pub enum TimgInstance {
1155            Timg0 = 0,
1156            Timg1 = 1,
1157        }
1158        #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1159        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1160        pub enum UartInstance {
1161            Uart0 = 0,
1162            Uart1 = 1,
1163            Uart2 = 2,
1164        }
1165        /// Selects the output frequency of `XTAL_CLK`.
1166        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1167        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1168        pub enum XtalClkConfig {
1169            /// 40 MHz
1170            _40,
1171        }
1172        impl XtalClkConfig {
1173            pub fn value(&self) -> u32 {
1174                match self {
1175                    XtalClkConfig::_40 => 40000000,
1176                }
1177            }
1178        }
1179        /// The list of clock signals that the `HP_ROOT_CLK` multiplexer can output.
1180        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1181        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1182        pub enum HpRootClkConfig {
1183            /// Selects `XTAL_CLK`.
1184            Xtal,
1185            /// Selects `RC_FAST_CLK`.
1186            RcFast,
1187            /// Selects `PLL_F160M`.
1188            PllF160m,
1189        }
1190        /// Configures the `CPU_CLK` clock node.
1191        ///
1192        /// The output is calculated as `OUTPUT = HP_ROOT_CLK / (divisor + 1)`.
1193        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1194        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1195        pub struct CpuClkConfig {
1196            divisor: u32,
1197        }
1198        impl CpuClkConfig {
1199            /// Creates a new configuration for the CPU_CLK clock node.
1200            ///
1201            /// ## Panics
1202            ///
1203            /// Panics if the divisor value is outside the
1204            /// valid range (0 ..= 255).
1205            pub const fn new(divisor: u32) -> Self {
1206                ::core::assert!(
1207                    divisor <= 255,
1208                    "`CPU_CLK` divisor must be between 0 and 255 (inclusive)."
1209                );
1210                Self { divisor }
1211            }
1212            pub(crate) fn divisor(self) -> u32 {
1213                self.divisor as u32
1214            }
1215        }
1216        /// Configures the `AHB_CLK` clock node.
1217        ///
1218        /// The output is calculated as `OUTPUT = HP_ROOT_CLK / (divisor + 1)`.
1219        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1220        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1221        pub struct AhbClkConfig {
1222            divisor: u32,
1223        }
1224        impl AhbClkConfig {
1225            /// Creates a new configuration for the AHB_CLK clock node.
1226            ///
1227            /// ## Panics
1228            ///
1229            /// Panics if the divisor value is outside the
1230            /// valid range (0 ..= 255).
1231            pub const fn new(divisor: u32) -> Self {
1232                ::core::assert!(
1233                    divisor <= 255,
1234                    "`AHB_CLK` divisor must be between 0 and 255 (inclusive)."
1235                );
1236                Self { divisor }
1237            }
1238            pub(crate) fn divisor(self) -> u32 {
1239                self.divisor as u32
1240            }
1241        }
1242        /// Configures the `APB_CLK` clock node.
1243        ///
1244        /// The output is calculated as `OUTPUT = AHB_CLK / (divisor + 1)`.
1245        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1246        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1247        pub struct ApbClkConfig {
1248            divisor: u32,
1249        }
1250        impl ApbClkConfig {
1251            /// Creates a new configuration for the APB_CLK clock node.
1252            ///
1253            /// ## Panics
1254            ///
1255            /// Panics if the divisor value is outside the
1256            /// valid range (0 ..= 255).
1257            pub const fn new(divisor: u32) -> Self {
1258                ::core::assert!(
1259                    divisor <= 255,
1260                    "`APB_CLK` divisor must be between 0 and 255 (inclusive)."
1261                );
1262                Self { divisor }
1263            }
1264            pub(crate) fn divisor(self) -> u32 {
1265                self.divisor as u32
1266            }
1267        }
1268        /// The list of clock signals that the `LP_FAST_CLK` multiplexer can output.
1269        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1270        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1271        pub enum LpFastClkConfig {
1272            /// Selects `RC_FAST_CLK`.
1273            RcFast,
1274            /// Selects `XTAL_D2_CLK`.
1275            XtalD2,
1276            /// Selects `XTAL_CLK`.
1277            Xtal,
1278        }
1279        /// The list of clock signals that the `LP_SLOW_CLK` multiplexer can output.
1280        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1281        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1282        pub enum LpSlowClkConfig {
1283            /// Selects `RC_SLOW_CLK`.
1284            RcSlow,
1285            /// Selects `XTAL32K_CLK`.
1286            Xtal32k,
1287            /// Selects `OSC_SLOW_CLK`.
1288            OscSlow,
1289        }
1290        /// The list of clock signals that the `TIMG_CALIBRATION_CLOCK` multiplexer can output.
1291        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1292        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1293        pub enum TimgCalibrationClockConfig {
1294            /// Selects `OSC_SLOW_CLK`.
1295            OscSlowClk,
1296            /// Selects `RC_SLOW_CLK`.
1297            RcSlowClk,
1298            /// Selects `RC_FAST_CLK`.
1299            RcFastDivClk,
1300            /// Selects `XTAL32K_CLK`.
1301            Xtal32kClk,
1302        }
1303        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1304        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1305        pub enum I2cFunctionClockSclk {
1306            #[default]
1307            /// Selects `XTAL_CLK`.
1308            Xtal,
1309            /// Selects `RC_FAST_CLK`.
1310            RcFast,
1311        }
1312        /// Configures the `I2C0_FUNCTION_CLOCK` clock node.
1313        ///
1314        /// The output is calculated as `OUTPUT = sclk / (div_num + 1)`.
1315        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1316        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1317        pub struct I2cFunctionClockConfig {
1318            sclk: I2cFunctionClockSclk,
1319            div_num: u32,
1320        }
1321        impl I2cFunctionClockConfig {
1322            /// Creates a new configuration for the FUNCTION_CLOCK clock node.
1323            ///
1324            /// ## Panics
1325            ///
1326            /// Panics if the div_num value is outside the
1327            /// valid range (0 ..= 255).
1328            pub const fn new(sclk: I2cFunctionClockSclk, div_num: u32) -> Self {
1329                ::core::assert!(
1330                    div_num <= 255,
1331                    "`I2C0_FUNCTION_CLOCK` div_num must be between 0 and 255 (inclusive)."
1332                );
1333                Self { sclk, div_num }
1334            }
1335            pub(crate) fn sclk(self) -> I2cFunctionClockSclk {
1336                self.sclk
1337            }
1338            pub(crate) fn div_num(self) -> u32 {
1339                self.div_num as u32
1340            }
1341        }
1342        /// The list of clock signals that the `SPI2_FUNCTION_CLOCK` multiplexer can output.
1343        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1344        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1345        pub enum SpiFunctionClockConfig {
1346            #[default]
1347            /// Selects `XTAL_CLK`.
1348            Xtal,
1349            /// Selects `PLL_F160M`.
1350            PllF160m,
1351            /// Selects `RC_FAST_CLK`.
1352            RcFast,
1353        }
1354        /// The list of clock signals that the `TIMG0_FUNCTION_CLOCK` multiplexer can output.
1355        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1356        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1357        pub enum TimgFunctionClockConfig {
1358            #[default]
1359            /// Selects `XTAL_CLK`.
1360            XtalClk,
1361            /// Selects `RC_FAST_CLK`.
1362            RcFastClk,
1363            /// Selects `PLL_F80M`.
1364            PllF80m,
1365        }
1366        /// The list of clock signals that the `TIMG0_WDT_CLOCK` multiplexer can output.
1367        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1368        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1369        pub enum TimgWdtClockConfig {
1370            #[default]
1371            /// Selects `XTAL_CLK`.
1372            XtalClk,
1373            /// Selects `RC_FAST_CLK`.
1374            RcFastClk,
1375            /// Selects `PLL_F80M`.
1376            PllF80m,
1377        }
1378        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1379        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1380        pub enum UartFunctionClockSclk {
1381            #[default]
1382            /// Selects `XTAL_CLK`.
1383            Xtal,
1384            /// Selects `PLL_F80M`.
1385            PllF80m,
1386            /// Selects `RC_FAST_CLK`.
1387            RcFast,
1388        }
1389        /// Configures the `UART0_FUNCTION_CLOCK` clock node.
1390        ///
1391        /// The output is calculated as `OUTPUT = sclk / (div_num + 1)`.
1392        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1393        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1394        pub struct UartFunctionClockConfig {
1395            sclk: UartFunctionClockSclk,
1396            div_num: u32,
1397        }
1398        impl UartFunctionClockConfig {
1399            /// Creates a new configuration for the FUNCTION_CLOCK clock node.
1400            ///
1401            /// ## Panics
1402            ///
1403            /// Panics if the div_num value is outside the
1404            /// valid range (0 ..= 255).
1405            pub const fn new(sclk: UartFunctionClockSclk, div_num: u32) -> Self {
1406                ::core::assert!(
1407                    div_num <= 255,
1408                    "`UART0_FUNCTION_CLOCK` div_num must be between 0 and 255 (inclusive)."
1409                );
1410                Self { sclk, div_num }
1411            }
1412            pub(crate) fn sclk(self) -> UartFunctionClockSclk {
1413                self.sclk
1414            }
1415            pub(crate) fn div_num(self) -> u32 {
1416                self.div_num as u32
1417            }
1418        }
1419        /// Configures the `UART0_BAUD_RATE_GENERATOR` clock node.
1420        ///
1421        /// The output is calculated as `OUTPUT = (FUNCTION_CLOCK * 16) / (integral * 16 +
1422        /// fractional)`.
1423        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1424        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1425        pub struct UartBaudRateGeneratorConfig {
1426            fractional: u32,
1427            integral: u32,
1428        }
1429        impl UartBaudRateGeneratorConfig {
1430            /// Creates a new configuration for the BAUD_RATE_GENERATOR clock node.
1431            ///
1432            /// ## Panics
1433            ///
1434            /// Panics if the fractional value is outside the
1435            /// valid range (0 ..= 15).
1436            ///
1437            /// Panics if the integral value is outside the
1438            /// valid range (0 ..= 4095).
1439            pub const fn new(fractional: u32, integral: u32) -> Self {
1440                ::core::assert!(
1441                    fractional <= 15,
1442                    "`UART0_BAUD_RATE_GENERATOR` fractional must be between 0 and 15 (inclusive)."
1443                );
1444                ::core::assert!(
1445                    integral <= 4095,
1446                    "`UART0_BAUD_RATE_GENERATOR` integral must be between 0 and 4095 (inclusive)."
1447                );
1448                Self {
1449                    fractional,
1450                    integral,
1451                }
1452            }
1453            pub(crate) fn fractional(self) -> u32 {
1454                self.fractional as u32
1455            }
1456            pub(crate) fn integral(self) -> u32 {
1457                self.integral as u32
1458            }
1459        }
1460        /// Represents the device's clock tree.
1461        pub struct ClockTree {
1462            xtal_clk: Option<XtalClkConfig>,
1463            hp_root_clk: Option<HpRootClkConfig>,
1464            cpu_clk: Option<CpuClkConfig>,
1465            ahb_clk: Option<AhbClkConfig>,
1466            apb_clk: Option<ApbClkConfig>,
1467            lp_fast_clk: Option<LpFastClkConfig>,
1468            lp_slow_clk: Option<LpSlowClkConfig>,
1469            timg_calibration_clock: Option<TimgCalibrationClockConfig>,
1470            i2c_function_clock: [Option<I2cFunctionClockConfig>; 1],
1471            spi_function_clock: [Option<SpiFunctionClockConfig>; 1],
1472            timg_function_clock: [Option<TimgFunctionClockConfig>; 2],
1473            timg_wdt_clock: [Option<TimgWdtClockConfig>; 2],
1474            uart_function_clock: [Option<UartFunctionClockConfig>; 3],
1475            uart_baud_rate_generator: [Option<UartBaudRateGeneratorConfig>; 3],
1476            rc_fast_clk_refcount: u32,
1477            pll_clk_refcount: u32,
1478            xtal32k_clk_refcount: u32,
1479            osc_slow_clk_refcount: u32,
1480            rc_slow_clk_refcount: u32,
1481            pll_f20m_refcount: u32,
1482            pll_f40m_refcount: u32,
1483            pll_f48m_refcount: u32,
1484            pll_f60m_refcount: u32,
1485            pll_f80m_refcount: u32,
1486            pll_f120m_refcount: u32,
1487            pll_f160m_refcount: u32,
1488            hp_root_clk_refcount: u32,
1489            cpu_clk_refcount: u32,
1490            apb_clk_refcount: u32,
1491            lp_fast_clk_refcount: u32,
1492            lp_slow_clk_refcount: u32,
1493            timg_calibration_clock_refcount: u32,
1494            i2c_function_clock_refcount: [u32; 1],
1495            spi_function_clock_refcount: [u32; 1],
1496            timg_function_clock_refcount: [u32; 2],
1497            timg_wdt_clock_refcount: [u32; 2],
1498            uart_function_clock_refcount: [u32; 3],
1499            uart_baud_rate_generator_refcount: [u32; 3],
1500        }
1501        impl ClockTree {
1502            /// Locks the clock tree for exclusive access.
1503            pub fn with<R>(f: impl FnOnce(&mut ClockTree) -> R) -> R {
1504                CLOCK_TREE.with(f)
1505            }
1506            /// Returns the current configuration of the XTAL_CLK clock tree node
1507            pub fn xtal_clk(&self) -> Option<XtalClkConfig> {
1508                self.xtal_clk
1509            }
1510            /// Returns the current configuration of the HP_ROOT_CLK clock tree node
1511            pub fn hp_root_clk(&self) -> Option<HpRootClkConfig> {
1512                self.hp_root_clk
1513            }
1514            /// Returns the current configuration of the CPU_CLK clock tree node
1515            pub fn cpu_clk(&self) -> Option<CpuClkConfig> {
1516                self.cpu_clk
1517            }
1518            /// Returns the current configuration of the AHB_CLK clock tree node
1519            pub fn ahb_clk(&self) -> Option<AhbClkConfig> {
1520                self.ahb_clk
1521            }
1522            /// Returns the current configuration of the APB_CLK clock tree node
1523            pub fn apb_clk(&self) -> Option<ApbClkConfig> {
1524                self.apb_clk
1525            }
1526            /// Returns the current configuration of the LP_FAST_CLK clock tree node
1527            pub fn lp_fast_clk(&self) -> Option<LpFastClkConfig> {
1528                self.lp_fast_clk
1529            }
1530            /// Returns the current configuration of the LP_SLOW_CLK clock tree node
1531            pub fn lp_slow_clk(&self) -> Option<LpSlowClkConfig> {
1532                self.lp_slow_clk
1533            }
1534            /// Returns the current configuration of the TIMG_CALIBRATION_CLOCK clock tree node
1535            pub fn timg_calibration_clock(&self) -> Option<TimgCalibrationClockConfig> {
1536                self.timg_calibration_clock
1537            }
1538            /// Returns the current configuration of the I2C0_FUNCTION_CLOCK clock tree node
1539            pub fn i2c0_function_clock(&self) -> Option<I2cFunctionClockConfig> {
1540                self.i2c_function_clock[I2cInstance::I2c0 as usize]
1541            }
1542            /// Returns the current configuration of the SPI2_FUNCTION_CLOCK clock tree node
1543            pub fn spi2_function_clock(&self) -> Option<SpiFunctionClockConfig> {
1544                self.spi_function_clock[SpiInstance::Spi2 as usize]
1545            }
1546            /// Returns the current configuration of the TIMG0_FUNCTION_CLOCK clock tree node
1547            pub fn timg0_function_clock(&self) -> Option<TimgFunctionClockConfig> {
1548                self.timg_function_clock[TimgInstance::Timg0 as usize]
1549            }
1550            /// Returns the current configuration of the TIMG0_WDT_CLOCK clock tree node
1551            pub fn timg0_wdt_clock(&self) -> Option<TimgWdtClockConfig> {
1552                self.timg_wdt_clock[TimgInstance::Timg0 as usize]
1553            }
1554            /// Returns the current configuration of the TIMG1_FUNCTION_CLOCK clock tree node
1555            pub fn timg1_function_clock(&self) -> Option<TimgFunctionClockConfig> {
1556                self.timg_function_clock[TimgInstance::Timg1 as usize]
1557            }
1558            /// Returns the current configuration of the TIMG1_WDT_CLOCK clock tree node
1559            pub fn timg1_wdt_clock(&self) -> Option<TimgWdtClockConfig> {
1560                self.timg_wdt_clock[TimgInstance::Timg1 as usize]
1561            }
1562            /// Returns the current configuration of the UART0_FUNCTION_CLOCK clock tree node
1563            pub fn uart0_function_clock(&self) -> Option<UartFunctionClockConfig> {
1564                self.uart_function_clock[UartInstance::Uart0 as usize]
1565            }
1566            /// Returns the current configuration of the UART0_BAUD_RATE_GENERATOR clock tree node
1567            pub fn uart0_baud_rate_generator(&self) -> Option<UartBaudRateGeneratorConfig> {
1568                self.uart_baud_rate_generator[UartInstance::Uart0 as usize]
1569            }
1570            /// Returns the current configuration of the UART1_FUNCTION_CLOCK clock tree node
1571            pub fn uart1_function_clock(&self) -> Option<UartFunctionClockConfig> {
1572                self.uart_function_clock[UartInstance::Uart1 as usize]
1573            }
1574            /// Returns the current configuration of the UART1_BAUD_RATE_GENERATOR clock tree node
1575            pub fn uart1_baud_rate_generator(&self) -> Option<UartBaudRateGeneratorConfig> {
1576                self.uart_baud_rate_generator[UartInstance::Uart1 as usize]
1577            }
1578            /// Returns the current configuration of the UART2_FUNCTION_CLOCK clock tree node
1579            pub fn uart2_function_clock(&self) -> Option<UartFunctionClockConfig> {
1580                self.uart_function_clock[UartInstance::Uart2 as usize]
1581            }
1582            /// Returns the current configuration of the UART2_BAUD_RATE_GENERATOR clock tree node
1583            pub fn uart2_baud_rate_generator(&self) -> Option<UartBaudRateGeneratorConfig> {
1584                self.uart_baud_rate_generator[UartInstance::Uart2 as usize]
1585            }
1586        }
1587        static CLOCK_TREE: ::esp_sync::NonReentrantMutex<ClockTree> =
1588            ::esp_sync::NonReentrantMutex::new(ClockTree {
1589                xtal_clk: None,
1590                hp_root_clk: None,
1591                cpu_clk: None,
1592                ahb_clk: None,
1593                apb_clk: None,
1594                lp_fast_clk: None,
1595                lp_slow_clk: None,
1596                timg_calibration_clock: None,
1597                i2c_function_clock: [None; 1],
1598                spi_function_clock: [None; 1],
1599                timg_function_clock: [None; 2],
1600                timg_wdt_clock: [None; 2],
1601                uart_function_clock: [None; 3],
1602                uart_baud_rate_generator: [None; 3],
1603                rc_fast_clk_refcount: 0,
1604                pll_clk_refcount: 0,
1605                xtal32k_clk_refcount: 0,
1606                osc_slow_clk_refcount: 0,
1607                rc_slow_clk_refcount: 0,
1608                pll_f20m_refcount: 0,
1609                pll_f40m_refcount: 0,
1610                pll_f48m_refcount: 0,
1611                pll_f60m_refcount: 0,
1612                pll_f80m_refcount: 0,
1613                pll_f120m_refcount: 0,
1614                pll_f160m_refcount: 0,
1615                hp_root_clk_refcount: 0,
1616                cpu_clk_refcount: 0,
1617                apb_clk_refcount: 0,
1618                lp_fast_clk_refcount: 0,
1619                lp_slow_clk_refcount: 0,
1620                timg_calibration_clock_refcount: 0,
1621                i2c_function_clock_refcount: [0; 1],
1622                spi_function_clock_refcount: [0; 1],
1623                timg_function_clock_refcount: [0; 2],
1624                timg_wdt_clock_refcount: [0; 2],
1625                uart_function_clock_refcount: [0; 3],
1626                uart_baud_rate_generator_refcount: [0; 3],
1627            });
1628        static XTAL_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1629            ::core::sync::atomic::AtomicU32::new(0);
1630        static HP_ROOT_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1631            ::core::sync::atomic::AtomicU32::new(0);
1632        static CPU_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1633            ::core::sync::atomic::AtomicU32::new(0);
1634        static AHB_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1635            ::core::sync::atomic::AtomicU32::new(0);
1636        static APB_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1637            ::core::sync::atomic::AtomicU32::new(0);
1638        static LP_FAST_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1639            ::core::sync::atomic::AtomicU32::new(0);
1640        static LP_SLOW_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1641            ::core::sync::atomic::AtomicU32::new(0);
1642        static TIMG_CALIBRATION_CLOCK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1643            ::core::sync::atomic::AtomicU32::new(0);
1644        static I2C_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
1645            [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
1646        static SPI_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
1647            [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
1648        static TIMG_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 2] =
1649            [const { ::core::sync::atomic::AtomicU32::new(0) }; 2];
1650        static TIMG_WDT_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 2] =
1651            [const { ::core::sync::atomic::AtomicU32::new(0) }; 2];
1652        static UART_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 3] =
1653            [const { ::core::sync::atomic::AtomicU32::new(0) }; 3];
1654        static UART_BAUD_RATE_GENERATOR_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 3] =
1655            [const { ::core::sync::atomic::AtomicU32::new(0) }; 3];
1656        pub fn configure_xtal_clk(clocks: &mut ClockTree, config: XtalClkConfig) {
1657            let old_config = clocks.xtal_clk.replace(config);
1658            refresh_xtal_clk_downstream(clocks);
1659            configure_xtal_clk_impl(clocks, old_config, config);
1660        }
1661        pub fn xtal_clk_config(clocks: &mut ClockTree) -> Option<XtalClkConfig> {
1662            clocks.xtal_clk
1663        }
1664        fn request_xtal_clk(_clocks: &mut ClockTree) {}
1665        fn release_xtal_clk(_clocks: &mut ClockTree) {}
1666        #[allow(unused_variables)]
1667        pub fn xtal_clk_config_frequency(clocks: &mut ClockTree, config: XtalClkConfig) -> u32 {
1668            config.value()
1669        }
1670        pub fn xtal_clk_frequency() -> u32 {
1671            XTAL_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
1672        }
1673        pub fn request_rc_fast_clk(clocks: &mut ClockTree) {
1674            trace!("Requesting RC_FAST_CLK");
1675            if increment_reference_count(&mut clocks.rc_fast_clk_refcount) {
1676                trace!("Enabling RC_FAST_CLK");
1677                enable_rc_fast_clk_impl(clocks, true);
1678            }
1679        }
1680        pub fn release_rc_fast_clk(clocks: &mut ClockTree) {
1681            trace!("Releasing RC_FAST_CLK");
1682            if decrement_reference_count(&mut clocks.rc_fast_clk_refcount) {
1683                trace!("Disabling RC_FAST_CLK");
1684                enable_rc_fast_clk_impl(clocks, false);
1685            }
1686        }
1687        pub fn rc_fast_clk_frequency() -> u32 {
1688            17500000
1689        }
1690        pub fn request_pll_clk(clocks: &mut ClockTree) {
1691            trace!("Requesting PLL_CLK");
1692            if increment_reference_count(&mut clocks.pll_clk_refcount) {
1693                trace!("Enabling PLL_CLK");
1694                request_xtal_clk(clocks);
1695                enable_pll_clk_impl(clocks, true);
1696            }
1697        }
1698        pub fn release_pll_clk(clocks: &mut ClockTree) {
1699            trace!("Releasing PLL_CLK");
1700            if decrement_reference_count(&mut clocks.pll_clk_refcount) {
1701                trace!("Disabling PLL_CLK");
1702                enable_pll_clk_impl(clocks, false);
1703                release_xtal_clk(clocks);
1704            }
1705        }
1706        pub fn pll_clk_frequency() -> u32 {
1707            480000000
1708        }
1709        pub fn pll_clk_source_frequency() -> u32 {
1710            xtal_clk_frequency()
1711        }
1712        pub fn request_xtal32k_clk(clocks: &mut ClockTree) {
1713            trace!("Requesting XTAL32K_CLK");
1714            if increment_reference_count(&mut clocks.xtal32k_clk_refcount) {
1715                trace!("Enabling XTAL32K_CLK");
1716                enable_xtal32k_clk_impl(clocks, true);
1717            }
1718        }
1719        pub fn release_xtal32k_clk(clocks: &mut ClockTree) {
1720            trace!("Releasing XTAL32K_CLK");
1721            if decrement_reference_count(&mut clocks.xtal32k_clk_refcount) {
1722                trace!("Disabling XTAL32K_CLK");
1723                enable_xtal32k_clk_impl(clocks, false);
1724            }
1725        }
1726        pub fn xtal32k_clk_frequency() -> u32 {
1727            32768
1728        }
1729        pub fn request_osc_slow_clk(clocks: &mut ClockTree) {
1730            trace!("Requesting OSC_SLOW_CLK");
1731            if increment_reference_count(&mut clocks.osc_slow_clk_refcount) {
1732                trace!("Enabling OSC_SLOW_CLK");
1733                enable_osc_slow_clk_impl(clocks, true);
1734            }
1735        }
1736        pub fn release_osc_slow_clk(clocks: &mut ClockTree) {
1737            trace!("Releasing OSC_SLOW_CLK");
1738            if decrement_reference_count(&mut clocks.osc_slow_clk_refcount) {
1739                trace!("Disabling OSC_SLOW_CLK");
1740                enable_osc_slow_clk_impl(clocks, false);
1741            }
1742        }
1743        pub fn osc_slow_clk_frequency() -> u32 {
1744            32768
1745        }
1746        pub fn request_rc_slow_clk(clocks: &mut ClockTree) {
1747            trace!("Requesting RC_SLOW_CLK");
1748            if increment_reference_count(&mut clocks.rc_slow_clk_refcount) {
1749                trace!("Enabling RC_SLOW_CLK");
1750                enable_rc_slow_clk_impl(clocks, true);
1751            }
1752        }
1753        pub fn release_rc_slow_clk(clocks: &mut ClockTree) {
1754            trace!("Releasing RC_SLOW_CLK");
1755            if decrement_reference_count(&mut clocks.rc_slow_clk_refcount) {
1756                trace!("Disabling RC_SLOW_CLK");
1757                enable_rc_slow_clk_impl(clocks, false);
1758            }
1759        }
1760        pub fn rc_slow_clk_frequency() -> u32 {
1761            136000
1762        }
1763        pub fn request_pll_f20m(clocks: &mut ClockTree) {
1764            trace!("Requesting PLL_F20M");
1765            if increment_reference_count(&mut clocks.pll_f20m_refcount) {
1766                trace!("Enabling PLL_F20M");
1767                request_pll_clk(clocks);
1768                enable_pll_f20m_impl(clocks, true);
1769            }
1770        }
1771        pub fn release_pll_f20m(clocks: &mut ClockTree) {
1772            trace!("Releasing PLL_F20M");
1773            if decrement_reference_count(&mut clocks.pll_f20m_refcount) {
1774                trace!("Disabling PLL_F20M");
1775                enable_pll_f20m_impl(clocks, false);
1776                release_pll_clk(clocks);
1777            }
1778        }
1779        pub fn pll_f20m_frequency() -> u32 {
1780            (pll_clk_frequency() / 24)
1781        }
1782        pub fn pll_f20m_source_frequency() -> u32 {
1783            pll_clk_frequency()
1784        }
1785        pub fn request_pll_f40m(clocks: &mut ClockTree) {
1786            trace!("Requesting PLL_F40M");
1787            if increment_reference_count(&mut clocks.pll_f40m_refcount) {
1788                trace!("Enabling PLL_F40M");
1789                request_pll_clk(clocks);
1790                enable_pll_f40m_impl(clocks, true);
1791            }
1792        }
1793        pub fn release_pll_f40m(clocks: &mut ClockTree) {
1794            trace!("Releasing PLL_F40M");
1795            if decrement_reference_count(&mut clocks.pll_f40m_refcount) {
1796                trace!("Disabling PLL_F40M");
1797                enable_pll_f40m_impl(clocks, false);
1798                release_pll_clk(clocks);
1799            }
1800        }
1801        pub fn pll_f40m_frequency() -> u32 {
1802            (pll_clk_frequency() / 12)
1803        }
1804        pub fn pll_f40m_source_frequency() -> u32 {
1805            pll_clk_frequency()
1806        }
1807        pub fn request_pll_f48m(clocks: &mut ClockTree) {
1808            trace!("Requesting PLL_F48M");
1809            if increment_reference_count(&mut clocks.pll_f48m_refcount) {
1810                trace!("Enabling PLL_F48M");
1811                request_pll_clk(clocks);
1812                enable_pll_f48m_impl(clocks, true);
1813            }
1814        }
1815        pub fn release_pll_f48m(clocks: &mut ClockTree) {
1816            trace!("Releasing PLL_F48M");
1817            if decrement_reference_count(&mut clocks.pll_f48m_refcount) {
1818                trace!("Disabling PLL_F48M");
1819                enable_pll_f48m_impl(clocks, false);
1820                release_pll_clk(clocks);
1821            }
1822        }
1823        pub fn pll_f48m_frequency() -> u32 {
1824            (pll_clk_frequency() / 10)
1825        }
1826        pub fn pll_f48m_source_frequency() -> u32 {
1827            pll_clk_frequency()
1828        }
1829        pub fn request_pll_f60m(clocks: &mut ClockTree) {
1830            trace!("Requesting PLL_F60M");
1831            if increment_reference_count(&mut clocks.pll_f60m_refcount) {
1832                trace!("Enabling PLL_F60M");
1833                request_pll_clk(clocks);
1834                enable_pll_f60m_impl(clocks, true);
1835            }
1836        }
1837        pub fn release_pll_f60m(clocks: &mut ClockTree) {
1838            trace!("Releasing PLL_F60M");
1839            if decrement_reference_count(&mut clocks.pll_f60m_refcount) {
1840                trace!("Disabling PLL_F60M");
1841                enable_pll_f60m_impl(clocks, false);
1842                release_pll_clk(clocks);
1843            }
1844        }
1845        pub fn pll_f60m_frequency() -> u32 {
1846            (pll_clk_frequency() / 8)
1847        }
1848        pub fn pll_f60m_source_frequency() -> u32 {
1849            pll_clk_frequency()
1850        }
1851        pub fn request_pll_f80m(clocks: &mut ClockTree) {
1852            trace!("Requesting PLL_F80M");
1853            if increment_reference_count(&mut clocks.pll_f80m_refcount) {
1854                trace!("Enabling PLL_F80M");
1855                request_pll_clk(clocks);
1856                enable_pll_f80m_impl(clocks, true);
1857            }
1858        }
1859        pub fn release_pll_f80m(clocks: &mut ClockTree) {
1860            trace!("Releasing PLL_F80M");
1861            if decrement_reference_count(&mut clocks.pll_f80m_refcount) {
1862                trace!("Disabling PLL_F80M");
1863                enable_pll_f80m_impl(clocks, false);
1864                release_pll_clk(clocks);
1865            }
1866        }
1867        pub fn pll_f80m_frequency() -> u32 {
1868            (pll_clk_frequency() / 6)
1869        }
1870        pub fn pll_f80m_source_frequency() -> u32 {
1871            pll_clk_frequency()
1872        }
1873        pub fn request_pll_f120m(clocks: &mut ClockTree) {
1874            trace!("Requesting PLL_F120M");
1875            if increment_reference_count(&mut clocks.pll_f120m_refcount) {
1876                trace!("Enabling PLL_F120M");
1877                request_pll_clk(clocks);
1878                enable_pll_f120m_impl(clocks, true);
1879            }
1880        }
1881        pub fn release_pll_f120m(clocks: &mut ClockTree) {
1882            trace!("Releasing PLL_F120M");
1883            if decrement_reference_count(&mut clocks.pll_f120m_refcount) {
1884                trace!("Disabling PLL_F120M");
1885                enable_pll_f120m_impl(clocks, false);
1886                release_pll_clk(clocks);
1887            }
1888        }
1889        pub fn pll_f120m_frequency() -> u32 {
1890            (pll_clk_frequency() / 4)
1891        }
1892        pub fn pll_f120m_source_frequency() -> u32 {
1893            pll_clk_frequency()
1894        }
1895        pub fn request_pll_f160m(clocks: &mut ClockTree) {
1896            trace!("Requesting PLL_F160M");
1897            if increment_reference_count(&mut clocks.pll_f160m_refcount) {
1898                trace!("Enabling PLL_F160M");
1899                request_pll_clk(clocks);
1900                enable_pll_f160m_impl(clocks, true);
1901            }
1902        }
1903        pub fn release_pll_f160m(clocks: &mut ClockTree) {
1904            trace!("Releasing PLL_F160M");
1905            if decrement_reference_count(&mut clocks.pll_f160m_refcount) {
1906                trace!("Disabling PLL_F160M");
1907                enable_pll_f160m_impl(clocks, false);
1908                release_pll_clk(clocks);
1909            }
1910        }
1911        pub fn pll_f160m_frequency() -> u32 {
1912            (pll_clk_frequency() / 3)
1913        }
1914        pub fn pll_f160m_source_frequency() -> u32 {
1915            pll_clk_frequency()
1916        }
1917        pub fn configure_hp_root_clk(clocks: &mut ClockTree, new_selector: HpRootClkConfig) {
1918            let old_selector = clocks.hp_root_clk.replace(new_selector);
1919            refresh_hp_root_clk_downstream(clocks);
1920            if clocks.hp_root_clk_refcount > 0 {
1921                match new_selector {
1922                    HpRootClkConfig::Xtal => request_xtal_clk(clocks),
1923                    HpRootClkConfig::RcFast => request_rc_fast_clk(clocks),
1924                    HpRootClkConfig::PllF160m => request_pll_f160m(clocks),
1925                }
1926                configure_hp_root_clk_impl(clocks, old_selector, new_selector);
1927                if let Some(old_selector) = old_selector {
1928                    match old_selector {
1929                        HpRootClkConfig::Xtal => release_xtal_clk(clocks),
1930                        HpRootClkConfig::RcFast => release_rc_fast_clk(clocks),
1931                        HpRootClkConfig::PllF160m => release_pll_f160m(clocks),
1932                    }
1933                }
1934            } else {
1935                configure_hp_root_clk_impl(clocks, old_selector, new_selector);
1936            }
1937        }
1938        pub fn hp_root_clk_config(clocks: &mut ClockTree) -> Option<HpRootClkConfig> {
1939            clocks.hp_root_clk
1940        }
1941        pub fn request_hp_root_clk(clocks: &mut ClockTree) {
1942            trace!("Requesting HP_ROOT_CLK");
1943            if increment_reference_count(&mut clocks.hp_root_clk_refcount) {
1944                trace!("Enabling HP_ROOT_CLK");
1945                match unwrap!(clocks.hp_root_clk) {
1946                    HpRootClkConfig::Xtal => request_xtal_clk(clocks),
1947                    HpRootClkConfig::RcFast => request_rc_fast_clk(clocks),
1948                    HpRootClkConfig::PllF160m => request_pll_f160m(clocks),
1949                }
1950                enable_hp_root_clk_impl(clocks, true);
1951            }
1952        }
1953        pub fn release_hp_root_clk(clocks: &mut ClockTree) {
1954            trace!("Releasing HP_ROOT_CLK");
1955            if decrement_reference_count(&mut clocks.hp_root_clk_refcount) {
1956                trace!("Disabling HP_ROOT_CLK");
1957                enable_hp_root_clk_impl(clocks, false);
1958                match unwrap!(clocks.hp_root_clk) {
1959                    HpRootClkConfig::Xtal => release_xtal_clk(clocks),
1960                    HpRootClkConfig::RcFast => release_rc_fast_clk(clocks),
1961                    HpRootClkConfig::PllF160m => release_pll_f160m(clocks),
1962                }
1963            }
1964        }
1965        #[allow(unused_variables)]
1966        pub fn hp_root_clk_config_frequency(
1967            clocks: &mut ClockTree,
1968            config: HpRootClkConfig,
1969        ) -> u32 {
1970            match config {
1971                HpRootClkConfig::Xtal => xtal_clk_frequency(),
1972                HpRootClkConfig::RcFast => rc_fast_clk_frequency(),
1973                HpRootClkConfig::PllF160m => pll_f160m_frequency(),
1974            }
1975        }
1976        pub fn hp_root_clk_frequency() -> u32 {
1977            HP_ROOT_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
1978        }
1979        pub fn hp_root_clk_source_frequency(source: HpRootClkConfig) -> u32 {
1980            match source {
1981                HpRootClkConfig::Xtal => xtal_clk_frequency(),
1982                HpRootClkConfig::RcFast => rc_fast_clk_frequency(),
1983                HpRootClkConfig::PllF160m => pll_f160m_frequency(),
1984            }
1985        }
1986        pub fn configure_cpu_clk(clocks: &mut ClockTree, config: CpuClkConfig) {
1987            let old_config = clocks.cpu_clk.replace(config);
1988            refresh_cpu_clk_downstream(clocks);
1989            configure_cpu_clk_impl(clocks, old_config, config);
1990        }
1991        pub fn cpu_clk_config(clocks: &mut ClockTree) -> Option<CpuClkConfig> {
1992            clocks.cpu_clk
1993        }
1994        pub fn request_cpu_clk(clocks: &mut ClockTree) {
1995            trace!("Requesting CPU_CLK");
1996            if increment_reference_count(&mut clocks.cpu_clk_refcount) {
1997                trace!("Enabling CPU_CLK");
1998                request_hp_root_clk(clocks);
1999                enable_cpu_clk_impl(clocks, true);
2000            }
2001        }
2002        pub fn release_cpu_clk(clocks: &mut ClockTree) {
2003            trace!("Releasing CPU_CLK");
2004            if decrement_reference_count(&mut clocks.cpu_clk_refcount) {
2005                trace!("Disabling CPU_CLK");
2006                enable_cpu_clk_impl(clocks, false);
2007                release_hp_root_clk(clocks);
2008            }
2009        }
2010        #[allow(unused_variables)]
2011        pub fn cpu_clk_config_frequency(clocks: &mut ClockTree, config: CpuClkConfig) -> u32 {
2012            (hp_root_clk_frequency() / (config.divisor() + 1))
2013        }
2014        pub fn cpu_clk_frequency() -> u32 {
2015            CPU_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2016        }
2017        pub fn cpu_clk_source_frequency() -> u32 {
2018            hp_root_clk_frequency()
2019        }
2020        pub fn configure_ahb_clk(clocks: &mut ClockTree, config: AhbClkConfig) {
2021            let old_config = clocks.ahb_clk.replace(config);
2022            refresh_ahb_clk_downstream(clocks);
2023            configure_ahb_clk_impl(clocks, old_config, config);
2024        }
2025        pub fn ahb_clk_config(clocks: &mut ClockTree) -> Option<AhbClkConfig> {
2026            clocks.ahb_clk
2027        }
2028        pub fn request_ahb_clk(clocks: &mut ClockTree) {
2029            trace!("Requesting AHB_CLK");
2030            trace!("Enabling AHB_CLK");
2031            request_hp_root_clk(clocks);
2032            enable_ahb_clk_impl(clocks, true);
2033        }
2034        pub fn release_ahb_clk(clocks: &mut ClockTree) {
2035            trace!("Releasing AHB_CLK");
2036            trace!("Disabling AHB_CLK");
2037            enable_ahb_clk_impl(clocks, false);
2038            release_hp_root_clk(clocks);
2039        }
2040        #[allow(unused_variables)]
2041        pub fn ahb_clk_config_frequency(clocks: &mut ClockTree, config: AhbClkConfig) -> u32 {
2042            (hp_root_clk_frequency() / (config.divisor() + 1))
2043        }
2044        pub fn ahb_clk_frequency() -> u32 {
2045            AHB_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2046        }
2047        pub fn ahb_clk_source_frequency() -> u32 {
2048            hp_root_clk_frequency()
2049        }
2050        pub fn configure_apb_clk(clocks: &mut ClockTree, config: ApbClkConfig) {
2051            let old_config = clocks.apb_clk.replace(config);
2052            refresh_apb_clk_downstream(clocks);
2053            configure_apb_clk_impl(clocks, old_config, config);
2054        }
2055        pub fn apb_clk_config(clocks: &mut ClockTree) -> Option<ApbClkConfig> {
2056            clocks.apb_clk
2057        }
2058        pub fn request_apb_clk(clocks: &mut ClockTree) {
2059            trace!("Requesting APB_CLK");
2060            if increment_reference_count(&mut clocks.apb_clk_refcount) {
2061                trace!("Enabling APB_CLK");
2062                request_ahb_clk(clocks);
2063                enable_apb_clk_impl(clocks, true);
2064            }
2065        }
2066        pub fn release_apb_clk(clocks: &mut ClockTree) {
2067            trace!("Releasing APB_CLK");
2068            if decrement_reference_count(&mut clocks.apb_clk_refcount) {
2069                trace!("Disabling APB_CLK");
2070                enable_apb_clk_impl(clocks, false);
2071                release_ahb_clk(clocks);
2072            }
2073        }
2074        #[allow(unused_variables)]
2075        pub fn apb_clk_config_frequency(clocks: &mut ClockTree, config: ApbClkConfig) -> u32 {
2076            (ahb_clk_frequency() / (config.divisor() + 1))
2077        }
2078        pub fn apb_clk_frequency() -> u32 {
2079            APB_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2080        }
2081        pub fn apb_clk_source_frequency() -> u32 {
2082            ahb_clk_frequency()
2083        }
2084        pub fn request_xtal_d2_clk(clocks: &mut ClockTree) {
2085            trace!("Requesting XTAL_D2_CLK");
2086            trace!("Enabling XTAL_D2_CLK");
2087            request_xtal_clk(clocks);
2088            enable_xtal_d2_clk_impl(clocks, true);
2089        }
2090        pub fn release_xtal_d2_clk(clocks: &mut ClockTree) {
2091            trace!("Releasing XTAL_D2_CLK");
2092            trace!("Disabling XTAL_D2_CLK");
2093            enable_xtal_d2_clk_impl(clocks, false);
2094            release_xtal_clk(clocks);
2095        }
2096        pub fn xtal_d2_clk_frequency() -> u32 {
2097            (xtal_clk_frequency() / 2)
2098        }
2099        pub fn xtal_d2_clk_source_frequency() -> u32 {
2100            xtal_clk_frequency()
2101        }
2102        pub fn configure_lp_fast_clk(clocks: &mut ClockTree, new_selector: LpFastClkConfig) {
2103            let old_selector = clocks.lp_fast_clk.replace(new_selector);
2104            refresh_lp_fast_clk_downstream(clocks);
2105            if clocks.lp_fast_clk_refcount > 0 {
2106                match new_selector {
2107                    LpFastClkConfig::RcFast => request_rc_fast_clk(clocks),
2108                    LpFastClkConfig::XtalD2 => request_xtal_d2_clk(clocks),
2109                    LpFastClkConfig::Xtal => request_xtal_clk(clocks),
2110                }
2111                configure_lp_fast_clk_impl(clocks, old_selector, new_selector);
2112                if let Some(old_selector) = old_selector {
2113                    match old_selector {
2114                        LpFastClkConfig::RcFast => release_rc_fast_clk(clocks),
2115                        LpFastClkConfig::XtalD2 => release_xtal_d2_clk(clocks),
2116                        LpFastClkConfig::Xtal => release_xtal_clk(clocks),
2117                    }
2118                }
2119            } else {
2120                configure_lp_fast_clk_impl(clocks, old_selector, new_selector);
2121            }
2122        }
2123        pub fn lp_fast_clk_config(clocks: &mut ClockTree) -> Option<LpFastClkConfig> {
2124            clocks.lp_fast_clk
2125        }
2126        pub fn request_lp_fast_clk(clocks: &mut ClockTree) {
2127            trace!("Requesting LP_FAST_CLK");
2128            if increment_reference_count(&mut clocks.lp_fast_clk_refcount) {
2129                trace!("Enabling LP_FAST_CLK");
2130                match unwrap!(clocks.lp_fast_clk) {
2131                    LpFastClkConfig::RcFast => request_rc_fast_clk(clocks),
2132                    LpFastClkConfig::XtalD2 => request_xtal_d2_clk(clocks),
2133                    LpFastClkConfig::Xtal => request_xtal_clk(clocks),
2134                }
2135                enable_lp_fast_clk_impl(clocks, true);
2136            }
2137        }
2138        pub fn release_lp_fast_clk(clocks: &mut ClockTree) {
2139            trace!("Releasing LP_FAST_CLK");
2140            if decrement_reference_count(&mut clocks.lp_fast_clk_refcount) {
2141                trace!("Disabling LP_FAST_CLK");
2142                enable_lp_fast_clk_impl(clocks, false);
2143                match unwrap!(clocks.lp_fast_clk) {
2144                    LpFastClkConfig::RcFast => release_rc_fast_clk(clocks),
2145                    LpFastClkConfig::XtalD2 => release_xtal_d2_clk(clocks),
2146                    LpFastClkConfig::Xtal => release_xtal_clk(clocks),
2147                }
2148            }
2149        }
2150        #[allow(unused_variables)]
2151        pub fn lp_fast_clk_config_frequency(
2152            clocks: &mut ClockTree,
2153            config: LpFastClkConfig,
2154        ) -> u32 {
2155            match config {
2156                LpFastClkConfig::RcFast => rc_fast_clk_frequency(),
2157                LpFastClkConfig::XtalD2 => xtal_d2_clk_frequency(),
2158                LpFastClkConfig::Xtal => xtal_clk_frequency(),
2159            }
2160        }
2161        pub fn lp_fast_clk_frequency() -> u32 {
2162            LP_FAST_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2163        }
2164        pub fn lp_fast_clk_source_frequency(source: LpFastClkConfig) -> u32 {
2165            match source {
2166                LpFastClkConfig::RcFast => rc_fast_clk_frequency(),
2167                LpFastClkConfig::XtalD2 => xtal_d2_clk_frequency(),
2168                LpFastClkConfig::Xtal => xtal_clk_frequency(),
2169            }
2170        }
2171        pub fn configure_lp_slow_clk(clocks: &mut ClockTree, new_selector: LpSlowClkConfig) {
2172            let old_selector = clocks.lp_slow_clk.replace(new_selector);
2173            refresh_lp_slow_clk_downstream(clocks);
2174            if clocks.lp_slow_clk_refcount > 0 {
2175                match new_selector {
2176                    LpSlowClkConfig::RcSlow => request_rc_slow_clk(clocks),
2177                    LpSlowClkConfig::Xtal32k => request_xtal32k_clk(clocks),
2178                    LpSlowClkConfig::OscSlow => request_osc_slow_clk(clocks),
2179                }
2180                configure_lp_slow_clk_impl(clocks, old_selector, new_selector);
2181                if let Some(old_selector) = old_selector {
2182                    match old_selector {
2183                        LpSlowClkConfig::RcSlow => release_rc_slow_clk(clocks),
2184                        LpSlowClkConfig::Xtal32k => release_xtal32k_clk(clocks),
2185                        LpSlowClkConfig::OscSlow => release_osc_slow_clk(clocks),
2186                    }
2187                }
2188            } else {
2189                configure_lp_slow_clk_impl(clocks, old_selector, new_selector);
2190            }
2191        }
2192        pub fn lp_slow_clk_config(clocks: &mut ClockTree) -> Option<LpSlowClkConfig> {
2193            clocks.lp_slow_clk
2194        }
2195        pub fn request_lp_slow_clk(clocks: &mut ClockTree) {
2196            trace!("Requesting LP_SLOW_CLK");
2197            if increment_reference_count(&mut clocks.lp_slow_clk_refcount) {
2198                trace!("Enabling LP_SLOW_CLK");
2199                match unwrap!(clocks.lp_slow_clk) {
2200                    LpSlowClkConfig::RcSlow => request_rc_slow_clk(clocks),
2201                    LpSlowClkConfig::Xtal32k => request_xtal32k_clk(clocks),
2202                    LpSlowClkConfig::OscSlow => request_osc_slow_clk(clocks),
2203                }
2204                enable_lp_slow_clk_impl(clocks, true);
2205            }
2206        }
2207        pub fn release_lp_slow_clk(clocks: &mut ClockTree) {
2208            trace!("Releasing LP_SLOW_CLK");
2209            if decrement_reference_count(&mut clocks.lp_slow_clk_refcount) {
2210                trace!("Disabling LP_SLOW_CLK");
2211                enable_lp_slow_clk_impl(clocks, false);
2212                match unwrap!(clocks.lp_slow_clk) {
2213                    LpSlowClkConfig::RcSlow => release_rc_slow_clk(clocks),
2214                    LpSlowClkConfig::Xtal32k => release_xtal32k_clk(clocks),
2215                    LpSlowClkConfig::OscSlow => release_osc_slow_clk(clocks),
2216                }
2217            }
2218        }
2219        #[allow(unused_variables)]
2220        pub fn lp_slow_clk_config_frequency(
2221            clocks: &mut ClockTree,
2222            config: LpSlowClkConfig,
2223        ) -> u32 {
2224            match config {
2225                LpSlowClkConfig::RcSlow => rc_slow_clk_frequency(),
2226                LpSlowClkConfig::Xtal32k => xtal32k_clk_frequency(),
2227                LpSlowClkConfig::OscSlow => osc_slow_clk_frequency(),
2228            }
2229        }
2230        pub fn lp_slow_clk_frequency() -> u32 {
2231            LP_SLOW_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2232        }
2233        pub fn lp_slow_clk_source_frequency(source: LpSlowClkConfig) -> u32 {
2234            match source {
2235                LpSlowClkConfig::RcSlow => rc_slow_clk_frequency(),
2236                LpSlowClkConfig::Xtal32k => xtal32k_clk_frequency(),
2237                LpSlowClkConfig::OscSlow => osc_slow_clk_frequency(),
2238            }
2239        }
2240        pub fn configure_timg_calibration_clock(
2241            clocks: &mut ClockTree,
2242            new_selector: TimgCalibrationClockConfig,
2243        ) {
2244            let old_selector = clocks.timg_calibration_clock.replace(new_selector);
2245            refresh_timg_calibration_clock_downstream(clocks);
2246            if clocks.timg_calibration_clock_refcount > 0 {
2247                match new_selector {
2248                    TimgCalibrationClockConfig::OscSlowClk => request_osc_slow_clk(clocks),
2249                    TimgCalibrationClockConfig::RcSlowClk => request_rc_slow_clk(clocks),
2250                    TimgCalibrationClockConfig::RcFastDivClk => request_rc_fast_clk(clocks),
2251                    TimgCalibrationClockConfig::Xtal32kClk => request_xtal32k_clk(clocks),
2252                }
2253                configure_timg_calibration_clock_impl(clocks, old_selector, new_selector);
2254                if let Some(old_selector) = old_selector {
2255                    match old_selector {
2256                        TimgCalibrationClockConfig::OscSlowClk => release_osc_slow_clk(clocks),
2257                        TimgCalibrationClockConfig::RcSlowClk => release_rc_slow_clk(clocks),
2258                        TimgCalibrationClockConfig::RcFastDivClk => release_rc_fast_clk(clocks),
2259                        TimgCalibrationClockConfig::Xtal32kClk => release_xtal32k_clk(clocks),
2260                    }
2261                }
2262            } else {
2263                configure_timg_calibration_clock_impl(clocks, old_selector, new_selector);
2264            }
2265        }
2266        pub fn timg_calibration_clock_config(
2267            clocks: &mut ClockTree,
2268        ) -> Option<TimgCalibrationClockConfig> {
2269            clocks.timg_calibration_clock
2270        }
2271        pub fn request_timg_calibration_clock(clocks: &mut ClockTree) {
2272            trace!("Requesting TIMG_CALIBRATION_CLOCK");
2273            if increment_reference_count(&mut clocks.timg_calibration_clock_refcount) {
2274                trace!("Enabling TIMG_CALIBRATION_CLOCK");
2275                crate::rtc_cntl::WakeLock::acquire();
2276                match unwrap!(clocks.timg_calibration_clock) {
2277                    TimgCalibrationClockConfig::OscSlowClk => request_osc_slow_clk(clocks),
2278                    TimgCalibrationClockConfig::RcSlowClk => request_rc_slow_clk(clocks),
2279                    TimgCalibrationClockConfig::RcFastDivClk => request_rc_fast_clk(clocks),
2280                    TimgCalibrationClockConfig::Xtal32kClk => request_xtal32k_clk(clocks),
2281                }
2282                enable_timg_calibration_clock_impl(clocks, true);
2283            }
2284        }
2285        pub fn release_timg_calibration_clock(clocks: &mut ClockTree) {
2286            trace!("Releasing TIMG_CALIBRATION_CLOCK");
2287            if decrement_reference_count(&mut clocks.timg_calibration_clock_refcount) {
2288                trace!("Disabling TIMG_CALIBRATION_CLOCK");
2289                crate::rtc_cntl::WakeLock::release();
2290                enable_timg_calibration_clock_impl(clocks, false);
2291                match unwrap!(clocks.timg_calibration_clock) {
2292                    TimgCalibrationClockConfig::OscSlowClk => release_osc_slow_clk(clocks),
2293                    TimgCalibrationClockConfig::RcSlowClk => release_rc_slow_clk(clocks),
2294                    TimgCalibrationClockConfig::RcFastDivClk => release_rc_fast_clk(clocks),
2295                    TimgCalibrationClockConfig::Xtal32kClk => release_xtal32k_clk(clocks),
2296                }
2297            }
2298        }
2299        #[allow(unused_variables)]
2300        pub fn timg_calibration_clock_config_frequency(
2301            clocks: &mut ClockTree,
2302            config: TimgCalibrationClockConfig,
2303        ) -> u32 {
2304            match config {
2305                TimgCalibrationClockConfig::OscSlowClk => osc_slow_clk_frequency(),
2306                TimgCalibrationClockConfig::RcSlowClk => rc_slow_clk_frequency(),
2307                TimgCalibrationClockConfig::RcFastDivClk => rc_fast_clk_frequency(),
2308                TimgCalibrationClockConfig::Xtal32kClk => xtal32k_clk_frequency(),
2309            }
2310        }
2311        pub fn timg_calibration_clock_frequency() -> u32 {
2312            TIMG_CALIBRATION_CLOCK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2313        }
2314        pub fn timg_calibration_clock_source_frequency(source: TimgCalibrationClockConfig) -> u32 {
2315            match source {
2316                TimgCalibrationClockConfig::OscSlowClk => osc_slow_clk_frequency(),
2317                TimgCalibrationClockConfig::RcSlowClk => rc_slow_clk_frequency(),
2318                TimgCalibrationClockConfig::RcFastDivClk => rc_fast_clk_frequency(),
2319                TimgCalibrationClockConfig::Xtal32kClk => xtal32k_clk_frequency(),
2320            }
2321        }
2322        impl I2cInstance {
2323            pub fn configure_function_clock(
2324                self,
2325                clocks: &mut ClockTree,
2326                config: I2cFunctionClockConfig,
2327            ) {
2328                let old_config = clocks.i2c_function_clock[self as usize].replace(config);
2329                refresh_i2c_function_clock_downstream(clocks, self);
2330                if clocks.i2c_function_clock_refcount[self as usize] > 0 {
2331                    match config.sclk {
2332                        I2cFunctionClockSclk::Xtal => request_xtal_clk(clocks),
2333                        I2cFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
2334                    }
2335                    self.configure_function_clock_impl(clocks, old_config, config);
2336                    if let Some(old_config) = old_config {
2337                        match old_config.sclk {
2338                            I2cFunctionClockSclk::Xtal => release_xtal_clk(clocks),
2339                            I2cFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
2340                        }
2341                    }
2342                } else {
2343                    self.configure_function_clock_impl(clocks, old_config, config);
2344                }
2345            }
2346            pub fn function_clock_config(
2347                self,
2348                clocks: &mut ClockTree,
2349            ) -> Option<I2cFunctionClockConfig> {
2350                clocks.i2c_function_clock[self as usize]
2351            }
2352            pub fn request_function_clock(self, clocks: &mut ClockTree) {
2353                trace!("Requesting {:?}::FUNCTION_CLOCK", self);
2354                if increment_reference_count(&mut clocks.i2c_function_clock_refcount[self as usize])
2355                {
2356                    trace!("Enabling {:?}::FUNCTION_CLOCK", self);
2357                    match unwrap!(clocks.i2c_function_clock[self as usize]).sclk {
2358                        I2cFunctionClockSclk::Xtal => request_xtal_clk(clocks),
2359                        I2cFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
2360                    }
2361                    self.enable_function_clock_impl(clocks, true);
2362                }
2363            }
2364            pub fn release_function_clock(self, clocks: &mut ClockTree) {
2365                trace!("Releasing {:?}::FUNCTION_CLOCK", self);
2366                if decrement_reference_count(&mut clocks.i2c_function_clock_refcount[self as usize])
2367                {
2368                    trace!("Disabling {:?}::FUNCTION_CLOCK", self);
2369                    self.enable_function_clock_impl(clocks, false);
2370                    match unwrap!(clocks.i2c_function_clock[self as usize]).sclk {
2371                        I2cFunctionClockSclk::Xtal => release_xtal_clk(clocks),
2372                        I2cFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
2373                    }
2374                }
2375            }
2376            #[allow(unused_variables)]
2377            pub fn function_clock_config_frequency(
2378                clocks: &mut ClockTree,
2379                config: I2cFunctionClockConfig,
2380            ) -> u32 {
2381                (match config.sclk {
2382                    I2cFunctionClockSclk::Xtal => xtal_clk_frequency(),
2383                    I2cFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
2384                } / (config.div_num() + 1))
2385            }
2386            pub fn function_clock_frequency(self) -> u32 {
2387                I2C_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
2388                    .load(::core::sync::atomic::Ordering::Acquire)
2389            }
2390            pub fn function_clock_source_frequency(sclk: I2cFunctionClockSclk) -> u32 {
2391                match sclk {
2392                    I2cFunctionClockSclk::Xtal => xtal_clk_frequency(),
2393                    I2cFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
2394                }
2395            }
2396        }
2397        impl SpiInstance {
2398            pub fn configure_function_clock(
2399                self,
2400                clocks: &mut ClockTree,
2401                new_selector: SpiFunctionClockConfig,
2402            ) {
2403                let old_selector = clocks.spi_function_clock[self as usize].replace(new_selector);
2404                refresh_spi_function_clock_downstream(clocks, self);
2405                if clocks.spi_function_clock_refcount[self as usize] > 0 {
2406                    match new_selector {
2407                        SpiFunctionClockConfig::Xtal => request_xtal_clk(clocks),
2408                        SpiFunctionClockConfig::PllF160m => request_pll_f160m(clocks),
2409                        SpiFunctionClockConfig::RcFast => request_rc_fast_clk(clocks),
2410                    }
2411                    self.configure_function_clock_impl(clocks, old_selector, new_selector);
2412                    if let Some(old_selector) = old_selector {
2413                        match old_selector {
2414                            SpiFunctionClockConfig::Xtal => release_xtal_clk(clocks),
2415                            SpiFunctionClockConfig::PllF160m => release_pll_f160m(clocks),
2416                            SpiFunctionClockConfig::RcFast => release_rc_fast_clk(clocks),
2417                        }
2418                    }
2419                } else {
2420                    self.configure_function_clock_impl(clocks, old_selector, new_selector);
2421                }
2422            }
2423            pub fn function_clock_config(
2424                self,
2425                clocks: &mut ClockTree,
2426            ) -> Option<SpiFunctionClockConfig> {
2427                clocks.spi_function_clock[self as usize]
2428            }
2429            pub fn request_function_clock(self, clocks: &mut ClockTree) {
2430                trace!("Requesting {:?}::FUNCTION_CLOCK", self);
2431                if increment_reference_count(&mut clocks.spi_function_clock_refcount[self as usize])
2432                {
2433                    trace!("Enabling {:?}::FUNCTION_CLOCK", self);
2434                    match unwrap!(clocks.spi_function_clock[self as usize]) {
2435                        SpiFunctionClockConfig::Xtal => request_xtal_clk(clocks),
2436                        SpiFunctionClockConfig::PllF160m => request_pll_f160m(clocks),
2437                        SpiFunctionClockConfig::RcFast => request_rc_fast_clk(clocks),
2438                    }
2439                    self.enable_function_clock_impl(clocks, true);
2440                }
2441            }
2442            pub fn release_function_clock(self, clocks: &mut ClockTree) {
2443                trace!("Releasing {:?}::FUNCTION_CLOCK", self);
2444                if decrement_reference_count(&mut clocks.spi_function_clock_refcount[self as usize])
2445                {
2446                    trace!("Disabling {:?}::FUNCTION_CLOCK", self);
2447                    self.enable_function_clock_impl(clocks, false);
2448                    match unwrap!(clocks.spi_function_clock[self as usize]) {
2449                        SpiFunctionClockConfig::Xtal => release_xtal_clk(clocks),
2450                        SpiFunctionClockConfig::PllF160m => release_pll_f160m(clocks),
2451                        SpiFunctionClockConfig::RcFast => release_rc_fast_clk(clocks),
2452                    }
2453                }
2454            }
2455            #[allow(unused_variables)]
2456            pub fn function_clock_config_frequency(
2457                clocks: &mut ClockTree,
2458                config: SpiFunctionClockConfig,
2459            ) -> u32 {
2460                match config {
2461                    SpiFunctionClockConfig::Xtal => xtal_clk_frequency(),
2462                    SpiFunctionClockConfig::PllF160m => pll_f160m_frequency(),
2463                    SpiFunctionClockConfig::RcFast => rc_fast_clk_frequency(),
2464                }
2465            }
2466            pub fn function_clock_frequency(self) -> u32 {
2467                SPI_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
2468                    .load(::core::sync::atomic::Ordering::Acquire)
2469            }
2470            pub fn function_clock_source_frequency(source: SpiFunctionClockConfig) -> u32 {
2471                match source {
2472                    SpiFunctionClockConfig::Xtal => xtal_clk_frequency(),
2473                    SpiFunctionClockConfig::PllF160m => pll_f160m_frequency(),
2474                    SpiFunctionClockConfig::RcFast => rc_fast_clk_frequency(),
2475                }
2476            }
2477        }
2478        impl TimgInstance {
2479            pub fn configure_function_clock(
2480                self,
2481                clocks: &mut ClockTree,
2482                new_selector: TimgFunctionClockConfig,
2483            ) {
2484                let old_selector = clocks.timg_function_clock[self as usize].replace(new_selector);
2485                refresh_timg_function_clock_downstream(clocks, self);
2486                if clocks.timg_function_clock_refcount[self as usize] > 0 {
2487                    match new_selector {
2488                        TimgFunctionClockConfig::XtalClk => request_xtal_clk(clocks),
2489                        TimgFunctionClockConfig::RcFastClk => request_rc_fast_clk(clocks),
2490                        TimgFunctionClockConfig::PllF80m => request_pll_f80m(clocks),
2491                    }
2492                    self.configure_function_clock_impl(clocks, old_selector, new_selector);
2493                    if let Some(old_selector) = old_selector {
2494                        match old_selector {
2495                            TimgFunctionClockConfig::XtalClk => release_xtal_clk(clocks),
2496                            TimgFunctionClockConfig::RcFastClk => release_rc_fast_clk(clocks),
2497                            TimgFunctionClockConfig::PllF80m => release_pll_f80m(clocks),
2498                        }
2499                    }
2500                } else {
2501                    self.configure_function_clock_impl(clocks, old_selector, new_selector);
2502                }
2503            }
2504            pub fn function_clock_config(
2505                self,
2506                clocks: &mut ClockTree,
2507            ) -> Option<TimgFunctionClockConfig> {
2508                clocks.timg_function_clock[self as usize]
2509            }
2510            pub fn request_function_clock(self, clocks: &mut ClockTree) {
2511                trace!("Requesting {:?}::FUNCTION_CLOCK", self);
2512                if increment_reference_count(
2513                    &mut clocks.timg_function_clock_refcount[self as usize],
2514                ) {
2515                    trace!("Enabling {:?}::FUNCTION_CLOCK", self);
2516                    match unwrap!(clocks.timg_function_clock[self as usize]) {
2517                        TimgFunctionClockConfig::XtalClk => request_xtal_clk(clocks),
2518                        TimgFunctionClockConfig::RcFastClk => request_rc_fast_clk(clocks),
2519                        TimgFunctionClockConfig::PllF80m => request_pll_f80m(clocks),
2520                    }
2521                    self.enable_function_clock_impl(clocks, true);
2522                }
2523            }
2524            pub fn release_function_clock(self, clocks: &mut ClockTree) {
2525                trace!("Releasing {:?}::FUNCTION_CLOCK", self);
2526                if decrement_reference_count(
2527                    &mut clocks.timg_function_clock_refcount[self as usize],
2528                ) {
2529                    trace!("Disabling {:?}::FUNCTION_CLOCK", self);
2530                    self.enable_function_clock_impl(clocks, false);
2531                    match unwrap!(clocks.timg_function_clock[self as usize]) {
2532                        TimgFunctionClockConfig::XtalClk => release_xtal_clk(clocks),
2533                        TimgFunctionClockConfig::RcFastClk => release_rc_fast_clk(clocks),
2534                        TimgFunctionClockConfig::PllF80m => release_pll_f80m(clocks),
2535                    }
2536                }
2537            }
2538            #[allow(unused_variables)]
2539            pub fn function_clock_config_frequency(
2540                clocks: &mut ClockTree,
2541                config: TimgFunctionClockConfig,
2542            ) -> u32 {
2543                match config {
2544                    TimgFunctionClockConfig::XtalClk => xtal_clk_frequency(),
2545                    TimgFunctionClockConfig::RcFastClk => rc_fast_clk_frequency(),
2546                    TimgFunctionClockConfig::PllF80m => pll_f80m_frequency(),
2547                }
2548            }
2549            pub fn function_clock_frequency(self) -> u32 {
2550                TIMG_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
2551                    .load(::core::sync::atomic::Ordering::Acquire)
2552            }
2553            pub fn function_clock_source_frequency(source: TimgFunctionClockConfig) -> u32 {
2554                match source {
2555                    TimgFunctionClockConfig::XtalClk => xtal_clk_frequency(),
2556                    TimgFunctionClockConfig::RcFastClk => rc_fast_clk_frequency(),
2557                    TimgFunctionClockConfig::PllF80m => pll_f80m_frequency(),
2558                }
2559            }
2560            pub fn configure_wdt_clock(
2561                self,
2562                clocks: &mut ClockTree,
2563                new_selector: TimgWdtClockConfig,
2564            ) {
2565                let old_selector = clocks.timg_wdt_clock[self as usize].replace(new_selector);
2566                refresh_timg_wdt_clock_downstream(clocks, self);
2567                if clocks.timg_wdt_clock_refcount[self as usize] > 0 {
2568                    match new_selector {
2569                        TimgWdtClockConfig::XtalClk => request_xtal_clk(clocks),
2570                        TimgWdtClockConfig::RcFastClk => request_rc_fast_clk(clocks),
2571                        TimgWdtClockConfig::PllF80m => request_pll_f80m(clocks),
2572                    }
2573                    self.configure_wdt_clock_impl(clocks, old_selector, new_selector);
2574                    if let Some(old_selector) = old_selector {
2575                        match old_selector {
2576                            TimgWdtClockConfig::XtalClk => release_xtal_clk(clocks),
2577                            TimgWdtClockConfig::RcFastClk => release_rc_fast_clk(clocks),
2578                            TimgWdtClockConfig::PllF80m => release_pll_f80m(clocks),
2579                        }
2580                    }
2581                } else {
2582                    self.configure_wdt_clock_impl(clocks, old_selector, new_selector);
2583                }
2584            }
2585            pub fn wdt_clock_config(self, clocks: &mut ClockTree) -> Option<TimgWdtClockConfig> {
2586                clocks.timg_wdt_clock[self as usize]
2587            }
2588            pub fn request_wdt_clock(self, clocks: &mut ClockTree) {
2589                trace!("Requesting {:?}::WDT_CLOCK", self);
2590                if increment_reference_count(&mut clocks.timg_wdt_clock_refcount[self as usize]) {
2591                    trace!("Enabling {:?}::WDT_CLOCK", self);
2592                    match unwrap!(clocks.timg_wdt_clock[self as usize]) {
2593                        TimgWdtClockConfig::XtalClk => request_xtal_clk(clocks),
2594                        TimgWdtClockConfig::RcFastClk => request_rc_fast_clk(clocks),
2595                        TimgWdtClockConfig::PllF80m => request_pll_f80m(clocks),
2596                    }
2597                    self.enable_wdt_clock_impl(clocks, true);
2598                }
2599            }
2600            pub fn release_wdt_clock(self, clocks: &mut ClockTree) {
2601                trace!("Releasing {:?}::WDT_CLOCK", self);
2602                if decrement_reference_count(&mut clocks.timg_wdt_clock_refcount[self as usize]) {
2603                    trace!("Disabling {:?}::WDT_CLOCK", self);
2604                    self.enable_wdt_clock_impl(clocks, false);
2605                    match unwrap!(clocks.timg_wdt_clock[self as usize]) {
2606                        TimgWdtClockConfig::XtalClk => release_xtal_clk(clocks),
2607                        TimgWdtClockConfig::RcFastClk => release_rc_fast_clk(clocks),
2608                        TimgWdtClockConfig::PllF80m => release_pll_f80m(clocks),
2609                    }
2610                }
2611            }
2612            #[allow(unused_variables)]
2613            pub fn wdt_clock_config_frequency(
2614                clocks: &mut ClockTree,
2615                config: TimgWdtClockConfig,
2616            ) -> u32 {
2617                match config {
2618                    TimgWdtClockConfig::XtalClk => xtal_clk_frequency(),
2619                    TimgWdtClockConfig::RcFastClk => rc_fast_clk_frequency(),
2620                    TimgWdtClockConfig::PllF80m => pll_f80m_frequency(),
2621                }
2622            }
2623            pub fn wdt_clock_frequency(self) -> u32 {
2624                TIMG_WDT_CLOCK_FREQ_CACHE[self as usize]
2625                    .load(::core::sync::atomic::Ordering::Acquire)
2626            }
2627            pub fn wdt_clock_source_frequency(source: TimgWdtClockConfig) -> u32 {
2628                match source {
2629                    TimgWdtClockConfig::XtalClk => xtal_clk_frequency(),
2630                    TimgWdtClockConfig::RcFastClk => rc_fast_clk_frequency(),
2631                    TimgWdtClockConfig::PllF80m => pll_f80m_frequency(),
2632                }
2633            }
2634        }
2635        impl UartInstance {
2636            pub fn configure_function_clock(
2637                self,
2638                clocks: &mut ClockTree,
2639                config: UartFunctionClockConfig,
2640            ) {
2641                let old_config = clocks.uart_function_clock[self as usize].replace(config);
2642                refresh_uart_function_clock_downstream(clocks, self);
2643                if clocks.uart_function_clock_refcount[self as usize] > 0 {
2644                    match config.sclk {
2645                        UartFunctionClockSclk::Xtal => request_xtal_clk(clocks),
2646                        UartFunctionClockSclk::PllF80m => request_pll_f80m(clocks),
2647                        UartFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
2648                    }
2649                    self.configure_function_clock_impl(clocks, old_config, config);
2650                    if let Some(old_config) = old_config {
2651                        match old_config.sclk {
2652                            UartFunctionClockSclk::Xtal => release_xtal_clk(clocks),
2653                            UartFunctionClockSclk::PllF80m => release_pll_f80m(clocks),
2654                            UartFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
2655                        }
2656                    }
2657                } else {
2658                    self.configure_function_clock_impl(clocks, old_config, config);
2659                }
2660            }
2661            pub fn function_clock_config(
2662                self,
2663                clocks: &mut ClockTree,
2664            ) -> Option<UartFunctionClockConfig> {
2665                clocks.uart_function_clock[self as usize]
2666            }
2667            pub fn request_function_clock(self, clocks: &mut ClockTree) {
2668                trace!("Requesting {:?}::FUNCTION_CLOCK", self);
2669                if increment_reference_count(
2670                    &mut clocks.uart_function_clock_refcount[self as usize],
2671                ) {
2672                    trace!("Enabling {:?}::FUNCTION_CLOCK", self);
2673                    match unwrap!(clocks.uart_function_clock[self as usize]).sclk {
2674                        UartFunctionClockSclk::Xtal => request_xtal_clk(clocks),
2675                        UartFunctionClockSclk::PllF80m => request_pll_f80m(clocks),
2676                        UartFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
2677                    }
2678                    self.enable_function_clock_impl(clocks, true);
2679                }
2680            }
2681            pub fn release_function_clock(self, clocks: &mut ClockTree) {
2682                trace!("Releasing {:?}::FUNCTION_CLOCK", self);
2683                if decrement_reference_count(
2684                    &mut clocks.uart_function_clock_refcount[self as usize],
2685                ) {
2686                    trace!("Disabling {:?}::FUNCTION_CLOCK", self);
2687                    self.enable_function_clock_impl(clocks, false);
2688                    match unwrap!(clocks.uart_function_clock[self as usize]).sclk {
2689                        UartFunctionClockSclk::Xtal => release_xtal_clk(clocks),
2690                        UartFunctionClockSclk::PllF80m => release_pll_f80m(clocks),
2691                        UartFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
2692                    }
2693                }
2694            }
2695            #[allow(unused_variables)]
2696            pub fn function_clock_config_frequency(
2697                clocks: &mut ClockTree,
2698                config: UartFunctionClockConfig,
2699            ) -> u32 {
2700                (match config.sclk {
2701                    UartFunctionClockSclk::Xtal => xtal_clk_frequency(),
2702                    UartFunctionClockSclk::PllF80m => pll_f80m_frequency(),
2703                    UartFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
2704                } / (config.div_num() + 1))
2705            }
2706            pub fn function_clock_frequency(self) -> u32 {
2707                UART_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
2708                    .load(::core::sync::atomic::Ordering::Acquire)
2709            }
2710            pub fn function_clock_source_frequency(sclk: UartFunctionClockSclk) -> u32 {
2711                match sclk {
2712                    UartFunctionClockSclk::Xtal => xtal_clk_frequency(),
2713                    UartFunctionClockSclk::PllF80m => pll_f80m_frequency(),
2714                    UartFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
2715                }
2716            }
2717            pub fn configure_baud_rate_generator(
2718                self,
2719                clocks: &mut ClockTree,
2720                config: UartBaudRateGeneratorConfig,
2721            ) {
2722                let old_config = clocks.uart_baud_rate_generator[self as usize].replace(config);
2723                refresh_uart_baud_rate_generator_downstream(clocks, self);
2724                self.configure_baud_rate_generator_impl(clocks, old_config, config);
2725            }
2726            pub fn baud_rate_generator_config(
2727                self,
2728                clocks: &mut ClockTree,
2729            ) -> Option<UartBaudRateGeneratorConfig> {
2730                clocks.uart_baud_rate_generator[self as usize]
2731            }
2732            pub fn request_baud_rate_generator(self, clocks: &mut ClockTree) {
2733                trace!("Requesting {:?}::BAUD_RATE_GENERATOR", self);
2734                if increment_reference_count(
2735                    &mut clocks.uart_baud_rate_generator_refcount[self as usize],
2736                ) {
2737                    trace!("Enabling {:?}::BAUD_RATE_GENERATOR", self);
2738                    self.request_function_clock(clocks);
2739                    self.enable_baud_rate_generator_impl(clocks, true);
2740                }
2741            }
2742            pub fn release_baud_rate_generator(self, clocks: &mut ClockTree) {
2743                trace!("Releasing {:?}::BAUD_RATE_GENERATOR", self);
2744                if decrement_reference_count(
2745                    &mut clocks.uart_baud_rate_generator_refcount[self as usize],
2746                ) {
2747                    trace!("Disabling {:?}::BAUD_RATE_GENERATOR", self);
2748                    self.enable_baud_rate_generator_impl(clocks, false);
2749                    self.release_function_clock(clocks);
2750                }
2751            }
2752            #[allow(unused_variables)]
2753            pub fn baud_rate_generator_config_frequency(
2754                self,
2755                clocks: &mut ClockTree,
2756                config: UartBaudRateGeneratorConfig,
2757            ) -> u32 {
2758                ((self.function_clock_frequency() * 16)
2759                    / ((config.integral() * 16) + config.fractional()))
2760            }
2761            pub fn baud_rate_generator_frequency(self) -> u32 {
2762                UART_BAUD_RATE_GENERATOR_FREQ_CACHE[self as usize]
2763                    .load(::core::sync::atomic::Ordering::Acquire)
2764            }
2765        }
2766        /// Clock tree configuration.
2767        ///
2768        /// The fields of this struct are optional, with the following caveats:
2769        /// - If `XTAL_CLK` is not specified, the crystal frequency will be automatically detected
2770        ///   if possible.
2771        /// - The CPU and its upstream clock nodes will be set to a default configuration.
2772        /// - Other unspecified clock sources will not be useable by peripherals.
2773        #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2774        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
2775        #[instability::unstable]
2776        pub struct ClockConfig {
2777            /// `XTAL_CLK` configuration.
2778            pub xtal_clk: Option<XtalClkConfig>,
2779            /// `HP_ROOT_CLK` configuration.
2780            pub hp_root_clk: Option<HpRootClkConfig>,
2781            /// `CPU_CLK` configuration.
2782            pub cpu_clk: Option<CpuClkConfig>,
2783            /// `AHB_CLK` configuration.
2784            pub ahb_clk: Option<AhbClkConfig>,
2785            /// `APB_CLK` configuration.
2786            pub apb_clk: Option<ApbClkConfig>,
2787            /// `LP_FAST_CLK` configuration.
2788            pub lp_fast_clk: Option<LpFastClkConfig>,
2789            /// `LP_SLOW_CLK` configuration.
2790            pub lp_slow_clk: Option<LpSlowClkConfig>,
2791            /// `TIMG_CALIBRATION_CLOCK` configuration.
2792            pub timg_calibration_clock: Option<TimgCalibrationClockConfig>,
2793        }
2794        impl ClockConfig {
2795            fn apply(&self, clocks: &mut ClockTree) {
2796                if let Some(config) = self.xtal_clk {
2797                    configure_xtal_clk(clocks, config);
2798                }
2799                if let Some(config) = self.hp_root_clk {
2800                    configure_hp_root_clk(clocks, config);
2801                }
2802                if let Some(config) = self.cpu_clk {
2803                    configure_cpu_clk(clocks, config);
2804                }
2805                if let Some(config) = self.ahb_clk {
2806                    configure_ahb_clk(clocks, config);
2807                }
2808                if let Some(config) = self.apb_clk {
2809                    configure_apb_clk(clocks, config);
2810                }
2811                if let Some(config) = self.lp_fast_clk {
2812                    configure_lp_fast_clk(clocks, config);
2813                }
2814                if let Some(config) = self.lp_slow_clk {
2815                    configure_lp_slow_clk(clocks, config);
2816                }
2817                if let Some(config) = self.timg_calibration_clock {
2818                    configure_timg_calibration_clock(clocks, config);
2819                }
2820            }
2821        }
2822        fn increment_reference_count(refcount: &mut u32) -> bool {
2823            let first = *refcount == 0;
2824            *refcount = unwrap!(refcount.checked_add(1), "Reference count overflow");
2825            first
2826        }
2827        fn decrement_reference_count(refcount: &mut u32) -> bool {
2828            *refcount = refcount.saturating_sub(1);
2829            let last = *refcount == 0;
2830            last
2831        }
2832        fn refresh_xtal_clk_downstream(clocks: &mut ClockTree) {
2833            if let Some(config) = clocks.xtal_clk {
2834                XTAL_CLK_FREQ_CACHE.store(
2835                    xtal_clk_config_frequency(clocks, config),
2836                    ::core::sync::atomic::Ordering::Release,
2837                );
2838            }
2839            refresh_hp_root_clk_downstream(clocks);
2840            refresh_lp_fast_clk_downstream(clocks);
2841            for child_instance in [I2cInstance::I2c0] {
2842                refresh_i2c_function_clock_downstream(clocks, child_instance);
2843            }
2844            for child_instance in [SpiInstance::Spi2] {
2845                refresh_spi_function_clock_downstream(clocks, child_instance);
2846            }
2847            for child_instance in [TimgInstance::Timg0, TimgInstance::Timg1] {
2848                refresh_timg_function_clock_downstream(clocks, child_instance);
2849                refresh_timg_wdt_clock_downstream(clocks, child_instance);
2850            }
2851            for child_instance in [
2852                UartInstance::Uart0,
2853                UartInstance::Uart1,
2854                UartInstance::Uart2,
2855            ] {
2856                refresh_uart_function_clock_downstream(clocks, child_instance);
2857            }
2858        }
2859        fn refresh_hp_root_clk_downstream(clocks: &mut ClockTree) {
2860            if let Some(config) = clocks.hp_root_clk {
2861                HP_ROOT_CLK_FREQ_CACHE.store(
2862                    hp_root_clk_config_frequency(clocks, config),
2863                    ::core::sync::atomic::Ordering::Release,
2864                );
2865            }
2866            refresh_cpu_clk_downstream(clocks);
2867            refresh_ahb_clk_downstream(clocks);
2868        }
2869        fn refresh_cpu_clk_downstream(clocks: &mut ClockTree) {
2870            if let Some(config) = clocks.cpu_clk {
2871                CPU_CLK_FREQ_CACHE.store(
2872                    cpu_clk_config_frequency(clocks, config),
2873                    ::core::sync::atomic::Ordering::Release,
2874                );
2875            }
2876        }
2877        fn refresh_ahb_clk_downstream(clocks: &mut ClockTree) {
2878            if let Some(config) = clocks.ahb_clk {
2879                AHB_CLK_FREQ_CACHE.store(
2880                    ahb_clk_config_frequency(clocks, config),
2881                    ::core::sync::atomic::Ordering::Release,
2882                );
2883            }
2884            refresh_apb_clk_downstream(clocks);
2885        }
2886        fn refresh_apb_clk_downstream(clocks: &mut ClockTree) {
2887            if let Some(config) = clocks.apb_clk {
2888                APB_CLK_FREQ_CACHE.store(
2889                    apb_clk_config_frequency(clocks, config),
2890                    ::core::sync::atomic::Ordering::Release,
2891                );
2892            }
2893        }
2894        fn refresh_lp_fast_clk_downstream(clocks: &mut ClockTree) {
2895            if let Some(config) = clocks.lp_fast_clk {
2896                LP_FAST_CLK_FREQ_CACHE.store(
2897                    lp_fast_clk_config_frequency(clocks, config),
2898                    ::core::sync::atomic::Ordering::Release,
2899                );
2900            }
2901        }
2902        fn refresh_lp_slow_clk_downstream(clocks: &mut ClockTree) {
2903            if let Some(config) = clocks.lp_slow_clk {
2904                LP_SLOW_CLK_FREQ_CACHE.store(
2905                    lp_slow_clk_config_frequency(clocks, config),
2906                    ::core::sync::atomic::Ordering::Release,
2907                );
2908            }
2909        }
2910        fn refresh_timg_calibration_clock_downstream(clocks: &mut ClockTree) {
2911            if let Some(config) = clocks.timg_calibration_clock {
2912                TIMG_CALIBRATION_CLOCK_FREQ_CACHE.store(
2913                    timg_calibration_clock_config_frequency(clocks, config),
2914                    ::core::sync::atomic::Ordering::Release,
2915                );
2916            }
2917        }
2918        fn refresh_i2c_function_clock_downstream(clocks: &mut ClockTree, instance: I2cInstance) {
2919            if let Some(config) = clocks.i2c_function_clock[instance as usize] {
2920                I2C_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
2921                    I2cInstance::function_clock_config_frequency(clocks, config),
2922                    ::core::sync::atomic::Ordering::Release,
2923                );
2924            }
2925        }
2926        fn refresh_spi_function_clock_downstream(clocks: &mut ClockTree, instance: SpiInstance) {
2927            if let Some(config) = clocks.spi_function_clock[instance as usize] {
2928                SPI_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
2929                    SpiInstance::function_clock_config_frequency(clocks, config),
2930                    ::core::sync::atomic::Ordering::Release,
2931                );
2932            }
2933        }
2934        fn refresh_timg_function_clock_downstream(clocks: &mut ClockTree, instance: TimgInstance) {
2935            if let Some(config) = clocks.timg_function_clock[instance as usize] {
2936                TIMG_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
2937                    TimgInstance::function_clock_config_frequency(clocks, config),
2938                    ::core::sync::atomic::Ordering::Release,
2939                );
2940            }
2941        }
2942        fn refresh_timg_wdt_clock_downstream(clocks: &mut ClockTree, instance: TimgInstance) {
2943            if let Some(config) = clocks.timg_wdt_clock[instance as usize] {
2944                TIMG_WDT_CLOCK_FREQ_CACHE[instance as usize].store(
2945                    TimgInstance::wdt_clock_config_frequency(clocks, config),
2946                    ::core::sync::atomic::Ordering::Release,
2947                );
2948            }
2949        }
2950        fn refresh_uart_function_clock_downstream(clocks: &mut ClockTree, instance: UartInstance) {
2951            if let Some(config) = clocks.uart_function_clock[instance as usize] {
2952                UART_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
2953                    UartInstance::function_clock_config_frequency(clocks, config),
2954                    ::core::sync::atomic::Ordering::Release,
2955                );
2956            }
2957            refresh_uart_baud_rate_generator_downstream(clocks, instance);
2958        }
2959        fn refresh_uart_baud_rate_generator_downstream(
2960            clocks: &mut ClockTree,
2961            instance: UartInstance,
2962        ) {
2963            if let Some(config) = clocks.uart_baud_rate_generator[instance as usize] {
2964                UART_BAUD_RATE_GENERATOR_FREQ_CACHE[instance as usize].store(
2965                    instance.baud_rate_generator_config_frequency(clocks, config),
2966                    ::core::sync::atomic::Ordering::Release,
2967                );
2968            }
2969        }
2970    };
2971}
2972/// Implement the `Peripheral` enum and enable/disable/reset functions.
2973///
2974/// This macro is intended to be placed in `esp_hal::system`.
2975#[macro_export]
2976#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
2977macro_rules! implement_peripheral_clocks {
2978    () => {
2979        #[doc(hidden)]
2980        #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2981        #[repr(u8)]
2982        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
2983        pub enum Peripheral {
2984            /// AHB_GDMA peripheral clock signal
2985            AhbGdma,
2986            /// APB_SAR_ADC peripheral clock signal
2987            ApbSarAdc,
2988            /// ECC peripheral clock signal
2989            Ecc,
2990            /// I2C_EXT0 peripheral clock signal
2991            I2cExt0,
2992            /// I2S0 peripheral clock signal
2993            I2s0,
2994            /// SHA peripheral clock signal
2995            Sha,
2996            /// SPI2 peripheral clock signal
2997            Spi2,
2998            /// SYSTIMER peripheral clock signal
2999            Systimer,
3000            /// TIMG0 peripheral clock signal
3001            Timg0,
3002            /// TIMG1 peripheral clock signal
3003            Timg1,
3004            /// UART0 peripheral clock signal
3005            Uart0,
3006            /// UART1 peripheral clock signal
3007            Uart1,
3008            /// UART2 peripheral clock signal
3009            Uart2,
3010            /// USB_DEVICE peripheral clock signal
3011            UsbDevice,
3012        }
3013        impl Peripheral {
3014            const KEEP_ENABLED: &[Peripheral] =
3015                &[Self::Systimer, Self::Timg0, Self::Uart0, Self::UsbDevice];
3016            const COUNT: usize = Self::ALL.len();
3017            const ALL: &[Self] = &[
3018                Self::AhbGdma,
3019                Self::ApbSarAdc,
3020                Self::Ecc,
3021                Self::I2cExt0,
3022                Self::I2s0,
3023                Self::Sha,
3024                Self::Spi2,
3025                Self::Systimer,
3026                Self::Timg0,
3027                Self::Timg1,
3028                Self::Uart0,
3029                Self::Uart1,
3030                Self::Uart2,
3031                Self::UsbDevice,
3032            ];
3033        }
3034        unsafe fn enable_internal_racey(peripheral: Peripheral, enable: bool) {
3035            match peripheral {
3036                Peripheral::AhbGdma => {
3037                    crate::peripherals::SYSTEM::regs()
3038                        .gdma_conf()
3039                        .modify(|_, w| w.gdma_clk_en().bit(enable));
3040                }
3041                Peripheral::ApbSarAdc => {
3042                    crate::peripherals::SYSTEM::regs()
3043                        .saradc_conf()
3044                        .modify(|_, w| w.saradc_reg_clk_en().bit(enable));
3045                }
3046                Peripheral::Ecc => {
3047                    crate::peripherals::SYSTEM::regs()
3048                        .ecc_conf()
3049                        .modify(|_, w| w.ecc_clk_en().bit(enable));
3050                }
3051                Peripheral::I2cExt0 => {
3052                    crate::peripherals::SYSTEM::regs()
3053                        .i2c0_conf()
3054                        .modify(|_, w| w.i2c0_clk_en().bit(enable));
3055                }
3056                Peripheral::I2s0 => {
3057                    crate::peripherals::SYSTEM::regs()
3058                        .i2s_conf()
3059                        .modify(|_, w| w.i2s_clk_en().bit(enable));
3060                }
3061                Peripheral::Sha => {
3062                    crate::peripherals::SYSTEM::regs()
3063                        .sha_conf()
3064                        .modify(|_, w| w.sha_clk_en().bit(enable));
3065                }
3066                Peripheral::Spi2 => {
3067                    crate::peripherals::SYSTEM::regs()
3068                        .spi2_conf()
3069                        .modify(|_, w| w.spi2_clk_en().bit(enable));
3070                }
3071                Peripheral::Systimer => {
3072                    crate::peripherals::SYSTEM::regs()
3073                        .systimer_conf()
3074                        .modify(|_, w| w.systimer_clk_en().bit(enable));
3075                }
3076                Peripheral::Timg0 => {
3077                    crate::peripherals::SYSTEM::regs()
3078                        .timergroup(0)
3079                        .conf()
3080                        .modify(|_, w| w.clk_en().bit(enable));
3081                }
3082                Peripheral::Timg1 => {
3083                    crate::peripherals::SYSTEM::regs()
3084                        .timergroup(1)
3085                        .conf()
3086                        .modify(|_, w| w.clk_en().bit(enable));
3087                }
3088                Peripheral::Uart0 => {
3089                    crate::peripherals::SYSTEM::regs()
3090                        .uart(0)
3091                        .conf()
3092                        .modify(|_, w| w.clk_en().bit(enable));
3093                }
3094                Peripheral::Uart1 => {
3095                    crate::peripherals::SYSTEM::regs()
3096                        .uart(1)
3097                        .conf()
3098                        .modify(|_, w| w.clk_en().bit(enable));
3099                }
3100                Peripheral::Uart2 => {
3101                    crate::peripherals::SYSTEM::regs()
3102                        .uart(2)
3103                        .conf()
3104                        .modify(|_, w| w.clk_en().bit(enable));
3105                }
3106                Peripheral::UsbDevice => {
3107                    crate::peripherals::SYSTEM::regs()
3108                        .usb_device_conf()
3109                        .modify(|_, w| w.usb_device_clk_en().bit(enable));
3110                }
3111            }
3112        }
3113        unsafe fn assert_peri_reset_racey(peripheral: Peripheral, reset: bool) {
3114            match peripheral {
3115                Peripheral::AhbGdma => {
3116                    crate::peripherals::SYSTEM::regs()
3117                        .gdma_conf()
3118                        .modify(|_, w| w.gdma_rst_en().bit(reset));
3119                }
3120                Peripheral::ApbSarAdc => {
3121                    crate::peripherals::SYSTEM::regs()
3122                        .saradc_conf()
3123                        .modify(|_, w| w.saradc_reg_rst_en().bit(reset));
3124                }
3125                Peripheral::Ecc => {
3126                    crate::peripherals::SYSTEM::regs()
3127                        .ecc_conf()
3128                        .modify(|_, w| w.ecc_rst_en().bit(reset));
3129                }
3130                Peripheral::I2cExt0 => {
3131                    crate::peripherals::SYSTEM::regs()
3132                        .i2c0_conf()
3133                        .modify(|_, w| w.i2c0_rst_en().bit(reset));
3134                }
3135                Peripheral::I2s0 => {
3136                    crate::peripherals::SYSTEM::regs()
3137                        .i2s_conf()
3138                        .modify(|_, w| w.i2s_rst_en().bit(reset));
3139                }
3140                Peripheral::Sha => {
3141                    crate::peripherals::SYSTEM::regs()
3142                        .sha_conf()
3143                        .modify(|_, w| w.sha_rst_en().bit(reset));
3144                }
3145                Peripheral::Spi2 => {
3146                    crate::peripherals::SYSTEM::regs()
3147                        .spi2_conf()
3148                        .modify(|_, w| w.spi2_rst_en().bit(reset));
3149                }
3150                Peripheral::Systimer => {
3151                    crate::peripherals::SYSTEM::regs()
3152                        .systimer_conf()
3153                        .modify(|_, w| w.systimer_rst_en().bit(reset));
3154                }
3155                Peripheral::Timg0 => {
3156                    crate::peripherals::SYSTEM::regs()
3157                        .timergroup(0)
3158                        .conf()
3159                        .modify(|_, w| w.rst_en().bit(reset));
3160                }
3161                Peripheral::Timg1 => {
3162                    crate::peripherals::SYSTEM::regs()
3163                        .timergroup(1)
3164                        .conf()
3165                        .modify(|_, w| w.rst_en().bit(reset));
3166                }
3167                Peripheral::Uart0 => {
3168                    crate::peripherals::SYSTEM::regs()
3169                        .uart(0)
3170                        .conf()
3171                        .modify(|_, w| w.rst_en().bit(reset));
3172                }
3173                Peripheral::Uart1 => {
3174                    crate::peripherals::SYSTEM::regs()
3175                        .uart(1)
3176                        .conf()
3177                        .modify(|_, w| w.rst_en().bit(reset));
3178                }
3179                Peripheral::Uart2 => {
3180                    crate::peripherals::SYSTEM::regs()
3181                        .uart(2)
3182                        .conf()
3183                        .modify(|_, w| w.rst_en().bit(reset));
3184                }
3185                Peripheral::UsbDevice => {
3186                    crate::peripherals::SYSTEM::regs()
3187                        .usb_device_conf()
3188                        .modify(|_, w| w.usb_device_rst_en().bit(reset));
3189                }
3190            }
3191        }
3192    };
3193}
3194/// Macro to get the address range of the given memory region.
3195///
3196/// This macro provides two syntax options for each memory region:
3197///
3198/// - `memory_range!("region_name")` returns the address range as a range expression (`start..end`).
3199/// - `memory_range!(size as str, "region_name")` returns the size of the region as a string
3200///   literal.
3201#[macro_export]
3202#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3203macro_rules! memory_range {
3204    ("DRAM") => {
3205        0x40800000..0x40850000
3206    };
3207    (size as str, "DRAM") => {
3208        "327680"
3209    };
3210    ("DRAM2_UNINIT") => {
3211        0x4083EA70..0x4084EA70
3212    };
3213    (size as str, "DRAM2_UNINIT") => {
3214        "65536"
3215    };
3216    ("IROM") => {
3217        0x42000000..0x44000000
3218    };
3219    (size as str, "IROM") => {
3220        "33554432"
3221    };
3222    ("DROM") => {
3223        0x42000000..0x44000000
3224    };
3225    (size as str, "DROM") => {
3226        "33554432"
3227    };
3228}
3229/// This macro can be used to generate code for each peripheral instance of the I2C master driver.
3230///
3231/// For an explanation on the general syntax, as well as usage of individual/repeated
3232/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
3233///
3234/// This macro has one option for its "Individual matcher" case:
3235///
3236/// Syntax: `($id:literal, $instance:ident, $sys:ident, $scl:ident, $sda:ident)`
3237///
3238/// Macro fragments:
3239/// - `$id`: the index of the I2C instance
3240/// - `$instance`: the name of the I2C instance
3241/// - `$sys`: the name of the instance as it is in the `esp_hal::system::Peripheral` enum.
3242/// - `$scl`, `$sda`: peripheral signal names.
3243///
3244/// Example data: `(0, I2C0, I2cExt0, I2CEXT0_SCL, I2CEXT0_SDA)`
3245#[macro_export]
3246#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3247macro_rules! for_each_i2c_master {
3248    ($($pattern:tt => $code:tt;)*) => {
3249        macro_rules! _for_each_inner_i2c_master { $(($pattern) => $code;)* ($other : tt)
3250        => {} } _for_each_inner_i2c_master!((0, I2C0, I2cExt0, I2CEXT0_SCL,
3251        I2CEXT0_SDA)); _for_each_inner_i2c_master!((all(0, I2C0, I2cExt0, I2CEXT0_SCL,
3252        I2CEXT0_SDA)));
3253    };
3254}
3255/// This macro can be used to generate code for each peripheral instance of the I2S driver.
3256///
3257/// For an explanation on the general syntax, as well as usage of individual/repeated
3258/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
3259///
3260/// This macro has one option for its "Individual matcher" case:
3261///
3262/// Syntax: `($instance:ident, $sys:ident, $mclk:ident, $bclk:ident, $ws:ident, $bclk_rx:ident,
3263/// $ws_rx:ident, [$($dout:ident),*], [$($din:ident),*], $pdm_tx:literal, $pdm_rx:literal,
3264/// $pcm2pdm:literal, $pdm2pcm:literal)`
3265///
3266/// Macro fragments:
3267///
3268/// - `$instance`: the name of the I2S instance
3269/// - `$sys`: the name of the instance as it is in the `esp_hal::system::Peripheral` enum.
3270/// - `$mclk`: the MCLK output signal (a placeholder on chips without a GPIO-matrix MCLK).
3271/// - `$bclk`, `$ws`: TX bit clock and word select output signals.
3272/// - `$bclk_rx`, `$ws_rx`: RX bit clock and word select output signals.
3273/// - `$dout`, `$din`: data-out and data-in signal names.
3274/// - `$pdm_tx`, `$pdm_rx`: whether the instance supports PDM TX/RX.
3275/// - `$pcm2pdm`, `$pdm2pcm`: whether the instance supports the hardware PCM<->PDM format conversion
3276///   filter on TX/RX.
3277///
3278/// Example data:
3279/// - `(I2S0, I2s0, I2S_MCLK, I2SO_BCK, I2SO_WS, I2SI_BCK, I2SI_WS, [I2SO_SD], [I2SI_SD], true,
3280///   true, true, true)`
3281#[macro_export]
3282#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3283macro_rules! for_each_i2s {
3284    ($($pattern:tt => $code:tt;)*) => {
3285        macro_rules! _for_each_inner_i2s { $(($pattern) => $code;)* ($other : tt) => {} }
3286        _for_each_inner_i2s!((I2S0)); _for_each_inner_i2s!((I2S0, I2s0, I2S_MCLK,
3287        I2SO_BCK, I2SO_WS, I2SI_BCK, I2SI_WS, [I2SO_SD], [I2SI_SD], true, true, true,
3288        false)); _for_each_inner_i2s!((names(I2S0))); _for_each_inner_i2s!((all(I2S0,
3289        I2s0, I2S_MCLK, I2SO_BCK, I2SO_WS, I2SI_BCK, I2SI_WS, [I2SO_SD], [I2SI_SD], true,
3290        true, true, false)));
3291    };
3292}
3293/// This macro can be used to generate code for each peripheral instance of the UART driver.
3294///
3295/// For an explanation on the general syntax, as well as usage of individual/repeated
3296/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
3297///
3298/// This macro has one option for its "Individual matcher" case:
3299///
3300/// Syntax: `($id:literal, $instance:ident, $sys:ident, $rx:ident, $tx:ident, $cts:ident,
3301/// $rts:ident)`
3302///
3303/// Macro fragments:
3304///
3305/// - `$id`: the index of the UART instance
3306/// - `$instance`: the name of the UART instance
3307/// - `$sys`: the name of the instance as it is in the `esp_hal::system::Peripheral` enum.
3308/// - `$rx`, `$tx`, `$cts`, `$rts`: signal names.
3309///
3310/// Example data: `(0, UART0, Uart0, U0RXD, U0TXD, U0CTS, U0RTS)`
3311#[macro_export]
3312#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3313macro_rules! for_each_uart {
3314    ($($pattern:tt => $code:tt;)*) => {
3315        macro_rules! _for_each_inner_uart { $(($pattern) => $code;)* ($other : tt) => {}
3316        } _for_each_inner_uart!((0, UART0, Uart0, U0RXD, U0TXD, U0CTS, U0RTS,
3317        wakeup_source = true)); _for_each_inner_uart!((1, UART1, Uart1, U1RXD, U1TXD,
3318        U1CTS, U1RTS, wakeup_source = true)); _for_each_inner_uart!((2, UART2, Uart2,
3319        U2RXD, U2TXD, U2CTS, U2RTS, wakeup_source = true)); _for_each_inner_uart!((all(0,
3320        UART0, Uart0, U0RXD, U0TXD, U0CTS, U0RTS, wakeup_source = true), (1, UART1,
3321        Uart1, U1RXD, U1TXD, U1CTS, U1RTS, wakeup_source = true), (2, UART2, Uart2,
3322        U2RXD, U2TXD, U2CTS, U2RTS, wakeup_source = true)));
3323    };
3324}
3325/// This macro can be used to generate code for each peripheral instance of the SPI master driver.
3326///
3327/// For an explanation on the general syntax, as well as usage of individual/repeated
3328/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
3329///
3330/// This macro has one option for its "Individual matcher" case:
3331///
3332/// Syntax: `($instance:ident, $sys:ident, $sclk:ident [$($cs:ident),*] [$($sio:ident),*]
3333/// $($is_qspi:literal)?)`
3334///
3335/// Macro fragments:
3336///
3337/// - `$instance`: the name of the SPI instance
3338/// - `$sys`: the name of the instance as it is in the `esp_hal::system::Peripheral` enum.
3339/// - `$cs`, `$sio`: chip select and SIO signal names.
3340/// - `$is_qspi`: a `true` literal present if the SPI instance supports QSPI.
3341///
3342/// Example data:
3343/// - `(SPI2, Spi2, FSPICLK [FSPICS0, FSPICS1, FSPICS2, FSPICS3, FSPICS4, FSPICS5] [FSPID, FSPIQ,
3344///   FSPIWP, FSPIHD, FSPIIO4, FSPIIO5, FSPIIO6, FSPIIO7], true)`
3345/// - `(SPI3, Spi3, SPI3_CLK [SPI3_CS0, SPI3_CS1, SPI3_CS2] [SPI3_D, SPI3_Q])`
3346#[macro_export]
3347#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3348macro_rules! for_each_spi_master {
3349    ($($pattern:tt => $code:tt;)*) => {
3350        macro_rules! _for_each_inner_spi_master { $(($pattern) => $code;)* ($other : tt)
3351        => {} } _for_each_inner_spi_master!((SPI2)); _for_each_inner_spi_master!((SPI2,
3352        Spi2, FSPICLK[FSPICS0, FSPICS1, FSPICS2, FSPICS3, FSPICS4, FSPICS5] [FSPID,
3353        FSPIQ, FSPIWP, FSPIHD], true)); _for_each_inner_spi_master!((names(SPI2)));
3354        _for_each_inner_spi_master!((all(SPI2, Spi2, FSPICLK[FSPICS0, FSPICS1, FSPICS2,
3355        FSPICS3, FSPICS4, FSPICS5] [FSPID, FSPIQ, FSPIWP, FSPIHD], true)));
3356    };
3357}
3358/// This macro can be used to generate code for each peripheral instance of the SPI slave driver.
3359///
3360/// For an explanation on the general syntax, as well as usage of individual/repeated
3361/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
3362///
3363/// This macro has one option for its "Individual matcher" case:
3364///
3365/// Syntax: `($instance:ident, $sys:ident, $sclk:ident, $mosi:ident, $miso:ident, $cs:ident)`
3366///
3367/// Macro fragments:
3368///
3369/// - `$instance`: the name of the SPI instance
3370/// - `$sys`: the name of the instance as it is in the `esp_hal::system::Peripheral` enum.
3371/// - `$sclk`, `$mosi`, `$miso`, `$cs`: signal names.
3372///
3373/// Example data: `(SPI2, Spi2, FSPICLK, FSPID, FSPIQ, FSPICS0)`
3374#[macro_export]
3375#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3376macro_rules! for_each_spi_slave {
3377    ($($pattern:tt => $code:tt;)*) => {
3378        macro_rules! _for_each_inner_spi_slave { $(($pattern) => $code;)* ($other : tt)
3379        => {} } _for_each_inner_spi_slave!((SPI2)); _for_each_inner_spi_slave!((SPI2,
3380        Spi2, FSPICLK, FSPID, FSPIQ, FSPICS0));
3381        _for_each_inner_spi_slave!((names(SPI2))); _for_each_inner_spi_slave!((all(SPI2,
3382        Spi2, FSPICLK, FSPID, FSPIQ, FSPICS0)));
3383    };
3384}
3385#[macro_export]
3386#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3387macro_rules! for_each_peripheral {
3388    ($($pattern:tt => $code:tt;)*) => {
3389        macro_rules! _for_each_inner_peripheral { $(($pattern) => $code;)* ($other : tt)
3390        => {} } _for_each_inner_peripheral!((@ peri_type #[doc =
3391        "GPIO0 peripheral singleton"] GPIO0 <= virtual()));
3392        _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO1 peripheral singleton"]
3393        GPIO1 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
3394        "GPIO2 peripheral singleton"] GPIO2 <= virtual()));
3395        _for_each_inner_peripheral!((@ peri_type #[doc =
3396        "GPIO3 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3397        "<section class=\"warning\">"] #[doc =
3398        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3399        #[doc = "<ul>"] #[doc =
3400        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
3401        =
3402        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3403        #[doc = "</ul>"] #[doc = "</section>"] GPIO3 <= virtual()));
3404        _for_each_inner_peripheral!((@ peri_type #[doc =
3405        "GPIO4 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3406        "<section class=\"warning\">"] #[doc =
3407        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3408        #[doc = "<ul>"] #[doc =
3409        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
3410        =
3411        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3412        #[doc = "</ul>"] #[doc = "</section>"] GPIO4 <= virtual()));
3413        _for_each_inner_peripheral!((@ peri_type #[doc =
3414        "GPIO5 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3415        "<section class=\"warning\">"] #[doc =
3416        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3417        #[doc = "<ul>"] #[doc =
3418        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3419        #[doc = "</ul>"] #[doc = "</section>"] GPIO5 <= virtual()));
3420        _for_each_inner_peripheral!((@ peri_type #[doc =
3421        "GPIO6 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3422        "<section class=\"warning\">"] #[doc =
3423        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3424        #[doc = "<ul>"] #[doc =
3425        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3426        #[doc = "</ul>"] #[doc = "</section>"] GPIO6 <= virtual()));
3427        _for_each_inner_peripheral!((@ peri_type #[doc =
3428        "GPIO7 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3429        "<section class=\"warning\">"] #[doc =
3430        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3431        #[doc = "<ul>"] #[doc =
3432        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
3433        = "</ul>"] #[doc = "</section>"] GPIO7 <= virtual()));
3434        _for_each_inner_peripheral!((@ peri_type #[doc =
3435        "GPIO8 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3436        "<section class=\"warning\">"] #[doc =
3437        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3438        #[doc = "<ul>"] #[doc =
3439        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
3440        = "</ul>"] #[doc = "</section>"] GPIO8 <= virtual()));
3441        _for_each_inner_peripheral!((@ peri_type #[doc =
3442        "GPIO9 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3443        "<section class=\"warning\">"] #[doc =
3444        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3445        #[doc = "<ul>"] #[doc =
3446        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
3447        = "</ul>"] #[doc = "</section>"] GPIO9 <= virtual()));
3448        _for_each_inner_peripheral!((@ peri_type #[doc =
3449        "GPIO10 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3450        "<section class=\"warning\">"] #[doc =
3451        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3452        #[doc = "<ul>"] #[doc =
3453        "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
3454        = "</ul>"] #[doc = "</section>"] GPIO10 <= virtual()));
3455        _for_each_inner_peripheral!((@ peri_type #[doc =
3456        "GPIO11 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3457        "<section class=\"warning\">"] #[doc =
3458        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3459        #[doc = "<ul>"] #[doc =
3460        "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
3461        = "</ul>"] #[doc = "</section>"] GPIO11 <= virtual()));
3462        _for_each_inner_peripheral!((@ peri_type #[doc =
3463        "GPIO12 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3464        "<section class=\"warning\">"] #[doc =
3465        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3466        #[doc = "<ul>"] #[doc =
3467        "<li>These pins may be used to debug the chip using USB.</li>"] #[doc = "</ul>"]
3468        #[doc = "</section>"] GPIO12 <= virtual())); _for_each_inner_peripheral!((@
3469        peri_type #[doc = "GPIO13 peripheral singleton (Limitations exist)"] #[doc = ""]
3470        #[doc = "<section class=\"warning\">"] #[doc =
3471        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3472        #[doc = "<ul>"] #[doc =
3473        "<li>These pins may be used to debug the chip using USB.</li>"] #[doc = "</ul>"]
3474        #[doc = "</section>"] GPIO13 <= virtual())); _for_each_inner_peripheral!((@
3475        peri_type #[doc = "GPIO14 peripheral singleton (Limitations exist)"] #[doc = ""]
3476        #[doc = "<section class=\"warning\">"] #[doc =
3477        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3478        #[doc = "<ul>"] #[doc =
3479        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
3480        "</ul>"] #[doc = "</section>"] GPIO14 <= virtual()));
3481        _for_each_inner_peripheral!((@ peri_type #[doc =
3482        "GPIO15 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3483        "<section class=\"warning\">"] #[doc =
3484        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3485        #[doc = "<ul>"] #[doc =
3486        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3487        "</ul>"] #[doc = "</section>"] GPIO15 <= virtual()));
3488        _for_each_inner_peripheral!((@ peri_type #[doc =
3489        "GPIO16 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3490        "<section class=\"warning\">"] #[doc =
3491        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3492        #[doc = "<ul>"] #[doc =
3493        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3494        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
3495        "</ul>"] #[doc = "</section>"] GPIO16 <= virtual()));
3496        _for_each_inner_peripheral!((@ peri_type #[doc =
3497        "GPIO17 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3498        "<section class=\"warning\">"] #[doc =
3499        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3500        #[doc = "<ul>"] #[doc =
3501        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3502        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
3503        "</ul>"] #[doc = "</section>"] GPIO17 <= virtual()));
3504        _for_each_inner_peripheral!((@ peri_type #[doc =
3505        "GPIO18 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3506        "<section class=\"warning\">"] #[doc =
3507        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3508        #[doc = "<ul>"] #[doc =
3509        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3510        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
3511        "</ul>"] #[doc = "</section>"] GPIO18 <= virtual()));
3512        _for_each_inner_peripheral!((@ peri_type #[doc =
3513        "GPIO19 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3514        "<section class=\"warning\">"] #[doc =
3515        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3516        #[doc = "<ul>"] #[doc =
3517        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3518        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
3519        "</ul>"] #[doc = "</section>"] GPIO19 <= virtual()));
3520        _for_each_inner_peripheral!((@ peri_type #[doc =
3521        "GPIO20 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3522        "<section class=\"warning\">"] #[doc =
3523        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3524        #[doc = "<ul>"] #[doc =
3525        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3526        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
3527        "</ul>"] #[doc = "</section>"] GPIO20 <= virtual()));
3528        _for_each_inner_peripheral!((@ peri_type #[doc =
3529        "GPIO21 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3530        "<section class=\"warning\">"] #[doc =
3531        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3532        #[doc = "<ul>"] #[doc =
3533        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3534        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
3535        "</ul>"] #[doc = "</section>"] GPIO21 <= virtual()));
3536        _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO22 peripheral singleton"]
3537        GPIO22 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
3538        "GPIO23 peripheral singleton"] GPIO23 <= virtual()));
3539        _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO24 peripheral singleton"]
3540        GPIO24 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
3541        "GPIO25 peripheral singleton"] GPIO25 <= virtual()));
3542        _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO26 peripheral singleton"]
3543        GPIO26 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
3544        "GPIO27 peripheral singleton"] GPIO27 <= virtual()));
3545        _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO28 peripheral singleton"]
3546        GPIO28 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
3547        "GPIO29 peripheral singleton"] GPIO29 <= virtual()));
3548        _for_each_inner_peripheral!((@ peri_type #[doc = "DMA_CH0 peripheral singleton"]
3549        DMA_CH0 <= virtual(DMA_IN_CH0 : { bind_dma_in_interrupt, enable_dma_in_interrupt,
3550        disable_dma_in_interrupt }, DMA_OUT_CH0 : { bind_dma_out_interrupt,
3551        enable_dma_out_interrupt, disable_dma_out_interrupt }) (unstable)));
3552        _for_each_inner_peripheral!((@ peri_type #[doc = "DMA_CH1 peripheral singleton"]
3553        DMA_CH1 <= virtual(DMA_IN_CH1 : { bind_dma_in_interrupt, enable_dma_in_interrupt,
3554        disable_dma_in_interrupt }, DMA_OUT_CH1 : { bind_dma_out_interrupt,
3555        enable_dma_out_interrupt, disable_dma_out_interrupt }) (unstable)));
3556        _for_each_inner_peripheral!((@ peri_type #[doc =
3557        "APB_SARADC peripheral singleton"] APB_SARADC <= APB_SARADC() (unstable)));
3558        _for_each_inner_peripheral!((@ peri_type #[doc =
3559        "ASSIST_DEBUG peripheral singleton"] ASSIST_DEBUG <= ASSIST_DEBUG() (unstable)));
3560        _for_each_inner_peripheral!((@ peri_type #[doc = "CLINT peripheral singleton"]
3561        CLINT <= CLINT() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3562        "CACHE peripheral singleton"] CACHE <= CACHE() (unstable)));
3563        _for_each_inner_peripheral!((@ peri_type #[doc = "DMA peripheral singleton"] DMA
3564        <= DMA() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3565        "ECC peripheral singleton"] ECC <= ECC() (unstable)));
3566        _for_each_inner_peripheral!((@ peri_type #[doc = "ECDSA peripheral singleton"]
3567        ECDSA <= ECDSA() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3568        "EFUSE peripheral singleton"] EFUSE <= EFUSE() (unstable)));
3569        _for_each_inner_peripheral!((@ peri_type #[doc = "ETM peripheral singleton"] ETM
3570        <= SOC_ETM() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3571        "GPIO peripheral singleton"] GPIO <= GPIO() (unstable)));
3572        _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO_SD peripheral singleton"]
3573        GPIO_SD <= GPIO_EXT() (unstable))); _for_each_inner_peripheral!((@ peri_type
3574        #[doc = "HP_APM peripheral singleton"] HP_APM <= HP_APM() (unstable)));
3575        _for_each_inner_peripheral!((@ peri_type #[doc = "HP_SYS peripheral singleton"]
3576        HP_SYS <= HP_SYS() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3577        "I2C_ANA_MST peripheral singleton"] I2C_ANA_MST <= I2C_ANA_MST() (unstable)));
3578        _for_each_inner_peripheral!((@ peri_type #[doc = "I2C0 peripheral singleton"]
3579        I2C0 <= I2C0(I2C_EXT0 : { bind_peri_interrupt, enable_peri_interrupt,
3580        disable_peri_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
3581        "I2S0 peripheral singleton"] I2S0 <= I2S0(I2S0 : { bind_peri_interrupt,
3582        enable_peri_interrupt, disable_peri_interrupt }) (unstable)));
3583        _for_each_inner_peripheral!((@ peri_type #[doc =
3584        "INTERRUPT_CORE0 peripheral singleton"] INTERRUPT_CORE0 <= INTERRUPT_CORE0()
3585        (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3586        "INTPRI peripheral singleton"] INTPRI <= INTPRI() (unstable)));
3587        _for_each_inner_peripheral!((@ peri_type #[doc = "IO_MUX peripheral singleton"]
3588        IO_MUX <= IO_MUX() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3589        "LP_ANA peripheral singleton"] LP_ANA <= LP_ANA() (unstable)));
3590        _for_each_inner_peripheral!((@ peri_type #[doc = "LP_AON peripheral singleton"]
3591        LP_AON <= LP_AON() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3592        "LP_APM peripheral singleton"] LP_APM <= LP_APM() (unstable)));
3593        _for_each_inner_peripheral!((@ peri_type #[doc =
3594        "LP_CLKRST peripheral singleton"] LP_CLKRST <= LP_CLKRST() (unstable)));
3595        _for_each_inner_peripheral!((@ peri_type #[doc = "LPWR peripheral singleton"]
3596        LPWR <= LP_CLKRST() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc
3597        = "LP_GPIO peripheral singleton"] LP_GPIO <= LP_GPIO() (unstable)));
3598        _for_each_inner_peripheral!((@ peri_type #[doc =
3599        "LP_IO_MUX peripheral singleton"] LP_IO_MUX <= LP_IO_MUX() (unstable)));
3600        _for_each_inner_peripheral!((@ peri_type #[doc = "LP_PERI peripheral singleton"]
3601        LP_PERI <= LPPERI() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc
3602        = "LP_TEE peripheral singleton"] LP_TEE <= LP_TEE() (unstable)));
3603        _for_each_inner_peripheral!((@ peri_type #[doc =
3604        "RTC_TIMER peripheral singleton"] RTC_TIMER <= LP_TIMER() (unstable)));
3605        _for_each_inner_peripheral!((@ peri_type #[doc = "LP_WDT peripheral singleton"]
3606        LP_WDT <= LP_WDT() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3607        "MEM_MONITOR peripheral singleton"] MEM_MONITOR <= MEM_MONITOR() (unstable)));
3608        _for_each_inner_peripheral!((@ peri_type #[doc =
3609        "MODEM_LPCON peripheral singleton"] MODEM_LPCON <= MODEM_LPCON() (unstable)));
3610        _for_each_inner_peripheral!((@ peri_type #[doc =
3611        "MODEM_SYSCON peripheral singleton"] MODEM_SYSCON <= MODEM_SYSCON() (unstable)));
3612        _for_each_inner_peripheral!((@ peri_type #[doc = "PAU peripheral singleton"] PAU
3613        <= PAU() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3614        "PCR peripheral singleton"] PCR <= PCR() (unstable)));
3615        _for_each_inner_peripheral!((@ peri_type #[doc = "PMU peripheral singleton"] PMU
3616        <= PMU() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3617        "RNG peripheral singleton"] RNG <= LPPERI() (unstable)));
3618        _for_each_inner_peripheral!((@ peri_type #[doc = "SHA peripheral singleton"] SHA
3619        <= SHA(SHA : { bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt
3620        }) (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3621        "SLC peripheral singleton"] SLC <= SLC() (unstable)));
3622        _for_each_inner_peripheral!((@ peri_type #[doc = "SPI0 peripheral singleton"]
3623        SPI0 <= SPI0() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3624        "SPI1 peripheral singleton"] SPI1 <= SPI1() (unstable)));
3625        _for_each_inner_peripheral!((@ peri_type #[doc = "SPI2 peripheral singleton"]
3626        SPI2 <= SPI2(SPI2 : { bind_peri_interrupt, enable_peri_interrupt,
3627        disable_peri_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
3628        "SYSTEM peripheral singleton"] SYSTEM <= PCR() (unstable)));
3629        _for_each_inner_peripheral!((@ peri_type #[doc = "SYSTIMER peripheral singleton"]
3630        SYSTIMER <= SYSTIMER() (unstable))); _for_each_inner_peripheral!((@ peri_type
3631        #[doc = "TEE peripheral singleton"] TEE <= TEE() (unstable)));
3632        _for_each_inner_peripheral!((@ peri_type #[doc = "TIMG0 peripheral singleton"]
3633        TIMG0 <= TIMG0() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3634        "TIMG1 peripheral singleton"] TIMG1 <= TIMG1() (unstable)));
3635        _for_each_inner_peripheral!((@ peri_type #[doc = "UART0 peripheral singleton"]
3636        UART0 <= UART0(UART0 : { bind_peri_interrupt, enable_peri_interrupt,
3637        disable_peri_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
3638        "UART1 peripheral singleton"] UART1 <= UART1(UART1 : { bind_peri_interrupt,
3639        enable_peri_interrupt, disable_peri_interrupt })));
3640        _for_each_inner_peripheral!((@ peri_type #[doc = "UART2 peripheral singleton"]
3641        UART2 <= UART2(UART2 : { bind_peri_interrupt, enable_peri_interrupt,
3642        disable_peri_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
3643        "USB_DEVICE peripheral singleton"] USB_DEVICE <= USB_DEVICE(USB_DEVICE : {
3644        bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })
3645        (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3646        "ADC1 peripheral singleton"] ADC1 <= virtual() (unstable)));
3647        _for_each_inner_peripheral!((@ peri_type #[doc = "BT peripheral singleton"] BT <=
3648        virtual(LP_TIMER : { bind_lp_timer_interrupt, enable_lp_timer_interrupt,
3649        disable_lp_timer_interrupt }, BT_MAC : { bind_mac_interrupt,
3650        enable_mac_interrupt, disable_mac_interrupt }) (unstable)));
3651        _for_each_inner_peripheral!((@ peri_type #[doc = "FLASH peripheral singleton"]
3652        FLASH <= virtual() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3653        "GPIO_DEDICATED peripheral singleton"] GPIO_DEDICATED <= virtual() (unstable)));
3654        _for_each_inner_peripheral!((@ peri_type #[doc = "WIFI peripheral singleton"]
3655        WIFI <= virtual(WIFI_BB : { bind_bb_interrupt, enable_bb_interrupt,
3656        disable_bb_interrupt }, WIFI_MAC : { bind_mac_interrupt, enable_mac_interrupt,
3657        disable_mac_interrupt }, WIFI_PWR : { bind_pwr_interrupt, enable_pwr_interrupt,
3658        disable_pwr_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
3659        "PSRAM peripheral singleton"] PSRAM <= virtual() (unstable)));
3660        _for_each_inner_peripheral!((@ peri_type #[doc =
3661        "FROM_CPU_INTR0 peripheral singleton"] FROM_CPU_INTR0 <= virtual() (unstable)));
3662        _for_each_inner_peripheral!((@ peri_type #[doc =
3663        "FROM_CPU_INTR1 peripheral singleton"] FROM_CPU_INTR1 <= virtual() (unstable)));
3664        _for_each_inner_peripheral!((@ peri_type #[doc =
3665        "FROM_CPU_INTR2 peripheral singleton"] FROM_CPU_INTR2 <= virtual() (unstable)));
3666        _for_each_inner_peripheral!((@ peri_type #[doc =
3667        "FROM_CPU_INTR3 peripheral singleton"] FROM_CPU_INTR3 <= virtual() (unstable)));
3668        _for_each_inner_peripheral!((#[cfg(not(use_xtal32k))] GPIO0));
3669        _for_each_inner_peripheral!((#[cfg(not(use_xtal32k))] GPIO1));
3670        _for_each_inner_peripheral!((GPIO2)); _for_each_inner_peripheral!((GPIO3));
3671        _for_each_inner_peripheral!((GPIO4)); _for_each_inner_peripheral!((GPIO5));
3672        _for_each_inner_peripheral!((GPIO6)); _for_each_inner_peripheral!((GPIO7));
3673        _for_each_inner_peripheral!((GPIO8)); _for_each_inner_peripheral!((GPIO9));
3674        _for_each_inner_peripheral!((GPIO10)); _for_each_inner_peripheral!((GPIO11));
3675        _for_each_inner_peripheral!((GPIO12)); _for_each_inner_peripheral!((GPIO13));
3676        _for_each_inner_peripheral!((GPIO14)); _for_each_inner_peripheral!((GPIO15));
3677        _for_each_inner_peripheral!((GPIO16)); _for_each_inner_peripheral!((GPIO17));
3678        _for_each_inner_peripheral!((GPIO18)); _for_each_inner_peripheral!((GPIO19));
3679        _for_each_inner_peripheral!((GPIO20)); _for_each_inner_peripheral!((GPIO21));
3680        _for_each_inner_peripheral!((GPIO22)); _for_each_inner_peripheral!((GPIO23));
3681        _for_each_inner_peripheral!((GPIO24)); _for_each_inner_peripheral!((GPIO25));
3682        _for_each_inner_peripheral!((GPIO26)); _for_each_inner_peripheral!((GPIO27));
3683        _for_each_inner_peripheral!((GPIO28)); _for_each_inner_peripheral!((GPIO29));
3684        _for_each_inner_peripheral!((DMA_CH0(unstable)));
3685        _for_each_inner_peripheral!((DMA_CH1(unstable)));
3686        _for_each_inner_peripheral!((APB_SARADC(unstable)));
3687        _for_each_inner_peripheral!((ASSIST_DEBUG(unstable)));
3688        _for_each_inner_peripheral!((CLINT(unstable)));
3689        _for_each_inner_peripheral!((CACHE(unstable)));
3690        _for_each_inner_peripheral!((DMA(unstable)));
3691        _for_each_inner_peripheral!((ECC(unstable)));
3692        _for_each_inner_peripheral!((ECDSA(unstable)));
3693        _for_each_inner_peripheral!((EFUSE(unstable)));
3694        _for_each_inner_peripheral!((ETM(unstable)));
3695        _for_each_inner_peripheral!((GPIO(unstable)));
3696        _for_each_inner_peripheral!((GPIO_SD(unstable)));
3697        _for_each_inner_peripheral!((HP_APM(unstable)));
3698        _for_each_inner_peripheral!((HP_SYS(unstable)));
3699        _for_each_inner_peripheral!((I2C_ANA_MST(unstable)));
3700        _for_each_inner_peripheral!((I2C0));
3701        _for_each_inner_peripheral!((I2S0(unstable)));
3702        _for_each_inner_peripheral!((INTERRUPT_CORE0(unstable)));
3703        _for_each_inner_peripheral!((INTPRI(unstable)));
3704        _for_each_inner_peripheral!((IO_MUX(unstable)));
3705        _for_each_inner_peripheral!((LP_ANA(unstable)));
3706        _for_each_inner_peripheral!((LP_AON(unstable)));
3707        _for_each_inner_peripheral!((LP_APM(unstable)));
3708        _for_each_inner_peripheral!((LP_CLKRST(unstable)));
3709        _for_each_inner_peripheral!((LPWR(unstable)));
3710        _for_each_inner_peripheral!((LP_GPIO(unstable)));
3711        _for_each_inner_peripheral!((LP_IO_MUX(unstable)));
3712        _for_each_inner_peripheral!((LP_PERI(unstable)));
3713        _for_each_inner_peripheral!((LP_TEE(unstable)));
3714        _for_each_inner_peripheral!((RTC_TIMER(unstable)));
3715        _for_each_inner_peripheral!((LP_WDT(unstable)));
3716        _for_each_inner_peripheral!((MEM_MONITOR(unstable)));
3717        _for_each_inner_peripheral!((MODEM_LPCON(unstable)));
3718        _for_each_inner_peripheral!((MODEM_SYSCON(unstable)));
3719        _for_each_inner_peripheral!((PAU(unstable)));
3720        _for_each_inner_peripheral!((PCR(unstable)));
3721        _for_each_inner_peripheral!((PMU(unstable)));
3722        _for_each_inner_peripheral!((RNG(unstable)));
3723        _for_each_inner_peripheral!((SHA(unstable)));
3724        _for_each_inner_peripheral!((SLC(unstable)));
3725        _for_each_inner_peripheral!((SPI0(unstable)));
3726        _for_each_inner_peripheral!((SPI1(unstable)));
3727        _for_each_inner_peripheral!((SPI2));
3728        _for_each_inner_peripheral!((SYSTEM(unstable)));
3729        _for_each_inner_peripheral!((SYSTIMER(unstable)));
3730        _for_each_inner_peripheral!((TEE(unstable)));
3731        _for_each_inner_peripheral!((TIMG0(unstable)));
3732        _for_each_inner_peripheral!((TIMG1(unstable)));
3733        _for_each_inner_peripheral!((UART0)); _for_each_inner_peripheral!((UART1));
3734        _for_each_inner_peripheral!((UART2));
3735        _for_each_inner_peripheral!((USB_DEVICE(unstable)));
3736        _for_each_inner_peripheral!((ADC1(unstable)));
3737        _for_each_inner_peripheral!((BT(unstable)));
3738        _for_each_inner_peripheral!((FLASH(unstable)));
3739        _for_each_inner_peripheral!((GPIO_DEDICATED(unstable)));
3740        _for_each_inner_peripheral!((WIFI));
3741        _for_each_inner_peripheral!((PSRAM(unstable)));
3742        _for_each_inner_peripheral!((FROM_CPU_INTR0(unstable)));
3743        _for_each_inner_peripheral!((FROM_CPU_INTR1(unstable)));
3744        _for_each_inner_peripheral!((FROM_CPU_INTR2(unstable)));
3745        _for_each_inner_peripheral!((FROM_CPU_INTR3(unstable)));
3746        _for_each_inner_peripheral!((SPI2, Spi2, 1, AhbGdmaChannel));
3747        _for_each_inner_peripheral!((I2S0, I2s0, 3, AhbGdmaChannel));
3748        _for_each_inner_peripheral!((SHA, Sha, 7, AhbGdmaChannel));
3749        _for_each_inner_peripheral!((all(@ peri_type #[doc =
3750        "GPIO0 peripheral singleton"] GPIO0 <= virtual()), (@ peri_type #[doc =
3751        "GPIO1 peripheral singleton"] GPIO1 <= virtual()), (@ peri_type #[doc =
3752        "GPIO2 peripheral singleton"] GPIO2 <= virtual()), (@ peri_type #[doc =
3753        "GPIO3 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3754        "<section class=\"warning\">"] #[doc =
3755        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3756        #[doc = "<ul>"] #[doc =
3757        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
3758        =
3759        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3760        #[doc = "</ul>"] #[doc = "</section>"] GPIO3 <= virtual()), (@ peri_type #[doc =
3761        "GPIO4 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3762        "<section class=\"warning\">"] #[doc =
3763        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3764        #[doc = "<ul>"] #[doc =
3765        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
3766        =
3767        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3768        #[doc = "</ul>"] #[doc = "</section>"] GPIO4 <= virtual()), (@ peri_type #[doc =
3769        "GPIO5 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3770        "<section class=\"warning\">"] #[doc =
3771        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3772        #[doc = "<ul>"] #[doc =
3773        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3774        #[doc = "</ul>"] #[doc = "</section>"] GPIO5 <= virtual()), (@ peri_type #[doc =
3775        "GPIO6 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3776        "<section class=\"warning\">"] #[doc =
3777        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3778        #[doc = "<ul>"] #[doc =
3779        "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3780        #[doc = "</ul>"] #[doc = "</section>"] GPIO6 <= virtual()), (@ peri_type #[doc =
3781        "GPIO7 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3782        "<section class=\"warning\">"] #[doc =
3783        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3784        #[doc = "<ul>"] #[doc =
3785        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
3786        = "</ul>"] #[doc = "</section>"] GPIO7 <= virtual()), (@ peri_type #[doc =
3787        "GPIO8 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3788        "<section class=\"warning\">"] #[doc =
3789        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3790        #[doc = "<ul>"] #[doc =
3791        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
3792        = "</ul>"] #[doc = "</section>"] GPIO8 <= virtual()), (@ peri_type #[doc =
3793        "GPIO9 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3794        "<section class=\"warning\">"] #[doc =
3795        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3796        #[doc = "<ul>"] #[doc =
3797        "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
3798        = "</ul>"] #[doc = "</section>"] GPIO9 <= virtual()), (@ peri_type #[doc =
3799        "GPIO10 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3800        "<section class=\"warning\">"] #[doc =
3801        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3802        #[doc = "<ul>"] #[doc =
3803        "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
3804        = "</ul>"] #[doc = "</section>"] GPIO10 <= virtual()), (@ peri_type #[doc =
3805        "GPIO11 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3806        "<section class=\"warning\">"] #[doc =
3807        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3808        #[doc = "<ul>"] #[doc =
3809        "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
3810        = "</ul>"] #[doc = "</section>"] GPIO11 <= virtual()), (@ peri_type #[doc =
3811        "GPIO12 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3812        "<section class=\"warning\">"] #[doc =
3813        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3814        #[doc = "<ul>"] #[doc =
3815        "<li>These pins may be used to debug the chip using USB.</li>"] #[doc = "</ul>"]
3816        #[doc = "</section>"] GPIO12 <= virtual()), (@ peri_type #[doc =
3817        "GPIO13 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3818        "<section class=\"warning\">"] #[doc =
3819        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3820        #[doc = "<ul>"] #[doc =
3821        "<li>These pins may be used to debug the chip using USB.</li>"] #[doc = "</ul>"]
3822        #[doc = "</section>"] GPIO13 <= virtual()), (@ peri_type #[doc =
3823        "GPIO14 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3824        "<section class=\"warning\">"] #[doc =
3825        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3826        #[doc = "<ul>"] #[doc =
3827        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
3828        "</ul>"] #[doc = "</section>"] GPIO14 <= virtual()), (@ peri_type #[doc =
3829        "GPIO15 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3830        "<section class=\"warning\">"] #[doc =
3831        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3832        #[doc = "<ul>"] #[doc =
3833        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3834        "</ul>"] #[doc = "</section>"] GPIO15 <= virtual()), (@ peri_type #[doc =
3835        "GPIO16 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3836        "<section class=\"warning\">"] #[doc =
3837        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3838        #[doc = "<ul>"] #[doc =
3839        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3840        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
3841        "</ul>"] #[doc = "</section>"] GPIO16 <= virtual()), (@ peri_type #[doc =
3842        "GPIO17 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3843        "<section class=\"warning\">"] #[doc =
3844        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3845        #[doc = "<ul>"] #[doc =
3846        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3847        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
3848        "</ul>"] #[doc = "</section>"] GPIO17 <= virtual()), (@ peri_type #[doc =
3849        "GPIO18 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3850        "<section class=\"warning\">"] #[doc =
3851        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3852        #[doc = "<ul>"] #[doc =
3853        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3854        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
3855        "</ul>"] #[doc = "</section>"] GPIO18 <= virtual()), (@ peri_type #[doc =
3856        "GPIO19 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3857        "<section class=\"warning\">"] #[doc =
3858        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3859        #[doc = "<ul>"] #[doc =
3860        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3861        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
3862        "</ul>"] #[doc = "</section>"] GPIO19 <= virtual()), (@ peri_type #[doc =
3863        "GPIO20 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3864        "<section class=\"warning\">"] #[doc =
3865        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3866        #[doc = "<ul>"] #[doc =
3867        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3868        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
3869        "</ul>"] #[doc = "</section>"] GPIO20 <= virtual()), (@ peri_type #[doc =
3870        "GPIO21 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3871        "<section class=\"warning\">"] #[doc =
3872        "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3873        #[doc = "<ul>"] #[doc =
3874        "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3875        "<li>This pin may be reserved for interfacing with SPI PSRAM.</li>"] #[doc =
3876        "</ul>"] #[doc = "</section>"] GPIO21 <= virtual()), (@ peri_type #[doc =
3877        "GPIO22 peripheral singleton"] GPIO22 <= virtual()), (@ peri_type #[doc =
3878        "GPIO23 peripheral singleton"] GPIO23 <= virtual()), (@ peri_type #[doc =
3879        "GPIO24 peripheral singleton"] GPIO24 <= virtual()), (@ peri_type #[doc =
3880        "GPIO25 peripheral singleton"] GPIO25 <= virtual()), (@ peri_type #[doc =
3881        "GPIO26 peripheral singleton"] GPIO26 <= virtual()), (@ peri_type #[doc =
3882        "GPIO27 peripheral singleton"] GPIO27 <= virtual()), (@ peri_type #[doc =
3883        "GPIO28 peripheral singleton"] GPIO28 <= virtual()), (@ peri_type #[doc =
3884        "GPIO29 peripheral singleton"] GPIO29 <= virtual()), (@ peri_type #[doc =
3885        "DMA_CH0 peripheral singleton"] DMA_CH0 <= virtual(DMA_IN_CH0 : {
3886        bind_dma_in_interrupt, enable_dma_in_interrupt, disable_dma_in_interrupt },
3887        DMA_OUT_CH0 : { bind_dma_out_interrupt, enable_dma_out_interrupt,
3888        disable_dma_out_interrupt }) (unstable)), (@ peri_type #[doc =
3889        "DMA_CH1 peripheral singleton"] DMA_CH1 <= virtual(DMA_IN_CH1 : {
3890        bind_dma_in_interrupt, enable_dma_in_interrupt, disable_dma_in_interrupt },
3891        DMA_OUT_CH1 : { bind_dma_out_interrupt, enable_dma_out_interrupt,
3892        disable_dma_out_interrupt }) (unstable)), (@ peri_type #[doc =
3893        "APB_SARADC peripheral singleton"] APB_SARADC <= APB_SARADC() (unstable)), (@
3894        peri_type #[doc = "ASSIST_DEBUG peripheral singleton"] ASSIST_DEBUG <=
3895        ASSIST_DEBUG() (unstable)), (@ peri_type #[doc = "CLINT peripheral singleton"]
3896        CLINT <= CLINT() (unstable)), (@ peri_type #[doc = "CACHE peripheral singleton"]
3897        CACHE <= CACHE() (unstable)), (@ peri_type #[doc = "DMA peripheral singleton"]
3898        DMA <= DMA() (unstable)), (@ peri_type #[doc = "ECC peripheral singleton"] ECC <=
3899        ECC() (unstable)), (@ peri_type #[doc = "ECDSA peripheral singleton"] ECDSA <=
3900        ECDSA() (unstable)), (@ peri_type #[doc = "EFUSE peripheral singleton"] EFUSE <=
3901        EFUSE() (unstable)), (@ peri_type #[doc = "ETM peripheral singleton"] ETM <=
3902        SOC_ETM() (unstable)), (@ peri_type #[doc = "GPIO peripheral singleton"] GPIO <=
3903        GPIO() (unstable)), (@ peri_type #[doc = "GPIO_SD peripheral singleton"] GPIO_SD
3904        <= GPIO_EXT() (unstable)), (@ peri_type #[doc = "HP_APM peripheral singleton"]
3905        HP_APM <= HP_APM() (unstable)), (@ peri_type #[doc =
3906        "HP_SYS peripheral singleton"] HP_SYS <= HP_SYS() (unstable)), (@ peri_type #[doc
3907        = "I2C_ANA_MST peripheral singleton"] I2C_ANA_MST <= I2C_ANA_MST() (unstable)),
3908        (@ peri_type #[doc = "I2C0 peripheral singleton"] I2C0 <= I2C0(I2C_EXT0 : {
3909        bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })), (@
3910        peri_type #[doc = "I2S0 peripheral singleton"] I2S0 <= I2S0(I2S0 : {
3911        bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })
3912        (unstable)), (@ peri_type #[doc = "INTERRUPT_CORE0 peripheral singleton"]
3913        INTERRUPT_CORE0 <= INTERRUPT_CORE0() (unstable)), (@ peri_type #[doc =
3914        "INTPRI peripheral singleton"] INTPRI <= INTPRI() (unstable)), (@ peri_type #[doc
3915        = "IO_MUX peripheral singleton"] IO_MUX <= IO_MUX() (unstable)), (@ peri_type
3916        #[doc = "LP_ANA peripheral singleton"] LP_ANA <= LP_ANA() (unstable)), (@
3917        peri_type #[doc = "LP_AON peripheral singleton"] LP_AON <= LP_AON() (unstable)),
3918        (@ peri_type #[doc = "LP_APM peripheral singleton"] LP_APM <= LP_APM()
3919        (unstable)), (@ peri_type #[doc = "LP_CLKRST peripheral singleton"] LP_CLKRST <=
3920        LP_CLKRST() (unstable)), (@ peri_type #[doc = "LPWR peripheral singleton"] LPWR
3921        <= LP_CLKRST() (unstable)), (@ peri_type #[doc = "LP_GPIO peripheral singleton"]
3922        LP_GPIO <= LP_GPIO() (unstable)), (@ peri_type #[doc =
3923        "LP_IO_MUX peripheral singleton"] LP_IO_MUX <= LP_IO_MUX() (unstable)), (@
3924        peri_type #[doc = "LP_PERI peripheral singleton"] LP_PERI <= LPPERI()
3925        (unstable)), (@ peri_type #[doc = "LP_TEE peripheral singleton"] LP_TEE <=
3926        LP_TEE() (unstable)), (@ peri_type #[doc = "RTC_TIMER peripheral singleton"]
3927        RTC_TIMER <= LP_TIMER() (unstable)), (@ peri_type #[doc =
3928        "LP_WDT peripheral singleton"] LP_WDT <= LP_WDT() (unstable)), (@ peri_type #[doc
3929        = "MEM_MONITOR peripheral singleton"] MEM_MONITOR <= MEM_MONITOR() (unstable)),
3930        (@ peri_type #[doc = "MODEM_LPCON peripheral singleton"] MODEM_LPCON <=
3931        MODEM_LPCON() (unstable)), (@ peri_type #[doc =
3932        "MODEM_SYSCON peripheral singleton"] MODEM_SYSCON <= MODEM_SYSCON() (unstable)),
3933        (@ peri_type #[doc = "PAU peripheral singleton"] PAU <= PAU() (unstable)), (@
3934        peri_type #[doc = "PCR peripheral singleton"] PCR <= PCR() (unstable)), (@
3935        peri_type #[doc = "PMU peripheral singleton"] PMU <= PMU() (unstable)), (@
3936        peri_type #[doc = "RNG peripheral singleton"] RNG <= LPPERI() (unstable)), (@
3937        peri_type #[doc = "SHA peripheral singleton"] SHA <= SHA(SHA : {
3938        bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })
3939        (unstable)), (@ peri_type #[doc = "SLC peripheral singleton"] SLC <= SLC()
3940        (unstable)), (@ peri_type #[doc = "SPI0 peripheral singleton"] SPI0 <= SPI0()
3941        (unstable)), (@ peri_type #[doc = "SPI1 peripheral singleton"] SPI1 <= SPI1()
3942        (unstable)), (@ peri_type #[doc = "SPI2 peripheral singleton"] SPI2 <= SPI2(SPI2
3943        : { bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })), (@
3944        peri_type #[doc = "SYSTEM peripheral singleton"] SYSTEM <= PCR() (unstable)), (@
3945        peri_type #[doc = "SYSTIMER peripheral singleton"] SYSTIMER <= SYSTIMER()
3946        (unstable)), (@ peri_type #[doc = "TEE peripheral singleton"] TEE <= TEE()
3947        (unstable)), (@ peri_type #[doc = "TIMG0 peripheral singleton"] TIMG0 <= TIMG0()
3948        (unstable)), (@ peri_type #[doc = "TIMG1 peripheral singleton"] TIMG1 <= TIMG1()
3949        (unstable)), (@ peri_type #[doc = "UART0 peripheral singleton"] UART0 <=
3950        UART0(UART0 : { bind_peri_interrupt, enable_peri_interrupt,
3951        disable_peri_interrupt })), (@ peri_type #[doc = "UART1 peripheral singleton"]
3952        UART1 <= UART1(UART1 : { bind_peri_interrupt, enable_peri_interrupt,
3953        disable_peri_interrupt })), (@ peri_type #[doc = "UART2 peripheral singleton"]
3954        UART2 <= UART2(UART2 : { bind_peri_interrupt, enable_peri_interrupt,
3955        disable_peri_interrupt })), (@ peri_type #[doc =
3956        "USB_DEVICE peripheral singleton"] USB_DEVICE <= USB_DEVICE(USB_DEVICE : {
3957        bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })
3958        (unstable)), (@ peri_type #[doc = "ADC1 peripheral singleton"] ADC1 <= virtual()
3959        (unstable)), (@ peri_type #[doc = "BT peripheral singleton"] BT <=
3960        virtual(LP_TIMER : { bind_lp_timer_interrupt, enable_lp_timer_interrupt,
3961        disable_lp_timer_interrupt }, BT_MAC : { bind_mac_interrupt,
3962        enable_mac_interrupt, disable_mac_interrupt }) (unstable)), (@ peri_type #[doc =
3963        "FLASH peripheral singleton"] FLASH <= virtual() (unstable)), (@ peri_type #[doc
3964        = "GPIO_DEDICATED peripheral singleton"] GPIO_DEDICATED <= virtual() (unstable)),
3965        (@ peri_type #[doc = "WIFI peripheral singleton"] WIFI <= virtual(WIFI_BB : {
3966        bind_bb_interrupt, enable_bb_interrupt, disable_bb_interrupt }, WIFI_MAC : {
3967        bind_mac_interrupt, enable_mac_interrupt, disable_mac_interrupt }, WIFI_PWR : {
3968        bind_pwr_interrupt, enable_pwr_interrupt, disable_pwr_interrupt })), (@ peri_type
3969        #[doc = "PSRAM peripheral singleton"] PSRAM <= virtual() (unstable)), (@
3970        peri_type #[doc = "FROM_CPU_INTR0 peripheral singleton"] FROM_CPU_INTR0 <=
3971        virtual() (unstable)), (@ peri_type #[doc =
3972        "FROM_CPU_INTR1 peripheral singleton"] FROM_CPU_INTR1 <= virtual() (unstable)),
3973        (@ peri_type #[doc = "FROM_CPU_INTR2 peripheral singleton"] FROM_CPU_INTR2 <=
3974        virtual() (unstable)), (@ peri_type #[doc =
3975        "FROM_CPU_INTR3 peripheral singleton"] FROM_CPU_INTR3 <= virtual() (unstable))));
3976        _for_each_inner_peripheral!((singletons(#[cfg(not(use_xtal32k))] GPIO0),
3977        (#[cfg(not(use_xtal32k))] GPIO1), (GPIO2), (GPIO3), (GPIO4), (GPIO5), (GPIO6),
3978        (GPIO7), (GPIO8), (GPIO9), (GPIO10), (GPIO11), (GPIO12), (GPIO13), (GPIO14),
3979        (GPIO15), (GPIO16), (GPIO17), (GPIO18), (GPIO19), (GPIO20), (GPIO21), (GPIO22),
3980        (GPIO23), (GPIO24), (GPIO25), (GPIO26), (GPIO27), (GPIO28), (GPIO29),
3981        (DMA_CH0(unstable)), (DMA_CH1(unstable)), (APB_SARADC(unstable)),
3982        (ASSIST_DEBUG(unstable)), (CLINT(unstable)), (CACHE(unstable)), (DMA(unstable)),
3983        (ECC(unstable)), (ECDSA(unstable)), (EFUSE(unstable)), (ETM(unstable)),
3984        (GPIO(unstable)), (GPIO_SD(unstable)), (HP_APM(unstable)), (HP_SYS(unstable)),
3985        (I2C_ANA_MST(unstable)), (I2C0), (I2S0(unstable)), (INTERRUPT_CORE0(unstable)),
3986        (INTPRI(unstable)), (IO_MUX(unstable)), (LP_ANA(unstable)), (LP_AON(unstable)),
3987        (LP_APM(unstable)), (LP_CLKRST(unstable)), (LPWR(unstable)), (LP_GPIO(unstable)),
3988        (LP_IO_MUX(unstable)), (LP_PERI(unstable)), (LP_TEE(unstable)),
3989        (RTC_TIMER(unstable)), (LP_WDT(unstable)), (MEM_MONITOR(unstable)),
3990        (MODEM_LPCON(unstable)), (MODEM_SYSCON(unstable)), (PAU(unstable)),
3991        (PCR(unstable)), (PMU(unstable)), (RNG(unstable)), (SHA(unstable)),
3992        (SLC(unstable)), (SPI0(unstable)), (SPI1(unstable)), (SPI2), (SYSTEM(unstable)),
3993        (SYSTIMER(unstable)), (TEE(unstable)), (TIMG0(unstable)), (TIMG1(unstable)),
3994        (UART0), (UART1), (UART2), (USB_DEVICE(unstable)), (ADC1(unstable)),
3995        (BT(unstable)), (FLASH(unstable)), (GPIO_DEDICATED(unstable)), (WIFI),
3996        (PSRAM(unstable)), (FROM_CPU_INTR0(unstable)), (FROM_CPU_INTR1(unstable)),
3997        (FROM_CPU_INTR2(unstable)), (FROM_CPU_INTR3(unstable))));
3998        _for_each_inner_peripheral!((dma_eligible(SPI2, Spi2, 1, AhbGdmaChannel), (I2S0,
3999        I2s0, 3, AhbGdmaChannel), (SHA, Sha, 7, AhbGdmaChannel)));
4000    };
4001}
4002/// This macro can be used to generate code for each `GPIOn` instance.
4003///
4004/// For an explanation on the general syntax, as well as usage of individual/repeated
4005/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
4006///
4007/// This macro has one option for its "Individual matcher" case:
4008///
4009/// Syntax: `($n:literal, $gpio:ident ($($digital_input_function:ident =>
4010/// $digital_input_signal:ident)*) ($($digital_output_function:ident =>
4011/// $digital_output_signal:ident)*) ($([$pin_attribute:ident])*))`
4012///
4013/// Macro fragments:
4014///
4015/// - `$n`: the number of the GPIO. For `GPIO0`, `$n` is 0.
4016/// - `$gpio`: the name of the GPIO.
4017/// - `$digital_input_function`: the number of the digital function, as an identifier (i.e. for
4018///   function 0 this is `_0`).
4019/// - `$digital_input_function`: the name of the digital function, as an identifier.
4020/// - `$digital_output_function`: the number of the digital function, as an identifier (i.e. for
4021///   function 0 this is `_0`).
4022/// - `$digital_output_function`: the name of the digital function, as an identifier.
4023/// - `$pin_attribute`: `Input` and/or `Output`, marks the possible directions of the GPIO.
4024///   Bracketed so that they can also be matched as optional fragments. Order is always Input first.
4025///
4026/// Example data: `(0, GPIO0 (_5 => EMAC_TX_CLK) (_1 => CLK_OUT1 _5 => EMAC_TX_CLK) ([Input]
4027/// [Output]))`
4028#[macro_export]
4029#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4030macro_rules! for_each_gpio {
4031    ($($pattern:tt => $code:tt;)*) => {
4032        macro_rules! _for_each_inner_gpio { $(($pattern) => $code;)* ($other : tt) => {}
4033        } _for_each_inner_gpio!((0, GPIO0() () ([Input] [Output])));
4034        _for_each_inner_gpio!((1, GPIO1() () ([Input] [Output])));
4035        _for_each_inner_gpio!((2, GPIO2(_2 => FSPIQ) (_2 => FSPIQ) ([Input] [Output])));
4036        _for_each_inner_gpio!((3, GPIO3(_0 => MTMS _2 => FSPIHD) (_2 => FSPIHD) ([Input]
4037        [Output]))); _for_each_inner_gpio!((4, GPIO4(_0 => MTDI _2 => FSPIWP) (_2 =>
4038        FSPIWP) ([Input] [Output]))); _for_each_inner_gpio!((5, GPIO5(_0 => MTCK) ()
4039        ([Input] [Output]))); _for_each_inner_gpio!((6, GPIO6(_0 => MTDO _2 => FSPICLK)
4040        (_2 => FSPICLK) ([Input] [Output]))); _for_each_inner_gpio!((7, GPIO7(_2 =>
4041        FSPID) (_2 => FSPID) ([Input] [Output]))); _for_each_inner_gpio!((8, GPIO8(_2 =>
4042        FSPICS0) (_2 => FSPICS0) ([Input] [Output]))); _for_each_inner_gpio!((9, GPIO9()
4043        () ([Input] [Output]))); _for_each_inner_gpio!((10, GPIO10(_0 => U0RXD) ()
4044        ([Input] [Output]))); _for_each_inner_gpio!((11, GPIO11() (_0 => U0TXD) ([Input]
4045        [Output]))); _for_each_inner_gpio!((12, GPIO12() () ([Input] [Output])));
4046        _for_each_inner_gpio!((13, GPIO13() () ([Input] [Output])));
4047        _for_each_inner_gpio!((14, GPIO14() (_0 => FSPICS1) ([Input] [Output])));
4048        _for_each_inner_gpio!((15, GPIO15(_0 => FSPICS0) (_0 => FSPICS0) ([Input]
4049        [Output]))); _for_each_inner_gpio!((16, GPIO16(_0 => FSPIQ) (_0 => FSPIQ)
4050        ([Input] [Output]))); _for_each_inner_gpio!((17, GPIO17(_0 => FSPIWP) (_0 =>
4051        FSPIWP) ([Input] [Output]))); _for_each_inner_gpio!((18, GPIO18() () ([Input]
4052        [Output]))); _for_each_inner_gpio!((19, GPIO19(_0 => FSPIHD) (_0 => FSPIHD)
4053        ([Input] [Output]))); _for_each_inner_gpio!((20, GPIO20(_0 => FSPICLK) (_0 =>
4054        FSPICLK) ([Input] [Output]))); _for_each_inner_gpio!((21, GPIO21(_0 => FSPID) (_0
4055        => FSPID) ([Input] [Output]))); _for_each_inner_gpio!((22, GPIO22(_0 =>
4056        SDIO_DATA2) () ([Input] [Output]))); _for_each_inner_gpio!((23, GPIO23(_0 =>
4057        SDIO_DATA3) () ([Input] [Output]))); _for_each_inner_gpio!((24, GPIO24() ()
4058        ([Input] [Output]))); _for_each_inner_gpio!((25, GPIO25(_0 => SDIO_CMD) ()
4059        ([Input] [Output]))); _for_each_inner_gpio!((26, GPIO26(_0 => SDIO_CLK) ()
4060        ([Input] [Output]))); _for_each_inner_gpio!((27, GPIO27(_0 => SDIO_DATA0) ()
4061        ([Input] [Output]))); _for_each_inner_gpio!((28, GPIO28(_0 => SDIO_DATA1) ()
4062        ([Input] [Output]))); _for_each_inner_gpio!((29, GPIO29() () ([Input]
4063        [Output]))); _for_each_inner_gpio!((all(0, GPIO0() () ([Input] [Output])), (1,
4064        GPIO1() () ([Input] [Output])), (2, GPIO2(_2 => FSPIQ) (_2 => FSPIQ) ([Input]
4065        [Output])), (3, GPIO3(_0 => MTMS _2 => FSPIHD) (_2 => FSPIHD) ([Input]
4066        [Output])), (4, GPIO4(_0 => MTDI _2 => FSPIWP) (_2 => FSPIWP) ([Input]
4067        [Output])), (5, GPIO5(_0 => MTCK) () ([Input] [Output])), (6, GPIO6(_0 => MTDO _2
4068        => FSPICLK) (_2 => FSPICLK) ([Input] [Output])), (7, GPIO7(_2 => FSPID) (_2 =>
4069        FSPID) ([Input] [Output])), (8, GPIO8(_2 => FSPICS0) (_2 => FSPICS0) ([Input]
4070        [Output])), (9, GPIO9() () ([Input] [Output])), (10, GPIO10(_0 => U0RXD) ()
4071        ([Input] [Output])), (11, GPIO11() (_0 => U0TXD) ([Input] [Output])), (12,
4072        GPIO12() () ([Input] [Output])), (13, GPIO13() () ([Input] [Output])), (14,
4073        GPIO14() (_0 => FSPICS1) ([Input] [Output])), (15, GPIO15(_0 => FSPICS0) (_0 =>
4074        FSPICS0) ([Input] [Output])), (16, GPIO16(_0 => FSPIQ) (_0 => FSPIQ) ([Input]
4075        [Output])), (17, GPIO17(_0 => FSPIWP) (_0 => FSPIWP) ([Input] [Output])), (18,
4076        GPIO18() () ([Input] [Output])), (19, GPIO19(_0 => FSPIHD) (_0 => FSPIHD)
4077        ([Input] [Output])), (20, GPIO20(_0 => FSPICLK) (_0 => FSPICLK) ([Input]
4078        [Output])), (21, GPIO21(_0 => FSPID) (_0 => FSPID) ([Input] [Output])), (22,
4079        GPIO22(_0 => SDIO_DATA2) () ([Input] [Output])), (23, GPIO23(_0 => SDIO_DATA3) ()
4080        ([Input] [Output])), (24, GPIO24() () ([Input] [Output])), (25, GPIO25(_0 =>
4081        SDIO_CMD) () ([Input] [Output])), (26, GPIO26(_0 => SDIO_CLK) () ([Input]
4082        [Output])), (27, GPIO27(_0 => SDIO_DATA0) () ([Input] [Output])), (28, GPIO28(_0
4083        => SDIO_DATA1) () ([Input] [Output])), (29, GPIO29() () ([Input] [Output]))));
4084    };
4085}
4086/// This macro can be used to generate code for each analog function of each GPIO.
4087///
4088/// For an explanation on the general syntax, as well as usage of individual/repeated
4089/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
4090///
4091/// This macro has two options for its "Individual matcher" case:
4092///
4093/// - `all`: `($signal:ident, $gpio:ident)` - simple case where you only need identifiers
4094/// - group: `(($signal:ident, $group:ident $(, $number:literal)+), $gpio:ident)` - expanded signal
4095///   case, where you need the number(s) of a signal, or the general group to which the signal
4096///   belongs. For example, in case of `ADC2_CH3` the expanded form looks like `(ADC2_CH3, ADCn_CHm,
4097///   2, 3)`.
4098///
4099/// Macro fragments:
4100///
4101/// - `$signal`: the name of the signal.
4102/// - `$group`: the name of the signal, with numbers replaced by placeholders. For `ADC2_CH3` this
4103///   is `ADCn_CHm`.
4104/// - `$number`: the numbers extracted from `$signal`.
4105/// - `$gpio`: the name of the GPIO.
4106///
4107/// Example data:
4108/// - `(ADC2_CH5, GPIO12)`
4109/// - `((ADC2_CH5, ADCn_CHm, 2, 5), GPIO12)`
4110///
4111/// The expanded syntax is only available when the signal has at least one numbered component.
4112#[macro_export]
4113#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4114macro_rules! for_each_analog_function {
4115    ($($pattern:tt => $code:tt;)*) => {
4116        macro_rules! _for_each_inner_analog_function { $(($pattern) => $code;)* ($other :
4117        tt) => {} } _for_each_inner_analog_function!((XTAL_32K_P, GPIO0));
4118        _for_each_inner_analog_function!((XTAL_32K_N, GPIO1));
4119        _for_each_inner_analog_function!((ADC1_CH0, GPIO1));
4120        _for_each_inner_analog_function!((ADC1_CH1, GPIO3));
4121        _for_each_inner_analog_function!((ADC1_CH2, GPIO4));
4122        _for_each_inner_analog_function!((ADC1_CH3, GPIO5));
4123        _for_each_inner_analog_function!((ZCD0, GPIO8));
4124        _for_each_inner_analog_function!((ZCD1, GPIO9));
4125        _for_each_inner_analog_function!((USJ_DM, GPIO12));
4126        _for_each_inner_analog_function!((USJ_DP, GPIO13));
4127        _for_each_inner_analog_function!(((ADC1_CH0, ADCn_CHm, 1, 0), GPIO1));
4128        _for_each_inner_analog_function!(((ADC1_CH1, ADCn_CHm, 1, 1), GPIO3));
4129        _for_each_inner_analog_function!(((ADC1_CH2, ADCn_CHm, 1, 2), GPIO4));
4130        _for_each_inner_analog_function!(((ADC1_CH3, ADCn_CHm, 1, 3), GPIO5));
4131        _for_each_inner_analog_function!(((ZCD0, ZCDn, 0), GPIO8));
4132        _for_each_inner_analog_function!(((ZCD1, ZCDn, 1), GPIO9));
4133        _for_each_inner_analog_function!((all(XTAL_32K_P, GPIO0), (XTAL_32K_N, GPIO1),
4134        (ADC1_CH0, GPIO1), (ADC1_CH1, GPIO3), (ADC1_CH2, GPIO4), (ADC1_CH3, GPIO5),
4135        (ZCD0, GPIO8), (ZCD1, GPIO9), (USJ_DM, GPIO12), (USJ_DP, GPIO13)));
4136        _for_each_inner_analog_function!((ADCn_CHm((ADC1_CH0, ADCn_CHm, 1, 0), GPIO1),
4137        ((ADC1_CH1, ADCn_CHm, 1, 1), GPIO3), ((ADC1_CH2, ADCn_CHm, 1, 2), GPIO4),
4138        ((ADC1_CH3, ADCn_CHm, 1, 3), GPIO5)));
4139        _for_each_inner_analog_function!((ZCDn((ZCD0, ZCDn, 0), GPIO8), ((ZCD1, ZCDn, 1),
4140        GPIO9)));
4141    };
4142}
4143/// This macro can be used to generate code for each LP function of each GPIO.
4144///
4145/// For an explanation on the general syntax, as well as usage of individual/repeated
4146/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
4147///
4148/// This macro has two options for its "Individual matcher" case:
4149///
4150/// - `all`: `($signal:ident, $gpio:ident, $af:ident)` - simple case where you only need
4151///   identifiers, and maybe the function.
4152/// - group: `(($signal:ident, $group:ident $(, $number:literal)+), $gpio:ident, $af:ident, ($(
4153///   $lp_input_af:ident => $lp_input_signal:ident )*) ($( $lp_output_af:ident =>
4154///   $lp_output_signal:ident )*))` - expanded signal case, where you need the number(s) of a
4155///   signal, or the general group to which the signal belongs. Every expanded branch ends with the
4156///   pad's LP input and output function groups (empty on chips without an LP GPIO matrix).
4157///
4158/// Macro fragments:
4159///
4160/// - `$signal`: the name of the signal.
4161/// - `$group`: the name of the signal, with numbers replaced by placeholders. For `ADC2_CH3` this
4162///   is `ADCn_CHm`.
4163/// - `$number`: the numbers extracted from `$signal`.
4164/// - `$gpio`: the name of the GPIO.
4165/// - `$af`: the LP IO MUX function, as an identifier (i.e. for function 0 this is `_0`). This is
4166///   the name of an `LpFunction` variant, and its number is the value to write to the pad's
4167///   function select field.
4168/// - `$lp_input_af`: the LP IO MUX function for an LP peripheral input on this pad.
4169/// - `$lp_input_signal`: the LP peripheral input signal name.
4170/// - `$lp_output_af`: the LP IO MUX function for an LP peripheral output on this pad.
4171/// - `$lp_output_signal`: the LP peripheral output signal name.
4172///
4173/// Example data:
4174/// - `(LP_GPIO15, GPIO12, _0)`
4175/// - `((LP_GPIO15, LP_GPIOn, 15), GPIO12, _0, () ())`
4176/// - `((LP_GPIO14, LP_GPIOn, 14), GPIO14, _1, () (_0 => LP_UART_TXD))`
4177/// - `((SAR_I2C_SCL_1, SAR_I2C_SCL_n, 1), GPIO2, _3, () ())`
4178///
4179/// The expanded syntax is only available when the signal has at least one numbered component.
4180#[macro_export]
4181#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4182macro_rules! for_each_lp_function {
4183    ($($pattern:tt => $code:tt;)*) => {
4184        macro_rules! _for_each_inner_lp_function { $(($pattern) => $code;)* ($other : tt)
4185        => {} } _for_each_inner_lp_function!((LP_GPIO0, GPIO0, _1));
4186        _for_each_inner_lp_function!((LP_GPIO1, GPIO1, _1));
4187        _for_each_inner_lp_function!((LP_GPIO2, GPIO2, _1));
4188        _for_each_inner_lp_function!((LP_GPIO3, GPIO3, _1));
4189        _for_each_inner_lp_function!((LP_GPIO4, GPIO4, _1));
4190        _for_each_inner_lp_function!((LP_GPIO5, GPIO5, _1));
4191        _for_each_inner_lp_function!((LP_GPIO6, GPIO6, _1));
4192        _for_each_inner_lp_function!(((LP_GPIO0, LP_GPIOn, 0), GPIO0, _1, () ()));
4193        _for_each_inner_lp_function!(((LP_GPIO1, LP_GPIOn, 1), GPIO1, _1, () ()));
4194        _for_each_inner_lp_function!(((LP_GPIO2, LP_GPIOn, 2), GPIO2, _1, () ()));
4195        _for_each_inner_lp_function!(((LP_GPIO3, LP_GPIOn, 3), GPIO3, _1, () ()));
4196        _for_each_inner_lp_function!(((LP_GPIO4, LP_GPIOn, 4), GPIO4, _1, () ()));
4197        _for_each_inner_lp_function!(((LP_GPIO5, LP_GPIOn, 5), GPIO5, _1, () ()));
4198        _for_each_inner_lp_function!(((LP_GPIO6, LP_GPIOn, 6), GPIO6, _1, () ()));
4199        _for_each_inner_lp_function!((all(LP_GPIO0, GPIO0, _1), (LP_GPIO1, GPIO1, _1),
4200        (LP_GPIO2, GPIO2, _1), (LP_GPIO3, GPIO3, _1), (LP_GPIO4, GPIO4, _1), (LP_GPIO5,
4201        GPIO5, _1), (LP_GPIO6, GPIO6, _1)));
4202        _for_each_inner_lp_function!((LP_GPIOn((LP_GPIO0, LP_GPIOn, 0), GPIO0, _1, ()
4203        ()), ((LP_GPIO1, LP_GPIOn, 1), GPIO1, _1, () ()), ((LP_GPIO2, LP_GPIOn, 2),
4204        GPIO2, _1, () ()), ((LP_GPIO3, LP_GPIOn, 3), GPIO3, _1, () ()), ((LP_GPIO4,
4205        LP_GPIOn, 4), GPIO4, _1, () ()), ((LP_GPIO5, LP_GPIOn, 5), GPIO5, _1, () ()),
4206        ((LP_GPIO6, LP_GPIOn, 6), GPIO6, _1, () ())));
4207    };
4208}
4209/// This macro can be used to generate code for each IOMUX digital function of each GPIO.
4210///
4211/// IOMUX functions are the alternate digital functions configured via the IO_MUX registers.
4212/// Use this to implement signal-specific traits for peripherals whose pins must bypass the
4213/// GPIO matrix (e.g., EMAC, USB).
4214///
4215/// For an explanation on the general syntax, as well as usage of individual/repeated
4216/// matchers, refer to [the crate-level documentation][crate#for_each-macros].
4217///
4218/// This macro has two options for its "Individual matcher" case:
4219///
4220/// - `all`: `($signal:ident, $gpio:ident, $af:ident)` - simple case where you only need
4221///   identifiers, and maybe the alternate function.
4222/// - group: `(($signal:ident, $group:ident $(, $number:literal)+), $gpio:ident, $af:ident)` -
4223///   expanded signal case, where you need the number(s) of a signal, or the general group to which
4224///   the signal belongs.
4225///
4226/// Macro fragments:
4227///
4228/// - `$signal`: the name of the signal.
4229/// - `$group`: the name of the signal, with numbers replaced by placeholders.
4230/// - `$number`: the numbers extracted from `$signal`.
4231/// - `$gpio`: the name of the GPIO.
4232/// - `$af`: the alternate function number, as an identifier (e.g. `_5`).
4233///
4234/// Example data:
4235/// - `(EMAC_RXD0, GPIO25, _5)`
4236/// - `((EMAC_RXDn, EMAC_RXDn, 0), GPIO25, _5)`
4237///
4238/// The expanded syntax is only available when the signal has at least one numbered component.
4239#[macro_export]
4240#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4241macro_rules! for_each_iomux_function {
4242    ($($pattern:tt => $code:tt;)*) => {
4243        macro_rules! _for_each_inner_iomux_function { $(($pattern) => $code;)* ($other :
4244        tt) => {} } _for_each_inner_iomux_function!((FSPIQ, GPIO2, _2));
4245        _for_each_inner_iomux_function!((MTMS, GPIO3, _0));
4246        _for_each_inner_iomux_function!((FSPIHD, GPIO3, _2));
4247        _for_each_inner_iomux_function!((MTDI, GPIO4, _0));
4248        _for_each_inner_iomux_function!((FSPIWP, GPIO4, _2));
4249        _for_each_inner_iomux_function!((MTCK, GPIO5, _0));
4250        _for_each_inner_iomux_function!((MTDO, GPIO6, _0));
4251        _for_each_inner_iomux_function!((FSPICLK, GPIO6, _2));
4252        _for_each_inner_iomux_function!((FSPID, GPIO7, _2));
4253        _for_each_inner_iomux_function!((FSPICS0, GPIO8, _2));
4254        _for_each_inner_iomux_function!((U0RXD, GPIO10, _0));
4255        _for_each_inner_iomux_function!((U0TXD, GPIO11, _0));
4256        _for_each_inner_iomux_function!((FSPICS1, GPIO14, _0));
4257        _for_each_inner_iomux_function!((FSPICS0, GPIO15, _0));
4258        _for_each_inner_iomux_function!((FSPIQ, GPIO16, _0));
4259        _for_each_inner_iomux_function!((FSPIWP, GPIO17, _0));
4260        _for_each_inner_iomux_function!((FSPIHD, GPIO19, _0));
4261        _for_each_inner_iomux_function!((FSPICLK, GPIO20, _0));
4262        _for_each_inner_iomux_function!((FSPID, GPIO21, _0));
4263        _for_each_inner_iomux_function!((SDIO_DATA2, GPIO22, _0));
4264        _for_each_inner_iomux_function!((SDIO_DATA3, GPIO23, _0));
4265        _for_each_inner_iomux_function!((SDIO_CMD, GPIO25, _0));
4266        _for_each_inner_iomux_function!((SDIO_CLK, GPIO26, _0));
4267        _for_each_inner_iomux_function!((SDIO_DATA0, GPIO27, _0));
4268        _for_each_inner_iomux_function!((SDIO_DATA1, GPIO28, _0));
4269        _for_each_inner_iomux_function!(((FSPICS0, FSPICSn, 0), GPIO8, _2));
4270        _for_each_inner_iomux_function!(((FSPICS1, FSPICSn, 1), GPIO14, _0));
4271        _for_each_inner_iomux_function!(((FSPICS0, FSPICSn, 0), GPIO15, _0));
4272        _for_each_inner_iomux_function!(((SDIO_DATA2, SDIO_DATAn, 2), GPIO22, _0));
4273        _for_each_inner_iomux_function!(((SDIO_DATA3, SDIO_DATAn, 3), GPIO23, _0));
4274        _for_each_inner_iomux_function!(((SDIO_DATA0, SDIO_DATAn, 0), GPIO27, _0));
4275        _for_each_inner_iomux_function!(((SDIO_DATA1, SDIO_DATAn, 1), GPIO28, _0));
4276        _for_each_inner_iomux_function!((all(FSPIQ, GPIO2, _2), (MTMS, GPIO3, _0),
4277        (FSPIHD, GPIO3, _2), (MTDI, GPIO4, _0), (FSPIWP, GPIO4, _2), (MTCK, GPIO5, _0),
4278        (MTDO, GPIO6, _0), (FSPICLK, GPIO6, _2), (FSPID, GPIO7, _2), (FSPICS0, GPIO8,
4279        _2), (U0RXD, GPIO10, _0), (U0TXD, GPIO11, _0), (FSPICS1, GPIO14, _0), (FSPICS0,
4280        GPIO15, _0), (FSPIQ, GPIO16, _0), (FSPIWP, GPIO17, _0), (FSPIHD, GPIO19, _0),
4281        (FSPICLK, GPIO20, _0), (FSPID, GPIO21, _0), (SDIO_DATA2, GPIO22, _0),
4282        (SDIO_DATA3, GPIO23, _0), (SDIO_CMD, GPIO25, _0), (SDIO_CLK, GPIO26, _0),
4283        (SDIO_DATA0, GPIO27, _0), (SDIO_DATA1, GPIO28, _0)));
4284        _for_each_inner_iomux_function!((FSPICSn((FSPICS0, FSPICSn, 0), GPIO8, _2),
4285        ((FSPICS1, FSPICSn, 1), GPIO14, _0), ((FSPICS0, FSPICSn, 0), GPIO15, _0)));
4286        _for_each_inner_iomux_function!((SDIO_DATAn((SDIO_DATA2, SDIO_DATAn, 2), GPIO22,
4287        _0), ((SDIO_DATA3, SDIO_DATAn, 3), GPIO23, _0), ((SDIO_DATA0, SDIO_DATAn, 0),
4288        GPIO27, _0), ((SDIO_DATA1, SDIO_DATAn, 1), GPIO28, _0)));
4289    };
4290}
4291/// Returns the name of the GPIO that provides the given signal, as a string.
4292///
4293/// The macro takes the name of a direct function - a digital IO MUX function, an analog
4294/// function, or an LP IO MUX function - and expands to a string literal like `"GPIO4"`. It
4295/// is meant to keep documentation free of per-chip pin lists.
4296///
4297/// Signals that are not wired to a pad on this chip have to be routed through the GPIO
4298/// matrix, which can reach any pad. The macro has no pad to return for those, so it accepts
4299/// an optional fallback to expand to instead. The fallback is not validated.
4300///
4301/// If multiple pads provide the signal, the macro returns one that is not reserved for some
4302/// other purpose, such as booting or interfacing with flash.
4303///
4304/// Example usage:
4305/// - `gpio_for_signal!(ADC1_CH0)`
4306/// - `gpio_for_signal!(LP_I2C_SDA, "GPIO6")`
4307#[macro_export]
4308#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4309macro_rules! gpio_for_signal {
4310    (XTAL_32K_P $(, $_fallback:literal)?) => {
4311        "GPIO0"
4312    };
4313    (LP_GPIO0 $(, $_fallback:literal)?) => {
4314        "GPIO0"
4315    };
4316    (XTAL_32K_N $(, $_fallback:literal)?) => {
4317        "GPIO1"
4318    };
4319    (ADC1_CH0 $(, $_fallback:literal)?) => {
4320        "GPIO1"
4321    };
4322    (LP_GPIO1 $(, $_fallback:literal)?) => {
4323        "GPIO1"
4324    };
4325    (FSPIQ $(, $_fallback:literal)?) => {
4326        "GPIO2"
4327    };
4328    (LP_GPIO2 $(, $_fallback:literal)?) => {
4329        "GPIO2"
4330    };
4331    (MTMS $(, $_fallback:literal)?) => {
4332        "GPIO3"
4333    };
4334    (FSPIHD $(, $_fallback:literal)?) => {
4335        "GPIO3"
4336    };
4337    (ADC1_CH1 $(, $_fallback:literal)?) => {
4338        "GPIO3"
4339    };
4340    (LP_GPIO3 $(, $_fallback:literal)?) => {
4341        "GPIO3"
4342    };
4343    (MTDI $(, $_fallback:literal)?) => {
4344        "GPIO4"
4345    };
4346    (FSPIWP $(, $_fallback:literal)?) => {
4347        "GPIO4"
4348    };
4349    (ADC1_CH2 $(, $_fallback:literal)?) => {
4350        "GPIO4"
4351    };
4352    (LP_GPIO4 $(, $_fallback:literal)?) => {
4353        "GPIO4"
4354    };
4355    (MTCK $(, $_fallback:literal)?) => {
4356        "GPIO5"
4357    };
4358    (ADC1_CH3 $(, $_fallback:literal)?) => {
4359        "GPIO5"
4360    };
4361    (LP_GPIO5 $(, $_fallback:literal)?) => {
4362        "GPIO5"
4363    };
4364    (MTDO $(, $_fallback:literal)?) => {
4365        "GPIO6"
4366    };
4367    (FSPICLK $(, $_fallback:literal)?) => {
4368        "GPIO6"
4369    };
4370    (LP_GPIO6 $(, $_fallback:literal)?) => {
4371        "GPIO6"
4372    };
4373    (FSPID $(, $_fallback:literal)?) => {
4374        "GPIO7"
4375    };
4376    (FSPICS0 $(, $_fallback:literal)?) => {
4377        "GPIO8"
4378    };
4379    (ZCD0 $(, $_fallback:literal)?) => {
4380        "GPIO8"
4381    };
4382    (ZCD1 $(, $_fallback:literal)?) => {
4383        "GPIO9"
4384    };
4385    (U0RXD $(, $_fallback:literal)?) => {
4386        "GPIO10"
4387    };
4388    (U0TXD $(, $_fallback:literal)?) => {
4389        "GPIO11"
4390    };
4391    (USJ_DM $(, $_fallback:literal)?) => {
4392        "GPIO12"
4393    };
4394    (USJ_DP $(, $_fallback:literal)?) => {
4395        "GPIO13"
4396    };
4397    (FSPICS1 $(, $_fallback:literal)?) => {
4398        "GPIO14"
4399    };
4400    (SDIO_DATA2 $(, $_fallback:literal)?) => {
4401        "GPIO22"
4402    };
4403    (SDIO_DATA3 $(, $_fallback:literal)?) => {
4404        "GPIO23"
4405    };
4406    (SDIO_CMD $(, $_fallback:literal)?) => {
4407        "GPIO25"
4408    };
4409    (SDIO_CLK $(, $_fallback:literal)?) => {
4410        "GPIO26"
4411    };
4412    (SDIO_DATA0 $(, $_fallback:literal)?) => {
4413        "GPIO27"
4414    };
4415    (SDIO_DATA1 $(, $_fallback:literal)?) => {
4416        "GPIO28"
4417    };
4418    ($_signal:ident, $fallback:literal) => {
4419        $fallback
4420    };
4421}
4422/// Defines the `InputSignal` and `OutputSignal` enums.
4423///
4424/// This macro is intended to be called in esp-hal only.
4425#[macro_export]
4426#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4427macro_rules! define_io_mux_signals {
4428    () => {
4429        #[allow(non_camel_case_types, clippy::upper_case_acronyms)]
4430        #[derive(Debug, PartialEq, Copy, Clone)]
4431        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
4432        #[doc(hidden)]
4433        pub enum InputSignal {
4434            U0RXD               = 6,
4435            U0CTS               = 7,
4436            U0DSR               = 8,
4437            U1RXD               = 9,
4438            U1CTS               = 10,
4439            U1DSR               = 11,
4440            I2S_MCLK            = 12,
4441            I2SO_BCK            = 13,
4442            I2SO_WS             = 14,
4443            I2SI_SD             = 15,
4444            I2SI_BCK            = 16,
4445            I2SI_WS             = 17,
4446            CPU_GPIO_0          = 27,
4447            CPU_GPIO_1          = 28,
4448            CPU_GPIO_2          = 29,
4449            CPU_GPIO_3          = 30,
4450            CPU_GPIO_4          = 31,
4451            CPU_GPIO_5          = 32,
4452            CPU_GPIO_6          = 33,
4453            CPU_GPIO_7          = 34,
4454            USB_JTAG_TDO_BRIDGE = 35,
4455            I2CEXT0_SCL         = 46,
4456            I2CEXT0_SDA         = 47,
4457            FSPICLK             = 64,
4458            FSPIQ               = 65,
4459            FSPID               = 66,
4460            FSPIHD              = 67,
4461            FSPIWP              = 68,
4462            FSPICS0             = 69,
4463            U2RXD               = 72,
4464            U2CTS               = 73,
4465            U2DSR               = 74,
4466            SIG_IN_FUNC97       = 97,
4467            SIG_IN_FUNC98       = 98,
4468            SIG_IN_FUNC99       = 99,
4469            SIG_IN_FUNC100      = 100,
4470            SDIO_CLK,
4471            SDIO_CMD,
4472            SDIO_DATA0,
4473            SDIO_DATA1,
4474            SDIO_DATA2,
4475            SDIO_DATA3,
4476            MTDI,
4477            MTDO,
4478            MTCK,
4479            MTMS,
4480        }
4481        #[allow(non_camel_case_types, clippy::upper_case_acronyms)]
4482        #[derive(Debug, PartialEq, Copy, Clone)]
4483        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
4484        #[doc(hidden)]
4485        pub enum OutputSignal {
4486            LEDC_LS_SIG0    = 0,
4487            LEDC_LS_SIG1    = 1,
4488            LEDC_LS_SIG2    = 2,
4489            LEDC_LS_SIG3    = 3,
4490            LEDC_LS_SIG4    = 4,
4491            LEDC_LS_SIG5    = 5,
4492            U0TXD           = 6,
4493            U0RTS           = 7,
4494            U0DTR           = 8,
4495            U1TXD           = 9,
4496            U1RTS           = 10,
4497            U1DTR           = 11,
4498            I2S_MCLK        = 12,
4499            I2SO_BCK        = 13,
4500            I2SO_WS         = 14,
4501            I2SO_SD         = 15,
4502            I2SI_BCK        = 16,
4503            I2SI_WS         = 17,
4504            I2SO_SD1        = 18,
4505            CPU_GPIO_0      = 27,
4506            CPU_GPIO_1      = 28,
4507            CPU_GPIO_2      = 29,
4508            CPU_GPIO_3      = 30,
4509            CPU_GPIO_4      = 31,
4510            CPU_GPIO_5      = 32,
4511            CPU_GPIO_6      = 33,
4512            CPU_GPIO_7      = 34,
4513            I2CEXT0_SCL     = 46,
4514            I2CEXT0_SDA     = 47,
4515            FSPICLK         = 64,
4516            FSPIQ           = 65,
4517            FSPID           = 66,
4518            FSPIHD          = 67,
4519            FSPIWP          = 68,
4520            FSPICS0         = 69,
4521            U2TXD           = 72,
4522            U2RTS           = 73,
4523            U2DTR           = 74,
4524            FSPICS1         = 102,
4525            FSPICS2         = 103,
4526            FSPICS3         = 104,
4527            FSPICS4         = 105,
4528            FSPICS5         = 106,
4529            SDIO_TOHOST_INT = 124,
4530            GPIO            = 256,
4531        }
4532    };
4533}
4534/// Defines the `LpFunction` enum.
4535///
4536/// The enum only contains the LP IO MUX functions that the chip implements. It is
4537/// empty on chips without an LP IO peripheral.
4538///
4539/// This macro is intended to be called in esp-hal only.
4540#[macro_export]
4541#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4542macro_rules! define_lp_functions {
4543    () => {
4544        /// LP IO MUX function of a pad.
4545        ///
4546        /// This is the low-power counterpart of `AlternateFunction`: it selects which function
4547        /// drives a pad while the pad belongs to the low-power domain.
4548        #[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
4549        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
4550        #[doc(hidden)]
4551        pub enum LpFunction {
4552            /// LP IO MUX function 1.
4553            _1 = 1,
4554        }
4555        impl LpFunction {
4556            /// The function that connects the pad to the LP GPIO peripheral.
4557            pub const LP_GPIO: Self = Self::_1;
4558        }
4559    };
4560}
4561/// Defines and implements the `io_mux_reg` function.
4562///
4563/// The generated function has the following signature:
4564///
4565/// ```rust,ignore
4566/// pub(crate) fn io_mux_reg(gpio_num: u8) -> &'static crate::pac::io_mux::GPIO0 {
4567///     // ...
4568/// # unimplemented!()
4569/// }
4570/// ```
4571///
4572/// This macro is intended to be called in esp-hal only.
4573#[macro_export]
4574#[expect(clippy::crate_in_macro_def)]
4575#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4576macro_rules! define_io_mux_reg {
4577    () => {
4578        pub(crate) fn io_mux_reg(gpio_num: u8) -> &'static crate::pac::io_mux::GPIO {
4579            crate::peripherals::IO_MUX::regs().gpio(gpio_num as usize)
4580        }
4581    };
4582}