Skip to main content

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