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