static bool mpu6050_test_connection() { return mpu6050_read_byte(MPUREG_WHOAMI) == 0x68; }
static int mpu6050_probe(struct i2c_client *client, const struct i2c_device_id *id) { unsigned short accel_x = 0, accel_y = 0, accel_z = 0; unsigned short gyro_x = 0, gyro_y = 0, gyro_z = 0; unsigned short temp = 0; printk("match OK!\n"); printk("irqno = %d\n", client->irq); printk("addr = %d\n", client->addr); mpu6050_write_byte(client, PWR_MGMT_1, 0x00); mpu6050_write_byte(client, SMPLRT_DIV, 0x07); mpu6050_write_byte(client, CONFIG, 0x06); mpu6050_write_byte(client, GYRO_CONFIG, 0x18); mpu6050_write_byte(client, ACCEL_CONFIG, 0x01); while(1) { accel_x = mpu6050_read_byte(client, ACCEL_XOUT_L); accel_x |= mpu6050_read_byte(client, ACCEL_XOUT_H) << 8; accel_y = mpu6050_read_byte(client, ACCEL_YOUT_L); accel_y |= mpu6050_read_byte(client, ACCEL_YOUT_H) << 8; accel_z = mpu6050_read_byte(client, ACCEL_ZOUT_L); accel_z |= mpu6050_read_byte(client, ACCEL_ZOUT_H) << 8; printk("acceleration data: x = %04x, y = %04x, z = %04x\n", accel_x, accel_y, accel_z); gyro_x = mpu6050_read_byte(client, GYRO_XOUT_L); gyro_x |= mpu6050_read_byte(client, GYRO_XOUT_H) << 8; gyro_y = mpu6050_read_byte(client, GYRO_YOUT_L); gyro_y |= mpu6050_read_byte(client, GYRO_YOUT_H) << 8; gyro_z = mpu6050_read_byte(client, GYRO_ZOUT_L); gyro_z |= mpu6050_read_byte(client, GYRO_ZOUT_H) << 8; printk("gyroscope data: x = %04x, y = %04x, z = %04x\n", gyro_x, gyro_y, gyro_z); temp = mpu6050_read_byte(client, TEMP_OUT_L); temp |= mpu6050_read_byte(client, TEMP_OUT_H) << 8; printk("temperature data: %x\n", temp); mdelay(500); } return 0; }