#BL602 I2C HAL looks a little dubious... Why is there an Assignment inside a Condition? 🤔
https://github.com/bouffalolab/bl_iot_sdk/blob/master/components/hal_drv/bl602_hal/hal_i2c.c#L74-L95
@lupyuen Unless the right side is secretly a variable: because someone has been developing in C in hubris mode (aka "I don't need fatal warnings, I know what I'm doing").
@chrysn Haha I doubt that's the intention 😉 I changed "=" to "==" and it seems to work fine
@lupyuen @chrysn
Yeah, it probably should be a "==", although I've often seen guys take advantage of the way "AND" conditionals are processed in order to assign variables (if the first condition is in not true, it won't bother to execute the second test and so the variable won't get assigned, but if the first condition is true the variable is assigned. It's bad form but seems to be accepted practice in some scripting languages.
@lupyuen as a longtime professional C programmer this is obviously the error you describe, not just because the variable isn't used later, but also because the if-test can't possibly do what is intended with the = that is there.
The code is trying to handle write interrupts if the msg is a write, and read interrupts if the msg is a read. With the mistake, it enters the "write" block for both read and write interrupts on a M_WRITE postmsg, and enters the "read" block for both read and write interrupts on a M_READ postmsg.
The Assignment looks odd because "pstmsg->event" has already been set by the calling function "i2c_interrupt_entry" ... And "pstmsg->event" isn't used after "i2c_transferbytes" returns to "i2c_interrupt_entry" 🤔
https://github.com/bouffalolab/bl_iot_sdk/blob/master/components/hal_drv/bl602_hal/hal_i2c.c#L97-L133
We have created an issue for this...
https://github.com/bouffalolab/bl_iot_sdk/issues/33