Skip to content

Commit

Permalink
[i2c] Add more convenience functions to I2cDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Jun 24, 2024
1 parent cf7769b commit b2ffe2d
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions src/modm/architecture/interface/i2c_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,46 @@ class I2cDevice : protected modm::NestedResumable< NestingLevels + 1 >
RF_END_RETURN( wasTransactionSuccessful() );
}

/// Starts a write-read transaction and waits until finished.
modm::ResumableResult<bool>
writeRead(const uint8_t *writeBuffer, std::size_t writeSize,
uint8_t *readBuffer, std::size_t readSize)
{
RF_BEGIN();

RF_WAIT_UNTIL( startWriteRead(writeBuffer, writeSize, readBuffer, readSize) );

RF_WAIT_WHILE( isTransactionRunning() );

RF_END_RETURN( wasTransactionSuccessful() );
}

/// Starts a write transaction and waits until finished.
modm::ResumableResult<bool>
write(const uint8_t *buffer, std::size_t size)
{
RF_BEGIN();

RF_WAIT_UNTIL( startWrite(buffer, size) );

RF_WAIT_WHILE( isTransactionRunning() );

RF_END_RETURN( wasTransactionSuccessful() );
}

/// Starts a write transaction and waits until finished.
modm::ResumableResult<bool>
read(uint8_t *buffer, std::size_t size)
{
RF_BEGIN();

RF_WAIT_UNTIL( startRead(buffer, size) );

RF_WAIT_WHILE( isTransactionRunning() );

RF_END_RETURN( wasTransactionSuccessful() );
}

protected:
/// Configures the transaction with a write/read operation and starts it.
bool inline
Expand Down Expand Up @@ -114,8 +154,8 @@ class I2cDevice : protected modm::NestedResumable< NestingLevels + 1 >
return startTransaction(&this->transaction);
}

/// Starts the transaction with a seperate transaction object.
bool inline
/// Starts the transaction with a separate transaction object.
static bool inline
startTransaction(modm::I2cTransaction *transaction)
{
return I2cMaster::start(transaction, configuration);
Expand Down

0 comments on commit b2ffe2d

Please sign in to comment.