mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-21 22:32:29 +00:00
shared_bus/blocking/spi: fix build and behaviour when "time" disabled
new behaviour: check for DelayUs presence in operations instead of shortcircuiting
This commit is contained in:
parent
3a8a950bb8
commit
2c9f4bce01
@ -55,6 +55,10 @@ where
|
|||||||
CS: OutputPin,
|
CS: OutputPin,
|
||||||
{
|
{
|
||||||
fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> {
|
fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> {
|
||||||
|
if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayUs(_))) {
|
||||||
|
return Err(SpiDeviceError::DelayUsNotSupported);
|
||||||
|
}
|
||||||
|
|
||||||
self.bus.lock(|bus| {
|
self.bus.lock(|bus| {
|
||||||
let mut bus = bus.borrow_mut();
|
let mut bus = bus.borrow_mut();
|
||||||
self.cs.set_low().map_err(SpiDeviceError::Cs)?;
|
self.cs.set_low().map_err(SpiDeviceError::Cs)?;
|
||||||
@ -65,7 +69,7 @@ where
|
|||||||
Operation::Transfer(read, write) => bus.transfer(read, write),
|
Operation::Transfer(read, write) => bus.transfer(read, write),
|
||||||
Operation::TransferInPlace(buf) => bus.transfer_in_place(buf),
|
Operation::TransferInPlace(buf) => bus.transfer_in_place(buf),
|
||||||
#[cfg(not(feature = "time"))]
|
#[cfg(not(feature = "time"))]
|
||||||
Operation::DelayUs(_) => Err(SpiDeviceError::DelayUsNotSupported),
|
Operation::DelayUs(_) => unreachable!(),
|
||||||
#[cfg(feature = "time")]
|
#[cfg(feature = "time")]
|
||||||
Operation::DelayUs(us) => {
|
Operation::DelayUs(us) => {
|
||||||
embassy_time::block_for(embassy_time::Duration::from_micros(*us as _));
|
embassy_time::block_for(embassy_time::Duration::from_micros(*us as _));
|
||||||
@ -161,6 +165,10 @@ where
|
|||||||
CS: OutputPin,
|
CS: OutputPin,
|
||||||
{
|
{
|
||||||
fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> {
|
fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> {
|
||||||
|
if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayUs(_))) {
|
||||||
|
return Err(SpiDeviceError::DelayUsNotSupported);
|
||||||
|
}
|
||||||
|
|
||||||
self.bus.lock(|bus| {
|
self.bus.lock(|bus| {
|
||||||
let mut bus = bus.borrow_mut();
|
let mut bus = bus.borrow_mut();
|
||||||
bus.set_config(&self.config).map_err(|_| SpiDeviceError::Config)?;
|
bus.set_config(&self.config).map_err(|_| SpiDeviceError::Config)?;
|
||||||
@ -172,7 +180,7 @@ where
|
|||||||
Operation::Transfer(read, write) => bus.transfer(read, write),
|
Operation::Transfer(read, write) => bus.transfer(read, write),
|
||||||
Operation::TransferInPlace(buf) => bus.transfer_in_place(buf),
|
Operation::TransferInPlace(buf) => bus.transfer_in_place(buf),
|
||||||
#[cfg(not(feature = "time"))]
|
#[cfg(not(feature = "time"))]
|
||||||
Operation::DelayUs(_) => Err(SpiDeviceError::DelayUsNotSupported),
|
Operation::DelayUs(_) => unreachable!(),
|
||||||
#[cfg(feature = "time")]
|
#[cfg(feature = "time")]
|
||||||
Operation::DelayUs(us) => {
|
Operation::DelayUs(us) => {
|
||||||
embassy_time::block_for(embassy_time::Duration::from_micros(*us as _));
|
embassy_time::block_for(embassy_time::Duration::from_micros(*us as _));
|
||||||
|
Loading…
Reference in New Issue
Block a user