Skip to content

Commit

Permalink
Merge pull request tock#3747 from twilfredo/wilfred/fixup-nrf52-i2c
Browse files Browse the repository at this point in the history
nrf52: i2c: fixup buffer usage
  • Loading branch information
bradjc authored Nov 27, 2023
2 parents d63678d + d2a2f5d commit d2b44c3
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions chips/nrf52/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,29 @@ impl<'a> TWI<'a> {
} else {
self.registers.events_stopped.write(EVENT::EVENT::CLEAR);

// If RX started and we don't have a buffer then report
// read_expected()
// If RX started (master started write) and we don't have a buffer then report
// write_expected()
if self.registers.events_rxstarted.is_set(EVENT::EVENT) {
self.registers.events_rxstarted.write(EVENT::EVENT::CLEAR);
self.slave_client
.map(|client| match self.slave_read_buf.take() {
None => {
client.read_expected();
}
Some(_buf) => {}
});
self.slave_client.map(|client| {
if self.buf.is_none() {
client.write_expected();
}
});
}

// If TX started (master started read) and we don't have a buffer then report
// read_expected()
if self.registers.events_txstarted.is_set(EVENT::EVENT) {
self.registers.events_txstarted.write(EVENT::EVENT::CLEAR);
self.slave_client.map(|client| {
if self.slave_read_buf.is_none() {
client.read_expected();
}
});
}

// Write command received
if self.registers.events_write.is_set(EVENT::EVENT) {
self.registers.events_write.write(EVENT::EVENT::CLEAR);
let length = self.registers.rxd_amount.read(AMOUNT::AMOUNT) as usize;
Expand Down Expand Up @@ -173,7 +183,6 @@ impl<'a> TWI<'a> {

// We can blindly clear the following events since we're not using them.
self.registers.events_suspended.write(EVENT::EVENT::CLEAR);
self.registers.events_rxstarted.write(EVENT::EVENT::CLEAR);
self.registers.events_lastrx.write(EVENT::EVENT::CLEAR);
self.registers.events_lasttx.write(EVENT::EVENT::CLEAR);
}
Expand Down

0 comments on commit d2b44c3

Please sign in to comment.