Giovanni wrote:1) i2c_lld_reset(0 function is not used.
Not sure, is function need at all?
Giovanni wrote: 2) i2c_lld_set_clock() and i2c_lld_set_opmode() can be static because the HLL does not uses them anymore.
3) i2c_lld_master_transceive() can be static and cannot use the keyword "inline", you could inline it directly because it is used only one time.
fixed
Giovanni wrote: 3) There are while loop not protected by timeout in i2c_lld_master_receive_timeout() (OK, here I should explain how to do that using VTs).
I know, how to use VTs in regular threads but never used they in driver context. Are there any examples in other drivers?
Giovanni wrote:4) In i2c_lld_master_receive_timeout() and i2c_lld_master_transmit_timeout()
is it correct to call first i2c_lld_wait_bus_free() and then wait for
I2C_CR1_STOP ?
Yes, correct because there is some time between releasing bus wires (clearing BUSY bit) and
STOP bit clearing. Both checks are needed because line may be busy
in case of hardware errors. By the way, I moved this macro into functions
to improve readability.
Giovanni wrote:5) Use of __NOP() is forbidden, it should not even needed.
6) Some fields of the driver structures have "id_" prefixes, this is obsolete, those prefixes have been removed from all drivers.
fixed
Giovanni wrote: 7) The id_thread field (and several others) cannot be in the "mandatory" part
of the driver structure because are not mandated by the HLL driver.
It is architecture dependant features, so please move it correct himself.
Giovanni wrote: 8) The field txbytes of the driver structure is never used.
fixed
Giovanni wrote: 9) Could the field rxbytes of the driver structure be eliminated with some rework ? (not sure)
Not sure too. In ISR we need correct pointer to receive buffer to realize
read through write behavior. Is there more elegant way to pass it to ISR without separate field
in driver?
Giovanni wrote: 10) Driver fields should not be prefixed with the __IO macro, those are not I/O registers and "volatile" should not be necessary unless there are fields you access from ISRs and out of IRSs outside critical zones (and probably this would be an error anyway).
fixed
Giovanni wrote: 11) The macro i2c_lld_wait_bus_free() hides a lock, this is generally not a
good idea for code readability. Better do it in the same place where the
unlock() is.
Moved this lock from macro to low level functions. Yes, it is better
to do that in one place, but how to realize atomic state transitions
in I2C driver?
Giovanni wrote: 12) The macro i2c_lld_error_wakeup_isr() assigns a critical pointer outside the critical zone.
fixed in i2c_lld_error_wakeup_isr() and i2c_lld_wakeup_isr()
Giovanni wrote: 13) The driver contains non standard sections like "Knowledge base". This kind
of documentation should not be in the code. It must be either private or
in the user documentation using Doxygen.
Please move they to doxygen documentation.
Giovanni wrote: 14) #define inside function bodies are not allowed. Definitions must go in the proper section and do not have private scope.
15) Compile time checks must be done in the header file (clock checks).
fixed
Changes quickly tested on F1x and F4x with simple tests from testhal without any extreme loads. Works as expected.
rev. 3713
--------------------------------------------------------------------------------
@DrunkenDonkey
DrunkenDonkey wrote:Fun aside, is there a way to tell if some i2c slave is alive at all? If it is not responding the state will be defined as NAK on the address write right?
Not always true. If slave "kick the bucket"
and pull one (both) of wire down than you lose the bus at all.
Also, look in testhal\STM32F1xx\I2C\fake.c
DrunkenDonkey wrote:Also, shouldn't the stm32 quirk with inability to receive a single byte be workarounded inside the low level driver implementation by receiving 2 and return 1?
But what byte from 2 return? It is also slave dependent feature.
DrunkenDonkey wrote:The list above sounds like dictatorship to me
I think successful projects must have one and only one dictator to be successful (for example Python, Linux). If you want to contribute code you must keep rules of the project. If not agree than make your own fork "with blackjack and whores". All is simple.