Skip to content

boschmemssolutions/SMI130-Sensor-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

SMI130-Sensor-API and Sensor Driver

Table of Contents

General Description

This document introduces the usage of SMI130 Linux driver

License

See LICENSE file

System Configuration

Table 1: System Configuration

System Configuration Settings
Linux Kernel configuration CONFIG_SYSFS=y
I2C interface configuration CONFIG_I2C=y
SPI interface configuration CONFIG_SPI_MASTER=y

Linux driver files

Table 2: Driver Description

Files name Description
bs_log.c
bs_log.h
This file implements Bosch sensor log driver
Kconfig Kconfig
Makefile Makefile
LICENSE License
README.md Brief info of SMI130 Linux driver
smi130_i2c_driver.c
smi130_spi_driver.c
This file implements i2c/spi interface function of SMI130
smi130_acc_driver.c
smi130_acc_driver.h
This file implements the Linux input level driver of SMI130 ACC
smi130_acc.c
smi130_acc.h
This file implements the low level API of SMI130 ACC
smi130_gyro_driver.c
smi130_gyro_driver.h
This file implements the Linux input level driver of SMI130 GYRO
smi130_gyro.c
smi130_gyro.h
This file implements the low level API of SMI130 GYRO
smi130_defs.h This file implements the common definition of SMI130

Linux driver principle

By sysfs interface, application enables sensor to launch a delay task on work queue. The task delay value can be configured by sysfs interface. The default delay value is 200ms. The delay task will get the sensor values and update them as input event on input device. If compiled with interrupt support, the interrupt service routine will launch an IRQ task on work queue.The IRQ task will identify the interrupt type and send the interrupt event on input device. Application will block read the input device to get the input events. The input event will carry the sensor values or the interrupt type data.

              User space
----------------------------------------------
             |          |
           sysfs       dev
             \          /
           input-subsystem
                  |
i2c/spi bus <-- smi130_driver --> sensor_API
                  |
----------------------------------------------
               Hardware

The sysfs interface attributes

SMI130_ACC driver is registered as input class. In /sys/devices/virtual/input/inputX(X indicates the sensor number) on sysfs, the registered name is “smi130_acc”.

Table 3: sysfs interface attributes

Name Descriptions RW Usage
Range Set and get sensor G-range RW Write:
3------ +/- 2G
5 ------ +/- 4G
8 ------ +/- 8G
12 ------ +/- 16G
Read:
3------ +/- 2G
5 ------ +/- 4G
8 ------ +/- 8G
12 ------ +/- 16G
Default : 3
bandwidth Set and get sensor bandwidth RW Write:
8 ------ 7.81 Hz
9 ------ 15.63 H
10 ------ 31.25 Hz
11 ------ 62.5 Hz
12 ------ 125 Hz
13 ------ 250 Hz
14 ------ 500 Hz
15 ------ 1000 Hz
Read:
8 ------ 7.81 Hz
9 ------ 15.63 Hz
10 ------ 31.25 Hz
11 ------ 62.5 Hz
12 ------ 125 Hz
13 ------ 250 Hz
14 ------ 500 Hz
15 ------ 1000 Hz
Default : 12
op_mode Set and get sensor mode RW Write :
0 ------ normal Mode
3 ------ deep suspend
4 ------ low power 2
5 ------ standby
Read:
0 ------ normal Mode
3 ------ deep suspend
4 ------ low power 2
5 ------ standby Mode
Default : 5
Value Get sensor x, y, z axis valus R Read return x, y, z axis values
Delay Set and get delay time for delay task RW value Range (0- 200) ms
Default : 200
Enable Enable or disable sensor work task RW Write :
0 ------ disable sensor
1 ------ enable sensor
Read :
0 ------ disable sensor
1 ------ enable sensor
Default : 0
sleepdur Set and get sleep phase
duration in Low Power mode
RW Write :
5 ------ 0.5ms
6 ------ 1ms
7 ------ 2ms
8 ------ 4ms
9 ------ 6ms
10 ------ 10ms
11 ------ 25ms
12 ------ 50ms
13 ------ 100ms
14 ------ 500ms
15 ------ 1s
Read :
5 ------ 0.5ms
6 ------ 1ms
7 ------ 2ms
8 ------ 4ms
9 ------ 6ms
10 ------ 10ms
11 ------ 25ms
12 ------ 50ms
13 ------ 100ms
14 ------ 500ms
15 ------ 1s
Default : 0
reg Set value to specific
register and get whole
register value
RW Write :
para1 para2
Para1: register address
Para2: value to be set
Read:
whole register and value
fast_calibration_x Set and get fast calibration
configure value for x axis
RW Write :
0 ------ 0 g
1 ------ 1 g
2 ------ -1 g
3 ------ 0 g
Read :
0 ------ 0 g
1 ------ 1 g
2 ------ -1 g
3 ------ 0 g
Default : 0
fast_calibration_y Set and get fast calibration
configure value for y axis
RW Write :
0 ------ 0 g
1 ------ 1 g
2 ------ -1 g
3 ------ 0 g
Read :
0 ------ 0 g
1 ------ 1 g
2 ------ -1 g
3 ------ 0 g
Default : 0
fast_calibration_z Set and get fast calibration
configure value for z axis
RW Write :
0 ------ 0 g
1 ------ 1 g
2 ------ -1 g
3 ------ 0 g
Read :
0 ------ 0 g
1 ------ 1 g
2 ------ -1 g
3 ------ 0 g
Default : 0
Chip_id Get sensor chip id R 0xFA
offset_x Set and get offset x register RW value Range (0- 255)
offset_y Set and get offset y register RW value Range (0- 255)
offset_z Set and get offset z register RW value Range (0- 255)
enable_int Enable or disable sensor interrupt W Write : para1 para2
Para1:
4 ------ Data Ready Interrupt
5 ------ Slope X Interrupt
6 ------ Slope Y Interrupt
7 ------ Slope Z Interrupt
Para2:
0 ------ disable interrupt
1 ------ enable interrupt
int_mode Set and get interrupt latched time RW Write :
0 ------ non-latched
1 ------ temporary, 250 ms
2 ------ temporary, 500 ms
3 ------ temporary, 1 s
4 ------ temporary, 2 s
5 ------ temporary, 4 s
6 ------ temporary, 8 s
7 ------ latched
8 ------ non-latched
9 ------ temporary, 500 us
10 ------ temporary, 500 us
11 ------ temporary, 1 ms
12 ------ temporary, 12.5 ms
13 ------ temporary, 25 ms
14 ------ temporary, 50 ms
15 ------ latched
Read :
0 ------ non-latched
1 ------ temporary, 250 ms
2 ------ temporary, 500 ms
3 ------ temporary, 1 s
4 ------ temporary, 2 s
5 ------ temporary, 4 s
6 ------ temporary, 8 s
7 ------ latched
8 ------ non-latched
9 ------ temporary, 250 us
10 ------ temporary, 500 us
11 ------ temporary, 1 ms
12 ------ temporary, 12.5 ms
13 ------ temporary, 25 ms
14 ------ temporary, 50 ms
15 ------ latched
Default : 1
slope_duration Set and get slope interrupt duration RW value Range (0- 3)
Default : 0
slope_threshold Set and get slope interrupt threshold RW value Range (0- 255)
Default : 0
en_sig_motion enable and disable slope function RW Write :
0 ------ disable
1 ------ enable
Read :
0 ------ disable
1 ------ enable
Default : 0
selftest Set selftest and get result RW Write:
1 ------ start self-test
Read:
0 ------ success
1 ------ x axis failed
2 ------ y axis failed
3 ------ x and y axis failed
4 ------ z axis failed
5 ------ x and z axis failed
6 ------ y and z axis failed
7 ------ x, y and z axis failed
softreset set soft reset W Write:
1 ------ start soft reset
temperature Read temperature in LSB R value Range (-127- 127)

SMI130_GYRO driver is registered as input class. In /sys/devices/virtual/input/inputX(X indicates the sensor number) on sysfs, the registered name is “smi130_gyro”.

The gyro sysfs interfaces are shown below.

Name Descriptions RW Usage
chip_id Get sensor chip id R 0x0F
name Get sensor name R smi130_gyro
range Set and get sensor range RW Write:
0 ------ +/- 2000 º/s
1 ------ +/- 1000 º/s
2 ------ +/- 500 º/s
3 ------ +/- 250 º/s
4 ------ +/- 125 º/s
Read:
0 ------ +/- 2000 º/s
1 ------ +/- 1000 º/s
2 ------ +/- 500 º/s
3 ------ +/- 250 º/s
4 ------ +/- 125 º/s
Default : 0
bandwidth set and get sensor bandwidth RW Write:
0 ------ 523 Hz
1 ------ 230 Hz
2 ------ 116 Hz
3 ------ 47 Hz
4 ------ 23 Hz
5 ------ 12 Hz
6 ------ 64 Hz
7 ------ 32 Hz
Read:
0 ------ 523 Hz
1 ------ 230 Hz
2 ------ 116 Hz
3 ------ 47 Hz
4 ------ 23 Hz
5 ------ 12 Hz
6 ------ 64 Hz
7 ------ 32 Hz
Default : 7
op_mode Set and get sensor mode RW Read :
0 ------ Normal Mode
1 ------ Deep suspend Mode
Write :
0 ------ normal Mode
1 ------ Deep suspend Mode
Default : 0
value Get sensor x, y, z axis values R Read return LSB values of x, y, z axis
reg Set value to specific
register and get whole
register value
RW Write :
para1 para2
Para1: register address
Para2: value to be set
Read:
whole register and value
selftest Perform a selftest for sensor R Read :
0 ------ selftest passed
1 ------ selftest failed
delay Set and get delay time for delay task RW value Range (0- 200) ms
enable Enable or disable sensor work task RW Write :
0 ------ disable sensor
1 ------ enable sensor
Read :
0 ------ disable sensor
1 ------ enable sensor
Default : 0

Input Event

Application should read input event for the sensor value and interrupt report. The input event descriptions are shown below. Table 4: Input event

Type Code Description Value
EV_MSC MSC_GESTURE Event for x axis LSB Value of X axis
EV_MSC MSC_RAW Event for x axis LSB Value of X axis
EV_MSC MSC_SCAN Event for x axis LSB Value of X axis
EV_MSC MSC_TIMESTAMP Event for Time Stamp Timestamp value
EV_REL REL_DIAL slope/any motion interrupt Interrupt notification 7-12

Interrupt support

Set SENSORS_SMI130_ENABLE_INTERRUPT to 'yes' in Kconfig file is prerequisite before using other interrupt features

SMI130 ACC interrupt

New data interrupt support

Set SENSORS_SMI130_ACC_ENABLE_NEWDATA_INT to ‘yes’ in Kconfig file

MOTION detection function support

Set SENSORS_SMI130_ACC_ENABLE_MOTION to ‘yes’ in Kconfig file

SMI130 GYRO interrupt

New data interrupt support

Set SENSORS_SMI130_GYRO_ENABLE_NEWDATA_INT to ‘yes’ in Kconfig file

Other configurations

Device Tree configuration

To enable driver probing, add the smi130_acc and smi130_gyro node to the platform device tree as described below.

Required properties:

- compatible: "bosch,smi130_acc"

- compatible: "bosch,smi130_gyro"

- reg: the I2C address or SPI chip select the device will respond to

- interrupt-parent: phandle to the parent interrupt controller as documented in interrupts

- interrupts: interrupt mapping for IRQ as documented in interrupts

I2C example (Qualcomm DragonBoard 410c):

  	status = "okay";
  	smi130_acc@19{
  			compatible = "smi130_acc";
  			reg = <0x19>;
  			interrupt-parent = <&msmgpio>;
  			interrupts = <115 0>; 
  			smi130_acc,gpio_irq = <&msmgpio 115 0>;
  			};
  	smi130_gyro@69{
  			compatible = "smi130_gyro";
  			reg = <0x69>;
  			interrupt-parent = <&msmgpio>;
  			interrupts = <13 0>; 
  			smi130_gyro,gpio_irq = <&msmgpio 13 0>;
  			};	

SPI example (Qualcomm DragonBoard 410c):

  	status = "okay";
  	cs-gpios = <&msmgpio 18 0>,<&msmgpio 110 0>;
  	spi-cpol = <0>;
  	spi-cpha = <0>;
  	smi130_acc@0{
  	 			spi-max-frequency = <500000>;					
  				compatible = "smi130_acc";
  				reg = <0>;
  				interrupt-parent = <&msmgpio>;
  				interrupts = <115 0>; 
  				smi130_acc,gpio_irq = <&msmgpio 115 0>;			
  	    };
  	smi130_gyro@1{
  				spi-max-frequency = <500000>;					
  				compatible = "smi130_gyro";
  				reg = <1>;
  				interrupt-parent = <&msmgpio>;
  				interrupts = <13 0>; 
  				smi130_gyro,gpio_irq = <&msmgpio 13 0>;
  		};

Kconfig configuration

Configure kernel with make menuconfig

  Device Drivers  --->
  	Input device support  --->
  	[*] Enable Bosch SMI130 IMU sensor  ---> 
  		Select communication interface (Enable I2C connection)  --->
  		  ( ) Enable SPI connection
  		  (X) Enable I2C connection
  		<*>  Bosch Sensor driver smart log function support  
  		<*>  SMI130 sensor support
  		  <*>  SMI130_ACC acceleration sensor interrupt INT2 support
  			  <*> enable acc data ready interrupt
  			  <*> support sensor slope/any motion function
  			  <*> enable gyro data ready interrupt 

Makefile configuration

  • Copy driver source code into the target directory (e.g. drivers/input/sensors/smi130)
  • Edit related Kconfig to include smi130 support:
    source "drivers/input/sensors/smi130/Kconfig"
  • Edit related Makefile adding the following line:
    obj-$(CONFIG_INPUT_SMI130)	+= sensors/smi130/