stm32f1xx_hal/spi/
hal_02.rs1use super::*;
2
3pub use embedded_hal_02::spi::{Mode, Phase, Polarity};
4use embedded_hal_02::{blocking::spi as blocking, spi};
5
6impl From<Polarity> for super::Polarity {
7 fn from(p: Polarity) -> Self {
8 match p {
9 Polarity::IdleLow => Self::IdleLow,
10 Polarity::IdleHigh => Self::IdleHigh,
11 }
12 }
13}
14
15impl From<Phase> for super::Phase {
16 fn from(p: Phase) -> Self {
17 match p {
18 Phase::CaptureOnFirstTransition => Self::CaptureOnFirstTransition,
19 Phase::CaptureOnSecondTransition => Self::CaptureOnSecondTransition,
20 }
21 }
22}
23
24impl From<Mode> for super::Mode {
25 fn from(m: Mode) -> Self {
26 Self {
27 polarity: m.polarity.into(),
28 phase: m.phase.into(),
29 }
30 }
31}
32
33impl<SPI, W, PULL> spi::FullDuplex<W> for Spi<SPI, W, PULL>
34where
35 SPI: Instance,
36 W: FrameSize,
37{
38 type Error = Error;
39
40 fn read(&mut self) -> nb::Result<W, Error> {
41 self.read_nonblocking()
42 }
43
44 fn send(&mut self, data: W) -> nb::Result<(), Error> {
45 self.write_nonblocking(data)
46 }
47}
48
49impl<SPI, W, PULL> blocking::transfer::Default<W> for Spi<SPI, W, PULL>
50where
51 SPI: Instance,
52 W: FrameSize,
53{
54}
55
56impl<SPI: Instance, PULL> blocking::Write<u8> for Spi<SPI, u8, PULL> {
57 type Error = Error;
58
59 fn write(&mut self, words: &[u8]) -> Result<(), Error> {
60 self.deref_mut().write(words)
61 }
62}
63
64impl<SPI: Instance, PULL> blocking::Write<u16> for Spi<SPI, u16, PULL> {
65 type Error = Error;
66
67 fn write(&mut self, words: &[u16]) -> Result<(), Error> {
68 self.deref_mut().write(words)
69 }
70}