esp_metadata_generated/
_generated_esp32.rs

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