From 2cf17b1ccf2e58eb14e2ea0d788d4bc0f599de7a Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Wed, 23 Dec 2015 07:52:30 +1100 Subject: i9300: use synchronous setsurface Change-Id: I715cbce3f4387bb557a9ddd2ec23deebc1b1d7ec --- BoardConfig.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BoardConfig.mk b/BoardConfig.mk index f10e0e4..3cbef38 100644 --- a/BoardConfig.mk +++ b/BoardConfig.mk @@ -28,6 +28,9 @@ BOARD_MODEM_TYPE := xmm6262 TARGET_SPECIFIC_HEADER_PATH := device/samsung/i9300/include COMMON_GLOBAL_CFLAGS += -DDISABLE_ASHMEM_TRACKING +# Graphics +TARGET_REQUIRES_SYNCHRONOUS_SETSURFACE := true + # Bluetooth BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR := device/samsung/i9300/bluetooth -- cgit v1.1 From f115fa584b0a929ba504b51899b97c706404e6dd Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Wed, 23 Dec 2015 14:28:03 +1100 Subject: i9300: update proprietary files Change-Id: I2386805d1fe134109b983c389ffa4208222c6f5a --- proprietary-files.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/proprietary-files.txt b/proprietary-files.txt index 56fe3d8..4ec4901 100644 --- a/proprietary-files.txt +++ b/proprietary-files.txt @@ -1,5 +1,6 @@ -system/bin/gpsd +system/bin/glgps +system/lib/hw/sensors.smkd4x12.so system/lib/hw/gps.exynos4.so +system/lib/libakm.so system/lib/libsec-ril.so -system/usr/idc/sec_touchscreen.idc system/usr/keylayout/sec_touchkey.kl -- cgit v1.1 From 68a1cea0871a356d7c6e2989ec576bff3178db7e Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Wed, 23 Dec 2015 14:29:13 +1100 Subject: i9300: ensure we don't build opensource sensors currently the compass seems to be really broken, so we'll use the proprietary ones for now Change-Id: I195e0765da7789d38940835d9e8c6eff4e09a900 --- BoardConfig.mk | 3 +++ libsensors/Android.mk | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/BoardConfig.mk b/BoardConfig.mk index 3cbef38..3130ef3 100644 --- a/BoardConfig.mk +++ b/BoardConfig.mk @@ -31,6 +31,9 @@ COMMON_GLOBAL_CFLAGS += -DDISABLE_ASHMEM_TRACKING # Graphics TARGET_REQUIRES_SYNCHRONOUS_SETSURFACE := true +# Sensors +BOARD_USES_OPENSOURCE_SENSORS := false + # Bluetooth BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR := device/samsung/i9300/bluetooth diff --git a/libsensors/Android.mk b/libsensors/Android.mk index 8d15195..8bdcd66 100644 --- a/libsensors/Android.mk +++ b/libsensors/Android.mk @@ -12,7 +12,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . - +ifeq ($(BOARD_USES_OPENSOURCE_SENSORS),true) LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) @@ -46,3 +46,4 @@ LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw LOCAL_MODULE_TAGS := optional include $(BUILD_SHARED_LIBRARY) +endif -- cgit v1.1 From 5e3bd2316fb1e5f017ba70ae5a0710ed919ed432 Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Thu, 14 Jan 2016 16:12:03 +1100 Subject: i9300: join the snap party Change-Id: Id397b5a07a3239e87f8be41868401c9f5c788e36 --- i9300.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/i9300.mk b/i9300.mk index c426f41..5735dfa 100644 --- a/i9300.mk +++ b/i9300.mk @@ -66,7 +66,8 @@ PRODUCT_PACKAGES += \ # Camera PRODUCT_PACKAGES += \ - camera.smdk4x12 + camera.smdk4x12 \ + Snap PRODUCT_COPY_FILES += \ packages/apps/Nfc/migrate_nfc.txt:system/etc/updatecmds/migrate_nfc.txt \ -- cgit v1.1 From dc7601b1fcf97f847e0316b8cac3d886aefcae14 Mon Sep 17 00:00:00 2001 From: keepcalm444 Date: Fri, 29 Jan 2016 23:56:16 +1100 Subject: i9300: add lmk config Change-Id: I8736cb90544f5dc5b28ac2a166e99f85ad2eaf04 --- overlay/frameworks/base/core/res/res/values/config.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml index 74d4119..2b8c412 100644 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -313,4 +313,13 @@ format is UMTS|LTE|... --> GPRS|EDGE|WCDMA + + + 122880 -- cgit v1.1 From b6a0d03e64f725627828653e071e2b1e8d9b4347 Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Mon, 1 Feb 2016 02:56:43 -0800 Subject: Revert "i9300: add lmk config" * this did not seem to work as well as I'd hoped. This reverts commit dc7601b1fcf97f847e0316b8cac3d886aefcae14. Change-Id: I3041187d8b3aaee46bd09eaa2a9082cf56635b7b --- overlay/frameworks/base/core/res/res/values/config.xml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml index 2b8c412..74d4119 100644 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -313,13 +313,4 @@ format is UMTS|LTE|... --> GPRS|EDGE|WCDMA - - - 122880 -- cgit v1.1 From 4e0a903a42f1acd7a01eacdcb2f5f5c50ebe135f Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Tue, 2 Feb 2016 22:31:38 +1100 Subject: i9300: downclock more aggressively previously, pegasusq would keep 3 or 4 cores active with static content on the screen tweak the governor's values so that sometimes we get down to 1 core active with screen on, both by increasing the on/off clock speeds/rq sizes of secondary cores, bumping up_threshold and encouraging faster downclocking. Change-Id: I698bec823312cac7b859ed8d5ac303873fddc7bc --- rootdir/init.target.rc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/rootdir/init.target.rc b/rootdir/init.target.rc index 4b9b015..1c94d39 100644 --- a/rootdir/init.target.rc +++ b/rootdir/init.target.rc @@ -3,6 +3,7 @@ on init # ko files for FM Radio insmod /system/lib/modules/Si4709_driver.ko + on post-fs-data # icd exec icd_check @@ -59,4 +60,21 @@ service gps-daemon /system/bin/sh /system/bin/gps_daemon.sh group system inet sdcard_rw gps seclabel u:r:glgps:s0 - +on property:dev.bootcomplete=1 +# boot on default pegasusq settings (for better performance) +# switch to more conservative settings after bootup is complete + write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_1_1 500000 + write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_2_0 500000 + write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_2_1 700000 + write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_3_0 700000 + write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_3_1 900000 + write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_4_0 900000 + write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_1_1 150 + write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_2_0 150 + write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_2_1 250 + write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_3_0 250 + write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_3_1 350 + write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_4_0 450 + write /sys/devices/system/cpu/cpufreq/pegasusq/up_threshold 90 + write /sys/devices/system/cpu/cpufreq/pegasusq/cpu_down_rate 10 + write /sys/devices/system/cpu/cpufreq/pegasusq/down_differential 3 -- cgit v1.1 From 50a1bdc2081282d5340ddee956f8b0548c3f1d4a Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Thu, 11 Feb 2016 23:42:52 +1100 Subject: i9300: allow system_server access to mdnie sysfs needed for any mdnie stuff that ends up in cmhw Change-Id: I6efe58e295cae59f074abc4a1fd64258fb5d8188 --- selinux/system_server.te | 3 +++ 1 file changed, 3 insertions(+) diff --git a/selinux/system_server.te b/selinux/system_server.te index b9cc2f2..b20927b 100644 --- a/selinux/system_server.te +++ b/selinux/system_server.te @@ -4,6 +4,9 @@ allow system_server sensors_data_file:file r_file_perms; allow system_server wpa_socket:unix_dgram_socket sendto; allow system_server sysfs:file { read open write }; +allow system_server sysfs_display:lnk_file rw_file_perms; +allow system_server sysfs_display:dir rw_dir_perms; +allow system_server sysfs_display:file rw_file_perms; allow system_server self:capability { sys_module }; allow system_server efs_file:dir search; -- cgit v1.1 From bcb3068019136761aaa95c82fd060cf56c863d8a Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Tue, 9 Feb 2016 12:23:15 +1100 Subject: i9300: move macloader and tinyplay sepolicy up to -common [2/2] Change-Id: I874a9f2f6590755e5815e18bcdc5d1e0cdac4523 --- selinux/file_contexts | 2 -- selinux/init.te | 2 -- selinux/macloader.te | 9 --------- selinux/tinyplay.te | 6 ------ 4 files changed, 19 deletions(-) delete mode 100644 selinux/macloader.te delete mode 100644 selinux/tinyplay.te diff --git a/selinux/file_contexts b/selinux/file_contexts index 12bbd51..6e54311 100644 --- a/selinux/file_contexts +++ b/selinux/file_contexts @@ -62,5 +62,3 @@ # Misc /dev/HPD u:object_r:hpd_device:s0 -/system/bin/macloader u:object_r:macloader_exec:s0 -/system/bin/tinyplay u:object_r:tinyplay_exec:s0 diff --git a/selinux/init.te b/selinux/init.te index 795e077..6056a94 100644 --- a/selinux/init.te +++ b/selinux/init.te @@ -11,5 +11,3 @@ allow init rild:process noatsecure; domain_trans(init, rootfs, glgps) domain_trans(init, rootfs, cpboot-daemon) -domain_trans(init, rootfs, tinyplay) -domain_trans(init, rootfs, macloader) diff --git a/selinux/macloader.te b/selinux/macloader.te deleted file mode 100644 index 464f201..0000000 --- a/selinux/macloader.te +++ /dev/null @@ -1,9 +0,0 @@ -type macloader, domain; -type macloader_exec, exec_type, file_type; -init_daemon_domain(macloader); - -allow macloader efs_file:dir search; -allow macloader efs_device_file:dir search; -allow macloader wifi_data_file:file { read getattr open write setattr }; -allow macloader self:capability { dac_override chown fowner fsetid }; -allow macloader system_data_file:dir w_dir_perms; diff --git a/selinux/tinyplay.te b/selinux/tinyplay.te deleted file mode 100644 index ef7de81..0000000 --- a/selinux/tinyplay.te +++ /dev/null @@ -1,6 +0,0 @@ -type tinyplay, domain; -type tinyplay_exec, exec_type, file_type; -init_daemon_domain(tinyplay) - -allow tinyplay audio_device:chr_file { open read write ioctl }; -allow tinyplay audio_device:dir search; -- cgit v1.1 From 05bc142abca6ecabaaeca16f980c5904ff90926d Mon Sep 17 00:00:00 2001 From: rogersb11 Date: Sun, 14 Feb 2016 18:19:23 -0500 Subject: Move Snap to common tree Change-Id: I0ffe9a68ebadab7a91866857e1b5dfcf398551ea --- i9300.mk | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/i9300.mk b/i9300.mk index 5735dfa..c426f41 100644 --- a/i9300.mk +++ b/i9300.mk @@ -66,8 +66,7 @@ PRODUCT_PACKAGES += \ # Camera PRODUCT_PACKAGES += \ - camera.smdk4x12 \ - Snap + camera.smdk4x12 PRODUCT_COPY_FILES += \ packages/apps/Nfc/migrate_nfc.txt:system/etc/updatecmds/migrate_nfc.txt \ -- cgit v1.1 From 2a12d023390e1d1477728ff1cd8f665a394a8ce9 Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Mon, 15 Feb 2016 23:17:39 +1100 Subject: i9300: mqanelements should actually be 4 fixes manual network selection Change-Id: I516917a816a202020d41b8621d7ea07464c73f1f --- system.prop | 1 - 1 file changed, 1 deletion(-) diff --git a/system.prop b/system.prop index 975f696..db6bcfd 100644 --- a/system.prop +++ b/system.prop @@ -5,6 +5,5 @@ dalvik.vm.dexopt-data-only=1 rild.libpath=/system/lib/ril-wrapper.so rild.libargs=-d /dev/ttyS0 -ro.ril.telephony.mqanelements=5 ro.sf.lcd_density=320 ro.lcd_min_brightness=20 -- cgit v1.1 From dfd4d7db60d9b1abeeadcd203179803e6d9be7c6 Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Sun, 14 Feb 2016 23:15:20 +1100 Subject: i9300: enable f2fs support Change-Id: I4405cbf6573e277ac7d2dbcb0014131d9cbbcc9d --- BoardConfig.mk | 1 + i9300.mk | 6 ++++++ rootdir/fstab.smdk4x12 | 2 ++ 3 files changed, 9 insertions(+) diff --git a/BoardConfig.mk b/BoardConfig.mk index 3130ef3..262c044 100644 --- a/BoardConfig.mk +++ b/BoardConfig.mk @@ -44,6 +44,7 @@ BOARD_RIL_CLASS := ../../../device/samsung/i9300/ril # Recovery TARGET_RECOVERY_FSTAB := device/samsung/i9300/rootdir/fstab.smdk4x12 +TARGET_USERIMAGES_USE_F2FS := true RECOVERY_FSTAB_VERSION := 2 # Selinux diff --git a/i9300.mk b/i9300.mk index c426f41..0b14d57 100644 --- a/i9300.mk +++ b/i9300.mk @@ -68,6 +68,12 @@ PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \ camera.smdk4x12 +# f2fs +PRODUCT_PACKAGES += \ + fibmap.f2fs \ + fsck.f2fs \ + mkfs.f2fs + PRODUCT_COPY_FILES += \ packages/apps/Nfc/migrate_nfc.txt:system/etc/updatecmds/migrate_nfc.txt \ frameworks/base/nfc-extras/com.android.nfc_extras.xml:system/etc/permissions/com.android.nfc_extras.xml \ diff --git a/rootdir/fstab.smdk4x12 b/rootdir/fstab.smdk4x12 index 507d3ed..878876e 100644 --- a/rootdir/fstab.smdk4x12 +++ b/rootdir/fstab.smdk4x12 @@ -4,8 +4,10 @@ # specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK /dev/block/mmcblk0p3 /efs ext4 noatime,nosuid,nodev,journal_async_commit,errors=panic wait /dev/block/mmcblk0p9 /system ext4 ro,noatime wait +/dev/block/mmcblk0p8 /cache f2fs noatime,nosuid,nodev wait /dev/block/mmcblk0p8 /cache ext4 noatime,nosuid,nodev,journal_async_commit,errors=panic wait /dev/block/mmcblk0p10 /preload ext4 noatime,nosuid,nodev,journal_async_commit wait +/dev/block/mmcblk0p12 /data f2fs noatime,nosuid,nodev wait,check,encryptable=footer /dev/block/mmcblk0p12 /data ext4 noatime,nosuid,nodev,noauto_da_alloc,journal_async_commit,errors=panic wait,check,encryptable=footer # vold-managed volumes ("block device" is actually a sysfs devpath) -- cgit v1.1 From 5339fe1e8ffc87f04ed2692c2e6d1c892f63a0c1 Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Thu, 18 Feb 2016 17:27:25 +1100 Subject: i9300: fix selinux denial Change-Id: I3e8a8ca2e35cca22bdd248c1bfe9433f2d8285fb --- selinux/system_server.te | 2 ++ 1 file changed, 2 insertions(+) diff --git a/selinux/system_server.te b/selinux/system_server.te index b20927b..edf79dc 100644 --- a/selinux/system_server.te +++ b/selinux/system_server.te @@ -22,6 +22,8 @@ allow system_server system_file:file execmod; # /efs/wifi/.mac.info allow system_server wifi_data_file:file { read open }; +allow system_server radio_data:dir r_dir_perms; + allow system_server glgps:binder transfer; type_transition system_server system_data_file:fifo_file gps_data_file ".gps.interface.pipe.to_jni"; -- cgit v1.1 From df49c15ad129636319fe201151fea4292d0c7b0a Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Sat, 20 Feb 2016 17:33:20 +1100 Subject: i9300: update proprietary-files and extract-files extract gps HAL to the expected location Change-Id: I3f391310b416889c8d99107dec53eb276823e5f7 --- extract-files.sh | 24 +++++++++++++++++------- proprietary-files.txt | 4 ++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/extract-files.sh b/extract-files.sh index 19dd948..c9d5f07 100755 --- a/extract-files.sh +++ b/extract-files.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright (C) 2013 The CyanogenMod Project +# Copyright (C) 2016 The CyanogenMod Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -26,16 +26,21 @@ adb wait-for-device echo "Pulling proprietary files..." for FILE in `cat proprietary-files.txt | grep -v ^# | grep -v ^$`; do - DIR=`dirname $FILE` + DEST=$FILE + if echo $FILE | grep ':' 2>&1 >/dev/null; then + DEST=`echo $FILE | sed 's/.*://'` + FILE=`echo $FILE | sed 's/:.*//'` + fi + DIR=`dirname $DEST` if [ ! -d ../../../vendor/$VENDOR/$DEVICE/proprietary/$DIR ]; then mkdir -p ../../../vendor/$VENDOR/$DEVICE/proprietary/$DIR fi - adb pull /$FILE ../../../vendor/$VENDOR/$DEVICE/proprietary/$FILE + adb pull /$FILE ../../../vendor/$VENDOR/$DEVICE/proprietary/$DEST done (cat << EOF) | sed s/__DEVICE__/$DEVICE/g | sed s/__VENDOR__/$VENDOR/g > ../../../vendor/$VENDOR/$DEVICE/$DEVICE-vendor-blobs.mk -# Copyright (C) 2013 The CyanogenMod Project +# Copyright (C) 2016 The CyanogenMod Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -61,11 +66,16 @@ for FILE in `cat proprietary-files.txt | grep -v ^# | grep -v ^$`; do if [ $COUNT = "0" ]; then LINEEND="" fi - echo " \$(LOCAL_PATH)/proprietary/$FILE:$FILE$LINEEND" >> ../../../vendor/$VENDOR/$DEVICE/$DEVICE-vendor-blobs.mk + DEST=$FILE + if echo $FILE | grep ':' 2>&1 >/dev/null; then + DEST=`echo $FILE | sed 's/.*://'` + FILE=`echo $FILE | sed 's/:.*//'` + fi + echo " \$(LOCAL_PATH)/proprietary/$DEST:$FILE$LINEEND" >> ../../../vendor/$VENDOR/$DEVICE/$DEVICE-vendor-blobs.mk done (cat << EOF) | sed s/__DEVICE__/$DEVICE/g | sed s/__VENDOR__/$VENDOR/g > ../../../vendor/$VENDOR/$DEVICE/$DEVICE-vendor.mk -# Copyright (C) 2013 The CyanogenMod Project +# Copyright (C) 2016 The CyanogenMod Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -86,7 +96,7 @@ DEVICE_PACKAGE_OVERLAYS += vendor/__VENDOR__/__DEVICE__/overlay EOF (cat << EOF) | sed s/__DEVICE__/$DEVICE/g | sed s/__VENDOR__/$VENDOR/g > ../../../vendor/$VENDOR/$DEVICE/BoardConfigVendor.mk -# Copyright (C) 2013 The CyanogenMod Project +# Copyright (C) 2016 The CyanogenMod Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/proprietary-files.txt b/proprietary-files.txt index 4ec4901..ac24b1c 100644 --- a/proprietary-files.txt +++ b/proprietary-files.txt @@ -1,6 +1,6 @@ system/bin/glgps -system/lib/hw/sensors.smkd4x12.so -system/lib/hw/gps.exynos4.so +system/lib/hw/sensors.smdk4x12.so +system/lib/hw/gps.exynos4.so:system/lib/hw/gps.tegra3.so system/lib/libakm.so system/lib/libsec-ril.so system/usr/keylayout/sec_touchkey.kl -- cgit v1.1 From fc026276eb8c351447d4f6b0a6b65c48e64327bd Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Fri, 12 Feb 2016 23:36:41 +1100 Subject: i9300: chown pegasusq cpufreq nodes to system:system Change-Id: Iadbeeffcf0db58a0a96f99df596cdb0f32dd589f --- rootdir/init.target.rc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/rootdir/init.target.rc b/rootdir/init.target.rc index 1c94d39..492b130 100644 --- a/rootdir/init.target.rc +++ b/rootdir/init.target.rc @@ -2,6 +2,36 @@ on init export LD_SHIM_LIBS /system/lib/libsec-ril.so|libsamsung_symbols.so # ko files for FM Radio insmod /system/lib/modules/Si4709_driver.ko + chown system system /sys/devices/system/cpu/cpufreq/pegasusq + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/cpu_down_freq + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/cpu_down_rate + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/cpu_up_freq + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/cpu_up_rate + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/cpucore_table + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/down_differential + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/dvfs_debug + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/freq_step + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_1_1 + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_2_0 + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_2_1 + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_3_0 + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_3_1 + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_4_0 + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_lock + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_1_1 + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_2_0 + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_2_1 + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_3_0 + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_3_1 + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_4_0 + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/ignore_nice_load + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/io_is_busy + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/up_threshold + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/min_cpu_lock + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/max_cpu_lock + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/sampling_rate + + on post-fs-data -- cgit v1.1 From 07aacd2a067df13e5b4fc07ec978c0d127073b61 Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Thu, 11 Feb 2016 23:43:38 +1100 Subject: i9300: initial pegasusq powerhal * based off flo * powersave (3 core max/1GHz), balanced (current defaults), and performance (back off on downscaling) * support for separate low power profiles (activated on screen off) PS2: low power + min/max cpu freq support PS3: whitespace fixes PS4: apparently POWER_HINT_LOW_POWER means PROFILES[POWER_SAVE]. Change-Id: I786a9e0e35fcc1dba1510baa13493ecf261bdfcc --- BoardConfig.mk | 3 + i9300.mk | 4 + power/Android.mk | 29 +++++ power/power.c | 340 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ power/power.h | 198 ++++++++++++++++++++++++++++++++ 5 files changed, 574 insertions(+) create mode 100644 power/Android.mk create mode 100644 power/power.c create mode 100644 power/power.h diff --git a/BoardConfig.mk b/BoardConfig.mk index 262c044..cabfc99 100644 --- a/BoardConfig.mk +++ b/BoardConfig.mk @@ -47,6 +47,9 @@ TARGET_RECOVERY_FSTAB := device/samsung/i9300/rootdir/fstab.smdk4x12 TARGET_USERIMAGES_USE_F2FS := true RECOVERY_FSTAB_VERSION := 2 +# PowerHAL +TARGET_POWERHAL_VARIANT := pegasusq + # Selinux BOARD_SEPOLICY_DIRS += \ device/samsung/i9300/selinux diff --git a/i9300.mk b/i9300.mk index 0b14d57..8a2c01a 100644 --- a/i9300.mk +++ b/i9300.mk @@ -39,6 +39,10 @@ PRODUCT_COPY_FILES += \ PRODUCT_PACKAGES += \ sensors.smdk4x12 +# Power +PRODUCT_PACKAGES += \ + power.smdk4x12 + # Gps PRODUCT_COPY_FILES += \ $(LOCAL_PATH)/configs/gps.xml:system/etc/gps.xml \ diff --git a/power/Android.mk b/power/Android.mk new file mode 100644 index 0000000..0cb4890 --- /dev/null +++ b/power/Android.mk @@ -0,0 +1,29 @@ +# Copyright (C) 2016 The CyanogenMod Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +LOCAL_PATH := $(call my-dir) + +ifeq ($(TARGET_POWERHAL_VARIANT),pegasusq) + +include $(CLEAR_VARS) + +LOCAL_MODULE := power.$(TARGET_BOOTLOADER_BOARD_NAME) +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_SHARED_LIBRARIES := liblog libcutils +LOCAL_SRC_FILES := power.c +LOCAL_MODULE_TAGS := optional + +include $(BUILD_SHARED_LIBRARY) + +endif diff --git a/power/power.c b/power/power.c new file mode 100644 index 0000000..2e65f1b --- /dev/null +++ b/power/power.c @@ -0,0 +1,340 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#define LOG_TAG "PegasusPowerHAL" + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#define LOG_NDEBUG 0 +#include + +#include "power.h" + +#define PEGASUSQ_PATH "/sys/devices/system/cpu/cpufreq/pegasusq/" +#define MINMAX_CPU_PATH "/sys/power/" + +static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; + +static int current_power_profile = -1; +static bool is_low_power = false; + +static int sysfs_write_str(char *path, char *s) { + char buf[80]; + int len; + int ret = 0; + int fd; + + fd = open(path, O_WRONLY); + if (fd < 0) { + strerror_r(errno, buf, sizeof(buf)); + ALOGE("Error opening %s: %s\n", path, buf); + return -1 ; + } + + len = write(fd, s, strlen(s)); + if (len < 0) { + strerror_r(errno, buf, sizeof(buf)); + ALOGE("Error writing to %s: %s\n", path, buf); + ret = -1; + } + + close(fd); + + return ret; +} + +static int sysfs_write_int(char *path, int value) { + char buf[80]; + snprintf(buf, 80, "%d", value); + return sysfs_write_str(path, buf); +} +#ifdef LOG_NDEBUG +#define WRITE_PEGASUSQ_PARAM(profile, param) do { \ + ALOGV("%s: WRITE_PEGASUSQ_PARAM(profile=%d, param=%s): new val => %d", __func__, profile, #param, profiles[profile].param); \ + sysfs_write_int(PEGASUSQ_PATH #param, profiles[profile].param); \ +} while (0) +#define WRITE_LOW_POWER_PARAM(profile, param) do { \ + ALOGV("%s: WRITE_LOW_POWER_PARAM(profile=%d, param=%s): new val => %d", \ + __func__, profile, #param, profiles_low_power[profile].param); \ + sysfs_write_int(PEGASUSQ_PATH #param, profiles_low_power[profile].param); \ +} while (0) +#define WRITE_PEGASUSQ_VALUE(param, value) do { \ + ALOGV("%s: WRITE_PEGASUSQ_VALUE(param=%s, value=%d)", __func__, #param, value); \ + sysfs_write_int(PEGASUSQ_PATH #param, value); \ +} while (0) +#define WRITE_MINMAX_CPU(param, value) do { \ + ALOGV("%s: WRITE_MINMAX_CPU(param=%s, value=%d)", __func__, #param, value); \ + sysfs_write_int(MINMAX_CPU_PATH #param, value); \ +} while(0) +#else +#define WRITE_PEGASUSQ_PARAM(profile, param) sysfs_write_int(PEGASUSQ_PATH #param, profiles[profile].param) +#define WRITE_LOW_POWER_PARAM(profile, param) sysfs_write_int(PEGASUSQ_PATH #param, profiles_low_power[profile].param) +#define WRITE_PEGASUSQ_VALUE(param, value) sysfs_write_int(PEGASUSQ_PATH #param, value) +#define WRITE_MINMAX_CPU(param, value) sysfs_write_int(MINMAX_CPU_PATH #param, value) +#endif +static bool check_governor() { + struct stat s; + int err = stat(PEGASUSQ_PATH, &s); + if (err != 0) return false; + return S_ISDIR(s.st_mode); +} + +static bool is_profile_valid(int profile) { + return profile >= 0 && profile < PROFILE_MAX; +} + +static void set_power_profile(int profile) { + if (!is_profile_valid(profile)) { + ALOGE("%s: unknown profile: %d", __func__, profile); + return; + } + + if (!check_governor()) return; + + if (profile == current_power_profile) return; + + WRITE_PEGASUSQ_PARAM(profile, hotplug_freq_1_1); + WRITE_PEGASUSQ_PARAM(profile, hotplug_freq_2_0); + WRITE_PEGASUSQ_PARAM(profile, hotplug_freq_2_1); + WRITE_PEGASUSQ_PARAM(profile, hotplug_freq_3_0); + WRITE_PEGASUSQ_PARAM(profile, hotplug_freq_3_1); + WRITE_PEGASUSQ_PARAM(profile, hotplug_freq_4_0); + WRITE_PEGASUSQ_PARAM(profile, hotplug_rq_1_1); + WRITE_PEGASUSQ_PARAM(profile, hotplug_rq_2_0); + WRITE_PEGASUSQ_PARAM(profile, hotplug_rq_2_1); + WRITE_PEGASUSQ_PARAM(profile, hotplug_rq_3_0); + WRITE_PEGASUSQ_PARAM(profile, hotplug_rq_3_1); + WRITE_PEGASUSQ_PARAM(profile, hotplug_rq_4_0); + WRITE_MINMAX_CPU(cpufreq_max_limit, profiles[profile].max_freq); + WRITE_MINMAX_CPU(cpufreq_min_limit, profiles[profile].min_freq); + WRITE_PEGASUSQ_PARAM(profile, up_threshold); + WRITE_PEGASUSQ_PARAM(profile, down_differential); + WRITE_PEGASUSQ_PARAM(profile, min_cpu_lock); + WRITE_PEGASUSQ_PARAM(profile, max_cpu_lock); + WRITE_PEGASUSQ_PARAM(profile, cpu_down_rate); + WRITE_PEGASUSQ_PARAM(profile, sampling_rate); + WRITE_PEGASUSQ_PARAM(profile, io_is_busy); + + current_power_profile = profile; + + ALOGV("%s: %d", __func__, profile); + +} + +static void set_low_power(bool low_power) { + if (!is_profile_valid(current_power_profile)) { + ALOGV("%s: current_power_profile not set yet", __func__); + return; + } + + if (!check_governor()) return; + + if (is_low_power == low_power) return; + + if (low_power) { + WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_freq_1_1); + WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_freq_2_0); + WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_freq_2_1); + WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_freq_3_0); + WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_freq_3_1); + WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_freq_4_0); + WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_rq_1_1); + WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_rq_2_0); + WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_rq_2_1); + WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_rq_3_0); + WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_rq_3_1); + WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_rq_4_0); + WRITE_MINMAX_CPU(cpufreq_max_limit, profiles_low_power[current_power_profile].max_freq); + WRITE_MINMAX_CPU(cpufreq_min_limit, profiles_low_power[current_power_profile].min_freq); + WRITE_LOW_POWER_PARAM(current_power_profile, up_threshold); + WRITE_LOW_POWER_PARAM(current_power_profile, down_differential); + WRITE_LOW_POWER_PARAM(current_power_profile, min_cpu_lock); + WRITE_LOW_POWER_PARAM(current_power_profile, max_cpu_lock); + WRITE_LOW_POWER_PARAM(current_power_profile, cpu_down_rate); + WRITE_LOW_POWER_PARAM(current_power_profile, sampling_rate); + WRITE_LOW_POWER_PARAM(current_power_profile, io_is_busy); + is_low_power = true; + } else { + WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_freq_1_1); + WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_freq_2_0); + WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_freq_2_1); + WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_freq_3_0); + WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_freq_3_1); + WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_freq_4_0); + WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_rq_1_1); + WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_rq_2_0); + WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_rq_2_1); + WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_rq_3_0); + WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_rq_3_1); + WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_rq_4_0); + WRITE_MINMAX_CPU(cpufreq_max_limit, profiles[current_power_profile].max_freq); + WRITE_MINMAX_CPU(cpufreq_min_limit, profiles[current_power_profile].min_freq); + WRITE_PEGASUSQ_PARAM(current_power_profile, up_threshold); + WRITE_PEGASUSQ_PARAM(current_power_profile, down_differential); + WRITE_PEGASUSQ_PARAM(current_power_profile, min_cpu_lock); + WRITE_PEGASUSQ_PARAM(current_power_profile, max_cpu_lock); + WRITE_PEGASUSQ_PARAM(current_power_profile, cpu_down_rate); + WRITE_PEGASUSQ_PARAM(current_power_profile, sampling_rate); + WRITE_PEGASUSQ_PARAM(current_power_profile, io_is_busy); + is_low_power = false; + } +} + + + +/* + * (*init)() performs power management setup actions at runtime + * startup, such as to set default cpufreq parameters. This is + * called only by the Power HAL instance loaded by + * PowerManagerService. + */ +static void power_init(__attribute__((unused)) struct power_module *module) { + set_power_profile(PROFILE_BALANCED); + ALOGV("%s", __func__); +} + +/* + * The setInteractive function performs power management actions upon the + * system entering interactive state (that is, the system is awake and ready + * for interaction, often with UI devices such as display and touchscreen + * enabled) or non-interactive state (the system appears asleep, display + * usually turned off). The non-interactive state is usually entered after a + * period of inactivity, in order to conserve battery power during such + * inactive periods. + * + * Typical actions are to turn on or off devices and adjust cpufreq parameters. + * This function may also call the appropriate interfaces to allow the kernel + * to suspend the system to low-power sleep state when entering non-interactive + * state, and to disallow low-power suspend when the system is in interactive + * state. When low-power suspend state is allowed, the kernel may suspend the + * system whenever no wakelocks are held. + * + * on is non-zero when the system is transitioning to an interactive / awake + * state, and zero when transitioning to a non-interactive / asleep state. + * + * This function is called to enter non-interactive state after turning off the + * screen (if present), and called to enter interactive state prior to turning + * on the screen. + */ +static void power_set_interactive(__attribute__((unused)) struct power_module *module, int on) { + if (!is_profile_valid(current_power_profile)) { + ALOGD("%s: no power profile selected", __func__); + return; + } + + if (!check_governor()) return; + ALOGV("%s: setting interactive => %d", __func__, on); + pthread_mutex_lock(&lock); + set_low_power(!on); + pthread_mutex_unlock(&lock); +} + +/* + * The powerHint function is called to pass hints on power requirements, which + * may result in adjustment of power/performance parameters of the cpufreq + * governor and other controls. + * + * The possible hints are: + * + * POWER_HINT_VSYNC + * + * Foreground app has started or stopped requesting a VSYNC pulse + * from SurfaceFlinger. If the app has started requesting VSYNC + * then CPU and GPU load is expected soon, and it may be appropriate + * to raise speeds of CPU, memory bus, etc. The data parameter is + * non-zero to indicate VSYNC pulse is now requested, or zero for + * VSYNC pulse no longer requested. + * + * POWER_HINT_INTERACTION + * + * User is interacting with the device, for example, touchscreen + * events are incoming. CPU and GPU load may be expected soon, + * and it may be appropriate to raise speeds of CPU, memory bus, + * etc. The data parameter is unused. + * + * POWER_HINT_LOW_POWER + * + * Low power mode is activated or deactivated. Low power mode + * is intended to save battery at the cost of performance. The data + * parameter is non-zero when low power mode is activated, and zero + * when deactivated. + * + * POWER_HINT_CPU_BOOST + * + * An operation is happening where it would be ideal for the CPU to + * be boosted for a specific duration. The data parameter is an + * integer value of the boost duration in microseconds. + */ +static void power_hint(__attribute__((unused)) struct power_module *module, power_hint_t hint, void *data) { + switch (hint) { + case POWER_HINT_SET_PROFILE: + ALOGV("%s: set profile %d", __func__, *(int32_t *)data); + pthread_mutex_lock(&lock); + set_power_profile(*(int32_t *)data); + pthread_mutex_unlock(&lock); + break; + case POWER_HINT_INTERACTION: + case POWER_HINT_VSYNC: + break; + case POWER_HINT_LOW_POWER: + break; + default: + break; + } +} + +/* + * (*getFeature) is called to get the current value of a particular + * feature or capability from the hardware or PowerHAL + */ +static int power_get_feature(__attribute__((unused)) struct power_module *module, feature_t feature) { + ALOGV("%s: %d", __func__, feature); + if (feature == POWER_FEATURE_SUPPORTED_PROFILES) { + return PROFILE_MAX; + } + ALOGV("%s: unknown feature %d", __func__, feature); + return -1; +} + +static struct hw_module_methods_t power_module_methods = { + .open = NULL, +}; + +struct power_module HAL_MODULE_INFO_SYM = { + .common = { + .tag = HARDWARE_MODULE_TAG, + .module_api_version = POWER_MODULE_API_VERSION_0_2, + .hal_api_version = HARDWARE_HAL_API_VERSION, + .id = POWER_HARDWARE_MODULE_ID, + .name = "smdk4x12 Power HAL", + .author = "The CyanogenMod Project", + .methods = &power_module_methods, + }, + + .init = power_init, + .setInteractive = power_set_interactive, + .powerHint = power_hint, + .getFeature = power_get_feature +}; diff --git a/power/power.h b/power/power.h new file mode 100644 index 0000000..db031cf --- /dev/null +++ b/power/power.h @@ -0,0 +1,198 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +enum { + PROFILE_POWER_SAVE = 0, + PROFILE_BALANCED, + PROFILE_PERFORMANCE, + PROFILE_MAX +}; + +typedef struct governor_settings { + // freq values for core up/down + int hotplug_freq_1_1; + int hotplug_freq_2_0; + int hotplug_freq_2_1; + int hotplug_freq_3_0; + int hotplug_freq_3_1; + int hotplug_freq_4_0; + // rq sizes for up/down + int hotplug_rq_1_1; + int hotplug_rq_2_0; + int hotplug_rq_2_1; + int hotplug_rq_3_0; + int hotplug_rq_3_1; + int hotplug_rq_4_0; + // max/min freqs (-1 for default) + int max_freq; + int min_freq; + // load at which to start scaling up + int up_threshold; + // higher down_differential == slower downscaling + int down_differential; + // min/max num of cpus to have online + int min_cpu_lock; + int max_cpu_lock; + // wait sampling_rate * cpu_down_rate us before trying to downscale + int cpu_down_rate; + int sampling_rate; // in microseconds + int io_is_busy; +} power_profile; + +static power_profile profiles[PROFILE_MAX] = { + [PROFILE_POWER_SAVE] = { + .hotplug_freq_1_1 = 800000, + .hotplug_freq_2_0 = 700000, + .hotplug_freq_2_1 = 1000000, + .hotplug_freq_3_0 = 900000, + .hotplug_freq_3_1 = 1200000, + .hotplug_freq_4_0 = 1100000, + .hotplug_rq_1_1 = 200, + .hotplug_rq_2_0 = 200, + .hotplug_rq_2_1 = 300, + .hotplug_rq_3_0 = 300, + .hotplug_rq_3_1 = 400, + .hotplug_rq_4_0 = 400, + .max_freq = 1000000, + .min_freq = -1, + .up_threshold = 95, + .down_differential = 2, + .min_cpu_lock = 0, + .max_cpu_lock = 3, + .cpu_down_rate = 5, + .sampling_rate = 200000, + .io_is_busy = 0, + }, + [PROFILE_BALANCED] = { + .hotplug_freq_1_1 = 500000, + .hotplug_freq_2_0 = 500000, + .hotplug_freq_2_1 = 700000, + .hotplug_freq_3_0 = 700000, + .hotplug_freq_3_1 = 900000, + .hotplug_freq_4_0 = 900000, + .hotplug_rq_1_1 = 150, + .hotplug_rq_2_0 = 150, + .hotplug_rq_2_1 = 250, + .hotplug_rq_3_0 = 250, + .hotplug_rq_3_1 = 350, + .hotplug_rq_4_0 = 350, + .max_freq = -1, + .min_freq = -1, + .up_threshold = 90, + .down_differential = 3, + .min_cpu_lock = 0, + .max_cpu_lock = 0, + .cpu_down_rate = 10, + .sampling_rate = 200000, + .io_is_busy = 0, + }, + [PROFILE_PERFORMANCE] = { + .hotplug_freq_1_1 = 500000, + .hotplug_freq_2_0 = 200000, + .hotplug_freq_2_1 = 500000, + .hotplug_freq_3_0 = 200000, + .hotplug_freq_3_1 = 700000, + .hotplug_freq_4_0 = 200000, + .hotplug_rq_1_1 = 150, + .hotplug_rq_2_0 = 100, + .hotplug_rq_2_1 = 200, + .hotplug_rq_3_0 = 150, + .hotplug_rq_3_1 = 250, + .hotplug_rq_4_0 = 200, + .min_freq = -1, + .max_freq = -1, + .up_threshold = 80, + .down_differential = 5, + .min_cpu_lock = 0, + .max_cpu_lock = 0, + .cpu_down_rate = 20, + .sampling_rate = 200000, + .io_is_busy = 1, + }, +}; + +static power_profile profiles_low_power[PROFILE_MAX] = { + [PROFILE_POWER_SAVE] = { + .hotplug_freq_1_1 = 800000, + .hotplug_freq_2_0 = 800000, + .hotplug_freq_2_1 = 900000, + .hotplug_freq_3_0 = 900000, + .hotplug_freq_3_1 = 1200000, + .hotplug_freq_4_0 = 1100000, + .hotplug_rq_1_1 = 200, + .hotplug_rq_2_0 = 200, + .hotplug_rq_2_1 = 300, + .hotplug_rq_3_0 = 300, + .hotplug_rq_3_1 = 400, + .hotplug_rq_4_0 = 400, + .max_freq = 900000, + .min_freq = -1, + .up_threshold = 95, + .down_differential = 1, + .min_cpu_lock = 0, + .max_cpu_lock = 2, + .cpu_down_rate = 5, + .sampling_rate = 200000, + .io_is_busy = 0, + }, + [PROFILE_BALANCED] = { + .hotplug_freq_1_1 = 700000, + .hotplug_freq_2_0 = 700000, + .hotplug_freq_2_1 = 900000, + .hotplug_freq_3_0 = 900000, + .hotplug_freq_3_1 = 1100000, + .hotplug_freq_4_0 = 1100000, + .hotplug_rq_1_1 = 150, + .hotplug_rq_2_0 = 150, + .hotplug_rq_2_1 = 250, + .hotplug_rq_3_0 = 250, + .hotplug_rq_3_1 = 350, + .hotplug_rq_4_0 = 350, + .max_freq = 1200000, + .min_freq = -1, + .up_threshold = 90, + .down_differential = 2, + .min_cpu_lock = 0, + .max_cpu_lock = 0, + .cpu_down_rate = 8, + .sampling_rate = 200000, + .io_is_busy = 0, + }, + [PROFILE_PERFORMANCE] = { + .hotplug_freq_1_1 = 800000, + .hotplug_freq_2_0 = 500000, + .hotplug_freq_2_1 = 800000, + .hotplug_freq_3_0 = 500000, + .hotplug_freq_3_1 = 1000000, + .hotplug_freq_4_0 = 700000, + .hotplug_rq_1_1 = 150, + .hotplug_rq_2_0 = 100, + .hotplug_rq_2_1 = 200, + .hotplug_rq_3_0 = 150, + .hotplug_rq_3_1 = 250, + .hotplug_rq_4_0 = 200, + .min_freq = -1, + .max_freq = -1, + .up_threshold = 85, + .down_differential = 5, + .min_cpu_lock = 0, + .max_cpu_lock = 0, + .cpu_down_rate = 15, + .sampling_rate = 200000, + .io_is_busy = 1, + }, +}; + -- cgit v1.1 From b0b03ea832d645620527342e5efc465baafec50e Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Sat, 20 Feb 2016 23:23:17 +1100 Subject: i9300: don't overwrite powerhal governor settings from init Change-Id: Id704829e1f65b538e7fd05a599a1159ffe37aeb1 --- rootdir/init.target.rc | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/rootdir/init.target.rc b/rootdir/init.target.rc index 492b130..a9a3168 100644 --- a/rootdir/init.target.rc +++ b/rootdir/init.target.rc @@ -89,22 +89,3 @@ service gps-daemon /system/bin/sh /system/bin/gps_daemon.sh user gps group system inet sdcard_rw gps seclabel u:r:glgps:s0 - -on property:dev.bootcomplete=1 -# boot on default pegasusq settings (for better performance) -# switch to more conservative settings after bootup is complete - write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_1_1 500000 - write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_2_0 500000 - write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_2_1 700000 - write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_3_0 700000 - write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_3_1 900000 - write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_4_0 900000 - write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_1_1 150 - write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_2_0 150 - write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_2_1 250 - write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_3_0 250 - write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_3_1 350 - write /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_4_0 450 - write /sys/devices/system/cpu/cpufreq/pegasusq/up_threshold 90 - write /sys/devices/system/cpu/cpufreq/pegasusq/cpu_down_rate 10 - write /sys/devices/system/cpu/cpufreq/pegasusq/down_differential 3 -- cgit v1.1 From c8cff8ce3b0535dca43f4e5b0bc8bfb6766dd593 Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Sat, 20 Feb 2016 23:52:29 +1100 Subject: i9300: kill powerhal logspam Change-Id: Ie6e9b431ee3f73e799238305676eee5e068b9390 --- power/power.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/power/power.c b/power/power.c index 2e65f1b..f5df011 100644 --- a/power/power.c +++ b/power/power.c @@ -27,7 +27,7 @@ #include #include -#define LOG_NDEBUG 0 +//#define LOG_NDEBUG 0 #include #include "power.h" -- cgit v1.1 From 2ecc6a053755cf9dba8a4994501755c60d0a0c74 Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Thu, 25 Feb 2016 19:45:33 +1100 Subject: i9300: refactor processUnsolicited closer to frameworks * easier kanging later on Change-Id: I0217a819187f914e261d4e58d53de3e085b97607 --- .../internal/telephony/SamsungExynos4RIL.java | 29 ++++++++++++++-------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/ril/telephony/java/com/android/internal/telephony/SamsungExynos4RIL.java b/ril/telephony/java/com/android/internal/telephony/SamsungExynos4RIL.java index 5501efc..2b6fcc3 100644 --- a/ril/telephony/java/com/android/internal/telephony/SamsungExynos4RIL.java +++ b/ril/telephony/java/com/android/internal/telephony/SamsungExynos4RIL.java @@ -440,10 +440,25 @@ public class SamsungExynos4RIL extends RIL implements CommandsInterface { processUnsolicited (Parcel p) { int dataPosition = p.dataPosition(); int response = p.readInt(); + Object ret; + + try{switch(response) { + case RIL_UNSOL_STK_PROACTIVE_COMMAND: ret = responseString(p); break; + default: + // Rewind the Parcel + p.setDataPosition(dataPosition); + + // Forward responses that we are not overriding to the super class + super.processUnsolicited(p); + return; + }} catch (Throwable tr) { + Rlog.e(RILJ_LOG_TAG, "Exception processing unsol response: " + response + + " Exception: " + tr.toString()); + return; + } switch(response) { - case RIL_UNSOL_STK_PROACTIVE_COMMAND: - Object ret = responseString(p); + case RIL_UNSOL_STK_PROACTIVE_COMMAND: if (RILJ_LOGD) unsljLogRet(response, ret); if (mCatProCmdRegistrant != null) { @@ -455,15 +470,7 @@ public class SamsungExynos4RIL extends RIL implements CommandsInterface { // does not get ignored (and breaks CatService). mCatProCmdBuffer = ret; } - break; - - default: - // Rewind the Parcel - p.setDataPosition(dataPosition); - - // Forward responses that we are not overriding to the super class - super.processUnsolicited(p); - return; + break; } } -- cgit v1.1 From 594d5b834867c09c975f2217659bd37aef05d9d9 Mon Sep 17 00:00:00 2001 From: Dheeraj CVR Date: Thu, 11 Jun 2015 17:57:26 +0400 Subject: libsensors: update sensor flags Change-Id: Ia57026f4e8f5dd270da7619bc25289fc414bce30 --- libsensors/smdk4x12_sensors.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libsensors/smdk4x12_sensors.c b/libsensors/smdk4x12_sensors.c index bd79a48..4cbc7c2 100644 --- a/libsensors/smdk4x12_sensors.c +++ b/libsensors/smdk4x12_sensors.c @@ -35,12 +35,12 @@ */ struct sensor_t smdk4x12_sensors[] = { - { "LSM330DLC Acceleration Sensor", "STMicroelectronics", 1, SENSOR_TYPE_ACCELEROMETER, + { "LSM330DLC 3-Axis Accelerometer", "STMicroelectronics", 1, SENSOR_TYPE_ACCELEROMETER, SENSOR_TYPE_ACCELEROMETER, 2 * GRAVITY_EARTH, 0.0096f, 0.23f, 10000, 0, 0, SENSOR_STRING_TYPE_ACCELEROMETER, 0, 0, - SENSOR_FLAG_ON_CHANGE_MODE, {}, }, - { "AKM8975 Magnetic Sensor", "Asahi Kasei", 1, SENSOR_TYPE_MAGNETIC_FIELD, + SENSOR_FLAG_CONTINUOUS_MODE, {}, }, + { "AKM8975C 3-Axis Magnetic Sensor", "Asahi Kasei", 1, SENSOR_TYPE_MAGNETIC_FIELD, SENSOR_TYPE_MAGNETIC_FIELD, 2000.0f, 1.0f / 16, 6.8f, 10000, 0, 0, SENSOR_STRING_TYPE_MAGNETIC_FIELD, 0, 0, - SENSOR_FLAG_ON_CHANGE_MODE, {}, }, + SENSOR_FLAG_CONTINUOUS_MODE, {}, }, { "CM36651 Light Sensor", "Capella", 1, SENSOR_TYPE_LIGHT, SENSOR_TYPE_LIGHT, 121240.0f, 1.0f, 0.2f, 0, 0, 0, SENSOR_STRING_TYPE_LIGHT, 0, 0, SENSOR_FLAG_ON_CHANGE_MODE, {}, }, @@ -49,7 +49,7 @@ struct sensor_t smdk4x12_sensors[] = { SENSOR_FLAG_WAKE_UP | SENSOR_FLAG_ON_CHANGE_MODE, {}, }, { "LSM330DLC Gyroscope Sensor", "STMicroelectronics", 1, SENSOR_TYPE_GYROSCOPE, SENSOR_TYPE_GYROSCOPE, 500.0f * (3.1415926535f / 180.0f), (70.0f / 4000.0f) * (3.1415926535f / 180.0f), 6.1f, 5000, 0, 0, SENSOR_STRING_TYPE_GYROSCOPE, 0, 0, - SENSOR_FLAG_ON_CHANGE_MODE, {}, }, + SENSOR_FLAG_CONTINUOUS_MODE, {}, }, { "LPS331AP Pressure Sensor", "STMicroelectronics", 1, SENSOR_TYPE_PRESSURE, SENSOR_TYPE_PRESSURE, 1260.0f, 1.0f / 4096, 0.045f, 40000, 0, 0, SENSOR_STRING_TYPE_PRESSURE, 0, 20000, SENSOR_FLAG_CONTINUOUS_MODE, {}, }, -- cgit v1.1 From 76829befcaaff1647d99be7477229bad9b0cb329 Mon Sep 17 00:00:00 2001 From: Pawit Pornkitprasan Date: Fri, 30 Nov 2012 23:30:00 +1100 Subject: i9300: SamsungExynos4RIL: Samsung STK support Change-Id: I1915332e8d6917dea2f4e71cb4e84564e7ad9556 --- .../android/internal/telephony/SamsungExynos4RIL.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ril/telephony/java/com/android/internal/telephony/SamsungExynos4RIL.java b/ril/telephony/java/com/android/internal/telephony/SamsungExynos4RIL.java index 2b6fcc3..8aaca62 100644 --- a/ril/telephony/java/com/android/internal/telephony/SamsungExynos4RIL.java +++ b/ril/telephony/java/com/android/internal/telephony/SamsungExynos4RIL.java @@ -131,6 +131,15 @@ public class SamsungExynos4RIL extends RIL implements CommandsInterface { } } + static String + responseToString(int response) { + switch (response) { + case RIL_UNSOL_STK_SEND_SMS_RESULT: return "RIL_UNSOL_STK_SEND_SMS_RESULT"; + default: return RIL.responseToString(response); + } + } + + @Override protected RILRequest processSolicited (Parcel p) { int serial, error; @@ -444,6 +453,7 @@ public class SamsungExynos4RIL extends RIL implements CommandsInterface { try{switch(response) { case RIL_UNSOL_STK_PROACTIVE_COMMAND: ret = responseString(p); break; + case RIL_UNSOL_STK_SEND_SMS_RESULT: ret = responseInts(p); break; // Samsung STK default: // Rewind the Parcel p.setDataPosition(dataPosition); @@ -471,6 +481,14 @@ public class SamsungExynos4RIL extends RIL implements CommandsInterface { mCatProCmdBuffer = ret; } break; + case RIL_UNSOL_STK_SEND_SMS_RESULT: + if (RILJ_LOGD) unsljLogRet(response, ret); + + if (mCatSendSmsResultRegistrant != null) { + mCatSendSmsResultRegistrant.notifyRegistrant( + new AsyncResult (null, ret, null)); + } + break; } } -- cgit v1.1 From a7fd009a5e056ce4baf1816506a6138b79fa4d50 Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Tue, 1 Mar 2016 17:51:33 +1100 Subject: i9300: lmk config Change-Id: I5be3949709af51bab502efc7b0a24fb125936165 --- .../frameworks/base/core/res/res/values/config.xml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml index 74d4119..9441f8b 100644 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -250,6 +250,25 @@ true + + 122880 + + + 0 + + -- cgit v1.1 From ddc02ec2b3d19e301c4cb761b778f43ceff9f8ad Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Wed, 2 Mar 2016 23:26:16 +1100 Subject: i9300: tweak f2fs config Change-Id: I48e23ddb012769efce1251716763a5b94e51a5d8 --- rootdir/fstab.smdk4x12 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rootdir/fstab.smdk4x12 b/rootdir/fstab.smdk4x12 index 878876e..8c2e87d 100644 --- a/rootdir/fstab.smdk4x12 +++ b/rootdir/fstab.smdk4x12 @@ -4,10 +4,10 @@ # specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK /dev/block/mmcblk0p3 /efs ext4 noatime,nosuid,nodev,journal_async_commit,errors=panic wait /dev/block/mmcblk0p9 /system ext4 ro,noatime wait -/dev/block/mmcblk0p8 /cache f2fs noatime,nosuid,nodev wait +/dev/block/mmcblk0p8 /cache f2fs noatime,discard,inline_xattr,inline_data,nosuid,nodev wait /dev/block/mmcblk0p8 /cache ext4 noatime,nosuid,nodev,journal_async_commit,errors=panic wait /dev/block/mmcblk0p10 /preload ext4 noatime,nosuid,nodev,journal_async_commit wait -/dev/block/mmcblk0p12 /data f2fs noatime,nosuid,nodev wait,check,encryptable=footer +/dev/block/mmcblk0p12 /data f2fs noatime,discard,inline_xattr,inline_data,nosuid,nodev wait,check,encryptable=footer /dev/block/mmcblk0p12 /data ext4 noatime,nosuid,nodev,noauto_da_alloc,journal_async_commit,errors=panic wait,check,encryptable=footer # vold-managed volumes ("block device" is actually a sysfs devpath) -- cgit v1.1 From be4c4ec36f214eda40301450cd0691d08719852c Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Sat, 27 Feb 2016 20:37:29 +1100 Subject: i9300: power: pegasusq boosting support implement INTERACTION, LAUNCH_BOOST, and CPU_BOOST hints. Change-Id: Iac8c84ecb910a72a6de4c81a470c9d2d800ff631 --- power/Android.mk | 2 ++ power/power.c | 80 +++++++++++++++++++++++++++++++++++++++++++------- power/power.h | 27 +++++++++++++++++ rootdir/init.target.rc | 3 ++ 4 files changed, 101 insertions(+), 11 deletions(-) diff --git a/power/Android.mk b/power/Android.mk index 0cb4890..af65a3c 100644 --- a/power/Android.mk +++ b/power/Android.mk @@ -18,6 +18,8 @@ ifeq ($(TARGET_POWERHAL_VARIANT),pegasusq) include $(CLEAR_VARS) +LOCAL_CFLAGS += -DUSE_PEGASUSQ_BOOSTING + LOCAL_MODULE := power.$(TARGET_BOOTLOADER_BOARD_NAME) LOCAL_MODULE_RELATIVE_PATH := hw LOCAL_SHARED_LIBRARIES := liblog libcutils diff --git a/power/power.c b/power/power.c index f5df011..278994e 100644 --- a/power/power.c +++ b/power/power.c @@ -35,10 +35,13 @@ #define PEGASUSQ_PATH "/sys/devices/system/cpu/cpufreq/pegasusq/" #define MINMAX_CPU_PATH "/sys/power/" +#define US_TO_NS (1000L) + static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; static int current_power_profile = -1; static bool is_low_power = false; +static bool is_vsync_active = false; static int sysfs_write_str(char *path, char *s) { char buf[80]; @@ -70,6 +73,13 @@ static int sysfs_write_int(char *path, int value) { snprintf(buf, 80, "%d", value); return sysfs_write_str(path, buf); } + +static int sysfs_write_long(char *path, long value) { + char buf[80]; + snprintf(buf, 80, "%ld", value); + return sysfs_write_str(path, buf); +} + #ifdef LOG_NDEBUG #define WRITE_PEGASUSQ_PARAM(profile, param) do { \ ALOGV("%s: WRITE_PEGASUSQ_PARAM(profile=%d, param=%s): new val => %d", __func__, profile, #param, profiles[profile].param); \ @@ -136,6 +146,8 @@ static void set_power_profile(int profile) { WRITE_PEGASUSQ_PARAM(profile, cpu_down_rate); WRITE_PEGASUSQ_PARAM(profile, sampling_rate); WRITE_PEGASUSQ_PARAM(profile, io_is_busy); + WRITE_PEGASUSQ_PARAM(profile, boost_freq); + WRITE_PEGASUSQ_PARAM(profile, boost_mincpus); current_power_profile = profile; @@ -143,6 +155,24 @@ static void set_power_profile(int profile) { } +static void boost(long boost_time) { +#ifdef USE_PEGASUSQ_BOOSTING + if (is_vsync_active) return; + if (boost_time == -1) { + sysfs_write_int(PEGASUSQ_PATH "boost_lock_time", -1); + } else { + sysfs_write_long(PEGASUSQ_PATH "boost_lock_time", boost_time); + } +#endif +} + +static void end_boost() { +#ifdef USE_PEGASUSQ_BOOSTING + if (is_vsync_active) return; + sysfs_write_int(PEGASUSQ_PATH "boost_lock_time", 0); +#endif +} + static void set_low_power(bool low_power) { if (!is_profile_valid(current_power_profile)) { ALOGV("%s: current_power_profile not set yet", __func__); @@ -154,6 +184,8 @@ static void set_low_power(bool low_power) { if (is_low_power == low_power) return; if (low_power) { + end_boost(); + WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_freq_1_1); WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_freq_2_0); WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_freq_2_1); @@ -198,6 +230,9 @@ static void set_low_power(bool low_power) { WRITE_PEGASUSQ_PARAM(current_power_profile, cpu_down_rate); WRITE_PEGASUSQ_PARAM(current_power_profile, sampling_rate); WRITE_PEGASUSQ_PARAM(current_power_profile, io_is_busy); + WRITE_PEGASUSQ_PARAM(current_power_profile, boost_freq); + WRITE_PEGASUSQ_PARAM(current_power_profile, boost_mincpus); + is_low_power = false; } } @@ -288,21 +323,44 @@ static void power_set_interactive(__attribute__((unused)) struct power_module *m * integer value of the boost duration in microseconds. */ static void power_hint(__attribute__((unused)) struct power_module *module, power_hint_t hint, void *data) { + if (hint == POWER_HINT_SET_PROFILE) { + ALOGV("%s: set profile %d", __func__, *(int32_t *)data); + pthread_mutex_lock(&lock); + if (is_vsync_active) { + is_vsync_active = false; + end_boost(); + } + set_power_profile(*(int32_t *)data); + pthread_mutex_unlock(&lock); + } + + if (current_power_profile == PROFILE_POWER_SAVE) return; + + pthread_mutex_lock(&lock); + switch (hint) { - case POWER_HINT_SET_PROFILE: - ALOGV("%s: set profile %d", __func__, *(int32_t *)data); - pthread_mutex_lock(&lock); - set_power_profile(*(int32_t *)data); - pthread_mutex_unlock(&lock); - break; case POWER_HINT_INTERACTION: - case POWER_HINT_VSYNC: + case POWER_HINT_LAUNCH_BOOST: + ALOGV("%s: interaction/launch", __func__); + boost(profiles[current_power_profile].interaction_boost_time); + break; +/* case POWER_HINT_VSYNC: + if (*(int32_t *)data) { + ALOGV("%s: vsync", __func__); + boost(-1); + is_vsync_active = true; + } else { + is_vsync_active = false; + end_boost(); + } + break;*/ + case POWER_HINT_CPU_BOOST: + ALOGV("%s: cpu_boost", __func__); + boost((*(int32_t *)data) * US_TO_NS); break; - case POWER_HINT_LOW_POWER: - break; - default: - break; } + + pthread_mutex_unlock(&lock); } /* diff --git a/power/power.h b/power/power.h index db031cf..08ceb51 100644 --- a/power/power.h +++ b/power/power.h @@ -14,6 +14,8 @@ * limitations under the License. */ +#define MS_TO_NS (1000000L) + enum { PROFILE_POWER_SAVE = 0, PROFILE_BALANCED, @@ -50,6 +52,10 @@ typedef struct governor_settings { int cpu_down_rate; int sampling_rate; // in microseconds int io_is_busy; + // boosting + int boost_freq; + int boost_mincpus; + long interaction_boost_time; } power_profile; static power_profile profiles[PROFILE_MAX] = { @@ -75,6 +81,10 @@ static power_profile profiles[PROFILE_MAX] = { .cpu_down_rate = 5, .sampling_rate = 200000, .io_is_busy = 0, + // nb: boosting power hints are ignored for PROFILE_POWER_SAVE + .boost_freq = 0, + .boost_mincpus = 0, + .interaction_boost_time = 0, }, [PROFILE_BALANCED] = { .hotplug_freq_1_1 = 500000, @@ -98,6 +108,9 @@ static power_profile profiles[PROFILE_MAX] = { .cpu_down_rate = 10, .sampling_rate = 200000, .io_is_busy = 0, + .boost_freq = 700000, + .boost_mincpus = 0, + .interaction_boost_time = 60 * (MS_TO_NS), }, [PROFILE_PERFORMANCE] = { .hotplug_freq_1_1 = 500000, @@ -121,9 +134,14 @@ static power_profile profiles[PROFILE_MAX] = { .cpu_down_rate = 20, .sampling_rate = 200000, .io_is_busy = 1, + .boost_freq = 900000, + .boost_mincpus = 2, + .interaction_boost_time = 90 * (MS_TO_NS), }, }; +// for non-interactive profiles we don't need to worry about +// boosting as it (should) only occur while the screen is on static power_profile profiles_low_power[PROFILE_MAX] = { [PROFILE_POWER_SAVE] = { .hotplug_freq_1_1 = 800000, @@ -147,6 +165,9 @@ static power_profile profiles_low_power[PROFILE_MAX] = { .cpu_down_rate = 5, .sampling_rate = 200000, .io_is_busy = 0, + .boost_freq = 0, + .boost_mincpus = 0, + .interaction_boost_time = 0, }, [PROFILE_BALANCED] = { .hotplug_freq_1_1 = 700000, @@ -170,6 +191,9 @@ static power_profile profiles_low_power[PROFILE_MAX] = { .cpu_down_rate = 8, .sampling_rate = 200000, .io_is_busy = 0, + .boost_freq = 0, + .boost_mincpus = 0, + .interaction_boost_time = 0, }, [PROFILE_PERFORMANCE] = { .hotplug_freq_1_1 = 800000, @@ -193,6 +217,9 @@ static power_profile profiles_low_power[PROFILE_MAX] = { .cpu_down_rate = 15, .sampling_rate = 200000, .io_is_busy = 1, + .boost_freq = 0, + .boost_mincpus = 0, + .interaction_boost_time = 0, }, }; diff --git a/rootdir/init.target.rc b/rootdir/init.target.rc index a9a3168..d17fc69 100644 --- a/rootdir/init.target.rc +++ b/rootdir/init.target.rc @@ -3,6 +3,9 @@ on init # ko files for FM Radio insmod /system/lib/modules/Si4709_driver.ko chown system system /sys/devices/system/cpu/cpufreq/pegasusq + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/boost_freq + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/boost_lock_time + chown system system /sys/devices/system/cpu/cpufreq/pegasusq/boost_mincpus chown system system /sys/devices/system/cpu/cpufreq/pegasusq/cpu_down_freq chown system system /sys/devices/system/cpu/cpufreq/pegasusq/cpu_down_rate chown system system /sys/devices/system/cpu/cpufreq/pegasusq/cpu_up_freq -- cgit v1.1 From 381a05756bdbe474ab76242a4e2934d81b8975e9 Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Sat, 5 Mar 2016 20:36:08 +1100 Subject: i9300: rewrite libsensors in c++ * based off t0lte sensors * AkmSensor kanged from i9100 (added sensor status support) * has a working compass! Change-Id: Iaed0463c33089ca0b636be4ba3f966f2e25f34f9 --- BoardConfig.mk | 3 - libsensors/AccelSensor.cpp | 168 ++++++ libsensors/AccelSensor.h | 72 +++ libsensors/AkmSensor.cpp | 281 ++++++++++ libsensors/AkmSensor.h | 63 +++ libsensors/Android.mk | 72 ++- libsensors/GyroSensor.cpp | 181 +++++++ libsensors/GyroSensor.h | 55 ++ libsensors/InputEventReader.cpp | 89 ++++ libsensors/InputEventReader.h | 47 ++ libsensors/LightSensor.cpp | 152 ++++++ libsensors/LightSensor.h | 55 ++ libsensors/MODULE_LICENSE_APACHE2 | 0 libsensors/PressureSensor.cpp | 155 ++++++ libsensors/PressureSensor.h | 54 ++ libsensors/ProximitySensor.cpp | 164 ++++++ libsensors/ProximitySensor.h | 55 ++ libsensors/SensorBase.cpp | 141 +++++ libsensors/SensorBase.h | 70 +++ libsensors/ak8973b.h | 51 ++ libsensors/ak8975-reg.h | 48 -- libsensors/ak8975.h | 73 --- libsensors/akm8975.c | 612 ---------------------- libsensors/akmdfs/AK8975Driver.c | 318 ----------- libsensors/akmdfs/AK8975Driver.h | 102 ---- libsensors/akmdfs/AKFS_APIs.c | 389 -------------- libsensors/akmdfs/AKFS_APIs.h | 69 --- libsensors/akmdfs/AKFS_APIs_8975/AKFS_AK8975.c | 44 -- libsensors/akmdfs/AKFS_APIs_8975/AKFS_AK8975.h | 50 -- libsensors/akmdfs/AKFS_APIs_8975/AKFS_AOC.c | 333 ------------ libsensors/akmdfs/AKFS_APIs_8975/AKFS_AOC.h | 53 -- libsensors/akmdfs/AKFS_APIs_8975/AKFS_Configure.h | 37 -- libsensors/akmdfs/AKFS_APIs_8975/AKFS_Device.c | 110 ---- libsensors/akmdfs/AKFS_APIs_8975/AKFS_Device.h | 107 ---- libsensors/akmdfs/AKFS_APIs_8975/AKFS_Direction.c | 133 ----- libsensors/akmdfs/AKFS_APIs_8975/AKFS_Direction.h | 39 -- libsensors/akmdfs/AKFS_APIs_8975/AKFS_Math.h | 47 -- libsensors/akmdfs/AKFS_APIs_8975/AKFS_VNorm.c | 107 ---- libsensors/akmdfs/AKFS_APIs_8975/AKFS_VNorm.h | 46 -- libsensors/akmdfs/AKFS_CSpec.h | 38 -- libsensors/akmdfs/AKFS_Common.h | 141 ----- libsensors/akmdfs/AKFS_Compass.h | 84 --- libsensors/akmdfs/AKFS_Disp.c | 89 ---- libsensors/akmdfs/AKFS_Disp.h | 52 -- libsensors/akmdfs/AKFS_FileIO.c | 130 ----- libsensors/akmdfs/AKFS_FileIO.h | 39 -- libsensors/akmdfs/AKFS_Measure.c | 410 --------------- libsensors/akmdfs/AKFS_Measure.h | 70 --- libsensors/akmdfs/NOTICE | 202 ------- libsensors/akmdfs/Version.txt | 31 -- libsensors/akmdfs/main.c | 293 ----------- libsensors/cm36651_light.c | 264 ---------- libsensors/cm36651_proximity.c | 213 -------- libsensors/input.c | 336 ------------ libsensors/lps331ap.c | 244 --------- libsensors/lsm330dlc_accel.h | 185 ------- libsensors/lsm330dlc_acceleration.c | 390 -------------- libsensors/lsm330dlc_gyroscope.c | 256 --------- libsensors/sensors.cpp | 395 ++++++++++++++ libsensors/sensors.h | 112 ++++ libsensors/smdk4x12_sensors.c | 295 ----------- libsensors/smdk4x12_sensors.h | 102 ---- 62 files changed, 2395 insertions(+), 6621 deletions(-) create mode 100644 libsensors/AccelSensor.cpp create mode 100644 libsensors/AccelSensor.h create mode 100644 libsensors/AkmSensor.cpp create mode 100644 libsensors/AkmSensor.h create mode 100644 libsensors/GyroSensor.cpp create mode 100644 libsensors/GyroSensor.h create mode 100644 libsensors/InputEventReader.cpp create mode 100644 libsensors/InputEventReader.h create mode 100644 libsensors/LightSensor.cpp create mode 100644 libsensors/LightSensor.h create mode 100644 libsensors/MODULE_LICENSE_APACHE2 create mode 100644 libsensors/PressureSensor.cpp create mode 100644 libsensors/PressureSensor.h create mode 100644 libsensors/ProximitySensor.cpp create mode 100644 libsensors/ProximitySensor.h create mode 100644 libsensors/SensorBase.cpp create mode 100644 libsensors/SensorBase.h create mode 100644 libsensors/ak8973b.h delete mode 100644 libsensors/ak8975-reg.h delete mode 100644 libsensors/ak8975.h delete mode 100644 libsensors/akm8975.c delete mode 100644 libsensors/akmdfs/AK8975Driver.c delete mode 100644 libsensors/akmdfs/AK8975Driver.h delete mode 100644 libsensors/akmdfs/AKFS_APIs.c delete mode 100644 libsensors/akmdfs/AKFS_APIs.h delete mode 100644 libsensors/akmdfs/AKFS_APIs_8975/AKFS_AK8975.c delete mode 100644 libsensors/akmdfs/AKFS_APIs_8975/AKFS_AK8975.h delete mode 100644 libsensors/akmdfs/AKFS_APIs_8975/AKFS_AOC.c delete mode 100644 libsensors/akmdfs/AKFS_APIs_8975/AKFS_AOC.h delete mode 100644 libsensors/akmdfs/AKFS_APIs_8975/AKFS_Configure.h delete mode 100644 libsensors/akmdfs/AKFS_APIs_8975/AKFS_Device.c delete mode 100644 libsensors/akmdfs/AKFS_APIs_8975/AKFS_Device.h delete mode 100644 libsensors/akmdfs/AKFS_APIs_8975/AKFS_Direction.c delete mode 100644 libsensors/akmdfs/AKFS_APIs_8975/AKFS_Direction.h delete mode 100644 libsensors/akmdfs/AKFS_APIs_8975/AKFS_Math.h delete mode 100644 libsensors/akmdfs/AKFS_APIs_8975/AKFS_VNorm.c delete mode 100644 libsensors/akmdfs/AKFS_APIs_8975/AKFS_VNorm.h delete mode 100644 libsensors/akmdfs/AKFS_CSpec.h delete mode 100644 libsensors/akmdfs/AKFS_Common.h delete mode 100644 libsensors/akmdfs/AKFS_Compass.h delete mode 100644 libsensors/akmdfs/AKFS_Disp.c delete mode 100644 libsensors/akmdfs/AKFS_Disp.h delete mode 100644 libsensors/akmdfs/AKFS_FileIO.c delete mode 100644 libsensors/akmdfs/AKFS_FileIO.h delete mode 100644 libsensors/akmdfs/AKFS_Measure.c delete mode 100644 libsensors/akmdfs/AKFS_Measure.h delete mode 100644 libsensors/akmdfs/NOTICE delete mode 100644 libsensors/akmdfs/Version.txt delete mode 100644 libsensors/akmdfs/main.c delete mode 100644 libsensors/cm36651_light.c delete mode 100644 libsensors/cm36651_proximity.c delete mode 100644 libsensors/input.c delete mode 100644 libsensors/lps331ap.c delete mode 100644 libsensors/lsm330dlc_accel.h delete mode 100644 libsensors/lsm330dlc_acceleration.c delete mode 100644 libsensors/lsm330dlc_gyroscope.c create mode 100644 libsensors/sensors.cpp create mode 100644 libsensors/sensors.h delete mode 100644 libsensors/smdk4x12_sensors.c delete mode 100644 libsensors/smdk4x12_sensors.h diff --git a/BoardConfig.mk b/BoardConfig.mk index cabfc99..001780d 100644 --- a/BoardConfig.mk +++ b/BoardConfig.mk @@ -31,9 +31,6 @@ COMMON_GLOBAL_CFLAGS += -DDISABLE_ASHMEM_TRACKING # Graphics TARGET_REQUIRES_SYNCHRONOUS_SETSURFACE := true -# Sensors -BOARD_USES_OPENSOURCE_SENSORS := false - # Bluetooth BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR := device/samsung/i9300/bluetooth diff --git a/libsensors/AccelSensor.cpp b/libsensors/AccelSensor.cpp new file mode 100644 index 0000000..1a5510c --- /dev/null +++ b/libsensors/AccelSensor.cpp @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include "AccelSensor.h" + +#define LOGTAG "AccelerometerSensor" + +// ioctls +#define LSM330DLC_ACCEL_IOCTL_BASE 'a' +#define LSM330DLC_ACCEL_IOCTL_SET_ENABLE \ + _IOW(LSM330DLC_ACCEL_IOCTL_BASE, 9, int) + + +/*****************************************************************************/ +AccelSensor::AccelSensor() + : SensorBase("/dev/acceleration", "accelerometer_sensor"), + mEnabled(0), + mInputReader(4), + mHasPendingEvent(false) +{ + + mPendingEvent.version = sizeof(sensors_event_t); + mPendingEvent.sensor = ID_A; + mPendingEvent.type = SENSOR_TYPE_ACCELEROMETER; + memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data)); + + if (data_fd) { + strcpy(input_sysfs_path, "/sys/class/input/"); + strcat(input_sysfs_path, input_name); + strcat(input_sysfs_path, "/device/"); + input_sysfs_path_len = strlen(input_sysfs_path); + } +} + +AccelSensor::~AccelSensor() { + + // ALOGD("AccelSensor::~AccelSensor()"); + if (mEnabled) { + enable(0, 0); + } +} + +int AccelSensor::setInitialState() { + return 0; +} + +int AccelSensor::enable(int32_t handle, int en) { + int flags = en ? 1 : 0; + int fd; + if (flags != mEnabled) { + strcpy(&input_sysfs_path[input_sysfs_path_len], "enable"); + fd = open(input_sysfs_path, O_RDWR); + if (fd >= 0) { + write(fd, en == 1 ? "1" : "0", 2); + close(fd); + mEnabled = flags; + setInitialState(); + return 0; + } + return -1; + } + return 0; +} + + +bool AccelSensor::hasPendingEvents() const { + /* FIXME probably here should be returning mEnabled but instead + mHasPendingEvents. It does not work, so we cheat.*/ + //ALOGD("AccelSensor::~hasPendingEvents %d", mHasPendingEvent ? 1 : 0 ); + return mHasPendingEvent; +} + + +int AccelSensor::setDelay(int32_t handle, int64_t ns) +{ + int fd; + + if (ns < 10000000) { + ns = 10000000; // Minimum on stock + } + + strcpy(&input_sysfs_path[input_sysfs_path_len], "acc_poll_delay"); + fd = open(input_sysfs_path, O_RDWR); + if (fd >= 0) { + char buf[80]; + sprintf(buf, "%lld", ns / 10000000 * 10); // Some flooring to match stock value + write(fd, buf, strlen(buf)+1); + close(fd); + return 0; + } + return -1; +} + + +int AccelSensor::readEvents(sensors_event_t* data, int count) +{ + if (count < 1) + return -EINVAL; + + if (mHasPendingEvent) { + mHasPendingEvent = false; + mPendingEvent.timestamp = getTimestamp(); + *data = mPendingEvent; + return mEnabled ? 1 : 0; + } + + ssize_t n = mInputReader.fill(data_fd); + if (n < 0) + return n; + int numEventReceived = 0; + input_event const* event; + + while (count && mInputReader.readEvent(&event)) { + int type = event->type; + if (type == EV_REL) { + float value = event->value; + if (event->code == EVENT_TYPE_ACCEL_X) { + mPendingEvent.acceleration.x = value * CONVERT_A_X; + } else if (event->code == EVENT_TYPE_ACCEL_Y) { + mPendingEvent.acceleration.y = value * CONVERT_A_Y; + } else if (event->code == EVENT_TYPE_ACCEL_Z) { + mPendingEvent.acceleration.z = value * CONVERT_A_Z; + } + } else if (type == EV_SYN) { + mPendingEvent.timestamp = timevalToNano(event->time); + if (mEnabled) { + *data++ = mPendingEvent; + count--; + numEventReceived++; + } + } else { + ALOGE("%s: unknown event (type=%d, code=%d)", LOGTAG, + type, event->code); + } + + mInputReader.next(); + } + return numEventReceived++; + +} diff --git a/libsensors/AccelSensor.h b/libsensors/AccelSensor.h new file mode 100644 index 0000000..09508e9 --- /dev/null +++ b/libsensors/AccelSensor.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_SMB380_SENSOR_H +#define ANDROID_SMB380_SENSOR_H + +#include +#include +#include +#include + +#include "sensors.h" +#include "SensorBase.h" +#include "InputEventReader.h" + +/*****************************************************************************/ + + +struct smb380acc_t { + short x, /**< holds x-axis acceleration data sign extended. Range -512 to 511. */ + y, /**< holds y-axis acceleration data sign extended. Range -512 to 511. */ + z; /**< holds z-axis acceleration data sign extended. Range -512 to 511. */ +} ; + +/* smb ioctl command label */ +#define IOCTL_SMB_GET_ACC_VALUE 0 +#define DCM_IOC_MAGIC 's' +#define IOC_SET_ACCELEROMETER _IO (DCM_IOC_MAGIC, 0x64) +#define BMA150_CALIBRATION _IOWR(DCM_IOC_MAGIC,48,short) + +#define SMB_POWER_OFF 0 +#define SMB_POWER_ON 1 + +struct input_event; + +class AccelSensor : public SensorBase { + int mEnabled; + InputEventCircularReader mInputReader; + sensors_event_t mPendingEvent; + bool mHasPendingEvent; + char input_sysfs_path[PATH_MAX]; + int input_sysfs_path_len; +// int mUinputDevice; + + int setInitialState(); + +public: + AccelSensor(); + virtual ~AccelSensor(); +// virtual int createUinput(); + virtual int readEvents(sensors_event_t* data, int count); + virtual bool hasPendingEvents() const; + virtual int setDelay(int32_t handle, int64_t ns); + virtual int enable(int32_t handle, int enabled); +}; + +/*****************************************************************************/ + +#endif // ANDROID_GYRO_SENSOR_H diff --git a/libsensors/AkmSensor.cpp b/libsensors/AkmSensor.cpp new file mode 100644 index 0000000..e7e0a4b --- /dev/null +++ b/libsensors/AkmSensor.cpp @@ -0,0 +1,281 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ak8973b.h" + +#include +#include "AkmSensor.h" + + +/*****************************************************************************/ + +int (*akm_is_sensor_enabled)(uint32_t sensor_type); +int (*akm_enable_sensor)(uint32_t sensor_type); +int (*akm_disable_sensor)(uint32_t sensor_type); +int (*akm_set_delay)(uint32_t sensor_type, uint64_t delay); + +int stub_is_sensor_enabled(uint32_t sensor_type) { + return 0; +} + +int stub_enable_disable_sensor(uint32_t sensor_type) { + return -ENODEV; +} + +int stub_set_delay(uint32_t sensor_type, uint64_t delay) { + return -ENODEV; +} + +AkmSensor::AkmSensor() +: SensorBase(NULL, NULL), + mEnabled(0), + mPendingMask(0), + mInputReader(32) +{ + /* Open the library before opening the input device. The library + * creates a uinput device. + */ + if (loadAKMLibrary() == 0) { + data_name = "compass_sensor"; + data_fd = openInput("compass_sensor"); + } + + memset(mPendingEvents, 0, sizeof(mPendingEvents)); + + mPendingEvents[Accelerometer].version = sizeof(sensors_event_t); + mPendingEvents[Accelerometer].sensor = ID_A; + mPendingEvents[Accelerometer].type = SENSOR_TYPE_ACCELEROMETER; + mPendingEvents[Accelerometer].acceleration.status = SENSOR_STATUS_UNRELIABLE; + + mPendingEvents[MagneticField].version = sizeof(sensors_event_t); + mPendingEvents[MagneticField].sensor = ID_M; + mPendingEvents[MagneticField].type = SENSOR_TYPE_MAGNETIC_FIELD; + mPendingEvents[MagneticField].magnetic.status = SENSOR_STATUS_UNRELIABLE; + + // read the actual value of all sensors if they're enabled already + struct input_absinfo absinfo; + short flags = 0; + + if (akm_is_sensor_enabled(SENSOR_TYPE_ACCELEROMETER)) { + mEnabled |= 1<= numSensors) + return -EINVAL; + + int newState = en ? 1 : 0; + int err = 0; + + if ((uint32_t(newState)<type; + if (type == EV_REL) { + processEvent(event->code, event->value); + mInputReader.next(); + } else if (type == EV_SYN) { + int64_t time = timevalToNano(event->time); + for (int j=0 ; count && mPendingMask && jcode); + mInputReader.next(); + } + } + return numEventReceived; +} + +void AkmSensor::processEvent(int code, int value) +{ + switch (code) { + case EVENT_TYPE_MAGV_X: + ALOGV("AkmSensor: MAGV_X =>%d", value); + mPendingMask |= 1<%d", value); + mPendingMask |= 1<%d", value); + mPendingMask |= 1<%d", value); + mPendingMask |= 1< +#include +#include +#include + + +#include "sensors.h" +#include "SensorBase.h" +#include "InputEventReader.h" + +/*****************************************************************************/ + +struct input_event; + +class AkmSensor : public SensorBase { +public: + AkmSensor(); + virtual ~AkmSensor(); + + enum { + Accelerometer = 0, + MagneticField = 1, + numSensors + }; + + virtual int setDelay(int32_t handle, int64_t ns); + virtual int enable(int32_t handle, int enabled); + virtual int readEvents(sensors_event_t* data, int count); + void processEvent(int code, int value); + +private: + int loadAKMLibrary(); + int update_delay(); + void *mLibAKM; + uint32_t mEnabled; + uint32_t mPendingMask; + InputEventCircularReader mInputReader; + sensors_event_t mPendingEvents[numSensors]; + uint64_t mDelays[numSensors]; +}; + +/*****************************************************************************/ + +#endif // ANDROID_AKM_SENSOR_H diff --git a/libsensors/Android.mk b/libsensors/Android.mk index 8bdcd66..636ad9d 100644 --- a/libsensors/Android.mk +++ b/libsensors/Android.mk @@ -1,49 +1,47 @@ -# Copyright (C) 2013 Paul Kocialkowski +# Copyright (C) 2008 The Android Open Source Project # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# http://www.apache.org/licenses/LICENSE-2.0 # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -ifeq ($(BOARD_USES_OPENSOURCE_SENSORS),true) +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + LOCAL_PATH := $(call my-dir) -include $(CLEAR_VARS) +ifneq ($(TARGET_SIMULATOR),true) -LOCAL_SRC_FILES := \ - smdk4x12_sensors.c \ - input.c \ - akm8975.c \ - akmdfs/AKFS_APIs_8975/AKFS_AK8975.c \ - akmdfs/AKFS_APIs_8975/AKFS_AOC.c \ - akmdfs/AKFS_APIs_8975/AKFS_Device.c \ - akmdfs/AKFS_APIs_8975/AKFS_Direction.c \ - akmdfs/AKFS_APIs_8975/AKFS_VNorm.c \ - akmdfs/AKFS_FileIO.c \ - cm36651_proximity.c \ - cm36651_light.c \ - lsm330dlc_acceleration.c \ - lsm330dlc_gyroscope.c \ - lps331ap.c - -LOCAL_C_INCLUDES := \ - $(LOCAL_PATH)/akmdfs \ - $(LOCAL_PATH)/akmdfs/AKFS_APIs_8975 \ - $(LOCAL_PATH) - -LOCAL_SHARED_LIBRARIES := libutils libcutils liblog libhardware -LOCAL_PRELINK_MODULE := false +# HAL module implemenation, not prelinked, and stored in +# hw/..so +include $(CLEAR_VARS) LOCAL_MODULE := sensors.$(TARGET_BOOTLOADER_BOARD_NAME) + LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw + LOCAL_MODULE_TAGS := optional +LOCAL_CFLAGS := -DLOG_TAG=\"sensorscpp\" +LOCAL_SRC_FILES := \ + sensors.cpp \ + SensorBase.cpp \ + LightSensor.cpp \ + ProximitySensor.cpp \ + AkmSensor.cpp \ + GyroSensor.cpp \ + InputEventReader.cpp \ + AccelSensor.cpp \ + PressureSensor.cpp + +LOCAL_SHARED_LIBRARIES := liblog libcutils libdl +LOCAL_PRELINK_MODULE := false + include $(BUILD_SHARED_LIBRARY) -endif + +endif # !TARGET_SIMULATOR diff --git a/libsensors/GyroSensor.cpp b/libsensors/GyroSensor.cpp new file mode 100644 index 0000000..ceb7d9c --- /dev/null +++ b/libsensors/GyroSensor.cpp @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "GyroSensor.h" + +#define LOGTAG "GyroSensor" + +#define FETCH_FULL_EVENT_BEFORE_RETURN 1 +#define IGNORE_EVENT_TIME 350000000 +/*****************************************************************************/ + +GyroSensor::GyroSensor() + : SensorBase(NULL, "gyro_sensor"), + mEnabled(0), + mInputReader(4), + mHasPendingEvent(false), + mEnabledTime(0) +{ + mPendingEvent.version = sizeof(sensors_event_t); + mPendingEvent.sensor = ID_GY; + mPendingEvent.type = SENSOR_TYPE_GYROSCOPE; + memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data)); + + if (data_fd) { + strcpy(input_sysfs_path, "/sys/class/input/"); + strcat(input_sysfs_path, input_name); + strcat(input_sysfs_path, "/device/"); + input_sysfs_path_len = strlen(input_sysfs_path); + enable(0, 1); + } +} + +GyroSensor::~GyroSensor() { + if (mEnabled) { + enable(0, 0); + } +} + +int GyroSensor::setInitialState() { + struct input_absinfo absinfo_x; + struct input_absinfo absinfo_y; + struct input_absinfo absinfo_z; + float value; + if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_GYRO_X), &absinfo_x) && + !ioctl(data_fd, EVIOCGABS(EVENT_TYPE_GYRO_X), &absinfo_y) && + !ioctl(data_fd, EVIOCGABS(EVENT_TYPE_GYRO_X), &absinfo_z)) { + value = absinfo_x.value; + mPendingEvent.data[0] = value * CONVERT_GYRO_X; + value = absinfo_x.value; + mPendingEvent.data[1] = value * CONVERT_GYRO_Y; + value = absinfo_x.value; + mPendingEvent.data[2] = value * CONVERT_GYRO_Z; + mHasPendingEvent = true; + } + return 0; +} + +int GyroSensor::enable(int32_t handle, int en) { + int flags = en ? 1 : 0; + int fd; + if (flags != mEnabled) { + strcpy(&input_sysfs_path[input_sysfs_path_len], "enable"); + fd = open(input_sysfs_path, O_RDWR); + if (fd >= 0){ + write(fd, en == 1 ? "1" : "0", 2); + close(fd); + mEnabled = flags; + setInitialState(); + + return 0; + } + return -1; + } + return 0; +} + +bool GyroSensor::hasPendingEvents() const { + return mHasPendingEvent; +} + +int GyroSensor::setDelay(int32_t handle, int64_t ns) +{ + int fd; + + strcpy(&input_sysfs_path[input_sysfs_path_len], "poll_delay"); + fd = open(input_sysfs_path, O_RDWR); + if (fd >= 0) { + char buf[80]; + sprintf(buf, "%lld", ns); + write(fd, buf, strlen(buf)+1); + close(fd); + return 0; + } + return -1; +} + +int GyroSensor::readEvents(sensors_event_t* data, int count) +{ + if (count < 1) + return -EINVAL; + + if (mHasPendingEvent) { + mHasPendingEvent = false; + mPendingEvent.timestamp = getTimestamp(); + *data = mPendingEvent; + return mEnabled ? 1 : 0; + } + + ssize_t n = mInputReader.fill(data_fd); + if (n < 0) + return n; + + int numEventReceived = 0; + input_event const* event; + +#if FETCH_FULL_EVENT_BEFORE_RETURN +again: +#endif + while (count && mInputReader.readEvent(&event)) { + int type = event->type; + if (type == EV_REL) { + float value = event->value; + if (event->code == EVENT_TYPE_GYRO_X) { + mPendingEvent.data[0] = value * CONVERT_GYRO_X; + } else if (event->code == EVENT_TYPE_GYRO_Y) { + mPendingEvent.data[1] = value * CONVERT_GYRO_Y; + } else if (event->code == EVENT_TYPE_GYRO_Z) { + mPendingEvent.data[2] = value * CONVERT_GYRO_Z; + } + } else if (type == EV_SYN) { + mPendingEvent.timestamp = timevalToNano(event->time); + if (mEnabled) { + if (mPendingEvent.timestamp >= mEnabledTime) { + *data++ = mPendingEvent; + numEventReceived++; + } + count--; + } + } else { + ALOGE("%s: unknown event (type=%d, code=%d)", LOGTAG, + type, event->code); + } + mInputReader.next(); + } + +#if FETCH_FULL_EVENT_BEFORE_RETURN + /* if we didn't read a complete event, see if we can fill and + try again instead of returning with nothing and redoing poll. */ + if (numEventReceived == 0 && mEnabled == 1) { + n = mInputReader.fill(data_fd); + if (n) + goto again; + } +#endif + + return numEventReceived; +} + diff --git a/libsensors/GyroSensor.h b/libsensors/GyroSensor.h new file mode 100644 index 0000000..e8997de --- /dev/null +++ b/libsensors/GyroSensor.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_GYRO_SENSOR_H +#define ANDROID_GYRO_SENSOR_H + +#include +#include +#include +#include + +#include "sensors.h" +#include "SensorBase.h" +#include "InputEventReader.h" + +/*****************************************************************************/ + +struct input_event; + +class GyroSensor : public SensorBase { + int mEnabled; + InputEventCircularReader mInputReader; + sensors_event_t mPendingEvent; + bool mHasPendingEvent; + char input_sysfs_path[PATH_MAX]; + int input_sysfs_path_len; + int64_t mEnabledTime; + + int setInitialState(); + +public: + GyroSensor(); + virtual ~GyroSensor(); + virtual int readEvents(sensors_event_t* data, int count); + virtual bool hasPendingEvents() const; + virtual int setDelay(int32_t handle, int64_t ns); + virtual int enable(int32_t handle, int enabled); +}; + +/*****************************************************************************/ + +#endif // ANDROID_GYRO_SENSOR_H diff --git a/libsensors/InputEventReader.cpp b/libsensors/InputEventReader.cpp new file mode 100644 index 0000000..ab23a22 --- /dev/null +++ b/libsensors/InputEventReader.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include + +#include "InputEventReader.h" + +/*****************************************************************************/ + +struct input_event; + +InputEventCircularReader::InputEventCircularReader(size_t numEvents) + : mBuffer(new input_event[numEvents * 2]), + mBufferEnd(mBuffer + numEvents), + mHead(mBuffer), + mCurr(mBuffer), + mFreeSpace(numEvents) +{ +} + +InputEventCircularReader::~InputEventCircularReader() +{ + delete [] mBuffer; +} + +ssize_t InputEventCircularReader::fill(int fd) +{ + size_t numEventsRead = 0; + if (mFreeSpace) { + const ssize_t nread = read(fd, mHead, mFreeSpace * sizeof(input_event)); + if (nread<0 || nread % sizeof(input_event)) { + // we got a partial event!! + return nread<0 ? -errno : -EINVAL; + } + + numEventsRead = nread / sizeof(input_event); + if (numEventsRead) { + mHead += numEventsRead; + mFreeSpace -= numEventsRead; + if (mHead > mBufferEnd) { + size_t s = mHead - mBufferEnd; + memcpy(mBuffer, mBufferEnd, s * sizeof(input_event)); + mHead = mBuffer + s; + } + } + } + + return numEventsRead; +} + +ssize_t InputEventCircularReader::readEvent(input_event const** events) +{ + *events = mCurr; + ssize_t available = (mBufferEnd - mBuffer) - mFreeSpace; + return available ? 1 : 0; +} + +void InputEventCircularReader::next() +{ + mCurr++; + mFreeSpace++; + if (mCurr >= mBufferEnd) { + mCurr = mBuffer; + } +} diff --git a/libsensors/InputEventReader.h b/libsensors/InputEventReader.h new file mode 100644 index 0000000..180aade --- /dev/null +++ b/libsensors/InputEventReader.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_INPUT_EVENT_READER_H +#define ANDROID_INPUT_EVENT_READER_H + +#include +#include +#include +#include + +/*****************************************************************************/ + +struct input_event; + +class InputEventCircularReader +{ + struct input_event* const mBuffer; + struct input_event* const mBufferEnd; + struct input_event* mHead; + struct input_event* mCurr; + ssize_t mFreeSpace; + +public: + InputEventCircularReader(size_t numEvents); + ~InputEventCircularReader(); + ssize_t fill(int fd); + ssize_t readEvent(input_event const** events); + void next(); +}; + +/*****************************************************************************/ + +#endif // ANDROID_INPUT_EVENT_READER_H diff --git a/libsensors/LightSensor.cpp b/libsensors/LightSensor.cpp new file mode 100644 index 0000000..405348f --- /dev/null +++ b/libsensors/LightSensor.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "LightSensor.h" + +#define LOGTAG "LightSensor" + +// #define ALOG_NDEBUG 0 + +/*****************************************************************************/ + +LightSensor::LightSensor() + : SensorBase(NULL, "light_sensor"), + mEnabled(0), + mInputReader(4), + mHasPendingEvent(false) +{ + mPendingEvent.version = sizeof(sensors_event_t); + mPendingEvent.sensor = ID_L; + mPendingEvent.type = SENSOR_TYPE_LIGHT; + memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data)); + + if (data_fd) { + strcpy(input_sysfs_path, "/sys/class/input/"); + strcat(input_sysfs_path, input_name); + strcat(input_sysfs_path, "/device/"); + input_sysfs_path_len = strlen(input_sysfs_path); + enable(0, 1); + } +} + +LightSensor::~LightSensor() { + if (mEnabled) { + enable(0, 0); + } +} + +int LightSensor::setInitialState() { + struct input_absinfo absinfo; + if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_LIGHT), &absinfo)) { + // make sure to report an event immediately + mHasPendingEvent = true; + mPendingEvent.light = absinfo.value; + } + return 0; +} + +int LightSensor::setDelay(int32_t handle, int64_t ns) +{ + int fd; + + strcpy(&input_sysfs_path[input_sysfs_path_len], "poll_delay"); + fd = open(input_sysfs_path, O_RDWR); + if (fd >= 0) { + char buf[80]; + sprintf(buf, "%lld", ns); + write(fd, buf, strlen(buf)+1); + close(fd); + return 0; + } + return -1; +} + +int LightSensor::enable(int32_t handle, int en) +{ + int flags = en ? 1 : 0; + int err; + int fd; + if (flags != mEnabled) { + strcpy(&input_sysfs_path[input_sysfs_path_len], "enable"); + fd = open(input_sysfs_path, O_RDWR); + if (fd >= 0) { + write(fd, en == 1 ? "1" : "0", 2); + close(fd); + mEnabled = flags; + setInitialState(); + return 0; + } + return -1; + } + return 0; +} + +bool LightSensor::hasPendingEvents() const { + return mHasPendingEvent; +} + +int LightSensor::readEvents(sensors_event_t* data, int count) +{ + if (count < 1) + return -EINVAL; + + if (mHasPendingEvent) { + mHasPendingEvent = false; + mPendingEvent.timestamp = getTimestamp(); + *data = mPendingEvent; + return mEnabled ? 1 : 0; + } + + ssize_t n = mInputReader.fill(data_fd); + if (n < 0) + return n; + + int numEventReceived = 0; + input_event const* event; + + while (count && mInputReader.readEvent(&event)) { + int type = event->type; + if (type == EV_REL) { + if (event->code == EVENT_TYPE_LIGHT) { + mPendingEvent.light = event->value; + } + } else if (type == EV_SYN) { + mPendingEvent.timestamp = timevalToNano(event->time); + if (mEnabled) { + *data++ = mPendingEvent; + count--; + numEventReceived++; + } + } else { + ALOGE("%s: unknown event (type=%d, code=%d)", LOGTAG, + type, event->code); + } + mInputReader.next(); + } + + return numEventReceived; +} diff --git a/libsensors/LightSensor.h b/libsensors/LightSensor.h new file mode 100644 index 0000000..85e65d9 --- /dev/null +++ b/libsensors/LightSensor.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_LIGHT_SENSOR_H +#define ANDROID_LIGHT_SENSOR_H + +#include +#include +#include +#include + +#include "sensors.h" +#include "SensorBase.h" +#include "InputEventReader.h" + +/*****************************************************************************/ + +struct input_event; + +class LightSensor : public SensorBase { + int mEnabled; + InputEventCircularReader mInputReader; + sensors_event_t mPendingEvent; + bool mHasPendingEvent; + char input_sysfs_path[PATH_MAX]; + int input_sysfs_path_len; + + float indexToValue(size_t index) const; + int setInitialState(); + +public: + LightSensor(); + virtual ~LightSensor(); + virtual int readEvents(sensors_event_t* data, int count); + virtual bool hasPendingEvents() const; + virtual int setDelay(int32_t handle, int64_t ns); + virtual int enable(int32_t handle, int enabled); +}; + +/*****************************************************************************/ + +#endif // ANDROID_LIGHT_SENSOR_H diff --git a/libsensors/MODULE_LICENSE_APACHE2 b/libsensors/MODULE_LICENSE_APACHE2 new file mode 100644 index 0000000..e69de29 diff --git a/libsensors/PressureSensor.cpp b/libsensors/PressureSensor.cpp new file mode 100644 index 0000000..6539ce0 --- /dev/null +++ b/libsensors/PressureSensor.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "PressureSensor.h" + +#define LOGTAG "PressureSensor" + +#define PRESSURE_CONVERT(x) (x/4096.0f) + +/*****************************************************************************/ + +PressureSensor::PressureSensor() + : SensorBase(NULL, "barometer_sensor"), + mEnabled(0), + mInputReader(4), + mHasPendingEvent(false) +{ + mPendingEvent.version = sizeof(sensors_event_t); + mPendingEvent.sensor = ID_PR; + mPendingEvent.type = SENSOR_TYPE_PRESSURE; + memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data)); + + if (data_fd) { + strcpy(input_sysfs_path, "/sys/class/input/"); + strcat(input_sysfs_path, input_name); + strcat(input_sysfs_path, "/device/"); + input_sysfs_path_len = strlen(input_sysfs_path); + enable(0, 1); + } +} + +PressureSensor::~PressureSensor() { + if (mEnabled) { + enable(0, 0); + } +} + +int PressureSensor::setInitialState() { + struct input_absinfo absinfo; + if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_PRESSURE), &absinfo)) { + // make sure to report an event immediately + mHasPendingEvent = true; + mPendingEvent.pressure = PRESSURE_CONVERT(absinfo.value); + } + return 0; +} + +int PressureSensor::enable(int32_t handle, int en) { + int flags = en ? 1 : 0; + int fd; + if (flags != mEnabled) { + strcpy(&input_sysfs_path[input_sysfs_path_len], "enable"); + fd = open(input_sysfs_path, O_RDWR); + if (fd >= 0) { + write(fd, flags == 1 ? "1" : "0", 2); + close(fd); + mEnabled = flags; + setInitialState(); + return 0; + } + + return -1; + } + return 0; +} + +bool PressureSensor::hasPendingEvents() const { + return mHasPendingEvent; +} + +int PressureSensor::setDelay(int32_t handle, int64_t delay) +{ + int fd; + if (delay < 10000000) + delay = 10; + else + delay = delay / 1000000; + strcpy(&input_sysfs_path[input_sysfs_path_len], "poll_delay"); + fd = open(input_sysfs_path, O_RDWR); + if (fd >= 0) { + char buf[80]; + sprintf(buf, "%lld", delay); + write(fd, buf, strlen(buf)+1); + close(fd); + return 0; + } + return -1; +} + + +int PressureSensor::readEvents(sensors_event_t* data, int count) +{ + if (count < 1) + return -EINVAL; + + if (mHasPendingEvent) { + mHasPendingEvent = false; + mPendingEvent.timestamp = getTimestamp(); + *data = mPendingEvent; + return mEnabled ? 1 : 0; + } + + ssize_t n = mInputReader.fill(data_fd); + if (n < 0) + return n; + + int numEventReceived = 0; + input_event const* event; + + while (count && mInputReader.readEvent(&event)) { + int type = event->type; + if (type == EV_REL) { + if (event->code == REL_X) { + mPendingEvent.pressure = PRESSURE_CONVERT(event->value); + } + } else if (type == EV_SYN) { + mPendingEvent.timestamp = timevalToNano(event->time); + if (mEnabled) { + *data++ = mPendingEvent; + count--; + numEventReceived++; + } + } else { + ALOGE("%s: unknown event (type=%d, code=%d)", LOGTAG, + type, event->code); + } + mInputReader.next(); + } + + return numEventReceived; +} diff --git a/libsensors/PressureSensor.h b/libsensors/PressureSensor.h new file mode 100644 index 0000000..9333d44 --- /dev/null +++ b/libsensors/PressureSensor.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_PRESSURE_SENSOR_H +#define ANDROID_PRESSURE_SENSOR_H + +#include +#include +#include +#include + +#include "sensors.h" +#include "SensorBase.h" +#include "InputEventReader.h" + +/*****************************************************************************/ + +struct input_event; + +class PressureSensor : public SensorBase { + int mEnabled; + InputEventCircularReader mInputReader; + sensors_event_t mPendingEvent; + bool mHasPendingEvent; + char input_sysfs_path[PATH_MAX]; + int input_sysfs_path_len; + + int setInitialState(); + +public: + PressureSensor(); + virtual ~PressureSensor(); + virtual int readEvents(sensors_event_t* data, int count); + virtual bool hasPendingEvents() const; + virtual int enable(int32_t handle, int enabled); + virtual int setDelay(int32_t handle, int64_t ns); +}; + +/*****************************************************************************/ + +#endif // ANDROID_PRESSURE_SENSOR_H diff --git a/libsensors/ProximitySensor.cpp b/libsensors/ProximitySensor.cpp new file mode 100644 index 0000000..2ba56c1 --- /dev/null +++ b/libsensors/ProximitySensor.cpp @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define ALOG_NDEBUG 0 +#define LOG_NDEBUG 0 +#include + +#include "ProximitySensor.h" +#include "SensorBase.h" + +#define LOGTAG "ProximitySensor" + +/*****************************************************************************/ + +ProximitySensor::ProximitySensor() + : SensorBase(NULL, "proximity_sensor"), + mEnabled(0), + mInputReader(4), + mHasPendingEvent(false) +{ + mPendingEvent.version = sizeof(sensors_event_t); + mPendingEvent.sensor = ID_P; + mPendingEvent.type = SENSOR_TYPE_PROXIMITY; + memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data)); + + if (data_fd) { + ALOGE("%s: got input_name %s", LOGTAG, input_name); + strcpy(input_sysfs_path, "/sys/class/input/"); + strcat(input_sysfs_path, input_name); + strcat(input_sysfs_path, "/device/"); + input_sysfs_path_len = strlen(input_sysfs_path); + enable(0, 1); + } +} + +ProximitySensor::~ProximitySensor() { + if (mEnabled) { + enable(0, 0); + } +} + +int ProximitySensor::setInitialState() { + struct input_absinfo absinfo; + if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_PROXIMITY), &absinfo)) { + // make sure to report an event immediately + mHasPendingEvent = true; + mPendingEvent.distance = indexToValue(absinfo.value); + } + return 0; +} + +int ProximitySensor::setDelay(int32_t handle, int64_t ns) +{ + int fd; + + strcpy(&input_sysfs_path[input_sysfs_path_len], "prox_poll_delay"); + fd = open(input_sysfs_path, O_RDWR); + if (fd >= 0) { + char buf[80]; + sprintf(buf, "%lld", ns); + write(fd, buf, strlen(buf)+1); + close(fd); + return 0; + } + return -1; +} + +int ProximitySensor::enable(int32_t handle, int en) { + int fd; + int flags = en ? 1 : 0; + int err; + ALOGD("%s: Enable: %i", __func__, en); + if (flags != mEnabled) { + strcpy(&input_sysfs_path[input_sysfs_path_len], "enable"); + fd = open(input_sysfs_path, O_RDWR); + if (fd >= 0) { + write(fd, en == 1 ? "1" : "0", 2); + close(fd); + mEnabled = flags; + setInitialState(); + return 0; + } + + return -1; + } + return 0; +} + +bool ProximitySensor::hasPendingEvents() const { + return mHasPendingEvent; +} + +int ProximitySensor::readEvents(sensors_event_t* data, int count) +{ + if (count < 1) + return -EINVAL; + + if (mHasPendingEvent) { + mHasPendingEvent = false; + mPendingEvent.timestamp = getTimestamp(); + *data = mPendingEvent; + return mEnabled ? 1 : 0; + } + + ssize_t n = mInputReader.fill(data_fd); + if (n < 0) + return n; + + int numEventReceived = 0; + input_event const* event; + + while (count && mInputReader.readEvent(&event)) { + int type = event->type; + if (type == EV_ABS) { + if (event->code == EVENT_TYPE_PROXIMITY) { + if (event->value != -1) { + // FIXME: not sure why we're getting -1 sometimes + mPendingEvent.distance = indexToValue(event->value); + } + } + } else if (type == EV_SYN) { + mPendingEvent.timestamp = timevalToNano(event->time); + if (mEnabled) { + *data++ = mPendingEvent; + count--; + numEventReceived++; + } + } else { + ALOGE("%s: unknown event (type=%d, code=%d)",LOGTAG, + type, event->code); + } + mInputReader.next(); + } + + return numEventReceived; +} + +float ProximitySensor::indexToValue(size_t index) const +{ + ALOGV("%s: Index = %zu",LOGTAG, index); + return index * PROXIMITY_THRESHOLD_CM; +} diff --git a/libsensors/ProximitySensor.h b/libsensors/ProximitySensor.h new file mode 100644 index 0000000..a6aa851 --- /dev/null +++ b/libsensors/ProximitySensor.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_PROXIMITY_SENSOR_H +#define ANDROID_PROXIMITY_SENSOR_H + +#include +#include +#include +#include + +#include "sensors.h" +#include "SensorBase.h" +#include "InputEventReader.h" + +/*****************************************************************************/ + +struct input_event; + +class ProximitySensor : public SensorBase { + int mEnabled; + InputEventCircularReader mInputReader; + sensors_event_t mPendingEvent; + bool mHasPendingEvent; + char input_sysfs_path[PATH_MAX]; + int input_sysfs_path_len; + + int setInitialState(); + float indexToValue(size_t index) const; + +public: + ProximitySensor(); + virtual ~ProximitySensor(); + virtual int readEvents(sensors_event_t* data, int count); + virtual bool hasPendingEvents() const; + virtual int enable(int32_t handle, int enabled); + virtual int setDelay(int32_t handle, int64_t ns); +}; + +/*****************************************************************************/ + +#endif // ANDROID_PROXIMITY_SENSOR_H diff --git a/libsensors/SensorBase.cpp b/libsensors/SensorBase.cpp new file mode 100644 index 0000000..f08ffb7 --- /dev/null +++ b/libsensors/SensorBase.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include "SensorBase.h" + +/*****************************************************************************/ + +SensorBase::SensorBase( + const char* dev_name, + const char* data_name) + : dev_name(dev_name), data_name(data_name), + dev_fd(-1), data_fd(-1) +{ + if (data_name) { + data_fd = openInput(data_name); + } +} + +SensorBase::~SensorBase() { + if (data_fd >= 0) { + close(data_fd); + } + if (dev_fd >= 0) { + close(dev_fd); + } +} + +int SensorBase::open_device() { + if (dev_fd<0 && dev_name) { + dev_fd = open(dev_name, O_RDONLY); + ALOGE_IF(dev_fd<0, "Couldn't open %s (%s)", dev_name, strerror(errno)); + } + return 0; +} + +int SensorBase::close_device() { + if (dev_fd >= 0) { + close(dev_fd); + dev_fd = -1; + } + return 0; +} + +int SensorBase::getFd() const { + if (!data_name) { + return dev_fd; + } + return data_fd; +} + +int SensorBase::setDelay(int32_t handle, int64_t ns) { + return 0; +} + +bool SensorBase::hasPendingEvents() const { + return false; +} + +int64_t SensorBase::getTimestamp() { + struct timespec t; + t.tv_sec = t.tv_nsec = 0; + clock_gettime(CLOCK_MONOTONIC, &t); + return int64_t(t.tv_sec)*1000000000LL + t.tv_nsec; +} + +int SensorBase::openInput(const char* inputName) { + int fd = -1; + const char *dirname = "/dev/input"; + char devname[PATH_MAX]; + char *filename; + DIR *dir; + struct dirent *de; + dir = opendir(dirname); + if(dir == NULL) + return -1; + strcpy(devname, dirname); + filename = devname + strlen(devname); + *filename++ = '/'; + while((de = readdir(dir))) { + if(de->d_name[0] == '.' && + (de->d_name[1] == '\0' || + (de->d_name[1] == '.' && de->d_name[2] == '\0'))) + continue; + strcpy(filename, de->d_name); + fd = open(devname, O_RDONLY); + if (fd>=0) { + char name[80]; + if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) { + name[0] = '\0'; + } + if (!strcmp(name, inputName)) { + strcpy(input_name, filename); + break; + } else { + close(fd); + fd = -1; + } + } + } + closedir(dir); + ALOGE_IF(fd<0, "couldn't find '%s' input device", inputName); + + return fd; +} + +int SensorBase::batch(int handle, int flags, int64_t period_ns, int64_t timeout) +{ + return 0; +} + +int SensorBase::flush(int handle) +{ + return 0; +} diff --git a/libsensors/SensorBase.h b/libsensors/SensorBase.h new file mode 100644 index 0000000..13a4ae6 --- /dev/null +++ b/libsensors/SensorBase.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_SENSOR_BASE_H +#define ANDROID_SENSOR_BASE_H + +#include +#include +#include +#include + +#include "sensors.h" + + +/*****************************************************************************/ + +struct sensors_event_t; + +class SensorBase { +protected: + const char* dev_name; + const char* data_name; + char input_name[PATH_MAX]; + int dev_fd; + int data_fd; + + int openInput(const char* inputName); + static int64_t getTimestamp(); + + + static int64_t timevalToNano(timeval const& t) { + return t.tv_sec*1000000000LL + t.tv_usec*1000; + } + + int open_device(); + int close_device(); + +public: + SensorBase( + const char* dev_name, + const char* data_name); + + virtual ~SensorBase(); + + virtual int readEvents(sensors_event_t* data, int count) = 0; + virtual bool hasPendingEvents() const; + virtual int getFd() const; + virtual int setDelay(int32_t handle, int64_t ns); + virtual int enable(int32_t handle, int enabled) = 0; + virtual int batch(int handle, int flags, int64_t period_ns, int64_t timeout); + virtual int flush(int handle); + +}; + +/*****************************************************************************/ + +#endif // ANDROID_SENSOR_BASE_H diff --git a/libsensors/ak8973b.h b/libsensors/ak8973b.h new file mode 100644 index 0000000..9b7ab60 --- /dev/null +++ b/libsensors/ak8973b.h @@ -0,0 +1,51 @@ +/* + * Definitions for akm8973 compass chip. + */ +#ifndef AKM8973_H +#define AKM8973_H + +#include + +#define AKM8973_I2C_NAME "ak8973b" + +#define AKMIO 0xA1 + +/* IOCTLs for AKM library */ +#define ECS_IOCTL_WRITE _IOW(AKMIO, 0x01, char*) +#define ECS_IOCTL_READ _IOWR(AKMIO, 0x02, char*) +#define ECS_IOCTL_RESET _IO(AKMIO, 0x03) +#define ECS_IOCTL_SET_MODE _IOW(AKMIO, 0x04, short) +#define ECS_IOCTL_GETDATA _IOR(AKMIO, 0x05, char[SENSOR_DATA_SIZE]) +#define ECS_IOCTL_SET_YPR _IOW(AKMIO, 0x06, short[12]) +#define ECS_IOCTL_GET_OPEN_STATUS _IOR(AKMIO, 0x07, int) +#define ECS_IOCTL_GET_CLOSE_STATUS _IOR(AKMIO, 0x08, int) +#define ECS_IOCTL_GET_DELAY _IOR(AKMIO, 0x30, int64_t) +#define ECS_IOCTL_GET_PROJECT_NAME _IOR(AKMIO, 0x0D, char[64]) +#define ECS_IOCTL_GET_MATRIX _IOR(AKMIO, 0x0E, short [4][3][3]) + +/* IOCTLs for APPs */ +#define ECS_IOCTL_APP_SET_MODE _IOW(AKMIO, 0x10, short) +#define ECS_IOCTL_APP_SET_MFLAG _IOW(AKMIO, 0x11, short) +#define ECS_IOCTL_APP_GET_MFLAG _IOW(AKMIO, 0x12, short) +#define ECS_IOCTL_APP_SET_AFLAG _IOW(AKMIO, 0x13, short) +#define ECS_IOCTL_APP_GET_AFLAG _IOR(AKMIO, 0x14, short) +#define ECS_IOCTL_APP_SET_TFLAG _IOR(AKMIO, 0x15, short) +#define ECS_IOCTL_APP_GET_TFLAG _IOR(AKMIO, 0x16, short) +#define ECS_IOCTL_APP_RESET_PEDOMETER _IO(AKMIO, 0x17) +#define ECS_IOCTL_APP_SET_DELAY _IOW(AKMIO, 0x18, int64_t) +#define ECS_IOCTL_APP_GET_DELAY ECS_IOCTL_GET_DELAY + +/* Set raw magnetic vector flag */ +#define ECS_IOCTL_APP_SET_MVFLAG _IOW(AKMIO, 0x19, short) + +/* Get raw magnetic vector flag */ +#define ECS_IOCTL_APP_GET_MVFLAG _IOR(AKMIO, 0x1A, short) + +struct akm8973_platform_data { + short layouts[4][3][3]; + char project_name[64]; + int gpio_RST; + int gpio_INT; +}; + +#endif diff --git a/libsensors/ak8975-reg.h b/libsensors/ak8975-reg.h deleted file mode 100644 index 1a78a27..0000000 --- a/libsensors/ak8975-reg.h +++ /dev/null @@ -1,48 +0,0 @@ -/* linux/drivers/misc/ak8975-reg.h - * - * Copyright (c) 2010 Samsung Electronics Co., Ltd. - * http://www.samsung.com/ - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. -*/ -#ifndef __AK8975_REG__ -#define __AK8975_REG__ - -/* Compass device dependent definition */ -#define AK8975_MODE_SNG_MEASURE 0x01 -#define AK8975_MODE_SELF_TEST 0x08 -#define AK8975_MODE_FUSE_ACCESS 0x0F -#define AK8975_MODE_POWER_DOWN 0x00 - -/* Rx buffer size. i.e ST,TMPS,H1X,H1Y,H1Z*/ -#define SENSOR_DATA_SIZE 8 - -/* Read/Write buffer size.*/ -#define RWBUF_SIZE 16 - -/* AK8975 register address */ -#define AK8975_REG_WIA 0x00 -#define AK8975_REG_INFO 0x01 -#define AK8975_REG_ST1 0x02 -#define AK8975_REG_HXL 0x03 -#define AK8975_REG_HXH 0x04 -#define AK8975_REG_HYL 0x05 -#define AK8975_REG_HYH 0x06 -#define AK8975_REG_HZL 0x07 -#define AK8975_REG_HZH 0x08 -#define AK8975_REG_ST2 0x09 -#define AK8975_REG_CNTL 0x0A -#define AK8975_REG_RSV 0x0B -#define AK8975_REG_ASTC 0x0C -#define AK8975_REG_TS1 0x0D -#define AK8975_REG_TS2 0x0E -#define AK8975_REG_I2CDIS 0x0F - -/* AK8975 fuse-rom address */ -#define AK8975_FUSE_ASAX 0x10 -#define AK8975_FUSE_ASAY 0x11 -#define AK8975_FUSE_ASAZ 0x12 - -#endif /* __AK8975_REG__ */ diff --git a/libsensors/ak8975.h b/libsensors/ak8975.h deleted file mode 100644 index 79a5de4..0000000 --- a/libsensors/ak8975.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2010 Samsung Electronics. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * version 2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#ifndef AKM8975_H -#define AKM8975_H - -#include - -#define AKM8975_I2C_NAME "ak8975" - -/* Rx buffer size, i.e from ST1 to ST2 */ -#define SENSOR_DATA_SIZE 8 -#define AKMIO 0xA1 - -/* IOCTLs for AKM library */ -/* WRITE and READ sizes don't include data. On WRITE, the first value is data - * size plus one and the second value is the register address. On READ - * the first value is the data size and second value is the register - * address and the data is written back into the buffer starting at - * the second byte (the length is unchanged). - */ -#define ECS_IOCTL_WRITE _IOW(AKMIO, 0x01, char*) -#define ECS_IOCTL_READ _IOWR(AKMIO, 0x02, char*) -#define ECS_IOCTL_RESET _IO(AKMIO, 0x03) -#define ECS_IOCTL_SET_MODE _IOW(AKMIO, 0x04, short) -#define ECS_IOCTL_GETDATA _IOR(AKMIO, 0x05, \ - char[SENSOR_DATA_SIZE]) -#define ECS_IOCTL_SET_YPR _IOW(AKMIO, 0x06, short[12]) -#define ECS_IOCTL_GET_OPEN_STATUS _IOR(AKMIO, 0x07, int) -#define ECS_IOCTL_GET_CLOSE_STATUS _IOR(AKMIO, 0x08, int) -#define ECS_IOCTL_GET_DELAY _IOR(AKMIO, 0x30, int64_t) -#define ECS_IOCTL_GET_PROJECT_NAME _IOR(AKMIO, 0x0D, char[64]) -#define ECS_IOCTL_GET_MATRIX _IOR(AKMIO, 0x0E, short[4][3][3]) - -/* IOCTLs for APPs */ -#define ECS_IOCTL_APP_SET_MODE _IOW(AKMIO, 0x10, short) -#define ECS_IOCTL_APP_SET_MFLAG _IOW(AKMIO, 0x11, short) -#define ECS_IOCTL_APP_GET_MFLAG _IOR(AKMIO, 0x12, short) -#define ECS_IOCTL_APP_SET_AFLAG _IOW(AKMIO, 0x13, short) -#define ECS_IOCTL_APP_GET_AFLAG _IOR(AKMIO, 0x14, short) -#define ECS_IOCTL_APP_SET_TFLAG _IOW(AKMIO, 0x15, short) -#define ECS_IOCTL_APP_GET_TFLAG _IOR(AKMIO, 0x16, short) -#define ECS_IOCTL_APP_RESET_PEDOMETER _IO(AKMIO, 0x17) -#define ECS_IOCTL_APP_SET_DELAY _IOW(AKMIO, 0x18, int64_t) -#define ECS_IOCTL_APP_GET_DELAY ECS_IOCTL_GET_DELAY - -/* Set raw magnetic vector flag */ -#define ECS_IOCTL_APP_SET_MVFLAG _IOW(AKMIO, 0x19, short) - -/* Get raw magnetic vector flag */ -#define ECS_IOCTL_APP_GET_MVFLAG _IOR(AKMIO, 0x1A, short) - -#ifdef __KERNEL__ -struct akm8975_platform_data { - int gpio_data_ready_int; -}; -#endif - -#endif diff --git a/libsensors/akm8975.c b/libsensors/akm8975.c deleted file mode 100644 index 47771fb..0000000 --- a/libsensors/akm8975.c +++ /dev/null @@ -1,612 +0,0 @@ -/* - * Copyright (C) 2013 Paul Kocialkowski - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include - -#include -#include - -#define LOG_TAG "smdk4x12_sensors" -#include - -#include "smdk4x12_sensors.h" -#include "ak8975.h" -#include "ak8975-reg.h" - -#include -#include - -#define AKFS_CONFIG_PATH "/data/misc/akfs.txt" -#define AKFS_PAT PAT3 - -struct akm8975_data { - AK8975PRMS akfs_params; - sensors_vec_t magnetic; - - int64_t delay; - int device_fd; - int uinput_fd; - - pthread_t thread; - pthread_mutex_t mutex; - int thread_continue; -}; - -int akfs_get_magnetic_field(struct akm8975_data *akm8975_data, short *magnetic_data) -{ - AK8975PRMS *params; - int rc, aocret; - float radius; - - if (akm8975_data == NULL || magnetic_data == NULL) - return -EINVAL; - - params = &akm8975_data->akfs_params; - - // Decomposition - // Sensitivity adjustment, i.e. multiply ASA, is done in this function. - rc = AKFS_DecompAK8975(magnetic_data, 1, ¶ms->mi_asa, AKFS_HDATA_SIZE, params->mfv_hdata); - if (rc == AKFS_ERROR) { - ALOGE("Failed to decomp!"); - return -1; - } - - // Adjust coordination - rc = AKFS_Rotate(params->m_hpat, ¶ms->mfv_hdata[0]); - if (rc == AKFS_ERROR) { - ALOGE("Failed to rotate!"); - return -1; - } - - // AOC for magnetometer - // Offset estimation is done in this function - aocret = AKFS_AOC(¶ms->m_aocv, params->mfv_hdata, ¶ms->mfv_ho); - - // Subtract offset - // Then, a magnetic vector, the unit is uT, is stored in mfv_hvbuf. - rc = AKFS_VbNorm(AKFS_HDATA_SIZE, params->mfv_hdata, 1, - ¶ms->mfv_ho, ¶ms->mfv_hs, AK8975_HSENSE_TARGET, - AKFS_HDATA_SIZE, params->mfv_hvbuf); - if (rc == AKFS_ERROR) { - ALOGE("Failed to normalize!"); - return -1; - } - - // Averaging - rc = AKFS_VbAve(AKFS_HDATA_SIZE, params->mfv_hvbuf, CSPEC_HNAVE_V, ¶ms->mfv_hvec); - if (rc == AKFS_ERROR) { - ALOGE("Failed to average!"); - return -1; - } - - // Check the size of magnetic vector - radius = sqrtf( - (params->mfv_hvec.u.x * params->mfv_hvec.u.x) + - (params->mfv_hvec.u.y * params->mfv_hvec.u.y) + - (params->mfv_hvec.u.z * params->mfv_hvec.u.z)); - - // Sanity check result and set accuracy - if ((radius > MAGNETIC_FIELD_EARTH_MAX + 10) || (radius < MAGNETIC_FIELD_EARTH_MIN - 10)) { - params->mi_hstatus = SENSOR_STATUS_UNRELIABLE; - } else if(params->mi_hstatus == SENSOR_STATUS_UNRELIABLE) { - params->mi_hstatus = SENSOR_STATUS_ACCURACY_MEDIUM; - } else if (aocret == AKFS_SUCCESS) { - params->mi_hstatus = SENSOR_STATUS_ACCURACY_HIGH; - } - - akm8975_data->magnetic.x = params->mfv_hvec.u.x; - akm8975_data->magnetic.y = params->mfv_hvec.u.y; - akm8975_data->magnetic.z = params->mfv_hvec.u.z; - akm8975_data->magnetic.status = params->mi_hstatus; - - return 0; -} - -int akfs_init(struct akm8975_data *akm8975_data, char *asa, AKFS_PATNO pat) -{ - AK8975PRMS *params; - - if (akm8975_data == NULL || asa == NULL) - return -EINVAL; - - params = &akm8975_data->akfs_params; - - memset(params, 0, sizeof(AK8975PRMS)); - - // Sensitivity - params->mfv_hs.u.x = AK8975_HSENSE_DEFAULT; - params->mfv_hs.u.y = AK8975_HSENSE_DEFAULT; - params->mfv_hs.u.z = AK8975_HSENSE_DEFAULT; - params->mfv_as.u.x = AK8975_ASENSE_DEFAULT; - params->mfv_as.u.y = AK8975_ASENSE_DEFAULT; - params->mfv_as.u.z = AK8975_ASENSE_DEFAULT; - - // Initialize variables that initial value is not 0. - params->mi_hnaveV = CSPEC_HNAVE_V; - params->mi_hnaveD = CSPEC_HNAVE_D; - params->mi_anaveV = CSPEC_ANAVE_V; - params->mi_anaveD = CSPEC_ANAVE_D; - - // Copy ASA values - params->mi_asa.u.x = asa[0]; - params->mi_asa.u.y = asa[1]; - params->mi_asa.u.z = asa[2]; - - // Copy layout pattern - params->m_hpat = pat; - - return 0; -} - -void *akm8975_thread(void *thread_data) -{ - struct smdk4x12_sensors_handlers *handlers = NULL; - struct akm8975_data *data = NULL; - struct input_event event; - struct timeval time; - char i2c_data[SENSOR_DATA_SIZE] = { 0 }; - short magnetic_data[3]; - short mode; - int64_t before, after; - int diff; - int device_fd; - int uinput_fd; - int rc; - - if (thread_data == NULL) - return NULL; - - handlers = (struct smdk4x12_sensors_handlers *) thread_data; - if (handlers->data == NULL) - return NULL; - - data = (struct akm8975_data *) handlers->data; - - device_fd = data->device_fd; - if (device_fd < 0) - return NULL; - - uinput_fd = data->uinput_fd; - if (uinput_fd < 0) - return NULL; - - while (data->thread_continue) { - pthread_mutex_lock(&data->mutex); - if (!data->thread_continue) - break; - - while (handlers->activated) { - gettimeofday(&time, NULL); - before = timestamp(&time); - - mode = AK8975_MODE_SNG_MEASURE; - rc = ioctl(device_fd, ECS_IOCTL_SET_MODE, &mode); - if (rc < 0) { - ALOGE("%s: Unable to set akm8975 mode", __func__); - return NULL; - } - - memset(&i2c_data, 0, sizeof(i2c_data)); - rc = ioctl(device_fd, ECS_IOCTL_GETDATA, &i2c_data); - if (rc < 0) { - ALOGE("%s: Unable to get akm8975 data", __func__); - return NULL; - } - - if (!(i2c_data[0] & 0x01)) { - ALOGE("%s: akm8975 data is not ready", __func__); - continue; - } - - if (i2c_data[7] & (1 << 2) || i2c_data[7] & (1 << 3)) { - ALOGE("%s: akm8975 data read error or overflow", __func__); - continue; - } - - magnetic_data[0] = (short) (i2c_data[2] << 8) | (i2c_data[1]); - magnetic_data[1] = (short) (i2c_data[4] << 8) | (i2c_data[3]); - magnetic_data[2] = (short) (i2c_data[6] << 8) | (i2c_data[5]); - - rc = akfs_get_magnetic_field(data, (short *) &magnetic_data); - if (rc < 0) { - ALOGE("%s: Unable to get AKFS magnetic field", __func__); - continue; - } - - input_event_set(&event, EV_REL, REL_X, (int) (data->magnetic.x * 1000)); - write(uinput_fd, &event, sizeof(event)); - input_event_set(&event, EV_REL, REL_Y, (int) (data->magnetic.y * 1000)); - write(uinput_fd, &event, sizeof(event)); - input_event_set(&event, EV_REL, REL_Z, (int) (data->magnetic.z * 1000)); - write(uinput_fd, &event, sizeof(event)); - input_event_set(&event, EV_REL, REL_MISC, (int) data->magnetic.status); - write(uinput_fd, &event, sizeof(event)); - input_event_set(&event, EV_SYN, 0, 0); - write(uinput_fd, &event, sizeof(event)); - - gettimeofday(&time, NULL); - after = timestamp(&time); - - diff = (int) (data->delay - (after - before)) / 1000; - if (diff <= 0) - continue; - - usleep(diff); - } - } - return NULL; -} - -int akm8975_init(struct smdk4x12_sensors_handlers *handlers, - struct smdk4x12_sensors_device *device) -{ - struct akm8975_data *data = NULL; - pthread_attr_t thread_attr; - char i2c_data[RWBUF_SIZE] = { 0 }; - short mode; - int device_fd = -1; - int uinput_fd = -1; - int input_fd = -1; - int rc; - int i; - - ALOGD("%s(%p, %p)", __func__, handlers, device); - - if (handlers == NULL || device == NULL) - return -EINVAL; - - data = (struct akm8975_data *) calloc(1, sizeof(struct akm8975_data)); - - device_fd = open("/dev/akm8975", O_RDONLY); - if (device_fd < 0) { - ALOGE("%s: Unable to open device", __func__); - goto error; - } - - mode = AK8975_MODE_POWER_DOWN; - rc = ioctl(device_fd, ECS_IOCTL_SET_MODE, &mode); - if (rc < 0) { - ALOGE("%s: Unable to set akm8975 mode", __func__); - goto error; - } - - mode = AK8975_MODE_FUSE_ACCESS; - rc = ioctl(device_fd, ECS_IOCTL_SET_MODE, &mode); - if (rc < 0) { - ALOGE("%s: Unable to set akm8975 mode", __func__); - goto error; - } - - i2c_data[0] = 3; - i2c_data[1] = AK8975_FUSE_ASAX; - rc = ioctl(device_fd, ECS_IOCTL_READ, &i2c_data); - if (rc < 0) { - ALOGE("%s: Unable to read akm8975 FUSE data", __func__); - goto error; - } - - ALOGD("AKM8975 ASA (Sensitivity Adjustment) values are: (%d, %d, %d)", - i2c_data[1], i2c_data[2], i2c_data[3]); - - rc = akfs_init(data, &i2c_data[1], AKFS_PAT); - if (rc < 0) { - ALOGE("%s: Unable to init AKFS", __func__); - goto error; - } - - i2c_data[0] = 1; - i2c_data[1] = AK8975_REG_WIA; - rc = ioctl(device_fd, ECS_IOCTL_READ, &i2c_data); - if (rc < 0) { - ALOGE("%s: Unable to read akm8975 WIA data", __func__); - goto error; - } - - ALOGD("AKM8975 WIA (Device ID) value is: 0x%x", i2c_data[1]); - - mode = AK8975_MODE_POWER_DOWN; - rc = ioctl(device_fd, ECS_IOCTL_SET_MODE, &mode); - if (rc < 0) { - ALOGE("%s: Unable to set akm8975 mode", __func__); - goto error; - } - - uinput_fd = uinput_rel_create("magnetic"); - if (uinput_fd < 0) { - ALOGD("%s: Unable to create uinput", __func__); - goto error; - } - - input_fd = input_open("magnetic"); - if (input_fd < 0) { - ALOGE("%s: Unable to open magnetic input", __func__); - goto error; - } - - data->thread_continue = 1; - - pthread_mutex_init(&data->mutex, NULL); - pthread_mutex_lock(&data->mutex); - - pthread_attr_init(&thread_attr); - pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); - - rc = pthread_create(&data->thread, &thread_attr, akm8975_thread, (void *) handlers); - if (rc < 0) { - ALOGE("%s: Unable to create akm8975 thread", __func__); - pthread_mutex_destroy(&data->mutex); - goto error; - } - - data->device_fd = device_fd; - data->uinput_fd = uinput_fd; - handlers->poll_fd = input_fd; - handlers->data = (void *) data; - - return 0; - -error: - if (data != NULL) - free(data); - - if (uinput_fd >= 0) - close(uinput_fd); - - if (input_fd >= 0) - close(input_fd); - - if (device_fd >= 0) - close(device_fd); - - handlers->poll_fd = -1; - handlers->data = NULL; - - return -1; -} - -int akm8975_deinit(struct smdk4x12_sensors_handlers *handlers) -{ - struct akm8975_data *data = NULL; - short mode; - int rc; - - ALOGD("%s(%p)", __func__, handlers); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct akm8975_data *) handlers->data; - - handlers->activated = 0; - data->thread_continue = 0; - pthread_mutex_unlock(&data->mutex); - - pthread_mutex_destroy(&data->mutex); - - if (data->uinput_fd >= 0) { - uinput_destroy(data->uinput_fd); - close(data->uinput_fd); - } - data->uinput_fd = -1; - - if (handlers->poll_fd >= 0) - close(handlers->poll_fd); - handlers->poll_fd = -1; - - mode = AK8975_MODE_POWER_DOWN; - rc = ioctl(data->device_fd, ECS_IOCTL_SET_MODE, &mode); - if (rc < 0) - ALOGE("%s: Unable to set akm8975 mode", __func__); - - if (data->device_fd >= 0) - close(data->device_fd); - data->device_fd = -1; - - free(handlers->data); - handlers->data = NULL; - - return 0; -} - -int akm8975_activate(struct smdk4x12_sensors_handlers *handlers) -{ - struct akm8975_data *data; - AK8975PRMS *akfs_params; - int rc; - - ALOGD("%s(%p)", __func__, handlers); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct akm8975_data *) handlers->data; - akfs_params = &data->akfs_params; - - // Read settings from a file - rc = AKFS_LoadParameters(akfs_params, AKFS_CONFIG_PATH); - if (rc != AKM_SUCCESS) { - ALOGE("%s: Unable to read AKFS HO parameters", __func__); - akfs_params->mfv_ho.u.x = 0.0f; - akfs_params->mfv_ho.u.y = 0.0f; - akfs_params->mfv_ho.u.z = 0.0f; - } else { - ALOGD("AKM8975 HO (Offset Adjustment) parameters read are: (%f, %f, %f)", - akfs_params->mfv_ho.u.x, akfs_params->mfv_ho.u.y, akfs_params->mfv_ho.u.z); - } - - // Initialize buffer - AKFS_InitBuffer(AKFS_HDATA_SIZE, akfs_params->mfv_hdata); - AKFS_InitBuffer(AKFS_HDATA_SIZE, akfs_params->mfv_hvbuf); - AKFS_InitBuffer(AKFS_ADATA_SIZE, akfs_params->mfv_adata); - AKFS_InitBuffer(AKFS_ADATA_SIZE, akfs_params->mfv_avbuf); - - // Initialize for AOC - AKFS_InitAOC(&akfs_params->m_aocv); - // Initialize magnetic status - akfs_params->mi_hstatus = SENSOR_STATUS_UNRELIABLE; - - handlers->activated = 1; - pthread_mutex_unlock(&data->mutex); - - return 0; -} - -int akm8975_deactivate(struct smdk4x12_sensors_handlers *handlers) -{ - struct akm8975_data *data; - AK8975PRMS *akfs_params; - int device_fd; - short mode; - int empty; - int rc; - int i; - - ALOGD("%s(%p)", __func__, handlers); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct akm8975_data *) handlers->data; - akfs_params = &data->akfs_params; - - device_fd = data->device_fd; - if (device_fd < 0) - return -1; - - empty = 1; - - if ((akfs_params->mfv_ho.u.x != 0.0f) || (akfs_params->mfv_ho.u.y != 0.0f) || - (akfs_params->mfv_ho.u.z != 0.0f)) { - empty = 0; - } - - if (!empty) { - // Write settings to a file - rc = AKFS_SaveParameters(akfs_params, AKFS_CONFIG_PATH); - if (rc != AKM_SUCCESS) { - ALOGE("%s: Unable to write AKFS HO parameters", __func__); - } else { - ALOGD("AKM8975 HO (Offset Adjustment) parameters written are: (%f, %f, %f)", - akfs_params->mfv_ho.u.x, akfs_params->mfv_ho.u.y, akfs_params->mfv_ho.u.z); - } - } - - mode = AK8975_MODE_POWER_DOWN; - rc = ioctl(device_fd, ECS_IOCTL_SET_MODE, &mode); - if (rc < 0) - ALOGE("%s: Unable to set akm8975 mode", __func__); - - handlers->activated = 0; - - return 0; -} - -int akm8975_set_delay(struct smdk4x12_sensors_handlers *handlers, int64_t delay) -{ - struct akm8975_data *data; - - ALOGD("%s(%p, %" PRId64 ")", __func__, handlers, delay); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct akm8975_data *) handlers->data; - - data->delay = delay; - - return 0; -} - -float akm8975_convert(int value) -{ - return (float) value / 1000.0f; -} - -int akm8975_get_data(struct smdk4x12_sensors_handlers *handlers, - struct sensors_event_t *event) -{ - struct akm8975_data *data; - struct input_event input_event; - int input_fd; - int rc; - -// ALOGD("%s(%p, %p)", __func__, handlers, event); - - if (handlers == NULL || handlers->data == NULL || event == NULL) - return -EINVAL; - - data = (struct akm8975_data *) handlers->data; - - input_fd = handlers->poll_fd; - if (input_fd < 0) - return -1; - - memset(event, 0, sizeof(struct sensors_event_t)); - event->version = sizeof(struct sensors_event_t); - event->sensor = handlers->handle; - event->type = handlers->handle; - - do { - rc = read(input_fd, &input_event, sizeof(input_event)); - if (rc < (int) sizeof(input_event)) - break; - - if (input_event.type == EV_REL) { - switch (input_event.code) { - case REL_X: - event->magnetic.x = akm8975_convert(input_event.value); - break; - case REL_Y: - event->magnetic.y = akm8975_convert(input_event.value); - break; - case REL_Z: - event->magnetic.z = akm8975_convert(input_event.value); - break; - case REL_MISC: - event->magnetic.status = input_event.value; - break; - default: - continue; - } - } else if (input_event.type == EV_SYN) { - if (input_event.code == SYN_REPORT) - event->timestamp = input_timestamp(&input_event); - } - } while (input_event.type != EV_SYN); - - return 0; -} - -struct smdk4x12_sensors_handlers akm8975 = { - .name = "AKM8975", - .handle = SENSOR_TYPE_MAGNETIC_FIELD, - .init = akm8975_init, - .deinit = akm8975_deinit, - .activate = akm8975_activate, - .deactivate = akm8975_deactivate, - .set_delay = akm8975_set_delay, - .get_data = akm8975_get_data, - .activated = 0, - .needed = 0, - .poll_fd = -1, - .data = NULL, -}; diff --git a/libsensors/akmdfs/AK8975Driver.c b/libsensors/akmdfs/AK8975Driver.c deleted file mode 100644 index 003c8d2..0000000 --- a/libsensors/akmdfs/AK8975Driver.c +++ /dev/null @@ -1,318 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#include -#include "AKFS_Common.h" -#include "AK8975Driver.h" - -#define MSENSOR_NAME "/dev/akm8975_dev" - -static int s_fdDev = -1; - -/*! - Open device driver. - This function opens both device drivers of magnetic sensor and acceleration - sensor. Additionally, some initial hardware settings are done, such as - measurement range, built-in filter function and etc. - @return If this function succeeds, the return value is #AKD_SUCCESS. - Otherwise the return value is #AKD_FAIL. - */ -int16_t AKD_InitDevice(void) -{ - if (s_fdDev < 0) { - /* Open magnetic sensor's device driver. */ - if ((s_fdDev = open(MSENSOR_NAME, O_RDWR)) < 0) { - AKMERROR_STR("open"); - return AKD_FAIL; - } - } - - return AKD_SUCCESS; -} - -/*! - Close device driver. - This function closes both device drivers of magnetic sensor and acceleration - sensor. - */ -void AKD_DeinitDevice(void) -{ - if (s_fdDev >= 0) { - close(s_fdDev); - s_fdDev = -1; - } -} - -/*! - Writes data to a register of the AK8975. When more than one byte of data is - specified, the data is written in contiguous locations starting at an address - specified in \a address. - @return If this function succeeds, the return value is #AKD_SUCCESS. Otherwise - the return value is #AKD_FAIL. - @param[in] address Specify the address of a register in which data is to be - written. - @param[in] data Specify data to write or a pointer to a data array containing - the data. When specifying more than one byte of data, specify the starting - address of the array. - @param[in] numberOfBytesToWrite Specify the number of bytes that make up the - data to write. When a pointer to an array is specified in data, this argument - equals the number of elements of the array. - */ -int16_t AKD_TxData( - const BYTE address, - const BYTE * data, - const uint16_t numberOfBytesToWrite) -{ - int i; - char buf[RWBUF_SIZE]; - - if (s_fdDev < 0) { - ALOGE("%s: Device file is not opened.", __FUNCTION__); - return AKD_FAIL; - } - if (numberOfBytesToWrite > (RWBUF_SIZE-2)) { - ALOGE("%s: Tx size is too large.", __FUNCTION__); - return AKD_FAIL; - } - - buf[0] = numberOfBytesToWrite + 1; - buf[1] = address; - - for (i = 0; i < numberOfBytesToWrite; i++) { - buf[i + 2] = data[i]; - } - if (ioctl(s_fdDev, ECS_IOCTL_WRITE, buf) < 0) { - AKMERROR_STR("ioctl"); - return AKD_FAIL; - } else { - -#if ENABLE_AKMDEBUG - AKMDATA(AKMDATA_DRV, "addr(HEX)=%02x data(HEX)=", address); - for (i = 0; i < numberOfBytesToWrite; i++) { - AKMDATA(AKMDATA_DRV, " %02x", data[i]); - } - AKMDATA(AKMDATA_DRV, "\n"); -#endif - return AKD_SUCCESS; - } -} - -/*! - Acquires data from a register or the EEPROM of the AK8975. - @return If this function succeeds, the return value is #AKD_SUCCESS. Otherwise - the return value is #AKD_FAIL. - @param[in] address Specify the address of a register from which data is to be - read. - @param[out] data Specify a pointer to a data array which the read data are - stored. - @param[in] numberOfBytesToRead Specify the number of bytes that make up the - data to read. When a pointer to an array is specified in data, this argument - equals the number of elements of the array. - */ -int16_t AKD_RxData( - const BYTE address, - BYTE * data, - const uint16_t numberOfBytesToRead) -{ - int i; - char buf[RWBUF_SIZE]; - - memset(data, 0, numberOfBytesToRead); - - if (s_fdDev < 0) { - ALOGE("%s: Device file is not opened.", __FUNCTION__); - return AKD_FAIL; - } - if (numberOfBytesToRead > (RWBUF_SIZE-1)) { - ALOGE("%s: Rx size is too large.", __FUNCTION__); - return AKD_FAIL; - } - - buf[0] = numberOfBytesToRead; - buf[1] = address; - - if (ioctl(s_fdDev, ECS_IOCTL_READ, buf) < 0) { - AKMERROR_STR("ioctl"); - return AKD_FAIL; - } else { - for (i = 0; i < numberOfBytesToRead; i++) { - data[i] = buf[i + 1]; - } -#if ENABLE_AKMDEBUG - AKMDATA(AKMDATA_DRV, "addr(HEX)=%02x len=%d data(HEX)=", - address, numberOfBytesToRead); - for (i = 0; i < numberOfBytesToRead; i++) { - AKMDATA(AKMDATA_DRV, " %02x", data[i]); - } - AKMDATA(AKMDATA_DRV, "\n"); -#endif - return AKD_SUCCESS; - } -} - -/*! - Acquire magnetic data from AK8975. If measurement is not done, this function - waits until measurement completion. - @return If this function succeeds, the return value is #AKD_SUCCESS. Otherwise - the return value is #AKD_FAIL. - @param[out] data A magnetic data array. The size should be larger than #SENSOR_DATA_SIZE. - */ -int16_t AKD_GetMagneticData(BYTE data[SENSOR_DATA_SIZE]) -{ - memset(data, 0, SENSOR_DATA_SIZE); - - if (s_fdDev < 0) { - ALOGE("%s: Device file is not opened.", __FUNCTION__); - return AKD_FAIL; - } - - if (ioctl(s_fdDev, ECS_IOCTL_GETDATA, data) < 0) { - AKMERROR_STR("ioctl"); - return AKD_FAIL; - } - - AKMDATA(AKMDATA_DRV, - "bdata(HEX)= %02x %02x %02x %02x %02x %02x %02x %02x\n", - data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]); - - return AKD_SUCCESS; -} - -/*! - Set calculated data to device driver. - @param[in] buf The order of input data depends on driver's specification. - */ -void AKD_SetYPR(const int buf[YPR_DATA_SIZE]) -{ - if (s_fdDev < 0) { - ALOGE("%s: Device file is not opened.", __FUNCTION__); - } else { - if (ioctl(s_fdDev, ECS_IOCTL_SET_YPR, buf) < 0) { - AKMERROR_STR("ioctl"); - } - } -} - -/*! - */ -int AKD_GetOpenStatus(int* status) -{ - if (s_fdDev < 0) { - ALOGE("%s: Device file is not opened.", __FUNCTION__); - return AKD_FAIL; - } - if (ioctl(s_fdDev, ECS_IOCTL_GET_OPEN_STATUS, status) < 0) { - AKMERROR_STR("ioctl"); - return AKD_FAIL; - } - return AKD_SUCCESS; -} - -/*! - */ -int AKD_GetCloseStatus(int* status) -{ - if (s_fdDev < 0) { - ALOGE("%s: Device file is not opened.", __FUNCTION__); - return AKD_FAIL; - } - if (ioctl(s_fdDev, ECS_IOCTL_GET_CLOSE_STATUS, status) < 0) { - AKMERROR_STR("ioctl"); - return AKD_FAIL; - } - return AKD_SUCCESS; -} - -/*! - Set AK8975 to the specific mode. - @return If this function succeeds, the return value is #AKD_SUCCESS. Otherwise - the return value is #AKD_FAIL. - @param[in] mode This value should be one of the AK8975_Mode which is defined in - akm8975.h file. - */ -int16_t AKD_SetMode(const BYTE mode) -{ - if (s_fdDev < 0) { - ALOGE("%s: Device file is not opened.", __FUNCTION__); - return AKD_FAIL; - } - - if (ioctl(s_fdDev, ECS_IOCTL_SET_MODE, &mode) < 0) { - AKMERROR_STR("ioctl"); - return AKD_FAIL; - } - - return AKD_SUCCESS; -} - -/*! - Acquire delay - @return If this function succeeds, the return value is #AKD_SUCCESS. Otherwise - the return value is #AKD_FAIL. - @param[out] delay A delay in nanosecond. - */ -int16_t AKD_GetDelay(int64_t delay[AKM_NUM_SENSORS]) -{ - if (s_fdDev < 0) { - ALOGE("%s: Device file is not opened.\n", __FUNCTION__); - return AKD_FAIL; - } - if (ioctl(s_fdDev, ECS_IOCTL_GET_DELAY, delay) < 0) { - AKMERROR_STR("ioctl"); - return AKD_FAIL; - } - return AKD_SUCCESS; -} - -/*! - Get layout information from device driver, i.e. platform data. - */ -int16_t AKD_GetLayout(int16_t* layout) -{ - char tmp; - - if (s_fdDev < 0) { - ALOGE("%s: Device file is not opened.", __FUNCTION__); - return AKD_FAIL; - } - - if (ioctl(s_fdDev, ECS_IOCTL_GET_LAYOUT, &tmp) < 0) { - AKMERROR_STR("ioctl"); - return AKD_FAIL; - } - - *layout = tmp; - return AKD_SUCCESS; -} - -/* Get acceleration data. */ -int16_t AKD_GetAccelerationData(int16_t data[3]) -{ - if (s_fdDev < 0) { - ALOGE("%s: Device file is not opened.", __FUNCTION__); - return AKD_FAIL; - } - if (ioctl(s_fdDev, ECS_IOCTL_GET_ACCEL, data) < 0) { - AKMERROR_STR("ioctl"); - return AKD_FAIL; - } - - AKMDATA(AKMDATA_DRV, "%s: acc=%d, %d, %d\n", - __FUNCTION__, data[0], data[1], data[2]); - - return AKD_SUCCESS; -} diff --git a/libsensors/akmdfs/AK8975Driver.h b/libsensors/akmdfs/AK8975Driver.h deleted file mode 100644 index 731210d..0000000 --- a/libsensors/akmdfs/AK8975Driver.h +++ /dev/null @@ -1,102 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifndef AKMD_INC_AK8975DRIVER_H -#define AKMD_INC_AK8975DRIVER_H - -#include /* Device driver */ -#include /* int8_t, int16_t etc. */ - -/*** Constant definition ******************************************************/ -#define AKD_TRUE 1 /*!< Represents true */ -#define AKD_FALSE 0 /*!< Represents false */ -#define AKD_SUCCESS 1 /*!< Represents success.*/ -#define AKD_FAIL 0 /*!< Represents fail. */ -#define AKD_ERROR -1 /*!< Represents error. */ - -/*! 0:Don't Output data, 1:Output data */ -#define AKD_DBG_DATA 0 -/*! Typical interval in ns */ -#define AK8975_MEASUREMENT_TIME_NS ((AK8975_MEASUREMENT_TIME_US) * 1000) -/*! 720 LSG = 1G = 9.8 m/s2 */ -#define LSG 720 - - -/*** Type declaration *********************************************************/ -typedef unsigned char BYTE; - -/*! - Open device driver. - This function opens device driver of acceleration sensor. - @return If this function succeeds, the return value is #AKD_SUCCESS. Otherwise - the return value is #AKD_FAIL. - */ -typedef int16_t(*ACCFNC_INITDEVICE)(void); - -/*! - Close device driver. - This function closes device drivers of acceleration sensor. - */ -typedef void(*ACCFNC_DEINITDEVICE)(void); - -/*! - Acquire acceleration data from acceleration sensor and convert it to Android - coordinate system. - @return If this function succeeds, the return value is #AKD_SUCCESS. Otherwise - the return value is #AKD_FAIL. - @param[out] data A acceleration data array. The coordinate system of the - acquired data follows the definition of Android. Unit is SmartCompass. - */ -typedef int16_t(*ACCFNC_GETACCDATA)(short data[3]); - - -/*** Global variables *********************************************************/ - -/*** Prototype of Function ***************************************************/ - -int16_t AKD_InitDevice(void); - -void AKD_DeinitDevice(void); - -int16_t AKD_TxData( - const BYTE address, - const BYTE* data, - const uint16_t numberOfBytesToWrite); - -int16_t AKD_RxData( - const BYTE address, - BYTE* data, - const uint16_t numberOfBytesToRead); - -int16_t AKD_GetMagneticData(BYTE data[SENSOR_DATA_SIZE]); - -void AKD_SetYPR(const int buf[YPR_DATA_SIZE]); - -int AKD_GetOpenStatus(int* status); - -int AKD_GetCloseStatus(int* status); - -int16_t AKD_SetMode(const BYTE mode); - -int16_t AKD_GetDelay(int64_t delay[AKM_NUM_SENSORS]); - -int16_t AKD_GetLayout(int16_t* layout); - -int16_t AKD_GetAccelerationData(int16_t data[3]); - -#endif /* AKMD_INC_AK8975DRIVER_H */ - diff --git a/libsensors/akmdfs/AKFS_APIs.c b/libsensors/akmdfs/AKFS_APIs.c deleted file mode 100644 index ace9bc1..0000000 --- a/libsensors/akmdfs/AKFS_APIs.c +++ /dev/null @@ -1,389 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#include "AKFS_Common.h" -#include "AKFS_Disp.h" -#include "AKFS_FileIO.h" -#include "AKFS_APIs.h" - -#ifdef WIN32 -#include "AK8975_LinuxDriver.h" -#endif - -static AK8975PRMS g_prms; - -/*! - Initialize library. At first, 0 is set to all parameters. After that, some - parameters, which should not be 0, are set to specific value. Some of initial - values can be customized by editing the file \c "AKFS_CSpec.h". - @return The return value is #AKM_SUCCESS. - @param[in] hpat Specify a layout pattern number. The number is determined - according to the mount orientation of the magnetometer. - @param[in] regs[3] Specify the ASA values which are read out from - fuse ROM. regs[0] is ASAX, regs[1] is ASAY, regs[2] is ASAZ. - */ -int16 AKFS_Init( - const AKFS_PATNO hpat, - const uint8 regs[] -) -{ - AKMDATA(AKMDATA_DUMP, "%s: hpat=%d, r[0]=0x%02X, r[1]=0x%02X, r[2]=0x%02X\n", - __FUNCTION__, hpat, regs[0], regs[1], regs[2]); - - /* Set 0 to the AK8975 structure. */ - memset(&g_prms, 0, sizeof(AK8975PRMS)); - - /* Sensitivity */ - g_prms.mfv_hs.u.x = AK8975_HSENSE_DEFAULT; - g_prms.mfv_hs.u.y = AK8975_HSENSE_DEFAULT; - g_prms.mfv_hs.u.z = AK8975_HSENSE_DEFAULT; - g_prms.mfv_as.u.x = AK8975_ASENSE_DEFAULT; - g_prms.mfv_as.u.y = AK8975_ASENSE_DEFAULT; - g_prms.mfv_as.u.z = AK8975_ASENSE_DEFAULT; - - /* Initialize variables that initial value is not 0. */ - g_prms.mi_hnaveV = CSPEC_HNAVE_V; - g_prms.mi_hnaveD = CSPEC_HNAVE_D; - g_prms.mi_anaveV = CSPEC_ANAVE_V; - g_prms.mi_anaveD = CSPEC_ANAVE_D; - - /* Copy ASA values */ - g_prms.mi_asa.u.x = regs[0]; - g_prms.mi_asa.u.y = regs[1]; - g_prms.mi_asa.u.z = regs[2]; - - /* Copy layout pattern */ - g_prms.m_hpat = hpat; - - return AKM_SUCCESS; -} - -/*! - Release resources. This function is for future expansion. - @return The return value is #AKM_SUCCESS. - */ -int16 AKFS_Release(void) -{ - return AKM_SUCCESS; -} - -/* - This function is called just before a measurement sequence starts. - This function reads parameters from file, then initializes algorithm - parameters. - @return The return value is #AKM_SUCCESS. - @param[in] path Specify a path to the settings file. - */ -int16 AKFS_Start( - const char* path -) -{ - AKMDATA(AKMDATA_DUMP, "%s: path=%s\n", __FUNCTION__, path); - - /* Read setting files from a file */ - if (AKFS_LoadParameters(&g_prms, path) != AKM_SUCCESS) { - AKMERROR_STR("AKFS_Load"); - } - - /* Initialize buffer */ - AKFS_InitBuffer(AKFS_HDATA_SIZE, g_prms.mfv_hdata); - AKFS_InitBuffer(AKFS_HDATA_SIZE, g_prms.mfv_hvbuf); - AKFS_InitBuffer(AKFS_ADATA_SIZE, g_prms.mfv_adata); - AKFS_InitBuffer(AKFS_ADATA_SIZE, g_prms.mfv_avbuf); - - /* Initialize for AOC */ - AKFS_InitAOC(&g_prms.m_aocv); - /* Initialize magnetic status */ - g_prms.mi_hstatus = 0; - - return AKM_SUCCESS; -} - -/*! - This function is called when a measurement sequence is done. - This fucntion writes parameters to file. - @return The return value is #AKM_SUCCESS. - @param[in] path Specify a path to the settings file. - */ -int16 AKFS_Stop( - const char* path -) -{ - AKMDATA(AKMDATA_DUMP, "%s: path=%s\n", __FUNCTION__, path); - - /* Write setting files to a file */ - if (AKFS_SaveParameters(&g_prms, path) != AKM_SUCCESS) { - AKMERROR_STR("AKFS_Save"); - } - - return AKM_SUCCESS; -} - -/*! - This function is called when new magnetometer data is available. The output - vector format and coordination system follow the Android definition. - @return The return value is #AKM_SUCCESS. - Otherwise the return value is #AKM_FAIL. - @param[in] mag A set of measurement data from magnetometer. X axis value - should be in mag[0], Y axis value should be in mag[1], Z axis value should be - in mag[2]. - @param[in] status A status of magnetometer. This status indicates the result - of measurement data, i.e. overflow, success or fail, etc. - @param[out] vx X axis value of magnetic field vector. - @param[out] vy Y axis value of magnetic field vector. - @param[out] vz Z axis value of magnetic field vector. - @param[out] accuracy Accuracy of magnetic field vector. - */ -int16 AKFS_Get_MAGNETIC_FIELD( - const int16 mag[3], - const int16 status, - AKFLOAT* vx, - AKFLOAT* vy, - AKFLOAT* vz, - int16* accuracy -) -{ - int16 akret; - int16 aocret; - AKFLOAT radius; - - AKMDATA(AKMDATA_DUMP, "%s: m[0]=%d, m[1]=%d, m[2]=%d, st=%d\n", - __FUNCTION__, mag[0], mag[1], mag[2], status); - - /* Decomposition */ - /* Sensitivity adjustment, i.e. multiply ASA, is done in this function. */ - akret = AKFS_DecompAK8975( - mag, - status, - &g_prms.mi_asa, - AKFS_HDATA_SIZE, - g_prms.mfv_hdata - ); - if(akret == AKFS_ERROR) { - AKMERROR; - return AKM_FAIL; - } - - /* Adjust coordination */ - akret = AKFS_Rotate( - g_prms.m_hpat, - &g_prms.mfv_hdata[0] - ); - if (akret == AKFS_ERROR) { - AKMERROR; - return AKM_FAIL; - } - - /* AOC for magnetometer */ - /* Offset estimation is done in this function */ - aocret = AKFS_AOC( - &g_prms.m_aocv, - g_prms.mfv_hdata, - &g_prms.mfv_ho - ); - - /* Subtract offset */ - /* Then, a magnetic vector, the unit is uT, is stored in mfv_hvbuf. */ - akret = AKFS_VbNorm( - AKFS_HDATA_SIZE, - g_prms.mfv_hdata, - 1, - &g_prms.mfv_ho, - &g_prms.mfv_hs, - AK8975_HSENSE_TARGET, - AKFS_HDATA_SIZE, - g_prms.mfv_hvbuf - ); - if(akret == AKFS_ERROR) { - AKMERROR; - return AKM_FAIL; - } - - /* Averaging */ - akret = AKFS_VbAve( - AKFS_HDATA_SIZE, - g_prms.mfv_hvbuf, - CSPEC_HNAVE_V, - &g_prms.mfv_hvec - ); - if (akret == AKFS_ERROR) { - AKMERROR; - return AKM_FAIL; - } - - /* Check the size of magnetic vector */ - radius = AKFS_SQRT( - (g_prms.mfv_hvec.u.x * g_prms.mfv_hvec.u.x) + - (g_prms.mfv_hvec.u.y * g_prms.mfv_hvec.u.y) + - (g_prms.mfv_hvec.u.z * g_prms.mfv_hvec.u.z)); - - if (radius > AKFS_GEOMAG_MAX) { - g_prms.mi_hstatus = 0; - } else { - if (aocret) { - g_prms.mi_hstatus = 3; - } - } - - *vx = g_prms.mfv_hvec.u.x; - *vy = g_prms.mfv_hvec.u.y; - *vz = g_prms.mfv_hvec.u.z; - *accuracy = g_prms.mi_hstatus; - - /* Debug output */ - AKMDATA(AKMDATA_MAG, "Mag(%d):%8.2f, %8.2f, %8.2f\n", - *accuracy, *vx, *vy, *vz); - - return AKM_SUCCESS; -} - -/*! - This function is called when new accelerometer data is available. The output - vector format and coordination system follow the Android definition. - @return The return value is #AKM_SUCCESS when function succeeds. Otherwise - the return value is #AKM_FAIL. - @param[in] acc A set of measurement data from accelerometer. X axis value - should be in acc[0], Y axis value should be in acc[1], Z axis value should be - in acc[2]. - @param[in] status A status of accelerometer. This status indicates the result - of acceleration data, i.e. overflow, success or fail, etc. - @param[out] vx X axis value of acceleration vector. - @param[out] vy Y axis value of acceleration vector. - @param[out] vz Z axis value of acceleration vector. - @param[out] accuracy Accuracy of acceleration vector. - This value is always 3. - */ -int16 AKFS_Get_ACCELEROMETER( - const int16 acc[3], - const int16 status, - AKFLOAT* vx, - AKFLOAT* vy, - AKFLOAT* vz, - int16* accuracy -) -{ - int16 akret; - - AKMDATA(AKMDATA_DUMP, "%s: a[0]=%d, a[1]=%d, a[2]=%d, st=%d\n", - __FUNCTION__, acc[0], acc[1], acc[2], status); - - /* Save data to buffer */ - AKFS_BufShift( - AKFS_ADATA_SIZE, - 1, - g_prms.mfv_adata - ); - g_prms.mfv_adata[0].u.x = acc[0]; - g_prms.mfv_adata[0].u.y = acc[1]; - g_prms.mfv_adata[0].u.z = acc[2]; - - /* Subtract offset, adjust sensitivity */ - /* As a result, a unit of acceleration data in mfv_avbuf is '1G = 9.8' */ - akret = AKFS_VbNorm( - AKFS_ADATA_SIZE, - g_prms.mfv_adata, - 1, - &g_prms.mfv_ao, - &g_prms.mfv_as, - AK8975_ASENSE_TARGET, - AKFS_ADATA_SIZE, - g_prms.mfv_avbuf - ); - if(akret == AKFS_ERROR) { - AKMERROR; - return AKM_FAIL; - } - - /* Averaging */ - akret = AKFS_VbAve( - AKFS_ADATA_SIZE, - g_prms.mfv_avbuf, - CSPEC_ANAVE_V, - &g_prms.mfv_avec - ); - if (akret == AKFS_ERROR) { - AKMERROR; - return AKM_FAIL; - } - - /* Adjust coordination */ - /* It is not needed. Because, the data from AK8975 driver is already - follows Android coordinate system. */ - - *vx = g_prms.mfv_avec.u.x; - *vy = g_prms.mfv_avec.u.y; - *vz = g_prms.mfv_avec.u.z; - *accuracy = 3; - - /* Debug output */ - AKMDATA(AKMDATA_ACC, "Acc(%d):%8.2f, %8.2f, %8.2f\n", - *accuracy, *vx, *vy, *vz); - - return AKM_SUCCESS; -} - -/*! - Get orientation sensor's elements. The vector format and coordination system - follow the Android definition. Before this function is called, magnetic - field vector and acceleration vector should be stored in the buffer by - calling #AKFS_Get_MAGNETIC_FIELD and #AKFS_Get_ACCELEROMETER. - @return The return value is #AKM_SUCCESS when function succeeds. Otherwise - the return value is #AKM_FAIL. - @param[out] azimuth Azimuthal angle in degree. - @param[out] pitch Pitch angle in degree. - @param[out] roll Roll angle in degree. - @param[out] accuracy Accuracy of orientation sensor. - */ -int16 AKFS_Get_ORIENTATION( - AKFLOAT* azimuth, - AKFLOAT* pitch, - AKFLOAT* roll, - int16* accuracy -) -{ - int16 akret; - - /* Azimuth calculation */ - /* Coordination system follows the Android coordination. */ - akret = AKFS_Direction( - AKFS_HDATA_SIZE, - g_prms.mfv_hvbuf, - CSPEC_HNAVE_D, - AKFS_ADATA_SIZE, - g_prms.mfv_avbuf, - CSPEC_ANAVE_D, - &g_prms.mf_azimuth, - &g_prms.mf_pitch, - &g_prms.mf_roll - ); - - if(akret == AKFS_ERROR) { - AKMERROR; - return AKM_FAIL; - } - *azimuth = g_prms.mf_azimuth; - *pitch = g_prms.mf_pitch; - *roll = g_prms.mf_roll; - *accuracy = g_prms.mi_hstatus; - - /* Debug output */ - AKMDATA(AKMDATA_ORI, "Ori(%d):%8.2f, %8.2f, %8.2f\n", - *accuracy, *azimuth, *pitch, *roll); - - return AKM_SUCCESS; -} - diff --git a/libsensors/akmdfs/AKFS_APIs.h b/libsensors/akmdfs/AKFS_APIs.h deleted file mode 100644 index e4d1e48..0000000 --- a/libsensors/akmdfs/AKFS_APIs.h +++ /dev/null @@ -1,69 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifndef AKFS_INC_APIS_H -#define AKFS_INC_APIS_H - -/* Include files for AK8975 library. */ -#include "AKFS_Compass.h" - -/*** Constant definition ******************************************************/ -#define AKFS_GEOMAG_MAX 70 - -/*** Type declaration *********************************************************/ - -/*** Global variables *********************************************************/ - -/*** Prototype of function ****************************************************/ -int16 AKFS_Init( - const AKFS_PATNO hpat, - const uint8 regs[] -); - -int16 AKFS_Release(void); - -int16 AKFS_Start(const char* path); - -int16 AKFS_Stop(const char* path); - -int16 AKFS_Get_MAGNETIC_FIELD( - const int16 mag[3], - const int16 status, - AKFLOAT* vx, - AKFLOAT* vy, - AKFLOAT* vz, - int16* accuracy -); - -int16 AKFS_Get_ACCELEROMETER( - const int16 acc[3], - const int16 status, - AKFLOAT* vx, - AKFLOAT* vy, - AKFLOAT* vz, - int16* accuracy -); - -int16 AKFS_Get_ORIENTATION( - AKFLOAT* azimuth, - AKFLOAT* pitch, - AKFLOAT* roll, - int16* accuracy -); - -#endif - diff --git a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_AK8975.c b/libsensors/akmdfs/AKFS_APIs_8975/AKFS_AK8975.c deleted file mode 100644 index 7bac9a1..0000000 --- a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_AK8975.c +++ /dev/null @@ -1,44 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#include "AKFS_AK8975.h" -#include "AKFS_Device.h" - -/*! - */ -int16 AKFS_DecompAK8975( - const int16 mag[3], - const int16 status, - const uint8vec* asa, - const int16 nhdata, - AKFVEC hdata[] -) -{ - /* put st1 and st2 value */ - if (AK8975_ST_ERROR(status)) { - return AKFS_ERROR; - } - - /* magnetic */ - AKFS_BufShift(nhdata, 1, hdata); - hdata[0].u.x = mag[0] * (((asa->u.x)/256.0f) + 0.5f); - hdata[0].u.y = mag[1] * (((asa->u.y)/256.0f) + 0.5f); - hdata[0].u.z = mag[2] * (((asa->u.z)/256.0f) + 0.5f); - - return AKFS_SUCCESS; -} - diff --git a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_AK8975.h b/libsensors/akmdfs/AKFS_APIs_8975/AKFS_AK8975.h deleted file mode 100644 index 25459e3..0000000 --- a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_AK8975.h +++ /dev/null @@ -1,50 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifndef AKFS_INC_AK8975_H -#define AKFS_INC_AK8975_H - -#include "AKFS_Device.h" - -/***** Constant definition ****************************************************/ -#define AK8975_BDATA_SIZE 8 - -#define AK8975_HSENSE_DEFAULT 1 -#define AK8975_HSENSE_TARGET 0.3f -#define AK8975_ASENSE_DEFAULT 720 -#define AK8975_ASENSE_TARGET 9.80665f - -#define AK8975_HDATA_CONVERTER(hi, low, asa) \ - (AKFLOAT)((int16)((((uint16)(hi))<<8)+(uint16)(low))*(((asa)/256.0f) + 0.5f)) - -#define AK8975_ST_ERROR(st) (((st)&0x09) != 0x01) - -/***** Type declaration *******************************************************/ - -/***** Prototype of function **************************************************/ -AKLIB_C_API_START -int16 AKFS_DecompAK8975( - const int16 mag[3], - const int16 status, - const uint8vec* asa, - const int16 nhdata, - AKFVEC hdata[] -); -AKLIB_C_API_END - -#endif - diff --git a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_AOC.c b/libsensors/akmdfs/AKFS_APIs_8975/AKFS_AOC.c deleted file mode 100644 index 62b2361..0000000 --- a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_AOC.c +++ /dev/null @@ -1,333 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#include "AKFS_AOC.h" -#include "AKFS_Math.h" - -/* - * CalcR - */ -static AKFLOAT CalcR( - const AKFVEC* x, - const AKFVEC* y -){ - int16 i; - AKFLOAT r; - - r = 0.0; - for(i = 0; i < 3; i++){ - r += (x->v[i]-y->v[i]) * (x->v[i]-y->v[i]); - } - r = sqrt(r); - - return r; -} - -/* - * From4Points2Sphere() - */ -static int16 From4Points2Sphere( - const AKFVEC points[], /*! (i/o) : input vectors */ - AKFVEC* center, /*! (o) : center of sphere */ - AKFLOAT* r /*! (i) : add/subtract value */ -){ - AKFLOAT dif[3][3]; - AKFLOAT r2[3]; - - AKFLOAT A; - AKFLOAT B; - AKFLOAT C; - AKFLOAT D; - AKFLOAT E; - AKFLOAT F; - AKFLOAT G; - - AKFLOAT OU; - AKFLOAT OD; - - int16 i, j; - - for(i = 0; i < 3; i++){ - r2[i] = 0.0; - for(j = 0; j < 3; j++){ - dif[i][j] = points[i].v[j] - points[3].v[j]; - r2[i] += (points[i].v[j]*points[i].v[j] - - points[3].v[j]*points[3].v[j]); - } - r2[i] *= 0.5; - } - - A = dif[0][0]*dif[2][2] - dif[0][2]*dif[2][0]; - B = dif[0][1]*dif[2][0] - dif[0][0]*dif[2][1]; - C = dif[0][0]*dif[2][1] - dif[0][1]*dif[2][0]; - D = dif[0][0]*r2[2] - dif[2][0]*r2[0]; - E = dif[0][0]*dif[1][1] - dif[0][1]*dif[1][0]; - F = dif[1][0]*dif[0][2] - dif[0][0]*dif[1][2]; - G = dif[0][0]*r2[1] - dif[1][0]*r2[0]; - - OU = D*E + B*G; - OD = C*F + A*E; - - if(fabs(OD) < AKFS_EPSILON){ - return -1; - } - - center->v[2] = OU / OD; - - OU = F*center->v[2] + G; - OD = E; - - if(fabs(OD) < AKFS_EPSILON){ - return -1; - } - - center->v[1] = OU / OD; - - OU = r2[0] - dif[0][1]*center->v[1] - dif[0][2]*center->v[2]; - OD = dif[0][0]; - - if(fabs(OD) < AKFS_EPSILON){ - return -1; - } - - center->v[0] = OU / OD; - - *r = CalcR(&points[0], center); - - return 0; - -} - -/* - * MeanVar - */ -static void MeanVar( - const AKFVEC v[], /*!< (i) : input vectors */ - const int16 n, /*!< (i) : number of vectors */ - AKFVEC* mean, /*!< (o) : (max+min)/2 */ - AKFVEC* var /*!< (o) : variation in vectors */ -){ - int16 i; - int16 j; - AKFVEC max; - AKFVEC min; - - for(j = 0; j < 3; j++){ - min.v[j] = v[0].v[j]; - max.v[j] = v[0].v[j]; - for(i = 1; i < n; i++){ - if(v[i].v[j] < min.v[j]){ - min.v[j] = v[i].v[j]; - } - if(v[i].v[j] > max.v[j]){ - max.v[j] = v[i].v[j]; - } - } - mean->v[j] = (max.v[j] + min.v[j]) / 2.0; /*mean */ - var->v[j] = max.v[j] - min.v[j]; /*var */ - } -} - -/* - * Get4points - */ -static void Get4points( - const AKFVEC v[], /*!< (i) : input vectors */ - const int16 n, /*!< (i) : number of vectors */ - AKFVEC out[] /*!< (o) : */ -){ - int16 i, j; - AKFLOAT temp; - AKFLOAT d; - - AKFVEC dv[AKFS_HBUF_SIZE]; - AKFVEC cross; - AKFVEC tempv; - - /* out 0 */ - out[0] = v[0]; - - /* out 1 */ - d = 0.0; - for(i = 1; i < n; i++){ - temp = CalcR(&v[i], &out[0]); - if(d < temp){ - d = temp; - out[1] = v[i]; - } - } - - /* out 2 */ - d = 0.0; - for(j = 0; j < 3; j++){ - dv[0].v[j] = out[1].v[j] - out[0].v[j]; - } - for(i = 1; i < n; i++){ - for(j = 0; j < 3; j++){ - dv[i].v[j] = v[i].v[j] - out[0].v[j]; - } - tempv.v[0] = dv[0].v[1]*dv[i].v[2] - dv[0].v[2]*dv[i].v[1]; - tempv.v[1] = dv[0].v[2]*dv[i].v[0] - dv[0].v[0]*dv[i].v[2]; - tempv.v[2] = dv[0].v[0]*dv[i].v[1] - dv[0].v[1]*dv[i].v[0]; - temp = tempv.u.x * tempv.u.x - + tempv.u.y * tempv.u.y - + tempv.u.z * tempv.u.z; - if(d < temp){ - d = temp; - out[2] = v[i]; - cross = tempv; - } - } - - /* out 3 */ - d = 0.0; - for(i = 1; i < n; i++){ - temp = dv[i].u.x * cross.u.x - + dv[i].u.y * cross.u.y - + dv[i].u.z * cross.u.z; - temp = fabs(temp); - if(d < temp){ - d = temp; - out[3] = v[i]; - } - } -} - -/* - * CheckInitFvec - */ -static int16 CheckInitFvec( - const AKFVEC *v /*!< [in] vector */ -){ - int16 i; - - for(i = 0; i < 3; i++){ - if(AKFS_FMAX <= v->v[i]){ - return 1; /* initvalue */ - } - } - - return 0; /* not initvalue */ -} - -/* - * AKFS_AOC - */ -int16 AKFS_AOC( /*!< (o) : calibration success(1), failure(0) */ - AKFS_AOC_VAR* haocv, /*!< (i/o) : a set of variables */ - const AKFVEC* hdata, /*!< (i) : vectors of data */ - AKFVEC* ho /*!< (i/o) : offset */ -){ - int16 i, j; - int16 num; - AKFLOAT tempf; - AKFVEC tempho; - - AKFVEC fourpoints[4]; - - AKFVEC var; - AKFVEC mean; - - /* buffer new data */ - for(i = 1; i < AKFS_HBUF_SIZE; i++){ - haocv->hbuf[AKFS_HBUF_SIZE-i] = haocv->hbuf[AKFS_HBUF_SIZE-i-1]; - } - haocv->hbuf[0] = *hdata; - - /* Check Init */ - num = 0; - for(i = AKFS_HBUF_SIZE; 3 < i; i--){ - if(CheckInitFvec(&haocv->hbuf[i-1]) == 0){ - num = i; - break; - } - } - if(num < 4){ - return AKFS_ERROR; - } - - /* get 4 points */ - Get4points(haocv->hbuf, num, fourpoints); - - /* estimate offset */ - if(0 != From4Points2Sphere(fourpoints, &tempho, &haocv->hraoc)){ - return AKFS_ERROR; - } - - /* check distance */ - for(i = 0; i < 4; i++){ - for(j = (i+1); j < 4; j++){ - tempf = CalcR(&fourpoints[i], &fourpoints[j]); - if((tempf < haocv->hraoc)||(tempf < AKFS_HR_TH)){ - return AKFS_ERROR; - } - } - } - - /* update offset buffer */ - for(i = 1; i < AKFS_HOBUF_SIZE; i++){ - haocv->hobuf[AKFS_HOBUF_SIZE-i] = haocv->hobuf[AKFS_HOBUF_SIZE-i-1]; - } - haocv->hobuf[0] = tempho; - - /* clear hbuf */ - for(i = (AKFS_HBUF_SIZE>>1); i < AKFS_HBUF_SIZE; i++) { - for(j = 0; j < 3; j++) { - haocv->hbuf[i].v[j]= AKFS_FMAX; - } - } - - /* Check Init */ - if(CheckInitFvec(&haocv->hobuf[AKFS_HOBUF_SIZE-1]) == 1){ - return AKFS_ERROR; - } - - /* Check ovar */ - tempf = haocv->hraoc * AKFS_HO_TH; - MeanVar(haocv->hobuf, AKFS_HOBUF_SIZE, &mean, &var); - if ((var.u.x >= tempf) || (var.u.y >= tempf) || (var.u.z >= tempf)){ - return AKFS_ERROR; - } - - *ho = mean; - - return AKFS_SUCCESS; -} - -/* - * AKFS_InitAOC - */ -void AKFS_InitAOC( - AKFS_AOC_VAR* haocv -){ - int16 i, j; - - /* Initialize buffer */ - for(i = 0; i < AKFS_HBUF_SIZE; i++) { - for(j = 0; j < 3; j++) { - haocv->hbuf[i].v[j]= AKFS_FMAX; - } - } - for(i = 0; i < AKFS_HOBUF_SIZE; i++) { - for(j = 0; j < 3; j++) { - haocv->hobuf[i].v[j]= AKFS_FMAX; - } - } - - haocv->hraoc = 0.0; -} - diff --git a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_AOC.h b/libsensors/akmdfs/AKFS_APIs_8975/AKFS_AOC.h deleted file mode 100644 index ffaaa88..0000000 --- a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_AOC.h +++ /dev/null @@ -1,53 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifndef AKFS_INC_AOC_H -#define AKFS_INC_AOC_H - -#include "AKFS_Device.h" - -/***** Constant definition ****************************************************/ -#define AKFS_HBUF_SIZE 20 -#define AKFS_HOBUF_SIZE 4 -#define AKFS_HR_TH 10 -#define AKFS_HO_TH 0.15 - -/***** Macro definition *******************************************************/ - -/***** Type declaration *******************************************************/ -typedef struct _AKFS_AOC_VAR{ - AKFVEC hbuf[AKFS_HBUF_SIZE]; - AKFVEC hobuf[AKFS_HOBUF_SIZE]; - AKFLOAT hraoc; -} AKFS_AOC_VAR; - -/***** Prototype of function **************************************************/ -AKLIB_C_API_START -int16 AKFS_AOC( - AKFS_AOC_VAR* haocv, - const AKFVEC* hdata, - AKFVEC* ho -); - -void AKFS_InitAOC( - AKFS_AOC_VAR* haocv -); - -AKLIB_C_API_END - -#endif - diff --git a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_Configure.h b/libsensors/akmdfs/AKFS_APIs_8975/AKFS_Configure.h deleted file mode 100644 index 1f80f48..0000000 --- a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_Configure.h +++ /dev/null @@ -1,37 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifndef AKFS_INC_CONFIG_H -#define AKFS_INC_CONFIG_H - -/***** Language configuration *************************************************/ -#if defined(__cplusplus) -#define AKLIB_C_API_START extern "C" { -#define AKLIB_C_API_END } -#else -#define AKLIB_C_API_START -#define AKLIB_C_API_END -#endif - -/*! If following line is commented in, double type is used for floating point - calculation */ -/* -#define AKFS_PRECISION_DOUBLE -*/ - -#endif - diff --git a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_Device.c b/libsensors/akmdfs/AKFS_APIs_8975/AKFS_Device.c deleted file mode 100644 index 3d99ab1..0000000 --- a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_Device.c +++ /dev/null @@ -1,110 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#include "AKFS_Device.h" - -int16 AKFS_InitBuffer( - const int16 ndata, /*!< Size of vector buffer */ - AKFVEC vdata[] /*!< Vector buffer */ -) -{ - int i; - - /* size check */ - if (ndata <= 0) { - return AKFS_ERROR; - } - - for (i=0; i= shift; i--) { - v[i] = v[i-shift]; - } - return AKFS_SUCCESS; -} - -int16 AKFS_Rotate( - const AKFS_PATNO pat, - AKFVEC* vec -) -{ - AKFLOAT tmp; - switch(pat){ - /* Obverse */ - case PAT1: - /* This is Android default */ - break; - case PAT2: - tmp = vec->u.x; - vec->u.x = vec->u.y; - vec->u.y = -tmp; - break; - case PAT3: - vec->u.x = -(vec->u.x); - vec->u.y = -(vec->u.y); - break; - case PAT4: - tmp = vec->u.x; - vec->u.x = -(vec->u.y); - vec->u.y = tmp; - break; - /* Reverse */ - case PAT5: - vec->u.x = -(vec->u.x); - vec->u.z = -(vec->u.z); - break; - case PAT6: - tmp = vec->u.x; - vec->u.x = vec->u.y; - vec->u.y = tmp; - vec->u.z = -(vec->u.z); - break; - case PAT7: - vec->u.y = -(vec->u.y); - vec->u.z = -(vec->u.z); - break; - case PAT8: - tmp = vec->u.x; - vec->u.x = -(vec->u.y); - vec->u.y = -tmp; - vec->u.z = -(vec->u.z); - break; - default: - return AKFS_ERROR; - } - - return AKFS_SUCCESS; -} - diff --git a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_Device.h b/libsensors/akmdfs/AKFS_APIs_8975/AKFS_Device.h deleted file mode 100644 index 0292d54..0000000 --- a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_Device.h +++ /dev/null @@ -1,107 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifndef AKFS_INC_DEVICE_H -#define AKFS_INC_DEVICE_H - -#include -#include "AKFS_Configure.h" - -/***** Constant definition ****************************************************/ -#define AKFS_ERROR 0 -#define AKFS_SUCCESS 1 - -#define AKFS_HDATA_SIZE 32 -#define AKFS_ADATA_SIZE 32 - -/***** Type declaration *******************************************************/ -typedef signed char int8; -typedef signed short int16; -typedef unsigned char uint8; -typedef unsigned short uint16; - - -#ifdef AKFS_PRECISION_DOUBLE -typedef double AKFLOAT; -#define AKFS_EPSILON DBL_EPSILON -#define AKFS_FMAX DBL_MAX -#define AKFS_FMIN DBL_MIN - -#else -typedef float AKFLOAT; -#define AKFS_EPSILON FLT_EPSILON -#define AKFS_FMAX FLT_MAX -#define AKFS_FMIN FLT_MIN - -#endif - -/* Treat maximum value as initial value */ -#define AKFS_INIT_VALUE_F AKFS_FMAX - -/***** Vector *****/ -typedef union _uint8vec{ - struct { - uint8 x; - uint8 y; - uint8 z; - }u; - uint8 v[3]; -} uint8vec; - -typedef union _AKFVEC{ - struct { - AKFLOAT x; - AKFLOAT y; - AKFLOAT z; - }u; - AKFLOAT v[3]; -} AKFVEC; - -/***** Layout pattern *****/ -typedef enum _AKFS_PATNO { - PAT_INVALID = 0, - PAT1, /* obverse: 1st pin is right down */ - PAT2, /* obverse: 1st pin is left down */ - PAT3, /* obverse: 1st pin is left top */ - PAT4, /* obverse: 1st pin is right top */ - PAT5, /* reverse: 1st pin is left down (from top view) */ - PAT6, /* reverse: 1st pin is left top (from top view) */ - PAT7, /* reverse: 1st pin is right top (from top view) */ - PAT8 /* reverse: 1st pin is right down (from top view) */ -} AKFS_PATNO; - -/***** Prototype of function **************************************************/ -AKLIB_C_API_START -int16 AKFS_InitBuffer( - const int16 ndata, /*!< Size of raw vector buffer */ - AKFVEC vdata[] /*!< Raw vector buffer */ -); - -int16 AKFS_BufShift( - const int16 len, - const int16 shift, - AKFVEC v[] -); - -int16 AKFS_Rotate( - const AKFS_PATNO pat, - AKFVEC* vec -); -AKLIB_C_API_END - -#endif - diff --git a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_Direction.c b/libsensors/akmdfs/AKFS_APIs_8975/AKFS_Direction.c deleted file mode 100644 index f47e930..0000000 --- a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_Direction.c +++ /dev/null @@ -1,133 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#include "AKFS_Direction.h" -#include "AKFS_VNorm.h" -#include "AKFS_Math.h" - -/* - Coordinate system is right-handed. - X-Axis: from left to right. - Y-Axis: from bottom to top. - Z-Axis: from reverse to obverse. - - azimuth: Rotaion around Z axis, with positive values - when y-axis moves toward the x-axis. - pitch: Rotation around X axis, with positive values - when z-axis moves toward the y-axis. - roll: Rotation around Y axis, with positive values - when x-axis moves toward the z-axis. -*/ - -/* - This function is used internaly, so output is RADIAN! - */ -static void AKFS_Angle( - const AKFVEC* avec, - AKFLOAT* pitch, /* radian */ - AKFLOAT* roll /* radian */ -) -{ - AKFLOAT av; /* Size of vector */ - - av = AKFS_SQRT((avec->u.x)*(avec->u.x) + (avec->u.y)*(avec->u.y) + (avec->u.z)*(avec->u.z)); - - *pitch = AKFS_ASIN(-(avec->u.y) / av); - *roll = AKFS_ASIN((avec->u.x) / av); -} - -/* - This function is used internaly, so output is RADIAN! - */ -static void AKFS_Azimuth( - const AKFVEC* hvec, - const AKFLOAT pitch, /* radian */ - const AKFLOAT roll, /* radian */ - AKFLOAT* azimuth /* radian */ -) -{ - AKFLOAT sinP; /* sin value of pitch angle */ - AKFLOAT cosP; /* cos value of pitch angle */ - AKFLOAT sinR; /* sin value of roll angle */ - AKFLOAT cosR; /* cos value of roll angle */ - AKFLOAT Xh; /* X axis element of vector which is projected to horizontal plane */ - AKFLOAT Yh; /* Y axis element of vector which is projected to horizontal plane */ - - sinP = AKFS_SIN(pitch); - cosP = AKFS_COS(pitch); - sinR = AKFS_SIN(roll); - cosR = AKFS_COS(roll); - - Yh = -(hvec->u.x)*cosR + (hvec->u.z)*sinR; - Xh = (hvec->u.x)*sinP*sinR + (hvec->u.y)*cosP + (hvec->u.z)*sinP*cosR; - - /* atan2(y, x) -> divisor and dividend is opposite from mathematical equation. */ - *azimuth = AKFS_ATAN2(Yh, Xh); -} - -int16 AKFS_Direction( - const int16 nhvec, - const AKFVEC hvec[], - const int16 hnave, - const int16 navec, - const AKFVEC avec[], - const int16 anave, - AKFLOAT* azimuth, - AKFLOAT* pitch, - AKFLOAT* roll -) -{ - AKFVEC have, aave; - AKFLOAT azimuthRad; - AKFLOAT pitchRad; - AKFLOAT rollRad; - - /* arguments check */ - if ((nhvec <= 0) || (navec <= 0) || (hnave <= 0) || (anave <= 0)) { - return AKFS_ERROR; - } - if ((nhvec < hnave) || (navec < anave)) { - return AKFS_ERROR; - } - - /* average */ - if (AKFS_VbAve(nhvec, hvec, hnave, &have) != AKFS_SUCCESS) { - return AKFS_ERROR; - } - if (AKFS_VbAve(navec, avec, anave, &aave) != AKFS_SUCCESS) { - return AKFS_ERROR; - } - - /* calculate pitch and roll */ - AKFS_Angle(&aave, &pitchRad, &rollRad); - - /* calculate azimuth */ - AKFS_Azimuth(&have, pitchRad, rollRad, &azimuthRad); - - *azimuth = RAD2DEG(azimuthRad); - *pitch = RAD2DEG(pitchRad); - *roll = RAD2DEG(rollRad); - - /* Adjust range of azimuth */ - if (*azimuth < 0) { - *azimuth += 360.0f; - } - - return AKFS_SUCCESS; -} - - diff --git a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_Direction.h b/libsensors/akmdfs/AKFS_APIs_8975/AKFS_Direction.h deleted file mode 100644 index c08338d..0000000 --- a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_Direction.h +++ /dev/null @@ -1,39 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifndef AKFS_INC_DIRECTION_H -#define AKFS_INC_DIRECTION_H - -#include "AKFS_Device.h" - -/***** Prototype of function **************************************************/ -AKLIB_C_API_START -int16 AKFS_Direction( - const int16 nhvec, - const AKFVEC hvec[], - const int16 hnave, - const int16 navec, - const AKFVEC avec[], - const int16 anave, - AKFLOAT* azimuth, - AKFLOAT* pitch, - AKFLOAT* roll -); -AKLIB_C_API_END - -#endif - diff --git a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_Math.h b/libsensors/akmdfs/AKFS_APIs_8975/AKFS_Math.h deleted file mode 100644 index dfe48b3..0000000 --- a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_Math.h +++ /dev/null @@ -1,47 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifndef AKFS_INC_MATH_H -#define AKFS_INC_MATH_H - -#include -#include "AKFS_Configure.h" - -/***** Constant definition ****************************************************/ -#define AKFS_PI 3.141592654f -#define RAD2DEG(rad) ((rad)*180.0f/AKFS_PI) - -/***** Macro definition *******************************************************/ - -#ifdef AKFS_PRECISION_DOUBLE -#define AKFS_SIN(x) sin(x) -#define AKFS_COS(x) cos(x) -#define AKFS_ASIN(x) asin(x) -#define AKFS_ACOS(x) acos(x) -#define AKFS_ATAN2(y, x) atan2((y), (x)) -#define AKFS_SQRT(x) sqrt(x) -#else -#define AKFS_SIN(x) sinf(x) -#define AKFS_COS(x) cosf(x) -#define AKFS_ASIN(x) asinf(x) -#define AKFS_ACOS(x) acosf(x) -#define AKFS_ATAN2(y, x) atan2f((y), (x)) -#define AKFS_SQRT(x) sqrtf(x) -#endif - -#endif - diff --git a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_VNorm.c b/libsensors/akmdfs/AKFS_APIs_8975/AKFS_VNorm.c deleted file mode 100644 index ffa934a..0000000 --- a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_VNorm.c +++ /dev/null @@ -1,107 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#include "AKFS_VNorm.h" -#include "AKFS_Device.h" - -/*! - */ -int16 AKFS_VbNorm( - const int16 ndata, /*!< Size of raw vector buffer */ - const AKFVEC vdata[], /*!< Raw vector buffer */ - const int16 nbuf, /*!< Size of data to be buffered */ - const AKFVEC* o, /*!< Offset */ - const AKFVEC* s, /*!< Sensitivity */ - const AKFLOAT tgt, /*!< Target sensitivity */ - const int16 nvec, /*!< Size of normalized vector buffer */ - AKFVEC vvec[] /*!< Normalized vector buffer */ -) -{ - int i; - - /* size check */ - if ((ndata <= 0) || (nvec <= 0) || (nbuf <= 0)) { - return AKFS_ERROR; - } - /* dependency check */ - if ((nbuf < 1) || (ndata < nbuf) || (nvec < nbuf)) { - return AKFS_ERROR; - } - /* sensitivity check */ - if ((s->u.x <= AKFS_EPSILON) || - (s->u.y <= AKFS_EPSILON) || - (s->u.z <= AKFS_EPSILON) || - (tgt <= 0)) { - return AKFS_ERROR; - } - - /* calculate and store data to buffer */ - if (AKFS_BufShift(nvec, nbuf, vvec) != AKFS_SUCCESS) { - return AKFS_ERROR; - } - for (i=0; iu.x) / (s->u.x) * (AKFLOAT)tgt); - vvec[i].u.y = ((vdata[i].u.y - o->u.y) / (s->u.y) * (AKFLOAT)tgt); - vvec[i].u.z = ((vdata[i].u.z - o->u.z) / (s->u.z) * (AKFLOAT)tgt); - } - - return AKFS_SUCCESS; -} - -/*! - */ -int16 AKFS_VbAve( - const int16 nvec, /*!< Size of normalized vector buffer */ - const AKFVEC vvec[], /*!< Normalized vector buffer */ - const int16 nave, /*!< Number of averaeg */ - AKFVEC* vave /*!< Averaged vector */ -) -{ - int i; - - /* arguments check */ - if ((nave <= 0) || (nvec <= 0) || (nvec < nave)) { - return AKFS_ERROR; - } - - /* calculate average */ - vave->u.x = 0; - vave->u.y = 0; - vave->u.z = 0; - for (i=0; iu.x += vvec[i].u.x; - vave->u.y += vvec[i].u.y; - vave->u.z += vvec[i].u.z; - } - if (i == 0) { - vave->u.x = 0; - vave->u.y = 0; - vave->u.z = 0; - } else { - vave->u.x /= i; - vave->u.y /= i; - vave->u.z /= i; - } - return AKFS_SUCCESS; -} - - diff --git a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_VNorm.h b/libsensors/akmdfs/AKFS_APIs_8975/AKFS_VNorm.h deleted file mode 100644 index c3c9bed..0000000 --- a/libsensors/akmdfs/AKFS_APIs_8975/AKFS_VNorm.h +++ /dev/null @@ -1,46 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifndef AKFS_INC_VNORM_H -#define AKFS_INC_VNORM_H - -#include "AKFS_Device.h" - -/***** Prototype of function **************************************************/ -AKLIB_C_API_START -int16 AKFS_VbNorm( - const int16 ndata, /*!< Size of raw vector buffer */ - const AKFVEC vdata[], /*!< Raw vector buffer */ - const int16 nbuf, /*!< Size of data to be buffered */ - const AKFVEC* o, /*!< Offset */ - const AKFVEC* s, /*!< Sensitivity */ - const AKFLOAT tgt, /*!< Target sensitivity */ - const int16 nvec, /*!< Size of normalized vector buffer */ - AKFVEC vvec[] /*!< Normalized vector buffer */ -); - -int16 AKFS_VbAve( - const int16 nvec, /*!< Size of normalized vector buffer */ - const AKFVEC vvec[], /*!< Normalized vector buffer */ - const int16 nave, /*!< Number of averaeg */ - AKFVEC* vave /*!< Averaged vector */ -); - -AKLIB_C_API_END - -#endif - diff --git a/libsensors/akmdfs/AKFS_CSpec.h b/libsensors/akmdfs/AKFS_CSpec.h deleted file mode 100644 index 380f06f..0000000 --- a/libsensors/akmdfs/AKFS_CSpec.h +++ /dev/null @@ -1,38 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifndef AKFS_INC_CSPEC_H -#define AKFS_INC_CSPEC_H - -/******************************************************************************* - User defines parameters. - ******************************************************************************/ -/* Parameters for Average */ -/* The number of magnetic/acceleration data to be averaged. */ -#define CSPEC_HNAVE_D 4 -#define CSPEC_ANAVE_D 4 -#define CSPEC_HNAVE_V 8 -#define CSPEC_ANAVE_V 8 - -#ifdef WIN32 -#define CSPEC_SETTING_FILE "akmdfs.txt" -#else -#define CSPEC_SETTING_FILE "/data/misc/akmdfs.txt" -#endif - -#endif - diff --git a/libsensors/akmdfs/AKFS_Common.h b/libsensors/akmdfs/AKFS_Common.h deleted file mode 100644 index 7780801..0000000 --- a/libsensors/akmdfs/AKFS_Common.h +++ /dev/null @@ -1,141 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifndef AKFS_INC_COMMON_H -#define AKFS_INC_COMMON_H - -#ifdef WIN32 -#ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0501 -#endif - -#include -#include -#include -#include -#include -#include -#include "Android.h" - -#define DBG_LEVEL DBG_LEVEL4 -#define ENABLE_AKMDEBUG 1 - -#else -#include /* frpintf */ -#include /* atoi */ -#include /* memset */ -#include -#include /* va_list */ -#include /* ALOGV */ -#include /* errno */ - -#endif - -/*** Constant definition ******************************************************/ -#define AKM_TRUE 1 /*!< Represents true */ -#define AKM_FALSE 0 /*!< Represents false */ -#define AKM_SUCCESS 1 /*!< Represents success */ -#define AKM_FAIL 0 /*!< Represents fail */ - -#define DBG_LEVEL0 0 /* Critical */ -#define DBG_LEVEL1 1 /* Notice */ -#define DBG_LEVEL2 2 /* Information */ -#define DBG_LEVEL3 3 /* Debug */ -#define DBG_LEVEL4 4 /* Verbose */ - -#ifndef DBG_LEVEL -#define DBG_LEVEL DBG_LEVEL0 -#endif - -#define DATA_AREA01 0x0001 -#define DATA_AREA02 0x0002 -#define DATA_AREA03 0x0004 -#define DATA_AREA04 0x0008 -#define DATA_AREA05 0x0010 -#define DATA_AREA06 0x0020 -#define DATA_AREA07 0x0040 -#define DATA_AREA08 0x0080 -#define DATA_AREA09 0x0100 -#define DATA_AREA10 0x0200 -#define DATA_AREA11 0x0400 -#define DATA_AREA12 0x0800 -#define DATA_AREA13 0x1000 -#define DATA_AREA14 0x2000 -#define DATA_AREA15 0x4000 -#define DATA_AREA16 0x8000 - - -/* Debug area definition */ -#define AKMDATA_DUMP DATA_AREA01 /* "); - fgets(msg, 10, stdin); - AKMDEBUG(DBG_LEVEL1, "\n"); - - /* BUG : If 2-digits number is input, */ - /* only the first character is compared. */ - if (!strncmp(msg, "1", 1)) { - return MODE_Measure; - } else if (!strncmp(msg, "2", 1)) { - return MODE_SelfTest; - } else if (strncmp(msg, "Q", 1) == 0 || strncmp(msg, "q", 1) == 0) { - return MODE_Quit; - } else { - return MODE_ERROR; - } -} - diff --git a/libsensors/akmdfs/AKFS_Disp.h b/libsensors/akmdfs/AKFS_Disp.h deleted file mode 100644 index 4769e3c..0000000 --- a/libsensors/akmdfs/AKFS_Disp.h +++ /dev/null @@ -1,52 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifndef AKFS_INC_DISP_H -#define AKFS_INC_DISP_H - -/* Include file for AK8975 library. */ -#include "AKFS_Compass.h" - -/*** Constant definition ******************************************************/ -#define REVERT_ACC(a) ((float)((a) * 9.8f / 720.0f)) -#define REVERT_MAG(m) ((float)((m) * 0.06f)) -#define REVERT_ORI(o) ((float)((o) / 64.0f)) - -/*** Type declaration *********************************************************/ - -/*! These defined types represents the current mode. */ -typedef enum _MODE { - MODE_ERROR, /*!< Error */ - MODE_Measure, /*!< Measurement */ - MODE_SelfTest, /*!< Self-test */ - MODE_Quit /*!< Quit */ -} MODE; - -/*** Prototype of function ****************************************************/ -/* - Disp_ : Display messages. - Menu_ : Display menu (two or more selection) and wait for user input. - */ - -void Disp_StartMessage(void); -void Disp_EndMessage(int ret); -void Disp_Result(int buf[YPR_DATA_SIZE]); - -MODE Menu_Main(void); - -#endif - diff --git a/libsensors/akmdfs/AKFS_FileIO.c b/libsensors/akmdfs/AKFS_FileIO.c deleted file mode 100644 index 92c2ce9..0000000 --- a/libsensors/akmdfs/AKFS_FileIO.c +++ /dev/null @@ -1,130 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#include "AKFS_FileIO.h" - -/*** Constant definition ******************************************************/ -#ifdef AKFS_PRECISION_DOUBLE -#define AKFS_SCANF_FORMAT "%63s = %lf" -#else -#define AKFS_SCANF_FORMAT "%63s = %f" -#endif -#define AKFS_PRINTF_FORMAT "%s = %f\n" -#define LOAD_BUF_SIZE 64 - -/*! - Load parameters from file which is specified with #path. This function reads - data from a beginning of the file line by line, and check parameter name - sequentially. In otherword, this function depends on the order of eache - parameter described in the file. - @return If function fails, the return value is #AKM_FAIL. When function fails, - the output is undefined. Therefore, parameters which are possibly overwritten - by this function should be initialized again. If function succeeds, the - return value is #AKM_SUCCESS. - @param[out] prms A pointer to #AK8975PRMS structure. Loaded parameter is - stored to the member of this structure. - @param[in] path A path to the setting file. - */ -int16 AKFS_LoadParameters(AK8975PRMS * prms, const char* path) -{ - int16 ret; - char buf[LOAD_BUF_SIZE]; - FILE *fp = NULL; - - /* Open setting file for read. */ - if ((fp = fopen(path, "r")) == NULL) { - AKMERROR_STR("fopen"); - return AKM_FAIL; - } - - ret = 1; - - /* Load data to HO */ - if (fscanf(fp, AKFS_SCANF_FORMAT, buf, &prms->mfv_ho.u.x) != 2) { - ret = 0; - } else { - if (strncmp(buf, "HO.x", sizeof(buf)) != 0) { - ret = 0; - } - } - if (fscanf(fp, AKFS_SCANF_FORMAT, buf, &prms->mfv_ho.u.y) != 2) { - ret = 0; - } else { - if (strncmp(buf, "HO.y", sizeof(buf)) != 0) { - ret = 0; - } - } - if (fscanf(fp, AKFS_SCANF_FORMAT, buf, &prms->mfv_ho.u.z) != 2) { - ret = 0; - } else { - if (strncmp(buf, "HO.z", sizeof(buf)) != 0) { - ret = 0; - } - } - - if (fclose(fp) != 0) { - AKMERROR_STR("fclose"); - ret = 0; - } - - if (ret == 0) { - AKMERROR; - return AKM_FAIL; - } - - return AKM_SUCCESS; -} - -/*! - Save parameters to file which is specified with #path. This function saves - variables when the offsets of magnetic sensor estimated successfully. - @return If function fails, the return value is #AKM_FAIL. When function fails, - the parameter file may collapsed. Therefore, the parameters file should be - discarded. If function succeeds, the return value is #AKM_SUCCESS. - @param[out] prms A pointer to #AK8975PRMS structure. Member variables are - saved to the parameter file. - @param[in] path A path to the setting file. - */ -int16 AKFS_SaveParameters(AK8975PRMS *prms, const char* path) -{ - int16 ret = 1; - FILE *fp; - - /*Open setting file for write. */ - if ((fp = fopen(path, "w")) == NULL) { - AKMERROR_STR("fopen"); - return AKM_FAIL; - } - - /* Save data to HO */ - if (fprintf(fp, AKFS_PRINTF_FORMAT, "HO.x", prms->mfv_ho.u.x) < 0) { ret = 0; } - if (fprintf(fp, AKFS_PRINTF_FORMAT, "HO.y", prms->mfv_ho.u.y) < 0) { ret = 0; } - if (fprintf(fp, AKFS_PRINTF_FORMAT, "HO.z", prms->mfv_ho.u.z) < 0) { ret = 0; } - - if (fclose(fp) != 0) { - AKMERROR_STR("fclose"); - ret = 0; - } - - if (ret == 0) { - AKMERROR; - return AKM_FAIL; - } - - return AKM_SUCCESS; -} - diff --git a/libsensors/akmdfs/AKFS_FileIO.h b/libsensors/akmdfs/AKFS_FileIO.h deleted file mode 100644 index 62f6e77..0000000 --- a/libsensors/akmdfs/AKFS_FileIO.h +++ /dev/null @@ -1,39 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifndef AKFS_INC_FILEIO_H -#define AKFS_INC_FILEIO_H - -/* Common include files. */ -#include "AKFS_Common.h" - -/* Include file for AK8975 library. */ -#include "AKFS_Compass.h" - -/*** Constant definition ******************************************************/ - -/*** Type declaration *********************************************************/ - -/*** Global variables *********************************************************/ - -/*** Prototype of function ****************************************************/ -int16 AKFS_LoadParameters(AK8975PRMS *prms, const char* path); - -int16 AKFS_SaveParameters(AK8975PRMS* prms, const char* path); - -#endif - diff --git a/libsensors/akmdfs/AKFS_Measure.c b/libsensors/akmdfs/AKFS_Measure.c deleted file mode 100644 index 84c0843..0000000 --- a/libsensors/akmdfs/AKFS_Measure.c +++ /dev/null @@ -1,410 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifdef WIN32 -#include "AK8975_LinuxDriver.h" -#else -#include "AK8975Driver.h" -#endif - -#include "AKFS_Measure.h" -#include "AKFS_Disp.h" -#include "AKFS_APIs.h" - -/*! - Read sensitivity adjustment data from fuse ROM. - @return If data are read successfully, the return value is #AKM_SUCCESS. - Otherwise the return value is #AKM_FAIL. - @param[out] regs The read ASA values. When this function succeeds, ASAX value - is saved in regs[0], ASAY is saved in regs[1], ASAZ is saved in regs[2]. - */ -int16 AKFS_ReadAK8975FUSEROM( - uint8 regs[3] -) -{ - /* Set to FUSE ROM access mode */ - if (AKD_SetMode(AK8975_MODE_FUSE_ACCESS) != AKD_SUCCESS) { - AKMERROR; - return AKM_FAIL; - } - - /* Read values. ASAX, ASAY, ASAZ */ - if (AKD_RxData(AK8975_FUSE_ASAX, regs, 3) != AKD_SUCCESS) { - AKMERROR; - return AKM_FAIL; - } - - /* Set to PowerDown mode */ - if (AKD_SetMode(AK8975_MODE_POWERDOWN) != AKD_SUCCESS) { - AKMERROR; - return AKM_FAIL; - } - - AKMDEBUG(DBG_LEVEL2, "%s: asa(dec)=%d,%d,%d\n", - __FUNCTION__, regs[0], regs[1], regs[2]); - - return AKM_SUCCESS; -} - -/*! - Carry out self-test. - @return If this function succeeds, the return value is #AKM_SUCCESS. - Otherwise the return value is #AKM_FAIL. - */ -int16 AKFS_SelfTest(void) -{ - BYTE i2cData[SENSOR_DATA_SIZE]; - BYTE asa[3]; - AKFLOAT hdata[3]; - int16 ret; - - /* Set to FUSE ROM access mode */ - if (AKD_SetMode(AK8975_MODE_FUSE_ACCESS) != AKD_SUCCESS) { - AKMERROR; - return AKM_FAIL; - } - - /* Read values from ASAX to ASAZ */ - if (AKD_RxData(AK8975_FUSE_ASAX, asa, 3) != AKD_SUCCESS) { - AKMERROR; - return AKM_FAIL; - } - - /* Set to PowerDown mode */ - if (AKD_SetMode(AK8975_MODE_POWERDOWN) != AKD_SUCCESS) { - AKMERROR; - return AKM_FAIL; - } - - /* Set to self-test mode */ - i2cData[0] = 0x40; - if (AKD_TxData(AK8975_REG_ASTC, i2cData, 1) != AKD_SUCCESS) { - AKMERROR; - return AKM_FAIL; - } - - /* Set to Self-test mode */ - if (AKD_SetMode(AK8975_MODE_SELF_TEST) != AKD_SUCCESS) { - AKMERROR; - return AKM_FAIL; - } - - /* - Wait for DRDY pin changes to HIGH. - Get measurement data from AK8975 - */ - if (AKD_GetMagneticData(i2cData) != AKD_SUCCESS) { - AKMERROR; - return AKM_FAIL; - } - - hdata[0] = AK8975_HDATA_CONVERTER(i2cData[2], i2cData[1], asa[0]); - hdata[1] = AK8975_HDATA_CONVERTER(i2cData[4], i2cData[3], asa[1]); - hdata[2] = AK8975_HDATA_CONVERTER(i2cData[6], i2cData[5], asa[2]); - - /* Test */ - ret = 1; - if ((hdata[0] < AK8975_SELFTEST_MIN_X) || - (AK8975_SELFTEST_MAX_X < hdata[0])) { - ret = 0; - } - if ((hdata[1] < AK8975_SELFTEST_MIN_Y) || - (AK8975_SELFTEST_MAX_Y < hdata[1])) { - ret = 0; - } - if ((hdata[2] < AK8975_SELFTEST_MIN_Z) || - (AK8975_SELFTEST_MAX_Z < hdata[2])) { - ret = 0; - } - - AKMDEBUG(DBG_LEVEL2, "Test(%s):%8.2f, %8.2f, %8.2f\n", - (ret ? "Success" : "fail"), hdata[0], hdata[1], hdata[2]); - - if (ret) { - return AKM_SUCCESS; - } else { - return AKM_FAIL; - } -} - -/*! - This function calculate the duration of sleep for maintaining - the loop keep the period. - This function calculates "minimum - (end - start)". - @return The result of above equation in nanosecond. - @param end The time of after execution. - @param start The time of before execution. - @param minimum Loop period of each execution. - */ -struct timespec AKFS_CalcSleep( - const struct timespec* end, - const struct timespec* start, - const int64_t minimum -) -{ - int64_t endL; - int64_t startL; - int64_t diff; - - struct timespec ret; - - endL = (end->tv_sec * 1000000000) + end->tv_nsec; - startL = (start->tv_sec * 1000000000) + start->tv_nsec; - diff = minimum; - - diff -= (endL - startL); - - /* Don't allow negative value */ - if (diff < 0) { - diff = 0; - } - - /* Convert to timespec */ - if (diff > 1000000000) { - ret.tv_sec = diff / 1000000000; - ret.tv_nsec = diff % 1000000000; - } else { - ret.tv_sec = 0; - ret.tv_nsec = diff; - } - return ret; -} - -/*! - Get interval of each sensors from device driver. - @return If this function succeeds, the return value is #AKM_SUCCESS. - Otherwise the return value is #AKM_FAIL. - @param flag This variable indicates what sensor frequency is updated. - @param minimum This value show the minimum loop period in all sensors. - */ -int16 AKFS_GetInterval( - uint16* flag, - int64_t* minimum -) -{ - /* Accelerometer, Magnetometer, Orientation */ - /* Delay is in nano second unit. */ - /* Negative value means the sensor is disabled.*/ - int64_t delay[AKM_NUM_SENSORS]; - int i; - - if (AKD_GetDelay(delay) < 0) { - AKMERROR; - return AKM_FAIL; - } - AKMDATA(AKMDATA_GETINTERVAL,"delay[A,M,O]=%lld,%lld,%lld\n", - delay[0], delay[1], delay[2]); - - /* update */ - *minimum = 1000000000; - *flag = 0; - for (i=0; i= 0) { - *flag |= 1 << i; - if (*minimum > delay[i]) { - *minimum = delay[i]; - } - } - } - return AKM_SUCCESS; -} - -/*! - If this program run as console mode, measurement result will be displayed - on console terminal. - @return If this function succeeds, the return value is #AKM_SUCCESS. - Otherwise the return value is #AKM_FAIL. - */ -void AKFS_OutputResult( - const uint16 flag, - const AKSENSOR_DATA* acc, - const AKSENSOR_DATA* mag, - const AKSENSOR_DATA* ori -) -{ - int buf[YPR_DATA_SIZE]; - - /* Store to buffer */ - buf[0] = flag; /* Data flag */ - buf[1] = CONVERT_ACC(acc->x); /* Ax */ - buf[2] = CONVERT_ACC(acc->y); /* Ay */ - buf[3] = CONVERT_ACC(acc->z); /* Az */ - buf[4] = acc->status; /* Acc status */ - buf[5] = CONVERT_MAG(mag->x); /* Mx */ - buf[6] = CONVERT_MAG(mag->y); /* My */ - buf[7] = CONVERT_MAG(mag->z); /* Mz */ - buf[8] = mag->status; /* Mag status */ - buf[9] = CONVERT_ORI(ori->x); /* yaw */ - buf[10] = CONVERT_ORI(ori->y); /* pitch */ - buf[11] = CONVERT_ORI(ori->z); /* roll */ - - if (g_opmode & OPMODE_CONSOLE) { - /* Console mode */ - Disp_Result(buf); - } - - /* Set result to driver */ - AKD_SetYPR(buf); -} - -/*! - This is the main routine of measurement. - */ -void AKFS_MeasureLoop(void) -{ - BYTE i2cData[SENSOR_DATA_SIZE]; /* ST1 ~ ST2 */ - int16 mag[3]; - int16 mstat; - int16 acc[3]; - struct timespec tsstart= {0, 0}; - struct timespec tsend = {0, 0}; - struct timespec doze; - int64_t minimum; - uint16 flag; - AKSENSOR_DATA sv_acc; - AKSENSOR_DATA sv_mag; - AKSENSOR_DATA sv_ori; - AKFLOAT tmpx, tmpy, tmpz; - int16 tmp_accuracy; - - minimum = -1; - -#ifdef WIN32 - clock_init_time(); -#endif - - /* Initialize library functions and device */ - if (AKFS_Start(CSPEC_SETTING_FILE) != AKM_SUCCESS) { - AKMERROR; - goto MEASURE_END; - } - - while (g_stopRequest != AKM_TRUE) { - /* Beginning time */ - if (clock_gettime(CLOCK_MONOTONIC, &tsstart) < 0) { - AKMERROR; - goto MEASURE_END; - } - - /* Get interval */ - if (AKFS_GetInterval(&flag, &minimum) != AKM_SUCCESS) { - AKMERROR; - goto MEASURE_END; - } - - if ((flag & ACC_DATA_READY) || (flag & ORI_DATA_READY)) { - /* Get accelerometer */ - if (AKD_GetAccelerationData(acc) != AKD_SUCCESS) { - AKMERROR; - goto MEASURE_END; - } - - /* Calculate accelerometer vector */ - if (AKFS_Get_ACCELEROMETER(acc, 0, &tmpx, &tmpy, &tmpz, &tmp_accuracy) == AKM_SUCCESS) { - sv_acc.x = tmpx; - sv_acc.y = tmpy; - sv_acc.z = tmpz; - sv_acc.status = tmp_accuracy; - } else { - flag &= ~ACC_DATA_READY; - flag &= ~ORI_DATA_READY; - } - } - - if ((flag & MAG_DATA_READY) || (flag & ORI_DATA_READY)) { - /* Set to measurement mode */ - if (AKD_SetMode(AK8975_MODE_SNG_MEASURE) != AKD_SUCCESS) { - AKMERROR; - goto MEASURE_END; - } - - /* Wait for DRDY and get data from device */ - if (AKD_GetMagneticData(i2cData) != AKD_SUCCESS) { - AKMERROR; - goto MEASURE_END; - } - /* raw data to x,y,z value */ - mag[0] = (int)((int16_t)(i2cData[2]<<8)+((int16_t)i2cData[1])); - mag[1] = (int)((int16_t)(i2cData[4]<<8)+((int16_t)i2cData[3])); - mag[2] = (int)((int16_t)(i2cData[6]<<8)+((int16_t)i2cData[5])); - mstat = i2cData[0] | i2cData[7]; - - AKMDATA(AKMDATA_BDATA, - "bData=%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X\n", - i2cData[0], i2cData[1], i2cData[2], i2cData[3], - i2cData[4], i2cData[5], i2cData[6], i2cData[7]); - - /* Calculate magnetic field vector */ - if (AKFS_Get_MAGNETIC_FIELD(mag, mstat, &tmpx, &tmpy, &tmpz, &tmp_accuracy) == AKM_SUCCESS) { - sv_mag.x = tmpx; - sv_mag.y = tmpy; - sv_mag.z = tmpz; - sv_mag.status = tmp_accuracy; - } else { - flag &= ~MAG_DATA_READY; - flag &= ~ORI_DATA_READY; - } - } - - if (flag & ORI_DATA_READY) { - if (AKFS_Get_ORIENTATION(&tmpx, &tmpy, &tmpz, &tmp_accuracy) == AKM_SUCCESS) { - sv_ori.x = tmpx; - sv_ori.y = tmpy; - sv_ori.z = tmpz; - sv_ori.status = tmp_accuracy; - } else { - flag &= ~ORI_DATA_READY; - } - } - - /* Output result */ - AKFS_OutputResult(flag, &sv_acc, &sv_mag, &sv_ori); - - /* Ending time */ - if (clock_gettime(CLOCK_MONOTONIC, &tsend) < 0) { - AKMERROR; - goto MEASURE_END; - } - - /* Calculate duration */ - doze = AKFS_CalcSleep(&tsend, &tsstart, minimum); - AKMDATA(AKMDATA_LOOP, "Sleep: %6.2f msec\n", (doze.tv_nsec/1000000.0f)); - nanosleep(&doze, NULL); - -#ifdef WIN32 - if (_kbhit()) { - _getch(); - break; - } -#endif - } - -MEASURE_END: - /* Set to PowerDown mode */ - if (AKD_SetMode(AK8975_MODE_POWERDOWN) != AKD_SUCCESS) { - AKMERROR; - return; - } - - /* Save parameters */ - if (AKFS_Stop(CSPEC_SETTING_FILE) != AKM_SUCCESS) { - AKMERROR; - } -} - - diff --git a/libsensors/akmdfs/AKFS_Measure.h b/libsensors/akmdfs/AKFS_Measure.h deleted file mode 100644 index d156b95..0000000 --- a/libsensors/akmdfs/AKFS_Measure.h +++ /dev/null @@ -1,70 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifndef AKFS_INC_MEASURE_H -#define AKFS_INC_MEASURE_H - -/* Include files for AK8975 library. */ -#include "AKFS_Compass.h" - -/*** Constant definition ******************************************************/ -#define AK8975_SELFTEST_MIN_X -100 -#define AK8975_SELFTEST_MAX_X 100 - -#define AK8975_SELFTEST_MIN_Y -100 -#define AK8975_SELFTEST_MAX_Y 100 - -#define AK8975_SELFTEST_MIN_Z -1000 -#define AK8975_SELFTEST_MAX_Z -300 - -#define CONVERT_ACC(a) ((int)((a) * 720 / 9.8f)) -#define CONVERT_MAG(m) ((int)((m) / 0.06f)) -#define CONVERT_ORI(o) ((int)((o) * 64)) - -/*** Type declaration *********************************************************/ - -/*** Global variables *********************************************************/ - -/*** Prototype of function ****************************************************/ -int16 AKFS_ReadAK8975FUSEROM( - uint8 regs[3] -); - -int16 AKFS_SelfTest(void); - -struct timespec AKFS_CalcSleep( - const struct timespec* end, - const struct timespec* start, - const int64_t minimum -); - -int16 AKFS_GetInterval( - uint16* flag, - int64_t* minimum -); - -void AKFS_OutputResult( - const uint16 flag, - const AKSENSOR_DATA* acc, - const AKSENSOR_DATA* mag, - const AKSENSOR_DATA* ori -); - -void AKFS_MeasureLoop(void); - -#endif - diff --git a/libsensors/akmdfs/NOTICE b/libsensors/akmdfs/NOTICE deleted file mode 100644 index d645695..0000000 --- a/libsensors/akmdfs/NOTICE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/libsensors/akmdfs/Version.txt b/libsensors/akmdfs/Version.txt deleted file mode 100644 index 3d56b30..0000000 --- a/libsensors/akmdfs/Version.txt +++ /dev/null @@ -1,31 +0,0 @@ -Version - * Console Version 20120329 - 570 AK8975Driver.c - 496 AK8975Driver.h - 579 AKFS_APIs.c - 572 AKFS_APIs.h - 580 AKFS_APIs_8975/AKFS_AK8975.c - 580 AKFS_APIs_8975/AKFS_AK8975.h - 580 AKFS_APIs_8975/AKFS_AOC.c - 580 AKFS_APIs_8975/AKFS_AOC.h - 580 AKFS_APIs_8975/AKFS_Configure.h - 580 AKFS_APIs_8975/AKFS_Device.c - 580 AKFS_APIs_8975/AKFS_Device.h - 580 AKFS_APIs_8975/AKFS_Direction.c - 580 AKFS_APIs_8975/AKFS_Direction.h - 580 AKFS_APIs_8975/AKFS_Math.h - 580 AKFS_APIs_8975/AKFS_VNorm.c - 580 AKFS_APIs_8975/AKFS_VNorm.h - 568 AKFS_CSpec.h - 573 AKFS_Common.h - 572 AKFS_Compass.h - 579 AKFS_Disp.c - 568 AKFS_Disp.h - 568 AKFS_FileIO.c - 549 AKFS_FileIO.h - 573 AKFS_Measure.c - 568 AKFS_Measure.h - 574 Android.mk - 575 NOTICE - 579 main.c - diff --git a/libsensors/akmdfs/main.c b/libsensors/akmdfs/main.c deleted file mode 100644 index a3df0bc..0000000 --- a/libsensors/akmdfs/main.c +++ /dev/null @@ -1,293 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#include "AKFS_Common.h" -#include "AKFS_Compass.h" -#include "AKFS_Disp.h" -#include "AKFS_FileIO.h" -#include "AKFS_Measure.h" -#include "AKFS_APIs.h" - -#ifndef WIN32 -#include -#include -#include -#endif - -#define ERROR_INITDEVICE (-1) -#define ERROR_OPTPARSE (-2) -#define ERROR_SELF_TEST (-3) -#define ERROR_READ_FUSE (-4) -#define ERROR_INIT (-5) -#define ERROR_GETOPEN_STAT (-6) -#define ERROR_STARTCLONE (-7) -#define ERROR_GETCLOSE_STAT (-8) - -/* Global variable. See AKFS_Common.h file. */ -int g_stopRequest = 0; -int g_opmode = 0; -int g_dbgzone = 0; -int g_mainQuit = AKD_FALSE; - -/* Static variable. */ -static pthread_t s_thread; /*!< Thread handle */ - -/*! - A thread function which is raised when measurement is started. - @param[in] args This parameter is not used currently. - */ -static void* thread_main(void* args) -{ - AKFS_MeasureLoop(); - return ((void*)0); -} - -/*! - Signal handler. This should be used only in DEBUG mode. - @param[in] sig Event - */ -static void signal_handler(int sig) -{ - if (sig == SIGINT) { - ALOGE("SIGINT signal"); - g_stopRequest = 1; - g_mainQuit = AKD_TRUE; - } -} - -/*! - Starts new thread. - @return If this function succeeds, the return value is 1. Otherwise, - the return value is 0. - */ -static int startClone(void) -{ - pthread_attr_t attr; - - pthread_attr_init(&attr); - g_stopRequest = 0; - if (pthread_create(&s_thread, &attr, thread_main, NULL) == 0) { - return 1; - } else { - return 0; - } -} - -/*! - This function parse the option. - @retval 1 Parse succeeds. - @retval 0 Parse failed. - @param[in] argc Argument count - @param[in] argv Argument vector - @param[out] layout_patno - */ -int OptParse( - int argc, - char* argv[], - AKFS_PATNO* layout_patno) -{ -#ifdef WIN32 - /* Static */ -#if defined(AKFS_WIN32_PAT1) - *layout_patno = PAT1; -#elif defined(AKFS_WIN32_PAT2) - *layout_patno = PAT2; -#elif defined(AKFS_WIN32_PAT3) - *layout_patno = PAT3; -#elif defined(AKFS_WIN32_PAT4) - *layout_patno = PAT4; -#elif defined(AKFS_WIN32_PAT5) - *layout_patno = PAT5; -#else - *layout_patno = PAT1; -#endif - g_opmode = OPMODE_CONSOLE; - /*g_opmode = 0;*/ - g_dbgzone = AKMDATA_LOOP | AKMDATA_TEST; -#else - int opt; - char optVal; - - *layout_patno = PAT_INVALID; - - while ((opt = getopt(argc, argv, "sm:z:")) != -1) { - switch(opt){ - case 'm': - optVal = (char)(optarg[0] - '0'); - if ((PAT1 <= optVal) && (optVal <= PAT8)) { - *layout_patno = (AKFS_PATNO)optVal; - AKMDEBUG(DBG_LEVEL2, "%s: Layout=%d\n", __FUNCTION__, optVal); - } - break; - case 's': - g_opmode |= OPMODE_CONSOLE; - break; - case 'z': - /* If error detected, hopefully 0 is returned. */ - errno = 0; - g_dbgzone = (int)strtol(optarg, (char**)NULL, 0); - AKMDEBUG(DBG_LEVEL2, "%s: Dbg Zone=%d\n", __FUNCTION__, g_dbgzone); - break; - default: - ALOGE("%s: Invalid argument", argv[0]); - return 0; - } - } - - /* If layout is not specified with argument, get parameter from driver */ - if (*layout_patno == PAT_INVALID) { - int16_t n; - if (AKD_GetLayout(&n) == AKM_SUCCESS) { - if ((PAT1 <= n) && (n <= PAT8)) { - *layout_patno = (AKFS_PATNO)n; - } - } - } - /* Error */ - if (*layout_patno == PAT_INVALID) { - ALOGE("No layout is specified."); - return 0; - } -#endif - - return 1; -} - -void ConsoleMode(void) -{ - /*** Console Mode *********************************************/ - while (AKD_TRUE) { - /* Select operation */ - switch (Menu_Main()) { - case MODE_SelfTest: - AKFS_SelfTest(); - break; - case MODE_Measure: - /* Reset flag */ - g_stopRequest = 0; - /* Measurement routine */ - AKFS_MeasureLoop(); - break; - - case MODE_Quit: - return; - - default: - AKMDEBUG(DBG_LEVEL0, "Unknown operation mode.\n"); - break; - } - } -} - -int main(int argc, char **argv) -{ - int retValue = 0; - AKFS_PATNO pat; - uint8 regs[3]; - - /* Show the version info of this software. */ - Disp_StartMessage(); - -#if ENABLE_AKMDEBUG - /* Register signal handler */ - signal(SIGINT, signal_handler); -#endif - - /* Open device driver */ - if(AKD_InitDevice() != AKD_SUCCESS) { - retValue = ERROR_INITDEVICE; - goto MAIN_QUIT; - } - - /* Parse command-line options */ - /* This function calls device driver function to get layout */ - if (OptParse(argc, argv, &pat) == 0) { - retValue = ERROR_OPTPARSE; - goto MAIN_QUIT; - } - - /* Self Test */ - if (g_opmode & OPMODE_FST){ - if (AKFS_SelfTest() != AKD_SUCCESS) { - retValue = ERROR_SELF_TEST; - goto MAIN_QUIT; - } - } - - /* OK, then start */ - if (AKFS_ReadAK8975FUSEROM(regs) != AKM_SUCCESS) { - retValue = ERROR_READ_FUSE; - goto MAIN_QUIT; - } - - /* Initialize library. */ - if (AKFS_Init(pat, regs) != AKM_SUCCESS) { - retValue = ERROR_INIT; - goto MAIN_QUIT; - } - - /* Start console mode */ - if (g_opmode & OPMODE_CONSOLE) { - ConsoleMode(); - goto MAIN_QUIT; - } - - /*** Start Daemon ********************************************/ - while (g_mainQuit == AKD_FALSE) { - int st = 0; - /* Wait until device driver is opened. */ - if (AKD_GetOpenStatus(&st) != AKD_SUCCESS) { - retValue = ERROR_GETOPEN_STAT; - goto MAIN_QUIT; - } - if (st == 0) { - ALOGI("Suspended."); - } else { - ALOGI("Compass Opened."); - /* Reset flag */ - g_stopRequest = 0; - /* Start measurement thread. */ - if (startClone() == 0) { - retValue = ERROR_STARTCLONE; - goto MAIN_QUIT; - } - - /* Wait until device driver is closed. */ - if (AKD_GetCloseStatus(&st) != AKD_SUCCESS) { - retValue = ERROR_GETCLOSE_STAT; - g_mainQuit = AKD_TRUE; - } - /* Wait thread completion. */ - g_stopRequest = 1; - pthread_join(s_thread, NULL); - ALOGI("Compass Closed."); - } - } - -MAIN_QUIT: - - /* Release library */ - AKFS_Release(); - /* Close device driver. */ - AKD_DeinitDevice(); - /* Show the last message. */ - Disp_EndMessage(retValue); - - return retValue; -} - - diff --git a/libsensors/cm36651_light.c b/libsensors/cm36651_light.c deleted file mode 100644 index 6781797..0000000 --- a/libsensors/cm36651_light.c +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (C) 2013 Paul Kocialkowski - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#define LOG_TAG "smdk4x12_sensors" -#include - -#include "smdk4x12_sensors.h" - -struct cm36651_light_data { - char path_enable[PATH_MAX]; - char path_delay[PATH_MAX]; -}; - -int cm36651_light_init(struct smdk4x12_sensors_handlers *handlers, - struct smdk4x12_sensors_device *device) -{ - struct cm36651_light_data *data = NULL; - char path[PATH_MAX] = { 0 }; - int input_fd = -1; - int rc; - - ALOGD("%s(%p, %p)", __func__, handlers, device); - - if (handlers == NULL) - return -EINVAL; - - data = (struct cm36651_light_data *) calloc(1, sizeof(struct cm36651_light_data)); - - input_fd = input_open("light_sensor"); - if (input_fd < 0) { - ALOGE("%s: Unable to open input", __func__); - goto error; - } - - rc = sysfs_path_prefix("light_sensor", (char *) &path); - if (rc < 0 || path[0] == '\0') { - ALOGE("%s: Unable to open sysfs", __func__); - goto error; - } - - snprintf(data->path_enable, PATH_MAX, "%s/enable", path); - snprintf(data->path_delay, PATH_MAX, "%s/poll_delay", path); - - handlers->poll_fd = input_fd; - handlers->data = (void *) data; - - return 0; - -error: - if (data != NULL) - free(data); - - if (input_fd >= 0) - close(input_fd); - - handlers->poll_fd = -1; - handlers->data = NULL; - - return -1; -} - -int cm36651_light_deinit(struct smdk4x12_sensors_handlers *handlers) -{ - ALOGD("%s(%p)", __func__, handlers); - - if (handlers == NULL) - return -EINVAL; - - if (handlers->poll_fd >= 0) - close(handlers->poll_fd); - handlers->poll_fd = -1; - - if (handlers->data != NULL) - free(handlers->data); - handlers->data = NULL; - - return 0; -} - -int cm36651_light_activate(struct smdk4x12_sensors_handlers *handlers) -{ - struct cm36651_light_data *data; - int rc; - - ALOGD("%s(%p)", __func__, handlers); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct cm36651_light_data *) handlers->data; - - rc = sysfs_value_write(data->path_enable, 1); - if (rc < 0) { - ALOGE("%s: Unable to write sysfs value", __func__); - return -1; - } - - handlers->activated = 1; - - return 0; -} - -int cm36651_light_deactivate(struct smdk4x12_sensors_handlers *handlers) -{ - struct cm36651_light_data *data; - int rc; - - ALOGD("%s(%p)", __func__, handlers); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct cm36651_light_data *) handlers->data; - - rc = sysfs_value_write(data->path_enable, 0); - if (rc < 0) { - ALOGE("%s: Unable to write sysfs value", __func__); - return -1; - } - - handlers->activated = 1; - - return 0; -} - -int cm36651_light_set_delay(struct smdk4x12_sensors_handlers *handlers, int64_t delay) -{ - struct cm36651_light_data *data; - int rc; - - ALOGD("%s(%p, %" PRId64 ")", __func__, handlers, delay); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct cm36651_light_data *) handlers->data; - - rc = sysfs_value_write(data->path_delay, delay); - if (rc < 0) { - ALOGE("%s: Unable to write sysfs value", __func__); - return -1; - } - - return 0; -} - -float cm36651_light_convert(int white, int green) -{ - float gwrel = 1.0f; - float aux; - float r1, r2, r3, r4; - - if (green <= 4) - return 0.0f; - else { - if (white > 0) - gwrel = (float) green / (float) white; - - r1 = floorf( (float) (pow((double) green, 1.3341) * 0.0258) ); - - aux = floorf( ((float) green * 0.18f * 9.44f) / gwrel); - r2 = aux; - r3 = aux * 0.77f; - - r4 = floorf( (float) green * ( (gwrel * 1.546) - 0.46) ); - - if (gwrel <= 0.5f) { - return r1; - } else if (gwrel >= 0.9f) { - if (white <= 5999) - return r2; - else - return r3; - } else { - return r4; - } - } -} - -int cm36651_light_get_data(struct smdk4x12_sensors_handlers *handlers, - struct sensors_event_t *event) -{ - struct input_event input_event; - int input_fd; - int green = 0; - int white = 0; - int rc; - -// ALOGD("%s(%p, %p)", __func__, handlers, event); - - if (handlers == NULL || event == NULL) - return -EINVAL; - - input_fd = handlers->poll_fd; - if (input_fd < 0) - return -EINVAL; - - memset(event, 0, sizeof(struct sensors_event_t)); - event->version = sizeof(struct sensors_event_t); - event->sensor = handlers->handle; - event->type = handlers->handle; - - do { - rc = read(input_fd, &input_event, sizeof(input_event)); - if (rc < (int) sizeof(input_event)) - break; - - if (input_event.type == EV_REL) { - if (input_event.code == REL_Y) - green = input_event.value; - if (input_event.code == REL_MISC) - white = input_event.value; - } else if (input_event.type == EV_SYN) { - if (input_event.code == SYN_REPORT) - event->timestamp = input_timestamp(&input_event); - } - } while (input_event.type != EV_SYN); - - event->light = cm36651_light_convert(white, green); - - return 0; -} - -struct smdk4x12_sensors_handlers cm36651_light = { - .name = "CM36651 Light", - .handle = SENSOR_TYPE_LIGHT, - .init = cm36651_light_init, - .deinit = cm36651_light_deinit, - .activate = cm36651_light_activate, - .deactivate = cm36651_light_deactivate, - .set_delay = cm36651_light_set_delay, - .get_data = cm36651_light_get_data, - .activated = 0, - .needed = 0, - .poll_fd = -1, - .data = NULL, -}; diff --git a/libsensors/cm36651_proximity.c b/libsensors/cm36651_proximity.c deleted file mode 100644 index 6529543..0000000 --- a/libsensors/cm36651_proximity.c +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (C) 2013 Paul Kocialkowski - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#define LOG_TAG "smdk4x12_sensors" -#include - -#include "smdk4x12_sensors.h" - -struct cm36651_proximity_data { - char path_enable[PATH_MAX]; -}; - -int cm36651_proximity_init(struct smdk4x12_sensors_handlers *handlers, - struct smdk4x12_sensors_device *device) -{ - struct cm36651_proximity_data *data = NULL; - char path[PATH_MAX] = { 0 }; - int input_fd = -1; - int rc; - - ALOGD("%s(%p, %p)", __func__, handlers, device); - - if (handlers == NULL) - return -EINVAL; - - data = (struct cm36651_proximity_data *) calloc(1, sizeof(struct cm36651_proximity_data)); - - input_fd = input_open("proximity_sensor"); - if (input_fd < 0) { - ALOGE("%s: Unable to open input", __func__); - goto error; - } - - rc = sysfs_path_prefix("proximity_sensor", (char *) &path); - if (rc < 0 || path[0] == '\0') { - ALOGE("%s: Unable to open sysfs", __func__); - goto error; - } - - snprintf(data->path_enable, PATH_MAX, "%s/enable", path); - - handlers->poll_fd = input_fd; - handlers->data = (void *) data; - - return 0; - -error: - if (data != NULL) - free(data); - - if (input_fd >= 0) - close(input_fd); - - handlers->poll_fd = -1; - handlers->data = NULL; - - return -1; -} - -int cm36651_proximity_deinit(struct smdk4x12_sensors_handlers *handlers) -{ - ALOGD("%s(%p)", __func__, handlers); - - if (handlers == NULL) - return -EINVAL; - - if (handlers->poll_fd >= 0) - close(handlers->poll_fd); - handlers->poll_fd = -1; - - if (handlers->data != NULL) - free(handlers->data); - handlers->data = NULL; - - return 0; -} - -int cm36651_proximity_activate(struct smdk4x12_sensors_handlers *handlers) -{ - struct cm36651_proximity_data *data; - int rc; - - ALOGD("%s(%p)", __func__, handlers); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct cm36651_proximity_data *) handlers->data; - - rc = sysfs_value_write(data->path_enable, 1); - if (rc < 0) { - ALOGE("%s: Unable to write sysfs value", __func__); - return -1; - } - - handlers->activated = 1; - - return 0; -} - -int cm36651_proximity_deactivate(struct smdk4x12_sensors_handlers *handlers) -{ - struct cm36651_proximity_data *data; - int rc; - - ALOGD("%s(%p)", __func__, handlers); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct cm36651_proximity_data *) handlers->data; - - rc = sysfs_value_write(data->path_enable, 0); - if (rc < 0) { - ALOGE("%s: Unable to write sysfs value", __func__); - return -1; - } - - handlers->activated = 1; - - return 0; -} - -int cm36651_proximity_set_delay(struct smdk4x12_sensors_handlers *handlers, int64_t delay) -{ - ALOGD("%s(%p, %" PRId64 ")", __func__, handlers, delay); - - return 0; -} - -float cm36651_proximity_convert(int value) -{ - return (float) value * 6.0f; -} - -int cm36651_proximity_get_data(struct smdk4x12_sensors_handlers *handlers, - struct sensors_event_t *event) -{ - struct input_event input_event; - int input_fd; - int rc; - -// ALOGD("%s(%p, %p)", __func__, handlers, event); - - if (handlers == NULL || event == NULL) - return -EINVAL; - - input_fd = handlers->poll_fd; - if (input_fd < 0) - return -EINVAL; - - memset(event, 0, sizeof(struct sensors_event_t)); - event->version = sizeof(struct sensors_event_t); - event->sensor = handlers->handle; - event->type = handlers->handle; - - do { - rc = read(input_fd, &input_event, sizeof(input_event)); - if (rc < (int) sizeof(input_event)) - break; - - if (input_event.type == EV_ABS) { - if (input_event.code == ABS_DISTANCE) - event->distance = cm36651_proximity_convert(input_event.value); - } else if (input_event.type == EV_SYN) { - if (input_event.code == SYN_REPORT) - event->timestamp = input_timestamp(&input_event); - } - } while (input_event.type != EV_SYN); - - return 0; -} - -struct smdk4x12_sensors_handlers cm36651_proximity = { - .name = "CM36651 Proximity", - .handle = SENSOR_TYPE_PROXIMITY, - .init = cm36651_proximity_init, - .deinit = cm36651_proximity_deinit, - .activate = cm36651_proximity_activate, - .deactivate = cm36651_proximity_deactivate, - .set_delay = cm36651_proximity_set_delay, - .get_data = cm36651_proximity_get_data, - .activated = 0, - .needed = 0, - .poll_fd = -1, - .data = NULL, -}; diff --git a/libsensors/input.c b/libsensors/input.c deleted file mode 100644 index da3d6d7..0000000 --- a/libsensors/input.c +++ /dev/null @@ -1,336 +0,0 @@ -/* - * Copyright (C) 2013 Paul Kocialkowski - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define LOG_TAG "smdk4x12_sensors" -#include - -#include "smdk4x12_sensors.h" - -void input_event_set(struct input_event *event, int type, int code, int value) -{ - if (event == NULL) - return; - - memset(event, 0, sizeof(struct input_event)); - - event->type = type, - event->code = code; - event->value = value; - - gettimeofday(&event->time, NULL); -} - -int64_t timestamp(struct timeval *time) -{ - if (time == NULL) - return -1; - - return time->tv_sec * 1000000000LL + time->tv_usec * 1000; -} - -int64_t input_timestamp(struct input_event *event) -{ - if (event == NULL) - return -1; - - return timestamp(&event->time); -} - -int uinput_rel_create(const char *name) -{ - struct uinput_user_dev uinput_dev; - int uinput_fd; - int rc; - - if (name == NULL) - return -1; - - uinput_fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK); - if (uinput_fd < 0) { - ALOGE("%s: Unable to open uinput device", __func__); - goto error; - } - - memset(&uinput_dev, 0, sizeof(uinput_dev)); - - strncpy(uinput_dev.name, name, sizeof(uinput_dev.name)); - uinput_dev.id.bustype = BUS_I2C; - uinput_dev.id.vendor = 0; - uinput_dev.id.product = 0; - uinput_dev.id.version = 0; - - rc = 0; - rc |= ioctl(uinput_fd, UI_SET_EVBIT, EV_REL); - rc |= ioctl(uinput_fd, UI_SET_RELBIT, REL_X); - rc |= ioctl(uinput_fd, UI_SET_RELBIT, REL_Y); - rc |= ioctl(uinput_fd, UI_SET_RELBIT, REL_Z); - rc |= ioctl(uinput_fd, UI_SET_RELBIT, REL_MISC); - rc |= ioctl(uinput_fd, UI_SET_EVBIT, EV_SYN); - - if (rc < 0) { - ALOGE("%s: Unable to set uinput bits", __func__); - goto error; - } - - rc = write(uinput_fd, &uinput_dev, sizeof(uinput_dev)); - if (rc < 0) { - ALOGE("%s: Unable to write uinput device", __func__); - goto error; - } - - rc = ioctl(uinput_fd, UI_DEV_CREATE); - if (rc < 0) { - ALOGE("%s: Unable to create uinput device", __func__); - goto error; - } - - usleep(3000); - - return uinput_fd; - -error: - if (uinput_fd >= 0) - close(uinput_fd); - - return -1; -} - -void uinput_destroy(int uinput_fd) -{ - if (uinput_fd < 0) - return; - - ioctl(uinput_fd, UI_DEV_DESTROY); -} - -int input_open(char *name) -{ - DIR *d; - struct dirent *di; - - char input_name[80] = { 0 }; - char path[PATH_MAX]; - char *c; - int fd; - int rc; - - if (name == NULL) - return -EINVAL; - - d = opendir("/dev/input"); - if (d == NULL) - return -1; - - while ((di = readdir(d))) { - if (di == NULL || strcmp(di->d_name, ".") == 0 || strcmp(di->d_name, "..") == 0) - continue; - - snprintf(path, PATH_MAX, "/dev/input/%s", di->d_name); - fd = open(path, O_RDONLY | O_NONBLOCK); - if (fd < 0) - continue; - - rc = ioctl(fd, EVIOCGNAME(sizeof(input_name) - 1), &input_name); - if (rc < 0) - continue; - - c = strstr((char *) &input_name, "\n"); - if (c != NULL) - *c = '\0'; - - if (strcmp(input_name, name) == 0) - return fd; - else - close(fd); - } - - return -1; -} - -int sysfs_path_prefix(char *name, char *path_prefix) -{ - DIR *d; - struct dirent *di; - - char input_name[80] = { 0 }; - char path[PATH_MAX]; - char *c; - int fd; - - if (name == NULL || path_prefix == NULL) - return -EINVAL; - - d = opendir("/sys/class/input"); - if (d == NULL) - return -1; - - while ((di = readdir(d))) { - if (di == NULL || strcmp(di->d_name, ".") == 0 || strcmp(di->d_name, "..") == 0) - continue; - - snprintf(path, PATH_MAX, "/sys/class/input/%s/name", di->d_name); - - fd = open(path, O_RDONLY); - if (fd < 0) - continue; - - read(fd, &input_name, sizeof(input_name)); - close(fd); - - c = strstr((char *) &input_name, "\n"); - if (c != NULL) - *c = '\0'; - - if (strcmp(input_name, name) == 0) { - snprintf(path_prefix, PATH_MAX, "/sys/class/input/%s", di->d_name); - return 0; - } - } - - return -1; -} - -int64_t sysfs_value_read(char *path) -{ - char buffer[100]; - int64_t value; - int fd = -1; - int rc; - - if (path == NULL) - return -1; - - fd = open(path, O_RDONLY); - if (fd < 0) - goto error; - - rc = read(fd, &buffer, sizeof(buffer)); - if (rc <= 0) - goto error; - - value = (int64_t)strtoimax(buffer, NULL, 10); - goto complete; - -error: - value = -1; - -complete: - if (fd >= 0) - close(fd); - - return value; -} - -int sysfs_value_write(char *path, int64_t value) -{ - char buffer[100]; - int fd = -1; - int rc; - - if (path == NULL) - return -1; - - fd = open(path, O_WRONLY); - if (fd < 0) - goto error; - - snprintf((char *) &buffer, sizeof(buffer), "%" PRId64 "\n", value); - - rc = write(fd, buffer, strlen(buffer)); - if (rc < (int) strlen(buffer)) - goto error; - - rc = 0; - goto complete; - -error: - rc = -1; - -complete: - if (fd >= 0) - close(fd); - - return rc; -} - -int sysfs_string_read(char *path, char *buffer, size_t length) -{ - int fd = -1; - int rc; - - if (path == NULL || buffer == NULL || length == 0) - return -1; - - fd = open(path, O_RDONLY); - if (fd < 0) - goto error; - - rc = read(fd, buffer, length); - if (rc <= 0) - goto error; - - rc = 0; - goto complete; - -error: - rc = -1; - -complete: - if (fd >= 0) - close(fd); - - return rc; -} - -int sysfs_string_write(char *path, char *buffer, size_t length) -{ - int fd = -1; - int rc; - - if (path == NULL || buffer == NULL || length == 0) - return -1; - - fd = open(path, O_WRONLY); - if (fd < 0) - goto error; - - rc = write(fd, buffer, length); - if (rc <= 0) - goto error; - - rc = 0; - goto complete; - -error: - rc = -1; - -complete: - if (fd >= 0) - close(fd); - - return rc; -} diff --git a/libsensors/lps331ap.c b/libsensors/lps331ap.c deleted file mode 100644 index a8ef55a..0000000 --- a/libsensors/lps331ap.c +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright (C) 2013 Paul Kocialkowski - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#define LOG_TAG "smdk4x12_sensors" -#include - -#include "smdk4x12_sensors.h" - -struct lps331ap_data { - char path_enable[PATH_MAX]; - char path_delay[PATH_MAX]; -}; - -int lps331ap_init(struct smdk4x12_sensors_handlers *handlers, - struct smdk4x12_sensors_device *device) -{ - struct lps331ap_data *data = NULL; - char path[PATH_MAX] = { 0 }; - int input_fd = -1; - int rc; - - ALOGD("%s(%p, %p)", __func__, handlers, device); - - if (handlers == NULL) - return -EINVAL; - - data = (struct lps331ap_data *) calloc(1, sizeof(struct lps331ap_data)); - - input_fd = input_open("barometer_sensor"); - if (input_fd < 0) { - ALOGE("%s: Unable to open input", __func__); - goto error; - } - - rc = sysfs_path_prefix("barometer_sensor", (char *) &path); - if (rc < 0 || path[0] == '\0') { - ALOGE("%s: Unable to open sysfs", __func__); - goto error; - } - - snprintf(data->path_enable, PATH_MAX, "%s/enable", path); - snprintf(data->path_delay, PATH_MAX, "%s/poll_delay", path); - - handlers->poll_fd = input_fd; - handlers->data = (void *) data; - - return 0; - -error: - if (data != NULL) - free(data); - - if (input_fd >= 0) - close(input_fd); - - handlers->poll_fd = -1; - handlers->data = NULL; - - return -1; -} - -int lps331ap_deinit(struct smdk4x12_sensors_handlers *handlers) -{ - ALOGD("%s(%p)", __func__, handlers); - - if (handlers == NULL) - return -EINVAL; - - if (handlers->poll_fd >= 0) - close(handlers->poll_fd); - handlers->poll_fd = -1; - - if (handlers->data != NULL) - free(handlers->data); - handlers->data = NULL; - - return 0; -} - -int lps331ap_activate(struct smdk4x12_sensors_handlers *handlers) -{ - struct lps331ap_data *data; - int rc; - - ALOGD("%s(%p)", __func__, handlers); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct lps331ap_data *) handlers->data; - - rc = sysfs_value_write(data->path_enable, 1); - if (rc < 0) { - ALOGE("%s: Unable to write sysfs value", __func__); - return -1; - } - - handlers->activated = 1; - - return 0; -} - -int lps331ap_deactivate(struct smdk4x12_sensors_handlers *handlers) -{ - struct lps331ap_data *data; - int rc; - - ALOGD("%s(%p)", __func__, handlers); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct lps331ap_data *) handlers->data; - - rc = sysfs_value_write(data->path_enable, 0); - if (rc < 0) { - ALOGE("%s: Unable to write sysfs value", __func__); - return -1; - } - - handlers->activated = 1; - - return 0; -} - -int lps331ap_set_delay(struct smdk4x12_sensors_handlers *handlers, int64_t delay) -{ - struct lps331ap_data *data; - int rc; - - ALOGD("%s(%p, %" PRId64 ")", __func__, handlers, delay); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct lps331ap_data *) handlers->data; - - if (delay < 10000000) - delay = 10; - else - delay = delay / 1000000; - - rc = sysfs_value_write(data->path_delay, delay); - if (rc < 0) { - ALOGE("%s: Unable to write sysfs value", __func__); - return -1; - } - - return 0; -} - -float lps331ap_convert(int value) -{ - return value / 4096.0f; -} - -int lps331ap_get_data(struct smdk4x12_sensors_handlers *handlers, - struct sensors_event_t *event) -{ - struct input_event input_event; - int input_fd; - int rc; - -// ALOGD("%s(%p, %p)", __func__, handlers, event); - - if (handlers == NULL || event == NULL) - return -EINVAL; - - input_fd = handlers->poll_fd; - if (input_fd < 0) - return -EINVAL; - - memset(event, 0, sizeof(struct sensors_event_t)); - event->version = sizeof(struct sensors_event_t); - event->sensor = handlers->handle; - event->type = handlers->handle; - - do { - rc = read(input_fd, &input_event, sizeof(input_event)); - if (rc < (int) sizeof(input_event)) - break; - - if (input_event.type == EV_REL) { - switch (input_event.code) { - case REL_X: - event->pressure = lps331ap_convert(input_event.value); - break; - default: - continue; - } - } else if (input_event.type == EV_SYN) { - if (input_event.code == SYN_REPORT && event->pressure != 0) { - event->timestamp = input_timestamp(&input_event); - break; - } else { - return -1; - } - } - } while (1); - - return 0; -} - -struct smdk4x12_sensors_handlers lps331ap = { - .name = "LPS331AP", - .handle = SENSOR_TYPE_PRESSURE, - .init = lps331ap_init, - .deinit = lps331ap_deinit, - .activate = lps331ap_activate, - .deactivate = lps331ap_deactivate, - .set_delay = lps331ap_set_delay, - .get_data = lps331ap_get_data, - .activated = 0, - .needed = 0, - .poll_fd = -1, - .data = NULL, -}; diff --git a/libsensors/lsm330dlc_accel.h b/libsensors/lsm330dlc_accel.h deleted file mode 100644 index ff5f666..0000000 --- a/libsensors/lsm330dlc_accel.h +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2011, Samsung Electronics Co. Ltd. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -#ifndef __LSM330DLC_ACCEL_HEADER__ -#define __LSM330DLC_ACCEL_HEADER__ - -#include -#include - -/*lsm330dlc_accel registers */ -#define STATUS_AUX 0x07 -#define OUT_1_L 0x08 -#define OUT_1_H 0x09 -#define OUT_2_L 0x0A -#define OUT_2_H 0x0B -#define OUT_3_L 0x0C -#define OUT_3_H 0x0D -#define INT_COUNTER 0x0E -#define WHO_AM_I 0x0F -#define TEMP_CFG_REG 0x1F -#define CTRL_REG1 0x20 /* power control reg */ -#define CTRL_REG2 0x21 /* power control reg */ -#define CTRL_REG3 0x22 /* power control reg */ -#define CTRL_REG4 0x23 /* interrupt control reg */ -#define CTRL_REG5 0x24 /* interrupt control reg */ -#define CTRL_REG6 0x25 -#define REFERENCE 0x26 -#define STATUS_REG 0x27 -#define OUT_X_L 0x28 -#define OUT_X_H 0x29 -#define OUT_Y_L 0x2A -#define OUT_Y_H 0x2B -#define OUT_Z_L 0x2C -#define OUT_Z_H 0x2D -#define FIFO_CTRL_REG 0x2E -#define FIFO_SRC_REG 0x2F -#define INT1_CFG 0x30 -#define INT1_SRC 0x31 -#define INT1_THS 0x32 -#define INT1_DURATION 0x33 -#define INT2_CFG 0x34 -#define INT2_SRC 0x35 -#define INT2_THS 0x36 -#define INT2_DURATION 0x37 -#define CLICK_CFG 0x38 -#define CLICK_SRC 0x39 -#define CLICK_THS 0x3A -#define TIME_LIMIT 0x3B -#define TIME_LATENCY 0x3C -#define TIME_WINDOW 0x3D - -/* CTRL_REG1 */ -#define CTRL_REG1_ODR3 (1 << 7) -#define CTRL_REG1_ODR2 (1 << 6) -#define CTRL_REG1_ODR1 (1 << 5) -#define CTRL_REG1_ODR0 (1 << 4) -#define CTRL_REG1_LPEN (1 << 3) -#define CTRL_REG1_Zen (1 << 2) -#define CTRL_REG1_Yen (1 << 1) -#define CTRL_REG1_Xen (1 << 0) - -#define PM_OFF 0x00 -#define LOW_PWR_MODE 0x4F /* 50HZ */ -#define FASTEST_MODE 0x9F /* 1344Hz */ -#define ENABLE_ALL_AXES 0x07 - -#define ODR1 0x10 /* 1Hz output data rate */ -#define ODR10 0x20 /* 10Hz output data rate */ -#define ODR25 0x30 /* 25Hz output data rate */ -#define ODR50 0x40 /* 50Hz output data rate */ -#define ODR100 0x50 /* 100Hz output data rate */ -#define ODR200 0x60 /* 100Hz output data rate */ -#define ODR400 0x70 /* 400Hz output data rate */ -#define ODR1344 0x90 /* 1344Hz output data rate */ -#define ODR_MASK 0xf0 - -/* CTRL_REG2 */ -#define CTRL_REG2_HPM1 (1 << 7) -#define CTRL_REG2_HPM0 (1 << 6) -#define CTRL_REG2_HPCF2 (1 << 5) -#define CTRL_REG2_HPCF1 (1 << 4) -#define CTRL_REG2_FDS (1 << 3) -#define CTRL_REG2_HPPCLICK (1 << 2) -#define CTRL_REG2_HPIS2 (1 << 1) -#define CTRL_REG2_HPIS1 (1 << 0) - -#define HPM_Normal (CTRL_REG2_HPM1) -#define HPM_Filter (CTRL_REG2_HPM0) - -/* CTRL_REG3 */ -#define I1_CLICK (1 << 7) -#define I1_AOI1 (1 << 6) -#define I1_AOI2 (1 << 5) -#define I1_DRDY1 (1 << 4) -#define I1_DRDY2 (1 << 3) -#define I1_WTM (1 << 2) -#define I1_OVERRUN (1 << 1) - -/* CTRL_REG4 */ -#define CTRL_REG4_BLE (1 << 6) -#define CTRL_REG4_FS1 (1 << 5) -#define CTRL_REG4_FS0 (1 << 4) -#define CTRL_REG4_HR (1 << 3) -#define CTRL_REG4_ST1 (1 << 2) -#define CTRL_REG4_ST0 (1 << 1) -#define CTRL_REG4_SIM (1 << 0) - -#define FS2g 0x00 -#define FS4g (CTRL_REG4_FS0) -#define FS8g (CTRL_REG4_FS1) -#define FS16g (CTRL_REG4_FS1|CTRL_REG4_FS0) - -/* CTRL_REG5 */ -#define BOOT (1 << 7) -#define FIFO_EN (1 << 6) -#define LIR_INT1 (1 << 3) -#define D4D_INT1 (1 << 2) - -/* STATUS_REG */ -#define ZYXOR (1 << 7) -#define ZOR (1 << 6) -#define YOR (1 << 5) -#define XOR (1 << 4) -#define ZYXDA (1 << 3) -#define ZDA (1 << 2) -#define YDA (1 << 1) -#define XDA (1 << 0) - -/* INT1_CFG */ -#define INT_CFG_AOI (1 << 7) -#define INT_CFG_6D (1 << 6) -#define INT_CFG_ZHIE (1 << 5) -#define INT_CFG_ZLIE (1 << 4) -#define INT_CFG_YHIE (1 << 3) -#define INT_CFG_YLIE (1 << 2) -#define INT_CFG_XHIE (1 << 1) -#define INT_CFG_XLIE (1 << 0) - -/* INT1_SRC */ -#define IA (1 << 6) -#define ZH (1 << 5) -#define ZL (1 << 4) -#define YH (1 << 3) -#define YL (1 << 2) -#define XH (1 << 1) -#define XL (1 << 0) - -/* Register Auto-increase */ -#define AC (1 << 7) - -/* dev info */ -#define ACC_DEV_NAME "accelerometer" - -struct lsm330dlc_acc { - __s16 x; - __s16 y; - __s16 z; -}; - -/* For movement recognition*/ -#define USES_MOVEMENT_RECOGNITION - -/* LSM330DLC_ACCEL ioctl command label */ -#define LSM330DLC_ACCEL_IOCTL_BASE 'a' -#define LSM330DLC_ACCEL_IOCTL_SET_DELAY \ - _IOW(LSM330DLC_ACCEL_IOCTL_BASE, 0, int64_t) -#define LSM330DLC_ACCEL_IOCTL_GET_DELAY \ - _IOR(LSM330DLC_ACCEL_IOCTL_BASE, 1, int64_t) -#define LSM330DLC_ACCEL_IOCTL_READ_XYZ\ - _IOR(LSM330DLC_ACCEL_IOCTL_BASE, 8, struct lsm330dlc_acc) -#define LSM330DLC_ACCEL_IOCTL_SET_ENABLE \ - _IOW(LSM330DLC_ACCEL_IOCTL_BASE, 9, int) -#endif diff --git a/libsensors/lsm330dlc_acceleration.c b/libsensors/lsm330dlc_acceleration.c deleted file mode 100644 index 7f6985b..0000000 --- a/libsensors/lsm330dlc_acceleration.c +++ /dev/null @@ -1,390 +0,0 @@ -/* - * Copyright (C) 2013 Paul Kocialkowski - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include - -#include -#include - -#define LOG_TAG "smdk4x12_sensors" -#include - -#include "smdk4x12_sensors.h" -#include "lsm330dlc_accel.h" - -struct lsm330dlc_acceleration_data { - int64_t delay; - int device_fd; - int uinput_fd; - - pthread_t thread; - pthread_mutex_t mutex; - int thread_continue; -}; - -void *lsm330dlc_acceleration_thread(void *thread_data) -{ - struct smdk4x12_sensors_handlers *handlers = NULL; - struct lsm330dlc_acceleration_data *data = NULL; - struct input_event event; - struct timeval time; - struct lsm330dlc_acc acceleration_data; - int64_t before, after; - int diff; - int device_fd; - int uinput_fd; - int rc; - - if (thread_data == NULL) - return NULL; - - handlers = (struct smdk4x12_sensors_handlers *) thread_data; - if (handlers->data == NULL) - return NULL; - - data = (struct lsm330dlc_acceleration_data *) handlers->data; - - device_fd = data->device_fd; - if (device_fd < 0) - return NULL; - - uinput_fd = data->uinput_fd; - if (uinput_fd < 0) - return NULL; - - while (data->thread_continue) { - pthread_mutex_lock(&data->mutex); - if (!data->thread_continue) - break; - - while (handlers->activated) { - gettimeofday(&time, NULL); - before = timestamp(&time); - - memset(&acceleration_data, 0, sizeof(acceleration_data)); - - rc = ioctl(device_fd, LSM330DLC_ACCEL_IOCTL_READ_XYZ, &acceleration_data); - if (rc < 0) { - ALOGE("%s: Unable to get lsm330dlc acceleration data", __func__); - return NULL; - } - - input_event_set(&event, EV_REL, REL_X, (int) (acceleration_data.x * 1000)); - write(uinput_fd, &event, sizeof(event)); - input_event_set(&event, EV_REL, REL_Y, (int) (acceleration_data.y * 1000)); - write(uinput_fd, &event, sizeof(event)); - input_event_set(&event, EV_REL, REL_Z, (int) (acceleration_data.z * 1000)); - write(uinput_fd, &event, sizeof(event)); - input_event_set(&event, EV_SYN, 0, 0); - write(uinput_fd, &event, sizeof(event)); - -next: - gettimeofday(&time, NULL); - after = timestamp(&time); - - diff = (int) (data->delay - (after - before)) / 1000; - if (diff <= 0) - continue; - - usleep(diff); - } - } - return NULL; -} - -int lsm330dlc_acceleration_init(struct smdk4x12_sensors_handlers *handlers, - struct smdk4x12_sensors_device *device) -{ - struct lsm330dlc_acceleration_data *data = NULL; - pthread_attr_t thread_attr; - int device_fd = -1; - int uinput_fd = -1; - int input_fd = -1; - int rc; - int i; - - ALOGD("%s(%p, %p)", __func__, handlers, device); - - if (handlers == NULL || device == NULL) - return -EINVAL; - - data = (struct lsm330dlc_acceleration_data *) calloc(1, sizeof(struct lsm330dlc_acceleration_data)); - - device_fd = open("/dev/accelerometer", O_RDONLY); - if (device_fd < 0) { - ALOGE("%s: Unable to open device", __func__); - goto error; - } - - uinput_fd = uinput_rel_create("acceleration"); - if (uinput_fd < 0) { - ALOGD("%s: Unable to create uinput", __func__); - goto error; - } - - input_fd = input_open("acceleration"); - if (input_fd < 0) { - ALOGE("%s: Unable to open acceleration input", __func__); - goto error; - } - - data->thread_continue = 1; - - pthread_mutex_init(&data->mutex, NULL); - pthread_mutex_lock(&data->mutex); - - pthread_attr_init(&thread_attr); - pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); - - rc = pthread_create(&data->thread, &thread_attr, lsm330dlc_acceleration_thread, (void *) handlers); - if (rc < 0) { - ALOGE("%s: Unable to create lsm330dlc acceleration thread", __func__); - pthread_mutex_destroy(&data->mutex); - goto error; - } - - data->device_fd = device_fd; - data->uinput_fd = uinput_fd; - handlers->poll_fd = input_fd; - handlers->data = (void *) data; - - return 0; - -error: - if (data != NULL) - free(data); - - if (uinput_fd >= 0) - close(uinput_fd); - - if (input_fd >= 0) - close(input_fd); - - if (device_fd >= 0) - close(device_fd); - - handlers->poll_fd = -1; - handlers->data = NULL; - - return -1; -} - -int lsm330dlc_acceleration_deinit(struct smdk4x12_sensors_handlers *handlers) -{ - struct lsm330dlc_acceleration_data *data = NULL; - - ALOGD("%s(%p)", __func__, handlers); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct lsm330dlc_acceleration_data *) handlers->data; - - handlers->activated = 0; - data->thread_continue = 0; - pthread_mutex_unlock(&data->mutex); - - pthread_mutex_destroy(&data->mutex); - - if (data->uinput_fd >= 0) { - uinput_destroy(data->uinput_fd); - close(data->uinput_fd); - } - data->uinput_fd = -1; - - if (handlers->poll_fd >= 0) - close(handlers->poll_fd); - handlers->poll_fd = -1; - - if (data->device_fd >= 0) - close(data->device_fd); - data->device_fd = -1; - - free(handlers->data); - handlers->data = NULL; - - return 0; -} - -int lsm330dlc_acceleration_activate(struct smdk4x12_sensors_handlers *handlers) -{ - struct lsm330dlc_acceleration_data *data; - int device_fd; - int enable; - int rc; - - ALOGD("%s(%p)", __func__, handlers); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct lsm330dlc_acceleration_data *) handlers->data; - - device_fd = data->device_fd; - if (device_fd < 0) - return -1; - - enable = 1; - rc = ioctl(device_fd, LSM330DLC_ACCEL_IOCTL_SET_ENABLE, &enable); - if (rc < 0) { - ALOGE("%s: Unable to set lsm330dlc acceleration enable", __func__); - return -1; - } - - handlers->activated = 1; - pthread_mutex_unlock(&data->mutex); - - return 0; -} - -int lsm330dlc_acceleration_deactivate(struct smdk4x12_sensors_handlers *handlers) -{ - struct lsm330dlc_acceleration_data *data; - int device_fd; - int enable; - int rc; - - ALOGD("%s(%p)", __func__, handlers); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct lsm330dlc_acceleration_data *) handlers->data; - - device_fd = data->device_fd; - if (device_fd < 0) - return -1; - - enable = 0; - rc = ioctl(device_fd, LSM330DLC_ACCEL_IOCTL_SET_ENABLE, &enable); - if (rc < 0) { - ALOGE("%s: Unable to set lsm330dlc acceleration enable", __func__); - return -1; - } - - handlers->activated = 0; - - return 0; -} - -int lsm330dlc_acceleration_set_delay(struct smdk4x12_sensors_handlers *handlers, int64_t delay) -{ - struct lsm330dlc_acceleration_data *data; - int64_t d; - int device_fd; - int rc; - - ALOGD("%s(%p, %" PRId64 ")", __func__, handlers, delay); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct lsm330dlc_acceleration_data *) handlers->data; - - device_fd = data->device_fd; - if (device_fd < 0) - return -1; - - d = (int64_t) delay; - rc = ioctl(device_fd, LSM330DLC_ACCEL_IOCTL_SET_DELAY, &d); - if (rc < 0) { - ALOGE("%s: Unable to set lsm330dlc acceleration delay", __func__); - return -1; - } - - data->delay = delay; - - return 0; -} - -float lsm330dlc_acceleration_convert(int value) -{ - return (float) (value / 1000.f) * (GRAVITY_EARTH / 1024.0f); -} - -int lsm330dlc_acceleration_get_data(struct smdk4x12_sensors_handlers *handlers, - struct sensors_event_t *event) -{ - struct lsm330dlc_acceleration_data *data; - struct input_event input_event; - int input_fd; - int rc; - -// ALOGD("%s(%p, %p)", __func__, handlers, event); - - if (handlers == NULL || handlers->data == NULL || event == NULL) - return -EINVAL; - - data = (struct lsm330dlc_acceleration_data *) handlers->data; - - input_fd = handlers->poll_fd; - if (input_fd < 0) - return -1; - - memset(event, 0, sizeof(struct sensors_event_t)); - event->version = sizeof(struct sensors_event_t); - event->sensor = handlers->handle; - event->type = handlers->handle; - - event->acceleration.status = SENSOR_STATUS_ACCURACY_MEDIUM; - - do { - rc = read(input_fd, &input_event, sizeof(input_event)); - if (rc < (int) sizeof(input_event)) - break; - - if (input_event.type == EV_REL) { - switch (input_event.code) { - case REL_X: - event->acceleration.x = lsm330dlc_acceleration_convert(input_event.value); - break; - case REL_Y: - event->acceleration.y = lsm330dlc_acceleration_convert(input_event.value); - break; - case REL_Z: - event->acceleration.z = lsm330dlc_acceleration_convert(input_event.value); - break; - default: - continue; - } - } else if (input_event.type == EV_SYN) { - if (input_event.code == SYN_REPORT) - event->timestamp = input_timestamp(&input_event); - } - } while (input_event.type != EV_SYN); - - return 0; -} - -struct smdk4x12_sensors_handlers lsm330dlc_acceleration = { - .name = "LSM330DLC Acceleration", - .handle = SENSOR_TYPE_ACCELEROMETER, - .init = lsm330dlc_acceleration_init, - .deinit = lsm330dlc_acceleration_deinit, - .activate = lsm330dlc_acceleration_activate, - .deactivate = lsm330dlc_acceleration_deactivate, - .set_delay = lsm330dlc_acceleration_set_delay, - .get_data = lsm330dlc_acceleration_get_data, - .activated = 0, - .needed = 0, - .poll_fd = -1, - .data = NULL, -}; diff --git a/libsensors/lsm330dlc_gyroscope.c b/libsensors/lsm330dlc_gyroscope.c deleted file mode 100644 index b91b433..0000000 --- a/libsensors/lsm330dlc_gyroscope.c +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright (C) 2013 Paul Kocialkowski - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#define LOG_TAG "smdk4x12_sensors" -#include - -#include "smdk4x12_sensors.h" - -struct lsm330dlc_gyroscope_data { - char path_enable[PATH_MAX]; - char path_delay[PATH_MAX]; - - sensors_vec_t gyro; -}; - -int lsm330dlc_gyroscope_init(struct smdk4x12_sensors_handlers *handlers, - struct smdk4x12_sensors_device *device) -{ - struct lsm330dlc_gyroscope_data *data = NULL; - char path[PATH_MAX] = { 0 }; - int input_fd = -1; - int rc; - - ALOGD("%s(%p, %p)", __func__, handlers, device); - - if (handlers == NULL) - return -EINVAL; - - data = (struct lsm330dlc_gyroscope_data *) calloc(1, sizeof(struct lsm330dlc_gyroscope_data)); - - input_fd = input_open("gyro_sensor"); - if (input_fd < 0) { - ALOGE("%s: Unable to open input", __func__); - goto error; - } - - rc = sysfs_path_prefix("gyro_sensor", (char *) &path); - if (rc < 0 || path[0] == '\0') { - ALOGE("%s: Unable to open sysfs", __func__); - goto error; - } - - snprintf(data->path_enable, PATH_MAX, "%s/enable", path); - snprintf(data->path_delay, PATH_MAX, "%s/poll_delay", path); - - handlers->poll_fd = input_fd; - handlers->data = (void *) data; - - return 0; - -error: - if (data != NULL) - free(data); - - if (input_fd >= 0) - close(input_fd); - - handlers->poll_fd = -1; - handlers->data = NULL; - - return -1; -} - -int lsm330dlc_gyroscope_deinit(struct smdk4x12_sensors_handlers *handlers) -{ - ALOGD("%s(%p)", __func__, handlers); - - if (handlers == NULL) - return -EINVAL; - - if (handlers->poll_fd >= 0) - close(handlers->poll_fd); - handlers->poll_fd = -1; - - if (handlers->data != NULL) - free(handlers->data); - handlers->data = NULL; - - return 0; -} - -int lsm330dlc_gyroscope_activate(struct smdk4x12_sensors_handlers *handlers) -{ - struct lsm330dlc_gyroscope_data *data; - int rc; - - ALOGD("%s(%p)", __func__, handlers); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct lsm330dlc_gyroscope_data *) handlers->data; - - rc = sysfs_value_write(data->path_enable, 1); - if (rc < 0) { - ALOGE("%s: Unable to write sysfs value", __func__); - return -1; - } - - handlers->activated = 1; - - return 0; -} - -int lsm330dlc_gyroscope_deactivate(struct smdk4x12_sensors_handlers *handlers) -{ - struct lsm330dlc_gyroscope_data *data; - int rc; - - ALOGD("%s(%p)", __func__, handlers); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct lsm330dlc_gyroscope_data *) handlers->data; - - rc = sysfs_value_write(data->path_enable, 0); - if (rc < 0) { - ALOGE("%s: Unable to write sysfs value", __func__); - return -1; - } - - handlers->activated = 1; - - return 0; -} - -int lsm330dlc_gyroscope_set_delay(struct smdk4x12_sensors_handlers *handlers, int64_t delay) -{ - struct lsm330dlc_gyroscope_data *data; - int rc; - - ALOGD("%s(%p, %" PRId64 ")", __func__, handlers, delay); - - if (handlers == NULL || handlers->data == NULL) - return -EINVAL; - - data = (struct lsm330dlc_gyroscope_data *) handlers->data; - - rc = sysfs_value_write(data->path_delay, delay); - if (rc < 0) { - ALOGE("%s: Unable to write sysfs value", __func__); - return -1; - } - - return 0; -} - -float lsm330dlc_gyroscope_convert(int value) -{ - return value * (70.0f / 4000.0f) * (3.1415926535f / 180.0f); -} - -int lsm330dlc_gyroscope_get_data(struct smdk4x12_sensors_handlers *handlers, - struct sensors_event_t *event) -{ - struct lsm330dlc_gyroscope_data *data; - struct input_event input_event; - int input_fd; - int rc; - -// ALOGD("%s(%p, %p)", __func__, handlers, event); - - if (handlers == NULL || handlers->data == NULL || event == NULL) - return -EINVAL; - - data = (struct lsm330dlc_gyroscope_data *) handlers->data; - - input_fd = handlers->poll_fd; - if (input_fd < 0) - return -EINVAL; - - memset(event, 0, sizeof(struct sensors_event_t)); - event->version = sizeof(struct sensors_event_t); - event->sensor = handlers->handle; - event->type = handlers->handle; - - event->gyro.x = data->gyro.x; - event->gyro.y = data->gyro.y; - event->gyro.z = data->gyro.z; - - event->gyro.status = SENSOR_STATUS_ACCURACY_MEDIUM; - - do { - rc = read(input_fd, &input_event, sizeof(input_event)); - if (rc < (int) sizeof(input_event)) - break; - - if (input_event.type == EV_REL) { - switch (input_event.code) { - case REL_RX: - event->gyro.x = lsm330dlc_gyroscope_convert(input_event.value); - break; - case REL_RY: - event->gyro.y = lsm330dlc_gyroscope_convert(input_event.value); - break; - case REL_RZ: - event->gyro.z = lsm330dlc_gyroscope_convert(input_event.value); - break; - default: - continue; - } - } else if (input_event.type == EV_SYN) { - if (input_event.code == SYN_REPORT) - event->timestamp = input_timestamp(&input_event); - } - } while (input_event.type != EV_SYN); - - data->gyro.x = event->gyro.x; - data->gyro.y = event->gyro.y; - data->gyro.z = event->gyro.z; - - return 0; -} - -struct smdk4x12_sensors_handlers lsm330dlc_gyroscope = { - .name = "LSM330DLC Gyroscope", - .handle = SENSOR_TYPE_GYROSCOPE, - .init = lsm330dlc_gyroscope_init, - .deinit = lsm330dlc_gyroscope_deinit, - .activate = lsm330dlc_gyroscope_activate, - .deactivate = lsm330dlc_gyroscope_deactivate, - .set_delay = lsm330dlc_gyroscope_set_delay, - .get_data = lsm330dlc_gyroscope_get_data, - .activated = 0, - .needed = 0, - .poll_fd = -1, - .data = NULL, -}; diff --git a/libsensors/sensors.cpp b/libsensors/sensors.cpp new file mode 100644 index 0000000..74b7f21 --- /dev/null +++ b/libsensors/sensors.cpp @@ -0,0 +1,395 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define ALOG_TAG "Sensors" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include "sensors.h" + +#include "LightSensor.h" +#include "ProximitySensor.h" +#include "AkmSensor.h" +#include "GyroSensor.h" +#include "AccelSensor.h" +#include "PressureSensor.h" + +/*****************************************************************************/ + +#define DELAY_OUT_TIME 0x7FFFFFFF + +#define LIGHT_SENSOR_POLLTIME 2000000000 + + +#define SENSORS_ACCELERATION (1<getFd(); + mPollFds[light].events = POLLIN; + mPollFds[light].revents = 0; + + mSensors[proximity] = new ProximitySensor(); + mPollFds[proximity].fd = mSensors[proximity]->getFd(); + mPollFds[proximity].events = POLLIN; + mPollFds[proximity].revents = 0; + + mSensors[akm] = new AkmSensor(); + mPollFds[akm].fd = mSensors[akm]->getFd(); + mPollFds[akm].events = POLLIN; + mPollFds[akm].revents = 0; + + mSensors[gyro] = new GyroSensor(); + mPollFds[gyro].fd = mSensors[gyro]->getFd(); + mPollFds[gyro].events = POLLIN; + mPollFds[gyro].revents = 0; + + mSensors[accel] = new AccelSensor(); + mPollFds[accel].fd = mSensors[accel]->getFd(); + mPollFds[accel].events = POLLIN; + mPollFds[accel].revents = 0; + + mSensors[pressure] = new PressureSensor(); + mPollFds[pressure].fd = mSensors[pressure]->getFd(); + mPollFds[pressure].events = POLLIN; + mPollFds[pressure].revents = 0; + + int wakeFds[2]; + int result = pipe(wakeFds); + ALOGE_IF(result<0, "error creating wake pipe (%s)", strerror(errno)); + fcntl(wakeFds[0], F_SETFL, O_NONBLOCK); + fcntl(wakeFds[1], F_SETFL, O_NONBLOCK); + mWritePipeFd = wakeFds[1]; + + mPollFds[wake].fd = wakeFds[0]; + mPollFds[wake].events = POLLIN; + mPollFds[wake].revents = 0; + mInitialized = true; +} + +sensors_poll_context_t::~sensors_poll_context_t() { + for (int i=0 ; ienable(handle, enabled); + if (enabled && !err) { + const char wakeMessage(WAKE_MESSAGE); + int result = write(mWritePipeFd, &wakeMessage, 1); + ALOGE_IF(result<0, "error sending wake message (%s)", strerror(errno)); + } + return err; +} + +int sensors_poll_context_t::setDelay(int handle, int64_t ns) { + + int index = handleToDriver(handle); + if (index < 0) return index; + return mSensors[index]->setDelay(handle, ns); +} + +int sensors_poll_context_t::pollEvents(sensors_event_t* data, int count) +{ + int nbEvents = 0; + int n = 0; + + do { + // see if we have some leftover from the last poll() + for (int i=0 ; count && ihasPendingEvents())) { + int nb = sensor->readEvents(data, count); + if (nb < count) { + // no more data for this sensor + mPollFds[i].revents = 0; + } + count -= nb; + nbEvents += nb; + data += nb; + } + } + + if (count) { + // we still have some room, so try to see if we can get + // some events immediately or just wait if we don't have + // anything to return + n = poll(mPollFds, numFds, nbEvents ? 0 : -1); + if (n<0) { + ALOGE("poll() failed (%s)", strerror(errno)); + return -errno; + } + if (mPollFds[wake].revents & POLLIN) { + char msg; + int result = read(mPollFds[wake].fd, &msg, 1); + ALOGE_IF(result<0, "error reading from wake pipe (%s)", strerror(errno)); + ALOGE_IF(msg != WAKE_MESSAGE, "unknown message on wake queue (0x%02x)", int(msg)); + mPollFds[wake].revents = 0; + } + } + // if we have events and space, go read them + } while (n && count); + + return nbEvents; +} + +int sensors_poll_context_t::batch(int handle, int flags, int64_t period_ns, int64_t timeout) +{ + int index = handleToDriver(handle); + if (index < 0) return index; + return mSensors[index]->batch(handle, flags, period_ns, timeout); +} + +int sensors_poll_context_t::flush(int handle) +{ + int index = handleToDriver(handle); + if (index < 0) return index; + return mSensors[index]->flush(handle); +} + +/*****************************************************************************/ + +static int poll__close(struct hw_device_t *dev) +{ + sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev; + if (ctx) { + delete ctx; + } + return 0; +} + +static int poll__activate(struct sensors_poll_device_t *dev, + int handle, int enabled) { + sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev; + return ctx->activate(handle, enabled); +} + +static int poll__setDelay(struct sensors_poll_device_t *dev, + int handle, int64_t ns) { + sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev; + return ctx->setDelay(handle, ns); +} + +static int poll__poll(struct sensors_poll_device_t *dev, + sensors_event_t* data, int count) { + sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev; + return ctx->pollEvents(data, count); +} + +static int poll__batch(struct sensors_poll_device_1 *dev, + int handle, int flags, int64_t period_ns, int64_t timeout) +{ + sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev; + return ctx->batch(handle, flags, period_ns, timeout); +} + +static int poll__flush(struct sensors_poll_device_1 *dev, + int handle) +{ + sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev; + return ctx->flush(handle); +} + +/*****************************************************************************/ + +/** Open a new instance of a sensor device using name */ +static int open_sensors(const struct hw_module_t* module, const char* id, + struct hw_device_t** device) +{ + int status = -EINVAL; + sensors_poll_context_t *dev = new sensors_poll_context_t(); + + memset(&dev->device, 0, sizeof(sensors_poll_device_1)); + + dev->device.common.tag = HARDWARE_DEVICE_TAG; + dev->device.common.version = SENSORS_DEVICE_API_VERSION_1_0; + dev->device.common.module = const_cast(module); + dev->device.common.close = poll__close; + dev->device.activate = poll__activate; + dev->device.setDelay = poll__setDelay; + dev->device.poll = poll__poll; + + /* Batch processing */ + dev->device.batch = poll__batch; + dev->device.flush = poll__flush; + + *device = &dev->device.common; + status = 0; + + return status; +} + diff --git a/libsensors/sensors.h b/libsensors/sensors.h new file mode 100644 index 0000000..0d61ac2 --- /dev/null +++ b/libsensors/sensors.h @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_SENSORS_H +#define ANDROID_SENSORS_H + +#include +#include +#include +#include + +#include + +#include +#include + +__BEGIN_DECLS + +/*****************************************************************************/ + +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) + +#define LOG_TAG "sensorscpp" + +#define ID_A (0) +#define ID_M (1) +#define ID_O (2) +#define ID_L (3) +#define ID_P (4) +#define ID_GY (5) +#define ID_PR (6) + +/*****************************************************************************/ + +/* + * The SENSORS Module + */ + +/* the CM3663 is a binary proximity sensor that triggers around 6 cm on + * this hardware */ +#define PROXIMITY_THRESHOLD_CM 6.0f + +/*****************************************************************************/ + +#define EVENT_TYPE_ACCEL_X ABS_X //1 +#define EVENT_TYPE_ACCEL_Y ABS_Y //0 +#define EVENT_TYPE_ACCEL_Z ABS_Z //2 + +#define EVENT_TYPE_YAW ABS_RX //3 +#define EVENT_TYPE_PITCH ABS_RY //4 +#define EVENT_TYPE_ROLL ABS_RZ //5 +#define EVENT_TYPE_ORIENT_STATUS ABS_WHEEL //8 + +#define EVENT_TYPE_MAGV_X ABS_THROTTLE // 6 +#define EVENT_TYPE_MAGV_Y ABS_RUDDER // 7 +#define EVENT_TYPE_MAGV_Z ABS_GAS // 9 +#define EVENT_TYPE_MAGV_ACC ABS_WHEEL // 8 + +#define EVENT_TYPE_TEMPERATURE ABS_THROTTLE +#define EVENT_TYPE_STEP_COUNT ABS_GAS +#define EVENT_TYPE_PROXIMITY ABS_DISTANCE +#define EVENT_TYPE_LIGHT REL_MISC + +#define EVENT_TYPE_GYRO_X REL_RX +#define EVENT_TYPE_GYRO_Y REL_RY +#define EVENT_TYPE_GYRO_Z REL_RZ + +#define EVENT_TYPE_PRESSURE REL_X + +#define LSG (1000.0f) + +// conversion of acceleration data to SI units (m/s^2) +#define RANGE_A (2*GRAVITY_EARTH) +#define RESOLUTION_A (GRAVITY_EARTH / LSG) +#define CONVERT_A (GRAVITY_EARTH / LSG) +#define CONVERT_A_X (CONVERT_A) +#define CONVERT_A_Y (CONVERT_A) +#define CONVERT_A_Z (CONVERT_A) + +// conversion of magnetic data to uT units +#define CONVERT_M (1.0f/16.0f) +#define CONVERT_M_X (-CONVERT_M) +#define CONVERT_M_Y (-CONVERT_M) +#define CONVERT_M_Z (CONVERT_M) + +// conversion of gyro data to SI units (radian/sec) +#define RANGE_GYRO (500.0f*(float)M_PI/180.0f) +#define CONVERT_GYRO ((70.0f / 4000.0f) * ((float)M_PI / 180.0f)) +#define CONVERT_GYRO_X (CONVERT_GYRO) +#define CONVERT_GYRO_Y (CONVERT_GYRO) +#define CONVERT_GYRO_Z (CONVERT_GYRO) + +#define SENSOR_STATE_MASK (0x7FFF) + +/*****************************************************************************/ + +__END_DECLS + +#endif // ANDROID_SENSORS_H diff --git a/libsensors/smdk4x12_sensors.c b/libsensors/smdk4x12_sensors.c deleted file mode 100644 index 4cbc7c2..0000000 --- a/libsensors/smdk4x12_sensors.c +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright (C) 2013 Paul Kocialkowski - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define LOG_TAG "smdk4x12_sensors" -#include - -#include "smdk4x12_sensors.h" - -/* - * Sensors list - */ - -struct sensor_t smdk4x12_sensors[] = { - { "LSM330DLC 3-Axis Accelerometer", "STMicroelectronics", 1, SENSOR_TYPE_ACCELEROMETER, - SENSOR_TYPE_ACCELEROMETER, 2 * GRAVITY_EARTH, 0.0096f, 0.23f, 10000, 0, 0, SENSOR_STRING_TYPE_ACCELEROMETER, 0, 0, - SENSOR_FLAG_CONTINUOUS_MODE, {}, }, - { "AKM8975C 3-Axis Magnetic Sensor", "Asahi Kasei", 1, SENSOR_TYPE_MAGNETIC_FIELD, - SENSOR_TYPE_MAGNETIC_FIELD, 2000.0f, 1.0f / 16, 6.8f, 10000, 0, 0, SENSOR_STRING_TYPE_MAGNETIC_FIELD, 0, 0, - SENSOR_FLAG_CONTINUOUS_MODE, {}, }, - { "CM36651 Light Sensor", "Capella", 1, SENSOR_TYPE_LIGHT, - SENSOR_TYPE_LIGHT, 121240.0f, 1.0f, 0.2f, 0, 0, 0, SENSOR_STRING_TYPE_LIGHT, 0, 0, - SENSOR_FLAG_ON_CHANGE_MODE, {}, }, - { "CM36651 Proximity Sensor", "Capella", 1, SENSOR_TYPE_PROXIMITY, - SENSOR_TYPE_PROXIMITY, 8.0f, 8.0f, 1.3f, 0, 0, 0, SENSOR_STRING_TYPE_PROXIMITY, 0, 0, - SENSOR_FLAG_WAKE_UP | SENSOR_FLAG_ON_CHANGE_MODE, {}, }, - { "LSM330DLC Gyroscope Sensor", "STMicroelectronics", 1, SENSOR_TYPE_GYROSCOPE, - SENSOR_TYPE_GYROSCOPE, 500.0f * (3.1415926535f / 180.0f), (70.0f / 4000.0f) * (3.1415926535f / 180.0f), 6.1f, 5000, 0, 0, SENSOR_STRING_TYPE_GYROSCOPE, 0, 0, - SENSOR_FLAG_CONTINUOUS_MODE, {}, }, - { "LPS331AP Pressure Sensor", "STMicroelectronics", 1, SENSOR_TYPE_PRESSURE, - SENSOR_TYPE_PRESSURE, 1260.0f, 1.0f / 4096, 0.045f, 40000, 0, 0, SENSOR_STRING_TYPE_PRESSURE, 0, 20000, - SENSOR_FLAG_CONTINUOUS_MODE, {}, }, -}; - -int smdk4x12_sensors_count = sizeof(smdk4x12_sensors) / sizeof(struct sensor_t); - -struct smdk4x12_sensors_handlers *smdk4x12_sensors_handlers[] = { - &lsm330dlc_acceleration, - &akm8975, - &cm36651_proximity, - &cm36651_light, - &lsm330dlc_gyroscope, - &lps331ap, -}; - -int smdk4x12_sensors_handlers_count = sizeof(smdk4x12_sensors_handlers) / - sizeof(struct smdk4x12_sensors_handlers *); - -/* - * SMDK4x12 Sensors - */ - -int smdk4x12_sensors_activate(struct sensors_poll_device_t *dev, int handle, - int enabled) -{ - struct smdk4x12_sensors_device *device; - int i; - - ALOGD("%s(%p, %d, %d)", __func__, dev, handle, enabled); - - if (dev == NULL) - return -EINVAL; - - device = (struct smdk4x12_sensors_device *) dev; - - if (device->handlers == NULL || device->handlers_count <= 0) - return -EINVAL; - - for (i = 0; i < device->handlers_count; i++) { - if (device->handlers[i] == NULL) - continue; - - if (device->handlers[i]->handle == handle) { - if (enabled && device->handlers[i]->activate != NULL) { - device->handlers[i]->needed |= SMDK4x12_SENSORS_NEEDED_API; - if (device->handlers[i]->needed == SMDK4x12_SENSORS_NEEDED_API) - return device->handlers[i]->activate(device->handlers[i]); - else - return 0; - } else if (!enabled && device->handlers[i]->deactivate != NULL) { - device->handlers[i]->needed &= ~SMDK4x12_SENSORS_NEEDED_API; - if (device->handlers[i]->needed == 0) - return device->handlers[i]->deactivate(device->handlers[i]); - else - return 0; - } - } - } - - return -1; -} - -int smdk4x12_sensors_set_delay(struct sensors_poll_device_t *dev, int handle, - int64_t ns) -{ - struct smdk4x12_sensors_device *device; - int i; - - ALOGD("%s(%p, %d, %" PRId64 ")", __func__, dev, handle, ns); - - if (dev == NULL) - return -EINVAL; - - device = (struct smdk4x12_sensors_device *) dev; - - if (device->handlers == NULL || device->handlers_count <= 0) - return -EINVAL; - - for (i = 0; i < device->handlers_count; i++) { - if (device->handlers[i] == NULL) - continue; - - if (device->handlers[i]->handle == handle && device->handlers[i]->set_delay != NULL) - return device->handlers[i]->set_delay(device->handlers[i], ns); - } - - return 0; -} - -int smdk4x12_sensors_poll(struct sensors_poll_device_t *dev, - struct sensors_event_t* data, int count) -{ - struct smdk4x12_sensors_device *device; - int i, j; - int c, n; - int poll_rc, rc; - -// ALOGD("%s(%p, %p, %d)", __func__, dev, data, count); - - if (dev == NULL) - return -EINVAL; - - device = (struct smdk4x12_sensors_device *) dev; - - if (device->handlers == NULL || device->handlers_count <= 0 || - device->poll_fds == NULL || device->poll_fds_count <= 0) - return -EINVAL; - - n = 0; - - do { - poll_rc = poll(device->poll_fds, device->poll_fds_count, n > 0 ? 0 : -1); - if (poll_rc < 0) - return -1; - - for (i = 0; i < device->poll_fds_count; i++) { - if (!(device->poll_fds[i].revents & POLLIN)) - continue; - - for (j = 0; j < device->handlers_count; j++) { - if (device->handlers[j] == NULL || device->handlers[j]->poll_fd != device->poll_fds[i].fd || device->handlers[j]->get_data == NULL) - continue; - - rc = device->handlers[j]->get_data(device->handlers[j], &data[n]); - if (rc < 0) { - device->poll_fds[i].revents = 0; - poll_rc = -1; - } else { - n++; - count--; - } - } - } - } while ((poll_rc > 0 || n < 1) && count > 0); - - return n; -} - -/* - * Interface - */ - -int smdk4x12_sensors_close(hw_device_t *device) -{ - struct smdk4x12_sensors_device *smdk4x12_sensors_device; - int i; - - ALOGD("%s(%p)", __func__, device); - - if (device == NULL) - return -EINVAL; - - smdk4x12_sensors_device = (struct smdk4x12_sensors_device *) device; - - if (smdk4x12_sensors_device->poll_fds != NULL) - free(smdk4x12_sensors_device->poll_fds); - - for (i = 0; i < smdk4x12_sensors_device->handlers_count; i++) { - if (smdk4x12_sensors_device->handlers[i] == NULL || smdk4x12_sensors_device->handlers[i]->deinit == NULL) - continue; - - smdk4x12_sensors_device->handlers[i]->deinit(smdk4x12_sensors_device->handlers[i]); - } - - free(device); - - return 0; -} - -int smdk4x12_sensors_open(const struct hw_module_t* module, const char *id, - struct hw_device_t** device) -{ - struct smdk4x12_sensors_device *smdk4x12_sensors_device; - int p, i; - - ALOGD("%s(%p, %s, %p)", __func__, module, id, device); - - if (module == NULL || device == NULL) - return -EINVAL; - - smdk4x12_sensors_device = (struct smdk4x12_sensors_device *) - calloc(1, sizeof(struct smdk4x12_sensors_device)); - smdk4x12_sensors_device->device.common.tag = HARDWARE_DEVICE_TAG; - smdk4x12_sensors_device->device.common.version = 0; - smdk4x12_sensors_device->device.common.module = (struct hw_module_t *) module; - smdk4x12_sensors_device->device.common.close = smdk4x12_sensors_close; - smdk4x12_sensors_device->device.activate = smdk4x12_sensors_activate; - smdk4x12_sensors_device->device.setDelay = smdk4x12_sensors_set_delay; - smdk4x12_sensors_device->device.poll = smdk4x12_sensors_poll; - smdk4x12_sensors_device->handlers = smdk4x12_sensors_handlers; - smdk4x12_sensors_device->handlers_count = smdk4x12_sensors_handlers_count; - smdk4x12_sensors_device->poll_fds = (struct pollfd *) - calloc(1, smdk4x12_sensors_handlers_count * sizeof(struct pollfd)); - - p = 0; - for (i = 0; i < smdk4x12_sensors_handlers_count; i++) { - if (smdk4x12_sensors_handlers[i] == NULL || smdk4x12_sensors_handlers[i]->init == NULL) - continue; - - smdk4x12_sensors_handlers[i]->init(smdk4x12_sensors_handlers[i], smdk4x12_sensors_device); - if (smdk4x12_sensors_handlers[i]->poll_fd >= 0) { - smdk4x12_sensors_device->poll_fds[p].fd = smdk4x12_sensors_handlers[i]->poll_fd; - smdk4x12_sensors_device->poll_fds[p].events = POLLIN; - p++; - } - } - - smdk4x12_sensors_device->poll_fds_count = p; - - *device = &(smdk4x12_sensors_device->device.common); - - return 0; -} - -int smdk4x12_sensors_get_sensors_list(struct sensors_module_t* module, - const struct sensor_t **sensors_p) -{ - ALOGD("%s(%p, %p)", __func__, module, sensors_p); - - if (sensors_p == NULL) - return -EINVAL; - - *sensors_p = smdk4x12_sensors; - return smdk4x12_sensors_count; -} - -struct hw_module_methods_t smdk4x12_sensors_module_methods = { - .open = smdk4x12_sensors_open, -}; - -struct sensors_module_t HAL_MODULE_INFO_SYM = { - .common = { - .tag = HARDWARE_MODULE_TAG, - .version_major = 1, - .version_minor = 0, - .id = SENSORS_HARDWARE_MODULE_ID, - .name = "SMDK4x12 Sensors", - .author = "Paul Kocialkowski", - .methods = &smdk4x12_sensors_module_methods, - }, - .get_sensors_list = smdk4x12_sensors_get_sensors_list, -}; diff --git a/libsensors/smdk4x12_sensors.h b/libsensors/smdk4x12_sensors.h deleted file mode 100644 index 7100334..0000000 --- a/libsensors/smdk4x12_sensors.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2013 Paul Kocialkowski - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#define __STDC_FORMAT_MACROS -#include - -#include -#include - -#ifndef _SMDK4x12_SENSORS_H_ -#define _SMDK4x12_SENSORS_H_ - -#define SMDK4x12_SENSORS_NEEDED_API (1 << 0) - -struct smdk4x12_sensors_device; - -struct smdk4x12_sensors_handlers { - char *name; - int handle; - - int (*init)(struct smdk4x12_sensors_handlers *handlers, - struct smdk4x12_sensors_device *device); - int (*deinit)(struct smdk4x12_sensors_handlers *handlers); - int (*activate)(struct smdk4x12_sensors_handlers *handlers); - int (*deactivate)(struct smdk4x12_sensors_handlers *handlers); - int (*set_delay)(struct smdk4x12_sensors_handlers *handlers, - int64_t delay); - int (*get_data)(struct smdk4x12_sensors_handlers *handlers, - struct sensors_event_t *event); - - int activated; - int needed; - int poll_fd; - - void *data; -}; - -struct smdk4x12_sensors_device { - struct sensors_poll_device_t device; - - struct smdk4x12_sensors_handlers **handlers; - int handlers_count; - - struct pollfd *poll_fds; - int poll_fds_count; -}; - -extern struct smdk4x12_sensors_handlers *smdk4x12_sensors_handlers[]; -extern int smdk4x12_sensors_handlers_count; - -int smdk4x12_sensors_activate(struct sensors_poll_device_t *dev, int handle, - int enabled); -int smdk4x12_sensors_set_delay(struct sensors_poll_device_t *dev, int handle, - int64_t ns); -int smdk4x12_sensors_poll(struct sensors_poll_device_t *dev, - struct sensors_event_t* data, int count); - -/* - * Input - */ - -void input_event_set(struct input_event *event, int type, int code, int value); -int64_t timestamp(struct timeval *time); -int64_t input_timestamp(struct input_event *event); -int uinput_rel_create(const char *name); -void uinput_destroy(int uinput_fd); -int input_open(char *name); -int sysfs_path_prefix(char *name, char *path_prefix); -int64_t sysfs_value_read(char *path); -int sysfs_value_write(char *path, int64_t value); -int sysfs_string_read(char *path, char *buffer, size_t length); -int sysfs_string_write(char *path, char *buffer, size_t length); - -/* - * Sensors - */ - -extern struct smdk4x12_sensors_handlers lsm330dlc_acceleration; -extern struct smdk4x12_sensors_handlers akm8975; -extern struct smdk4x12_sensors_handlers cm36651_proximity; -extern struct smdk4x12_sensors_handlers cm36651_light; -extern struct smdk4x12_sensors_handlers lsm330dlc_gyroscope; -extern struct smdk4x12_sensors_handlers lps331ap; - -#endif -- cgit v1.1 From 2e3a8c5b3a2e9f091e3f7c75bd4c3cdd8f5ebd17 Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Sat, 5 Mar 2016 22:39:56 +1100 Subject: i9300: update proprietary-files.txt Change-Id: I0dd459bbce11d4f1f11194adb9702dbebfce0ed9 --- proprietary-files.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/proprietary-files.txt b/proprietary-files.txt index ac24b1c..b021eee 100644 --- a/proprietary-files.txt +++ b/proprietary-files.txt @@ -1,5 +1,4 @@ system/bin/glgps -system/lib/hw/sensors.smdk4x12.so system/lib/hw/gps.exynos4.so:system/lib/hw/gps.tegra3.so system/lib/libakm.so system/lib/libsec-ril.so -- cgit v1.1 From c6f16d5c1fc1a803cba6674cc0d67156c222efec Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Sun, 6 Mar 2016 10:29:23 +1100 Subject: i9300: libsensors: fix a couple of poll_delay derps Change-Id: I6a6e307588e1d9a0c56895d4dc6a1702066b6059 --- libsensors/AccelSensor.cpp | 2 +- libsensors/ProximitySensor.cpp | 14 ++------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/libsensors/AccelSensor.cpp b/libsensors/AccelSensor.cpp index 1a5510c..fddb2cd 100644 --- a/libsensors/AccelSensor.cpp +++ b/libsensors/AccelSensor.cpp @@ -107,7 +107,7 @@ int AccelSensor::setDelay(int32_t handle, int64_t ns) ns = 10000000; // Minimum on stock } - strcpy(&input_sysfs_path[input_sysfs_path_len], "acc_poll_delay"); + strcpy(&input_sysfs_path[input_sysfs_path_len], "poll_delay"); fd = open(input_sysfs_path, O_RDWR); if (fd >= 0) { char buf[80]; diff --git a/libsensors/ProximitySensor.cpp b/libsensors/ProximitySensor.cpp index 2ba56c1..9e5d7d1 100644 --- a/libsensors/ProximitySensor.cpp +++ b/libsensors/ProximitySensor.cpp @@ -73,18 +73,8 @@ int ProximitySensor::setInitialState() { int ProximitySensor::setDelay(int32_t handle, int64_t ns) { - int fd; - - strcpy(&input_sysfs_path[input_sysfs_path_len], "prox_poll_delay"); - fd = open(input_sysfs_path, O_RDWR); - if (fd >= 0) { - char buf[80]; - sprintf(buf, "%lld", ns); - write(fd, buf, strlen(buf)+1); - close(fd); - return 0; - } - return -1; + // unsupported + return 0; } int ProximitySensor::enable(int32_t handle, int en) { -- cgit v1.1 From 276ec04ef3b865d3aaf6a1b8a07f791a0213c9c4 Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Sat, 20 Feb 2016 22:06:57 +1100 Subject: i9300: enable auto power modes * We don't have a significant motion sensor, so device idle detection will be disabled[1] * Enabling this will allow app standby to be enabled, so there's no harm in doing it. [1]: https://github.com/CyanogenMod/android_frameworks_base/blob/cm-13.0/services/core/java/com/android/server/DeviceIdleController.java#L1435 Change-Id: Ia23a577ed0e6ae344da0836232dd2ed21d8a867d --- overlay/frameworks/base/core/res/res/values/config.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml index 9441f8b..3a1c60b 100644 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -332,4 +332,13 @@ format is UMTS|LTE|... --> GPRS|EDGE|WCDMA + + + true -- cgit v1.1 From 1ea8f299e6b9c46eea55a9fa6ebee88faf91220e Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Mon, 7 Mar 2016 21:47:04 +1100 Subject: libsensors: don't floor accelerometer value this is a leftover from t0, here it causes broken autorotate and slow response times on the lockscreen Change-Id: I30d682a65447d7f846d277ca4f9b63315b2ca526 --- libsensors/AccelSensor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsensors/AccelSensor.cpp b/libsensors/AccelSensor.cpp index fddb2cd..d5040c1 100644 --- a/libsensors/AccelSensor.cpp +++ b/libsensors/AccelSensor.cpp @@ -111,7 +111,7 @@ int AccelSensor::setDelay(int32_t handle, int64_t ns) fd = open(input_sysfs_path, O_RDWR); if (fd >= 0) { char buf[80]; - sprintf(buf, "%lld", ns / 10000000 * 10); // Some flooring to match stock value + sprintf(buf, "%lld", ns); write(fd, buf, strlen(buf)+1); close(fd); return 0; -- cgit v1.1 From 6eaec4905ca050b6eff728c40e81186b194a59d5 Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Sat, 12 Mar 2016 21:58:06 +1100 Subject: i9300: libsensors: use CLOCK_BOOTTIME, not CLOCK_MONOTONIC Change-Id: Ib3d5596e694ff553ed843cc7ff3525c73944ef6c --- libsensors/SensorBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsensors/SensorBase.cpp b/libsensors/SensorBase.cpp index f08ffb7..3790f81 100644 --- a/libsensors/SensorBase.cpp +++ b/libsensors/SensorBase.cpp @@ -86,7 +86,7 @@ bool SensorBase::hasPendingEvents() const { int64_t SensorBase::getTimestamp() { struct timespec t; t.tv_sec = t.tv_nsec = 0; - clock_gettime(CLOCK_MONOTONIC, &t); + clock_gettime(CLOCK_BOOTTIME, &t); return int64_t(t.tv_sec)*1000000000LL + t.tv_nsec; } -- cgit v1.1 From 258dde57636ccaf8ec013915fe131aa7803e074a Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Fri, 18 Mar 2016 23:03:14 +1100 Subject: i9300: more memory tweaks some users are seeing OOMs. Enable KSM, bump up zram and be more aggressive about swapping. Some of these values are taken from "Android Memory Tuning": https://01.org/android-ia/user-guides/android-memory-tuning-android-5.0-and-5.1 Change-Id: Id950c473a5de29bb0e1e2f0a1d3602ddb982e663 --- rootdir/fstab.smdk4x12 | 2 +- rootdir/init.target.rc | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/rootdir/fstab.smdk4x12 b/rootdir/fstab.smdk4x12 index 8c2e87d..ba27ca6 100644 --- a/rootdir/fstab.smdk4x12 +++ b/rootdir/fstab.smdk4x12 @@ -20,4 +20,4 @@ /dev/block/mmcblk0p7 /modem emmc defaults recoveryonly # zram -/dev/block/zram0 none swap defaults zramsize=268435456 +/dev/block/zram0 none swap defaults zramsize=419430400 diff --git a/rootdir/init.target.rc b/rootdir/init.target.rc index d17fc69..5e4890f 100644 --- a/rootdir/init.target.rc +++ b/rootdir/init.target.rc @@ -34,6 +34,22 @@ on init chown system system /sys/devices/system/cpu/cpufreq/pegasusq/max_cpu_lock chown system system /sys/devices/system/cpu/cpufreq/pegasusq/sampling_rate +on boot + # Flash storage isn't a good entropy source, and only causes + # locking overhead in the kernel. Turn it off. + write /sys/block/mmcblk0/queue/add_random 0 + write /sys/block/mmcblk1/queue/add_random 0 + + # KSM + write /sys/kernel/mm/ksm/deferred_timer 1 + write /sys/kernel/mm/ksm/pages_to_scan 100 + write /sys/kernel/mm/ksm/sleep_millisecs 500 + write /sys/kernel/mm/ksm/run 1 + + # Swapping 1 page at a time is ok + write /proc/sys/vm/page-cluster 0 + + write /proc/sys/vm/swappiness 100 -- cgit v1.1 From 169608c87e18267ce9f5fd7fc12a754def1fda43 Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Tue, 22 Mar 2016 22:05:57 +1100 Subject: i9300: disable ksm * this seems to exacerbate certain issues with HW video en/decoding * disable it to see if things improve Change-Id: Ibacc7dc99c217832b56a47a738d57882997d8da0 --- rootdir/init.target.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootdir/init.target.rc b/rootdir/init.target.rc index 5e4890f..d7494ac 100644 --- a/rootdir/init.target.rc +++ b/rootdir/init.target.rc @@ -44,7 +44,7 @@ on boot write /sys/kernel/mm/ksm/deferred_timer 1 write /sys/kernel/mm/ksm/pages_to_scan 100 write /sys/kernel/mm/ksm/sleep_millisecs 500 - write /sys/kernel/mm/ksm/run 1 + write /sys/kernel/mm/ksm/run 0 # Swapping 1 page at a time is ok write /proc/sys/vm/page-cluster 0 -- cgit v1.1 From e292f77eff94cfb47673ff8bc6aaceaf9733d532 Mon Sep 17 00:00:00 2001 From: Wolfgang Wiedmeyer Date: Fri, 25 Mar 2016 20:51:06 +0100 Subject: selinux: allow to write the firmware files from recovery mode Change-Id: I061c9d67b171099a3c5cf21c5961e15a2bc114fc Signed-off-by: Wolfgang Wiedmeyer --- selinux/recovery.te | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 selinux/recovery.te diff --git a/selinux/recovery.te b/selinux/recovery.te new file mode 100644 index 0000000..531f480 --- /dev/null +++ b/selinux/recovery.te @@ -0,0 +1,7 @@ +recovery_only(` + +# firmware files +allow recovery firmware_exynos:dir { create setattr relabelto relabelfrom }; +allow recovery firmware_exynos:file { create write open setattr relabelto relabelfrom }; +allow recovery firmware_mfc:file { create write open setattr relabelto relabelfrom }; +') -- cgit v1.1 From 474b2c14ad9f3ee7f3063354d952d32d3d86e7f0 Mon Sep 17 00:00:00 2001 From: Ziyan Date: Fri, 8 Jan 2016 17:57:59 +0100 Subject: init: increase read-ahead value to 256 kb Apps and database file sizes have increased in recent Android versions, which makes it practical to increase our read-ahead value from 128 kb. General user experience seem to have improved a bit. Change-Id: I35788444a8552a8f376c699ead163e951ed06b30 --- rootdir/init.target.rc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rootdir/init.target.rc b/rootdir/init.target.rc index d7494ac..55c7369 100644 --- a/rootdir/init.target.rc +++ b/rootdir/init.target.rc @@ -51,7 +51,8 @@ on boot write /proc/sys/vm/swappiness 100 - + # increase read-ahead value to 256 kb + write /sys/block/mmcblk0/queue/read_ahead_kb 256 on post-fs-data # icd -- cgit v1.1 From d04b5650aa7fcf9999c7c62b477f231a3d3534d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20M=C4=83ce=C8=99?= Date: Sun, 6 Dec 2015 13:04:34 -0500 Subject: Use 2 zRAM compression streams (now that our driver can) Change-Id: I84f26a40e5b89d100b5a1fd2eab1ba59e5957750 --- rootdir/fstab.smdk4x12 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootdir/fstab.smdk4x12 b/rootdir/fstab.smdk4x12 index ba27ca6..6c86c30 100644 --- a/rootdir/fstab.smdk4x12 +++ b/rootdir/fstab.smdk4x12 @@ -20,4 +20,4 @@ /dev/block/mmcblk0p7 /modem emmc defaults recoveryonly # zram -/dev/block/zram0 none swap defaults zramsize=419430400 +/dev/block/zram0 none swap defaults zramsize=419430400,zramstreams=2 -- cgit v1.1 From 81ec5d14e7e2bfa78d6967a51b04822d4e646398 Mon Sep 17 00:00:00 2001 From: H4RTI3 Date: Thu, 15 Sep 2016 23:30:25 +0200 Subject: Added SELinux rule for nfc QS tile Change-Id: I5f80a383b0e72bcbc86bf51bd935149ee981ac86 --- selinux/platform_app.te | 1 + 1 file changed, 1 insertion(+) create mode 100755 selinux/platform_app.te diff --git a/selinux/platform_app.te b/selinux/platform_app.te new file mode 100755 index 0000000..4d92e6b --- /dev/null +++ b/selinux/platform_app.te @@ -0,0 +1 @@ +allow platform_app nfc_service:service_manager find; -- cgit v1.1 From 8d6104a1b32497db2a73885129fcc3adaced9a80 Mon Sep 17 00:00:00 2001 From: Zhao Wei Liew Date: Fri, 18 Nov 2016 17:54:08 +0800 Subject: i9300: Remove enhanced NFC feature This is no longer used anywhere. Change-Id: Iaabfaec2d7c734b5f286f3dc4ef651d93b2f2bc8 --- i9300.mk | 2 -- 1 file changed, 2 deletions(-) diff --git a/i9300.mk b/i9300.mk index 8a2c01a..a0303d8 100644 --- a/i9300.mk +++ b/i9300.mk @@ -96,8 +96,6 @@ PRODUCT_COPY_FILES += \ PRODUCT_PACKAGES += \ com.android.nfc_extras -$(call inherit-product, vendor/cm/config/nfc_enhanced.mk) - # RIL PRODUCT_PROPERTY_OVERRIDES += \ ro.telephony.ril_class=SamsungExynos4RIL \ -- cgit v1.1 From 25eedce86d2723b23b6fc21dece20540f7ec68c0 Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Sat, 3 Dec 2016 15:39:49 +1100 Subject: i9300: use OTA as misc seems unused Change-Id: Ifa9fbf490e7af4791796c285511b4fac51208115 (cherry picked from commit f64986b2dbf2b0c01a961ff9343e750c6120b9ca) --- rootdir/fstab.smdk4x12 | 1 + 1 file changed, 1 insertion(+) diff --git a/rootdir/fstab.smdk4x12 b/rootdir/fstab.smdk4x12 index 6c86c30..dba5118 100644 --- a/rootdir/fstab.smdk4x12 +++ b/rootdir/fstab.smdk4x12 @@ -9,6 +9,7 @@ /dev/block/mmcblk0p10 /preload ext4 noatime,nosuid,nodev,journal_async_commit wait /dev/block/mmcblk0p12 /data f2fs noatime,discard,inline_xattr,inline_data,nosuid,nodev wait,check,encryptable=footer /dev/block/mmcblk0p12 /data ext4 noatime,nosuid,nodev,noauto_da_alloc,journal_async_commit,errors=panic wait,check,encryptable=footer +/dev/block/platform/dw_mmc/by-name/OTA /misc emmc defaults defaults # vold-managed volumes ("block device" is actually a sysfs devpath) /devices/platform/s3c-sdhci.2/mmc_host/mmc1* /storage/sdcard1 auto defaults voldmanaged=sdcard1:auto,encryptable=userdata -- cgit v1.1