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

Spi Deref #182

Merged
merged 2 commits into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

- Use `Deref` for SPI generic implementations instead of macros
- Make traits `rcc::Enable` and `rcc::Reset` public, but `RccBus` sealed
- Add `QeiOptions` struct to configure slave mode and auto reload value of QEI interface

## [v0.5.3] - 2020-01-20
Expand Down
2 changes: 1 addition & 1 deletion examples/spi-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn main() -> ! {
polarity: Polarity::IdleLow,
phase: Phase::CaptureOnFirstTransition
};
let mut spi = Spi::spi2(
let spi = Spi::spi2(
dp.SPI2,
pins,
spi_mode,
Expand Down
18 changes: 12 additions & 6 deletions src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::gpio::{Alternate, OpenDrain};
use crate::hal::blocking::i2c::{Read, Write, WriteRead};
use nb::Error::{Other, WouldBlock};
use nb::{Error as NbError, Result as NbResult};
use crate::rcc::{Clocks, APB1, Enable, Reset, RccBus, GetBusFreq};
use crate::rcc::{Clocks, Enable, Reset, sealed::RccBus, GetBusFreq};
use crate::pac::{DWT, I2C1, I2C2};

/// I2C error
Expand Down Expand Up @@ -105,7 +105,7 @@ impl<PINS> I2c<I2C1, PINS> {
mapr: &mut MAPR,
mode: Mode,
clocks: Clocks,
apb: &mut APB1,
apb: &mut <I2C1 as RccBus>::Bus,
) -> Self
where
PINS: Pins<I2C1>,
Expand All @@ -122,7 +122,7 @@ impl<PINS> BlockingI2c<I2C1, PINS> {
mapr: &mut MAPR,
mode: Mode,
clocks: Clocks,
apb: &mut APB1,
apb: &mut <I2C1 as RccBus>::Bus,
start_timeout_us: u32,
start_retries: u8,
addr_timeout_us: u32,
Expand All @@ -147,7 +147,13 @@ impl<PINS> BlockingI2c<I2C1, PINS> {
}

impl<PINS> I2c<I2C2, PINS> {
pub fn i2c2(i2c: I2C2, pins: PINS, mode: Mode, clocks: Clocks, apb: &mut APB1) -> Self
pub fn i2c2(
i2c: I2C2,
pins: PINS,
mode: Mode,
clocks: Clocks,
apb: &mut <I2C2 as RccBus>::Bus
) -> Self
where
PINS: Pins<I2C2>,
{
Expand All @@ -161,7 +167,7 @@ impl<PINS> BlockingI2c<I2C2, PINS> {
pins: PINS,
mode: Mode,
clocks: Clocks,
apb: &mut APB1,
apb: &mut <I2C2 as RccBus>::Bus,
start_timeout_us: u32,
start_retries: u8,
addr_timeout_us: u32,
Expand Down Expand Up @@ -352,7 +358,7 @@ macro_rules! hal {
pins: PINS,
mode: Mode,
clocks: Clocks,
apb: &mut APB1,
apb: &mut <$I2CX as RccBus>::Bus,
start_timeout_us: u32,
start_retries: u8,
addr_timeout_us: u32,
Expand Down
2 changes: 1 addition & 1 deletion src/pwm_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::pac::TIM4;

use crate::afio::MAPR;
use crate::gpio::{self, Floating, Input};
use crate::rcc::{Clocks, GetBusFreq, RccBus};
use crate::rcc::{Clocks, GetBusFreq, sealed::RccBus};
use crate::time::Hertz;
use crate::timer::Timer;

Expand Down
15 changes: 9 additions & 6 deletions src/rcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,20 +496,23 @@ impl GetBusFreq for APB2 {
}
}

/// Bus associated to peripheral
pub trait RccBus {
/// Bus type;
type Bus;
pub(crate) mod sealed {
/// Bus associated to peripheral
pub trait RccBus {
/// Bus type;
type Bus;
}
}
use sealed::RccBus;

/// Enable/disable peripheral
pub(crate) trait Enable: RccBus {
pub trait Enable: RccBus {
fn enable(apb: &mut Self::Bus);
fn disable(apb: &mut Self::Bus);
}

/// Reset peripheral
pub(crate) trait Reset: RccBus {
pub trait Reset: RccBus {
fn reset(apb: &mut Self::Bus);
}

Expand Down
2 changes: 1 addition & 1 deletion src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use crate::gpio::gpiob::{PB10, PB11, PB6, PB7};
use crate::gpio::gpioc::{PC10, PC11};
use crate::gpio::gpiod::{PD5, PD6, PD8, PD9};
use crate::gpio::{Alternate, Floating, Input, PushPull};
use crate::rcc::{RccBus, Clocks, Enable, Reset, GetBusFreq};
use crate::rcc::{sealed::RccBus, Clocks, Enable, Reset, GetBusFreq};
use crate::time::{U32Ext, Bps};

/// Interrupt event
Expand Down
Loading