X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=src%2Fdrivers%2Fao_mpu6000.c;h=c894239ec0e54ae0934781886c44a759e8bcc38b;hp=8c85ab01fd82c00041128a9147e3f6a26f2caa39;hb=HEAD;hpb=684741765117611b7d666efbdfafd87c6199752c diff --git a/src/drivers/ao_mpu6000.c b/src/drivers/ao_mpu6000.c index 8c85ab01..e5594a66 100644 --- a/src/drivers/ao_mpu6000.c +++ b/src/drivers/ao_mpu6000.c @@ -32,7 +32,9 @@ static uint8_t ao_mpu6000_configured; #if AO_MPU6000_SPI -#define ao_mpu6000_spi_get() ao_spi_get(AO_MPU6000_SPI_BUS, AO_SPI_SPEED_1MHz) +#define AO_MPU6000_SPI_SPEED ao_spi_speed(AO_MPU6000_SPI_BUS, 1000000) /* 1Mhz for all register access */ + +#define ao_mpu6000_spi_get() ao_spi_get(AO_MPU6000_SPI_BUS, AO_MPU6000_SPI_SPEED) #define ao_mpu6000_spi_put() ao_spi_put(AO_MPU6000_SPI_BUS) #define ao_mpu6000_spi_start() ao_spi_set_cs(AO_MPU6000_SPI_CS_PORT, \ @@ -111,7 +113,7 @@ _ao_mpu6000_sample(struct ao_mpu6000_sample *sample) /* byte swap */ while (i--) { uint16_t t = *d; - *d++ = (t >> 8) | (t << 8); + *d++ = (uint16_t) ((t >> 8) | (t << 8)); } #endif } @@ -162,6 +164,8 @@ ao_mpu6000_gyro_check(int16_t normal, int16_t test) return 0; } +static uint8_t mpu_id; + static void _ao_mpu6000_wait_alive(void) { @@ -170,11 +174,11 @@ _ao_mpu6000_wait_alive(void) /* Wait for the chip to wake up */ for (i = 0; i < 30; i++) { ao_delay(AO_MS_TO_TICKS(100)); - if (_ao_mpu6000_reg_read(MPU6000_WHO_AM_I) == 0x68) - break; + mpu_id = _ao_mpu6000_reg_read(MPU6000_WHO_AM_I); + if (mpu_id == 0x68) + return; } - if (i == 30) - ao_panic(AO_PANIC_SELF_TEST_MPU6000); + AO_SENSOR_ERROR(AO_DATA_MPU6000); } #define ST_TRIES 10 @@ -305,7 +309,7 @@ _ao_mpu6000_setup(void) } if (st_tries == ST_TRIES) - ao_sensor_errors = 1; + AO_SENSOR_ERROR(AO_DATA_MPU6000); /* Filter to about 100Hz, which also sets the gyro rate to 1000Hz */ _ao_mpu6000_reg_write(MPU6000_CONFIG, @@ -353,6 +357,15 @@ static struct ao_task ao_mpu6000_task; static void ao_mpu6000_show(void) { +#ifdef AO_LOG_NORMALIZED + printf ("MPU6000: %7d %7d %7d %7d %7d %7d\n", + ao_mpu6000_along(&ao_mpu6000_current), + ao_mpu6000_across(&ao_mpu6000_current), + ao_mpu6000_through(&ao_mpu6000_current), + ao_mpu6000_roll(&ao_mpu6000_current), + ao_mpu6000_pitch(&ao_mpu6000_current), + ao_mpu6000_yaw(&ao_mpu6000_current)); +#else printf ("Accel: %7d %7d %7d Gyro: %7d %7d %7d\n", ao_mpu6000_current.accel_x, ao_mpu6000_current.accel_y, @@ -360,6 +373,7 @@ ao_mpu6000_show(void) ao_mpu6000_current.gyro_x, ao_mpu6000_current.gyro_y, ao_mpu6000_current.gyro_z); +#endif } static const struct ao_cmds ao_mpu6000_cmds[] = { @@ -383,7 +397,7 @@ ao_mpu6000_init(void) */ ao_cur_task = &ao_mpu6000_task; - ao_spi_get(AO_MPU6000_SPI_BUS, AO_SPI_SPEED_1MHz); + ao_mpu6000_spi_get(); ao_cur_task = NULL; #endif