2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 #include <ao_mpu6000.h>
22 static uint8_t ao_mpu6000_wake;
23 static uint8_t ao_mpu6000_configured;
28 ao_exti_disable(&AO_MPU6000_INT_PORT, AO_MPU6000_INT_PIN);
30 ao_wakeup(&ao_mpu6000_wake);
34 ao_mpu6000_write(uint8_t addr, uint8_t *data, uint8_t len)
36 ao_i2c_get(AO_MPU6000_I2C_INDEX);
37 ao_i2c_start(AO_MPU6000_I2C_INDEX, MPU6000_ADDR_WRITE);
38 ao_i2c_send(&addr, 1, AO_MPU6000_I2C_INDEX);
40 ao_i2c_send(data, len, AO_MPU6000_I2C_INDEX);
41 ao_i2c_stop(AO_MPU6000_I2C_INDEX);
42 ao_i2c_put(AO_MPU6000_I2C_INDEX);
46 ao_mpu6000_read(uint8_t addr, uint8_t *data, uint8_t len)
48 ao_i2c_get(AO_MPU6000_I2C_INDEX);
49 ao_i2c_start(AO_MPU6000_I2C_INDEX, MPU6000_ADDR_WRITE);
50 ao_i2c_send(&addr, 1, AO_MPU6000_I2C_INDEX);
51 ao_i2c_start(AO_MPU6000_I2C_INDEX, MPU6000_ADDR_READ);
53 ao_i2c_recv(data, len, AO_MPU6000_I2C_INDEX);
54 ao_i2c_stop(AO_MPU6000_I2C_INDEX);
55 ao_i2c_put(AO_MPU6000_I2C_INDEX);
59 ao_mpu6000_setup(void)
61 if (ao_mpu6000_configured)
64 /* Enable the EXTI interrupt for the appropriate pin */
65 ao_enable_port(AO_MPU6000_INT_PORT);
66 ao_exti_setup(&AO_MPU6000_INT_PORT, AO_MPU6000_INT_PIN,
67 AO_EXTI_MODE_FALLING, ao_mpu6000_isr);
69 ao_mpu6000_configured = 1;
79 ao_mpu6000_read(MPU6000_WHO_AM_I, data, 1);
80 printf ("mpu6000 WHO_AM_I: %02x\n", data[0]);
81 ao_mpu6000_read(MPU6000_ACCEL_XOUT_H, data, 1);
82 for (i = 0; i < 14; i++)
83 printf ("reg %02x: %02x\n", i + MPU6000_ACCEL_XOUT_H, data[i]);
86 static const struct ao_cmds ao_mpu6000_cmds[] = {
87 { ao_mpu6000_show, "I\0Show MPU6000 status" },
94 ao_mpu6000_configured = 0;
96 ao_cmd_register(&ao_mpu6000_cmds[0]);