Skip to content

Commit 914ef01

Browse files
authored
Merge pull request #182 from burrbull/spi_deref2
Spi Deref
2 parents 58d286f + cc69572 commit 914ef01

File tree

8 files changed

+209
-168
lines changed

8 files changed

+209
-168
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

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

1214
## [v0.5.3] - 2020-01-20

examples/spi-dma.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn main() -> ! {
4141
polarity: Polarity::IdleLow,
4242
phase: Phase::CaptureOnFirstTransition
4343
};
44-
let mut spi = Spi::spi2(
44+
let spi = Spi::spi2(
4545
dp.SPI2,
4646
pins,
4747
spi_mode,

src/i2c.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::gpio::{Alternate, OpenDrain};
1111
use crate::hal::blocking::i2c::{Read, Write, WriteRead};
1212
use nb::Error::{Other, WouldBlock};
1313
use nb::{Error as NbError, Result as NbResult};
14-
use crate::rcc::{Clocks, APB1, Enable, Reset, RccBus, GetBusFreq};
14+
use crate::rcc::{Clocks, Enable, Reset, sealed::RccBus, GetBusFreq};
1515
use crate::pac::{DWT, I2C1, I2C2};
1616

1717
/// I2C error
@@ -105,7 +105,7 @@ impl<PINS> I2c<I2C1, PINS> {
105105
mapr: &mut MAPR,
106106
mode: Mode,
107107
clocks: Clocks,
108-
apb: &mut APB1,
108+
apb: &mut <I2C1 as RccBus>::Bus,
109109
) -> Self
110110
where
111111
PINS: Pins<I2C1>,
@@ -122,7 +122,7 @@ impl<PINS> BlockingI2c<I2C1, PINS> {
122122
mapr: &mut MAPR,
123123
mode: Mode,
124124
clocks: Clocks,
125-
apb: &mut APB1,
125+
apb: &mut <I2C1 as RccBus>::Bus,
126126
start_timeout_us: u32,
127127
start_retries: u8,
128128
addr_timeout_us: u32,
@@ -147,7 +147,13 @@ impl<PINS> BlockingI2c<I2C1, PINS> {
147147
}
148148

149149
impl<PINS> I2c<I2C2, PINS> {
150-
pub fn i2c2(i2c: I2C2, pins: PINS, mode: Mode, clocks: Clocks, apb: &mut APB1) -> Self
150+
pub fn i2c2(
151+
i2c: I2C2,
152+
pins: PINS,
153+
mode: Mode,
154+
clocks: Clocks,
155+
apb: &mut <I2C2 as RccBus>::Bus
156+
) -> Self
151157
where
152158
PINS: Pins<I2C2>,
153159
{
@@ -161,7 +167,7 @@ impl<PINS> BlockingI2c<I2C2, PINS> {
161167
pins: PINS,
162168
mode: Mode,
163169
clocks: Clocks,
164-
apb: &mut APB1,
170+
apb: &mut <I2C2 as RccBus>::Bus,
165171
start_timeout_us: u32,
166172
start_retries: u8,
167173
addr_timeout_us: u32,
@@ -352,7 +358,7 @@ macro_rules! hal {
352358
pins: PINS,
353359
mode: Mode,
354360
clocks: Clocks,
355-
apb: &mut APB1,
361+
apb: &mut <$I2CX as RccBus>::Bus,
356362
start_timeout_us: u32,
357363
start_retries: u8,
358364
addr_timeout_us: u32,

src/pwm_input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::pac::TIM4;
1717

1818
use crate::afio::MAPR;
1919
use crate::gpio::{self, Floating, Input};
20-
use crate::rcc::{Clocks, GetBusFreq, RccBus};
20+
use crate::rcc::{Clocks, GetBusFreq, sealed::RccBus};
2121
use crate::time::Hertz;
2222
use crate::timer::Timer;
2323

src/rcc.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,20 +496,23 @@ impl GetBusFreq for APB2 {
496496
}
497497
}
498498

499-
/// Bus associated to peripheral
500-
pub trait RccBus {
501-
/// Bus type;
502-
type Bus;
499+
pub(crate) mod sealed {
500+
/// Bus associated to peripheral
501+
pub trait RccBus {
502+
/// Bus type;
503+
type Bus;
504+
}
503505
}
506+
use sealed::RccBus;
504507

505508
/// Enable/disable peripheral
506-
pub(crate) trait Enable: RccBus {
509+
pub trait Enable: RccBus {
507510
fn enable(apb: &mut Self::Bus);
508511
fn disable(apb: &mut Self::Bus);
509512
}
510513

511514
/// Reset peripheral
512-
pub(crate) trait Reset: RccBus {
515+
pub trait Reset: RccBus {
513516
fn reset(apb: &mut Self::Bus);
514517
}
515518

src/serial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use crate::gpio::gpiob::{PB10, PB11, PB6, PB7};
5454
use crate::gpio::gpioc::{PC10, PC11};
5555
use crate::gpio::gpiod::{PD5, PD6, PD8, PD9};
5656
use crate::gpio::{Alternate, Floating, Input, PushPull};
57-
use crate::rcc::{RccBus, Clocks, Enable, Reset, GetBusFreq};
57+
use crate::rcc::{sealed::RccBus, Clocks, Enable, Reset, GetBusFreq};
5858
use crate::time::{U32Ext, Bps};
5959

6060
/// Interrupt event

0 commit comments

Comments
 (0)