Skip to content

Commit eb7c5d1

Browse files
Add non-existent pins
1 parent 77a6dad commit eb7c5d1

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Added
1111

1212
- Support for stm32f0x8 line - @jessebraham
13+
- Added non-existent pins for SPI & I2C (#27) - @david-sawatzke
1314

1415
### Changed
1516

examples/unused.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//! This is not intended to be used on a real system
2+
#![no_main]
3+
#![no_std]
4+
5+
#[allow(unused)]
6+
use panic_halt;
7+
8+
use stm32f0xx_hal as hal;
9+
10+
use crate::hal::i2c::*;
11+
use crate::hal::prelude::*;
12+
use crate::hal::spi::*;
13+
use crate::hal::stm32;
14+
15+
use cortex_m_rt::entry;
16+
#[entry]
17+
fn main() -> ! {
18+
const MODE: Mode = Mode {
19+
polarity: Polarity::IdleHigh,
20+
phase: Phase::CaptureOnSecondTransition,
21+
};
22+
23+
if let Some(p) = stm32::Peripherals::take() {
24+
let mut flash = p.FLASH;
25+
let mut rcc = p.RCC.configure().sysclk(8.mhz()).freeze(&mut flash);
26+
27+
let pins = unsafe { (NoSck::new(), NoMiso::new(), NoMosi::new()) };
28+
let _ = Spi::spi1(p.SPI1, pins, MODE, 100_000.hz(), &mut rcc);
29+
30+
let pins = unsafe { (NoScl::new(), NoSda::new()) };
31+
let _ = I2c::i2c1(p.I2C1, pins, 400.khz(), &mut rcc);
32+
}
33+
loop {
34+
continue;
35+
}
36+
}

src/i2c.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,44 @@ pub enum Error {
151151
NACK,
152152
}
153153

154+
/// Filler for a SDA Pin
155+
///
156+
/// Usefull if you don't want to utilize the sda pin,
157+
/// but a pin parameter is required
158+
pub struct NoSda {
159+
_1: (),
160+
}
161+
162+
impl NoSda {
163+
/// Create a new unused pin
164+
pub unsafe fn new() -> Self {
165+
Self { _1: () }
166+
}
167+
}
168+
169+
/// Filler for a SCL Pin
170+
///
171+
/// Usefull if you don't want to utilize the scl pin,
172+
/// but a pin parameter is required
173+
pub struct NoScl {
174+
_1: (),
175+
}
176+
177+
impl NoScl {
178+
/// Create a new unused pin
179+
pub unsafe fn new() -> Self {
180+
Self { _1: () }
181+
}
182+
}
183+
154184
macro_rules! i2c {
155185
($($I2C:ident: ($i2c:ident, $i2cXen:ident, $i2cXrst:ident, $apbenr:ident, $apbrstr:ident),)+) => {
156186
$(
157187
use crate::stm32::$I2C;
188+
189+
impl SclPin<$I2C> for NoScl {}
190+
impl SdaPin<$I2C> for NoSda {}
191+
158192
impl<SCLPIN, SDAPIN> I2c<$I2C, SCLPIN, SDAPIN> {
159193
pub fn $i2c(i2c: $I2C, pins: (SCLPIN, SDAPIN), speed: KiloHertz, rcc: &mut Rcc) -> Self
160194
where

src/spi.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,58 @@ spi_pins! {
201201
}
202202
}
203203

204+
/// Filler for a SCK pin
205+
///
206+
/// Usefull if you don't want to utilize the sck pin,
207+
/// but a pin parameter is required
208+
pub struct NoSck {
209+
_1: (),
210+
}
211+
212+
impl NoSck {
213+
/// Create a new filler sck pin
214+
pub unsafe fn new() -> Self {
215+
Self { _1: () }
216+
}
217+
}
218+
219+
/// Filler for a MISO Pin
220+
///
221+
/// Usefull if you don't want to utilize the miso pin,
222+
/// but a pin parameter is required
223+
pub struct NoMiso {
224+
_1: (),
225+
}
226+
227+
impl NoMiso {
228+
/// Create a new filler mosi pin
229+
pub unsafe fn new() -> Self {
230+
Self { _1: () }
231+
}
232+
}
233+
234+
/// Filler for a MOSI Pin
235+
///
236+
/// Usefull if you don't want to utilize the miso pin,
237+
/// but a pin parameter is required
238+
pub struct NoMosi {
239+
_1: (),
240+
}
241+
242+
impl NoMosi {
243+
/// Create a new filler mosi pin
244+
pub unsafe fn new() -> Self {
245+
Self { _1: () }
246+
}
247+
}
248+
204249
macro_rules! spi {
205250
($($SPI:ident: ($spi:ident, $spiXen:ident, $spiXrst:ident, $apbenr:ident, $apbrstr:ident),)+) => {
206251
$(
252+
impl SckPin<$SPI> for NoSck {}
253+
impl MisoPin<$SPI> for NoMiso {}
254+
impl MosiPin<$SPI> for NoMosi {}
255+
207256
impl<SCKPIN, MISOPIN, MOSIPIN> Spi<$SPI, SCKPIN, MISOPIN, MOSIPIN> {
208257
/// Creates a new spi instance
209258
pub fn $spi<F>(

0 commit comments

Comments
 (0)