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 "esp32c2"
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-C2"
34 };
35}
36#[macro_export]
38#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
39macro_rules! property {
40 ("chip") => {
41 "esp32c2"
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/esp8684_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 ("i2c_master.version") => {
149 3
150 };
151 ("i2c_master.version", str) => {
152 stringify!(3)
153 };
154 ("i2c_master.has_fsm_timeouts") => {
155 true
156 };
157 ("i2c_master.has_hw_bus_clear") => {
158 true
159 };
160 ("i2c_master.has_bus_timeout_enable") => {
161 true
162 };
163 ("i2c_master.separate_filter_config_registers") => {
164 false
165 };
166 ("i2c_master.can_estimate_nack_reason") => {
167 false
168 };
169 ("i2c_master.has_conf_update") => {
170 true
171 };
172 ("i2c_master.has_reliable_fsm_reset") => {
173 false
174 };
175 ("i2c_master.has_arbitration_en") => {
176 true
177 };
178 ("i2c_master.has_tx_fifo_watermark") => {
179 true
180 };
181 ("i2c_master.bus_timeout_is_exponential") => {
182 true
183 };
184 ("i2c_master.has_pd_en") => {
185 true
186 };
187 ("i2c_master.max_bus_timeout") => {
188 31
189 };
190 ("i2c_master.max_bus_timeout", str) => {
191 stringify!(31)
192 };
193 ("i2c_master.ll_intr_mask") => {
194 262143
195 };
196 ("i2c_master.ll_intr_mask", str) => {
197 stringify!(262143)
198 };
199 ("i2c_master.fifo_size") => {
200 16
201 };
202 ("i2c_master.fifo_size", str) => {
203 stringify!(16)
204 };
205 ("spi_master.version") => {
206 3
207 };
208 ("spi_master.version", str) => {
209 stringify!(3)
210 };
211 ("spi_master.fifo_size") => {
212 64
213 };
214 ("spi_master.fifo_size", str) => {
215 stringify!(64)
216 };
217 ("spi_master.bit_order_is_bool") => {
218 false
219 };
220 ("spi_master.has_octal") => {
221 false
222 };
223 ("spi_master.has_app_interrupts") => {
224 true
225 };
226 ("spi_master.has_dma_segmented_transfer") => {
227 true
228 };
229 ("spi_master.has_clk_pre_div") => {
230 false
231 };
232 ("spi_master.dma_can_access_flash") => {
233 false
234 };
235 ("bt.controller") => {
236 "npl"
237 };
238 ("bt.requires_fast_cpu") => {
239 false
240 };
241 ("bt.bredr") => {
242 false
243 };
244 ("wifi.has_wifi6") => {
245 false
246 };
247 ("wifi.mac_version") => {
248 1
249 };
250 ("wifi.mac_version", str) => {
251 stringify!(1)
252 };
253 ("wifi.has_5g") => {
254 false
255 };
256 ("wifi.csi_supported") => {
257 false
258 };
259 ("wifi.has_nan") => {
260 false
261 };
262 ("wifi.has_ftm") => {
263 true
264 };
265 ("wifi.requires_fast_cpu") => {
266 false
267 };
268 ("phy.combo_module") => {
269 true
270 };
271 ("phy.hw_freq_hop") => {
272 true
273 };
274 ("adc.controller") => {
275 "digital"
276 };
277 ("adc.channel_count") => {
278 5
279 };
280 ("adc.channel_count", str) => {
281 stringify!(5)
282 };
283 ("adc.line_calibration") => {
284 true
285 };
286 ("adc.curve_calibration") => {
287 false
288 };
289 ("adc.basic_calibration") => {
290 true
291 };
292 ("adc.calibration_v1_scheme_supported") => {
293 true
294 };
295 ("adc.channel_compensation") => {
296 false
297 };
298 ("adc.pcr_clock") => {
299 false
300 };
301 ("adc.pcr_sar_clk_div") => {
302 false
303 };
304 ("adc.sar_power_override") => {
305 false
306 };
307 ("temp_sensor.min_stabilization_time_us") => {
308 0
309 };
310 ("temp_sensor.min_stabilization_time_us", str) => {
311 stringify!(0)
312 };
313 ("ledc.version") => {
314 2
315 };
316 ("ledc.version", str) => {
317 stringify!(2)
318 };
319 ("ledc.channel_count") => {
320 6
321 };
322 ("ledc.channel_count", str) => {
323 stringify!(6)
324 };
325 ("timergroup.timg_has_timer1") => {
326 false
327 };
328 ("timergroup.timg_has_divcnt_rst") => {
329 true
330 };
331 ("timergroup.wdt_has_conf_update") => {
332 true
333 };
334 ("ecc.zero_extend_writes") => {
335 true
336 };
337 ("ecc.separate_jacobian_point_memory") => {
338 false
339 };
340 ("ecc.has_memory_clock_gate") => {
341 false
342 };
343 ("ecc.supports_enhanced_security") => {
344 false
345 };
346 ("ecc.mem_block_size") => {
347 32
348 };
349 ("rng.apb_cycle_wait_num") => {
350 16
351 };
352 ("rng.apb_cycle_wait_num", str) => {
353 stringify!(16)
354 };
355 ("rng.trng_supported") => {
356 true
357 };
358 ("rng.is_lp_sys") => {
359 false
360 };
361 ("sleep.light_sleep") => {
362 true
363 };
364 ("sleep.deep_sleep") => {
365 true
366 };
367 ("sleep.rejectable_mask") => {
368 1068
369 };
370 ("sleep.pin_wakeup_version") => {
371 2
372 };
373 ("sleep.pin_wakeup_version", str) => {
374 stringify!(2)
375 };
376 ("sleep.deep_sleep_needs_gpio_isolation") => {
377 true
378 };
379 ("sleep.idle_frequency_scaling") => {
380 false
381 };
382 ("assist_debug.has_sp_monitor") => {
383 true
384 };
385 ("assist_debug.has_region_monitor") => {
386 false
387 };
388 ("dma.mem2mem_requires_peripheral") => {
389 false
390 };
391 ("dma.ext_mem_configurable_block_size") => {
392 false
393 };
394 ("dma.separate_in_out_interrupts") => {
395 false
396 };
397 ("dma.gdma_version") => {
398 1
399 };
400 ("dma.gdma_version", str) => {
401 stringify!(1)
402 };
403 ("interrupts.status_registers") => {
404 2
405 };
406 ("interrupts.status_registers", str) => {
407 stringify!(2)
408 };
409 ("interrupts.disabled_interrupt") => {
410 0
411 };
412 ("mmu.page_size") => {
413 65536
414 };
415 ("mmu.page_size", str) => {
416 stringify!(65536)
417 };
418 ("mmu.entry_num") => {
419 64
420 };
421 ("mmu.entry_num", str) => {
422 stringify!(64)
423 };
424 ("rom.has_crc_le") => {
425 true
426 };
427 ("rom.has_crc_be") => {
428 true
429 };
430 ("rom.has_md5_bsd") => {
431 false
432 };
433 ("rom.has_md5_mbedtls") => {
434 true
435 };
436 ("rom.no_libgcc") => {
437 false
438 };
439 ("soc.cpu_has_branch_predictor") => {
440 false
441 };
442 ("soc.cpu_has_csr_pc") => {
443 true
444 };
445 ("soc.cpu_has_zcmp_workaround") => {
446 false
447 };
448 ("soc.multi_core_enabled") => {
449 false
450 };
451 ("soc.cpu_pma_needs_core1_setup") => {
452 false
453 };
454 ("soc.internal_memory_cached") => {
455 false
456 };
457 ("soc.cpu_powers_down_cache") => {
458 false
459 };
460 ("soc.has_swd_watchdog") => {
461 true
462 };
463 ("soc.has_bus_clock_update") => {
464 false
465 };
466 ("soc.has_apb_frequency_reduction") => {
467 false
468 };
469 ("soc.cpu_mcause_mask") => {
470 31
471 };
472 ("soc.cpu_mcause_mask", str) => {
473 stringify!(31)
474 };
475 ("soc.cpu_pmp_granularity") => {
476 4
477 };
478 ("soc.cpu_pmp_granularity", str) => {
479 stringify!(4)
480 };
481 ("clock_tree.system_pre_div_in") => {
482 [crate ::soc::clocks::SystemPreDivInConfig::Xtal, crate
483 ::soc::clocks::SystemPreDivInConfig::RcFast]
484 };
485 ("clock_tree.system_pre_div.divisor") => {
486 (0, 1023)
487 };
488 ("clock_tree.cpu_pll_div.divisor") => {
489 [4, 6]
490 };
491 ("clock_tree.cpu_clk") => {
492 [crate ::soc::clocks::CpuClkConfig::Xtal, crate
493 ::soc::clocks::CpuClkConfig::RcFast, crate ::soc::clocks::CpuClkConfig::Pll]
494 };
495 ("clock_tree.apb_clk") => {
496 [crate ::soc::clocks::ApbClkConfig::Pll40m, crate
497 ::soc::clocks::ApbClkConfig::Cpu]
498 };
499 ("clock_tree.crypto_clk") => {
500 [crate ::soc::clocks::CryptoClkConfig::Pll80m, crate
501 ::soc::clocks::CryptoClkConfig::Cpu]
502 };
503 ("clock_tree.mspi_clk") => {
504 [crate ::soc::clocks::MspiClkConfig::CpuDiv2, crate
505 ::soc::clocks::MspiClkConfig::Cpu]
506 };
507 ("clock_tree.rc_fast_clk_div_n.divisor") => {
508 (0, 3)
509 };
510 ("clock_tree.rtc_slow_clk") => {
511 [crate ::soc::clocks::RtcSlowClkConfig::OscSlow, crate
512 ::soc::clocks::RtcSlowClkConfig::RcSlow, crate
513 ::soc::clocks::RtcSlowClkConfig::RcFast]
514 };
515 ("clock_tree.ble_lp_clk.sclk") => {
516 [crate ::soc::clocks::BleLpClkSclk::Xtal, crate
517 ::soc::clocks::BleLpClkSclk::RcSlow]
518 };
519 ("clock_tree.ble_lp_clk.divisor") => {
520 (0, 255)
521 };
522 ("clock_tree.rtc_fast_clk") => {
523 [crate ::soc::clocks::RtcFastClkConfig::Xtal, crate
524 ::soc::clocks::RtcFastClkConfig::Rc]
525 };
526 ("clock_tree.low_power_clk") => {
527 [crate ::soc::clocks::LowPowerClkConfig::Xtal, crate
528 ::soc::clocks::LowPowerClkConfig::RcFast, crate
529 ::soc::clocks::LowPowerClkConfig::OscSlow, crate
530 ::soc::clocks::LowPowerClkConfig::RtcSlow]
531 };
532 ("clock_tree.timg_calibration_clock") => {
533 [crate ::soc::clocks::TimgCalibrationClockConfig::RcSlowClk, crate
534 ::soc::clocks::TimgCalibrationClockConfig::RcFastDivClk, crate
535 ::soc::clocks::TimgCalibrationClockConfig::Osc32kClk]
536 };
537 ("clock_tree.tsens.sclk") => {
538 [crate ::soc::clocks::TsensSclkConfig::RcFast, crate
539 ::soc::clocks::TsensSclkConfig::Xtal]
540 };
541 ("clock_tree.timg.function_clock") => {
542 [crate ::soc::clocks::TimgFunctionClockConfig::XtalClk, crate
543 ::soc::clocks::TimgFunctionClockConfig::Pll40m]
544 };
545 ("clock_tree.timg.wdt_clock") => {
546 [crate ::soc::clocks::TimgWdtClockConfig::Pll40m, crate
547 ::soc::clocks::TimgWdtClockConfig::XtalClk]
548 };
549 ("clock_tree.uart.function_clock.sclk") => {
550 [crate ::soc::clocks::UartFunctionClockSclk::PllF40m, crate
551 ::soc::clocks::UartFunctionClockSclk::RcFast, crate
552 ::soc::clocks::UartFunctionClockSclk::Xtal]
553 };
554 ("clock_tree.uart.function_clock.div_num") => {
555 (0, 255)
556 };
557 ("clock_tree.uart.baud_rate_generator.fractional") => {
558 (0, 15)
559 };
560 ("clock_tree.uart.baud_rate_generator.integral") => {
561 (0, 4095)
562 };
563 ("clock_tree.i2c.function_clock.sclk") => {
564 [crate ::soc::clocks::I2cFunctionClockSclk::Xtal, crate
565 ::soc::clocks::I2cFunctionClockSclk::RcFast]
566 };
567 ("clock_tree.i2c.function_clock.div_num") => {
568 (0, 255)
569 };
570 ("clock_tree.spi.function_clock") => {
571 [crate ::soc::clocks::SpiFunctionClockConfig::Xtal, crate
572 ::soc::clocks::SpiFunctionClockConfig::Pll40m]
573 };
574}
575#[macro_export]
576#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
577macro_rules! for_each_dedicated_gpio {
578 ($($pattern:tt => $code:tt;)*) => {
579 macro_rules! _for_each_inner_dedicated_gpio { $(($pattern) => $code;)* ($other :
580 tt) => {} } _for_each_inner_dedicated_gpio!((0));
581 _for_each_inner_dedicated_gpio!((1)); _for_each_inner_dedicated_gpio!((2));
582 _for_each_inner_dedicated_gpio!((3)); _for_each_inner_dedicated_gpio!((4));
583 _for_each_inner_dedicated_gpio!((5)); _for_each_inner_dedicated_gpio!((6));
584 _for_each_inner_dedicated_gpio!((7)); _for_each_inner_dedicated_gpio!((0, 0,
585 CPU_GPIO_0)); _for_each_inner_dedicated_gpio!((0, 1, CPU_GPIO_1));
586 _for_each_inner_dedicated_gpio!((0, 2, CPU_GPIO_2));
587 _for_each_inner_dedicated_gpio!((0, 3, CPU_GPIO_3));
588 _for_each_inner_dedicated_gpio!((0, 4, CPU_GPIO_4));
589 _for_each_inner_dedicated_gpio!((0, 5, CPU_GPIO_5));
590 _for_each_inner_dedicated_gpio!((0, 6, CPU_GPIO_6));
591 _for_each_inner_dedicated_gpio!((0, 7, CPU_GPIO_7));
592 _for_each_inner_dedicated_gpio!((channels(0), (1), (2), (3), (4), (5), (6),
593 (7))); _for_each_inner_dedicated_gpio!((signals(0, 0, CPU_GPIO_0), (0, 1,
594 CPU_GPIO_1), (0, 2, CPU_GPIO_2), (0, 3, CPU_GPIO_3), (0, 4, CPU_GPIO_4), (0, 5,
595 CPU_GPIO_5), (0, 6, CPU_GPIO_6), (0, 7, CPU_GPIO_7)));
596 };
597}
598#[macro_export]
602#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
603macro_rules! define_lp_io_signals {
604 () => {};
605}
606#[macro_export]
607#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
608macro_rules! for_each_ecc_working_mode {
609 ($($pattern:tt => $code:tt;)*) => {
610 macro_rules! _for_each_inner_ecc_working_mode { $(($pattern) => $code;)* ($other
611 : tt) => {} } _for_each_inner_ecc_working_mode!((0, AffinePointMultiplication));
612 _for_each_inner_ecc_working_mode!((1, FiniteFieldDivision));
613 _for_each_inner_ecc_working_mode!((2, AffinePointVerification));
614 _for_each_inner_ecc_working_mode!((3, AffinePointVerificationAndMultiplication));
615 _for_each_inner_ecc_working_mode!((4, JacobianPointMultiplication));
616 _for_each_inner_ecc_working_mode!((6, JacobianPointVerification));
617 _for_each_inner_ecc_working_mode!((7,
618 AffinePointVerificationAndJacobianPointMultiplication));
619 _for_each_inner_ecc_working_mode!((all(0, AffinePointMultiplication), (1,
620 FiniteFieldDivision), (2, AffinePointVerification), (3,
621 AffinePointVerificationAndMultiplication), (4, JacobianPointMultiplication), (6,
622 JacobianPointVerification), (7,
623 AffinePointVerificationAndJacobianPointMultiplication)));
624 };
625}
626#[macro_export]
627#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
628macro_rules! for_each_ecc_curve {
629 ($($pattern:tt => $code:tt;)*) => {
630 macro_rules! _for_each_inner_ecc_curve { $(($pattern) => $code;)* ($other : tt)
631 => {} } _for_each_inner_ecc_curve!((0, P192, 192));
632 _for_each_inner_ecc_curve!((1, P256, 256)); _for_each_inner_ecc_curve!((all(0,
633 P192, 192), (1, P256, 256)));
634 };
635}
636#[macro_export]
637#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
638macro_rules! for_each_sha_algorithm {
639 ($($pattern:tt => $code:tt;)*) => {
640 macro_rules! _for_each_inner_sha_algorithm { $(($pattern) => $code;)* ($other :
641 tt) => {} } _for_each_inner_sha_algorithm!((Sha1, "SHA-1"(sizes : 64, 20, 8)
642 (insecure_against : "collision", "length extension"), 0));
643 _for_each_inner_sha_algorithm!((Sha224, "SHA-224"(sizes : 64, 28, 8)
644 (insecure_against : "length extension"), 1));
645 _for_each_inner_sha_algorithm!((Sha256, "SHA-256"(sizes : 64, 32, 8)
646 (insecure_against : "length extension"), 2));
647 _for_each_inner_sha_algorithm!((algos(Sha1, "SHA-1"(sizes : 64, 20, 8)
648 (insecure_against : "collision", "length extension"), 0), (Sha224,
649 "SHA-224"(sizes : 64, 28, 8) (insecure_against : "length extension"), 1),
650 (Sha256, "SHA-256"(sizes : 64, 32, 8) (insecure_against : "length extension"),
651 2)));
652 };
653}
654#[macro_export]
655#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
656macro_rules! for_each_wakeup_source {
657 ($($pattern:tt => $code:tt;)*) => {
658 macro_rules! _for_each_inner_wakeup_source { $(($pattern) => $code;)* ($other :
659 tt) => {} } _for_each_inner_wakeup_source!((Gpio, 2));
660 _for_each_inner_wakeup_source!((Timer, 3)); _for_each_inner_wakeup_source!((Wifi,
661 5)); _for_each_inner_wakeup_source!((Uart0, 6));
662 _for_each_inner_wakeup_source!((Uart1, 7)); _for_each_inner_wakeup_source!((Bt,
663 10)); _for_each_inner_wakeup_source!((all(Gpio, 2), (Timer, 3), (Wifi, 5),
664 (Uart0, 6), (Uart1, 7), (Bt, 10)));
665 };
666}
667#[macro_export]
668#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
669macro_rules! for_each_dma_engine {
670 ($($pattern:tt => $code:tt;)*) => {
671 macro_rules! _for_each_inner_dma_engine { $(($pattern) => $code;)* ($other : tt)
672 => {} } _for_each_inner_dma_engine!(("AHB_GDMA"));
673 _for_each_inner_dma_engine!(("AHB_GDMA", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9));
674 _for_each_inner_dma_engine!(("AHB_GDMA", internal = [Disabled, Enabled], external
675 = [], external_default = Size32));
676 _for_each_inner_dma_engine!((all("AHB_GDMA")));
677 _for_each_inner_dma_engine!((priority("AHB_GDMA", 0, 1, 2, 3, 4, 5, 6, 7, 8,
678 9))); _for_each_inner_dma_engine!((burst("AHB_GDMA", internal = [Disabled,
679 Enabled], external = [], external_default = Size32)));
680 };
681}
682#[macro_export]
683#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
684macro_rules! for_each_dma_channel {
685 ($($pattern:tt => $code:tt;)*) => {
686 macro_rules! _for_each_inner_dma_channel { $(($pattern) => $code;)* ($other : tt)
687 => {} } _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH0));
688 _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH0, 0, interrupt = DMA_CH0,
689 compatible = [SPI2, SHA])); _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH0,
690 can_access_psram = false)); _for_each_inner_dma_channel!((names("AHB_GDMA",
691 DMA_CH0))); _for_each_inner_dma_channel!((separate_any_type));
692 _for_each_inner_dma_channel!((shared("AHB_GDMA", DMA_CH0, 0, interrupt = DMA_CH0,
693 compatible = [SPI2, SHA]))); _for_each_inner_dma_channel!((split));
694 _for_each_inner_dma_channel!((no_own_interrupt));
695 _for_each_inner_dma_channel!((psram("AHB_GDMA", DMA_CH0, can_access_psram =
696 false)));
697 };
698}
699#[macro_export]
700#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
701macro_rules! for_each_dma_channel_peri_pair {
702 ($($pattern:tt => $code:tt;)*) => {
703 macro_rules! _for_each_inner_dma_channel_peri_pair { $(($pattern) => $code;)*
704 ($other : tt) => {} } _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA",
705 DMA_CH0, SPI2)); _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH0,
706 SHA)); _for_each_inner_dma_channel_peri_pair!((channels("AHB_GDMA", DMA_CH0,
707 SPI2), ("AHB_GDMA", DMA_CH0, SHA)));
708 _for_each_inner_dma_channel_peri_pair!((any_channels));
709 };
710}
711#[macro_export]
712#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
713macro_rules! for_each_mem2mem_channel {
714 ($($pattern:tt => $code:tt;)*) => {
715 macro_rules! _for_each_inner_mem2mem_channel { $(($pattern) => $code;)* ($other :
716 tt) => {} } _for_each_inner_mem2mem_channel!(("AHB_GDMA", AhbGdma,
717 AhbGdmaChannel, DMA_CH0, 2)); _for_each_inner_mem2mem_channel!(("AHB_GDMA",
718 AhbGdma, AhbGdmaChannel, 0, 2)); _for_each_inner_mem2mem_channel!(("AHB_GDMA",
719 AhbGdma, AhbGdmaChannel)); _for_each_inner_mem2mem_channel!((channels("AHB_GDMA",
720 AhbGdma, AhbGdmaChannel, DMA_CH0, 2)));
721 _for_each_inner_mem2mem_channel!((erased("AHB_GDMA", AhbGdma, AhbGdmaChannel, 0,
722 2))); _for_each_inner_mem2mem_channel!((engines("AHB_GDMA", AhbGdma,
723 AhbGdmaChannel)));
724 };
725}
726#[macro_export]
727#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
728macro_rules! with_sha_dma_engine {
729 ($($pattern:tt => $code:tt;)*) => {
730 macro_rules! _with_inner_sha_dma_engine { $(($pattern) => $code;)* ($other : tt)
731 => {} } _with_inner_sha_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
732 };
733}
734#[macro_export]
735#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
736macro_rules! with_spi_master_dma_engine {
737 ($($pattern:tt => $code:tt;)*) => {
738 macro_rules! _with_inner_spi_master_dma_engine { $(($pattern) => $code;)* ($other
739 : tt) => {} } _with_inner_spi_master_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
740 };
741}
742#[macro_export]
743#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
744macro_rules! with_spi_slave_dma_engine {
745 ($($pattern:tt => $code:tt;)*) => {
746 macro_rules! _with_inner_spi_slave_dma_engine { $(($pattern) => $code;)* ($other
747 : tt) => {} } _with_inner_spi_slave_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
748 };
749}
750#[macro_export]
751#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
752macro_rules! for_each_interrupt {
753 ($($pattern:tt => $code:tt;)*) => {
754 macro_rules! _for_each_inner_interrupt { $(($pattern) => $code;)* ($other : tt)
755 => {} } _for_each_inner_interrupt!(([disabled 0] 0));
756 _for_each_inner_interrupt!(([reserved 0] 1));
757 _for_each_inner_interrupt!(([context_switch 0] 2));
758 _for_each_inner_interrupt!(([direct_bindable 0] 3));
759 _for_each_inner_interrupt!(([direct_bindable 1] 4));
760 _for_each_inner_interrupt!(([direct_bindable 2] 5));
761 _for_each_inner_interrupt!(([direct_bindable 3] 6));
762 _for_each_inner_interrupt!(([direct_bindable 4] 7));
763 _for_each_inner_interrupt!(([direct_bindable 5] 8));
764 _for_each_inner_interrupt!(([direct_bindable 6] 9));
765 _for_each_inner_interrupt!(([direct_bindable 7] 10));
766 _for_each_inner_interrupt!(([direct_bindable 8] 11));
767 _for_each_inner_interrupt!(([direct_bindable 9] 12));
768 _for_each_inner_interrupt!(([direct_bindable 10] 13));
769 _for_each_inner_interrupt!(([direct_bindable 11] 14));
770 _for_each_inner_interrupt!(([direct_bindable 12] 15));
771 _for_each_inner_interrupt!(([direct_bindable 13] 16));
772 _for_each_inner_interrupt!(([vector 0] 17)); _for_each_inner_interrupt!(([vector
773 1] 18)); _for_each_inner_interrupt!(([vector 2] 19));
774 _for_each_inner_interrupt!(([vector 3] 20)); _for_each_inner_interrupt!(([vector
775 4] 21)); _for_each_inner_interrupt!(([vector 5] 22));
776 _for_each_inner_interrupt!(([vector 6] 23)); _for_each_inner_interrupt!(([vector
777 7] 24)); _for_each_inner_interrupt!(([vector 8] 25));
778 _for_each_inner_interrupt!(([vector 9] 26)); _for_each_inner_interrupt!(([vector
779 10] 27)); _for_each_inner_interrupt!(([vector 11] 28));
780 _for_each_inner_interrupt!(([vector 12] 29)); _for_each_inner_interrupt!(([vector
781 13] 30)); _for_each_inner_interrupt!(([vector 14] 31));
782 _for_each_inner_interrupt!((all([disabled 0] 0), ([reserved 0] 1),
783 ([context_switch 0] 2), ([direct_bindable 0] 3), ([direct_bindable 1] 4),
784 ([direct_bindable 2] 5), ([direct_bindable 3] 6), ([direct_bindable 4] 7),
785 ([direct_bindable 5] 8), ([direct_bindable 6] 9), ([direct_bindable 7] 10),
786 ([direct_bindable 8] 11), ([direct_bindable 9] 12), ([direct_bindable 10] 13),
787 ([direct_bindable 11] 14), ([direct_bindable 12] 15), ([direct_bindable 13] 16),
788 ([vector 0] 17), ([vector 1] 18), ([vector 2] 19), ([vector 3] 20), ([vector 4]
789 21), ([vector 5] 22), ([vector 6] 23), ([vector 7] 24), ([vector 8] 25), ([vector
790 9] 26), ([vector 10] 27), ([vector 11] 28), ([vector 12] 29), ([vector 13] 30),
791 ([vector 14] 31)));
792 };
793}
794#[macro_export]
795#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
796macro_rules! for_each_classified_interrupt {
797 ($($pattern:tt => $code:tt;)*) => {
798 macro_rules! _for_each_inner_classified_interrupt { $(($pattern) => $code;)*
799 ($other : tt) => {} } _for_each_inner_classified_interrupt!(([direct_bindable 0]
800 3)); _for_each_inner_classified_interrupt!(([direct_bindable 1] 4));
801 _for_each_inner_classified_interrupt!(([direct_bindable 2] 5));
802 _for_each_inner_classified_interrupt!(([direct_bindable 3] 6));
803 _for_each_inner_classified_interrupt!(([direct_bindable 4] 7));
804 _for_each_inner_classified_interrupt!(([direct_bindable 5] 8));
805 _for_each_inner_classified_interrupt!(([direct_bindable 6] 9));
806 _for_each_inner_classified_interrupt!(([direct_bindable 7] 10));
807 _for_each_inner_classified_interrupt!(([direct_bindable 8] 11));
808 _for_each_inner_classified_interrupt!(([direct_bindable 9] 12));
809 _for_each_inner_classified_interrupt!(([direct_bindable 10] 13));
810 _for_each_inner_classified_interrupt!(([direct_bindable 11] 14));
811 _for_each_inner_classified_interrupt!(([direct_bindable 12] 15));
812 _for_each_inner_classified_interrupt!(([direct_bindable 13] 16));
813 _for_each_inner_classified_interrupt!(([vector 0] 17));
814 _for_each_inner_classified_interrupt!(([vector 1] 18));
815 _for_each_inner_classified_interrupt!(([vector 2] 19));
816 _for_each_inner_classified_interrupt!(([vector 3] 20));
817 _for_each_inner_classified_interrupt!(([vector 4] 21));
818 _for_each_inner_classified_interrupt!(([vector 5] 22));
819 _for_each_inner_classified_interrupt!(([vector 6] 23));
820 _for_each_inner_classified_interrupt!(([vector 7] 24));
821 _for_each_inner_classified_interrupt!(([vector 8] 25));
822 _for_each_inner_classified_interrupt!(([vector 9] 26));
823 _for_each_inner_classified_interrupt!(([vector 10] 27));
824 _for_each_inner_classified_interrupt!(([vector 11] 28));
825 _for_each_inner_classified_interrupt!(([vector 12] 29));
826 _for_each_inner_classified_interrupt!(([vector 13] 30));
827 _for_each_inner_classified_interrupt!(([vector 14] 31));
828 _for_each_inner_classified_interrupt!(([reserved 0] 1));
829 _for_each_inner_classified_interrupt!(([context_switch 0] 2));
830 _for_each_inner_classified_interrupt!((direct_bindable([direct_bindable 0] 3),
831 ([direct_bindable 1] 4), ([direct_bindable 2] 5), ([direct_bindable 3] 6),
832 ([direct_bindable 4] 7), ([direct_bindable 5] 8), ([direct_bindable 6] 9),
833 ([direct_bindable 7] 10), ([direct_bindable 8] 11), ([direct_bindable 9] 12),
834 ([direct_bindable 10] 13), ([direct_bindable 11] 14), ([direct_bindable 12] 15),
835 ([direct_bindable 13] 16)));
836 _for_each_inner_classified_interrupt!((vector([vector 0] 17), ([vector 1] 18),
837 ([vector 2] 19), ([vector 3] 20), ([vector 4] 21), ([vector 5] 22), ([vector 6]
838 23), ([vector 7] 24), ([vector 8] 25), ([vector 9] 26), ([vector 10] 27),
839 ([vector 11] 28), ([vector 12] 29), ([vector 13] 30), ([vector 14] 31)));
840 _for_each_inner_classified_interrupt!((reserved([reserved 0] 1)));
841 _for_each_inner_classified_interrupt!((context_switch([context_switch 0] 2)));
842 };
843}
844#[macro_export]
845#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
846macro_rules! for_each_interrupt_priority {
847 ($($pattern:tt => $code:tt;)*) => {
848 macro_rules! _for_each_inner_interrupt_priority { $(($pattern) => $code;)*
849 ($other : tt) => {} } _for_each_inner_interrupt_priority!((0, 1, Priority1,
850 Level1)); _for_each_inner_interrupt_priority!((1, 2, Priority2, Level2));
851 _for_each_inner_interrupt_priority!((2, 3, Priority3, Level3));
852 _for_each_inner_interrupt_priority!((3, 4, Priority4, Level4));
853 _for_each_inner_interrupt_priority!((4, 5, Priority5, Level5));
854 _for_each_inner_interrupt_priority!((5, 6, Priority6, Level6));
855 _for_each_inner_interrupt_priority!((6, 7, Priority7, Level7));
856 _for_each_inner_interrupt_priority!((7, 8, Priority8, Level8));
857 _for_each_inner_interrupt_priority!((8, 9, Priority9, Level9));
858 _for_each_inner_interrupt_priority!((9, 10, Priority10, Level10));
859 _for_each_inner_interrupt_priority!((10, 11, Priority11, Level11));
860 _for_each_inner_interrupt_priority!((11, 12, Priority12, Level12));
861 _for_each_inner_interrupt_priority!((12, 13, Priority13, Level13));
862 _for_each_inner_interrupt_priority!((13, 14, Priority14, Level14));
863 _for_each_inner_interrupt_priority!((14, 15, Priority15, Level15));
864 _for_each_inner_interrupt_priority!((all(0, 1, Priority1, Level1), (1, 2,
865 Priority2, Level2), (2, 3, Priority3, Level3), (3, 4, Priority4, Level4), (4, 5,
866 Priority5, Level5), (5, 6, Priority6, Level6), (6, 7, Priority7, Level7), (7, 8,
867 Priority8, Level8), (8, 9, Priority9, Level9), (9, 10, Priority10, Level10), (10,
868 11, Priority11, Level11), (11, 12, Priority12, Level12), (12, 13, Priority13,
869 Level13), (13, 14, Priority14, Level14), (14, 15, Priority15, Level15)));
870 };
871}
872#[macro_export]
873#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
874macro_rules! for_each_sw_interrupt {
875 ($($pattern:tt => $code:tt;)*) => {
876 macro_rules! _for_each_inner_sw_interrupt { $(($pattern) => $code;)* ($other :
877 tt) => {} } _for_each_inner_sw_interrupt!((0, FROM_CPU_INTR0,
878 software_interrupt0)); _for_each_inner_sw_interrupt!((1, FROM_CPU_INTR1,
879 software_interrupt1)); _for_each_inner_sw_interrupt!((2, FROM_CPU_INTR2,
880 software_interrupt2)); _for_each_inner_sw_interrupt!((3, FROM_CPU_INTR3,
881 software_interrupt3)); _for_each_inner_sw_interrupt!((all(0, FROM_CPU_INTR0,
882 software_interrupt0), (1, FROM_CPU_INTR1, software_interrupt1), (2,
883 FROM_CPU_INTR2, software_interrupt2), (3, FROM_CPU_INTR3, software_interrupt3)));
884 };
885}
886#[macro_export]
887macro_rules! define_clock_tree_types {
1280 () => {
1281 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1282 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1283 pub enum AdcInstance {
1284 ApbSaradc = 0,
1285 }
1286 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1287 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1288 pub enum I2cInstance {
1289 I2c0 = 0,
1290 }
1291 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1292 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1293 pub enum SpiInstance {
1294 Spi2 = 0,
1295 }
1296 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1297 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1298 pub enum TimgInstance {
1299 Timg0 = 0,
1300 }
1301 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1302 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1303 pub enum UartInstance {
1304 Uart0 = 0,
1305 Uart1 = 1,
1306 }
1307 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1308 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1309 pub enum TsensInstance {
1310 Tsens = 0,
1311 }
1312 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1314 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1315 pub enum XtalClkConfig {
1316 _26,
1318 _40,
1320 }
1321 impl XtalClkConfig {
1322 #[inline(always)]
1323 pub fn value(&self) -> u32 {
1324 match self {
1325 XtalClkConfig::_26 => 26000000,
1326 XtalClkConfig::_40 => 40000000,
1327 }
1328 }
1329 }
1330 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1332 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1333 pub enum SystemPreDivInConfig {
1334 Xtal,
1336 RcFast,
1338 }
1339 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1343 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1344 pub struct SystemPreDivConfig {
1345 divisor: u32,
1346 }
1347 impl SystemPreDivConfig {
1348 pub const fn new(divisor: u32) -> Self {
1355 ::core::assert!(
1356 divisor <= 1023,
1357 "`SYSTEM_PRE_DIV` divisor must be between 0 and 1023 (inclusive)."
1358 );
1359 Self { divisor }
1360 }
1361 pub fn divisor(self) -> u32 {
1362 self.divisor as u32
1363 }
1364 }
1365 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1366 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1367 pub enum CpuPllDivDivisor {
1368 _4 = 4,
1370 _6 = 6,
1372 }
1373 impl CpuPllDivDivisor {
1374 pub const fn new(raw: u32) -> Self {
1376 match raw {
1377 4 => Self::_4,
1378 6 => Self::_6,
1379 _ => ::core::panic!("Invalid CPU_PLL_DIV divisor value"),
1380 }
1381 }
1382 }
1383 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1387 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1388 pub struct CpuPllDivConfig {
1389 divisor: CpuPllDivDivisor,
1390 }
1391 impl CpuPllDivConfig {
1392 pub const fn new(divisor: CpuPllDivDivisor) -> Self {
1394 Self { divisor }
1395 }
1396 pub fn divisor(self) -> u32 {
1397 self.divisor as u32
1398 }
1399 }
1400 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1402 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1403 pub enum ApbClkConfig {
1404 Pll40m,
1406 Cpu,
1408 }
1409 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1411 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1412 pub enum CryptoClkConfig {
1413 Pll80m,
1415 Cpu,
1417 }
1418 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1420 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1421 pub enum MspiClkConfig {
1422 CpuDiv2,
1424 Cpu,
1426 }
1427 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1429 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1430 pub enum CpuClkConfig {
1431 Xtal,
1433 RcFast,
1435 Pll,
1437 }
1438 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1442 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1443 pub struct RcFastClkDivNConfig {
1444 divisor: u32,
1445 }
1446 impl RcFastClkDivNConfig {
1447 pub const fn new(divisor: u32) -> Self {
1454 ::core::assert!(
1455 divisor <= 3,
1456 "`RC_FAST_CLK_DIV_N` divisor must be between 0 and 3 (inclusive)."
1457 );
1458 Self { divisor }
1459 }
1460 pub fn divisor(self) -> u32 {
1461 self.divisor as u32
1462 }
1463 }
1464 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1466 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1467 pub enum RtcSlowClkConfig {
1468 OscSlow,
1470 RcSlow,
1472 RcFast,
1474 }
1475 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1476 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1477 pub enum BleLpClkSclk {
1478 #[default]
1479 Xtal,
1481 RcSlow,
1483 }
1484 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1488 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1489 pub struct BleLpClkConfig {
1490 sclk: BleLpClkSclk,
1491 divisor: u32,
1492 }
1493 impl BleLpClkConfig {
1494 pub const fn new(sclk: BleLpClkSclk, divisor: u32) -> Self {
1501 ::core::assert!(
1502 divisor <= 255,
1503 "`BLE_LP_CLK` divisor must be between 0 and 255 (inclusive)."
1504 );
1505 Self { sclk, divisor }
1506 }
1507 pub fn sclk(self) -> BleLpClkSclk {
1508 self.sclk
1509 }
1510 pub fn divisor(self) -> u32 {
1511 self.divisor as u32
1512 }
1513 }
1514 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1516 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1517 pub enum RtcFastClkConfig {
1518 Xtal,
1520 Rc,
1522 }
1523 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1525 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1526 pub enum LowPowerClkConfig {
1527 Xtal,
1529 RcFast,
1531 OscSlow,
1533 RtcSlow,
1535 }
1536 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1538 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1539 pub enum UartMemClkConfig {
1540 #[default]
1541 Xtal,
1543 }
1544 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1546 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1547 pub enum TimgCalibrationClockConfig {
1548 RcSlowClk,
1550 RcFastDivClk,
1552 Osc32kClk,
1554 }
1555 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1556 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1557 pub enum I2cFunctionClockSclk {
1558 #[default]
1559 Xtal,
1561 RcFast,
1563 }
1564 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1568 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1569 pub struct I2cFunctionClockConfig {
1570 sclk: I2cFunctionClockSclk,
1571 div_num: u32,
1572 }
1573 impl I2cFunctionClockConfig {
1574 pub const fn new(sclk: I2cFunctionClockSclk, div_num: u32) -> Self {
1581 ::core::assert!(
1582 div_num <= 255,
1583 "`I2C0_FUNCTION_CLOCK` div_num must be between 0 and 255 (inclusive)."
1584 );
1585 Self { sclk, div_num }
1586 }
1587 pub fn sclk(self) -> I2cFunctionClockSclk {
1588 self.sclk
1589 }
1590 pub fn div_num(self) -> u32 {
1591 self.div_num as u32
1592 }
1593 }
1594 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1596 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1597 pub enum SpiFunctionClockConfig {
1598 Xtal,
1600 #[default]
1601 Pll40m,
1603 }
1604 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1606 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1607 pub enum TimgFunctionClockConfig {
1608 #[default]
1609 XtalClk,
1611 Pll40m,
1613 }
1614 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1616 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1617 pub enum TimgWdtClockConfig {
1618 #[default]
1619 Pll40m,
1621 XtalClk,
1623 }
1624 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1625 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1626 pub enum UartFunctionClockSclk {
1627 PllF40m,
1629 RcFast,
1631 #[default]
1632 Xtal,
1634 }
1635 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1639 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1640 pub struct UartFunctionClockConfig {
1641 sclk: UartFunctionClockSclk,
1642 div_num: u32,
1643 }
1644 impl UartFunctionClockConfig {
1645 pub const fn new(sclk: UartFunctionClockSclk, div_num: u32) -> Self {
1652 ::core::assert!(
1653 div_num <= 255,
1654 "`UART0_FUNCTION_CLOCK` div_num must be between 0 and 255 (inclusive)."
1655 );
1656 Self { sclk, div_num }
1657 }
1658 pub fn sclk(self) -> UartFunctionClockSclk {
1659 self.sclk
1660 }
1661 pub fn div_num(self) -> u32 {
1662 self.div_num as u32
1663 }
1664 }
1665 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1670 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1671 pub struct UartBaudRateGeneratorConfig {
1672 fractional: u32,
1673 integral: u32,
1674 }
1675 impl UartBaudRateGeneratorConfig {
1676 pub const fn new(fractional: u32, integral: u32) -> Self {
1686 ::core::assert!(
1687 fractional <= 15,
1688 "`UART0_BAUD_RATE_GENERATOR` fractional must be between 0 and 15 (inclusive)."
1689 );
1690 ::core::assert!(
1691 integral <= 4095,
1692 "`UART0_BAUD_RATE_GENERATOR` integral must be between 0 and 4095 (inclusive)."
1693 );
1694 Self {
1695 fractional,
1696 integral,
1697 }
1698 }
1699 pub fn fractional(self) -> u32 {
1700 self.fractional as u32
1701 }
1702 pub fn integral(self) -> u32 {
1703 self.integral as u32
1704 }
1705 }
1706 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1708 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1709 pub enum TsensSclkConfig {
1710 RcFast,
1712 #[default]
1713 Xtal,
1715 }
1716 pub struct ClockTree {
1718 xtal_clk: Option<XtalClkConfig>,
1719 system_pre_div_in: Option<SystemPreDivInConfig>,
1720 system_pre_div: Option<SystemPreDivConfig>,
1721 cpu_pll_div: Option<CpuPllDivConfig>,
1722 apb_clk: Option<ApbClkConfig>,
1723 crypto_clk: Option<CryptoClkConfig>,
1724 mspi_clk: Option<MspiClkConfig>,
1725 cpu_clk: Option<CpuClkConfig>,
1726 rc_fast_clk_div_n: Option<RcFastClkDivNConfig>,
1727 rtc_slow_clk: Option<RtcSlowClkConfig>,
1728 ble_lp_clk: Option<BleLpClkConfig>,
1729 rtc_fast_clk: Option<RtcFastClkConfig>,
1730 low_power_clk: Option<LowPowerClkConfig>,
1731 timg_calibration_clock: Option<TimgCalibrationClockConfig>,
1732 i2c_function_clock: [Option<I2cFunctionClockConfig>; 1],
1733 spi_function_clock: [Option<SpiFunctionClockConfig>; 1],
1734 timg_function_clock: [Option<TimgFunctionClockConfig>; 1],
1735 timg_wdt_clock: [Option<TimgWdtClockConfig>; 1],
1736 uart_function_clock: [Option<UartFunctionClockConfig>; 2],
1737 uart_baud_rate_generator: [Option<UartBaudRateGeneratorConfig>; 2],
1738 tsens_sclk: [Option<TsensSclkConfig>; 1],
1739 pub(crate) rc_fast_clk_refcount: u32,
1740 pub(crate) osc_slow_clk_refcount: u32,
1741 pub(crate) rc_slow_clk_refcount: u32,
1742 pub(crate) rc_fast_div_clk_refcount: u32,
1743 pub(crate) crypto_clk_refcount: u32,
1744 pub(crate) mspi_clk_refcount: u32,
1745 pub(crate) pll_40m_refcount: u32,
1746 pub(crate) pll_60m_refcount: u32,
1747 pub(crate) ble_lp_clk_refcount: u32,
1748 pub(crate) rtc_fast_clk_refcount: u32,
1749 pub(crate) low_power_clk_refcount: u32,
1750 pub(crate) uart_mem_clk_refcount: u32,
1751 pub(crate) timg_calibration_clock_refcount: u32,
1752 pub(crate) adc_function_clock_refcount: [u32; 1],
1753 pub(crate) i2c_function_clock_refcount: [u32; 1],
1754 pub(crate) spi_function_clock_refcount: [u32; 1],
1755 pub(crate) timg_function_clock_refcount: [u32; 1],
1756 pub(crate) timg_wdt_clock_refcount: [u32; 1],
1757 pub(crate) uart_function_clock_refcount: [u32; 2],
1758 pub(crate) uart_mem_clock_refcount: [u32; 2],
1759 pub(crate) uart_baud_rate_generator_refcount: [u32; 2],
1760 pub(crate) tsens_sclk_refcount: [u32; 1],
1761 }
1762 impl ClockTree {
1763 pub fn with<R>(f: impl FnOnce(&mut ClockTree) -> R) -> R {
1765 CLOCK_TREE.with(f)
1766 }
1767 pub fn xtal_clk(&self) -> Option<XtalClkConfig> {
1769 self.xtal_clk
1770 }
1771 pub fn system_pre_div_in(&self) -> Option<SystemPreDivInConfig> {
1773 self.system_pre_div_in
1774 }
1775 pub fn system_pre_div(&self) -> Option<SystemPreDivConfig> {
1777 self.system_pre_div
1778 }
1779 pub fn cpu_pll_div(&self) -> Option<CpuPllDivConfig> {
1781 self.cpu_pll_div
1782 }
1783 pub fn apb_clk(&self) -> Option<ApbClkConfig> {
1785 self.apb_clk
1786 }
1787 pub fn crypto_clk(&self) -> Option<CryptoClkConfig> {
1789 self.crypto_clk
1790 }
1791 pub fn mspi_clk(&self) -> Option<MspiClkConfig> {
1793 self.mspi_clk
1794 }
1795 pub fn cpu_clk(&self) -> Option<CpuClkConfig> {
1797 self.cpu_clk
1798 }
1799 pub fn rc_fast_clk_div_n(&self) -> Option<RcFastClkDivNConfig> {
1801 self.rc_fast_clk_div_n
1802 }
1803 pub fn rtc_slow_clk(&self) -> Option<RtcSlowClkConfig> {
1805 self.rtc_slow_clk
1806 }
1807 pub fn ble_lp_clk(&self) -> Option<BleLpClkConfig> {
1809 self.ble_lp_clk
1810 }
1811 pub fn rtc_fast_clk(&self) -> Option<RtcFastClkConfig> {
1813 self.rtc_fast_clk
1814 }
1815 pub fn low_power_clk(&self) -> Option<LowPowerClkConfig> {
1817 self.low_power_clk
1818 }
1819 pub fn timg_calibration_clock(&self) -> Option<TimgCalibrationClockConfig> {
1821 self.timg_calibration_clock
1822 }
1823 pub fn i2c0_function_clock(&self) -> Option<I2cFunctionClockConfig> {
1825 self.i2c_function_clock[I2cInstance::I2c0 as usize]
1826 }
1827 pub fn spi2_function_clock(&self) -> Option<SpiFunctionClockConfig> {
1829 self.spi_function_clock[SpiInstance::Spi2 as usize]
1830 }
1831 pub fn timg0_function_clock(&self) -> Option<TimgFunctionClockConfig> {
1833 self.timg_function_clock[TimgInstance::Timg0 as usize]
1834 }
1835 pub fn timg0_wdt_clock(&self) -> Option<TimgWdtClockConfig> {
1837 self.timg_wdt_clock[TimgInstance::Timg0 as usize]
1838 }
1839 pub fn uart0_function_clock(&self) -> Option<UartFunctionClockConfig> {
1841 self.uart_function_clock[UartInstance::Uart0 as usize]
1842 }
1843 pub fn uart0_baud_rate_generator(&self) -> Option<UartBaudRateGeneratorConfig> {
1845 self.uart_baud_rate_generator[UartInstance::Uart0 as usize]
1846 }
1847 pub fn uart1_function_clock(&self) -> Option<UartFunctionClockConfig> {
1849 self.uart_function_clock[UartInstance::Uart1 as usize]
1850 }
1851 pub fn uart1_baud_rate_generator(&self) -> Option<UartBaudRateGeneratorConfig> {
1853 self.uart_baud_rate_generator[UartInstance::Uart1 as usize]
1854 }
1855 pub fn tsens_sclk(&self) -> Option<TsensSclkConfig> {
1857 self.tsens_sclk[TsensInstance::Tsens as usize]
1858 }
1859 }
1860 static CLOCK_TREE: ::esp_sync::NonReentrantMutex<ClockTree> =
1861 ::esp_sync::NonReentrantMutex::new(ClockTree {
1862 xtal_clk: None,
1863 system_pre_div_in: None,
1864 system_pre_div: None,
1865 cpu_pll_div: None,
1866 apb_clk: None,
1867 crypto_clk: None,
1868 mspi_clk: None,
1869 cpu_clk: None,
1870 rc_fast_clk_div_n: None,
1871 rtc_slow_clk: None,
1872 ble_lp_clk: None,
1873 rtc_fast_clk: None,
1874 low_power_clk: None,
1875 timg_calibration_clock: None,
1876 i2c_function_clock: [None; 1],
1877 spi_function_clock: [None; 1],
1878 timg_function_clock: [None; 1],
1879 timg_wdt_clock: [None; 1],
1880 uart_function_clock: [None; 2],
1881 uart_baud_rate_generator: [None; 2],
1882 tsens_sclk: [None; 1],
1883 rc_fast_clk_refcount: 0,
1884 osc_slow_clk_refcount: 0,
1885 rc_slow_clk_refcount: 0,
1886 rc_fast_div_clk_refcount: 0,
1887 crypto_clk_refcount: 0,
1888 mspi_clk_refcount: 0,
1889 pll_40m_refcount: 0,
1890 pll_60m_refcount: 0,
1891 ble_lp_clk_refcount: 0,
1892 rtc_fast_clk_refcount: 0,
1893 low_power_clk_refcount: 0,
1894 uart_mem_clk_refcount: 0,
1895 timg_calibration_clock_refcount: 0,
1896 adc_function_clock_refcount: [0; 1],
1897 i2c_function_clock_refcount: [0; 1],
1898 spi_function_clock_refcount: [0; 1],
1899 timg_function_clock_refcount: [0; 1],
1900 timg_wdt_clock_refcount: [0; 1],
1901 uart_function_clock_refcount: [0; 2],
1902 uart_mem_clock_refcount: [0; 2],
1903 uart_baud_rate_generator_refcount: [0; 2],
1904 tsens_sclk_refcount: [0; 1],
1905 });
1906 static XTAL_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1907 ::core::sync::atomic::AtomicU32::new(0);
1908 static SYSTEM_PRE_DIV_IN_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1909 ::core::sync::atomic::AtomicU32::new(0);
1910 static SYSTEM_PRE_DIV_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1911 ::core::sync::atomic::AtomicU32::new(0);
1912 static CPU_PLL_DIV_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1913 ::core::sync::atomic::AtomicU32::new(0);
1914 static CPU_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1915 ::core::sync::atomic::AtomicU32::new(0);
1916 static RC_FAST_CLK_DIV_N_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1917 ::core::sync::atomic::AtomicU32::new(0);
1918 static RTC_SLOW_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1919 ::core::sync::atomic::AtomicU32::new(0);
1920 static BLE_LP_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1921 ::core::sync::atomic::AtomicU32::new(0);
1922 static RTC_FAST_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1923 ::core::sync::atomic::AtomicU32::new(0);
1924 static LOW_POWER_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1925 ::core::sync::atomic::AtomicU32::new(0);
1926 static TIMG_CALIBRATION_CLOCK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1927 ::core::sync::atomic::AtomicU32::new(0);
1928 static I2C_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
1929 [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
1930 static SPI_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
1931 [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
1932 static TIMG_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
1933 [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
1934 static TIMG_WDT_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
1935 [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
1936 static UART_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 2] =
1937 [const { ::core::sync::atomic::AtomicU32::new(0) }; 2];
1938 static UART_BAUD_RATE_GENERATOR_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 2] =
1939 [const { ::core::sync::atomic::AtomicU32::new(0) }; 2];
1940 static TSENS_SCLK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
1941 [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
1942 static APB_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1943 ::core::sync::atomic::AtomicU32::new(0);
1944 static CRYPTO_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1945 ::core::sync::atomic::AtomicU32::new(0);
1946 static MSPI_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1947 ::core::sync::atomic::AtomicU32::new(0);
1948 #[derive(Debug, enumset::EnumSetType)]
1953 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1954 pub enum ClockSource {
1955 XtalClk,
1957 RcFastClk,
1959 OscSlowClk,
1961 RcSlowClk,
1963 }
1964 pub fn xtal_clk_root_source(_clocks: &mut ClockTree) -> Option<ClockSource> {
1966 Some(ClockSource::XtalClk)
1967 }
1968 pub fn pll_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1970 xtal_clk_root_source(clocks)
1971 }
1972 pub fn rc_fast_clk_root_source(_clocks: &mut ClockTree) -> Option<ClockSource> {
1974 Some(ClockSource::RcFastClk)
1975 }
1976 pub fn osc_slow_clk_root_source(_clocks: &mut ClockTree) -> Option<ClockSource> {
1978 Some(ClockSource::OscSlowClk)
1979 }
1980 pub fn rc_slow_clk_root_source(_clocks: &mut ClockTree) -> Option<ClockSource> {
1982 Some(ClockSource::RcSlowClk)
1983 }
1984 pub fn rc_fast_div_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1986 rc_fast_clk_root_source(clocks)
1987 }
1988 pub fn system_pre_div_in_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1990 let config = clocks.system_pre_div_in?;
1991 match config {
1992 SystemPreDivInConfig::Xtal => xtal_clk_root_source(clocks),
1993 SystemPreDivInConfig::RcFast => rc_fast_clk_root_source(clocks),
1994 }
1995 }
1996 pub fn system_pre_div_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
1998 system_pre_div_in_root_source(clocks)
1999 }
2000 pub fn cpu_pll_div_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2002 pll_clk_root_source(clocks)
2003 }
2004 pub fn cpu_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2006 let config = clocks.cpu_clk?;
2007 match config {
2008 CpuClkConfig::Xtal => system_pre_div_root_source(clocks),
2009 CpuClkConfig::RcFast => system_pre_div_root_source(clocks),
2010 CpuClkConfig::Pll => cpu_pll_div_root_source(clocks),
2011 }
2012 }
2013 pub fn pll_40m_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2015 cpu_clk_root_source(clocks)
2016 }
2017 pub fn pll_60m_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2019 cpu_clk_root_source(clocks)
2020 }
2021 pub fn pll_80m_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2023 cpu_clk_root_source(clocks)
2024 }
2025 pub fn cpu_div2_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2027 cpu_clk_root_source(clocks)
2028 }
2029 pub fn rc_fast_clk_div_n_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2031 rc_fast_clk_root_source(clocks)
2032 }
2033 pub fn xtal_div_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2035 xtal_clk_root_source(clocks)
2036 }
2037 pub fn rtc_slow_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2039 let config = clocks.rtc_slow_clk?;
2040 match config {
2041 RtcSlowClkConfig::OscSlow => osc_slow_clk_root_source(clocks),
2042 RtcSlowClkConfig::RcSlow => rc_slow_clk_root_source(clocks),
2043 RtcSlowClkConfig::RcFast => rc_fast_div_clk_root_source(clocks),
2044 }
2045 }
2046 pub fn ble_lp_xtal_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2048 xtal_clk_root_source(clocks)
2049 }
2050 pub fn ble_lp_rc_slow_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2052 rc_slow_clk_root_source(clocks)
2053 }
2054 pub fn ble_lp_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2056 let config = clocks.ble_lp_clk?;
2057 match config.sclk() {
2058 BleLpClkSclk::Xtal => ble_lp_xtal_clk_root_source(clocks),
2059 BleLpClkSclk::RcSlow => ble_lp_rc_slow_clk_root_source(clocks),
2060 }
2061 }
2062 pub fn rtc_fast_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2064 let config = clocks.rtc_fast_clk?;
2065 match config {
2066 RtcFastClkConfig::Xtal => xtal_div_clk_root_source(clocks),
2067 RtcFastClkConfig::Rc => rc_fast_clk_div_n_root_source(clocks),
2068 }
2069 }
2070 pub fn low_power_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2072 let config = clocks.low_power_clk?;
2073 match config {
2074 LowPowerClkConfig::Xtal => xtal_clk_root_source(clocks),
2075 LowPowerClkConfig::RcFast => rc_fast_clk_root_source(clocks),
2076 LowPowerClkConfig::OscSlow => osc_slow_clk_root_source(clocks),
2077 LowPowerClkConfig::RtcSlow => rtc_slow_clk_root_source(clocks),
2078 }
2079 }
2080 pub fn uart_mem_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2082 xtal_clk_root_source(clocks)
2083 }
2084 pub fn timg_calibration_clock_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2086 let config = clocks.timg_calibration_clock?;
2087 match config {
2088 TimgCalibrationClockConfig::RcSlowClk => rc_slow_clk_root_source(clocks),
2089 TimgCalibrationClockConfig::RcFastDivClk => rc_fast_div_clk_root_source(clocks),
2090 TimgCalibrationClockConfig::Osc32kClk => osc_slow_clk_root_source(clocks),
2091 }
2092 }
2093 pub fn apb_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2095 let config = clocks.apb_clk?;
2096 match config {
2097 ApbClkConfig::Pll40m => pll_40m_root_source(clocks),
2098 ApbClkConfig::Cpu => cpu_clk_root_source(clocks),
2099 }
2100 }
2101 pub fn crypto_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2103 let config = clocks.crypto_clk?;
2104 match config {
2105 CryptoClkConfig::Pll80m => pll_80m_root_source(clocks),
2106 CryptoClkConfig::Cpu => cpu_clk_root_source(clocks),
2107 }
2108 }
2109 pub fn mspi_clk_root_source(clocks: &mut ClockTree) -> Option<ClockSource> {
2111 let config = clocks.mspi_clk?;
2112 match config {
2113 MspiClkConfig::CpuDiv2 => cpu_div2_root_source(clocks),
2114 MspiClkConfig::Cpu => cpu_clk_root_source(clocks),
2115 }
2116 }
2117 pub fn configure_xtal_clk(clocks: &mut ClockTree, config: XtalClkConfig) {
2118 let old_config = clocks.xtal_clk.replace(config);
2119 refresh_xtal_clk_downstream(clocks);
2120 configure_xtal_clk_impl(clocks, old_config, config);
2121 }
2122 pub fn xtal_clk_config(clocks: &mut ClockTree) -> Option<XtalClkConfig> {
2123 clocks.xtal_clk
2124 }
2125 fn request_xtal_clk(_clocks: &mut ClockTree) {}
2126 fn release_xtal_clk(_clocks: &mut ClockTree) {}
2127 pub fn xtal_clk_config_frequency(config: XtalClkConfig) -> u32 {
2128 config.value()
2129 }
2130 #[inline(always)]
2131 pub fn xtal_clk_frequency() -> u32 {
2132 XTAL_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2133 }
2134 pub fn request_pll_clk(clocks: &mut ClockTree) {
2135 trace!("Enabling PLL_CLK");
2136 request_xtal_clk(clocks);
2137 enable_pll_clk_impl(clocks, true);
2138 }
2139 pub fn release_pll_clk(clocks: &mut ClockTree) {
2140 trace!("Disabling PLL_CLK");
2141 enable_pll_clk_impl(clocks, false);
2142 release_xtal_clk(clocks);
2143 }
2144 #[inline(always)]
2145 pub fn pll_clk_frequency() -> u32 {
2146 480000000
2147 }
2148 pub fn pll_clk_source_frequency() -> u32 {
2149 xtal_clk_frequency()
2150 }
2151 pub fn request_rc_fast_clk(clocks: &mut ClockTree) {
2152 trace!("Requesting RC_FAST_CLK");
2153 if increment_reference_count(&mut clocks.rc_fast_clk_refcount) {
2154 trace!("Enabling RC_FAST_CLK");
2155 enable_rc_fast_clk_impl(clocks, true);
2156 }
2157 }
2158 pub fn release_rc_fast_clk(clocks: &mut ClockTree) {
2159 trace!("Releasing RC_FAST_CLK");
2160 if decrement_reference_count(&mut clocks.rc_fast_clk_refcount) {
2161 trace!("Disabling RC_FAST_CLK");
2162 enable_rc_fast_clk_impl(clocks, false);
2163 }
2164 }
2165 static RC_FAST_CLK_FREQUENCY: ::core::sync::atomic::AtomicU32 =
2166 ::core::sync::atomic::AtomicU32::new(rc_fast_clk_nominal_frequency());
2167 pub const fn rc_fast_clk_nominal_frequency() -> u32 {
2168 17500000
2169 }
2170 #[inline(always)]
2171 pub fn rc_fast_clk_frequency() -> u32 {
2172 RC_FAST_CLK_FREQUENCY.load(::core::sync::atomic::Ordering::Acquire)
2173 }
2174 pub fn set_rc_fast_clk_frequency(clocks: &mut ClockTree, frequency: u32) {
2175 if !(8750000..=26250000).contains(&frequency) {
2176 warn!(
2177 "Ignoring out-of-range RC_FAST_CLK frequency: {} Hz",
2178 frequency
2179 );
2180 return;
2181 }
2182 debug!(
2183 "Updating RC_FAST_CLK frequency to {} Hz (nominal {} Hz)",
2184 frequency,
2185 rc_fast_clk_nominal_frequency()
2186 );
2187 RC_FAST_CLK_FREQUENCY.store(frequency, ::core::sync::atomic::Ordering::Release);
2188 refresh_rc_fast_clk_downstream(clocks);
2189 }
2190 pub fn request_osc_slow_clk(clocks: &mut ClockTree) {
2191 trace!("Requesting OSC_SLOW_CLK");
2192 if increment_reference_count(&mut clocks.osc_slow_clk_refcount) {
2193 trace!("Enabling OSC_SLOW_CLK");
2194 enable_osc_slow_clk_impl(clocks, true);
2195 }
2196 }
2197 pub fn release_osc_slow_clk(clocks: &mut ClockTree) {
2198 trace!("Releasing OSC_SLOW_CLK");
2199 if decrement_reference_count(&mut clocks.osc_slow_clk_refcount) {
2200 trace!("Disabling OSC_SLOW_CLK");
2201 enable_osc_slow_clk_impl(clocks, false);
2202 }
2203 }
2204 #[inline(always)]
2205 pub fn osc_slow_clk_frequency() -> u32 {
2206 32768
2207 }
2208 pub fn request_rc_slow_clk(clocks: &mut ClockTree) {
2209 trace!("Requesting RC_SLOW_CLK");
2210 if increment_reference_count(&mut clocks.rc_slow_clk_refcount) {
2211 trace!("Enabling RC_SLOW_CLK");
2212 enable_rc_slow_clk_impl(clocks, true);
2213 }
2214 }
2215 pub fn release_rc_slow_clk(clocks: &mut ClockTree) {
2216 trace!("Releasing RC_SLOW_CLK");
2217 if decrement_reference_count(&mut clocks.rc_slow_clk_refcount) {
2218 trace!("Disabling RC_SLOW_CLK");
2219 enable_rc_slow_clk_impl(clocks, false);
2220 }
2221 }
2222 static RC_SLOW_CLK_FREQUENCY: ::core::sync::atomic::AtomicU32 =
2223 ::core::sync::atomic::AtomicU32::new(rc_slow_clk_nominal_frequency());
2224 pub const fn rc_slow_clk_nominal_frequency() -> u32 {
2225 136000
2226 }
2227 #[inline(always)]
2228 pub fn rc_slow_clk_frequency() -> u32 {
2229 RC_SLOW_CLK_FREQUENCY.load(::core::sync::atomic::Ordering::Acquire)
2230 }
2231 pub fn set_rc_slow_clk_frequency(clocks: &mut ClockTree, frequency: u32) {
2232 if !(68000..=204000).contains(&frequency) {
2233 warn!(
2234 "Ignoring out-of-range RC_SLOW_CLK frequency: {} Hz",
2235 frequency
2236 );
2237 return;
2238 }
2239 debug!(
2240 "Updating RC_SLOW_CLK frequency to {} Hz (nominal {} Hz)",
2241 frequency,
2242 rc_slow_clk_nominal_frequency()
2243 );
2244 RC_SLOW_CLK_FREQUENCY.store(frequency, ::core::sync::atomic::Ordering::Release);
2245 refresh_rc_slow_clk_downstream(clocks);
2246 }
2247 pub fn request_rc_fast_div_clk(clocks: &mut ClockTree) {
2248 trace!("Requesting RC_FAST_DIV_CLK");
2249 if increment_reference_count(&mut clocks.rc_fast_div_clk_refcount) {
2250 trace!("Enabling RC_FAST_DIV_CLK");
2251 request_rc_fast_clk(clocks);
2252 enable_rc_fast_div_clk_impl(clocks, true);
2253 }
2254 }
2255 pub fn release_rc_fast_div_clk(clocks: &mut ClockTree) {
2256 trace!("Releasing RC_FAST_DIV_CLK");
2257 if decrement_reference_count(&mut clocks.rc_fast_div_clk_refcount) {
2258 trace!("Disabling RC_FAST_DIV_CLK");
2259 enable_rc_fast_div_clk_impl(clocks, false);
2260 release_rc_fast_clk(clocks);
2261 }
2262 }
2263 #[inline(always)]
2264 pub fn rc_fast_div_clk_frequency() -> u32 {
2265 (rc_fast_clk_frequency() / 256)
2266 }
2267 pub fn rc_fast_div_clk_source_frequency() -> u32 {
2268 rc_fast_clk_frequency()
2269 }
2270 pub fn configure_system_pre_div_in(
2271 clocks: &mut ClockTree,
2272 new_selector: SystemPreDivInConfig,
2273 ) {
2274 let old_selector = clocks.system_pre_div_in.replace(new_selector);
2275 refresh_system_pre_div_in_downstream(clocks);
2276 match new_selector {
2277 SystemPreDivInConfig::Xtal => request_xtal_clk(clocks),
2278 SystemPreDivInConfig::RcFast => request_rc_fast_clk(clocks),
2279 }
2280 configure_system_pre_div_in_impl(clocks, old_selector, new_selector);
2281 if let Some(old_selector) = old_selector {
2282 match old_selector {
2283 SystemPreDivInConfig::Xtal => release_xtal_clk(clocks),
2284 SystemPreDivInConfig::RcFast => release_rc_fast_clk(clocks),
2285 }
2286 }
2287 }
2288 pub fn system_pre_div_in_config(clocks: &mut ClockTree) -> Option<SystemPreDivInConfig> {
2289 clocks.system_pre_div_in
2290 }
2291 pub fn request_system_pre_div_in(clocks: &mut ClockTree) {
2292 trace!("Enabling SYSTEM_PRE_DIV_IN");
2293 match unwrap!(clocks.system_pre_div_in) {
2294 SystemPreDivInConfig::Xtal => request_xtal_clk(clocks),
2295 SystemPreDivInConfig::RcFast => request_rc_fast_clk(clocks),
2296 }
2297 enable_system_pre_div_in_impl(clocks, true);
2298 }
2299 pub fn release_system_pre_div_in(clocks: &mut ClockTree) {
2300 trace!("Disabling SYSTEM_PRE_DIV_IN");
2301 enable_system_pre_div_in_impl(clocks, false);
2302 match unwrap!(clocks.system_pre_div_in) {
2303 SystemPreDivInConfig::Xtal => release_xtal_clk(clocks),
2304 SystemPreDivInConfig::RcFast => release_rc_fast_clk(clocks),
2305 }
2306 }
2307 pub fn system_pre_div_in_config_frequency(config: SystemPreDivInConfig) -> u32 {
2308 match config {
2309 SystemPreDivInConfig::Xtal => xtal_clk_frequency(),
2310 SystemPreDivInConfig::RcFast => rc_fast_clk_frequency(),
2311 }
2312 }
2313 #[inline(always)]
2314 pub fn system_pre_div_in_frequency() -> u32 {
2315 SYSTEM_PRE_DIV_IN_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2316 }
2317 pub fn system_pre_div_in_source_frequency(source: SystemPreDivInConfig) -> u32 {
2318 system_pre_div_in_config_frequency(source)
2319 }
2320 pub fn configure_system_pre_div(clocks: &mut ClockTree, config: SystemPreDivConfig) {
2321 let old_config = clocks.system_pre_div.replace(config);
2322 refresh_system_pre_div_downstream(clocks);
2323 configure_system_pre_div_impl(clocks, old_config, config);
2324 }
2325 pub fn system_pre_div_config(clocks: &mut ClockTree) -> Option<SystemPreDivConfig> {
2326 clocks.system_pre_div
2327 }
2328 pub fn request_system_pre_div(clocks: &mut ClockTree) {
2329 trace!("Enabling SYSTEM_PRE_DIV");
2330 request_system_pre_div_in(clocks);
2331 enable_system_pre_div_impl(clocks, true);
2332 }
2333 pub fn release_system_pre_div(clocks: &mut ClockTree) {
2334 trace!("Disabling SYSTEM_PRE_DIV");
2335 enable_system_pre_div_impl(clocks, false);
2336 release_system_pre_div_in(clocks);
2337 }
2338 pub fn system_pre_div_config_frequency(config: SystemPreDivConfig) -> u32 {
2339 (system_pre_div_in_frequency() / (config.divisor() + 1))
2340 }
2341 #[inline(always)]
2342 pub fn system_pre_div_frequency() -> u32 {
2343 SYSTEM_PRE_DIV_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2344 }
2345 pub fn system_pre_div_source_frequency() -> u32 {
2346 system_pre_div_in_frequency()
2347 }
2348 pub fn configure_cpu_pll_div(clocks: &mut ClockTree, config: CpuPllDivConfig) {
2349 let old_config = clocks.cpu_pll_div.replace(config);
2350 refresh_cpu_pll_div_downstream(clocks);
2351 configure_cpu_pll_div_impl(clocks, old_config, config);
2352 }
2353 pub fn cpu_pll_div_config(clocks: &mut ClockTree) -> Option<CpuPllDivConfig> {
2354 clocks.cpu_pll_div
2355 }
2356 pub fn request_cpu_pll_div(clocks: &mut ClockTree) {
2357 trace!("Enabling CPU_PLL_DIV");
2358 request_pll_clk(clocks);
2359 enable_cpu_pll_div_impl(clocks, true);
2360 }
2361 pub fn release_cpu_pll_div(clocks: &mut ClockTree) {
2362 trace!("Disabling CPU_PLL_DIV");
2363 enable_cpu_pll_div_impl(clocks, false);
2364 release_pll_clk(clocks);
2365 }
2366 pub fn cpu_pll_div_config_frequency(config: CpuPllDivConfig) -> u32 {
2367 (pll_clk_frequency() / config.divisor())
2368 }
2369 #[inline(always)]
2370 pub fn cpu_pll_div_frequency() -> u32 {
2371 CPU_PLL_DIV_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2372 }
2373 pub fn cpu_pll_div_source_frequency() -> u32 {
2374 pll_clk_frequency()
2375 }
2376 pub fn configure_apb_clk(clocks: &mut ClockTree, new_selector: ApbClkConfig) {
2377 let old_selector = clocks.apb_clk.replace(new_selector);
2378 refresh_apb_clk_downstream(clocks);
2379 match new_selector {
2380 ApbClkConfig::Pll40m => request_pll_40m(clocks),
2381 ApbClkConfig::Cpu => request_cpu_clk(clocks),
2382 }
2383 configure_apb_clk_impl(clocks, old_selector, new_selector);
2384 if let Some(old_selector) = old_selector {
2385 match old_selector {
2386 ApbClkConfig::Pll40m => release_pll_40m(clocks),
2387 ApbClkConfig::Cpu => release_cpu_clk(clocks),
2388 }
2389 }
2390 }
2391 pub fn apb_clk_config(clocks: &mut ClockTree) -> Option<ApbClkConfig> {
2392 clocks.apb_clk
2393 }
2394 pub fn request_apb_clk(clocks: &mut ClockTree) {
2395 trace!("Enabling APB_CLK");
2396 match unwrap!(clocks.apb_clk) {
2397 ApbClkConfig::Pll40m => request_pll_40m(clocks),
2398 ApbClkConfig::Cpu => request_cpu_clk(clocks),
2399 }
2400 enable_apb_clk_impl(clocks, true);
2401 }
2402 pub fn release_apb_clk(clocks: &mut ClockTree) {
2403 trace!("Disabling APB_CLK");
2404 enable_apb_clk_impl(clocks, false);
2405 match unwrap!(clocks.apb_clk) {
2406 ApbClkConfig::Pll40m => release_pll_40m(clocks),
2407 ApbClkConfig::Cpu => release_cpu_clk(clocks),
2408 }
2409 }
2410 pub fn apb_clk_config_frequency(config: ApbClkConfig) -> u32 {
2411 match config {
2412 ApbClkConfig::Pll40m => pll_40m_frequency(),
2413 ApbClkConfig::Cpu => cpu_clk_frequency(),
2414 }
2415 }
2416 #[inline(always)]
2417 pub fn apb_clk_frequency() -> u32 {
2418 APB_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2419 }
2420 pub fn apb_clk_source_frequency(source: ApbClkConfig) -> u32 {
2421 apb_clk_config_frequency(source)
2422 }
2423 pub fn configure_crypto_clk(clocks: &mut ClockTree, new_selector: CryptoClkConfig) {
2424 let old_selector = clocks.crypto_clk.replace(new_selector);
2425 refresh_crypto_clk_downstream(clocks);
2426 let active = clocks.crypto_clk_refcount > 0;
2427 if active {
2428 match new_selector {
2429 CryptoClkConfig::Pll80m => request_pll_80m(clocks),
2430 CryptoClkConfig::Cpu => request_cpu_clk(clocks),
2431 }
2432 }
2433 configure_crypto_clk_impl(clocks, old_selector, new_selector);
2434 if active && let Some(old_selector) = old_selector {
2435 match old_selector {
2436 CryptoClkConfig::Pll80m => release_pll_80m(clocks),
2437 CryptoClkConfig::Cpu => release_cpu_clk(clocks),
2438 }
2439 }
2440 }
2441 pub fn crypto_clk_config(clocks: &mut ClockTree) -> Option<CryptoClkConfig> {
2442 clocks.crypto_clk
2443 }
2444 pub fn request_crypto_clk(clocks: &mut ClockTree) {
2445 trace!("Requesting CRYPTO_CLK");
2446 if increment_reference_count(&mut clocks.crypto_clk_refcount) {
2447 trace!("Enabling CRYPTO_CLK");
2448 match unwrap!(clocks.crypto_clk) {
2449 CryptoClkConfig::Pll80m => request_pll_80m(clocks),
2450 CryptoClkConfig::Cpu => request_cpu_clk(clocks),
2451 }
2452 enable_crypto_clk_impl(clocks, true);
2453 }
2454 }
2455 pub fn release_crypto_clk(clocks: &mut ClockTree) {
2456 trace!("Releasing CRYPTO_CLK");
2457 if decrement_reference_count(&mut clocks.crypto_clk_refcount) {
2458 trace!("Disabling CRYPTO_CLK");
2459 enable_crypto_clk_impl(clocks, false);
2460 match unwrap!(clocks.crypto_clk) {
2461 CryptoClkConfig::Pll80m => release_pll_80m(clocks),
2462 CryptoClkConfig::Cpu => release_cpu_clk(clocks),
2463 }
2464 }
2465 }
2466 pub fn crypto_clk_config_frequency(config: CryptoClkConfig) -> u32 {
2467 match config {
2468 CryptoClkConfig::Pll80m => pll_80m_frequency(),
2469 CryptoClkConfig::Cpu => cpu_clk_frequency(),
2470 }
2471 }
2472 #[inline(always)]
2473 pub fn crypto_clk_frequency() -> u32 {
2474 CRYPTO_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2475 }
2476 pub fn crypto_clk_source_frequency(source: CryptoClkConfig) -> u32 {
2477 crypto_clk_config_frequency(source)
2478 }
2479 pub fn configure_mspi_clk(clocks: &mut ClockTree, new_selector: MspiClkConfig) {
2480 let old_selector = clocks.mspi_clk.replace(new_selector);
2481 refresh_mspi_clk_downstream(clocks);
2482 let active = clocks.mspi_clk_refcount > 0;
2483 if active {
2484 match new_selector {
2485 MspiClkConfig::CpuDiv2 => request_cpu_div2(clocks),
2486 MspiClkConfig::Cpu => request_cpu_clk(clocks),
2487 }
2488 }
2489 configure_mspi_clk_impl(clocks, old_selector, new_selector);
2490 if active && let Some(old_selector) = old_selector {
2491 match old_selector {
2492 MspiClkConfig::CpuDiv2 => release_cpu_div2(clocks),
2493 MspiClkConfig::Cpu => release_cpu_clk(clocks),
2494 }
2495 }
2496 }
2497 pub fn mspi_clk_config(clocks: &mut ClockTree) -> Option<MspiClkConfig> {
2498 clocks.mspi_clk
2499 }
2500 pub fn request_mspi_clk(clocks: &mut ClockTree) {
2501 trace!("Requesting MSPI_CLK");
2502 if increment_reference_count(&mut clocks.mspi_clk_refcount) {
2503 trace!("Enabling MSPI_CLK");
2504 match unwrap!(clocks.mspi_clk) {
2505 MspiClkConfig::CpuDiv2 => request_cpu_div2(clocks),
2506 MspiClkConfig::Cpu => request_cpu_clk(clocks),
2507 }
2508 enable_mspi_clk_impl(clocks, true);
2509 }
2510 }
2511 pub fn release_mspi_clk(clocks: &mut ClockTree) {
2512 trace!("Releasing MSPI_CLK");
2513 if decrement_reference_count(&mut clocks.mspi_clk_refcount) {
2514 trace!("Disabling MSPI_CLK");
2515 enable_mspi_clk_impl(clocks, false);
2516 match unwrap!(clocks.mspi_clk) {
2517 MspiClkConfig::CpuDiv2 => release_cpu_div2(clocks),
2518 MspiClkConfig::Cpu => release_cpu_clk(clocks),
2519 }
2520 }
2521 }
2522 pub fn mspi_clk_config_frequency(config: MspiClkConfig) -> u32 {
2523 match config {
2524 MspiClkConfig::CpuDiv2 => cpu_div2_frequency(),
2525 MspiClkConfig::Cpu => cpu_clk_frequency(),
2526 }
2527 }
2528 #[inline(always)]
2529 pub fn mspi_clk_frequency() -> u32 {
2530 MSPI_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2531 }
2532 pub fn mspi_clk_source_frequency(source: MspiClkConfig) -> u32 {
2533 mspi_clk_config_frequency(source)
2534 }
2535 pub fn configure_cpu_clk(clocks: &mut ClockTree, new_selector: CpuClkConfig) {
2536 let old_selector = clocks.cpu_clk.replace(new_selector);
2537 refresh_cpu_clk_downstream(clocks);
2538 match new_selector {
2539 CpuClkConfig::Xtal => {
2540 configure_apb_clk(clocks, ApbClkConfig::Cpu);
2541 configure_crypto_clk(clocks, CryptoClkConfig::Cpu);
2542 configure_mspi_clk(clocks, MspiClkConfig::Cpu);
2543 configure_system_pre_div_in(clocks, SystemPreDivInConfig::Xtal);
2544 }
2545 CpuClkConfig::RcFast => {
2546 configure_apb_clk(clocks, ApbClkConfig::Cpu);
2547 configure_crypto_clk(clocks, CryptoClkConfig::Cpu);
2548 configure_mspi_clk(clocks, MspiClkConfig::Cpu);
2549 configure_system_pre_div_in(clocks, SystemPreDivInConfig::RcFast);
2550 }
2551 CpuClkConfig::Pll => {
2552 configure_apb_clk(clocks, ApbClkConfig::Pll40m);
2553 configure_crypto_clk(clocks, CryptoClkConfig::Pll80m);
2554 configure_mspi_clk(clocks, MspiClkConfig::CpuDiv2);
2555 }
2556 }
2557 match new_selector {
2558 CpuClkConfig::Xtal => request_system_pre_div(clocks),
2559 CpuClkConfig::RcFast => request_system_pre_div(clocks),
2560 CpuClkConfig::Pll => request_cpu_pll_div(clocks),
2561 }
2562 configure_cpu_clk_impl(clocks, old_selector, new_selector);
2563 if let Some(old_selector) = old_selector {
2564 match old_selector {
2565 CpuClkConfig::Xtal => release_system_pre_div(clocks),
2566 CpuClkConfig::RcFast => release_system_pre_div(clocks),
2567 CpuClkConfig::Pll => release_cpu_pll_div(clocks),
2568 }
2569 }
2570 }
2571 pub fn cpu_clk_config(clocks: &mut ClockTree) -> Option<CpuClkConfig> {
2572 clocks.cpu_clk
2573 }
2574 fn request_cpu_clk(_clocks: &mut ClockTree) {}
2575 fn release_cpu_clk(_clocks: &mut ClockTree) {}
2576 pub fn cpu_clk_config_frequency(config: CpuClkConfig) -> u32 {
2577 match config {
2578 CpuClkConfig::Xtal => system_pre_div_frequency(),
2579 CpuClkConfig::RcFast => system_pre_div_frequency(),
2580 CpuClkConfig::Pll => cpu_pll_div_frequency(),
2581 }
2582 }
2583 #[inline(always)]
2584 pub fn cpu_clk_frequency() -> u32 {
2585 CPU_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2586 }
2587 pub fn request_pll_40m(clocks: &mut ClockTree) {
2588 trace!("Requesting PLL_40M");
2589 if increment_reference_count(&mut clocks.pll_40m_refcount) {
2590 trace!("Enabling PLL_40M");
2591 request_cpu_clk(clocks);
2592 enable_pll_40m_impl(clocks, true);
2593 }
2594 }
2595 pub fn release_pll_40m(clocks: &mut ClockTree) {
2596 trace!("Releasing PLL_40M");
2597 if decrement_reference_count(&mut clocks.pll_40m_refcount) {
2598 trace!("Disabling PLL_40M");
2599 enable_pll_40m_impl(clocks, false);
2600 release_cpu_clk(clocks);
2601 }
2602 }
2603 #[inline(always)]
2604 pub fn pll_40m_frequency() -> u32 {
2605 40000000
2606 }
2607 pub fn pll_40m_source_frequency() -> u32 {
2608 cpu_clk_frequency()
2609 }
2610 pub fn request_pll_60m(clocks: &mut ClockTree) {
2611 trace!("Requesting PLL_60M");
2612 if increment_reference_count(&mut clocks.pll_60m_refcount) {
2613 trace!("Enabling PLL_60M");
2614 request_cpu_clk(clocks);
2615 enable_pll_60m_impl(clocks, true);
2616 }
2617 }
2618 pub fn release_pll_60m(clocks: &mut ClockTree) {
2619 trace!("Releasing PLL_60M");
2620 if decrement_reference_count(&mut clocks.pll_60m_refcount) {
2621 trace!("Disabling PLL_60M");
2622 enable_pll_60m_impl(clocks, false);
2623 release_cpu_clk(clocks);
2624 }
2625 }
2626 #[inline(always)]
2627 pub fn pll_60m_frequency() -> u32 {
2628 60000000
2629 }
2630 pub fn pll_60m_source_frequency() -> u32 {
2631 cpu_clk_frequency()
2632 }
2633 pub fn request_pll_80m(clocks: &mut ClockTree) {
2634 trace!("Enabling PLL_80M");
2635 request_cpu_clk(clocks);
2636 enable_pll_80m_impl(clocks, true);
2637 }
2638 pub fn release_pll_80m(clocks: &mut ClockTree) {
2639 trace!("Disabling PLL_80M");
2640 enable_pll_80m_impl(clocks, false);
2641 release_cpu_clk(clocks);
2642 }
2643 #[inline(always)]
2644 pub fn pll_80m_frequency() -> u32 {
2645 80000000
2646 }
2647 pub fn pll_80m_source_frequency() -> u32 {
2648 cpu_clk_frequency()
2649 }
2650 pub fn request_cpu_div2(clocks: &mut ClockTree) {
2651 trace!("Enabling CPU_DIV2");
2652 request_cpu_clk(clocks);
2653 enable_cpu_div2_impl(clocks, true);
2654 }
2655 pub fn release_cpu_div2(clocks: &mut ClockTree) {
2656 trace!("Disabling CPU_DIV2");
2657 enable_cpu_div2_impl(clocks, false);
2658 release_cpu_clk(clocks);
2659 }
2660 #[inline(always)]
2661 pub fn cpu_div2_frequency() -> u32 {
2662 (cpu_clk_frequency() / 2)
2663 }
2664 pub fn cpu_div2_source_frequency() -> u32 {
2665 cpu_clk_frequency()
2666 }
2667 pub fn configure_rc_fast_clk_div_n(clocks: &mut ClockTree, config: RcFastClkDivNConfig) {
2668 let old_config = clocks.rc_fast_clk_div_n.replace(config);
2669 refresh_rc_fast_clk_div_n_downstream(clocks);
2670 configure_rc_fast_clk_div_n_impl(clocks, old_config, config);
2671 }
2672 pub fn rc_fast_clk_div_n_config(clocks: &mut ClockTree) -> Option<RcFastClkDivNConfig> {
2673 clocks.rc_fast_clk_div_n
2674 }
2675 pub fn request_rc_fast_clk_div_n(clocks: &mut ClockTree) {
2676 trace!("Enabling RC_FAST_CLK_DIV_N");
2677 request_rc_fast_clk(clocks);
2678 enable_rc_fast_clk_div_n_impl(clocks, true);
2679 }
2680 pub fn release_rc_fast_clk_div_n(clocks: &mut ClockTree) {
2681 trace!("Disabling RC_FAST_CLK_DIV_N");
2682 enable_rc_fast_clk_div_n_impl(clocks, false);
2683 release_rc_fast_clk(clocks);
2684 }
2685 pub fn rc_fast_clk_div_n_config_frequency(config: RcFastClkDivNConfig) -> u32 {
2686 (rc_fast_clk_frequency() / (config.divisor() + 1))
2687 }
2688 #[inline(always)]
2689 pub fn rc_fast_clk_div_n_frequency() -> u32 {
2690 RC_FAST_CLK_DIV_N_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2691 }
2692 pub fn rc_fast_clk_div_n_source_frequency() -> u32 {
2693 rc_fast_clk_frequency()
2694 }
2695 pub fn request_xtal_div_clk(clocks: &mut ClockTree) {
2696 trace!("Enabling XTAL_DIV_CLK");
2697 request_xtal_clk(clocks);
2698 enable_xtal_div_clk_impl(clocks, true);
2699 }
2700 pub fn release_xtal_div_clk(clocks: &mut ClockTree) {
2701 trace!("Disabling XTAL_DIV_CLK");
2702 enable_xtal_div_clk_impl(clocks, false);
2703 release_xtal_clk(clocks);
2704 }
2705 #[inline(always)]
2706 pub fn xtal_div_clk_frequency() -> u32 {
2707 (xtal_clk_frequency() / 2)
2708 }
2709 pub fn xtal_div_clk_source_frequency() -> u32 {
2710 xtal_clk_frequency()
2711 }
2712 pub fn configure_rtc_slow_clk(clocks: &mut ClockTree, new_selector: RtcSlowClkConfig) {
2713 let old_selector = clocks.rtc_slow_clk.replace(new_selector);
2714 refresh_rtc_slow_clk_downstream(clocks);
2715 match new_selector {
2716 RtcSlowClkConfig::OscSlow => request_osc_slow_clk(clocks),
2717 RtcSlowClkConfig::RcSlow => request_rc_slow_clk(clocks),
2718 RtcSlowClkConfig::RcFast => request_rc_fast_div_clk(clocks),
2719 }
2720 configure_rtc_slow_clk_impl(clocks, old_selector, new_selector);
2721 if let Some(old_selector) = old_selector {
2722 match old_selector {
2723 RtcSlowClkConfig::OscSlow => release_osc_slow_clk(clocks),
2724 RtcSlowClkConfig::RcSlow => release_rc_slow_clk(clocks),
2725 RtcSlowClkConfig::RcFast => release_rc_fast_div_clk(clocks),
2726 }
2727 }
2728 }
2729 pub fn rtc_slow_clk_config(clocks: &mut ClockTree) -> Option<RtcSlowClkConfig> {
2730 clocks.rtc_slow_clk
2731 }
2732 pub fn request_rtc_slow_clk(clocks: &mut ClockTree) {
2733 trace!("Enabling RTC_SLOW_CLK");
2734 match unwrap!(clocks.rtc_slow_clk) {
2735 RtcSlowClkConfig::OscSlow => request_osc_slow_clk(clocks),
2736 RtcSlowClkConfig::RcSlow => request_rc_slow_clk(clocks),
2737 RtcSlowClkConfig::RcFast => request_rc_fast_div_clk(clocks),
2738 }
2739 enable_rtc_slow_clk_impl(clocks, true);
2740 }
2741 pub fn release_rtc_slow_clk(clocks: &mut ClockTree) {
2742 trace!("Disabling RTC_SLOW_CLK");
2743 enable_rtc_slow_clk_impl(clocks, false);
2744 match unwrap!(clocks.rtc_slow_clk) {
2745 RtcSlowClkConfig::OscSlow => release_osc_slow_clk(clocks),
2746 RtcSlowClkConfig::RcSlow => release_rc_slow_clk(clocks),
2747 RtcSlowClkConfig::RcFast => release_rc_fast_div_clk(clocks),
2748 }
2749 }
2750 pub fn rtc_slow_clk_config_frequency(config: RtcSlowClkConfig) -> u32 {
2751 match config {
2752 RtcSlowClkConfig::OscSlow => osc_slow_clk_frequency(),
2753 RtcSlowClkConfig::RcSlow => rc_slow_clk_frequency(),
2754 RtcSlowClkConfig::RcFast => rc_fast_div_clk_frequency(),
2755 }
2756 }
2757 #[inline(always)]
2758 pub fn rtc_slow_clk_frequency() -> u32 {
2759 RTC_SLOW_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2760 }
2761 pub fn rtc_slow_clk_source_frequency(source: RtcSlowClkConfig) -> u32 {
2762 rtc_slow_clk_config_frequency(source)
2763 }
2764 pub fn request_ble_lp_xtal_clk(clocks: &mut ClockTree) {
2765 trace!("Enabling BLE_LP_XTAL_CLK");
2766 request_xtal_clk(clocks);
2767 enable_ble_lp_xtal_clk_impl(clocks, true);
2768 }
2769 pub fn release_ble_lp_xtal_clk(clocks: &mut ClockTree) {
2770 trace!("Disabling BLE_LP_XTAL_CLK");
2771 enable_ble_lp_xtal_clk_impl(clocks, false);
2772 release_xtal_clk(clocks);
2773 }
2774 #[inline(always)]
2775 pub fn ble_lp_xtal_clk_frequency() -> u32 {
2776 (xtal_clk_frequency() / 5)
2777 }
2778 pub fn ble_lp_xtal_clk_source_frequency() -> u32 {
2779 xtal_clk_frequency()
2780 }
2781 pub fn request_ble_lp_rc_slow_clk(clocks: &mut ClockTree) {
2782 trace!("Enabling BLE_LP_RC_SLOW_CLK");
2783 request_rc_slow_clk(clocks);
2784 enable_ble_lp_rc_slow_clk_impl(clocks, true);
2785 }
2786 pub fn release_ble_lp_rc_slow_clk(clocks: &mut ClockTree) {
2787 trace!("Disabling BLE_LP_RC_SLOW_CLK");
2788 enable_ble_lp_rc_slow_clk_impl(clocks, false);
2789 release_rc_slow_clk(clocks);
2790 }
2791 #[inline(always)]
2792 pub fn ble_lp_rc_slow_clk_frequency() -> u32 {
2793 (rc_slow_clk_frequency() / 5)
2794 }
2795 pub fn ble_lp_rc_slow_clk_source_frequency() -> u32 {
2796 rc_slow_clk_frequency()
2797 }
2798 pub fn configure_ble_lp_clk(clocks: &mut ClockTree, config: BleLpClkConfig) {
2799 let old_config = clocks.ble_lp_clk.replace(config);
2800 refresh_ble_lp_clk_downstream(clocks);
2801 let active = clocks.ble_lp_clk_refcount > 0;
2802 if active {
2803 match config.sclk {
2804 BleLpClkSclk::Xtal => request_ble_lp_xtal_clk(clocks),
2805 BleLpClkSclk::RcSlow => request_ble_lp_rc_slow_clk(clocks),
2806 }
2807 }
2808 configure_ble_lp_clk_impl(clocks, old_config, config);
2809 if active && let Some(old_config) = old_config {
2810 match old_config.sclk {
2811 BleLpClkSclk::Xtal => release_ble_lp_xtal_clk(clocks),
2812 BleLpClkSclk::RcSlow => release_ble_lp_rc_slow_clk(clocks),
2813 }
2814 }
2815 }
2816 pub fn ble_lp_clk_config(clocks: &mut ClockTree) -> Option<BleLpClkConfig> {
2817 clocks.ble_lp_clk
2818 }
2819 pub fn request_ble_lp_clk(clocks: &mut ClockTree) {
2820 trace!("Requesting BLE_LP_CLK");
2821 if increment_reference_count(&mut clocks.ble_lp_clk_refcount) {
2822 trace!("Enabling BLE_LP_CLK");
2823 match unwrap!(clocks.ble_lp_clk).sclk {
2824 BleLpClkSclk::Xtal => request_ble_lp_xtal_clk(clocks),
2825 BleLpClkSclk::RcSlow => request_ble_lp_rc_slow_clk(clocks),
2826 }
2827 enable_ble_lp_clk_impl(clocks, true);
2828 }
2829 }
2830 pub fn release_ble_lp_clk(clocks: &mut ClockTree) {
2831 trace!("Releasing BLE_LP_CLK");
2832 if decrement_reference_count(&mut clocks.ble_lp_clk_refcount) {
2833 trace!("Disabling BLE_LP_CLK");
2834 enable_ble_lp_clk_impl(clocks, false);
2835 match unwrap!(clocks.ble_lp_clk).sclk {
2836 BleLpClkSclk::Xtal => release_ble_lp_xtal_clk(clocks),
2837 BleLpClkSclk::RcSlow => release_ble_lp_rc_slow_clk(clocks),
2838 }
2839 }
2840 }
2841 pub fn ble_lp_clk_config_frequency(config: BleLpClkConfig) -> u32 {
2842 (match config.sclk {
2843 BleLpClkSclk::Xtal => ble_lp_xtal_clk_frequency(),
2844 BleLpClkSclk::RcSlow => ble_lp_rc_slow_clk_frequency(),
2845 } / (config.divisor() + 1))
2846 }
2847 #[inline(always)]
2848 pub fn ble_lp_clk_frequency() -> u32 {
2849 BLE_LP_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2850 }
2851 pub fn ble_lp_clk_source_frequency(sclk: BleLpClkSclk) -> u32 {
2852 match sclk {
2853 BleLpClkSclk::Xtal => ble_lp_xtal_clk_frequency(),
2854 BleLpClkSclk::RcSlow => ble_lp_rc_slow_clk_frequency(),
2855 }
2856 }
2857 pub fn configure_rtc_fast_clk(clocks: &mut ClockTree, new_selector: RtcFastClkConfig) {
2858 let old_selector = clocks.rtc_fast_clk.replace(new_selector);
2859 refresh_rtc_fast_clk_downstream(clocks);
2860 let active = clocks.rtc_fast_clk_refcount > 0;
2861 if active {
2862 match new_selector {
2863 RtcFastClkConfig::Xtal => request_xtal_div_clk(clocks),
2864 RtcFastClkConfig::Rc => request_rc_fast_clk_div_n(clocks),
2865 }
2866 }
2867 configure_rtc_fast_clk_impl(clocks, old_selector, new_selector);
2868 if active && let Some(old_selector) = old_selector {
2869 match old_selector {
2870 RtcFastClkConfig::Xtal => release_xtal_div_clk(clocks),
2871 RtcFastClkConfig::Rc => release_rc_fast_clk_div_n(clocks),
2872 }
2873 }
2874 }
2875 pub fn rtc_fast_clk_config(clocks: &mut ClockTree) -> Option<RtcFastClkConfig> {
2876 clocks.rtc_fast_clk
2877 }
2878 pub fn request_rtc_fast_clk(clocks: &mut ClockTree) {
2879 trace!("Requesting RTC_FAST_CLK");
2880 if increment_reference_count(&mut clocks.rtc_fast_clk_refcount) {
2881 trace!("Enabling RTC_FAST_CLK");
2882 match unwrap!(clocks.rtc_fast_clk) {
2883 RtcFastClkConfig::Xtal => request_xtal_div_clk(clocks),
2884 RtcFastClkConfig::Rc => request_rc_fast_clk_div_n(clocks),
2885 }
2886 enable_rtc_fast_clk_impl(clocks, true);
2887 }
2888 }
2889 pub fn release_rtc_fast_clk(clocks: &mut ClockTree) {
2890 trace!("Releasing RTC_FAST_CLK");
2891 if decrement_reference_count(&mut clocks.rtc_fast_clk_refcount) {
2892 trace!("Disabling RTC_FAST_CLK");
2893 enable_rtc_fast_clk_impl(clocks, false);
2894 match unwrap!(clocks.rtc_fast_clk) {
2895 RtcFastClkConfig::Xtal => release_xtal_div_clk(clocks),
2896 RtcFastClkConfig::Rc => release_rc_fast_clk_div_n(clocks),
2897 }
2898 }
2899 }
2900 pub fn rtc_fast_clk_config_frequency(config: RtcFastClkConfig) -> u32 {
2901 match config {
2902 RtcFastClkConfig::Xtal => xtal_div_clk_frequency(),
2903 RtcFastClkConfig::Rc => rc_fast_clk_div_n_frequency(),
2904 }
2905 }
2906 #[inline(always)]
2907 pub fn rtc_fast_clk_frequency() -> u32 {
2908 RTC_FAST_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2909 }
2910 pub fn rtc_fast_clk_source_frequency(source: RtcFastClkConfig) -> u32 {
2911 rtc_fast_clk_config_frequency(source)
2912 }
2913 pub fn configure_low_power_clk(clocks: &mut ClockTree, new_selector: LowPowerClkConfig) {
2914 let old_selector = clocks.low_power_clk.replace(new_selector);
2915 refresh_low_power_clk_downstream(clocks);
2916 let active = clocks.low_power_clk_refcount > 0;
2917 if active {
2918 match new_selector {
2919 LowPowerClkConfig::Xtal => request_xtal_clk(clocks),
2920 LowPowerClkConfig::RcFast => request_rc_fast_clk(clocks),
2921 LowPowerClkConfig::OscSlow => request_osc_slow_clk(clocks),
2922 LowPowerClkConfig::RtcSlow => request_rtc_slow_clk(clocks),
2923 }
2924 }
2925 configure_low_power_clk_impl(clocks, old_selector, new_selector);
2926 if active && let Some(old_selector) = old_selector {
2927 match old_selector {
2928 LowPowerClkConfig::Xtal => release_xtal_clk(clocks),
2929 LowPowerClkConfig::RcFast => release_rc_fast_clk(clocks),
2930 LowPowerClkConfig::OscSlow => release_osc_slow_clk(clocks),
2931 LowPowerClkConfig::RtcSlow => release_rtc_slow_clk(clocks),
2932 }
2933 }
2934 }
2935 pub fn low_power_clk_config(clocks: &mut ClockTree) -> Option<LowPowerClkConfig> {
2936 clocks.low_power_clk
2937 }
2938 pub fn request_low_power_clk(clocks: &mut ClockTree) {
2939 trace!("Requesting LOW_POWER_CLK");
2940 if increment_reference_count(&mut clocks.low_power_clk_refcount) {
2941 trace!("Enabling LOW_POWER_CLK");
2942 match unwrap!(clocks.low_power_clk) {
2943 LowPowerClkConfig::Xtal => request_xtal_clk(clocks),
2944 LowPowerClkConfig::RcFast => request_rc_fast_clk(clocks),
2945 LowPowerClkConfig::OscSlow => request_osc_slow_clk(clocks),
2946 LowPowerClkConfig::RtcSlow => request_rtc_slow_clk(clocks),
2947 }
2948 enable_low_power_clk_impl(clocks, true);
2949 }
2950 }
2951 pub fn release_low_power_clk(clocks: &mut ClockTree) {
2952 trace!("Releasing LOW_POWER_CLK");
2953 if decrement_reference_count(&mut clocks.low_power_clk_refcount) {
2954 trace!("Disabling LOW_POWER_CLK");
2955 enable_low_power_clk_impl(clocks, false);
2956 match unwrap!(clocks.low_power_clk) {
2957 LowPowerClkConfig::Xtal => release_xtal_clk(clocks),
2958 LowPowerClkConfig::RcFast => release_rc_fast_clk(clocks),
2959 LowPowerClkConfig::OscSlow => release_osc_slow_clk(clocks),
2960 LowPowerClkConfig::RtcSlow => release_rtc_slow_clk(clocks),
2961 }
2962 }
2963 }
2964 pub fn low_power_clk_config_frequency(config: LowPowerClkConfig) -> u32 {
2965 match config {
2966 LowPowerClkConfig::Xtal => xtal_clk_frequency(),
2967 LowPowerClkConfig::RcFast => rc_fast_clk_frequency(),
2968 LowPowerClkConfig::OscSlow => osc_slow_clk_frequency(),
2969 LowPowerClkConfig::RtcSlow => rtc_slow_clk_frequency(),
2970 }
2971 }
2972 #[inline(always)]
2973 pub fn low_power_clk_frequency() -> u32 {
2974 LOW_POWER_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2975 }
2976 pub fn low_power_clk_source_frequency(source: LowPowerClkConfig) -> u32 {
2977 low_power_clk_config_frequency(source)
2978 }
2979 pub fn request_uart_mem_clk(clocks: &mut ClockTree) {
2980 trace!("Requesting UART_MEM_CLK");
2981 if increment_reference_count(&mut clocks.uart_mem_clk_refcount) {
2982 trace!("Enabling UART_MEM_CLK");
2983 request_xtal_clk(clocks);
2984 enable_uart_mem_clk_impl(clocks, true);
2985 }
2986 }
2987 pub fn release_uart_mem_clk(clocks: &mut ClockTree) {
2988 trace!("Releasing UART_MEM_CLK");
2989 if decrement_reference_count(&mut clocks.uart_mem_clk_refcount) {
2990 trace!("Disabling UART_MEM_CLK");
2991 enable_uart_mem_clk_impl(clocks, false);
2992 release_xtal_clk(clocks);
2993 }
2994 }
2995 #[inline(always)]
2996 pub fn uart_mem_clk_frequency() -> u32 {
2997 xtal_clk_frequency()
2998 }
2999 pub fn uart_mem_clk_source_frequency(source: UartMemClkConfig) -> u32 {
3000 match source {
3001 UartMemClkConfig::Xtal => xtal_clk_frequency(),
3002 }
3003 }
3004 pub fn configure_timg_calibration_clock(
3005 clocks: &mut ClockTree,
3006 new_selector: TimgCalibrationClockConfig,
3007 ) {
3008 let old_selector = clocks.timg_calibration_clock.replace(new_selector);
3009 refresh_timg_calibration_clock_downstream(clocks);
3010 let active = clocks.timg_calibration_clock_refcount > 0;
3011 if active {
3012 match new_selector {
3013 TimgCalibrationClockConfig::RcSlowClk => request_rc_slow_clk(clocks),
3014 TimgCalibrationClockConfig::RcFastDivClk => request_rc_fast_div_clk(clocks),
3015 TimgCalibrationClockConfig::Osc32kClk => request_osc_slow_clk(clocks),
3016 }
3017 }
3018 configure_timg_calibration_clock_impl(clocks, old_selector, new_selector);
3019 if active && let Some(old_selector) = old_selector {
3020 match old_selector {
3021 TimgCalibrationClockConfig::RcSlowClk => release_rc_slow_clk(clocks),
3022 TimgCalibrationClockConfig::RcFastDivClk => release_rc_fast_div_clk(clocks),
3023 TimgCalibrationClockConfig::Osc32kClk => release_osc_slow_clk(clocks),
3024 }
3025 }
3026 }
3027 pub fn timg_calibration_clock_config(
3028 clocks: &mut ClockTree,
3029 ) -> Option<TimgCalibrationClockConfig> {
3030 clocks.timg_calibration_clock
3031 }
3032 pub fn request_timg_calibration_clock(clocks: &mut ClockTree) {
3033 trace!("Requesting TIMG_CALIBRATION_CLOCK");
3034 if increment_reference_count(&mut clocks.timg_calibration_clock_refcount) {
3035 trace!("Enabling TIMG_CALIBRATION_CLOCK");
3036 crate::rtc_cntl::WakeLock::acquire();
3037 match unwrap!(clocks.timg_calibration_clock) {
3038 TimgCalibrationClockConfig::RcSlowClk => request_rc_slow_clk(clocks),
3039 TimgCalibrationClockConfig::RcFastDivClk => request_rc_fast_div_clk(clocks),
3040 TimgCalibrationClockConfig::Osc32kClk => request_osc_slow_clk(clocks),
3041 }
3042 enable_timg_calibration_clock_impl(clocks, true);
3043 }
3044 }
3045 pub fn release_timg_calibration_clock(clocks: &mut ClockTree) {
3046 trace!("Releasing TIMG_CALIBRATION_CLOCK");
3047 if decrement_reference_count(&mut clocks.timg_calibration_clock_refcount) {
3048 trace!("Disabling TIMG_CALIBRATION_CLOCK");
3049 crate::rtc_cntl::WakeLock::release();
3050 enable_timg_calibration_clock_impl(clocks, false);
3051 match unwrap!(clocks.timg_calibration_clock) {
3052 TimgCalibrationClockConfig::RcSlowClk => release_rc_slow_clk(clocks),
3053 TimgCalibrationClockConfig::RcFastDivClk => release_rc_fast_div_clk(clocks),
3054 TimgCalibrationClockConfig::Osc32kClk => release_osc_slow_clk(clocks),
3055 }
3056 }
3057 }
3058 pub fn timg_calibration_clock_config_frequency(config: TimgCalibrationClockConfig) -> u32 {
3059 match config {
3060 TimgCalibrationClockConfig::RcSlowClk => rc_slow_clk_frequency(),
3061 TimgCalibrationClockConfig::RcFastDivClk => rc_fast_div_clk_frequency(),
3062 TimgCalibrationClockConfig::Osc32kClk => osc_slow_clk_frequency(),
3063 }
3064 }
3065 #[inline(always)]
3066 pub fn timg_calibration_clock_frequency() -> u32 {
3067 TIMG_CALIBRATION_CLOCK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
3068 }
3069 pub fn timg_calibration_clock_source_frequency(source: TimgCalibrationClockConfig) -> u32 {
3070 timg_calibration_clock_config_frequency(source)
3071 }
3072 impl AdcInstance {
3073 pub fn request_function_clock(self, clocks: &mut ClockTree) {
3074 trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3075 if increment_reference_count(&mut clocks.adc_function_clock_refcount[self as usize])
3076 {
3077 trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3078 request_apb_clk(clocks);
3079 self.enable_function_clock_impl(clocks, true);
3080 }
3081 }
3082 pub fn release_function_clock(self, clocks: &mut ClockTree) {
3083 trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3084 if decrement_reference_count(&mut clocks.adc_function_clock_refcount[self as usize])
3085 {
3086 trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3087 self.enable_function_clock_impl(clocks, false);
3088 release_apb_clk(clocks);
3089 }
3090 }
3091 #[inline(always)]
3092 pub fn function_clock_frequency(self) -> u32 {
3093 apb_clk_frequency()
3094 }
3095 pub fn function_clock_source_frequency() -> u32 {
3096 apb_clk_frequency()
3097 }
3098 }
3099 impl I2cInstance {
3100 pub fn configure_function_clock(
3101 self,
3102 clocks: &mut ClockTree,
3103 config: I2cFunctionClockConfig,
3104 ) {
3105 let old_config = clocks.i2c_function_clock[self as usize].replace(config);
3106 refresh_i2c_function_clock_downstream(clocks, self);
3107 let active = clocks.i2c_function_clock_refcount[self as usize] > 0;
3108 if active {
3109 match config.sclk {
3110 I2cFunctionClockSclk::Xtal => request_xtal_clk(clocks),
3111 I2cFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
3112 }
3113 }
3114 self.configure_function_clock_impl(clocks, old_config, config);
3115 if active && let Some(old_config) = old_config {
3116 match old_config.sclk {
3117 I2cFunctionClockSclk::Xtal => release_xtal_clk(clocks),
3118 I2cFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
3119 }
3120 }
3121 }
3122 pub fn function_clock_config(
3123 self,
3124 clocks: &mut ClockTree,
3125 ) -> Option<I2cFunctionClockConfig> {
3126 clocks.i2c_function_clock[self as usize]
3127 }
3128 pub fn request_function_clock(self, clocks: &mut ClockTree) {
3129 trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3130 if increment_reference_count(&mut clocks.i2c_function_clock_refcount[self as usize])
3131 {
3132 trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3133 crate::rtc_cntl::WakeLock::acquire();
3134 match unwrap!(clocks.i2c_function_clock[self as usize]).sclk {
3135 I2cFunctionClockSclk::Xtal => request_xtal_clk(clocks),
3136 I2cFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
3137 }
3138 self.enable_function_clock_impl(clocks, true);
3139 }
3140 }
3141 pub fn release_function_clock(self, clocks: &mut ClockTree) {
3142 trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3143 if decrement_reference_count(&mut clocks.i2c_function_clock_refcount[self as usize])
3144 {
3145 trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3146 crate::rtc_cntl::WakeLock::release();
3147 self.enable_function_clock_impl(clocks, false);
3148 match unwrap!(clocks.i2c_function_clock[self as usize]).sclk {
3149 I2cFunctionClockSclk::Xtal => release_xtal_clk(clocks),
3150 I2cFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
3151 }
3152 }
3153 }
3154 pub fn function_clock_config_frequency(config: I2cFunctionClockConfig) -> u32 {
3155 (match config.sclk {
3156 I2cFunctionClockSclk::Xtal => xtal_clk_frequency(),
3157 I2cFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
3158 } / (config.div_num() + 1))
3159 }
3160 #[inline(always)]
3161 pub fn function_clock_frequency(self) -> u32 {
3162 I2C_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
3163 .load(::core::sync::atomic::Ordering::Acquire)
3164 }
3165 pub fn function_clock_source_frequency(sclk: I2cFunctionClockSclk) -> u32 {
3166 match sclk {
3167 I2cFunctionClockSclk::Xtal => xtal_clk_frequency(),
3168 I2cFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
3169 }
3170 }
3171 }
3172 impl SpiInstance {
3173 pub fn configure_function_clock(
3174 self,
3175 clocks: &mut ClockTree,
3176 new_selector: SpiFunctionClockConfig,
3177 ) {
3178 let old_selector = clocks.spi_function_clock[self as usize].replace(new_selector);
3179 refresh_spi_function_clock_downstream(clocks, self);
3180 let active = clocks.spi_function_clock_refcount[self as usize] > 0;
3181 if active {
3182 match new_selector {
3183 SpiFunctionClockConfig::Xtal => request_xtal_clk(clocks),
3184 SpiFunctionClockConfig::Pll40m => request_pll_40m(clocks),
3185 }
3186 }
3187 self.configure_function_clock_impl(clocks, old_selector, new_selector);
3188 if active && let Some(old_selector) = old_selector {
3189 match old_selector {
3190 SpiFunctionClockConfig::Xtal => release_xtal_clk(clocks),
3191 SpiFunctionClockConfig::Pll40m => release_pll_40m(clocks),
3192 }
3193 }
3194 }
3195 pub fn function_clock_config(
3196 self,
3197 clocks: &mut ClockTree,
3198 ) -> Option<SpiFunctionClockConfig> {
3199 clocks.spi_function_clock[self as usize]
3200 }
3201 pub fn request_function_clock(self, clocks: &mut ClockTree) {
3202 trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3203 if increment_reference_count(&mut clocks.spi_function_clock_refcount[self as usize])
3204 {
3205 trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3206 crate::rtc_cntl::WakeLock::acquire();
3207 match unwrap!(clocks.spi_function_clock[self as usize]) {
3208 SpiFunctionClockConfig::Xtal => request_xtal_clk(clocks),
3209 SpiFunctionClockConfig::Pll40m => request_pll_40m(clocks),
3210 }
3211 self.enable_function_clock_impl(clocks, true);
3212 }
3213 }
3214 pub fn release_function_clock(self, clocks: &mut ClockTree) {
3215 trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3216 if decrement_reference_count(&mut clocks.spi_function_clock_refcount[self as usize])
3217 {
3218 trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3219 crate::rtc_cntl::WakeLock::release();
3220 self.enable_function_clock_impl(clocks, false);
3221 match unwrap!(clocks.spi_function_clock[self as usize]) {
3222 SpiFunctionClockConfig::Xtal => release_xtal_clk(clocks),
3223 SpiFunctionClockConfig::Pll40m => release_pll_40m(clocks),
3224 }
3225 }
3226 }
3227 pub fn function_clock_config_frequency(config: SpiFunctionClockConfig) -> u32 {
3228 match config {
3229 SpiFunctionClockConfig::Xtal => xtal_clk_frequency(),
3230 SpiFunctionClockConfig::Pll40m => pll_40m_frequency(),
3231 }
3232 }
3233 #[inline(always)]
3234 pub fn function_clock_frequency(self) -> u32 {
3235 SPI_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
3236 .load(::core::sync::atomic::Ordering::Acquire)
3237 }
3238 pub fn function_clock_source_frequency(source: SpiFunctionClockConfig) -> u32 {
3239 Self::function_clock_config_frequency(source)
3240 }
3241 }
3242 impl TimgInstance {
3243 pub fn configure_function_clock(
3244 self,
3245 clocks: &mut ClockTree,
3246 new_selector: TimgFunctionClockConfig,
3247 ) {
3248 let old_selector = clocks.timg_function_clock[self as usize].replace(new_selector);
3249 refresh_timg_function_clock_downstream(clocks, self);
3250 let active = clocks.timg_function_clock_refcount[self as usize] > 0;
3251 if active {
3252 match new_selector {
3253 TimgFunctionClockConfig::XtalClk => request_xtal_clk(clocks),
3254 TimgFunctionClockConfig::Pll40m => request_pll_40m(clocks),
3255 }
3256 }
3257 self.configure_function_clock_impl(clocks, old_selector, new_selector);
3258 if active && let Some(old_selector) = old_selector {
3259 match old_selector {
3260 TimgFunctionClockConfig::XtalClk => release_xtal_clk(clocks),
3261 TimgFunctionClockConfig::Pll40m => release_pll_40m(clocks),
3262 }
3263 }
3264 }
3265 pub fn function_clock_config(
3266 self,
3267 clocks: &mut ClockTree,
3268 ) -> Option<TimgFunctionClockConfig> {
3269 clocks.timg_function_clock[self as usize]
3270 }
3271 pub fn request_function_clock(self, clocks: &mut ClockTree) {
3272 trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3273 if increment_reference_count(
3274 &mut clocks.timg_function_clock_refcount[self as usize],
3275 ) {
3276 trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3277 match unwrap!(clocks.timg_function_clock[self as usize]) {
3278 TimgFunctionClockConfig::XtalClk => request_xtal_clk(clocks),
3279 TimgFunctionClockConfig::Pll40m => request_pll_40m(clocks),
3280 }
3281 self.enable_function_clock_impl(clocks, true);
3282 }
3283 }
3284 pub fn release_function_clock(self, clocks: &mut ClockTree) {
3285 trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3286 if decrement_reference_count(
3287 &mut clocks.timg_function_clock_refcount[self as usize],
3288 ) {
3289 trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3290 self.enable_function_clock_impl(clocks, false);
3291 match unwrap!(clocks.timg_function_clock[self as usize]) {
3292 TimgFunctionClockConfig::XtalClk => release_xtal_clk(clocks),
3293 TimgFunctionClockConfig::Pll40m => release_pll_40m(clocks),
3294 }
3295 }
3296 }
3297 pub fn function_clock_config_frequency(config: TimgFunctionClockConfig) -> u32 {
3298 match config {
3299 TimgFunctionClockConfig::XtalClk => xtal_clk_frequency(),
3300 TimgFunctionClockConfig::Pll40m => pll_40m_frequency(),
3301 }
3302 }
3303 #[inline(always)]
3304 pub fn function_clock_frequency(self) -> u32 {
3305 TIMG_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
3306 .load(::core::sync::atomic::Ordering::Acquire)
3307 }
3308 pub fn function_clock_source_frequency(source: TimgFunctionClockConfig) -> u32 {
3309 Self::function_clock_config_frequency(source)
3310 }
3311 pub fn configure_wdt_clock(
3312 self,
3313 clocks: &mut ClockTree,
3314 new_selector: TimgWdtClockConfig,
3315 ) {
3316 let old_selector = clocks.timg_wdt_clock[self as usize].replace(new_selector);
3317 refresh_timg_wdt_clock_downstream(clocks, self);
3318 let active = clocks.timg_wdt_clock_refcount[self as usize] > 0;
3319 if active {
3320 match new_selector {
3321 TimgWdtClockConfig::Pll40m => request_pll_40m(clocks),
3322 TimgWdtClockConfig::XtalClk => request_xtal_clk(clocks),
3323 }
3324 }
3325 self.configure_wdt_clock_impl(clocks, old_selector, new_selector);
3326 if active && let Some(old_selector) = old_selector {
3327 match old_selector {
3328 TimgWdtClockConfig::Pll40m => release_pll_40m(clocks),
3329 TimgWdtClockConfig::XtalClk => release_xtal_clk(clocks),
3330 }
3331 }
3332 }
3333 pub fn wdt_clock_config(self, clocks: &mut ClockTree) -> Option<TimgWdtClockConfig> {
3334 clocks.timg_wdt_clock[self as usize]
3335 }
3336 pub fn request_wdt_clock(self, clocks: &mut ClockTree) {
3337 trace!("Requesting {:?}::WDT_CLOCK", self);
3338 if increment_reference_count(&mut clocks.timg_wdt_clock_refcount[self as usize]) {
3339 trace!("Enabling {:?}::WDT_CLOCK", self);
3340 match unwrap!(clocks.timg_wdt_clock[self as usize]) {
3341 TimgWdtClockConfig::Pll40m => request_pll_40m(clocks),
3342 TimgWdtClockConfig::XtalClk => request_xtal_clk(clocks),
3343 }
3344 self.enable_wdt_clock_impl(clocks, true);
3345 }
3346 }
3347 pub fn release_wdt_clock(self, clocks: &mut ClockTree) {
3348 trace!("Releasing {:?}::WDT_CLOCK", self);
3349 if decrement_reference_count(&mut clocks.timg_wdt_clock_refcount[self as usize]) {
3350 trace!("Disabling {:?}::WDT_CLOCK", self);
3351 self.enable_wdt_clock_impl(clocks, false);
3352 match unwrap!(clocks.timg_wdt_clock[self as usize]) {
3353 TimgWdtClockConfig::Pll40m => release_pll_40m(clocks),
3354 TimgWdtClockConfig::XtalClk => release_xtal_clk(clocks),
3355 }
3356 }
3357 }
3358 pub fn wdt_clock_config_frequency(config: TimgWdtClockConfig) -> u32 {
3359 match config {
3360 TimgWdtClockConfig::Pll40m => pll_40m_frequency(),
3361 TimgWdtClockConfig::XtalClk => xtal_clk_frequency(),
3362 }
3363 }
3364 #[inline(always)]
3365 pub fn wdt_clock_frequency(self) -> u32 {
3366 TIMG_WDT_CLOCK_FREQ_CACHE[self as usize]
3367 .load(::core::sync::atomic::Ordering::Acquire)
3368 }
3369 pub fn wdt_clock_source_frequency(source: TimgWdtClockConfig) -> u32 {
3370 Self::wdt_clock_config_frequency(source)
3371 }
3372 }
3373 impl UartInstance {
3374 pub fn configure_function_clock(
3375 self,
3376 clocks: &mut ClockTree,
3377 config: UartFunctionClockConfig,
3378 ) {
3379 let old_config = clocks.uart_function_clock[self as usize].replace(config);
3380 refresh_uart_function_clock_downstream(clocks, self);
3381 let active = clocks.uart_function_clock_refcount[self as usize] > 0;
3382 if active {
3383 match config.sclk {
3384 UartFunctionClockSclk::PllF40m => request_pll_40m(clocks),
3385 UartFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
3386 UartFunctionClockSclk::Xtal => request_xtal_clk(clocks),
3387 }
3388 }
3389 self.configure_function_clock_impl(clocks, old_config, config);
3390 if active && let Some(old_config) = old_config {
3391 match old_config.sclk {
3392 UartFunctionClockSclk::PllF40m => release_pll_40m(clocks),
3393 UartFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
3394 UartFunctionClockSclk::Xtal => release_xtal_clk(clocks),
3395 }
3396 }
3397 }
3398 pub fn function_clock_config(
3399 self,
3400 clocks: &mut ClockTree,
3401 ) -> Option<UartFunctionClockConfig> {
3402 clocks.uart_function_clock[self as usize]
3403 }
3404 pub fn request_function_clock(self, clocks: &mut ClockTree) {
3405 trace!("Requesting {:?}::FUNCTION_CLOCK", self);
3406 if increment_reference_count(
3407 &mut clocks.uart_function_clock_refcount[self as usize],
3408 ) {
3409 trace!("Enabling {:?}::FUNCTION_CLOCK", self);
3410 match unwrap!(clocks.uart_function_clock[self as usize]).sclk {
3411 UartFunctionClockSclk::PllF40m => request_pll_40m(clocks),
3412 UartFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
3413 UartFunctionClockSclk::Xtal => request_xtal_clk(clocks),
3414 }
3415 self.enable_function_clock_impl(clocks, true);
3416 }
3417 }
3418 pub fn release_function_clock(self, clocks: &mut ClockTree) {
3419 trace!("Releasing {:?}::FUNCTION_CLOCK", self);
3420 if decrement_reference_count(
3421 &mut clocks.uart_function_clock_refcount[self as usize],
3422 ) {
3423 trace!("Disabling {:?}::FUNCTION_CLOCK", self);
3424 self.enable_function_clock_impl(clocks, false);
3425 match unwrap!(clocks.uart_function_clock[self as usize]).sclk {
3426 UartFunctionClockSclk::PllF40m => release_pll_40m(clocks),
3427 UartFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
3428 UartFunctionClockSclk::Xtal => release_xtal_clk(clocks),
3429 }
3430 }
3431 }
3432 pub fn function_clock_config_frequency(config: UartFunctionClockConfig) -> u32 {
3433 (match config.sclk {
3434 UartFunctionClockSclk::PllF40m => pll_40m_frequency(),
3435 UartFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
3436 UartFunctionClockSclk::Xtal => xtal_clk_frequency(),
3437 } / (config.div_num() + 1))
3438 }
3439 #[inline(always)]
3440 pub fn function_clock_frequency(self) -> u32 {
3441 UART_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
3442 .load(::core::sync::atomic::Ordering::Acquire)
3443 }
3444 pub fn function_clock_source_frequency(sclk: UartFunctionClockSclk) -> u32 {
3445 match sclk {
3446 UartFunctionClockSclk::PllF40m => pll_40m_frequency(),
3447 UartFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
3448 UartFunctionClockSclk::Xtal => xtal_clk_frequency(),
3449 }
3450 }
3451 pub fn request_mem_clock(self, clocks: &mut ClockTree) {
3452 trace!("Requesting {:?}::MEM_CLOCK", self);
3453 if increment_reference_count(&mut clocks.uart_mem_clock_refcount[self as usize]) {
3454 trace!("Enabling {:?}::MEM_CLOCK", self);
3455 request_uart_mem_clk(clocks);
3456 self.enable_mem_clock_impl(clocks, true);
3457 }
3458 }
3459 pub fn release_mem_clock(self, clocks: &mut ClockTree) {
3460 trace!("Releasing {:?}::MEM_CLOCK", self);
3461 if decrement_reference_count(&mut clocks.uart_mem_clock_refcount[self as usize]) {
3462 trace!("Disabling {:?}::MEM_CLOCK", self);
3463 self.enable_mem_clock_impl(clocks, false);
3464 release_uart_mem_clk(clocks);
3465 }
3466 }
3467 #[inline(always)]
3468 pub fn mem_clock_frequency(self) -> u32 {
3469 uart_mem_clk_frequency()
3470 }
3471 pub fn mem_clock_source_frequency() -> u32 {
3472 uart_mem_clk_frequency()
3473 }
3474 pub fn configure_baud_rate_generator(
3475 self,
3476 clocks: &mut ClockTree,
3477 config: UartBaudRateGeneratorConfig,
3478 ) {
3479 let old_config = clocks.uart_baud_rate_generator[self as usize].replace(config);
3480 refresh_uart_baud_rate_generator_downstream(clocks, self);
3481 self.configure_baud_rate_generator_impl(clocks, old_config, config);
3482 }
3483 pub fn baud_rate_generator_config(
3484 self,
3485 clocks: &mut ClockTree,
3486 ) -> Option<UartBaudRateGeneratorConfig> {
3487 clocks.uart_baud_rate_generator[self as usize]
3488 }
3489 pub fn request_baud_rate_generator(self, clocks: &mut ClockTree) {
3490 trace!("Requesting {:?}::BAUD_RATE_GENERATOR", self);
3491 if increment_reference_count(
3492 &mut clocks.uart_baud_rate_generator_refcount[self as usize],
3493 ) {
3494 trace!("Enabling {:?}::BAUD_RATE_GENERATOR", self);
3495 self.request_function_clock(clocks);
3496 self.enable_baud_rate_generator_impl(clocks, true);
3497 }
3498 }
3499 pub fn release_baud_rate_generator(self, clocks: &mut ClockTree) {
3500 trace!("Releasing {:?}::BAUD_RATE_GENERATOR", self);
3501 if decrement_reference_count(
3502 &mut clocks.uart_baud_rate_generator_refcount[self as usize],
3503 ) {
3504 trace!("Disabling {:?}::BAUD_RATE_GENERATOR", self);
3505 self.enable_baud_rate_generator_impl(clocks, false);
3506 self.release_function_clock(clocks);
3507 }
3508 }
3509 pub fn baud_rate_generator_config_frequency(
3510 self,
3511 config: UartBaudRateGeneratorConfig,
3512 ) -> u32 {
3513 ((self.function_clock_frequency() * 16)
3514 / ((config.integral() * 16) + config.fractional()))
3515 }
3516 #[inline(always)]
3517 pub fn baud_rate_generator_frequency(self) -> u32 {
3518 UART_BAUD_RATE_GENERATOR_FREQ_CACHE[self as usize]
3519 .load(::core::sync::atomic::Ordering::Acquire)
3520 }
3521 }
3522 impl TsensInstance {
3523 pub fn configure_sclk(self, clocks: &mut ClockTree, new_selector: TsensSclkConfig) {
3524 let old_selector = clocks.tsens_sclk[self as usize].replace(new_selector);
3525 refresh_tsens_sclk_downstream(clocks, self);
3526 let active = clocks.tsens_sclk_refcount[self as usize] > 0;
3527 if active {
3528 match new_selector {
3529 TsensSclkConfig::RcFast => request_rc_fast_clk(clocks),
3530 TsensSclkConfig::Xtal => request_xtal_clk(clocks),
3531 }
3532 }
3533 self.configure_sclk_impl(clocks, old_selector, new_selector);
3534 if active && let Some(old_selector) = old_selector {
3535 match old_selector {
3536 TsensSclkConfig::RcFast => release_rc_fast_clk(clocks),
3537 TsensSclkConfig::Xtal => release_xtal_clk(clocks),
3538 }
3539 }
3540 }
3541 pub fn sclk_config(self, clocks: &mut ClockTree) -> Option<TsensSclkConfig> {
3542 clocks.tsens_sclk[self as usize]
3543 }
3544 pub fn request_sclk(self, clocks: &mut ClockTree) {
3545 trace!("Requesting {:?}::SCLK", self);
3546 if increment_reference_count(&mut clocks.tsens_sclk_refcount[self as usize]) {
3547 trace!("Enabling {:?}::SCLK", self);
3548 match unwrap!(clocks.tsens_sclk[self as usize]) {
3549 TsensSclkConfig::RcFast => request_rc_fast_clk(clocks),
3550 TsensSclkConfig::Xtal => request_xtal_clk(clocks),
3551 }
3552 self.enable_sclk_impl(clocks, true);
3553 }
3554 }
3555 pub fn release_sclk(self, clocks: &mut ClockTree) {
3556 trace!("Releasing {:?}::SCLK", self);
3557 if decrement_reference_count(&mut clocks.tsens_sclk_refcount[self as usize]) {
3558 trace!("Disabling {:?}::SCLK", self);
3559 self.enable_sclk_impl(clocks, false);
3560 match unwrap!(clocks.tsens_sclk[self as usize]) {
3561 TsensSclkConfig::RcFast => release_rc_fast_clk(clocks),
3562 TsensSclkConfig::Xtal => release_xtal_clk(clocks),
3563 }
3564 }
3565 }
3566 pub fn sclk_config_frequency(config: TsensSclkConfig) -> u32 {
3567 match config {
3568 TsensSclkConfig::RcFast => rc_fast_clk_frequency(),
3569 TsensSclkConfig::Xtal => xtal_clk_frequency(),
3570 }
3571 }
3572 #[inline(always)]
3573 pub fn sclk_frequency(self) -> u32 {
3574 TSENS_SCLK_FREQ_CACHE[self as usize].load(::core::sync::atomic::Ordering::Acquire)
3575 }
3576 pub fn sclk_source_frequency(source: TsensSclkConfig) -> u32 {
3577 Self::sclk_config_frequency(source)
3578 }
3579 }
3580 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
3588 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
3589 #[instability::unstable]
3590 pub struct ClockConfig {
3591 pub xtal_clk: Option<XtalClkConfig>,
3593 pub system_pre_div: Option<SystemPreDivConfig>,
3595 pub cpu_pll_div: Option<CpuPllDivConfig>,
3597 pub cpu_clk: Option<CpuClkConfig>,
3599 pub rc_fast_clk_div_n: Option<RcFastClkDivNConfig>,
3601 pub rtc_slow_clk: Option<RtcSlowClkConfig>,
3603 pub ble_lp_clk: Option<BleLpClkConfig>,
3605 pub rtc_fast_clk: Option<RtcFastClkConfig>,
3607 pub low_power_clk: Option<LowPowerClkConfig>,
3609 pub timg_calibration_clock: Option<TimgCalibrationClockConfig>,
3611 }
3612 impl ClockConfig {
3613 fn apply(&self, clocks: &mut ClockTree) {
3614 if let Some(config) = self.xtal_clk {
3615 configure_xtal_clk(clocks, config);
3616 }
3617 if let Some(config) = self.system_pre_div {
3618 configure_system_pre_div(clocks, config);
3619 }
3620 if let Some(config) = self.cpu_pll_div {
3621 configure_cpu_pll_div(clocks, config);
3622 }
3623 if let Some(config) = self.cpu_clk {
3624 configure_cpu_clk(clocks, config);
3625 }
3626 if let Some(config) = self.rc_fast_clk_div_n {
3627 configure_rc_fast_clk_div_n(clocks, config);
3628 }
3629 if let Some(config) = self.rtc_slow_clk {
3630 configure_rtc_slow_clk(clocks, config);
3631 }
3632 if let Some(config) = self.ble_lp_clk {
3633 configure_ble_lp_clk(clocks, config);
3634 }
3635 if let Some(config) = self.rtc_fast_clk {
3636 configure_rtc_fast_clk(clocks, config);
3637 }
3638 if let Some(config) = self.low_power_clk {
3639 configure_low_power_clk(clocks, config);
3640 }
3641 if let Some(config) = self.timg_calibration_clock {
3642 configure_timg_calibration_clock(clocks, config);
3643 }
3644 }
3645 }
3646 fn increment_reference_count(refcount: &mut u32) -> bool {
3647 let first = *refcount == 0;
3648 *refcount = unwrap!(refcount.checked_add(1), "Reference count overflow");
3649 first
3650 }
3651 fn decrement_reference_count(refcount: &mut u32) -> bool {
3652 *refcount = refcount.saturating_sub(1);
3653 let last = *refcount == 0;
3654 last
3655 }
3656 fn refresh_xtal_clk_downstream(clocks: &mut ClockTree) {
3657 if let Some(config) = clocks.xtal_clk {
3658 XTAL_CLK_FREQ_CACHE.store(
3659 xtal_clk_config_frequency(config),
3660 ::core::sync::atomic::Ordering::Release,
3661 );
3662 }
3663 refresh_system_pre_div_in_downstream(clocks);
3664 refresh_cpu_pll_div_downstream(clocks);
3665 refresh_ble_lp_clk_downstream(clocks);
3666 refresh_rtc_fast_clk_downstream(clocks);
3667 refresh_low_power_clk_downstream(clocks);
3668 for child_instance in [I2cInstance::I2c0] {
3669 refresh_i2c_function_clock_downstream(clocks, child_instance);
3670 }
3671 for child_instance in [SpiInstance::Spi2] {
3672 refresh_spi_function_clock_downstream(clocks, child_instance);
3673 }
3674 for child_instance in [TimgInstance::Timg0] {
3675 refresh_timg_function_clock_downstream(clocks, child_instance);
3676 refresh_timg_wdt_clock_downstream(clocks, child_instance);
3677 }
3678 for child_instance in [UartInstance::Uart0, UartInstance::Uart1] {
3679 refresh_uart_function_clock_downstream(clocks, child_instance);
3680 }
3681 for child_instance in [TsensInstance::Tsens] {
3682 refresh_tsens_sclk_downstream(clocks, child_instance);
3683 }
3684 }
3685 fn refresh_rc_fast_clk_downstream(clocks: &mut ClockTree) {
3686 refresh_system_pre_div_in_downstream(clocks);
3687 refresh_rc_fast_clk_div_n_downstream(clocks);
3688 refresh_rtc_slow_clk_downstream(clocks);
3689 refresh_low_power_clk_downstream(clocks);
3690 refresh_timg_calibration_clock_downstream(clocks);
3691 for child_instance in [I2cInstance::I2c0] {
3692 refresh_i2c_function_clock_downstream(clocks, child_instance);
3693 }
3694 for child_instance in [UartInstance::Uart0, UartInstance::Uart1] {
3695 refresh_uart_function_clock_downstream(clocks, child_instance);
3696 }
3697 for child_instance in [TsensInstance::Tsens] {
3698 refresh_tsens_sclk_downstream(clocks, child_instance);
3699 }
3700 }
3701 fn refresh_rc_slow_clk_downstream(clocks: &mut ClockTree) {
3702 refresh_rtc_slow_clk_downstream(clocks);
3703 refresh_ble_lp_clk_downstream(clocks);
3704 refresh_timg_calibration_clock_downstream(clocks);
3705 }
3706 fn refresh_system_pre_div_in_downstream(clocks: &mut ClockTree) {
3707 if let Some(config) = clocks.system_pre_div_in {
3708 SYSTEM_PRE_DIV_IN_FREQ_CACHE.store(
3709 system_pre_div_in_config_frequency(config),
3710 ::core::sync::atomic::Ordering::Release,
3711 );
3712 }
3713 refresh_system_pre_div_downstream(clocks);
3714 }
3715 fn refresh_system_pre_div_downstream(clocks: &mut ClockTree) {
3716 if let Some(config) = clocks.system_pre_div {
3717 SYSTEM_PRE_DIV_FREQ_CACHE.store(
3718 system_pre_div_config_frequency(config),
3719 ::core::sync::atomic::Ordering::Release,
3720 );
3721 }
3722 refresh_cpu_clk_downstream(clocks);
3723 }
3724 fn refresh_cpu_pll_div_downstream(clocks: &mut ClockTree) {
3725 if let Some(config) = clocks.cpu_pll_div {
3726 CPU_PLL_DIV_FREQ_CACHE.store(
3727 cpu_pll_div_config_frequency(config),
3728 ::core::sync::atomic::Ordering::Release,
3729 );
3730 }
3731 refresh_cpu_clk_downstream(clocks);
3732 }
3733 fn refresh_cpu_clk_downstream(clocks: &mut ClockTree) {
3734 if let Some(config) = clocks.cpu_clk {
3735 CPU_CLK_FREQ_CACHE.store(
3736 cpu_clk_config_frequency(config),
3737 ::core::sync::atomic::Ordering::Release,
3738 );
3739 }
3740 refresh_apb_clk_downstream(clocks);
3741 refresh_crypto_clk_downstream(clocks);
3742 refresh_mspi_clk_downstream(clocks);
3743 for child_instance in [SpiInstance::Spi2] {
3744 refresh_spi_function_clock_downstream(clocks, child_instance);
3745 }
3746 for child_instance in [TimgInstance::Timg0] {
3747 refresh_timg_function_clock_downstream(clocks, child_instance);
3748 refresh_timg_wdt_clock_downstream(clocks, child_instance);
3749 }
3750 for child_instance in [UartInstance::Uart0, UartInstance::Uart1] {
3751 refresh_uart_function_clock_downstream(clocks, child_instance);
3752 }
3753 }
3754 fn refresh_rc_fast_clk_div_n_downstream(clocks: &mut ClockTree) {
3755 if let Some(config) = clocks.rc_fast_clk_div_n {
3756 RC_FAST_CLK_DIV_N_FREQ_CACHE.store(
3757 rc_fast_clk_div_n_config_frequency(config),
3758 ::core::sync::atomic::Ordering::Release,
3759 );
3760 }
3761 refresh_rtc_fast_clk_downstream(clocks);
3762 }
3763 fn refresh_rtc_slow_clk_downstream(clocks: &mut ClockTree) {
3764 if let Some(config) = clocks.rtc_slow_clk {
3765 RTC_SLOW_CLK_FREQ_CACHE.store(
3766 rtc_slow_clk_config_frequency(config),
3767 ::core::sync::atomic::Ordering::Release,
3768 );
3769 }
3770 refresh_low_power_clk_downstream(clocks);
3771 }
3772 fn refresh_ble_lp_clk_downstream(clocks: &mut ClockTree) {
3773 if let Some(config) = clocks.ble_lp_clk {
3774 BLE_LP_CLK_FREQ_CACHE.store(
3775 ble_lp_clk_config_frequency(config),
3776 ::core::sync::atomic::Ordering::Release,
3777 );
3778 }
3779 }
3780 fn refresh_rtc_fast_clk_downstream(clocks: &mut ClockTree) {
3781 if let Some(config) = clocks.rtc_fast_clk {
3782 RTC_FAST_CLK_FREQ_CACHE.store(
3783 rtc_fast_clk_config_frequency(config),
3784 ::core::sync::atomic::Ordering::Release,
3785 );
3786 }
3787 }
3788 fn refresh_low_power_clk_downstream(clocks: &mut ClockTree) {
3789 if let Some(config) = clocks.low_power_clk {
3790 LOW_POWER_CLK_FREQ_CACHE.store(
3791 low_power_clk_config_frequency(config),
3792 ::core::sync::atomic::Ordering::Release,
3793 );
3794 }
3795 }
3796 fn refresh_timg_calibration_clock_downstream(clocks: &mut ClockTree) {
3797 if let Some(config) = clocks.timg_calibration_clock {
3798 TIMG_CALIBRATION_CLOCK_FREQ_CACHE.store(
3799 timg_calibration_clock_config_frequency(config),
3800 ::core::sync::atomic::Ordering::Release,
3801 );
3802 }
3803 }
3804 fn refresh_i2c_function_clock_downstream(clocks: &mut ClockTree, instance: I2cInstance) {
3805 if let Some(config) = clocks.i2c_function_clock[instance as usize] {
3806 I2C_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
3807 I2cInstance::function_clock_config_frequency(config),
3808 ::core::sync::atomic::Ordering::Release,
3809 );
3810 }
3811 }
3812 fn refresh_spi_function_clock_downstream(clocks: &mut ClockTree, instance: SpiInstance) {
3813 if let Some(config) = clocks.spi_function_clock[instance as usize] {
3814 SPI_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
3815 SpiInstance::function_clock_config_frequency(config),
3816 ::core::sync::atomic::Ordering::Release,
3817 );
3818 }
3819 }
3820 fn refresh_timg_function_clock_downstream(clocks: &mut ClockTree, instance: TimgInstance) {
3821 if let Some(config) = clocks.timg_function_clock[instance as usize] {
3822 TIMG_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
3823 TimgInstance::function_clock_config_frequency(config),
3824 ::core::sync::atomic::Ordering::Release,
3825 );
3826 }
3827 }
3828 fn refresh_timg_wdt_clock_downstream(clocks: &mut ClockTree, instance: TimgInstance) {
3829 if let Some(config) = clocks.timg_wdt_clock[instance as usize] {
3830 TIMG_WDT_CLOCK_FREQ_CACHE[instance as usize].store(
3831 TimgInstance::wdt_clock_config_frequency(config),
3832 ::core::sync::atomic::Ordering::Release,
3833 );
3834 }
3835 }
3836 fn refresh_uart_function_clock_downstream(clocks: &mut ClockTree, instance: UartInstance) {
3837 if let Some(config) = clocks.uart_function_clock[instance as usize] {
3838 UART_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
3839 UartInstance::function_clock_config_frequency(config),
3840 ::core::sync::atomic::Ordering::Release,
3841 );
3842 }
3843 refresh_uart_baud_rate_generator_downstream(clocks, instance);
3844 }
3845 fn refresh_uart_baud_rate_generator_downstream(
3846 clocks: &mut ClockTree,
3847 instance: UartInstance,
3848 ) {
3849 if let Some(config) = clocks.uart_baud_rate_generator[instance as usize] {
3850 UART_BAUD_RATE_GENERATOR_FREQ_CACHE[instance as usize].store(
3851 instance.baud_rate_generator_config_frequency(config),
3852 ::core::sync::atomic::Ordering::Release,
3853 );
3854 }
3855 }
3856 fn refresh_tsens_sclk_downstream(clocks: &mut ClockTree, instance: TsensInstance) {
3857 if let Some(config) = clocks.tsens_sclk[instance as usize] {
3858 TSENS_SCLK_FREQ_CACHE[instance as usize].store(
3859 TsensInstance::sclk_config_frequency(config),
3860 ::core::sync::atomic::Ordering::Release,
3861 );
3862 }
3863 }
3864 fn refresh_apb_clk_downstream(clocks: &mut ClockTree) {
3865 if let Some(config) = clocks.apb_clk {
3866 APB_CLK_FREQ_CACHE.store(
3867 apb_clk_config_frequency(config),
3868 ::core::sync::atomic::Ordering::Release,
3869 );
3870 }
3871 }
3872 fn refresh_crypto_clk_downstream(clocks: &mut ClockTree) {
3873 if let Some(config) = clocks.crypto_clk {
3874 CRYPTO_CLK_FREQ_CACHE.store(
3875 crypto_clk_config_frequency(config),
3876 ::core::sync::atomic::Ordering::Release,
3877 );
3878 }
3879 }
3880 fn refresh_mspi_clk_downstream(clocks: &mut ClockTree) {
3881 if let Some(config) = clocks.mspi_clk {
3882 MSPI_CLK_FREQ_CACHE.store(
3883 mspi_clk_config_frequency(config),
3884 ::core::sync::atomic::Ordering::Release,
3885 );
3886 }
3887 }
3888 };
3889}
3890#[macro_export]
3894#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3895macro_rules! implement_peripheral_clocks {
3896 () => {
3897 #[doc(hidden)]
3898 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
3899 #[repr(u8)]
3900 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
3901 pub enum Peripheral {
3902 AhbGdma,
3904 ApbSarAdc,
3906 Ecc,
3908 I2cExt0,
3910 Ledc,
3912 Sha,
3914 Spi2,
3916 Systimer,
3918 Timg0,
3920 Tsens,
3922 Uart0,
3924 Uart1,
3926 UartMem,
3928 }
3929 impl Peripheral {
3930 const KEEP_ENABLED: &[Peripheral] = &[
3931 Self::Systimer,
3932 Self::Timg0,
3933 #[cfg(keep_uart0_enabled)]
3934 Self::Uart0,
3935 #[cfg(keep_uart0_enabled)]
3936 Self::UartMem,
3937 ];
3938 const COUNT: usize = Self::ALL.len();
3939 const ALL: &[Self] = &[
3940 Self::AhbGdma,
3941 Self::ApbSarAdc,
3942 Self::Ecc,
3943 Self::I2cExt0,
3944 Self::Ledc,
3945 Self::Sha,
3946 Self::Spi2,
3947 Self::Systimer,
3948 Self::Timg0,
3949 Self::Tsens,
3950 Self::Uart0,
3951 Self::Uart1,
3952 Self::UartMem,
3953 ];
3954 }
3955 unsafe fn enable_internal_racey(peripheral: Peripheral, enable: bool) {
3956 match peripheral {
3957 Peripheral::AhbGdma => {
3958 crate::peripherals::SYSTEM::regs()
3959 .perip_clk_en1()
3960 .modify(|_, w| w.dma_clk_en().bit(enable));
3961 }
3962 Peripheral::ApbSarAdc => {
3963 crate::peripherals::SYSTEM::regs()
3964 .perip_clk_en0()
3965 .modify(|_, w| w.apb_saradc_clk_en().bit(enable));
3966 }
3967 Peripheral::Ecc => {
3968 crate::peripherals::SYSTEM::regs()
3969 .perip_clk_en1()
3970 .modify(|_, w| w.crypto_ecc_clk_en().bit(enable));
3971 }
3972 Peripheral::I2cExt0 => {
3973 crate::peripherals::SYSTEM::regs()
3974 .perip_clk_en0()
3975 .modify(|_, w| w.i2c_ext0_clk_en().bit(enable));
3976 }
3977 Peripheral::Ledc => {
3978 crate::peripherals::SYSTEM::regs()
3979 .perip_clk_en0()
3980 .modify(|_, w| w.ledc_clk_en().bit(enable));
3981 }
3982 Peripheral::Sha => {
3983 crate::peripherals::SYSTEM::regs()
3984 .perip_clk_en1()
3985 .modify(|_, w| w.crypto_sha_clk_en().bit(enable));
3986 }
3987 Peripheral::Spi2 => {
3988 crate::peripherals::SYSTEM::regs()
3989 .perip_clk_en0()
3990 .modify(|_, w| w.spi2_clk_en().bit(enable));
3991 }
3992 Peripheral::Systimer => {
3993 crate::peripherals::SYSTEM::regs()
3994 .perip_clk_en0()
3995 .modify(|_, w| w.systimer_clk_en().bit(enable));
3996 }
3997 Peripheral::Timg0 => {
3998 crate::peripherals::SYSTEM::regs()
3999 .perip_clk_en0()
4000 .modify(|_, w| w.timergroup_clk_en().bit(enable));
4001 }
4002 Peripheral::Tsens => {
4003 crate::peripherals::SYSTEM::regs()
4004 .perip_clk_en1()
4005 .modify(|_, w| w.tsens_clk_en().bit(enable));
4006 }
4007 Peripheral::Uart0 => {
4008 crate::peripherals::SYSTEM::regs()
4009 .perip_clk_en0()
4010 .modify(|_, w| w.uart_clk_en().bit(enable));
4011 }
4012 Peripheral::Uart1 => {
4013 crate::peripherals::SYSTEM::regs()
4014 .perip_clk_en0()
4015 .modify(|_, w| w.uart1_clk_en().bit(enable));
4016 }
4017 Peripheral::UartMem => {
4018 crate::peripherals::SYSTEM::regs()
4019 .perip_clk_en0()
4020 .modify(|_, w| w.uart_mem_clk_en().bit(enable));
4021 }
4022 }
4023 }
4024 unsafe fn assert_peri_reset_racey(peripheral: Peripheral, reset: bool) {
4025 match peripheral {
4026 Peripheral::AhbGdma => {
4027 crate::peripherals::SYSTEM::regs()
4028 .perip_rst_en1()
4029 .modify(|_, w| w.dma_rst().bit(reset));
4030 }
4031 Peripheral::ApbSarAdc => {
4032 crate::peripherals::SYSTEM::regs()
4033 .perip_rst_en0()
4034 .modify(|_, w| w.apb_saradc_rst().bit(reset));
4035 }
4036 Peripheral::Ecc => {
4037 crate::peripherals::SYSTEM::regs()
4038 .perip_rst_en1()
4039 .modify(|_, w| w.crypto_ecc_rst().bit(reset));
4040 }
4041 Peripheral::I2cExt0 => {
4042 crate::peripherals::SYSTEM::regs()
4043 .perip_rst_en0()
4044 .modify(|_, w| w.i2c_ext0_rst().bit(reset));
4045 }
4046 Peripheral::Ledc => {
4047 crate::peripherals::SYSTEM::regs()
4048 .perip_rst_en0()
4049 .modify(|_, w| w.ledc_rst().bit(reset));
4050 }
4051 Peripheral::Sha => {
4052 crate::peripherals::SYSTEM::regs()
4053 .perip_rst_en1()
4054 .modify(|_, w| w.crypto_sha_rst().bit(reset));
4055 }
4056 Peripheral::Spi2 => {
4057 crate::peripherals::SYSTEM::regs()
4058 .perip_rst_en0()
4059 .modify(|_, w| w.spi2_rst().bit(reset));
4060 }
4061 Peripheral::Systimer => {
4062 crate::peripherals::SYSTEM::regs()
4063 .perip_rst_en0()
4064 .modify(|_, w| w.systimer_rst().bit(reset));
4065 }
4066 Peripheral::Timg0 => {
4067 crate::peripherals::SYSTEM::regs()
4068 .perip_rst_en0()
4069 .modify(|_, w| w.timergroup_rst().bit(reset));
4070 }
4071 Peripheral::Tsens => {
4072 crate::peripherals::SYSTEM::regs()
4073 .perip_rst_en1()
4074 .modify(|_, w| w.tsens_rst().bit(reset));
4075 }
4076 Peripheral::Uart0 => {
4077 crate::peripherals::SYSTEM::regs()
4078 .perip_rst_en0()
4079 .modify(|_, w| w.uart_rst().bit(reset));
4080 }
4081 Peripheral::Uart1 => {
4082 crate::peripherals::SYSTEM::regs()
4083 .perip_rst_en0()
4084 .modify(|_, w| w.uart1_rst().bit(reset));
4085 }
4086 Peripheral::UartMem => {
4087 crate::peripherals::SYSTEM::regs()
4088 .perip_rst_en0()
4089 .modify(|_, w| w.uart_mem_rst().bit(reset));
4090 }
4091 }
4092 }
4093 };
4094}
4095#[macro_export]
4103#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4104macro_rules! memory_range {
4105 ("DRAM") => {
4106 0x3FCA0000..0x3FCE0000
4107 };
4108 (size as str, "DRAM") => {
4109 "262144"
4110 };
4111 ("IROM") => {
4112 0x42000000..0x42400000
4113 };
4114 (size as str, "IROM") => {
4115 "4194304"
4116 };
4117 ("DROM") => {
4118 0x3C000000..0x3C400000
4119 };
4120 (size as str, "DROM") => {
4121 "4194304"
4122 };
4123}
4124#[macro_export]
4143#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4144macro_rules! for_each_i2c_master {
4145 ($($pattern:tt => $code:tt;)*) => {
4146 macro_rules! _for_each_inner_i2c_master { $(($pattern) => $code;)* ($other : tt)
4147 => {} } _for_each_inner_i2c_master!((0, I2C0, I2cExt0, I2C_EXT0, I2CEXT0_SCL,
4148 I2CEXT0_SDA)); _for_each_inner_i2c_master!((all(0, I2C0, I2cExt0, I2C_EXT0,
4149 I2CEXT0_SCL, I2CEXT0_SDA)));
4150 };
4151}
4152#[macro_export]
4171#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4172macro_rules! for_each_uart {
4173 ($($pattern:tt => $code:tt;)*) => {
4174 macro_rules! _for_each_inner_uart { $(($pattern) => $code;)* ($other : tt) => {}
4175 } _for_each_inner_uart!((0, UART0, Uart0, U0RXD, U0TXD, U0CTS, U0RTS,
4176 wakeup_source = true)); _for_each_inner_uart!((1, UART1, Uart1, U1RXD, U1TXD,
4177 U1CTS, U1RTS, wakeup_source = true)); _for_each_inner_uart!((all(0, UART0, Uart0,
4178 U0RXD, U0TXD, U0CTS, U0RTS, wakeup_source = true), (1, UART1, Uart1, U1RXD,
4179 U1TXD, U1CTS, U1RTS, wakeup_source = true)));
4180 };
4181}
4182#[macro_export]
4204#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4205macro_rules! for_each_spi_master {
4206 ($($pattern:tt => $code:tt;)*) => {
4207 macro_rules! _for_each_inner_spi_master { $(($pattern) => $code;)* ($other : tt)
4208 => {} } _for_each_inner_spi_master!((SPI2)); _for_each_inner_spi_master!((SPI2,
4209 Spi2, FSPICLK[FSPICS0, FSPICS1, FSPICS2, FSPICS3, FSPICS4, FSPICS5] [FSPID,
4210 FSPIQ, FSPIWP, FSPIHD], true)); _for_each_inner_spi_master!((names(SPI2)));
4211 _for_each_inner_spi_master!((all(SPI2, Spi2, FSPICLK[FSPICS0, FSPICS1, FSPICS2,
4212 FSPICS3, FSPICS4, FSPICS5] [FSPID, FSPIQ, FSPIWP, FSPIHD], true)));
4213 };
4214}
4215#[macro_export]
4232#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4233macro_rules! for_each_spi_slave {
4234 ($($pattern:tt => $code:tt;)*) => {
4235 macro_rules! _for_each_inner_spi_slave { $(($pattern) => $code;)* ($other : tt)
4236 => {} } _for_each_inner_spi_slave!((SPI2)); _for_each_inner_spi_slave!((SPI2,
4237 Spi2, FSPICLK, FSPID, FSPIQ, FSPICS0));
4238 _for_each_inner_spi_slave!((names(SPI2))); _for_each_inner_spi_slave!((all(SPI2,
4239 Spi2, FSPICLK, FSPID, FSPIQ, FSPICS0)));
4240 };
4241}
4242#[macro_export]
4243#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4244macro_rules! for_each_peripheral {
4245 ($($pattern:tt => $code:tt;)*) => {
4246 macro_rules! _for_each_inner_peripheral { $(($pattern) => $code;)* ($other : tt)
4247 => {} } _for_each_inner_peripheral!((@ peri_type #[doc =
4248 "GPIO0 peripheral singleton"] GPIO0 <= virtual()));
4249 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO1 peripheral singleton"]
4250 GPIO1 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
4251 "GPIO2 peripheral singleton"] GPIO2 <= virtual()));
4252 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO3 peripheral singleton"]
4253 GPIO3 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
4254 "GPIO4 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4255 "<section class=\"warning\">"] #[doc =
4256 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4257 #[doc = "<ul>"] #[doc =
4258 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4259 #[doc = "</ul>"] #[doc = "</section>"] GPIO4 <= virtual()));
4260 _for_each_inner_peripheral!((@ peri_type #[doc =
4261 "GPIO5 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4262 "<section class=\"warning\">"] #[doc =
4263 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4264 #[doc = "<ul>"] #[doc =
4265 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4266 #[doc = "</ul>"] #[doc = "</section>"] GPIO5 <= virtual()));
4267 _for_each_inner_peripheral!((@ peri_type #[doc =
4268 "GPIO6 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4269 "<section class=\"warning\">"] #[doc =
4270 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4271 #[doc = "<ul>"] #[doc =
4272 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4273 #[doc = "</ul>"] #[doc = "</section>"] GPIO6 <= virtual()));
4274 _for_each_inner_peripheral!((@ peri_type #[doc =
4275 "GPIO7 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4276 "<section class=\"warning\">"] #[doc =
4277 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4278 #[doc = "<ul>"] #[doc =
4279 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4280 #[doc = "</ul>"] #[doc = "</section>"] GPIO7 <= virtual()));
4281 _for_each_inner_peripheral!((@ peri_type #[doc =
4282 "GPIO8 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4283 "<section class=\"warning\">"] #[doc =
4284 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4285 #[doc = "<ul>"] #[doc =
4286 "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
4287 = "</ul>"] #[doc = "</section>"] GPIO8 <= virtual()));
4288 _for_each_inner_peripheral!((@ peri_type #[doc =
4289 "GPIO9 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4290 "<section class=\"warning\">"] #[doc =
4291 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4292 #[doc = "<ul>"] #[doc =
4293 "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
4294 = "</ul>"] #[doc = "</section>"] GPIO9 <= virtual()));
4295 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO10 peripheral singleton"]
4296 GPIO10 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
4297 "GPIO11 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4298 "<section class=\"warning\">"] #[doc =
4299 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4300 #[doc = "<ul>"] #[doc =
4301 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4302 "</ul>"] #[doc = "</section>"] GPIO11 <= virtual()));
4303 _for_each_inner_peripheral!((@ peri_type #[doc =
4304 "GPIO12 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4305 "<section class=\"warning\">"] #[doc =
4306 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4307 #[doc = "<ul>"] #[doc =
4308 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4309 "</ul>"] #[doc = "</section>"] GPIO12 <= virtual()));
4310 _for_each_inner_peripheral!((@ peri_type #[doc =
4311 "GPIO13 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4312 "<section class=\"warning\">"] #[doc =
4313 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4314 #[doc = "<ul>"] #[doc =
4315 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4316 "</ul>"] #[doc = "</section>"] GPIO13 <= virtual()));
4317 _for_each_inner_peripheral!((@ peri_type #[doc =
4318 "GPIO14 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4319 "<section class=\"warning\">"] #[doc =
4320 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4321 #[doc = "<ul>"] #[doc =
4322 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4323 "</ul>"] #[doc = "</section>"] GPIO14 <= virtual()));
4324 _for_each_inner_peripheral!((@ peri_type #[doc =
4325 "GPIO15 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4326 "<section class=\"warning\">"] #[doc =
4327 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4328 #[doc = "<ul>"] #[doc =
4329 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4330 "</ul>"] #[doc = "</section>"] GPIO15 <= virtual()));
4331 _for_each_inner_peripheral!((@ peri_type #[doc =
4332 "GPIO16 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4333 "<section class=\"warning\">"] #[doc =
4334 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4335 #[doc = "<ul>"] #[doc =
4336 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4337 "</ul>"] #[doc = "</section>"] GPIO16 <= virtual()));
4338 _for_each_inner_peripheral!((@ peri_type #[doc =
4339 "GPIO17 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4340 "<section class=\"warning\">"] #[doc =
4341 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4342 #[doc = "<ul>"] #[doc =
4343 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4344 "</ul>"] #[doc = "</section>"] GPIO17 <= virtual()));
4345 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO18 peripheral singleton"]
4346 GPIO18 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
4347 "GPIO19 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4348 "<section class=\"warning\">"] #[doc =
4349 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4350 #[doc = "<ul>"] #[doc =
4351 "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
4352 = "</ul>"] #[doc = "</section>"] GPIO19 <= virtual()));
4353 _for_each_inner_peripheral!((@ peri_type #[doc =
4354 "GPIO20 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4355 "<section class=\"warning\">"] #[doc =
4356 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4357 #[doc = "<ul>"] #[doc =
4358 "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
4359 = "</ul>"] #[doc = "</section>"] GPIO20 <= virtual()));
4360 _for_each_inner_peripheral!((@ peri_type #[doc = "DMA_CH0 peripheral singleton"]
4361 DMA_CH0 <= virtual(DMA_CH0 : { bind_dma_interrupt, enable_dma_interrupt,
4362 disable_dma_interrupt }) (unstable))); _for_each_inner_peripheral!((@ peri_type
4363 #[doc = "APB_CTRL peripheral singleton"] APB_CTRL <= APB_CTRL() (unstable)));
4364 _for_each_inner_peripheral!((@ peri_type #[doc =
4365 "APB_SARADC peripheral singleton"] APB_SARADC <= APB_SARADC() (unstable)));
4366 _for_each_inner_peripheral!((@ peri_type #[doc = "BB peripheral singleton"] BB <=
4367 BB() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4368 "ASSIST_DEBUG peripheral singleton"] ASSIST_DEBUG <= ASSIST_DEBUG() (unstable)));
4369 _for_each_inner_peripheral!((@ peri_type #[doc = "DMA peripheral singleton"] DMA
4370 <= DMA() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4371 "ECC peripheral singleton"] ECC <= ECC() (unstable)));
4372 _for_each_inner_peripheral!((@ peri_type #[doc = "EFUSE peripheral singleton"]
4373 EFUSE <= EFUSE() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4374 "EXTMEM peripheral singleton"] EXTMEM <= EXTMEM() (unstable)));
4375 _for_each_inner_peripheral!((@ peri_type #[doc =
4376 "MMU_TABLE peripheral singleton"] MMU_TABLE <= MMU_TABLE() (unstable)));
4377 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO peripheral singleton"]
4378 GPIO <= GPIO() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4379 "I2C_ANA_MST peripheral singleton"] I2C_ANA_MST <= I2C_ANA_MST() (unstable)));
4380 _for_each_inner_peripheral!((@ peri_type #[doc = "I2C0 peripheral singleton"]
4381 I2C0 <= I2C0(I2C_EXT0 : { bind_peri_interrupt, enable_peri_interrupt,
4382 disable_peri_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
4383 "INTERRUPT_CORE0 peripheral singleton"] INTERRUPT_CORE0 <= INTERRUPT_CORE0()
4384 (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4385 "IO_MUX peripheral singleton"] IO_MUX <= IO_MUX() (unstable)));
4386 _for_each_inner_peripheral!((@ peri_type #[doc = "LEDC peripheral singleton"]
4387 LEDC <= LEDC() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4388 "RNG peripheral singleton"] RNG <= RNG() (unstable)));
4389 _for_each_inner_peripheral!((@ peri_type #[doc = "LPWR peripheral singleton"]
4390 LPWR <= RTC_CNTL() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4391 "RTC_TIMER peripheral singleton"] RTC_TIMER <= RTC_CNTL() (unstable)));
4392 _for_each_inner_peripheral!((@ peri_type #[doc =
4393 "MODEM_CLKRST peripheral singleton"] MODEM_CLKRST <= MODEM_CLKRST() (unstable)));
4394 _for_each_inner_peripheral!((@ peri_type #[doc =
4395 "SENSITIVE peripheral singleton"] SENSITIVE <= SENSITIVE() (unstable)));
4396 _for_each_inner_peripheral!((@ peri_type #[doc = "SHA peripheral singleton"] SHA
4397 <= SHA(SHA : { bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt
4398 }) (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4399 "SPI0 peripheral singleton"] SPI0 <= SPI0() (unstable)));
4400 _for_each_inner_peripheral!((@ peri_type #[doc = "SPI1 peripheral singleton"]
4401 SPI1 <= SPI1() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4402 "SPI2 peripheral singleton"] SPI2 <= SPI2(SPI2 : { bind_peri_interrupt,
4403 enable_peri_interrupt, disable_peri_interrupt })));
4404 _for_each_inner_peripheral!((@ peri_type #[doc = "SYSTEM peripheral singleton"]
4405 SYSTEM <= SYSTEM() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4406 "SYSTIMER peripheral singleton"] SYSTIMER <= SYSTIMER() (unstable)));
4407 _for_each_inner_peripheral!((@ peri_type #[doc = "TIMG0 peripheral singleton"]
4408 TIMG0 <= TIMG0() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4409 "UART0 peripheral singleton"] UART0 <= UART0(UART0 : { bind_peri_interrupt,
4410 enable_peri_interrupt, disable_peri_interrupt })));
4411 _for_each_inner_peripheral!((@ peri_type #[doc = "UART1 peripheral singleton"]
4412 UART1 <= UART1(UART1 : { bind_peri_interrupt, enable_peri_interrupt,
4413 disable_peri_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
4414 "XTS_AES peripheral singleton"] XTS_AES <= XTS_AES() (unstable)));
4415 _for_each_inner_peripheral!((@ peri_type #[doc = "ADC1 peripheral singleton"]
4416 ADC1 <= virtual() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4417 "BT peripheral singleton"] BT <= virtual(LP_TIMER : { bind_lp_timer_interrupt,
4418 enable_lp_timer_interrupt, disable_lp_timer_interrupt }, BT_MAC : {
4419 bind_mac_interrupt, enable_mac_interrupt, disable_mac_interrupt }) (unstable)));
4420 _for_each_inner_peripheral!((@ peri_type #[doc = "FLASH peripheral singleton"]
4421 FLASH <= virtual() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4422 "GPIO_DEDICATED peripheral singleton"] GPIO_DEDICATED <= virtual() (unstable)));
4423 _for_each_inner_peripheral!((@ peri_type #[doc = "TSENS peripheral singleton"]
4424 TSENS <= virtual() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4425 "WIFI peripheral singleton"] WIFI <= virtual(WIFI_MAC : { bind_mac_interrupt,
4426 enable_mac_interrupt, disable_mac_interrupt }, WIFI_PWR : { bind_pwr_interrupt,
4427 enable_pwr_interrupt, disable_pwr_interrupt }))); _for_each_inner_peripheral!((@
4428 peri_type #[doc = "FROM_CPU_INTR0 peripheral singleton"] FROM_CPU_INTR0 <=
4429 virtual() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
4430 "FROM_CPU_INTR1 peripheral singleton"] FROM_CPU_INTR1 <= virtual() (unstable)));
4431 _for_each_inner_peripheral!((@ peri_type #[doc =
4432 "FROM_CPU_INTR2 peripheral singleton"] FROM_CPU_INTR2 <= virtual() (unstable)));
4433 _for_each_inner_peripheral!((@ peri_type #[doc =
4434 "FROM_CPU_INTR3 peripheral singleton"] FROM_CPU_INTR3 <= virtual() (unstable)));
4435 _for_each_inner_peripheral!((GPIO0)); _for_each_inner_peripheral!((GPIO1));
4436 _for_each_inner_peripheral!((GPIO2)); _for_each_inner_peripheral!((GPIO3));
4437 _for_each_inner_peripheral!((GPIO4)); _for_each_inner_peripheral!((GPIO5));
4438 _for_each_inner_peripheral!((GPIO6)); _for_each_inner_peripheral!((GPIO7));
4439 _for_each_inner_peripheral!((GPIO8)); _for_each_inner_peripheral!((GPIO9));
4440 _for_each_inner_peripheral!((GPIO10)); _for_each_inner_peripheral!((GPIO11));
4441 _for_each_inner_peripheral!((GPIO12)); _for_each_inner_peripheral!((GPIO13));
4442 _for_each_inner_peripheral!((GPIO14)); _for_each_inner_peripheral!((GPIO15));
4443 _for_each_inner_peripheral!((GPIO16)); _for_each_inner_peripheral!((GPIO17));
4444 _for_each_inner_peripheral!((GPIO18)); _for_each_inner_peripheral!((GPIO19));
4445 _for_each_inner_peripheral!((GPIO20));
4446 _for_each_inner_peripheral!((DMA_CH0(unstable)));
4447 _for_each_inner_peripheral!((APB_CTRL(unstable)));
4448 _for_each_inner_peripheral!((APB_SARADC(unstable)));
4449 _for_each_inner_peripheral!((BB(unstable)));
4450 _for_each_inner_peripheral!((ASSIST_DEBUG(unstable)));
4451 _for_each_inner_peripheral!((DMA(unstable)));
4452 _for_each_inner_peripheral!((ECC(unstable)));
4453 _for_each_inner_peripheral!((EXTMEM(unstable)));
4454 _for_each_inner_peripheral!((GPIO(unstable)));
4455 _for_each_inner_peripheral!((I2C_ANA_MST(unstable)));
4456 _for_each_inner_peripheral!((I2C0));
4457 _for_each_inner_peripheral!((INTERRUPT_CORE0(unstable)));
4458 _for_each_inner_peripheral!((IO_MUX(unstable)));
4459 _for_each_inner_peripheral!((LEDC(unstable)));
4460 _for_each_inner_peripheral!((RNG(unstable)));
4461 _for_each_inner_peripheral!((LPWR(unstable)));
4462 _for_each_inner_peripheral!((RTC_TIMER(unstable)));
4463 _for_each_inner_peripheral!((MODEM_CLKRST(unstable)));
4464 _for_each_inner_peripheral!((SENSITIVE(unstable)));
4465 _for_each_inner_peripheral!((SHA(unstable)));
4466 _for_each_inner_peripheral!((SPI0(unstable)));
4467 _for_each_inner_peripheral!((SPI1(unstable)));
4468 _for_each_inner_peripheral!((SPI2));
4469 _for_each_inner_peripheral!((SYSTEM(unstable)));
4470 _for_each_inner_peripheral!((SYSTIMER(unstable)));
4471 _for_each_inner_peripheral!((TIMG0(unstable)));
4472 _for_each_inner_peripheral!((UART0)); _for_each_inner_peripheral!((UART1));
4473 _for_each_inner_peripheral!((XTS_AES(unstable)));
4474 _for_each_inner_peripheral!((ADC1(unstable)));
4475 _for_each_inner_peripheral!((BT(unstable)));
4476 _for_each_inner_peripheral!((FLASH(unstable)));
4477 _for_each_inner_peripheral!((GPIO_DEDICATED(unstable)));
4478 _for_each_inner_peripheral!((TSENS(unstable)));
4479 _for_each_inner_peripheral!((WIFI));
4480 _for_each_inner_peripheral!((FROM_CPU_INTR1(unstable)));
4481 _for_each_inner_peripheral!((FROM_CPU_INTR2(unstable)));
4482 _for_each_inner_peripheral!((FROM_CPU_INTR3(unstable)));
4483 _for_each_inner_peripheral!((SPI2, Spi2, 0, AhbGdmaChannel));
4484 _for_each_inner_peripheral!((SHA, Sha, 7, AhbGdmaChannel));
4485 _for_each_inner_peripheral!((all(@ peri_type #[doc =
4486 "GPIO0 peripheral singleton"] GPIO0 <= virtual()), (@ peri_type #[doc =
4487 "GPIO1 peripheral singleton"] GPIO1 <= virtual()), (@ peri_type #[doc =
4488 "GPIO2 peripheral singleton"] GPIO2 <= virtual()), (@ peri_type #[doc =
4489 "GPIO3 peripheral singleton"] GPIO3 <= virtual()), (@ peri_type #[doc =
4490 "GPIO4 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4491 "<section class=\"warning\">"] #[doc =
4492 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4493 #[doc = "<ul>"] #[doc =
4494 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4495 #[doc = "</ul>"] #[doc = "</section>"] GPIO4 <= virtual()), (@ peri_type #[doc =
4496 "GPIO5 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4497 "<section class=\"warning\">"] #[doc =
4498 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4499 #[doc = "<ul>"] #[doc =
4500 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4501 #[doc = "</ul>"] #[doc = "</section>"] GPIO5 <= virtual()), (@ peri_type #[doc =
4502 "GPIO6 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4503 "<section class=\"warning\">"] #[doc =
4504 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4505 #[doc = "<ul>"] #[doc =
4506 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4507 #[doc = "</ul>"] #[doc = "</section>"] GPIO6 <= virtual()), (@ peri_type #[doc =
4508 "GPIO7 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4509 "<section class=\"warning\">"] #[doc =
4510 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4511 #[doc = "<ul>"] #[doc =
4512 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
4513 #[doc = "</ul>"] #[doc = "</section>"] GPIO7 <= virtual()), (@ peri_type #[doc =
4514 "GPIO8 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4515 "<section class=\"warning\">"] #[doc =
4516 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4517 #[doc = "<ul>"] #[doc =
4518 "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
4519 = "</ul>"] #[doc = "</section>"] GPIO8 <= virtual()), (@ peri_type #[doc =
4520 "GPIO9 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4521 "<section class=\"warning\">"] #[doc =
4522 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4523 #[doc = "<ul>"] #[doc =
4524 "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
4525 = "</ul>"] #[doc = "</section>"] GPIO9 <= virtual()), (@ peri_type #[doc =
4526 "GPIO10 peripheral singleton"] GPIO10 <= virtual()), (@ peri_type #[doc =
4527 "GPIO11 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4528 "<section class=\"warning\">"] #[doc =
4529 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4530 #[doc = "<ul>"] #[doc =
4531 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4532 "</ul>"] #[doc = "</section>"] GPIO11 <= virtual()), (@ peri_type #[doc =
4533 "GPIO12 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4534 "<section class=\"warning\">"] #[doc =
4535 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4536 #[doc = "<ul>"] #[doc =
4537 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4538 "</ul>"] #[doc = "</section>"] GPIO12 <= virtual()), (@ peri_type #[doc =
4539 "GPIO13 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4540 "<section class=\"warning\">"] #[doc =
4541 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4542 #[doc = "<ul>"] #[doc =
4543 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4544 "</ul>"] #[doc = "</section>"] GPIO13 <= virtual()), (@ peri_type #[doc =
4545 "GPIO14 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4546 "<section class=\"warning\">"] #[doc =
4547 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4548 #[doc = "<ul>"] #[doc =
4549 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4550 "</ul>"] #[doc = "</section>"] GPIO14 <= virtual()), (@ peri_type #[doc =
4551 "GPIO15 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4552 "<section class=\"warning\">"] #[doc =
4553 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4554 #[doc = "<ul>"] #[doc =
4555 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4556 "</ul>"] #[doc = "</section>"] GPIO15 <= virtual()), (@ peri_type #[doc =
4557 "GPIO16 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4558 "<section class=\"warning\">"] #[doc =
4559 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4560 #[doc = "<ul>"] #[doc =
4561 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4562 "</ul>"] #[doc = "</section>"] GPIO16 <= virtual()), (@ peri_type #[doc =
4563 "GPIO17 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4564 "<section class=\"warning\">"] #[doc =
4565 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4566 #[doc = "<ul>"] #[doc =
4567 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
4568 "</ul>"] #[doc = "</section>"] GPIO17 <= virtual()), (@ peri_type #[doc =
4569 "GPIO18 peripheral singleton"] GPIO18 <= virtual()), (@ peri_type #[doc =
4570 "GPIO19 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4571 "<section class=\"warning\">"] #[doc =
4572 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4573 #[doc = "<ul>"] #[doc =
4574 "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
4575 = "</ul>"] #[doc = "</section>"] GPIO19 <= virtual()), (@ peri_type #[doc =
4576 "GPIO20 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4577 "<section class=\"warning\">"] #[doc =
4578 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4579 #[doc = "<ul>"] #[doc =
4580 "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
4581 = "</ul>"] #[doc = "</section>"] GPIO20 <= virtual()), (@ peri_type #[doc =
4582 "DMA_CH0 peripheral singleton"] DMA_CH0 <= virtual(DMA_CH0 : {
4583 bind_dma_interrupt, enable_dma_interrupt, disable_dma_interrupt }) (unstable)),
4584 (@ peri_type #[doc = "APB_CTRL peripheral singleton"] APB_CTRL <= APB_CTRL()
4585 (unstable)), (@ peri_type #[doc = "APB_SARADC peripheral singleton"] APB_SARADC
4586 <= APB_SARADC() (unstable)), (@ peri_type #[doc = "BB peripheral singleton"] BB
4587 <= BB() (unstable)), (@ peri_type #[doc = "ASSIST_DEBUG peripheral singleton"]
4588 ASSIST_DEBUG <= ASSIST_DEBUG() (unstable)), (@ peri_type #[doc =
4589 "DMA peripheral singleton"] DMA <= DMA() (unstable)), (@ peri_type #[doc =
4590 "ECC peripheral singleton"] ECC <= ECC() (unstable)), (@ peri_type #[doc =
4591 "EFUSE peripheral singleton"] EFUSE <= EFUSE() (unstable)), (@ peri_type #[doc =
4592 "EXTMEM peripheral singleton"] EXTMEM <= EXTMEM() (unstable)), (@ peri_type #[doc
4593 = "MMU_TABLE peripheral singleton"] MMU_TABLE <= MMU_TABLE() (unstable)), (@
4594 peri_type #[doc = "GPIO peripheral singleton"] GPIO <= GPIO() (unstable)), (@
4595 peri_type #[doc = "I2C_ANA_MST peripheral singleton"] I2C_ANA_MST <=
4596 I2C_ANA_MST() (unstable)), (@ peri_type #[doc = "I2C0 peripheral singleton"] I2C0
4597 <= I2C0(I2C_EXT0 : { bind_peri_interrupt, enable_peri_interrupt,
4598 disable_peri_interrupt })), (@ peri_type #[doc =
4599 "INTERRUPT_CORE0 peripheral singleton"] INTERRUPT_CORE0 <= INTERRUPT_CORE0()
4600 (unstable)), (@ peri_type #[doc = "IO_MUX peripheral singleton"] IO_MUX <=
4601 IO_MUX() (unstable)), (@ peri_type #[doc = "LEDC peripheral singleton"] LEDC <=
4602 LEDC() (unstable)), (@ peri_type #[doc = "RNG peripheral singleton"] RNG <= RNG()
4603 (unstable)), (@ peri_type #[doc = "LPWR peripheral singleton"] LPWR <= RTC_CNTL()
4604 (unstable)), (@ peri_type #[doc = "RTC_TIMER peripheral singleton"] RTC_TIMER <=
4605 RTC_CNTL() (unstable)), (@ peri_type #[doc = "MODEM_CLKRST peripheral singleton"]
4606 MODEM_CLKRST <= MODEM_CLKRST() (unstable)), (@ peri_type #[doc =
4607 "SENSITIVE peripheral singleton"] SENSITIVE <= SENSITIVE() (unstable)), (@
4608 peri_type #[doc = "SHA peripheral singleton"] SHA <= SHA(SHA : {
4609 bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })
4610 (unstable)), (@ peri_type #[doc = "SPI0 peripheral singleton"] SPI0 <= SPI0()
4611 (unstable)), (@ peri_type #[doc = "SPI1 peripheral singleton"] SPI1 <= SPI1()
4612 (unstable)), (@ peri_type #[doc = "SPI2 peripheral singleton"] SPI2 <= SPI2(SPI2
4613 : { bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })), (@
4614 peri_type #[doc = "SYSTEM peripheral singleton"] SYSTEM <= SYSTEM() (unstable)),
4615 (@ peri_type #[doc = "SYSTIMER peripheral singleton"] SYSTIMER <= SYSTIMER()
4616 (unstable)), (@ peri_type #[doc = "TIMG0 peripheral singleton"] TIMG0 <= TIMG0()
4617 (unstable)), (@ peri_type #[doc = "UART0 peripheral singleton"] UART0 <=
4618 UART0(UART0 : { bind_peri_interrupt, enable_peri_interrupt,
4619 disable_peri_interrupt })), (@ peri_type #[doc = "UART1 peripheral singleton"]
4620 UART1 <= UART1(UART1 : { bind_peri_interrupt, enable_peri_interrupt,
4621 disable_peri_interrupt })), (@ peri_type #[doc = "XTS_AES peripheral singleton"]
4622 XTS_AES <= XTS_AES() (unstable)), (@ peri_type #[doc =
4623 "ADC1 peripheral singleton"] ADC1 <= virtual() (unstable)), (@ peri_type #[doc =
4624 "BT peripheral singleton"] BT <= virtual(LP_TIMER : { bind_lp_timer_interrupt,
4625 enable_lp_timer_interrupt, disable_lp_timer_interrupt }, BT_MAC : {
4626 bind_mac_interrupt, enable_mac_interrupt, disable_mac_interrupt }) (unstable)),
4627 (@ peri_type #[doc = "FLASH peripheral singleton"] FLASH <= virtual()
4628 (unstable)), (@ peri_type #[doc = "GPIO_DEDICATED peripheral singleton"]
4629 GPIO_DEDICATED <= virtual() (unstable)), (@ peri_type #[doc =
4630 "TSENS peripheral singleton"] TSENS <= virtual() (unstable)), (@ peri_type #[doc
4631 = "WIFI peripheral singleton"] WIFI <= virtual(WIFI_MAC : { bind_mac_interrupt,
4632 enable_mac_interrupt, disable_mac_interrupt }, WIFI_PWR : { bind_pwr_interrupt,
4633 enable_pwr_interrupt, disable_pwr_interrupt })), (@ peri_type #[doc =
4634 "FROM_CPU_INTR0 peripheral singleton"] FROM_CPU_INTR0 <= virtual() (unstable)),
4635 (@ peri_type #[doc = "FROM_CPU_INTR1 peripheral singleton"] FROM_CPU_INTR1 <=
4636 virtual() (unstable)), (@ peri_type #[doc =
4637 "FROM_CPU_INTR2 peripheral singleton"] FROM_CPU_INTR2 <= virtual() (unstable)),
4638 (@ peri_type #[doc = "FROM_CPU_INTR3 peripheral singleton"] FROM_CPU_INTR3 <=
4639 virtual() (unstable)))); _for_each_inner_peripheral!((singletons(GPIO0), (GPIO1),
4640 (GPIO2), (GPIO3), (GPIO4), (GPIO5), (GPIO6), (GPIO7), (GPIO8), (GPIO9), (GPIO10),
4641 (GPIO11), (GPIO12), (GPIO13), (GPIO14), (GPIO15), (GPIO16), (GPIO17), (GPIO18),
4642 (GPIO19), (GPIO20), (DMA_CH0(unstable)), (APB_CTRL(unstable)),
4643 (APB_SARADC(unstable)), (BB(unstable)), (ASSIST_DEBUG(unstable)),
4644 (DMA(unstable)), (ECC(unstable)), (EXTMEM(unstable)), (GPIO(unstable)),
4645 (I2C_ANA_MST(unstable)), (I2C0), (INTERRUPT_CORE0(unstable)), (IO_MUX(unstable)),
4646 (LEDC(unstable)), (RNG(unstable)), (LPWR(unstable)), (RTC_TIMER(unstable)),
4647 (MODEM_CLKRST(unstable)), (SENSITIVE(unstable)), (SHA(unstable)),
4648 (SPI0(unstable)), (SPI1(unstable)), (SPI2), (SYSTEM(unstable)),
4649 (SYSTIMER(unstable)), (TIMG0(unstable)), (UART0), (UART1), (XTS_AES(unstable)),
4650 (ADC1(unstable)), (BT(unstable)), (FLASH(unstable)), (GPIO_DEDICATED(unstable)),
4651 (TSENS(unstable)), (WIFI), (FROM_CPU_INTR1(unstable)),
4652 (FROM_CPU_INTR2(unstable)), (FROM_CPU_INTR3(unstable))));
4653 _for_each_inner_peripheral!((dma_eligible(SPI2, Spi2, 0, AhbGdmaChannel), (SHA,
4654 Sha, 7, AhbGdmaChannel)));
4655 };
4656}
4657#[macro_export]
4684#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4685macro_rules! for_each_gpio {
4686 ($($pattern:tt => $code:tt;)*) => {
4687 macro_rules! _for_each_inner_gpio { $(($pattern) => $code;)* ($other : tt) => {}
4688 } _for_each_inner_gpio!((0, GPIO0() () ([Input] [Output])));
4689 _for_each_inner_gpio!((1, GPIO1() () ([Input] [Output])));
4690 _for_each_inner_gpio!((2, GPIO2(_2 => FSPIQ) (_2 => FSPIQ) ([Input] [Output])));
4691 _for_each_inner_gpio!((3, GPIO3() () ([Input] [Output])));
4692 _for_each_inner_gpio!((4, GPIO4(_0 => MTMS _2 => FSPIHD) (_2 => FSPIHD) ([Input]
4693 [Output]))); _for_each_inner_gpio!((5, GPIO5(_0 => MTDI _2 => FSPIWP) (_2 =>
4694 FSPIWP) ([Input] [Output]))); _for_each_inner_gpio!((6, GPIO6(_0 => MTCK _2 =>
4695 FSPICLK) (_2 => FSPICLK) ([Input] [Output]))); _for_each_inner_gpio!((7, GPIO7(_2
4696 => FSPID) (_0 => MTDO _2 => FSPID) ([Input] [Output])));
4697 _for_each_inner_gpio!((8, GPIO8() () ([Input] [Output])));
4698 _for_each_inner_gpio!((9, GPIO9() () ([Input] [Output])));
4699 _for_each_inner_gpio!((10, GPIO10(_2 => FSPICS0) (_2 => FSPICS0) ([Input]
4700 [Output]))); _for_each_inner_gpio!((11, GPIO11(_0 => SPIHD) (_0 => SPIHD)
4701 ([Input] [Output]))); _for_each_inner_gpio!((12, GPIO12(_0 => SPIHD) (_0 =>
4702 SPIHD) ([Input] [Output]))); _for_each_inner_gpio!((13, GPIO13(_0 => SPIWP) (_0
4703 => SPIWP) ([Input] [Output]))); _for_each_inner_gpio!((14, GPIO14() (_0 =>
4704 SPICS0) ([Input] [Output]))); _for_each_inner_gpio!((15, GPIO15() (_0 => SPICLK)
4705 ([Input] [Output]))); _for_each_inner_gpio!((16, GPIO16(_0 => SPID) (_0 => SPID)
4706 ([Input] [Output]))); _for_each_inner_gpio!((17, GPIO17(_0 => SPIQ) (_0 => SPIQ)
4707 ([Input] [Output]))); _for_each_inner_gpio!((18, GPIO18() () ([Input]
4708 [Output]))); _for_each_inner_gpio!((19, GPIO19(_0 => U0RXD) () ([Input]
4709 [Output]))); _for_each_inner_gpio!((20, GPIO20() (_0 => U0TXD) ([Input]
4710 [Output]))); _for_each_inner_gpio!((all(0, GPIO0() () ([Input] [Output])), (1,
4711 GPIO1() () ([Input] [Output])), (2, GPIO2(_2 => FSPIQ) (_2 => FSPIQ) ([Input]
4712 [Output])), (3, GPIO3() () ([Input] [Output])), (4, GPIO4(_0 => MTMS _2 =>
4713 FSPIHD) (_2 => FSPIHD) ([Input] [Output])), (5, GPIO5(_0 => MTDI _2 => FSPIWP)
4714 (_2 => FSPIWP) ([Input] [Output])), (6, GPIO6(_0 => MTCK _2 => FSPICLK) (_2 =>
4715 FSPICLK) ([Input] [Output])), (7, GPIO7(_2 => FSPID) (_0 => MTDO _2 => FSPID)
4716 ([Input] [Output])), (8, GPIO8() () ([Input] [Output])), (9, GPIO9() () ([Input]
4717 [Output])), (10, GPIO10(_2 => FSPICS0) (_2 => FSPICS0) ([Input] [Output])), (11,
4718 GPIO11(_0 => SPIHD) (_0 => SPIHD) ([Input] [Output])), (12, GPIO12(_0 => SPIHD)
4719 (_0 => SPIHD) ([Input] [Output])), (13, GPIO13(_0 => SPIWP) (_0 => SPIWP)
4720 ([Input] [Output])), (14, GPIO14() (_0 => SPICS0) ([Input] [Output])), (15,
4721 GPIO15() (_0 => SPICLK) ([Input] [Output])), (16, GPIO16(_0 => SPID) (_0 => SPID)
4722 ([Input] [Output])), (17, GPIO17(_0 => SPIQ) (_0 => SPIQ) ([Input] [Output])),
4723 (18, GPIO18() () ([Input] [Output])), (19, GPIO19(_0 => U0RXD) () ([Input]
4724 [Output])), (20, GPIO20() (_0 => U0TXD) ([Input] [Output]))));
4725 };
4726}
4727#[macro_export]
4754#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4755macro_rules! for_each_analog_function {
4756 ($($pattern:tt => $code:tt;)*) => {
4757 macro_rules! _for_each_inner_analog_function { $(($pattern) => $code;)* ($other :
4758 tt) => {} } _for_each_inner_analog_function!((ADC1_CH0, GPIO0));
4759 _for_each_inner_analog_function!((ADC1_CH1, GPIO1));
4760 _for_each_inner_analog_function!((ADC1_CH2, GPIO2));
4761 _for_each_inner_analog_function!((ADC1_CH3, GPIO3));
4762 _for_each_inner_analog_function!((ADC1_CH4, GPIO4));
4763 _for_each_inner_analog_function!(((ADC1_CH0, ADCn_CHm, 1, 0), GPIO0));
4764 _for_each_inner_analog_function!(((ADC1_CH1, ADCn_CHm, 1, 1), GPIO1));
4765 _for_each_inner_analog_function!(((ADC1_CH2, ADCn_CHm, 1, 2), GPIO2));
4766 _for_each_inner_analog_function!(((ADC1_CH3, ADCn_CHm, 1, 3), GPIO3));
4767 _for_each_inner_analog_function!(((ADC1_CH4, ADCn_CHm, 1, 4), GPIO4));
4768 _for_each_inner_analog_function!((all(ADC1_CH0, GPIO0), (ADC1_CH1, GPIO1),
4769 (ADC1_CH2, GPIO2), (ADC1_CH3, GPIO3), (ADC1_CH4, GPIO4)));
4770 _for_each_inner_analog_function!((ADCn_CHm((ADC1_CH0, ADCn_CHm, 1, 0), GPIO0),
4771 ((ADC1_CH1, ADCn_CHm, 1, 1), GPIO1), ((ADC1_CH2, ADCn_CHm, 1, 2), GPIO2),
4772 ((ADC1_CH3, ADCn_CHm, 1, 3), GPIO3), ((ADC1_CH4, ADCn_CHm, 1, 4), GPIO4)));
4773 };
4774}
4775#[macro_export]
4813#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4814macro_rules! for_each_lp_function {
4815 ($($pattern:tt => $code:tt;)*) => {
4816 macro_rules! _for_each_inner_lp_function { $(($pattern) => $code;)* ($other : tt)
4817 => {} } _for_each_inner_lp_function!((LP_GPIO0, GPIO0, _0));
4818 _for_each_inner_lp_function!((LP_GPIO1, GPIO1, _0));
4819 _for_each_inner_lp_function!((LP_GPIO2, GPIO2, _0));
4820 _for_each_inner_lp_function!((LP_GPIO3, GPIO3, _0));
4821 _for_each_inner_lp_function!((LP_GPIO4, GPIO4, _0));
4822 _for_each_inner_lp_function!((LP_GPIO5, GPIO5, _0));
4823 _for_each_inner_lp_function!(((LP_GPIO0, LP_GPIOn, 0), GPIO0, _0, () ()));
4824 _for_each_inner_lp_function!(((LP_GPIO1, LP_GPIOn, 1), GPIO1, _0, () ()));
4825 _for_each_inner_lp_function!(((LP_GPIO2, LP_GPIOn, 2), GPIO2, _0, () ()));
4826 _for_each_inner_lp_function!(((LP_GPIO3, LP_GPIOn, 3), GPIO3, _0, () ()));
4827 _for_each_inner_lp_function!(((LP_GPIO4, LP_GPIOn, 4), GPIO4, _0, () ()));
4828 _for_each_inner_lp_function!(((LP_GPIO5, LP_GPIOn, 5), GPIO5, _0, () ()));
4829 _for_each_inner_lp_function!((all(LP_GPIO0, GPIO0, _0), (LP_GPIO1, GPIO1, _0),
4830 (LP_GPIO2, GPIO2, _0), (LP_GPIO3, GPIO3, _0), (LP_GPIO4, GPIO4, _0), (LP_GPIO5,
4831 GPIO5, _0))); _for_each_inner_lp_function!((LP_GPIOn((LP_GPIO0, LP_GPIOn, 0),
4832 GPIO0, _0, () ()), ((LP_GPIO1, LP_GPIOn, 1), GPIO1, _0, () ()), ((LP_GPIO2,
4833 LP_GPIOn, 2), GPIO2, _0, () ()), ((LP_GPIO3, LP_GPIOn, 3), GPIO3, _0, () ()),
4834 ((LP_GPIO4, LP_GPIOn, 4), GPIO4, _0, () ()), ((LP_GPIO5, LP_GPIOn, 5), GPIO5, _0,
4835 () ())));
4836 };
4837}
4838#[macro_export]
4869#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4870macro_rules! for_each_iomux_function {
4871 ($($pattern:tt => $code:tt;)*) => {
4872 macro_rules! _for_each_inner_iomux_function { $(($pattern) => $code;)* ($other :
4873 tt) => {} } _for_each_inner_iomux_function!((FSPIQ, GPIO2, _2));
4874 _for_each_inner_iomux_function!((MTMS, GPIO4, _0));
4875 _for_each_inner_iomux_function!((FSPIHD, GPIO4, _2));
4876 _for_each_inner_iomux_function!((MTDI, GPIO5, _0));
4877 _for_each_inner_iomux_function!((FSPIWP, GPIO5, _2));
4878 _for_each_inner_iomux_function!((MTCK, GPIO6, _0));
4879 _for_each_inner_iomux_function!((FSPICLK, GPIO6, _2));
4880 _for_each_inner_iomux_function!((MTDO, GPIO7, _0));
4881 _for_each_inner_iomux_function!((FSPID, GPIO7, _2));
4882 _for_each_inner_iomux_function!((FSPICS0, GPIO10, _2));
4883 _for_each_inner_iomux_function!((SPIHD, GPIO11, _0));
4884 _for_each_inner_iomux_function!((SPIHD, GPIO12, _0));
4885 _for_each_inner_iomux_function!((SPIWP, GPIO13, _0));
4886 _for_each_inner_iomux_function!((SPICS0, GPIO14, _0));
4887 _for_each_inner_iomux_function!((SPICLK, GPIO15, _0));
4888 _for_each_inner_iomux_function!((SPID, GPIO16, _0));
4889 _for_each_inner_iomux_function!((SPIQ, GPIO17, _0));
4890 _for_each_inner_iomux_function!((U0RXD, GPIO19, _0));
4891 _for_each_inner_iomux_function!((U0TXD, GPIO20, _0));
4892 _for_each_inner_iomux_function!(((FSPICS0, FSPICSn, 0), GPIO10, _2));
4893 _for_each_inner_iomux_function!(((SPICS0, SPICSn, 0), GPIO14, _0));
4894 _for_each_inner_iomux_function!((all(FSPIQ, GPIO2, _2), (MTMS, GPIO4, _0),
4895 (FSPIHD, GPIO4, _2), (MTDI, GPIO5, _0), (FSPIWP, GPIO5, _2), (MTCK, GPIO6, _0),
4896 (FSPICLK, GPIO6, _2), (MTDO, GPIO7, _0), (FSPID, GPIO7, _2), (FSPICS0, GPIO10,
4897 _2), (SPIHD, GPIO11, _0), (SPIHD, GPIO12, _0), (SPIWP, GPIO13, _0), (SPICS0,
4898 GPIO14, _0), (SPICLK, GPIO15, _0), (SPID, GPIO16, _0), (SPIQ, GPIO17, _0),
4899 (U0RXD, GPIO19, _0), (U0TXD, GPIO20, _0)));
4900 _for_each_inner_iomux_function!((FSPICSn((FSPICS0, FSPICSn, 0), GPIO10, _2)));
4901 _for_each_inner_iomux_function!((SPICSn((SPICS0, SPICSn, 0), GPIO14, _0)));
4902 };
4903}
4904#[macro_export]
4921#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4922macro_rules! gpio_for_signal {
4923 (ADC1_CH0 $(, $_fallback:literal)?) => {
4924 "GPIO0"
4925 };
4926 (LP_GPIO0 $(, $_fallback:literal)?) => {
4927 "GPIO0"
4928 };
4929 (ADC1_CH1 $(, $_fallback:literal)?) => {
4930 "GPIO1"
4931 };
4932 (LP_GPIO1 $(, $_fallback:literal)?) => {
4933 "GPIO1"
4934 };
4935 (FSPIQ $(, $_fallback:literal)?) => {
4936 "GPIO2"
4937 };
4938 (ADC1_CH2 $(, $_fallback:literal)?) => {
4939 "GPIO2"
4940 };
4941 (LP_GPIO2 $(, $_fallback:literal)?) => {
4942 "GPIO2"
4943 };
4944 (ADC1_CH3 $(, $_fallback:literal)?) => {
4945 "GPIO3"
4946 };
4947 (LP_GPIO3 $(, $_fallback:literal)?) => {
4948 "GPIO3"
4949 };
4950 (MTMS $(, $_fallback:literal)?) => {
4951 "GPIO4"
4952 };
4953 (FSPIHD $(, $_fallback:literal)?) => {
4954 "GPIO4"
4955 };
4956 (ADC1_CH4 $(, $_fallback:literal)?) => {
4957 "GPIO4"
4958 };
4959 (LP_GPIO4 $(, $_fallback:literal)?) => {
4960 "GPIO4"
4961 };
4962 (MTDI $(, $_fallback:literal)?) => {
4963 "GPIO5"
4964 };
4965 (FSPIWP $(, $_fallback:literal)?) => {
4966 "GPIO5"
4967 };
4968 (LP_GPIO5 $(, $_fallback:literal)?) => {
4969 "GPIO5"
4970 };
4971 (MTCK $(, $_fallback:literal)?) => {
4972 "GPIO6"
4973 };
4974 (FSPICLK $(, $_fallback:literal)?) => {
4975 "GPIO6"
4976 };
4977 (MTDO $(, $_fallback:literal)?) => {
4978 "GPIO7"
4979 };
4980 (FSPID $(, $_fallback:literal)?) => {
4981 "GPIO7"
4982 };
4983 (FSPICS0 $(, $_fallback:literal)?) => {
4984 "GPIO10"
4985 };
4986 (SPIHD $(, $_fallback:literal)?) => {
4987 "GPIO11"
4988 };
4989 (SPIWP $(, $_fallback:literal)?) => {
4990 "GPIO13"
4991 };
4992 (SPICS0 $(, $_fallback:literal)?) => {
4993 "GPIO14"
4994 };
4995 (SPICLK $(, $_fallback:literal)?) => {
4996 "GPIO15"
4997 };
4998 (SPID $(, $_fallback:literal)?) => {
4999 "GPIO16"
5000 };
5001 (SPIQ $(, $_fallback:literal)?) => {
5002 "GPIO17"
5003 };
5004 (U0RXD $(, $_fallback:literal)?) => {
5005 "GPIO19"
5006 };
5007 (U0TXD $(, $_fallback:literal)?) => {
5008 "GPIO20"
5009 };
5010 ($_signal:ident, $fallback:literal) => {
5011 $fallback
5012 };
5013}
5014#[macro_export]
5018#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5019macro_rules! define_io_mux_signals {
5020 () => {
5021 #[allow(non_camel_case_types, clippy::upper_case_acronyms)]
5022 #[derive(Debug, PartialEq, Copy, Clone)]
5023 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
5024 #[doc(hidden)]
5025 pub enum InputSignal {
5026 SPIQ = 0,
5027 SPID = 1,
5028 SPIHD = 2,
5029 SPIWP = 3,
5030 U0RXD = 6,
5031 U0CTS = 7,
5032 U0DSR = 8,
5033 U1RXD = 9,
5034 U1CTS = 10,
5035 U1DSR = 11,
5036 CPU_GPIO_0 = 28,
5037 CPU_GPIO_1 = 29,
5038 CPU_GPIO_2 = 30,
5039 CPU_GPIO_3 = 31,
5040 CPU_GPIO_4 = 32,
5041 CPU_GPIO_5 = 33,
5042 CPU_GPIO_6 = 34,
5043 CPU_GPIO_7 = 35,
5044 EXT_ADC_START = 45,
5045 RMT_SIG_0 = 51,
5046 RMT_SIG_1 = 52,
5047 I2CEXT0_SCL = 53,
5048 I2CEXT0_SDA = 54,
5049 FSPICLK = 63,
5050 FSPIQ = 64,
5051 FSPID = 65,
5052 FSPIHD = 66,
5053 FSPIWP = 67,
5054 FSPICS0 = 68,
5055 SIG_FUNC_97 = 97,
5056 SIG_FUNC_98 = 98,
5057 SIG_FUNC_99 = 99,
5058 SIG_FUNC_100 = 100,
5059 MTCK,
5060 MTMS,
5061 MTDI,
5062 }
5063 #[allow(non_camel_case_types, clippy::upper_case_acronyms)]
5064 #[derive(Debug, PartialEq, Copy, Clone)]
5065 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
5066 #[doc(hidden)]
5067 pub enum OutputSignal {
5068 SPIQ = 0,
5069 SPID = 1,
5070 SPIHD = 2,
5071 SPIWP = 3,
5072 SPICLK = 4,
5073 SPICS0 = 5,
5074 U0TXD = 6,
5075 U0RTS = 7,
5076 U0DTR = 8,
5077 U1TXD = 9,
5078 U1RTS = 10,
5079 U1DTR = 11,
5080 SPIQ_MONITOR = 15,
5081 SPID_MONITOR = 16,
5082 SPIHD_MONITOR = 17,
5083 SPIWP_MONITOR = 18,
5084 SPICS1 = 19,
5085 CPU_GPIO_0 = 28,
5086 CPU_GPIO_1 = 29,
5087 CPU_GPIO_2 = 30,
5088 CPU_GPIO_3 = 31,
5089 CPU_GPIO_4 = 32,
5090 CPU_GPIO_5 = 33,
5091 CPU_GPIO_6 = 34,
5092 CPU_GPIO_7 = 35,
5093 LEDC_LS_SIG0 = 45,
5094 LEDC_LS_SIG1 = 46,
5095 LEDC_LS_SIG2 = 47,
5096 LEDC_LS_SIG3 = 48,
5097 LEDC_LS_SIG4 = 49,
5098 LEDC_LS_SIG5 = 50,
5099 RMT_SIG_0 = 51,
5100 RMT_SIG_1 = 52,
5101 I2CEXT0_SCL = 53,
5102 I2CEXT0_SDA = 54,
5103 FSPICLK = 63,
5104 FSPIQ = 64,
5105 FSPID = 65,
5106 FSPIHD = 66,
5107 FSPIWP = 67,
5108 FSPICS0 = 68,
5109 FSPICS1 = 69,
5110 FSPICS3 = 70,
5111 FSPICS2 = 71,
5112 FSPICS4 = 72,
5113 FSPICS5 = 73,
5114 ANT_SEL0 = 89,
5115 ANT_SEL1 = 90,
5116 ANT_SEL2 = 91,
5117 ANT_SEL3 = 92,
5118 ANT_SEL4 = 93,
5119 ANT_SEL5 = 94,
5120 ANT_SEL6 = 95,
5121 ANT_SEL7 = 96,
5122 SIG_FUNC_97 = 97,
5123 SIG_FUNC_98 = 98,
5124 SIG_FUNC_99 = 99,
5125 SIG_FUNC_100 = 100,
5126 CLK_OUT1 = 123,
5127 CLK_OUT2 = 124,
5128 CLK_OUT3 = 125,
5129 GPIO = 128,
5130 MTDO,
5131 }
5132 };
5133}
5134#[macro_export]
5141#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5142macro_rules! define_lp_functions {
5143 () => {
5144 #[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
5149 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
5150 #[doc(hidden)]
5151 pub enum LpFunction {
5152 _0 = 0,
5154 }
5155 impl LpFunction {
5156 pub const LP_GPIO: Self = Self::_0;
5158 }
5159 };
5160}
5161#[macro_export]
5174#[expect(clippy::crate_in_macro_def)]
5175#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
5176macro_rules! define_io_mux_reg {
5177 () => {
5178 pub(crate) fn io_mux_reg(gpio_num: u8) -> &'static crate::pac::io_mux::GPIO {
5179 crate::peripherals::IO_MUX::regs().gpio(gpio_num as usize)
5180 }
5181 };
5182}