Skip to content
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

Fully Enforced Cordic #143

Closed
wants to merge 15 commits into from
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
- stm32g474
- stm32g483
- stm32g484
#- stm32g491 # Does not seem ready yet
#- stm32g4a1 # Does not seem ready yet
- stm32g491 # Does not seem ready yet
- stm32g4a1 # Does not seem ready yet
features:
- log-rtt,defmt
# TODO: -log-rtt # log-rtt without defmt, more combos?
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ version = "0.0.2"

[dependencies]
nb = "0.1.1"
stm32g4 = "0.15.1"
#stm32g4 = { git = "https://github.com/stm32-rs/stm32-rs-nightlies" } #"0.15.1"
stm32g4 = { version = "0.17.0", package = "stm32g4-staging" }
paste = "1.0"
bitflags = "1.2"
vcell = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion examples/flash_with_rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ mod app {

unsafe {
let mut flash = &(*stm32g4xx_hal::stm32::FLASH::ptr());
flash.acr.modify(|_, w| {
flash.acr().modify(|_, w| {
w.latency().bits(0b1000) // 8 wait states
});
}
Expand Down
233 changes: 126 additions & 107 deletions src/adc.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ where
{
Self::enable(&rcc.rb);

if rcc.rb.ccipr.read().fdcansel().is_hse() {
if rcc.rb.ccipr().read().fdcansel().is_hse() {
// Select P clock as FDCAN clock source
rcc.rb.ccipr.modify(|_, w| {
rcc.rb.ccipr().modify(|_, w| {
// This is sound, as `FdCanClockSource` only contains valid values for this field.
unsafe {
w.fdcansel().bits(FdCanClockSource::PCLK as u8);
Expand Down
36 changes: 18 additions & 18 deletions src/comparator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,26 @@ impl EnabledState for Enabled {}
impl EnabledState for Locked {}

macro_rules! impl_comp {
($($t:ident: $reg_t:ident, $reg:ident,)+) => {$(
($($t:ident: $reg:ident,)+) => {$(
pub struct $t {
_rb: PhantomData<()>,
}

impl $t {
pub fn csr(&self) -> &$crate::stm32::comp::$reg_t {
pub fn csr(&self) -> &$crate::stm32::comp::CCSR {
// SAFETY: The COMP1 type is only constructed with logical ownership of
// these registers.
&unsafe { &*COMP::ptr() }.$reg
&unsafe { &*COMP::ptr() }.$reg()
}
}
)+};
}

impl_comp! {
COMP1: C1CSR, c1csr,
COMP2: C2CSR, c2csr,
COMP3: C3CSR, c3csr,
COMP4: C4CSR, c4csr,
COMP1: c1csr,
COMP2: c2csr,
COMP3: c3csr,
COMP4: c4csr,
}
#[cfg(any(
feature = "stm32g473",
Expand All @@ -83,9 +83,9 @@ impl_comp! {
feature = "stm32g484"
))]
impl_comp! {
COMP5: C5CSR, c5csr,
COMP6: C6CSR, c6csr,
COMP7: C7CSR, c7csr,
COMP5: c5csr,
COMP6: c6csr,
COMP7: c7csr,
}

// TODO: Split COMP in PAC
Expand Down Expand Up @@ -162,13 +162,13 @@ macro_rules! positive_input_pin {
($COMP:ident, $pin_0:ident, $pin_1:ident) => {
impl PositiveInput<$COMP> for &$pin_0<Analog> {
fn setup(&self, comp: &$COMP) {
comp.csr().modify(|_, w| w.inpsel().bit(false))
comp.csr().modify(|_, w| w.inpsel().bit(false));
}
}

impl PositiveInput<$COMP> for &$pin_1<Analog> {
fn setup(&self, comp: &$COMP) {
comp.csr().modify(|_, w| w.inpsel().bit(true))
comp.csr().modify(|_, w| w.inpsel().bit(true));
}
}
};
Expand Down Expand Up @@ -213,7 +213,7 @@ macro_rules! negative_input_pin_helper {
}

fn setup(&self, comp: &$COMP) {
comp.csr().modify(|_, w| unsafe { w.inmsel().bits($bits) })
comp.csr().modify(|_, w| unsafe { w.inmsel().bits($bits) });
}
}
};
Expand Down Expand Up @@ -268,7 +268,7 @@ macro_rules! refint_input {

fn setup(&self, comp: &$COMP) {
comp.csr()
.modify(|_, w| unsafe { w.inmsel().bits(*self as u8) })
.modify(|_, w| unsafe { w.inmsel().bits(*self as u8) });
}
}
)+};
Expand All @@ -294,7 +294,7 @@ macro_rules! dac_input_helper {
}

fn setup(&self, comp: &$COMP) {
comp.csr().modify(|_, w| unsafe { w.inmsel().bits($bits) })
comp.csr().modify(|_, w| unsafe { w.inmsel().bits($bits) });
}
}
};
Expand Down Expand Up @@ -541,11 +541,11 @@ type Comparators = (COMP1, COMP2, COMP3, COMP4, COMP5, COMP6, COMP7);
/// Enables the comparator peripheral, and splits the [`COMP`] into independent [`COMP1`] and [`COMP2`]
pub fn split(_comp: COMP, rcc: &mut Rcc) -> Comparators {
// Enable COMP, SYSCFG, VREFBUF clocks
rcc.rb.apb2enr.modify(|_, w| w.syscfgen().set_bit());
rcc.rb.apb2enr().modify(|_, w| w.syscfgen().set_bit());

// Reset COMP, SYSCFG, VREFBUF
rcc.rb.apb2rstr.modify(|_, w| w.syscfgrst().set_bit());
rcc.rb.apb2rstr.modify(|_, w| w.syscfgrst().clear_bit());
rcc.rb.apb2rstr().modify(|_, w| w.syscfgrst().set_bit());
rcc.rb.apb2rstr().modify(|_, w| w.syscfgrst().clear_bit());

(
COMP1 { _rb: PhantomData },
Expand Down
Loading
Loading