Skip to main content

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