Skip to content

Commit

Permalink
Merge pull request #55 from nickray/v0.7.0-pac
Browse files Browse the repository at this point in the history
Use 0.7.0 PAC and fix PWM
  • Loading branch information
MabezDev authored May 8, 2019
2 parents 82fd75b + 86d3a65 commit c23fd78
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ edition = "2018"
[dependencies]
cortex-m = "0.5.8"
nb = "0.1.1"
stm32l4 = "0.6.0"
stm32l4 = "0.7.0"
as-slice = "0.1"

[dependencies.cast]
Expand Down
26 changes: 25 additions & 1 deletion src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ macro_rules! gpio {
use crate::rcc::AHB2;
use super::{
Alternate,
AF1, AF4, AF5, AF6, AF7, AF8, AF9,
AF1, AF4, AF5, AF6, AF7, AF8, AF9, AF10,
Floating, GpioExt, Input, OpenDrain, Output,
PullDown, PullUp, PushPull, State,
};
Expand Down Expand Up @@ -402,6 +402,30 @@ macro_rules! gpio {
$PXi { _mode: PhantomData }
}

/// Configures the pin to serve as alternate function 10 (AF10)
pub fn into_af10(
self,
moder: &mut MODER,
afr: &mut $AFR,
) -> $PXi<Alternate<AF10, MODE>> {
let offset = 2 * $i;

// alternate function mode
let mode = 0b10;
moder.moder().modify(|r, w| unsafe {
w.bits((r.bits() & !(0b11 << offset)) | (mode << offset))
});

let af = 10;
let offset = 4 * ($i % 8);

afr.afr().modify(|r, w| unsafe {
w.bits((r.bits() & !(0b1111 << offset)) | (af << offset))
});

$PXi { _mode: PhantomData }
}

/// Configures the pin to operate as a floating input pin
pub fn into_floating_input(
self,
Expand Down
16 changes: 8 additions & 8 deletions src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,15 @@ macro_rules! hal {
}

fn get_duty(&self) -> Self::Duty {
unsafe { (*$TIMX::ptr()).ccr1.read().ccr1().bits() }
unsafe { (*$TIMX::ptr()).ccr1.read().ccr().bits() }
}

fn get_max_duty(&self) -> Self::Duty {
unsafe { (*$TIMX::ptr()).arr.read().arr().bits() }
}

fn set_duty(&mut self, duty: Self::Duty) {
unsafe { (*$TIMX::ptr()).ccr1.write(|w| w.ccr1().bits(duty)) }
unsafe { (*$TIMX::ptr()).ccr1.write(|w| w.ccr().bits(duty)) }
}
}

Expand All @@ -216,15 +216,15 @@ macro_rules! hal {
}

fn get_duty(&self) -> Self::Duty {
unsafe { (*$TIMX::ptr()).ccr2.read().ccr2().bits() }
unsafe { (*$TIMX::ptr()).ccr2.read().ccr().bits() }
}

fn get_max_duty(&self) -> Self::Duty {
unsafe { (*$TIMX::ptr()).arr.read().arr().bits() }
}

fn set_duty(&mut self, duty: Self::Duty) {
unsafe { (*$TIMX::ptr()).ccr2.write(|w| w.ccr2().bits(duty)) }
unsafe { (*$TIMX::ptr()).ccr2.write(|w| w.ccr().bits(duty)) }
}
}

Expand All @@ -240,15 +240,15 @@ macro_rules! hal {
}

fn get_duty(&self) -> Self::Duty {
unsafe { (*$TIMX::ptr()).ccr3.read().ccr3().bits() }
unsafe { (*$TIMX::ptr()).ccr3.read().ccr().bits() }
}

fn get_max_duty(&self) -> Self::Duty {
unsafe { (*$TIMX::ptr()).arr.read().arr().bits() }
}

fn set_duty(&mut self, duty: Self::Duty) {
unsafe { (*$TIMX::ptr()).ccr3.write(|w| w.ccr3().bits(duty)) }
unsafe { (*$TIMX::ptr()).ccr3.write(|w| w.ccr().bits(duty)) }
}
}

Expand All @@ -264,15 +264,15 @@ macro_rules! hal {
}

fn get_duty(&self) -> Self::Duty {
unsafe { (*$TIMX::ptr()).ccr4.read().ccr4().bits() }
unsafe { (*$TIMX::ptr()).ccr4.read().ccr().bits() }
}

fn get_max_duty(&self) -> Self::Duty {
unsafe { (*$TIMX::ptr()).arr.read().arr().bits() }
}

fn set_duty(&mut self, duty: Self::Duty) {
unsafe { (*$TIMX::ptr()).ccr4.write(|w| w.ccr4().bits(duty)) }
unsafe { (*$TIMX::ptr()).ccr4.write(|w| w.ccr().bits(duty)) }
}
}
)+
Expand Down

0 comments on commit c23fd78

Please sign in to comment.