解析如何在android中增加gsensor驱动(MMA7660)
程序员文章站
2023-10-19 13:45:56
系统原来用的是bosch_bma222的gsensor, 现在要求换成使用mma7660,我们来看一下怎样增加驱动和调试过程。 1. 修改makefie首先,修改放置驱动的...
系统原来用的是bosch_bma222的gsensor, 现在要求换成使用mma7660,我们来看一下怎样增加驱动和调试过程。
1. 修改makefie
首先,修改放置驱动的目录里的makefile(kernel/driver/misc),添置如下语句:
obj-$(config_sensors_mma7660) += mma7660.o
2. 增加驱动文件
把驱动文件mma7660.c添加到kernel/driver/misc下。
3. 修改.config文件,把下面两行注释掉
# config_bosch_sensor=y
# config_bosch_bma222=y
再增加下面这项
config_sensors_mma7660=y
编译,显示提示:
make uimage -j16
scripts/kconfig/conf -s arch/arm/kconfig
*
* restart config...
*
*
* misc devices
*
misc devices (misc_devices) [y/n/?] y
analog devices ad525x digital potentiometers (ad525x_dpot) [n/m/y/?] n
android pmem allocator (android_pmem) [n/y] n
integrated circuits ics932s401 (ics932s401) [n/m/y/?] n
enclosure services (enclosure_services) [n/m/y/?] n
kernel debugger core (kernel_debugger_core) [n/y/?] n
intersil isl29003 ambient light sensor (isl29003) [n/m/y/?] n
taos tsl2550 ambient light sensor (sensors_tsl2550) [n/m/y/?] n
dallas ds1682 total elapsed time recorder with alarm (ds1682) [n/m/y/?] n
texas instruments dac7512 (ti_dac7512) [n/m/y/?] n
uid based statistics tracking exported to /proc/uid_stat (uid_stat) [y/n] y
bluetooth power control driver for ti wl127x (wl127x_rfkill) [n/m/y/?] n
android kernel panic diagnostics driver (apanic) [n/y/?] n
6 axis sensor mpu3050 (six_axis_sensor_mpu3050) [n/y] n
motion processing unit driver version
> 1. mpu version < v3.4.0 (mpu_pre_v340)
2. mpu version >= v3.4.0 (mpu_new)
choice[1-2]: 1
bosch bma222 acceleration sensor (bosch_sensor) [n/m/y/?] (new) n
*
* miscellaneous i2c chip support
*
bma222 acceleration sensor support (bosch_bma222) [n/m/y/?] (new) n
#
# configuration written to .config
这时看编译输出,系统没有编译mma7660.c, 而且编译后.config的mma7660的宏也被覆盖掉了,所以这样是没有办法挂载的。之所以出现这个错误的原因,是因为make的时候会检查各个kconfig文件,没有的选项会自动率掉,所以,我们还需要修改kconfig文件。
5. 修改kernel/driver/misc/kconfig,在menuconfig misc_devices下添加如下:
config sensors_mma7660
tristate "memsic accelerometer sensor mma7660 driver support"
depends on i2c
help
if you say yes here you get support for the memsic accelerometer sensor
6. 由于这里gsensor是一个i2c的外挂,所以,还必须修改板子的i2c的device信息,以便系统可以查找到设备。修改板子的资源文件(我这里的特例是./arch/arm/mach-meson3/board-m3-reff24.c),在结构aml_i2c_bus_info_1[]中添加一下信息:
#ifdef config_sensors_mma7660
{
i2c_board_info("mma7660", 0x4c),
.irq = int_gpio_2,
},
#endif
7. 再进行编译,驱动就被编译了。
1. 修改makefie
首先,修改放置驱动的目录里的makefile(kernel/driver/misc),添置如下语句:
复制代码 代码如下:
obj-$(config_sensors_mma7660) += mma7660.o
2. 增加驱动文件
把驱动文件mma7660.c添加到kernel/driver/misc下。
3. 修改.config文件,把下面两行注释掉
复制代码 代码如下:
# config_bosch_sensor=y
# config_bosch_bma222=y
再增加下面这项
复制代码 代码如下:
config_sensors_mma7660=y
编译,显示提示:
复制代码 代码如下:
make uimage -j16
scripts/kconfig/conf -s arch/arm/kconfig
*
* restart config...
*
*
* misc devices
*
misc devices (misc_devices) [y/n/?] y
analog devices ad525x digital potentiometers (ad525x_dpot) [n/m/y/?] n
android pmem allocator (android_pmem) [n/y] n
integrated circuits ics932s401 (ics932s401) [n/m/y/?] n
enclosure services (enclosure_services) [n/m/y/?] n
kernel debugger core (kernel_debugger_core) [n/y/?] n
intersil isl29003 ambient light sensor (isl29003) [n/m/y/?] n
taos tsl2550 ambient light sensor (sensors_tsl2550) [n/m/y/?] n
dallas ds1682 total elapsed time recorder with alarm (ds1682) [n/m/y/?] n
texas instruments dac7512 (ti_dac7512) [n/m/y/?] n
uid based statistics tracking exported to /proc/uid_stat (uid_stat) [y/n] y
bluetooth power control driver for ti wl127x (wl127x_rfkill) [n/m/y/?] n
android kernel panic diagnostics driver (apanic) [n/y/?] n
6 axis sensor mpu3050 (six_axis_sensor_mpu3050) [n/y] n
motion processing unit driver version
> 1. mpu version < v3.4.0 (mpu_pre_v340)
2. mpu version >= v3.4.0 (mpu_new)
choice[1-2]: 1
bosch bma222 acceleration sensor (bosch_sensor) [n/m/y/?] (new) n
*
* miscellaneous i2c chip support
*
bma222 acceleration sensor support (bosch_bma222) [n/m/y/?] (new) n
#
# configuration written to .config
这时看编译输出,系统没有编译mma7660.c, 而且编译后.config的mma7660的宏也被覆盖掉了,所以这样是没有办法挂载的。之所以出现这个错误的原因,是因为make的时候会检查各个kconfig文件,没有的选项会自动率掉,所以,我们还需要修改kconfig文件。
5. 修改kernel/driver/misc/kconfig,在menuconfig misc_devices下添加如下:
复制代码 代码如下:
config sensors_mma7660
tristate "memsic accelerometer sensor mma7660 driver support"
depends on i2c
help
if you say yes here you get support for the memsic accelerometer sensor
6. 由于这里gsensor是一个i2c的外挂,所以,还必须修改板子的i2c的device信息,以便系统可以查找到设备。修改板子的资源文件(我这里的特例是./arch/arm/mach-meson3/board-m3-reff24.c),在结构aml_i2c_bus_info_1[]中添加一下信息:
复制代码 代码如下:
#ifdef config_sensors_mma7660
{
i2c_board_info("mma7660", 0x4c),
.irq = int_gpio_2,
},
#endif
7. 再进行编译,驱动就被编译了。