Skip to content

Commit 9669cc4

Browse files
Fix incorrect radian to degrees, clear set config bit, widen FIFO length, add null check
1 parent 67f0622 commit 9669cc4

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

components/mpu6886/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ mpu6886_set_fifo_watermark(sensor, 512);
178178
uint16_t count;
179179
mpu6886_get_fifo_count(sensor, &count);
180180
uint8_t buf[512];
181-
mpu6886_read_fifo(sensor, buf, count > 512 ? 512 : (uint8_t)count);
181+
mpu6886_read_fifo(sensor, buf, count > 512 ? 512 : count);
182182
```
183183

184184
### Low-Power Mode

components/mpu6886/include/mpu6886.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ esp_err_t mpu6886_get_fifo_count(mpu6886_handle_t sensor, uint16_t *count);
491491
* - ESP_OK Success
492492
* - ESP_FAIL Fail
493493
*/
494-
esp_err_t mpu6886_read_fifo(mpu6886_handle_t sensor, uint8_t *buf, uint8_t len);
494+
esp_err_t mpu6886_read_fifo(mpu6886_handle_t sensor, uint8_t *buf, uint16_t len);
495495

496496
/**
497497
* @brief Set FIFO watermark threshold. Watermark interrupt disabled when threshold is 0.

components/mpu6886/mpu6886.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "mpu6886.h"
1515

1616
#define ALPHA 0.99f /*!< Weight of gyroscope */
17-
#define RAD_TO_DEG 57.27272727f /*!< Radians to degrees */
17+
#define RAD_TO_DEG 57.29577951f /*!< Radians to degrees (180/π) */
1818

1919
/* MPU6886 register addresses (from datasheet DS-000193 Rev 1.1) */
2020
#define MPU6886_SELF_TEST_X_ACCEL 0x0Du
@@ -103,7 +103,7 @@ static esp_err_t mpu6886_write(mpu6886_handle_t sensor, const uint8_t reg_start_
103103
}
104104

105105
static esp_err_t mpu6886_read(mpu6886_handle_t sensor, const uint8_t reg_start_addr, uint8_t *const data_buf,
106-
const uint8_t data_len)
106+
const uint16_t data_len)
107107
{
108108
mpu6886_dev_t *sens = (mpu6886_dev_t *) sensor;
109109
return i2c_master_transmit_receive(sens->i2c_dev, &reg_start_addr, 1, data_buf, data_len, 1000);
@@ -166,7 +166,7 @@ static esp_err_t mpu6886_write(mpu6886_handle_t sensor, const uint8_t reg_start_
166166
}
167167

168168
static esp_err_t mpu6886_read(mpu6886_handle_t sensor, const uint8_t reg_start_addr, uint8_t *const data_buf,
169-
const uint8_t data_len)
169+
const uint16_t data_len)
170170
{
171171
mpu6886_dev_t *sens = (mpu6886_dev_t *) sensor;
172172
esp_err_t ret;
@@ -195,6 +195,9 @@ static esp_err_t mpu6886_read(mpu6886_handle_t sensor, const uint8_t reg_start_a
195195
mpu6886_handle_t mpu6886_create(i2c_port_t port, const uint16_t dev_addr)
196196
{
197197
mpu6886_dev_t *sensor = (mpu6886_dev_t *) calloc(1, sizeof(mpu6886_dev_t));
198+
if (!sensor) {
199+
return NULL;
200+
}
198201
sensor->bus = port;
199202
sensor->dev_addr = dev_addr << 1;
200203
sensor->counter = 0;
@@ -548,7 +551,7 @@ esp_err_t mpu6886_get_fifo_count(mpu6886_handle_t sensor, uint16_t *count)
548551
return ret;
549552
}
550553

551-
esp_err_t mpu6886_read_fifo(mpu6886_handle_t sensor, uint8_t *buf, uint8_t len)
554+
esp_err_t mpu6886_read_fifo(mpu6886_handle_t sensor, uint8_t *buf, uint16_t len)
552555
{
553556
return mpu6886_read(sensor, MPU6886_FIFO_R_W, buf, len);
554557
}
@@ -704,18 +707,26 @@ esp_err_t mpu6886_config_interrupts(mpu6886_handle_t sensor, const mpu6886_int_c
704707

705708
if (MPU6886_INTERRUPT_PIN_ACTIVE_LOW == interrupt_configuration->active_level) {
706709
int_pin_cfg |= BIT7;
710+
} else {
711+
int_pin_cfg &= ~BIT7;
707712
}
708713

709714
if (MPU6886_INTERRUPT_PIN_OPEN_DRAIN == interrupt_configuration->pin_mode) {
710715
int_pin_cfg |= BIT6;
716+
} else {
717+
int_pin_cfg &= ~BIT6;
711718
}
712719

713720
if (MPU6886_INTERRUPT_LATCH_UNTIL_CLEARED == interrupt_configuration->interrupt_latch) {
714721
int_pin_cfg |= BIT5;
722+
} else {
723+
int_pin_cfg &= ~BIT5;
715724
}
716725

717726
if (MPU6886_INTERRUPT_CLEAR_ON_ANY_READ == interrupt_configuration->interrupt_clear_behavior) {
718727
int_pin_cfg |= BIT4;
728+
} else {
729+
int_pin_cfg &= ~BIT4;
719730
}
720731

721732
ret = mpu6886_write(sensor, MPU6886_INTR_PIN_CFG, &int_pin_cfg, 1);

0 commit comments

Comments
 (0)