|
1 |
| -use crate::stm32::{HRTIM_COMMON, RCC}; |
| 1 | +use core::marker::PhantomData; |
2 | 2 |
|
3 |
| -use super::HrControltExt; |
| 3 | +use crate::{ |
| 4 | + hrtim::fault::{ |
| 5 | + FaultInput1, FaultInput2, FaultInput3, FaultInput4, FaultInput5, FaultInput6, FltMonitor1, |
| 6 | + FltMonitor2, FltMonitor3, FltMonitor4, FltMonitor5, FltMonitor6, FltMonitorSys, |
| 7 | + }, |
| 8 | + rcc::{Enable, Rcc, Reset}, |
| 9 | + stm32::{HRTIM_COMMON, RCC}, |
| 10 | +}; |
| 11 | + |
| 12 | +use super::fault::FaultInputs; |
4 | 13 |
|
5 | 14 | pub trait HrControltExt {
|
6 | 15 | fn hr_control(self, _rcc: &mut Rcc) -> HrTimOngoingCalibration;
|
@@ -84,7 +93,7 @@ pub struct HrTimOngoingCalibration {
|
84 | 93 |
|
85 | 94 | impl HrTimOngoingCalibration {
|
86 | 95 | /// SAFETY: Calibration needs to be done before calling this
|
87 |
| - unsafe fn init(self) -> (HrPwmControl, FaultInputs) { |
| 96 | + unsafe fn init(self) { |
88 | 97 | use Adc13Trigger as Ad13T;
|
89 | 98 | use Adc24Trigger as Ad24T;
|
90 | 99 |
|
@@ -410,37 +419,18 @@ impl HrTimOngoingCalibration {
|
410 | 419 |
|
411 | 420 | // TODO: Adc trigger 5-10
|
412 | 421 | }
|
413 |
| - |
414 |
| - ( |
415 |
| - HrPwmControl { |
416 |
| - _x: PhantomData, |
417 |
| - fault_sys: FltMonitorSys { _x: PhantomData }, |
418 |
| - fault_1: FltMonitor1 { _x: PhantomData }, |
419 |
| - fault_2: FltMonitor2 { _x: PhantomData }, |
420 |
| - fault_3: FltMonitor3 { _x: PhantomData }, |
421 |
| - fault_4: FltMonitor4 { _x: PhantomData }, |
422 |
| - fault_5: FltMonitor5 { _x: PhantomData }, |
423 |
| - fault_6: FltMonitor6 { _x: PhantomData }, |
424 |
| - }, |
425 |
| - FaultInputs { |
426 |
| - fault_input1: FaultInput1 { _x: PhantomData }, |
427 |
| - fault_input2: FaultInput2 { _x: PhantomData }, |
428 |
| - fault_input3: FaultInput3 { _x: PhantomData }, |
429 |
| - fault_input4: FaultInput4 { _x: PhantomData }, |
430 |
| - fault_input5: FaultInput5 { _x: PhantomData }, |
431 |
| - fault_input6: FaultInput6 { _x: PhantomData }, |
432 |
| - }, |
433 |
| - ) |
434 | 422 | }
|
435 | 423 |
|
436 |
| - pub fn wait_for_calibration(self) -> (HrPwmControl, FaultInputs) { |
| 424 | + pub fn wait_for_calibration(self) -> HrTimCalibrated { |
437 | 425 | let common = unsafe { &*HRTIM_COMMON::ptr() };
|
438 | 426 | while common.isr.read().dllrdy().bit_is_clear() {
|
439 | 427 | // Wait until ready
|
440 | 428 | }
|
441 | 429 |
|
442 | 430 | // Calibration is now done, it is safe to continue
|
443 |
| - unsafe { self.init() } |
| 431 | + unsafe { self.init() }; |
| 432 | + |
| 433 | + HrTimCalibrated { _x: PhantomData } |
444 | 434 | }
|
445 | 435 |
|
446 | 436 | pub fn enable_adc_trigger1_source(mut self, trigger: Adc13Trigger) -> Self {
|
@@ -526,6 +516,38 @@ impl HrTimOngoingCalibration {
|
526 | 516 | // TODO: Adc trigger 5-10
|
527 | 517 | }
|
528 | 518 |
|
| 519 | +/// This object may be used for things that needs to be done before any timers have been started but after the calibration has been completed. Its existence is proof that no timers have started. |
| 520 | +/// |
| 521 | +/// Once done with setup, use the `constrain` to get a `HrPwmControl` which can be used to start the timers. |
| 522 | +pub struct HrTimCalibrated { |
| 523 | + _x: PhantomData<()>, |
| 524 | +} |
| 525 | + |
| 526 | +impl HrTimCalibrated { |
| 527 | + pub fn constrain(self) -> (HrPwmControl, FaultInputs) { |
| 528 | + ( |
| 529 | + HrPwmControl { |
| 530 | + _x: PhantomData, |
| 531 | + fault_sys: FltMonitorSys { _x: PhantomData }, |
| 532 | + fault_1: FltMonitor1 { _x: PhantomData }, |
| 533 | + fault_2: FltMonitor2 { _x: PhantomData }, |
| 534 | + fault_3: FltMonitor3 { _x: PhantomData }, |
| 535 | + fault_4: FltMonitor4 { _x: PhantomData }, |
| 536 | + fault_5: FltMonitor5 { _x: PhantomData }, |
| 537 | + fault_6: FltMonitor6 { _x: PhantomData }, |
| 538 | + }, |
| 539 | + FaultInputs { |
| 540 | + fault_input1: FaultInput1 { _x: PhantomData }, |
| 541 | + fault_input2: FaultInput2 { _x: PhantomData }, |
| 542 | + fault_input3: FaultInput3 { _x: PhantomData }, |
| 543 | + fault_input4: FaultInput4 { _x: PhantomData }, |
| 544 | + fault_input5: FaultInput5 { _x: PhantomData }, |
| 545 | + fault_input6: FaultInput6 { _x: PhantomData }, |
| 546 | + }, |
| 547 | + ) |
| 548 | + } |
| 549 | +} |
| 550 | + |
529 | 551 | pub struct HrPwmControl {
|
530 | 552 | _x: PhantomData<()>,
|
531 | 553 |
|
|
0 commit comments