Skip to content

Commit b99ce15

Browse files
Remove redundant check
1 parent fde4074 commit b99ce15

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

targets/TARGET_NUVOTON/TARGET_M480/i2c_api.c

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -704,40 +704,33 @@ static void i2c_irq(i2c_t *obj)
704704
case 0x68: // Slave Receive Arbitration Lost
705705
obj->i2c.slaveaddr_state = WriteAddressed;
706706
if ((obj->i2c.tran_ctrl & TRANCTRL_STARTED) && obj->i2c.tran_pos) {
707-
if (obj->i2c.tran_pos < obj->i2c.tran_end) {
708-
709-
// Did we receive any data? If so, receive it (if there is space in the buffer) and update tran_pos
710-
if (status == 0x80 || status == 0x88) {
711-
if (obj->i2c.tran_ctrl & TRANCTRL_RECVDATA) {
712-
if(obj->i2c.tran_pos < obj->i2c.tran_end)
713-
{
714-
*obj->i2c.tran_pos ++ = I2C_GET_DATA(i2c_base);
715-
}
716-
717-
obj->i2c.tran_ctrl &= ~TRANCTRL_RECVDATA;
707+
// Did we receive any data? If so, receive it (if there is space in the buffer) and update tran_pos
708+
if (status == 0x80 || status == 0x88) {
709+
if (obj->i2c.tran_ctrl & TRANCTRL_RECVDATA) {
710+
if(obj->i2c.tran_pos < obj->i2c.tran_end)
711+
{
712+
*obj->i2c.tran_pos ++ = I2C_GET_DATA(i2c_base);
718713
}
714+
715+
obj->i2c.tran_ctrl &= ~TRANCTRL_RECVDATA;
719716
}
717+
}
720718

721-
// Did we NACK this byte, ending the transaction?
722-
if (status == 0x88) {
723-
obj->i2c.slaveaddr_state = NoData;
724-
i2c_fsm_reset(obj, I2C_CTL0_SI_Msk | I2C_CTL0_AA_Msk);
725-
}
726-
// Otherwise, tell the peripheral to receive the next byte
727-
else {
728-
uint32_t i2c_ctl = I2C_CTL0_SI_Msk | I2C_CTL0_AA_Msk;
729-
if ((obj->i2c.tran_end - obj->i2c.tran_pos) == 1 &&
730-
obj->i2c.tran_ctrl & TRANCTRL_NAKLASTDATA) {
731-
// Last data
732-
i2c_ctl &= ~I2C_CTL0_AA_Msk;
733-
}
734-
I2C_SET_CONTROL_REG(i2c_base, i2c_ctl);
735-
obj->i2c.tran_ctrl |= TRANCTRL_RECVDATA;
719+
// Did we NACK this byte, ending the transaction?
720+
if (status == 0x88) {
721+
obj->i2c.slaveaddr_state = NoData;
722+
i2c_fsm_reset(obj, I2C_CTL0_SI_Msk | I2C_CTL0_AA_Msk);
723+
}
724+
// Otherwise, tell the peripheral to receive the next byte
725+
else {
726+
uint32_t i2c_ctl = I2C_CTL0_SI_Msk | I2C_CTL0_AA_Msk;
727+
if ((obj->i2c.tran_end - obj->i2c.tran_pos) == 1 &&
728+
obj->i2c.tran_ctrl & TRANCTRL_NAKLASTDATA) {
729+
// Last data
730+
i2c_ctl &= ~I2C_CTL0_AA_Msk;
736731
}
737-
} else {
738-
obj->i2c.tran_ctrl &= ~TRANCTRL_STARTED;
739-
i2c_disable_int(obj);
740-
break;
732+
I2C_SET_CONTROL_REG(i2c_base, i2c_ctl);
733+
obj->i2c.tran_ctrl |= TRANCTRL_RECVDATA;
741734
}
742735
} else {
743736
i2c_disable_int(obj);

0 commit comments

Comments
 (0)