aboutsummaryrefslogtreecommitdiffstats
path: root/sw/picardy/src/cw.rs
diff options
context:
space:
mode:
Diffstat (limited to 'sw/picardy/src/cw.rs')
-rw-r--r--sw/picardy/src/cw.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/sw/picardy/src/cw.rs b/sw/picardy/src/cw.rs
new file mode 100644
index 0000000..ce99e39
--- /dev/null
+++ b/sw/picardy/src/cw.rs
@@ -0,0 +1,35 @@
+//! CW output using PWM on PA8, TIM1 CH1
+
+use stm32f1xx_hal::{
+ prelude::*,
+ timer,
+ pac::TIM1,
+ gpio::gpioa::*,
+ gpio::{Alternate, PushPull},
+ afio::MAPR,
+ pwm,
+};
+
+pub struct CWPWM {
+ channel : pwm::PwmChannel<TIM1, pwm::C1>,
+}
+
+impl CWPWM {
+ pub fn new(pa8: PA8<Alternate<PushPull>>, tim1: timer::Timer<TIM1>, mapr: &mut MAPR) -> Self {
+ let pwm = tim1.pwm(pa8, mapr, 400.hz());
+ let mut channel = pwm.split();
+ channel.enable();
+ channel.set_duty(0);
+ CWPWM { channel }
+ }
+
+ pub fn on(&mut self) {
+ let max = self.channel.get_max_duty();
+ self.channel.set_duty(max / 2);
+ }
+
+ pub fn off(&mut self) {
+ self.channel.set_duty(0);
+ }
+}
+