Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/flash' into flash
Browse files Browse the repository at this point in the history
  • Loading branch information
JanekGraff committed Dec 12, 2023
2 parents baed308 + 1fad8f5 commit 41c761d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Provide ability to reset timer UIF interrupt flag
- PWM complementary output capability for TIM1 with new example to demonstrate
- Implement interface for reading and writing to the internal flash memory and an example for demonstration.
- PWM output on complementary channels only for single channel timers (TIM16 + TIM17)

### Fixed

Expand Down
34 changes: 33 additions & 1 deletion src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ pins_impl!(
(P2), (PinC2), (C2);
(P3), (PinC3), (C3);
(P4), (PinC4), (C4);
(P1N), (PinC1N), (C1N);
(P2N), (PinC2N), (C2N);
(P3N), (PinC3N), (C3N);
);

impl<TIM, P1: PinC1<TIM>, P2: PinC1<TIM>> PinC1<TIM> for (P1, P2) {}
Expand Down Expand Up @@ -803,7 +806,7 @@ macro_rules! pwm_1_channel_with_complementary_outputs {
rcc.regs.$apbrstr.modify(|_, w| w.$timXrst().set_bit());
rcc.regs.$apbrstr.modify(|_, w| w.$timXrst().clear_bit());

if PINS::C1 {
if PINS::C1 || PINS::C1N {
tim.ccmr1_output().modify(|_, w| w.oc1pe().set_bit().oc1m().bits(6));
}

Expand Down Expand Up @@ -868,6 +871,35 @@ macro_rules! pwm_1_channel_with_complementary_outputs {
unsafe { (*$TIMX::ptr()).ccr1.write(|w| w.ccr().bits(duty.into())) }
}
}

impl hal::PwmPin for PwmChannels<$TIMX, C1N> {
type Duty = u16;

//NOTE(unsafe) atomic write with no side effects
fn disable(&mut self) {
unsafe { (*($TIMX::ptr())).ccer.modify(|_, w| w.cc1ne().clear_bit()) };
}

//NOTE(unsafe) atomic write with no side effects
fn enable(&mut self) {
unsafe { (*($TIMX::ptr())).ccer.modify(|_, w| w.cc1ne().set_bit()) };
}

//NOTE(unsafe) atomic read with no side effects
fn get_duty(&self) -> u16 {
unsafe { (*$TIMX::ptr()).ccr1.read().ccr().bits() as u16 }
}

//NOTE(unsafe) atomic read with no side effects
fn get_max_duty(&self) -> u16 {
unsafe { (*$TIMX::ptr()).arr.read().arr().bits() as u16 }
}

//NOTE(unsafe) atomic write with no side effects
fn set_duty(&mut self, duty: u16) {
unsafe { (*$TIMX::ptr()).ccr1.write(|w| w.ccr().bits(duty.into())) }
}
}
)+
};
}
Expand Down
1 change: 1 addition & 0 deletions src/timers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ channel_impl!(

TIM16, PinC1, PA6, Alternate<AF5>;
TIM16, PinC1, PB8, Alternate<AF2>;
TIM16, PinC1N, PB6, Alternate<AF2>;

TIM17, PinC1, PA7, Alternate<AF5>;
TIM17, PinC1, PB9, Alternate<AF2>;
Expand Down

0 comments on commit 41c761d

Please sign in to comment.