the annoying macro:
from —— embassy-stm32/src/time_driver.rs
Q1: why there are duplicate code?
to be written, still confused.
Q2: I want to know how this macro decoded
generate by embassy-stm32:
S2:
first, look at:
__foreach_interrupt_inner!((TIM1,timer,TIM_ADV,CC,TIM1_CC));
according to :
and you need to be aware that the macro above is inside a macro. So you must notice
$(($pat) => $code;)*
. the outer$(…)
comes from:so it will be expanded depending on the
$($pat:tt => $code:tt;)*
match. for example, we will see :
will be used to replace the pattern in
__foreach_interrupt_inner
as(the middle state, and I reserve the cfg):and with this
__foreach_interrupt_inner
we can further explain the rest part of foreach_interrupt
turns into(suppose we enable feature: time_driver_tim1):
So the key is : we produce a huge
__foreach_interrupt_inner
macro by the code in embassy-stm32/src/time_driver.rs, and for the board’s possible interrupt: for example:(TIM3,timer,TIM_GP16,CC,TIM3)
we can see it will match the __foreach_interrupt_inner
macro and use the corresponding interrupt handler to run. For our example, this is: DRIVER.on_interrupt()