Skip to main content

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