3535 *
3636 * @{
3737 */
38+
39+ /**
40+ * Indicates that an unspecified error has occurred in the transfer. This usually means
41+ * either an internal error in the Mbed MCU's I2C module, or something like an arbitration loss.
42+ * Does not indicate a NACK.
43+ */
3844#define I2C_EVENT_ERROR (1 << 1)
45+
46+ /**
47+ * Indicates that the slave did not respond to the address byte of the transfer.
48+ */
3949#define I2C_EVENT_ERROR_NO_SLAVE (1 << 2)
50+
51+ /**
52+ * Indicates that the transfer completed successfully.
53+ */
4054#define I2C_EVENT_TRANSFER_COMPLETE (1 << 3)
55+
56+ /**
57+ * Indicates that a NACK was received after the address byte, but before the requested number of bytes
58+ * could be transferred.
59+ *
60+ * Note: Not every manufacturer HAL is able to make a distinction between this flag and #I2C_EVENT_ERROR_NO_SLAVE.
61+ * On a NACK, you might conceivably get one or both of these flags.
62+ */
4163#define I2C_EVENT_TRANSFER_EARLY_NACK (1 << 4)
64+
65+ /**
66+ * Use this macro to request all possible I2C events.
67+ */
4268#define I2C_EVENT_ALL (I2C_EVENT_ERROR | I2C_EVENT_TRANSFER_COMPLETE | I2C_EVENT_ERROR_NO_SLAVE | I2C_EVENT_TRANSFER_EARLY_NACK)
4369
4470/**@}*/
@@ -61,7 +87,8 @@ typedef struct i2c_s i2c_t;
6187
6288enum {
6389 I2C_ERROR_NO_SLAVE = -1 ,
64- I2C_ERROR_BUS_BUSY = -2
90+ I2C_ERROR_BUS_BUSY = -2 ,
91+ I2C_ERROR_INVALID_USAGE = -3 ///< Invalid usage of the I2C API, e.g. by mixing single-byte and transactional function calls.
6592};
6693
6794typedef struct {
@@ -229,7 +256,7 @@ int i2c_byte_read(i2c_t *obj, int last);
229256 *
230257 * @param obj The I2C object
231258 * @param data Byte to be written
232- * @return 0 if NAK was received, 1 if ACK was received, 2 for timeout.
259+ * @return 0 if NAK was received, 1 if ACK was received, 2 for timeout, or 3 for other error .
233260 */
234261int i2c_byte_write (i2c_t * obj , int data );
235262
0 commit comments