mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Merge pull request #2283 from kwagyeman/kwabena/fix_mlx90640
ports/mimxrt: Fix I2C for the MLX90640 driver.
This commit is contained in:
commit
547859cb00
@ -35,17 +35,24 @@ int MLX90640_I2CGeneralReset()
|
|||||||
|
|
||||||
int MLX90640_I2CRead(uint8_t slaveAddr, uint16_t startAddress, uint16_t nMemAddressRead, uint16_t *data)
|
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;
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startAddress += read_size;
|
||||||
|
n -= read_size;
|
||||||
|
d += read_size;
|
||||||
|
}
|
||||||
|
|
||||||
for(int i=0; i<nMemAddressRead; i++) {
|
for(int i=0; i<nMemAddressRead; i++) {
|
||||||
data[i] = __REVSH(data[i]);
|
data[i] = __REVSH(data[i]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,17 +35,24 @@ int MLX90641_I2CGeneralReset(void)
|
|||||||
|
|
||||||
int MLX90641_I2CRead(uint8_t slaveAddr, uint16_t startAddress, uint16_t nMemAddressRead, uint16_t *data)
|
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;
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startAddress += read_size;
|
||||||
|
n -= read_size;
|
||||||
|
d += read_size;
|
||||||
|
}
|
||||||
|
|
||||||
for(int i=0; i<nMemAddressRead; i++) {
|
for(int i=0; i<nMemAddressRead; i++) {
|
||||||
data[i] = __REVSH(data[i]);
|
data[i] = __REVSH(data[i]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -127,4 +127,6 @@ struct { \
|
|||||||
lpspi_transfer_t xfer_descr; \
|
lpspi_transfer_t xfer_descr; \
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define OMV_I2C_MAX_8BIT_XFER (1024U)
|
||||||
|
#define OMV_I2C_MAX_16BIT_XFER (512U)
|
||||||
#endif // __OMV_PORTCONFIG_H__
|
#endif // __OMV_PORTCONFIG_H__
|
||||||
|
|||||||
@ -31,4 +31,8 @@ typedef uint32_t omv_gpio_t;
|
|||||||
|
|
||||||
// omv_i2c_dev_t definition
|
// omv_i2c_dev_t definition
|
||||||
typedef nrfx_twi_t omv_i2c_dev_t;
|
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__
|
#endif // __OMV_PORTCONFIG_H__
|
||||||
|
|||||||
@ -98,4 +98,6 @@ typedef I2C_HandleTypeDef *omv_i2c_dev_t;
|
|||||||
DMA_HandleTypeDef dma_descr_rx; \
|
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__
|
#endif // __OMV_PORTCONFIG_H__
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user