nrf/spim: make mosi,miso optional

This commit is contained in:
Richard Dodd 2021-03-27 03:20:58 +01:00 committed by Dario Nieuwenhuis
parent 5646926cca
commit 2c248dab56

View File

@ -9,7 +9,8 @@ use embassy_extras::unborrow;
use futures::future::poll_fn; use futures::future::poll_fn;
use traits::spi::FullDuplex; use traits::spi::FullDuplex;
use crate::gpio::Pin as GpioPin; use crate::gpio::sealed::Pin as _;
use crate::gpio::{OptionalPin, Pin as GpioPin};
use crate::interrupt::{self, Interrupt}; use crate::interrupt::{self, Interrupt};
use crate::{pac, peripherals, slice_in_ram_or}; use crate::{pac, peripherals, slice_in_ram_or};
@ -43,8 +44,8 @@ impl<'d, T: Instance> Spim<'d, T> {
spim: impl PeripheralBorrow<Target = T> + 'd, spim: impl PeripheralBorrow<Target = T> + 'd,
irq: impl PeripheralBorrow<Target = T::Interrupt> + 'd, irq: impl PeripheralBorrow<Target = T::Interrupt> + 'd,
sck: impl PeripheralBorrow<Target = impl GpioPin> + 'd, sck: impl PeripheralBorrow<Target = impl GpioPin> + 'd,
miso: impl PeripheralBorrow<Target = impl GpioPin> + 'd, miso: impl PeripheralBorrow<Target = impl OptionalPin> + 'd,
mosi: impl PeripheralBorrow<Target = impl GpioPin> + 'd, mosi: impl PeripheralBorrow<Target = impl OptionalPin> + 'd,
config: Config, config: Config,
) -> Self { ) -> Self {
unborrow!(spim, irq, sck, miso, mosi); unborrow!(spim, irq, sck, miso, mosi);
@ -53,21 +54,30 @@ impl<'d, T: Instance> Spim<'d, T> {
// Configure pins // Configure pins
sck.conf().write(|w| w.dir().output().drive().h0h1()); sck.conf().write(|w| w.dir().output().drive().h0h1());
mosi.conf().write(|w| w.dir().output().drive().h0h1()); if let Some(mosi) = mosi.pin_mut() {
miso.conf().write(|w| w.input().connect().drive().h0h1()); mosi.conf().write(|w| w.dir().output().drive().h0h1());
}
if let Some(miso) = miso.pin_mut() {
miso.conf().write(|w| w.input().connect().drive().h0h1());
}
match config.mode.polarity { match config.mode.polarity {
Polarity::IdleHigh => { Polarity::IdleHigh => {
sck.set_high(); sck.set_high();
mosi.set_high(); if let Some(mosi) = mosi.pin_mut() {
mosi.set_high();
}
} }
Polarity::IdleLow => { Polarity::IdleLow => {
sck.set_low(); sck.set_low();
mosi.set_low(); if let Some(mosi) = mosi.pin_mut() {
mosi.set_low();
}
} }
} }
// Select pins. // Select pins.
// Note: OptionalPin reports 'disabled' for psel_bits when no pin was selected.
r.psel.sck.write(|w| unsafe { w.bits(sck.psel_bits()) }); r.psel.sck.write(|w| unsafe { w.bits(sck.psel_bits()) });
r.psel.mosi.write(|w| unsafe { w.bits(mosi.psel_bits()) }); r.psel.mosi.write(|w| unsafe { w.bits(mosi.psel_bits()) });
r.psel.miso.write(|w| unsafe { w.bits(miso.psel_bits()) }); r.psel.miso.write(|w| unsafe { w.bits(miso.psel_bits()) });