Skip to content

Commit 9a325cc

Browse files
Add non-existent pins
1 parent ac4c91b commit 9a325cc

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
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- Support for stm32f0x1 line - @jessebraham
1313
- Support for HSE as a system clocksource (#25 - breaking change) - @zklapow
14+
- Added non-existent pins for SPI & I2C
1415

1516
### Changed
1617

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 rcc = p.RCC.constrain();
25+
let clocks = rcc.cfgr.freeze();
26+
27+
let pins = unsafe { (NoSck::new(), NoMiso::new(), NoMosi::new()) };
28+
let _ = Spi::spi1(p.SPI1, pins, MODE, 100_000.hz(), clocks);
29+
30+
let pins = unsafe { (NoScl::new(), NoSda::new()) };
31+
let _ = I2c::i2c1(p.I2C1, pins, 400.khz());
32+
}
33+
loop {
34+
continue;
35+
}
36+
}

src/i2c.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,44 @@ pub enum Error {
132132
NACK,
133133
}
134134

135+
/// Filler for a SDA Pin
136+
///
137+
/// Usefull if you don't want to utilize the sda pin,
138+
/// but a pin parameter is required
139+
pub struct NoSda {
140+
_1: (),
141+
}
142+
143+
impl NoSda {
144+
/// Create a new unused pin
145+
pub unsafe fn new() -> Self {
146+
Self { _1: () }
147+
}
148+
}
149+
150+
/// Filler for a SCL Pin
151+
///
152+
/// Usefull if you don't want to utilize the scl pin,
153+
/// but a pin parameter is required
154+
pub struct NoScl {
155+
_1: (),
156+
}
157+
158+
impl NoScl {
159+
/// Create a new unused pin
160+
pub unsafe fn new() -> Self {
161+
Self { _1: () }
162+
}
163+
}
164+
135165
macro_rules! i2c {
136166
($($I2C:ident: ($i2c:ident, $i2cXen:ident, $i2cXrst:ident, $apbenr:ident, $apbrstr:ident),)+) => {
137167
$(
138168
use crate::stm32::$I2C;
169+
170+
impl SclPin<$I2C> for NoScl {}
171+
impl SdaPin<$I2C> for NoSda {}
172+
139173
impl<SCLPIN, SDAPIN> I2c<$I2C, SCLPIN, SDAPIN> {
140174
pub fn $i2c(i2c: $I2C, pins: (SCLPIN, SDAPIN), speed: KiloHertz, rcc: &mut Rcc) -> Self
141175
where

src/spi.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,58 @@ spi_pins! {
171171
}
172172
}
173173

174+
/// Filler for a SCK pin
175+
///
176+
/// Usefull if you don't want to utilize the sck pin,
177+
/// but a pin parameter is required
178+
pub struct NoSck {
179+
_1: (),
180+
}
181+
182+
impl NoSck {
183+
/// Create a new filler sck pin
184+
pub unsafe fn new() -> Self {
185+
Self { _1: () }
186+
}
187+
}
188+
189+
/// Filler for a MISO Pin
190+
///
191+
/// Usefull if you don't want to utilize the miso pin,
192+
/// but a pin parameter is required
193+
pub struct NoMiso {
194+
_1: (),
195+
}
196+
197+
impl NoMiso {
198+
/// Create a new filler mosi pin
199+
pub unsafe fn new() -> Self {
200+
Self { _1: () }
201+
}
202+
}
203+
204+
/// Filler for a MOSI Pin
205+
///
206+
/// Usefull if you don't want to utilize the miso pin,
207+
/// but a pin parameter is required
208+
pub struct NoMosi {
209+
_1: (),
210+
}
211+
212+
impl NoMosi {
213+
/// Create a new filler mosi pin
214+
pub unsafe fn new() -> Self {
215+
Self { _1: () }
216+
}
217+
}
218+
174219
macro_rules! spi {
175220
($($SPI:ident: ($spi:ident, $spiXen:ident, $spiXrst:ident, $apbenr:ident, $apbrstr:ident),)+) => {
176221
$(
222+
impl SckPin<$SPI> for NoSck {}
223+
impl MisoPin<$SPI> for NoMiso {}
224+
impl MosiPin<$SPI> for NoMosi {}
225+
177226
impl<SCKPIN, MISOPIN, MOSIPIN> Spi<$SPI, SCKPIN, MISOPIN, MOSIPIN> {
178227
/// Creates a new spi instance
179228
pub fn $spi<F>(

0 commit comments

Comments
 (0)