| 405 | |
| 406 | template<typename Functor> |
| 407 | std::pair<int, uint8_t> waitWhile(const SpiMasterHandle& spiMasterHandle, const distortos::TickClock::duration duration, |
| 408 | Functor functor) |
| 409 | { |
| 410 | const auto deadline = distortos::TickClock::now() + duration; |
| 411 | while (distortos::TickClock::now() < deadline) |
| 412 | { |
| 413 | uint8_t byte; |
| 414 | const SpiMasterTransfer transfer {nullptr, &byte, sizeof(byte)}; |
| 415 | const auto ret = spiMasterHandle.executeTransaction(SpiMasterTransfersRange{transfer}); |
| 416 | if (ret != 0) |
| 417 | return {ret, {}}; |
| 418 | if (functor(byte) == false) |
| 419 | return {{}, byte}; |
| 420 | } |
| 421 | |
| 422 | return {ETIMEDOUT, {}}; |
| 423 | } |
| 424 | |
| 425 | /** |
| 426 | * \brief Waits while SD card connected via SPI is busy. |
no test coverage detected