Skip to content

Commit d035344

Browse files
committed
A little more cleanup and styling fixes
1 parent 4170177 commit d035344

File tree

5 files changed

+24
-26
lines changed

5 files changed

+24
-26
lines changed

tracking/imu/bmi160.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <furi_hal.h>
21
#include "imu.h"
32
#include "../../lib/bmi160-api/bmi160.h"
43

tracking/imu/imu.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,49 @@ struct imu_t* imu_types[] = {
1414

1515
static const int imu_count = sizeof(imu_types) / sizeof(struct imu_t*);
1616

17-
struct imu_t* imu_found;
17+
static struct imu_t* imu_found;
1818

19-
bool imu_begin() {
20-
furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
21-
if (imu_found == NULL) {
22-
imu_found = find_imu();
19+
struct imu_t* find_imu() {
20+
unsigned int i;
21+
for(i = 0; i < imu_count; i++) {
22+
if(furi_hal_i2c_is_device_ready(&furi_hal_i2c_handle_external, imu_types[i]->address, 50)) {
23+
FURI_LOG_E(IMU_TAG, "found i2c device address 0x%X", imu_types[i]->address);
24+
return imu_types[i];
25+
}
2326
}
27+
return NULL;
28+
}
29+
30+
bool imu_begin() {
31+
if (imu_found != NULL)
32+
return true;
2433

2534
bool ret = false;
35+
furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
36+
imu_found = find_imu();
37+
2638
if (imu_found != NULL) {
2739
FURI_LOG_E(IMU_TAG, "Found Device %s", imu_found->name);
2840
ret = imu_found->begin();
2941
}
42+
3043
furi_hal_i2c_release(&furi_hal_i2c_handle_external);
3144
return ret;
3245
}
3346

3447
void imu_end() {
35-
if (imu_found == NULL) return;
48+
if (imu_found == NULL)
49+
return;
3650
furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
3751
imu_found->end();
3852
furi_hal_i2c_release(&furi_hal_i2c_handle_external);
3953
}
4054

4155
int imu_read(double* vec) {
42-
if (imu_found == NULL) return 0;
56+
if (imu_found == NULL)
57+
return 0;
4358
furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
4459
int ret = imu_found->read(vec);
4560
furi_hal_i2c_release(&furi_hal_i2c_handle_external);
4661
return ret;
4762
}
48-
49-
struct imu_t* find_imu() {
50-
unsigned int i;
51-
for(i = 0; i < imu_count; i++) {
52-
if(furi_hal_i2c_is_device_ready(&furi_hal_i2c_handle_external, imu_types[i]->address, 50)) {
53-
FURI_LOG_E(IMU_TAG, "found i2c device address 0x%X", imu_types[i]->address);
54-
return imu_types[i];
55-
}
56-
}
57-
return NULL;
58-
}

tracking/imu/imu.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ static const double GRAVITY = 9.81;
2626
bool imu_begin();
2727
void imu_end();
2828
int imu_read(double* vec);
29-
struct imu_t* get_imu(uint8_t address);
30-
unsigned int imu_scan_i2c();
31-
struct imu_t* find_imu();
3229

3330
#ifdef __cplusplus
3431
}

tracking/imu/lsm6ds3trc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <furi_hal.h>
21
#include "imu.h"
32
#include "../../lib/lsm6ds3tr-api/lsm6ds3tr-c_reg.h"
43

@@ -14,7 +13,8 @@ int32_t lsm6ds3trc_write_i2c(void* handle, uint8_t reg_addr, const uint8_t* data
1413
}
1514

1615
int32_t lsm6ds3trc_read_i2c(void* handle, uint8_t reg_addr, uint8_t* read_data, uint16_t len) {
17-
if(furi_hal_i2c_read_mem(handle, LSM6DS3_DEV_ADDRESS, reg_addr, read_data, len, 50)) return 0;
16+
if(furi_hal_i2c_read_mem(handle, LSM6DS3_DEV_ADDRESS, reg_addr, read_data, len, 50))
17+
return 0;
1818
return -1;
1919
}
2020

tracking/imu/lsm6dso.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <furi_hal.h>
21
#include "imu.h"
32
#include "../../lib/lsm6dso-api/lsm6dso_reg.h"
43

@@ -49,7 +48,6 @@ bool lsm6dso_begin() {
4948
lsm6dso_xl_data_rate_set(&lsm6dso_ctx, LSM6DSO_XL_ODR_104Hz);
5049
lsm6dso_xl_full_scale_set(&lsm6dso_ctx, LSM6DSO_4g);
5150
//lsm6dso_xl_lp1_bandwidth_set(&lsm6dso_ctx, LSM6DSO_XL_LP1_ODR_DIV_4);
52-
//lsm6dso_aux_gy_lp1_bandwidth_set() ???
5351

5452
lsm6dso_gy_data_rate_set(&lsm6dso_ctx, LSM6DSO_GY_ODR_104Hz);
5553
lsm6dso_gy_full_scale_set(&lsm6dso_ctx, LSM6DSO_2000dps);

0 commit comments

Comments
 (0)