http://github.com/01org/android-iio-sensors-hal
https://source.android.com/devices/sensors/sensor-stack.html
sysfs path
buffer handling
/dev/iio:device0
/sys/bus/iio/devices/iio:device0/scan_elements
trigger setup
/sys/bus/iio/devices/iio:device0
/sys/bus/iio/triggers/trigger0
events handling
/sys/bus/iio/devices/iio:device0/events/
/dev/iio:device0
ioctl IIO_GET_EVENT_FD_IOCTL
close()
module struct must be named HAL_MODULE_INFO_SYM
declared in hardware/libhardware/include/hardware/sensors.h
interface must be thread safe
main data types
sensors_module_t
sensors_poll_device_t
sensor_t
sensor_event_t
main functions
get_sensors_list()
activate()
setDelay()
poll()
batch()
https://01.org/android-iio-sensors-hal
8K lines of code
open source
used on IRDA for Baytrail and Sofia
supported sensors
struct sensor_poll_device
hw_device_t
activate()
setDelay()
poll()
batch()
allocate_control_data()
enumerate_sensors()
discover supported sensors and save them into an array of sensor_t items
we can have up to MAX_SENSORS (at this moment 12)
10
/dev/iio:deviceX, X = 0..MAX_DEVICES
cannot have multiple sensors of the same type on the same IIO device
discovery done by iterating over /sys/bus/iio/devices
/sys/bus/iio/devices/iio:device0/scan_elements
11
sensor_info_t
device name
trigger name
drdy trigger
any motion trigger
hrtimer trigger
device index
array with channel_info
internal (accel_3d)
friendly (accelerometer)
offset, scale
path (raw, input)
mode
poll
trigger buffer
event
12
13
trigger mode
enable buffer
setup trigger
add fd associated with /dev/iio:deviceX to poll_fd
poll mode
enable sensor
start acquisition thread
event mode
enable event
get fd associated with event and add it to poll_fd
reverse operations for deactivate (enabled = false)
14
/sys/bus/iio/devices/iio:device0/in_accel_sampling_frequency
in buffer mode
/sys/bus/iio/devices/iio:device0/sampling_frequency
/sys/bus/iio/devices/iio:device0/available_sampling_frequency
15
calls in set_delay()
16
17
sensors_event_t
data passed from HAL layer to Android framework
struct sensors_event_t {
/* sensor type */
int32_t type;
/* time is in nanosecond */
int64_t timestamp;
union {
union {
float
data[16];
/* acceleration values are in (m/s^2) */
sensors_vec_t
acceleration;
/* other sensors */
union {
uint64_t
data[8];
/* step-counter */
uint64_t
step_counter;
}
}
};
18
sens tool
sens start <hal name>
sens ls
19
Q&A
continuous
on change
one shot
21
filtering
calibration
quirks
unit conversions
android properties
min_freq, max_freq
ro.iio.accel.kxcjk1013.min_freq = 50
22