mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-30 18:06:39 +08:00
RM3100: enable I2C (#11038)
This commit is contained in:
committed by
Daniel Agar
parent
1699c577c3
commit
490eeeb9d9
@@ -59,7 +59,8 @@
|
|||||||
* RM3100 internal constants and data structures.
|
* RM3100 internal constants and data structures.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define RM3100_CONVERSION_INTERVAL 6850 // Microseconds, corresponds to 146 Hz (cycle count 200 on 3 axis)
|
/* At 146 Hz we encounter errors, 100 Hz is safer */
|
||||||
|
#define RM3100_CONVERSION_INTERVAL 10000 // Microseconds, corresponds to 100 Hz (cycle count 200 on 3 axis)
|
||||||
#define UTESLA_TO_GAUSS 100.0f
|
#define UTESLA_TO_GAUSS 100.0f
|
||||||
#define RM3100_SENSITIVITY 75.0f
|
#define RM3100_SENSITIVITY 75.0f
|
||||||
|
|
||||||
|
|||||||
@@ -61,9 +61,6 @@
|
|||||||
|
|
||||||
#define RM3100_ADDRESS 0x20
|
#define RM3100_ADDRESS 0x20
|
||||||
|
|
||||||
#define DIR_READ (1<<7)
|
|
||||||
#define DIR_WRITE (0<<7)
|
|
||||||
|
|
||||||
class RM3100_I2C : public device::I2C
|
class RM3100_I2C : public device::I2C
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -143,8 +140,20 @@ RM3100_I2C::probe()
|
|||||||
int
|
int
|
||||||
RM3100_I2C::read(unsigned address, void *data, unsigned count)
|
RM3100_I2C::read(unsigned address, void *data, unsigned count)
|
||||||
{
|
{
|
||||||
uint8_t cmd = address | DIR_READ;
|
uint8_t cmd = address;
|
||||||
return transfer(&cmd, 1, (uint8_t *)data, count);
|
int ret;
|
||||||
|
|
||||||
|
/* We need a first transfer where we write the register to read */
|
||||||
|
ret = transfer(&cmd, 1, nullptr, 0);
|
||||||
|
|
||||||
|
if (ret != OK) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now we read the previously selected register */
|
||||||
|
ret = transfer(nullptr, 0, (uint8_t *)data, count);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -156,7 +165,7 @@ RM3100_I2C::write(unsigned address, void *data, unsigned count)
|
|||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf[0] = address | DIR_WRITE;
|
buf[0] = address;
|
||||||
memcpy(&buf[1], data, count);
|
memcpy(&buf[1], data, count);
|
||||||
|
|
||||||
return transfer(&buf[0], count + 1, nullptr, 0);
|
return transfer(&buf[0], count + 1, nullptr, 0);
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ rm3100::init(RM3100_BUS bus_id)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
PX4_INFO("Poll rate set to max (146 Hz)");
|
PX4_INFO("Poll rate set to 100 Hz");
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|||||||
Reference in New Issue
Block a user