Skip to content

Commit

Permalink
Clean up driver headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ginkage committed Jun 5, 2024
1 parent 79e9154 commit 4170177
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 91 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ See early prototype [in action](https://www.youtube.com/watch?v=DdxAmmsYfMA).

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

Note: in fact, some other IMU chips are also supported.
It's detected via the first found I2C Address.

| Chip | Expected I2C Address |
|:--------:|:--------------------:|
| BMI160 | 0x69 |
| LSM6DS3 | 0x6A |
| LSM6DSO | 0x6B |

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.

Original idea:
Expand Down
6 changes: 3 additions & 3 deletions tracking/imu/bmi160.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "bmi160.h"
#include <furi_hal.h>
#include "imu.h"
#include "../../lib/bmi160-api/bmi160.h"

#define BMI160_TAG "BMI160"
#define BMI160_DEV_ADDR (0x69 << 1)
Expand Down Expand Up @@ -89,5 +91,3 @@ struct imu_t imu_bmi160 = {
bmi160_read,
BMI160_TAG
};


17 changes: 0 additions & 17 deletions tracking/imu/bmi160.h

This file was deleted.

19 changes: 12 additions & 7 deletions tracking/imu/imu.c
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
#include "imu.h"

#define IMU_TAG "IMU_H"

extern struct imu_t imu_bmi160;
extern struct imu_t imu_lsm6ds3trc;
extern struct imu_t imu_lsm6dso;

struct imu_t* imu_types[] = {
&imu_bmi160,
&imu_lsm6ds3trc,
&imu_lsm6dso
};

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

struct imu_t* imu_found;

bool imu_begin() {
furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
if (imu_found == NULL) {
imu_found = find_imu();
if (imu_found == NULL) {
furi_hal_i2c_release(&furi_hal_i2c_handle_external);
return false;
}
FURI_LOG_E(IMU_TAG, "Found Device %s", imu_found->name);
}
bool ret = 0;

bool ret = false;
if (imu_found != NULL) {
FURI_LOG_E(IMU_TAG, "Found Device %s", imu_found->name);
ret = imu_found->begin();
}
furi_hal_i2c_release(&furi_hal_i2c_handle_external);
Expand All @@ -43,7 +48,7 @@ int imu_read(double* vec) {

struct imu_t* find_imu() {
unsigned int i;
for(i = 0; i < sizeof(imu_types) / sizeof(struct imu_t*); i++) {
for(i = 0; i < imu_count; i++) {
if(furi_hal_i2c_is_device_ready(&furi_hal_i2c_handle_external, imu_types[i]->address, 50)) {
FURI_LOG_E(IMU_TAG, "found i2c device address 0x%X", imu_types[i]->address);
return imu_types[i];
Expand Down
16 changes: 9 additions & 7 deletions tracking/imu/imu.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@
#include <stdbool.h>
#include <furi_hal.h>

#include "imu_t.h"
#include "bmi160.h"
#include "lsm6ds3trc.h"
#include "lsm6dso.h"

#ifdef __cplusplus
extern "C" {
#endif

struct imu_t
{
unsigned int address;
bool (*begin)(void);
void (*end)(void);
int (*read)(double* vec);
char* name;
};

#define ACC_DATA_READY (1 << 0)
#define GYR_DATA_READY (1 << 1)

#define IMU_TAG "IMU_H"

static const double DEG_TO_RAD = 0.017453292519943295769236907684886;
static const double GRAVITY = 9.81;

Expand Down
13 changes: 0 additions & 13 deletions tracking/imu/imu_t.h

This file was deleted.

6 changes: 4 additions & 2 deletions tracking/imu/lsm6ds3trc.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "lsm6ds3trc.h"
#include <furi_hal.h>
#include "imu.h"
#include "../../lib/lsm6ds3tr-api/lsm6ds3tr-c_reg.h"

#define LSM6DS3_TAG "LSM6DS3"
#define LSM6DS3_DEV_ADDRESS (0x6A << 1)
Expand Down Expand Up @@ -92,4 +94,4 @@ struct imu_t imu_lsm6ds3trc = {
lsm6ds3trc_end,
lsm6ds3trc_read,
LSM6DS3_TAG
};
};
22 changes: 0 additions & 22 deletions tracking/imu/lsm6ds3trc.h

This file was deleted.

4 changes: 3 additions & 1 deletion tracking/imu/lsm6dso.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "lsm6dso.h"
#include <furi_hal.h>
#include "imu.h"
#include "../../lib/lsm6dso-api/lsm6dso_reg.h"

#define LSM6DSO_TAG "LSM6DO"
#define LSM6DSO_DEV_ADDRESS (0x6B << 1)
Expand Down
19 changes: 0 additions & 19 deletions tracking/imu/lsm6dso.h

This file was deleted.

0 comments on commit 4170177

Please sign in to comment.