电子发烧友App

硬声App

0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示
创作
电子发烧友网>电子资料下载>类型>参考设计>ADXL362输入三轴数字加速度计Linux驱动程序

ADXL362输入三轴数字加速度计Linux驱动程序

2021-04-21 | pdf | 128.83KB | 次下载 | 3积分

资料介绍

This version (11 Feb 2016 21:21) was approved by Lars-Peter Clausen.The Previously approved version (07 Jun 2013 11:15) is available.Diff

ADXL362 Input 3-Axis Digital Accelerometer Linux Driver

Supported Devices

Reference Circuits

Evaluation Boards

ADXL362: Micropower 3-Axis MEMS Accelerometer: Digital Output, ±2/±4/±8 g Range

Source Code

Status

Source Mainlined?
git In Progress

Files

Example platform device initialization

For compile time configuration, it’s common Linux practice to keep board- and application-specific configuration out of the main driver file, instead putting it into the board support file.

For devices on custom boards, as typical of embedded and SoC-(system-on-chip) based hardware, Linux uses platform_data to point to board-specific structures describing devices and how they are connected to the SoC. This can include available ports, chip variants, preferred modes, default initialization, additional pin roles, and so on. This shrinks the board-support packages (BSPs) and minimizes board and application specific #ifdefs in drivers.

21 Oct 2010 16:10

Digital Accelerometer characteristics are application specific and may vary between boards and models. The platform_data for the device's “struct device” holds this information.

enum adxl_odr {
	ADXL_ODR_12_5HZ	= 13,
	ADXL_ODR_25HZ	= 25,
	ADXL_ODR_50HZ	= 50,
	ADXL_ODR_100HZ	= 100,
	ADXL_ODR_200HZ	= 200,
	ADXL_ODR_400HZ	= 400,
};
 
enum adxl_g_range {
	ADXL_RANGE_PM_2g = 2,
	ADXL_RANGE_PM_4g = 4,
	ADXL_RANGE_PM_8g = 8,
};
 
enum adxl_power_mode {
	ADXL_NORM_OPERATION	= 0,
	ADXL_LOW_NOISE_MODE	= 1,
	ADXL_ULTRA_LOW_NOISE_MODE = 2,
};
 
struct adxl362_platform_data {
	/*
	 * data_range:
	 * Measurement range selection +/- 2,4,8 g
	 */
	enum adxl_g_range data_range;
 
	/*
	 * low_power_mode:
	 * Power versus noise tradeoff.
	 */
	enum adxl_power_mode low_power_mode;
 
	/*
	 * data_rate:
	 * Selects the output data rate (ODR).
	 */
	enum adxl_odr data_rate;
 
	/*
	 * half_bw:
	 * Sets the anti-aliasing filter to 1/4 of the output data rate (ODR)
	 */
	bool half_bw;
 
	/*
	 * watermark_odr:
	 * The Watermark feature can be used to reduce the interrupt/poll load
	 * of the system. The FIFO fills up to watermark value in sample sets
	 * [1..170] and then generates an interrupt. Each ODR can have it's
	 * own watermark.
	 */
	u8 watermark_odr_12Hz;
	u8 watermark_odr_25Hz;
	u8 watermark_odr_50Hz;
	u8 watermark_odr_100Hz;
	u8 watermark_odr_200Hz;
	u8 watermark_odr_400Hz;
 
	/*
	 * When acceleration measurements are received from the ADXL362
	 * events are sent to the input event subsystem. The following settings
	 * select the event code for ABS x, y and z axis data
	 * respectively. The event codes can also be negated to further account
	 * for sensor orientation.
	 */
	s32 ev_code_x;	/* (+/-)ABS_X,Y,Z */
	s32 ev_code_y;	/* (+/-)ABS_X,Y,Z */
	s32 ev_code_z;	/* (+/-)ABS_X,Y,Z */
	s32 abs_fuzz;	/* input fuzz val */
 
	/*
	 * [in]activity_threshold:
	 * holds the threshold value for activity detection.
	 * The data format is unsigned. The scale factor is
	 * 1mg/LSB.
	 */
	u16 activity_threshold;
	u16 inactivity_threshold;
 
	/*
	 * [in]activity_time:
	 * is an unsigned time value representing the
	 * amount of time that acceleration must be [below]/above the value in
	 * [in]activity_threshold for [in]activity to be declared.
	 * The scale factor is 1ms/LSB.
	 */
	u32 inactivity_time;
	u32 activity_time;
 
	/*
	 * referenced_[in]activity_en:
	 * Sets [in]activity detection to operate in referenced mode opposed to
	 * absolute mode.
	 */
	bool referenced_activity_en;
	bool referenced_inactivity_en;
 
	/*
	 * Use ADXL362 INT2 pin instead of INT1 pin for interrupt output
	 */
	bool use_int2;
 
	/*
	 * Optional IRQ flags
	 */
	unsigned irqflags;
};
static struct adxl362_platform_data adxl362_info = {
	.data_rate = ADXL_ODR_100HZ,	/* 100Hz */
	.data_range = ADXL_RANGE_PM_2g,	/* +/- 2000mg */
	.activity_threshold = 70,	/* 70mg (referenced) */
	.inactivity_threshold = 30,	/* 30mg (referenced) */
	.inactivity_time = 10000,	/* 10s */
	.activity_time = 1,		/* 1ms */
	.referenced_activity_en = true, /* cancel static accel. of gravity */
	.referenced_inactivity_en = true, /* cancel static accel. of gravity */
	.watermark_odr_12Hz = 1,
	.watermark_odr_25Hz = 1,
	.watermark_odr_50Hz = 1,
	.watermark_odr_100Hz = 1,
	.watermark_odr_200Hz = 2, /* limit irq/poll interval to 10ms */
	.watermark_odr_400Hz = 4, /* limit irq/poll interval to 10ms */
	.ev_code_x = ABS_X,		/* default mapping */
	.ev_code_y = ABS_Y,
	.ev_code_z = ABS_Z,
};

Declaring SPI slave devices

Unlike PCI or USB devices, SPI devices are not enumerated at the hardware level. Instead, the software must know which devices are connected on each SPI bus segment, and what slave selects these devices are using. For this reason, the kernel code must instantiate SPI devices explicitly. The most common method is to declare the SPI devices by bus number.

This method is appropriate when the SPI bus is a system bus, as in many embedded systems, wherein each SPI bus has a number which is known in advance. It is thus possible to pre-declare the SPI devices that inhabit this bus. This is done with an array of struct spi_board_info, which is registered by calling spi_register_board_info().

For more information see: Documentation/spi/spi-summary

21 Oct 2010 16:10

Depending on the DDS IC used, you may need to set the modalias accordingly, matching your part name. It may also required to adjust max_speed_hz. Please consult the datasheet, for maximum spi clock supported by the device in question.

static struct spi_board_info board_spi_board_info[] __initdata = {
#if defined(CONFIG_INPUT_ADXL362) || defined(CONFIG_INPUT_ADXL362_MODULE)
	{
		.modalias	= "adxl362",
		.platform_data	= &adxl362_info,
		.irq		= IRQ_PF6,
		.max_speed_hz	= 5000000,    /* max spi clock (SCK) speed in HZ */
		.bus_num	= 0,
		.chip_select 	= 1,
		.mode 		= SPI_MODE_0,
	},
#endif
};
static int __init board_init(void)
{
	[--snip--]
 
	spi_register_board_info(board_spi_board_info, ARRAY_SIZE(board_spi_board_info));
 
	[--snip--]
 
	return 0;
}
arch_initcall(board_init);

Adding Linux driver support

Configure kernel with “make menuconfig” (alternatively use “make xconfig” or “make qconfig”)

The ADXL34x Driver depends on CONFIG_SPI

Input device support
  -*- Generic input layer (needed for keyboard, mouse, ...)
  < >   Support for memoryless force-feedback devices
  < >   Polled input device skeleton
  < >   Sparse keymap support library
        * Userland interfaces *
  < >   Mouse interface
  < >   Joystick interface
  <*>   Event interface
  < >   Event debugging
        * Input Device Drivers *
  [ ]   Keyboards  --->
  [ ]   Mice  --->
  [ ]   Joysticks/Gamepads  --->
  [ ]   Tablets  --->
  [ ]   Touchscreens  --->
  [*]   Miscellaneous devices  --->
		--- Miscellaneous devices
		< >   Analog Devices AD714x Capacitance Touch Sensor
		< >   BMA150/SMB380 acceleration sensor support
		< >   MMA8450 - Freescale's 3-Axis, 8/12-bit Digital Accelerometer
		< >   MPU3050 Triaxial gyroscope sensor
		< >   Sharp GP2AP002A00F I2C Proximity/Opto sensor driver
		< >   Polled GPIO tilt switch
		< >   Kionix KXTJ9 tri-axis digital accelerometer
		< >   User level driver support
		< >   PCF8574 Keypad input device
		< >   Rotary encoders connected to GPIO pins
		< >   Analog Devices ADXL34x Three-Axis Digital Accelerometer
		<*>   Analog Devices ADXL362 Three-Axis Digital Accelerometer
		< >   VTI CMA3000 Tri-axis accelerometer
        Hardware I/O ports  --->

Hardware configuration

eval-adxl362z

Driver testing

Driver compiled as a module

root:~> modprobe evdev
root:~> modprobe adxl362
input: ADXL362 accelerometer as /devices/platform/bfin-spi.0/spi_master/spi0/spi0.1/input/input0

Driver compiled into the kernel

Your kernel startup messages should include something like this

input: ADXL362 accelerometer as /devices/platform/bfin-spi.0/spi_master/spi0/spi0.1/input/input0

Common Problems

In case you see a message like this

adxl362 spi0.1: Failed to probe (0x00:0x00)

This means that the SPI communication and initilaization with the ADXL362 failed. check bus_num and chip_select in your platform device file

Checking for proper installation

After the kernel boot your device folder should include at least one device node for the accelerometer

root:/> ls -al /dev/input/
drw-r--r--    2 root     root            0 Jan  1 00:03 .
drwxr-xr-x    5 root     root            0 Jan  1 00:03 ..
crw-rw-r--    1 root     root      13,  64 Jan  1 00:03 event0
root:/>

root:~> cat /sys/class/input/input0/name
ADXL362 accelerometer

Use the event_test utility to test proper function

root:/> event_test /dev/input/event0
Input driver version is 1.0.1
Input device ID: bus 0x1c vendor 0xad product 0xf2 version 0x1
Input device name: "ADXL362 accelerometer"
Supported events:
  Event type 0 (Sync)
  Event type 3 (Absolute)
    Event code 0 (X)
      Value   -144
      Min    -2000
      Max     2000
    Event code 1 (Y)
      Value   -256
      Min    -2000
      Max     2000
    Event code 2 (Z)
      Value    398
      Min    -2000
      Max     2000
Testing ... (interrupt to exit)
Event: time 43.641571, -------------- Report Sync ------------
Event: time 43.641582, type 3 (Absolute), code 0 (X), value 192
Event: time 43.641588, type 3 (Absolute), code 1 (Y), value 7
Event: time 43.641593, type 3 (Absolute), code 2 (Z), value 291
Event: time 43.641597, -------------- Report Sync ------------
Event: time 43.656442, type 3 (Absolute), code 0 (X), value 211
Event: time 43.656451, type 3 (Absolute), code 1 (Y), value 12
Event: time 43.656456, type 3 (Absolute), code 2 (Z), value 295
Event: time 43.656461, -------------- Report Sync ------------
Event: time 43.656476, type 3 (Absolute), code 1 (Y), value 15
Event: time 43.656481, type 3 (Absolute), code 2 (Z), value 280
Event: time 43.656486, -------------- Report Sync ------------

In case you move the accelerometer and don't receive events, it's likely that something with your Interrupt is wrong.
check irq number in your platform device file

In case you get a message like: evtest: No such device, it's likely that you have not install the necessary modules

ADXL34x Sysfs runtime controls

root:/> cd sys/class/input/input0/device/
root:/sys/devices/platform/bfin-spi.0/spi_master/spi0/spi0.1> ls -al
drwxr-xr-x    4 root     root             0 Jan  1 01:40 .
drwxr-xr-x    4 root     root             0 Jan  1 01:40 ..
-rw-rw-r--    1 root     root          4096 Jan  1 01:50 autosleep
lrwxrwxrwx    1 root     root             0 Jan  1 01:50 driver -> ../../../../../../bus/spi/drivers/adxl362
drwxr-xr-x    3 root     root             0 Jan  1 01:40 input
-r--r--r--    1 root     root          4096 Jan  1 01:50 modalias
drwxr-xr-x    2 root     root             0 Jan  1 01:50 power
-rw-rw-r--    1 root     root          4096 Jan  1 01:50 rate
lrwxrwxrwx    1 root     root             0 Jan  1 01:50 subsystem -> ../../../../../../bus/spi
-rw-r--r--    1 root     root          4096 Jan  1 01:50 uevent

Controlling the Output Data Rate

Output Data Rate (Hz) Bandwidth (Hz)
400 200
200 100
100 50
50 25
25 12.5
12.5 6.25

Writing 'Output Data Rate' into rate sets the desired sample rate
Reading rate returns the current Output Data Rate

See table above for supported sample rates

root:/sys/devices/platform/bfin-spi.0/spi_master/spi0/spi0.1> echo 400 > rate
root:/sys/devices/platform/bfin-spi.0/spi_master/spi0/spi0.1> cat rate
400

Enabling / Disabling Autosleep Upon Inactivity

Writing '1' into autosleep - enables Autosleep Upon Inactivity
Writing '0' into autosleep - disables Autosleep Upon Inactivity

root:/sys/devices/platform/bfin-spi.0/spi_master/spi0/spi0.1> echo 1 > autosleep
root:/sys/devices/platform/bfin-spi.0/spi_master/spi0/spi0.1> echo 0 > autosleep

More Information

ADXL362/6 Android Acceleration Sensor

Using this driver under Android as Acceleration Sensor Follow the link here ADXL362 Android Sensor

下载该资料的人也在下载 下载该资料的人还在阅读
更多 >

评论

查看更多

下载排行

本周

  1. 1电子威廉希尔官方网站 原理第七版PDF电子教材免费下载
  2. 0.00 MB  |  1491次下载  |  免费
  3. 2单片机典型实例介绍
  4. 18.19 MB  |  95次下载  |  1 积分
  5. 3S7-200PLC编程实例详细资料
  6. 1.17 MB  |  27次下载  |  1 积分
  7. 4笔记本电脑主板的元件识别和讲解说明
  8. 4.28 MB  |  18次下载  |  4 积分
  9. 5开关电源原理及各功能威廉希尔官方网站 详解
  10. 0.38 MB  |  11次下载  |  免费
  11. 6100W短波放大威廉希尔官方网站 图
  12. 0.05 MB  |  4次下载  |  3 积分
  13. 7基于单片机和 SG3525的程控开关电源设计
  14. 0.23 MB  |  4次下载  |  免费
  15. 8基于AT89C2051/4051单片机编程器的实验
  16. 0.11 MB  |  4次下载  |  免费

本月

  1. 1OrCAD10.5下载OrCAD10.5中文版软件
  2. 0.00 MB  |  234313次下载  |  免费
  3. 2PADS 9.0 2009最新版 -下载
  4. 0.00 MB  |  66304次下载  |  免费
  5. 3protel99下载protel99软件下载(中文版)
  6. 0.00 MB  |  51209次下载  |  免费
  7. 4LabView 8.0 专业版下载 (3CD完整版)
  8. 0.00 MB  |  51043次下载  |  免费
  9. 5555集成威廉希尔官方网站 应用800例(新编版)
  10. 0.00 MB  |  33562次下载  |  免费
  11. 6接口威廉希尔官方网站 图大全
  12. 未知  |  30320次下载  |  免费
  13. 7Multisim 10下载Multisim 10 中文版
  14. 0.00 MB  |  28588次下载  |  免费
  15. 8开关电源设计实例指南
  16. 未知  |  21539次下载  |  免费

总榜

  1. 1matlab软件下载入口
  2. 未知  |  935053次下载  |  免费
  3. 2protel99se软件下载(可英文版转中文版)
  4. 78.1 MB  |  537793次下载  |  免费
  5. 3MATLAB 7.1 下载 (含软件介绍)
  6. 未知  |  420026次下载  |  免费
  7. 4OrCAD10.5下载OrCAD10.5中文版软件
  8. 0.00 MB  |  234313次下载  |  免费
  9. 5Altium DXP2002下载入口
  10. 未知  |  233046次下载  |  免费
  11. 6威廉希尔官方网站 仿真软件multisim 10.0免费下载
  12. 340992  |  191183次下载  |  免费
  13. 7十天学会AVR单片机与C语言视频教程 下载
  14. 158M  |  183277次下载  |  免费
  15. 8proe5.0野火版下载(中文版免费下载)
  16. 未知  |  138039次下载  |  免费