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.has_bank_1") => {
92 false
93 };
94 ("gpio.input_signal_max") => {
95 100
96 };
97 ("gpio.input_signal_max", str) => {
98 stringify!(100)
99 };
100 ("gpio.output_signal_max") => {
101 128
102 };
103 ("gpio.output_signal_max", str) => {
104 stringify!(128)
105 };
106 ("dedicated_gpio.version") => {
107 "riscv_v1"
108 };
109 ("dedicated_gpio.needs_initialization") => {
110 false
111 };
112 ("dedicated_gpio.channel_count") => {
113 8
114 };
115 ("dedicated_gpio.channel_count", str) => {
116 stringify!(8)
117 };
118 ("lp_io.version") => {
119 "v3"
120 };
121 ("lp_io.has_gpio_matrix") => {
122 false
123 };
124 ("uart.ram_size") => {
125 128
126 };
127 ("uart.ram_size", str) => {
128 stringify!(128)
129 };
130 ("uart.version") => {
131 1
132 };
133 ("uart.version", str) => {
134 stringify!(1)
135 };
136 ("uart.peripheral_controls_mem_clk") => {
137 false
138 };
139 ("uart.has_sclk_divider") => {
140 true
141 };
142 ("uart.has_sclk_enable") => {
143 true
144 };
145 ("i2c_master.version") => {
146 3
147 };
148 ("i2c_master.version", str) => {
149 stringify!(3)
150 };
151 ("i2c_master.has_fsm_timeouts") => {
152 true
153 };
154 ("i2c_master.has_hw_bus_clear") => {
155 true
156 };
157 ("i2c_master.has_bus_timeout_enable") => {
158 true
159 };
160 ("i2c_master.separate_filter_config_registers") => {
161 false
162 };
163 ("i2c_master.can_estimate_nack_reason") => {
164 false
165 };
166 ("i2c_master.has_conf_update") => {
167 true
168 };
169 ("i2c_master.has_reliable_fsm_reset") => {
170 false
171 };
172 ("i2c_master.has_arbitration_en") => {
173 true
174 };
175 ("i2c_master.has_tx_fifo_watermark") => {
176 true
177 };
178 ("i2c_master.bus_timeout_is_exponential") => {
179 true
180 };
181 ("i2c_master.has_pd_en") => {
182 true
183 };
184 ("i2c_master.max_bus_timeout") => {
185 31
186 };
187 ("i2c_master.max_bus_timeout", str) => {
188 stringify!(31)
189 };
190 ("i2c_master.ll_intr_mask") => {
191 262143
192 };
193 ("i2c_master.ll_intr_mask", str) => {
194 stringify!(262143)
195 };
196 ("i2c_master.fifo_size") => {
197 16
198 };
199 ("i2c_master.fifo_size", str) => {
200 stringify!(16)
201 };
202 ("spi_master.version") => {
203 3
204 };
205 ("spi_master.version", str) => {
206 stringify!(3)
207 };
208 ("spi_master.fifo_size") => {
209 64
210 };
211 ("spi_master.fifo_size", str) => {
212 stringify!(64)
213 };
214 ("spi_master.bit_order_is_bool") => {
215 false
216 };
217 ("spi_master.has_octal") => {
218 false
219 };
220 ("spi_master.has_app_interrupts") => {
221 true
222 };
223 ("spi_master.has_dma_segmented_transfer") => {
224 true
225 };
226 ("spi_master.has_clk_pre_div") => {
227 false
228 };
229 ("spi_master.dma_can_access_flash") => {
230 false
231 };
232 ("bt.controller") => {
233 "npl"
234 };
235 ("wifi.has_wifi6") => {
236 false
237 };
238 ("wifi.mac_version") => {
239 1
240 };
241 ("wifi.mac_version", str) => {
242 stringify!(1)
243 };
244 ("wifi.has_5g") => {
245 false
246 };
247 ("wifi.csi_supported") => {
248 false
249 };
250 ("phy.combo_module") => {
251 true
252 };
253 ("ledc.version") => {
254 2
255 };
256 ("ledc.version", str) => {
257 stringify!(2)
258 };
259 ("ledc.channel_count") => {
260 6
261 };
262 ("ledc.channel_count", str) => {
263 stringify!(6)
264 };
265 ("timergroup.timg_has_timer1") => {
266 false
267 };
268 ("timergroup.timg_has_divcnt_rst") => {
269 true
270 };
271 ("ecc.zero_extend_writes") => {
272 true
273 };
274 ("ecc.separate_jacobian_point_memory") => {
275 false
276 };
277 ("ecc.has_memory_clock_gate") => {
278 false
279 };
280 ("ecc.supports_enhanced_security") => {
281 false
282 };
283 ("ecc.mem_block_size") => {
284 32
285 };
286 ("rng.apb_cycle_wait_num") => {
287 16
288 };
289 ("rng.apb_cycle_wait_num", str) => {
290 stringify!(16)
291 };
292 ("rng.trng_supported") => {
293 true
294 };
295 ("rng.is_lp_sys") => {
296 false
297 };
298 ("sleep.light_sleep") => {
299 true
300 };
301 ("sleep.deep_sleep") => {
302 true
303 };
304 ("sleep.rejectable_mask") => {
305 1852
306 };
307 ("sleep.pin_wakeup_version") => {
308 2
309 };
310 ("sleep.pin_wakeup_version", str) => {
311 stringify!(2)
312 };
313 ("sleep.deep_sleep_needs_gpio_isolation") => {
314 true
315 };
316 ("assist_debug.has_sp_monitor") => {
317 true
318 };
319 ("assist_debug.has_region_monitor") => {
320 false
321 };
322 ("dma.mem2mem_requires_peripheral") => {
323 false
324 };
325 ("dma.ext_mem_configurable_block_size") => {
326 false
327 };
328 ("dma.separate_in_out_interrupts") => {
329 false
330 };
331 ("dma.gdma_version") => {
332 1
333 };
334 ("dma.gdma_version", str) => {
335 stringify!(1)
336 };
337 ("interrupts.status_registers") => {
338 2
339 };
340 ("interrupts.status_registers", str) => {
341 stringify!(2)
342 };
343 ("interrupts.disabled_interrupt") => {
344 0
345 };
346 ("mmu.page_size") => {
347 65536
348 };
349 ("mmu.page_size", str) => {
350 stringify!(65536)
351 };
352 ("mmu.entry_num") => {
353 64
354 };
355 ("mmu.entry_num", str) => {
356 stringify!(64)
357 };
358 ("rom.has_crc_le") => {
359 true
360 };
361 ("rom.has_crc_be") => {
362 true
363 };
364 ("rom.has_md5_bsd") => {
365 false
366 };
367 ("rom.has_md5_mbedtls") => {
368 true
369 };
370 ("soc.cpu_has_branch_predictor") => {
371 false
372 };
373 ("soc.cpu_has_csr_pc") => {
374 true
375 };
376 ("soc.multi_core_enabled") => {
377 false
378 };
379 ("soc.internal_memory_cached") => {
380 false
381 };
382 ("soc.has_swd_watchdog") => {
383 true
384 };
385 ("soc.cpu_mcause_mask") => {
386 31
387 };
388 ("soc.cpu_mcause_mask", str) => {
389 stringify!(31)
390 };
391 ("clock_tree.system_pre_div_in") => {
392 [crate ::soc::clocks::SystemPreDivInConfig::Xtal, crate
393 ::soc::clocks::SystemPreDivInConfig::RcFast]
394 };
395 ("clock_tree.system_pre_div.divisor") => {
396 (0, 1023)
397 };
398 ("clock_tree.cpu_pll_div.divisor") => {
399 [4, 6]
400 };
401 ("clock_tree.cpu_clk") => {
402 [crate ::soc::clocks::CpuClkConfig::Xtal, crate
403 ::soc::clocks::CpuClkConfig::RcFast, crate ::soc::clocks::CpuClkConfig::Pll]
404 };
405 ("clock_tree.apb_clk") => {
406 [crate ::soc::clocks::ApbClkConfig::Pll40m, crate
407 ::soc::clocks::ApbClkConfig::Cpu]
408 };
409 ("clock_tree.crypto_clk") => {
410 [crate ::soc::clocks::CryptoClkConfig::Pll80m, crate
411 ::soc::clocks::CryptoClkConfig::Cpu]
412 };
413 ("clock_tree.mspi_clk") => {
414 [crate ::soc::clocks::MspiClkConfig::CpuDiv2, crate
415 ::soc::clocks::MspiClkConfig::Cpu]
416 };
417 ("clock_tree.rc_fast_clk_div_n.divisor") => {
418 (0, 3)
419 };
420 ("clock_tree.rtc_slow_clk") => {
421 [crate ::soc::clocks::RtcSlowClkConfig::OscSlow, crate
422 ::soc::clocks::RtcSlowClkConfig::RcSlow, crate
423 ::soc::clocks::RtcSlowClkConfig::RcFast]
424 };
425 ("clock_tree.rtc_fast_clk") => {
426 [crate ::soc::clocks::RtcFastClkConfig::Xtal, crate
427 ::soc::clocks::RtcFastClkConfig::Rc]
428 };
429 ("clock_tree.low_power_clk") => {
430 [crate ::soc::clocks::LowPowerClkConfig::Xtal, crate
431 ::soc::clocks::LowPowerClkConfig::RcFast, crate
432 ::soc::clocks::LowPowerClkConfig::OscSlow, crate
433 ::soc::clocks::LowPowerClkConfig::RtcSlow]
434 };
435 ("clock_tree.timg_calibration_clock") => {
436 [crate ::soc::clocks::TimgCalibrationClockConfig::RcSlowClk, crate
437 ::soc::clocks::TimgCalibrationClockConfig::RcFastDivClk, crate
438 ::soc::clocks::TimgCalibrationClockConfig::Osc32kClk]
439 };
440 ("clock_tree.timg.function_clock") => {
441 [crate ::soc::clocks::TimgFunctionClockConfig::XtalClk, crate
442 ::soc::clocks::TimgFunctionClockConfig::Pll40m]
443 };
444 ("clock_tree.timg.wdt_clock") => {
445 [crate ::soc::clocks::TimgWdtClockConfig::Pll40m, crate
446 ::soc::clocks::TimgWdtClockConfig::XtalClk]
447 };
448 ("clock_tree.uart.function_clock.sclk") => {
449 [crate ::soc::clocks::UartFunctionClockSclk::PllF40m, crate
450 ::soc::clocks::UartFunctionClockSclk::RcFast, crate
451 ::soc::clocks::UartFunctionClockSclk::Xtal]
452 };
453 ("clock_tree.uart.function_clock.div_num") => {
454 (0, 255)
455 };
456 ("clock_tree.uart.baud_rate_generator.fractional") => {
457 (0, 15)
458 };
459 ("clock_tree.uart.baud_rate_generator.integral") => {
460 (0, 4095)
461 };
462 ("clock_tree.i2c.function_clock.sclk") => {
463 [crate ::soc::clocks::I2cFunctionClockSclk::Xtal, crate
464 ::soc::clocks::I2cFunctionClockSclk::RcFast]
465 };
466 ("clock_tree.i2c.function_clock.div_num") => {
467 (0, 255)
468 };
469 ("clock_tree.spi.function_clock") => {
470 [crate ::soc::clocks::SpiFunctionClockConfig::Xtal, crate
471 ::soc::clocks::SpiFunctionClockConfig::Pll40m]
472 };
473}
474#[macro_export]
475#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
476macro_rules! for_each_dedicated_gpio {
477 ($($pattern:tt => $code:tt;)*) => {
478 macro_rules! _for_each_inner_dedicated_gpio { $(($pattern) => $code;)* ($other :
479 tt) => {} } _for_each_inner_dedicated_gpio!((0));
480 _for_each_inner_dedicated_gpio!((1)); _for_each_inner_dedicated_gpio!((2));
481 _for_each_inner_dedicated_gpio!((3)); _for_each_inner_dedicated_gpio!((4));
482 _for_each_inner_dedicated_gpio!((5)); _for_each_inner_dedicated_gpio!((6));
483 _for_each_inner_dedicated_gpio!((7)); _for_each_inner_dedicated_gpio!((0, 0,
484 CPU_GPIO_0)); _for_each_inner_dedicated_gpio!((0, 1, CPU_GPIO_1));
485 _for_each_inner_dedicated_gpio!((0, 2, CPU_GPIO_2));
486 _for_each_inner_dedicated_gpio!((0, 3, CPU_GPIO_3));
487 _for_each_inner_dedicated_gpio!((0, 4, CPU_GPIO_4));
488 _for_each_inner_dedicated_gpio!((0, 5, CPU_GPIO_5));
489 _for_each_inner_dedicated_gpio!((0, 6, CPU_GPIO_6));
490 _for_each_inner_dedicated_gpio!((0, 7, CPU_GPIO_7));
491 _for_each_inner_dedicated_gpio!((channels(0), (1), (2), (3), (4), (5), (6),
492 (7))); _for_each_inner_dedicated_gpio!((signals(0, 0, CPU_GPIO_0), (0, 1,
493 CPU_GPIO_1), (0, 2, CPU_GPIO_2), (0, 3, CPU_GPIO_3), (0, 4, CPU_GPIO_4), (0, 5,
494 CPU_GPIO_5), (0, 6, CPU_GPIO_6), (0, 7, CPU_GPIO_7)));
495 };
496}
497#[macro_export]
501#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
502macro_rules! define_lp_io_signals {
503 () => {};
504}
505#[macro_export]
506#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
507macro_rules! for_each_ecc_working_mode {
508 ($($pattern:tt => $code:tt;)*) => {
509 macro_rules! _for_each_inner_ecc_working_mode { $(($pattern) => $code;)* ($other
510 : tt) => {} } _for_each_inner_ecc_working_mode!((0, AffinePointMultiplication));
511 _for_each_inner_ecc_working_mode!((1, FiniteFieldDivision));
512 _for_each_inner_ecc_working_mode!((2, AffinePointVerification));
513 _for_each_inner_ecc_working_mode!((3, AffinePointVerificationAndMultiplication));
514 _for_each_inner_ecc_working_mode!((4, JacobianPointMultiplication));
515 _for_each_inner_ecc_working_mode!((6, JacobianPointVerification));
516 _for_each_inner_ecc_working_mode!((7,
517 AffinePointVerificationAndJacobianPointMultiplication));
518 _for_each_inner_ecc_working_mode!((all(0, AffinePointMultiplication), (1,
519 FiniteFieldDivision), (2, AffinePointVerification), (3,
520 AffinePointVerificationAndMultiplication), (4, JacobianPointMultiplication), (6,
521 JacobianPointVerification), (7,
522 AffinePointVerificationAndJacobianPointMultiplication)));
523 };
524}
525#[macro_export]
526#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
527macro_rules! for_each_ecc_curve {
528 ($($pattern:tt => $code:tt;)*) => {
529 macro_rules! _for_each_inner_ecc_curve { $(($pattern) => $code;)* ($other : tt)
530 => {} } _for_each_inner_ecc_curve!((0, P192, 192));
531 _for_each_inner_ecc_curve!((1, P256, 256)); _for_each_inner_ecc_curve!((all(0,
532 P192, 192), (1, P256, 256)));
533 };
534}
535#[macro_export]
536#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
537macro_rules! for_each_sha_algorithm {
538 ($($pattern:tt => $code:tt;)*) => {
539 macro_rules! _for_each_inner_sha_algorithm { $(($pattern) => $code;)* ($other :
540 tt) => {} } _for_each_inner_sha_algorithm!((Sha1, "SHA-1"(sizes : 64, 20, 8)
541 (insecure_against : "collision", "length extension"), 0));
542 _for_each_inner_sha_algorithm!((Sha224, "SHA-224"(sizes : 64, 28, 8)
543 (insecure_against : "length extension"), 1));
544 _for_each_inner_sha_algorithm!((Sha256, "SHA-256"(sizes : 64, 32, 8)
545 (insecure_against : "length extension"), 2));
546 _for_each_inner_sha_algorithm!((algos(Sha1, "SHA-1"(sizes : 64, 20, 8)
547 (insecure_against : "collision", "length extension"), 0), (Sha224,
548 "SHA-224"(sizes : 64, 28, 8) (insecure_against : "length extension"), 1),
549 (Sha256, "SHA-256"(sizes : 64, 32, 8) (insecure_against : "length extension"),
550 2)));
551 };
552}
553#[macro_export]
554#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
555macro_rules! for_each_wakeup_source {
556 ($($pattern:tt => $code:tt;)*) => {
557 macro_rules! _for_each_inner_wakeup_source { $(($pattern) => $code;)* ($other :
558 tt) => {} } _for_each_inner_wakeup_source!((Gpio, 2));
559 _for_each_inner_wakeup_source!((Timer, 3)); _for_each_inner_wakeup_source!((Sdio,
560 4)); _for_each_inner_wakeup_source!((Wifi, 5));
561 _for_each_inner_wakeup_source!((Uart0, 6));
562 _for_each_inner_wakeup_source!((Uart1, 7));
563 _for_each_inner_wakeup_source!((Touch, 8)); _for_each_inner_wakeup_source!((Ulp,
564 9)); _for_each_inner_wakeup_source!((Bt, 10));
565 _for_each_inner_wakeup_source!((all(Gpio, 2), (Timer, 3), (Sdio, 4), (Wifi, 5),
566 (Uart0, 6), (Uart1, 7), (Touch, 8), (Ulp, 9), (Bt, 10)));
567 };
568}
569#[macro_export]
570#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
571macro_rules! for_each_dma_engine {
572 ($($pattern:tt => $code:tt;)*) => {
573 macro_rules! _for_each_inner_dma_engine { $(($pattern) => $code;)* ($other : tt)
574 => {} } _for_each_inner_dma_engine!(("AHB_GDMA"));
575 _for_each_inner_dma_engine!((all("AHB_GDMA")));
576 };
577}
578#[macro_export]
579#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
580macro_rules! for_each_dma_channel {
581 ($($pattern:tt => $code:tt;)*) => {
582 macro_rules! _for_each_inner_dma_channel { $(($pattern) => $code;)* ($other : tt)
583 => {} } _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH0));
584 _for_each_inner_dma_channel!(("AHB_GDMA", DMA_CH0, 0, interrupt = DMA_CH0,
585 compatible = [SPI2, SHA])); _for_each_inner_dma_channel!((names("AHB_GDMA",
586 DMA_CH0))); _for_each_inner_dma_channel!((separate_any_type));
587 _for_each_inner_dma_channel!((shared("AHB_GDMA", DMA_CH0, 0, interrupt = DMA_CH0,
588 compatible = [SPI2, SHA]))); _for_each_inner_dma_channel!((split));
589 _for_each_inner_dma_channel!((no_own_interrupt));
590 };
591}
592#[macro_export]
593#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
594macro_rules! for_each_dma_channel_peri_pair {
595 ($($pattern:tt => $code:tt;)*) => {
596 macro_rules! _for_each_inner_dma_channel_peri_pair { $(($pattern) => $code;)*
597 ($other : tt) => {} } _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA",
598 DMA_CH0, SPI2)); _for_each_inner_dma_channel_peri_pair!(("AHB_GDMA", DMA_CH0,
599 SHA)); _for_each_inner_dma_channel_peri_pair!((channels("AHB_GDMA", DMA_CH0,
600 SPI2), ("AHB_GDMA", DMA_CH0, SHA)));
601 _for_each_inner_dma_channel_peri_pair!((any_channels));
602 };
603}
604#[macro_export]
605#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
606macro_rules! for_each_mem2mem_channel {
607 ($($pattern:tt => $code:tt;)*) => {
608 macro_rules! _for_each_inner_mem2mem_channel { $(($pattern) => $code;)* ($other :
609 tt) => {} } _for_each_inner_mem2mem_channel!(("AHB_GDMA", AhbGdma,
610 AhbGdmaChannel, DMA_CH0, 2)); _for_each_inner_mem2mem_channel!(("AHB_GDMA",
611 AhbGdma, AhbGdmaChannel, 0, 2)); _for_each_inner_mem2mem_channel!(("AHB_GDMA",
612 AhbGdma, AhbGdmaChannel)); _for_each_inner_mem2mem_channel!((channels("AHB_GDMA",
613 AhbGdma, AhbGdmaChannel, DMA_CH0, 2)));
614 _for_each_inner_mem2mem_channel!((erased("AHB_GDMA", AhbGdma, AhbGdmaChannel, 0,
615 2))); _for_each_inner_mem2mem_channel!((engines("AHB_GDMA", AhbGdma,
616 AhbGdmaChannel)));
617 };
618}
619#[macro_export]
620#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
621macro_rules! with_sha_dma_engine {
622 ($($pattern:tt => $code:tt;)*) => {
623 macro_rules! _with_inner_sha_dma_engine { $(($pattern) => $code;)* ($other : tt)
624 => {} } _with_inner_sha_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
625 };
626}
627#[macro_export]
628#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
629macro_rules! with_spi_master_dma_engine {
630 ($($pattern:tt => $code:tt;)*) => {
631 macro_rules! _with_inner_spi_master_dma_engine { $(($pattern) => $code;)* ($other
632 : tt) => {} } _with_inner_spi_master_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
633 };
634}
635#[macro_export]
636#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
637macro_rules! with_spi_slave_dma_engine {
638 ($($pattern:tt => $code:tt;)*) => {
639 macro_rules! _with_inner_spi_slave_dma_engine { $(($pattern) => $code;)* ($other
640 : tt) => {} } _with_inner_spi_slave_dma_engine!(("AHB_GDMA", AhbGdmaChannel));
641 };
642}
643#[macro_export]
644#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
645macro_rules! for_each_interrupt {
646 ($($pattern:tt => $code:tt;)*) => {
647 macro_rules! _for_each_inner_interrupt { $(($pattern) => $code;)* ($other : tt)
648 => {} } _for_each_inner_interrupt!(([disabled 0] 0));
649 _for_each_inner_interrupt!(([reserved 0] 1));
650 _for_each_inner_interrupt!(([direct_bindable 0] 2));
651 _for_each_inner_interrupt!(([direct_bindable 1] 3));
652 _for_each_inner_interrupt!(([direct_bindable 2] 4));
653 _for_each_inner_interrupt!(([direct_bindable 3] 5));
654 _for_each_inner_interrupt!(([direct_bindable 4] 6));
655 _for_each_inner_interrupt!(([direct_bindable 5] 7));
656 _for_each_inner_interrupt!(([direct_bindable 6] 8));
657 _for_each_inner_interrupt!(([direct_bindable 7] 9));
658 _for_each_inner_interrupt!(([direct_bindable 8] 10));
659 _for_each_inner_interrupt!(([direct_bindable 9] 11));
660 _for_each_inner_interrupt!(([direct_bindable 10] 12));
661 _for_each_inner_interrupt!(([direct_bindable 11] 13));
662 _for_each_inner_interrupt!(([direct_bindable 12] 14));
663 _for_each_inner_interrupt!(([direct_bindable 13] 15));
664 _for_each_inner_interrupt!(([direct_bindable 14] 16));
665 _for_each_inner_interrupt!(([vector 0] 17)); _for_each_inner_interrupt!(([vector
666 1] 18)); _for_each_inner_interrupt!(([vector 2] 19));
667 _for_each_inner_interrupt!(([vector 3] 20)); _for_each_inner_interrupt!(([vector
668 4] 21)); _for_each_inner_interrupt!(([vector 5] 22));
669 _for_each_inner_interrupt!(([vector 6] 23)); _for_each_inner_interrupt!(([vector
670 7] 24)); _for_each_inner_interrupt!(([vector 8] 25));
671 _for_each_inner_interrupt!(([vector 9] 26)); _for_each_inner_interrupt!(([vector
672 10] 27)); _for_each_inner_interrupt!(([vector 11] 28));
673 _for_each_inner_interrupt!(([vector 12] 29)); _for_each_inner_interrupt!(([vector
674 13] 30)); _for_each_inner_interrupt!(([vector 14] 31));
675 _for_each_inner_interrupt!((all([disabled 0] 0), ([reserved 0] 1),
676 ([direct_bindable 0] 2), ([direct_bindable 1] 3), ([direct_bindable 2] 4),
677 ([direct_bindable 3] 5), ([direct_bindable 4] 6), ([direct_bindable 5] 7),
678 ([direct_bindable 6] 8), ([direct_bindable 7] 9), ([direct_bindable 8] 10),
679 ([direct_bindable 9] 11), ([direct_bindable 10] 12), ([direct_bindable 11] 13),
680 ([direct_bindable 12] 14), ([direct_bindable 13] 15), ([direct_bindable 14] 16),
681 ([vector 0] 17), ([vector 1] 18), ([vector 2] 19), ([vector 3] 20), ([vector 4]
682 21), ([vector 5] 22), ([vector 6] 23), ([vector 7] 24), ([vector 8] 25), ([vector
683 9] 26), ([vector 10] 27), ([vector 11] 28), ([vector 12] 29), ([vector 13] 30),
684 ([vector 14] 31)));
685 };
686}
687#[macro_export]
688#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
689macro_rules! for_each_classified_interrupt {
690 ($($pattern:tt => $code:tt;)*) => {
691 macro_rules! _for_each_inner_classified_interrupt { $(($pattern) => $code;)*
692 ($other : tt) => {} } _for_each_inner_classified_interrupt!(([direct_bindable 0]
693 2)); _for_each_inner_classified_interrupt!(([direct_bindable 1] 3));
694 _for_each_inner_classified_interrupt!(([direct_bindable 2] 4));
695 _for_each_inner_classified_interrupt!(([direct_bindable 3] 5));
696 _for_each_inner_classified_interrupt!(([direct_bindable 4] 6));
697 _for_each_inner_classified_interrupt!(([direct_bindable 5] 7));
698 _for_each_inner_classified_interrupt!(([direct_bindable 6] 8));
699 _for_each_inner_classified_interrupt!(([direct_bindable 7] 9));
700 _for_each_inner_classified_interrupt!(([direct_bindable 8] 10));
701 _for_each_inner_classified_interrupt!(([direct_bindable 9] 11));
702 _for_each_inner_classified_interrupt!(([direct_bindable 10] 12));
703 _for_each_inner_classified_interrupt!(([direct_bindable 11] 13));
704 _for_each_inner_classified_interrupt!(([direct_bindable 12] 14));
705 _for_each_inner_classified_interrupt!(([direct_bindable 13] 15));
706 _for_each_inner_classified_interrupt!(([direct_bindable 14] 16));
707 _for_each_inner_classified_interrupt!(([vector 0] 17));
708 _for_each_inner_classified_interrupt!(([vector 1] 18));
709 _for_each_inner_classified_interrupt!(([vector 2] 19));
710 _for_each_inner_classified_interrupt!(([vector 3] 20));
711 _for_each_inner_classified_interrupt!(([vector 4] 21));
712 _for_each_inner_classified_interrupt!(([vector 5] 22));
713 _for_each_inner_classified_interrupt!(([vector 6] 23));
714 _for_each_inner_classified_interrupt!(([vector 7] 24));
715 _for_each_inner_classified_interrupt!(([vector 8] 25));
716 _for_each_inner_classified_interrupt!(([vector 9] 26));
717 _for_each_inner_classified_interrupt!(([vector 10] 27));
718 _for_each_inner_classified_interrupt!(([vector 11] 28));
719 _for_each_inner_classified_interrupt!(([vector 12] 29));
720 _for_each_inner_classified_interrupt!(([vector 13] 30));
721 _for_each_inner_classified_interrupt!(([vector 14] 31));
722 _for_each_inner_classified_interrupt!(([reserved 0] 1));
723 _for_each_inner_classified_interrupt!((direct_bindable([direct_bindable 0] 2),
724 ([direct_bindable 1] 3), ([direct_bindable 2] 4), ([direct_bindable 3] 5),
725 ([direct_bindable 4] 6), ([direct_bindable 5] 7), ([direct_bindable 6] 8),
726 ([direct_bindable 7] 9), ([direct_bindable 8] 10), ([direct_bindable 9] 11),
727 ([direct_bindable 10] 12), ([direct_bindable 11] 13), ([direct_bindable 12] 14),
728 ([direct_bindable 13] 15), ([direct_bindable 14] 16)));
729 _for_each_inner_classified_interrupt!((vector([vector 0] 17), ([vector 1] 18),
730 ([vector 2] 19), ([vector 3] 20), ([vector 4] 21), ([vector 5] 22), ([vector 6]
731 23), ([vector 7] 24), ([vector 8] 25), ([vector 9] 26), ([vector 10] 27),
732 ([vector 11] 28), ([vector 12] 29), ([vector 13] 30), ([vector 14] 31)));
733 _for_each_inner_classified_interrupt!((reserved([reserved 0] 1)));
734 };
735}
736#[macro_export]
737#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
738macro_rules! for_each_interrupt_priority {
739 ($($pattern:tt => $code:tt;)*) => {
740 macro_rules! _for_each_inner_interrupt_priority { $(($pattern) => $code;)*
741 ($other : tt) => {} } _for_each_inner_interrupt_priority!((0, 1, Priority1,
742 Level1)); _for_each_inner_interrupt_priority!((1, 2, Priority2, Level2));
743 _for_each_inner_interrupt_priority!((2, 3, Priority3, Level3));
744 _for_each_inner_interrupt_priority!((3, 4, Priority4, Level4));
745 _for_each_inner_interrupt_priority!((4, 5, Priority5, Level5));
746 _for_each_inner_interrupt_priority!((5, 6, Priority6, Level6));
747 _for_each_inner_interrupt_priority!((6, 7, Priority7, Level7));
748 _for_each_inner_interrupt_priority!((7, 8, Priority8, Level8));
749 _for_each_inner_interrupt_priority!((8, 9, Priority9, Level9));
750 _for_each_inner_interrupt_priority!((9, 10, Priority10, Level10));
751 _for_each_inner_interrupt_priority!((10, 11, Priority11, Level11));
752 _for_each_inner_interrupt_priority!((11, 12, Priority12, Level12));
753 _for_each_inner_interrupt_priority!((12, 13, Priority13, Level13));
754 _for_each_inner_interrupt_priority!((13, 14, Priority14, Level14));
755 _for_each_inner_interrupt_priority!((14, 15, Priority15, Level15));
756 _for_each_inner_interrupt_priority!((all(0, 1, Priority1, Level1), (1, 2,
757 Priority2, Level2), (2, 3, Priority3, Level3), (3, 4, Priority4, Level4), (4, 5,
758 Priority5, Level5), (5, 6, Priority6, Level6), (6, 7, Priority7, Level7), (7, 8,
759 Priority8, Level8), (8, 9, Priority9, Level9), (9, 10, Priority10, Level10), (10,
760 11, Priority11, Level11), (11, 12, Priority12, Level12), (12, 13, Priority13,
761 Level13), (13, 14, Priority14, Level14), (14, 15, Priority15, Level15)));
762 };
763}
764#[macro_export]
765#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
766macro_rules! for_each_sw_interrupt {
767 ($($pattern:tt => $code:tt;)*) => {
768 macro_rules! _for_each_inner_sw_interrupt { $(($pattern) => $code;)* ($other :
769 tt) => {} } _for_each_inner_sw_interrupt!((0, FROM_CPU_INTR0,
770 software_interrupt0)); _for_each_inner_sw_interrupt!((1, FROM_CPU_INTR1,
771 software_interrupt1)); _for_each_inner_sw_interrupt!((2, FROM_CPU_INTR2,
772 software_interrupt2)); _for_each_inner_sw_interrupt!((3, FROM_CPU_INTR3,
773 software_interrupt3)); _for_each_inner_sw_interrupt!((all(0, FROM_CPU_INTR0,
774 software_interrupt0), (1, FROM_CPU_INTR1, software_interrupt1), (2,
775 FROM_CPU_INTR2, software_interrupt2), (3, FROM_CPU_INTR3, software_interrupt3)));
776 };
777}
778#[macro_export]
779macro_rules! define_clock_tree_types {
1123 () => {
1124 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1125 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1126 pub enum I2cInstance {
1127 I2c0 = 0,
1128 }
1129 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1130 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1131 pub enum SpiInstance {
1132 Spi2 = 0,
1133 }
1134 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1135 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1136 pub enum TimgInstance {
1137 Timg0 = 0,
1138 }
1139 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
1140 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1141 pub enum UartInstance {
1142 Uart0 = 0,
1143 Uart1 = 1,
1144 }
1145 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1147 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1148 pub enum XtalClkConfig {
1149 _26,
1151 _40,
1153 }
1154 impl XtalClkConfig {
1155 pub fn value(&self) -> u32 {
1156 match self {
1157 XtalClkConfig::_26 => 26000000,
1158 XtalClkConfig::_40 => 40000000,
1159 }
1160 }
1161 }
1162 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1164 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1165 pub enum SystemPreDivInConfig {
1166 Xtal,
1168 RcFast,
1170 }
1171 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1175 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1176 pub struct SystemPreDivConfig {
1177 divisor: u32,
1178 }
1179 impl SystemPreDivConfig {
1180 pub const fn new(divisor: u32) -> Self {
1187 ::core::assert!(
1188 divisor <= 1023,
1189 "`SYSTEM_PRE_DIV` divisor must be between 0 and 1023 (inclusive)."
1190 );
1191 Self { divisor }
1192 }
1193 pub(crate) fn divisor(self) -> u32 {
1194 self.divisor as u32
1195 }
1196 }
1197 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1198 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1199 pub enum CpuPllDivDivisor {
1200 _4 = 4,
1202 _6 = 6,
1204 }
1205 impl CpuPllDivDivisor {
1206 pub const fn new(raw: u32) -> Self {
1208 match raw {
1209 4 => Self::_4,
1210 6 => Self::_6,
1211 _ => ::core::panic!("Invalid CPU_PLL_DIV divisor value"),
1212 }
1213 }
1214 }
1215 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1219 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1220 pub struct CpuPllDivConfig {
1221 divisor: CpuPllDivDivisor,
1222 }
1223 impl CpuPllDivConfig {
1224 pub const fn new(divisor: CpuPllDivDivisor) -> Self {
1226 Self { divisor }
1227 }
1228 pub(crate) fn divisor(self) -> u32 {
1229 self.divisor as u32
1230 }
1231 }
1232 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1234 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1235 pub enum ApbClkConfig {
1236 Pll40m,
1238 Cpu,
1240 }
1241 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1243 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1244 pub enum CryptoClkConfig {
1245 Pll80m,
1247 Cpu,
1249 }
1250 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1252 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1253 pub enum MspiClkConfig {
1254 CpuDiv2,
1256 Cpu,
1258 }
1259 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1261 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1262 pub enum CpuClkConfig {
1263 Xtal,
1265 RcFast,
1267 Pll,
1269 }
1270 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1274 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1275 pub struct RcFastClkDivNConfig {
1276 divisor: u32,
1277 }
1278 impl RcFastClkDivNConfig {
1279 pub const fn new(divisor: u32) -> Self {
1286 ::core::assert!(
1287 divisor <= 3,
1288 "`RC_FAST_CLK_DIV_N` divisor must be between 0 and 3 (inclusive)."
1289 );
1290 Self { divisor }
1291 }
1292 pub(crate) fn divisor(self) -> u32 {
1293 self.divisor as u32
1294 }
1295 }
1296 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1298 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1299 pub enum RtcSlowClkConfig {
1300 OscSlow,
1302 RcSlow,
1304 RcFast,
1306 }
1307 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1309 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1310 pub enum RtcFastClkConfig {
1311 Xtal,
1313 Rc,
1315 }
1316 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1318 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1319 pub enum LowPowerClkConfig {
1320 Xtal,
1322 RcFast,
1324 OscSlow,
1326 RtcSlow,
1328 }
1329 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1331 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1332 pub enum UartMemClkConfig {
1333 #[default]
1334 Xtal,
1336 }
1337 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1339 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1340 pub enum TimgCalibrationClockConfig {
1341 RcSlowClk,
1343 RcFastDivClk,
1345 Osc32kClk,
1347 }
1348 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1349 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1350 pub enum I2cFunctionClockSclk {
1351 #[default]
1352 Xtal,
1354 RcFast,
1356 }
1357 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1361 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1362 pub struct I2cFunctionClockConfig {
1363 sclk: I2cFunctionClockSclk,
1364 div_num: u32,
1365 }
1366 impl I2cFunctionClockConfig {
1367 pub const fn new(sclk: I2cFunctionClockSclk, div_num: u32) -> Self {
1374 ::core::assert!(
1375 div_num <= 255,
1376 "`I2C0_FUNCTION_CLOCK` div_num must be between 0 and 255 (inclusive)."
1377 );
1378 Self { sclk, div_num }
1379 }
1380 pub(crate) fn sclk(self) -> I2cFunctionClockSclk {
1381 self.sclk
1382 }
1383 pub(crate) fn div_num(self) -> u32 {
1384 self.div_num as u32
1385 }
1386 }
1387 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1389 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1390 pub enum SpiFunctionClockConfig {
1391 #[default]
1392 Xtal,
1394 Pll40m,
1396 }
1397 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1399 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1400 pub enum TimgFunctionClockConfig {
1401 #[default]
1402 XtalClk,
1404 Pll40m,
1406 }
1407 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1409 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1410 pub enum TimgWdtClockConfig {
1411 #[default]
1412 Pll40m,
1414 XtalClk,
1416 }
1417 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1418 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1419 pub enum UartFunctionClockSclk {
1420 PllF40m,
1422 RcFast,
1424 #[default]
1425 Xtal,
1427 }
1428 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1432 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1433 pub struct UartFunctionClockConfig {
1434 sclk: UartFunctionClockSclk,
1435 div_num: u32,
1436 }
1437 impl UartFunctionClockConfig {
1438 pub const fn new(sclk: UartFunctionClockSclk, div_num: u32) -> Self {
1445 ::core::assert!(
1446 div_num <= 255,
1447 "`UART0_FUNCTION_CLOCK` div_num must be between 0 and 255 (inclusive)."
1448 );
1449 Self { sclk, div_num }
1450 }
1451 pub(crate) fn sclk(self) -> UartFunctionClockSclk {
1452 self.sclk
1453 }
1454 pub(crate) fn div_num(self) -> u32 {
1455 self.div_num as u32
1456 }
1457 }
1458 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1463 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
1464 pub struct UartBaudRateGeneratorConfig {
1465 fractional: u32,
1466 integral: u32,
1467 }
1468 impl UartBaudRateGeneratorConfig {
1469 pub const fn new(fractional: u32, integral: u32) -> Self {
1479 ::core::assert!(
1480 fractional <= 15,
1481 "`UART0_BAUD_RATE_GENERATOR` fractional must be between 0 and 15 (inclusive)."
1482 );
1483 ::core::assert!(
1484 integral <= 4095,
1485 "`UART0_BAUD_RATE_GENERATOR` integral must be between 0 and 4095 (inclusive)."
1486 );
1487 Self {
1488 fractional,
1489 integral,
1490 }
1491 }
1492 pub(crate) fn fractional(self) -> u32 {
1493 self.fractional as u32
1494 }
1495 pub(crate) fn integral(self) -> u32 {
1496 self.integral as u32
1497 }
1498 }
1499 pub struct ClockTree {
1501 xtal_clk: Option<XtalClkConfig>,
1502 system_pre_div_in: Option<SystemPreDivInConfig>,
1503 system_pre_div: Option<SystemPreDivConfig>,
1504 cpu_pll_div: Option<CpuPllDivConfig>,
1505 apb_clk: Option<ApbClkConfig>,
1506 crypto_clk: Option<CryptoClkConfig>,
1507 mspi_clk: Option<MspiClkConfig>,
1508 cpu_clk: Option<CpuClkConfig>,
1509 rc_fast_clk_div_n: Option<RcFastClkDivNConfig>,
1510 rtc_slow_clk: Option<RtcSlowClkConfig>,
1511 rtc_fast_clk: Option<RtcFastClkConfig>,
1512 low_power_clk: Option<LowPowerClkConfig>,
1513 timg_calibration_clock: Option<TimgCalibrationClockConfig>,
1514 i2c_function_clock: [Option<I2cFunctionClockConfig>; 1],
1515 spi_function_clock: [Option<SpiFunctionClockConfig>; 1],
1516 timg_function_clock: [Option<TimgFunctionClockConfig>; 1],
1517 timg_wdt_clock: [Option<TimgWdtClockConfig>; 1],
1518 uart_function_clock: [Option<UartFunctionClockConfig>; 2],
1519 uart_baud_rate_generator: [Option<UartBaudRateGeneratorConfig>; 2],
1520 rc_fast_clk_refcount: u32,
1521 osc_slow_clk_refcount: u32,
1522 rc_slow_clk_refcount: u32,
1523 rc_fast_div_clk_refcount: u32,
1524 apb_clk_refcount: u32,
1525 crypto_clk_refcount: u32,
1526 mspi_clk_refcount: u32,
1527 pll_40m_refcount: u32,
1528 pll_60m_refcount: u32,
1529 rtc_fast_clk_refcount: u32,
1530 low_power_clk_refcount: u32,
1531 uart_mem_clk_refcount: u32,
1532 timg_calibration_clock_refcount: u32,
1533 i2c_function_clock_refcount: [u32; 1],
1534 spi_function_clock_refcount: [u32; 1],
1535 timg_function_clock_refcount: [u32; 1],
1536 timg_wdt_clock_refcount: [u32; 1],
1537 uart_function_clock_refcount: [u32; 2],
1538 uart_mem_clock_refcount: [u32; 2],
1539 uart_baud_rate_generator_refcount: [u32; 2],
1540 }
1541 impl ClockTree {
1542 pub fn with<R>(f: impl FnOnce(&mut ClockTree) -> R) -> R {
1544 CLOCK_TREE.with(f)
1545 }
1546 pub fn xtal_clk(&self) -> Option<XtalClkConfig> {
1548 self.xtal_clk
1549 }
1550 pub fn system_pre_div_in(&self) -> Option<SystemPreDivInConfig> {
1552 self.system_pre_div_in
1553 }
1554 pub fn system_pre_div(&self) -> Option<SystemPreDivConfig> {
1556 self.system_pre_div
1557 }
1558 pub fn cpu_pll_div(&self) -> Option<CpuPllDivConfig> {
1560 self.cpu_pll_div
1561 }
1562 pub fn apb_clk(&self) -> Option<ApbClkConfig> {
1564 self.apb_clk
1565 }
1566 pub fn crypto_clk(&self) -> Option<CryptoClkConfig> {
1568 self.crypto_clk
1569 }
1570 pub fn mspi_clk(&self) -> Option<MspiClkConfig> {
1572 self.mspi_clk
1573 }
1574 pub fn cpu_clk(&self) -> Option<CpuClkConfig> {
1576 self.cpu_clk
1577 }
1578 pub fn rc_fast_clk_div_n(&self) -> Option<RcFastClkDivNConfig> {
1580 self.rc_fast_clk_div_n
1581 }
1582 pub fn rtc_slow_clk(&self) -> Option<RtcSlowClkConfig> {
1584 self.rtc_slow_clk
1585 }
1586 pub fn rtc_fast_clk(&self) -> Option<RtcFastClkConfig> {
1588 self.rtc_fast_clk
1589 }
1590 pub fn low_power_clk(&self) -> Option<LowPowerClkConfig> {
1592 self.low_power_clk
1593 }
1594 pub fn timg_calibration_clock(&self) -> Option<TimgCalibrationClockConfig> {
1596 self.timg_calibration_clock
1597 }
1598 pub fn i2c0_function_clock(&self) -> Option<I2cFunctionClockConfig> {
1600 self.i2c_function_clock[I2cInstance::I2c0 as usize]
1601 }
1602 pub fn spi2_function_clock(&self) -> Option<SpiFunctionClockConfig> {
1604 self.spi_function_clock[SpiInstance::Spi2 as usize]
1605 }
1606 pub fn timg0_function_clock(&self) -> Option<TimgFunctionClockConfig> {
1608 self.timg_function_clock[TimgInstance::Timg0 as usize]
1609 }
1610 pub fn timg0_wdt_clock(&self) -> Option<TimgWdtClockConfig> {
1612 self.timg_wdt_clock[TimgInstance::Timg0 as usize]
1613 }
1614 pub fn uart0_function_clock(&self) -> Option<UartFunctionClockConfig> {
1616 self.uart_function_clock[UartInstance::Uart0 as usize]
1617 }
1618 pub fn uart0_baud_rate_generator(&self) -> Option<UartBaudRateGeneratorConfig> {
1620 self.uart_baud_rate_generator[UartInstance::Uart0 as usize]
1621 }
1622 pub fn uart1_function_clock(&self) -> Option<UartFunctionClockConfig> {
1624 self.uart_function_clock[UartInstance::Uart1 as usize]
1625 }
1626 pub fn uart1_baud_rate_generator(&self) -> Option<UartBaudRateGeneratorConfig> {
1628 self.uart_baud_rate_generator[UartInstance::Uart1 as usize]
1629 }
1630 }
1631 static CLOCK_TREE: ::esp_sync::NonReentrantMutex<ClockTree> =
1632 ::esp_sync::NonReentrantMutex::new(ClockTree {
1633 xtal_clk: None,
1634 system_pre_div_in: None,
1635 system_pre_div: None,
1636 cpu_pll_div: None,
1637 apb_clk: None,
1638 crypto_clk: None,
1639 mspi_clk: None,
1640 cpu_clk: None,
1641 rc_fast_clk_div_n: None,
1642 rtc_slow_clk: None,
1643 rtc_fast_clk: None,
1644 low_power_clk: None,
1645 timg_calibration_clock: None,
1646 i2c_function_clock: [None; 1],
1647 spi_function_clock: [None; 1],
1648 timg_function_clock: [None; 1],
1649 timg_wdt_clock: [None; 1],
1650 uart_function_clock: [None; 2],
1651 uart_baud_rate_generator: [None; 2],
1652 rc_fast_clk_refcount: 0,
1653 osc_slow_clk_refcount: 0,
1654 rc_slow_clk_refcount: 0,
1655 rc_fast_div_clk_refcount: 0,
1656 apb_clk_refcount: 0,
1657 crypto_clk_refcount: 0,
1658 mspi_clk_refcount: 0,
1659 pll_40m_refcount: 0,
1660 pll_60m_refcount: 0,
1661 rtc_fast_clk_refcount: 0,
1662 low_power_clk_refcount: 0,
1663 uart_mem_clk_refcount: 0,
1664 timg_calibration_clock_refcount: 0,
1665 i2c_function_clock_refcount: [0; 1],
1666 spi_function_clock_refcount: [0; 1],
1667 timg_function_clock_refcount: [0; 1],
1668 timg_wdt_clock_refcount: [0; 1],
1669 uart_function_clock_refcount: [0; 2],
1670 uart_mem_clock_refcount: [0; 2],
1671 uart_baud_rate_generator_refcount: [0; 2],
1672 });
1673 static XTAL_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1674 ::core::sync::atomic::AtomicU32::new(0);
1675 static SYSTEM_PRE_DIV_IN_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1676 ::core::sync::atomic::AtomicU32::new(0);
1677 static SYSTEM_PRE_DIV_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1678 ::core::sync::atomic::AtomicU32::new(0);
1679 static CPU_PLL_DIV_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1680 ::core::sync::atomic::AtomicU32::new(0);
1681 static CPU_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1682 ::core::sync::atomic::AtomicU32::new(0);
1683 static RC_FAST_CLK_DIV_N_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1684 ::core::sync::atomic::AtomicU32::new(0);
1685 static RTC_SLOW_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1686 ::core::sync::atomic::AtomicU32::new(0);
1687 static RTC_FAST_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1688 ::core::sync::atomic::AtomicU32::new(0);
1689 static LOW_POWER_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1690 ::core::sync::atomic::AtomicU32::new(0);
1691 static TIMG_CALIBRATION_CLOCK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1692 ::core::sync::atomic::AtomicU32::new(0);
1693 static I2C_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
1694 [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
1695 static SPI_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
1696 [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
1697 static TIMG_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
1698 [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
1699 static TIMG_WDT_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 1] =
1700 [const { ::core::sync::atomic::AtomicU32::new(0) }; 1];
1701 static UART_FUNCTION_CLOCK_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 2] =
1702 [const { ::core::sync::atomic::AtomicU32::new(0) }; 2];
1703 static UART_BAUD_RATE_GENERATOR_FREQ_CACHE: [::core::sync::atomic::AtomicU32; 2] =
1704 [const { ::core::sync::atomic::AtomicU32::new(0) }; 2];
1705 static APB_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1706 ::core::sync::atomic::AtomicU32::new(0);
1707 static CRYPTO_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1708 ::core::sync::atomic::AtomicU32::new(0);
1709 static MSPI_CLK_FREQ_CACHE: ::core::sync::atomic::AtomicU32 =
1710 ::core::sync::atomic::AtomicU32::new(0);
1711 pub fn configure_xtal_clk(clocks: &mut ClockTree, config: XtalClkConfig) {
1712 let old_config = clocks.xtal_clk.replace(config);
1713 refresh_xtal_clk_downstream(clocks);
1714 configure_xtal_clk_impl(clocks, old_config, config);
1715 }
1716 pub fn xtal_clk_config(clocks: &mut ClockTree) -> Option<XtalClkConfig> {
1717 clocks.xtal_clk
1718 }
1719 fn request_xtal_clk(_clocks: &mut ClockTree) {}
1720 fn release_xtal_clk(_clocks: &mut ClockTree) {}
1721 #[allow(unused_variables)]
1722 pub fn xtal_clk_config_frequency(clocks: &mut ClockTree, config: XtalClkConfig) -> u32 {
1723 config.value()
1724 }
1725 pub fn xtal_clk_frequency() -> u32 {
1726 XTAL_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
1727 }
1728 pub fn request_pll_clk(clocks: &mut ClockTree) {
1729 trace!("Requesting PLL_CLK");
1730 trace!("Enabling PLL_CLK");
1731 request_xtal_clk(clocks);
1732 enable_pll_clk_impl(clocks, true);
1733 }
1734 pub fn release_pll_clk(clocks: &mut ClockTree) {
1735 trace!("Releasing PLL_CLK");
1736 trace!("Disabling PLL_CLK");
1737 enable_pll_clk_impl(clocks, false);
1738 release_xtal_clk(clocks);
1739 }
1740 pub fn pll_clk_frequency() -> u32 {
1741 480000000
1742 }
1743 pub fn pll_clk_source_frequency() -> u32 {
1744 xtal_clk_frequency()
1745 }
1746 pub fn request_rc_fast_clk(clocks: &mut ClockTree) {
1747 trace!("Requesting RC_FAST_CLK");
1748 if increment_reference_count(&mut clocks.rc_fast_clk_refcount) {
1749 trace!("Enabling RC_FAST_CLK");
1750 enable_rc_fast_clk_impl(clocks, true);
1751 }
1752 }
1753 pub fn release_rc_fast_clk(clocks: &mut ClockTree) {
1754 trace!("Releasing RC_FAST_CLK");
1755 if decrement_reference_count(&mut clocks.rc_fast_clk_refcount) {
1756 trace!("Disabling RC_FAST_CLK");
1757 enable_rc_fast_clk_impl(clocks, false);
1758 }
1759 }
1760 pub fn rc_fast_clk_frequency() -> u32 {
1761 17500000
1762 }
1763 pub fn request_osc_slow_clk(clocks: &mut ClockTree) {
1764 trace!("Requesting OSC_SLOW_CLK");
1765 if increment_reference_count(&mut clocks.osc_slow_clk_refcount) {
1766 trace!("Enabling OSC_SLOW_CLK");
1767 enable_osc_slow_clk_impl(clocks, true);
1768 }
1769 }
1770 pub fn release_osc_slow_clk(clocks: &mut ClockTree) {
1771 trace!("Releasing OSC_SLOW_CLK");
1772 if decrement_reference_count(&mut clocks.osc_slow_clk_refcount) {
1773 trace!("Disabling OSC_SLOW_CLK");
1774 enable_osc_slow_clk_impl(clocks, false);
1775 }
1776 }
1777 pub fn osc_slow_clk_frequency() -> u32 {
1778 32768
1779 }
1780 pub fn request_rc_slow_clk(clocks: &mut ClockTree) {
1781 trace!("Requesting RC_SLOW_CLK");
1782 if increment_reference_count(&mut clocks.rc_slow_clk_refcount) {
1783 trace!("Enabling RC_SLOW_CLK");
1784 enable_rc_slow_clk_impl(clocks, true);
1785 }
1786 }
1787 pub fn release_rc_slow_clk(clocks: &mut ClockTree) {
1788 trace!("Releasing RC_SLOW_CLK");
1789 if decrement_reference_count(&mut clocks.rc_slow_clk_refcount) {
1790 trace!("Disabling RC_SLOW_CLK");
1791 enable_rc_slow_clk_impl(clocks, false);
1792 }
1793 }
1794 pub fn rc_slow_clk_frequency() -> u32 {
1795 136000
1796 }
1797 pub fn request_rc_fast_div_clk(clocks: &mut ClockTree) {
1798 trace!("Requesting RC_FAST_DIV_CLK");
1799 if increment_reference_count(&mut clocks.rc_fast_div_clk_refcount) {
1800 trace!("Enabling RC_FAST_DIV_CLK");
1801 request_rc_fast_clk(clocks);
1802 enable_rc_fast_div_clk_impl(clocks, true);
1803 }
1804 }
1805 pub fn release_rc_fast_div_clk(clocks: &mut ClockTree) {
1806 trace!("Releasing RC_FAST_DIV_CLK");
1807 if decrement_reference_count(&mut clocks.rc_fast_div_clk_refcount) {
1808 trace!("Disabling RC_FAST_DIV_CLK");
1809 enable_rc_fast_div_clk_impl(clocks, false);
1810 release_rc_fast_clk(clocks);
1811 }
1812 }
1813 pub fn rc_fast_div_clk_frequency() -> u32 {
1814 (rc_fast_clk_frequency() / 256)
1815 }
1816 pub fn rc_fast_div_clk_source_frequency() -> u32 {
1817 rc_fast_clk_frequency()
1818 }
1819 pub fn configure_system_pre_div_in(
1820 clocks: &mut ClockTree,
1821 new_selector: SystemPreDivInConfig,
1822 ) {
1823 let old_selector = clocks.system_pre_div_in.replace(new_selector);
1824 refresh_system_pre_div_in_downstream(clocks);
1825 match new_selector {
1826 SystemPreDivInConfig::Xtal => request_xtal_clk(clocks),
1827 SystemPreDivInConfig::RcFast => request_rc_fast_clk(clocks),
1828 }
1829 configure_system_pre_div_in_impl(clocks, old_selector, new_selector);
1830 if let Some(old_selector) = old_selector {
1831 match old_selector {
1832 SystemPreDivInConfig::Xtal => release_xtal_clk(clocks),
1833 SystemPreDivInConfig::RcFast => release_rc_fast_clk(clocks),
1834 }
1835 }
1836 }
1837 pub fn system_pre_div_in_config(clocks: &mut ClockTree) -> Option<SystemPreDivInConfig> {
1838 clocks.system_pre_div_in
1839 }
1840 pub fn request_system_pre_div_in(clocks: &mut ClockTree) {
1841 trace!("Requesting SYSTEM_PRE_DIV_IN");
1842 trace!("Enabling SYSTEM_PRE_DIV_IN");
1843 match unwrap!(clocks.system_pre_div_in) {
1844 SystemPreDivInConfig::Xtal => request_xtal_clk(clocks),
1845 SystemPreDivInConfig::RcFast => request_rc_fast_clk(clocks),
1846 }
1847 enable_system_pre_div_in_impl(clocks, true);
1848 }
1849 pub fn release_system_pre_div_in(clocks: &mut ClockTree) {
1850 trace!("Releasing SYSTEM_PRE_DIV_IN");
1851 trace!("Disabling SYSTEM_PRE_DIV_IN");
1852 enable_system_pre_div_in_impl(clocks, false);
1853 match unwrap!(clocks.system_pre_div_in) {
1854 SystemPreDivInConfig::Xtal => release_xtal_clk(clocks),
1855 SystemPreDivInConfig::RcFast => release_rc_fast_clk(clocks),
1856 }
1857 }
1858 #[allow(unused_variables)]
1859 pub fn system_pre_div_in_config_frequency(
1860 clocks: &mut ClockTree,
1861 config: SystemPreDivInConfig,
1862 ) -> u32 {
1863 match config {
1864 SystemPreDivInConfig::Xtal => xtal_clk_frequency(),
1865 SystemPreDivInConfig::RcFast => rc_fast_clk_frequency(),
1866 }
1867 }
1868 pub fn system_pre_div_in_frequency() -> u32 {
1869 SYSTEM_PRE_DIV_IN_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
1870 }
1871 pub fn system_pre_div_in_source_frequency(source: SystemPreDivInConfig) -> u32 {
1872 match source {
1873 SystemPreDivInConfig::Xtal => xtal_clk_frequency(),
1874 SystemPreDivInConfig::RcFast => rc_fast_clk_frequency(),
1875 }
1876 }
1877 pub fn configure_system_pre_div(clocks: &mut ClockTree, config: SystemPreDivConfig) {
1878 let old_config = clocks.system_pre_div.replace(config);
1879 refresh_system_pre_div_downstream(clocks);
1880 configure_system_pre_div_impl(clocks, old_config, config);
1881 }
1882 pub fn system_pre_div_config(clocks: &mut ClockTree) -> Option<SystemPreDivConfig> {
1883 clocks.system_pre_div
1884 }
1885 pub fn request_system_pre_div(clocks: &mut ClockTree) {
1886 trace!("Requesting SYSTEM_PRE_DIV");
1887 trace!("Enabling SYSTEM_PRE_DIV");
1888 request_system_pre_div_in(clocks);
1889 enable_system_pre_div_impl(clocks, true);
1890 }
1891 pub fn release_system_pre_div(clocks: &mut ClockTree) {
1892 trace!("Releasing SYSTEM_PRE_DIV");
1893 trace!("Disabling SYSTEM_PRE_DIV");
1894 enable_system_pre_div_impl(clocks, false);
1895 release_system_pre_div_in(clocks);
1896 }
1897 #[allow(unused_variables)]
1898 pub fn system_pre_div_config_frequency(
1899 clocks: &mut ClockTree,
1900 config: SystemPreDivConfig,
1901 ) -> u32 {
1902 (system_pre_div_in_frequency() / (config.divisor() + 1))
1903 }
1904 pub fn system_pre_div_frequency() -> u32 {
1905 SYSTEM_PRE_DIV_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
1906 }
1907 pub fn system_pre_div_source_frequency() -> u32 {
1908 system_pre_div_in_frequency()
1909 }
1910 pub fn configure_cpu_pll_div(clocks: &mut ClockTree, config: CpuPllDivConfig) {
1911 let old_config = clocks.cpu_pll_div.replace(config);
1912 refresh_cpu_pll_div_downstream(clocks);
1913 configure_cpu_pll_div_impl(clocks, old_config, config);
1914 }
1915 pub fn cpu_pll_div_config(clocks: &mut ClockTree) -> Option<CpuPllDivConfig> {
1916 clocks.cpu_pll_div
1917 }
1918 pub fn request_cpu_pll_div(clocks: &mut ClockTree) {
1919 trace!("Requesting CPU_PLL_DIV");
1920 trace!("Enabling CPU_PLL_DIV");
1921 request_pll_clk(clocks);
1922 enable_cpu_pll_div_impl(clocks, true);
1923 }
1924 pub fn release_cpu_pll_div(clocks: &mut ClockTree) {
1925 trace!("Releasing CPU_PLL_DIV");
1926 trace!("Disabling CPU_PLL_DIV");
1927 enable_cpu_pll_div_impl(clocks, false);
1928 release_pll_clk(clocks);
1929 }
1930 #[allow(unused_variables)]
1931 pub fn cpu_pll_div_config_frequency(
1932 clocks: &mut ClockTree,
1933 config: CpuPllDivConfig,
1934 ) -> u32 {
1935 (pll_clk_frequency() / config.divisor())
1936 }
1937 pub fn cpu_pll_div_frequency() -> u32 {
1938 CPU_PLL_DIV_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
1939 }
1940 pub fn cpu_pll_div_source_frequency() -> u32 {
1941 pll_clk_frequency()
1942 }
1943 pub fn configure_apb_clk(clocks: &mut ClockTree, new_selector: ApbClkConfig) {
1944 let old_selector = clocks.apb_clk.replace(new_selector);
1945 refresh_apb_clk_downstream(clocks);
1946 if clocks.apb_clk_refcount > 0 {
1947 match new_selector {
1948 ApbClkConfig::Pll40m => request_pll_40m(clocks),
1949 ApbClkConfig::Cpu => request_cpu_clk(clocks),
1950 }
1951 configure_apb_clk_impl(clocks, old_selector, new_selector);
1952 if let Some(old_selector) = old_selector {
1953 match old_selector {
1954 ApbClkConfig::Pll40m => release_pll_40m(clocks),
1955 ApbClkConfig::Cpu => release_cpu_clk(clocks),
1956 }
1957 }
1958 } else {
1959 configure_apb_clk_impl(clocks, old_selector, new_selector);
1960 }
1961 }
1962 pub fn apb_clk_config(clocks: &mut ClockTree) -> Option<ApbClkConfig> {
1963 clocks.apb_clk
1964 }
1965 pub fn request_apb_clk(clocks: &mut ClockTree) {
1966 trace!("Requesting APB_CLK");
1967 if increment_reference_count(&mut clocks.apb_clk_refcount) {
1968 trace!("Enabling APB_CLK");
1969 match unwrap!(clocks.apb_clk) {
1970 ApbClkConfig::Pll40m => request_pll_40m(clocks),
1971 ApbClkConfig::Cpu => request_cpu_clk(clocks),
1972 }
1973 enable_apb_clk_impl(clocks, true);
1974 }
1975 }
1976 pub fn release_apb_clk(clocks: &mut ClockTree) {
1977 trace!("Releasing APB_CLK");
1978 if decrement_reference_count(&mut clocks.apb_clk_refcount) {
1979 trace!("Disabling APB_CLK");
1980 enable_apb_clk_impl(clocks, false);
1981 match unwrap!(clocks.apb_clk) {
1982 ApbClkConfig::Pll40m => release_pll_40m(clocks),
1983 ApbClkConfig::Cpu => release_cpu_clk(clocks),
1984 }
1985 }
1986 }
1987 #[allow(unused_variables)]
1988 pub fn apb_clk_config_frequency(clocks: &mut ClockTree, config: ApbClkConfig) -> u32 {
1989 match config {
1990 ApbClkConfig::Pll40m => pll_40m_frequency(),
1991 ApbClkConfig::Cpu => cpu_clk_frequency(),
1992 }
1993 }
1994 pub fn apb_clk_frequency() -> u32 {
1995 APB_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
1996 }
1997 pub fn apb_clk_source_frequency(source: ApbClkConfig) -> u32 {
1998 match source {
1999 ApbClkConfig::Pll40m => pll_40m_frequency(),
2000 ApbClkConfig::Cpu => cpu_clk_frequency(),
2001 }
2002 }
2003 pub fn configure_crypto_clk(clocks: &mut ClockTree, new_selector: CryptoClkConfig) {
2004 let old_selector = clocks.crypto_clk.replace(new_selector);
2005 refresh_crypto_clk_downstream(clocks);
2006 if clocks.crypto_clk_refcount > 0 {
2007 match new_selector {
2008 CryptoClkConfig::Pll80m => request_pll_80m(clocks),
2009 CryptoClkConfig::Cpu => request_cpu_clk(clocks),
2010 }
2011 configure_crypto_clk_impl(clocks, old_selector, new_selector);
2012 if let Some(old_selector) = old_selector {
2013 match old_selector {
2014 CryptoClkConfig::Pll80m => release_pll_80m(clocks),
2015 CryptoClkConfig::Cpu => release_cpu_clk(clocks),
2016 }
2017 }
2018 } else {
2019 configure_crypto_clk_impl(clocks, old_selector, new_selector);
2020 }
2021 }
2022 pub fn crypto_clk_config(clocks: &mut ClockTree) -> Option<CryptoClkConfig> {
2023 clocks.crypto_clk
2024 }
2025 pub fn request_crypto_clk(clocks: &mut ClockTree) {
2026 trace!("Requesting CRYPTO_CLK");
2027 if increment_reference_count(&mut clocks.crypto_clk_refcount) {
2028 trace!("Enabling CRYPTO_CLK");
2029 match unwrap!(clocks.crypto_clk) {
2030 CryptoClkConfig::Pll80m => request_pll_80m(clocks),
2031 CryptoClkConfig::Cpu => request_cpu_clk(clocks),
2032 }
2033 enable_crypto_clk_impl(clocks, true);
2034 }
2035 }
2036 pub fn release_crypto_clk(clocks: &mut ClockTree) {
2037 trace!("Releasing CRYPTO_CLK");
2038 if decrement_reference_count(&mut clocks.crypto_clk_refcount) {
2039 trace!("Disabling CRYPTO_CLK");
2040 enable_crypto_clk_impl(clocks, false);
2041 match unwrap!(clocks.crypto_clk) {
2042 CryptoClkConfig::Pll80m => release_pll_80m(clocks),
2043 CryptoClkConfig::Cpu => release_cpu_clk(clocks),
2044 }
2045 }
2046 }
2047 #[allow(unused_variables)]
2048 pub fn crypto_clk_config_frequency(clocks: &mut ClockTree, config: CryptoClkConfig) -> u32 {
2049 match config {
2050 CryptoClkConfig::Pll80m => pll_80m_frequency(),
2051 CryptoClkConfig::Cpu => cpu_clk_frequency(),
2052 }
2053 }
2054 pub fn crypto_clk_frequency() -> u32 {
2055 CRYPTO_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2056 }
2057 pub fn crypto_clk_source_frequency(source: CryptoClkConfig) -> u32 {
2058 match source {
2059 CryptoClkConfig::Pll80m => pll_80m_frequency(),
2060 CryptoClkConfig::Cpu => cpu_clk_frequency(),
2061 }
2062 }
2063 pub fn configure_mspi_clk(clocks: &mut ClockTree, new_selector: MspiClkConfig) {
2064 let old_selector = clocks.mspi_clk.replace(new_selector);
2065 refresh_mspi_clk_downstream(clocks);
2066 if clocks.mspi_clk_refcount > 0 {
2067 match new_selector {
2068 MspiClkConfig::CpuDiv2 => request_cpu_div2(clocks),
2069 MspiClkConfig::Cpu => request_cpu_clk(clocks),
2070 }
2071 configure_mspi_clk_impl(clocks, old_selector, new_selector);
2072 if let Some(old_selector) = old_selector {
2073 match old_selector {
2074 MspiClkConfig::CpuDiv2 => release_cpu_div2(clocks),
2075 MspiClkConfig::Cpu => release_cpu_clk(clocks),
2076 }
2077 }
2078 } else {
2079 configure_mspi_clk_impl(clocks, old_selector, new_selector);
2080 }
2081 }
2082 pub fn mspi_clk_config(clocks: &mut ClockTree) -> Option<MspiClkConfig> {
2083 clocks.mspi_clk
2084 }
2085 pub fn request_mspi_clk(clocks: &mut ClockTree) {
2086 trace!("Requesting MSPI_CLK");
2087 if increment_reference_count(&mut clocks.mspi_clk_refcount) {
2088 trace!("Enabling MSPI_CLK");
2089 match unwrap!(clocks.mspi_clk) {
2090 MspiClkConfig::CpuDiv2 => request_cpu_div2(clocks),
2091 MspiClkConfig::Cpu => request_cpu_clk(clocks),
2092 }
2093 enable_mspi_clk_impl(clocks, true);
2094 }
2095 }
2096 pub fn release_mspi_clk(clocks: &mut ClockTree) {
2097 trace!("Releasing MSPI_CLK");
2098 if decrement_reference_count(&mut clocks.mspi_clk_refcount) {
2099 trace!("Disabling MSPI_CLK");
2100 enable_mspi_clk_impl(clocks, false);
2101 match unwrap!(clocks.mspi_clk) {
2102 MspiClkConfig::CpuDiv2 => release_cpu_div2(clocks),
2103 MspiClkConfig::Cpu => release_cpu_clk(clocks),
2104 }
2105 }
2106 }
2107 #[allow(unused_variables)]
2108 pub fn mspi_clk_config_frequency(clocks: &mut ClockTree, config: MspiClkConfig) -> u32 {
2109 match config {
2110 MspiClkConfig::CpuDiv2 => cpu_div2_frequency(),
2111 MspiClkConfig::Cpu => cpu_clk_frequency(),
2112 }
2113 }
2114 pub fn mspi_clk_frequency() -> u32 {
2115 MSPI_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2116 }
2117 pub fn mspi_clk_source_frequency(source: MspiClkConfig) -> u32 {
2118 match source {
2119 MspiClkConfig::CpuDiv2 => cpu_div2_frequency(),
2120 MspiClkConfig::Cpu => cpu_clk_frequency(),
2121 }
2122 }
2123 pub fn configure_cpu_clk(clocks: &mut ClockTree, new_selector: CpuClkConfig) {
2124 let old_selector = clocks.cpu_clk.replace(new_selector);
2125 refresh_cpu_clk_downstream(clocks);
2126 match new_selector {
2127 CpuClkConfig::Xtal => {
2128 configure_apb_clk(clocks, ApbClkConfig::Cpu);
2129 configure_crypto_clk(clocks, CryptoClkConfig::Cpu);
2130 configure_mspi_clk(clocks, MspiClkConfig::Cpu);
2131 configure_system_pre_div_in(clocks, SystemPreDivInConfig::Xtal);
2132 }
2133 CpuClkConfig::RcFast => {
2134 configure_apb_clk(clocks, ApbClkConfig::Cpu);
2135 configure_crypto_clk(clocks, CryptoClkConfig::Cpu);
2136 configure_mspi_clk(clocks, MspiClkConfig::Cpu);
2137 configure_system_pre_div_in(clocks, SystemPreDivInConfig::RcFast);
2138 }
2139 CpuClkConfig::Pll => {
2140 configure_apb_clk(clocks, ApbClkConfig::Pll40m);
2141 configure_crypto_clk(clocks, CryptoClkConfig::Pll80m);
2142 configure_mspi_clk(clocks, MspiClkConfig::CpuDiv2);
2143 }
2144 }
2145 match new_selector {
2146 CpuClkConfig::Xtal => request_system_pre_div(clocks),
2147 CpuClkConfig::RcFast => request_system_pre_div(clocks),
2148 CpuClkConfig::Pll => request_cpu_pll_div(clocks),
2149 }
2150 configure_cpu_clk_impl(clocks, old_selector, new_selector);
2151 if let Some(old_selector) = old_selector {
2152 match old_selector {
2153 CpuClkConfig::Xtal => release_system_pre_div(clocks),
2154 CpuClkConfig::RcFast => release_system_pre_div(clocks),
2155 CpuClkConfig::Pll => release_cpu_pll_div(clocks),
2156 }
2157 }
2158 }
2159 pub fn cpu_clk_config(clocks: &mut ClockTree) -> Option<CpuClkConfig> {
2160 clocks.cpu_clk
2161 }
2162 fn request_cpu_clk(_clocks: &mut ClockTree) {}
2163 fn release_cpu_clk(_clocks: &mut ClockTree) {}
2164 #[allow(unused_variables)]
2165 pub fn cpu_clk_config_frequency(clocks: &mut ClockTree, config: CpuClkConfig) -> u32 {
2166 match config {
2167 CpuClkConfig::Xtal => system_pre_div_frequency(),
2168 CpuClkConfig::RcFast => system_pre_div_frequency(),
2169 CpuClkConfig::Pll => cpu_pll_div_frequency(),
2170 }
2171 }
2172 pub fn cpu_clk_frequency() -> u32 {
2173 CPU_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2174 }
2175 pub fn request_pll_40m(clocks: &mut ClockTree) {
2176 trace!("Requesting PLL_40M");
2177 if increment_reference_count(&mut clocks.pll_40m_refcount) {
2178 trace!("Enabling PLL_40M");
2179 request_cpu_clk(clocks);
2180 enable_pll_40m_impl(clocks, true);
2181 }
2182 }
2183 pub fn release_pll_40m(clocks: &mut ClockTree) {
2184 trace!("Releasing PLL_40M");
2185 if decrement_reference_count(&mut clocks.pll_40m_refcount) {
2186 trace!("Disabling PLL_40M");
2187 enable_pll_40m_impl(clocks, false);
2188 release_cpu_clk(clocks);
2189 }
2190 }
2191 pub fn pll_40m_frequency() -> u32 {
2192 40000000
2193 }
2194 pub fn pll_40m_source_frequency() -> u32 {
2195 cpu_clk_frequency()
2196 }
2197 pub fn request_pll_60m(clocks: &mut ClockTree) {
2198 trace!("Requesting PLL_60M");
2199 if increment_reference_count(&mut clocks.pll_60m_refcount) {
2200 trace!("Enabling PLL_60M");
2201 request_cpu_clk(clocks);
2202 enable_pll_60m_impl(clocks, true);
2203 }
2204 }
2205 pub fn release_pll_60m(clocks: &mut ClockTree) {
2206 trace!("Releasing PLL_60M");
2207 if decrement_reference_count(&mut clocks.pll_60m_refcount) {
2208 trace!("Disabling PLL_60M");
2209 enable_pll_60m_impl(clocks, false);
2210 release_cpu_clk(clocks);
2211 }
2212 }
2213 pub fn pll_60m_frequency() -> u32 {
2214 60000000
2215 }
2216 pub fn pll_60m_source_frequency() -> u32 {
2217 cpu_clk_frequency()
2218 }
2219 pub fn request_pll_80m(clocks: &mut ClockTree) {
2220 trace!("Requesting PLL_80M");
2221 trace!("Enabling PLL_80M");
2222 request_cpu_clk(clocks);
2223 enable_pll_80m_impl(clocks, true);
2224 }
2225 pub fn release_pll_80m(clocks: &mut ClockTree) {
2226 trace!("Releasing PLL_80M");
2227 trace!("Disabling PLL_80M");
2228 enable_pll_80m_impl(clocks, false);
2229 release_cpu_clk(clocks);
2230 }
2231 pub fn pll_80m_frequency() -> u32 {
2232 80000000
2233 }
2234 pub fn pll_80m_source_frequency() -> u32 {
2235 cpu_clk_frequency()
2236 }
2237 pub fn request_cpu_div2(clocks: &mut ClockTree) {
2238 trace!("Requesting CPU_DIV2");
2239 trace!("Enabling CPU_DIV2");
2240 request_cpu_clk(clocks);
2241 enable_cpu_div2_impl(clocks, true);
2242 }
2243 pub fn release_cpu_div2(clocks: &mut ClockTree) {
2244 trace!("Releasing CPU_DIV2");
2245 trace!("Disabling CPU_DIV2");
2246 enable_cpu_div2_impl(clocks, false);
2247 release_cpu_clk(clocks);
2248 }
2249 pub fn cpu_div2_frequency() -> u32 {
2250 (cpu_clk_frequency() / 2)
2251 }
2252 pub fn cpu_div2_source_frequency() -> u32 {
2253 cpu_clk_frequency()
2254 }
2255 pub fn configure_rc_fast_clk_div_n(clocks: &mut ClockTree, config: RcFastClkDivNConfig) {
2256 let old_config = clocks.rc_fast_clk_div_n.replace(config);
2257 refresh_rc_fast_clk_div_n_downstream(clocks);
2258 configure_rc_fast_clk_div_n_impl(clocks, old_config, config);
2259 }
2260 pub fn rc_fast_clk_div_n_config(clocks: &mut ClockTree) -> Option<RcFastClkDivNConfig> {
2261 clocks.rc_fast_clk_div_n
2262 }
2263 pub fn request_rc_fast_clk_div_n(clocks: &mut ClockTree) {
2264 trace!("Requesting RC_FAST_CLK_DIV_N");
2265 trace!("Enabling RC_FAST_CLK_DIV_N");
2266 request_rc_fast_clk(clocks);
2267 enable_rc_fast_clk_div_n_impl(clocks, true);
2268 }
2269 pub fn release_rc_fast_clk_div_n(clocks: &mut ClockTree) {
2270 trace!("Releasing RC_FAST_CLK_DIV_N");
2271 trace!("Disabling RC_FAST_CLK_DIV_N");
2272 enable_rc_fast_clk_div_n_impl(clocks, false);
2273 release_rc_fast_clk(clocks);
2274 }
2275 #[allow(unused_variables)]
2276 pub fn rc_fast_clk_div_n_config_frequency(
2277 clocks: &mut ClockTree,
2278 config: RcFastClkDivNConfig,
2279 ) -> u32 {
2280 (rc_fast_clk_frequency() / (config.divisor() + 1))
2281 }
2282 pub fn rc_fast_clk_div_n_frequency() -> u32 {
2283 RC_FAST_CLK_DIV_N_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2284 }
2285 pub fn rc_fast_clk_div_n_source_frequency() -> u32 {
2286 rc_fast_clk_frequency()
2287 }
2288 pub fn request_xtal_div_clk(clocks: &mut ClockTree) {
2289 trace!("Requesting XTAL_DIV_CLK");
2290 trace!("Enabling XTAL_DIV_CLK");
2291 request_xtal_clk(clocks);
2292 enable_xtal_div_clk_impl(clocks, true);
2293 }
2294 pub fn release_xtal_div_clk(clocks: &mut ClockTree) {
2295 trace!("Releasing XTAL_DIV_CLK");
2296 trace!("Disabling XTAL_DIV_CLK");
2297 enable_xtal_div_clk_impl(clocks, false);
2298 release_xtal_clk(clocks);
2299 }
2300 pub fn xtal_div_clk_frequency() -> u32 {
2301 (xtal_clk_frequency() / 2)
2302 }
2303 pub fn xtal_div_clk_source_frequency() -> u32 {
2304 xtal_clk_frequency()
2305 }
2306 pub fn configure_rtc_slow_clk(clocks: &mut ClockTree, new_selector: RtcSlowClkConfig) {
2307 let old_selector = clocks.rtc_slow_clk.replace(new_selector);
2308 refresh_rtc_slow_clk_downstream(clocks);
2309 match new_selector {
2310 RtcSlowClkConfig::OscSlow => request_osc_slow_clk(clocks),
2311 RtcSlowClkConfig::RcSlow => request_rc_slow_clk(clocks),
2312 RtcSlowClkConfig::RcFast => request_rc_fast_div_clk(clocks),
2313 }
2314 configure_rtc_slow_clk_impl(clocks, old_selector, new_selector);
2315 if let Some(old_selector) = old_selector {
2316 match old_selector {
2317 RtcSlowClkConfig::OscSlow => release_osc_slow_clk(clocks),
2318 RtcSlowClkConfig::RcSlow => release_rc_slow_clk(clocks),
2319 RtcSlowClkConfig::RcFast => release_rc_fast_div_clk(clocks),
2320 }
2321 }
2322 }
2323 pub fn rtc_slow_clk_config(clocks: &mut ClockTree) -> Option<RtcSlowClkConfig> {
2324 clocks.rtc_slow_clk
2325 }
2326 pub fn request_rtc_slow_clk(clocks: &mut ClockTree) {
2327 trace!("Requesting RTC_SLOW_CLK");
2328 trace!("Enabling RTC_SLOW_CLK");
2329 match unwrap!(clocks.rtc_slow_clk) {
2330 RtcSlowClkConfig::OscSlow => request_osc_slow_clk(clocks),
2331 RtcSlowClkConfig::RcSlow => request_rc_slow_clk(clocks),
2332 RtcSlowClkConfig::RcFast => request_rc_fast_div_clk(clocks),
2333 }
2334 enable_rtc_slow_clk_impl(clocks, true);
2335 }
2336 pub fn release_rtc_slow_clk(clocks: &mut ClockTree) {
2337 trace!("Releasing RTC_SLOW_CLK");
2338 trace!("Disabling RTC_SLOW_CLK");
2339 enable_rtc_slow_clk_impl(clocks, false);
2340 match unwrap!(clocks.rtc_slow_clk) {
2341 RtcSlowClkConfig::OscSlow => release_osc_slow_clk(clocks),
2342 RtcSlowClkConfig::RcSlow => release_rc_slow_clk(clocks),
2343 RtcSlowClkConfig::RcFast => release_rc_fast_div_clk(clocks),
2344 }
2345 }
2346 #[allow(unused_variables)]
2347 pub fn rtc_slow_clk_config_frequency(
2348 clocks: &mut ClockTree,
2349 config: RtcSlowClkConfig,
2350 ) -> u32 {
2351 match config {
2352 RtcSlowClkConfig::OscSlow => osc_slow_clk_frequency(),
2353 RtcSlowClkConfig::RcSlow => rc_slow_clk_frequency(),
2354 RtcSlowClkConfig::RcFast => rc_fast_div_clk_frequency(),
2355 }
2356 }
2357 pub fn rtc_slow_clk_frequency() -> u32 {
2358 RTC_SLOW_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2359 }
2360 pub fn rtc_slow_clk_source_frequency(source: RtcSlowClkConfig) -> u32 {
2361 match source {
2362 RtcSlowClkConfig::OscSlow => osc_slow_clk_frequency(),
2363 RtcSlowClkConfig::RcSlow => rc_slow_clk_frequency(),
2364 RtcSlowClkConfig::RcFast => rc_fast_div_clk_frequency(),
2365 }
2366 }
2367 pub fn configure_rtc_fast_clk(clocks: &mut ClockTree, new_selector: RtcFastClkConfig) {
2368 let old_selector = clocks.rtc_fast_clk.replace(new_selector);
2369 refresh_rtc_fast_clk_downstream(clocks);
2370 if clocks.rtc_fast_clk_refcount > 0 {
2371 match new_selector {
2372 RtcFastClkConfig::Xtal => request_xtal_div_clk(clocks),
2373 RtcFastClkConfig::Rc => request_rc_fast_clk_div_n(clocks),
2374 }
2375 configure_rtc_fast_clk_impl(clocks, old_selector, new_selector);
2376 if let Some(old_selector) = old_selector {
2377 match old_selector {
2378 RtcFastClkConfig::Xtal => release_xtal_div_clk(clocks),
2379 RtcFastClkConfig::Rc => release_rc_fast_clk_div_n(clocks),
2380 }
2381 }
2382 } else {
2383 configure_rtc_fast_clk_impl(clocks, old_selector, new_selector);
2384 }
2385 }
2386 pub fn rtc_fast_clk_config(clocks: &mut ClockTree) -> Option<RtcFastClkConfig> {
2387 clocks.rtc_fast_clk
2388 }
2389 pub fn request_rtc_fast_clk(clocks: &mut ClockTree) {
2390 trace!("Requesting RTC_FAST_CLK");
2391 if increment_reference_count(&mut clocks.rtc_fast_clk_refcount) {
2392 trace!("Enabling RTC_FAST_CLK");
2393 match unwrap!(clocks.rtc_fast_clk) {
2394 RtcFastClkConfig::Xtal => request_xtal_div_clk(clocks),
2395 RtcFastClkConfig::Rc => request_rc_fast_clk_div_n(clocks),
2396 }
2397 enable_rtc_fast_clk_impl(clocks, true);
2398 }
2399 }
2400 pub fn release_rtc_fast_clk(clocks: &mut ClockTree) {
2401 trace!("Releasing RTC_FAST_CLK");
2402 if decrement_reference_count(&mut clocks.rtc_fast_clk_refcount) {
2403 trace!("Disabling RTC_FAST_CLK");
2404 enable_rtc_fast_clk_impl(clocks, false);
2405 match unwrap!(clocks.rtc_fast_clk) {
2406 RtcFastClkConfig::Xtal => release_xtal_div_clk(clocks),
2407 RtcFastClkConfig::Rc => release_rc_fast_clk_div_n(clocks),
2408 }
2409 }
2410 }
2411 #[allow(unused_variables)]
2412 pub fn rtc_fast_clk_config_frequency(
2413 clocks: &mut ClockTree,
2414 config: RtcFastClkConfig,
2415 ) -> u32 {
2416 match config {
2417 RtcFastClkConfig::Xtal => xtal_div_clk_frequency(),
2418 RtcFastClkConfig::Rc => rc_fast_clk_div_n_frequency(),
2419 }
2420 }
2421 pub fn rtc_fast_clk_frequency() -> u32 {
2422 RTC_FAST_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2423 }
2424 pub fn rtc_fast_clk_source_frequency(source: RtcFastClkConfig) -> u32 {
2425 match source {
2426 RtcFastClkConfig::Xtal => xtal_div_clk_frequency(),
2427 RtcFastClkConfig::Rc => rc_fast_clk_div_n_frequency(),
2428 }
2429 }
2430 pub fn configure_low_power_clk(clocks: &mut ClockTree, new_selector: LowPowerClkConfig) {
2431 let old_selector = clocks.low_power_clk.replace(new_selector);
2432 refresh_low_power_clk_downstream(clocks);
2433 if clocks.low_power_clk_refcount > 0 {
2434 match new_selector {
2435 LowPowerClkConfig::Xtal => request_xtal_clk(clocks),
2436 LowPowerClkConfig::RcFast => request_rc_fast_clk(clocks),
2437 LowPowerClkConfig::OscSlow => request_osc_slow_clk(clocks),
2438 LowPowerClkConfig::RtcSlow => request_rtc_slow_clk(clocks),
2439 }
2440 configure_low_power_clk_impl(clocks, old_selector, new_selector);
2441 if let Some(old_selector) = old_selector {
2442 match old_selector {
2443 LowPowerClkConfig::Xtal => release_xtal_clk(clocks),
2444 LowPowerClkConfig::RcFast => release_rc_fast_clk(clocks),
2445 LowPowerClkConfig::OscSlow => release_osc_slow_clk(clocks),
2446 LowPowerClkConfig::RtcSlow => release_rtc_slow_clk(clocks),
2447 }
2448 }
2449 } else {
2450 configure_low_power_clk_impl(clocks, old_selector, new_selector);
2451 }
2452 }
2453 pub fn low_power_clk_config(clocks: &mut ClockTree) -> Option<LowPowerClkConfig> {
2454 clocks.low_power_clk
2455 }
2456 pub fn request_low_power_clk(clocks: &mut ClockTree) {
2457 trace!("Requesting LOW_POWER_CLK");
2458 if increment_reference_count(&mut clocks.low_power_clk_refcount) {
2459 trace!("Enabling LOW_POWER_CLK");
2460 match unwrap!(clocks.low_power_clk) {
2461 LowPowerClkConfig::Xtal => request_xtal_clk(clocks),
2462 LowPowerClkConfig::RcFast => request_rc_fast_clk(clocks),
2463 LowPowerClkConfig::OscSlow => request_osc_slow_clk(clocks),
2464 LowPowerClkConfig::RtcSlow => request_rtc_slow_clk(clocks),
2465 }
2466 enable_low_power_clk_impl(clocks, true);
2467 }
2468 }
2469 pub fn release_low_power_clk(clocks: &mut ClockTree) {
2470 trace!("Releasing LOW_POWER_CLK");
2471 if decrement_reference_count(&mut clocks.low_power_clk_refcount) {
2472 trace!("Disabling LOW_POWER_CLK");
2473 enable_low_power_clk_impl(clocks, false);
2474 match unwrap!(clocks.low_power_clk) {
2475 LowPowerClkConfig::Xtal => release_xtal_clk(clocks),
2476 LowPowerClkConfig::RcFast => release_rc_fast_clk(clocks),
2477 LowPowerClkConfig::OscSlow => release_osc_slow_clk(clocks),
2478 LowPowerClkConfig::RtcSlow => release_rtc_slow_clk(clocks),
2479 }
2480 }
2481 }
2482 #[allow(unused_variables)]
2483 pub fn low_power_clk_config_frequency(
2484 clocks: &mut ClockTree,
2485 config: LowPowerClkConfig,
2486 ) -> u32 {
2487 match config {
2488 LowPowerClkConfig::Xtal => xtal_clk_frequency(),
2489 LowPowerClkConfig::RcFast => rc_fast_clk_frequency(),
2490 LowPowerClkConfig::OscSlow => osc_slow_clk_frequency(),
2491 LowPowerClkConfig::RtcSlow => rtc_slow_clk_frequency(),
2492 }
2493 }
2494 pub fn low_power_clk_frequency() -> u32 {
2495 LOW_POWER_CLK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2496 }
2497 pub fn low_power_clk_source_frequency(source: LowPowerClkConfig) -> u32 {
2498 match source {
2499 LowPowerClkConfig::Xtal => xtal_clk_frequency(),
2500 LowPowerClkConfig::RcFast => rc_fast_clk_frequency(),
2501 LowPowerClkConfig::OscSlow => osc_slow_clk_frequency(),
2502 LowPowerClkConfig::RtcSlow => rtc_slow_clk_frequency(),
2503 }
2504 }
2505 pub fn request_uart_mem_clk(clocks: &mut ClockTree) {
2506 trace!("Requesting UART_MEM_CLK");
2507 if increment_reference_count(&mut clocks.uart_mem_clk_refcount) {
2508 trace!("Enabling UART_MEM_CLK");
2509 request_xtal_clk(clocks);
2510 enable_uart_mem_clk_impl(clocks, true);
2511 }
2512 }
2513 pub fn release_uart_mem_clk(clocks: &mut ClockTree) {
2514 trace!("Releasing UART_MEM_CLK");
2515 if decrement_reference_count(&mut clocks.uart_mem_clk_refcount) {
2516 trace!("Disabling UART_MEM_CLK");
2517 enable_uart_mem_clk_impl(clocks, false);
2518 release_xtal_clk(clocks);
2519 }
2520 }
2521 pub fn uart_mem_clk_frequency() -> u32 {
2522 xtal_clk_frequency()
2523 }
2524 pub fn uart_mem_clk_source_frequency(source: UartMemClkConfig) -> u32 {
2525 match source {
2526 UartMemClkConfig::Xtal => xtal_clk_frequency(),
2527 }
2528 }
2529 pub fn configure_timg_calibration_clock(
2530 clocks: &mut ClockTree,
2531 new_selector: TimgCalibrationClockConfig,
2532 ) {
2533 let old_selector = clocks.timg_calibration_clock.replace(new_selector);
2534 refresh_timg_calibration_clock_downstream(clocks);
2535 if clocks.timg_calibration_clock_refcount > 0 {
2536 match new_selector {
2537 TimgCalibrationClockConfig::RcSlowClk => request_rc_slow_clk(clocks),
2538 TimgCalibrationClockConfig::RcFastDivClk => request_rc_fast_div_clk(clocks),
2539 TimgCalibrationClockConfig::Osc32kClk => request_osc_slow_clk(clocks),
2540 }
2541 configure_timg_calibration_clock_impl(clocks, old_selector, new_selector);
2542 if let Some(old_selector) = old_selector {
2543 match old_selector {
2544 TimgCalibrationClockConfig::RcSlowClk => release_rc_slow_clk(clocks),
2545 TimgCalibrationClockConfig::RcFastDivClk => release_rc_fast_div_clk(clocks),
2546 TimgCalibrationClockConfig::Osc32kClk => release_osc_slow_clk(clocks),
2547 }
2548 }
2549 } else {
2550 configure_timg_calibration_clock_impl(clocks, old_selector, new_selector);
2551 }
2552 }
2553 pub fn timg_calibration_clock_config(
2554 clocks: &mut ClockTree,
2555 ) -> Option<TimgCalibrationClockConfig> {
2556 clocks.timg_calibration_clock
2557 }
2558 pub fn request_timg_calibration_clock(clocks: &mut ClockTree) {
2559 trace!("Requesting TIMG_CALIBRATION_CLOCK");
2560 if increment_reference_count(&mut clocks.timg_calibration_clock_refcount) {
2561 trace!("Enabling TIMG_CALIBRATION_CLOCK");
2562 crate::rtc_cntl::WakeLock::acquire();
2563 match unwrap!(clocks.timg_calibration_clock) {
2564 TimgCalibrationClockConfig::RcSlowClk => request_rc_slow_clk(clocks),
2565 TimgCalibrationClockConfig::RcFastDivClk => request_rc_fast_div_clk(clocks),
2566 TimgCalibrationClockConfig::Osc32kClk => request_osc_slow_clk(clocks),
2567 }
2568 enable_timg_calibration_clock_impl(clocks, true);
2569 }
2570 }
2571 pub fn release_timg_calibration_clock(clocks: &mut ClockTree) {
2572 trace!("Releasing TIMG_CALIBRATION_CLOCK");
2573 if decrement_reference_count(&mut clocks.timg_calibration_clock_refcount) {
2574 trace!("Disabling TIMG_CALIBRATION_CLOCK");
2575 crate::rtc_cntl::WakeLock::release();
2576 enable_timg_calibration_clock_impl(clocks, false);
2577 match unwrap!(clocks.timg_calibration_clock) {
2578 TimgCalibrationClockConfig::RcSlowClk => release_rc_slow_clk(clocks),
2579 TimgCalibrationClockConfig::RcFastDivClk => release_rc_fast_div_clk(clocks),
2580 TimgCalibrationClockConfig::Osc32kClk => release_osc_slow_clk(clocks),
2581 }
2582 }
2583 }
2584 #[allow(unused_variables)]
2585 pub fn timg_calibration_clock_config_frequency(
2586 clocks: &mut ClockTree,
2587 config: TimgCalibrationClockConfig,
2588 ) -> u32 {
2589 match config {
2590 TimgCalibrationClockConfig::RcSlowClk => rc_slow_clk_frequency(),
2591 TimgCalibrationClockConfig::RcFastDivClk => rc_fast_div_clk_frequency(),
2592 TimgCalibrationClockConfig::Osc32kClk => osc_slow_clk_frequency(),
2593 }
2594 }
2595 pub fn timg_calibration_clock_frequency() -> u32 {
2596 TIMG_CALIBRATION_CLOCK_FREQ_CACHE.load(::core::sync::atomic::Ordering::Acquire)
2597 }
2598 pub fn timg_calibration_clock_source_frequency(source: TimgCalibrationClockConfig) -> u32 {
2599 match source {
2600 TimgCalibrationClockConfig::RcSlowClk => rc_slow_clk_frequency(),
2601 TimgCalibrationClockConfig::RcFastDivClk => rc_fast_div_clk_frequency(),
2602 TimgCalibrationClockConfig::Osc32kClk => osc_slow_clk_frequency(),
2603 }
2604 }
2605 impl I2cInstance {
2606 pub fn configure_function_clock(
2607 self,
2608 clocks: &mut ClockTree,
2609 config: I2cFunctionClockConfig,
2610 ) {
2611 let old_config = clocks.i2c_function_clock[self as usize].replace(config);
2612 refresh_i2c_function_clock_downstream(clocks, self);
2613 if clocks.i2c_function_clock_refcount[self as usize] > 0 {
2614 match config.sclk {
2615 I2cFunctionClockSclk::Xtal => request_xtal_clk(clocks),
2616 I2cFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
2617 }
2618 self.configure_function_clock_impl(clocks, old_config, config);
2619 if let Some(old_config) = old_config {
2620 match old_config.sclk {
2621 I2cFunctionClockSclk::Xtal => release_xtal_clk(clocks),
2622 I2cFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
2623 }
2624 }
2625 } else {
2626 self.configure_function_clock_impl(clocks, old_config, config);
2627 }
2628 }
2629 pub fn function_clock_config(
2630 self,
2631 clocks: &mut ClockTree,
2632 ) -> Option<I2cFunctionClockConfig> {
2633 clocks.i2c_function_clock[self as usize]
2634 }
2635 pub fn request_function_clock(self, clocks: &mut ClockTree) {
2636 trace!("Requesting {:?}::FUNCTION_CLOCK", self);
2637 if increment_reference_count(&mut clocks.i2c_function_clock_refcount[self as usize])
2638 {
2639 trace!("Enabling {:?}::FUNCTION_CLOCK", self);
2640 crate::rtc_cntl::WakeLock::acquire();
2641 match unwrap!(clocks.i2c_function_clock[self as usize]).sclk {
2642 I2cFunctionClockSclk::Xtal => request_xtal_clk(clocks),
2643 I2cFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
2644 }
2645 self.enable_function_clock_impl(clocks, true);
2646 }
2647 }
2648 pub fn release_function_clock(self, clocks: &mut ClockTree) {
2649 trace!("Releasing {:?}::FUNCTION_CLOCK", self);
2650 if decrement_reference_count(&mut clocks.i2c_function_clock_refcount[self as usize])
2651 {
2652 trace!("Disabling {:?}::FUNCTION_CLOCK", self);
2653 crate::rtc_cntl::WakeLock::release();
2654 self.enable_function_clock_impl(clocks, false);
2655 match unwrap!(clocks.i2c_function_clock[self as usize]).sclk {
2656 I2cFunctionClockSclk::Xtal => release_xtal_clk(clocks),
2657 I2cFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
2658 }
2659 }
2660 }
2661 #[allow(unused_variables)]
2662 pub fn function_clock_config_frequency(
2663 clocks: &mut ClockTree,
2664 config: I2cFunctionClockConfig,
2665 ) -> u32 {
2666 (match config.sclk {
2667 I2cFunctionClockSclk::Xtal => xtal_clk_frequency(),
2668 I2cFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
2669 } / (config.div_num() + 1))
2670 }
2671 pub fn function_clock_frequency(self) -> u32 {
2672 I2C_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
2673 .load(::core::sync::atomic::Ordering::Acquire)
2674 }
2675 pub fn function_clock_source_frequency(sclk: I2cFunctionClockSclk) -> u32 {
2676 match sclk {
2677 I2cFunctionClockSclk::Xtal => xtal_clk_frequency(),
2678 I2cFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
2679 }
2680 }
2681 }
2682 impl SpiInstance {
2683 pub fn configure_function_clock(
2684 self,
2685 clocks: &mut ClockTree,
2686 new_selector: SpiFunctionClockConfig,
2687 ) {
2688 let old_selector = clocks.spi_function_clock[self as usize].replace(new_selector);
2689 refresh_spi_function_clock_downstream(clocks, self);
2690 if clocks.spi_function_clock_refcount[self as usize] > 0 {
2691 match new_selector {
2692 SpiFunctionClockConfig::Xtal => request_xtal_clk(clocks),
2693 SpiFunctionClockConfig::Pll40m => request_pll_40m(clocks),
2694 }
2695 self.configure_function_clock_impl(clocks, old_selector, new_selector);
2696 if let Some(old_selector) = old_selector {
2697 match old_selector {
2698 SpiFunctionClockConfig::Xtal => release_xtal_clk(clocks),
2699 SpiFunctionClockConfig::Pll40m => release_pll_40m(clocks),
2700 }
2701 }
2702 } else {
2703 self.configure_function_clock_impl(clocks, old_selector, new_selector);
2704 }
2705 }
2706 pub fn function_clock_config(
2707 self,
2708 clocks: &mut ClockTree,
2709 ) -> Option<SpiFunctionClockConfig> {
2710 clocks.spi_function_clock[self as usize]
2711 }
2712 pub fn request_function_clock(self, clocks: &mut ClockTree) {
2713 trace!("Requesting {:?}::FUNCTION_CLOCK", self);
2714 if increment_reference_count(&mut clocks.spi_function_clock_refcount[self as usize])
2715 {
2716 trace!("Enabling {:?}::FUNCTION_CLOCK", self);
2717 crate::rtc_cntl::WakeLock::acquire();
2718 match unwrap!(clocks.spi_function_clock[self as usize]) {
2719 SpiFunctionClockConfig::Xtal => request_xtal_clk(clocks),
2720 SpiFunctionClockConfig::Pll40m => request_pll_40m(clocks),
2721 }
2722 self.enable_function_clock_impl(clocks, true);
2723 }
2724 }
2725 pub fn release_function_clock(self, clocks: &mut ClockTree) {
2726 trace!("Releasing {:?}::FUNCTION_CLOCK", self);
2727 if decrement_reference_count(&mut clocks.spi_function_clock_refcount[self as usize])
2728 {
2729 trace!("Disabling {:?}::FUNCTION_CLOCK", self);
2730 crate::rtc_cntl::WakeLock::release();
2731 self.enable_function_clock_impl(clocks, false);
2732 match unwrap!(clocks.spi_function_clock[self as usize]) {
2733 SpiFunctionClockConfig::Xtal => release_xtal_clk(clocks),
2734 SpiFunctionClockConfig::Pll40m => release_pll_40m(clocks),
2735 }
2736 }
2737 }
2738 #[allow(unused_variables)]
2739 pub fn function_clock_config_frequency(
2740 clocks: &mut ClockTree,
2741 config: SpiFunctionClockConfig,
2742 ) -> u32 {
2743 match config {
2744 SpiFunctionClockConfig::Xtal => xtal_clk_frequency(),
2745 SpiFunctionClockConfig::Pll40m => pll_40m_frequency(),
2746 }
2747 }
2748 pub fn function_clock_frequency(self) -> u32 {
2749 SPI_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
2750 .load(::core::sync::atomic::Ordering::Acquire)
2751 }
2752 pub fn function_clock_source_frequency(source: SpiFunctionClockConfig) -> u32 {
2753 match source {
2754 SpiFunctionClockConfig::Xtal => xtal_clk_frequency(),
2755 SpiFunctionClockConfig::Pll40m => pll_40m_frequency(),
2756 }
2757 }
2758 }
2759 impl TimgInstance {
2760 pub fn configure_function_clock(
2761 self,
2762 clocks: &mut ClockTree,
2763 new_selector: TimgFunctionClockConfig,
2764 ) {
2765 let old_selector = clocks.timg_function_clock[self as usize].replace(new_selector);
2766 refresh_timg_function_clock_downstream(clocks, self);
2767 if clocks.timg_function_clock_refcount[self as usize] > 0 {
2768 match new_selector {
2769 TimgFunctionClockConfig::XtalClk => request_xtal_clk(clocks),
2770 TimgFunctionClockConfig::Pll40m => request_pll_40m(clocks),
2771 }
2772 self.configure_function_clock_impl(clocks, old_selector, new_selector);
2773 if let Some(old_selector) = old_selector {
2774 match old_selector {
2775 TimgFunctionClockConfig::XtalClk => release_xtal_clk(clocks),
2776 TimgFunctionClockConfig::Pll40m => release_pll_40m(clocks),
2777 }
2778 }
2779 } else {
2780 self.configure_function_clock_impl(clocks, old_selector, new_selector);
2781 }
2782 }
2783 pub fn function_clock_config(
2784 self,
2785 clocks: &mut ClockTree,
2786 ) -> Option<TimgFunctionClockConfig> {
2787 clocks.timg_function_clock[self as usize]
2788 }
2789 pub fn request_function_clock(self, clocks: &mut ClockTree) {
2790 trace!("Requesting {:?}::FUNCTION_CLOCK", self);
2791 if increment_reference_count(
2792 &mut clocks.timg_function_clock_refcount[self as usize],
2793 ) {
2794 trace!("Enabling {:?}::FUNCTION_CLOCK", self);
2795 match unwrap!(clocks.timg_function_clock[self as usize]) {
2796 TimgFunctionClockConfig::XtalClk => request_xtal_clk(clocks),
2797 TimgFunctionClockConfig::Pll40m => request_pll_40m(clocks),
2798 }
2799 self.enable_function_clock_impl(clocks, true);
2800 }
2801 }
2802 pub fn release_function_clock(self, clocks: &mut ClockTree) {
2803 trace!("Releasing {:?}::FUNCTION_CLOCK", self);
2804 if decrement_reference_count(
2805 &mut clocks.timg_function_clock_refcount[self as usize],
2806 ) {
2807 trace!("Disabling {:?}::FUNCTION_CLOCK", self);
2808 self.enable_function_clock_impl(clocks, false);
2809 match unwrap!(clocks.timg_function_clock[self as usize]) {
2810 TimgFunctionClockConfig::XtalClk => release_xtal_clk(clocks),
2811 TimgFunctionClockConfig::Pll40m => release_pll_40m(clocks),
2812 }
2813 }
2814 }
2815 #[allow(unused_variables)]
2816 pub fn function_clock_config_frequency(
2817 clocks: &mut ClockTree,
2818 config: TimgFunctionClockConfig,
2819 ) -> u32 {
2820 match config {
2821 TimgFunctionClockConfig::XtalClk => xtal_clk_frequency(),
2822 TimgFunctionClockConfig::Pll40m => pll_40m_frequency(),
2823 }
2824 }
2825 pub fn function_clock_frequency(self) -> u32 {
2826 TIMG_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
2827 .load(::core::sync::atomic::Ordering::Acquire)
2828 }
2829 pub fn function_clock_source_frequency(source: TimgFunctionClockConfig) -> u32 {
2830 match source {
2831 TimgFunctionClockConfig::XtalClk => xtal_clk_frequency(),
2832 TimgFunctionClockConfig::Pll40m => pll_40m_frequency(),
2833 }
2834 }
2835 pub fn configure_wdt_clock(
2836 self,
2837 clocks: &mut ClockTree,
2838 new_selector: TimgWdtClockConfig,
2839 ) {
2840 let old_selector = clocks.timg_wdt_clock[self as usize].replace(new_selector);
2841 refresh_timg_wdt_clock_downstream(clocks, self);
2842 if clocks.timg_wdt_clock_refcount[self as usize] > 0 {
2843 match new_selector {
2844 TimgWdtClockConfig::Pll40m => request_pll_40m(clocks),
2845 TimgWdtClockConfig::XtalClk => request_xtal_clk(clocks),
2846 }
2847 self.configure_wdt_clock_impl(clocks, old_selector, new_selector);
2848 if let Some(old_selector) = old_selector {
2849 match old_selector {
2850 TimgWdtClockConfig::Pll40m => release_pll_40m(clocks),
2851 TimgWdtClockConfig::XtalClk => release_xtal_clk(clocks),
2852 }
2853 }
2854 } else {
2855 self.configure_wdt_clock_impl(clocks, old_selector, new_selector);
2856 }
2857 }
2858 pub fn wdt_clock_config(self, clocks: &mut ClockTree) -> Option<TimgWdtClockConfig> {
2859 clocks.timg_wdt_clock[self as usize]
2860 }
2861 pub fn request_wdt_clock(self, clocks: &mut ClockTree) {
2862 trace!("Requesting {:?}::WDT_CLOCK", self);
2863 if increment_reference_count(&mut clocks.timg_wdt_clock_refcount[self as usize]) {
2864 trace!("Enabling {:?}::WDT_CLOCK", self);
2865 match unwrap!(clocks.timg_wdt_clock[self as usize]) {
2866 TimgWdtClockConfig::Pll40m => request_pll_40m(clocks),
2867 TimgWdtClockConfig::XtalClk => request_xtal_clk(clocks),
2868 }
2869 self.enable_wdt_clock_impl(clocks, true);
2870 }
2871 }
2872 pub fn release_wdt_clock(self, clocks: &mut ClockTree) {
2873 trace!("Releasing {:?}::WDT_CLOCK", self);
2874 if decrement_reference_count(&mut clocks.timg_wdt_clock_refcount[self as usize]) {
2875 trace!("Disabling {:?}::WDT_CLOCK", self);
2876 self.enable_wdt_clock_impl(clocks, false);
2877 match unwrap!(clocks.timg_wdt_clock[self as usize]) {
2878 TimgWdtClockConfig::Pll40m => release_pll_40m(clocks),
2879 TimgWdtClockConfig::XtalClk => release_xtal_clk(clocks),
2880 }
2881 }
2882 }
2883 #[allow(unused_variables)]
2884 pub fn wdt_clock_config_frequency(
2885 clocks: &mut ClockTree,
2886 config: TimgWdtClockConfig,
2887 ) -> u32 {
2888 match config {
2889 TimgWdtClockConfig::Pll40m => pll_40m_frequency(),
2890 TimgWdtClockConfig::XtalClk => xtal_clk_frequency(),
2891 }
2892 }
2893 pub fn wdt_clock_frequency(self) -> u32 {
2894 TIMG_WDT_CLOCK_FREQ_CACHE[self as usize]
2895 .load(::core::sync::atomic::Ordering::Acquire)
2896 }
2897 pub fn wdt_clock_source_frequency(source: TimgWdtClockConfig) -> u32 {
2898 match source {
2899 TimgWdtClockConfig::Pll40m => pll_40m_frequency(),
2900 TimgWdtClockConfig::XtalClk => xtal_clk_frequency(),
2901 }
2902 }
2903 }
2904 impl UartInstance {
2905 pub fn configure_function_clock(
2906 self,
2907 clocks: &mut ClockTree,
2908 config: UartFunctionClockConfig,
2909 ) {
2910 let old_config = clocks.uart_function_clock[self as usize].replace(config);
2911 refresh_uart_function_clock_downstream(clocks, self);
2912 if clocks.uart_function_clock_refcount[self as usize] > 0 {
2913 match config.sclk {
2914 UartFunctionClockSclk::PllF40m => request_pll_40m(clocks),
2915 UartFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
2916 UartFunctionClockSclk::Xtal => request_xtal_clk(clocks),
2917 }
2918 self.configure_function_clock_impl(clocks, old_config, config);
2919 if let Some(old_config) = old_config {
2920 match old_config.sclk {
2921 UartFunctionClockSclk::PllF40m => release_pll_40m(clocks),
2922 UartFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
2923 UartFunctionClockSclk::Xtal => release_xtal_clk(clocks),
2924 }
2925 }
2926 } else {
2927 self.configure_function_clock_impl(clocks, old_config, config);
2928 }
2929 }
2930 pub fn function_clock_config(
2931 self,
2932 clocks: &mut ClockTree,
2933 ) -> Option<UartFunctionClockConfig> {
2934 clocks.uart_function_clock[self as usize]
2935 }
2936 pub fn request_function_clock(self, clocks: &mut ClockTree) {
2937 trace!("Requesting {:?}::FUNCTION_CLOCK", self);
2938 if increment_reference_count(
2939 &mut clocks.uart_function_clock_refcount[self as usize],
2940 ) {
2941 trace!("Enabling {:?}::FUNCTION_CLOCK", self);
2942 match unwrap!(clocks.uart_function_clock[self as usize]).sclk {
2943 UartFunctionClockSclk::PllF40m => request_pll_40m(clocks),
2944 UartFunctionClockSclk::RcFast => request_rc_fast_clk(clocks),
2945 UartFunctionClockSclk::Xtal => request_xtal_clk(clocks),
2946 }
2947 self.enable_function_clock_impl(clocks, true);
2948 }
2949 }
2950 pub fn release_function_clock(self, clocks: &mut ClockTree) {
2951 trace!("Releasing {:?}::FUNCTION_CLOCK", self);
2952 if decrement_reference_count(
2953 &mut clocks.uart_function_clock_refcount[self as usize],
2954 ) {
2955 trace!("Disabling {:?}::FUNCTION_CLOCK", self);
2956 self.enable_function_clock_impl(clocks, false);
2957 match unwrap!(clocks.uart_function_clock[self as usize]).sclk {
2958 UartFunctionClockSclk::PllF40m => release_pll_40m(clocks),
2959 UartFunctionClockSclk::RcFast => release_rc_fast_clk(clocks),
2960 UartFunctionClockSclk::Xtal => release_xtal_clk(clocks),
2961 }
2962 }
2963 }
2964 #[allow(unused_variables)]
2965 pub fn function_clock_config_frequency(
2966 clocks: &mut ClockTree,
2967 config: UartFunctionClockConfig,
2968 ) -> u32 {
2969 (match config.sclk {
2970 UartFunctionClockSclk::PllF40m => pll_40m_frequency(),
2971 UartFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
2972 UartFunctionClockSclk::Xtal => xtal_clk_frequency(),
2973 } / (config.div_num() + 1))
2974 }
2975 pub fn function_clock_frequency(self) -> u32 {
2976 UART_FUNCTION_CLOCK_FREQ_CACHE[self as usize]
2977 .load(::core::sync::atomic::Ordering::Acquire)
2978 }
2979 pub fn function_clock_source_frequency(sclk: UartFunctionClockSclk) -> u32 {
2980 match sclk {
2981 UartFunctionClockSclk::PllF40m => pll_40m_frequency(),
2982 UartFunctionClockSclk::RcFast => rc_fast_clk_frequency(),
2983 UartFunctionClockSclk::Xtal => xtal_clk_frequency(),
2984 }
2985 }
2986 pub fn request_mem_clock(self, clocks: &mut ClockTree) {
2987 trace!("Requesting {:?}::MEM_CLOCK", self);
2988 if increment_reference_count(&mut clocks.uart_mem_clock_refcount[self as usize]) {
2989 trace!("Enabling {:?}::MEM_CLOCK", self);
2990 request_uart_mem_clk(clocks);
2991 self.enable_mem_clock_impl(clocks, true);
2992 }
2993 }
2994 pub fn release_mem_clock(self, clocks: &mut ClockTree) {
2995 trace!("Releasing {:?}::MEM_CLOCK", self);
2996 if decrement_reference_count(&mut clocks.uart_mem_clock_refcount[self as usize]) {
2997 trace!("Disabling {:?}::MEM_CLOCK", self);
2998 self.enable_mem_clock_impl(clocks, false);
2999 release_uart_mem_clk(clocks);
3000 }
3001 }
3002 pub fn mem_clock_frequency(self) -> u32 {
3003 uart_mem_clk_frequency()
3004 }
3005 pub fn mem_clock_source_frequency() -> u32 {
3006 uart_mem_clk_frequency()
3007 }
3008 pub fn configure_baud_rate_generator(
3009 self,
3010 clocks: &mut ClockTree,
3011 config: UartBaudRateGeneratorConfig,
3012 ) {
3013 let old_config = clocks.uart_baud_rate_generator[self as usize].replace(config);
3014 refresh_uart_baud_rate_generator_downstream(clocks, self);
3015 self.configure_baud_rate_generator_impl(clocks, old_config, config);
3016 }
3017 pub fn baud_rate_generator_config(
3018 self,
3019 clocks: &mut ClockTree,
3020 ) -> Option<UartBaudRateGeneratorConfig> {
3021 clocks.uart_baud_rate_generator[self as usize]
3022 }
3023 pub fn request_baud_rate_generator(self, clocks: &mut ClockTree) {
3024 trace!("Requesting {:?}::BAUD_RATE_GENERATOR", self);
3025 if increment_reference_count(
3026 &mut clocks.uart_baud_rate_generator_refcount[self as usize],
3027 ) {
3028 trace!("Enabling {:?}::BAUD_RATE_GENERATOR", self);
3029 self.request_function_clock(clocks);
3030 self.enable_baud_rate_generator_impl(clocks, true);
3031 }
3032 }
3033 pub fn release_baud_rate_generator(self, clocks: &mut ClockTree) {
3034 trace!("Releasing {:?}::BAUD_RATE_GENERATOR", self);
3035 if decrement_reference_count(
3036 &mut clocks.uart_baud_rate_generator_refcount[self as usize],
3037 ) {
3038 trace!("Disabling {:?}::BAUD_RATE_GENERATOR", self);
3039 self.enable_baud_rate_generator_impl(clocks, false);
3040 self.release_function_clock(clocks);
3041 }
3042 }
3043 #[allow(unused_variables)]
3044 pub fn baud_rate_generator_config_frequency(
3045 self,
3046 clocks: &mut ClockTree,
3047 config: UartBaudRateGeneratorConfig,
3048 ) -> u32 {
3049 ((self.function_clock_frequency() * 16)
3050 / ((config.integral() * 16) + config.fractional()))
3051 }
3052 pub fn baud_rate_generator_frequency(self) -> u32 {
3053 UART_BAUD_RATE_GENERATOR_FREQ_CACHE[self as usize]
3054 .load(::core::sync::atomic::Ordering::Acquire)
3055 }
3056 }
3057 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
3065 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
3066 #[instability::unstable]
3067 pub struct ClockConfig {
3068 pub xtal_clk: Option<XtalClkConfig>,
3070 pub system_pre_div: Option<SystemPreDivConfig>,
3072 pub cpu_pll_div: Option<CpuPllDivConfig>,
3074 pub cpu_clk: Option<CpuClkConfig>,
3076 pub rc_fast_clk_div_n: Option<RcFastClkDivNConfig>,
3078 pub rtc_slow_clk: Option<RtcSlowClkConfig>,
3080 pub rtc_fast_clk: Option<RtcFastClkConfig>,
3082 pub low_power_clk: Option<LowPowerClkConfig>,
3084 pub timg_calibration_clock: Option<TimgCalibrationClockConfig>,
3086 }
3087 impl ClockConfig {
3088 fn apply(&self, clocks: &mut ClockTree) {
3089 if let Some(config) = self.xtal_clk {
3090 configure_xtal_clk(clocks, config);
3091 }
3092 if let Some(config) = self.system_pre_div {
3093 configure_system_pre_div(clocks, config);
3094 }
3095 if let Some(config) = self.cpu_pll_div {
3096 configure_cpu_pll_div(clocks, config);
3097 }
3098 if let Some(config) = self.cpu_clk {
3099 configure_cpu_clk(clocks, config);
3100 }
3101 if let Some(config) = self.rc_fast_clk_div_n {
3102 configure_rc_fast_clk_div_n(clocks, config);
3103 }
3104 if let Some(config) = self.rtc_slow_clk {
3105 configure_rtc_slow_clk(clocks, config);
3106 }
3107 if let Some(config) = self.rtc_fast_clk {
3108 configure_rtc_fast_clk(clocks, config);
3109 }
3110 if let Some(config) = self.low_power_clk {
3111 configure_low_power_clk(clocks, config);
3112 }
3113 if let Some(config) = self.timg_calibration_clock {
3114 configure_timg_calibration_clock(clocks, config);
3115 }
3116 }
3117 }
3118 fn increment_reference_count(refcount: &mut u32) -> bool {
3119 let first = *refcount == 0;
3120 *refcount = unwrap!(refcount.checked_add(1), "Reference count overflow");
3121 first
3122 }
3123 fn decrement_reference_count(refcount: &mut u32) -> bool {
3124 *refcount = refcount.saturating_sub(1);
3125 let last = *refcount == 0;
3126 last
3127 }
3128 fn refresh_xtal_clk_downstream(clocks: &mut ClockTree) {
3129 if let Some(config) = clocks.xtal_clk {
3130 XTAL_CLK_FREQ_CACHE.store(
3131 xtal_clk_config_frequency(clocks, config),
3132 ::core::sync::atomic::Ordering::Release,
3133 );
3134 }
3135 refresh_system_pre_div_in_downstream(clocks);
3136 refresh_cpu_pll_div_downstream(clocks);
3137 refresh_rtc_fast_clk_downstream(clocks);
3138 refresh_low_power_clk_downstream(clocks);
3139 for child_instance in [I2cInstance::I2c0] {
3140 refresh_i2c_function_clock_downstream(clocks, child_instance);
3141 }
3142 for child_instance in [SpiInstance::Spi2] {
3143 refresh_spi_function_clock_downstream(clocks, child_instance);
3144 }
3145 for child_instance in [TimgInstance::Timg0] {
3146 refresh_timg_function_clock_downstream(clocks, child_instance);
3147 refresh_timg_wdt_clock_downstream(clocks, child_instance);
3148 }
3149 for child_instance in [UartInstance::Uart0, UartInstance::Uart1] {
3150 refresh_uart_function_clock_downstream(clocks, child_instance);
3151 }
3152 }
3153 fn refresh_system_pre_div_in_downstream(clocks: &mut ClockTree) {
3154 if let Some(config) = clocks.system_pre_div_in {
3155 SYSTEM_PRE_DIV_IN_FREQ_CACHE.store(
3156 system_pre_div_in_config_frequency(clocks, config),
3157 ::core::sync::atomic::Ordering::Release,
3158 );
3159 }
3160 refresh_system_pre_div_downstream(clocks);
3161 }
3162 fn refresh_system_pre_div_downstream(clocks: &mut ClockTree) {
3163 if let Some(config) = clocks.system_pre_div {
3164 SYSTEM_PRE_DIV_FREQ_CACHE.store(
3165 system_pre_div_config_frequency(clocks, config),
3166 ::core::sync::atomic::Ordering::Release,
3167 );
3168 }
3169 refresh_cpu_clk_downstream(clocks);
3170 }
3171 fn refresh_cpu_pll_div_downstream(clocks: &mut ClockTree) {
3172 if let Some(config) = clocks.cpu_pll_div {
3173 CPU_PLL_DIV_FREQ_CACHE.store(
3174 cpu_pll_div_config_frequency(clocks, config),
3175 ::core::sync::atomic::Ordering::Release,
3176 );
3177 }
3178 refresh_cpu_clk_downstream(clocks);
3179 }
3180 fn refresh_cpu_clk_downstream(clocks: &mut ClockTree) {
3181 if let Some(config) = clocks.cpu_clk {
3182 CPU_CLK_FREQ_CACHE.store(
3183 cpu_clk_config_frequency(clocks, config),
3184 ::core::sync::atomic::Ordering::Release,
3185 );
3186 }
3187 refresh_apb_clk_downstream(clocks);
3188 refresh_crypto_clk_downstream(clocks);
3189 refresh_mspi_clk_downstream(clocks);
3190 for child_instance in [SpiInstance::Spi2] {
3191 refresh_spi_function_clock_downstream(clocks, child_instance);
3192 }
3193 for child_instance in [TimgInstance::Timg0] {
3194 refresh_timg_function_clock_downstream(clocks, child_instance);
3195 refresh_timg_wdt_clock_downstream(clocks, child_instance);
3196 }
3197 for child_instance in [UartInstance::Uart0, UartInstance::Uart1] {
3198 refresh_uart_function_clock_downstream(clocks, child_instance);
3199 }
3200 }
3201 fn refresh_rc_fast_clk_div_n_downstream(clocks: &mut ClockTree) {
3202 if let Some(config) = clocks.rc_fast_clk_div_n {
3203 RC_FAST_CLK_DIV_N_FREQ_CACHE.store(
3204 rc_fast_clk_div_n_config_frequency(clocks, config),
3205 ::core::sync::atomic::Ordering::Release,
3206 );
3207 }
3208 refresh_rtc_fast_clk_downstream(clocks);
3209 }
3210 fn refresh_rtc_slow_clk_downstream(clocks: &mut ClockTree) {
3211 if let Some(config) = clocks.rtc_slow_clk {
3212 RTC_SLOW_CLK_FREQ_CACHE.store(
3213 rtc_slow_clk_config_frequency(clocks, config),
3214 ::core::sync::atomic::Ordering::Release,
3215 );
3216 }
3217 refresh_low_power_clk_downstream(clocks);
3218 }
3219 fn refresh_rtc_fast_clk_downstream(clocks: &mut ClockTree) {
3220 if let Some(config) = clocks.rtc_fast_clk {
3221 RTC_FAST_CLK_FREQ_CACHE.store(
3222 rtc_fast_clk_config_frequency(clocks, config),
3223 ::core::sync::atomic::Ordering::Release,
3224 );
3225 }
3226 }
3227 fn refresh_low_power_clk_downstream(clocks: &mut ClockTree) {
3228 if let Some(config) = clocks.low_power_clk {
3229 LOW_POWER_CLK_FREQ_CACHE.store(
3230 low_power_clk_config_frequency(clocks, config),
3231 ::core::sync::atomic::Ordering::Release,
3232 );
3233 }
3234 }
3235 fn refresh_timg_calibration_clock_downstream(clocks: &mut ClockTree) {
3236 if let Some(config) = clocks.timg_calibration_clock {
3237 TIMG_CALIBRATION_CLOCK_FREQ_CACHE.store(
3238 timg_calibration_clock_config_frequency(clocks, config),
3239 ::core::sync::atomic::Ordering::Release,
3240 );
3241 }
3242 }
3243 fn refresh_i2c_function_clock_downstream(clocks: &mut ClockTree, instance: I2cInstance) {
3244 if let Some(config) = clocks.i2c_function_clock[instance as usize] {
3245 I2C_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
3246 I2cInstance::function_clock_config_frequency(clocks, config),
3247 ::core::sync::atomic::Ordering::Release,
3248 );
3249 }
3250 }
3251 fn refresh_spi_function_clock_downstream(clocks: &mut ClockTree, instance: SpiInstance) {
3252 if let Some(config) = clocks.spi_function_clock[instance as usize] {
3253 SPI_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
3254 SpiInstance::function_clock_config_frequency(clocks, config),
3255 ::core::sync::atomic::Ordering::Release,
3256 );
3257 }
3258 }
3259 fn refresh_timg_function_clock_downstream(clocks: &mut ClockTree, instance: TimgInstance) {
3260 if let Some(config) = clocks.timg_function_clock[instance as usize] {
3261 TIMG_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
3262 TimgInstance::function_clock_config_frequency(clocks, config),
3263 ::core::sync::atomic::Ordering::Release,
3264 );
3265 }
3266 }
3267 fn refresh_timg_wdt_clock_downstream(clocks: &mut ClockTree, instance: TimgInstance) {
3268 if let Some(config) = clocks.timg_wdt_clock[instance as usize] {
3269 TIMG_WDT_CLOCK_FREQ_CACHE[instance as usize].store(
3270 TimgInstance::wdt_clock_config_frequency(clocks, config),
3271 ::core::sync::atomic::Ordering::Release,
3272 );
3273 }
3274 }
3275 fn refresh_uart_function_clock_downstream(clocks: &mut ClockTree, instance: UartInstance) {
3276 if let Some(config) = clocks.uart_function_clock[instance as usize] {
3277 UART_FUNCTION_CLOCK_FREQ_CACHE[instance as usize].store(
3278 UartInstance::function_clock_config_frequency(clocks, config),
3279 ::core::sync::atomic::Ordering::Release,
3280 );
3281 }
3282 refresh_uart_baud_rate_generator_downstream(clocks, instance);
3283 }
3284 fn refresh_uart_baud_rate_generator_downstream(
3285 clocks: &mut ClockTree,
3286 instance: UartInstance,
3287 ) {
3288 if let Some(config) = clocks.uart_baud_rate_generator[instance as usize] {
3289 UART_BAUD_RATE_GENERATOR_FREQ_CACHE[instance as usize].store(
3290 instance.baud_rate_generator_config_frequency(clocks, config),
3291 ::core::sync::atomic::Ordering::Release,
3292 );
3293 }
3294 }
3295 fn refresh_apb_clk_downstream(clocks: &mut ClockTree) {
3296 if let Some(config) = clocks.apb_clk {
3297 APB_CLK_FREQ_CACHE.store(
3298 apb_clk_config_frequency(clocks, config),
3299 ::core::sync::atomic::Ordering::Release,
3300 );
3301 }
3302 }
3303 fn refresh_crypto_clk_downstream(clocks: &mut ClockTree) {
3304 if let Some(config) = clocks.crypto_clk {
3305 CRYPTO_CLK_FREQ_CACHE.store(
3306 crypto_clk_config_frequency(clocks, config),
3307 ::core::sync::atomic::Ordering::Release,
3308 );
3309 }
3310 }
3311 fn refresh_mspi_clk_downstream(clocks: &mut ClockTree) {
3312 if let Some(config) = clocks.mspi_clk {
3313 MSPI_CLK_FREQ_CACHE.store(
3314 mspi_clk_config_frequency(clocks, config),
3315 ::core::sync::atomic::Ordering::Release,
3316 );
3317 }
3318 }
3319 };
3320}
3321#[macro_export]
3325#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3326macro_rules! implement_peripheral_clocks {
3327 () => {
3328 #[doc(hidden)]
3329 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
3330 #[repr(u8)]
3331 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
3332 pub enum Peripheral {
3333 AhbGdma,
3335 ApbSarAdc,
3337 Ecc,
3339 I2cExt0,
3341 Ledc,
3343 Sha,
3345 Spi2,
3347 Systimer,
3349 Timg0,
3351 Tsens,
3353 Uart0,
3355 Uart1,
3357 UartMem,
3359 }
3360 impl Peripheral {
3361 const KEEP_ENABLED: &[Peripheral] =
3362 &[Self::Systimer, Self::Timg0, Self::Uart0, Self::UartMem];
3363 const COUNT: usize = Self::ALL.len();
3364 const ALL: &[Self] = &[
3365 Self::AhbGdma,
3366 Self::ApbSarAdc,
3367 Self::Ecc,
3368 Self::I2cExt0,
3369 Self::Ledc,
3370 Self::Sha,
3371 Self::Spi2,
3372 Self::Systimer,
3373 Self::Timg0,
3374 Self::Tsens,
3375 Self::Uart0,
3376 Self::Uart1,
3377 Self::UartMem,
3378 ];
3379 }
3380 unsafe fn enable_internal_racey(peripheral: Peripheral, enable: bool) {
3381 match peripheral {
3382 Peripheral::AhbGdma => {
3383 crate::peripherals::SYSTEM::regs()
3384 .perip_clk_en1()
3385 .modify(|_, w| w.dma_clk_en().bit(enable));
3386 }
3387 Peripheral::ApbSarAdc => {
3388 crate::peripherals::SYSTEM::regs()
3389 .perip_clk_en0()
3390 .modify(|_, w| w.apb_saradc_clk_en().bit(enable));
3391 }
3392 Peripheral::Ecc => {
3393 crate::peripherals::SYSTEM::regs()
3394 .perip_clk_en1()
3395 .modify(|_, w| w.crypto_ecc_clk_en().bit(enable));
3396 }
3397 Peripheral::I2cExt0 => {
3398 crate::peripherals::SYSTEM::regs()
3399 .perip_clk_en0()
3400 .modify(|_, w| w.i2c_ext0_clk_en().bit(enable));
3401 }
3402 Peripheral::Ledc => {
3403 crate::peripherals::SYSTEM::regs()
3404 .perip_clk_en0()
3405 .modify(|_, w| w.ledc_clk_en().bit(enable));
3406 }
3407 Peripheral::Sha => {
3408 crate::peripherals::SYSTEM::regs()
3409 .perip_clk_en1()
3410 .modify(|_, w| w.crypto_sha_clk_en().bit(enable));
3411 }
3412 Peripheral::Spi2 => {
3413 crate::peripherals::SYSTEM::regs()
3414 .perip_clk_en0()
3415 .modify(|_, w| w.spi2_clk_en().bit(enable));
3416 }
3417 Peripheral::Systimer => {
3418 crate::peripherals::SYSTEM::regs()
3419 .perip_clk_en0()
3420 .modify(|_, w| w.systimer_clk_en().bit(enable));
3421 }
3422 Peripheral::Timg0 => {
3423 crate::peripherals::SYSTEM::regs()
3424 .perip_clk_en0()
3425 .modify(|_, w| w.timergroup_clk_en().bit(enable));
3426 }
3427 Peripheral::Tsens => {
3428 crate::peripherals::SYSTEM::regs()
3429 .perip_clk_en1()
3430 .modify(|_, w| w.tsens_clk_en().bit(enable));
3431 }
3432 Peripheral::Uart0 => {
3433 crate::peripherals::SYSTEM::regs()
3434 .perip_clk_en0()
3435 .modify(|_, w| w.uart_clk_en().bit(enable));
3436 }
3437 Peripheral::Uart1 => {
3438 crate::peripherals::SYSTEM::regs()
3439 .perip_clk_en0()
3440 .modify(|_, w| w.uart1_clk_en().bit(enable));
3441 }
3442 Peripheral::UartMem => {
3443 crate::peripherals::SYSTEM::regs()
3444 .perip_clk_en0()
3445 .modify(|_, w| w.uart_mem_clk_en().bit(enable));
3446 }
3447 }
3448 }
3449 unsafe fn assert_peri_reset_racey(peripheral: Peripheral, reset: bool) {
3450 match peripheral {
3451 Peripheral::AhbGdma => {
3452 crate::peripherals::SYSTEM::regs()
3453 .perip_rst_en1()
3454 .modify(|_, w| w.dma_rst().bit(reset));
3455 }
3456 Peripheral::ApbSarAdc => {
3457 crate::peripherals::SYSTEM::regs()
3458 .perip_rst_en0()
3459 .modify(|_, w| w.apb_saradc_rst().bit(reset));
3460 }
3461 Peripheral::Ecc => {
3462 crate::peripherals::SYSTEM::regs()
3463 .perip_rst_en1()
3464 .modify(|_, w| w.crypto_ecc_rst().bit(reset));
3465 }
3466 Peripheral::I2cExt0 => {
3467 crate::peripherals::SYSTEM::regs()
3468 .perip_rst_en0()
3469 .modify(|_, w| w.i2c_ext0_rst().bit(reset));
3470 }
3471 Peripheral::Ledc => {
3472 crate::peripherals::SYSTEM::regs()
3473 .perip_rst_en0()
3474 .modify(|_, w| w.ledc_rst().bit(reset));
3475 }
3476 Peripheral::Sha => {
3477 crate::peripherals::SYSTEM::regs()
3478 .perip_rst_en1()
3479 .modify(|_, w| w.crypto_sha_rst().bit(reset));
3480 }
3481 Peripheral::Spi2 => {
3482 crate::peripherals::SYSTEM::regs()
3483 .perip_rst_en0()
3484 .modify(|_, w| w.spi2_rst().bit(reset));
3485 }
3486 Peripheral::Systimer => {
3487 crate::peripherals::SYSTEM::regs()
3488 .perip_rst_en0()
3489 .modify(|_, w| w.systimer_rst().bit(reset));
3490 }
3491 Peripheral::Timg0 => {
3492 crate::peripherals::SYSTEM::regs()
3493 .perip_rst_en0()
3494 .modify(|_, w| w.timergroup_rst().bit(reset));
3495 }
3496 Peripheral::Tsens => {
3497 crate::peripherals::SYSTEM::regs()
3498 .perip_rst_en1()
3499 .modify(|_, w| w.tsens_rst().bit(reset));
3500 }
3501 Peripheral::Uart0 => {
3502 crate::peripherals::SYSTEM::regs()
3503 .perip_rst_en0()
3504 .modify(|_, w| w.uart_rst().bit(reset));
3505 }
3506 Peripheral::Uart1 => {
3507 crate::peripherals::SYSTEM::regs()
3508 .perip_rst_en0()
3509 .modify(|_, w| w.uart1_rst().bit(reset));
3510 }
3511 Peripheral::UartMem => {
3512 crate::peripherals::SYSTEM::regs()
3513 .perip_rst_en0()
3514 .modify(|_, w| w.uart_mem_rst().bit(reset));
3515 }
3516 }
3517 }
3518 };
3519}
3520#[macro_export]
3528#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3529macro_rules! memory_range {
3530 ("DRAM") => {
3531 0x3FCA0000..0x3FCE0000
3532 };
3533 (size as str, "DRAM") => {
3534 "262144"
3535 };
3536 ("DRAM2_UNINIT") => {
3537 0x3FCCE800..0x3FCDEB70
3538 };
3539 (size as str, "DRAM2_UNINIT") => {
3540 "66416"
3541 };
3542 ("IROM") => {
3543 0x42000000..0x42400000
3544 };
3545 (size as str, "IROM") => {
3546 "4194304"
3547 };
3548 ("DROM") => {
3549 0x3C000000..0x3C400000
3550 };
3551 (size as str, "DROM") => {
3552 "4194304"
3553 };
3554}
3555#[macro_export]
3572#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3573macro_rules! for_each_i2c_master {
3574 ($($pattern:tt => $code:tt;)*) => {
3575 macro_rules! _for_each_inner_i2c_master { $(($pattern) => $code;)* ($other : tt)
3576 => {} } _for_each_inner_i2c_master!((0, I2C0, I2cExt0, I2CEXT0_SCL,
3577 I2CEXT0_SDA)); _for_each_inner_i2c_master!((all(0, I2C0, I2cExt0, I2CEXT0_SCL,
3578 I2CEXT0_SDA)));
3579 };
3580}
3581#[macro_export]
3600#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3601macro_rules! for_each_uart {
3602 ($($pattern:tt => $code:tt;)*) => {
3603 macro_rules! _for_each_inner_uart { $(($pattern) => $code;)* ($other : tt) => {}
3604 } _for_each_inner_uart!((0, UART0, Uart0, U0RXD, U0TXD, U0CTS, U0RTS,
3605 wakeup_source = true)); _for_each_inner_uart!((1, UART1, Uart1, U1RXD, U1TXD,
3606 U1CTS, U1RTS, wakeup_source = true)); _for_each_inner_uart!((all(0, UART0, Uart0,
3607 U0RXD, U0TXD, U0CTS, U0RTS, wakeup_source = true), (1, UART1, Uart1, U1RXD,
3608 U1TXD, U1CTS, U1RTS, wakeup_source = true)));
3609 };
3610}
3611#[macro_export]
3633#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3634macro_rules! for_each_spi_master {
3635 ($($pattern:tt => $code:tt;)*) => {
3636 macro_rules! _for_each_inner_spi_master { $(($pattern) => $code;)* ($other : tt)
3637 => {} } _for_each_inner_spi_master!((SPI2)); _for_each_inner_spi_master!((SPI2,
3638 Spi2, FSPICLK[FSPICS0, FSPICS1, FSPICS2, FSPICS3, FSPICS4, FSPICS5] [FSPID,
3639 FSPIQ, FSPIWP, FSPIHD], true)); _for_each_inner_spi_master!((names(SPI2)));
3640 _for_each_inner_spi_master!((all(SPI2, Spi2, FSPICLK[FSPICS0, FSPICS1, FSPICS2,
3641 FSPICS3, FSPICS4, FSPICS5] [FSPID, FSPIQ, FSPIWP, FSPIHD], true)));
3642 };
3643}
3644#[macro_export]
3661#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3662macro_rules! for_each_spi_slave {
3663 ($($pattern:tt => $code:tt;)*) => {
3664 macro_rules! _for_each_inner_spi_slave { $(($pattern) => $code;)* ($other : tt)
3665 => {} } _for_each_inner_spi_slave!((SPI2)); _for_each_inner_spi_slave!((SPI2,
3666 Spi2, FSPICLK, FSPID, FSPIQ, FSPICS0));
3667 _for_each_inner_spi_slave!((names(SPI2))); _for_each_inner_spi_slave!((all(SPI2,
3668 Spi2, FSPICLK, FSPID, FSPIQ, FSPICS0)));
3669 };
3670}
3671#[macro_export]
3672#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
3673macro_rules! for_each_peripheral {
3674 ($($pattern:tt => $code:tt;)*) => {
3675 macro_rules! _for_each_inner_peripheral { $(($pattern) => $code;)* ($other : tt)
3676 => {} } _for_each_inner_peripheral!((@ peri_type #[doc =
3677 "GPIO0 peripheral singleton"] GPIO0 <= virtual()));
3678 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO1 peripheral singleton"]
3679 GPIO1 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
3680 "GPIO2 peripheral singleton"] GPIO2 <= virtual()));
3681 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO3 peripheral singleton"]
3682 GPIO3 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
3683 "GPIO4 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3684 "<section class=\"warning\">"] #[doc =
3685 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3686 #[doc = "<ul>"] #[doc =
3687 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3688 #[doc = "</ul>"] #[doc = "</section>"] GPIO4 <= virtual()));
3689 _for_each_inner_peripheral!((@ peri_type #[doc =
3690 "GPIO5 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3691 "<section class=\"warning\">"] #[doc =
3692 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3693 #[doc = "<ul>"] #[doc =
3694 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3695 #[doc = "</ul>"] #[doc = "</section>"] GPIO5 <= virtual()));
3696 _for_each_inner_peripheral!((@ peri_type #[doc =
3697 "GPIO6 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3698 "<section class=\"warning\">"] #[doc =
3699 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3700 #[doc = "<ul>"] #[doc =
3701 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3702 #[doc = "</ul>"] #[doc = "</section>"] GPIO6 <= virtual()));
3703 _for_each_inner_peripheral!((@ peri_type #[doc =
3704 "GPIO7 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3705 "<section class=\"warning\">"] #[doc =
3706 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3707 #[doc = "<ul>"] #[doc =
3708 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3709 #[doc = "</ul>"] #[doc = "</section>"] GPIO7 <= virtual()));
3710 _for_each_inner_peripheral!((@ peri_type #[doc =
3711 "GPIO8 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3712 "<section class=\"warning\">"] #[doc =
3713 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3714 #[doc = "<ul>"] #[doc =
3715 "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
3716 = "</ul>"] #[doc = "</section>"] GPIO8 <= virtual()));
3717 _for_each_inner_peripheral!((@ peri_type #[doc =
3718 "GPIO9 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3719 "<section class=\"warning\">"] #[doc =
3720 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3721 #[doc = "<ul>"] #[doc =
3722 "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
3723 = "</ul>"] #[doc = "</section>"] GPIO9 <= virtual()));
3724 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO10 peripheral singleton"]
3725 GPIO10 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
3726 "GPIO11 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3727 "<section class=\"warning\">"] #[doc =
3728 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3729 #[doc = "<ul>"] #[doc =
3730 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3731 "</ul>"] #[doc = "</section>"] GPIO11 <= virtual()));
3732 _for_each_inner_peripheral!((@ peri_type #[doc =
3733 "GPIO12 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3734 "<section class=\"warning\">"] #[doc =
3735 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3736 #[doc = "<ul>"] #[doc =
3737 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3738 "</ul>"] #[doc = "</section>"] GPIO12 <= virtual()));
3739 _for_each_inner_peripheral!((@ peri_type #[doc =
3740 "GPIO13 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3741 "<section class=\"warning\">"] #[doc =
3742 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3743 #[doc = "<ul>"] #[doc =
3744 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3745 "</ul>"] #[doc = "</section>"] GPIO13 <= virtual()));
3746 _for_each_inner_peripheral!((@ peri_type #[doc =
3747 "GPIO14 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3748 "<section class=\"warning\">"] #[doc =
3749 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3750 #[doc = "<ul>"] #[doc =
3751 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3752 "</ul>"] #[doc = "</section>"] GPIO14 <= virtual()));
3753 _for_each_inner_peripheral!((@ peri_type #[doc =
3754 "GPIO15 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3755 "<section class=\"warning\">"] #[doc =
3756 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3757 #[doc = "<ul>"] #[doc =
3758 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3759 "</ul>"] #[doc = "</section>"] GPIO15 <= virtual()));
3760 _for_each_inner_peripheral!((@ peri_type #[doc =
3761 "GPIO16 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3762 "<section class=\"warning\">"] #[doc =
3763 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3764 #[doc = "<ul>"] #[doc =
3765 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3766 "</ul>"] #[doc = "</section>"] GPIO16 <= virtual()));
3767 _for_each_inner_peripheral!((@ peri_type #[doc =
3768 "GPIO17 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3769 "<section class=\"warning\">"] #[doc =
3770 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3771 #[doc = "<ul>"] #[doc =
3772 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3773 "</ul>"] #[doc = "</section>"] GPIO17 <= virtual()));
3774 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO18 peripheral singleton"]
3775 GPIO18 <= virtual())); _for_each_inner_peripheral!((@ peri_type #[doc =
3776 "GPIO19 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3777 "<section class=\"warning\">"] #[doc =
3778 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3779 #[doc = "<ul>"] #[doc =
3780 "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
3781 = "</ul>"] #[doc = "</section>"] GPIO19 <= virtual()));
3782 _for_each_inner_peripheral!((@ peri_type #[doc =
3783 "GPIO20 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3784 "<section class=\"warning\">"] #[doc =
3785 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3786 #[doc = "<ul>"] #[doc =
3787 "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
3788 = "</ul>"] #[doc = "</section>"] GPIO20 <= virtual()));
3789 _for_each_inner_peripheral!((@ peri_type #[doc = "DMA_CH0 peripheral singleton"]
3790 DMA_CH0 <= virtual(DMA_CH0 : { bind_dma_interrupt, enable_dma_interrupt,
3791 disable_dma_interrupt }) (unstable))); _for_each_inner_peripheral!((@ peri_type
3792 #[doc = "APB_CTRL peripheral singleton"] APB_CTRL <= APB_CTRL() (unstable)));
3793 _for_each_inner_peripheral!((@ peri_type #[doc =
3794 "APB_SARADC peripheral singleton"] APB_SARADC <= APB_SARADC() (unstable)));
3795 _for_each_inner_peripheral!((@ peri_type #[doc = "BB peripheral singleton"] BB <=
3796 BB() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3797 "ASSIST_DEBUG peripheral singleton"] ASSIST_DEBUG <= ASSIST_DEBUG() (unstable)));
3798 _for_each_inner_peripheral!((@ peri_type #[doc = "DMA peripheral singleton"] DMA
3799 <= DMA() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3800 "ECC peripheral singleton"] ECC <= ECC() (unstable)));
3801 _for_each_inner_peripheral!((@ peri_type #[doc = "EFUSE peripheral singleton"]
3802 EFUSE <= EFUSE() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3803 "EXTMEM peripheral singleton"] EXTMEM <= EXTMEM() (unstable)));
3804 _for_each_inner_peripheral!((@ peri_type #[doc =
3805 "MMU_TABLE peripheral singleton"] MMU_TABLE <= MMU_TABLE() (unstable)));
3806 _for_each_inner_peripheral!((@ peri_type #[doc = "GPIO peripheral singleton"]
3807 GPIO <= GPIO() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3808 "I2C_ANA_MST peripheral singleton"] I2C_ANA_MST <= I2C_ANA_MST() (unstable)));
3809 _for_each_inner_peripheral!((@ peri_type #[doc = "I2C0 peripheral singleton"]
3810 I2C0 <= I2C0(I2C_EXT0 : { bind_peri_interrupt, enable_peri_interrupt,
3811 disable_peri_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
3812 "INTERRUPT_CORE0 peripheral singleton"] INTERRUPT_CORE0 <= INTERRUPT_CORE0()
3813 (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3814 "IO_MUX peripheral singleton"] IO_MUX <= IO_MUX() (unstable)));
3815 _for_each_inner_peripheral!((@ peri_type #[doc = "LEDC peripheral singleton"]
3816 LEDC <= LEDC() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3817 "RNG peripheral singleton"] RNG <= RNG() (unstable)));
3818 _for_each_inner_peripheral!((@ peri_type #[doc = "LPWR peripheral singleton"]
3819 LPWR <= RTC_CNTL() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3820 "RTC_TIMER peripheral singleton"] RTC_TIMER <= RTC_CNTL() (unstable)));
3821 _for_each_inner_peripheral!((@ peri_type #[doc =
3822 "MODEM_CLKRST peripheral singleton"] MODEM_CLKRST <= MODEM_CLKRST() (unstable)));
3823 _for_each_inner_peripheral!((@ peri_type #[doc =
3824 "SENSITIVE peripheral singleton"] SENSITIVE <= SENSITIVE() (unstable)));
3825 _for_each_inner_peripheral!((@ peri_type #[doc = "SHA peripheral singleton"] SHA
3826 <= SHA(SHA : { bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt
3827 }) (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3828 "SPI0 peripheral singleton"] SPI0 <= SPI0() (unstable)));
3829 _for_each_inner_peripheral!((@ peri_type #[doc = "SPI1 peripheral singleton"]
3830 SPI1 <= SPI1() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3831 "SPI2 peripheral singleton"] SPI2 <= SPI2(SPI2 : { bind_peri_interrupt,
3832 enable_peri_interrupt, disable_peri_interrupt })));
3833 _for_each_inner_peripheral!((@ peri_type #[doc = "SYSTEM peripheral singleton"]
3834 SYSTEM <= SYSTEM() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3835 "SYSTIMER peripheral singleton"] SYSTIMER <= SYSTIMER() (unstable)));
3836 _for_each_inner_peripheral!((@ peri_type #[doc = "TIMG0 peripheral singleton"]
3837 TIMG0 <= TIMG0() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3838 "UART0 peripheral singleton"] UART0 <= UART0(UART0 : { bind_peri_interrupt,
3839 enable_peri_interrupt, disable_peri_interrupt })));
3840 _for_each_inner_peripheral!((@ peri_type #[doc = "UART1 peripheral singleton"]
3841 UART1 <= UART1(UART1 : { bind_peri_interrupt, enable_peri_interrupt,
3842 disable_peri_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
3843 "XTS_AES peripheral singleton"] XTS_AES <= XTS_AES() (unstable)));
3844 _for_each_inner_peripheral!((@ peri_type #[doc = "ADC1 peripheral singleton"]
3845 ADC1 <= virtual() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3846 "BT peripheral singleton"] BT <= virtual(LP_TIMER : { bind_lp_timer_interrupt,
3847 enable_lp_timer_interrupt, disable_lp_timer_interrupt }, BT_MAC : {
3848 bind_mac_interrupt, enable_mac_interrupt, disable_mac_interrupt }) (unstable)));
3849 _for_each_inner_peripheral!((@ peri_type #[doc = "FLASH peripheral singleton"]
3850 FLASH <= virtual() (unstable))); _for_each_inner_peripheral!((@ peri_type #[doc =
3851 "GPIO_DEDICATED peripheral singleton"] GPIO_DEDICATED <= virtual() (unstable)));
3852 _for_each_inner_peripheral!((@ peri_type #[doc = "WIFI peripheral singleton"]
3853 WIFI <= virtual(WIFI_MAC : { bind_mac_interrupt, enable_mac_interrupt,
3854 disable_mac_interrupt }, WIFI_PWR : { bind_pwr_interrupt, enable_pwr_interrupt,
3855 disable_pwr_interrupt }))); _for_each_inner_peripheral!((@ peri_type #[doc =
3856 "FROM_CPU_INTR0 peripheral singleton"] FROM_CPU_INTR0 <= virtual() (unstable)));
3857 _for_each_inner_peripheral!((@ peri_type #[doc =
3858 "FROM_CPU_INTR1 peripheral singleton"] FROM_CPU_INTR1 <= virtual() (unstable)));
3859 _for_each_inner_peripheral!((@ peri_type #[doc =
3860 "FROM_CPU_INTR2 peripheral singleton"] FROM_CPU_INTR2 <= virtual() (unstable)));
3861 _for_each_inner_peripheral!((@ peri_type #[doc =
3862 "FROM_CPU_INTR3 peripheral singleton"] FROM_CPU_INTR3 <= virtual() (unstable)));
3863 _for_each_inner_peripheral!((GPIO0)); _for_each_inner_peripheral!((GPIO1));
3864 _for_each_inner_peripheral!((GPIO2)); _for_each_inner_peripheral!((GPIO3));
3865 _for_each_inner_peripheral!((GPIO4)); _for_each_inner_peripheral!((GPIO5));
3866 _for_each_inner_peripheral!((GPIO6)); _for_each_inner_peripheral!((GPIO7));
3867 _for_each_inner_peripheral!((GPIO8)); _for_each_inner_peripheral!((GPIO9));
3868 _for_each_inner_peripheral!((GPIO10)); _for_each_inner_peripheral!((GPIO11));
3869 _for_each_inner_peripheral!((GPIO12)); _for_each_inner_peripheral!((GPIO13));
3870 _for_each_inner_peripheral!((GPIO14)); _for_each_inner_peripheral!((GPIO15));
3871 _for_each_inner_peripheral!((GPIO16)); _for_each_inner_peripheral!((GPIO17));
3872 _for_each_inner_peripheral!((GPIO18)); _for_each_inner_peripheral!((GPIO19));
3873 _for_each_inner_peripheral!((GPIO20));
3874 _for_each_inner_peripheral!((DMA_CH0(unstable)));
3875 _for_each_inner_peripheral!((APB_CTRL(unstable)));
3876 _for_each_inner_peripheral!((APB_SARADC(unstable)));
3877 _for_each_inner_peripheral!((BB(unstable)));
3878 _for_each_inner_peripheral!((ASSIST_DEBUG(unstable)));
3879 _for_each_inner_peripheral!((DMA(unstable)));
3880 _for_each_inner_peripheral!((ECC(unstable)));
3881 _for_each_inner_peripheral!((EXTMEM(unstable)));
3882 _for_each_inner_peripheral!((GPIO(unstable)));
3883 _for_each_inner_peripheral!((I2C_ANA_MST(unstable)));
3884 _for_each_inner_peripheral!((I2C0));
3885 _for_each_inner_peripheral!((INTERRUPT_CORE0(unstable)));
3886 _for_each_inner_peripheral!((IO_MUX(unstable)));
3887 _for_each_inner_peripheral!((LEDC(unstable)));
3888 _for_each_inner_peripheral!((RNG(unstable)));
3889 _for_each_inner_peripheral!((LPWR(unstable)));
3890 _for_each_inner_peripheral!((RTC_TIMER(unstable)));
3891 _for_each_inner_peripheral!((MODEM_CLKRST(unstable)));
3892 _for_each_inner_peripheral!((SENSITIVE(unstable)));
3893 _for_each_inner_peripheral!((SHA(unstable)));
3894 _for_each_inner_peripheral!((SPI0(unstable)));
3895 _for_each_inner_peripheral!((SPI1(unstable)));
3896 _for_each_inner_peripheral!((SPI2));
3897 _for_each_inner_peripheral!((SYSTEM(unstable)));
3898 _for_each_inner_peripheral!((SYSTIMER(unstable)));
3899 _for_each_inner_peripheral!((TIMG0(unstable)));
3900 _for_each_inner_peripheral!((UART0)); _for_each_inner_peripheral!((UART1));
3901 _for_each_inner_peripheral!((XTS_AES(unstable)));
3902 _for_each_inner_peripheral!((ADC1(unstable)));
3903 _for_each_inner_peripheral!((BT(unstable)));
3904 _for_each_inner_peripheral!((FLASH(unstable)));
3905 _for_each_inner_peripheral!((GPIO_DEDICATED(unstable)));
3906 _for_each_inner_peripheral!((WIFI));
3907 _for_each_inner_peripheral!((FROM_CPU_INTR0(unstable)));
3908 _for_each_inner_peripheral!((FROM_CPU_INTR1(unstable)));
3909 _for_each_inner_peripheral!((FROM_CPU_INTR2(unstable)));
3910 _for_each_inner_peripheral!((FROM_CPU_INTR3(unstable)));
3911 _for_each_inner_peripheral!((SPI2, Spi2, 0, AhbGdmaChannel));
3912 _for_each_inner_peripheral!((SHA, Sha, 7, AhbGdmaChannel));
3913 _for_each_inner_peripheral!((all(@ peri_type #[doc =
3914 "GPIO0 peripheral singleton"] GPIO0 <= virtual()), (@ peri_type #[doc =
3915 "GPIO1 peripheral singleton"] GPIO1 <= virtual()), (@ peri_type #[doc =
3916 "GPIO2 peripheral singleton"] GPIO2 <= virtual()), (@ peri_type #[doc =
3917 "GPIO3 peripheral singleton"] GPIO3 <= virtual()), (@ peri_type #[doc =
3918 "GPIO4 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3919 "<section class=\"warning\">"] #[doc =
3920 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3921 #[doc = "<ul>"] #[doc =
3922 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3923 #[doc = "</ul>"] #[doc = "</section>"] GPIO4 <= virtual()), (@ peri_type #[doc =
3924 "GPIO5 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3925 "<section class=\"warning\">"] #[doc =
3926 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3927 #[doc = "<ul>"] #[doc =
3928 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3929 #[doc = "</ul>"] #[doc = "</section>"] GPIO5 <= virtual()), (@ peri_type #[doc =
3930 "GPIO6 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3931 "<section class=\"warning\">"] #[doc =
3932 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3933 #[doc = "<ul>"] #[doc =
3934 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3935 #[doc = "</ul>"] #[doc = "</section>"] GPIO6 <= virtual()), (@ peri_type #[doc =
3936 "GPIO7 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3937 "<section class=\"warning\">"] #[doc =
3938 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3939 #[doc = "<ul>"] #[doc =
3940 "<li>These pins may be used to debug the chip using an external JTAG debugger.</li>"]
3941 #[doc = "</ul>"] #[doc = "</section>"] GPIO7 <= virtual()), (@ peri_type #[doc =
3942 "GPIO8 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3943 "<section class=\"warning\">"] #[doc =
3944 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3945 #[doc = "<ul>"] #[doc =
3946 "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
3947 = "</ul>"] #[doc = "</section>"] GPIO8 <= virtual()), (@ peri_type #[doc =
3948 "GPIO9 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3949 "<section class=\"warning\">"] #[doc =
3950 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3951 #[doc = "<ul>"] #[doc =
3952 "<li>This pin is a strapping pin, it determines how the chip boots.</li>"] #[doc
3953 = "</ul>"] #[doc = "</section>"] GPIO9 <= virtual()), (@ peri_type #[doc =
3954 "GPIO10 peripheral singleton"] GPIO10 <= virtual()), (@ peri_type #[doc =
3955 "GPIO11 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3956 "<section class=\"warning\">"] #[doc =
3957 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3958 #[doc = "<ul>"] #[doc =
3959 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3960 "</ul>"] #[doc = "</section>"] GPIO11 <= virtual()), (@ peri_type #[doc =
3961 "GPIO12 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3962 "<section class=\"warning\">"] #[doc =
3963 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3964 #[doc = "<ul>"] #[doc =
3965 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3966 "</ul>"] #[doc = "</section>"] GPIO12 <= virtual()), (@ peri_type #[doc =
3967 "GPIO13 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3968 "<section class=\"warning\">"] #[doc =
3969 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3970 #[doc = "<ul>"] #[doc =
3971 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3972 "</ul>"] #[doc = "</section>"] GPIO13 <= virtual()), (@ peri_type #[doc =
3973 "GPIO14 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3974 "<section class=\"warning\">"] #[doc =
3975 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3976 #[doc = "<ul>"] #[doc =
3977 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3978 "</ul>"] #[doc = "</section>"] GPIO14 <= virtual()), (@ peri_type #[doc =
3979 "GPIO15 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3980 "<section class=\"warning\">"] #[doc =
3981 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3982 #[doc = "<ul>"] #[doc =
3983 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3984 "</ul>"] #[doc = "</section>"] GPIO15 <= virtual()), (@ peri_type #[doc =
3985 "GPIO16 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3986 "<section class=\"warning\">"] #[doc =
3987 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3988 #[doc = "<ul>"] #[doc =
3989 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3990 "</ul>"] #[doc = "</section>"] GPIO16 <= virtual()), (@ peri_type #[doc =
3991 "GPIO17 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3992 "<section class=\"warning\">"] #[doc =
3993 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
3994 #[doc = "<ul>"] #[doc =
3995 "<li>This pin may be reserved for interfacing with SPI flash.</li>"] #[doc =
3996 "</ul>"] #[doc = "</section>"] GPIO17 <= virtual()), (@ peri_type #[doc =
3997 "GPIO18 peripheral singleton"] GPIO18 <= virtual()), (@ peri_type #[doc =
3998 "GPIO19 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
3999 "<section class=\"warning\">"] #[doc =
4000 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4001 #[doc = "<ul>"] #[doc =
4002 "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
4003 = "</ul>"] #[doc = "</section>"] GPIO19 <= virtual()), (@ peri_type #[doc =
4004 "GPIO20 peripheral singleton (Limitations exist)"] #[doc = ""] #[doc =
4005 "<section class=\"warning\">"] #[doc =
4006 "This pin may be available with certain limitations. Check your hardware to make sure whether you can use it."]
4007 #[doc = "<ul>"] #[doc =
4008 "<li>By default, this pin is used by the UART programming interface.</li>"] #[doc
4009 = "</ul>"] #[doc = "</section>"] GPIO20 <= virtual()), (@ peri_type #[doc =
4010 "DMA_CH0 peripheral singleton"] DMA_CH0 <= virtual(DMA_CH0 : {
4011 bind_dma_interrupt, enable_dma_interrupt, disable_dma_interrupt }) (unstable)),
4012 (@ peri_type #[doc = "APB_CTRL peripheral singleton"] APB_CTRL <= APB_CTRL()
4013 (unstable)), (@ peri_type #[doc = "APB_SARADC peripheral singleton"] APB_SARADC
4014 <= APB_SARADC() (unstable)), (@ peri_type #[doc = "BB peripheral singleton"] BB
4015 <= BB() (unstable)), (@ peri_type #[doc = "ASSIST_DEBUG peripheral singleton"]
4016 ASSIST_DEBUG <= ASSIST_DEBUG() (unstable)), (@ peri_type #[doc =
4017 "DMA peripheral singleton"] DMA <= DMA() (unstable)), (@ peri_type #[doc =
4018 "ECC peripheral singleton"] ECC <= ECC() (unstable)), (@ peri_type #[doc =
4019 "EFUSE peripheral singleton"] EFUSE <= EFUSE() (unstable)), (@ peri_type #[doc =
4020 "EXTMEM peripheral singleton"] EXTMEM <= EXTMEM() (unstable)), (@ peri_type #[doc
4021 = "MMU_TABLE peripheral singleton"] MMU_TABLE <= MMU_TABLE() (unstable)), (@
4022 peri_type #[doc = "GPIO peripheral singleton"] GPIO <= GPIO() (unstable)), (@
4023 peri_type #[doc = "I2C_ANA_MST peripheral singleton"] I2C_ANA_MST <=
4024 I2C_ANA_MST() (unstable)), (@ peri_type #[doc = "I2C0 peripheral singleton"] I2C0
4025 <= I2C0(I2C_EXT0 : { bind_peri_interrupt, enable_peri_interrupt,
4026 disable_peri_interrupt })), (@ peri_type #[doc =
4027 "INTERRUPT_CORE0 peripheral singleton"] INTERRUPT_CORE0 <= INTERRUPT_CORE0()
4028 (unstable)), (@ peri_type #[doc = "IO_MUX peripheral singleton"] IO_MUX <=
4029 IO_MUX() (unstable)), (@ peri_type #[doc = "LEDC peripheral singleton"] LEDC <=
4030 LEDC() (unstable)), (@ peri_type #[doc = "RNG peripheral singleton"] RNG <= RNG()
4031 (unstable)), (@ peri_type #[doc = "LPWR peripheral singleton"] LPWR <= RTC_CNTL()
4032 (unstable)), (@ peri_type #[doc = "RTC_TIMER peripheral singleton"] RTC_TIMER <=
4033 RTC_CNTL() (unstable)), (@ peri_type #[doc = "MODEM_CLKRST peripheral singleton"]
4034 MODEM_CLKRST <= MODEM_CLKRST() (unstable)), (@ peri_type #[doc =
4035 "SENSITIVE peripheral singleton"] SENSITIVE <= SENSITIVE() (unstable)), (@
4036 peri_type #[doc = "SHA peripheral singleton"] SHA <= SHA(SHA : {
4037 bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })
4038 (unstable)), (@ peri_type #[doc = "SPI0 peripheral singleton"] SPI0 <= SPI0()
4039 (unstable)), (@ peri_type #[doc = "SPI1 peripheral singleton"] SPI1 <= SPI1()
4040 (unstable)), (@ peri_type #[doc = "SPI2 peripheral singleton"] SPI2 <= SPI2(SPI2
4041 : { bind_peri_interrupt, enable_peri_interrupt, disable_peri_interrupt })), (@
4042 peri_type #[doc = "SYSTEM peripheral singleton"] SYSTEM <= SYSTEM() (unstable)),
4043 (@ peri_type #[doc = "SYSTIMER peripheral singleton"] SYSTIMER <= SYSTIMER()
4044 (unstable)), (@ peri_type #[doc = "TIMG0 peripheral singleton"] TIMG0 <= TIMG0()
4045 (unstable)), (@ peri_type #[doc = "UART0 peripheral singleton"] UART0 <=
4046 UART0(UART0 : { bind_peri_interrupt, enable_peri_interrupt,
4047 disable_peri_interrupt })), (@ peri_type #[doc = "UART1 peripheral singleton"]
4048 UART1 <= UART1(UART1 : { bind_peri_interrupt, enable_peri_interrupt,
4049 disable_peri_interrupt })), (@ peri_type #[doc = "XTS_AES peripheral singleton"]
4050 XTS_AES <= XTS_AES() (unstable)), (@ peri_type #[doc =
4051 "ADC1 peripheral singleton"] ADC1 <= virtual() (unstable)), (@ peri_type #[doc =
4052 "BT peripheral singleton"] BT <= virtual(LP_TIMER : { bind_lp_timer_interrupt,
4053 enable_lp_timer_interrupt, disable_lp_timer_interrupt }, BT_MAC : {
4054 bind_mac_interrupt, enable_mac_interrupt, disable_mac_interrupt }) (unstable)),
4055 (@ peri_type #[doc = "FLASH peripheral singleton"] FLASH <= virtual()
4056 (unstable)), (@ peri_type #[doc = "GPIO_DEDICATED peripheral singleton"]
4057 GPIO_DEDICATED <= virtual() (unstable)), (@ peri_type #[doc =
4058 "WIFI peripheral singleton"] WIFI <= virtual(WIFI_MAC : { bind_mac_interrupt,
4059 enable_mac_interrupt, disable_mac_interrupt }, WIFI_PWR : { bind_pwr_interrupt,
4060 enable_pwr_interrupt, disable_pwr_interrupt })), (@ peri_type #[doc =
4061 "FROM_CPU_INTR0 peripheral singleton"] FROM_CPU_INTR0 <= virtual() (unstable)),
4062 (@ peri_type #[doc = "FROM_CPU_INTR1 peripheral singleton"] FROM_CPU_INTR1 <=
4063 virtual() (unstable)), (@ peri_type #[doc =
4064 "FROM_CPU_INTR2 peripheral singleton"] FROM_CPU_INTR2 <= virtual() (unstable)),
4065 (@ peri_type #[doc = "FROM_CPU_INTR3 peripheral singleton"] FROM_CPU_INTR3 <=
4066 virtual() (unstable)))); _for_each_inner_peripheral!((singletons(GPIO0), (GPIO1),
4067 (GPIO2), (GPIO3), (GPIO4), (GPIO5), (GPIO6), (GPIO7), (GPIO8), (GPIO9), (GPIO10),
4068 (GPIO11), (GPIO12), (GPIO13), (GPIO14), (GPIO15), (GPIO16), (GPIO17), (GPIO18),
4069 (GPIO19), (GPIO20), (DMA_CH0(unstable)), (APB_CTRL(unstable)),
4070 (APB_SARADC(unstable)), (BB(unstable)), (ASSIST_DEBUG(unstable)),
4071 (DMA(unstable)), (ECC(unstable)), (EXTMEM(unstable)), (GPIO(unstable)),
4072 (I2C_ANA_MST(unstable)), (I2C0), (INTERRUPT_CORE0(unstable)), (IO_MUX(unstable)),
4073 (LEDC(unstable)), (RNG(unstable)), (LPWR(unstable)), (RTC_TIMER(unstable)),
4074 (MODEM_CLKRST(unstable)), (SENSITIVE(unstable)), (SHA(unstable)),
4075 (SPI0(unstable)), (SPI1(unstable)), (SPI2), (SYSTEM(unstable)),
4076 (SYSTIMER(unstable)), (TIMG0(unstable)), (UART0), (UART1), (XTS_AES(unstable)),
4077 (ADC1(unstable)), (BT(unstable)), (FLASH(unstable)), (GPIO_DEDICATED(unstable)),
4078 (WIFI), (FROM_CPU_INTR0(unstable)), (FROM_CPU_INTR1(unstable)),
4079 (FROM_CPU_INTR2(unstable)), (FROM_CPU_INTR3(unstable))));
4080 _for_each_inner_peripheral!((dma_eligible(SPI2, Spi2, 0, AhbGdmaChannel), (SHA,
4081 Sha, 7, AhbGdmaChannel)));
4082 };
4083}
4084#[macro_export]
4111#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4112macro_rules! for_each_gpio {
4113 ($($pattern:tt => $code:tt;)*) => {
4114 macro_rules! _for_each_inner_gpio { $(($pattern) => $code;)* ($other : tt) => {}
4115 } _for_each_inner_gpio!((0, GPIO0() () ([Input] [Output])));
4116 _for_each_inner_gpio!((1, GPIO1() () ([Input] [Output])));
4117 _for_each_inner_gpio!((2, GPIO2(_2 => FSPIQ) (_2 => FSPIQ) ([Input] [Output])));
4118 _for_each_inner_gpio!((3, GPIO3() () ([Input] [Output])));
4119 _for_each_inner_gpio!((4, GPIO4(_0 => MTMS _2 => FSPIHD) (_2 => FSPIHD) ([Input]
4120 [Output]))); _for_each_inner_gpio!((5, GPIO5(_0 => MTDI _2 => FSPIWP) (_2 =>
4121 FSPIWP) ([Input] [Output]))); _for_each_inner_gpio!((6, GPIO6(_0 => MTCK _2 =>
4122 FSPICLK) (_2 => FSPICLK) ([Input] [Output]))); _for_each_inner_gpio!((7, GPIO7(_2
4123 => FSPID) (_0 => MTDO _2 => FSPID) ([Input] [Output])));
4124 _for_each_inner_gpio!((8, GPIO8() () ([Input] [Output])));
4125 _for_each_inner_gpio!((9, GPIO9() () ([Input] [Output])));
4126 _for_each_inner_gpio!((10, GPIO10(_2 => FSPICS0) (_2 => FSPICS0) ([Input]
4127 [Output]))); _for_each_inner_gpio!((11, GPIO11(_0 => SPIHD) (_0 => SPIHD)
4128 ([Input] [Output]))); _for_each_inner_gpio!((12, GPIO12(_0 => SPIHD) (_0 =>
4129 SPIHD) ([Input] [Output]))); _for_each_inner_gpio!((13, GPIO13(_0 => SPIWP) (_0
4130 => SPIWP) ([Input] [Output]))); _for_each_inner_gpio!((14, GPIO14() (_0 =>
4131 SPICS0) ([Input] [Output]))); _for_each_inner_gpio!((15, GPIO15() (_0 => SPICLK)
4132 ([Input] [Output]))); _for_each_inner_gpio!((16, GPIO16(_0 => SPID) (_0 => SPID)
4133 ([Input] [Output]))); _for_each_inner_gpio!((17, GPIO17(_0 => SPIQ) (_0 => SPIQ)
4134 ([Input] [Output]))); _for_each_inner_gpio!((18, GPIO18() () ([Input]
4135 [Output]))); _for_each_inner_gpio!((19, GPIO19(_0 => U0RXD) () ([Input]
4136 [Output]))); _for_each_inner_gpio!((20, GPIO20() (_0 => U0TXD) ([Input]
4137 [Output]))); _for_each_inner_gpio!((all(0, GPIO0() () ([Input] [Output])), (1,
4138 GPIO1() () ([Input] [Output])), (2, GPIO2(_2 => FSPIQ) (_2 => FSPIQ) ([Input]
4139 [Output])), (3, GPIO3() () ([Input] [Output])), (4, GPIO4(_0 => MTMS _2 =>
4140 FSPIHD) (_2 => FSPIHD) ([Input] [Output])), (5, GPIO5(_0 => MTDI _2 => FSPIWP)
4141 (_2 => FSPIWP) ([Input] [Output])), (6, GPIO6(_0 => MTCK _2 => FSPICLK) (_2 =>
4142 FSPICLK) ([Input] [Output])), (7, GPIO7(_2 => FSPID) (_0 => MTDO _2 => FSPID)
4143 ([Input] [Output])), (8, GPIO8() () ([Input] [Output])), (9, GPIO9() () ([Input]
4144 [Output])), (10, GPIO10(_2 => FSPICS0) (_2 => FSPICS0) ([Input] [Output])), (11,
4145 GPIO11(_0 => SPIHD) (_0 => SPIHD) ([Input] [Output])), (12, GPIO12(_0 => SPIHD)
4146 (_0 => SPIHD) ([Input] [Output])), (13, GPIO13(_0 => SPIWP) (_0 => SPIWP)
4147 ([Input] [Output])), (14, GPIO14() (_0 => SPICS0) ([Input] [Output])), (15,
4148 GPIO15() (_0 => SPICLK) ([Input] [Output])), (16, GPIO16(_0 => SPID) (_0 => SPID)
4149 ([Input] [Output])), (17, GPIO17(_0 => SPIQ) (_0 => SPIQ) ([Input] [Output])),
4150 (18, GPIO18() () ([Input] [Output])), (19, GPIO19(_0 => U0RXD) () ([Input]
4151 [Output])), (20, GPIO20() (_0 => U0TXD) ([Input] [Output]))));
4152 };
4153}
4154#[macro_export]
4181#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4182macro_rules! for_each_analog_function {
4183 ($($pattern:tt => $code:tt;)*) => {
4184 macro_rules! _for_each_inner_analog_function { $(($pattern) => $code;)* ($other :
4185 tt) => {} } _for_each_inner_analog_function!((ADC1_CH0, GPIO0));
4186 _for_each_inner_analog_function!((ADC1_CH1, GPIO1));
4187 _for_each_inner_analog_function!((ADC1_CH2, GPIO2));
4188 _for_each_inner_analog_function!((ADC1_CH3, GPIO3));
4189 _for_each_inner_analog_function!((ADC1_CH4, GPIO4));
4190 _for_each_inner_analog_function!(((ADC1_CH0, ADCn_CHm, 1, 0), GPIO0));
4191 _for_each_inner_analog_function!(((ADC1_CH1, ADCn_CHm, 1, 1), GPIO1));
4192 _for_each_inner_analog_function!(((ADC1_CH2, ADCn_CHm, 1, 2), GPIO2));
4193 _for_each_inner_analog_function!(((ADC1_CH3, ADCn_CHm, 1, 3), GPIO3));
4194 _for_each_inner_analog_function!(((ADC1_CH4, ADCn_CHm, 1, 4), GPIO4));
4195 _for_each_inner_analog_function!((all(ADC1_CH0, GPIO0), (ADC1_CH1, GPIO1),
4196 (ADC1_CH2, GPIO2), (ADC1_CH3, GPIO3), (ADC1_CH4, GPIO4)));
4197 _for_each_inner_analog_function!((ADCn_CHm((ADC1_CH0, ADCn_CHm, 1, 0), GPIO0),
4198 ((ADC1_CH1, ADCn_CHm, 1, 1), GPIO1), ((ADC1_CH2, ADCn_CHm, 1, 2), GPIO2),
4199 ((ADC1_CH3, ADCn_CHm, 1, 3), GPIO3), ((ADC1_CH4, ADCn_CHm, 1, 4), GPIO4)));
4200 };
4201}
4202#[macro_export]
4240#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4241macro_rules! for_each_lp_function {
4242 ($($pattern:tt => $code:tt;)*) => {
4243 macro_rules! _for_each_inner_lp_function { $(($pattern) => $code;)* ($other : tt)
4244 => {} } _for_each_inner_lp_function!((LP_GPIO0, GPIO0, _0));
4245 _for_each_inner_lp_function!((LP_GPIO1, GPIO1, _0));
4246 _for_each_inner_lp_function!((LP_GPIO2, GPIO2, _0));
4247 _for_each_inner_lp_function!((LP_GPIO3, GPIO3, _0));
4248 _for_each_inner_lp_function!((LP_GPIO4, GPIO4, _0));
4249 _for_each_inner_lp_function!((LP_GPIO5, GPIO5, _0));
4250 _for_each_inner_lp_function!(((LP_GPIO0, LP_GPIOn, 0), GPIO0, _0, () ()));
4251 _for_each_inner_lp_function!(((LP_GPIO1, LP_GPIOn, 1), GPIO1, _0, () ()));
4252 _for_each_inner_lp_function!(((LP_GPIO2, LP_GPIOn, 2), GPIO2, _0, () ()));
4253 _for_each_inner_lp_function!(((LP_GPIO3, LP_GPIOn, 3), GPIO3, _0, () ()));
4254 _for_each_inner_lp_function!(((LP_GPIO4, LP_GPIOn, 4), GPIO4, _0, () ()));
4255 _for_each_inner_lp_function!(((LP_GPIO5, LP_GPIOn, 5), GPIO5, _0, () ()));
4256 _for_each_inner_lp_function!((all(LP_GPIO0, GPIO0, _0), (LP_GPIO1, GPIO1, _0),
4257 (LP_GPIO2, GPIO2, _0), (LP_GPIO3, GPIO3, _0), (LP_GPIO4, GPIO4, _0), (LP_GPIO5,
4258 GPIO5, _0))); _for_each_inner_lp_function!((LP_GPIOn((LP_GPIO0, LP_GPIOn, 0),
4259 GPIO0, _0, () ()), ((LP_GPIO1, LP_GPIOn, 1), GPIO1, _0, () ()), ((LP_GPIO2,
4260 LP_GPIOn, 2), GPIO2, _0, () ()), ((LP_GPIO3, LP_GPIOn, 3), GPIO3, _0, () ()),
4261 ((LP_GPIO4, LP_GPIOn, 4), GPIO4, _0, () ()), ((LP_GPIO5, LP_GPIOn, 5), GPIO5, _0,
4262 () ())));
4263 };
4264}
4265#[macro_export]
4296#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4297macro_rules! for_each_iomux_function {
4298 ($($pattern:tt => $code:tt;)*) => {
4299 macro_rules! _for_each_inner_iomux_function { $(($pattern) => $code;)* ($other :
4300 tt) => {} } _for_each_inner_iomux_function!((FSPIQ, GPIO2, _2));
4301 _for_each_inner_iomux_function!((MTMS, GPIO4, _0));
4302 _for_each_inner_iomux_function!((FSPIHD, GPIO4, _2));
4303 _for_each_inner_iomux_function!((MTDI, GPIO5, _0));
4304 _for_each_inner_iomux_function!((FSPIWP, GPIO5, _2));
4305 _for_each_inner_iomux_function!((MTCK, GPIO6, _0));
4306 _for_each_inner_iomux_function!((FSPICLK, GPIO6, _2));
4307 _for_each_inner_iomux_function!((MTDO, GPIO7, _0));
4308 _for_each_inner_iomux_function!((FSPID, GPIO7, _2));
4309 _for_each_inner_iomux_function!((FSPICS0, GPIO10, _2));
4310 _for_each_inner_iomux_function!((SPIHD, GPIO11, _0));
4311 _for_each_inner_iomux_function!((SPIHD, GPIO12, _0));
4312 _for_each_inner_iomux_function!((SPIWP, GPIO13, _0));
4313 _for_each_inner_iomux_function!((SPICS0, GPIO14, _0));
4314 _for_each_inner_iomux_function!((SPICLK, GPIO15, _0));
4315 _for_each_inner_iomux_function!((SPID, GPIO16, _0));
4316 _for_each_inner_iomux_function!((SPIQ, GPIO17, _0));
4317 _for_each_inner_iomux_function!((U0RXD, GPIO19, _0));
4318 _for_each_inner_iomux_function!((U0TXD, GPIO20, _0));
4319 _for_each_inner_iomux_function!(((FSPICS0, FSPICSn, 0), GPIO10, _2));
4320 _for_each_inner_iomux_function!(((SPICS0, SPICSn, 0), GPIO14, _0));
4321 _for_each_inner_iomux_function!((all(FSPIQ, GPIO2, _2), (MTMS, GPIO4, _0),
4322 (FSPIHD, GPIO4, _2), (MTDI, GPIO5, _0), (FSPIWP, GPIO5, _2), (MTCK, GPIO6, _0),
4323 (FSPICLK, GPIO6, _2), (MTDO, GPIO7, _0), (FSPID, GPIO7, _2), (FSPICS0, GPIO10,
4324 _2), (SPIHD, GPIO11, _0), (SPIHD, GPIO12, _0), (SPIWP, GPIO13, _0), (SPICS0,
4325 GPIO14, _0), (SPICLK, GPIO15, _0), (SPID, GPIO16, _0), (SPIQ, GPIO17, _0),
4326 (U0RXD, GPIO19, _0), (U0TXD, GPIO20, _0)));
4327 _for_each_inner_iomux_function!((FSPICSn((FSPICS0, FSPICSn, 0), GPIO10, _2)));
4328 _for_each_inner_iomux_function!((SPICSn((SPICS0, SPICSn, 0), GPIO14, _0)));
4329 };
4330}
4331#[macro_export]
4348#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4349macro_rules! gpio_for_signal {
4350 (ADC1_CH0 $(, $_fallback:literal)?) => {
4351 "GPIO0"
4352 };
4353 (LP_GPIO0 $(, $_fallback:literal)?) => {
4354 "GPIO0"
4355 };
4356 (ADC1_CH1 $(, $_fallback:literal)?) => {
4357 "GPIO1"
4358 };
4359 (LP_GPIO1 $(, $_fallback:literal)?) => {
4360 "GPIO1"
4361 };
4362 (FSPIQ $(, $_fallback:literal)?) => {
4363 "GPIO2"
4364 };
4365 (ADC1_CH2 $(, $_fallback:literal)?) => {
4366 "GPIO2"
4367 };
4368 (LP_GPIO2 $(, $_fallback:literal)?) => {
4369 "GPIO2"
4370 };
4371 (ADC1_CH3 $(, $_fallback:literal)?) => {
4372 "GPIO3"
4373 };
4374 (LP_GPIO3 $(, $_fallback:literal)?) => {
4375 "GPIO3"
4376 };
4377 (MTMS $(, $_fallback:literal)?) => {
4378 "GPIO4"
4379 };
4380 (FSPIHD $(, $_fallback:literal)?) => {
4381 "GPIO4"
4382 };
4383 (ADC1_CH4 $(, $_fallback:literal)?) => {
4384 "GPIO4"
4385 };
4386 (LP_GPIO4 $(, $_fallback:literal)?) => {
4387 "GPIO4"
4388 };
4389 (MTDI $(, $_fallback:literal)?) => {
4390 "GPIO5"
4391 };
4392 (FSPIWP $(, $_fallback:literal)?) => {
4393 "GPIO5"
4394 };
4395 (LP_GPIO5 $(, $_fallback:literal)?) => {
4396 "GPIO5"
4397 };
4398 (MTCK $(, $_fallback:literal)?) => {
4399 "GPIO6"
4400 };
4401 (FSPICLK $(, $_fallback:literal)?) => {
4402 "GPIO6"
4403 };
4404 (MTDO $(, $_fallback:literal)?) => {
4405 "GPIO7"
4406 };
4407 (FSPID $(, $_fallback:literal)?) => {
4408 "GPIO7"
4409 };
4410 (FSPICS0 $(, $_fallback:literal)?) => {
4411 "GPIO10"
4412 };
4413 (SPIHD $(, $_fallback:literal)?) => {
4414 "GPIO11"
4415 };
4416 (SPIWP $(, $_fallback:literal)?) => {
4417 "GPIO13"
4418 };
4419 (SPICS0 $(, $_fallback:literal)?) => {
4420 "GPIO14"
4421 };
4422 (SPICLK $(, $_fallback:literal)?) => {
4423 "GPIO15"
4424 };
4425 (SPID $(, $_fallback:literal)?) => {
4426 "GPIO16"
4427 };
4428 (SPIQ $(, $_fallback:literal)?) => {
4429 "GPIO17"
4430 };
4431 (U0RXD $(, $_fallback:literal)?) => {
4432 "GPIO19"
4433 };
4434 (U0TXD $(, $_fallback:literal)?) => {
4435 "GPIO20"
4436 };
4437 ($_signal:ident, $fallback:literal) => {
4438 $fallback
4439 };
4440}
4441#[macro_export]
4445#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4446macro_rules! define_io_mux_signals {
4447 () => {
4448 #[allow(non_camel_case_types, clippy::upper_case_acronyms)]
4449 #[derive(Debug, PartialEq, Copy, Clone)]
4450 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
4451 #[doc(hidden)]
4452 pub enum InputSignal {
4453 SPIQ = 0,
4454 SPID = 1,
4455 SPIHD = 2,
4456 SPIWP = 3,
4457 U0RXD = 6,
4458 U0CTS = 7,
4459 U0DSR = 8,
4460 U1RXD = 9,
4461 U1CTS = 10,
4462 U1DSR = 11,
4463 CPU_GPIO_0 = 28,
4464 CPU_GPIO_1 = 29,
4465 CPU_GPIO_2 = 30,
4466 CPU_GPIO_3 = 31,
4467 CPU_GPIO_4 = 32,
4468 CPU_GPIO_5 = 33,
4469 CPU_GPIO_6 = 34,
4470 CPU_GPIO_7 = 35,
4471 EXT_ADC_START = 45,
4472 RMT_SIG_0 = 51,
4473 RMT_SIG_1 = 52,
4474 I2CEXT0_SCL = 53,
4475 I2CEXT0_SDA = 54,
4476 FSPICLK = 63,
4477 FSPIQ = 64,
4478 FSPID = 65,
4479 FSPIHD = 66,
4480 FSPIWP = 67,
4481 FSPICS0 = 68,
4482 SIG_FUNC_97 = 97,
4483 SIG_FUNC_98 = 98,
4484 SIG_FUNC_99 = 99,
4485 SIG_FUNC_100 = 100,
4486 MTCK,
4487 MTMS,
4488 MTDI,
4489 }
4490 #[allow(non_camel_case_types, clippy::upper_case_acronyms)]
4491 #[derive(Debug, PartialEq, Copy, Clone)]
4492 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
4493 #[doc(hidden)]
4494 pub enum OutputSignal {
4495 SPIQ = 0,
4496 SPID = 1,
4497 SPIHD = 2,
4498 SPIWP = 3,
4499 SPICLK = 4,
4500 SPICS0 = 5,
4501 U0TXD = 6,
4502 U0RTS = 7,
4503 U0DTR = 8,
4504 U1TXD = 9,
4505 U1RTS = 10,
4506 U1DTR = 11,
4507 SPIQ_MONITOR = 15,
4508 SPID_MONITOR = 16,
4509 SPIHD_MONITOR = 17,
4510 SPIWP_MONITOR = 18,
4511 SPICS1 = 19,
4512 CPU_GPIO_0 = 28,
4513 CPU_GPIO_1 = 29,
4514 CPU_GPIO_2 = 30,
4515 CPU_GPIO_3 = 31,
4516 CPU_GPIO_4 = 32,
4517 CPU_GPIO_5 = 33,
4518 CPU_GPIO_6 = 34,
4519 CPU_GPIO_7 = 35,
4520 LEDC_LS_SIG0 = 45,
4521 LEDC_LS_SIG1 = 46,
4522 LEDC_LS_SIG2 = 47,
4523 LEDC_LS_SIG3 = 48,
4524 LEDC_LS_SIG4 = 49,
4525 LEDC_LS_SIG5 = 50,
4526 RMT_SIG_0 = 51,
4527 RMT_SIG_1 = 52,
4528 I2CEXT0_SCL = 53,
4529 I2CEXT0_SDA = 54,
4530 FSPICLK = 63,
4531 FSPIQ = 64,
4532 FSPID = 65,
4533 FSPIHD = 66,
4534 FSPIWP = 67,
4535 FSPICS0 = 68,
4536 FSPICS1 = 69,
4537 FSPICS3 = 70,
4538 FSPICS2 = 71,
4539 FSPICS4 = 72,
4540 FSPICS5 = 73,
4541 ANT_SEL0 = 89,
4542 ANT_SEL1 = 90,
4543 ANT_SEL2 = 91,
4544 ANT_SEL3 = 92,
4545 ANT_SEL4 = 93,
4546 ANT_SEL5 = 94,
4547 ANT_SEL6 = 95,
4548 ANT_SEL7 = 96,
4549 SIG_FUNC_97 = 97,
4550 SIG_FUNC_98 = 98,
4551 SIG_FUNC_99 = 99,
4552 SIG_FUNC_100 = 100,
4553 CLK_OUT1 = 123,
4554 CLK_OUT2 = 124,
4555 CLK_OUT3 = 125,
4556 GPIO = 128,
4557 MTDO,
4558 }
4559 };
4560}
4561#[macro_export]
4568#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4569macro_rules! define_lp_functions {
4570 () => {
4571 #[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
4576 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
4577 #[doc(hidden)]
4578 pub enum LpFunction {
4579 _0 = 0,
4581 }
4582 impl LpFunction {
4583 pub const LP_GPIO: Self = Self::_0;
4585 }
4586 };
4587}
4588#[macro_export]
4601#[expect(clippy::crate_in_macro_def)]
4602#[cfg_attr(docsrs, doc(cfg(feature = "_device-selected")))]
4603macro_rules! define_io_mux_reg {
4604 () => {
4605 pub(crate) fn io_mux_reg(gpio_num: u8) -> &'static crate::pac::io_mux::GPIO {
4606 crate::peripherals::IO_MUX::regs().gpio(gpio_num as usize)
4607 }
4608 };
4609}