Skip to content

Commit 7807024

Browse files
Feature/add process raw imu (#13)
* initial changes, will add changes to track Fs and update processed values * changing prints to remove duplicate box brackets * clang-format.yml addded to do post-commit * updating clang-format with something better for formatting * adding changes to process raw counts * clang-format changes * Auto format code with clang-format --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent c2b87eb commit 7807024

File tree

8 files changed

+276
-255
lines changed

8 files changed

+276
-255
lines changed

.clang-format

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,5 @@
1-
BasedOnStyle: Google
1+
BasedOnStyle: WebKit
22
IndentWidth: 2
3-
TabWidth: 4
3+
TabWidth: 2
44
UseTab: Never
55
ColumnLimit: 100
6-
BreakBeforeBraces: Allman
7-
AllowShortIfStatementsOnASingleLine: Never
8-
AllowShortLoopsOnASingleLine: false
9-
AlwaysBreakTemplateDeclarations: Yes
10-
BinPackArguments: false
11-
BinPackParameters: false
12-
ConstructorInitializerIndentWidth: 2
13-
ContinuationIndentWidth: 2
14-
DerivePointerAlignment: false
15-
PointerAlignment: Left
16-
IndentCaseLabels: true
17-
IndentSwitchCaseLabels: true
18-
SpaceAfterCStyleCast: true
19-
SortIncludes: Never
20-
IndentPPDirectives: AfterHash
21-
Cpp11BracedListStyle: true
22-
IncludeBlocks: Preserve
23-
SortUsingDeclarations: false
24-
25-
# Additional options for personal preferences
26-
SpaceBeforeParens: ControlStatements
27-
AllowAllParametersOfDeclarationOnNextLine: false
28-
KeepEmptyLinesAtTheStartOfBlocks: false
29-
BreakConstructorInitializersBeforeComma: false
30-
PenaltyBreakComment: 10
31-
PenaltyBreakFirstLessLess: 1000
32-
PenaltyExcessCharacter: 100
33-
PenaltyReturnTypeOnItsOwnLine: 200
34-
AlignAfterOpenBracket: Align
35-
AlignOperands: Align
36-
AlignTrailingComments: true
37-
BreakStringLiterals: true
38-
ReflowComments: true
39-
SpacesInParentheses: false
40-
SpacesInSquareBrackets: false
41-
SpaceBeforeRangeBasedForLoopColon: true

.github/workflows/clang-format.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: clang-format check
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
clang-format:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v2
18+
with:
19+
ref: ${{ github.head_ref }}
20+
21+
- name: Install clang-format
22+
run: sudo apt-get install -y clang-format
23+
24+
- name: Run clang-format on C++ files
25+
run: |
26+
find . -name '*.cpp' -o -name '*.h' | xargs clang-format -i
27+
28+
- name: Check for changes
29+
run: |
30+
git config --global user.name 'github-actions[bot]'
31+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
32+
if [[ `git status --porcelain` ]]; then
33+
git add .
34+
git commit -m "Auto format code with clang-format"
35+
git push origin HEAD:${{ github.head_ref }}
36+
else
37+
echo "No formatting needed"
38+
fi

inc/hw_config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#include "sys_common.h"
44

55
enum _hw_config_pins {
6-
QMI_SDA_PIN = 6,
7-
QMI_SCL_PIN = 7,
8-
};
6+
QMI_SDA_PIN = 6,
7+
QMI_SCL_PIN = 7,
8+
};
99

1010
status_t init_hardware();
1111
status_t deinit_hardware();

inc/interrupts.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
void setup_interrupts();
44
void enable_interrupts();
55
void disable_interrupts();
6-

inc/qmi8658.h

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define QMI8658_I2C_ADDR 0x6b
88
#define QMI_I2C_PORT i2c1
99
#define QMI_DEFAULT_REV_ID 0x7b
10+
1011
// Register addresses
1112
enum __QMI8658Registers {
1213
QMI_WHOAMI_REG = 0x00,
@@ -45,7 +46,7 @@ enum __QMI8658Registers {
4546
enum __QMICTRL1RegisterActions {
4647
QMIC1_SENSOR_DISABLE = 0x01,
4748
QMIC1_SPI_BE_EN = 0x20, // SPI read big endian enable
48-
QMIC1_AI_EN = 0x40, // auto increment enable
49+
QMIC1_AI_EN = 0x40, // auto increment enable
4950
QMIC1_SIM3_EN = 0x80,
5051
QMIC1_DEFAULT = QMIC1_SPI_BE_EN | QMIC1_AI_EN,
5152
};
@@ -108,13 +109,13 @@ enum __QMICTRL5RegisterActions {
108109
QMIC5_ACCL_LPF_MODE_2 = 0x02 << 1, // 5.32% BW
109110
QMIC5_ACCL_LPF_MODE_3 = 0x03 << 1, // 14.0% BW
110111
QMIC5_ACCL_LPF_ENABLE = 0x01 << 0, // Accl LPF Enable
111-
QMIC5_DEFAULT = QMIC5_GYRO_LPF_MODE_0 | QMIC5_GYRO_LPF_ENABLE |
112-
QMIC5_ACCL_LPF_MODE_0 | QMIC5_ACCL_LPF_ENABLE,
112+
QMIC5_DEFAULT
113+
= QMIC5_GYRO_LPF_MODE_0 | QMIC5_GYRO_LPF_ENABLE | QMIC5_ACCL_LPF_MODE_0 | QMIC5_ACCL_LPF_ENABLE,
113114
};
114115

115116
// Attitude Engine actions
116117
enum __QMICTRL6RegisterActions {
117-
QMIC6_SMOD_EN = 1 << 7, // requires sEN = 1
118+
QMIC6_SMOD_EN = 1 << 7, // requires sEN = 1
118119
QMIC6_ATT_ODR_0 = 0x00 << 0, // 1 Hz
119120
QMIC6_ATT_ODR_1 = 0x01 << 0, // 2 Hz
120121
QMIC6_ATT_ODR_2 = 0x02 << 0, // 4 Hz
@@ -127,21 +128,21 @@ enum __QMICTRL6RegisterActions {
127128

128129
// Sensor enable + data read configure
129130
enum __QMIC7RegisterActions {
130-
QMIC7_SS_EN = 0x01 << 7, // sync sample enable
131-
QMIC7_HSC_EN = 0x01 << 6, // high speed internal clock enable
131+
QMIC7_SS_EN = 0x01 << 7, // sync sample enable
132+
QMIC7_HSC_EN = 0x01 << 6, // high speed internal clock enable
132133
QMIC7_GYRO_SNOOZE_EN = 0x01 << 4, // gyro snooze mode enable
133-
QMIC7_ATT_EN = 0x01 << 3, // attitude engine enable
134-
QMIC7_MAG_EN = 0x01 << 2, // external mag enable
135-
QMIC7_GYRO_EN = 0x01 << 1, // gyro enable
136-
QMIC7_ACCL_EN = 0x01 << 0, // accel enable
134+
QMIC7_ATT_EN = 0x01 << 3, // attitude engine enable
135+
QMIC7_MAG_EN = 0x01 << 2, // external mag enable
136+
QMIC7_GYRO_EN = 0x01 << 1, // gyro enable
137+
QMIC7_ACCL_EN = 0x01 << 0, // accel enable
137138
QMIC7_DEFAULT = QMIC7_ACCL_EN | QMIC7_GYRO_EN,
138139
};
139140

140141
typedef struct _qmi_imu_pkt {
141142
int16_t raw[3];
142-
float x;
143-
float y;
144-
float z;
143+
double x;
144+
double y;
145+
double z;
145146
} imu_pkt_t;
146147

147148
typedef enum _qmi_odr_config {
@@ -157,32 +158,32 @@ typedef enum _qmi_odr_config {
157158
QMI_ODR_128HZ_LP, // illegal for gyro
158159
QMI_ODR_21HZ_LP,
159160
QMI_ODR_11HZ_LP,
160-
QMI_ODR_3HZ_LP,
161+
QMI_ODR_3HZ_LP,
161162
QMI_ATT_ODR_1HZ, // illegal for gyro, accel
162163
QMI_ATT_ODR_2HZ,
163164
QMI_ATT_ODR_4HZ,
164165
QMI_ATT_ODR_8HZ,
165166
QMI_ATT_ODR_16HZ,
166167
QMI_ATT_ODR_32HZ,
167168
QMI_ATT_ODR_64HZ,
168-
} qmi_odr_config_e;
169+
} qmi_odr_config_e;
169170

170171
typedef enum _qmi_dps_config {
171-
QMI_DPS_16 = 0,
172-
QMI_DPS_32,
173-
QMI_DPS_64,
174-
QMI_DPS_128,
175-
QMI_DPS_256,
176-
QMI_DPS_512,
177-
QMI_DPS_1024,
178-
QMI_DPS_2048,
172+
QMI_DPS_16 = 16,
173+
QMI_DPS_32 = 32,
174+
QMI_DPS_64 = 64,
175+
QMI_DPS_128 = 128,
176+
QMI_DPS_256 = 256,
177+
QMI_DPS_512 = 512,
178+
QMI_DPS_1024 = 1024,
179+
QMI_DPS_2048 = 2048,
179180
} qmi_dps_config_e;
180181

181182
typedef enum _qmi_g_config {
182-
QMI_G_2 = 0,
183-
QMI_G_4,
184-
QMI_G_8,
185-
QMI_G_16,
183+
QMI_G_2 = 2,
184+
QMI_G_4 = 4,
185+
QMI_G_8 = 8,
186+
QMI_G_16 = 16,
186187
} qmi_g_config_e;
187188

188189
typedef struct _qmi_enabled {
@@ -241,7 +242,7 @@ typedef struct _qmi_imu_config {
241242
qmi_component_config_t accl_config;
242243
} imu_config_t;
243244

244-
// TODO: add attitude pkt
245+
// TODO: add attitude pkt
245246
typedef struct _QMI8658State {
246247
qmi_chip_info_t chip_info;
247248
uint64_t imu_timestamp;
@@ -255,12 +256,10 @@ status_t qmi8658_configure();
255256
status_t qmi8658_enable_imu();
256257
status_t qmi8658_disable_imu();
257258
void qmi8658_print_raw();
259+
void qmi8658_process_raw();
258260
void qmi8658_interrupt_handler(uint gpio, uint32_t event_mask); // read data
259-
void qmi8658_read_xyz_raw(int16_t raw_acc_xyz[3], int16_t raw_gyro_xyz[3],
260-
uint64_t *ts);
261+
void qmi8658_read_xyz_raw(int16_t raw_acc_xyz[3], int16_t raw_gyro_xyz[3], uint64_t* ts);
261262
status_t qmi8658_verify_chip(qmi_chip_info_t* chip_info);
262263
status_t qmi8658_write_register(uint8_t reg, uint8_t data, uint8_t len);
263-
status_t qmi8658_read_register(uint8_t reg_addr, uint8_t *value);
264-
status_t qmi8658_read_nregisters(uint8_t start_addr, uint8_t *pData,
265-
uint8_t len);
266-
// status_t qmi8658_write_regs();
264+
status_t qmi8658_read_register(uint8_t reg_addr, uint8_t* value);
265+
status_t qmi8658_read_nregisters(uint8_t start_addr, uint8_t* pData, uint8_t len);

inc/sys_common.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
#pragma once
1+
#pragma once
22

33
typedef enum _status_t {
4-
STATUS_OK = 0,
5-
STATUS_FAIL_HW_COMM,
6-
STATUS_QMI_I2C_READ_FAIL,
7-
STATUS_QMI_CHIP_NOT_VERIFIED,
8-
STATUS_NULL_PTR_ERROR,
9-
STATUS_FAIL,
4+
STATUS_OK = 0,
5+
STATUS_FAIL_HW_COMM,
6+
STATUS_QMI_I2C_READ_FAIL,
7+
STATUS_QMI_CHIP_NOT_VERIFIED,
8+
STATUS_NULL_PTR_ERROR,
9+
STATUS_FAIL,
1010
} status_t;
1111

1212
typedef enum _print_type_e {
13-
DEBUG = 0,
14-
WARNING,
15-
ERROR,
16-
INFO,
13+
DEBUG = 0,
14+
WARNING,
15+
ERROR,
16+
INFO,
1717
} print_type_e;
1818

19-
void gprintf(print_type_e type, const char* format, ...);
19+
void gprintf(print_type_e type, const char* format, ...);
2020
void handle_status(status_t status, const char* format, ...);

main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int main() {
1414
uint64_t time_count;
1515
while (true) {
1616
/* move qmi init and configure to configure hardware */
17-
qmi8658_print_raw();
17+
qmi8658_process_raw();
1818
sleep_ms(10);
1919
}
2020
return 0;

0 commit comments

Comments
 (0)