Skip to content

Commit e10dae9

Browse files
authored
Merge pull request #37 from david-sawatzke/spi_doc
Add more spi documentation
2 parents aef1521 + 083323b commit e10dae9

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/spi.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1+
//! API for the integrate SPI peripherals
2+
//!
3+
//! The spi bus acts as the master (generating the clock) and you need to handle the CS separately.
4+
//!
5+
//! The most significant bit is transmitted first & only 8-bit transfers are supported
6+
//!
7+
//! # Example
8+
//! Echo incoming data in the next transfer
9+
//! ``` no_run
10+
//! use stm32f0xx_hal as hal;
11+
//!
12+
//! use crate::hal::stm32;
13+
//! use crate::hal::prelude::*;
14+
//! use crate::hal::spi::{Spi, Mode, Phase, Polarity};
15+
//!
16+
//! let p = stm32::Peripherals::take().unwrap();
17+
//! let clcks = p.RCC.constrain().cfgr.freeze();
18+
//!
19+
//! let gpioa = p.GPIOA.split();
20+
//!
21+
//! // Configure pins for SPI
22+
//! let sck = gpioa.pa5.into_alternate_af0();
23+
//! let miso = gpioa.pa6.into_alternate_af0();
24+
//! let mosi = gpioa.pa7.into_alternate_af0();
25+
//!
26+
//! // Configure SPI with 1MHz rate
27+
//! let mut spi = Spi::spi1(p.SPI1, (sck, miso, mosi), Mode {
28+
//! polarity: Polarity::IdleHigh,
29+
//! phase: Phase::CaptureOnSecondTransition,
30+
//! }, 1.mhz(), clocks);
31+
//!
32+
//! let mut data = [ 0 ];
33+
//! loop {
34+
//! spi.transfer(&mut data).unwrap();
35+
//! }
36+
//! ```
37+
138
#[allow(unused)]
239
use core::{ops::Deref, ptr};
340

@@ -142,6 +179,7 @@ macro_rules! spi {
142179
($($SPI:ident: ($spi:ident, $spiXen:ident, $spiXrst:ident, $apbenr:ident, $apbrstr:ident),)+) => {
143180
$(
144181
impl<SCKPIN, MISOPIN, MOSIPIN> Spi<$SPI, SCKPIN, MISOPIN, MOSIPIN> {
182+
/// Creates a new spi instance
145183
pub fn $spi<F>(
146184
spi: $SPI,
147185
pins: (SCKPIN, MISOPIN, MOSIPIN),

0 commit comments

Comments
 (0)