Skip to content

raspberrypi/I2CTarget: Fixed bug where I2C starts were seen as restarts. #10474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ports/raspberrypi/common-hal/i2ctarget/I2CTarget.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ void common_hal_i2ctarget_i2c_target_deinit(i2ctarget_i2c_target_obj_t *self) {
}

int common_hal_i2ctarget_i2c_target_is_addressed(i2ctarget_i2c_target_obj_t *self, uint8_t *address, bool *is_read, bool *is_restart) {
common_hal_i2ctarget_i2c_target_is_stop(self);

if (!((self->peripheral->hw->raw_intr_stat & I2C_IC_INTR_STAT_R_RX_FULL_BITS) || (self->peripheral->hw->raw_intr_stat & I2C_IC_INTR_STAT_R_RD_REQ_BITS))) {
return 0;
}
Expand Down Expand Up @@ -123,6 +125,19 @@ int common_hal_i2ctarget_i2c_target_write_byte(i2ctarget_i2c_target_obj_t *self,
}
}

int common_hal_i2ctarget_i2c_target_is_stop(i2ctarget_i2c_target_obj_t *self) {
// Interrupt bits must be cleared by software. Clear the STOP and
// RESTART interrupt bits after an I2C transaction finishes.
if (self->peripheral->hw->raw_intr_stat & I2C_IC_INTR_STAT_R_STOP_DET_BITS) {
self->peripheral->hw->clr_stop_det;
self->peripheral->hw->clr_restart_det;
return 1;
} else {
return 0;
}

}

void common_hal_i2ctarget_i2c_target_ack(i2ctarget_i2c_target_obj_t *self, bool ack) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions ports/raspberrypi/common-hal/i2ctarget/I2CTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ typedef struct {
uint8_t scl_pin;
uint8_t sda_pin;
} i2ctarget_i2c_target_obj_t;

int common_hal_i2ctarget_i2c_target_is_stop(i2ctarget_i2c_target_obj_t *self);