ESP-IDF platform fix for I2C only: sending 0 bytes.
If, for the ESP-IDF platform, an attempt was made to send 0 bytes of I2C data, uPortI2cControllerSendReceive() would end up sending -1 bytes of I2C data instead, which is not good.  This is now fixed.
@@ -169,10 +169,13 @@ static int32_t receive(int32_t handle, uint16_t address, char *pData, size_t siz
}
}
if (errorCodeOrLength == (int32_t) U_ERROR_COMMON_SUCCESS) {
- errorCodeOrLength = (int32_t) U_ERROR_COMMON_PLATFORM;
// Now read the data, the last byte with a nack, and execute it
- if ((i2c_master_read(cmd, (uint8_t *) pData, size - 1, I2C_MASTER_ACK) == ESP_OK) &&
- (i2c_master_read_byte(cmd, (uint8_t *) (pData + size - 1), I2C_MASTER_LAST_NACK) == ESP_OK) &&
+ if ((size > 0) &&
+ ((i2c_master_read(cmd, (uint8_t *) pData, size - 1, I2C_MASTER_ACK) != ESP_OK) ||
+ (i2c_master_read_byte(cmd, (uint8_t *) (pData + size - 1), I2C_MASTER_LAST_NACK) != ESP_OK))) {
+ errorCodeOrLength = (int32_t) U_ERROR_COMMON_PLATFORM;
+ }
+ if ((errorCodeOrLength == (int32_t) U_ERROR_COMMON_SUCCESS) &&
(i2c_master_stop(cmd) == ESP_OK) &&
(i2c_master_cmd_begin(handle, cmd, 0) == ESP_OK)) {
errorCodeOrLength = (int32_t) size;
