Merge pull request #2283 from kwagyeman/kwabena/fix_mlx90640

ports/mimxrt: Fix I2C for the MLX90640 driver.
This commit is contained in:
Ibrahim Abdelkader 2024-07-16 12:04:19 +02:00 committed by GitHub
commit 547859cb00
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 36 additions and 14 deletions

View File

@ -35,17 +35,24 @@ int MLX90640_I2CGeneralReset()
int MLX90640_I2CRead(uint8_t slaveAddr, uint16_t startAddress, uint16_t nMemAddressRead, uint16_t *data)
{
startAddress = __REVSH(startAddress);
for (uint16_t n = nMemAddressRead, *d = data; n; ) {
uint16_t write_address = __REVSH(startAddress);
uint16_t read_size = n > OMV_I2C_MAX_16BIT_XFER ? OMV_I2C_MAX_16BIT_XFER : n;
if (omv_i2c_write_bytes(bus, (slaveAddr<<1), (uint8_t *) &startAddress, 2, OMV_I2C_XFER_NO_STOP) != 0) {
if (omv_i2c_write_bytes(bus, (slaveAddr<<1), (uint8_t *) &write_address, 2, OMV_I2C_XFER_NO_STOP) != 0) {
return -1;
}
if (omv_i2c_read_bytes(bus, (slaveAddr<<1), (uint8_t *) data, nMemAddressRead*2, OMV_I2C_XFER_NO_FLAGS) != 0) {
if (omv_i2c_read_bytes(bus, (slaveAddr<<1), (uint8_t *) d, read_size*2, OMV_I2C_XFER_NO_FLAGS) != 0) {
return -1;
}
startAddress += read_size;
n -= read_size;
d += read_size;
}
for(int i=0; i<nMemAddressRead; i++) {
data[i] = __REVSH(data[i]);
}

View File

@ -35,17 +35,24 @@ int MLX90641_I2CGeneralReset(void)
int MLX90641_I2CRead(uint8_t slaveAddr, uint16_t startAddress, uint16_t nMemAddressRead, uint16_t *data)
{
startAddress = __REVSH(startAddress);
for (uint16_t n = nMemAddressRead, *d = data; n; ) {
uint16_t write_address = __REVSH(startAddress);
uint16_t read_size = n > OMV_I2C_MAX_16BIT_XFER ? OMV_I2C_MAX_16BIT_XFER : n;
if (omv_i2c_write_bytes(bus, (slaveAddr<<1), (uint8_t *) &startAddress, 2, OMV_I2C_XFER_NO_STOP) != 0) {
if (omv_i2c_write_bytes(bus, (slaveAddr<<1), (uint8_t *) &write_address, 2, OMV_I2C_XFER_NO_STOP) != 0) {
return -1;
}
if (omv_i2c_read_bytes(bus, (slaveAddr<<1), (uint8_t *) data, nMemAddressRead*2, OMV_I2C_XFER_NO_FLAGS) != 0) {
if (omv_i2c_read_bytes(bus, (slaveAddr<<1), (uint8_t *) d, read_size*2, OMV_I2C_XFER_NO_FLAGS) != 0) {
return -1;
}
startAddress += read_size;
n -= read_size;
d += read_size;
}
for(int i=0; i<nMemAddressRead; i++) {
data[i] = __REVSH(data[i]);
}

View File

@ -127,4 +127,6 @@ struct { \
lpspi_transfer_t xfer_descr; \
};
#define OMV_I2C_MAX_8BIT_XFER (1024U)
#define OMV_I2C_MAX_16BIT_XFER (512U)
#endif // __OMV_PORTCONFIG_H__

View File

@ -31,4 +31,8 @@ typedef uint32_t omv_gpio_t;
// omv_i2c_dev_t definition
typedef nrfx_twi_t omv_i2c_dev_t;
#define OMV_I2C_MAX_8BIT_XFER (65535U)
#define OMV_I2C_MAX_16BIT_XFER (65535U)
#endif // __OMV_PORTCONFIG_H__

View File

@ -98,4 +98,6 @@ typedef I2C_HandleTypeDef *omv_i2c_dev_t;
DMA_HandleTypeDef dma_descr_rx; \
};
#define OMV_I2C_MAX_8BIT_XFER (65536U - 16U)
#define OMV_I2C_MAX_16BIT_XFER (65536U - 8U)
#endif // __OMV_PORTCONFIG_H__