Skip to content

Commit 4170177

Browse files
committed
Clean up driver headers
1 parent 79e9154 commit 4170177

File tree

10 files changed

+40
-91
lines changed

10 files changed

+40
-91
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ See early prototype [in action](https://www.youtube.com/watch?v=DdxAmmsYfMA).
3636

3737
The custom module is using Bosch BMI160 accelerometer/gyroscope chip connected via I2C.
3838

39+
Note: in fact, some other IMU chips are also supported.
40+
It's detected via the first found I2C Address.
41+
42+
| Chip | Expected I2C Address |
43+
|:--------:|:--------------------:|
44+
| BMI160 | 0x69 |
45+
| LSM6DS3 | 0x6A |
46+
| LSM6DSO | 0x6B |
47+
3948
Take a look into the [schematic](https://github.com/ginkage/FlippAirMouse/tree/main/schematic) folder for Gerber, BOM and CPL files, so you can order directly from JLCPCB.
4049

4150
Original idea:

tracking/imu/bmi160.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#include "bmi160.h"
1+
#include <furi_hal.h>
2+
#include "imu.h"
3+
#include "../../lib/bmi160-api/bmi160.h"
24

35
#define BMI160_TAG "BMI160"
46
#define BMI160_DEV_ADDR (0x69 << 1)
@@ -89,5 +91,3 @@ struct imu_t imu_bmi160 = {
8991
bmi160_read,
9092
BMI160_TAG
9193
};
92-
93-

tracking/imu/bmi160.h

Lines changed: 0 additions & 17 deletions
This file was deleted.

tracking/imu/imu.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
#include "imu.h"
22

3+
#define IMU_TAG "IMU_H"
4+
5+
extern struct imu_t imu_bmi160;
6+
extern struct imu_t imu_lsm6ds3trc;
7+
extern struct imu_t imu_lsm6dso;
8+
39
struct imu_t* imu_types[] = {
410
&imu_bmi160,
511
&imu_lsm6ds3trc,
612
&imu_lsm6dso
713
};
814

15+
static const int imu_count = sizeof(imu_types) / sizeof(struct imu_t*);
16+
917
struct imu_t* imu_found;
1018

1119
bool imu_begin() {
1220
furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
1321
if (imu_found == NULL) {
1422
imu_found = find_imu();
15-
if (imu_found == NULL) {
16-
furi_hal_i2c_release(&furi_hal_i2c_handle_external);
17-
return false;
18-
}
19-
FURI_LOG_E(IMU_TAG, "Found Device %s", imu_found->name);
2023
}
21-
bool ret = 0;
24+
25+
bool ret = false;
2226
if (imu_found != NULL) {
27+
FURI_LOG_E(IMU_TAG, "Found Device %s", imu_found->name);
2328
ret = imu_found->begin();
2429
}
2530
furi_hal_i2c_release(&furi_hal_i2c_handle_external);
@@ -43,7 +48,7 @@ int imu_read(double* vec) {
4348

4449
struct imu_t* find_imu() {
4550
unsigned int i;
46-
for(i = 0; i < sizeof(imu_types) / sizeof(struct imu_t*); i++) {
51+
for(i = 0; i < imu_count; i++) {
4752
if(furi_hal_i2c_is_device_ready(&furi_hal_i2c_handle_external, imu_types[i]->address, 50)) {
4853
FURI_LOG_E(IMU_TAG, "found i2c device address 0x%X", imu_types[i]->address);
4954
return imu_types[i];

tracking/imu/imu.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44
#include <stdbool.h>
55
#include <furi_hal.h>
66

7-
#include "imu_t.h"
8-
#include "bmi160.h"
9-
#include "lsm6ds3trc.h"
10-
#include "lsm6dso.h"
11-
127
#ifdef __cplusplus
138
extern "C" {
149
#endif
1510

11+
struct imu_t
12+
{
13+
unsigned int address;
14+
bool (*begin)(void);
15+
void (*end)(void);
16+
int (*read)(double* vec);
17+
char* name;
18+
};
19+
1620
#define ACC_DATA_READY (1 << 0)
1721
#define GYR_DATA_READY (1 << 1)
1822

19-
#define IMU_TAG "IMU_H"
20-
2123
static const double DEG_TO_RAD = 0.017453292519943295769236907684886;
2224
static const double GRAVITY = 9.81;
2325

tracking/imu/imu_t.h

Lines changed: 0 additions & 13 deletions
This file was deleted.

tracking/imu/lsm6ds3trc.c

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

35
#define LSM6DS3_TAG "LSM6DS3"
46
#define LSM6DS3_DEV_ADDRESS (0x6A << 1)
@@ -92,4 +94,4 @@ struct imu_t imu_lsm6ds3trc = {
9294
lsm6ds3trc_end,
9395
lsm6ds3trc_read,
9496
LSM6DS3_TAG
95-
};
97+
};

tracking/imu/lsm6ds3trc.h

Lines changed: 0 additions & 22 deletions
This file was deleted.

tracking/imu/lsm6dso.c

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

35
#define LSM6DSO_TAG "LSM6DO"
46
#define LSM6DSO_DEV_ADDRESS (0x6B << 1)

tracking/imu/lsm6dso.h

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)