Skip to content

Commit 9fce4ef

Browse files
Merge pull request #5 from stephendpmurphy/dev
Release dev into master branch
2 parents 26d707e + 6014d53 commit 9fce4ef

File tree

4 files changed

+275
-71
lines changed

4 files changed

+275
-71
lines changed

README.md

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
# ICM-20948 9-Axis MEMS Motion Tracking Sensor Driver
22
[![Release](https://img.shields.io/github/release/stephendpmurphy/icm20948.svg?style=flat-square)](https://github.com/stephendpmurphy/icm20948/releases/latest)
33
![CI](https://github.com/stephendpmurphy/icm20948/workflows/CI/badge.svg)
4+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
45

6+
C Driver for the IC-20948 9-Axis Telemetry sensor. This driver can be included directly into a developers source or a static library can be created and then linked against. Development is done on the **dev** branch, and official releases can be found on the **master** branch. Releases will be made on a ~monthly basis assuming no driver breaking bugs are found. Otherwise, a fix will be released to **master** ASAP.
7+
8+
## Currently supported features
9+
The currently supported features are below. The API is written to greatly simplify the implementation of this IC, and thus only a small amount of control is given to the end-user. In the future, settings/config will be added to allow a user to change sample rates, resolution and more for each sensor in this part.
510
</br>
6-
C Driver for the IC-20948 9-Axis Telemetry sensor. This driver can be included directly into a developers source or a static library can be created and then linked against.
7-
</br></br>
8-
Development is done on the *dev* branch, and official releases can be found on the *master* branch. Releases will be made on a ~monthly basis assuming no driver breaking bugs are found. Otherwise, a fix will be released to *master* ASAP.
11+
Currently supported features:
12+
* Accel
13+
* +-2G
14+
* +-4G
15+
* +-8G
16+
* +-16G
17+
* Gyro
18+
* +-250DPS
19+
* +-500DPS
20+
* +-1000DPS
21+
* +-2000DPS
922

1023
## Retrieving the Source
11-
The source is located on Github and can be either downloaded and included directly into a developers source directoriy or the developer can add this repo as a submodule into their source (The latter is the preferred method).
24+
The source is located on Github and can be either downloaded and included directly into a developers source OR the developer can add this repo as a submodule into their project directory (The latter is the preferred method).
1225

1326
To include the driver as a git submodule
1427
```bash
@@ -18,7 +31,13 @@ $ git submodule add https://github.com/stephendpmurphy/icm20948.git
1831

1932
## Integration
2033
#### Creating & Linking against a static library
21-
To create a static library to link against, you must first source your build environment and ensure the **CC** environment variable is set to your desired toolchain. Once your cross-compiler is properly setup. Execute the following commands:
34+
To create a static library to link against, you must first source your build environment and ensure the **CC** environment variable is set to your desired toolchain. Below is an example of sourcing the **AVR** toolchain before compiling.
35+
```bash
36+
$ export CC=/usr/bin/avr-gcc
37+
$ export CXX=/usr/bin/avr-g++
38+
```
39+
40+
Once your cross-compiler is properly setup. Execute the following commands:
2241
```bash
2342
$ mkdir build && cd build
2443
$ cmake ..
@@ -53,15 +72,15 @@ Example application and main can be found below:
5372

5473
int8_t usr_write(uint8_t addr, uint8_t *data, uint32_t len) {
5574
icm20948_return_code_t ret = ICM20948_RET_OK;
56-
75+
5776
// Assert the CS
5877

5978
// Write the address
6079

6180
// Write the data from the provided data buffer
6281

6382
// De-assert the CS
64-
83+
6584
return ret;
6685
}
6786

@@ -80,7 +99,7 @@ int8_t usr_read(uint8_t addr, uint8_t *data, uint32_t len) {
8099
}
81100

82101
void usr_delay_us(uint32_t period) {
83-
// Delay for the requested period
102+
// uS Delay for the requested period
84103
}
85104

86105
int main(void) {
@@ -92,19 +111,25 @@ int main(void) {
92111
// Init the device function pointers
93112
ret = icm20948_init(usr_read, usr_write, usr_delay_us);
94113

114+
// Check if we successfully stored the function poiners provided
95115
if( ret == ICM20948_RET_OK ) {
96-
// Enable the gyro
97-
settings.gyro_en = ICM20948_GYRO_ENABLE;
98-
// Enable the accelerometer
99-
settings.accel_en = ICM20948_ACCEL_ENABLE;
100-
// Apply the settings
116+
// Enable the Gyro
117+
settings.gyro.en = ICM20948_MOD_ENABLED;
118+
// Select the +-20000dps range
119+
settings.gyro.fs = ICM20948_GYRO_FS_SEL_2000DPS;
120+
// Enable the Accel
121+
settings.accel.en = ICM20948_MOD_ENABLED;
122+
// Select the +-2G range
123+
settings.accel.fs = ICM20948_ACCEL_FS_SEL_2G;
101124
ret = icm20948_applySettings(&settings);
102125
}
103126

104127
while(1) {
105-
// Retireve the Gyro data and store it in our gyro_data struct
128+
// Retrieve the Gyro data and store it in our gyro_data struct
129+
// Output is in dps (Degress per second)
106130
ret |= icm20948_getGyroData(&gyro_data);
107131
// Retrieve the Accel data and store it in our accel_data struct
132+
// Output is in mG
108133
ret |= icm20948_getAccelData(&accel_data);
109134
}
110135

@@ -113,4 +138,5 @@ int main(void) {
113138
```
114139
115140
## License
116-
MIT License
141+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) </br>
142+
License has been provided with this source and can be found in the [License](./LICENSE) file.

inc/icm20948_api.h

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,6 @@
3232
#include <stdint.h>
3333
#include <stdbool.h>
3434

35-
#define ICM20948_GYRO_ENABLE (true)
36-
#define ICM20948_GYRO_DISABLE (false)
37-
38-
#define ICM20948_ACCEL_ENABLE (true)
39-
#define ICM20948_ACCEL_DISABLE (false)
40-
41-
#define ICM20948_MAG_ENABLE (true)
42-
#define ICM20948_MAG_DISABLE (false)
43-
4435
typedef int8_t(*icm20948_read_fptr_t)(const uint8_t addr, uint8_t *data, const uint32_t len);
4536
typedef int8_t(*icm20948_write_fptr_t)(const uint8_t addr, const uint8_t *data, const uint32_t len);
4637
typedef void(*icm20948_delay_us_fptr_t)(uint32_t period);
@@ -54,10 +45,43 @@ typedef enum {
5445
ICM20948_RET_TIMEOUT = -5
5546
} icm20948_return_code_t;
5647

48+
typedef enum {
49+
ICM20948_MOD_DISABLED = 0x00,
50+
ICM20948_MOD_ENABLED
51+
} icm20948_mod_enable_t;
52+
53+
typedef enum {
54+
ICM20948_GYRO_FS_SEL_250DPS = 0x00,
55+
ICM20948_GYRO_FS_SEL_500DPS = 0x01,
56+
ICM20948_GYRO_FS_SEL_1000DPS = 0x02,
57+
ICM20948_GYRO_FS_SEL_2000DPS = 0x03
58+
} icm20948_gyro_full_scale_select_t;
59+
60+
typedef struct {
61+
icm20948_mod_enable_t en;
62+
icm20948_gyro_full_scale_select_t fs;
63+
} icm20948_gyro_settings_t;
64+
65+
typedef enum {
66+
ICM20948_ACCEL_FS_SEL_2G = 0x00,
67+
ICM20948_ACCEL_FS_SEL_4G = 0x01,
68+
ICM20948_ACCEL_FS_SEL_8G = 0x02,
69+
ICM20948_ACCEL_FS_SEL_16G = 0x03
70+
} icm20948_accel_full_scale_select_t;
71+
5772
typedef struct {
58-
bool gyro_en;
59-
bool accel_en;
60-
bool mag_en;
73+
icm20948_mod_enable_t en;
74+
icm20948_accel_full_scale_select_t fs;
75+
} icm20948_accel_settings_t;
76+
77+
typedef struct {
78+
icm20948_mod_enable_t en;
79+
} icm20948_mag_settings_t;
80+
81+
typedef struct {
82+
icm20948_gyro_settings_t gyro;
83+
icm20948_accel_settings_t accel;
84+
icm20948_mag_settings_t mag;
6185
} icm20948_settings_t;
6286

6387
typedef struct {
@@ -78,9 +102,45 @@ typedef struct {
78102
int16_t z;
79103
} icm20948_mag_t;
80104

105+
/*!
106+
* @brief This API initializes the ICM20948 comms interface, and then does a read from the device
107+
* to verify working comms
108+
*
109+
* @param[in] r: Function pointer to the developers SPI read function
110+
* @param[in] w: Function pointer to the developers SPI write function
111+
* @param[in] delay: Function pointer to the developers micro-second delay function
112+
*
113+
* @return Returns the status of initialization
114+
*/
81115
icm20948_return_code_t icm20948_init(icm20948_read_fptr_t r, icm20948_write_fptr_t w, icm20948_delay_us_fptr_t delay);
116+
117+
/*!
118+
* @brief This API applys the developers settings for configuring the ICM20948 components
119+
*
120+
* @param[in] newSettings: Pointer to the new ICM20948 settings to be applied
121+
*
122+
* @return Returns the status of applying settings
123+
*/
82124
icm20948_return_code_t icm20948_applySettings(icm20948_settings_t *newSettings);
125+
126+
/*!
127+
* @brief This API retrieves the current gyro data from the device
128+
*
129+
* @param[in] gyro: Pointer to the gyro data struct where the new samples
130+
* should be placed
131+
*
132+
* @return Returns the status of reading gyro data
133+
*/
83134
icm20948_return_code_t icm20948_getGyroData(icm20948_gyro_t *gyro);
135+
136+
/*!
137+
* @brief This API retrieves the current accel data from the device
138+
*
139+
* @param[in] accel: Pointer to the accel data struct where the new samples
140+
* should be placed
141+
*
142+
* @return Returns the status of reading accel data
143+
*/
84144
icm20948_return_code_t icm20948_getAccelData(icm20948_accel_t *accel);
85145

86146
#endif // _ICM20948_API_H_

0 commit comments

Comments
 (0)