Skip to main content

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