1#[doc = concat!("assert_eq!(chip_name, ", chip!(), ")")]
12#[macro_export]
14#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
15macro_rules! chip {
16 () => {
17 "esp32c3"
18 };
19}
20#[doc = concat!("assert_eq!(chip_name, ", chip_pretty!(), ")")]
28#[macro_export]
30#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
31macro_rules! chip_pretty {
32 () => {
33 "ESP32-C3"
34 };
35}
36#[macro_export]
38#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
39macro_rules! property {
40 ("chip") => {
41 "esp32c3"
42 };
43 ("arch") => {
44 "riscv"
45 };
46 ("cores") => {
47 1
48 };
49 ("cores", str) => {
50 stringify!(1)
51 };
52 ("trm") => {
53 "https://www.espressif.com/sites/default/files/documentation/esp32-c3_technical_reference_manual_en.pdf"
54 };
55 ("gpio.version") => {
56 2
57 };
58 ("gpio.version", str) => {
59 stringify!(2)
60 };
61 ("gpio.has_input_sync") => {
62 true
63 };
64 ("gpio.gpio_function") => {
65 1
66 };
67 ("gpio.gpio_function", str) => {
68 stringify!(1)
69 };
70 ("gpio.constant_0_input") => {
71 31
72 };
73 ("gpio.constant_0_input", str) => {
74 stringify!(31)
75 };
76 ("gpio.constant_1_input") => {
77 30
78 };
79 ("gpio.constant_1_input", str) => {
80 stringify!(30)
81 };
82 ("gpio.remap_iomux_pin_registers") => {
83 false
84 };
85 ("gpio.func_in_sel_offset") => {
86 0
87 };
88 ("gpio.func_in_sel_offset", str) => {
89 stringify!(0)
90 };
91 ("gpio.need_soft_isolate_during_pd") => {
92 false
93 };
94 ("gpio.has_bank_1") => {
95 false
96 };
97 ("gpio.input_signal_max") => {
98 100
99 };
100 ("gpio.input_signal_max", str) => {
101 stringify!(100)
102 };
103 ("gpio.output_signal_max") => {
104 128
105 };
106 ("gpio.output_signal_max", str) => {
107 stringify!(128)
108 };
109 ("dedicated_gpio.version") => {
110 "riscv_v1"
111 };
112 ("dedicated_gpio.needs_initialization") => {
113 false
114 };
115 ("dedicated_gpio.channel_count") => {
116 8
117 };
118 ("dedicated_gpio.channel_count", str) => {
119 stringify!(8)
120 };
121 ("lp_io.version") => {
122 "v3"
123 };
124 ("lp_io.has_gpio_matrix") => {
125 false
126 };
127 ("uart.ram_size") => {
128 128
129 };
130 ("uart.ram_size", str) => {
131 stringify!(128)
132 };
133 ("uart.version") => {
134 1
135 };
136 ("uart.version", str) => {
137 stringify!(1)
138 };
139 ("uart.peripheral_controls_mem_clk") => {
140 false
141 };
142 ("uart.has_sclk_divider") => {
143 true
144 };
145 ("uart.has_sclk_enable") => {
146 true
147 };
148 ("uhci.combined_uart_selector_field") => {
149 false
150 };
151 ("i2c_master.version") => {
152 3
153 };
154 ("i2c_master.version", str) => {
155 stringify!(3)
156 };
157 ("i2c_master.has_fsm_timeouts") => {
158 true
159 };
160 ("i2c_master.has_hw_bus_clear") => {
161 true
162 };
163 ("i2c_master.has_bus_timeout_enable") => {
164 true
165 };
166 ("i2c_master.separate_filter_config_registers") => {
167 false
168 };
169 ("i2c_master.can_estimate_nack_reason") => {
170 false
171 };
172 ("i2c_master.has_conf_update") => {
173 true
174 };
175 ("i2c_master.has_reliable_fsm_reset") => {
176 false
177 };
178 ("i2c_master.has_arbitration_en") => {
179 true
180 };
181 ("i2c_master.has_tx_fifo_watermark") => {
182 true
183 };
184 ("i2c_master.bus_timeout_is_exponential") => {
185 true
186 };
187 ("i2c_master.has_pd_en") => {
188 true
189 };
190 ("i2c_master.max_bus_timeout") => {
191 31
192 };
193 ("i2c_master.max_bus_timeout", str) => {
194 stringify!(31)
195 };
196 ("i2c_master.ll_intr_mask") => {
197 262143
198 };
199 ("i2c_master.ll_intr_mask", str) => {
200 stringify!(262143)
201 };
202 ("i2c_master.fifo_size") => {
203 32
204 };
205 ("i2c_master.fifo_size", str) => {
206 stringify!(32)
207 };
208 ("spi_master.version") => {
209 3
210 };
211 ("spi_master.version", str) => {
212 stringify!(3)
213 };
214 ("spi_master.fifo_size") => {
215 64
216 };
217 ("spi_master.fifo_size", str) => {
218 stringify!(64)
219 };
220 ("spi_master.bit_order_is_bool") => {
221 true
222 };
223 ("spi_master.has_octal") => {
224 false
225 };
226 ("spi_master.has_app_interrupts") => {
227 true
228 };
229 ("spi_master.has_dma_segmented_transfer") => {
230 true
231 };
232 ("spi_master.has_clk_pre_div") => {
233 false
234 };
235 ("spi_master.dma_can_access_flash") => {
236 false
237 };
238 ("i2s.version") => {
239 2
240 };
241 ("i2s.version", str) => {
242 stringify!(2)
243 };
244 ("i2s.mclk_divider_bit_width") => {
245 9
246 };
247 ("i2s.mclk_divider_bit_width", str) => {
248 stringify!(9)
249 };
250 ("i2s.max_ws_width") => {
251 128
252 };
253 ("i2s.max_ws_width", str) => {
254 stringify!(128)
255 };
256 ("i2s.clock_configured_by_pcr") => {
257 false
258 };
259 ("i2s.clock_configured_by_hp_sys_clkrst") => {
260 false
261 };
262 ("i2s.supports_pdm_rx_hp_filter") => {
263 false
264 };
265 ("i2s.supports_pdm_tx") => {
266 true
267 };
268 ("i2s.supports_pdm_rx") => {
269 true
270 };
271 ("i2s.supports_pcm2pdm") => {
272 true
273 };
274 ("i2s.supports_pdm2pcm") => {
275 false
276 };
277 ("rmt.ram_start") => {
278 1610703872
279 };
280 ("rmt.ram_start", str) => {
281 stringify!(1610703872)
282 };
283 ("rmt.channel_ram_size") => {
284 48
285 };
286 ("rmt.channel_ram_size", str) => {
287 stringify!(48)
288 };
289 ("rmt.has_tx_immediate_stop") => {
290 true
291 };
292 ("rmt.has_tx_loop_count") => {
293 true
294 };
295 ("rmt.has_tx_loop_auto_stop") => {
296 false
297 };
298 ("rmt.has_tx_carrier_data_only") => {
299 true
300 };
301 ("rmt.has_tx_sync") => {
302 true
303 };
304 ("rmt.has_rx_wrap") => {
305 true
306 };
307 ("rmt.has_rx_demodulation") => {
308 true
309 };
310 ("rmt.has_per_channel_clock") => {
311 false
312 };
313 ("bt.controller") => {
314 "btdm"
315 };
316 ("wifi.has_wifi6") => {
317 false
318 };
319 ("wifi.mac_version") => {
320 1
321 };
322 ("wifi.mac_version", str) => {
323 stringify!(1)
324 };
325 ("wifi.has_5g") => {
326 false
327 };
328 ("wifi.csi_supported") => {
329 true
330 };
331 ("wifi.has_nan") => {
332 false
333 };
334 ("wifi.has_ftm") => {
335 true
336 };
337 ("phy.combo_module") => {
338 true
339 };
340 ("phy.backed_up_digital_register_count") => {
341 21
342 };
343 ("phy.backed_up_digital_register_count", str) => {
344 stringify!(21)
345 };
346 ("adc.controller") => {
347 "digital"
348 };
349 ("adc.channel_count") => {
350 5
351 };
352 ("adc.channel_count", str) => {
353 stringify!(5)
354 };
355 ("adc.line_calibration") => {
356 true
357 };
358 ("adc.curve_calibration") => {
359 true
360 };
361 ("adc.basic_calibration") => {
362 true
363 };
364 ("adc.calibration_v1_scheme_supported") => {
365 true
366 };
367 ("adc.channel_compensation") => {
368 false
369 };
370 ("adc.pcr_clock") => {
371 false
372 };
373 ("adc.pcr_sar_clk_div") => {
374 false
375 };
376 ("adc.sar_power_override") => {
377 false
378 };
379 ("ledc.version") => {
380 2
381 };
382 ("ledc.version", str) => {
383 stringify!(2)
384 };
385 ("ledc.channel_count") => {
386 6
387 };
388 ("ledc.channel_count", str) => {
389 stringify!(6)
390 };
391 ("sdm.channel_count") => {
392 4
393 };
394 ("sdm.channel_count", str) => {
395 stringify!(4)
396 };
397 ("timergroup.timg_has_timer1") => {
398 false
399 };
400 ("timergroup.timg_has_divcnt_rst") => {
401 true
402 };
403 ("timergroup.wdt_has_conf_update") => {
404 true
405 };
406 ("aes.has_split_text_registers") => {
407 true
408 };
409 ("aes.endianness_configurable") => {
410 false
411 };
412 ("rng.apb_cycle_wait_num") => {
413 16
414 };
415 ("rng.apb_cycle_wait_num", str) => {
416 stringify!(16)
417 };
418 ("rng.trng_supported") => {
419 true
420 };
421 ("rng.is_lp_sys") => {
422 false
423 };
424 ("rsa.version") => {
425 3
426 };
427 ("rsa.version", str) => {
428 stringify!(3)
429 };
430 ("rsa.size_increment") => {
431 32
432 };
433 ("rsa.size_increment", str) => {
434 stringify!(32)
435 };
436 ("rsa.memory_size_bytes") => {
437 384
438 };
439 ("rsa.memory_size_bytes", str) => {
440 stringify!(384)
441 };
442 ("sleep.light_sleep") => {
443 true
444 };
445 ("sleep.deep_sleep") => {
446 true
447 };
448 ("sleep.rejectable_mask") => {
449 1852
450 };
451 ("sleep.pin_wakeup_version") => {
452 2
453 };
454 ("sleep.pin_wakeup_version", str) => {
455 stringify!(2)
456 };
457 ("sleep.deep_sleep_needs_gpio_isolation") => {
458 true
459 };
460 ("sleep.cpu_retention_mem_size") => {
461 1744
462 };
463 ("sleep.cpu_retention_mem_align") => {
464 16
465 };
466 ("sleep.cpu_retention_mem_start") => {
467 1070333952
468 };
469 ("sleep.cpu_retention_mem_end") => {
470 1070465024
471 };
472 ("assist_debug.has_sp_monitor") => {
473 true
474 };
475 ("assist_debug.has_region_monitor") => {
476 true
477 };
478 ("dma.mem2mem_requires_peripheral") => {
479 true
480 };
481 ("dma.ext_mem_configurable_block_size") => {
482 false
483 };
484 ("dma.separate_in_out_interrupts") => {
485 false
486 };
487 ("dma.gdma_version") => {
488 1
489 };
490 ("dma.gdma_version", str) => {
491 stringify!(1)
492 };
493 ("interrupts.status_registers") => {
494 2
495 };
496 ("interrupts.status_registers", str) => {
497 stringify!(2)
498 };
499 ("interrupts.disabled_interrupt") => {
500 0
501 };
502 ("mmu.page_size") => {
503 65536
504 };
505 ("mmu.page_size", str) => {
506 stringify!(65536)
507 };
508 ("mmu.entry_num") => {
509 128
510 };
511 ("mmu.entry_num", str) => {
512 stringify!(128)
513 };
514 ("rom.has_crc_le") => {
515 true
516 };
517 ("rom.has_crc_be") => {
518 true
519 };
520 ("rom.has_md5_bsd") => {
521 true
522 };
523 ("rom.has_md5_mbedtls") => {
524 false
525 };
526 ("soc.cpu_has_branch_predictor") => {
527 false
528 };
529 ("soc.cpu_has_csr_pc") => {
530 true
531 };
532 ("soc.cpu_has_zcmp_workaround") => {
533 false
534 };
535 ("soc.multi_core_enabled") => {
536 false
537 };
538 ("soc.internal_memory_cached") => {
539 false
540 };
541 ("soc.has_swd_watchdog") => {
542 true
543 };
544 ("soc.cpu_mcause_mask") => {
545 31
546 };
547 ("soc.cpu_mcause_mask", str) => {
548 stringify!(31)
549 };
550 ("soc.cpu_pmp_granularity") => {
551 4
552 };
553 ("soc.cpu_pmp_granularity", str) => {
554 stringify!(4)
555 };
556 ("clock_tree.system_pre_div_in") => {
557 [crate ::soc::clocks::SystemPreDivInConfig::Xtal, crate
558 ::soc::clocks::SystemPreDivInConfig::RcFast]
559 };
560 ("clock_tree.system_pre_div.divisor") => {
561 (0, 1023)
562 };
563 ("clock_tree.cpu_clk") => {
564 [crate ::soc::clocks::CpuClkConfig::Xtal, crate
565 ::soc::clocks::CpuClkConfig::RcFast, crate ::soc::clocks::CpuClkConfig::Pll]
566 };
567 ("clock_tree.apb_clk") => {
568 [crate ::soc::clocks::ApbClkConfig::Pll80m, crate
569 ::soc::clocks::ApbClkConfig::Cpu]
570 };
571 ("clock_tree.crypto_clk") => {
572 [crate ::soc::clocks::CryptoClkConfig::Pll160m, crate
573 ::soc::clocks::CryptoClkConfig::Cpu]
574 };
575 ("clock_tree.rc_fast_clk_div_n.divisor") => {
576 (0, 3)
577 };
578 ("clock_tree.rtc_slow_clk") => {
579 [#[cfg(use_xtal32k)] crate ::soc::clocks::RtcSlowClkConfig::Xtal32k, crate
580 ::soc::clocks::RtcSlowClkConfig::RcSlow, crate
581 ::soc::clocks::RtcSlowClkConfig::RcFast]
582 };
583 ("clock_tree.ble_lp_clk") => {
584 [crate ::soc::clocks::BleLpClkConfig::Xtal, crate
585 ::soc::clocks::BleLpClkConfig::RtcSlow]
586 };
587 ("clock_tree.rtc_fast_clk") => {
588 [crate ::soc::clocks::RtcFastClkConfig::Xtal, crate
589 ::soc::clocks::RtcFastClkConfig::Rc]
590 };
591 ("clock_tree.low_power_clk") => {
592 [crate ::soc::clocks::LowPowerClkConfig::Xtal, crate
593 ::soc::clocks::LowPowerClkConfig::RcFast, #[cfg(use_xtal32k)] crate
594 ::soc::clocks::LowPowerClkConfig::Xtal32k, crate
595 ::soc::clocks::LowPowerClkConfig::RtcSlow]
596 };
597 ("clock_tree.timg_calibration_clock") => {
598 [crate ::soc::clocks::TimgCalibrationClockConfig::RcSlowClk, crate
599 ::soc::clocks::TimgCalibrationClockConfig::RcFastDivClk, #[cfg(use_xtal32k)]
600 crate ::soc::clocks::TimgCalibrationClockConfig::Xtal32kClk]
601 };
602 ("clock_tree.timg.function_clock") => {
603 [crate ::soc::clocks::TimgFunctionClockConfig::XtalClk, crate
604 ::soc::clocks::TimgFunctionClockConfig::ApbClk]
605 };
606 ("clock_tree.timg.wdt_clock") => {
607 [crate ::soc::clocks::TimgWdtClockConfig::ApbClk, crate
608 ::soc::clocks::TimgWdtClockConfig::XtalClk]
609 };
610 ("clock_tree.rmt.sclk") => {
611 [crate ::soc::clocks::RmtSclkConfig::ApbClk, crate
612 ::soc::clocks::RmtSclkConfig::RcFastClk, crate
613 ::soc::clocks::RmtSclkConfig::XtalClk]
614 };
615 ("clock_tree.uart.function_clock.sclk") => {
616 [crate ::soc::clocks::UartFunctionClockSclk::Apb, crate
617 ::soc::clocks::UartFunctionClockSclk::RcFast, crate
618 ::soc::clocks::UartFunctionClockSclk::Xtal]
619 };
620 ("clock_tree.uart.function_clock.div_num") => {
621 (0, 255)
622 };
623 ("clock_tree.uart.baud_rate_generator.fractional") => {
624 (0, 15)
625 };
626 ("clock_tree.uart.baud_rate_generator.integral") => {
627 (0, 4095)
628 };
629 ("clock_tree.i2c.function_clock.sclk") => {
630 [crate ::soc::clocks::I2cFunctionClockSclk::Xtal, crate
631 ::soc::clocks::I2cFunctionClockSclk::RcFast]
632 };
633 ("clock_tree.i2c.function_clock.div_num") => {
634 (0, 255)
635 };
636 ("clock_tree.tsens.sclk") => {
637 [crate ::soc::clocks::TsensSclkConfig::RcFast, crate
638 ::soc::clocks::TsensSclkConfig::Xtal]
639 };
640 ("clock_tree.spi.function_clock") => {
641 [crate ::soc::clocks::SpiFunctionClockConfig::Xtal, crate
642 ::soc::clocks::SpiFunctionClockConfig::Pll80m]
643 };
644 ("clock_tree.i2s.tx_clk.sclk") => {
645 [crate ::soc::clocks::I2sClkSclk::Xtal, crate ::soc::clocks::I2sClkSclk::Pll160m]
646 };
647 ("clock_tree.i2s.tx_clk.div_num") => {
648 (1, 255)
649 };
650 ("clock_tree.i2s.tx_clk.div_a") => {
651 (1, 511)
652 };
653 ("clock_tree.i2s.tx_clk.div_b") => {
654 (0, 511)
655 };
656 ("clock_tree.i2s.rx_clk.sclk") => {
657 [crate ::soc::clocks::I2sClkSclk::Xtal, crate ::soc::clocks::I2sClkSclk::Pll160m]
658 };
659 ("clock_tree.i2s.rx_clk.div_num") => {
660 (1, 255)
661 };
662 ("clock_tree.i2s.rx_clk.div_a") => {
663 (1, 511)
664 };
665 ("clock_tree.i2s.rx_clk.div_b") => {
666 (0, 511)
667 };
668 ("clock_tree.i2s.mclk_out") => {
669 [crate ::soc::clocks::I2sMclkOutConfig::Tx, crate
670 ::soc::clocks::I2sMclkOutConfig::Rx]
671 };
672}
673#[macro_export]
674#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
675macro_rules! for_each_dedicated_gpio {
676 ($($pattern:tt => $code:tt;)*) => {
677 macro_rules! _for_each_inner_dedicated_gpio { $(($pattern) => $code;)* ($other :
678 tt) => {} } _for_each_inner_dedicated_gpio!((0));
679 _for_each_inner_dedicated_gpio!((1)); _for_each_inner_dedicated_gpio!((2));
680 _for_each_inner_dedicated_gpio!((3)); _for_each_inner_dedicated_gpio!((4));
681 _for_each_inner_dedicated_gpio!((5)); _for_each_inner_dedicated_gpio!((6));
682 _for_each_inner_dedicated_gpio!((7)); _for_each_inner_dedicated_gpio!((0, 0,
683 CPU_GPIO_0)); _for_each_inner_dedicated_gpio!((0, 1, CPU_GPIO_1));
684 _for_each_inner_dedicated_gpio!((0, 2, CPU_GPIO_2));
685 _for_each_inner_dedicated_gpio!((0, 3, CPU_GPIO_3));
686 _for_each_inner_dedicated_gpio!((0, 4, CPU_GPIO_4));
687 _for_each_inner_dedicated_gpio!((0, 5, CPU_GPIO_5));
688 _for_each_inner_dedicated_gpio!((0, 6, CPU_GPIO_6));
689 _for_each_inner_dedicated_gpio!((0, 7, CPU_GPIO_7));
690 _for_each_inner_dedicated_gpio!((channels(0), (1), (2), (3), (4), (5), (6),
691 (7))); _for_each_inner_dedicated_gpio!((signals(0, 0, CPU_GPIO_0), (0, 1,
692 CPU_GPIO_1), (0, 2, CPU_GPIO_2), (0, 3, CPU_GPIO_3), (0, 4, CPU_GPIO_4), (0, 5,
693 CPU_GPIO_5), (0, 6, CPU_GPIO_6), (0, 7, CPU_GPIO_7)));
694 };
695}
696#[macro_export]
700#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
701macro_rules! define_lp_io_signals {
702 () => {};
703}
704#[macro_export]
726#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
727macro_rules! for_each_rmt_channel {
728 ($($pattern:tt => $code:tt;)*) => {
729 macro_rules! _for_each_inner_rmt_channel { $(($pattern) => $code;)* ($other : tt)
730 => {} } _for_each_inner_rmt_channel!((0)); _for_each_inner_rmt_channel!((1));
731 _for_each_inner_rmt_channel!((2)); _for_each_inner_rmt_channel!((3));
732 _for_each_inner_rmt_channel!((0, 0)); _for_each_inner_rmt_channel!((1, 1));
733 _for_each_inner_rmt_channel!((2, 0)); _for_each_inner_rmt_channel!((3, 1));
734 _for_each_inner_rmt_channel!((all(0), (1), (2), (3)));
735 _for_each_inner_rmt_channel!((tx(0, 0), (1, 1)));
736 _for_each_inner_rmt_channel!((rx(2, 0), (3, 1)));
737 };
738}
739#[macro_export]
740#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
741macro_rules! for_each_sdm_channel {
742 ($($pattern:tt => $code:tt;)*) => {
743 macro_rules! _for_each_inner_sdm_channel { $(($pattern) => $code;)* ($other : tt)
744 => {} } _for_each_inner_sdm_channel!((0, SDM_CH0, SdmCh0, GPIO_SD0));
745 _for_each_inner_sdm_channel!((1, SDM_CH1, SdmCh1, GPIO_SD1));
746 _for_each_inner_sdm_channel!((2, SDM_CH2, SdmCh2, GPIO_SD2));
747 _for_each_inner_sdm_channel!((3, SDM_CH3, SdmCh3, GPIO_SD3));
748 _for_each_inner_sdm_channel!((channels(0, SDM_CH0, SdmCh0, GPIO_SD0), (1,
749 SDM_CH1, SdmCh1, GPIO_SD1), (2, SDM_CH2, SdmCh2, GPIO_SD2), (3, SDM_CH3, SdmCh3,
750 GPIO_SD3)));
751 };
752}
753#[macro_export]
754#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
755macro_rules! for_each_aes_key_length {
756 ($($pattern:tt => $code:tt;)*) => {
757 macro_rules! _for_each_inner_aes_key_length { $(($pattern) => $code;)* ($other :
758 tt) => {} } _for_each_inner_aes_key_length!((128));
759 _for_each_inner_aes_key_length!((256)); _for_each_inner_aes_key_length!((128, 0,
760 4)); _for_each_inner_aes_key_length!((256, 2, 6));
761 _for_each_inner_aes_key_length!((bits(128), (256)));
762 _for_each_inner_aes_key_length!((modes(128, 0, 4), (256, 2, 6)));
763 };
764}
765#[macro_export]
766#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
767macro_rules! for_each_rsa_exponentiation {
768 ($($pattern:tt => $code:tt;)*) => {
769 macro_rules! _for_each_inner_rsa_exponentiation { $(($pattern) => $code;)*
770 ($other : tt) => {} } _for_each_inner_rsa_exponentiation!((32));
771 _for_each_inner_rsa_exponentiation!((64));
772 _for_each_inner_rsa_exponentiation!((96));
773 _for_each_inner_rsa_exponentiation!((128));
774 _for_each_inner_rsa_exponentiation!((160));
775 _for_each_inner_rsa_exponentiation!((192));
776 _for_each_inner_rsa_exponentiation!((224));
777 _for_each_inner_rsa_exponentiation!((256));
778 _for_each_inner_rsa_exponentiation!((288));
779 _for_each_inner_rsa_exponentiation!((320));
780 _for_each_inner_rsa_exponentiation!((352));
781 _for_each_inner_rsa_exponentiation!((384));
782 _for_each_inner_rsa_exponentiation!((416));
783 _for_each_inner_rsa_exponentiation!((448));
784 _for_each_inner_rsa_exponentiation!((480));
785 _for_each_inner_rsa_exponentiation!((512));
786 _for_each_inner_rsa_exponentiation!((544));
787 _for_each_inner_rsa_exponentiation!((576));
788 _for_each_inner_rsa_exponentiation!((608));
789 _for_each_inner_rsa_exponentiation!((640));
790 _for_each_inner_rsa_exponentiation!((672));
791 _for_each_inner_rsa_exponentiation!((704));
792 _for_each_inner_rsa_exponentiation!((736));
793 _for_each_inner_rsa_exponentiation!((768));
794 _for_each_inner_rsa_exponentiation!((800));
795 _for_each_inner_rsa_exponentiation!((832));
796 _for_each_inner_rsa_exponentiation!((864));
797 _for_each_inner_rsa_exponentiation!((896));
798 _for_each_inner_rsa_exponentiation!((928));
799 _for_each_inner_rsa_exponentiation!((960));
800 _for_each_inner_rsa_exponentiation!((992));
801 _for_each_inner_rsa_exponentiation!((1024));
802 _for_each_inner_rsa_exponentiation!((1056));
803 _for_each_inner_rsa_exponentiation!((1088));
804 _for_each_inner_rsa_exponentiation!((1120));
805 _for_each_inner_rsa_exponentiation!((1152));
806 _for_each_inner_rsa_exponentiation!((1184));
807 _for_each_inner_rsa_exponentiation!((1216));
808 _for_each_inner_rsa_exponentiation!((1248));
809 _for_each_inner_rsa_exponentiation!((1280));
810 _for_each_inner_rsa_exponentiation!((1312));
811 _for_each_inner_rsa_exponentiation!((1344));
812 _for_each_inner_rsa_exponentiation!((1376));
813 _for_each_inner_rsa_exponentiation!((1408));
814 _for_each_inner_rsa_exponentiation!((1440));
815 _for_each_inner_rsa_exponentiation!((1472));
816 _for_each_inner_rsa_exponentiation!((1504));
817 _for_each_inner_rsa_exponentiation!((1536));
818 _for_each_inner_rsa_exponentiation!((1568));
819 _for_each_inner_rsa_exponentiation!((1600));
820 _for_each_inner_rsa_exponentiation!((1632));
821 _for_each_inner_rsa_exponentiation!((1664));
822 _for_each_inner_rsa_exponentiation!((1696));
823 _for_each_inner_rsa_exponentiation!((1728));
824 _for_each_inner_rsa_exponentiation!((1760));
825 _for_each_inner_rsa_exponentiation!((1792));
826 _for_each_inner_rsa_exponentiation!((1824));
827 _for_each_inner_rsa_exponentiation!((1856));
828 _for_each_inner_rsa_exponentiation!((1888));
829 _for_each_inner_rsa_exponentiation!((1920));
830 _for_each_inner_rsa_exponentiation!((1952));
831 _for_each_inner_rsa_exponentiation!((1984));
832 _for_each_inner_rsa_exponentiation!((2016));
833 _for_each_inner_rsa_exponentiation!((2048));
834 _for_each_inner_rsa_exponentiation!((2080));
835 _for_each_inner_rsa_exponentiation!((2112));
836 _for_each_inner_rsa_exponentiation!((2144));
837 _for_each_inner_rsa_exponentiation!((2176));
838 _for_each_inner_rsa_exponentiation!((2208));
839 _for_each_inner_rsa_exponentiation!((2240));
840 _for_each_inner_rsa_exponentiation!((2272));
841 _for_each_inner_rsa_exponentiation!((2304));
842 _for_each_inner_rsa_exponentiation!((2336));
843 _for_each_inner_rsa_exponentiation!((2368));
844 _for_each_inner_rsa_exponentiation!((2400));
845 _for_each_inner_rsa_exponentiation!((2432));
846 _for_each_inner_rsa_exponentiation!((2464));
847 _for_each_inner_rsa_exponentiation!((2496));
848 _for_each_inner_rsa_exponentiation!((2528));
849 _for_each_inner_rsa_exponentiation!((2560));
850 _for_each_inner_rsa_exponentiation!((2592));
851 _for_each_inner_rsa_exponentiation!((2624));
852 _for_each_inner_rsa_exponentiation!((2656));
853 _for_each_inner_rsa_exponentiation!((2688));
854 _for_each_inner_rsa_exponentiation!((2720));
855 _for_each_inner_rsa_exponentiation!((2752));
856 _for_each_inner_rsa_exponentiation!((2784));
857 _for_each_inner_rsa_exponentiation!((2816));
858 _for_each_inner_rsa_exponentiation!((2848));
859 _for_each_inner_rsa_exponentiation!((2880));
860 _for_each_inner_rsa_exponentiation!((2912));
861 _for_each_inner_rsa_exponentiation!((2944));
862 _for_each_inner_rsa_exponentiation!((2976));
863 _for_each_inner_rsa_exponentiation!((3008));
864 _for_each_inner_rsa_exponentiation!((3040));
865 _for_each_inner_rsa_exponentiation!((3072));
866 _for_each_inner_rsa_exponentiation!((all(32), (64), (96), (128), (160), (192),
867 (224), (256), (288), (320), (352), (384), (416), (448), (480), (512), (544),
868 (576), (608), (640), (672), (704), (736), (768), (800), (832), (864), (896),
869 (928), (960), (992), (1024), (1056), (1088), (1120), (1152), (1184), (1216),
870 (1248), (1280), (1312), (1344), (1376), (1408), (1440), (1472), (1504), (1536),
871 (1568), (1600), (1632), (1664), (1696), (1728), (1760), (1792), (1824), (1856),
872 (1888), (1920), (1952), (1984), (2016), (2048), (2080), (2112), (2144), (2176),
873 (2208), (2240), (2272), (2304), (2336), (2368), (2400), (2432), (2464), (2496),
874 (2528), (2560), (2592), (2624), (2656), (2688), (2720), (2752), (2784), (2816),
875 (2848), (2880), (2912), (2944), (2976), (3008), (3040), (3072)));
876 };
877}
878#[macro_export]
879#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
880macro_rules! for_each_rsa_multiplication {
881 ($($pattern:tt => $code:tt;)*) => {
882 macro_rules! _for_each_inner_rsa_multiplication { $(($pattern) => $code;)*
883 ($other : tt) => {} } _for_each_inner_rsa_multiplication!((32));
884 _for_each_inner_rsa_multiplication!((64));
885 _for_each_inner_rsa_multiplication!((96));
886 _for_each_inner_rsa_multiplication!((128));
887 _for_each_inner_rsa_multiplication!((160));
888 _for_each_inner_rsa_multiplication!((192));
889 _for_each_inner_rsa_multiplication!((224));
890 _for_each_inner_rsa_multiplication!((256));
891 _for_each_inner_rsa_multiplication!((288));
892 _for_each_inner_rsa_multiplication!((320));
893 _for_each_inner_rsa_multiplication!((352));
894 _for_each_inner_rsa_multiplication!((384));
895 _for_each_inner_rsa_multiplication!((416));
896 _for_each_inner_rsa_multiplication!((448));
897 _for_each_inner_rsa_multiplication!((480));
898 _for_each_inner_rsa_multiplication!((512));
899 _for_each_inner_rsa_multiplication!((544));
900 _for_each_inner_rsa_multiplication!((576));
901 _for_each_inner_rsa_multiplication!((608));
902 _for_each_inner_rsa_multiplication!((640));
903 _for_each_inner_rsa_multiplication!((672));
904 _for_each_inner_rsa_multiplication!((704));
905 _for_each_inner_rsa_multiplication!((736));
906 _for_each_inner_rsa_multiplication!((768));
907 _for_each_inner_rsa_multiplication!((800));
908 _for_each_inner_rsa_multiplication!((832));
909 _for_each_inner_rsa_multiplication!((864));
910 _for_each_inner_rsa_multiplication!((896));
911 _for_each_inner_rsa_multiplication!((928));
912 _for_each_inner_rsa_multiplication!((960));
913 _for_each_inner_rsa_multiplication!((992));
914 _for_each_inner_rsa_multiplication!((1024));
915 _for_each_inner_rsa_multiplication!((1056));
916 _for_each_inner_rsa_multiplication!((1088));
917 _for_each_inner_rsa_multiplication!((1120));
918 _for_each_inner_rsa_multiplication!((1152));
919 _for_each_inner_rsa_multiplication!((1184));
920 _for_each_inner_rsa_multiplication!((1216));
921 _for_each_inner_rsa_multiplication!((1248));
922 _for_each_inner_rsa_multiplication!((1280));
923 _for_each_inner_rsa_multiplication!((1312));
924 _for_each_inner_rsa_multiplication!((1344));
925 _for_each_inner_rsa_multiplication!((1376));
926 _for_each_inner_rsa_multiplication!((1408));
927 _for_each_inner_rsa_multiplication!((1440));
928 _for_each_inner_rsa_multiplication!((1472));
929 _for_each_inner_rsa_multiplication!((1504));
930 _for_each_inner_rsa_multiplication!((1536));
931 _for_each_inner_rsa_multiplication!((all(32), (64), (96), (128), (160), (192),
932 (224), (256), (288), (320), (352), (384), (416), (448), (480), (512), (544),
933 (576), (608), (640), (672), (704), (736), (768), (800), (832), (864), (896),
934 (928), (960), (992), (1024), (1056), (1088), (1120), (1152), (1184), (1216),
935 (1248), (1280), (1312), (1344), (1376), (1408), (1440), (1472), (1504), (1536)));
936 };
937}
938#[macro_export]
939#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
940macro_rules! for_each_sha_algorithm {
941 ($($pattern:tt => $code:tt;)*) => {
942 macro_rules! _for_each_inner_sha_algorithm { $(($pattern) => $code;)* ($other :
943 tt) => {} } _for_each_inner_sha_algorithm!((Sha1, "SHA-1"(sizes : 64, 20, 8)
944 (insecure_against : "collision", "length extension"), 0));
945 _for_each_inner_sha_algorithm!((Sha224, "SHA-224"(sizes : 64, 28, 8)
946 (insecure_against : "length extension"), 1));
947 _for_each_inner_sha_algorithm!((Sha256, "SHA-256"(sizes : 64, 32, 8)
948 (insecure_against : "length extension"), 2));
949 _for_each_inner_sha_algorithm!((algos(Sha1, "SHA-1"(sizes : 64, 20, 8)
950 (insecure_against : "collision", "length extension"), 0), (Sha224,
951 "SHA-224"(sizes : 64, 28, 8) (insecure_against : "length extension"), 1),
952 (Sha256, "SHA-256"(sizes : 64, 32, 8) (insecure_against : "length extension"),
953 2)));
954 };
955}
956#[macro_export]
957#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
958macro_rules! for_each_wakeup_source {
959 ($($pattern:tt => $code:tt;)*) => {
960 macro_rules! _for_each_inner_wakeup_source { $(($pattern) => $code;)* ($other :
961 tt) => {} } _for_each_inner_wakeup_source!((Gpio, 2));
962 _for_each_inner_wakeup_source!((Timer, 3)); _for_each_inner_wakeup_source!((Sdio,
963 4)); _for_each_inner_wakeup_source!((Wifi, 5));
964 _for_each_inner_wakeup_source!((Uart0, 6));
965 _for_each_inner_wakeup_source!((Uart1, 7));
966 _for_each_inner_wakeup_source!((Touch, 8)); _for_each_inner_wakeup_source!((Ulp,
967 9)); _for_each_inner_wakeup_source!((Bt, 10));
968 _for_each_inner_wakeup_source!((all(Gpio, 2), (Timer, 3), (Sdio, 4), (Wifi, 5),
969 (Uart0, 6), (Uart1, 7), (Touch, 8), (Ulp, 9), (Bt, 10)));
970 };
971}
972#[macro_export]
973#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
974macro_rules! for_each_dma_engine {
975 ($($pattern:tt => $code:tt;)*) => {
976 macro_rules! _for_each_inner_dma_engine { $(($pattern) => $code;)* ($other : tt)
977 => {} } _for_each_inner_dma_engine!(("AHB_GDMA"));
978 _for_each_inner_dma_engine!((all("AHB_GDMA")));
979 };
980}
981#[macro_export]
982#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
983macro_rules! for_each_dma_channel {
984 ($($pattern:tt => $code:tt;)*) => {
985 macro_rules! _for_each_inner_dma_channel { $(($pattern) => $code;)* ($other : tt)
986 => {} } _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH0));
987 _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH1));
988 _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH2));
989 _for_each_inner_dma_channel!(("AHB_GDMA", any_channel = AhbGdmaChannel));
990 _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH0, 0, interrupt = DMA_CH0,
991 compatible = [SPI2, UHCI0, I2S0, AES, SHA, APB_SARADC]));
992 _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH1, 1, interrupt = DMA_CH1,
993 compatible = [SPI2, UHCI0, I2S0, AES, SHA, APB_SARADC]));
994 _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH2, 2, interrupt = DMA_CH2,
995 compatible = [SPI2, UHCI0, I2S0, AES, SHA, APB_SARADC]));
996 _for_each_inner_dma_channel!((names("AHB_GDMA", DMA_CH0), ("AHB_GDMA", DMA_CH1),
997 ("AHB_GDMA", DMA_CH2)));
998 _for_each_inner_dma_channel!((separate_any_type("AHB_GDMA", any_channel =
999 AhbGdmaChannel))); _for_each_inner_dma_channel!((shared("AHB_GDMA", DMA_CH0, 0,
1000 interrupt = DMA_CH0, compatible = [SPI2, UHCI0, I2S0, AES, SHA, APB_SARADC]),
1001 ("AHB_GDMA", DMA_CH1, 1, interrupt = DMA_CH1, compatible = [SPI2, UHCI0, I2S0,
1002 AES, SHA, APB_SARADC]), ("AHB_GDMA", DMA_CH2, 2, interrupt = DMA_CH2, compatible
1003 = [SPI2, UHCI0, I2S0, AES, SHA, APB_SARADC])));
1004 _for_each_inner_dma_channel!((split));
1005 _for_each_inner_dma_channel!((no_own_interrupt));
1006 };
1007}
1008#[macro_export]
1009#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
1010macro_rules! for_each_dma_channel_peri_pair {
1011 ($($pattern:tt => $code:tt;)*) => {
1012 macro_rules! _for_each_inner_dma_channel_peri_pair { $(($pattern) => $code;)*
1013 ($other : tt) => {} } _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA",
1014 DMA_CH0, SPI2)); _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH0,
1015 UHCI0)); _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH0, I2S0));
1016 _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH0, AES));
1017 _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH0, SHA));
1018 _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH0, APB_SARADC));
1019 _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH1, SPI2));
1020 _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH1, UHCI0));
1021 _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH1, I2S0));
1022 _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH1, AES));
1023 _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH1, SHA));
1024 _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH1, APB_SARADC));
1025 _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH2, SPI2));
1026 _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH2, UHCI0));
1027 _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH2, I2S0));
1028 _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH2, AES));
1029 _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH2, SHA));
1030 _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH2, APB_SARADC));
1031 _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", any_channel = AhbGdmaChannel,
1032 SPI2)); _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", any_channel =
1033 AhbGdmaChannel, UHCI0)); _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA",
1034 any_channel = AhbGdmaChannel, I2S0));
1035 _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", any_channel = AhbGdmaChannel,
1036 AES)); _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", any_channel =
1037 AhbGdmaChannel, SHA)); _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA",
1038 any_channel = AhbGdmaChannel, APB_SARADC));
1039 _for_each_inner_dma_channel_peri_pair!((channels("AHB_GDMA", DMA_CH0, SPI2),
1040 ("AHB_GDMA", DMA_CH0, UHCI0), ("AHB_GDMA", DMA_CH0, I2S0), ("AHB_GDMA", DMA_CH0,
1041 AES), ("AHB_GDMA", DMA_CH0, SHA), ("AHB_GDMA", DMA_CH0, APB_SARADC), ("AHB_GDMA",
1042 DMA_CH1, SPI2), ("AHB_GDMA", DMA_CH1, UHCI0), ("AHB_GDMA", DMA_CH1, I2S0),
1043 ("AHB_GDMA", DMA_CH1, AES), ("AHB_GDMA", DMA_CH1, SHA), ("AHB_GDMA", DMA_CH1,
1044 APB_SARADC), ("AHB_GDMA", DMA_CH2, SPI2), ("AHB_GDMA", DMA_CH2, UHCI0),
1045 ("AHB_GDMA", DMA_CH2, I2S0), ("AHB_GDMA", DMA_CH2, AES), ("AHB_GDMA", DMA_CH2,
1046 SHA), ("AHB_GDMA", DMA_CH2, APB_SARADC)));
1047 _for_each_inner_dma_channel_peri_pair!((any_channels("AHB_GDMA", any_channel =
1048 AhbGdmaChannel, SPI2), ("AHB_GDMA", any_channel = AhbGdmaChannel, UHCI0),
1049 ("AHB_GDMA", any_channel = AhbGdmaChannel, I2S0), ("AHB_GDMA", any_channel =
1050 AhbGdmaChannel, AES), ("AHB_GDMA", any_channel = AhbGdmaChannel, SHA),
1051 ("AHB_GDMA", any_channel = AhbGdmaChannel, APB_SARADC)));
1052 };
1053}
1054#[macro_export]
1055#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
1056macro_rules! for_each_mem2mem_channel {
1057 ($($pattern:tt => $code:tt;)*) => {
1058 macro_rules! _for_each_inner_mem2mem_channel { $(($pattern) => $code;)* ($other :
1059 tt) => {} } _for_each_inner_mem2mem_channel!(("AHB_GDMA", AhbGdma,
1060 AhbGdmaChannel, DMA_CH0, 0)); _for_each_inner_mem2mem_channel!(("AHB_GDMA",
1061 AhbGdma, AhbGdmaChannel, DMA_CH1, 0));
1062 _for_each_inner_mem2mem_channel!(("AHB_GDMA", AhbGdma, AhbGdmaChannel, DMA_CH2,
1063 0)); _for_each_inner_mem2mem_channel!(("AHB_GDMA", AhbGdma, AhbGdmaChannel, 0, 0,
1064 1, 0, 2, 0)); _for_each_inner_mem2mem_channel!(("AHB_GDMA", AhbGdma,
1065 AhbGdmaChannel)); _for_each_inner_mem2mem_channel!((channels("AHB_GDMA", AhbGdma,
1066 AhbGdmaChannel, DMA_CH0, 0), ("AHB_GDMA", AhbGdma, AhbGdmaChannel, DMA_CH1, 0),
1067 ("AHB_GDMA", AhbGdma, AhbGdmaChannel, DMA_CH2, 0)));
1068 _for_each_inner_mem2mem_channel!((erased("AHB_GDMA", AhbGdma, AhbGdmaChannel, 0,
1069 0, 1, 0, 2, 0))); _for_each_inner_mem2mem_channel!((engines("AHB_GDMA", AhbGdma,
1070 AhbGdmaChannel)));
1071 };
1072}
1073#[macro_export]
1074#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
1075macro_rules! with_aes_dma_engine {
1076 ($($pattern:tt => $code:tt;)*) => {
1077 macro_rules! _with_inner_aes_dma_engine { $(($pattern) => $code;)* ($other : tt)
1078 => {} } _with_inner_aes_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
1079 };
1080}
1081#[macro_export]
1082#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
1083macro_rules! with_i2s_dma_engine {
1084 ($($pattern:tt => $code:tt;)*) => {
1085 macro_rules! _with_inner_i2s_dma_engine { $(($pattern) => $code;)* ($other : tt)
1086 => {} } _with_inner_i2s_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
1087 };
1088}
1089#[macro_export]
1090#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
1091macro_rules! with_sha_dma_engine {
1092 ($($pattern:tt => $code:tt;)*) => {
1093 macro_rules! _with_inner_sha_dma_engine { $(($pattern) => $code;)* ($other : tt)
1094 => {} } _with_inner_sha_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
1095 };
1096}
1097#[macro_export]
1098#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
1099macro_rules! with_spi_master_dma_engine {
1100 ($($pattern:tt => $code:tt;)*) => {
1101 macro_rules! _with_inner_spi_master_dma_engine { $(($pattern) => $code;)* ($other
1102 : tt) => {} } _with_inner_spi_master_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
1103 };
1104}
1105#[macro_export]
1106#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
1107macro_rules! with_spi_slave_dma_engine {
1108 ($($pattern:tt => $code:tt;)*) => {
1109 macro_rules! _with_inner_spi_slave_dma_engine { $(($pattern) => $code;)* ($other
1110 : tt) => {} } _with_inner_spi_slave_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
1111 };
1112}
1113#[macro_export]
1114#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
1115macro_rules! with_uhci_dma_engine {
1116 ($($pattern:tt => $code:tt;)*) => {
1117 macro_rules! _with_inner_uhci_dma_engine { $(($pattern) => $code;)* ($other : tt)
1118 => {} } _with_inner_uhci_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
1119 };
1120}
1121#[macro_export]
1122#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
1123macro_rules! for_each_interrupt {
1124 ($($pattern:tt => $code:tt;)*) => {
1125 macro_rules! _for_each_inner_interrupt { $(($pattern) => $code;)* ($other : tt)
1126 => {} } _for_each_inner_interrupt!(([disabled 0] 0));
1127 _for_each_inner_interrupt!(([reserved 0] 1));
1128 _for_each_inner_interrupt!(([context_switch 0] 2));
1129 _for_each_inner_interrupt!(([direct_bindable 0] 3));
1130 _for_each_inner_interrupt!(([direct_bindable 1] 4));
1131 _for_each_inner_interrupt!(([direct_bindable 2] 5));
1132 _for_each_inner_interrupt!(([direct_bindable 3] 6));
1133 _for_each_inner_interrupt!(([direct_bindable 4] 7));
1134 _for_each_inner_interrupt!(([direct_bindable 5] 8));
1135 _for_each_inner_interrupt!(([direct_bindable 6] 9));
1136 _for_each_inner_interrupt!(([direct_bindable 7] 10));
1137 _for_each_inner_interrupt!(([direct_bindable 8] 11));
1138 _for_each_inner_interrupt!(([direct_bindable 9] 12));
1139 _for_each_inner_interrupt!(([direct_bindable 10] 13));
1140 _for_each_inner_interrupt!(([direct_bindable 11] 14));
1141 _for_each_inner_interrupt!(([direct_bindable 12] 15));
1142 _for_each_inner_interrupt!(([direct_bindable 13] 16));
1143 _for_each_inner_interrupt!(([vector 0] 17)); _for_each_inner_interrupt!(([vector
1144 1] 18)); _for_each_inner_interrupt!(([vector 2] 19));
1145 _for_each_inner_interrupt!(([vector 3] 20)); _for_each_inner_interrupt!(([vector
1146 4] 21)); _for_each_inner_interrupt!(([vector 5] 22));
1147 _for_each_inner_interrupt!(([vector 6] 23)); _for_each_inner_interrupt!(([vector
1148 7] 24)); _for_each_inner_interrupt!(([vector 8] 25));
1149 _for_each_inner_interrupt!(([vector 9] 26)); _for_each_inner_interrupt!(([vector
1150 10] 27)); _for_each_inner_interrupt!(([vector 11] 28));
1151 _for_each_inner_interrupt!(([vector 12] 29)); _for_each_inner_interrupt!(([vector
1152 13] 30)); _for_each_inner_interrupt!(([vector 14] 31));
1153 _for_each_inner_interrupt!((all([disabled 0] 0), ([reserved 0] 1),
1154 ([context_switch 0] 2), ([direct_bindable 0] 3), ([direct_bindable 1] 4),
1155 ([direct_bindable 2] 5), ([direct_bindable 3] 6), ([direct_bindable 4] 7),
1156 ([direct_bindable 5] 8), ([direct_bindable 6] 9), ([direct_bindable 7] 10),
1157 ([direct_bindable 8] 11), ([direct_bindable 9] 12), ([direct_bindable 10] 13),
1158 ([direct_bindable 11] 14), ([direct_bindable 12] 15), ([direct_bindable 13] 16),
1159 ([vector 0] 17), ([vector 1] 18), ([vector 2] 19), ([vector 3] 20), ([vector 4]
1160 21), ([vector 5] 22), ([vector 6] 23), ([vector 7] 24), ([vector 8] 25), ([vector
1161 9] 26), ([vector 10] 27), ([vector 11] 28), ([vector 12] 29), ([vector 13] 30),
1162 ([vector 14] 31)));
1163 };
1164}
1165#[macro_export]
1166#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
1167macro_rules! for_each_classified_interrupt {
1168 ($($pattern:tt => $code:tt;)*) => {
1169 macro_rules! _for_each_inner_classified_interrupt { $(($pattern) => $code;)*
1170 ($other : tt) => {} } _for_each_inner_classified_interrupt!(([direct_bindable 0]
1171 3)); _for_each_inner_classified_interrupt!(([direct_bindable 1] 4));
1172 _for_each_inner_classified_interrupt!(([direct_bindable 2] 5));
1173 _for_each_inner_classified_interrupt!(([direct_bindable 3] 6));
1174 _for_each_inner_classified_interrupt!(([direct_bindable 4] 7));
1175 _for_each_inner_classified_interrupt!(([direct_bindable 5] 8));
1176 _for_each_inner_classified_interrupt!(([direct_bindable 6] 9));
1177 _for_each_inner_classified_interrupt!(([direct_bindable 7] 10));
1178 _for_each_inner_classified_interrupt!(([direct_bindable 8] 11));
1179 _for_each_inner_classified_interrupt!(([direct_bindable 9] 12));
1180 _for_each_inner_classified_interrupt!(([direct_bindable 10] 13));
1181 _for_each_inner_classified_interrupt!(([direct_bindable 11] 14));
1182 _for_each_inner_classified_interrupt!(([direct_bindable 12] 15));
1183 _for_each_inner_classified_interrupt!(([direct_bindable 13] 16));
1184 _for_each_inner_classified_interrupt!(([vector 0] 17));
1185 _for_each_inner_classified_interrupt!(([vector 1] 18));
1186 _for_each_inner_classified_interrupt!(([vector 2] 19));
1187 _for_each_inner_classified_interrupt!(([vector 3] 20));
1188 _for_each_inner_classified_interrupt!(([vector 4] 21));
1189 _for_each_inner_classified_interrupt!(([vector 5] 22));
1190 _for_each_inner_classified_interrupt!(([vector 6] 23));
1191 _for_each_inner_classified_interrupt!(([vector 7] 24));
1192 _for_each_inner_classified_interrupt!(([vector 8] 25));
1193 _for_each_inner_classified_interrupt!(([vector 9] 26));
1194 _for_each_inner_classified_interrupt!(([vector 10] 27));
1195 _for_each_inner_classified_interrupt!(([vector 11] 28));
1196 _for_each_inner_classified_interrupt!(([vector 12] 29));
1197 _for_each_inner_classified_interrupt!(([vector 13] 30));
1198 _for_each_inner_classified_interrupt!(([vector 14] 31));
1199 _for_each_inner_classified_interrupt!(([reserved 0] 1));
1200 _for_each_inner_classified_interrupt!(([context_switch 0] 2));
1201 _for_each_inner_classified_interrupt!((direct_bindable([direct_bindable 0] 3),
1202 ([direct_bindable 1] 4), ([direct_bindable 2] 5), ([direct_bindable 3] 6),
1203 ([direct_bindable 4] 7), ([direct_bindable 5] 8), ([direct_bindable 6] 9),
1204 ([direct_bindable 7] 10), ([direct_bindable 8] 11), ([direct_bindable 9] 12),
1205 ([direct_bindable 10] 13), ([direct_bindable 11] 14), ([direct_bindable 12] 15),
1206 ([direct_bindable 13] 16)));
1207 _for_each_inner_classified_interrupt!((vector([vector 0] 17), ([vector 1] 18),
1208 ([vector 2] 19), ([vector 3] 20), ([vector 4] 21), ([vector 5] 22), ([vector 6]
1209 23), ([vector 7] 24), ([vector 8] 25), ([vector 9] 26), ([vector 10] 27),
1210 ([vector 11] 28), ([vector 12] 29), ([vector 13] 30), ([vector 14] 31)));
1211 _for_each_inner_classified_interrupt!((reserved([reserved 0] 1)));
1212 _for_each_inner_classified_interrupt!((context_switch([context_switch 0] 2)));
1213 };
1214}
1215#[macro_export]
1216#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
1217macro_rules! for_each_interrupt_priority {
1218 ($($pattern:tt => $code:tt;)*) => {
1219 macro_rules! _for_each_inner_interrupt_priority { $(($pattern) => $code;)*
1220 ($other : tt) => {} } _for_each_inner_interrupt_priority!((0, 1, Priority1,
1221 Level1)); _for_each_inner_interrupt_priority!((1, 2, Priority2, Level2));
1222 _for_each_inner_interrupt_priority!((2, 3, Priority3, Level3));
1223 _for_each_inner_interrupt_priority!((3, 4, Priority4, Level4));
1224 _for_each_inner_interrupt_priority!((4, 5, Priority5, Level5));
1225 _for_each_inner_interrupt_priority!((5, 6, Priority6, Level6));
1226 _for_each_inner_interrupt_priority!((6, 7, Priority7, Level7));
1227 _for_each_inner_interrupt_priority!((7, 8, Priority8, Level8));
1228 _for_each_inner_interrupt_priority!((8, 9, Priority9, Level9));
1229 _for_each_inner_interrupt_priority!((9, 10, Priority10, Level10));
1230 _for_each_inner_interrupt_priority!((10, 11, Priority11, Level11));
1231 _for_each_inner_interrupt_priority!((11, 12, Priority12, Level12));
1232 _for_each_inner_interrupt_priority!((12, 13, Priority13, Level13));
1233 _for_each_inner_interrupt_priority!((13, 14, Priority14, Level14));
1234 _for_each_inner_interrupt_priority!((14, 15, Priority15, Level15));
1235 _for_each_inner_interrupt_priority!((all(0, 1, Priority1, Level1), (1, 2,
1236 Priority2, Level2), (2, 3, Priority3, Level3), (3, 4, Priority4, Level4), (4, 5,
1237 Priority5, Level5), (5, 6, Priority6, Level6), (6, 7, Priority7, Level7), (7, 8,
1238 Priority8, Level8), (8, 9, Priority9, Level9), (9, 10, Priority10, Level10), (10,
1239 11, Priority11, Level11), (11, 12, Priority12, Level12), (12, 13, Priority13,
1240 Level13), (13, 14, Priority14, Level14), (14, 15, Priority15, Level15)));
1241 };
1242}
1243#[macro_export]
1244#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
1245macro_rules! for_each_sw_interrupt {
1246 ($($pattern:tt => $code:tt;)*) => {
1247 macro_rules! _for_each_inner_sw_interrupt { $(($pattern) => $code;)* ($other :
1248 tt) => {} } _for_each_inner_sw_interrupt!((0, FROM_CPU_INTR0,
1249 software_interrupt0)); _for_each_inner_sw_interrupt!((1, FROM_CPU_INTR1,
1250 software_interrupt1)); _for_each_inner_sw_interrupt!((2, FROM_CPU_INTR2,
1251 software_interrupt2)); _for_each_inner_sw_interrupt!((3, FROM_CPU_INTR3,
1252 software_interrupt3)); _for_each_inner_sw_interrupt!((all(0, FROM_CPU_INTR0,
1253 software_interrupt0), (1, FROM_CPU_INTR1, software_interrupt1), (2,
1254 FROM_CPU_INTR2, software_interrupt2), (3, FROM_CPU_INTR3, software_interrupt3)));
1255 };
1256}
1257#[macro_export]
1258macro_rules! define_clock_tree_types {
1697 () => {
1698 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1699 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1700 pub enum AdcInstance {
1701 ApbSaradc = 0,
1702 }
1703 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1704 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1705 pub enum SdmInstance {
1706 GpioSd = 0,
1707 }
1708 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1709 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1710 pub enum I2cInstance {
1711 I2c0 = 0,
1712 }
1713 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1714 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1715 pub enum I2sInstance {
1716 I2s0 = 0,
1717 }
1718 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1719 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1720 pub enum RmtInstance {
1721 Rmt = 0,
1722 }
1723 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1724 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1725 pub enum SpiInstance {
1726 Spi2 = 0,
1727 }
1728 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1729 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1730 pub enum TimgInstance {
1731 Timg0 = 0,
1732 Timg1 = 1,
1733 }
1734 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1735 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1736 pub enum UartInstance {
1737 Uart0 = 0,
1738 Uart1 = 1,
1739 }
1740 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1741 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1742 pub enum TsensInstance {
1743 Tsens = 0,
1744 }
1745 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1747 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1748 pub enum XtalClkConfig {
1749 _40,
1751 }
1752 impl XtalClkConfig {
1753 pub fn value(&self) -> u32 {
1754 match self {
1755 XtalClkConfig::_40 => 40000000,
1756 }
1757 }
1758 }
1759 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1761 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1762 pub enum PllClkConfig {
1763 _320,
1765 _480,
1767 }
1768 impl PllClkConfig {
1769 pub fn value(&self) -> u32 {
1770 match self {
1771 PllClkConfig::_320 => 320000000,
1772 PllClkConfig::_480 => 480000000,
1773 }
1774 }
1775 }
1776 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1778 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1779 pub enum SystemPreDivInConfig {
1780 Xtal,
1782 RcFast,
1784 }
1785 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1789 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1790 pub struct SystemPreDivConfig {
1791 divisor: u32,
1792 }
1793 impl SystemPreDivConfig {
1794 pub const fn new(divisor: u32) -> Self {
1801 ::core::assert!(
1802 divisor <= 1023,
1803 "`SYSTEM_PRE_DIV` divisor must be between 0 and 1023 (inclusive)."
1804 );
1805 Self { divisor }
1806 }
1807 pub fn divisor(self) -> u32 {
1808 self.divisor as u32
1809 }
1810 }
1811 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1813 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1814 pub enum CpuPllDivOutConfig {
1815 _80,
1817 _160,
1819 }
1820 impl CpuPllDivOutConfig {
1821 pub fn value(&self) -> u32 {
1822 match self {
1823 CpuPllDivOutConfig::_80 => 80000000,
1824 CpuPllDivOutConfig::_160 => 160000000,
1825 }
1826 }
1827 }
1828 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1830 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1831 pub enum ApbClkConfig {
1832 Pll80m,
1834 Cpu,
1836 }
1837 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1839 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1840 pub enum CryptoClkConfig {
1841 Pll160m,
1843 Cpu,
1845 }
1846 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1848 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1849 pub enum CpuClkConfig {
1850 Xtal,
1852 RcFast,
1854 Pll,
1856 }
1857 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1861 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1862 pub struct RcFastClkDivNConfig {
1863 divisor: u32,
1864 }
1865 impl RcFastClkDivNConfig {
1866 pub const fn new(divisor: u32) -> Self {
1873 ::core::assert!(
1874 divisor <= 3,
1875 "`RC_FAST_CLK_DIV_N` divisor must be between 0 and 3 (inclusive)."
1876 );
1877 Self { divisor }
1878 }
1879 pub fn divisor(self) -> u32 {
1880 self.divisor as u32
1881 }
1882 }
1883 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1885 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1886 pub enum RtcSlowClkConfig {
1887 #[cfg(use_xtal32k)]
1888 Xtal32k,
1890 RcSlow,
1892 RcFast,
1894 }
1895 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1897 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1898 pub enum BleLpClkConfig {
1899 Xtal,
1901 RtcSlow,
1903 }
1904 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1906 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1907 pub enum RtcFastClkConfig {
1908 Xtal,
1910 Rc,
1912 }
1913 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1915 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1916 pub enum LowPowerClkConfig {
1917 Xtal,
1919 RcFast,
1921 #[cfg(use_xtal32k)]
1922 Xtal32k,
1924 RtcSlow,
1926 }
1927 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1929 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1930 pub enum UartMemClkConfig {
1931 #[default]
1932 Xtal,
1934 }
1935 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1937 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1938 pub enum TimgCalibrationClockConfig {
1939 RcSlowClk,
1941 RcFastDivClk,
1943 #[cfg(use_xtal32k)]
1944 Xtal32kClk,
1946 }
1947 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1948 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1949 pub enum I2cFunctionClockSclk {
1950 #[default]
1951 Xtal,
1953 RcFast,
1955 }
1956 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1960 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1961 pub struct I2cFunctionClockConfig {
1962 sclk: I2cFunctionClockSclk,
1963 div_num: u32,
1964 }
1965 impl I2cFunctionClockConfig {
1966 pub const fn new(sclk: I2cFunctionClockSclk, div_num: u32) -> Self {
1973 ::core::assert!(
1974 div_num <= 255,
1975 "`I2C0_FUNCTION_CLOCK` div_num must be between 0 and 255 (inclusive)."
1976 );
1977 Self { sclk, div_num }
1978 }
1979 pub fn sclk(self) -> I2cFunctionClockSclk {
1980 self.sclk
1981 }
1982 pub fn div_num(self) -> u32 {
1983 self.div_num as u32
1984 }
1985 }
1986 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1987 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1988 pub enum I2sClkSclk {
1989 Xtal,
1991 #[default]
1992 Pll160m,
1994 }
1995 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1999 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
2000 pub struct I2sClkConfig {
2001 sclk: I2sClkSclk,
2002 div_num: u32,
2003 div_a: u32,
2004 div_b: u32,
2005 }
2006 impl I2sClkConfig {
2007 pub const fn new(sclk: I2sClkSclk, div_num: u32, div_a: u32, div_b: u32) -> Self {
2020 ::core::assert!(
2021 div_num >= 1 && div_num <= 255,
2022 "`I2S0_TX_CLK` div_num must be between 1 and 255 (inclusive)."
2023 );
2024 ::core::assert!(
2025 div_a >= 1 && div_a <= 511,
2026 "`I2S0_TX_CLK` div_a must be between 1 and 511 (inclusive)."
2027 );
2028 ::core::assert!(
2029 div_b <= 511,
2030 "`I2S0_TX_CLK` div_b must be between 0 and 511 (inclusive)."
2031 );
2032 Self {
2033 sclk,
2034 div_num,
2035 div_a,
2036 div_b,
2037 }
2038 }
2039 pub fn sclk(self) -> I2sClkSclk {
2040 self.sclk
2041 }
2042 pub fn div_num(self) -> u32 {
2043 self.div_num as u32
2044 }
2045 pub fn div_a(self) -> u32 {
2046 self.div_a as u32
2047 }
2048 pub fn div_b(self) -> u32 {
2049 self.div_b as u32
2050 }
2051 }
2052 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
2054 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
2055 pub enum I2sMclkOutConfig {
2056 Tx,
2058 #[default]
2059 Rx,
2061 }
2062 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
2064 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
2065 pub enum RmtSclkConfig {
2066 #[default]
2067 ApbClk,
2069 RcFastClk,
2071 XtalClk,
2073 }
2074 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
2076 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
2077 pub enum SpiFunctionClockConfig {
2078 Xtal,
2080 #[default]
2081 Pll80m,
2083 }
2084 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
2086 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
2087 pub enum TimgFunctionClockConfig {
2088 #[default]
2089 XtalClk,
2091 ApbClk,
2093 }
2094 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
2096 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
2097 pub enum TimgWdtClockConfig {
2098 #[default]
2099 ApbClk,
2101 XtalClk,
2103 }
2104 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
2105 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
2106 pub enum UartFunctionClockSclk {
2107 Apb,
2109 RcFast,
2111 #[default]
2112 Xtal,
2114 }
2115 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2119 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
2120 pub struct UartFunctionClockConfig {
2121 sclk: UartFunctionClockSclk,
2122 div_num: u32,
2123 }
2124 impl UartFunctionClockConfig {
2125 pub const fn new(sclk: UartFunctionClockSclk, div_num: u32) -> Self {
2132 ::core::assert!(
2133 div_num <= 255,
2134 "`UART0_FUNCTION_CLOCK` div_num must be between 0 and 255 (inclusive)."
2135 );
2136 Self { sclk, div_num }
2137 }
2138 pub fn sclk(self) -> UartFunctionClockSclk {
2139 self.sclk
2140 }
2141 pub fn div_num(self) -> u32 {
2142 self.div_num as u32
2143 }
2144 }
2145 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2150 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
2151 pub struct UartBaudRateGeneratorConfig {
2152 fractional: u32,
2153 integral: u32,
2154 }
2155 impl UartBaudRateGeneratorConfig {
2156 pub const fn new(fractional: u32, integral: u32) -> Self {
2166 ::core::assert!(
2167 fractional <= 15,
2168 "`UART0_BAUD_RATE_GENERATOR` fractional must be between 0 and 15 (inclusive)."
2169 );
2170 ::core::assert!(
2171 integral <= 4095,
2172 "`UART0_BAUD_RATE_GENERATOR` integral must be between 0 and 4095 (inclusive)."
2173 );
2174 Self {
2175 fractional,
2176 integral,
2177 }
2178 }
2179 pub fn fractional(self) -> u32 {
2180 self.fractional as u32
2181 }
2182 pub fn integral(self) -> u32 {
2183 self.integral as u32
2184 }
2185 }
2186 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
2188 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
2189 pub enum TsensSclkConfig {
2190 RcFast,
2192 #[default]
2193 Xtal,
2195 }
2196 pub struct ClockTree {
2198 xtal_clk: Option<XtalClkConfig>,
2199 pll_clk: Option<PllClkConfig>,
2200 system_pre_div_in: Option<SystemPreDivInConfig>,
2201 system_pre_div: Option<SystemPreDivConfig>,
2202 cpu_pll_div_out: Option<CpuPllDivOutConfig>,
2203 apb_clk: Option<ApbClkConfig>,
2204 crypto_clk: Option<CryptoClkConfig>,
2205 cpu_clk: Option<CpuClkConfig>,
2206 rc_fast_clk_div_n: Option<RcFastClkDivNConfig>,
2207 rtc_slow_clk: Option<RtcSlowClkConfig>,
2208 ble_lp_clk: Option<BleLpClkConfig>,
2209 rtc_fast_clk: Option<RtcFastClkConfig>,
2210 low_power_clk: Option<LowPowerClkConfig>,
2211 timg_calibration_clock: Option<TimgCalibrationClockConfig>,
2212 i2c_function_clock: [Option<I2cFunctionClockConfig>; 1],
2213 i2s_tx_clk: [Option<I2sClkConfig>; 1],
2214 i2s_rx_clk: [Option<I2sClkConfig>; 1],
2215 i2s_mclk_out: [Option<I2sMclkOutConfig>; 1],
2216 rmt_sclk: [Option<RmtSclkConfig>; 1],
2217 spi_function_clock: [Option<SpiFunctionClockConfig>; 1],
2218 timg_function_clock: [Option<TimgFunctionClockConfig>; 2],
2219 timg_wdt_clock: [Option<TimgWdtClockConfig>; 2],
2220 uart_function_clock: [Option<UartFunctionClockConfig>; 2],
2221 uart_baud_rate_generator: [Option<UartBaudRateGeneratorConfig>; 2],
2222 tsens_sclk: [Option<TsensSclkConfig>; 1],
2223 rc_fast_clk_refcount: u32,
2224 #[cfg(use_xtal32k)]
2225 xtal32k_clk_refcount: u32,
2226 rc_slow_clk_refcount: u32,
2227 rc_fast_div_clk_refcount: u32,
2228 apb_clk_refcount: u32,
2229 crypto_clk_refcount: u32,
2230 pll_80m_refcount: u32,
2231 pll_160m_refcount: u32,
2232 rtc_slow_clk_refcount: u32,
2233 ble_lp_clk_refcount: u32,
2234 rtc_fast_clk_refcount: u32,
2235 low_power_clk_refcount: u32,
2236 uart_mem_clk_refcount: u32,
2237 timg_calibration_clock_refcount: u32,
2238 adc_function_clock_refcount: [u32; 1],
2239 sdm_function_clock_refcount: [u32; 1],
2240 i2c_function_clock_refcount: [u32; 1],
2241 i2s_tx_clk_refcount: [u32; 1],
2242 i2s_rx_clk_refcount: [u32; 1],
2243 i2s_mclk_out_refcount: [u32; 1],
2244 rmt_sclk_refcount: [u32; 1],
2245 spi_function_clock_refcount: [u32; 1],
2246 timg_function_clock_refcount: [u32; 2],
2247 timg_wdt_clock_refcount: [u32; 2],
2248 uart_function_clock_refcount: [u32; 2],
2249 uart_mem_clock_refcount: [u32; 2],
2250 uart_baud_rate_generator_refcount: [u32; 2],
2251 tsens_sclk_refcount: [u32; 1],
2252 }
2253 impl ClockTree {
2254 pub fn with<R>(f: impl FnOnce(&mut ClockTree) -> R) -> R {
2256 CLOCK_TREE.with(f)
2257 }
2258 pub fn xtal_clk(&self) -> Option<XtalClkConfig> {
2260 self.xtal_clk
2261 }
2262 pub fn pll_clk(&self) -> Option<PllClkConfig> {
2264 self.pll_clk
2265 }
2266 pub fn system_pre_div_in(&self) -> Option<SystemPreDivInConfig> {
2268 self.system_pre_div_in
2269 }
2270 pub fn system_pre_div(&self) -> Option<SystemPreDivConfig> {
2272 self.system_pre_div
2273 }
2274 pub fn cpu_pll_div_out(&self) -> Option<CpuPllDivOutConfig> {
2276 self.cpu_pll_div_out
2277 }
2278 pub fn apb_clk(&self) -> Option<ApbClkConfig> {
2280 self.apb_clk
2281 }
2282 pub fn crypto_clk(&self) -> Option<CryptoClkConfig> {
2284 self.crypto_clk
2285 }
2286 pub fn cpu_clk(&self) -> Option<CpuClkConfig> {
2288 self.cpu_clk
2289 }
2290 pub fn rc_fast_clk_div_n(&self) -> Option<RcFastClkDivNConfig> {
2292 self.rc_fast_clk_div_n
2293 }
2294 pub fn rtc_slow_clk(&self) -> Option<RtcSlowClkConfig> {
2296 self.rtc_slow_clk
2297 }
2298 pub fn ble_lp_clk(&self) -> Option<BleLpClkConfig> {
2300 self.ble_lp_clk
2301 }
2302 pub fn rtc_fast_clk(&self) -> Option<RtcFastClkConfig> {
2304 self.rtc_fast_clk
2305 }
2306 pub fn low_power_clk(&self) -> Option<LowPowerClkConfig> {
2308 self.low_power_clk
2309 }
2310 pub fn timg_calibration_clock(&self) -> Option<TimgCalibrationClockConfig> {
2312 self.timg_calibration_clock
2313 }
2314 pub fn i2c0_function_clock(&self) -> Option<I2cFunctionClockConfig> {
2316 self.i2c_function_clock[I2cInstance::I2c0 as usize]
2317 }
2318 pub fn i2s0_tx_clk(&self) -> Option<I2sClkConfig> {
2320 self.i2s_tx_clk[I2sInstance::I2s0 as usize]
2321 }
2322 pub fn i2s0_rx_clk(&self) -> Option<I2sClkConfig> {
2324 self.i2s_rx_clk[I2sInstance::I2s0 as usize]
2325 }
2326 pub fn i2s0_mclk_out(&self) -> Option<I2sMclkOutConfig> {
2328 self.i2s_mclk_out[I2sInstance::I2s0 as usize]
2329 }
2330 pub fn rmt_sclk(&self) -> Option<RmtSclkConfig> {
2332 self.rmt_sclk[RmtInstance::Rmt as usize]
2333 }
2334 pub fn spi2_function_clock(&self) -> Option<SpiFunctionClockConfig> {
2336 self.spi_function_clock[SpiInstance::Spi2 as usize]
2337 }
2338 pub fn timg0_function_clock(&self) -> Option<TimgFunctionClockConfig> {
2340 self.timg_function_clock[TimgInstance::Timg0 as usize]
2341 }
2342 pub fn timg0_wdt_clock(&self) -> Option<TimgWdtClockConfig> {
2344 self.timg_wdt_clock[TimgInstance::Timg0 as usize]
2345 }
2346 pub fn timg1_function_clock(&self) -> Option<TimgFunctionClockConfig> {
2348 self.timg_function_clock[TimgInstance::Timg1 as usize]
2349 }
2350 pub fn timg1_wdt_clock(&self) -> Option<TimgWdtClockConfig> {
2352 self.timg_wdt_clock[TimgInstance::Timg1 as usize]
2353 }
2354 pub fn uart0_function_clock(&self) -> Option<UartFunctionClockConfig> {
2356 self.uart_function_clock[UartInstance::Uart0 as usize]
2357 }
2358 pub fn uart0_baud_rate_generator(&self) -> Option<UartBaudRateGeneratorConfig> {
2360 self.uart_baud_rate_generator[UartInstance::Uart0 as usize]
2361 }
2362 pub fn uart1_function_clock(&self) -> Option<UartFunctionClockConfig> {
2364 self.uart_function_clock[UartInstance::Uart1 as usize]
2365 }
2366 pub fn uart1_baud_rate_generator(&self) -> Option<UartBaudRateGeneratorConfig> {
2368 self.uart_baud_rate_generator[UartInstance::Uart1 as usize]
2369 }
2370 pub fn tsens_sclk(&self) -> Option<TsensSclkConfig> {
2372 self.tsens_sclk[TsensInstance::Tsens as usize]
2373 }
2374 }
2375 static CLOCK_TREE: ::esp_sync::NonReentrantMutex<ClockTree> =
2376 ::esp_sync::NonReentrantMutex::new(ClockTree {
2377 xtal_clk: None,
2378 pll_clk: None,
2379 system_pre_div_in: None,
2380 system_pre_div: None,
2381 cpu_pll_div_out: None,
2382 apb_clk: None,
2383 crypto_clk: None,
2384 cpu_clk: None,
2385 rc_fast_clk_div_n: None,
2386 rtc_slow_clk: None,
2387 ble_lp_clk: None,
2388 rtc_fast_clk: None,
2389 low_power_clk: None,
2390 timg_calibration_clock: None,
2391 i2c_function_clock: [None; 1],
2392 i2s_tx_clk: [None; 1],
2393 i2s_rx_clk: [None; 1],
2394 i2s_mclk_out: [None; 1],
2395 rmt_sclk: [None; 1],
2396 spi_function_clock: [None; 1],
2397 timg_function_clock: [None; 2],
2398 timg_wdt_clock: [None; 2],
2399 uart_function_clock: [None; 2],
2400 uart_baud_rate_generator: [None; 2],
2401 tsens_sclk: [None; 1],
2402 rc_fast_clk_refcount: 0,
2403 #[cfg(use_xtal32k)]
2404 xtal32k_clk_refcount: 0,
2405 rc_slow_clk_refcount: 0,
2406 rc_fast_div_clk_refcount: 0,
2407 apb_clk_refcount: 0,
2408 crypto_clk_refcount: 0,
2409 pll_80m_refcount: 0,
2410 pll_160m_refcount: 0,
2411 rtc_slow_clk_refcount: 0,
2412 ble_lp_clk_refcount: 0,
2413 rtc_fast_clk_refcount: 0,
2414 low_power_clk_refcount: 0,
2415 uart_mem_clk_refcount: 0,
2416 timg_calibration_clock_refcount: 0,
2417 adc_function_clock_refcount: [0; 1],
2418 sdm_function_clock_refcount: [0; 1],
2419 i2c_function_clock_refcount: [0; 1],
2420 i2s_tx_clk_refcount: [0; 1],
2421 i2s_rx_clk_refcount: [0; 1],
2422 i2s_mclk_out_refcount: [0; 1],
2423 rmt_sclk_refcount: [0; 1],
2424 spi_function_clock_refcount: [0; 1],
2425 timg_function_clock_refcount: [0; 2],
2426 timg_wdt_clock_refcount: [0; 2],
2427 uart_function_clock_refcount: [0; 2],
2428 uart_mem_clock_refcount: [0; 2],
2429 uart_baud_rate_generator_refcount: [0; 2],
2430 tsens_sclk_refcount: [0; 1],
2431 });
2432 static XTAL_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2433 ::core::sync::atomic::AtomicU32::new(0);
2434 static PLL_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2435 ::core::sync::atomic::AtomicU32::new(0);
2436 static SYSTEM_PRE_DIV_IN_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2437 ::core::sync::atomic::AtomicU32::new(0);
2438 static SYSTEM_PRE_DIV_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2439 ::core::sync::atomic::AtomicU32::new(0);
2440 static CPU_PLL_DIV_OUT_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2441 ::core::sync::atomic::AtomicU32::new(0);
2442 static CPU_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2443 ::core::sync::atomic::AtomicU32::new(0);
2444 static RC_FAST_CLK_DIV_N_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2445 ::core::sync::atomic::AtomicU32::new(0);
2446 static RTC_SLOW_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2447 ::core::sync::atomic::AtomicU32::new(0);
2448 static BLE_LP_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2449 ::core::sync::atomic::AtomicU32::new(0);
2450 static RTC_FAST_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2451 ::core::sync::atomic::AtomicU32::new(0);
2452 static LOW_POWER_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2453 ::core::sync::atomic::AtomicU32::new(0);
2454 static TIMG_CALIBRATION_CLOCK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2455 ::core::sync::atomic::AtomicU32::new(0);
2456 static I2C_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
2457 [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
2458 static I2S_TX_CLK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
2459 [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
2460 static I2S_RX_CLK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
2461 [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
2462 static I2S_MCLK_OUT_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
2463 [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
2464 static SPI_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
2465 [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
2466 static TSENS_SCLK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
2467 [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
2468 static APB_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2469 ::core::sync::atomic::AtomicU32::new(0);
2470 static CRYPTO_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
2471 ::core::sync::atomic::AtomicU32::new(0);
2472 static RMT_SCLK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
2473 [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
2474 static TIMG_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 2] =
2475 [const { ::core::sync::atomic::AtomicU32::new(0) }; 2];
2476 static TIMG_WDT_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 2] =
2477 [const { ::core::sync::atomic::AtomicU32::new(0) }; 2];
2478 static UART_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 2] =
2479 [const { ::core::sync::atomic::AtomicU32::new(0) }; 2];
2480 static UART_BAUD_RATE_GENERATOR_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 2] =
2481 [const { ::core::sync::atomic::AtomicU32::new(0) }; 2];
2482 #[derive(Debug, enumset::EnumSetType)]
2487 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
2488 pub enum ClockSource {
2489 XtalClk,
2491 RcFastClk,
2493 #[cfg(use_xtal32k)]
2494 Xtal32kClk,
2496 RcSlowClk,
2498 }
2499 pub fn xtal_clk_root_source(_clocks: &mut ClockTree) -> Option<ClockSource> {
2501 Some(ClockSource::XtalClk)
2502 }
2503 pub fn pll_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2505 xtal_clk_root_source(clocks)
2506 }
2507 pub fn rc_fast_clk_root_source(_clocks: &mut ClockTree) -> Option<ClockSource> {
2509 Some(ClockSource::RcFastClk)
2510 }
2511 #[cfg(use_xtal32k)]
2512 pub fn xtal32k_clk_root_source(_clocks: &mut ClockTree) -> Option<ClockSource> {
2514 Some(ClockSource::Xtal32kClk)
2515 }
2516 pub fn rc_slow_clk_root_source(_clocks: &mut ClockTree) -> Option<ClockSource> {
2518 Some(ClockSource::RcSlowClk)
2519 }
2520 pub fn rc_fast_div_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2522 rc_fast_clk_root_source(clocks)
2523 }
2524 pub fn system_pre_div_in_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2526 let config = clocks.system_pre_div_in?;
2527 match config {
2528 SystemPreDivInConfig::Xtal => xtal_clk_root_source(clocks),
2529 SystemPreDivInConfig::RcFast => rc_fast_clk_root_source(clocks),
2530 }
2531 }
2532 pub fn system_pre_div_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2534 system_pre_div_in_root_source(clocks)
2535 }
2536 pub fn cpu_pll_div_out_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2538 pll_clk_root_source(clocks)
2539 }
2540 pub fn cpu_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2542 let config = clocks.cpu_clk?;
2543 match config {
2544 CpuClkConfig::Xtal => system_pre_div_root_source(clocks),
2545 CpuClkConfig::RcFast => system_pre_div_root_source(clocks),
2546 CpuClkConfig::Pll => cpu_pll_div_out_root_source(clocks),
2547 }
2548 }
2549 pub fn pll_80m_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2551 cpu_clk_root_source(clocks)
2552 }
2553 pub fn pll_160m_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2555 cpu_clk_root_source(clocks)
2556 }
2557 pub fn rc_fast_clk_div_n_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2559 rc_fast_clk_root_source(clocks)
2560 }
2561 pub fn xtal_div_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2563 xtal_clk_root_source(clocks)
2564 }
2565 pub fn rtc_slow_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2567 let config = clocks.rtc_slow_clk?;
2568 match config {
2569 #[cfg(use_xtal32k)]
2570 RtcSlowClkConfig::Xtal32k => xtal32k_clk_root_source(clocks),
2571 RtcSlowClkConfig::RcSlow => rc_slow_clk_root_source(clocks),
2572 RtcSlowClkConfig::RcFast => rc_fast_div_clk_root_source(clocks),
2573 }
2574 }
2575 pub fn ble_lp_xtal_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2577 xtal_clk_root_source(clocks)
2578 }
2579 pub fn ble_lp_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2581 let config = clocks.ble_lp_clk?;
2582 match config {
2583 BleLpClkConfig::Xtal => ble_lp_xtal_clk_root_source(clocks),
2584 BleLpClkConfig::RtcSlow => rtc_slow_clk_root_source(clocks),
2585 }
2586 }
2587 pub fn rtc_fast_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2589 let config = clocks.rtc_fast_clk?;
2590 match config {
2591 RtcFastClkConfig::Xtal => xtal_div_clk_root_source(clocks),
2592 RtcFastClkConfig::Rc => rc_fast_clk_div_n_root_source(clocks),
2593 }
2594 }
2595 pub fn low_power_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2597 let config = clocks.low_power_clk?;
2598 match config {
2599 LowPowerClkConfig::Xtal => xtal_clk_root_source(clocks),
2600 LowPowerClkConfig::RcFast => rc_fast_clk_root_source(clocks),
2601 #[cfg(use_xtal32k)]
2602 LowPowerClkConfig::Xtal32k => xtal32k_clk_root_source(clocks),
2603 LowPowerClkConfig::RtcSlow => rtc_slow_clk_root_source(clocks),
2604 }
2605 }
2606 pub fn uart_mem_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2608 xtal_clk_root_source(clocks)
2609 }
2610 pub fn timg_calibration_clock_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2612 let config = clocks.timg_calibration_clock?;
2613 match config {
2614 TimgCalibrationClockConfig::RcSlowClk => rc_slow_clk_root_source(clocks),
2615 TimgCalibrationClockConfig::RcFastDivClk => rc_fast_div_clk_root_source(clocks),
2616 #[cfg(use_xtal32k)]
2617 TimgCalibrationClockConfig::Xtal32kClk => xtal32k_clk_root_source(clocks),
2618 }
2619 }
2620 pub fn apb_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2622 let config = clocks.apb_clk?;
2623 match config {
2624 ApbClkConfig::Pll80m => pll_80m_root_source(clocks),
2625 ApbClkConfig::Cpu => cpu_clk_root_source(clocks),
2626 }
2627 }
2628 pub fn crypto_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2630 let config = clocks.crypto_clk?;
2631 match config {
2632 CryptoClkConfig::Pll160m => pll_160m_root_source(clocks),
2633 CryptoClkConfig::Cpu => cpu_clk_root_source(clocks),
2634 }
2635 }
2636 pub fn configure_xtal_clk(clocks: &mut ClockTree, config: XtalClkConfig) {
2637 let old_config = clocks.xtal_clk.replace(config);
2638 refresh_xtal_clk_downstream(clocks);
2639 configure_xtal_clk_impl(clocks, old_config, config);
2640 }
2641 pub fn xtal_clk_config(clocks: &mut ClockTree) -> Option<XtalClkConfig> {
2642 clocks.xtal_clk
2643 }
2644 fn request_xtal_clk(_clocks: &mut ClockTree) {}
2645 fn release_xtal_clk(_clocks: &mut ClockTree) {}
2646 pub fn xtal_clk_config_frequency(config: XtalClkConfig) -> u32 {
2647 config.value()
2648 }
2649 pub fn xtal_clk_frequency() -> u32 {
2650 XTAL_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2651 }
2652 pub fn configure_pll_clk(clocks: &mut ClockTree, config: PllClkConfig) {
2653 let old_config = clocks.pll_clk.replace(config);
2654 refresh_pll_clk_downstream(clocks);
2655 configure_pll_clk_impl(clocks, old_config, config);
2656 }
2657 pub fn pll_clk_config(clocks: &mut ClockTree) -> Option<PllClkConfig> {
2658 clocks.pll_clk
2659 }
2660 pub fn request_pll_clk(clocks: &mut ClockTree) {
2661 trace!("Enabling PLL_CLK");
2662 request_xtal_clk(clocks);
2663 enable_pll_clk_impl(clocks, true);
2664 }
2665 pub fn release_pll_clk(clocks: &mut ClockTree) {
2666 trace!("Disabling PLL_CLK");
2667 enable_pll_clk_impl(clocks, false);
2668 release_xtal_clk(clocks);
2669 }
2670 pub fn pll_clk_config_frequency(config: PllClkConfig) -> u32 {
2671 config.value()
2672 }
2673 pub fn pll_clk_frequency() -> u32 {
2674 PLL_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2675 }
2676 pub fn pll_clk_source_frequency() -> u32 {
2677 xtal_clk_frequency()
2678 }
2679 pub fn request_rc_fast_clk(clocks: &mut ClockTree) {
2680 trace!("Requesting RC_FAST_CLK");
2681 if increment_reference_count(&mut clocks.rc_fast_clk_refcount) {
2682 trace!("Enabling RC_FAST_CLK");
2683 enable_rc_fast_clk_impl(clocks, true);
2684 }
2685 }
2686 pub fn release_rc_fast_clk(clocks: &mut ClockTree) {
2687 trace!("Releasing RC_FAST_CLK");
2688 if decrement_reference_count(&mut clocks.rc_fast_clk_refcount) {
2689 trace!("Disabling RC_FAST_CLK");
2690 enable_rc_fast_clk_impl(clocks, false);
2691 }
2692 }
2693 static RC_FAST_CLK_FREQUENCY: ::core::sync::atomic::AtomicU32 =
2694 ::core::sync::atomic::AtomicU32::new(rc_fast_clk_nominal_frequency());
2695 pub const fn rc_fast_clk_nominal_frequency() -> u32 {
2696 17500000
2697 }
2698 pub fn rc_fast_clk_frequency() -> u32 {
2699 RC_FAST_CLK_FREQUENCY.load(::core::sync::atomic::Ordering::Acquire)
2700 }
2701 pub fn set_rc_fast_clk_frequency(clocks: &mut ClockTree, frequency: u32) {
2702 if !(8750000..=26250000).contains(&frequency) {
2703 warn!(
2704 "Ignoring out-of-range RC_FAST_CLK frequency: {} Hz",
2705 frequency
2706 );
2707 return;
2708 }
2709 debug!(
2710 "Updating RC_FAST_CLK frequency to {} Hz (nominal {} Hz)",
2711 frequency,
2712 rc_fast_clk_nominal_frequency()
2713 );
2714 RC_FAST_CLK_FREQUENCY.store(frequency, ::core::sync::atomic::Ordering::Release);
2715 refresh_rc_fast_clk_downstream(clocks);
2716 }
2717 #[cfg(use_xtal32k)]
2718 pub fn request_xtal32k_clk(clocks: &mut ClockTree) {
2719 trace!("Requesting XTAL32K_CLK");
2720 if increment_reference_count(&mut clocks.xtal32k_clk_refcount) {
2721 trace!("Enabling XTAL32K_CLK");
2722 enable_xtal32k_clk_impl(clocks, true);
2723 }
2724 }
2725 #[cfg(use_xtal32k)]
2726 pub fn release_xtal32k_clk(clocks: &mut ClockTree) {
2727 trace!("Releasing XTAL32K_CLK");
2728 if decrement_reference_count(&mut clocks.xtal32k_clk_refcount) {
2729 trace!("Disabling XTAL32K_CLK");
2730 enable_xtal32k_clk_impl(clocks, false);
2731 }
2732 }
2733 #[cfg(use_xtal32k)]
2734 pub fn xtal32k_clk_frequency() -> u32 {
2735 32768
2736 }
2737 pub fn request_rc_slow_clk(clocks: &mut ClockTree) {
2738 trace!("Requesting RC_SLOW_CLK");
2739 if increment_reference_count(&mut clocks.rc_slow_clk_refcount) {
2740 trace!("Enabling RC_SLOW_CLK");
2741 enable_rc_slow_clk_impl(clocks, true);
2742 }
2743 }
2744 pub fn release_rc_slow_clk(clocks: &mut ClockTree) {
2745 trace!("Releasing RC_SLOW_CLK");
2746 if decrement_reference_count(&mut clocks.rc_slow_clk_refcount) {
2747 trace!("Disabling RC_SLOW_CLK");
2748 enable_rc_slow_clk_impl(clocks, false);
2749 }
2750 }
2751 static RC_SLOW_CLK_FREQUENCY: ::core::sync::atomic::AtomicU32 =
2752 ::core::sync::atomic::AtomicU32::new(rc_slow_clk_nominal_frequency());
2753 pub const fn rc_slow_clk_nominal_frequency() -> u32 {
2754 136000
2755 }
2756 pub fn rc_slow_clk_frequency() -> u32 {
2757 RC_SLOW_CLK_FREQUENCY.load(::core::sync::atomic::Ordering::Acquire)
2758 }
2759 pub fn set_rc_slow_clk_frequency(clocks: &mut ClockTree, frequency: u32) {
2760 if !(68000..=204000).contains(&frequency) {
2761 warn!(
2762 "Ignoring out-of-range RC_SLOW_CLK frequency: {} Hz",
2763 frequency
2764 );
2765 return;
2766 }
2767 debug!(
2768 "Updating RC_SLOW_CLK frequency to {} Hz (nominal {} Hz)",
2769 frequency,
2770 rc_slow_clk_nominal_frequency()
2771 );
2772 RC_SLOW_CLK_FREQUENCY.store(frequency, ::core::sync::atomic::Ordering::Release);
2773 refresh_rc_slow_clk_downstream(clocks);
2774 }
2775 pub fn request_rc_fast_div_clk(clocks: &mut ClockTree) {
2776 trace!("Requesting RC_FAST_DIV_CLK");
2777 if increment_reference_count(&mut clocks.rc_fast_div_clk_refcount) {
2778 trace!("Enabling RC_FAST_DIV_CLK");
2779 request_rc_fast_clk(clocks);
2780 enable_rc_fast_div_clk_impl(clocks, true);
2781 }
2782 }
2783 pub fn release_rc_fast_div_clk(clocks: &mut ClockTree) {
2784 trace!("Releasing RC_FAST_DIV_CLK");
2785 if decrement_reference_count(&mut clocks.rc_fast_div_clk_refcount) {
2786 trace!("Disabling RC_FAST_DIV_CLK");
2787 enable_rc_fast_div_clk_impl(clocks, false);
2788 release_rc_fast_clk(clocks);
2789 }
2790 }
2791 pub fn rc_fast_div_clk_frequency() -> u32 {
2792 (rc_fast_clk_frequency() / 256)
2793 }
2794 pub fn rc_fast_div_clk_source_frequency() -> u32 {
2795 rc_fast_clk_frequency()
2796 }
2797 pub fn configure_system_pre_div_in(
2798 clocks: &mut ClockTree,
2799 new_selector: SystemPreDivInConfig,
2800 ) {
2801 let old_selector = clocks.system_pre_div_in.replace(new_selector);
2802 refresh_system_pre_div_in_downstream(clocks);
2803 match new_selector {
2804 SystemPreDivInConfig::Xtal => request_xtal_clk(clocks),
2805 SystemPreDivInConfig::RcFast => request_rc_fast_clk(clocks),
2806 }
2807 configure_system_pre_div_in_impl(clocks, old_selector, new_selector);
2808 if let Some(old_selector) = old_selector {
2809 match old_selector {
2810 SystemPreDivInConfig::Xtal => release_xtal_clk(clocks),
2811 SystemPreDivInConfig::RcFast => release_rc_fast_clk(clocks),
2812 }
2813 }
2814 }
2815 pub fn system_pre_div_in_config(clocks: &mut ClockTree) -> Option<SystemPreDivInConfig> {
2816 clocks.system_pre_div_in
2817 }
2818 pub fn request_system_pre_div_in(clocks: &mut ClockTree) {
2819 trace!("Enabling SYSTEM_PRE_DIV_IN");
2820 match unwrap!(clocks.system_pre_div_in) {
2821 SystemPreDivInConfig::Xtal => request_xtal_clk(clocks),
2822 SystemPreDivInConfig::RcFast => request_rc_fast_clk(clocks),
2823 }
2824 enable_system_pre_div_in_impl(clocks, true);
2825 }
2826 pub fn release_system_pre_div_in(clocks: &mut ClockTree) {
2827 trace!("Disabling SYSTEM_PRE_DIV_IN");
2828 enable_system_pre_div_in_impl(clocks, false);
2829 match unwrap!(clocks.system_pre_div_in) {
2830 SystemPreDivInConfig::Xtal => release_xtal_clk(clocks),
2831 SystemPreDivInConfig::RcFast => release_rc_fast_clk(clocks),
2832 }
2833 }
2834 pub fn system_pre_div_in_config_frequency(config: SystemPreDivInConfig) -> u32 {
2835 match config {
2836 SystemPreDivInConfig::Xtal => xtal_clk_frequency(),
2837 SystemPreDivInConfig::RcFast => rc_fast_clk_frequency(),
2838 }
2839 }
2840 pub fn system_pre_div_in_frequency() -> u32 {
2841 SYSTEM_PRE_DIV_IN_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2842 }
2843 pub fn system_pre_div_in_source_frequency(source: SystemPreDivInConfig) -> u32 {
2844 system_pre_div_in_config_frequency(source)
2845 }
2846 pub fn configure_system_pre_div(clocks: &mut ClockTree, config: SystemPreDivConfig) {
2847 let old_config = clocks.system_pre_div.replace(config);
2848 refresh_system_pre_div_downstream(clocks);
2849 configure_system_pre_div_impl(clocks, old_config, config);
2850 }
2851 pub fn system_pre_div_config(clocks: &mut ClockTree) -> Option<SystemPreDivConfig> {
2852 clocks.system_pre_div
2853 }
2854 pub fn request_system_pre_div(clocks: &mut ClockTree) {
2855 trace!("Enabling SYSTEM_PRE_DIV");
2856 request_system_pre_div_in(clocks);
2857 enable_system_pre_div_impl(clocks, true);
2858 }
2859 pub fn release_system_pre_div(clocks: &mut ClockTree) {
2860 trace!("Disabling SYSTEM_PRE_DIV");
2861 enable_system_pre_div_impl(clocks, false);
2862 release_system_pre_div_in(clocks);
2863 }
2864 pub fn system_pre_div_config_frequency(config: SystemPreDivConfig) -> u32 {
2865 (system_pre_div_in_frequency() / (config.divisor() + 1))
2866 }
2867 pub fn system_pre_div_frequency() -> u32 {
2868 SYSTEM_PRE_DIV_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2869 }
2870 pub fn system_pre_div_source_frequency() -> u32 {
2871 system_pre_div_in_frequency()
2872 }
2873 pub fn configure_cpu_pll_div_out(clocks: &mut ClockTree, config: CpuPllDivOutConfig) {
2874 let old_config = clocks.cpu_pll_div_out.replace(config);
2875 refresh_cpu_pll_div_out_downstream(clocks);
2876 configure_cpu_pll_div_out_impl(clocks, old_config, config);
2877 }
2878 pub fn cpu_pll_div_out_config(clocks: &mut ClockTree) -> Option<CpuPllDivOutConfig> {
2879 clocks.cpu_pll_div_out
2880 }
2881 pub fn request_cpu_pll_div_out(clocks: &mut ClockTree) {
2882 trace!("Enabling CPU_PLL_DIV_OUT");
2883 request_pll_clk(clocks);
2884 enable_cpu_pll_div_out_impl(clocks, true);
2885 }
2886 pub fn release_cpu_pll_div_out(clocks: &mut ClockTree) {
2887 trace!("Disabling CPU_PLL_DIV_OUT");
2888 enable_cpu_pll_div_out_impl(clocks, false);
2889 release_pll_clk(clocks);
2890 }
2891 pub fn cpu_pll_div_out_config_frequency(config: CpuPllDivOutConfig) -> u32 {
2892 config.value()
2893 }
2894 pub fn cpu_pll_div_out_frequency() -> u32 {
2895 CPU_PLL_DIV_OUT_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2896 }
2897 pub fn cpu_pll_div_out_source_frequency() -> u32 {
2898 pll_clk_frequency()
2899 }
2900 pub fn configure_apb_clk(clocks: &mut ClockTree, new_selector: ApbClkConfig) {
2901 let old_selector = clocks.apb_clk.replace(new_selector);
2902 refresh_apb_clk_downstream(clocks);
2903 let active = clocks.apb_clk_refcount > 0;
2904 if active {
2905 match new_selector {
2906 ApbClkConfig::Pll80m => request_pll_80m(clocks),
2907 ApbClkConfig::Cpu => request_cpu_clk(clocks),
2908 }
2909 }
2910 configure_apb_clk_impl(clocks, old_selector, new_selector);
2911 if active && let Some(old_selector) = old_selector {
2912 match old_selector {
2913 ApbClkConfig::Pll80m => release_pll_80m(clocks),
2914 ApbClkConfig::Cpu => release_cpu_clk(clocks),
2915 }
2916 }
2917 }
2918 pub fn apb_clk_config(clocks: &mut ClockTree) -> Option<ApbClkConfig> {
2919 clocks.apb_clk
2920 }
2921 pub fn request_apb_clk(clocks: &mut ClockTree) {
2922 trace!("Requesting APB_CLK");
2923 if increment_reference_count(&mut clocks.apb_clk_refcount) {
2924 trace!("Enabling APB_CLK");
2925 match unwrap!(clocks.apb_clk) {
2926 ApbClkConfig::Pll80m => request_pll_80m(clocks),
2927 ApbClkConfig::Cpu => request_cpu_clk(clocks),
2928 }
2929 enable_apb_clk_impl(clocks, true);
2930 }
2931 }
2932 pub fn release_apb_clk(clocks: &mut ClockTree) {
2933 trace!("Releasing APB_CLK");
2934 if decrement_reference_count(&mut clocks.apb_clk_refcount) {
2935 trace!("Disabling APB_CLK");
2936 enable_apb_clk_impl(clocks, false);
2937 match unwrap!(clocks.apb_clk) {
2938 ApbClkConfig::Pll80m => release_pll_80m(clocks),
2939 ApbClkConfig::Cpu => release_cpu_clk(clocks),
2940 }
2941 }
2942 }
2943 pub fn apb_clk_config_frequency(config: ApbClkConfig) -> u32 {
2944 match config {
2945 ApbClkConfig::Pll80m => pll_80m_frequency(),
2946 ApbClkConfig::Cpu => cpu_clk_frequency(),
2947 }
2948 }
2949 pub fn apb_clk_frequency() -> u32 {
2950 APB_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2951 }
2952 pub fn apb_clk_source_frequency(source: ApbClkConfig) -> u32 {
2953 apb_clk_config_frequency(source)
2954 }
2955 pub fn configure_crypto_clk(clocks: &mut ClockTree, new_selector: CryptoClkConfig) {
2956 let old_selector = clocks.crypto_clk.replace(new_selector);
2957 refresh_crypto_clk_downstream(clocks);
2958 let active = clocks.crypto_clk_refcount > 0;
2959 if active {
2960 match new_selector {
2961 CryptoClkConfig::Pll160m => request_pll_160m(clocks),
2962 CryptoClkConfig::Cpu => request_cpu_clk(clocks),
2963 }
2964 }
2965 configure_crypto_clk_impl(clocks, old_selector, new_selector);
2966 if active && let Some(old_selector) = old_selector {
2967 match old_selector {
2968 CryptoClkConfig::Pll160m => release_pll_160m(clocks),
2969 CryptoClkConfig::Cpu => release_cpu_clk(clocks),
2970 }
2971 }
2972 }
2973 pub fn crypto_clk_config(clocks: &mut ClockTree) -> Option<CryptoClkConfig> {
2974 clocks.crypto_clk
2975 }
2976 pub fn request_crypto_clk(clocks: &mut ClockTree) {
2977 trace!("Requesting CRYPTO_CLK");
2978 if increment_reference_count(&mut clocks.crypto_clk_refcount) {
2979 trace!("Enabling CRYPTO_CLK");
2980 match unwrap!(clocks.crypto_clk) {
2981 CryptoClkConfig::Pll160m => request_pll_160m(clocks),
2982 CryptoClkConfig::Cpu => request_cpu_clk(clocks),
2983 }
2984 enable_crypto_clk_impl(clocks, true);
2985 }
2986 }
2987 pub fn release_crypto_clk(clocks: &mut ClockTree) {
2988 trace!("Releasing CRYPTO_CLK");
2989 if decrement_reference_count(&mut clocks.crypto_clk_refcount) {
2990 trace!("Disabling CRYPTO_CLK");
2991 enable_crypto_clk_impl(clocks, false);
2992 match unwrap!(clocks.crypto_clk) {
2993 CryptoClkConfig::Pll160m => release_pll_160m(clocks),
2994 CryptoClkConfig::Cpu => release_cpu_clk(clocks),
2995 }
2996 }
2997 }
2998 pub fn crypto_clk_config_frequency(config: CryptoClkConfig) -> u32 {
2999 match config {
3000 CryptoClkConfig::Pll160m => pll_160m_frequency(),
3001 CryptoClkConfig::Cpu => cpu_clk_frequency(),
3002 }
3003 }
3004 pub fn crypto_clk_frequency() -> u32 {
3005 CRYPTO_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
3006 }
3007 pub fn crypto_clk_source_frequency(source: CryptoClkConfig) -> u32 {
3008 crypto_clk_config_frequency(source)
3009 }
3010 pub fn configure_cpu_clk(clocks: &mut ClockTree, new_selector: CpuClkConfig) {
3011 let old_selector = clocks.cpu_clk.replace(new_selector);
3012 refresh_cpu_clk_downstream(clocks);
3013 match new_selector {
3014 CpuClkConfig::Xtal => {
3015 configure_apb_clk(clocks, ApbClkConfig::Cpu);
3016 configure_crypto_clk(clocks, CryptoClkConfig::Cpu);
3017 configure_system_pre_div_in(clocks, SystemPreDivInConfig::Xtal);
3018 }
3019 CpuClkConfig::RcFast => {
3020 configure_apb_clk(clocks, ApbClkConfig::Cpu);
3021 configure_crypto_clk(clocks, CryptoClkConfig::Cpu);
3022 configure_system_pre_div_in(clocks, SystemPreDivInConfig::RcFast);
3023 }
3024 CpuClkConfig::Pll => {
3025 configure_apb_clk(clocks, ApbClkConfig::Pll80m);
3026 configure_crypto_clk(clocks, CryptoClkConfig::Pll160m);
3027 }
3028 }
3029 match new_selector {
3030 CpuClkConfig::Xtal => request_system_pre_div(clocks),
3031 CpuClkConfig::RcFast => request_system_pre_div(clocks),
3032 CpuClkConfig::Pll => request_cpu_pll_div_out(clocks),
3033 }
3034 configure_cpu_clk_impl(clocks, old_selector, new_selector);
3035 if let Some(old_selector) = old_selector {
3036 match old_selector {
3037 CpuClkConfig::Xtal => release_system_pre_div(clocks),
3038 CpuClkConfig::RcFast => release_system_pre_div(clocks),
3039 CpuClkConfig::Pll => release_cpu_pll_div_out(clocks),
3040 }
3041 }
3042 }
3043 pub fn cpu_clk_config(clocks: &mut ClockTree) -> Option<CpuClkConfig> {
3044 clocks.cpu_clk
3045 }
3046 fn request_cpu_clk(_clocks: &mut ClockTree) {}
3047 fn release_cpu_clk(_clocks: &mut ClockTree) {}
3048 pub fn cpu_clk_config_frequency(config: CpuClkConfig) -> u32 {
3049 match config {
3050 CpuClkConfig::Xtal => system_pre_div_frequency(),
3051 CpuClkConfig::RcFast => system_pre_div_frequency(),
3052 CpuClkConfig::Pll => cpu_pll_div_out_frequency(),
3053 }
3054 }
3055 pub fn cpu_clk_frequency() -> u32 {
3056 CPU_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
3057 }
3058 pub fn request_pll_80m(clocks: &mut ClockTree) {
3059 trace!("Requesting PLL_80M");
3060 if increment_reference_count(&mut clocks.pll_80m_refcount) {
3061 trace!("Enabling PLL_80M");
3062 request_cpu_clk(clocks);
3063 enable_pll_80m_impl(clocks, true);
3064 }
3065 }
3066 pub fn release_pll_80m(clocks: &mut ClockTree) {
3067 trace!("Releasing PLL_80M");
3068 if decrement_reference_count(&mut clocks.pll_80m_refcount) {
3069 trace!("Disabling PLL_80M");
3070 enable_pll_80m_impl(clocks, false);
3071 release_cpu_clk(clocks);
3072 }
3073 }
3074 pub fn pll_80m_frequency() -> u32 {
3075 80000000
3076 }
3077 pub fn pll_80m_source_frequency() -> u32 {
3078 cpu_clk_frequency()
3079 }
3080 pub fn request_pll_160m(clocks: &mut ClockTree) {
3081 trace!("Requesting PLL_160M");
3082 if increment_reference_count(&mut clocks.pll_160m_refcount) {
3083 trace!("Enabling PLL_160M");
3084 request_cpu_clk(clocks);
3085 enable_pll_160m_impl(clocks, true);
3086 }
3087 }
3088 pub fn release_pll_160m(clocks: &mut ClockTree) {
3089 trace!("Releasing PLL_160M");
3090 if decrement_reference_count(&mut clocks.pll_160m_refcount) {
3091 trace!("Disabling PLL_160M");
3092 enable_pll_160m_impl(clocks, false);
3093 release_cpu_clk(clocks);
3094 }
3095 }
3096 pub fn pll_160m_frequency() -> u32 {
3097 160000000
3098 }
3099 pub fn pll_160m_source_frequency() -> u32 {
3100 cpu_clk_frequency()
3101 }
3102 pub fn configure_rc_fast_clk_div_n(clocks: &mut ClockTree, config: RcFastClkDivNConfig) {
3103 let old_config = clocks.rc_fast_clk_div_n.replace(config);
3104 refresh_rc_fast_clk_div_n_downstream(clocks);
3105 configure_rc_fast_clk_div_n_impl(clocks, old_config, config);
3106 }
3107 pub fn rc_fast_clk_div_n_config(clocks: &mut ClockTree) -> Option<RcFastClkDivNConfig> {
3108 clocks.rc_fast_clk_div_n
3109 }
3110 pub fn request_rc_fast_clk_div_n(clocks: &mut ClockTree) {
3111 trace!("Enabling RC_FAST_CLK_DIV_N");
3112 request_rc_fast_clk(clocks);
3113 enable_rc_fast_clk_div_n_impl(clocks, true);
3114 }
3115 pub fn release_rc_fast_clk_div_n(clocks: &mut ClockTree) {
3116 trace!("Disabling RC_FAST_CLK_DIV_N");
3117 enable_rc_fast_clk_div_n_impl(clocks, false);
3118 release_rc_fast_clk(clocks);
3119 }
3120 pub fn rc_fast_clk_div_n_config_frequency(config: RcFastClkDivNConfig) -> u32 {
3121 (rc_fast_clk_frequency() / (config.divisor() + 1))
3122 }
3123 pub fn rc_fast_clk_div_n_frequency() -> u32 {
3124 RC_FAST_CLK_DIV_N_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
3125 }
3126 pub fn rc_fast_clk_div_n_source_frequency() -> u32 {
3127 rc_fast_clk_frequency()
3128 }
3129 pub fn request_xtal_div_clk(clocks: &mut ClockTree) {
3130 trace!("Enabling XTAL_DIV_CLK");
3131 request_xtal_clk(clocks);
3132 enable_xtal_div_clk_impl(clocks, true);
3133 }
3134 pub fn release_xtal_div_clk(clocks: &mut ClockTree) {
3135 trace!("Disabling XTAL_DIV_CLK");
3136 enable_xtal_div_clk_impl(clocks, false);
3137 release_xtal_clk(clocks);
3138 }
3139 pub fn xtal_div_clk_frequency() -> u32 {
3140 (xtal_clk_frequency() / 2)
3141 }
3142 pub fn xtal_div_clk_source_frequency() -> u32 {
3143 xtal_clk_frequency()
3144 }
3145 pub fn configure_rtc_slow_clk(clocks: &mut ClockTree, new_selector: RtcSlowClkConfig) {
3146 let old_selector = clocks.rtc_slow_clk.replace(new_selector);
3147 refresh_rtc_slow_clk_downstream(clocks);
3148 let active = clocks.rtc_slow_clk_refcount > 0;
3149 if active {
3150 match new_selector {
3151 #[cfg(use_xtal32k)]
3152 RtcSlowClkConfig::Xtal32k => request_xtal32k_clk(clocks),
3153 RtcSlowClkConfig::RcSlow => request_rc_slow_clk(clocks),
3154 RtcSlowClkConfig::RcFast => request_rc_fast_div_clk(clocks),
3155 }
3156 }
3157 configure_rtc_slow_clk_impl(clocks, old_selector, new_selector);
3158 if active && let Some(old_selector) = old_selector {
3159 match old_selector {
3160 #[cfg(use_xtal32k)]
3161 RtcSlowClkConfig::Xtal32k => release_xtal32k_clk(clocks),
3162 RtcSlowClkConfig::RcSlow => release_rc_slow_clk(clocks),
3163 RtcSlowClkConfig::RcFast => release_rc_fast_div_clk(clocks),
3164 }
3165 }
3166 }
3167 pub fn rtc_slow_clk_config(clocks: &mut ClockTree) -> Option<RtcSlowClkConfig> {
3168 clocks.rtc_slow_clk
3169 }
3170 pub fn request_rtc_slow_clk(clocks: &mut ClockTree) {
3171 trace!("Requesting RTC_SLOW_CLK");
3172 if increment_reference_count(&mut clocks.rtc_slow_clk_refcount) {
3173 trace!("Enabling RTC_SLOW_CLK");
3174 match unwrap!(clocks.rtc_slow_clk) {
3175 #[cfg(use_xtal32k)]
3176 RtcSlowClkConfig::Xtal32k => request_xtal32k_clk(clocks),
3177 RtcSlowClkConfig::RcSlow => request_rc_slow_clk(clocks),
3178 RtcSlowClkConfig::RcFast => request_rc_fast_div_clk(clocks),
3179 }
3180 enable_rtc_slow_clk_impl(clocks, true);
3181 }
3182 }
3183 pub fn release_rtc_slow_clk(clocks: &mut ClockTree) {
3184 trace!("Releasing RTC_SLOW_CLK");
3185 if decrement_reference_count(&mut clocks.rtc_slow_clk_refcount) {
3186 trace!("Disabling RTC_SLOW_CLK");
3187 enable_rtc_slow_clk_impl(clocks, false);
3188 match unwrap!(clocks.rtc_slow_clk) {
3189 #[cfg(use_xtal32k)]
3190 RtcSlowClkConfig::Xtal32k => release_xtal32k_clk(clocks),
3191 RtcSlowClkConfig::RcSlow => release_rc_slow_clk(clocks),
3192 RtcSlowClkConfig::RcFast => release_rc_fast_div_clk(clocks),
3193 }
3194 }
3195 }
3196 pub fn rtc_slow_clk_config_frequency(config: RtcSlowClkConfig) -> u32 {
3197 match config {
3198 #[cfg(use_xtal32k)]
3199 RtcSlowClkConfig::Xtal32k => xtal32k_clk_frequency(),
3200 RtcSlowClkConfig::RcSlow => rc_slow_clk_frequency(),
3201 RtcSlowClkConfig::RcFast => rc_fast_div_clk_frequency(),
3202 }
3203 }
3204 pub fn rtc_slow_clk_frequency() -> u32 {
3205 RTC_SLOW_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
3206 }
3207 pub fn rtc_slow_clk_source_frequency(source: RtcSlowClkConfig) -> u32 {
3208 rtc_slow_clk_config_frequency(source)
3209 }
3210 pub fn request_ble_lp_xtal_clk(clocks: &mut ClockTree) {
3211 trace!("Enabling BLE_LP_XTAL_CLK");
3212 request_xtal_clk(clocks);
3213 enable_ble_lp_xtal_clk_impl(clocks, true);
3214 }
3215 pub fn release_ble_lp_xtal_clk(clocks: &mut ClockTree) {
3216 trace!("Disabling BLE_LP_XTAL_CLK");
3217 enable_ble_lp_xtal_clk_impl(clocks, false);
3218 release_xtal_clk(clocks);
3219 }
3220 pub fn ble_lp_xtal_clk_frequency() -> u32 {
3221 1000000
3222 }
3223 pub fn ble_lp_xtal_clk_source_frequency() -> u32 {
3224 xtal_clk_frequency()
3225 }
3226 pub fn configure_ble_lp_clk(clocks: &mut ClockTree, new_selector: BleLpClkConfig) {
3227 let old_selector = clocks.ble_lp_clk.replace(new_selector);
3228 refresh_ble_lp_clk_downstream(clocks);
3229 let active = clocks.ble_lp_clk_refcount > 0;
3230 if active {
3231 match new_selector {
3232 BleLpClkConfig::Xtal => request_ble_lp_xtal_clk(clocks),
3233 BleLpClkConfig::RtcSlow => request_rtc_slow_clk(clocks),
3234 }
3235 }
3236 configure_ble_lp_clk_impl(clocks, old_selector, new_selector);
3237 if active && let Some(old_selector) = old_selector {
3238 match old_selector {
3239 BleLpClkConfig::Xtal => release_ble_lp_xtal_clk(clocks),
3240 BleLpClkConfig::RtcSlow => release_rtc_slow_clk(clocks),
3241 }
3242 }
3243 }
3244 pub fn ble_lp_clk_config(clocks: &mut ClockTree) -> Option<BleLpClkConfig> {
3245 clocks.ble_lp_clk
3246 }
3247 pub fn request_ble_lp_clk(clocks: &mut ClockTree) {
3248 trace!("Requesting BLE_LP_CLK");
3249 if increment_reference_count(&mut clocks.ble_lp_clk_refcount) {
3250 trace!("Enabling BLE_LP_CLK");
3251 match unwrap!(clocks.ble_lp_clk) {
3252 BleLpClkConfig::Xtal => request_ble_lp_xtal_clk(clocks),
3253 BleLpClkConfig::RtcSlow => request_rtc_slow_clk(clocks),
3254 }
3255 enable_ble_lp_clk_impl(clocks, true);
3256 }
3257 }
3258 pub fn release_ble_lp_clk(clocks: &mut ClockTree) {
3259 trace!("Releasing BLE_LP_CLK");
3260 if decrement_reference_count(&mut clocks.ble_lp_clk_refcount) {
3261 trace!("Disabling BLE_LP_CLK");
3262 enable_ble_lp_clk_impl(clocks, false);
3263 match unwrap!(clocks.ble_lp_clk) {
3264 BleLpClkConfig::Xtal => release_ble_lp_xtal_clk(clocks),
3265 BleLpClkConfig::RtcSlow => release_rtc_slow_clk(clocks),
3266 }
3267 }
3268 }
3269 pub fn ble_lp_clk_config_frequency(config: BleLpClkConfig) -> u32 {
3270 match config {
3271 BleLpClkConfig::Xtal => ble_lp_xtal_clk_frequency(),
3272 BleLpClkConfig::RtcSlow => rtc_slow_clk_frequency(),
3273 }
3274 }
3275 pub fn ble_lp_clk_frequency() -> u32 {
3276 BLE_LP_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
3277 }
3278 pub fn ble_lp_clk_source_frequency(source: BleLpClkConfig) -> u32 {
3279 ble_lp_clk_config_frequency(source)
3280 }
3281 pub fn configure_rtc_fast_clk(clocks: &mut ClockTree, new_selector: RtcFastClkConfig) {
3282 let old_selector = clocks.rtc_fast_clk.replace(new_selector);
3283 refresh_rtc_fast_clk_downstream(clocks);
3284 let active = clocks.rtc_fast_clk_refcount > 0;
3285 if active {
3286 match new_selector {
3287 RtcFastClkConfig::Xtal => request_xtal_div_clk(clocks),
3288 RtcFastClkConfig::Rc => request_rc_fast_clk_div_n(clocks),
3289 }
3290 }
3291 configure_rtc_fast_clk_impl(clocks, old_selector, new_selector);
3292 if active && let Some(old_selector) = old_selector {
3293 match old_selector {
3294 RtcFastClkConfig::Xtal => release_xtal_div_clk(clocks),
3295 RtcFastClkConfig::Rc => release_rc_fast_clk_div_n(clocks),
3296 }
3297 }
3298 }
3299 pub fn rtc_fast_clk_config(clocks: &mut ClockTree) -> Option<RtcFastClkConfig> {
3300 clocks.rtc_fast_clk
3301 }
3302 pub fn request_rtc_fast_clk(clocks: &mut ClockTree) {
3303 trace!("Requesting RTC_FAST_CLK");
3304 if increment_reference_count(&mut clocks.rtc_fast_clk_refcount) {
3305 trace!("Enabling RTC_FAST_CLK");
3306 match unwrap!(clocks.rtc_fast_clk) {
3307 RtcFastClkConfig::Xtal => request_xtal_div_clk(clocks),
3308 RtcFastClkConfig::Rc => request_rc_fast_clk_div_n(clocks),
3309 }
3310 enable_rtc_fast_clk_impl(clocks, true);
3311 }
3312 }
3313 pub fn release_rtc_fast_clk(clocks: &mut ClockTree) {
3314 trace!("Releasing RTC_FAST_CLK");
3315 if decrement_reference_count(&mut clocks.rtc_fast_clk_refcount) {
3316 trace!("Disabling RTC_FAST_CLK");
3317 enable_rtc_fast_clk_impl(clocks, false);
3318 match unwrap!(clocks.rtc_fast_clk) {
3319 RtcFastClkConfig::Xtal => release_xtal_div_clk(clocks),
3320 RtcFastClkConfig::Rc => release_rc_fast_clk_div_n(clocks),
3321 }
3322 }
3323 }
3324 pub fn rtc_fast_clk_config_frequency(config: RtcFastClkConfig) -> u32 {
3325 match config {
3326 RtcFastClkConfig::Xtal => xtal_div_clk_frequency(),
3327 RtcFastClkConfig::Rc => rc_fast_clk_div_n_frequency(),
3328 }
3329 }
3330 pub fn rtc_fast_clk_frequency() -> u32 {
3331 RTC_FAST_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
3332 }
3333 pub fn rtc_fast_clk_source_frequency(source: RtcFastClkConfig) -> u32 {
3334 rtc_fast_clk_config_frequency(source)
3335 }
3336 pub fn configure_low_power_clk(clocks: &mut ClockTree, new_selector: LowPowerClkConfig) {
3337 let old_selector = clocks.low_power_clk.replace(new_selector);
3338 refresh_low_power_clk_downstream(clocks);
3339 let active = clocks.low_power_clk_refcount > 0;
3340 if active {
3341 match new_selector {
3342 LowPowerClkConfig::Xtal => request_xtal_clk(clocks),
3343 LowPowerClkConfig::RcFast => request_rc_fast_clk(clocks),
3344 #[cfg(use_xtal32k)]
3345 LowPowerClkConfig::Xtal32k => request_xtal32k_clk(clocks),
3346 LowPowerClkConfig::RtcSlow => request_rtc_slow_clk(clocks),
3347 }
3348 }
3349 configure_low_power_clk_impl(clocks, old_selector, new_selector);
3350 if active && let Some(old_selector) = old_selector {
3351 match old_selector {
3352 LowPowerClkConfig::Xtal => release_xtal_clk(clocks),
3353 LowPowerClkConfig::RcFast => release_rc_fast_clk(clocks),
3354 #[cfg(use_xtal32k)]
3355 LowPowerClkConfig::Xtal32k => release_xtal32k_clk(clocks),
3356 LowPowerClkConfig::RtcSlow => release_rtc_slow_clk(clocks),
3357 }
3358 }
3359 }
3360 pub fn low_power_clk_config(clocks: &mut ClockTree) -> Option<LowPowerClkConfig> {
3361 clocks.low_power_clk
3362 }
3363 pub fn request_low_power_clk(clocks: &mut ClockTree) {
3364 trace!("Requesting LOW_POWER_CLK");
3365 if increment_reference_count(&mut clocks.low_power_clk_refcount) {
3366 trace!("Enabling LOW_POWER_CLK");
3367 match unwrap!(clocks.low_power_clk) {
3368 LowPowerClkConfig::Xtal => request_xtal_clk(clocks),
3369 LowPowerClkConfig::RcFast => request_rc_fast_clk(clocks),
3370 #[cfg(use_xtal32k)]
3371 LowPowerClkConfig::Xtal32k => request_xtal32k_clk(clocks),
3372 LowPowerClkConfig::RtcSlow => request_rtc_slow_clk(clocks),
3373 }
3374 enable_low_power_clk_impl(clocks, true);
3375 }
3376 }
3377 pub fn release_low_power_clk(clocks: &mut ClockTree) {
3378 trace!("Releasing LOW_POWER_CLK");
3379 if decrement_reference_count(&mut clocks.low_power_clk_refcount) {
3380 trace!("Disabling LOW_POWER_CLK");
3381 enable_low_power_clk_impl(clocks, false);
3382 match unwrap!(clocks.low_power_clk) {
3383 LowPowerClkConfig::Xtal => release_xtal_clk(clocks),
3384 LowPowerClkConfig::RcFast => release_rc_fast_clk(clocks),
3385 #[cfg(use_xtal32k)]
3386 LowPowerClkConfig::Xtal32k => release_xtal32k_clk(clocks),
3387 LowPowerClkConfig::RtcSlow => release_rtc_slow_clk(clocks),
3388 }
3389 }
3390 }
3391 pub fn low_power_clk_config_frequency(config: LowPowerClkConfig) -> u32 {
3392 match config {
3393 LowPowerClkConfig::Xtal => xtal_clk_frequency(),
3394 LowPowerClkConfig::RcFast => rc_fast_clk_frequency(),
3395 #[cfg(use_xtal32k)]
3396 LowPowerClkConfig::Xtal32k => xtal32k_clk_frequency(),
3397 LowPowerClkConfig::RtcSlow => rtc_slow_clk_frequency(),
3398 }
3399 }
3400 pub fn low_power_clk_frequency() -> u32 {
3401 LOW_POWER_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
3402 }
3403 pub fn low_power_clk_source_frequency(source: LowPowerClkConfig) -> u32 {
3404 low_power_clk_config_frequency(source)
3405 }
3406 pub fn request_uart_mem_clk(clocks: &mut ClockTree) {
3407 trace!("Requesting UART_MEM_CLK");
3408 if increment_reference_count(&mut clocks.uart_mem_clk_refcount) {
3409 trace!("Enabling UART_MEM_CLK");
3410 request_xtal_clk(clocks);
3411 enable_uart_mem_clk_impl(clocks, true);
3412 }
3413 }
3414 pub fn release_uart_mem_clk(clocks: &mut ClockTree) {
3415 trace!("Releasing UART_MEM_CLK");
3416 if decrement_reference_count(&mut clocks.uart_mem_clk_refcount) {
3417 trace!("Disabling UART_MEM_CLK");
3418 enable_uart_mem_clk_impl(clocks, false);
3419 release_xtal_clk(clocks);
3420 }
3421 }
3422 pub fn uart_mem_clk_frequency() -> u32 {
3423 xtal_clk_frequency()
3424 }
3425 pub fn uart_mem_clk_source_frequency(source: UartMemClkConfig) -> u32 {
3426 match source {
3427 UartMemClkConfig::Xtal => xtal_clk_frequency(),
3428 }
3429 }
3430 pub fn configure_timg_calibration_clock(
3431 clocks: &mut ClockTree,
3432 new_selector: TimgCalibrationClockConfig,
3433 ) {
3434 let old_selector = clocks.timg_calibration_clock.replace(new_selector);
3435 refresh_timg_calibration_clock_downstream(clocks);
3436 let active = clocks.timg_calibration_clock_refcount > 0;
3437 if active {
3438 match new_selector {
3439 TimgCalibrationClockConfig::RcSlowClk => request_rc_slow_clk(clocks),
3440 TimgCalibrationClockConfig::RcFastDivClk => request_rc_fast_div_clk(clocks),
3441 #[cfg(use_xtal32k)]
3442 TimgCalibrationClockConfig::Xtal32kClk => request_xtal32k_clk(clocks),
3443 }
3444 }
3445 configure_timg_calibration_clock_impl(clocks, old_selector, new_selector);
3446 if active && let Some(old_selector) = old_selector {
3447 match old_selector {
3448 TimgCalibrationClockConfig::RcSlowClk => release_rc_slow_clk(clocks),
3449 TimgCalibrationClockConfig::RcFastDivClk => release_rc_fast_div_clk(clocks),
3450 #[cfg(use_xtal32k)]
3451 TimgCalibrationClockConfig::Xtal32kClk => release_xtal32k_clk(clocks),
3452 }
3453 }
3454 }
3455 pub fn timg_calibration_clock_config(
3456 clocks: &mut ClockTree,
3457 ) -> Option<TimgCalibrationClockConfig> {
3458 clocks.timg_calibration_clock
3459 }
3460 pub fn request_timg_calibration_clock(clocks: &mut ClockTree) {
3461 trace!("Requesting TIMG_CALIBRATION_CLOCK");
3462 if increment_reference_count(&mut clocks.timg_calibration_clock_refcount) {
3463 trace!("Enabling TIMG_CALIBRATION_CLOCK");
3464 crate::rtc_cntl::WakeLock::acquire();
3465 match unwrap!(clocks.timg_calibration_clock) {
3466 TimgCalibrationClockConfig::RcSlowClk => request_rc_slow_clk(clocks),
3467 TimgCalibrationClockConfig::RcFastDivClk => request_rc_fast_div_clk(clocks),
3468 #[cfg(use_xtal32k)]
3469 TimgCalibrationClockConfig::Xtal32kClk => request_xtal32k_clk(clocks),
3470 }
3471 enable_timg_calibration_clock_impl(clocks, true);
3472 }
3473 }
3474 pub fn release_timg_calibration_clock(clocks: &mut ClockTree) {
3475 trace!("Releasing TIMG_CALIBRATION_CLOCK");
3476 if decrement_reference_count(&mut clocks.timg_calibration_clock_refcount) {
3477 trace!("Disabling TIMG_CALIBRATION_CLOCK");
3478 crate::rtc_cntl::WakeLock::release();
3479 enable_timg_calibration_clock_impl(clocks, false);
3480 match unwrap!(clocks.timg_calibration_clock) {
3481 TimgCalibrationClockConfig::RcSlowClk => release_rc_slow_clk(clocks),
3482 TimgCalibrationClockConfig::RcFastDivClk => release_rc_fast_div_clk(clocks),
3483 #[cfg(use_xtal32k)]
3484 TimgCalibrationClockConfig::Xtal32kClk => release_xtal32k_clk(clocks),
3485 }
3486 }
3487 }
3488 pub fn timg_calibration_clock_config_frequency(config: TimgCalibrationClockConfig) -> u32 {
3489 match config {
3490 TimgCalibrationClockConfig::RcSlowClk => rc_slow_clk_frequency(),
3491 TimgCalibrationClockConfig::RcFastDivClk => rc_fast_div_clk_frequency(),
3492 #[cfg(use_xtal32k)]
3493 TimgCalibrationClockConfig::Xtal32kClk => xtal32k_clk_frequency(),
3494 }
3495 }
3496 pub fn timg_calibration_clock_frequency() -> u32 {
3497 TIMG_CALIBRATION_CLOCK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
3498 }
3499 pub fn timg_calibration_clock_source_frequency(source: TimgCalibrationClockConfig) -> u32 {
3500 timg_calibration_clock_config_frequency(source)
3501 }
3502 impl AdcInstance {
3503 pub fn request_function_clock(self, clocks: &mut ClockTree) {
3504 trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3505 if increment_reference_count(&mut clocks.adc_function_clock_refcount[self as usize])
3506 {
3507 trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3508 request_apb_clk(clocks);
3509 self.enable_function_clock_impl(clocks, true);
3510 }
3511 }
3512 pub fn release_function_clock(self, clocks: &mut ClockTree) {
3513 trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3514 if decrement_reference_count(&mut clocks.adc_function_clock_refcount[self as usize])
3515 {
3516 trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3517 self.enable_function_clock_impl(clocks, false);
3518 release_apb_clk(clocks);
3519 }
3520 }
3521 pub fn function_clock_frequency(self) -> u32 {
3522 apb_clk_frequency()
3523 }
3524 pub fn function_clock_source_frequency() -> u32 {
3525 apb_clk_frequency()
3526 }
3527 }
3528 impl SdmInstance {
3529 pub fn request_function_clock(self, clocks: &mut ClockTree) {
3530 trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3531 if increment_reference_count(&mut clocks.sdm_function_clock_refcount[self as usize])
3532 {
3533 trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3534 request_apb_clk(clocks);
3535 self.enable_function_clock_impl(clocks, true);
3536 }
3537 }
3538 pub fn release_function_clock(self, clocks: &mut ClockTree) {
3539 trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3540 if decrement_reference_count(&mut clocks.sdm_function_clock_refcount[self as usize])
3541 {
3542 trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3543 self.enable_function_clock_impl(clocks, false);
3544 release_apb_clk(clocks);
3545 }
3546 }
3547 pub fn function_clock_frequency(self) -> u32 {
3548 apb_clk_frequency()
3549 }
3550 pub fn function_clock_source_frequency() -> u32 {
3551 apb_clk_frequency()
3552 }
3553 }
3554 impl I2cInstance {
3555 pub fn configure_function_clock(
3556 self,
3557 clocks: &mut ClockTree,
3558 config: I2cFunctionClockConfig,
3559 ) {
3560 let old_config = clocks.i2c_function_clock[self as usize].replace(config);
3561 refresh_i2c_function_clock_downstream(clocks, self);
3562 let active = clocks.i2c_function_clock_refcount[self as usize] > 0;
3563 if active {
3564 match config.sclk {
3565 I2cFunctionClockSclk::Xtal => request_xtal_clk(clocks),
3566 I2cFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
3567 }
3568 }
3569 self.configure_function_clock_impl(clocks, old_config, config);
3570 if active && let Some(old_config) = old_config {
3571 match old_config.sclk {
3572 I2cFunctionClockSclk::Xtal => release_xtal_clk(clocks),
3573 I2cFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
3574 }
3575 }
3576 }
3577 pub fn function_clock_config(
3578 self,
3579 clocks: &mut ClockTree,
3580 ) -> Option<I2cFunctionClockConfig> {
3581 clocks.i2c_function_clock[self as usize]
3582 }
3583 pub fn request_function_clock(self, clocks: &mut ClockTree) {
3584 trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3585 if increment_reference_count(&mut clocks.i2c_function_clock_refcount[self as usize])
3586 {
3587 trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3588 crate::rtc_cntl::WakeLock::acquire();
3589 match unwrap!(clocks.i2c_function_clock[self as usize]).sclk {
3590 I2cFunctionClockSclk::Xtal => request_xtal_clk(clocks),
3591 I2cFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
3592 }
3593 self.enable_function_clock_impl(clocks, true);
3594 }
3595 }
3596 pub fn release_function_clock(self, clocks: &mut ClockTree) {
3597 trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3598 if decrement_reference_count(&mut clocks.i2c_function_clock_refcount[self as usize])
3599 {
3600 trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3601 crate::rtc_cntl::WakeLock::release();
3602 self.enable_function_clock_impl(clocks, false);
3603 match unwrap!(clocks.i2c_function_clock[self as usize]).sclk {
3604 I2cFunctionClockSclk::Xtal => release_xtal_clk(clocks),
3605 I2cFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
3606 }
3607 }
3608 }
3609 pub fn function_clock_config_frequency(config: I2cFunctionClockConfig) -> u32 {
3610 (match config.sclk {
3611 I2cFunctionClockSclk::Xtal => xtal_clk_frequency(),
3612 I2cFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
3613 } / (config.div_num() + 1))
3614 }
3615 pub fn function_clock_frequency(self) -> u32 {
3616 I2C_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
3617 .load(::core::sync::atomic::Ordering::Acquire)
3618 }
3619 pub fn function_clock_source_frequency(sclk: I2cFunctionClockSclk) -> u32 {
3620 match sclk {
3621 I2cFunctionClockSclk::Xtal => xtal_clk_frequency(),
3622 I2cFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
3623 }
3624 }
3625 }
3626 impl I2sInstance {
3627 pub fn configure_tx_clk(self, clocks: &mut ClockTree, config: I2sClkConfig) {
3628 let old_config = clocks.i2s_tx_clk[self as usize].replace(config);
3629 refresh_i2s_tx_clk_downstream(clocks, self);
3630 let active = clocks.i2s_tx_clk_refcount[self as usize] > 0;
3631 if active {
3632 match config.sclk {
3633 I2sClkSclk::Xtal => request_xtal_clk(clocks),
3634 I2sClkSclk::Pll160m => request_pll_160m(clocks),
3635 }
3636 }
3637 self.configure_tx_clk_impl(clocks, old_config, config);
3638 if active && let Some(old_config) = old_config {
3639 match old_config.sclk {
3640 I2sClkSclk::Xtal => release_xtal_clk(clocks),
3641 I2sClkSclk::Pll160m => release_pll_160m(clocks),
3642 }
3643 }
3644 }
3645 pub fn tx_clk_config(self, clocks: &mut ClockTree) -> Option<I2sClkConfig> {
3646 clocks.i2s_tx_clk[self as usize]
3647 }
3648 pub fn request_tx_clk(self, clocks: &mut ClockTree) {
3649 trace!("Requesting {:?}::TX_CLK", self);
3650 if increment_reference_count(&mut clocks.i2s_tx_clk_refcount[self as usize]) {
3651 trace!("Enabling {:?}::TX_CLK", self);
3652 crate::rtc_cntl::WakeLock::acquire();
3653 match unwrap!(clocks.i2s_tx_clk[self as usize]).sclk {
3654 I2sClkSclk::Xtal => request_xtal_clk(clocks),
3655 I2sClkSclk::Pll160m => request_pll_160m(clocks),
3656 }
3657 self.enable_tx_clk_impl(clocks, true);
3658 }
3659 }
3660 pub fn release_tx_clk(self, clocks: &mut ClockTree) {
3661 trace!("Releasing {:?}::TX_CLK", self);
3662 if decrement_reference_count(&mut clocks.i2s_tx_clk_refcount[self as usize]) {
3663 trace!("Disabling {:?}::TX_CLK", self);
3664 crate::rtc_cntl::WakeLock::release();
3665 self.enable_tx_clk_impl(clocks, false);
3666 match unwrap!(clocks.i2s_tx_clk[self as usize]).sclk {
3667 I2sClkSclk::Xtal => release_xtal_clk(clocks),
3668 I2sClkSclk::Pll160m => release_pll_160m(clocks),
3669 }
3670 }
3671 }
3672 pub fn tx_clk_config_frequency(config: I2sClkConfig) -> u32 {
3673 (((match config.sclk {
3674 I2sClkSclk::Xtal => xtal_clk_frequency(),
3675 I2sClkSclk::Pll160m => pll_160m_frequency(),
3676 } as u64)
3677 * (config.div_a() as u64))
3678 / (((config.div_num() * config.div_a()) + config.div_b()) as u64))
3679 as u32
3680 }
3681 pub fn tx_clk_frequency(self) -> u32 {
3682 I2S_TX_CLK_FREQ_CACHE[self as usize].load(::core::sync::atomic::Ordering::Acquire)
3683 }
3684 pub fn tx_clk_source_frequency(sclk: I2sClkSclk) -> u32 {
3685 match sclk {
3686 I2sClkSclk::Xtal => xtal_clk_frequency(),
3687 I2sClkSclk::Pll160m => pll_160m_frequency(),
3688 }
3689 }
3690 pub fn configure_rx_clk(self, clocks: &mut ClockTree, config: I2sClkConfig) {
3691 let old_config = clocks.i2s_rx_clk[self as usize].replace(config);
3692 refresh_i2s_rx_clk_downstream(clocks, self);
3693 let active = clocks.i2s_rx_clk_refcount[self as usize] > 0;
3694 if active {
3695 match config.sclk {
3696 I2sClkSclk::Xtal => request_xtal_clk(clocks),
3697 I2sClkSclk::Pll160m => request_pll_160m(clocks),
3698 }
3699 }
3700 self.configure_rx_clk_impl(clocks, old_config, config);
3701 if active && let Some(old_config) = old_config {
3702 match old_config.sclk {
3703 I2sClkSclk::Xtal => release_xtal_clk(clocks),
3704 I2sClkSclk::Pll160m => release_pll_160m(clocks),
3705 }
3706 }
3707 }
3708 pub fn rx_clk_config(self, clocks: &mut ClockTree) -> Option<I2sClkConfig> {
3709 clocks.i2s_rx_clk[self as usize]
3710 }
3711 pub fn request_rx_clk(self, clocks: &mut ClockTree) {
3712 trace!("Requesting {:?}::RX_CLK", self);
3713 if increment_reference_count(&mut clocks.i2s_rx_clk_refcount[self as usize]) {
3714 trace!("Enabling {:?}::RX_CLK", self);
3715 crate::rtc_cntl::WakeLock::acquire();
3716 match unwrap!(clocks.i2s_rx_clk[self as usize]).sclk {
3717 I2sClkSclk::Xtal => request_xtal_clk(clocks),
3718 I2sClkSclk::Pll160m => request_pll_160m(clocks),
3719 }
3720 self.enable_rx_clk_impl(clocks, true);
3721 }
3722 }
3723 pub fn release_rx_clk(self, clocks: &mut ClockTree) {
3724 trace!("Releasing {:?}::RX_CLK", self);
3725 if decrement_reference_count(&mut clocks.i2s_rx_clk_refcount[self as usize]) {
3726 trace!("Disabling {:?}::RX_CLK", self);
3727 crate::rtc_cntl::WakeLock::release();
3728 self.enable_rx_clk_impl(clocks, false);
3729 match unwrap!(clocks.i2s_rx_clk[self as usize]).sclk {
3730 I2sClkSclk::Xtal => release_xtal_clk(clocks),
3731 I2sClkSclk::Pll160m => release_pll_160m(clocks),
3732 }
3733 }
3734 }
3735 pub fn rx_clk_config_frequency(config: I2sClkConfig) -> u32 {
3736 (((match config.sclk {
3737 I2sClkSclk::Xtal => xtal_clk_frequency(),
3738 I2sClkSclk::Pll160m => pll_160m_frequency(),
3739 } as u64)
3740 * (config.div_a() as u64))
3741 / (((config.div_num() * config.div_a()) + config.div_b()) as u64))
3742 as u32
3743 }
3744 pub fn rx_clk_frequency(self) -> u32 {
3745 I2S_RX_CLK_FREQ_CACHE[self as usize].load(::core::sync::atomic::Ordering::Acquire)
3746 }
3747 pub fn rx_clk_source_frequency(sclk: I2sClkSclk) -> u32 {
3748 match sclk {
3749 I2sClkSclk::Xtal => xtal_clk_frequency(),
3750 I2sClkSclk::Pll160m => pll_160m_frequency(),
3751 }
3752 }
3753 pub fn configure_mclk_out(
3754 self,
3755 clocks: &mut ClockTree,
3756 new_selector: I2sMclkOutConfig,
3757 ) {
3758 let old_selector = clocks.i2s_mclk_out[self as usize].replace(new_selector);
3759 refresh_i2s_mclk_out_downstream(clocks, self);
3760 let active = clocks.i2s_mclk_out_refcount[self as usize] > 0;
3761 if active {
3762 match new_selector {
3763 I2sMclkOutConfig::Tx => self.request_tx_clk(clocks),
3764 I2sMclkOutConfig::Rx => self.request_rx_clk(clocks),
3765 }
3766 }
3767 self.configure_mclk_out_impl(clocks, old_selector, new_selector);
3768 if active && let Some(old_selector) = old_selector {
3769 match old_selector {
3770 I2sMclkOutConfig::Tx => self.release_tx_clk(clocks),
3771 I2sMclkOutConfig::Rx => self.release_rx_clk(clocks),
3772 }
3773 }
3774 }
3775 pub fn mclk_out_config(self, clocks: &mut ClockTree) -> Option<I2sMclkOutConfig> {
3776 clocks.i2s_mclk_out[self as usize]
3777 }
3778 pub fn request_mclk_out(self, clocks: &mut ClockTree) {
3779 trace!("Requesting {:?}::MCLK_OUT", self);
3780 if increment_reference_count(&mut clocks.i2s_mclk_out_refcount[self as usize]) {
3781 trace!("Enabling {:?}::MCLK_OUT", self);
3782 match unwrap!(clocks.i2s_mclk_out[self as usize]) {
3783 I2sMclkOutConfig::Tx => self.request_tx_clk(clocks),
3784 I2sMclkOutConfig::Rx => self.request_rx_clk(clocks),
3785 }
3786 self.enable_mclk_out_impl(clocks, true);
3787 }
3788 }
3789 pub fn release_mclk_out(self, clocks: &mut ClockTree) {
3790 trace!("Releasing {:?}::MCLK_OUT", self);
3791 if decrement_reference_count(&mut clocks.i2s_mclk_out_refcount[self as usize]) {
3792 trace!("Disabling {:?}::MCLK_OUT", self);
3793 self.enable_mclk_out_impl(clocks, false);
3794 match unwrap!(clocks.i2s_mclk_out[self as usize]) {
3795 I2sMclkOutConfig::Tx => self.release_tx_clk(clocks),
3796 I2sMclkOutConfig::Rx => self.release_rx_clk(clocks),
3797 }
3798 }
3799 }
3800 pub fn mclk_out_config_frequency(self, config: I2sMclkOutConfig) -> u32 {
3801 match config {
3802 I2sMclkOutConfig::Tx => self.tx_clk_frequency(),
3803 I2sMclkOutConfig::Rx => self.rx_clk_frequency(),
3804 }
3805 }
3806 pub fn mclk_out_frequency(self) -> u32 {
3807 I2S_MCLK_OUT_FREQ_CACHE[self as usize].load(::core::sync::atomic::Ordering::Acquire)
3808 }
3809 }
3810 impl RmtInstance {
3811 pub fn configure_sclk(self, clocks: &mut ClockTree, new_selector: RmtSclkConfig) {
3812 let old_selector = clocks.rmt_sclk[self as usize].replace(new_selector);
3813 refresh_rmt_sclk_downstream(clocks, self);
3814 let active = clocks.rmt_sclk_refcount[self as usize] > 0;
3815 if active {
3816 match new_selector {
3817 RmtSclkConfig::ApbClk => request_apb_clk(clocks),
3818 RmtSclkConfig::RcFastClk => request_rc_fast_clk(clocks),
3819 RmtSclkConfig::XtalClk => request_xtal_clk(clocks),
3820 }
3821 }
3822 self.configure_sclk_impl(clocks, old_selector, new_selector);
3823 if active && let Some(old_selector) = old_selector {
3824 match old_selector {
3825 RmtSclkConfig::ApbClk => release_apb_clk(clocks),
3826 RmtSclkConfig::RcFastClk => release_rc_fast_clk(clocks),
3827 RmtSclkConfig::XtalClk => release_xtal_clk(clocks),
3828 }
3829 }
3830 }
3831 pub fn sclk_config(self, clocks: &mut ClockTree) -> Option<RmtSclkConfig> {
3832 clocks.rmt_sclk[self as usize]
3833 }
3834 pub fn request_sclk(self, clocks: &mut ClockTree) {
3835 trace!("Requesting {:?}::SCLK", self);
3836 if increment_reference_count(&mut clocks.rmt_sclk_refcount[self as usize]) {
3837 trace!("Enabling {:?}::SCLK", self);
3838 crate::rtc_cntl::WakeLock::acquire();
3839 match unwrap!(clocks.rmt_sclk[self as usize]) {
3840 RmtSclkConfig::ApbClk => request_apb_clk(clocks),
3841 RmtSclkConfig::RcFastClk => request_rc_fast_clk(clocks),
3842 RmtSclkConfig::XtalClk => request_xtal_clk(clocks),
3843 }
3844 self.enable_sclk_impl(clocks, true);
3845 }
3846 }
3847 pub fn release_sclk(self, clocks: &mut ClockTree) {
3848 trace!("Releasing {:?}::SCLK", self);
3849 if decrement_reference_count(&mut clocks.rmt_sclk_refcount[self as usize]) {
3850 trace!("Disabling {:?}::SCLK", self);
3851 crate::rtc_cntl::WakeLock::release();
3852 self.enable_sclk_impl(clocks, false);
3853 match unwrap!(clocks.rmt_sclk[self as usize]) {
3854 RmtSclkConfig::ApbClk => release_apb_clk(clocks),
3855 RmtSclkConfig::RcFastClk => release_rc_fast_clk(clocks),
3856 RmtSclkConfig::XtalClk => release_xtal_clk(clocks),
3857 }
3858 }
3859 }
3860 pub fn sclk_config_frequency(config: RmtSclkConfig) -> u32 {
3861 match config {
3862 RmtSclkConfig::ApbClk => apb_clk_frequency(),
3863 RmtSclkConfig::RcFastClk => rc_fast_clk_frequency(),
3864 RmtSclkConfig::XtalClk => xtal_clk_frequency(),
3865 }
3866 }
3867 pub fn sclk_frequency(self) -> u32 {
3868 RMT_SCLK_FREQ_CACHE[self as usize].load(::core::sync::atomic::Ordering::Acquire)
3869 }
3870 pub fn sclk_source_frequency(source: RmtSclkConfig) -> u32 {
3871 Self::sclk_config_frequency(source)
3872 }
3873 }
3874 impl SpiInstance {
3875 pub fn configure_function_clock(
3876 self,
3877 clocks: &mut ClockTree,
3878 new_selector: SpiFunctionClockConfig,
3879 ) {
3880 let old_selector = clocks.spi_function_clock[self as usize].replace(new_selector);
3881 refresh_spi_function_clock_downstream(clocks, self);
3882 let active = clocks.spi_function_clock_refcount[self as usize] > 0;
3883 if active {
3884 match new_selector {
3885 SpiFunctionClockConfig::Xtal => request_xtal_clk(clocks),
3886 SpiFunctionClockConfig::Pll80m => request_pll_80m(clocks),
3887 }
3888 }
3889 self.configure_function_clock_impl(clocks, old_selector, new_selector);
3890 if active && let Some(old_selector) = old_selector {
3891 match old_selector {
3892 SpiFunctionClockConfig::Xtal => release_xtal_clk(clocks),
3893 SpiFunctionClockConfig::Pll80m => release_pll_80m(clocks),
3894 }
3895 }
3896 }
3897 pub fn function_clock_config(
3898 self,
3899 clocks: &mut ClockTree,
3900 ) -> Option<SpiFunctionClockConfig> {
3901 clocks.spi_function_clock[self as usize]
3902 }
3903 pub fn request_function_clock(self, clocks: &mut ClockTree) {
3904 trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3905 if increment_reference_count(&mut clocks.spi_function_clock_refcount[self as usize])
3906 {
3907 trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3908 crate::rtc_cntl::WakeLock::acquire();
3909 match unwrap!(clocks.spi_function_clock[self as usize]) {
3910 SpiFunctionClockConfig::Xtal => request_xtal_clk(clocks),
3911 SpiFunctionClockConfig::Pll80m => request_pll_80m(clocks),
3912 }
3913 self.enable_function_clock_impl(clocks, true);
3914 }
3915 }
3916 pub fn release_function_clock(self, clocks: &mut ClockTree) {
3917 trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3918 if decrement_reference_count(&mut clocks.spi_function_clock_refcount[self as usize])
3919 {
3920 trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3921 crate::rtc_cntl::WakeLock::release();
3922 self.enable_function_clock_impl(clocks, false);
3923 match unwrap!(clocks.spi_function_clock[self as usize]) {
3924 SpiFunctionClockConfig::Xtal => release_xtal_clk(clocks),
3925 SpiFunctionClockConfig::Pll80m => release_pll_80m(clocks),
3926 }
3927 }
3928 }
3929 pub fn function_clock_config_frequency(config: SpiFunctionClockConfig) -> u32 {
3930 match config {
3931 SpiFunctionClockConfig::Xtal => xtal_clk_frequency(),
3932 SpiFunctionClockConfig::Pll80m => pll_80m_frequency(),
3933 }
3934 }
3935 pub fn function_clock_frequency(self) -> u32 {
3936 SPI_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
3937 .load(::core::sync::atomic::Ordering::Acquire)
3938 }
3939 pub fn function_clock_source_frequency(source: SpiFunctionClockConfig) -> u32 {
3940 Self::function_clock_config_frequency(source)
3941 }
3942 }
3943 impl TimgInstance {
3944 pub fn configure_function_clock(
3945 self,
3946 clocks: &mut ClockTree,
3947 new_selector: TimgFunctionClockConfig,
3948 ) {
3949 let old_selector = clocks.timg_function_clock[self as usize].replace(new_selector);
3950 refresh_timg_function_clock_downstream(clocks, self);
3951 let active = clocks.timg_function_clock_refcount[self as usize] > 0;
3952 if active {
3953 match new_selector {
3954 TimgFunctionClockConfig::XtalClk => request_xtal_clk(clocks),
3955 TimgFunctionClockConfig::ApbClk => request_apb_clk(clocks),
3956 }
3957 }
3958 self.configure_function_clock_impl(clocks, old_selector, new_selector);
3959 if active && let Some(old_selector) = old_selector {
3960 match old_selector {
3961 TimgFunctionClockConfig::XtalClk => release_xtal_clk(clocks),
3962 TimgFunctionClockConfig::ApbClk => release_apb_clk(clocks),
3963 }
3964 }
3965 }
3966 pub fn function_clock_config(
3967 self,
3968 clocks: &mut ClockTree,
3969 ) -> Option<TimgFunctionClockConfig> {
3970 clocks.timg_function_clock[self as usize]
3971 }
3972 pub fn request_function_clock(self, clocks: &mut ClockTree) {
3973 trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3974 if increment_reference_count(
3975 &mut clocks.timg_function_clock_refcount[self as usize],
3976 ) {
3977 trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3978 match unwrap!(clocks.timg_function_clock[self as usize]) {
3979 TimgFunctionClockConfig::XtalClk => request_xtal_clk(clocks),
3980 TimgFunctionClockConfig::ApbClk => request_apb_clk(clocks),
3981 }
3982 self.enable_function_clock_impl(clocks, true);
3983 }
3984 }
3985 pub fn release_function_clock(self, clocks: &mut ClockTree) {
3986 trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3987 if decrement_reference_count(
3988 &mut clocks.timg_function_clock_refcount[self as usize],
3989 ) {
3990 trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3991 self.enable_function_clock_impl(clocks, false);
3992 match unwrap!(clocks.timg_function_clock[self as usize]) {
3993 TimgFunctionClockConfig::XtalClk => release_xtal_clk(clocks),
3994 TimgFunctionClockConfig::ApbClk => release_apb_clk(clocks),
3995 }
3996 }
3997 }
3998 pub fn function_clock_config_frequency(config: TimgFunctionClockConfig) -> u32 {
3999 match config {
4000 TimgFunctionClockConfig::XtalClk => xtal_clk_frequency(),
4001 TimgFunctionClockConfig::ApbClk => apb_clk_frequency(),
4002 }
4003 }
4004 pub fn function_clock_frequency(self) -> u32 {
4005 TIMG_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
4006 .load(::core::sync::atomic::Ordering::Acquire)
4007 }
4008 pub fn function_clock_source_frequency(source: TimgFunctionClockConfig) -> u32 {
4009 Self::function_clock_config_frequency(source)
4010 }
4011 pub fn configure_wdt_clock(
4012 self,
4013 clocks: &mut ClockTree,
4014 new_selector: TimgWdtClockConfig,
4015 ) {
4016 let old_selector = clocks.timg_wdt_clock[self as usize].replace(new_selector);
4017 refresh_timg_wdt_clock_downstream(clocks, self);
4018 let active = clocks.timg_wdt_clock_refcount[self as usize] > 0;
4019 if active {
4020 match new_selector {
4021 TimgWdtClockConfig::ApbClk => request_apb_clk(clocks),
4022 TimgWdtClockConfig::XtalClk => request_xtal_clk(clocks),
4023 }
4024 }
4025 self.configure_wdt_clock_impl(clocks, old_selector, new_selector);
4026 if active && let Some(old_selector) = old_selector {
4027 match old_selector {
4028 TimgWdtClockConfig::ApbClk => release_apb_clk(clocks),
4029 TimgWdtClockConfig::XtalClk => release_xtal_clk(clocks),
4030 }
4031 }
4032 }
4033 pub fn wdt_clock_config(self, clocks: &mut ClockTree) -> Option<TimgWdtClockConfig> {
4034 clocks.timg_wdt_clock[self as usize]
4035 }
4036 pub fn request_wdt_clock(self, clocks: &mut ClockTree) {
4037 trace!("Requesting {:?}::WDT_CLOCK", self);
4038 if increment_reference_count(&mut clocks.timg_wdt_clock_refcount[self as usize]) {
4039 trace!("Enabling {:?}::WDT_CLOCK", self);
4040 match unwrap!(clocks.timg_wdt_clock[self as usize]) {
4041 TimgWdtClockConfig::ApbClk => request_apb_clk(clocks),
4042 TimgWdtClockConfig::XtalClk => request_xtal_clk(clocks),
4043 }
4044 self.enable_wdt_clock_impl(clocks, true);
4045 }
4046 }
4047 pub fn release_wdt_clock(self, clocks: &mut ClockTree) {
4048 trace!("Releasing {:?}::WDT_CLOCK", self);
4049 if decrement_reference_count(&mut clocks.timg_wdt_clock_refcount[self as usize]) {
4050 trace!("Disabling {:?}::WDT_CLOCK", self);
4051 self.enable_wdt_clock_impl(clocks, false);
4052 match unwrap!(clocks.timg_wdt_clock[self as usize]) {
4053 TimgWdtClockConfig::ApbClk => release_apb_clk(clocks),
4054 TimgWdtClockConfig::XtalClk => release_xtal_clk(clocks),
4055 }
4056 }
4057 }
4058 pub fn wdt_clock_config_frequency(config: TimgWdtClockConfig) -> u32 {
4059 match config {
4060 TimgWdtClockConfig::ApbClk => apb_clk_frequency(),
4061 TimgWdtClockConfig::XtalClk => xtal_clk_frequency(),
4062 }
4063 }
4064 pub fn wdt_clock_frequency(self) -> u32 {
4065 TIMG_WDT_CLOCK_FREQ_CACHE[self as usize]
4066 .load(::core::sync::atomic::Ordering::Acquire)
4067 }
4068 pub fn wdt_clock_source_frequency(source: TimgWdtClockConfig) -> u32 {
4069 Self::wdt_clock_config_frequency(source)
4070 }
4071 }
4072 impl UartInstance {
4073 pub fn configure_function_clock(
4074 self,
4075 clocks: &mut ClockTree,
4076 config: UartFunctionClockConfig,
4077 ) {
4078 let old_config = clocks.uart_function_clock[self as usize].replace(config);
4079 refresh_uart_function_clock_downstream(clocks, self);
4080 let active = clocks.uart_function_clock_refcount[self as usize] > 0;
4081 if active {
4082 match config.sclk {
4083 UartFunctionClockSclk::Apb => request_apb_clk(clocks),
4084 UartFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
4085 UartFunctionClockSclk::Xtal => request_xtal_clk(clocks),
4086 }
4087 }
4088 self.configure_function_clock_impl(clocks, old_config, config);
4089 if active && let Some(old_config) = old_config {
4090 match old_config.sclk {
4091 UartFunctionClockSclk::Apb => release_apb_clk(clocks),
4092 UartFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
4093 UartFunctionClockSclk::Xtal => release_xtal_clk(clocks),
4094 }
4095 }
4096 }
4097 pub fn function_clock_config(
4098 self,
4099 clocks: &mut ClockTree,
4100 ) -> Option<UartFunctionClockConfig> {
4101 clocks.uart_function_clock[self as usize]
4102 }
4103 pub fn request_function_clock(self, clocks: &mut ClockTree) {
4104 trace!("Requesting {:?}::FUNCTION_CLOCK", self);
4105 if increment_reference_count(
4106 &mut clocks.uart_function_clock_refcount[self as usize],
4107 ) {
4108 trace!("Enabling {:?}::FUNCTION_CLOCK", self);
4109 match unwrap!(clocks.uart_function_clock[self as usize]).sclk {
4110 UartFunctionClockSclk::Apb => request_apb_clk(clocks),
4111 UartFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
4112 UartFunctionClockSclk::Xtal => request_xtal_clk(clocks),
4113 }
4114 self.enable_function_clock_impl(clocks, true);
4115 }
4116 }
4117 pub fn release_function_clock(self, clocks: &mut ClockTree) {
4118 trace!("Releasing {:?}::FUNCTION_CLOCK", self);
4119 if decrement_reference_count(
4120 &mut clocks.uart_function_clock_refcount[self as usize],
4121 ) {
4122 trace!("Disabling {:?}::FUNCTION_CLOCK", self);
4123 self.enable_function_clock_impl(clocks, false);
4124 match unwrap!(clocks.uart_function_clock[self as usize]).sclk {
4125 UartFunctionClockSclk::Apb => release_apb_clk(clocks),
4126 UartFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
4127 UartFunctionClockSclk::Xtal => release_xtal_clk(clocks),
4128 }
4129 }
4130 }
4131 pub fn function_clock_config_frequency(config: UartFunctionClockConfig) -> u32 {
4132 (match config.sclk {
4133 UartFunctionClockSclk::Apb => apb_clk_frequency(),
4134 UartFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
4135 UartFunctionClockSclk::Xtal => xtal_clk_frequency(),
4136 } / (config.div_num() + 1))
4137 }
4138 pub fn function_clock_frequency(self) -> u32 {
4139 UART_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
4140 .load(::core::sync::atomic::Ordering::Acquire)
4141 }
4142 pub fn function_clock_source_frequency(sclk: UartFunctionClockSclk) -> u32 {
4143 match sclk {
4144 UartFunctionClockSclk::Apb => apb_clk_frequency(),
4145 UartFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
4146 UartFunctionClockSclk::Xtal => xtal_clk_frequency(),
4147 }
4148 }
4149 pub fn request_mem_clock(self, clocks: &mut ClockTree) {
4150 trace!("Requesting {:?}::MEM_CLOCK", self);
4151 if increment_reference_count(&mut clocks.uart_mem_clock_refcount[self as usize]) {
4152 trace!("Enabling {:?}::MEM_CLOCK", self);
4153 request_uart_mem_clk(clocks);
4154 self.enable_mem_clock_impl(clocks, true);
4155 }
4156 }
4157 pub fn release_mem_clock(self, clocks: &mut ClockTree) {
4158 trace!("Releasing {:?}::MEM_CLOCK", self);
4159 if decrement_reference_count(&mut clocks.uart_mem_clock_refcount[self as usize]) {
4160 trace!("Disabling {:?}::MEM_CLOCK", self);
4161 self.enable_mem_clock_impl(clocks, false);
4162 release_uart_mem_clk(clocks);
4163 }
4164 }
4165 pub fn mem_clock_frequency(self) -> u32 {
4166 uart_mem_clk_frequency()
4167 }
4168 pub fn mem_clock_source_frequency() -> u32 {
4169 uart_mem_clk_frequency()
4170 }
4171 pub fn configure_baud_rate_generator(
4172 self,
4173 clocks: &mut ClockTree,
4174 config: UartBaudRateGeneratorConfig,
4175 ) {
4176 let old_config = clocks.uart_baud_rate_generator[self as usize].replace(config);
4177 refresh_uart_baud_rate_generator_downstream(clocks, self);
4178 self.configure_baud_rate_generator_impl(clocks, old_config, config);
4179 }
4180 pub fn baud_rate_generator_config(
4181 self,
4182 clocks: &mut ClockTree,
4183 ) -> Option<UartBaudRateGeneratorConfig> {
4184 clocks.uart_baud_rate_generator[self as usize]
4185 }
4186 pub fn request_baud_rate_generator(self, clocks: &mut ClockTree) {
4187 trace!("Requesting {:?}::BAUD_RATE_GENERATOR", self);
4188 if increment_reference_count(
4189 &mut clocks.uart_baud_rate_generator_refcount[self as usize],
4190 ) {
4191 trace!("Enabling {:?}::BAUD_RATE_GENERATOR", self);
4192 self.request_function_clock(clocks);
4193 self.enable_baud_rate_generator_impl(clocks, true);
4194 }
4195 }
4196 pub fn release_baud_rate_generator(self, clocks: &mut ClockTree) {
4197 trace!("Releasing {:?}::BAUD_RATE_GENERATOR", self);
4198 if decrement_reference_count(
4199 &mut clocks.uart_baud_rate_generator_refcount[self as usize],
4200 ) {
4201 trace!("Disabling {:?}::BAUD_RATE_GENERATOR", self);
4202 self.enable_baud_rate_generator_impl(clocks, false);
4203 self.release_function_clock(clocks);
4204 }
4205 }
4206 pub fn baud_rate_generator_config_frequency(
4207 self,
4208 config: UartBaudRateGeneratorConfig,
4209 ) -> u32 {
4210 ((self.function_clock_frequency() * 16)
4211 / ((config.integral() * 16) + config.fractional()))
4212 }
4213 pub fn baud_rate_generator_frequency(self) -> u32 {
4214 UART_BAUD_RATE_GENERATOR_FREQ_CACHE[self as usize]
4215 .load(::core::sync::atomic::Ordering::Acquire)
4216 }
4217 }
4218 impl TsensInstance {
4219 pub fn configure_sclk(self, clocks: &mut ClockTree, new_selector: TsensSclkConfig) {
4220 let old_selector = clocks.tsens_sclk[self as usize].replace(new_selector);
4221 refresh_tsens_sclk_downstream(clocks, self);
4222 let active = clocks.tsens_sclk_refcount[self as usize] > 0;
4223 if active {
4224 match new_selector {
4225 TsensSclkConfig::RcFast => request_rc_fast_clk(clocks),
4226 TsensSclkConfig::Xtal => request_xtal_clk(clocks),
4227 }
4228 }
4229 self.configure_sclk_impl(clocks, old_selector, new_selector);
4230 if active && let Some(old_selector) = old_selector {
4231 match old_selector {
4232 TsensSclkConfig::RcFast => release_rc_fast_clk(clocks),
4233 TsensSclkConfig::Xtal => release_xtal_clk(clocks),
4234 }
4235 }
4236 }
4237 pub fn sclk_config(self, clocks: &mut ClockTree) -> Option<TsensSclkConfig> {
4238 clocks.tsens_sclk[self as usize]
4239 }
4240 pub fn request_sclk(self, clocks: &mut ClockTree) {
4241 trace!("Requesting {:?}::SCLK", self);
4242 if increment_reference_count(&mut clocks.tsens_sclk_refcount[self as usize]) {
4243 trace!("Enabling {:?}::SCLK", self);
4244 match unwrap!(clocks.tsens_sclk[self as usize]) {
4245 TsensSclkConfig::RcFast => request_rc_fast_clk(clocks),
4246 TsensSclkConfig::Xtal => request_xtal_clk(clocks),
4247 }
4248 self.enable_sclk_impl(clocks, true);
4249 }
4250 }
4251 pub fn release_sclk(self, clocks: &mut ClockTree) {
4252 trace!("Releasing {:?}::SCLK", self);
4253 if decrement_reference_count(&mut clocks.tsens_sclk_refcount[self as usize]) {
4254 trace!("Disabling {:?}::SCLK", self);
4255 self.enable_sclk_impl(clocks, false);
4256 match unwrap!(clocks.tsens_sclk[self as usize]) {
4257 TsensSclkConfig::RcFast => release_rc_fast_clk(clocks),
4258 TsensSclkConfig::Xtal => release_xtal_clk(clocks),
4259 }
4260 }
4261 }
4262 pub fn sclk_config_frequency(config: TsensSclkConfig) -> u32 {
4263 match config {
4264 TsensSclkConfig::RcFast => rc_fast_clk_frequency(),
4265 TsensSclkConfig::Xtal => xtal_clk_frequency(),
4266 }
4267 }
4268 pub fn sclk_frequency(self) -> u32 {
4269 TSENS_SCLK_FREQ_CACHE[self as usize].load(::core::sync::atomic::Ordering::Acquire)
4270 }
4271 pub fn sclk_source_frequency(source: TsensSclkConfig) -> u32 {
4272 Self::sclk_config_frequency(source)
4273 }
4274 }
4275 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
4283 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
4284 #[instability::unstable]
4285 pub struct ClockConfig {
4286 pub xtal_clk: Option<XtalClkConfig>,
4288 pub pll_clk: Option<PllClkConfig>,
4290 pub system_pre_div: Option<SystemPreDivConfig>,
4292 pub cpu_pll_div_out: Option<CpuPllDivOutConfig>,
4294 pub cpu_clk: Option<CpuClkConfig>,
4296 pub rc_fast_clk_div_n: Option<RcFastClkDivNConfig>,
4298 pub rtc_slow_clk: Option<RtcSlowClkConfig>,
4300 pub ble_lp_clk: Option<BleLpClkConfig>,
4302 pub rtc_fast_clk: Option<RtcFastClkConfig>,
4304 pub low_power_clk: Option<LowPowerClkConfig>,
4306 pub timg_calibration_clock: Option<TimgCalibrationClockConfig>,
4308 }
4309 impl ClockConfig {
4310 fn apply(&self, clocks: &mut ClockTree) {
4311 if let Some(config) = self.xtal_clk {
4312 configure_xtal_clk(clocks, config);
4313 }
4314 if let Some(config) = self.pll_clk {
4315 configure_pll_clk(clocks, config);
4316 }
4317 if let Some(config) = self.system_pre_div {
4318 configure_system_pre_div(clocks, config);
4319 }
4320 if let Some(config) = self.cpu_pll_div_out {
4321 configure_cpu_pll_div_out(clocks, config);
4322 }
4323 if let Some(config) = self.cpu_clk {
4324 configure_cpu_clk(clocks, config);
4325 }
4326 if let Some(config) = self.rc_fast_clk_div_n {
4327 configure_rc_fast_clk_div_n(clocks, config);
4328 }
4329 if let Some(config) = self.rtc_slow_clk {
4330 configure_rtc_slow_clk(clocks, config);
4331 }
4332 if let Some(config) = self.ble_lp_clk {
4333 configure_ble_lp_clk(clocks, config);
4334 }
4335 if let Some(config) = self.rtc_fast_clk {
4336 configure_rtc_fast_clk(clocks, config);
4337 }
4338 if let Some(config) = self.low_power_clk {
4339 configure_low_power_clk(clocks, config);
4340 }
4341 if let Some(config) = self.timg_calibration_clock {
4342 configure_timg_calibration_clock(clocks, config);
4343 }
4344 }
4345 }
4346 fn increment_reference_count(refcount: &mut u32) -> bool {
4347 let first = *refcount == 0;
4348 *refcount = unwrap!(refcount.checked_add(1), "Reference count overflow");
4349 first
4350 }
4351 fn decrement_reference_count(refcount: &mut u32) -> bool {
4352 *refcount = refcount.saturating_sub(1);
4353 let last = *refcount == 0;
4354 last
4355 }
4356 fn refresh_xtal_clk_downstream(clocks: &mut ClockTree) {
4357 if let Some(config) = clocks.xtal_clk {
4358 XTAL_CLK_FREQ_CACHE.store(
4359 xtal_clk_config_frequency(config),
4360 ::core::sync::atomic::Ordering::Release,
4361 );
4362 }
4363 refresh_pll_clk_downstream(clocks);
4364 refresh_system_pre_div_in_downstream(clocks);
4365 refresh_ble_lp_clk_downstream(clocks);
4366 refresh_rtc_fast_clk_downstream(clocks);
4367 refresh_low_power_clk_downstream(clocks);
4368 for child_instance in [I2cInstance::I2c0] {
4369 refresh_i2c_function_clock_downstream(clocks, child_instance);
4370 }
4371 for child_instance in [I2sInstance::I2s0] {
4372 refresh_i2s_tx_clk_downstream(clocks, child_instance);
4373 refresh_i2s_rx_clk_downstream(clocks, child_instance);
4374 }
4375 for child_instance in [SpiInstance::Spi2] {
4376 refresh_spi_function_clock_downstream(clocks, child_instance);
4377 }
4378 for child_instance in [TsensInstance::Tsens] {
4379 refresh_tsens_sclk_downstream(clocks, child_instance);
4380 }
4381 for child_instance in [RmtInstance::Rmt] {
4382 refresh_rmt_sclk_downstream(clocks, child_instance);
4383 }
4384 for child_instance in [TimgInstance::Timg0, TimgInstance::Timg1] {
4385 refresh_timg_function_clock_downstream(clocks, child_instance);
4386 refresh_timg_wdt_clock_downstream(clocks, child_instance);
4387 }
4388 for child_instance in [UartInstance::Uart0, UartInstance::Uart1] {
4389 refresh_uart_function_clock_downstream(clocks, child_instance);
4390 }
4391 }
4392 fn refresh_pll_clk_downstream(clocks: &mut ClockTree) {
4393 if let Some(config) = clocks.pll_clk {
4394 PLL_CLK_FREQ_CACHE.store(
4395 pll_clk_config_frequency(config),
4396 ::core::sync::atomic::Ordering::Release,
4397 );
4398 }
4399 refresh_cpu_pll_div_out_downstream(clocks);
4400 }
4401 fn refresh_rc_fast_clk_downstream(clocks: &mut ClockTree) {
4402 refresh_system_pre_div_in_downstream(clocks);
4403 refresh_rc_fast_clk_div_n_downstream(clocks);
4404 refresh_rtc_slow_clk_downstream(clocks);
4405 refresh_low_power_clk_downstream(clocks);
4406 refresh_timg_calibration_clock_downstream(clocks);
4407 for child_instance in [I2cInstance::I2c0] {
4408 refresh_i2c_function_clock_downstream(clocks, child_instance);
4409 }
4410 for child_instance in [TsensInstance::Tsens] {
4411 refresh_tsens_sclk_downstream(clocks, child_instance);
4412 }
4413 for child_instance in [RmtInstance::Rmt] {
4414 refresh_rmt_sclk_downstream(clocks, child_instance);
4415 }
4416 for child_instance in [UartInstance::Uart0, UartInstance::Uart1] {
4417 refresh_uart_function_clock_downstream(clocks, child_instance);
4418 }
4419 }
4420 fn refresh_rc_slow_clk_downstream(clocks: &mut ClockTree) {
4421 refresh_rtc_slow_clk_downstream(clocks);
4422 refresh_timg_calibration_clock_downstream(clocks);
4423 }
4424 fn refresh_system_pre_div_in_downstream(clocks: &mut ClockTree) {
4425 if let Some(config) = clocks.system_pre_div_in {
4426 SYSTEM_PRE_DIV_IN_FREQ_CACHE.store(
4427 system_pre_div_in_config_frequency(config),
4428 ::core::sync::atomic::Ordering::Release,
4429 );
4430 }
4431 refresh_system_pre_div_downstream(clocks);
4432 }
4433 fn refresh_system_pre_div_downstream(clocks: &mut ClockTree) {
4434 if let Some(config) = clocks.system_pre_div {
4435 SYSTEM_PRE_DIV_FREQ_CACHE.store(
4436 system_pre_div_config_frequency(config),
4437 ::core::sync::atomic::Ordering::Release,
4438 );
4439 }
4440 refresh_cpu_clk_downstream(clocks);
4441 }
4442 fn refresh_cpu_pll_div_out_downstream(clocks: &mut ClockTree) {
4443 if let Some(config) = clocks.cpu_pll_div_out {
4444 CPU_PLL_DIV_OUT_FREQ_CACHE.store(
4445 cpu_pll_div_out_config_frequency(config),
4446 ::core::sync::atomic::Ordering::Release,
4447 );
4448 }
4449 refresh_cpu_clk_downstream(clocks);
4450 }
4451 fn refresh_cpu_clk_downstream(clocks: &mut ClockTree) {
4452 if let Some(config) = clocks.cpu_clk {
4453 CPU_CLK_FREQ_CACHE.store(
4454 cpu_clk_config_frequency(config),
4455 ::core::sync::atomic::Ordering::Release,
4456 );
4457 }
4458 refresh_apb_clk_downstream(clocks);
4459 refresh_crypto_clk_downstream(clocks);
4460 for child_instance in [I2sInstance::I2s0] {
4461 refresh_i2s_tx_clk_downstream(clocks, child_instance);
4462 refresh_i2s_rx_clk_downstream(clocks, child_instance);
4463 }
4464 for child_instance in [SpiInstance::Spi2] {
4465 refresh_spi_function_clock_downstream(clocks, child_instance);
4466 }
4467 }
4468 fn refresh_rc_fast_clk_div_n_downstream(clocks: &mut ClockTree) {
4469 if let Some(config) = clocks.rc_fast_clk_div_n {
4470 RC_FAST_CLK_DIV_N_FREQ_CACHE.store(
4471 rc_fast_clk_div_n_config_frequency(config),
4472 ::core::sync::atomic::Ordering::Release,
4473 );
4474 }
4475 refresh_rtc_fast_clk_downstream(clocks);
4476 }
4477 fn refresh_rtc_slow_clk_downstream(clocks: &mut ClockTree) {
4478 if let Some(config) = clocks.rtc_slow_clk {
4479 RTC_SLOW_CLK_FREQ_CACHE.store(
4480 rtc_slow_clk_config_frequency(config),
4481 ::core::sync::atomic::Ordering::Release,
4482 );
4483 }
4484 refresh_ble_lp_clk_downstream(clocks);
4485 refresh_low_power_clk_downstream(clocks);
4486 }
4487 fn refresh_ble_lp_clk_downstream(clocks: &mut ClockTree) {
4488 if let Some(config) = clocks.ble_lp_clk {
4489 BLE_LP_CLK_FREQ_CACHE.store(
4490 ble_lp_clk_config_frequency(config),
4491 ::core::sync::atomic::Ordering::Release,
4492 );
4493 }
4494 }
4495 fn refresh_rtc_fast_clk_downstream(clocks: &mut ClockTree) {
4496 if let Some(config) = clocks.rtc_fast_clk {
4497 RTC_FAST_CLK_FREQ_CACHE.store(
4498 rtc_fast_clk_config_frequency(config),
4499 ::core::sync::atomic::Ordering::Release,
4500 );
4501 }
4502 }
4503 fn refresh_low_power_clk_downstream(clocks: &mut ClockTree) {
4504 if let Some(config) = clocks.low_power_clk {
4505 LOW_POWER_CLK_FREQ_CACHE.store(
4506 low_power_clk_config_frequency(config),
4507 ::core::sync::atomic::Ordering::Release,
4508 );
4509 }
4510 }
4511 fn refresh_timg_calibration_clock_downstream(clocks: &mut ClockTree) {
4512 if let Some(config) = clocks.timg_calibration_clock {
4513 TIMG_CALIBRATION_CLOCK_FREQ_CACHE.store(
4514 timg_calibration_clock_config_frequency(config),
4515 ::core::sync::atomic::Ordering::Release,
4516 );
4517 }
4518 }
4519 fn refresh_i2c_function_clock_downstream(clocks: &mut ClockTree, instance: I2cInstance) {
4520 if let Some(config) = clocks.i2c_function_clock[instance as usize] {
4521 I2C_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
4522 I2cInstance::function_clock_config_frequency(config),
4523 ::core::sync::atomic::Ordering::Release,
4524 );
4525 }
4526 }
4527 fn refresh_i2s_tx_clk_downstream(clocks: &mut ClockTree, instance: I2sInstance) {
4528 if let Some(config) = clocks.i2s_tx_clk[instance as usize] {
4529 I2S_TX_CLK_FREQ_CACHE[instance as usize].store(
4530 I2sInstance::tx_clk_config_frequency(config),
4531 ::core::sync::atomic::Ordering::Release,
4532 );
4533 }
4534 refresh_i2s_mclk_out_downstream(clocks, instance);
4535 }
4536 fn refresh_i2s_rx_clk_downstream(clocks: &mut ClockTree, instance: I2sInstance) {
4537 if let Some(config) = clocks.i2s_rx_clk[instance as usize] {
4538 I2S_RX_CLK_FREQ_CACHE[instance as usize].store(
4539 I2sInstance::rx_clk_config_frequency(config),
4540 ::core::sync::atomic::Ordering::Release,
4541 );
4542 }
4543 refresh_i2s_mclk_out_downstream(clocks, instance);
4544 }
4545 fn refresh_i2s_mclk_out_downstream(clocks: &mut ClockTree, instance: I2sInstance) {
4546 if let Some(config) = clocks.i2s_mclk_out[instance as usize] {
4547 I2S_MCLK_OUT_FREQ_CACHE[instance as usize].store(
4548 instance.mclk_out_config_frequency(config),
4549 ::core::sync::atomic::Ordering::Release,
4550 );
4551 }
4552 }
4553 fn refresh_spi_function_clock_downstream(clocks: &mut ClockTree, instance: SpiInstance) {
4554 if let Some(config) = clocks.spi_function_clock[instance as usize] {
4555 SPI_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
4556 SpiInstance::function_clock_config_frequency(config),
4557 ::core::sync::atomic::Ordering::Release,
4558 );
4559 }
4560 }
4561 fn refresh_tsens_sclk_downstream(clocks: &mut ClockTree, instance: TsensInstance) {
4562 if let Some(config) = clocks.tsens_sclk[instance as usize] {
4563 TSENS_SCLK_FREQ_CACHE[instance as usize].store(
4564 TsensInstance::sclk_config_frequency(config),
4565 ::core::sync::atomic::Ordering::Release,
4566 );
4567 }
4568 }
4569 fn refresh_apb_clk_downstream(clocks: &mut ClockTree) {
4570 if let Some(config) = clocks.apb_clk {
4571 APB_CLK_FREQ_CACHE.store(
4572 apb_clk_config_frequency(config),
4573 ::core::sync::atomic::Ordering::Release,
4574 );
4575 }
4576 for child_instance in [RmtInstance::Rmt] {
4577 refresh_rmt_sclk_downstream(clocks, child_instance);
4578 }
4579 for child_instance in [TimgInstance::Timg0, TimgInstance::Timg1] {
4580 refresh_timg_function_clock_downstream(clocks, child_instance);
4581 refresh_timg_wdt_clock_downstream(clocks, child_instance);
4582 }
4583 for child_instance in [UartInstance::Uart0, UartInstance::Uart1] {
4584 refresh_uart_function_clock_downstream(clocks, child_instance);
4585 }
4586 }
4587 fn refresh_crypto_clk_downstream(clocks: &mut ClockTree) {
4588 if let Some(config) = clocks.crypto_clk {
4589 CRYPTO_CLK_FREQ_CACHE.store(
4590 crypto_clk_config_frequency(config),
4591 ::core::sync::atomic::Ordering::Release,
4592 );
4593 }
4594 }
4595 fn refresh_rmt_sclk_downstream(clocks: &mut ClockTree, instance: RmtInstance) {
4596 if let Some(config) = clocks.rmt_sclk[instance as usize] {
4597 RMT_SCLK_FREQ_CACHE[instance as usize].store(
4598 RmtInstance::sclk_config_frequency(config),
4599 ::core::sync::atomic::Ordering::Release,
4600 );
4601 }
4602 }
4603 fn refresh_timg_function_clock_downstream(clocks: &mut ClockTree, instance: TimgInstance) {
4604 if let Some(config) = clocks.timg_function_clock[instance as usize] {
4605 TIMG_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
4606 TimgInstance::function_clock_config_frequency(config),
4607 ::core::sync::atomic::Ordering::Release,
4608 );
4609 }
4610 }
4611 fn refresh_timg_wdt_clock_downstream(clocks: &mut ClockTree, instance: TimgInstance) {
4612 if let Some(config) = clocks.timg_wdt_clock[instance as usize] {
4613 TIMG_WDT_CLOCK_FREQ_CACHE[instance as usize].store(
4614 TimgInstance::wdt_clock_config_frequency(config),
4615 ::core::sync::atomic::Ordering::Release,
4616 );
4617 }
4618 }
4619 fn refresh_uart_function_clock_downstream(clocks: &mut ClockTree, instance: UartInstance) {
4620 if let Some(config) = clocks.uart_function_clock[instance as usize] {
4621 UART_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
4622 UartInstance::function_clock_config_frequency(config),
4623 ::core::sync::atomic::Ordering::Release,
4624 );
4625 }
4626 refresh_uart_baud_rate_generator_downstream(clocks, instance);
4627 }
4628 fn refresh_uart_baud_rate_generator_downstream(
4629 clocks: &mut ClockTree,
4630 instance: UartInstance,
4631 ) {
4632 if let Some(config) = clocks.uart_baud_rate_generator[instance as usize] {
4633 UART_BAUD_RATE_GENERATOR_FREQ_CACHE[instance as usize].store(
4634 instance.baud_rate_generator_config_frequency(config),
4635 ::core::sync::atomic::Ordering::Release,
4636 );
4637 }
4638 }
4639 };
4640}
4641#[macro_export]
4645#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4646macro_rules! implement_peripheral_clocks {
4647 () => {
4648 #[doc(hidden)]
4649 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
4650 #[repr(u8)]
4651 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
4652 pub enum Peripheral {
4653 Aes,
4655 AhbGdma,
4657 ApbSarAdc,
4659 Ds,
4661 GpioSd,
4663 Hmac,
4665 I2cExt0,
4667 I2s0,
4669 Ledc,
4671 Rmt,
4673 Rsa,
4675 Sha,
4677 Spi2,
4679 Systimer,
4681 Timg0,
4683 Timg1,
4685 Tsens,
4687 Twai0,
4689 Uart0,
4691 Uart1,
4693 UartMem,
4695 Uhci0,
4697 UsbDevice,
4699 }
4700 impl Peripheral {
4701 const KEEP_ENABLED: &[Peripheral] = &[
4702 Self::Systimer,
4703 Self::Timg0,
4704 Self::Uart0,
4705 Self::UartMem,
4706 Self::UsbDevice,
4707 ];
4708 const COUNT: usize = Self::ALL.len();
4709 const ALL: &[Self] = &[
4710 Self::Aes,
4711 Self::AhbGdma,
4712 Self::ApbSarAdc,
4713 Self::Ds,
4714 Self::GpioSd,
4715 Self::Hmac,
4716 Self::I2cExt0,
4717 Self::I2s0,
4718 Self::Ledc,
4719 Self::Rmt,
4720 Self::Rsa,
4721 Self::Sha,
4722 Self::Spi2,
4723 Self::Systimer,
4724 Self::Timg0,
4725 Self::Timg1,
4726 Self::Tsens,
4727 Self::Twai0,
4728 Self::Uart0,
4729 Self::Uart1,
4730 Self::UartMem,
4731 Self::Uhci0,
4732 Self::UsbDevice,
4733 ];
4734 }
4735 unsafe fn enable_internal_racey(peripheral: Peripheral, enable: bool) {
4736 match peripheral {
4737 Peripheral::Aes => {
4738 crate::peripherals::SYSTEM::regs()
4739 .perip_clk_en1()
4740 .modify(|_, w| w.crypto_aes_clk_en().bit(enable));
4741 }
4742 Peripheral::AhbGdma => {
4743 crate::peripherals::SYSTEM::regs()
4744 .perip_clk_en1()
4745 .modify(|_, w| w.dma_clk_en().bit(enable));
4746 }
4747 Peripheral::ApbSarAdc => {
4748 crate::peripherals::SYSTEM::regs()
4749 .perip_clk_en0()
4750 .modify(|_, w| w.apb_saradc_clk_en().bit(enable));
4751 }
4752 Peripheral::Ds => {
4753 crate::peripherals::SYSTEM::regs()
4754 .perip_clk_en1()
4755 .modify(|_, w| w.crypto_ds_clk_en().bit(enable));
4756 }
4757 Peripheral::GpioSd => {
4758 crate::peripherals::GPIO_SD::regs()
4759 .clock_gate()
4760 .modify(|_, w| w.clk_en().bit(enable));
4761 }
4762 Peripheral::Hmac => {
4763 crate::peripherals::SYSTEM::regs()
4764 .perip_clk_en1()
4765 .modify(|_, w| w.crypto_hmac_clk_en().bit(enable));
4766 }
4767 Peripheral::I2cExt0 => {
4768 crate::peripherals::SYSTEM::regs()
4769 .perip_clk_en0()
4770 .modify(|_, w| w.i2c_ext0_clk_en().bit(enable));
4771 }
4772 Peripheral::I2s0 => {
4773 crate::peripherals::SYSTEM::regs()
4774 .perip_clk_en0()
4775 .modify(|_, w| w.i2s0_clk_en().bit(enable));
4776 }
4777 Peripheral::Ledc => {
4778 crate::peripherals::SYSTEM::regs()
4779 .perip_clk_en0()
4780 .modify(|_, w| w.ledc_clk_en().bit(enable));
4781 }
4782 Peripheral::Rmt => {
4783 crate::peripherals::SYSTEM::regs()
4784 .perip_clk_en0()
4785 .modify(|_, w| w.rmt_clk_en().bit(enable));
4786 }
4787 Peripheral::Rsa => {
4788 crate::peripherals::SYSTEM::regs()
4789 .perip_clk_en1()
4790 .modify(|_, w| w.crypto_rsa_clk_en().bit(enable));
4791 }
4792 Peripheral::Sha => {
4793 crate::peripherals::SYSTEM::regs()
4794 .perip_clk_en1()
4795 .modify(|_, w| w.crypto_sha_clk_en().bit(enable));
4796 }
4797 Peripheral::Spi2 => {
4798 crate::peripherals::SYSTEM::regs()
4799 .perip_clk_en0()
4800 .modify(|_, w| w.spi2_clk_en().bit(enable));
4801 }
4802 Peripheral::Systimer => {
4803 crate::peripherals::SYSTEM::regs()
4804 .perip_clk_en0()
4805 .modify(|_, w| w.systimer_clk_en().bit(enable));
4806 }
4807 Peripheral::Timg0 => {
4808 crate::peripherals::SYSTEM::regs()
4809 .perip_clk_en0()
4810 .modify(|_, w| w.timergroup_clk_en().bit(enable));
4811 }
4812 Peripheral::Timg1 => {
4813 crate::peripherals::SYSTEM::regs()
4814 .perip_clk_en0()
4815 .modify(|_, w| w.timergroup1_clk_en().bit(enable));
4816 }
4817 Peripheral::Tsens => {
4818 crate::peripherals::SYSTEM::regs()
4819 .perip_clk_en1()
4820 .modify(|_, w| w.tsens_clk_en().bit(enable));
4821 }
4822 Peripheral::Twai0 => {
4823 crate::peripherals::SYSTEM::regs()
4824 .perip_clk_en0()
4825 .modify(|_, w| w.twai_clk_en().bit(enable));
4826 }
4827 Peripheral::Uart0 => {
4828 crate::peripherals::SYSTEM::regs()
4829 .perip_clk_en0()
4830 .modify(|_, w| w.uart_clk_en().bit(enable));
4831 }
4832 Peripheral::Uart1 => {
4833 crate::peripherals::SYSTEM::regs()
4834 .perip_clk_en0()
4835 .modify(|_, w| w.uart1_clk_en().bit(enable));
4836 }
4837 Peripheral::UartMem => {
4838 crate::peripherals::SYSTEM::regs()
4839 .perip_clk_en0()
4840 .modify(|_, w| w.uart_mem_clk_en().bit(enable));
4841 }
4842 Peripheral::Uhci0 => {
4843 crate::peripherals::SYSTEM::regs()
4844 .perip_clk_en0()
4845 .modify(|_, w| w.uhci0_clk_en().bit(enable));
4846 }
4847 Peripheral::UsbDevice => {
4848 crate::peripherals::SYSTEM::regs()
4849 .perip_clk_en0()
4850 .modify(|_, w| w.usb_device_clk_en().bit(enable));
4851 }
4852 }
4853 }
4854 unsafe fn assert_peri_reset_racey(peripheral: Peripheral, reset: bool) {
4855 match peripheral {
4856 Peripheral::Aes => {
4857 crate::peripherals::SYSTEM::regs()
4858 .perip_rst_en1()
4859 .modify(|_, w| w.crypto_aes_rst().bit(reset));
4860 }
4861 Peripheral::AhbGdma => {
4862 crate::peripherals::SYSTEM::regs()
4863 .perip_rst_en1()
4864 .modify(|_, w| w.dma_rst().bit(reset));
4865 }
4866 Peripheral::ApbSarAdc => {
4867 crate::peripherals::SYSTEM::regs()
4868 .perip_rst_en0()
4869 .modify(|_, w| w.apb_saradc_rst().bit(reset));
4870 }
4871 Peripheral::Ds => {
4872 crate::peripherals::SYSTEM::regs()
4873 .perip_rst_en1()
4874 .modify(|_, w| w.crypto_ds_rst().bit(reset));
4875 }
4876 Peripheral::GpioSd => {
4877 let _ = reset;
4878 }
4879 Peripheral::Hmac => {
4880 crate::peripherals::SYSTEM::regs()
4881 .perip_rst_en1()
4882 .modify(|_, w| w.crypto_hmac_rst().bit(reset));
4883 }
4884 Peripheral::I2cExt0 => {
4885 crate::peripherals::SYSTEM::regs()
4886 .perip_rst_en0()
4887 .modify(|_, w| w.i2c_ext0_rst().bit(reset));
4888 }
4889 Peripheral::I2s0 => {
4890 crate::peripherals::SYSTEM::regs()
4891 .perip_rst_en0()
4892 .modify(|_, w| w.i2s0_rst().bit(reset));
4893 }
4894 Peripheral::Ledc => {
4895 crate::peripherals::SYSTEM::regs()
4896 .perip_rst_en0()
4897 .modify(|_, w| w.ledc_rst().bit(reset));
4898 }
4899 Peripheral::Rmt => {
4900 crate::peripherals::SYSTEM::regs()
4901 .perip_rst_en0()
4902 .modify(|_, w| w.rmt_rst().bit(reset));
4903 }
4904 Peripheral::Rsa => {
4905 crate::peripherals::SYSTEM::regs()
4906 .perip_rst_en1()
4907 .modify(|_, w| w.crypto_rsa_rst().bit(reset));
4908 }
4909 Peripheral::Sha => {
4910 crate::peripherals::SYSTEM::regs()
4911 .perip_rst_en1()
4912 .modify(|_, w| w.crypto_sha_rst().bit(reset));
4913 }
4914 Peripheral::Spi2 => {
4915 crate::peripherals::SYSTEM::regs()
4916 .perip_rst_en0()
4917 .modify(|_, w| w.spi2_rst().bit(reset));
4918 }
4919 Peripheral::Systimer => {
4920 crate::peripherals::SYSTEM::regs()
4921 .perip_rst_en0()
4922 .modify(|_, w| w.systimer_rst().bit(reset));
4923 }
4924 Peripheral::Timg0 => {
4925 crate::peripherals::SYSTEM::regs()
4926 .perip_rst_en0()
4927 .modify(|_, w| w.timergroup_rst().bit(reset));
4928 }
4929 Peripheral::Timg1 => {
4930 crate::peripherals::SYSTEM::regs()
4931 .perip_rst_en0()
4932 .modify(|_, w| w.timergroup1_rst().bit(reset));
4933 }
4934 Peripheral::Tsens => {
4935 crate::peripherals::SYSTEM::regs()
4936 .perip_rst_en1()
4937 .modify(|_, w| w.tsens_rst().bit(reset));
4938 }
4939 Peripheral::Twai0 => {
4940 crate::peripherals::SYSTEM::regs()
4941 .perip_rst_en0()
4942 .modify(|_, w| w.twai_rst().bit(reset));
4943 }
4944 Peripheral::Uart0 => {
4945 crate::peripherals::SYSTEM::regs()
4946 .perip_rst_en0()
4947 .modify(|_, w| w.uart_rst().bit(reset));
4948 }
4949 Peripheral::Uart1 => {
4950 crate::peripherals::SYSTEM::regs()
4951 .perip_rst_en0()
4952 .modify(|_, w| w.uart1_rst().bit(reset));
4953 }
4954 Peripheral::UartMem => {
4955 crate::peripherals::SYSTEM::regs()
4956 .perip_rst_en0()
4957 .modify(|_, w| w.uart_mem_rst().bit(reset));
4958 }
4959 Peripheral::Uhci0 => {
4960 crate::peripherals::SYSTEM::regs()
4961 .perip_rst_en0()
4962 .modify(|_, w| w.uhci0_rst().bit(reset));
4963 }
4964 Peripheral::UsbDevice => {
4965 crate::peripherals::SYSTEM::regs()
4966 .perip_rst_en0()
4967 .modify(|_, w| w.usb_device_rst().bit(reset));
4968 }
4969 }
4970 }
4971 };
4972}
4973#[macro_export]
4981#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4982macro_rules! memory_range {
4983 ("DRAM") => {
4984 0x3FC80000..0x3FCE0000
4985 };
4986 (size as str, "DRAM") => {
4987 "393216"
4988 };
4989 ("DRAM2_UNINIT") => {
4990 0x3FCCE400..0x3FCDE710
4991 };
4992 (size as str, "DRAM2_UNINIT") => {
4993 "66320"
4994 };
4995 ("IROM") => {
4996 0x42000000..0x42800000
4997 };
4998 (size as str, "IROM") => {
4999 "8388608"
5000 };
5001 ("DROM") => {
5002 0x3C000000..0x3C800000
5003 };
5004 (size as str, "DROM") => {
5005 "8388608"
5006 };
5007}
5008#[macro_export]
5025#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5026macro_rules! for_each_i2c_master {
5027 ($($pattern:tt => $code:tt;)*) => {
5028 macro_rules! _for_each_inner_i2c_master { $(($pattern) => $code;)* ($other : tt)
5029 => {} } _for_each_inner_i2c_master!((0, I2C0, I2cExt0, I2CEXT0_SCL,
5030 I2CEXT0_SDA)); _for_each_inner_i2c_master!((all(0, I2C0, I2cExt0, I2CEXT0_SCL,
5031 I2CEXT0_SDA)));
5032 };
5033}
5034#[macro_export]
5061#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5062macro_rules! for_each_i2s {
5063 ($($pattern:tt => $code:tt;)*) => {
5064 macro_rules! _for_each_inner_i2s { $(($pattern) => $code;)* ($other : tt) => {} }
5065 _for_each_inner_i2s!((I2S0)); _for_each_inner_i2s!((I2S0, I2s0, I2S_MCLK,
5066 I2SO_BCK, I2SO_WS, I2SI_BCK, I2SI_WS, [I2SO_SD], [I2SI_SD], true, true, true,
5067 false)); _for_each_inner_i2s!((names(I2S0))); _for_each_inner_i2s!((all(I2S0,
5068 I2s0, I2S_MCLK, I2SO_BCK, I2SO_WS, I2SI_BCK, I2SI_WS, [I2SO_SD], [I2SI_SD], true,
5069 true, true, false)));
5070 };
5071}
5072#[macro_export]
5091#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5092macro_rules! for_each_uart {
5093 ($($pattern:tt => $code:tt;)*) => {
5094 macro_rules! _for_each_inner_uart { $(($pattern) => $code;)* ($other : tt) => {}
5095 } _for_each_inner_uart!((0, UART0, Uart0, U0RXD, U0TXD, U0CTS, U0RTS,
5096 wakeup_source = true)); _for_each_inner_uart!((1, UART1, Uart1, U1RXD, U1TXD,
5097 U1CTS, U1RTS, wakeup_source = true)); _for_each_inner_uart!((all(0, UART0, Uart0,
5098 U0RXD, U0TXD, U0CTS, U0RTS, wakeup_source = true), (1, UART1, Uart1, U1RXD,
5099 U1TXD, U1CTS, U1RTS, wakeup_source = true)));
5100 };
5101}
5102#[macro_export]
5124#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5125macro_rules! for_each_spi_master {
5126 ($($pattern:tt => $code:tt;)*) => {
5127 macro_rules! _for_each_inner_spi_master { $(($pattern) => $code;)* ($other : tt)
5128 => {} } _for_each_inner_spi_master!((SPI2)); _for_each_inner_spi_master!((SPI2,
5129 Spi2, FSPICLK[FSPICS0, FSPICS1, FSPICS2, FSPICS3, FSPICS4, FSPICS5] [FSPID,
5130 FSPIQ, FSPIWP, FSPIHD], true)); _for_each_inner_spi_master!((names(SPI2)));
5131 _for_each_inner_spi_master!((all(SPI2, Spi2, FSPICLK[FSPICS0, FSPICS1, FSPICS2,
5132 FSPICS3, FSPICS4, FSPICS5] [FSPID, FSPIQ, FSPIWP, FSPIHD], true)));
5133 };
5134}
5135#[macro_export]
5152#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5153macro_rules! for_each_spi_slave {
5154 ($($pattern:tt => $code:tt;)*) => {
5155 macro_rules! _for_each_inner_spi_slave { $(($pattern) => $code;)* ($other : tt)
5156 => {} } _for_each_inner_spi_slave!((SPI2)); _for_each_inner_spi_slave!((SPI2,
5157 Spi2, FSPICLK, FSPID, FSPIQ, FSPICS0));
5158 _for_each_inner_spi_slave!((names(SPI2))); _for_each_inner_spi_slave!((all(SPI2,
5159 Spi2, FSPICLK, FSPID, FSPIQ, FSPICS0)));
5160 };
5161}
5162#[macro_export]
5163#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5164macro_rules! for_each_peripheral {
5165 ($($pattern:tt => $code:tt;)*) => {
5166 macro_rules! _for_each_inner_peripheral { $(($pattern) => $code;)* ($other : tt)
5167 => {} } _for_each_inner_peripheral!((@ peri_type #[doc =
5168 "GPIO0 peripheral singleton"] GPIO0 <= virtual()));
5169 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO1 peripheral singleton"]
5170 GPIO1 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
5171 "GPIO2 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5172 "<section class=\"warning\">"] #[doc =
5173 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5174 #[doc = "<ul>"] #[doc =
5175 "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
5176 = "</ul>"] #[doc = "</section>"] GPIO2 <= virtual()));
5177 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO3 peripheral singleton"]
5178 GPIO3 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
5179 "GPIO4 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5180 "<section class=\"warning\">"] #[doc =
5181 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5182 #[doc = "<ul>"] #[doc =
5183 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
5184 #[doc = "</ul>"] #[doc = "</section>"] GPIO4 <= virtual()));
5185 _for_each_inner_peripheral!((@ peri_type #[doc =
5186 "GPIO5 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5187 "<section class=\"warning\">"] #[doc =
5188 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5189 #[doc = "<ul>"] #[doc =
5190 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
5191 #[doc = "</ul>"] #[doc = "</section>"] GPIO5 <= virtual()));
5192 _for_each_inner_peripheral!((@ peri_type #[doc =
5193 "GPIO6 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5194 "<section class=\"warning\">"] #[doc =
5195 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5196 #[doc = "<ul>"] #[doc =
5197 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
5198 #[doc = "</ul>"] #[doc = "</section>"] GPIO6 <= virtual()));
5199 _for_each_inner_peripheral!((@ peri_type #[doc =
5200 "GPIO7 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5201 "<section class=\"warning\">"] #[doc =
5202 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5203 #[doc = "<ul>"] #[doc =
5204 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
5205 #[doc = "</ul>"] #[doc = "</section>"] GPIO7 <= virtual()));
5206 _for_each_inner_peripheral!((@ peri_type #[doc =
5207 "GPIO8 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5208 "<section class=\"warning\">"] #[doc =
5209 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5210 #[doc = "<ul>"] #[doc =
5211 "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
5212 = "</ul>"] #[doc = "</section>"] GPIO8 <= virtual()));
5213 _for_each_inner_peripheral!((@ peri_type #[doc =
5214 "GPIO9 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5215 "<section class=\"warning\">"] #[doc =
5216 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5217 #[doc = "<ul>"] #[doc =
5218 "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
5219 = "</ul>"] #[doc = "</section>"] GPIO9 <= virtual()));
5220 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO10 peripheral singleton"]
5221 GPIO10 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
5222 "GPIO11 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5223 "<section class=\"warning\">"] #[doc =
5224 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5225 #[doc = "<ul>"] #[doc =
5226 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
5227 "</ul>"] #[doc = "</section>"] GPIO11 <= virtual()));
5228 _for_each_inner_peripheral!((@ peri_type #[doc =
5229 "GPIO12 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5230 "<section class=\"warning\">"] #[doc =
5231 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5232 #[doc = "<ul>"] #[doc =
5233 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
5234 "</ul>"] #[doc = "</section>"] GPIO12 <= virtual()));
5235 _for_each_inner_peripheral!((@ peri_type #[doc =
5236 "GPIO13 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5237 "<section class=\"warning\">"] #[doc =
5238 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5239 #[doc = "<ul>"] #[doc =
5240 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
5241 "</ul>"] #[doc = "</section>"] GPIO13 <= virtual()));
5242 _for_each_inner_peripheral!((@ peri_type #[doc =
5243 "GPIO14 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5244 "<section class=\"warning\">"] #[doc =
5245 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5246 #[doc = "<ul>"] #[doc =
5247 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
5248 "</ul>"] #[doc = "</section>"] GPIO14 <= virtual()));
5249 _for_each_inner_peripheral!((@ peri_type #[doc =
5250 "GPIO15 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5251 "<section class=\"warning\">"] #[doc =
5252 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5253 #[doc = "<ul>"] #[doc =
5254 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
5255 "</ul>"] #[doc = "</section>"] GPIO15 <= virtual()));
5256 _for_each_inner_peripheral!((@ peri_type #[doc =
5257 "GPIO16 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5258 "<section class=\"warning\">"] #[doc =
5259 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5260 #[doc = "<ul>"] #[doc =
5261 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
5262 "</ul>"] #[doc = "</section>"] GPIO16 <= virtual()));
5263 _for_each_inner_peripheral!((@ peri_type #[doc =
5264 "GPIO17 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5265 "<section class=\"warning\">"] #[doc =
5266 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5267 #[doc = "<ul>"] #[doc =
5268 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
5269 "</ul>"] #[doc = "</section>"] GPIO17 <= virtual()));
5270 _for_each_inner_peripheral!((@ peri_type #[doc =
5271 "GPIO18 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5272 "<section class=\"warning\">"] #[doc =
5273 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5274 #[doc = "<ul>"] #[doc =
5275 "<li>These pins may be used to debug the chip using USB.</li>"] #[doc = "</ul>"]
5276 #[doc = "</section>"] GPIO18 <= virtual())); _for_each_inner_peripheral!((@
5277 peri_type #[doc = "GPIO19 peripheral singleton (Limitations exist)"] #[doc = ""]
5278 #[doc = "<section class=\"warning\">"] #[doc =
5279 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5280 #[doc = "<ul>"] #[doc =
5281 "<li>These pins may be used to debug the chip using USB.</li>"] #[doc = "</ul>"]
5282 #[doc = "</section>"] GPIO19 <= virtual())); _for_each_inner_peripheral!((@
5283 peri_type #[doc = "GPIO20 peripheral singleton (Limitations exist)"] #[doc = ""]
5284 #[doc = "<section class=\"warning\">"] #[doc =
5285 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5286 #[doc = "<ul>"] #[doc =
5287 "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
5288 = "</ul>"] #[doc = "</section>"] GPIO20 <= virtual()));
5289 _for_each_inner_peripheral!((@ peri_type #[doc =
5290 "GPIO21 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5291 "<section class=\"warning\">"] #[doc =
5292 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5293 #[doc = "<ul>"] #[doc =
5294 "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
5295 = "</ul>"] #[doc = "</section>"] GPIO21 <= virtual()));
5296 _for_each_inner_peripheral!((@ peri_type #[doc = "DMA_CH0 peripheral singleton"]
5297 DMA_CH0 <= virtual(DMA_CH0 : { bind_dma_interrupt, enable_dma_interrupt,
5298 disable_dma_interrupt }) (unstable))); _for_each_inner_peripheral!((@ peri_type
5299 #[doc = "DMA_CH1 peripheral singleton"] DMA_CH1 <= virtual(DMA_CH1 : {
5300 bind_dma_interrupt, enable_dma_interrupt, disable_dma_interrupt }) (unstable)));
5301 _for_each_inner_peripheral!((@ peri_type #[doc = "DMA_CH2 peripheral singleton"]
5302 DMA_CH2 <= virtual(DMA_CH2 : { bind_dma_interrupt, enable_dma_interrupt,
5303 disable_dma_interrupt }) (unstable))); _for_each_inner_peripheral!((@ peri_type
5304 #[doc = "SDM_CH0 peripheral singleton"] SDM_CH0 <= virtual() (unstable)));
5305 _for_each_inner_peripheral!((@ peri_type #[doc = "SDM_CH1 peripheral singleton"]
5306 SDM_CH1 <= virtual() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc
5307 = "SDM_CH2 peripheral singleton"] SDM_CH2 <= virtual() (unstable)));
5308 _for_each_inner_peripheral!((@ peri_type #[doc = "SDM_CH3 peripheral singleton"]
5309 SDM_CH3 <= virtual() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc
5310 = "AES peripheral singleton"] AES <= AES(AES : { bind_peri_interrupt,
5311 enable_peri_interrupt, disable_peri_interrupt }) (unstable)));
5312 _for_each_inner_peripheral!((@ peri_type #[doc = "APB_CTRL peripheral singleton"]
5313 APB_CTRL <= APB_CTRL() (unstable))); _for_each_inner_peripheral!((@ peri_type
5314 #[doc = "APB_SARADC peripheral singleton"] APB_SARADC <= APB_SARADC()
5315 (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5316 "ASSIST_DEBUG peripheral singleton"] ASSIST_DEBUG <= ASSIST_DEBUG() (unstable)));
5317 _for_each_inner_peripheral!((@ peri_type #[doc = "BB peripheral singleton"] BB <=
5318 BB() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5319 "DMA peripheral singleton"] DMA <= DMA() (unstable)));
5320 _for_each_inner_peripheral!((@ peri_type #[doc = "DS peripheral singleton"] DS <=
5321 DS() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5322 "EFUSE peripheral singleton"] EFUSE <= EFUSE() (unstable)));
5323 _for_each_inner_peripheral!((@ peri_type #[doc = "EXTMEM peripheral singleton"]
5324 EXTMEM <= EXTMEM() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5325 "MMU_TABLE peripheral singleton"] MMU_TABLE <= MMU_TABLE() (unstable)));
5326 _for_each_inner_peripheral!((@ peri_type #[doc = "FE peripheral singleton"] FE <=
5327 FE() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5328 "FE2 peripheral singleton"] FE2 <= FE2() (unstable)));
5329 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO peripheral singleton"]
5330 GPIO <= GPIO() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5331 "GPIO_SD peripheral singleton"] GPIO_SD <= GPIO_SD() (unstable)));
5332 _for_each_inner_peripheral!((@ peri_type #[doc = "HMAC peripheral singleton"]
5333 HMAC <= HMAC() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5334 "I2C_ANA_MST peripheral singleton"] I2C_ANA_MST <= I2C_ANA_MST() (unstable)));
5335 _for_each_inner_peripheral!((@ peri_type #[doc = "I2C0 peripheral singleton"]
5336 I2C0 <= I2C0(I2C_EXT0 : { bind_peri_interrupt, enable_peri_interrupt,
5337 disable_peri_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
5338 "I2S0 peripheral singleton"] I2S0 <= I2S0(I2S0 : { bind_peri_interrupt,
5339 enable_peri_interrupt, disable_peri_interrupt }) (unstable)));
5340 _for_each_inner_peripheral!((@ peri_type #[doc =
5341 "INTERRUPT_CORE0 peripheral singleton"] INTERRUPT_CORE0 <= INTERRUPT_CORE0()
5342 (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5343 "IO_MUX peripheral singleton"] IO_MUX <= IO_MUX() (unstable)));
5344 _for_each_inner_peripheral!((@ peri_type #[doc = "LEDC peripheral singleton"]
5345 LEDC <= LEDC() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5346 "NRX peripheral singleton"] NRX <= NRX() (unstable)));
5347 _for_each_inner_peripheral!((@ peri_type #[doc = "RMT peripheral singleton"] RMT
5348 <= RMT() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5349 "RNG peripheral singleton"] RNG <= RNG() (unstable)));
5350 _for_each_inner_peripheral!((@ peri_type #[doc = "RSA peripheral singleton"] RSA
5351 <= RSA(RSA : { bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt
5352 }) (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5353 "LPWR peripheral singleton"] LPWR <= RTC_CNTL() (unstable)));
5354 _for_each_inner_peripheral!((@ peri_type #[doc =
5355 "RTC_TIMER peripheral singleton"] RTC_TIMER <= RTC_CNTL() (unstable)));
5356 _for_each_inner_peripheral!((@ peri_type #[doc =
5357 "SENSITIVE peripheral singleton"] SENSITIVE <= SENSITIVE() (unstable)));
5358 _for_each_inner_peripheral!((@ peri_type #[doc = "SHA peripheral singleton"] SHA
5359 <= SHA(SHA : { bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt
5360 }) (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5361 "SPI0 peripheral singleton"] SPI0 <= SPI0() (unstable)));
5362 _for_each_inner_peripheral!((@ peri_type #[doc = "SPI1 peripheral singleton"]
5363 SPI1 <= SPI1() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5364 "SPI2 peripheral singleton"] SPI2 <= SPI2(SPI2 : { bind_peri_interrupt,
5365 enable_peri_interrupt, disable_peri_interrupt })));
5366 _for_each_inner_peripheral!((@ peri_type #[doc = "SYSTEM peripheral singleton"]
5367 SYSTEM <= SYSTEM() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5368 "SYSTIMER peripheral singleton"] SYSTIMER <= SYSTIMER() (unstable)));
5369 _for_each_inner_peripheral!((@ peri_type #[doc = "TIMG0 peripheral singleton"]
5370 TIMG0 <= TIMG0() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5371 "TIMG1 peripheral singleton"] TIMG1 <= TIMG1() (unstable)));
5372 _for_each_inner_peripheral!((@ peri_type #[doc = "TWAI0 peripheral singleton"]
5373 TWAI0 <= TWAI0() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5374 "UART0 peripheral singleton"] UART0 <= UART0(UART0 : { bind_peri_interrupt,
5375 enable_peri_interrupt, disable_peri_interrupt })));
5376 _for_each_inner_peripheral!((@ peri_type #[doc = "UART1 peripheral singleton"]
5377 UART1 <= UART1(UART1 : { bind_peri_interrupt, enable_peri_interrupt,
5378 disable_peri_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
5379 "UHCI0 peripheral singleton"] UHCI0 <= UHCI0() (unstable)));
5380 _for_each_inner_peripheral!((@ peri_type #[doc =
5381 "USB_DEVICE peripheral singleton"] USB_DEVICE <= USB_DEVICE(USB_DEVICE : {
5382 bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })
5383 (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5384 "XTS_AES peripheral singleton"] XTS_AES <= XTS_AES() (unstable)));
5385 _for_each_inner_peripheral!((@ peri_type #[doc = "ADC1 peripheral singleton"]
5386 ADC1 <= virtual() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5387 "BT peripheral singleton"] BT <= virtual(BT_BB : { bind_bb_interrupt,
5388 enable_bb_interrupt, disable_bb_interrupt }, RWBLE : { bind_rwble_interrupt,
5389 enable_rwble_interrupt, disable_rwble_interrupt }, RWBT : { bind_rwbt_interrupt,
5390 enable_rwbt_interrupt, disable_rwbt_interrupt }) (unstable)));
5391 _for_each_inner_peripheral!((@ peri_type #[doc = "FLASH peripheral singleton"]
5392 FLASH <= virtual() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5393 "GPIO_DEDICATED peripheral singleton"] GPIO_DEDICATED <= virtual() (unstable)));
5394 _for_each_inner_peripheral!((@ peri_type #[doc = "TSENS peripheral singleton"]
5395 TSENS <= virtual() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5396 "WIFI peripheral singleton"] WIFI <= virtual(WIFI_MAC : { bind_mac_interrupt,
5397 enable_mac_interrupt, disable_mac_interrupt }, WIFI_PWR : { bind_pwr_interrupt,
5398 enable_pwr_interrupt, disable_pwr_interrupt }))); _for_each_inner_peripheral!((@
5399 peri_type #[doc = "FROM_CPU_INTR0 peripheral singleton"] FROM_CPU_INTR0 <=
5400 virtual() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
5401 "FROM_CPU_INTR1 peripheral singleton"] FROM_CPU_INTR1 <= virtual() (unstable)));
5402 _for_each_inner_peripheral!((@ peri_type #[doc =
5403 "FROM_CPU_INTR2 peripheral singleton"] FROM_CPU_INTR2 <= virtual() (unstable)));
5404 _for_each_inner_peripheral!((@ peri_type #[doc =
5405 "FROM_CPU_INTR3 peripheral singleton"] FROM_CPU_INTR3 <= virtual() (unstable)));
5406 _for_each_inner_peripheral!((GPIO0)); _for_each_inner_peripheral!((GPIO1));
5407 _for_each_inner_peripheral!((GPIO2)); _for_each_inner_peripheral!((GPIO3));
5408 _for_each_inner_peripheral!((GPIO4)); _for_each_inner_peripheral!((GPIO5));
5409 _for_each_inner_peripheral!((GPIO6)); _for_each_inner_peripheral!((GPIO7));
5410 _for_each_inner_peripheral!((GPIO8)); _for_each_inner_peripheral!((GPIO9));
5411 _for_each_inner_peripheral!((GPIO10)); _for_each_inner_peripheral!((GPIO11));
5412 _for_each_inner_peripheral!((GPIO12)); _for_each_inner_peripheral!((GPIO13));
5413 _for_each_inner_peripheral!((GPIO14)); _for_each_inner_peripheral!((GPIO15));
5414 _for_each_inner_peripheral!((GPIO16)); _for_each_inner_peripheral!((GPIO17));
5415 _for_each_inner_peripheral!((GPIO18)); _for_each_inner_peripheral!((GPIO19));
5416 _for_each_inner_peripheral!((GPIO20)); _for_each_inner_peripheral!((GPIO21));
5417 _for_each_inner_peripheral!((DMA_CH0(unstable)));
5418 _for_each_inner_peripheral!((DMA_CH1(unstable)));
5419 _for_each_inner_peripheral!((DMA_CH2(unstable)));
5420 _for_each_inner_peripheral!((SDM_CH0(unstable)));
5421 _for_each_inner_peripheral!((SDM_CH1(unstable)));
5422 _for_each_inner_peripheral!((SDM_CH2(unstable)));
5423 _for_each_inner_peripheral!((SDM_CH3(unstable)));
5424 _for_each_inner_peripheral!((AES(unstable)));
5425 _for_each_inner_peripheral!((APB_CTRL(unstable)));
5426 _for_each_inner_peripheral!((APB_SARADC(unstable)));
5427 _for_each_inner_peripheral!((ASSIST_DEBUG(unstable)));
5428 _for_each_inner_peripheral!((BB(unstable)));
5429 _for_each_inner_peripheral!((DMA(unstable)));
5430 _for_each_inner_peripheral!((DS(unstable)));
5431 _for_each_inner_peripheral!((EXTMEM(unstable)));
5432 _for_each_inner_peripheral!((FE(unstable)));
5433 _for_each_inner_peripheral!((FE2(unstable)));
5434 _for_each_inner_peripheral!((GPIO(unstable)));
5435 _for_each_inner_peripheral!((GPIO_SD(unstable)));
5436 _for_each_inner_peripheral!((HMAC(unstable)));
5437 _for_each_inner_peripheral!((I2C_ANA_MST(unstable)));
5438 _for_each_inner_peripheral!((I2C0));
5439 _for_each_inner_peripheral!((I2S0(unstable)));
5440 _for_each_inner_peripheral!((INTERRUPT_CORE0(unstable)));
5441 _for_each_inner_peripheral!((IO_MUX(unstable)));
5442 _for_each_inner_peripheral!((LEDC(unstable)));
5443 _for_each_inner_peripheral!((NRX(unstable)));
5444 _for_each_inner_peripheral!((RMT(unstable)));
5445 _for_each_inner_peripheral!((RNG(unstable)));
5446 _for_each_inner_peripheral!((RSA(unstable)));
5447 _for_each_inner_peripheral!((LPWR(unstable)));
5448 _for_each_inner_peripheral!((RTC_TIMER(unstable)));
5449 _for_each_inner_peripheral!((SENSITIVE(unstable)));
5450 _for_each_inner_peripheral!((SHA(unstable)));
5451 _for_each_inner_peripheral!((SPI0(unstable)));
5452 _for_each_inner_peripheral!((SPI1(unstable)));
5453 _for_each_inner_peripheral!((SPI2));
5454 _for_each_inner_peripheral!((SYSTEM(unstable)));
5455 _for_each_inner_peripheral!((SYSTIMER(unstable)));
5456 _for_each_inner_peripheral!((TIMG0(unstable)));
5457 _for_each_inner_peripheral!((TIMG1(unstable)));
5458 _for_each_inner_peripheral!((TWAI0(unstable)));
5459 _for_each_inner_peripheral!((UART0)); _for_each_inner_peripheral!((UART1));
5460 _for_each_inner_peripheral!((UHCI0(unstable)));
5461 _for_each_inner_peripheral!((USB_DEVICE(unstable)));
5462 _for_each_inner_peripheral!((XTS_AES(unstable)));
5463 _for_each_inner_peripheral!((ADC1(unstable)));
5464 _for_each_inner_peripheral!((BT(unstable)));
5465 _for_each_inner_peripheral!((FLASH(unstable)));
5466 _for_each_inner_peripheral!((GPIO_DEDICATED(unstable)));
5467 _for_each_inner_peripheral!((TSENS(unstable)));
5468 _for_each_inner_peripheral!((WIFI));
5469 _for_each_inner_peripheral!((FROM_CPU_INTR1(unstable)));
5470 _for_each_inner_peripheral!((FROM_CPU_INTR2(unstable)));
5471 _for_each_inner_peripheral!((FROM_CPU_INTR3(unstable)));
5472 _for_each_inner_peripheral!((SPI2, Spi2, 0, AhbGdmaChannel));
5473 _for_each_inner_peripheral!((UHCI0, Uhci0, 2, AhbGdmaChannel));
5474 _for_each_inner_peripheral!((I2S0, I2s0, 3, AhbGdmaChannel));
5475 _for_each_inner_peripheral!((AES, Aes, 6, AhbGdmaChannel));
5476 _for_each_inner_peripheral!((SHA, Sha, 7, AhbGdmaChannel));
5477 _for_each_inner_peripheral!((APB_SARADC, ApbSaradc, 8, AhbGdmaChannel));
5478 _for_each_inner_peripheral!((all(@ peri_type #[doc =
5479 "GPIO0 peripheral singleton"] GPIO0 <= virtual()), (@ peri_type #[doc =
5480 "GPIO1 peripheral singleton"] GPIO1 <= virtual()), (@ peri_type #[doc =
5481 "GPIO2 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5482 "<section class=\"warning\">"] #[doc =
5483 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5484 #[doc = "<ul>"] #[doc =
5485 "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
5486 = "</ul>"] #[doc = "</section>"] GPIO2 <= virtual()), (@ peri_type #[doc =
5487 "GPIO3 peripheral singleton"] GPIO3 <= virtual()), (@ peri_type #[doc =
5488 "GPIO4 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5489 "<section class=\"warning\">"] #[doc =
5490 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5491 #[doc = "<ul>"] #[doc =
5492 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
5493 #[doc = "</ul>"] #[doc = "</section>"] GPIO4 <= virtual()), (@ peri_type #[doc =
5494 "GPIO5 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5495 "<section class=\"warning\">"] #[doc =
5496 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5497 #[doc = "<ul>"] #[doc =
5498 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
5499 #[doc = "</ul>"] #[doc = "</section>"] GPIO5 <= virtual()), (@ peri_type #[doc =
5500 "GPIO6 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5501 "<section class=\"warning\">"] #[doc =
5502 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5503 #[doc = "<ul>"] #[doc =
5504 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
5505 #[doc = "</ul>"] #[doc = "</section>"] GPIO6 <= virtual()), (@ peri_type #[doc =
5506 "GPIO7 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5507 "<section class=\"warning\">"] #[doc =
5508 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5509 #[doc = "<ul>"] #[doc =
5510 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
5511 #[doc = "</ul>"] #[doc = "</section>"] GPIO7 <= virtual()), (@ peri_type #[doc =
5512 "GPIO8 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5513 "<section class=\"warning\">"] #[doc =
5514 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5515 #[doc = "<ul>"] #[doc =
5516 "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
5517 = "</ul>"] #[doc = "</section>"] GPIO8 <= virtual()), (@ peri_type #[doc =
5518 "GPIO9 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5519 "<section class=\"warning\">"] #[doc =
5520 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5521 #[doc = "<ul>"] #[doc =
5522 "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
5523 = "</ul>"] #[doc = "</section>"] GPIO9 <= virtual()), (@ peri_type #[doc =
5524 "GPIO10 peripheral singleton"] GPIO10 <= virtual()), (@ peri_type #[doc =
5525 "GPIO11 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5526 "<section class=\"warning\">"] #[doc =
5527 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5528 #[doc = "<ul>"] #[doc =
5529 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
5530 "</ul>"] #[doc = "</section>"] GPIO11 <= virtual()), (@ peri_type #[doc =
5531 "GPIO12 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5532 "<section class=\"warning\">"] #[doc =
5533 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5534 #[doc = "<ul>"] #[doc =
5535 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
5536 "</ul>"] #[doc = "</section>"] GPIO12 <= virtual()), (@ peri_type #[doc =
5537 "GPIO13 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5538 "<section class=\"warning\">"] #[doc =
5539 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5540 #[doc = "<ul>"] #[doc =
5541 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
5542 "</ul>"] #[doc = "</section>"] GPIO13 <= virtual()), (@ peri_type #[doc =
5543 "GPIO14 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5544 "<section class=\"warning\">"] #[doc =
5545 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5546 #[doc = "<ul>"] #[doc =
5547 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
5548 "</ul>"] #[doc = "</section>"] GPIO14 <= virtual()), (@ peri_type #[doc =
5549 "GPIO15 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5550 "<section class=\"warning\">"] #[doc =
5551 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5552 #[doc = "<ul>"] #[doc =
5553 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
5554 "</ul>"] #[doc = "</section>"] GPIO15 <= virtual()), (@ peri_type #[doc =
5555 "GPIO16 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5556 "<section class=\"warning\">"] #[doc =
5557 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5558 #[doc = "<ul>"] #[doc =
5559 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
5560 "</ul>"] #[doc = "</section>"] GPIO16 <= virtual()), (@ peri_type #[doc =
5561 "GPIO17 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5562 "<section class=\"warning\">"] #[doc =
5563 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5564 #[doc = "<ul>"] #[doc =
5565 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
5566 "</ul>"] #[doc = "</section>"] GPIO17 <= virtual()), (@ peri_type #[doc =
5567 "GPIO18 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5568 "<section class=\"warning\">"] #[doc =
5569 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5570 #[doc = "<ul>"] #[doc =
5571 "<li>These pins may be used to debug the chip using USB.</li>"] #[doc = "</ul>"]
5572 #[doc = "</section>"] GPIO18 <= virtual()), (@ peri_type #[doc =
5573 "GPIO19 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5574 "<section class=\"warning\">"] #[doc =
5575 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5576 #[doc = "<ul>"] #[doc =
5577 "<li>These pins may be used to debug the chip using USB.</li>"] #[doc = "</ul>"]
5578 #[doc = "</section>"] GPIO19 <= virtual()), (@ peri_type #[doc =
5579 "GPIO20 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5580 "<section class=\"warning\">"] #[doc =
5581 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5582 #[doc = "<ul>"] #[doc =
5583 "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
5584 = "</ul>"] #[doc = "</section>"] GPIO20 <= virtual()), (@ peri_type #[doc =
5585 "GPIO21 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
5586 "<section class=\"warning\">"] #[doc =
5587 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
5588 #[doc = "<ul>"] #[doc =
5589 "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
5590 = "</ul>"] #[doc = "</section>"] GPIO21 <= virtual()), (@ peri_type #[doc =
5591 "DMA_CH0 peripheral singleton"] DMA_CH0 <= virtual(DMA_CH0 : {
5592 bind_dma_interrupt, enable_dma_interrupt, disable_dma_interrupt }) (unstable)),
5593 (@ peri_type #[doc = "DMA_CH1 peripheral singleton"] DMA_CH1 <= virtual(DMA_CH1 :
5594 { bind_dma_interrupt, enable_dma_interrupt, disable_dma_interrupt }) (unstable)),
5595 (@ peri_type #[doc = "DMA_CH2 peripheral singleton"] DMA_CH2 <= virtual(DMA_CH2 :
5596 { bind_dma_interrupt, enable_dma_interrupt, disable_dma_interrupt }) (unstable)),
5597 (@ peri_type #[doc = "SDM_CH0 peripheral singleton"] SDM_CH0 <= virtual()
5598 (unstable)), (@ peri_type #[doc = "SDM_CH1 peripheral singleton"] SDM_CH1 <=
5599 virtual() (unstable)), (@ peri_type #[doc = "SDM_CH2 peripheral singleton"]
5600 SDM_CH2 <= virtual() (unstable)), (@ peri_type #[doc =
5601 "SDM_CH3 peripheral singleton"] SDM_CH3 <= virtual() (unstable)), (@ peri_type
5602 #[doc = "AES peripheral singleton"] AES <= AES(AES : { bind_peri_interrupt,
5603 enable_peri_interrupt, disable_peri_interrupt }) (unstable)), (@ peri_type #[doc
5604 = "APB_CTRL peripheral singleton"] APB_CTRL <= APB_CTRL() (unstable)), (@
5605 peri_type #[doc = "APB_SARADC peripheral singleton"] APB_SARADC <= APB_SARADC()
5606 (unstable)), (@ peri_type #[doc = "ASSIST_DEBUG peripheral singleton"]
5607 ASSIST_DEBUG <= ASSIST_DEBUG() (unstable)), (@ peri_type #[doc =
5608 "BB peripheral singleton"] BB <= BB() (unstable)), (@ peri_type #[doc =
5609 "DMA peripheral singleton"] DMA <= DMA() (unstable)), (@ peri_type #[doc =
5610 "DS peripheral singleton"] DS <= DS() (unstable)), (@ peri_type #[doc =
5611 "EFUSE peripheral singleton"] EFUSE <= EFUSE() (unstable)), (@ peri_type #[doc =
5612 "EXTMEM peripheral singleton"] EXTMEM <= EXTMEM() (unstable)), (@ peri_type #[doc
5613 = "MMU_TABLE peripheral singleton"] MMU_TABLE <= MMU_TABLE() (unstable)), (@
5614 peri_type #[doc = "FE peripheral singleton"] FE <= FE() (unstable)), (@ peri_type
5615 #[doc = "FE2 peripheral singleton"] FE2 <= FE2() (unstable)), (@ peri_type #[doc
5616 = "GPIO peripheral singleton"] GPIO <= GPIO() (unstable)), (@ peri_type #[doc =
5617 "GPIO_SD peripheral singleton"] GPIO_SD <= GPIO_SD() (unstable)), (@ peri_type
5618 #[doc = "HMAC peripheral singleton"] HMAC <= HMAC() (unstable)), (@ peri_type
5619 #[doc = "I2C_ANA_MST peripheral singleton"] I2C_ANA_MST <= I2C_ANA_MST()
5620 (unstable)), (@ peri_type #[doc = "I2C0 peripheral singleton"] I2C0 <=
5621 I2C0(I2C_EXT0 : { bind_peri_interrupt, enable_peri_interrupt,
5622 disable_peri_interrupt })), (@ peri_type #[doc = "I2S0 peripheral singleton"]
5623 I2S0 <= I2S0(I2S0 : { bind_peri_interrupt, enable_peri_interrupt,
5624 disable_peri_interrupt }) (unstable)), (@ peri_type #[doc =
5625 "INTERRUPT_CORE0 peripheral singleton"] INTERRUPT_CORE0 <= INTERRUPT_CORE0()
5626 (unstable)), (@ peri_type #[doc = "IO_MUX peripheral singleton"] IO_MUX <=
5627 IO_MUX() (unstable)), (@ peri_type #[doc = "LEDC peripheral singleton"] LEDC <=
5628 LEDC() (unstable)), (@ peri_type #[doc = "NRX peripheral singleton"] NRX <= NRX()
5629 (unstable)), (@ peri_type #[doc = "RMT peripheral singleton"] RMT <= RMT()
5630 (unstable)), (@ peri_type #[doc = "RNG peripheral singleton"] RNG <= RNG()
5631 (unstable)), (@ peri_type #[doc = "RSA peripheral singleton"] RSA <= RSA(RSA : {
5632 bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })
5633 (unstable)), (@ peri_type #[doc = "LPWR peripheral singleton"] LPWR <= RTC_CNTL()
5634 (unstable)), (@ peri_type #[doc = "RTC_TIMER peripheral singleton"] RTC_TIMER <=
5635 RTC_CNTL() (unstable)), (@ peri_type #[doc = "SENSITIVE peripheral singleton"]
5636 SENSITIVE <= SENSITIVE() (unstable)), (@ peri_type #[doc =
5637 "SHA peripheral singleton"] SHA <= SHA(SHA : { bind_peri_interrupt,
5638 enable_peri_interrupt, disable_peri_interrupt }) (unstable)), (@ peri_type #[doc
5639 = "SPI0 peripheral singleton"] SPI0 <= SPI0() (unstable)), (@ peri_type #[doc =
5640 "SPI1 peripheral singleton"] SPI1 <= SPI1() (unstable)), (@ peri_type #[doc =
5641 "SPI2 peripheral singleton"] SPI2 <= SPI2(SPI2 : { bind_peri_interrupt,
5642 enable_peri_interrupt, disable_peri_interrupt })), (@ peri_type #[doc =
5643 "SYSTEM peripheral singleton"] SYSTEM <= SYSTEM() (unstable)), (@ peri_type #[doc
5644 = "SYSTIMER peripheral singleton"] SYSTIMER <= SYSTIMER() (unstable)), (@
5645 peri_type #[doc = "TIMG0 peripheral singleton"] TIMG0 <= TIMG0() (unstable)), (@
5646 peri_type #[doc = "TIMG1 peripheral singleton"] TIMG1 <= TIMG1() (unstable)), (@
5647 peri_type #[doc = "TWAI0 peripheral singleton"] TWAI0 <= TWAI0() (unstable)), (@
5648 peri_type #[doc = "UART0 peripheral singleton"] UART0 <= UART0(UART0 : {
5649 bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })), (@
5650 peri_type #[doc = "UART1 peripheral singleton"] UART1 <= UART1(UART1 : {
5651 bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })), (@
5652 peri_type #[doc = "UHCI0 peripheral singleton"] UHCI0 <= UHCI0() (unstable)), (@
5653 peri_type #[doc = "USB_DEVICE peripheral singleton"] USB_DEVICE <=
5654 USB_DEVICE(USB_DEVICE : { bind_peri_interrupt, enable_peri_interrupt,
5655 disable_peri_interrupt }) (unstable)), (@ peri_type #[doc =
5656 "XTS_AES peripheral singleton"] XTS_AES <= XTS_AES() (unstable)), (@ peri_type
5657 #[doc = "ADC1 peripheral singleton"] ADC1 <= virtual() (unstable)), (@ peri_type
5658 #[doc = "BT peripheral singleton"] BT <= virtual(BT_BB : { bind_bb_interrupt,
5659 enable_bb_interrupt, disable_bb_interrupt }, RWBLE : { bind_rwble_interrupt,
5660 enable_rwble_interrupt, disable_rwble_interrupt }, RWBT : { bind_rwbt_interrupt,
5661 enable_rwbt_interrupt, disable_rwbt_interrupt }) (unstable)), (@ peri_type #[doc
5662 = "FLASH peripheral singleton"] FLASH <= virtual() (unstable)), (@ peri_type
5663 #[doc = "GPIO_DEDICATED peripheral singleton"] GPIO_DEDICATED <= virtual()
5664 (unstable)), (@ peri_type #[doc = "TSENS peripheral singleton"] TSENS <=
5665 virtual() (unstable)), (@ peri_type #[doc = "WIFI peripheral singleton"] WIFI <=
5666 virtual(WIFI_MAC : { bind_mac_interrupt, enable_mac_interrupt,
5667 disable_mac_interrupt }, WIFI_PWR : { bind_pwr_interrupt, enable_pwr_interrupt,
5668 disable_pwr_interrupt })), (@ peri_type #[doc =
5669 "FROM_CPU_INTR0 peripheral singleton"] FROM_CPU_INTR0 <= virtual() (unstable)),
5670 (@ peri_type #[doc = "FROM_CPU_INTR1 peripheral singleton"] FROM_CPU_INTR1 <=
5671 virtual() (unstable)), (@ peri_type #[doc =
5672 "FROM_CPU_INTR2 peripheral singleton"] FROM_CPU_INTR2 <= virtual() (unstable)),
5673 (@ peri_type #[doc = "FROM_CPU_INTR3 peripheral singleton"] FROM_CPU_INTR3 <=
5674 virtual() (unstable)))); _for_each_inner_peripheral!((singletons(GPIO0), (GPIO1),
5675 (GPIO2), (GPIO3), (GPIO4), (GPIO5), (GPIO6), (GPIO7), (GPIO8), (GPIO9), (GPIO10),
5676 (GPIO11), (GPIO12), (GPIO13), (GPIO14), (GPIO15), (GPIO16), (GPIO17), (GPIO18),
5677 (GPIO19), (GPIO20), (GPIO21), (DMA_CH0(unstable)), (DMA_CH1(unstable)),
5678 (DMA_CH2(unstable)), (SDM_CH0(unstable)), (SDM_CH1(unstable)),
5679 (SDM_CH2(unstable)), (SDM_CH3(unstable)), (AES(unstable)), (APB_CTRL(unstable)),
5680 (APB_SARADC(unstable)), (ASSIST_DEBUG(unstable)), (BB(unstable)),
5681 (DMA(unstable)), (DS(unstable)), (EXTMEM(unstable)), (FE(unstable)),
5682 (FE2(unstable)), (GPIO(unstable)), (GPIO_SD(unstable)), (HMAC(unstable)),
5683 (I2C_ANA_MST(unstable)), (I2C0), (I2S0(unstable)), (INTERRUPT_CORE0(unstable)),
5684 (IO_MUX(unstable)), (LEDC(unstable)), (NRX(unstable)), (RMT(unstable)),
5685 (RNG(unstable)), (RSA(unstable)), (LPWR(unstable)), (RTC_TIMER(unstable)),
5686 (SENSITIVE(unstable)), (SHA(unstable)), (SPI0(unstable)), (SPI1(unstable)),
5687 (SPI2), (SYSTEM(unstable)), (SYSTIMER(unstable)), (TIMG0(unstable)),
5688 (TIMG1(unstable)), (TWAI0(unstable)), (UART0), (UART1), (UHCI0(unstable)),
5689 (USB_DEVICE(unstable)), (XTS_AES(unstable)), (ADC1(unstable)), (BT(unstable)),
5690 (FLASH(unstable)), (GPIO_DEDICATED(unstable)), (TSENS(unstable)), (WIFI),
5691 (FROM_CPU_INTR1(unstable)), (FROM_CPU_INTR2(unstable)),
5692 (FROM_CPU_INTR3(unstable)))); _for_each_inner_peripheral!((dma_eligible(SPI2,
5693 Spi2, 0, AhbGdmaChannel), (UHCI0, Uhci0, 2, AhbGdmaChannel), (I2S0, I2s0, 3,
5694 AhbGdmaChannel), (AES, Aes, 6, AhbGdmaChannel), (SHA, Sha, 7, AhbGdmaChannel),
5695 (APB_SARADC, ApbSaradc, 8, AhbGdmaChannel)));
5696 };
5697}
5698#[macro_export]
5725#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5726macro_rules! for_each_gpio {
5727 ($($pattern:tt => $code:tt;)*) => {
5728 macro_rules! _for_each_inner_gpio { $(($pattern) => $code;)* ($other : tt) => {}
5729 } _for_each_inner_gpio!((0, GPIO0() () ([Input] [Output])));
5730 _for_each_inner_gpio!((1, GPIO1() () ([Input] [Output])));
5731 _for_each_inner_gpio!((2, GPIO2(_2 => FSPIQ) (_2 => FSPIQ) ([Input] [Output])));
5732 _for_each_inner_gpio!((3, GPIO3() () ([Input] [Output])));
5733 _for_each_inner_gpio!((4, GPIO4(_0 => MTMS _2 => FSPIHD) (_2 => FSPIHD) ([Input]
5734 [Output]))); _for_each_inner_gpio!((5, GPIO5(_0 => MTDI _2 => FSPIWP) (_2 =>
5735 FSPIWP) ([Input] [Output]))); _for_each_inner_gpio!((6, GPIO6(_0 => MTCK _2 =>
5736 FSPICLK) (_2 => FSPICLK) ([Input] [Output]))); _for_each_inner_gpio!((7, GPIO7(_2
5737 => FSPID) (_0 => MTDO _2 => FSPID) ([Input] [Output])));
5738 _for_each_inner_gpio!((8, GPIO8() () ([Input] [Output])));
5739 _for_each_inner_gpio!((9, GPIO9() () ([Input] [Output])));
5740 _for_each_inner_gpio!((10, GPIO10(_2 => FSPICS0) (_2 => FSPICS0) ([Input]
5741 [Output]))); _for_each_inner_gpio!((11, GPIO11() () ([Input] [Output])));
5742 _for_each_inner_gpio!((12, GPIO12(_0 => SPIHD) (_0 => SPIHD) ([Input]
5743 [Output]))); _for_each_inner_gpio!((13, GPIO13(_0 => SPIWP) (_0 => SPIWP)
5744 ([Input] [Output]))); _for_each_inner_gpio!((14, GPIO14() (_0 => SPICS0) ([Input]
5745 [Output]))); _for_each_inner_gpio!((15, GPIO15() (_0 => SPICLK) ([Input]
5746 [Output]))); _for_each_inner_gpio!((16, GPIO16(_0 => SPID) (_0 => SPID) ([Input]
5747 [Output]))); _for_each_inner_gpio!((17, GPIO17(_0 => SPIQ) (_0 => SPIQ) ([Input]
5748 [Output]))); _for_each_inner_gpio!((18, GPIO18() () ([Input] [Output])));
5749 _for_each_inner_gpio!((19, GPIO19() () ([Input] [Output])));
5750 _for_each_inner_gpio!((20, GPIO20(_0 => U0RXD) () ([Input] [Output])));
5751 _for_each_inner_gpio!((21, GPIO21() (_0 => U0TXD) ([Input] [Output])));
5752 _for_each_inner_gpio!((all(0, GPIO0() () ([Input] [Output])), (1, GPIO1() ()
5753 ([Input] [Output])), (2, GPIO2(_2 => FSPIQ) (_2 => FSPIQ) ([Input] [Output])),
5754 (3, GPIO3() () ([Input] [Output])), (4, GPIO4(_0 => MTMS _2 => FSPIHD) (_2 =>
5755 FSPIHD) ([Input] [Output])), (5, GPIO5(_0 => MTDI _2 => FSPIWP) (_2 => FSPIWP)
5756 ([Input] [Output])), (6, GPIO6(_0 => MTCK _2 => FSPICLK) (_2 => FSPICLK) ([Input]
5757 [Output])), (7, GPIO7(_2 => FSPID) (_0 => MTDO _2 => FSPID) ([Input] [Output])),
5758 (8, GPIO8() () ([Input] [Output])), (9, GPIO9() () ([Input] [Output])), (10,
5759 GPIO10(_2 => FSPICS0) (_2 => FSPICS0) ([Input] [Output])), (11, GPIO11() ()
5760 ([Input] [Output])), (12, GPIO12(_0 => SPIHD) (_0 => SPIHD) ([Input] [Output])),
5761 (13, GPIO13(_0 => SPIWP) (_0 => SPIWP) ([Input] [Output])), (14, GPIO14() (_0 =>
5762 SPICS0) ([Input] [Output])), (15, GPIO15() (_0 => SPICLK) ([Input] [Output])),
5763 (16, GPIO16(_0 => SPID) (_0 => SPID) ([Input] [Output])), (17, GPIO17(_0 => SPIQ)
5764 (_0 => SPIQ) ([Input] [Output])), (18, GPIO18() () ([Input] [Output])), (19,
5765 GPIO19() () ([Input] [Output])), (20, GPIO20(_0 => U0RXD) () ([Input] [Output])),
5766 (21, GPIO21() (_0 => U0TXD) ([Input] [Output]))));
5767 };
5768}
5769#[macro_export]
5796#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5797macro_rules! for_each_analog_function {
5798 ($($pattern:tt => $code:tt;)*) => {
5799 macro_rules! _for_each_inner_analog_function { $(($pattern) => $code;)* ($other :
5800 tt) => {} } _for_each_inner_analog_function!((ADC1_CH0, GPIO0));
5801 _for_each_inner_analog_function!((ADC1_CH1, GPIO1));
5802 _for_each_inner_analog_function!((ADC1_CH2, GPIO2));
5803 _for_each_inner_analog_function!((ADC1_CH3, GPIO3));
5804 _for_each_inner_analog_function!((ADC1_CH4, GPIO4));
5805 _for_each_inner_analog_function!((USJ_DM, GPIO18));
5806 _for_each_inner_analog_function!((USJ_DP, GPIO19));
5807 _for_each_inner_analog_function!(((ADC1_CH0, ADCn_CHm, 1, 0), GPIO0));
5808 _for_each_inner_analog_function!(((ADC1_CH1, ADCn_CHm, 1, 1), GPIO1));
5809 _for_each_inner_analog_function!(((ADC1_CH2, ADCn_CHm, 1, 2), GPIO2));
5810 _for_each_inner_analog_function!(((ADC1_CH3, ADCn_CHm, 1, 3), GPIO3));
5811 _for_each_inner_analog_function!(((ADC1_CH4, ADCn_CHm, 1, 4), GPIO4));
5812 _for_each_inner_analog_function!((all(ADC1_CH0, GPIO0), (ADC1_CH1, GPIO1),
5813 (ADC1_CH2, GPIO2), (ADC1_CH3, GPIO3), (ADC1_CH4, GPIO4), (USJ_DM, GPIO18),
5814 (USJ_DP, GPIO19))); _for_each_inner_analog_function!((ADCn_CHm((ADC1_CH0,
5815 ADCn_CHm, 1, 0), GPIO0), ((ADC1_CH1, ADCn_CHm, 1, 1), GPIO1), ((ADC1_CH2,
5816 ADCn_CHm, 1, 2), GPIO2), ((ADC1_CH3, ADCn_CHm, 1, 3), GPIO3), ((ADC1_CH4,
5817 ADCn_CHm, 1, 4), GPIO4)));
5818 };
5819}
5820#[macro_export]
5858#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5859macro_rules! for_each_lp_function {
5860 ($($pattern:tt => $code:tt;)*) => {
5861 macro_rules! _for_each_inner_lp_function { $(($pattern) => $code;)* ($other : tt)
5862 => {} } _for_each_inner_lp_function!((LP_GPIO0, GPIO0, _0));
5863 _for_each_inner_lp_function!((LP_GPIO1, GPIO1, _0));
5864 _for_each_inner_lp_function!((LP_GPIO2, GPIO2, _0));
5865 _for_each_inner_lp_function!((LP_GPIO3, GPIO3, _0));
5866 _for_each_inner_lp_function!((LP_GPIO4, GPIO4, _0));
5867 _for_each_inner_lp_function!((LP_GPIO5, GPIO5, _0));
5868 _for_each_inner_lp_function!(((LP_GPIO0, LP_GPIOn, 0), GPIO0, _0, () ()));
5869 _for_each_inner_lp_function!(((LP_GPIO1, LP_GPIOn, 1), GPIO1, _0, () ()));
5870 _for_each_inner_lp_function!(((LP_GPIO2, LP_GPIOn, 2), GPIO2, _0, () ()));
5871 _for_each_inner_lp_function!(((LP_GPIO3, LP_GPIOn, 3), GPIO3, _0, () ()));
5872 _for_each_inner_lp_function!(((LP_GPIO4, LP_GPIOn, 4), GPIO4, _0, () ()));
5873 _for_each_inner_lp_function!(((LP_GPIO5, LP_GPIOn, 5), GPIO5, _0, () ()));
5874 _for_each_inner_lp_function!((all(LP_GPIO0, GPIO0, _0), (LP_GPIO1, GPIO1, _0),
5875 (LP_GPIO2, GPIO2, _0), (LP_GPIO3, GPIO3, _0), (LP_GPIO4, GPIO4, _0), (LP_GPIO5,
5876 GPIO5, _0))); _for_each_inner_lp_function!((LP_GPIOn((LP_GPIO0, LP_GPIOn, 0),
5877 GPIO0, _0, () ()), ((LP_GPIO1, LP_GPIOn, 1), GPIO1, _0, () ()), ((LP_GPIO2,
5878 LP_GPIOn, 2), GPIO2, _0, () ()), ((LP_GPIO3, LP_GPIOn, 3), GPIO3, _0, () ()),
5879 ((LP_GPIO4, LP_GPIOn, 4), GPIO4, _0, () ()), ((LP_GPIO5, LP_GPIOn, 5), GPIO5, _0,
5880 () ())));
5881 };
5882}
5883#[macro_export]
5914#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5915macro_rules! for_each_iomux_function {
5916 ($($pattern:tt => $code:tt;)*) => {
5917 macro_rules! _for_each_inner_iomux_function { $(($pattern) => $code;)* ($other :
5918 tt) => {} } _for_each_inner_iomux_function!((FSPIQ, GPIO2, _2));
5919 _for_each_inner_iomux_function!((MTMS, GPIO4, _0));
5920 _for_each_inner_iomux_function!((FSPIHD, GPIO4, _2));
5921 _for_each_inner_iomux_function!((MTDI, GPIO5, _0));
5922 _for_each_inner_iomux_function!((FSPIWP, GPIO5, _2));
5923 _for_each_inner_iomux_function!((MTCK, GPIO6, _0));
5924 _for_each_inner_iomux_function!((FSPICLK, GPIO6, _2));
5925 _for_each_inner_iomux_function!((MTDO, GPIO7, _0));
5926 _for_each_inner_iomux_function!((FSPID, GPIO7, _2));
5927 _for_each_inner_iomux_function!((FSPICS0, GPIO10, _2));
5928 _for_each_inner_iomux_function!((SPIHD, GPIO12, _0));
5929 _for_each_inner_iomux_function!((SPIWP, GPIO13, _0));
5930 _for_each_inner_iomux_function!((SPICS0, GPIO14, _0));
5931 _for_each_inner_iomux_function!((SPICLK, GPIO15, _0));
5932 _for_each_inner_iomux_function!((SPID, GPIO16, _0));
5933 _for_each_inner_iomux_function!((SPIQ, GPIO17, _0));
5934 _for_each_inner_iomux_function!((U0RXD, GPIO20, _0));
5935 _for_each_inner_iomux_function!((U0TXD, GPIO21, _0));
5936 _for_each_inner_iomux_function!(((FSPICS0, FSPICSn, 0), GPIO10, _2));
5937 _for_each_inner_iomux_function!(((SPICS0, SPICSn, 0), GPIO14, _0));
5938 _for_each_inner_iomux_function!((all(FSPIQ, GPIO2, _2), (MTMS, GPIO4, _0),
5939 (FSPIHD, GPIO4, _2), (MTDI, GPIO5, _0), (FSPIWP, GPIO5, _2), (MTCK, GPIO6, _0),
5940 (FSPICLK, GPIO6, _2), (MTDO, GPIO7, _0), (FSPID, GPIO7, _2), (FSPICS0, GPIO10,
5941 _2), (SPIHD, GPIO12, _0), (SPIWP, GPIO13, _0), (SPICS0, GPIO14, _0), (SPICLK,
5942 GPIO15, _0), (SPID, GPIO16, _0), (SPIQ, GPIO17, _0), (U0RXD, GPIO20, _0), (U0TXD,
5943 GPIO21, _0))); _for_each_inner_iomux_function!((FSPICSn((FSPICS0, FSPICSn, 0),
5944 GPIO10, _2))); _for_each_inner_iomux_function!((SPICSn((SPICS0, SPICSn, 0),
5945 GPIO14, _0)));
5946 };
5947}
5948#[macro_export]
5965#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5966macro_rules! gpio_for_signal {
5967 (ADC1_CH0 $(, $_fallback:literal)?) => {
5968 "GPIO0"
5969 };
5970 (LP_GPIO0 $(, $_fallback:literal)?) => {
5971 "GPIO0"
5972 };
5973 (ADC1_CH1 $(, $_fallback:literal)?) => {
5974 "GPIO1"
5975 };
5976 (LP_GPIO1 $(, $_fallback:literal)?) => {
5977 "GPIO1"
5978 };
5979 (FSPIQ $(, $_fallback:literal)?) => {
5980 "GPIO2"
5981 };
5982 (ADC1_CH2 $(, $_fallback:literal)?) => {
5983 "GPIO2"
5984 };
5985 (LP_GPIO2 $(, $_fallback:literal)?) => {
5986 "GPIO2"
5987 };
5988 (ADC1_CH3 $(, $_fallback:literal)?) => {
5989 "GPIO3"
5990 };
5991 (LP_GPIO3 $(, $_fallback:literal)?) => {
5992 "GPIO3"
5993 };
5994 (MTMS $(, $_fallback:literal)?) => {
5995 "GPIO4"
5996 };
5997 (FSPIHD $(, $_fallback:literal)?) => {
5998 "GPIO4"
5999 };
6000 (ADC1_CH4 $(, $_fallback:literal)?) => {
6001 "GPIO4"
6002 };
6003 (LP_GPIO4 $(, $_fallback:literal)?) => {
6004 "GPIO4"
6005 };
6006 (MTDI $(, $_fallback:literal)?) => {
6007 "GPIO5"
6008 };
6009 (FSPIWP $(, $_fallback:literal)?) => {
6010 "GPIO5"
6011 };
6012 (LP_GPIO5 $(, $_fallback:literal)?) => {
6013 "GPIO5"
6014 };
6015 (MTCK $(, $_fallback:literal)?) => {
6016 "GPIO6"
6017 };
6018 (FSPICLK $(, $_fallback:literal)?) => {
6019 "GPIO6"
6020 };
6021 (MTDO $(, $_fallback:literal)?) => {
6022 "GPIO7"
6023 };
6024 (FSPID $(, $_fallback:literal)?) => {
6025 "GPIO7"
6026 };
6027 (FSPICS0 $(, $_fallback:literal)?) => {
6028 "GPIO10"
6029 };
6030 (SPIHD $(, $_fallback:literal)?) => {
6031 "GPIO12"
6032 };
6033 (SPIWP $(, $_fallback:literal)?) => {
6034 "GPIO13"
6035 };
6036 (SPICS0 $(, $_fallback:literal)?) => {
6037 "GPIO14"
6038 };
6039 (SPICLK $(, $_fallback:literal)?) => {
6040 "GPIO15"
6041 };
6042 (SPID $(, $_fallback:literal)?) => {
6043 "GPIO16"
6044 };
6045 (SPIQ $(, $_fallback:literal)?) => {
6046 "GPIO17"
6047 };
6048 (USJ_DM $(, $_fallback:literal)?) => {
6049 "GPIO18"
6050 };
6051 (USJ_DP $(, $_fallback:literal)?) => {
6052 "GPIO19"
6053 };
6054 (U0RXD $(, $_fallback:literal)?) => {
6055 "GPIO20"
6056 };
6057 (U0TXD $(, $_fallback:literal)?) => {
6058 "GPIO21"
6059 };
6060 ($_signal:ident, $fallback:literal) => {
6061 $fallback
6062 };
6063}
6064#[macro_export]
6068#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
6069macro_rules! define_io_mux_signals {
6070 () => {
6071 #[allow(non_camel_case_types, clippy::upper_case_acronyms)]
6072 #[derive(Debug, PartialEq, Copy, Clone)]
6073 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
6074 #[doc(hidden)]
6075 pub enum InputSignal {
6076 SPIQ = 0,
6077 SPID = 1,
6078 SPIHD = 2,
6079 SPIWP = 3,
6080 U0RXD = 6,
6081 U0CTS = 7,
6082 U0DSR = 8,
6083 U1RXD = 9,
6084 U1CTS = 10,
6085 U1DSR = 11,
6086 I2S_MCLK = 12,
6087 I2SO_BCK = 13,
6088 I2SO_WS = 14,
6089 I2SI_SD = 15,
6090 I2SI_BCK = 16,
6091 I2SI_WS = 17,
6092 GPIO_BT_PRIORITY = 18,
6093 GPIO_BT_ACTIVE = 19,
6094 CPU_GPIO_0 = 28,
6095 CPU_GPIO_1 = 29,
6096 CPU_GPIO_2 = 30,
6097 CPU_GPIO_3 = 31,
6098 CPU_GPIO_4 = 32,
6099 CPU_GPIO_5 = 33,
6100 CPU_GPIO_6 = 34,
6101 CPU_GPIO_7 = 35,
6102 EXT_ADC_START = 45,
6103 RMT_SIG_0 = 51,
6104 RMT_SIG_1 = 52,
6105 I2CEXT0_SCL = 53,
6106 I2CEXT0_SDA = 54,
6107 FSPICLK = 63,
6108 FSPIQ = 64,
6109 FSPID = 65,
6110 FSPIHD = 66,
6111 FSPIWP = 67,
6112 FSPICS0 = 68,
6113 TWAI_RX = 74,
6114 SIG_FUNC_97 = 97,
6115 SIG_FUNC_98 = 98,
6116 SIG_FUNC_99 = 99,
6117 SIG_FUNC_100 = 100,
6118 MTCK,
6119 MTMS,
6120 MTDI,
6121 }
6122 #[allow(non_camel_case_types, clippy::upper_case_acronyms)]
6123 #[derive(Debug, PartialEq, Copy, Clone)]
6124 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
6125 #[doc(hidden)]
6126 pub enum OutputSignal {
6127 SPIQ = 0,
6128 SPID = 1,
6129 SPIHD = 2,
6130 SPIWP = 3,
6131 SPICLK = 4,
6132 SPICS0 = 5,
6133 U0TXD = 6,
6134 U0RTS = 7,
6135 U0DTR = 8,
6136 U1TXD = 9,
6137 U1RTS = 10,
6138 U1DTR = 11,
6139 I2S_MCLK = 12,
6140 I2SO_BCK = 13,
6141 I2SO_WS = 14,
6142 I2SO_SD = 15,
6143 I2SI_BCK = 16,
6144 I2SI_WS = 17,
6145 GPIO_WLAN_PRIO = 18,
6146 GPIO_WLAN_ACTIVE = 19,
6147 CPU_GPIO_0 = 28,
6148 CPU_GPIO_1 = 29,
6149 CPU_GPIO_2 = 30,
6150 CPU_GPIO_3 = 31,
6151 CPU_GPIO_4 = 32,
6152 CPU_GPIO_5 = 33,
6153 CPU_GPIO_6 = 34,
6154 CPU_GPIO_7 = 35,
6155 USB_JTAG_TCK = 36,
6156 USB_JTAG_TMS = 37,
6157 USB_JTAG_TDI = 38,
6158 USB_JTAG_TDO = 39,
6159 LEDC_LS_SIG0 = 45,
6160 LEDC_LS_SIG1 = 46,
6161 LEDC_LS_SIG2 = 47,
6162 LEDC_LS_SIG3 = 48,
6163 LEDC_LS_SIG4 = 49,
6164 LEDC_LS_SIG5 = 50,
6165 RMT_SIG_0 = 51,
6166 RMT_SIG_1 = 52,
6167 I2CEXT0_SCL = 53,
6168 I2CEXT0_SDA = 54,
6169 GPIO_SD0 = 55,
6170 GPIO_SD1 = 56,
6171 GPIO_SD2 = 57,
6172 GPIO_SD3 = 58,
6173 I2SO_SD1 = 59,
6174 FSPICLK = 63,
6175 FSPIQ = 64,
6176 FSPID = 65,
6177 FSPIHD = 66,
6178 FSPIWP = 67,
6179 FSPICS0 = 68,
6180 FSPICS1 = 69,
6181 FSPICS3 = 70,
6182 FSPICS2 = 71,
6183 FSPICS4 = 72,
6184 FSPICS5 = 73,
6185 TWAI_TX = 74,
6186 TWAI_BUS_OFF_ON = 75,
6187 TWAI_CLKOUT = 76,
6188 ANT_SEL0 = 89,
6189 ANT_SEL1 = 90,
6190 ANT_SEL2 = 91,
6191 ANT_SEL3 = 92,
6192 ANT_SEL4 = 93,
6193 ANT_SEL5 = 94,
6194 ANT_SEL6 = 95,
6195 ANT_SEL7 = 96,
6196 SIG_FUNC_97 = 97,
6197 SIG_FUNC_98 = 98,
6198 SIG_FUNC_99 = 99,
6199 SIG_FUNC_100 = 100,
6200 CLK_OUT1 = 123,
6201 CLK_OUT2 = 124,
6202 CLK_OUT3 = 125,
6203 SPICS1 = 126,
6204 USB_JTAG_TRST = 127,
6205 GPIO = 128,
6206 MTDO,
6207 }
6208 };
6209}
6210#[macro_export]
6217#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
6218macro_rules! define_lp_functions {
6219 () => {
6220 #[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
6225 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
6226 #[doc(hidden)]
6227 pub enum LpFunction {
6228 _0 = 0,
6230 }
6231 impl LpFunction {
6232 pub const LP_GPIO: Self = Self::_0;
6234 }
6235 };
6236}
6237#[macro_export]
6250#[expect(clippy::crate_in_macro_def)]
6251#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
6252macro_rules! define_io_mux_reg {
6253 () => {
6254 pub(crate) fn io_mux_reg(gpio_num: u8) -> &'static crate::pac::io_mux::GPIO {
6255 crate::peripherals::IO_MUX::regs().gpio(gpio_num as usize)
6256 }
6257 };
6258}