|
14 | 14 | #include "mpu6886.h" |
15 | 15 |
|
16 | 16 | #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/π) */ |
18 | 18 |
|
19 | 19 | /* MPU6886 register addresses (from datasheet DS-000193 Rev 1.1) */ |
20 | 20 | #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_ |
103 | 103 | } |
104 | 104 |
|
105 | 105 | 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) |
107 | 107 | { |
108 | 108 | mpu6886_dev_t *sens = (mpu6886_dev_t *) sensor; |
109 | 109 | return i2c_master_transmit_receive(sens->i2c_dev, ®_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_ |
166 | 166 | } |
167 | 167 |
|
168 | 168 | 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) |
170 | 170 | { |
171 | 171 | mpu6886_dev_t *sens = (mpu6886_dev_t *) sensor; |
172 | 172 | esp_err_t ret; |
@@ -195,6 +195,9 @@ static esp_err_t mpu6886_read(mpu6886_handle_t sensor, const uint8_t reg_start_a |
195 | 195 | mpu6886_handle_t mpu6886_create(i2c_port_t port, const uint16_t dev_addr) |
196 | 196 | { |
197 | 197 | mpu6886_dev_t *sensor = (mpu6886_dev_t *) calloc(1, sizeof(mpu6886_dev_t)); |
| 198 | + if (!sensor) { |
| 199 | + return NULL; |
| 200 | + } |
198 | 201 | sensor->bus = port; |
199 | 202 | sensor->dev_addr = dev_addr << 1; |
200 | 203 | sensor->counter = 0; |
@@ -548,7 +551,7 @@ esp_err_t mpu6886_get_fifo_count(mpu6886_handle_t sensor, uint16_t *count) |
548 | 551 | return ret; |
549 | 552 | } |
550 | 553 |
|
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) |
552 | 555 | { |
553 | 556 | return mpu6886_read(sensor, MPU6886_FIFO_R_W, buf, len); |
554 | 557 | } |
@@ -704,18 +707,26 @@ esp_err_t mpu6886_config_interrupts(mpu6886_handle_t sensor, const mpu6886_int_c |
704 | 707 |
|
705 | 708 | if (MPU6886_INTERRUPT_PIN_ACTIVE_LOW == interrupt_configuration->active_level) { |
706 | 709 | int_pin_cfg |= BIT7; |
| 710 | + } else { |
| 711 | + int_pin_cfg &= ~BIT7; |
707 | 712 | } |
708 | 713 |
|
709 | 714 | if (MPU6886_INTERRUPT_PIN_OPEN_DRAIN == interrupt_configuration->pin_mode) { |
710 | 715 | int_pin_cfg |= BIT6; |
| 716 | + } else { |
| 717 | + int_pin_cfg &= ~BIT6; |
711 | 718 | } |
712 | 719 |
|
713 | 720 | if (MPU6886_INTERRUPT_LATCH_UNTIL_CLEARED == interrupt_configuration->interrupt_latch) { |
714 | 721 | int_pin_cfg |= BIT5; |
| 722 | + } else { |
| 723 | + int_pin_cfg &= ~BIT5; |
715 | 724 | } |
716 | 725 |
|
717 | 726 | if (MPU6886_INTERRUPT_CLEAR_ON_ANY_READ == interrupt_configuration->interrupt_clear_behavior) { |
718 | 727 | int_pin_cfg |= BIT4; |
| 728 | + } else { |
| 729 | + int_pin_cfg &= ~BIT4; |
719 | 730 | } |
720 | 731 |
|
721 | 732 | ret = mpu6886_write(sensor, MPU6886_INTR_PIN_CFG, &int_pin_cfg, 1); |
|
0 commit comments