Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wovo committed Jun 18, 2021
1 parent 193af4b commit 3d04a45
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions library/core/hwlib-i2c.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class i2c_write_transaction {
private:

i2c_primitives & primitives;
bool end_with_stop;

public:

Expand All @@ -169,12 +170,22 @@ class i2c_write_transaction {
i2c_primitives & primitives,
uint_fast8_t a
):
primitives( primitives )
primitives( primitives ),
end_with_stop( true )
{
primitives.write_start();
primitives.write( a << 1 );
}

/// prepare for a repeated start
///
/// Calling this function causes the transaction
/// to omit the terminating stop, so the nextr transaction
/// starts with a repeated start.
void prepare_repeated_start(){
end_with_stop = false;
}

/// write a single byte
///
/// This function write the byte d to the slave.
Expand All @@ -201,7 +212,11 @@ class i2c_write_transaction {
/// terminate (close) the write transaction
~i2c_write_transaction(){
primitives.read_ack();
primitives.write_stop();
if( end_with_stop ){
primitives.write_stop();
} else {
primitives.write_bit( 1 );
}
}

}; // class i2c_write_transaction
Expand Down

0 comments on commit 3d04a45

Please sign in to comment.