-
Notifications
You must be signed in to change notification settings - Fork 935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update embassy-stm32 after stm32-metapac timer_v2 #2499
Conversation
8acc9a4
to
a0b9b45
Compare
a0b9b45
to
aa3e5cc
Compare
Update 2024/Feb/2: restore original public API of timer, remove macro inside "sealed". This could make incorrect Timer-Channel mapping delay to a runtime panic, but more easier to write a high-level driver. Update 2024/Feb/1: Try use macro to add common method inside each "sealed" traits. TIM inheritance change
But this require user use ugly seal::SomeTimerInstance::some_method(self.inner.deref(), ...) or seal::SomeTimerInstance::some_method(self.inner.deref_mut(), ...) to resolve method name collision. First, let me show my appreciate to anyone review this PR! Thank you for your time and effort! I'm not sure what to do with this situation: Main branch has single Here is the TIM inheritance
Strickly speaking, 1CH / 2CH aren't "2CH is 1CH with one more channel", neither "1CH and 2CH are GP16 without some channels". Beside channel-related count, there are some other fields and/or registers addition. So we can't simply merge them into one TIM. My current implementation is make " - pub trait CaptureCompare16bitInstance: GeneralPurpose16bitInstance {
+ pub trait CaptureCompare16bitInstance: GeneralPurpose1ChannelInstance { But this cause Pins other than In my opinion, we will need to copy every method that has a - pin_trait!(Channel1Pin, CaptureCompare16bitInstance);
+ pin_trait!(Channel1Pin, GeneralPurpose1ChannelInstance);
- pin_trait!(Channel2Pin, CaptureCompare16bitInstance);
+ pin_trait!(Channel1Pin, GeneralPurpose2ChannelInstance);
... But this requires a lot of "just modify regs_xxx() and copy paste others" in sealed traits, and could render this piece of code sort of "unmaintainable".(For current impl, "simple modify and copy paste" is true. But we cannot assume there won't be someone make use of other additional fields/registers in future.) And the same thing could also apply between 1CH_CMP/2CH_CMP/ADV and I got no idea on this situation. Any ideas are welcomed! Thanks in advance! |
0245421
to
751185a
Compare
STM32L0 is special, External Trigger is on TIM_2CH |
dac1038
to
68f24a2
Compare
7ec042d
to
9847770
Compare
2c6520a
to
566b493
Compare
1607155
to
9e3608c
Compare
86b4578
to
10345ac
Compare
bender run |
It seems ok on HIL? |
10345ac
to
8fd803a
Compare
thank you! 🚀 |
bender run |
PR embassy-rs#2499 implemented timer hierarchy, but removed enable_outputs() from trait CaptureCompare16bitInstance and from SimplePwm. This functions is required for advanced timers to set bit BDTR.MOE and to enable the output signal.
PR embassy-rs#2499 implemented timer hierarchy, but removed enable_outputs() from trait CaptureCompare16bitInstance and from SimplePwm. This functions is required for advanced timers to set bit BDTR.MOE and to enable the output signal.
Summary
BasicInstance
CaptureComapre16bitInstance
CaptureComapre32bitInstance
ComplementaryCaptureCompare16bitInstace
GeneralPurpose16bitInstance
,GeneralPurpose32bitInstance
andAdvancedControlInstance
, since we merge different kinds of PAC TIMs, they are not accurate under new PAC.pin_trait!
has been redesign to match TimerInstance more precise.Such that this PR didn't do much modify to non-sealed trait.
Since PAC has 10 different blocks, and HAL only got 4 traits. The "sealed" part is a little bit thicker than original.
All methods other than Channel-count related is put into "smallest" sealed::TimerInstance
sealed::Core
is about PSC, CNT, ARR and Interruptsealed::BasicNoCr2
add extra methods to enable DMA. This one is for Timer other than 1CH and 2CH. 1CH and 2CH don't have DMA request.sealed::GeneralPurpose1ChannelInstance
(1CH of PAC) has all methods that all Channel shared.sealed::GeneralPurpose1ChannelComplementaryInstance
(1CH_CMP of PAC) has all methods that all Complementary Channel shared.Methods for Channel count related is put into "kind-largest" sealed::TimerInstance
sealed::GeneralPurpose16bitInstance
has all Capture/Compare Channel-count related methodssealed::AdvancedControlInstance
has all Complementary Capture/Compare Channel-count related methodsTo merge 10 TIM of PAC into 4 TimerInstance of HAL:
All merges are done by kinda-unsafe-promotion
sealed::GP16Instance
"sealed::ADVInstance
"mostly just read/write to empty fields of same register.
This PR is based on my fork of stm32-data-generated for embassy CI pick timer_v2 PAC
DO NOT MERGE BEFORE
MERGED.
NEED A
AFTER embassy-rs/stm32-data#364 MERGED, TO REMOVE MY FORK FROM CODEBASE
This PR should pass CI, but there still need review for functionality check.
Especially forCaptureCompare16bitInstance
andComplementaryCaptureCompare16bitInstance
trait design.