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