91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 5KB
    文件類型: .c
    金幣: 1
    下載: 0 次
    發布日期: 2021-06-23
  • 語言: 其他
  • 標簽: Linux??驅動??mpu6050??

資源簡介

自己寫的基于linux mpu6050的iic驅動代碼 已在開發板上運行過了

資源截圖

代碼片段和文件信息

#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?“mpu6050.h“




struct?mpu6050_device{
struct?i2c_client?*mpu6050_client;
????struct?cdev?cdev;

}

static?struct?mpu6050_device?*mpu6050;
static?int?major;
static?struct?class?*class;
//static?struct?device?*dev;



static?const?struct?i2c_device_id?mpu6050_id[]?=?{
{?“mpu6050“?0?}
{?}
};


static?int?mpu6050_read?(struct?i2c_client?*client?unsigned?char?reg)

{
???/*傳入buf[0]:addr*/
???struct?i2c_msg?msg[2];
???unsigned?char?reg_addrdata;
???//copy_from_user(®_addrbuf1);
???msg[0].addr=client->addr;
???msg[0].flags?=0;
???msg[0].len?=1;
???msg[0].buf=®_addr;
???msg[1].addr?=client->addr;
???msg[1].flags=I2C_M_RD;
???msg[1].len=1;
???msg[1].buf=&data;
???i2c_transfer(client->adaptermsg2);
???//i2c_smbus_read_byte_data(mpu6050_clientaddr);
??//?copy_to_user(buf&data1);
???return?data;

}


static?int?mpu6050_write?(struct?i2c_client?*client?unsigned?char?reg?unsigned?char?val)
{
???/*buf[0]?addr
????*buf[1]?data
????*/
????struct?i2c_msg?msg;
????unsigned?char?buf[2];
buf[0]=reg;
buf[1]=val;
????//unsigned?char?reg_addrdata;
????//unsigned?char?ker_buf[2];
//copy_from_user(ker_bufbuf2);
//reg_addr=ker_buf[0];
//data=ker_buf[1];
????msg.addr=client->addr;
msg.flags=0;
msg.buf?=buf;
msg.len=2;
i2c_transfer(client->adapter&msg1);
return?0;

}
static?int?mpu6050_ioctl(struct?file?*file?unsigned?int?cmdunsigned?long?arg)
{
???
???union?mpu6050_data?data;
struct?i2c_client?*client?=?mpu6050->client;

switch(cmd)?{
case?GET_ACCEL:
data.accel.x?=?mpu6050_read_byte(client?ACCEL_XOUT_L);
data.accel.x?|=?mpu6050_read_byte(client?ACCEL_XOUT_H)?<
data.accel.y?=?mpu6050_read_byte(client?ACCEL_YOUT_L);
data.accel.y?|=?mpu6050_read_byte(client?ACCEL_YOUT_H)?<
data.accel.z?=?mpu6050_read_byte(client?ACCEL_ZOUT_L);
data.accel.z?|=?mpu6050_read_byte(client?ACCEL_ZOUT_H)?< break;

case?GET_GYRO:

data.gyro.x?=?mpu6050_read_byte(client?GYRO_XOUT_L);
data.g

評論

共有 條評論