|
|
@@ -1,24 +1,25 @@
|
|
|
-#include "imu_lsm6ds3trc.h"
|
|
|
+#include "lsm6ds3trc.h"
|
|
|
|
|
|
-static const double LSM6DS3_DEG_TO_RAD = 0.017453292519943295769236907684886;
|
|
|
+#define LSM6DS3_TAG "LSM6DS3"
|
|
|
+#define LSM6DS3_DEV_ADDRESS (0x6A << 1)
|
|
|
|
|
|
stmdev_ctx_t lsm6ds3trc_ctx;
|
|
|
|
|
|
int32_t lsm6ds3trc_write_i2c(void* handle, uint8_t reg_addr, const uint8_t* data, uint16_t len) {
|
|
|
- if(furi_hal_i2c_write_mem(handle, LSM6DS3_ADDRESS, reg_addr, (uint8_t*)data, len, 50))
|
|
|
+ if(furi_hal_i2c_write_mem(handle, LSM6DS3_DEV_ADDRESS, reg_addr, (uint8_t*)data, len, 50))
|
|
|
return 0;
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
int32_t lsm6ds3trc_read_i2c(void* handle, uint8_t reg_addr, uint8_t* read_data, uint16_t len) {
|
|
|
- if(furi_hal_i2c_read_mem(handle, LSM6DS3_ADDRESS, reg_addr, read_data, len, 50)) return 0;
|
|
|
+ if(furi_hal_i2c_read_mem(handle, LSM6DS3_DEV_ADDRESS, reg_addr, read_data, len, 50)) return 0;
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
bool lsm6ds3trc_begin() {
|
|
|
FURI_LOG_I(LSM6DS3_TAG, "Init LSM6DS3TR-C");
|
|
|
|
|
|
- if(!furi_hal_i2c_is_device_ready(&furi_hal_i2c_handle_external, LSM6DS3_ADDRESS, 50)) {
|
|
|
+ if(!furi_hal_i2c_is_device_ready(&furi_hal_i2c_handle_external, LSM6DS3_DEV_ADDRESS, 50)) {
|
|
|
FURI_LOG_E(LSM6DS3_TAG, "Not ready");
|
|
|
return false;
|
|
|
}
|
|
|
@@ -76,11 +77,19 @@ int lsm6ds3trc_read(double* vec) {
|
|
|
|
|
|
if(reg.status_reg.gda) {
|
|
|
lsm6ds3tr_c_angular_rate_raw_get(&lsm6ds3trc_ctx, data);
|
|
|
- vec[5] = (double)lsm6ds3tr_c_from_fs2000dps_to_mdps(data[0]) * LSM6DS3_DEG_TO_RAD / 1000;
|
|
|
- vec[3] = (double)lsm6ds3tr_c_from_fs2000dps_to_mdps(data[1]) * LSM6DS3_DEG_TO_RAD / 1000;
|
|
|
- vec[4] = (double)lsm6ds3tr_c_from_fs2000dps_to_mdps(data[2]) * LSM6DS3_DEG_TO_RAD / 1000;
|
|
|
+ vec[5] = (double)lsm6ds3tr_c_from_fs2000dps_to_mdps(data[0]) * DEG_TO_RAD / 1000;
|
|
|
+ vec[3] = (double)lsm6ds3tr_c_from_fs2000dps_to_mdps(data[1]) * DEG_TO_RAD / 1000;
|
|
|
+ vec[4] = (double)lsm6ds3tr_c_from_fs2000dps_to_mdps(data[2]) * DEG_TO_RAD / 1000;
|
|
|
ret |= GYR_DATA_READY;
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
|
+
|
|
|
+struct imu_t imu_lsm6ds3trc = {
|
|
|
+ LSM6DS3_DEV_ADDRESS,
|
|
|
+ lsm6ds3trc_begin,
|
|
|
+ lsm6ds3trc_end,
|
|
|
+ lsm6ds3trc_read,
|
|
|
+ LSM6DS3_TAG
|
|
|
+};
|