Skip to content

Commit

Permalink
[fiber] Add yields to SPI and I2C bitbang drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Sep 29, 2024
1 parent a7cfe65 commit edb1a09
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/modm/platform/i2c/bitbang/bitbang_i2c_master_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef MODM_SOFTWARE_BITBANG_I2C_HPP
# error "Don't include this file directly, use 'bitbang_i2c_master.hpp' instead!"
#endif
#include <modm/processing/fiber.hpp>

// debugging for serious dummies
/*
Expand Down Expand Up @@ -314,6 +315,8 @@ template <class Scl, class Sda>
bool
modm::platform::BitBangI2cMaster<Scl, Sda>::write(uint8_t data)
{
modm::this_fiber::yield();

DEBUG_SW_I2C('W');
// shift through all 8 bits
for(uint_fast8_t i = 0; i < 8; ++i)
Expand Down Expand Up @@ -359,6 +362,8 @@ template <class Scl, class Sda>
bool
modm::platform::BitBangI2cMaster<Scl, Sda>::read(uint8_t &data, bool ack)
{
modm::this_fiber::yield();

DEBUG_SW_I2C('R');
// release data line
SDA::set();
Expand Down
3 changes: 3 additions & 0 deletions src/modm/platform/spi/bitbang/bitbang_spi_master_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef MODM_SOFTWARE_BITBANG_SPI_MASTER_HPP
# error "Don't include this file directly, use 'bitbang_spi_master.hpp' instead!"
#endif
#include <modm/processing/fiber.hpp>

template <typename Sck, typename Mosi, typename Miso>
uint16_t
Expand Down Expand Up @@ -84,6 +85,8 @@ template <typename Sck, typename Mosi, typename Miso>
uint8_t
modm::platform::BitBangSpiMaster<Sck, Mosi, Miso>::transferBlocking(uint8_t data)
{
modm::this_fiber::yield();

for (uint_fast8_t ii = 0; ii < 8; ++ii)
{
// CPHA=1, sample on falling edge
Expand Down

0 comments on commit edb1a09

Please sign in to comment.