diff options
| author | JP Abgrall <jpa@google.com> | 2013-09-03 17:52:22 -0700 |
|---|---|---|
| committer | JP Abgrall <jpa@google.com> | 2013-09-03 18:19:20 -0700 |
| commit | e6d9ab28b4f4e7684f6c07874ee819c9ea0002a2 (patch) | |
| tree | 4305cdfa0095ab729bcee76d166d2668d873e338 | |
| parent | 9b98ed996e18d6097c9976c9cfe9a0c9397998fe (diff) | |
| download | platform_hardware_invensense-idea133.tar.gz platform_hardware_invensense-idea133.tar.bz2 platform_hardware_invensense-idea133.zip | |
Remove unused GPL'd files (simple_apps, mpu.h)android-sdk-4.4.2_r1.0.1android-sdk-4.4.2_r1android-cts-4.4_r4android-cts-4.4_r1android-4.4w_r1android-4.4_r1.2.0.1android-4.4_r1.2android-4.4_r1.1.0.1android-4.4_r1.1android-4.4_r1.0.1android-4.4_r1android-4.4_r0.9android-4.4_r0.8android-4.4_r0.7android-4.4.4_r2.0.1android-4.4.4_r2android-4.4.4_r1.0.1android-4.4.4_r1android-4.4.3_r1.1.0.1android-4.4.3_r1.1android-4.4.3_r1.0.1android-4.4.3_r1android-4.4.2_r2.0.1android-4.4.2_r2android-4.4.2_r1.0.1android-4.4.2_r1android-4.4.1_r1.0.1android-4.4.1_r1kitkat-wearkitkat-releasekitkat-mr2.2-releasekitkat-mr2.1-releasekitkat-mr2-releasekitkat-mr1.1-releasekitkat-mr1-releasekitkat-devkitkat-cts-releasekitkat-cts-devidea133
The libsensors/* and mlsdk/* files reference an mpu.h which
is mlsdk/**/mpu.h that is not GPL.
Bug: 10612505
Change-Id: I15b4f883247d49c86cf5bcfad48315ee37ebb50d
51 files changed, 0 insertions, 11037 deletions
diff --git a/60xx/libsensors_iio/software/core/driver/include/linux/mpu.h b/60xx/libsensors_iio/software/core/driver/include/linux/mpu.h deleted file mode 100644 index 4391226..0000000 --- a/60xx/libsensors_iio/software/core/driver/include/linux/mpu.h +++ /dev/null @@ -1,108 +0,0 @@ -/* -* Copyright (C) 2012 Invensense, Inc. -* -* This software is licensed under the terms of the GNU General Public -* License version 2, as published by the Free Software Foundation, and -* may be copied, distributed, and modified under those terms. -* -* 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. -* -*/ - -/** - * @addtogroup DRIVERS - * @brief Hardware drivers. - * - * @{ - * @file mpu.h - * @brief mpu definition - */ - -#ifndef __MPU_H_ -#define __MPU_H_ - -#ifdef __KERNEL__ -#include <linux/types.h> -#include <linux/ioctl.h> -#endif - -enum secondary_slave_type { - SECONDARY_SLAVE_TYPE_NONE, - SECONDARY_SLAVE_TYPE_ACCEL, - SECONDARY_SLAVE_TYPE_COMPASS, - SECONDARY_SLAVE_TYPE_PRESSURE, - - SECONDARY_SLAVE_TYPE_TYPES -}; - -enum ext_slave_id { - ID_INVALID = 0, - GYRO_ID_MPU3050, - GYRO_ID_MPU6050A2, - GYRO_ID_MPU6050B1, - GYRO_ID_MPU6050B1_NO_ACCEL, - GYRO_ID_ITG3500, - - ACCEL_ID_LIS331, - ACCEL_ID_LSM303DLX, - ACCEL_ID_LIS3DH, - ACCEL_ID_KXSD9, - ACCEL_ID_KXTF9, - ACCEL_ID_BMA150, - ACCEL_ID_BMA222, - ACCEL_ID_BMA250, - ACCEL_ID_ADXL34X, - ACCEL_ID_MMA8450, - ACCEL_ID_MMA845X, - ACCEL_ID_MPU6050, - - COMPASS_ID_AK8963, - COMPASS_ID_AK8975, - COMPASS_ID_AK8972, - COMPASS_ID_AMI30X, - COMPASS_ID_AMI306, - COMPASS_ID_YAS529, - COMPASS_ID_YAS530, - COMPASS_ID_HMC5883, - COMPASS_ID_LSM303DLH, - COMPASS_ID_LSM303DLM, - COMPASS_ID_MMC314X, - COMPASS_ID_HSCDTD002B, - COMPASS_ID_HSCDTD004A, - - PRESSURE_ID_BMA085, -}; - -#define INV_PROD_KEY(ver, rev) (ver * 100 + rev) -/** - * struct mpu_platform_data - Platform data for the mpu driver - * @int_config: Bits [7:3] of the int config register. - * @level_shifter: 0: VLogic, 1: VDD - * @orientation: Orientation matrix of the gyroscope - * @sec_slave_type: secondary slave device type, can be compass, accel, etc - * @sec_slave_id: id of the secondary slave device - * @secondary_i2c_address: secondary device's i2c address - * @secondary_orientation: secondary device's orientation matrix - * @key: key for MPL library. - * - * Contains platform specific information on how to configure the MPU3050 to - * work on this platform. The orientation matricies are 3x3 rotation matricies - * that are applied to the data to rotate from the mounting orientation to the - * platform orientation. The values must be one of 0, 1, or -1 and each row and - * column should have exactly 1 non-zero value. - */ -struct mpu_platform_data { - __u8 int_config; - __u8 level_shifter; - __s8 orientation[9]; - enum secondary_slave_type sec_slave_type; - enum ext_slave_id sec_slave_id; - __u16 secondary_i2c_addr; - __s8 secondary_orientation[9]; - __u8 key[16]; -}; - -#endif /* __MPU_H_ */ diff --git a/60xx/libsensors_iio/software/simple_apps/gesture_test/build/android/inv_gesture_test-shared b/60xx/libsensors_iio/software/simple_apps/gesture_test/build/android/inv_gesture_test-shared Binary files differdeleted file mode 100644 index 7635cd8..0000000 --- a/60xx/libsensors_iio/software/simple_apps/gesture_test/build/android/inv_gesture_test-shared +++ /dev/null diff --git a/60xx/libsensors_iio/software/simple_apps/gesture_test/build/android/shared.mk b/60xx/libsensors_iio/software/simple_apps/gesture_test/build/android/shared.mk deleted file mode 100644 index 7655e4d..0000000 --- a/60xx/libsensors_iio/software/simple_apps/gesture_test/build/android/shared.mk +++ /dev/null @@ -1,95 +0,0 @@ -EXEC = inv_gesture_test$(SHARED_APP_SUFFIX) - -MK_NAME = $(notdir $(CURDIR)/$(firstword $(MAKEFILE_LIST))) - -CROSS ?= $(ANDROID_ROOT)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- -COMP ?= $(CROSS)gcc -LINK ?= $(CROSS)gcc - -OBJFOLDER = $(CURDIR)/obj - -INV_ROOT = ../../../../.. -APP_DIR = $(CURDIR)/../.. -MLLITE_DIR = $(INV_ROOT)/software/core/mllite -MPL_DIR = $(INV_ROOT)/software/core/mpl - -include $(INV_ROOT)/software/build/android/common.mk - -CFLAGS += $(CMDLINE_CFLAGS) -CFLAGS += -Wall -CFLAGS += -fpic -CFLAGS += -nostdlib -CFLAGS += -DNDEBUG -CFLAGS += -D_REENTRANT -CFLAGS += -DLINUX -CFLAGS += -DANDROID -CFLAGS += -mthumb-interwork -CFLAGS += -fno-exceptions -CFLAGS += -ffunction-sections -CFLAGS += -funwind-tables -CFLAGS += -fstack-protector -CFLAGS += -fno-short-enums -CFLAGS += -fmessage-length=0 -CFLAGS += -I$(MLLITE_DIR) -CFLAGS += -I$(MPL_DIR) -CFLAGS += -I$(COMMON_DIR) -CFLAGS += -I$(HAL_DIR)/include -CFLAGS += $(INV_INCLUDES) -CFLAGS += $(INV_DEFINES) - -LLINK = -lc -LLINK += -lm -LLINK += -lutils -LLINK += -lcutils -LLINK += -lgcc -LLINK += -ldl -LLINK += -lstdc++ -LLINK += -llog -LLINK += -lz - -LFLAGS += $(CMDLINE_LFLAGS) -LFLAGS += $(ANDROID_LINK_EXECUTABLE) - -LRPATH = -Wl,-rpath,$(ANDROID_ROOT)/out/target/product/$(PRODUCT)/obj/lib:$(ANDROID_ROOT)/out/target/product/$(PRODUCT)/system/lib - -#################################################################################################### -## sources - -INV_LIBS = $(MPL_DIR)/build/$(TARGET)/$(LIB_PREFIX)$(MPL_LIB_NAME).$(SHARED_LIB_EXT) -INV_LIBS += $(MLLITE_DIR)/build/$(TARGET)/$(LIB_PREFIX)$(MLLITE_LIB_NAME).$(SHARED_LIB_EXT) - -#INV_SOURCES and VPATH provided by Makefile.filelist -include ../filelist.mk - -INV_OBJS := $(addsuffix .o,$(INV_SOURCES)) -INV_OBJS_DST = $(addprefix $(OBJFOLDER)/,$(addsuffix .o, $(notdir $(INV_SOURCES)))) - -#################################################################################################### -## rules - -.PHONY: all clean cleanall install - -all: $(EXEC) $(MK_NAME) - -$(EXEC) : $(OBJFOLDER) $(INV_OBJS_DST) $(INV_LIBS) $(MK_NAME) - @$(call echo_in_colors, "\n<linking $(EXEC) with objects $(INV_OBJS_DST) $(PREBUILT_OBJS) and libraries $(INV_LIBS)\n") - $(LINK) $(INV_OBJS_DST) -o $(EXEC) $(LFLAGS) $(LLINK) $(INV_LIBS) $(LLINK) $(LRPATH) - -$(OBJFOLDER) : - @$(call echo_in_colors, "\n<creating object's folder 'obj/'>\n") - mkdir obj - -$(INV_OBJS_DST) : $(OBJFOLDER)/%.c.o : %.c $(MK_NAME) - @$(call echo_in_colors, "\n<compile $< to $(OBJFOLDER)/$(notdir $@)>\n") - $(COMP) $(ANDROID_INCLUDES) $(KERNEL_INCLUDES) $(INV_INCLUDES) $(CFLAGS) -o $@ -c $< - -clean : - rm -fR $(OBJFOLDER) - -cleanall : - rm -fR $(EXEC) $(OBJFOLDER) - -install : $(EXEC) - cp -f $(EXEC) $(INSTALL_DIR) - - diff --git a/60xx/libsensors_iio/software/simple_apps/gesture_test/build/filelist.mk b/60xx/libsensors_iio/software/simple_apps/gesture_test/build/filelist.mk deleted file mode 100644 index 75d93cf..0000000 --- a/60xx/libsensors_iio/software/simple_apps/gesture_test/build/filelist.mk +++ /dev/null @@ -1,11 +0,0 @@ -#### filelist.mk for inv_gesture_test #### - -# headers -#HEADERS += - -# sources -SOURCES := $(APP_DIR)/inv_gesture_test.c - -INV_SOURCES += $(SOURCES) - -VPATH += $(APP_DIR) diff --git a/60xx/libsensors_iio/software/simple_apps/gesture_test/inv_gesture_test.c b/60xx/libsensors_iio/software/simple_apps/gesture_test/inv_gesture_test.c deleted file mode 100644 index d38d478..0000000 --- a/60xx/libsensors_iio/software/simple_apps/gesture_test/inv_gesture_test.c +++ /dev/null @@ -1,535 +0,0 @@ -/** - * Gesture Test application for Invensense's MPU6/9xxx (w/ DMP). - */ - -#include <unistd.h> -#include <dirent.h> -#include <fcntl.h> -#include <stdio.h> -#include <errno.h> -#include <sys/stat.h> -#include <stdlib.h> -#include <features.h> -#include <dirent.h> -#include <string.h> -#include <poll.h> -#include <stddef.h> -#include <linux/input.h> -#include <time.h> -#include <linux/time.h> -#include <unistd.h> -#include <termios.h> - -#include "invensense.h" -#include "ml_math_func.h" -#include "storage_manager.h" -#include "ml_stored_data.h" -#include "ml_sysfs_helper.h" - -#define DEBUG_PRINT /* Uncomment to print Gyro & Accel read from Driver */ - -#define MAX_SYSFS_NAME_LEN (100) -#define MAX_SYSFS_ATTRB (sizeof(struct sysfs_attrbs) / sizeof(char*)) - -#define FLICK_UPPER_THRES 3147790 -#define FLICK_LOWER_THRES -3147790 -#define FLICK_COUNTER 50 -#define POLL_TIME 2000 // 2sec - -#define FALSE 0 -#define TRUE 1 - -char *sysfs_names_ptr; - -struct sysfs_attrbs { - char *enable; - char *power_state; - char *dmp_on; - char *dmp_int_on; - char *self_test; - char *dmp_firmware; - char *firmware_loaded; - char *display_orientation_on; - char *orientation_on; - char *event_flick; - char *event_display_orientation; - char *event_orientation; - char *event_tap; - char *flick_axis; - char *flick_counter; - char *flick_int_on; - char *flick_lower; - char *flick_upper; - char *flick_message_on; - char *tap_min_count; - char *tap_on; - char *tap_threshold; - char *tap_time; -} mpu; - -enum { - tap, - flick, - gOrient, - orient, - numDMPFeatures -}; - -struct pollfd pfd[numDMPFeatures]; - -/******************************************************************************* - * DMP Feature Supported Functions - ******************************************************************************/ - -int read_sysfs_int(char *filename, int *var) -{ - int res=0; - FILE *fp; - - fp = fopen(filename, "r"); - if (fp!=NULL) { - fscanf(fp, "%d\n", var); - fclose(fp); - } else { - MPL_LOGE("ERR open file to read"); - res= -1; - } - return res; -} - -int write_sysfs_int(char *filename, int data) -{ - int res=0; - FILE *fp; - - fp = fopen(filename, "w"); - if (fp!=NULL) { - fprintf(fp, "%d\n", data); - fclose(fp); - } else { - MPL_LOGE("ERR open file to write"); - res= -1; - } - return res; -} - -/************************************************** - This _kbhit() function is courtesy from Web -***************************************************/ -int _kbhit() { - static const int STDIN = 0; - static bool initialized = false; - - if (! initialized) { - // Use termios to turn off line buffering - struct termios term; - tcgetattr(STDIN, &term); - term.c_lflag &= ~ICANON; - tcsetattr(STDIN, TCSANOW, &term); - setbuf(stdin, NULL); - initialized = true; - } - - int bytesWaiting; - ioctl(STDIN, FIONREAD, &bytesWaiting); - return bytesWaiting; -} - -int inv_init_sysfs_attributes(void) -{ - unsigned char i = 0; - char sysfs_path[MAX_SYSFS_NAME_LEN]; - char *sptr; - char **dptr; - - sysfs_names_ptr = - (char*)malloc(sizeof(char[MAX_SYSFS_ATTRB][MAX_SYSFS_NAME_LEN])); - sptr = sysfs_names_ptr; - if (sptr != NULL) { - dptr = (char**)&mpu; - do { - *dptr++ = sptr; - sptr += sizeof(char[MAX_SYSFS_NAME_LEN]); - } while (++i < MAX_SYSFS_ATTRB); - } else { - MPL_LOGE("couldn't alloc mem for sysfs paths"); - return -1; - } - - // get proper (in absolute/relative) IIO path & build MPU's sysfs paths - inv_get_sysfs_path(sysfs_path); - - sprintf(mpu.enable, "%s%s", sysfs_path, "/buffer/enable"); - sprintf(mpu.power_state, "%s%s", sysfs_path, "/power_state"); - sprintf(mpu.dmp_on,"%s%s", sysfs_path, "/dmp_on"); - sprintf(mpu.dmp_int_on, "%s%s", sysfs_path, "/dmp_int_on"); - sprintf(mpu.self_test, "%s%s", sysfs_path, "/self_test"); - sprintf(mpu.dmp_firmware, "%s%s", sysfs_path, "/dmp_firmware"); - sprintf(mpu.firmware_loaded, "%s%s", sysfs_path, "/firmware_loaded"); - sprintf(mpu.display_orientation_on, "%s%s", sysfs_path, "/display_orientation_on"); - sprintf(mpu.orientation_on, "%s%s", sysfs_path, "/orientation_on"); - sprintf(mpu.event_flick, "%s%s", sysfs_path, "/event_flick"); - sprintf(mpu.event_display_orientation, "%s%s", sysfs_path, "/event_display_orientation"); - sprintf(mpu.event_orientation, "%s%s", sysfs_path, "/event_orientation"); - sprintf(mpu.event_tap, "%s%s", sysfs_path, "/event_tap"); - sprintf(mpu.flick_axis, "%s%s", sysfs_path, "/flick_axis"); - sprintf(mpu.flick_counter, "%s%s", sysfs_path, "/flick_counter"); - sprintf(mpu.flick_int_on, "%s%s", sysfs_path, "/flick_int_on"); - sprintf(mpu.flick_lower, "%s%s", sysfs_path, "/flick_lower"); - sprintf(mpu.flick_upper, "%s%s", sysfs_path, "/flick_upper"); - sprintf(mpu.flick_message_on, "%s%s", sysfs_path, "/flick_message_on"); - sprintf(mpu.tap_min_count, "%s%s", sysfs_path, "/tap_min_count"); - sprintf(mpu.tap_on, "%s%s", sysfs_path, "/tap_on"); - sprintf(mpu.tap_threshold, "%s%s", sysfs_path, "/tap_threshold"); - sprintf(mpu.tap_time, "%s%s", sysfs_path, "/tap_time"); - -#if 0 - // test print sysfs paths - dptr = (char**)&mpu; - for (i = 0; i < MAX_SYSFS_ATTRB; i++) { - MPL_LOGE("sysfs path: %s", *dptr++); - } -#endif - return 0; -} - -int DmpFWloaded() -{ - int res; - read_sysfs_int(mpu.firmware_loaded, &res); - return res; -} - -int enable_flick(int en) -{ - int res=0; - int flickUpper=0, flickLower=0, flickCounter=0; - - if (write_sysfs_int(mpu.flick_int_on, en) < 0) { - printf("GT:ERR-can't write 'flick_int_on'"); - res= -1; - } - - if (en) { - flickUpper= FLICK_UPPER_THRES; - flickLower= FLICK_LOWER_THRES; - flickCounter= FLICK_COUNTER; - } - - if (write_sysfs_int(mpu.flick_upper, flickUpper) < 0) { - printf("GT:ERR-can't write 'flick_upper'"); - res= -1; - } - - if (write_sysfs_int(mpu.flick_lower, flickLower) < 0) { - printf("GT:ERR-can't write 'flick_lower'"); - res= -1; - } - - if (write_sysfs_int(mpu.flick_counter, flickCounter) < 0) { - printf("GT:ERR-can't write 'flick_counter'"); - res= -1; - } - - if (write_sysfs_int(mpu.flick_message_on, 0) < 0) { - printf("GT:ERR-can't write 'flick_message_on'"); - res= -1; - } - - if (write_sysfs_int(mpu.flick_axis, 0) < 0) { - printf("GT:ERR_can't write 'flick_axis'"); - res= -1; - } - - return res; -} - -int enable_tap(int en) -{ - if (write_sysfs_int(mpu.tap_on, en) < 0) { - printf("GT:ERR-can't write 'tap_on'"); - return -1; - } - - return 0; -} - -int enable_displ_orient(int en) -{ - if (write_sysfs_int(mpu.display_orientation_on, en) < 0) { - printf("GT:ERR-can't write 'display_orientation_en'"); - return -1; - } - - return 0; -} - -int enable_orient(int en) -{ - if (write_sysfs_int(mpu.orientation_on, en) < 0) { - printf("GT:ERR-can't write 'orientation_on'"); - return -1; - } - - return 0; -} - -int flickHandler() -{ - FILE *fp; - int data; - -#ifdef DEBUG_PRINT - printf("GT:Flick Handler\n"); -#endif - - fp = fopen(mpu.event_flick, "rt"); - fscanf(fp, "%d\n", &data); - fclose (fp); - - printf("Flick= %x\n", data); - - return 0; -} - -int tapHandler() -{ - FILE *fp; - int tap, tap_dir, tap_num; - - fp = fopen(mpu.event_tap, "rt"); - fscanf(fp, "%d\n", &tap); - fclose(fp); - - tap_dir = tap/8; - tap_num = tap%8 + 1; - -#ifdef DEBUG_PRINT - printf("GT:Tap Handler **\n"); - printf("Tap= %x\n", tap); - printf("Tap Dir= %x\n", tap_dir); - printf("Tap Num= %x\n", tap_num); -#endif - - switch (tap_dir) { - case 1: - printf("Tap Axis->X Pos\n"); - break; - case 2: - printf("Tap Axis->X Neg\n"); - break; - case 3: - printf("Tap Axis->Y Pos\n"); - break; - case 4: - printf("Tap Axis->Y Neg\n"); - break; - case 5: - printf("Tap Axis->Z Pos\n"); - break; - case 6: - printf("Tap Axis->Z Neg\n"); - break; - default: - printf("Tap Axis->Unknown\n"); - break; - } - - return 0; -} - -int googleOrientHandler() -{ - FILE *fp; - int orient; - -#ifdef DEBUG_PRINT - printf("GT:Google Orient Handler\n"); -#endif - - fp = fopen(mpu.event_display_orientation, "rt"); - fscanf(fp, "%d\n", &orient); - fclose(fp); - - printf("Google Orient-> %d\n", orient); - - return 0; -} - -int orientHandler() -{ - FILE *fp; - int orient; - - fp = fopen(mpu.event_orientation, "rt"); - fscanf(fp, "%d\n", &orient); - fclose(fp); - -#ifdef DEBUG_PRINT - printf("GT:Reg Orient Handler\n"); -#endif - - if (orient & 0x01) - printf("Orient->X Up\n"); - - if (orient & 0x02) - printf("Orient->X Down\n"); - - if (orient & 0x04) - printf("Orient->Y Up\n"); - - if (orient & 0x08) - printf("Orient->Y Down\n"); - - if (orient & 0x10) - printf("Orient->Z Up\n"); - - if (orient & 0x20) - printf("Orient->Z Down\n"); - - if (orient & 0x40) - printf("Orient->Flip\n"); - - return 0; -} - -int enableDMPFeatures(int en) -{ - int res= -1; - - if (DmpFWloaded()) - { - /* Currently there's no info regarding DMP's supported features/capabilities */ - /* An error in enabling features below could be an indication of the feature */ - /* not supported in current loaded DMP firmware */ - - enable_flick(en); - enable_tap(en); - enable_displ_orient(en); - enable_orient(en); - res= 0; - } - - return res; -} - -int initFds() -{ - int i; - - for (i=0; i< numDMPFeatures; i++) { - switch(i) { - case tap: - pfd[i].fd = open(mpu.event_tap, O_RDONLY | O_NONBLOCK); - break; - - case flick: - pfd[i].fd = open(mpu.event_flick, O_RDONLY | O_NONBLOCK); - break; - - case gOrient: - pfd[i].fd = open(mpu.event_display_orientation, O_RDONLY | O_NONBLOCK); - break; - - case orient: - pfd[i].fd = open(mpu.event_orientation, O_RDONLY | O_NONBLOCK); - break; - - default: - pfd[i].fd = -1; - } - - pfd[i].events = POLLPRI|POLLERR, - pfd[i].revents = 0; -#ifdef DEBUG_PRINT - printf("GT:pfd[%d].fd= %d\n", i, pfd[i].fd); -#endif - } - - return 0; -} - -int closeFds() -{ - int i; - for (i = 0; i < numDMPFeatures; i++) { - if (!pfd[i].fd) - close(pfd[i].fd); - } - return 0; -} - -/******************************************************************************* - * M a i n S e l f T e s t - ******************************************************************************/ - -int main(int argc, char **argv) -{ - char data[4]; - int i, res= 0; - - res = inv_init_sysfs_attributes(); - if (res) { - printf("GT:ERR-Can't allocate mem"); - return -1; - } - - /* On Gesture/DMP supported features */ - enableDMPFeatures(1); - - /* init Fds to poll for Gesture data */ - initFds(); - - /* prompt user to make gesture and how to stop program */ - printf("\n**Please make Gesture to see data. Press any key to stop Prog**\n\n"); - - do { - for (i=0; i< numDMPFeatures; i++) { - read(pfd[i].fd, data, 4); - } - - poll(pfd, numDMPFeatures, POLL_TIME); - - for (i=0; i< numDMPFeatures; i++) { - if(pfd[i].revents != 0) { - switch(i) { - case tap: - tapHandler(); - break; - - case flick: - flickHandler(); - break; - - case gOrient: - googleOrientHandler(); - break; - - case orient: - orientHandler(); - break; - - default: - printf("GT:ERR-Not supported"); - break; - } - pfd[i].revents= 0; //no need. reset anyway - } - } - - } while (!_kbhit()); - - /* Off DMP features */ - enableDMPFeatures(0); - - /* release resources */ - closeFds(); - if (sysfs_names_ptr) { - free(sysfs_names_ptr); - } - - printf("\nThank You!\n"); - - return res; -} - diff --git a/60xx/libsensors_iio/software/simple_apps/mpu_iio/build/android/inv_mpu_iio-shared b/60xx/libsensors_iio/software/simple_apps/mpu_iio/build/android/inv_mpu_iio-shared Binary files differdeleted file mode 100644 index aab27bb..0000000 --- a/60xx/libsensors_iio/software/simple_apps/mpu_iio/build/android/inv_mpu_iio-shared +++ /dev/null diff --git a/60xx/libsensors_iio/software/simple_apps/mpu_iio/build/android/shared.mk b/60xx/libsensors_iio/software/simple_apps/mpu_iio/build/android/shared.mk deleted file mode 100644 index 234c1d9..0000000 --- a/60xx/libsensors_iio/software/simple_apps/mpu_iio/build/android/shared.mk +++ /dev/null @@ -1,109 +0,0 @@ -EXEC = inv_mpu_iio$(SHARED_APP_SUFFIX) - -MK_NAME = $(notdir $(CURDIR)/$(firstword $(MAKEFILE_LIST))) - -CROSS ?= $(ANDROID_ROOT)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- -COMP ?= $(CROSS)gcc -LINK ?= $(CROSS)gcc - -OBJFOLDER = $(CURDIR)/obj - -INV_ROOT = ../../../../.. -APP_DIR = $(CURDIR)/../.. -MLLITE_DIR = $(INV_ROOT)/software/core/mllite -COMMON_DIR = $(INV_ROOT)/software/simple_apps/common -MPL_DIR = $(INV_ROOT)/software/core/mpl -HAL_DIR = $(INV_ROOT)/software/core/HAL - -include $(INV_ROOT)/software/build/android/common.mk - -CFLAGS += $(CMDLINE_CFLAGS) -CFLAGS += -Wall -CFLAGS += -fpic -CFLAGS += -nostdlib -CFLAGS += -DNDEBUG -CFLAGS += -D_REENTRANT -CFLAGS += -DLINUX -CFLAGS += -DANDROID -CFLAGS += -mthumb-interwork -CFLAGS += -fno-exceptions -CFLAGS += -ffunction-sections -CFLAGS += -funwind-tables -CFLAGS += -fstack-protector -CFLAGS += -fno-short-enums -CFLAGS += -fmessage-length=0 -CFLAGS += -I$(MLLITE_DIR) -CFLAGS += -I$(MPL_DIR) -CFLAGS += -I$(COMMON_DIR) -CFLAGS += -I$(HAL_DIR)/include -CFLAGS += $(INV_INCLUDES) -CFLAGS += $(INV_DEFINES) - -LLINK = -lc -LLINK += -lm -LLINK += -lutils -LLINK += -lcutils -LLINK += -lgcc -LLINK += -ldl -LLINK += -lstdc++ -LLINK += -llog -LLINK += -lz - -PRE_LFLAGS := -Wl,-T,$(ANDROID_ROOT)/build/core/armelf.x -PRE_LFLAGS += $(ANDROID_ROOT)/out/target/product/$(PRODUCT)/obj/lib/crtend_android.o -PRE_LFLAGS += $(ANDROID_ROOT)/out/target/product/$(PRODUCT)/obj/lib/crtbegin_dynamic.o - -LFLAGS += $(CMDLINE_LFLAGS) -LFLAGS += -nostdlib -LFLAGS += -fpic -LFLAGS += -Wl,--gc-sections -LFLAGS += -Wl,--no-whole-archive -LFLAGS += -Wl,-dynamic-linker,/system/bin/linker -LFLAGS += $(ANDROID_LINK) -ifneq ($(PRODUCT),panda) -LFLAGS += -rdynamic -endif - -LRPATH = -Wl,-rpath,$(ANDROID_ROOT)/out/target/product/$(PRODUCT)/obj/lib:$(ANDROID_ROOT)/out/target/product/$(PRODUCT)/system/lib - -#################################################################################################### -## sources - -INV_LIBS = $(MPL_DIR)/build/$(TARGET)/$(LIB_PREFIX)$(MPL_LIB_NAME).$(SHARED_LIB_EXT) -INV_LIBS += $(MLLITE_DIR)/build/$(TARGET)/$(LIB_PREFIX)$(MLLITE_LIB_NAME).$(SHARED_LIB_EXT) - -#INV_SOURCES and VPATH provided by Makefile.filelist -include ../filelist.mk - -INV_OBJS := $(addsuffix .o,$(INV_SOURCES)) -INV_OBJS_DST = $(addprefix $(OBJFOLDER)/,$(addsuffix .o, $(notdir $(INV_SOURCES)))) - -#################################################################################################### -## rules - -.PHONY: all clean cleanall install - -all: $(EXEC) $(MK_NAME) - -$(EXEC) : $(OBJFOLDER) $(INV_OBJS_DST) $(INV_LIBS) $(MK_NAME) - @$(call echo_in_colors, "\n<linking $(EXEC) with objects $(INV_OBJS_DST) $(PREBUILT_OBJS) and libraries $(INV_LIBS)\n") - $(LINK) $(PRE_LFLAGS) $(INV_OBJS_DST) -o $(EXEC) $(LFLAGS) $(LLINK) $(INV_LIBS) $(LLINK) $(LRPATH) - -$(OBJFOLDER) : - @$(call echo_in_colors, "\n<creating object's folder 'obj/'>\n") - mkdir obj - -$(INV_OBJS_DST) : $(OBJFOLDER)/%.c.o : %.c $(MK_NAME) - @$(call echo_in_colors, "\n<compile $< to $(OBJFOLDER)/$(notdir $@)>\n") - $(COMP) $(ANDROID_INCLUDES) $(KERNEL_INCLUDES) $(INV_INCLUDES) $(CFLAGS) -o $@ -c $< - -clean : - rm -fR $(OBJFOLDER) - -cleanall : - rm -fR $(EXEC) $(OBJFOLDER) - -install : $(EXEC) - cp -f $(EXEC) $(INSTALL_DIR) - - diff --git a/60xx/libsensors_iio/software/simple_apps/mpu_iio/build/filelist.mk b/60xx/libsensors_iio/software/simple_apps/mpu_iio/build/filelist.mk deleted file mode 100644 index 8a3977a..0000000 --- a/60xx/libsensors_iio/software/simple_apps/mpu_iio/build/filelist.mk +++ /dev/null @@ -1,12 +0,0 @@ -#### filelist.mk for mpu_iio #### - -# headers -#HEADERS += $(HAL_DIR)/include/inv_sysfs_utils.h -HEADERS += $(APP_DIR)/iio_utils.h - -# sources -SOURCES := $(APP_DIR)/mpu_iio.c - -INV_SOURCES += $(SOURCES) - -VPATH += $(APP_DIR) $(COMMON_DIR) $(HAL_DIR)/linux diff --git a/60xx/libsensors_iio/software/simple_apps/mpu_iio/iio_utils.h b/60xx/libsensors_iio/software/simple_apps/mpu_iio/iio_utils.h deleted file mode 100644 index 773ff2c..0000000 --- a/60xx/libsensors_iio/software/simple_apps/mpu_iio/iio_utils.h +++ /dev/null @@ -1,643 +0,0 @@ -/* IIO - useful set of util functionality - * - * Copyright (c) 2008 Jonathan Cameron - * - * 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. - */ - -/* Made up value to limit allocation sizes */ -#include <string.h> -#include <stdlib.h> -#include <ctype.h> -#include <stdio.h> -#include <stdint.h> -#include <dirent.h> - -#define IIO_MAX_NAME_LENGTH 30 - -#define FORMAT_SCAN_ELEMENTS_DIR "%s/scan_elements" -#define FORMAT_TYPE_FILE "%s_type" - -const char *iio_dir = "/sys/bus/iio/devices/"; - -/** - * iioutils_break_up_name() - extract generic name from full channel name - * @full_name: the full channel name - * @generic_name: the output generic channel name - **/ -static int iioutils_break_up_name(const char *full_name, - char **generic_name) -{ - char *current; - char *w, *r; - char *working; - current = strdup(full_name); - working = strtok(current, "_\0"); - w = working; - r = working; - - while (*r != '\0') { - if (!isdigit(*r)) { - *w = *r; - w++; - } - r++; - } - *w = '\0'; - *generic_name = strdup(working); - free(current); - - return 0; -} - -/** - * struct iio_channel_info - information about a given channel - * @name: channel name - * @generic_name: general name for channel type - * @scale: scale factor to be applied for conversion to si units - * @offset: offset to be applied for conversion to si units - * @index: the channel index in the buffer output - * @bytes: number of bytes occupied in buffer output - * @mask: a bit mask for the raw output - * @is_signed: is the raw value stored signed - * @enabled: is this channel enabled - **/ -struct iio_channel_info { - char *name; - char *generic_name; - float scale; - float offset; - unsigned index; - unsigned bytes; - unsigned bits_used; - unsigned shift; - uint64_t mask; - unsigned be; - unsigned is_signed; - unsigned enabled; - unsigned location; -}; - -/** - * iioutils_get_type() - find and process _type attribute data - * @is_signed: output whether channel is signed - * @bytes: output how many bytes the channel storage occupies - * @mask: output a bit mask for the raw data - * @be: big endian - * @device_dir: the iio device directory - * @name: the channel name - * @generic_name: the channel type name - **/ -inline int iioutils_get_type(unsigned *is_signed, - unsigned *bytes, - unsigned *bits_used, - unsigned *shift, - uint64_t *mask, - unsigned *be, - const char *device_dir, - const char *name, - const char *generic_name) -{ - FILE *sysfsfp; - int ret; - DIR *dp; - char *scan_el_dir, *builtname, *builtname_generic, *filename = 0; - char signchar, endianchar; - unsigned padint; - const struct dirent *ent; - - ret = asprintf(&scan_el_dir, FORMAT_SCAN_ELEMENTS_DIR, device_dir); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - ret = asprintf(&builtname, FORMAT_TYPE_FILE, name); - if (ret < 0) { - ret = -ENOMEM; - goto error_free_scan_el_dir; - } - ret = asprintf(&builtname_generic, FORMAT_TYPE_FILE, generic_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_free_builtname; - } - - dp = opendir(scan_el_dir); - if (dp == NULL) { - ret = -errno; - goto error_free_builtname_generic; - } - while (ent = readdir(dp), ent != NULL) - /* - * Do we allow devices to override a generic name with - * a specific one? - */ - if ((strcmp(builtname, ent->d_name) == 0) || - (strcmp(builtname_generic, ent->d_name) == 0)) { - ret = asprintf(&filename, - "%s/%s", scan_el_dir, ent->d_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_closedir; - } - sysfsfp = fopen(filename, "r"); - if (sysfsfp == NULL) { - printf("failed to open %s\n", filename); - ret = -errno; - goto error_free_filename; - } - - ret = fscanf(sysfsfp, - "%ce:%c%u/%u>>%u", - &endianchar, - &signchar, - bits_used, - &padint, shift); - if (ret < 0) { - printf("failed to pass scan type description\n"); - return ret; - } - *be = (endianchar == 'b'); - *bytes = padint / 8; - if (*bits_used == 64) - *mask = ~0; - else - *mask = (1 << *bits_used) - 1; - if (signchar == 's') - *is_signed = 1; - else - *is_signed = 0; - fclose(sysfsfp); - free(filename); - - filename = 0; - } -error_free_filename: - if (filename) - free(filename); -error_closedir: - closedir(dp); -error_free_builtname_generic: - free(builtname_generic); -error_free_builtname: - free(builtname); -error_free_scan_el_dir: - free(scan_el_dir); -error_ret: - return ret; -} - -inline int iioutils_get_param_float(float *output, - const char *param_name, - const char *device_dir, - const char *name, - const char *generic_name) -{ - FILE *sysfsfp; - int ret; - DIR *dp; - char *builtname, *builtname_generic; - char *filename = NULL; - const struct dirent *ent; - - ret = asprintf(&builtname, "%s_%s", name, param_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - ret = asprintf(&builtname_generic, - "%s_%s", generic_name, param_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_free_builtname; - } - dp = opendir(device_dir); - if (dp == NULL) { - ret = -errno; - goto error_free_builtname_generic; - } - while (ent = readdir(dp), ent != NULL) - if ((strcmp(builtname, ent->d_name) == 0) || - (strcmp(builtname_generic, ent->d_name) == 0)) { - ret = asprintf(&filename, - "%s/%s", device_dir, ent->d_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_closedir; - } - sysfsfp = fopen(filename, "r"); - if (!sysfsfp) { - ret = -errno; - goto error_free_filename; - } - fscanf(sysfsfp, "%f", output); - break; - } -error_free_filename: - if (filename) - free(filename); -error_closedir: - closedir(dp); -error_free_builtname_generic: - free(builtname_generic); -error_free_builtname: - free(builtname); -error_ret: - return ret; -} - -/** - * bsort_channel_array_by_index() - reorder so that the array is in index order - * - **/ - -inline void bsort_channel_array_by_index(struct iio_channel_info **ci_array, - int cnt) -{ - - struct iio_channel_info temp; - int x, y; - - for (x = 0; x < cnt; x++) - for (y = 0; y < (cnt - 1); y++) - if ((*ci_array)[y].index > (*ci_array)[y+1].index) { - temp = (*ci_array)[y + 1]; - (*ci_array)[y + 1] = (*ci_array)[y]; - (*ci_array)[y] = temp; - } -} - -/** - * build_channel_array() - function to figure out what channels are present - * @device_dir: the IIO device directory in sysfs - * @ - **/ -inline int build_channel_array(const char *device_dir, - struct iio_channel_info **ci_array, - int *counter) -{ - DIR *dp; - FILE *sysfsfp; - int count, i; - struct iio_channel_info *current; - int ret; - const struct dirent *ent; - char *scan_el_dir; - char *filename; - - *counter = 0; - ret = asprintf(&scan_el_dir, FORMAT_SCAN_ELEMENTS_DIR, device_dir); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - dp = opendir(scan_el_dir); - if (dp == NULL) { - ret = -errno; - goto error_free_name; - } - while (ent = readdir(dp), ent != NULL) - if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), - "_en") == 0) { - ret = asprintf(&filename, - "%s/%s", scan_el_dir, ent->d_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_close_dir; - } - sysfsfp = fopen(filename, "r"); - if (sysfsfp == NULL) { - ret = -errno; - free(filename); - goto error_close_dir; - } - fscanf(sysfsfp, "%u", &ret); - printf("%s, %d\n", filename, ret); - if (ret == 1) - (*counter)++; - fclose(sysfsfp); - free(filename); - } - *ci_array = malloc(sizeof(**ci_array) * (*counter)); - if (*ci_array == NULL) { - ret = -ENOMEM; - goto error_close_dir; - } - closedir(dp); - dp = opendir(scan_el_dir); - //seekdir(dp, 0); - count = 0; - while (ent = readdir(dp), ent != NULL) { - if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), - "_en") == 0) { - current = &(*ci_array)[count++]; - ret = asprintf(&filename, - "%s/%s", scan_el_dir, ent->d_name); - if (ret < 0) { - ret = -ENOMEM; - /* decrement count to avoid freeing name */ - count--; - goto error_cleanup_array; - } - sysfsfp = fopen(filename, "r"); - if (sysfsfp == NULL) { - free(filename); - ret = -errno; - goto error_cleanup_array; - } - fscanf(sysfsfp, "%u", ¤t->enabled); - fclose(sysfsfp); - - if (!current->enabled) { - free(filename); - count--; - continue; - } - - current->scale = 1.0; - current->offset = 0; - current->name = strndup(ent->d_name, - strlen(ent->d_name) - - strlen("_en")); - if (current->name == NULL) { - free(filename); - ret = -ENOMEM; - goto error_cleanup_array; - } - /* Get the generic and specific name elements */ - ret = iioutils_break_up_name(current->name, - ¤t->generic_name); - if (ret) { - free(filename); - goto error_cleanup_array; - } - ret = asprintf(&filename, - "%s/%s_index", - scan_el_dir, - current->name); - if (ret < 0) { - free(filename); - ret = -ENOMEM; - goto error_cleanup_array; - } - sysfsfp = fopen(filename, "r"); - fscanf(sysfsfp, "%u", ¤t->index); - fclose(sysfsfp); - free(filename); - /* Find the scale */ - ret = iioutils_get_param_float(¤t->scale, - "scale", - device_dir, - current->name, - current->generic_name); - if (ret < 0) - goto error_cleanup_array; - ret = iioutils_get_param_float(¤t->offset, - "offset", - device_dir, - current->name, - current->generic_name); - if (ret < 0) - goto error_cleanup_array; - ret = iioutils_get_type(¤t->is_signed, - ¤t->bytes, - ¤t->bits_used, - ¤t->shift, - ¤t->mask, - ¤t->be, - device_dir, - current->name, - current->generic_name); - } - } - - closedir(dp); - /* reorder so that the array is in index order */ - bsort_channel_array_by_index(ci_array, *counter); - - return 0; - -error_cleanup_array: - for (i = count - 1; i >= 0; i--) - free((*ci_array)[i].name); - free(*ci_array); -error_close_dir: - closedir(dp); -error_free_name: - free(scan_el_dir); -error_ret: - return ret; -} - -inline int _write_sysfs_int(char *filename, char *basedir, int val, int verify) -{ - int ret; - FILE *sysfsfp; - int test; - char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) - return -ENOMEM; - sprintf(temp, "%s/%s", basedir, filename); - sysfsfp = fopen(temp, "w"); - if (sysfsfp == NULL) { - printf("failed to open %s\n", temp); - ret = -errno; - goto error_free; - } - fprintf(sysfsfp, "%d", val); - fclose(sysfsfp); - if (verify) { - sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { - printf("failed to open %s\n", temp); - ret = -errno; - goto error_free; - } - fscanf(sysfsfp, "%d", &test); - if (test != val) { - printf("Possible failure in int write %d to %s%s\n", - val, - basedir, - filename); - ret = -1; - } - } -error_free: - free(temp); - return ret; -} - -int write_sysfs_int(char *filename, char *basedir, int val) -{ - return _write_sysfs_int(filename, basedir, val, 0); -} - -int write_sysfs_int_and_verify(char *filename, char *basedir, int val) -{ - return _write_sysfs_int(filename, basedir, val, 1); -} - -int _write_sysfs_string(char *filename, char *basedir, char *val, int verify) -{ - int ret = 0; - FILE *sysfsfp; - char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) { - printf("Memory allocation failed\n"); - return -ENOMEM; - } - sprintf(temp, "%s/%s", basedir, filename); - sysfsfp = fopen(temp, "w"); - if (sysfsfp == NULL) { - printf("Could not open %s\n", temp); - ret = -errno; - goto error_free; - } - fprintf(sysfsfp, "%s", val); - fclose(sysfsfp); - if (verify) { - sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { - printf("could not open file to verify\n"); - ret = -errno; - goto error_free; - } - fscanf(sysfsfp, "%s", temp); - if (strcmp(temp, val) != 0) { - printf("Possible failure in string write of %s " - "Should be %s " - "written to %s\%s\n", - temp, - val, - basedir, - filename); - ret = -1; - } - } -error_free: - free(temp); - - return ret; -} - -/** - * write_sysfs_string_and_verify() - string write, readback and verify - * @filename: name of file to write to - * @basedir: the sysfs directory in which the file is to be found - * @val: the string to write - **/ -int write_sysfs_string_and_verify(char *filename, char *basedir, char *val) -{ - return _write_sysfs_string(filename, basedir, val, 1); -} - -int write_sysfs_string(char *filename, char *basedir, char *val) -{ - return _write_sysfs_string(filename, basedir, val, 0); -} - -int read_sysfs_posint(char *filename, char *basedir) -{ - int ret; - FILE *sysfsfp; - char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) { - printf("Memory allocation failed"); - return -ENOMEM; - } - sprintf(temp, "%s/%s", basedir, filename); - sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { - ret = -errno; - goto error_free; - } - fscanf(sysfsfp, "%d\n", &ret); - fclose(sysfsfp); -error_free: - free(temp); - return ret; -} - -int read_sysfs_float(char *filename, char *basedir, float *val) -{ - float ret = 0; - FILE *sysfsfp; - char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) { - printf("Memory allocation failed"); - return -ENOMEM; - } - sprintf(temp, "%s/%s", basedir, filename); - sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { - ret = -errno; - goto error_free; - } - fscanf(sysfsfp, "%f\n", val); - fclose(sysfsfp); -error_free: - free(temp); - return ret; -} -int enable(const char *device_dir, - struct iio_channel_info **ci_array, - int *counter) -{ - DIR *dp; - int ret; - const struct dirent *ent; - char *scan_el_dir; - - *counter = 0; - ret = asprintf(&scan_el_dir, FORMAT_SCAN_ELEMENTS_DIR, device_dir); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - dp = opendir(scan_el_dir); - if (dp == NULL) { - ret = -errno; - goto error_free_name; - } - while (ent = readdir(dp), ent != NULL) - if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), - "_en") == 0) { - write_sysfs_int_and_verify((char *)ent->d_name, scan_el_dir, 1); - } - return 0; -error_ret: -error_free_name: - return -1; -} -int disable_q_out(const char *device_dir, - struct iio_channel_info **ci_array, - int *counter) { - DIR *dp; - int ret; - const struct dirent *ent; - char *scan_el_dir; - - *counter = 0; - ret = asprintf(&scan_el_dir, FORMAT_SCAN_ELEMENTS_DIR, device_dir); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - dp = opendir(scan_el_dir); - if (dp == NULL) { - ret = -errno; - goto error_free_name; - } - while (ent = readdir(dp), ent != NULL) - if (strncmp(ent->d_name, "in_quaternion", strlen("in_quaternion")) == 0) { - write_sysfs_int_and_verify((char *)ent->d_name, scan_el_dir, 0); - } - return 0; -error_ret: -error_free_name: - return -1; - -} - diff --git a/60xx/libsensors_iio/software/simple_apps/mpu_iio/mpu_iio.c b/60xx/libsensors_iio/software/simple_apps/mpu_iio/mpu_iio.c deleted file mode 100644 index b3d323c..0000000 --- a/60xx/libsensors_iio/software/simple_apps/mpu_iio/mpu_iio.c +++ /dev/null @@ -1,685 +0,0 @@ -/* Industrialio buffer test code. - * - * Copyright (c) 2008 Jonathan Cameron - * - * 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 primarily intended as an example application. - * Reads the current buffer setup from sysfs and starts a short capture - * from the specified device, pretty printing the result after appropriate - * conversion. - * - * Command line parameters - * generic_buffer -n <device_name> -t <trigger_name> - * If trigger name is not specified the program assumes you want a dataready - * trigger associated with the device and goes looking for it. - * - */ - -#include <unistd.h> -#include <dirent.h> -#include <fcntl.h> -#include <stdio.h> -#include <errno.h> -#include <sys/stat.h> -#include <dirent.h> -#include <linux/types.h> -#include <string.h> -#include <poll.h> -#include "iio_utils.h" -#include "ml_load_dmp.h" -#include "ml_sysfs_helper.h" -#include "authenticate.h" - -#define FLICK_SUPPORTED (0) - -/** - * size_from_channelarray() - calculate the storage size of a scan - * @channels: the channel info array - * @num_channels: size of the channel info array - * - * Has the side effect of filling the channels[i].location values used - * in processing the buffer output. - **/ -int size_from_channelarray(struct iio_channel_info *channels, int num_channels) -{ - int bytes = 0; - int i = 0; - while (i < num_channels) { - if (bytes % channels[i].bytes == 0) - channels[i].location = bytes; - else - channels[i].location = bytes - bytes%channels[i].bytes - + channels[i].bytes; - bytes = channels[i].location + channels[i].bytes; - i++; - } - return bytes; -} - -void print2byte(int input, struct iio_channel_info *info) -{ - /* shift before conversion to avoid sign extension - of left aligned data */ - input = input >> info->shift; - if (info->is_signed) { - int16_t val = input; - val &= (1 << info->bits_used) - 1; - val = (int16_t)(val << (16 - info->bits_used)) >> - (16 - info->bits_used); - /*printf("%d, %05f, scale=%05f", val, - (float)(val + info->offset)*info->scale, info->scale);*/ - printf("%d, ", val); - - } else { - uint16_t val = input; - val &= (1 << info->bits_used) - 1; - printf("%05f ", ((float)val + info->offset)*info->scale); - } -} -/** - * process_scan() - print out the values in SI units - * @data: pointer to the start of the scan - * @infoarray: information about the channels. Note - * size_from_channelarray must have been called first to fill the - * location offsets. - * @num_channels: the number of active channels - **/ -void process_scan(char *data, - struct iio_channel_info *infoarray, - int num_channels) -{ - int k; - //char *tmp; - for (k = 0; k < num_channels; k++) { - switch (infoarray[k].bytes) { - /* only a few cases implemented so far */ - case 2: - print2byte(*(uint16_t *)(data + infoarray[k].location), - &infoarray[k]); - //tmp = data + infoarray[k].location; - break; - case 4: - if (infoarray[k].is_signed) { - int32_t val = *(int32_t *) - (data + - infoarray[k].location); - if ((val >> infoarray[k].bits_used) & 1) - val = (val & infoarray[k].mask) | - ~infoarray[k].mask; - /* special case for timestamp */ - printf(" %d ", val); - } - break; - case 8: - if (infoarray[k].is_signed) { - int64_t val = *(int64_t *) - (data + - infoarray[k].location); - if ((val >> infoarray[k].bits_used) & 1) - val = (val & infoarray[k].mask) | - ~infoarray[k].mask; - /* special case for timestamp */ - if (infoarray[k].scale == 1.0f && - infoarray[k].offset == 0.0f) - printf(" %lld", val); - else - printf("%05f ", ((float)val + - infoarray[k].offset)* - infoarray[k].scale); - } - break; - default: - break; - } - } - printf("\n"); -} - -#if FLICK_SUPPORTED /* hide flick, not offially supported */ -void enable_flick(char *p, int on){ - int ret; - printf("flick:%s\n", p); - ret = write_sysfs_int_and_verify("flick_int_on", p, on); - if (ret < 0) - return; - ret = write_sysfs_int_and_verify("flick_upper", p, 3147790); - if (ret < 0) - return; - ret = write_sysfs_int_and_verify("flick_lower", p, -3147790); - if (ret < 0) - return; - - ret = write_sysfs_int_and_verify("flick_counter", p, 50); - if (ret < 0) - return; - ret = write_sysfs_int_and_verify("flick_message_on", p, 0); - if (ret < 0) - return; - ret = write_sysfs_int_and_verify("flick_axis", p, 0); -} -#endif - -void HandleOrient(int orient) -{ - if (orient & 0x01) - printf("INV_X_UP\n"); - if (orient & 0x02) - printf("INV_X_DOWN\n"); - if (orient & 0x04) - printf("INV_Y_UP\n"); - if (orient & 0x08) - printf("INV_Y_DOWN\n"); - if (orient & 0x10) - printf("INV_Z_UP\n"); - if (orient & 0x20) - printf("INV_Z_DOWN\n"); - if (orient & 0x40) - printf("INV_ORIENTATION_FLIP\n"); -} - -void HandleTap(int tap) -{ - int tap_dir = tap/8; - int tap_num = tap%8 + 1; - - switch (tap_dir) { - case 1: - printf("INV_TAP_AXIS_X_POS\n"); - break; - case 2: - printf("INV_TAP_AXIS_X_NEG\n"); - break; - case 3: - printf("INV_TAP_AXIS_Y_POS\n"); - break; - case 4: - printf("INV_TAP_AXIS_Y_NEG\n"); - break; - case 5: - printf("INV_TAP_AXIS_Z_POS\n"); - break; - case 6: - printf("INV_TAP_AXIS_Z_NEG\n"); - break; - default: - break; - } - printf("Tap number: %d\n", tap_num); -} -#define DMP_CODE_SIZE 3060 -void verify_img(char *dmp_path){ - FILE *fp; - int i; - char dmp_img[DMP_CODE_SIZE]; - if ((fp = fopen(dmp_path, "rb")) < 0 ) { - perror("dmp fail"); - } - i = fread(dmp_img, 1, DMP_CODE_SIZE, fp); - printf("Result=%d\n", i); - fclose(fp); - fp = fopen("/dev/read_img.h", "wt"); - fprintf(fp, "char rec[]={\n"); - for(i=0; i<DMP_CODE_SIZE; i++) { - fprintf(fp, "0x%02x, ", dmp_img[i]); - if(((i+1)%16) == 0) { - fprintf(fp, "\n"); - } - } - fprintf(fp, "};\n "); - fclose(fp); -} - -void setup_dmp(char *dev_path, int p_event){ - char sysfs_path[200]; - char dmp_path[200]; - int ret; - FILE *fd; - sprintf(sysfs_path, "%s", dev_path); - printf("sysfs: %s\n", sysfs_path); - ret = write_sysfs_int_and_verify("power_state", sysfs_path, 1); - if (ret < 0) - return; - - ret = write_sysfs_int("in_accel_scale", dev_path, 0); - if (ret < 0) - return; - ret = write_sysfs_int("in_anglvel_scale", dev_path, 2); - if (ret < 0) - return; - ret = write_sysfs_int("sampling_frequency", sysfs_path, 200); - if (ret < 0) - return; - ret = write_sysfs_int_and_verify("firmware_loaded", sysfs_path, 0); - if (ret < 0) - return; - sprintf(dmp_path, "%s/dmp_firmware", dev_path); - if ((fd = fopen(dmp_path, "wb")) < 0 ) { - perror("dmp fail"); - } - inv_load_dmp(fd); - fclose(fd); - printf("firmware_loaded=%d\n", read_sysfs_posint("firmware_loaded", sysfs_path)); - ret = write_sysfs_int_and_verify("in_accel_x_offset", sysfs_path, 0xabcd0000); - ret = write_sysfs_int_and_verify("in_accel_y_offset", sysfs_path, 0xffff0000); - ret = write_sysfs_int_and_verify("in_accel_z_offset", sysfs_path, 0xcdef0000); - - ret = write_sysfs_int_and_verify("dmp_on", sysfs_path, 1); - if (ret < 0) - return; - ret = write_sysfs_int_and_verify("dmp_int_on", sysfs_path, 1); - if (ret < 0) - return; - /* selelct which event to enable and interrupt on/off here */ - //enable_flick(sysfs_path, 1); - ret = write_sysfs_int_and_verify("tap_on", sysfs_path, 1); - if (ret < 0) - return; - ret = write_sysfs_int_and_verify("display_orientation_on", sysfs_path, 1); - if (ret < 0) - return; - ret = write_sysfs_int_and_verify("orientation_on", sysfs_path, 1); - if (ret < 0) - return; - printf("rate\n"); - ret = write_sysfs_int_and_verify("dmp_output_rate", sysfs_path, 25); - if (ret < 0) - return; - ret = write_sysfs_int_and_verify("dmp_event_int_on", sysfs_path, p_event); - if (ret < 0) - return; - //verify_img(dmp_path); -} - -void get_dmp_event(char *dev_dir_name) -{ - char file_name[100]; - int i; -#if FLICK_SUPPORTED /* hide flick, not offially supported */ - int fp_tap, fp_orient, fp_disp, fp_flick; - const int n_gest = 6; -#else - int fp_tap, fp_orient, fp_disp, fp_motion; - //int fp_no_motion; - const int n_gest = 4; -#endif - int data; - char d[6]; - FILE *fp; - struct pollfd pfd[4]; - printf("%s\n", dev_dir_name); - while(1) { - sprintf(file_name, "%s/event_tap", dev_dir_name); - fp_tap = open(file_name, O_RDONLY | O_NONBLOCK); - sprintf(file_name, "%s/event_orientation", dev_dir_name); - fp_orient = open(file_name, O_RDONLY | O_NONBLOCK); - sprintf(file_name, "%s/event_display_orientation", dev_dir_name); - fp_disp = open(file_name, O_RDONLY | O_NONBLOCK); - - //sprintf(file_name, "%s/event_accel_motion", dev_dir_name); - sprintf(file_name, "%s/event_accel_wom", dev_dir_name); - fp_motion = open(file_name, O_RDONLY | O_NONBLOCK); - //sprintf(file_name, "%s/event_accel_no_motion", dev_dir_name); - //fp_no_motion = open(file_name, O_RDONLY | O_NONBLOCK); -#if FLICK_SUPPORTED /* hide flick, not offially supported */ - sprintf(file_name, "%s/event_flick", dev_dir_name); - fp_flick = open(file_name, O_RDONLY | O_NONBLOCK); -#endif - - pfd[0].fd = fp_tap; - pfd[0].events = POLLPRI|POLLERR, - pfd[0].revents = 0; - - pfd[1].fd = fp_orient; - pfd[1].events = POLLPRI|POLLERR, - pfd[1].revents = 0; - - pfd[2].fd = fp_disp; - pfd[2].events = POLLPRI|POLLERR, - pfd[2].revents = 0; - - pfd[3].fd = fp_motion; - pfd[3].events = POLLPRI|POLLERR, - pfd[3].revents = 0; - - //pfd[4].fd = fp_no_motion; - //pfd[4].events = POLLPRI|POLLERR, - //pfd[4].revents = 0; - -#if FLICK_SUPPORTED /* hide flick, not offially supported */ - pfd[5].fd = fp_flick; - pfd[5].events = POLLPRI|POLLERR, - pfd[5].revents = 0; -#endif - - read(fp_tap, d, 4); - read(fp_orient, d, 4); - read(fp_disp, d, 4); - read(fp_motion, d, 4); - //read(fp_no_motion, d, 4); -#if FLICK_SUPPORTED /* hide flick, not offially supported */ - read(fp_flick, d, 4); -#endif - - poll(pfd, n_gest, -1); - close(fp_tap); - close(fp_orient); - close(fp_disp); - close(fp_motion); - //close(fp_no_motion); -#if FLICK_SUPPORTED /* hide flick, not offially supported */ - close(fp_flick); -#endif - for (i = 0; i < ARRAY_SIZE(pfd); i++) { - if(pfd[i].revents != 0) { - switch (i){ - case 0: - sprintf(file_name, "%s/event_tap", dev_dir_name); - fp = fopen(file_name, "rt"); - fscanf(fp, "%d\n", &data); - printf("tap=%x\n", data); - HandleTap(data); - fclose(fp); - break; - case 1: - sprintf(file_name, "%s/event_orientation", dev_dir_name); - fp = fopen(file_name, "rt"); - fscanf(fp, "%d\n", &data); - printf("orient=%x\n", data); - HandleOrient(data); - fclose(fp); - break; - case 2: - sprintf(file_name, "%s/event_display_orientation", dev_dir_name); - fp = fopen(file_name, "rt"); - fscanf(fp, "%d\n", &data); - printf("display_orient=%x\n", data); - fclose(fp); - break; - case 3: - sprintf(file_name, "%s/event_accel_wom", dev_dir_name); - fp = fopen(file_name, "rt"); - fscanf(fp, "%d\n", &data); - printf("motion=%x\n", data); - fclose(fp); - break; - case 4: - sprintf(file_name, "%s/event_accel_no_motion", dev_dir_name); - fp = fopen(file_name, "rt"); - fscanf(fp, "%d\n", &data); - printf("No motion=%x\n", data); - fclose(fp); - break; - -#if FLICK_SUPPORTED /* hide flick, not offially supported */ - case 5: - sprintf(file_name, "%s/event_flick", dev_dir_name); - fp = fopen(file_name, "rt"); - fscanf(fp, "%d\n", &data); - printf("flick=%x\n", data); - fclose(fp); - break; -#endif - } - } - } - } -} - - -int main(int argc, char **argv) -{ - unsigned long num_loops = 2; - unsigned long timedelay = 100000; - unsigned long buf_len = 128; - - int ret, c, i, j, toread; - int fp; - - int num_channels; - char *trigger_name = NULL; - char *dev_dir_name, *buf_dir_name; - - int datardytrigger = 1; - char *data; - int read_size; - int dev_num, trig_num; - char *buffer_access; - int scan_size; - int noevents = 0; - int p_event = 0, nodmp = 0; - char *dummy; - char chip_name[10]; - char device_name[10]; - char sysfs[100]; - - struct iio_channel_info *infoarray; - /* -r means no DMP is enabled (raw) -> should be used for mpu3050. - -p means no print of data */ - /* when using -p, 1 means orientation, 2 means tap, 3 means flick */ - while ((c = getopt(argc, argv, "l:w:c:pret:")) != -1) { - switch (c) { - case 't': - trigger_name = optarg; - datardytrigger = 0; - break; - case 'e': - noevents = 1; - break; - case 'p': - p_event = 1; - break; - case 'r': - nodmp = 1; - break; - case 'c': - num_loops = strtoul(optarg, &dummy, 10); - break; - case 'w': - timedelay = strtoul(optarg, &dummy, 10); - break; - case 'l': - buf_len = strtoul(optarg, &dummy, 10); - break; - case '?': - return -1; - } - } - inv_get_sysfs_path(sysfs); - printf("sss:::%s\n", sysfs); - if (inv_get_chip_name(chip_name) != INV_SUCCESS) { - printf("get chip name fail\n"); - exit(0); - } - printf("chip_name=%s\n", chip_name); - if (INV_SUCCESS != inv_check_key()) - printf("key check fail\n"); - else - printf("key authenticated\n"); - - for (i=0; i<strlen(chip_name); i++) { - device_name[i] = tolower(chip_name[i]); - } - device_name[strlen(chip_name)] = '\0'; - printf("device name: %s\n", device_name); - - /* Find the device requested */ - dev_num = find_type_by_name(device_name, "iio:device"); - if (dev_num < 0) { - printf("Failed to find the %s\n", device_name); - ret = -ENODEV; - goto error_ret; - } - printf("iio device number being used is %d\n", dev_num); - asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num); - if (trigger_name == NULL) { - /* - * Build the trigger name. If it is device associated it's - * name is <device_name>_dev[n] where n matches the device - * number found above - */ - ret = asprintf(&trigger_name, - "%s-dev%d", device_name, dev_num); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - } - ret = write_sysfs_int("buffer/enable", dev_dir_name, 0); - - ret = write_sysfs_int_and_verify("power_state", dev_dir_name, 1); - ret = write_sysfs_int_and_verify("gyro_enable", dev_dir_name, 1); - ret = write_sysfs_int_and_verify("accl_enable", dev_dir_name, 1); - ret = write_sysfs_int_and_verify("compass_enable", dev_dir_name, 1); -/* - ret = write_sysfs_int_and_verify("zero_motion_on", dev_dir_name, 1); - ret = write_sysfs_int_and_verify("zero_motion_dur", dev_dir_name, 12); - ret = write_sysfs_int_and_verify("zero_motion_threshold", dev_dir_name, 13); - - ret = write_sysfs_int_and_verify("motion_on", dev_dir_name, 1); - ret = write_sysfs_int_and_verify("motion_dur", dev_dir_name, 1); - ret = write_sysfs_int_and_verify("motion_threshold", dev_dir_name, 1); -*/ - ret = write_sysfs_int_and_verify("accel_wom_on", dev_dir_name, 1); - ret = write_sysfs_int_and_verify("accel_wom_threshold", dev_dir_name, 100); - /* Verify the trigger exists */ - trig_num = find_type_by_name(trigger_name, "trigger"); - if (trig_num < 0) { - printf("Failed to find the trigger %s\n", trigger_name); - ret = -ENODEV; - goto error_free_triggername; - } - printf("iio trigger number being used is %d\n", trig_num); - /* - * Parse the files in scan_elements to identify what channels are - * present - */ - ret = 0; - ret = enable(dev_dir_name, &infoarray, &num_channels); - if (ret) { - printf("error enable\n"); - goto error_free_triggername; - } - if (!nodmp) - setup_dmp(dev_dir_name, p_event); - - /* - * Construct the directory name for the associated buffer. - * As we know that the lis3l02dq has only one buffer this may - * be built rather than found. - */ - ret = asprintf(&buf_dir_name, "%siio:device%d/buffer", iio_dir, dev_num); - if (ret < 0) { - ret = -ENOMEM; - goto error_free_triggername; - } - printf("%s %s\n", dev_dir_name, trigger_name); - - /* Set the device trigger to be the data rdy trigger found above */ - ret = write_sysfs_string_and_verify("trigger/current_trigger", - dev_dir_name, - trigger_name); - if (ret < 0) { - printf("Failed to write current_trigger file\n"); - goto error_free_buf_dir_name; - } - /* Setup ring buffer parameters */ - /* length must be even number because iio_store_to_sw_ring is expecting - half pointer to be equal to the read pointer, which is impossible - when buflen is odd number. This is actually a bug in the code */ - ret = write_sysfs_int("length", buf_dir_name, buf_len*2); - if (ret < 0) - goto exit_here; - ret = write_sysfs_int_and_verify("gyro_enable", dev_dir_name, 1); - ret = write_sysfs_int_and_verify("accl_enable", dev_dir_name, 1); - //ret = write_sysfs_int_and_verify("compass_enable", dev_dir_name, 0); - if (nodmp == 0) { - ret = write_sysfs_int_and_verify("quaternion_on", dev_dir_name, 1); - } else { - ret = disable_q_out(dev_dir_name, &infoarray, &num_channels); - ret = write_sysfs_int_and_verify("dmp_on", dev_dir_name, 0); - } - ret = build_channel_array(dev_dir_name, &infoarray, &num_channels); - if (ret) { - printf("Problem reading scan element information\n"); - goto exit_here; - } - - /* Enable the buffer */ - ret = write_sysfs_int("enable", buf_dir_name, 1); - if (ret < 0) - goto exit_here; - scan_size = size_from_channelarray(infoarray, num_channels); - data = malloc(scan_size*buf_len); - if (!data) { - ret = -ENOMEM; - goto exit_here; - } - - ret = asprintf(&buffer_access, - "/dev/iio:device%d", - dev_num); - if (ret < 0) { - ret = -ENOMEM; - goto error_free_data; - } - if (p_event) { - get_dmp_event(dev_dir_name); - goto error_free_buffer_access; - } - /* Attempt to open non blocking the access dev */ - fp = open(buffer_access, O_RDONLY | O_NONBLOCK); - if (fp == -1) { /*If it isn't there make the node */ - printf("Failed to open %s\n", buffer_access); - ret = -errno; - goto error_free_buffer_access; - } - /* Wait for events 10 times */ - for (j = 0; j < num_loops; j++) { - if (!noevents) { - struct pollfd pfd = { - .fd = fp, - .events = POLLIN, - }; - poll(&pfd, 1, -1); - toread = 1; - if ((j%128)==0) - usleep(timedelay); - - } else { - usleep(timedelay); - toread = 1; - } - read_size = read(fp, - data, - toread*scan_size); - if (read_size == -EAGAIN) { - printf("nothing available\n"); - continue; - } - if (0 == p_event) { - for (i = 0; i < read_size/scan_size; i++) - process_scan(data + scan_size*i, - infoarray, - num_channels); - } - } - close(fp); -error_free_buffer_access: - free(buffer_access); -error_free_data: - free(data); -exit_here: - /* Stop the ring buffer */ - ret = write_sysfs_int("enable", buf_dir_name, 0); - -error_free_buf_dir_name: - free(buf_dir_name); -error_free_triggername: - if (datardytrigger) - free(trigger_name); -error_ret: - return ret; -} diff --git a/60xx/libsensors_iio/software/simple_apps/self_test/build/android/inv_self_test-shared b/60xx/libsensors_iio/software/simple_apps/self_test/build/android/inv_self_test-shared Binary files differdeleted file mode 100644 index 6dc08bd..0000000 --- a/60xx/libsensors_iio/software/simple_apps/self_test/build/android/inv_self_test-shared +++ /dev/null diff --git a/60xx/libsensors_iio/software/simple_apps/self_test/build/android/shared.mk b/60xx/libsensors_iio/software/simple_apps/self_test/build/android/shared.mk deleted file mode 100644 index ed5fbf6..0000000 --- a/60xx/libsensors_iio/software/simple_apps/self_test/build/android/shared.mk +++ /dev/null @@ -1,98 +0,0 @@ -EXEC = inv_self_test$(SHARED_APP_SUFFIX) - -MK_NAME = $(notdir $(CURDIR)/$(firstword $(MAKEFILE_LIST))) - -CROSS ?= $(ANDROID_ROOT)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- -COMP ?= $(CROSS)gcc -LINK ?= $(CROSS)gcc - -OBJFOLDER = $(CURDIR)/obj - -INV_ROOT = ../../../../.. -APP_DIR = $(CURDIR)/../.. -MLLITE_DIR = $(INV_ROOT)/software/core/mllite -COMMON_DIR = $(INV_ROOT)/software/simple_apps/common -MPL_DIR = $(INV_ROOT)/software/core/mpl -HAL_DIR = $(INV_ROOT)/software/core/HAL - -include $(INV_ROOT)/software/build/android/common.mk - -CFLAGS += $(CMDLINE_CFLAGS) -CFLAGS += $(ANDROID_COMPILE) -CFLAGS += -Wall -CFLAGS += -fpic -CFLAGS += -nostdlib -CFLAGS += -DNDEBUG -CFLAGS += -D_REENTRANT -CFLAGS += -DLINUX -CFLAGS += -DANDROID -CFLAGS += -mthumb-interwork -CFLAGS += -fno-exceptions -CFLAGS += -ffunction-sections -CFLAGS += -funwind-tables -CFLAGS += -fstack-protector -CFLAGS += -fno-short-enums -CFLAGS += -fmessage-length=0 -CFLAGS += -I$(MLLITE_DIR) -CFLAGS += -I$(MPL_DIR) -CFLAGS += -I$(COMMON_DIR) -CFLAGS += -I$(HAL_DIR)/include -CFLAGS += $(INV_INCLUDES) -CFLAGS += $(INV_DEFINES) - -LLINK = -lc -LLINK += -lm -LLINK += -lutils -LLINK += -lcutils -LLINK += -lgcc -LLINK += -ldl -LLINK += -lstdc++ -LLINK += -llog -LLINK += -lz - -LFLAGS += $(CMDLINE_LFLAGS) -LFLAGS += $(ANDROID_LINK_EXECUTABLE) - -LRPATH = -Wl,-rpath,$(ANDROID_ROOT)/out/target/product/$(PRODUCT)/obj/lib:$(ANDROID_ROOT)/out/target/product/$(PRODUCT)/system/lib - -#################################################################################################### -## sources - -INV_LIBS = $(MPL_DIR)/build/$(TARGET)/$(LIB_PREFIX)$(MPL_LIB_NAME).$(SHARED_LIB_EXT) -INV_LIBS += $(MLLITE_DIR)/build/$(TARGET)/$(LIB_PREFIX)$(MLLITE_LIB_NAME).$(SHARED_LIB_EXT) - -#INV_SOURCES and VPATH provided by Makefile.filelist -include ../filelist.mk - -INV_OBJS := $(addsuffix .o,$(INV_SOURCES)) -INV_OBJS_DST = $(addprefix $(OBJFOLDER)/,$(addsuffix .o, $(notdir $(INV_SOURCES)))) - -#################################################################################################### -## rules - -.PHONY: all clean cleanall install - -all: $(EXEC) $(MK_NAME) - -$(EXEC) : $(OBJFOLDER) $(INV_OBJS_DST) $(INV_LIBS) $(MK_NAME) - @$(call echo_in_colors, "\n<linking $(EXEC) with objects $(INV_OBJS_DST) $(PREBUILT_OBJS) and libraries $(INV_LIBS)\n") - $(LINK) $(INV_OBJS_DST) -o $(EXEC) $(LFLAGS) $(LLINK) $(INV_LIBS) $(LLINK) $(LRPATH) - -$(OBJFOLDER) : - @$(call echo_in_colors, "\n<creating object's folder 'obj/'>\n") - mkdir obj - -$(INV_OBJS_DST) : $(OBJFOLDER)/%.c.o : %.c $(MK_NAME) - @$(call echo_in_colors, "\n<compile $< to $(OBJFOLDER)/$(notdir $@)>\n") - $(COMP) $(ANDROID_INCLUDES) $(KERNEL_INCLUDES) $(INV_INCLUDES) $(CFLAGS) -o $@ -c $< - -clean : - rm -fR $(OBJFOLDER) - -cleanall : - rm -fR $(EXEC) $(OBJFOLDER) - -install : $(EXEC) - cp -f $(EXEC) $(INSTALL_DIR) - - diff --git a/60xx/libsensors_iio/software/simple_apps/self_test/build/filelist.mk b/60xx/libsensors_iio/software/simple_apps/self_test/build/filelist.mk deleted file mode 100644 index 492f47e..0000000 --- a/60xx/libsensors_iio/software/simple_apps/self_test/build/filelist.mk +++ /dev/null @@ -1,11 +0,0 @@ -#### filelist.mk for console_test #### - -# headers -HEADERS += $(HAL_DIR)/include/inv_sysfs_utils.h - -# sources -SOURCES := $(APP_DIR)/inv_self_test.c - -INV_SOURCES += $(SOURCES) - -VPATH += $(APP_DIR) $(COMMON_DIR) $(HAL_DIR)/linux diff --git a/60xx/libsensors_iio/software/simple_apps/self_test/inv_self_test.c b/60xx/libsensors_iio/software/simple_apps/self_test/inv_self_test.c deleted file mode 100644 index 87ed703..0000000 --- a/60xx/libsensors_iio/software/simple_apps/self_test/inv_self_test.c +++ /dev/null @@ -1,417 +0,0 @@ -/** - * Self Test application for Invensense's MPU6050/MPU6500/MPU9150. - */ - -#include <unistd.h> -#include <dirent.h> -#include <fcntl.h> -#include <stdio.h> -#include <errno.h> -#include <sys/stat.h> -#include <stdlib.h> -#include <features.h> -#include <dirent.h> -#include <string.h> -#include <poll.h> -#include <stddef.h> -#include <linux/input.h> -#include <time.h> -#include <linux/time.h> - -#include "invensense.h" -#include "ml_math_func.h" -#include "storage_manager.h" -#include "ml_stored_data.h" -#include "ml_sysfs_helper.h" - -#ifndef ABS -#define ABS(x)(((x) >= 0) ? (x) : -(x)) -#endif - -//#define DEBUG_PRINT /* Uncomment to print Gyro & Accel read from Driver */ - -#define MAX_SYSFS_NAME_LEN (100) -#define MAX_SYSFS_ATTRB (sizeof(struct sysfs_attrbs) / sizeof(char*)) - -/** Change this key if the data being stored by this file changes */ -#define INV_DB_SAVE_KEY 53395 - -#define FALSE 0 -#define TRUE 1 - -#define GYRO_PASS_STATUS_BIT 0x01 -#define ACCEL_PASS_STATUS_BIT 0x02 -#define COMPASS_PASS_STATUS_BIT 0x04 - -typedef union { - long l; - int i; -} bias_dtype; - -char *sysfs_names_ptr; - -struct sysfs_attrbs { - char *enable; - char *power_state; - char *dmp_on; - char *dmp_int_on; - char *self_test; - char *temperature; - char *gyro_enable; - char *gyro_x_bias; - char *gyro_y_bias; - char *gyro_z_bias; - char *accel_enable; - char *accel_x_bias; - char *accel_y_bias; - char *accel_z_bias; - char *compass_enable; -} mpu; - -struct inv_db_save_t { - /** Compass Bias in Chip Frame in Hardware units scaled by 2^16 */ - long compass_bias[3]; - /** Gyro Bias in Chip Frame in Hardware units scaled by 2^16 */ - long gyro_bias[3]; - /** Temperature when *gyro_bias was stored. */ - long gyro_temp; - /** Accel Bias in Chip Frame in Hardware units scaled by 2^16 */ - long accel_bias[3]; - /** Temperature when accel bias was stored. */ - long accel_temp; - long gyro_temp_slope[3]; - /** Sensor Accuracy */ - int gyro_accuracy; - int accel_accuracy; - int compass_accuracy; -}; - -static struct inv_db_save_t save_data; - -/** This function receives the data that was stored in non-volatile memory - between power off */ -static inv_error_t inv_db_load_func(const unsigned char *data) -{ - memcpy(&save_data, data, sizeof(save_data)); - return INV_SUCCESS; -} - -/** This function returns the data to be stored in non-volatile memory between - power off */ -static inv_error_t inv_db_save_func(unsigned char *data) -{ - memcpy(data, &save_data, sizeof(save_data)); - return INV_SUCCESS; -} - -/** read a sysfs entry that represents an integer */ -int read_sysfs_int(char *filename, int *var) -{ - int res=0; - FILE *fp; - - fp = fopen(filename, "r"); - if (fp != NULL) { - fscanf(fp, "%d\n", var); - fclose(fp); - } else { - MPL_LOGE("inv_self_test: ERR open file to read"); - res= -1; - } - return res; -} - -/** write a sysfs entry that represents an integer */ -int write_sysfs_int(char *filename, int data) -{ - int res=0; - FILE *fp; - - fp = fopen(filename, "w"); - if (fp!=NULL) { - fprintf(fp, "%d\n", data); - fclose(fp); - } else { - MPL_LOGE("inv_self_test: ERR open file to write"); - res= -1; - } - return res; -} - -int inv_init_sysfs_attributes(void) -{ - unsigned char i = 0; - char sysfs_path[MAX_SYSFS_NAME_LEN]; - char *sptr; - char **dptr; - - sysfs_names_ptr = - (char*)malloc(sizeof(char[MAX_SYSFS_ATTRB][MAX_SYSFS_NAME_LEN])); - sptr = sysfs_names_ptr; - if (sptr != NULL) { - dptr = (char**)&mpu; - do { - *dptr++ = sptr; - sptr += sizeof(char[MAX_SYSFS_NAME_LEN]); - } while (++i < MAX_SYSFS_ATTRB); - } else { - MPL_LOGE("inv_self_test: couldn't alloc mem for sysfs paths"); - return -1; - } - - // get proper (in absolute/relative) IIO path & build MPU's sysfs paths - inv_get_sysfs_path(sysfs_path); - - sprintf(mpu.enable, "%s%s", sysfs_path, "/buffer/enable"); - sprintf(mpu.power_state, "%s%s", sysfs_path, "/power_state"); - sprintf(mpu.dmp_on,"%s%s", sysfs_path, "/dmp_on"); - sprintf(mpu.self_test, "%s%s", sysfs_path, "/self_test"); - sprintf(mpu.temperature, "%s%s", sysfs_path, "/temperature"); - - sprintf(mpu.gyro_enable, "%s%s", sysfs_path, "/gyro_enable"); - sprintf(mpu.gyro_x_bias, "%s%s", sysfs_path, "/in_anglvel_x_calibbias"); - sprintf(mpu.gyro_y_bias, "%s%s", sysfs_path, "/in_anglvel_y_calibbias"); - sprintf(mpu.gyro_z_bias, "%s%s", sysfs_path, "/in_anglvel_z_calibbias"); - - sprintf(mpu.accel_enable, "%s%s", sysfs_path, "/accl_enable"); - sprintf(mpu.accel_x_bias, "%s%s", sysfs_path, "/in_accel_x_calibbias"); - sprintf(mpu.accel_y_bias, "%s%s", sysfs_path, "/in_accel_y_calibbias"); - sprintf(mpu.accel_z_bias, "%s%s", sysfs_path, "/in_accel_z_calibbias"); - - sprintf(mpu.compass_enable, "%s%s", sysfs_path, "/compass_enable"); - -#if 0 - // test print sysfs paths - dptr = (char**)&mpu; - for (i = 0; i < MAX_SYSFS_ATTRB; i++) { - MPL_LOGE("inv_self_test: sysfs path: %s", *dptr++); - } -#endif - return 0; -} - -/******************************************************************************* - * M a i n S e l f T e s t - ******************************************************************************/ -int main(int argc, char **argv) -{ - FILE *fptr; - int self_test_status = 0; - inv_error_t result; - bias_dtype gyro_bias[3]; - bias_dtype accel_bias[3]; - int axis = 0; - size_t packet_sz; - int axis_sign = 1; - unsigned char *buffer; - long timestamp; - int temperature = 0; - bool compass_present = TRUE; - - result = inv_init_sysfs_attributes(); - if (result) - return -1; - - inv_init_storage_manager(); - - // Clear out data. - memset(&save_data, 0, sizeof(save_data)); - memset(gyro_bias, 0, sizeof(gyro_bias)); - memset(accel_bias, 0, sizeof(accel_bias)); - - // Register packet to be saved. - result = inv_register_load_store( - inv_db_load_func, inv_db_save_func, - sizeof(save_data), INV_DB_SAVE_KEY); - - // Power ON MPUxxxx chip - if (write_sysfs_int(mpu.power_state, 1) < 0) { - printf("Self-Test:ERR-Failed to set power state=1\n"); - } else { - // Note: Driver turns on power automatically when self-test invoked - } - - // Disable Master enable - if (write_sysfs_int(mpu.enable, 0) < 0) { - printf("Self-Test:ERR-Failed to disable master enable\n"); - } - - // Disable DMP - if (write_sysfs_int(mpu.dmp_on, 0) < 0) { - printf("Self-Test:ERR-Failed to disable DMP\n"); - } - - // Enable Accel - if (write_sysfs_int(mpu.accel_enable, 1) < 0) { - printf("Self-Test:ERR-Failed to enable accel\n"); - } - - // Enable Gyro - if (write_sysfs_int(mpu.gyro_enable, 1) < 0) { - printf("Self-Test:ERR-Failed to enable gyro\n"); - } - - // Enable Compass - if (write_sysfs_int(mpu.compass_enable, 1) < 0) { -#ifdef DEBUG_PRINT - printf("Self-Test:ERR-Failed to enable compass\n"); -#endif - compass_present= FALSE; - } - - fptr = fopen(mpu.self_test, "r"); - if (!fptr) { - printf("Self-Test:ERR-Couldn't invoke self-test\n"); - result = -1; - goto free_sysfs_storage; - } - - // Invoke self-test - fscanf(fptr, "%d", &self_test_status); - if (compass_present == TRUE) { - printf("Self-Test:Self test result- " - "Gyro passed= %x, Accel passed= %x, Compass passed= %x\n", - (self_test_status & GYRO_PASS_STATUS_BIT), - (self_test_status & ACCEL_PASS_STATUS_BIT) >> 1, - (self_test_status & COMPASS_PASS_STATUS_BIT) >> 2); - } else { - printf("Self-Test:Self test result- " - "Gyro passed= %x, Accel passed= %x\n", - (self_test_status & GYRO_PASS_STATUS_BIT), - (self_test_status & ACCEL_PASS_STATUS_BIT) >> 1); - } - fclose(fptr); - - if (self_test_status & GYRO_PASS_STATUS_BIT) { - // Read Gyro Bias - if (read_sysfs_int(mpu.gyro_x_bias, &gyro_bias[0].i) < 0 || - read_sysfs_int(mpu.gyro_y_bias, &gyro_bias[1].i) < 0 || - read_sysfs_int(mpu.gyro_z_bias, &gyro_bias[2].i) < 0) { - memset(gyro_bias, 0, sizeof(gyro_bias)); - printf("Self-Test:Failed to read Gyro bias\n"); - } else { - save_data.gyro_accuracy = 3; -#ifdef DEBUG_PRINT - printf("Self-Test:Gyro bias[0..2]= [%d %d %d]\n", - gyro_bias[0].i, gyro_bias[1].i, gyro_bias[2].i); -#endif - } - } else { - printf("Self-Test:Failed Gyro self-test\n"); - } - - if (self_test_status & ACCEL_PASS_STATUS_BIT) { - // Read Accel Bias - if (read_sysfs_int(mpu.accel_x_bias, &accel_bias[0].i) < 0 || - read_sysfs_int(mpu.accel_y_bias, &accel_bias[1].i) < 0 || - read_sysfs_int(mpu.accel_z_bias, &accel_bias[2].i) < 0) { - memset(accel_bias,0, sizeof(accel_bias)); - printf("Self-Test:Failed to read Accel bias\n"); - } else { - save_data.accel_accuracy = 3; -#ifdef DEBUG_PRINT - printf("Self-Test:Accel bias[0..2]= [%d %d %d]\n", - accel_bias[0].i, accel_bias[1].i, accel_bias[2].i); -#endif - } - } else { - printf("Self-Test:Failed Accel self-test\n"); - } - - if (!(self_test_status & (GYRO_PASS_STATUS_BIT | ACCEL_PASS_STATUS_BIT))) { - printf("Self-Test:Failed Gyro and Accel self-test, " - "nothing left to do\n"); - result = -1; - goto free_sysfs_storage; - } - - // Read temperature - fptr= fopen(mpu.temperature, "r"); - if (fptr != NULL) { - fscanf(fptr,"%d %ld", &temperature, ×tamp); - fclose(fptr); - } else { - printf("Self-Test:ERR-Couldn't read temperature\n"); - } - - // When we read gyro bias, the bias is in raw units scaled by 1000. - // We store the bias in raw units scaled by 2^16 - save_data.gyro_bias[0] = (long)(gyro_bias[0].l * 65536.f / 8000.f); - save_data.gyro_bias[1] = (long)(gyro_bias[1].l * 65536.f / 8000.f); - save_data.gyro_bias[2] = (long)(gyro_bias[2].l * 65536.f / 8000.f); - - // Save temperature @ time stored. - // Temperature is in degrees Celsius scaled by 2^16 - save_data.gyro_temp = temperature * (1L << 16); - save_data.accel_temp = save_data.gyro_temp; - - // When we read accel bias, the bias is in raw units scaled by 1000. - // and it contains the gravity vector. - - // Find the orientation of the device, by looking for gravity - if (ABS(accel_bias[1].l) > ABS(accel_bias[0].l)) { - axis = 1; - } - if (ABS(accel_bias[2].l) > ABS(accel_bias[axis].l)) { - axis = 2; - } - if (accel_bias[axis].l < 0) { - axis_sign = -1; - } - - // Remove gravity, gravity in raw units should be 16384 for a 2g setting. - // We read data scaled by 1000, so - accel_bias[axis].l -= axis_sign * 4096L * 1000L; - - // Convert scaling from raw units scaled by 1000 to raw scaled by 2^16 - save_data.accel_bias[0] = (long)(accel_bias[0].l * 65536.f / 1000.f * 4.f); - save_data.accel_bias[1] = (long)(accel_bias[1].l * 65536.f / 1000.f * 4.f); - save_data.accel_bias[2] = (long)(accel_bias[2].l * 65536.f / 1000.f * 4.f); - -#if 1 - printf("Self-Test:Saved Accel bias[0..2]= [%ld %ld %ld]\n", - save_data.accel_bias[0], save_data.accel_bias[1], - save_data.accel_bias[2]); - printf("Self-Test:Saved Gyro bias[0..2]= [%ld %ld %ld]\n", - save_data.gyro_bias[0], save_data.gyro_bias[1], - save_data.gyro_bias[2]); - printf("Self-Test:Gyro temperature @ time stored %ld\n", - save_data.gyro_temp); - printf("Self-Test:Accel temperature @ time stored %ld\n", - save_data.accel_temp); -#endif - - // Get size of packet to store. - inv_get_mpl_state_size(&packet_sz); - - // Create place to store data - buffer = (unsigned char *)malloc(packet_sz + 10); - if (buffer == NULL) { - printf("Self-Test:Can't allocate buffer\n"); - result = -1; - goto free_sysfs_storage; - } - - // Store the data - result = inv_save_mpl_states(buffer, packet_sz); - if (result) { - result = -1; - } else { - fptr= fopen(MLCAL_FILE, "wb+"); - if (fptr != NULL) { - fwrite(buffer, 1, packet_sz, fptr); - fclose(fptr); - } else { - printf("Self-Test:ERR- Can't open calibration file to write - %s\n", - MLCAL_FILE); - result = -1; - } - } - - free(buffer); - -free_sysfs_storage: - free(sysfs_names_ptr); - return result; -} - diff --git a/65xx/libsensors_iio/software/core/driver/include/linux/mpu.h b/65xx/libsensors_iio/software/core/driver/include/linux/mpu.h deleted file mode 100755 index 8676043..0000000 --- a/65xx/libsensors_iio/software/core/driver/include/linux/mpu.h +++ /dev/null @@ -1,103 +0,0 @@ -/* -* Copyright (C) 2012 Invensense, Inc. -* -* This software is licensed under the terms of the GNU General Public -* License version 2, as published by the Free Software Foundation, and -* may be copied, distributed, and modified under those terms. -* -* 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 __MPU_H_ -#define __MPU_H_ - -#ifdef __KERNEL__ -#include <linux/types.h> -#include <linux/ioctl.h> -#endif - -enum secondary_slave_type { - SECONDARY_SLAVE_TYPE_NONE, - SECONDARY_SLAVE_TYPE_ACCEL, - SECONDARY_SLAVE_TYPE_COMPASS, - SECONDARY_SLAVE_TYPE_PRESSURE, - - SECONDARY_SLAVE_TYPE_TYPES -}; - -enum ext_slave_id { - ID_INVALID = 0, - GYRO_ID_MPU3050, - GYRO_ID_MPU6050A2, - GYRO_ID_MPU6050B1, - GYRO_ID_MPU6050B1_NO_ACCEL, - GYRO_ID_ITG3500, - - ACCEL_ID_LIS331, - ACCEL_ID_LSM303DLX, - ACCEL_ID_LIS3DH, - ACCEL_ID_KXSD9, - ACCEL_ID_KXTF9, - ACCEL_ID_BMA150, - ACCEL_ID_BMA222, - ACCEL_ID_BMA250, - ACCEL_ID_ADXL34X, - ACCEL_ID_MMA8450, - ACCEL_ID_MMA845X, - ACCEL_ID_MPU6050, - - COMPASS_ID_AK8963, - COMPASS_ID_AK8975, - COMPASS_ID_AK8972, - COMPASS_ID_AMI30X, - COMPASS_ID_AMI306, - COMPASS_ID_YAS529, - COMPASS_ID_YAS530, - COMPASS_ID_HMC5883, - COMPASS_ID_LSM303DLH, - COMPASS_ID_LSM303DLM, - COMPASS_ID_MMC314X, - COMPASS_ID_HSCDTD002B, - COMPASS_ID_HSCDTD004A, - COMPASS_ID_MLX90399, - - PRESSURE_ID_BMP085, - PRESSURE_ID_BMP280, -}; - -#define INV_PROD_KEY(ver, rev) (ver * 100 + rev) -/** - * struct mpu_platform_data - Platform data for the mpu driver - * @int_config: Bits [7:3] of the int config register. - * @level_shifter: 0: VLogic, 1: VDD - * @orientation: Orientation matrix of the gyroscope - * @sec_slave_type: secondary slave device type, can be compass, accel, etc - * @sec_slave_id: id of the secondary slave device - * @secondary_i2c_address: secondary device's i2c address - * @secondary_orientation: secondary device's orientation matrix - * @key: key for MPL library. - * - * Contains platform specific information on how to configure the MPU3050 to - * work on this platform. The orientation matricies are 3x3 rotation matricies - * that are applied to the data to rotate from the mounting orientation to the - * platform orientation. The values must be one of 0, 1, or -1 and each row and - * column should have exactly 1 non-zero value. - */ -struct mpu_platform_data { - __u8 int_config; - __u8 level_shifter; - __s8 orientation[9]; - enum secondary_slave_type sec_slave_type; - enum ext_slave_id sec_slave_id; - __u16 secondary_i2c_addr; - __s8 secondary_orientation[9]; - __u8 key[16]; - enum secondary_slave_type aux_slave_type; - enum ext_slave_id aux_slave_id; - __u16 aux_i2c_addr; -}; - -#endif /* __MPU_H_ */ diff --git a/65xx/libsensors_iio/software/simple_apps/common/console_helper.c b/65xx/libsensors_iio/software/simple_apps/common/console_helper.c deleted file mode 100755 index 2888627..0000000 --- a/65xx/libsensors_iio/software/simple_apps/common/console_helper.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - $License: - Copyright (C) 2012 InvenSense Corporation, All Rights Reserved. - $ - */ - -/****************************************************************************** - * - * $Id:$ - * - *****************************************************************************/ - -#include <stdio.h> -#ifdef _WIN32 -#include <windows.h> -#include <conio.h> -#endif -#ifdef LINUX -#include <sys/select.h> -#endif -#include <time.h> -#include <string.h> - -int ConsoleKbhit(void) -{ -#ifdef _WIN32 - return _kbhit(); -#else - struct timeval tv; - fd_set read_fd; - - tv.tv_sec=0; - tv.tv_usec=0; - FD_ZERO(&read_fd); - FD_SET(0, &read_fd); - - if(select(1, &read_fd, NULL, NULL, &tv) == -1) - return 0; - - if(FD_ISSET(0, &read_fd)) - return 1; - - return 0; -#endif -} - -char ConsoleGetChar(void) -{ -#ifdef _WIN32 - return _getch(); -#else - return getchar(); -#endif -} diff --git a/65xx/libsensors_iio/software/simple_apps/common/console_helper.h b/65xx/libsensors_iio/software/simple_apps/common/console_helper.h deleted file mode 100755 index 5251d1c..0000000 --- a/65xx/libsensors_iio/software/simple_apps/common/console_helper.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - $License: - Copyright (C) 2011 InvenSense Corporation, All Rights Reserved. - $ - */ - -/****************************************************************************** - * - * $Id:$ - * - *****************************************************************************/ - -#ifndef _CONSOLE_HELPER_H_ -#define _CONSOLE_HELPER_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -//#include "mltypes.h" - -/* - Prototypes -*/ - -char ConsoleGetChar(void); -int ConsoleKbhit(void); - -#ifdef __cplusplus -} -#endif - -#endif // _CONSOLE_HELPER_H_ diff --git a/65xx/libsensors_iio/software/simple_apps/common/mlerrorcode.c b/65xx/libsensors_iio/software/simple_apps/common/mlerrorcode.c deleted file mode 100755 index 25b0df6..0000000 --- a/65xx/libsensors_iio/software/simple_apps/common/mlerrorcode.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - $License: - Copyright (C) 2011 InvenSense Corporation, All Rights Reserved. - $ - */ - -/****************************************************************************** - * - * $Id: mlerrorcode.c 5629 2011-06-11 03:13:08Z mcaramello $ - * - *****************************************************************************/ - -#include <stdio.h> -#include <string.h> - -#include "mltypes.h" -#include "mlerrorcode.h" - -#define ERROR_CODE_CASE(CODE) \ - case CODE: \ - return #CODE \ - -/** - * @brief return a string containing the label assigned to the error code. - * - * @param errorcode - * The errorcode value of which the label has to be returned. - * - * @return A string containing the error code label. - */ -char* MLErrorCode(inv_error_t errorcode) -{ - switch(errorcode) { - ERROR_CODE_CASE(INV_SUCCESS); - ERROR_CODE_CASE(INV_ERROR); - ERROR_CODE_CASE(INV_ERROR_INVALID_PARAMETER); - ERROR_CODE_CASE(INV_ERROR_FEATURE_NOT_ENABLED); - ERROR_CODE_CASE(INV_ERROR_FEATURE_NOT_IMPLEMENTED); - ERROR_CODE_CASE(INV_ERROR_DMP_NOT_STARTED); - ERROR_CODE_CASE(INV_ERROR_DMP_STARTED); - ERROR_CODE_CASE(INV_ERROR_NOT_OPENED); - ERROR_CODE_CASE(INV_ERROR_OPENED); - ERROR_CODE_CASE(INV_ERROR_INVALID_MODULE); - ERROR_CODE_CASE(INV_ERROR_MEMORY_EXAUSTED); - ERROR_CODE_CASE(INV_ERROR_DIVIDE_BY_ZERO); - ERROR_CODE_CASE(INV_ERROR_ASSERTION_FAILURE); - ERROR_CODE_CASE(INV_ERROR_FILE_OPEN); - ERROR_CODE_CASE(INV_ERROR_FILE_READ); - ERROR_CODE_CASE(INV_ERROR_FILE_WRITE); - - ERROR_CODE_CASE(INV_ERROR_SERIAL_CLOSED); - ERROR_CODE_CASE(INV_ERROR_SERIAL_OPEN_ERROR); - ERROR_CODE_CASE(INV_ERROR_SERIAL_READ); - ERROR_CODE_CASE(INV_ERROR_SERIAL_WRITE); - ERROR_CODE_CASE(INV_ERROR_SERIAL_DEVICE_NOT_RECOGNIZED); - - ERROR_CODE_CASE(INV_ERROR_SM_TRANSITION); - ERROR_CODE_CASE(INV_ERROR_SM_IMPROPER_STATE); - - ERROR_CODE_CASE(INV_ERROR_FIFO_OVERFLOW); - ERROR_CODE_CASE(INV_ERROR_FIFO_FOOTER); - ERROR_CODE_CASE(INV_ERROR_FIFO_READ_COUNT); - ERROR_CODE_CASE(INV_ERROR_FIFO_READ_DATA); - ERROR_CODE_CASE(INV_ERROR_MEMORY_SET); - - ERROR_CODE_CASE(INV_ERROR_LOG_MEMORY_ERROR); - ERROR_CODE_CASE(INV_ERROR_LOG_OUTPUT_ERROR); - - ERROR_CODE_CASE(INV_ERROR_OS_BAD_PTR); - ERROR_CODE_CASE(INV_ERROR_OS_BAD_HANDLE); - ERROR_CODE_CASE(INV_ERROR_OS_CREATE_FAILED); - ERROR_CODE_CASE(INV_ERROR_OS_LOCK_FAILED); - - ERROR_CODE_CASE(INV_ERROR_COMPASS_DATA_OVERFLOW); - ERROR_CODE_CASE(INV_ERROR_COMPASS_DATA_UNDERFLOW); - ERROR_CODE_CASE(INV_ERROR_COMPASS_DATA_NOT_READY); - ERROR_CODE_CASE(INV_ERROR_COMPASS_DATA_ERROR); - - ERROR_CODE_CASE(INV_ERROR_CALIBRATION_LOAD); - ERROR_CODE_CASE(INV_ERROR_CALIBRATION_STORE); - ERROR_CODE_CASE(INV_ERROR_CALIBRATION_LEN); - ERROR_CODE_CASE(INV_ERROR_CALIBRATION_CHECKSUM); - - default: - { - #define UNKNOWN_ERROR_CODE 1234 - return ERROR_NAME(UNKNOWN_ERROR_CODE); - break; - } - - } -} - -/** - * @} - */ diff --git a/65xx/libsensors_iio/software/simple_apps/common/mlerrorcode.h b/65xx/libsensors_iio/software/simple_apps/common/mlerrorcode.h deleted file mode 100755 index 9a35792..0000000 --- a/65xx/libsensors_iio/software/simple_apps/common/mlerrorcode.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - $License: - Copyright (C) 2011 InvenSense Corporation, All Rights Reserved. - $ - */ -/******************************************************************************* - * - * $Id: mltypes.h 3680 2010-09-04 03:13:32Z mcaramello $ - * - *******************************************************************************/ - -#ifndef _MLERRORCODE_H_ -#define _MLERRORCODE_H_ - -#include "mltypes.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* - Defines -*/ -#define CALL_N_CHECK(f) { \ - unsigned int r35uLt = f; \ - if(INV_SUCCESS != r35uLt) { \ - MPL_LOGE("Error in file %s, line %d : %s returned code %s (#%d)\n", \ - __FILE__, __LINE__, #f, MLErrorCode(r35uLt), r35uLt); \ - } \ -} - -#define CALL_CHECK_N_RETURN_ERROR(f) { \ - unsigned int r35uLt = f; \ - if(INV_SUCCESS != r35uLt) { \ - MPL_LOGE("Error in file %s, line %d : %s returned code %s (#%d)\n", \ - __FILE__, __LINE__, #f, MLErrorCode(r35uLt), r35uLt); \ - return r35uLt; \ - } \ -} - -// for functions returning void -#define CALL_CHECK_N_RETURN(f) do { \ - unsigned int r35uLt = f; \ - if(INV_SUCCESS != r35uLt) { \ - MPL_LOGE("Error in file %s, line %d : %s returned code %s (#%d)\n", \ - __FILE__, __LINE__, #f, MLErrorCode(r35uLt), r35uLt); \ - return; \ - } \ - } while(0) - -#define CALL_CHECK_N_EXIT(f) { \ - unsigned int r35uLt = f; \ - if(INV_SUCCESS != r35uLt) { \ - MPL_LOGE("Error in file %s, line %d : %s returned code %s (#%d)\n", \ - __FILE__, __LINE__, #f, MLErrorCode(r35uLt), r35uLt); \ - exit (r35uLt); \ - } \ -} - - -#define CALL_CHECK_N_CALLBACK(f, cb) { \ - unsigned int r35uLt = f; \ - if(INV_SUCCESS != r35uLt) { \ - MPL_LOGE("Error in file %s, line %d : %s returned code %s (#%d)\n", \ - __FILE__, __LINE__, #f, MLErrorCode(r35uLt), r35uLt); \ - cb; \ - } \ -} - -#define CALL_CHECK_N_GOTO(f, label) { \ - unsigned int r35uLt = f; \ - if(INV_SUCCESS != r35uLt) { \ - MPL_LOGE("Error in file %s, line %d : %s returned code %s (#%d)\n", \ - __FILE__, __LINE__, #f, MLErrorCode(r35uLt), r35uLt); \ - goto label; \ - } \ -} - -char* MLErrorCode(inv_error_t errorcode); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/65xx/libsensors_iio/software/simple_apps/common/testsupport.h b/65xx/libsensors_iio/software/simple_apps/common/testsupport.h deleted file mode 100755 index 0cab781..0000000 --- a/65xx/libsensors_iio/software/simple_apps/common/testsupport.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - $License: - Copyright (C) 2011 InvenSense Corporation, All Rights Reserved. - $ - */ - -/******************************************************************************* - * - * $Id: testsupport.h 5629 2011-06-11 03:13:08Z mcaramello $ - * - ******************************************************************************/ - -#ifndef _TESTSUPPORT_H_ -#define _TESTSUPPORT_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/*--------------------------- - Includes ----------------------------*/ - -#include "mltypes.h" -#include "mlerrorcode.h" - -#include "mlsl.h" -#include "log.h" - -/*--------------------------- - Defines ----------------------------*/ - -/*--------------------------- - p-Types ----------------------------*/ -#ifdef TESTING_SUPPORT - void SetHandle (void *sl_handle); - void CommandPrompt (void *sl_handle); - void RegisterMap (void *sl_handle); - void DataLogger (const unsigned long flag); - void DataLoggerSelector (const unsigned long flag); - void DataLoggerCb (void); - unsigned short KeyboardHandler (unsigned char key); - char* CompassStateName (char* out, int state); -#else -#define DataLoggerSelector(x) // -#define DataLogger(x) // -#define DataLoggerCb NULL -#endif - -#ifdef __cplusplus -} -#endif - -#endif // _TESTSUPPORT_H_ - diff --git a/65xx/libsensors_iio/software/simple_apps/devnode_parser/build/android/inv_devnode_parser-shared b/65xx/libsensors_iio/software/simple_apps/devnode_parser/build/android/inv_devnode_parser-shared Binary files differdeleted file mode 100755 index b4a6bdf..0000000 --- a/65xx/libsensors_iio/software/simple_apps/devnode_parser/build/android/inv_devnode_parser-shared +++ /dev/null diff --git a/65xx/libsensors_iio/software/simple_apps/devnode_parser/build/android/shared.mk b/65xx/libsensors_iio/software/simple_apps/devnode_parser/build/android/shared.mk deleted file mode 100755 index 38d1fb4..0000000 --- a/65xx/libsensors_iio/software/simple_apps/devnode_parser/build/android/shared.mk +++ /dev/null @@ -1,92 +0,0 @@ -EXEC = inv_devnode_parser$(SHARED_APP_SUFFIX) - -MK_NAME = $(notdir $(CURDIR)/$(firstword $(MAKEFILE_LIST))) - -CROSS ?= $(ANDROID_ROOT)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- -COMP ?= $(CROSS)gcc -LINK ?= $(CROSS)gcc - -OBJFOLDER = $(CURDIR)/obj - -INV_ROOT = ../../../../.. -APP_DIR = $(CURDIR)/../.. -MLLITE_DIR = $(INV_ROOT)/software/core/mllite - -include $(INV_ROOT)/software/build/android/common.mk - -CFLAGS += $(CMDLINE_CFLAGS) -CFLAGS += $(ANDROID_COMPILE) -CFLAGS += -Wall -CFLAGS += -fpic -CFLAGS += -nostdlib -CFLAGS += -DNDEBUG -CFLAGS += -D_REENTRANT -CFLAGS += -DLINUX -CFLAGS += -DANDROID -CFLAGS += -mthumb-interwork -CFLAGS += -fno-exceptions -CFLAGS += -ffunction-sections -CFLAGS += -funwind-tables -CFLAGS += -fstack-protector -CFLAGS += -fno-short-enums -CFLAGS += -fmessage-length=0 -CFLAGS += -I$(MLLITE_DIR) -CFLAGS += -I$(MPL_DIR) -CFLAGS += $(INV_INCLUDES) -CFLAGS += $(INV_DEFINES) - -LLINK = -lc -LLINK += -lm -LLINK += -lutils -LLINK += -lcutils -LLINK += -lgcc -LLINK += -ldl -LLINK += -lstdc++ -LLINK += -llog -LLINK += -lz - -LFLAGS += $(CMDLINE_LFLAGS) -LFLAGS += $(ANDROID_LINK_EXECUTABLE) - -LRPATH = -Wl,-rpath,$(ANDROID_ROOT)/out/target/product/$(PRODUCT)/obj/lib:$(ANDROID_ROOT)/out/target/product/$(PRODUCT)/system/lib - -#################################################################################################### -## sources - -INV_LIBS = $(MLLITE_DIR)/build/$(TARGET)/$(LIB_PREFIX)$(MLLITE_LIB_NAME).$(SHARED_LIB_EXT) - -#INV_SOURCES and VPATH provided by Makefile.filelist -include ../filelist.mk - -INV_OBJS := $(addsuffix .o,$(INV_SOURCES)) -INV_OBJS_DST = $(addprefix $(OBJFOLDER)/,$(addsuffix .o, $(notdir $(INV_SOURCES)))) - -#################################################################################################### -## rules - -.PHONY: all clean cleanall install - -all: $(EXEC) $(MK_NAME) - -$(EXEC) : $(OBJFOLDER) $(INV_OBJS_DST) $(INV_LIBS) $(MK_NAME) - @$(call echo_in_colors, "\n<linking $(EXEC) with objects $(INV_OBJS_DST) $(PREBUILT_OBJS) and libraries $(INV_LIBS)\n") - $(LINK) $(INV_OBJS_DST) -o $(EXEC) $(LFLAGS) $(LLINK) $(INV_LIBS) $(LLINK) $(LRPATH) - -$(OBJFOLDER) : - @$(call echo_in_colors, "\n<creating object's folder 'obj/'>\n") - mkdir obj - -$(INV_OBJS_DST) : $(OBJFOLDER)/%.c.o : %.c $(MK_NAME) - @$(call echo_in_colors, "\n<compile $< to $(OBJFOLDER)/$(notdir $@)>\n") - $(COMP) $(ANDROID_INCLUDES) $(KERNEL_INCLUDES) $(INV_INCLUDES) $(CFLAGS) -o $@ -c $< - -clean : - rm -fR $(OBJFOLDER) - -cleanall : - rm -fR $(EXEC) $(OBJFOLDER) - -install : $(EXEC) - cp -f $(EXEC) $(INSTALL_DIR) - - diff --git a/65xx/libsensors_iio/software/simple_apps/devnode_parser/build/filelist.mk b/65xx/libsensors_iio/software/simple_apps/devnode_parser/build/filelist.mk deleted file mode 100755 index fdecbc8..0000000 --- a/65xx/libsensors_iio/software/simple_apps/devnode_parser/build/filelist.mk +++ /dev/null @@ -1,11 +0,0 @@ -#### filelist.mk for inv_devnode_parser #### - -# headers -HEADERS += $(APP_DIR)/iio_utils.h - -# sources -SOURCES := $(APP_DIR)/read_device_node.c - -INV_SOURCES += $(SOURCES) - -VPATH += $(APP_DIR) $(COMMON_DIR) $(HAL_DIR)/linux diff --git a/65xx/libsensors_iio/software/simple_apps/devnode_parser/iio_utils.h b/65xx/libsensors_iio/software/simple_apps/devnode_parser/iio_utils.h deleted file mode 100755 index c3d4955..0000000 --- a/65xx/libsensors_iio/software/simple_apps/devnode_parser/iio_utils.h +++ /dev/null @@ -1,650 +0,0 @@ -/* IIO - useful set of util functionality - * - * Copyright (c) 2008 Jonathan Cameron - * - * 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. - */ - -/* Made up value to limit allocation sizes */ -#include <string.h> -#include <stdlib.h> -#include <ctype.h> -#include <stdio.h> -#include <stdint.h> -#include <dirent.h> - -#define IIO_MAX_NAME_LENGTH 30 - -#define FORMAT_SCAN_ELEMENTS_DIR "%s/scan_elements" -#define FORMAT_TYPE_FILE "%s_type" - -const char *iio_dir = "/sys/bus/iio/devices/"; - -extern int verbose; - -/** - * iioutils_break_up_name() - extract generic name from full channel name - * @full_name: the full channel name - * @generic_name: the output generic channel name - **/ -static int iioutils_break_up_name(const char *full_name, - char **generic_name) -{ - char *current; - char *w, *r; - char *working; - current = strdup(full_name); - working = strtok(current, "_\0"); - w = working; - r = working; - - while (*r != '\0') { - if (!isdigit(*r)) { - *w = *r; - w++; - } - r++; - } - *w = '\0'; - *generic_name = strdup(working); - free(current); - - return 0; -} - -/** - * struct iio_channel_info - information about a given channel - * @name: channel name - * @generic_name: general name for channel type - * @scale: scale factor to be applied for conversion to si units - * @offset: offset to be applied for conversion to si units - * @index: the channel index in the buffer output - * @bytes: number of bytes occupied in buffer output - * @mask: a bit mask for the raw output - * @is_signed: is the raw value stored signed - * @enabled: is this channel enabled - **/ -struct iio_channel_info { - char *name; - char *generic_name; - float scale; - float offset; - unsigned index; - unsigned bytes; - unsigned bits_used; - unsigned shift; - uint64_t mask; - unsigned be; - unsigned is_signed; - unsigned enabled; - unsigned location; -}; - -/** - * iioutils_get_type() - find and process _type attribute data - * @is_signed: output whether channel is signed - * @bytes: output how many bytes the channel storage occupies - * @mask: output a bit mask for the raw data - * @be: big endian - * @device_dir: the iio device directory - * @name: the channel name - * @generic_name: the channel type name - **/ -inline int iioutils_get_type(unsigned *is_signed, - unsigned *bytes, - unsigned *bits_used, - unsigned *shift, - uint64_t *mask, - unsigned *be, - const char *device_dir, - const char *name, - const char *generic_name) -{ - FILE *sysfsfp; - int ret; - DIR *dp; - char *scan_el_dir, *builtname, *builtname_generic, *filename = 0; - char signchar, endianchar; - unsigned padint; - const struct dirent *ent; - - ret = asprintf(&scan_el_dir, FORMAT_SCAN_ELEMENTS_DIR, device_dir); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - ret = asprintf(&builtname, FORMAT_TYPE_FILE, name); - if (ret < 0) { - ret = -ENOMEM; - goto error_free_scan_el_dir; - } - ret = asprintf(&builtname_generic, FORMAT_TYPE_FILE, generic_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_free_builtname; - } - - dp = opendir(scan_el_dir); - if (dp == NULL) { - ret = -errno; - goto error_free_builtname_generic; - } - while (ent = readdir(dp), ent != NULL) - /* - * Do we allow devices to override a generic name with - * a specific one? - */ - if ((strcmp(builtname, ent->d_name) == 0) || - (strcmp(builtname_generic, ent->d_name) == 0)) { - ret = asprintf(&filename, - "%s/%s", scan_el_dir, ent->d_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_closedir; - } - sysfsfp = fopen(filename, "r"); - if (sysfsfp == NULL) { - printf("failed to open %s\n", filename); - ret = -errno; - goto error_free_filename; - } - - ret = fscanf(sysfsfp, - "%ce:%c%u/%u>>%u", - &endianchar, - &signchar, - bits_used, - &padint, shift); - if (ret < 0) { - printf("failed to pass scan type description\n"); - return ret; - } - *be = (endianchar == 'b'); - *bytes = padint / 8; - if (*bits_used == 64) - *mask = ~0; - else - *mask = (1 << *bits_used) - 1; - if (signchar == 's') - *is_signed = 1; - else - *is_signed = 0; - fclose(sysfsfp); - free(filename); - - filename = 0; - } -error_free_filename: - if (filename) - free(filename); -error_closedir: - closedir(dp); -error_free_builtname_generic: - free(builtname_generic); -error_free_builtname: - free(builtname); -error_free_scan_el_dir: - free(scan_el_dir); -error_ret: - return ret; -} - -inline int iioutils_get_param_float(float *output, - const char *param_name, - const char *device_dir, - const char *name, - const char *generic_name) -{ - FILE *sysfsfp; - int ret; - DIR *dp; - char *builtname, *builtname_generic; - char *filename = NULL; - const struct dirent *ent; - - ret = asprintf(&builtname, "%s_%s", name, param_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - ret = asprintf(&builtname_generic, - "%s_%s", generic_name, param_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_free_builtname; - } - dp = opendir(device_dir); - if (dp == NULL) { - ret = -errno; - goto error_free_builtname_generic; - } - while (ent = readdir(dp), ent != NULL) - if ((strcmp(builtname, ent->d_name) == 0) || - (strcmp(builtname_generic, ent->d_name) == 0)) { - ret = asprintf(&filename, - "%s/%s", device_dir, ent->d_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_closedir; - } - sysfsfp = fopen(filename, "r"); - if (!sysfsfp) { - ret = -errno; - goto error_free_filename; - } - fscanf(sysfsfp, "%f", output); - break; - } -error_free_filename: - if (filename) - free(filename); -error_closedir: - closedir(dp); -error_free_builtname_generic: - free(builtname_generic); -error_free_builtname: - free(builtname); -error_ret: - return ret; -} - -/** - * bsort_channel_array_by_index() - reorder so that the array is in index order - * - **/ - -inline void bsort_channel_array_by_index(struct iio_channel_info **ci_array, - int cnt) -{ - struct iio_channel_info temp; - int x, y; - - for (x = 0; x < cnt; x++) - for (y = 0; y < (cnt - 1); y++) - if ((*ci_array)[y].index > (*ci_array)[y+1].index) { - temp = (*ci_array)[y + 1]; - (*ci_array)[y + 1] = (*ci_array)[y]; - (*ci_array)[y] = temp; - } -} - -/** - * build_channel_array() - function to figure out what channels are present - * @device_dir: the IIO device directory in sysfs - * @ - **/ -inline int build_channel_array(const char *device_dir, - struct iio_channel_info **ci_array, - int *counter) -{ - DIR *dp; - FILE *sysfsfp; - int count, i; - struct iio_channel_info *current; - int ret; - const struct dirent *ent; - char *scan_el_dir; - char *filename; - - *counter = 0; - ret = asprintf(&scan_el_dir, FORMAT_SCAN_ELEMENTS_DIR, device_dir); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - dp = opendir(scan_el_dir); - if (dp == NULL) { - ret = -errno; - goto error_free_name; - } - while (ent = readdir(dp), ent != NULL) - if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), - "_en") == 0) { - ret = asprintf(&filename, - "%s/%s", scan_el_dir, ent->d_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_close_dir; - } - sysfsfp = fopen(filename, "r"); - if (sysfsfp == NULL) { - ret = -errno; - free(filename); - goto error_close_dir; - } - fscanf(sysfsfp, "%u", &ret); - //printf("%s, %d\n", filename, ret); - if (ret == 1) - (*counter)++; - fclose(sysfsfp); - free(filename); - } - *ci_array = malloc(sizeof(**ci_array) * (*counter)); - if (*ci_array == NULL) { - ret = -ENOMEM; - goto error_close_dir; - } - closedir(dp); - dp = opendir(scan_el_dir); - //seekdir(dp, 0); - count = 0; - while (ent = readdir(dp), ent != NULL) { - if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), - "_en") == 0) { - current = &(*ci_array)[count++]; - ret = asprintf(&filename, - "%s/%s", scan_el_dir, ent->d_name); - if (ret < 0) { - ret = -ENOMEM; - /* decrement count to avoid freeing name */ - count--; - goto error_cleanup_array; - } - sysfsfp = fopen(filename, "r"); - if (sysfsfp == NULL) { - free(filename); - ret = -errno; - goto error_cleanup_array; - } - fscanf(sysfsfp, "%u", ¤t->enabled); - fclose(sysfsfp); - - if (!current->enabled) { - free(filename); - count--; - continue; - } - - current->scale = 1.0; - current->offset = 0; - current->name = strndup(ent->d_name, - strlen(ent->d_name) - - strlen("_en")); - if (current->name == NULL) { - free(filename); - ret = -ENOMEM; - goto error_cleanup_array; - } - /* Get the generic and specific name elements */ - ret = iioutils_break_up_name(current->name, - ¤t->generic_name); - if (ret) { - free(filename); - goto error_cleanup_array; - } - ret = asprintf(&filename, - "%s/%s_index", - scan_el_dir, - current->name); - if (ret < 0) { - free(filename); - ret = -ENOMEM; - goto error_cleanup_array; - } - sysfsfp = fopen(filename, "r"); - fscanf(sysfsfp, "%u", ¤t->index); - fclose(sysfsfp); - free(filename); - /* Find the scale */ - ret = iioutils_get_param_float(¤t->scale, - "scale", - device_dir, - current->name, - current->generic_name); - if (ret < 0) - goto error_cleanup_array; - ret = iioutils_get_param_float(¤t->offset, - "offset", - device_dir, - current->name, - current->generic_name); - if (ret < 0) - goto error_cleanup_array; - ret = iioutils_get_type(¤t->is_signed, - ¤t->bytes, - ¤t->bits_used, - ¤t->shift, - ¤t->mask, - ¤t->be, - device_dir, - current->name, - current->generic_name); - } - } - - closedir(dp); - /* reorder so that the array is in index order */ - bsort_channel_array_by_index(ci_array, *counter); - - return 0; - -error_cleanup_array: - for (i = count - 1; i >= 0; i--) - free((*ci_array)[i].name); - free(*ci_array); -error_close_dir: - closedir(dp); -error_free_name: - free(scan_el_dir); -error_ret: - return ret; -} - -inline int _write_sysfs_int(char *filename, char *basedir, int val, int verify) -{ - int ret = 0; - FILE *sysfsfp; - int test; - char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) - return -ENOMEM; - - sprintf(temp, "%s/%s", basedir, filename); - - if (verbose) - printf("VERB: echo %d > %s\n", val, temp); - sysfsfp = fopen(temp, "w"); - if (sysfsfp == NULL) { - printf("failed to open %s\n", temp); - ret = -errno; - goto error_free; - } - fprintf(sysfsfp, "%d", val); - fclose(sysfsfp); - - if (verify) { - sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { - printf("failed to open %s\n", temp); - ret = -errno; - goto error_free; - } - fscanf(sysfsfp, "%d", &test); - fclose(sysfsfp); - if (verbose) - printf("VERB: cat %s = %d\n", temp, test); - if (test != val) { - printf("Possible failure in int write %d to %s\n", - val, temp); - ret = -1; - } - } - -error_free: - free(temp); - return ret; -} - -int write_sysfs_int(char *filename, char *basedir, int val) -{ - return _write_sysfs_int(filename, basedir, val, 0); -} - -int write_sysfs_int_and_verify(char *filename, char *basedir, int val) -{ - return _write_sysfs_int(filename, basedir, val, 1); -} - -int _write_sysfs_string(char *filename, char *basedir, char *val, int verify) -{ - int ret = 0; - FILE *sysfsfp; - char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) { - printf("Memory allocation failed\n"); - return -ENOMEM; - } - sprintf(temp, "%s/%s", basedir, filename); - - sysfsfp = fopen(temp, "w"); - if (sysfsfp == NULL) { - printf("Could not open %s\n", temp); - ret = -errno; - goto error_free; - } - fprintf(sysfsfp, "%s", val); - fclose(sysfsfp); - - if (verify) { - sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { - printf("could not open file to verify\n"); - ret = -errno; - goto error_free; - } - fscanf(sysfsfp, "%s", temp); - fclose(sysfsfp); - - if (strcmp(temp, val) != 0) { - printf("Possible failure in string write of %s " - "Should be %s written to %s\%s\n", - temp, val, basedir, filename); - ret = -1; - } - } - -error_free: - free(temp); - - return ret; -} - -/** - * write_sysfs_string_and_verify() - string write, readback and verify - * @filename: name of file to write to - * @basedir: the sysfs directory in which the file is to be found - * @val: the string to write - **/ -int write_sysfs_string_and_verify(char *filename, char *basedir, char *val) -{ - return _write_sysfs_string(filename, basedir, val, 1); -} - -int write_sysfs_string(char *filename, char *basedir, char *val) -{ - return _write_sysfs_string(filename, basedir, val, 0); -} - -int read_sysfs_posint(char *filename, char *basedir) -{ - int ret; - FILE *sysfsfp; - char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) { - printf("Memory allocation failed"); - return -ENOMEM; - } - sprintf(temp, "%s/%s", basedir, filename); - sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { - ret = -errno; - goto error_free; - } - fscanf(sysfsfp, "%d\n", &ret); - fclose(sysfsfp); -error_free: - free(temp); - return ret; -} - -int read_sysfs_float(char *filename, char *basedir, float *val) -{ - float ret = 0; - FILE *sysfsfp; - char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) { - printf("Memory allocation failed"); - return -ENOMEM; - } - sprintf(temp, "%s/%s", basedir, filename); - sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { - ret = -errno; - goto error_free; - } - fscanf(sysfsfp, "%f\n", val); - fclose(sysfsfp); - -error_free: - free(temp); - return ret; -} - -int enable_se(const char *device_dir, struct iio_channel_info **ci_array, - int *counter, char *sensor, int en) -{ - DIR *dp; - int ret; - const struct dirent *ent; - char *scan_el_dir; - char pattern[50] = "in_"; - - *counter = 0; - ret = asprintf(&scan_el_dir, FORMAT_SCAN_ELEMENTS_DIR, device_dir); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - dp = opendir(scan_el_dir); - if (dp == NULL) { - ret = -errno; - goto error_free_name; - } - strcat(pattern, sensor); - while (ent = readdir(dp), ent != NULL) { - if (strncmp(ent->d_name, pattern, strlen(pattern)) == 0 && - strncmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), - "_en", strlen("_en")) == 0) { - write_sysfs_int_and_verify((char *)ent->d_name, scan_el_dir, en); - } - } - return 0; - -error_ret: -error_free_name: - return -1; -} - -int enable_accel_se(const char *device_dir, - struct iio_channel_info **ci_array, int *counter, - int en) -{ - return enable_se(device_dir, ci_array, counter, "accel", en); -} - -int enable_anglvel_se(const char *device_dir, - struct iio_channel_info **ci_array, int *counter, - int en) -{ - return enable_se(device_dir, ci_array, counter, "anglvel", en); -} - -int enable_quaternion_se(const char *device_dir, - struct iio_channel_info **ci_array, int *counter, - int en) -{ - return enable_se(device_dir, ci_array, counter, "quaternion", en); -} - diff --git a/65xx/libsensors_iio/software/simple_apps/devnode_parser/read_device_node.c b/65xx/libsensors_iio/software/simple_apps/devnode_parser/read_device_node.c deleted file mode 100755 index 7b73d4a..0000000 --- a/65xx/libsensors_iio/software/simple_apps/devnode_parser/read_device_node.c +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright (c) Invensense Inc. 2012 - * - * 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. - */ - -#include <unistd.h> -#include <dirent.h> -#include <fcntl.h> -#include <stdio.h> -#include <errno.h> -#include <sys/stat.h> -#include <dirent.h> -#include <linux/types.h> -#include <string.h> -#include <poll.h> -#include <termios.h> - -#include "iio_utils.h" -#include "ml_sysfs_helper.h" -#include "mlos.h" - -#define POLL_TIME (2000) // 2sec - -// settings -int verbose = false; - -// paths -char *dev_dir_name; - -/************************************************** - This _kbhit() function is courtesy of the web -***************************************************/ -int _kbhit(void) -{ - static const int STDIN = 0; - static bool initialized = false; - - if (!initialized) { - // Use termios to turn off line buffering - struct termios term; - tcgetattr(STDIN, &term); - term.c_lflag &= ~ICANON; - tcsetattr(STDIN, TCSANOW, &term); - setbuf(stdin, NULL); - initialized = true; - } - - int bytesWaiting; - ioctl(STDIN, FIONREAD, &bytesWaiting); - return bytesWaiting; -} - -void get_sensor_data(char *d, short *sensor) -{ - int i; - for (i = 0; i < 3; i++) - sensor[i] = *(short *)(d + 2 + i * 2); -} - -static int read_data(char *buffer_access) -{ -#define PRESSURE_HDR 0x8000 -#define ACCEL_HDR 0x4000 -#define GYRO_HDR 0x2000 -#define COMPASS_HDR 0x1000 -#define LPQUAT_HDR 0x0800 -#define SIXQUAT_HDR 0x0400 -#define PEDQUAT_HDR 0x0200 -#define STEP_DETECTOR_HDR 0x0100 - - static int left_over_size = 0; - char data[1048], *dptr, tmp[24]; - short sensor[3]; - int q[3]; - int ret, i, ind, fp; - int buf_size, read_size; - unsigned short hdr; - bool done_flag; - - fp = open(buffer_access, O_RDONLY | O_NONBLOCK); - if (fp == -1) { /* if it isn't there make the node */ - printf("Failed to open %s\n", buffer_access); - ret = -errno; - goto error_read_data; - } - ind = 0; - - { - struct pollfd pfd = { - .fd = fp, - .events = POLLIN, - }; - poll(&pfd, 1, -1); - - if (left_over_size > 0) - memcpy(data, tmp, left_over_size); - dptr = data + left_over_size; - - read_size = read(fp, dptr, 1024); - if (read_size <= 0) { - printf("Wrong size=%d\n", read_size); - ret = -EINVAL; - goto error_read_data; - } - - ind = read_size + left_over_size; - dptr = data; - buf_size = ind - (dptr - data); - done_flag = false; - while ((buf_size > 0) && (!done_flag)) { - hdr = *((short *)(dptr)); - if (hdr & 1) - printf("STEP\n"); - - switch (hdr & (~1)) { - case PRESSURE_HDR: - if (buf_size >= 16) { - get_sensor_data(dptr, sensor); - dptr += 8; - printf("PRESS, %d, %lld\n", (sensor[1] << 16) + (unsigned short)sensor[2], *(long long *)dptr); - } else - done_flag = true; - break; - case ACCEL_HDR: - if (buf_size >= 16) { - get_sensor_data(dptr, sensor); - dptr += 8; - printf("ACCEL, %d, %d, %d, %lld\n", sensor[0], sensor[1], sensor[2], *(long long *)dptr); - } else - done_flag = true; - break; - case GYRO_HDR: - if (buf_size >= 16) { - get_sensor_data(dptr, sensor); - dptr += 8; - printf("GYRO, %d, %d, %d, %lld\n", sensor[0], sensor[1], sensor[2], *(long long *)dptr); - } else - done_flag = true; - break; - case COMPASS_HDR: - if (buf_size >= 16) { - get_sensor_data(dptr, sensor); - dptr += 8; - printf("COMPASS, %d, %d, %d, %lld\n", sensor[0], sensor[1], sensor[2], *(long long *)dptr); - } else - done_flag = true; - break; - case PEDQUAT_HDR: - if (buf_size >= 16) { - get_sensor_data(dptr, sensor); - dptr += 8; - printf("LOW_RES_QUAT, %d, %d, %d, %lld\n", sensor[0], sensor[1], sensor[2], *(long long *)dptr); - } else - done_flag = true; - break; - case LPQUAT_HDR: - if (buf_size >= 24) { - q[0] = *(int *)(dptr + 4); - dptr += 8; - q[1] = *(int *)(dptr); - q[2] = *(int *)(dptr + 4); - dptr += 8; - printf("LPQ_3AXES, %d, %d, %d, %lld\n", q[0], q[1], q[2], *(long long *)dptr); - } else - done_flag = true; - break; - case SIXQUAT_HDR: - if (buf_size >= 24) { - q[0] = *(int *)(dptr + 4); - dptr += 8; - q[1] = *(int *)(dptr); - q[2] = *(int *)(dptr + 4); - dptr += 8; - printf("LPQ_6AXES, %d, %d, %d, %lld\n", q[0], q[1], q[2], *(long long *)dptr); - } else - done_flag = true; - break; - case STEP_DETECTOR_HDR: - if (buf_size >= 16) { - printf("STEP_DETECTOR, "); - dptr += 8; - printf("%lld\n", *(long long *)dptr); - } else - done_flag = true; - - break; - default: - printf("unknown, \n"); - for (i = 0; i < 8; i++) - printf("%02x, ", dptr[i]); - printf("\n"); - break; - } - if (!done_flag) - dptr += 8; - buf_size = ind - (dptr - data); - } - if (ind - (dptr - data) > 0) - memcpy(tmp, dptr, ind - (dptr - data)); - left_over_size = ind - (dptr - data); - } - close(fp); - -error_read_data: - return ret; -} - -/* - Main -*/ - -int main(int argc, char **argv) -{ - unsigned long num_loops = -1; - int ret, c, i; - - int dev_num; - char *buffer_access; - char chip_name[10]; - char *dummy; - char device_name[10]; - char sysfs[100]; - - // all output to stdout must be delivered immediately, no buffering - setvbuf(stdout, NULL, _IONBF, 0); - - /* parse the command line parameters - TODO description - */ - while ((c = getopt(argc, argv, "c:vh")) != -1) { - switch (c) { - case 'c': - num_loops = strtoul(optarg, &dummy, 10); - break; - case 'v': - verbose = true; - break; - case 'h': - //print_help(); - // TODO write print_help helper function - break; - case '?': - return -1; - } - } - - // get info about the device and driver - inv_get_sysfs_path(sysfs); - if (inv_get_chip_name(chip_name) != INV_SUCCESS) { - printf("get chip name fail\n"); - exit(0); - } - printf("INFO: chip_name=%s\n", chip_name); - - for (i = 0; i < strlen(chip_name); i++) - device_name[i] = tolower(chip_name[i]); - device_name[strlen(chip_name)] = '\0'; - printf("INFO: device name=%s\n", device_name); - - /* Find the device requested */ - dev_num = find_type_by_name(device_name, "iio:device"); - if (dev_num < 0) { - printf("Failed to find the %s\n", device_name); - ret = -ENODEV; - goto error_ret; - } - printf("INFO: iio device number=%d\n", dev_num); - - /* attempt to open non blocking the access dev */ - ret = asprintf(&buffer_access, "/dev/iio:device%d", dev_num); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - while (num_loops == -1 || num_loops--) - read_data(buffer_access); - free(buffer_access); - -error_ret: - return ret; -} diff --git a/65xx/libsensors_iio/software/simple_apps/gesture_test/build/android/inv_gesture_test-shared b/65xx/libsensors_iio/software/simple_apps/gesture_test/build/android/inv_gesture_test-shared Binary files differdeleted file mode 100755 index 0414ce3..0000000 --- a/65xx/libsensors_iio/software/simple_apps/gesture_test/build/android/inv_gesture_test-shared +++ /dev/null diff --git a/65xx/libsensors_iio/software/simple_apps/gesture_test/build/android/shared.mk b/65xx/libsensors_iio/software/simple_apps/gesture_test/build/android/shared.mk deleted file mode 100755 index 8591982..0000000 --- a/65xx/libsensors_iio/software/simple_apps/gesture_test/build/android/shared.mk +++ /dev/null @@ -1,96 +0,0 @@ -EXEC = inv_gesture_test$(SHARED_APP_SUFFIX) - -MK_NAME = $(notdir $(CURDIR)/$(firstword $(MAKEFILE_LIST))) - -CROSS ?= $(ANDROID_ROOT)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- -COMP ?= $(CROSS)gcc -LINK ?= $(CROSS)gcc - -OBJFOLDER = $(CURDIR)/obj - -INV_ROOT = ../../../../.. -APP_DIR = $(CURDIR)/../.. -MLLITE_DIR = $(INV_ROOT)/software/core/mllite -MPL_DIR = $(INV_ROOT)/software/core/mpl - -include $(INV_ROOT)/software/build/android/common.mk - -CFLAGS += $(CMDLINE_CFLAGS) -CFLAGS += $(ANDROID_COMPILE) -CFLAGS += -Wall -CFLAGS += -fpic -CFLAGS += -nostdlib -CFLAGS += -DNDEBUG -CFLAGS += -D_REENTRANT -CFLAGS += -DLINUX -CFLAGS += -DANDROID -CFLAGS += -mthumb-interwork -CFLAGS += -fno-exceptions -CFLAGS += -ffunction-sections -CFLAGS += -funwind-tables -CFLAGS += -fstack-protector -CFLAGS += -fno-short-enums -CFLAGS += -fmessage-length=0 -CFLAGS += -I$(MLLITE_DIR) -CFLAGS += -I$(MPL_DIR) -CFLAGS += -I$(COMMON_DIR) -CFLAGS += -I$(HAL_DIR)/include -CFLAGS += $(INV_INCLUDES) -CFLAGS += $(INV_DEFINES) - -LLINK = -lc -LLINK += -lm -LLINK += -lutils -LLINK += -lcutils -LLINK += -lgcc -LLINK += -ldl -LLINK += -lstdc++ -LLINK += -llog -LLINK += -lz - -LFLAGS += $(CMDLINE_LFLAGS) -LFLAGS += $(ANDROID_LINK_EXECUTABLE) - -LRPATH = -Wl,-rpath,$(ANDROID_ROOT)/out/target/product/$(PRODUCT)/obj/lib:$(ANDROID_ROOT)/out/target/product/$(PRODUCT)/system/lib - -#################################################################################################### -## sources - -INV_LIBS = $(MPL_DIR)/build/$(TARGET)/$(LIB_PREFIX)$(MPL_LIB_NAME).$(SHARED_LIB_EXT) -INV_LIBS += $(MLLITE_DIR)/build/$(TARGET)/$(LIB_PREFIX)$(MLLITE_LIB_NAME).$(SHARED_LIB_EXT) - -#INV_SOURCES and VPATH provided by Makefile.filelist -include ../filelist.mk - -INV_OBJS := $(addsuffix .o,$(INV_SOURCES)) -INV_OBJS_DST = $(addprefix $(OBJFOLDER)/,$(addsuffix .o, $(notdir $(INV_SOURCES)))) - -#################################################################################################### -## rules - -.PHONY: all clean cleanall install - -all: $(EXEC) $(MK_NAME) - -$(EXEC) : $(OBJFOLDER) $(INV_OBJS_DST) $(INV_LIBS) $(MK_NAME) - @$(call echo_in_colors, "\n<linking $(EXEC) with objects $(INV_OBJS_DST) $(PREBUILT_OBJS) and libraries $(INV_LIBS)\n") - $(LINK) $(INV_OBJS_DST) -o $(EXEC) $(LFLAGS) $(LLINK) $(INV_LIBS) $(LLINK) $(LRPATH) - -$(OBJFOLDER) : - @$(call echo_in_colors, "\n<creating object's folder 'obj/'>\n") - mkdir obj - -$(INV_OBJS_DST) : $(OBJFOLDER)/%.c.o : %.c $(MK_NAME) - @$(call echo_in_colors, "\n<compile $< to $(OBJFOLDER)/$(notdir $@)>\n") - $(COMP) $(ANDROID_INCLUDES) $(KERNEL_INCLUDES) $(INV_INCLUDES) $(CFLAGS) -o $@ -c $< - -clean : - rm -fR $(OBJFOLDER) - -cleanall : - rm -fR $(EXEC) $(OBJFOLDER) - -install : $(EXEC) - cp -f $(EXEC) $(INSTALL_DIR) - - diff --git a/65xx/libsensors_iio/software/simple_apps/gesture_test/build/filelist.mk b/65xx/libsensors_iio/software/simple_apps/gesture_test/build/filelist.mk deleted file mode 100755 index 75d93cf..0000000 --- a/65xx/libsensors_iio/software/simple_apps/gesture_test/build/filelist.mk +++ /dev/null @@ -1,11 +0,0 @@ -#### filelist.mk for inv_gesture_test #### - -# headers -#HEADERS += - -# sources -SOURCES := $(APP_DIR)/inv_gesture_test.c - -INV_SOURCES += $(SOURCES) - -VPATH += $(APP_DIR) diff --git a/65xx/libsensors_iio/software/simple_apps/gesture_test/inv_gesture_test.c b/65xx/libsensors_iio/software/simple_apps/gesture_test/inv_gesture_test.c deleted file mode 100755 index ac0803f..0000000 --- a/65xx/libsensors_iio/software/simple_apps/gesture_test/inv_gesture_test.c +++ /dev/null @@ -1,720 +0,0 @@ -/** - * Gesture Test application for Invensense's MPU6/9xxx (w/ DMP). - */ - -#include <unistd.h> -#include <dirent.h> -#include <fcntl.h> -#include <stdio.h> -#include <errno.h> -#include <sys/stat.h> -#include <stdlib.h> -#include <features.h> -#include <dirent.h> -#include <string.h> -#include <poll.h> -#include <stddef.h> -#include <linux/input.h> -#include <time.h> -#include <linux/time.h> -#include <unistd.h> -#include <termios.h> - -#include "invensense.h" -#include "ml_math_func.h" -#include "storage_manager.h" -#include "ml_stored_data.h" -#include "ml_sysfs_helper.h" -#include "mlos.h" - -//#define DEBUG_PRINT /* Uncomment to print Gyro & Accel read from Driver */ - -#define SUPPORT_SCREEN_ORIENTATION -//#define SUPPORT_TAP -//#define SUPPORT_ORIENTATION -#define SUPPORT_PEDOMETER -#define SUPPORT_SMD - -#define MAX_SYSFS_NAME_LEN (100) -#define MAX_SYSFS_ATTRB (sizeof(struct sysfs_attrbs) / sizeof(char*)) -#define IIO_SYSFS_PATH "/sys/bus/iio/devices/iio:device0" -#define IIO_HUB_NAME "inv_hub" - -#define POLL_TIME (2000) // 2sec - -struct sysfs_attrbs { - char *name; - char *enable; - char *power_state; - char *dmp_on; - char *dmp_int_on; - char *dmp_firmware; - char *firmware_loaded; -#ifdef SUPPORT_SCREEN_ORIENTATION - char *event_display_orientation; - char *display_orientation_on; -#endif -#ifdef SUPPORT_ORIENTATION - char *event_orientation; - char *orientation_on; -#endif -#ifdef SUPPORT_TAP - char *event_tap; - char *tap_min_count; - char *tap_on; - char *tap_threshold; - char *tap_time; -#endif -#ifdef SUPPORT_PEDOMETER - char *pedometer_on; - char *pedometer_steps; - char *pedometer_time; -#endif -#ifdef SUPPORT_SMD - char *event_smd; - char *smd_enable; - char *smd_threshold; - char *smd_delay_threshold; - char *smd_delay_threshold2; -#endif -} mpu; - -enum { -#ifdef SUPPORT_TAP - FEAT_TAP, -#endif -#ifdef SUPPORT_SCREEN_ORIENTATION - FEAT_SCREEN_ORIENTATION, -#endif -#ifdef SUPPORT_ORIENTATION - FEAT_ORIENTATION, -#endif -#ifdef SUPPORT_PEDOMETER - FEAT_PEDOMETER, -#endif -#ifdef SUPPORT_SMD - FEAT_SMD, -#endif - - NUM_DMP_FEATS -}; - -char *sysfs_names_ptr; -#ifdef SUPPORT_PEDOMETER -unsigned long last_pedometer_poll = 0L; -unsigned long pedometer_poll_timeout = 500L; // .5 second -#endif -struct pollfd pfd[NUM_DMP_FEATS]; -bool android_hub = false; // flag to indicate true=Hub, false=non-hub - -/******************************************************************************* - * DMP Feature Supported Functions - ******************************************************************************/ - -int read_sysfs_int(char *filename, int *var) -{ - int res=0; - FILE *fp; - - fp = fopen(filename, "r"); - if (fp!=NULL) { - fscanf(fp, "%d\n", var); - fclose(fp); - } else { - printf("ERR open file to read: %s\n", filename); - res= -1; - } - return res; -} - -int write_sysfs_int(char *filename, int data) -{ - int res=0; - FILE *fp; - -#ifdef DEBUG_PRINT - printf("writing '%s' with '%d'\n", filename, data); -#endif - - fp = fopen(filename, "w"); - if (fp != NULL) { - fprintf(fp, "%d\n", data); - fclose(fp); - } else { - printf("ERR open file to write: %s\n", filename); - res = -1; - } - return res; -} - -/************************************************** - This _kbhit() function is courtesy of the web -***************************************************/ -int _kbhit(void) -{ - static const int STDIN = 0; - static bool initialized = false; - - if (! initialized) { - // Use termios to turn off line buffering - struct termios term; - tcgetattr(STDIN, &term); - term.c_lflag &= ~ICANON; - tcsetattr(STDIN, TCSANOW, &term); - setbuf(stdin, NULL); - initialized = true; - } - - int bytesWaiting; - ioctl(STDIN, FIONREAD, &bytesWaiting); - return bytesWaiting; -} - -int inv_init_sysfs_attributes(void) -{ - unsigned char i = 0; - char sysfs_path[MAX_SYSFS_NAME_LEN]; - char *sptr; - char **dptr; - - sysfs_names_ptr = - (char*)malloc(sizeof(char[MAX_SYSFS_ATTRB][MAX_SYSFS_NAME_LEN])); - sptr = sysfs_names_ptr; - if (sptr != NULL) { - dptr = (char**)&mpu; - do { - *dptr++ = sptr; - sptr += sizeof(char[MAX_SYSFS_NAME_LEN]); - } while (++i < MAX_SYSFS_ATTRB); - } else { - printf("couldn't alloc mem for sysfs paths\n"); - return -1; - } - - // get proper (in absolute/relative) IIO path & build MPU's sysfs paths - inv_get_sysfs_path(sysfs_path); - - sprintf(mpu.name, "%s%s", sysfs_path, "/name"); - sprintf(mpu.enable, "%s%s", sysfs_path, "/buffer/enable"); - sprintf(mpu.power_state, "%s%s", sysfs_path, "/power_state"); - sprintf(mpu.dmp_on,"%s%s", sysfs_path, "/dmp_on"); - sprintf(mpu.dmp_int_on, "%s%s", sysfs_path, "/dmp_int_on"); - sprintf(mpu.dmp_firmware, "%s%s", sysfs_path, "/dmp_firmware"); - sprintf(mpu.firmware_loaded, "%s%s", sysfs_path, "/firmware_loaded"); - -#ifdef SUPPORT_SCREEN_ORIENTATION - sprintf(mpu.event_display_orientation, "%s%s", - sysfs_path, "/event_display_orientation"); - sprintf(mpu.display_orientation_on, "%s%s", - sysfs_path, "/display_orientation_on"); -#endif -#ifdef SUPPORT_ORIENTATION - sprintf(mpu.event_orientation, "%s%s", sysfs_path, "/event_orientation"); - sprintf(mpu.orientation_on, "%s%s", sysfs_path, "/orientation_on"); -#endif -#ifdef SUPPORT_TAP - sprintf(mpu.event_tap, "%s%s", sysfs_path, "/event_tap"); - sprintf(mpu.tap_min_count, "%s%s", sysfs_path, "/tap_min_count"); - sprintf(mpu.tap_on, "%s%s", sysfs_path, "/tap_on"); - sprintf(mpu.tap_threshold, "%s%s", sysfs_path, "/tap_threshold"); - sprintf(mpu.tap_time, "%s%s", sysfs_path, "/tap_time"); -#endif -#ifdef SUPPORT_PEDOMETER - sprintf(mpu.pedometer_on, "%s%s", sysfs_path, "/dmp_on"); - sprintf(mpu.pedometer_steps, "%s%s", sysfs_path, "/pedometer_steps"); - sprintf(mpu.pedometer_time, "%s%s", sysfs_path, "/pedometer_time"); -#endif -#ifdef SUPPORT_SMD - sprintf(mpu.event_smd, "%s%s", sysfs_path, "/event_smd"); - sprintf(mpu.smd_enable, "%s%s", sysfs_path, "/smd_enable"); - sprintf(mpu.smd_threshold, "%s%s", sysfs_path, "/smd_threshold"); - sprintf(mpu.smd_delay_threshold, "%s%s", - sysfs_path, "/smd_delay_threshold"); - sprintf(mpu.smd_delay_threshold2, "%s%s", - sysfs_path, "/smd_delay_threshold2"); -#endif - -#if 0 - // test print sysfs paths - dptr = (char**)&mpu; - for (i = 0; i < MAX_SYSFS_ATTRB; i++) { - MPL_LOGE("sysfs path: %s", *dptr++); - } -#endif - return 0; -} - -int dmp_fw_loaded(void) -{ - int fw_loaded; - if (read_sysfs_int(mpu.firmware_loaded, &fw_loaded) < 0) - fw_loaded= 0; - return fw_loaded; -} - -int is_android_hub(void) -{ - char dev_name[8]; - FILE *fp; - - fp= fopen(mpu.name, "r"); - fgets(dev_name, 8, fp); - fclose(fp); - - if (!strncmp(dev_name, IIO_HUB_NAME, sizeof(IIO_HUB_NAME))) { - android_hub = true; - }else { - android_hub = false; - } - - return 0; -} - -/* - Enablers for the gestures -*/ - -int master_enable(int en) -{ - if (write_sysfs_int(mpu.enable, en) < 0) { - printf("GT:ERR-can't write 'buffer/enable'"); - return -1; - } - return 0; -} - -#ifdef SUPPORT_TAP -int enable_tap(int en) -{ - if (write_sysfs_int(mpu.tap_on, en) < 0) { - printf("GT:ERR-can't write 'tap_on'\n"); - return -1; - } - - return 0; -} -#endif - -/* Unnecessary: pedometer_on == dmp_on, which is always on -#ifdef SUPPORT_PEDOMETER -int enable_pedometer(int en) -{ - if (write_sysfs_int(mpu.pedometer_on, en) < 0) { - printf("GT:ERR-can't write 'pedometer_on'\n"); - return -1; - } - - return 0; -} -#endif -*/ - -#ifdef SUPPORT_SCREEN_ORIENTATION -int enable_display_orientation(int en) -{ - if (write_sysfs_int(mpu.display_orientation_on, en) < 0) { - printf("GT:ERR-can't write 'display_orientation_on'\n"); - return -1; - } - - return 0; -} -#endif - -#ifdef SUPPORT_ORIENTATION -int enable_orientation(int en) -{ - if (write_sysfs_int(mpu.orientation_on, en) < 0) { - printf("GT:ERR-can't write 'orientation_on'\n"); - return -1; - } - - return 0; -} -#endif - -#ifdef SUPPORT_SMD -int enable_smd(int en) -{ - if (write_sysfs_int(mpu.smd_enable, en) < 0) { - printf("GT:ERR-can't write 'smd_enable'\n"); - return -1; - } - return 0; -} -#endif - -/* - Handlers for the gestures -*/ -#ifdef SUPPORT_TAP -int tap_handler(void) -{ - FILE *fp; - int tap, tap_dir, tap_num; - - fp = fopen(mpu.event_tap, "rt"); - fscanf(fp, "%d\n", &tap); - fclose(fp); - - tap_dir = tap/8; - tap_num = tap%8 + 1; - -#ifdef DEBUG_PRINT - printf("GT:Tap Handler **\n"); - printf("Tap= %x\n", tap); - printf("Tap Dir= %x\n", tap_dir); - printf("Tap Num= %x\n", tap_num); -#endif - - switch (tap_dir) { - case 1: - printf("Tap Axis->X Pos, "); - break; - case 2: - printf("Tap Axis->X Neg, "); - break; - case 3: - printf("Tap Axis->Y Pos, "); - break; - case 4: - printf("Tap Axis->Y Neg, "); - break; - case 5: - printf("Tap Axis->Z Pos, "); - break; - case 6: - printf("Tap Axis->Z Neg, "); - break; - default: - printf("Tap Axis->Unknown, "); - break; - } - printf("#%d\n", tap_num); - - return 0; -} -#endif - -#ifdef SUPPORT_PEDOMETER -int pedometer_handler(void) -{ - FILE *fp; - static int last_pedometer_steps = -1; - static long last_pedometer_time = -1; - int pedometer_steps; - long pedometer_time; - -#ifdef DEBUG_PRINT - printf("GT:Pedometer Handler\n"); -#endif - - fp = fopen(mpu.pedometer_steps, "rt"); - fscanf(fp, "%d\n", &pedometer_steps); - fclose(fp); - - fp = fopen(mpu.pedometer_time, "rt"); - fscanf(fp, "%ld\n", &pedometer_time); - fclose(fp); - - if (last_pedometer_steps == -1 && last_pedometer_time == -1) { - printf("Pedometer Steps: %d Time: %ld ", - pedometer_steps, pedometer_time); - if (pedometer_steps > 10 - || pedometer_time > (pedometer_poll_timeout * 2)) - printf("(resumed)\n"); - else - printf("\n"); - } else if (last_pedometer_steps != pedometer_steps - || last_pedometer_time != pedometer_time) { - printf("Pedometer Steps: %d Time: %ld\n", - pedometer_steps, pedometer_time); - } - - last_pedometer_steps = pedometer_steps; - last_pedometer_time = pedometer_time; - - return 0; -} -#endif - -#ifdef SUPPORT_SCREEN_ORIENTATION -int display_orientation_handler(void) -{ - FILE *fp; - int orient; - -#ifdef DEBUG_PRINT - printf("GT:Screen Orient Handler\n"); -#endif - - fp = fopen(mpu.event_display_orientation, "rt"); - if (!fp) { - printf("GT:Cannot open '%s'\n", mpu.event_display_orientation); - return -1; - } - fscanf(fp, "%d\n", &orient); - fclose(fp); - - printf("Screen Orient-> %d\n", orient); - - return 0; -} -#endif - -#ifdef SUPPORT_ORIENTATION -int host_orientation_handler(void) -{ - FILE *fp; - int orient; - - fp = fopen(mpu.event_orientation, "rt"); - fscanf(fp, "%d\n", &orient); - fclose(fp); - -#ifdef DEBUG_PRINT - printf("GT:Reg Orient Handler\n"); -#endif - - if (orient & 0x01) - printf("Orient->X Up\n"); - if (orient & 0x02) - printf("Orient->X Down\n"); - if (orient & 0x04) - printf("Orient->Y Up\n"); - if (orient & 0x08) - printf("Orient->Y Down\n"); - if (orient & 0x10) - printf("Orient->Z Up\n"); - if (orient & 0x20) - printf("Orient->Z Down\n"); - if (orient & 0x40) - printf("Orient->Flip\n"); - - return 0; -} -#endif - -#ifdef SUPPORT_SMD -int smd_handler(void) -{ - FILE *fp; - int smd; - - fp = fopen(mpu.event_smd, "rt"); - fscanf(fp, "%d\n", &smd); - fclose(fp); - -#ifdef DEBUG_PRINT - printf("GT:SMD Handler\n"); -#endif - printf("SMD (%d)\n", smd); - - /* wait for the acceleration low pass filtered tail to die off - - this is to prevent that the tail end of a 2nd event of above threhsold - motion be considered as also the 1st event for the next SM detection */ - inv_sleep(1000); - - /* re-enable to continue the detection */ - master_enable(0); - enable_smd(1); - master_enable(1); - - return 0; -} -#endif - -int enable_dmp_features(int en) -{ - int res= -1; - - if (android_hub || dmp_fw_loaded()) { - /* Currently there's no info regarding DMP's supported features/capabilities - An error in enabling features below could be an indication of the feature - not supported in current loaded DMP firmware */ - - master_enable(0); -#ifdef SUPPORT_TAP - enable_tap(en); -#endif -#ifdef SUPPORT_SCREEN_ORIENTATION - enable_display_orientation(en); -#endif -#ifdef SUPPORT_ORIENTATION - if (android_hub == false) { - // Android Hub does not support 'regular' orientation feature - enable_orientation(en); - } -#endif -#ifdef SUPPORT_SMD - enable_smd(en); -#endif - master_enable(1); - res = 0; - - } else { - printf("GT:ERR-No DMP firmware\n"); - res= -1; - } - - return res; -} - -int init_fds(void) -{ - int i; - - for (i = 0; i < NUM_DMP_FEATS; i++) { - switch(i) { -#ifdef SUPPORT_TAP - case FEAT_TAP: - pfd[i].fd = open(mpu.event_tap, O_RDONLY | O_NONBLOCK); - break; -#endif -#ifdef SUPPORT_SCREEN_ORIENTATION - case FEAT_SCREEN_ORIENTATION: - pfd[i].fd = open(mpu.event_display_orientation, - O_RDONLY | O_NONBLOCK); - break; -#endif -#ifdef SUPPORT_ORIENTATION - case FEAT_ORIENTATION: - pfd[i].fd = open(mpu.event_orientation, O_RDONLY | O_NONBLOCK); - break; -#endif -#ifdef SUPPORT_SMD - case FEAT_SMD: - pfd[i].fd = open(mpu.event_smd, O_RDONLY | O_NONBLOCK); - break; -#endif - default: - pfd[i].fd = -1; - } - - pfd[i].events = POLLPRI|POLLERR, - pfd[i].revents = 0; - } - - return 0; -} - -void parse_events(struct pollfd pfd[], int num_fds) -{ - int i; - - for (i = 0; i < num_fds; i++) { - if(pfd[i].revents != 0) { - switch(i) { -#ifdef SUPPORT_TAP - case FEAT_TAP: - tap_handler(); - break; -#endif -#ifdef SUPPORT_SCREEN_ORIENTATION - case FEAT_SCREEN_ORIENTATION: - display_orientation_handler(); - break; -#endif -#ifdef SUPPORT_ORIENTATION - case FEAT_ORIENTATION: - host_orientation_handler(); - break; -#endif -#ifdef SUPPORT_SMD - case FEAT_SMD: - smd_handler(); - break; -#endif - default: - printf("GT:ERR-unhandled/unrecognized gesture event"); - break; - } - pfd[i].revents = 0; // no need: reset anyway - } - } - -#ifdef SUPPORT_PEDOMETER - { - unsigned long now; - // pedometer is not event based, therefore we poll using a timer every - // pedometer_poll_timeout milliseconds - if ((now = inv_get_tick_count()) - last_pedometer_poll - > pedometer_poll_timeout) { - pedometer_handler(); - last_pedometer_poll = now; - } - } -#endif -} - -int close_fds(void) -{ - int i; - for (i = 0; i < NUM_DMP_FEATS; i++) { - if (!pfd[i].fd) - close(pfd[i].fd); - } - return 0; -} - -/******************************************************************************* - * M a i n - ******************************************************************************/ - -int main(int argc, char **argv) -{ - char data[4]; - int i, res= 0; - - printf("\n" - "****************************************************************\n" - "*** NOTE: ***\n" - "*** the HAL must be compiled with Low power quaternion ***\n" - "*** and/or DMP screen orientation support. ***\n" - "*** 'At least' one of the 4 Android virtual sensors ***\n" - "*** must be enabled. ***\n" - "*** ***\n" - "*** Please perform gestures to see the output. ***\n" - "*** Press any key to stop the program. ***\n" - "****************************************************************\n" - "\n"); - - res = inv_init_sysfs_attributes(); - if (res) { - printf("GT:ERR-Can't allocate mem\n"); - return -1; - } - - /* check if Android Hub */ - is_android_hub(); - - /* init Fds to poll for gesture data */ - init_fds(); - - /* on Gesture/DMP supported features */ - if (enable_dmp_features(1) < 0) { - printf("GT:ERR-Can't enable Gestures\n"); - return -1; - } - - do { - for (i = 0; i < NUM_DMP_FEATS; i++) - read(pfd[i].fd, data, 4); - poll(pfd, NUM_DMP_FEATS, POLL_TIME); - parse_events(pfd, NUM_DMP_FEATS); - } while (!_kbhit()); - - /* off Gesture/DMP supported features */ - if (enable_dmp_features(0) < 0) { - printf("GT:ERR-Can't disable Gestures\n"); - return -1; - } - - /* release resources */ - close_fds(); - if (sysfs_names_ptr) - free(sysfs_names_ptr); - - return res; -} - diff --git a/65xx/libsensors_iio/software/simple_apps/mpu_iio/build/android/inv_mpu_iio-shared b/65xx/libsensors_iio/software/simple_apps/mpu_iio/build/android/inv_mpu_iio-shared Binary files differdeleted file mode 100755 index f4ebc27..0000000 --- a/65xx/libsensors_iio/software/simple_apps/mpu_iio/build/android/inv_mpu_iio-shared +++ /dev/null diff --git a/65xx/libsensors_iio/software/simple_apps/mpu_iio/build/android/shared.mk b/65xx/libsensors_iio/software/simple_apps/mpu_iio/build/android/shared.mk deleted file mode 100755 index 2dda9e0..0000000 --- a/65xx/libsensors_iio/software/simple_apps/mpu_iio/build/android/shared.mk +++ /dev/null @@ -1,94 +0,0 @@ -EXEC = inv_mpu_iio$(SHARED_APP_SUFFIX) - -MK_NAME = $(notdir $(CURDIR)/$(firstword $(MAKEFILE_LIST))) - -CROSS ?= $(ANDROID_ROOT)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- -COMP ?= $(CROSS)gcc -LINK ?= $(CROSS)gcc - -OBJFOLDER = $(CURDIR)/obj - -INV_ROOT = ../../../../.. -APP_DIR = $(CURDIR)/../.. -MLLITE_DIR = $(INV_ROOT)/software/core/mllite -MPL_DIR = $(INV_ROOT)/software/core/mpl - -include $(INV_ROOT)/software/build/android/common.mk - -CFLAGS += $(CMDLINE_CFLAGS) -CFLAGS += $(ANDROID_COMPILE) -CFLAGS += -Wall -CFLAGS += -fpic -CFLAGS += -nostdlib -CFLAGS += -DNDEBUG -CFLAGS += -D_REENTRANT -CFLAGS += -DLINUX -CFLAGS += -DANDROID -CFLAGS += -mthumb-interwork -CFLAGS += -fno-exceptions -CFLAGS += -ffunction-sections -CFLAGS += -funwind-tables -CFLAGS += -fstack-protector -CFLAGS += -fno-short-enums -CFLAGS += -fmessage-length=0 -CFLAGS += -I$(MLLITE_DIR) -CFLAGS += -I$(MPL_DIR) -CFLAGS += $(INV_INCLUDES) -CFLAGS += $(INV_DEFINES) - -LLINK = -lc -LLINK += -lm -LLINK += -lutils -LLINK += -lcutils -LLINK += -lgcc -LLINK += -ldl -LLINK += -lstdc++ -LLINK += -llog -LLINK += -lz - -LFLAGS += $(CMDLINE_LFLAGS) -LFLAGS += $(ANDROID_LINK_EXECUTABLE) - -LRPATH = -Wl,-rpath,$(ANDROID_ROOT)/out/target/product/$(PRODUCT)/obj/lib:$(ANDROID_ROOT)/out/target/product/$(PRODUCT)/system/lib - -#################################################################################################### -## sources - -INV_LIBS = $(MPL_DIR)/build/$(TARGET)/$(LIB_PREFIX)$(MPL_LIB_NAME).$(SHARED_LIB_EXT) -INV_LIBS += $(MLLITE_DIR)/build/$(TARGET)/$(LIB_PREFIX)$(MLLITE_LIB_NAME).$(SHARED_LIB_EXT) - -#INV_SOURCES and VPATH provided by Makefile.filelist -include ../filelist.mk - -INV_OBJS := $(addsuffix .o,$(INV_SOURCES)) -INV_OBJS_DST = $(addprefix $(OBJFOLDER)/,$(addsuffix .o, $(notdir $(INV_SOURCES)))) - -#################################################################################################### -## rules - -.PHONY: all clean cleanall install - -all: $(EXEC) $(MK_NAME) - -$(EXEC) : $(OBJFOLDER) $(INV_OBJS_DST) $(INV_LIBS) $(MK_NAME) - @$(call echo_in_colors, "\n<linking $(EXEC) with objects $(INV_OBJS_DST) $(PREBUILT_OBJS) and libraries $(INV_LIBS)\n") - $(LINK) $(INV_OBJS_DST) -o $(EXEC) $(LFLAGS) $(LLINK) $(INV_LIBS) $(LLINK) $(LRPATH) - -$(OBJFOLDER) : - @$(call echo_in_colors, "\n<creating object's folder 'obj/'>\n") - mkdir obj - -$(INV_OBJS_DST) : $(OBJFOLDER)/%.c.o : %.c $(MK_NAME) - @$(call echo_in_colors, "\n<compile $< to $(OBJFOLDER)/$(notdir $@)>\n") - $(COMP) $(ANDROID_INCLUDES) $(KERNEL_INCLUDES) $(INV_INCLUDES) $(CFLAGS) -o $@ -c $< - -clean : - rm -fR $(OBJFOLDER) - -cleanall : - rm -fR $(EXEC) $(OBJFOLDER) - -install : $(EXEC) - cp -f $(EXEC) $(INSTALL_DIR) - - diff --git a/65xx/libsensors_iio/software/simple_apps/mpu_iio/build/filelist.mk b/65xx/libsensors_iio/software/simple_apps/mpu_iio/build/filelist.mk deleted file mode 100755 index 8a3977a..0000000 --- a/65xx/libsensors_iio/software/simple_apps/mpu_iio/build/filelist.mk +++ /dev/null @@ -1,12 +0,0 @@ -#### filelist.mk for mpu_iio #### - -# headers -#HEADERS += $(HAL_DIR)/include/inv_sysfs_utils.h -HEADERS += $(APP_DIR)/iio_utils.h - -# sources -SOURCES := $(APP_DIR)/mpu_iio.c - -INV_SOURCES += $(SOURCES) - -VPATH += $(APP_DIR) $(COMMON_DIR) $(HAL_DIR)/linux diff --git a/65xx/libsensors_iio/software/simple_apps/mpu_iio/iio_utils.h b/65xx/libsensors_iio/software/simple_apps/mpu_iio/iio_utils.h deleted file mode 100755 index c3d4955..0000000 --- a/65xx/libsensors_iio/software/simple_apps/mpu_iio/iio_utils.h +++ /dev/null @@ -1,650 +0,0 @@ -/* IIO - useful set of util functionality - * - * Copyright (c) 2008 Jonathan Cameron - * - * 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. - */ - -/* Made up value to limit allocation sizes */ -#include <string.h> -#include <stdlib.h> -#include <ctype.h> -#include <stdio.h> -#include <stdint.h> -#include <dirent.h> - -#define IIO_MAX_NAME_LENGTH 30 - -#define FORMAT_SCAN_ELEMENTS_DIR "%s/scan_elements" -#define FORMAT_TYPE_FILE "%s_type" - -const char *iio_dir = "/sys/bus/iio/devices/"; - -extern int verbose; - -/** - * iioutils_break_up_name() - extract generic name from full channel name - * @full_name: the full channel name - * @generic_name: the output generic channel name - **/ -static int iioutils_break_up_name(const char *full_name, - char **generic_name) -{ - char *current; - char *w, *r; - char *working; - current = strdup(full_name); - working = strtok(current, "_\0"); - w = working; - r = working; - - while (*r != '\0') { - if (!isdigit(*r)) { - *w = *r; - w++; - } - r++; - } - *w = '\0'; - *generic_name = strdup(working); - free(current); - - return 0; -} - -/** - * struct iio_channel_info - information about a given channel - * @name: channel name - * @generic_name: general name for channel type - * @scale: scale factor to be applied for conversion to si units - * @offset: offset to be applied for conversion to si units - * @index: the channel index in the buffer output - * @bytes: number of bytes occupied in buffer output - * @mask: a bit mask for the raw output - * @is_signed: is the raw value stored signed - * @enabled: is this channel enabled - **/ -struct iio_channel_info { - char *name; - char *generic_name; - float scale; - float offset; - unsigned index; - unsigned bytes; - unsigned bits_used; - unsigned shift; - uint64_t mask; - unsigned be; - unsigned is_signed; - unsigned enabled; - unsigned location; -}; - -/** - * iioutils_get_type() - find and process _type attribute data - * @is_signed: output whether channel is signed - * @bytes: output how many bytes the channel storage occupies - * @mask: output a bit mask for the raw data - * @be: big endian - * @device_dir: the iio device directory - * @name: the channel name - * @generic_name: the channel type name - **/ -inline int iioutils_get_type(unsigned *is_signed, - unsigned *bytes, - unsigned *bits_used, - unsigned *shift, - uint64_t *mask, - unsigned *be, - const char *device_dir, - const char *name, - const char *generic_name) -{ - FILE *sysfsfp; - int ret; - DIR *dp; - char *scan_el_dir, *builtname, *builtname_generic, *filename = 0; - char signchar, endianchar; - unsigned padint; - const struct dirent *ent; - - ret = asprintf(&scan_el_dir, FORMAT_SCAN_ELEMENTS_DIR, device_dir); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - ret = asprintf(&builtname, FORMAT_TYPE_FILE, name); - if (ret < 0) { - ret = -ENOMEM; - goto error_free_scan_el_dir; - } - ret = asprintf(&builtname_generic, FORMAT_TYPE_FILE, generic_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_free_builtname; - } - - dp = opendir(scan_el_dir); - if (dp == NULL) { - ret = -errno; - goto error_free_builtname_generic; - } - while (ent = readdir(dp), ent != NULL) - /* - * Do we allow devices to override a generic name with - * a specific one? - */ - if ((strcmp(builtname, ent->d_name) == 0) || - (strcmp(builtname_generic, ent->d_name) == 0)) { - ret = asprintf(&filename, - "%s/%s", scan_el_dir, ent->d_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_closedir; - } - sysfsfp = fopen(filename, "r"); - if (sysfsfp == NULL) { - printf("failed to open %s\n", filename); - ret = -errno; - goto error_free_filename; - } - - ret = fscanf(sysfsfp, - "%ce:%c%u/%u>>%u", - &endianchar, - &signchar, - bits_used, - &padint, shift); - if (ret < 0) { - printf("failed to pass scan type description\n"); - return ret; - } - *be = (endianchar == 'b'); - *bytes = padint / 8; - if (*bits_used == 64) - *mask = ~0; - else - *mask = (1 << *bits_used) - 1; - if (signchar == 's') - *is_signed = 1; - else - *is_signed = 0; - fclose(sysfsfp); - free(filename); - - filename = 0; - } -error_free_filename: - if (filename) - free(filename); -error_closedir: - closedir(dp); -error_free_builtname_generic: - free(builtname_generic); -error_free_builtname: - free(builtname); -error_free_scan_el_dir: - free(scan_el_dir); -error_ret: - return ret; -} - -inline int iioutils_get_param_float(float *output, - const char *param_name, - const char *device_dir, - const char *name, - const char *generic_name) -{ - FILE *sysfsfp; - int ret; - DIR *dp; - char *builtname, *builtname_generic; - char *filename = NULL; - const struct dirent *ent; - - ret = asprintf(&builtname, "%s_%s", name, param_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - ret = asprintf(&builtname_generic, - "%s_%s", generic_name, param_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_free_builtname; - } - dp = opendir(device_dir); - if (dp == NULL) { - ret = -errno; - goto error_free_builtname_generic; - } - while (ent = readdir(dp), ent != NULL) - if ((strcmp(builtname, ent->d_name) == 0) || - (strcmp(builtname_generic, ent->d_name) == 0)) { - ret = asprintf(&filename, - "%s/%s", device_dir, ent->d_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_closedir; - } - sysfsfp = fopen(filename, "r"); - if (!sysfsfp) { - ret = -errno; - goto error_free_filename; - } - fscanf(sysfsfp, "%f", output); - break; - } -error_free_filename: - if (filename) - free(filename); -error_closedir: - closedir(dp); -error_free_builtname_generic: - free(builtname_generic); -error_free_builtname: - free(builtname); -error_ret: - return ret; -} - -/** - * bsort_channel_array_by_index() - reorder so that the array is in index order - * - **/ - -inline void bsort_channel_array_by_index(struct iio_channel_info **ci_array, - int cnt) -{ - struct iio_channel_info temp; - int x, y; - - for (x = 0; x < cnt; x++) - for (y = 0; y < (cnt - 1); y++) - if ((*ci_array)[y].index > (*ci_array)[y+1].index) { - temp = (*ci_array)[y + 1]; - (*ci_array)[y + 1] = (*ci_array)[y]; - (*ci_array)[y] = temp; - } -} - -/** - * build_channel_array() - function to figure out what channels are present - * @device_dir: the IIO device directory in sysfs - * @ - **/ -inline int build_channel_array(const char *device_dir, - struct iio_channel_info **ci_array, - int *counter) -{ - DIR *dp; - FILE *sysfsfp; - int count, i; - struct iio_channel_info *current; - int ret; - const struct dirent *ent; - char *scan_el_dir; - char *filename; - - *counter = 0; - ret = asprintf(&scan_el_dir, FORMAT_SCAN_ELEMENTS_DIR, device_dir); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - dp = opendir(scan_el_dir); - if (dp == NULL) { - ret = -errno; - goto error_free_name; - } - while (ent = readdir(dp), ent != NULL) - if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), - "_en") == 0) { - ret = asprintf(&filename, - "%s/%s", scan_el_dir, ent->d_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_close_dir; - } - sysfsfp = fopen(filename, "r"); - if (sysfsfp == NULL) { - ret = -errno; - free(filename); - goto error_close_dir; - } - fscanf(sysfsfp, "%u", &ret); - //printf("%s, %d\n", filename, ret); - if (ret == 1) - (*counter)++; - fclose(sysfsfp); - free(filename); - } - *ci_array = malloc(sizeof(**ci_array) * (*counter)); - if (*ci_array == NULL) { - ret = -ENOMEM; - goto error_close_dir; - } - closedir(dp); - dp = opendir(scan_el_dir); - //seekdir(dp, 0); - count = 0; - while (ent = readdir(dp), ent != NULL) { - if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), - "_en") == 0) { - current = &(*ci_array)[count++]; - ret = asprintf(&filename, - "%s/%s", scan_el_dir, ent->d_name); - if (ret < 0) { - ret = -ENOMEM; - /* decrement count to avoid freeing name */ - count--; - goto error_cleanup_array; - } - sysfsfp = fopen(filename, "r"); - if (sysfsfp == NULL) { - free(filename); - ret = -errno; - goto error_cleanup_array; - } - fscanf(sysfsfp, "%u", ¤t->enabled); - fclose(sysfsfp); - - if (!current->enabled) { - free(filename); - count--; - continue; - } - - current->scale = 1.0; - current->offset = 0; - current->name = strndup(ent->d_name, - strlen(ent->d_name) - - strlen("_en")); - if (current->name == NULL) { - free(filename); - ret = -ENOMEM; - goto error_cleanup_array; - } - /* Get the generic and specific name elements */ - ret = iioutils_break_up_name(current->name, - ¤t->generic_name); - if (ret) { - free(filename); - goto error_cleanup_array; - } - ret = asprintf(&filename, - "%s/%s_index", - scan_el_dir, - current->name); - if (ret < 0) { - free(filename); - ret = -ENOMEM; - goto error_cleanup_array; - } - sysfsfp = fopen(filename, "r"); - fscanf(sysfsfp, "%u", ¤t->index); - fclose(sysfsfp); - free(filename); - /* Find the scale */ - ret = iioutils_get_param_float(¤t->scale, - "scale", - device_dir, - current->name, - current->generic_name); - if (ret < 0) - goto error_cleanup_array; - ret = iioutils_get_param_float(¤t->offset, - "offset", - device_dir, - current->name, - current->generic_name); - if (ret < 0) - goto error_cleanup_array; - ret = iioutils_get_type(¤t->is_signed, - ¤t->bytes, - ¤t->bits_used, - ¤t->shift, - ¤t->mask, - ¤t->be, - device_dir, - current->name, - current->generic_name); - } - } - - closedir(dp); - /* reorder so that the array is in index order */ - bsort_channel_array_by_index(ci_array, *counter); - - return 0; - -error_cleanup_array: - for (i = count - 1; i >= 0; i--) - free((*ci_array)[i].name); - free(*ci_array); -error_close_dir: - closedir(dp); -error_free_name: - free(scan_el_dir); -error_ret: - return ret; -} - -inline int _write_sysfs_int(char *filename, char *basedir, int val, int verify) -{ - int ret = 0; - FILE *sysfsfp; - int test; - char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) - return -ENOMEM; - - sprintf(temp, "%s/%s", basedir, filename); - - if (verbose) - printf("VERB: echo %d > %s\n", val, temp); - sysfsfp = fopen(temp, "w"); - if (sysfsfp == NULL) { - printf("failed to open %s\n", temp); - ret = -errno; - goto error_free; - } - fprintf(sysfsfp, "%d", val); - fclose(sysfsfp); - - if (verify) { - sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { - printf("failed to open %s\n", temp); - ret = -errno; - goto error_free; - } - fscanf(sysfsfp, "%d", &test); - fclose(sysfsfp); - if (verbose) - printf("VERB: cat %s = %d\n", temp, test); - if (test != val) { - printf("Possible failure in int write %d to %s\n", - val, temp); - ret = -1; - } - } - -error_free: - free(temp); - return ret; -} - -int write_sysfs_int(char *filename, char *basedir, int val) -{ - return _write_sysfs_int(filename, basedir, val, 0); -} - -int write_sysfs_int_and_verify(char *filename, char *basedir, int val) -{ - return _write_sysfs_int(filename, basedir, val, 1); -} - -int _write_sysfs_string(char *filename, char *basedir, char *val, int verify) -{ - int ret = 0; - FILE *sysfsfp; - char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) { - printf("Memory allocation failed\n"); - return -ENOMEM; - } - sprintf(temp, "%s/%s", basedir, filename); - - sysfsfp = fopen(temp, "w"); - if (sysfsfp == NULL) { - printf("Could not open %s\n", temp); - ret = -errno; - goto error_free; - } - fprintf(sysfsfp, "%s", val); - fclose(sysfsfp); - - if (verify) { - sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { - printf("could not open file to verify\n"); - ret = -errno; - goto error_free; - } - fscanf(sysfsfp, "%s", temp); - fclose(sysfsfp); - - if (strcmp(temp, val) != 0) { - printf("Possible failure in string write of %s " - "Should be %s written to %s\%s\n", - temp, val, basedir, filename); - ret = -1; - } - } - -error_free: - free(temp); - - return ret; -} - -/** - * write_sysfs_string_and_verify() - string write, readback and verify - * @filename: name of file to write to - * @basedir: the sysfs directory in which the file is to be found - * @val: the string to write - **/ -int write_sysfs_string_and_verify(char *filename, char *basedir, char *val) -{ - return _write_sysfs_string(filename, basedir, val, 1); -} - -int write_sysfs_string(char *filename, char *basedir, char *val) -{ - return _write_sysfs_string(filename, basedir, val, 0); -} - -int read_sysfs_posint(char *filename, char *basedir) -{ - int ret; - FILE *sysfsfp; - char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) { - printf("Memory allocation failed"); - return -ENOMEM; - } - sprintf(temp, "%s/%s", basedir, filename); - sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { - ret = -errno; - goto error_free; - } - fscanf(sysfsfp, "%d\n", &ret); - fclose(sysfsfp); -error_free: - free(temp); - return ret; -} - -int read_sysfs_float(char *filename, char *basedir, float *val) -{ - float ret = 0; - FILE *sysfsfp; - char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) { - printf("Memory allocation failed"); - return -ENOMEM; - } - sprintf(temp, "%s/%s", basedir, filename); - sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { - ret = -errno; - goto error_free; - } - fscanf(sysfsfp, "%f\n", val); - fclose(sysfsfp); - -error_free: - free(temp); - return ret; -} - -int enable_se(const char *device_dir, struct iio_channel_info **ci_array, - int *counter, char *sensor, int en) -{ - DIR *dp; - int ret; - const struct dirent *ent; - char *scan_el_dir; - char pattern[50] = "in_"; - - *counter = 0; - ret = asprintf(&scan_el_dir, FORMAT_SCAN_ELEMENTS_DIR, device_dir); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - dp = opendir(scan_el_dir); - if (dp == NULL) { - ret = -errno; - goto error_free_name; - } - strcat(pattern, sensor); - while (ent = readdir(dp), ent != NULL) { - if (strncmp(ent->d_name, pattern, strlen(pattern)) == 0 && - strncmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), - "_en", strlen("_en")) == 0) { - write_sysfs_int_and_verify((char *)ent->d_name, scan_el_dir, en); - } - } - return 0; - -error_ret: -error_free_name: - return -1; -} - -int enable_accel_se(const char *device_dir, - struct iio_channel_info **ci_array, int *counter, - int en) -{ - return enable_se(device_dir, ci_array, counter, "accel", en); -} - -int enable_anglvel_se(const char *device_dir, - struct iio_channel_info **ci_array, int *counter, - int en) -{ - return enable_se(device_dir, ci_array, counter, "anglvel", en); -} - -int enable_quaternion_se(const char *device_dir, - struct iio_channel_info **ci_array, int *counter, - int en) -{ - return enable_se(device_dir, ci_array, counter, "quaternion", en); -} - diff --git a/65xx/libsensors_iio/software/simple_apps/mpu_iio/mpu_iio.c b/65xx/libsensors_iio/software/simple_apps/mpu_iio/mpu_iio.c deleted file mode 100755 index 65e21ac..0000000 --- a/65xx/libsensors_iio/software/simple_apps/mpu_iio/mpu_iio.c +++ /dev/null @@ -1,935 +0,0 @@ -/* - * Copyright (c) Invensense Inc. 2012 - * - * 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. - */ - -#include <unistd.h> -#include <dirent.h> -#include <fcntl.h> -#include <stdio.h> -#include <errno.h> -#include <sys/stat.h> -#include <dirent.h> -#include <linux/types.h> -#include <string.h> -#include <poll.h> -#include <termios.h> - -#include "iio_utils.h" -#include "ml_load_dmp.h" -#include "ml_sysfs_helper.h" -#include "authenticate.h" -#include "mlos.h" - -#define DMP_CODE_SIZE (3060) -#define POLL_TIME (2000) // 2sec - -// settings -static int accel_only = false; -static int test_motion = false; -static int test_flick = false; -static int test_pedometer = false; -static int test_orientation = false; -int verbose = false; - -// paths -char *dev_dir_name, *buf_dir_name; - -// all the DMP features supported -enum { - FEAT_TAP = 0, - FEAT_ORIENTATION, - FEAT_DISPLAY_ORIENTATION, - FEAT_MOTION, - FEAT_FLICK, - - FEAT_NUM, -} features; - -typedef void (*handler_t) (int data); - -struct dmp_feat_t { - int enabled; - struct pollfd *pollfd; - char *sysfs_name; - handler_t phandler; -}; - -static struct dmp_feat_t dmp_feat[FEAT_NUM] = {{0}}; -static struct pollfd pollfds[FEAT_NUM]; -static int pollfds_used = 0; - -/************************************************** - This _kbhit() function is courtesy of the web -***************************************************/ -int _kbhit(void) -{ - static const int STDIN = 0; - static bool initialized = false; - - if (!initialized) { - // Use termios to turn off line buffering - struct termios term; - tcgetattr(STDIN, &term); - term.c_lflag &= ~ICANON; - tcsetattr(STDIN, TCSANOW, &term); - setbuf(stdin, NULL); - initialized = true; - } - - int bytesWaiting; - ioctl(STDIN, FIONREAD, &bytesWaiting); - return bytesWaiting; -} - -/** - * size_from_channelarray() - calculate the storage size of a scan - * @channels: the channel info array - * @num_channels: size of the channel info array - * - * Has the side effect of filling the channels[i].location values used - * in processing the buffer output. - */ -int size_from_channelarray(struct iio_channel_info *channels, int num_channels) -{ - int bytes = 0; - int i = 0; - while (i < num_channels) { - if (bytes % channels[i].bytes == 0) - channels[i].location = bytes; - else - channels[i].location = bytes - bytes%channels[i].bytes - + channels[i].bytes; - bytes = channels[i].location + channels[i].bytes; - i++; - } - return bytes; -} - -void print2byte(int input, struct iio_channel_info *info) -{ - /* shift before conversion to avoid sign extension - of left aligned data */ - input = input >> info->shift; - if (info->is_signed) { - int16_t val = input; - val &= (1 << info->bits_used) - 1; - val = (int16_t)(val << (16 - info->bits_used)) >> - (16 - info->bits_used); - /*printf("%d, %05f, scale=%05f", val, - (float)(val + info->offset)*info->scale, info->scale);*/ - printf("%d, ", val); - - } else { - uint16_t val = input; - val &= (1 << info->bits_used) - 1; - printf("%05f ", ((float)val + info->offset)*info->scale); - } -} - -/** - * process_scan() - print out the values in SI units - * @data: pointer to the start of the scan - * @infoarray: information about the channels. Note - * size_from_channelarray must have been called first to fill the - * location offsets. - * @num_channels: the number of active channels - */ -void process_scan(char *data, struct iio_channel_info *infoarray, - int num_channels) -{ - int k; - //char *tmp; - for (k = 0; k < num_channels; k++) { - switch (infoarray[k].bytes) { - /* only a few cases implemented so far */ - case 2: - print2byte(*(uint16_t *)(data + infoarray[k].location), - &infoarray[k]); - //tmp = data + infoarray[k].location; - break; - case 4: - if (infoarray[k].is_signed) { - int32_t val = *(int32_t *)(data + infoarray[k].location); - if ((val >> infoarray[k].bits_used) & 1) - val = (val & infoarray[k].mask) | ~infoarray[k].mask; - /* special case for timestamp */ - printf(" %d ", val); - } - break; - case 8: - if (infoarray[k].is_signed) { - int64_t val = *(int64_t *)(data + infoarray[k].location); - if ((val >> infoarray[k].bits_used) & 1) - val = (val & infoarray[k].mask) | ~infoarray[k].mask; - /* special case for timestamp */ - if (infoarray[k].scale == 1.0f && - infoarray[k].offset == 0.0f) - printf(" %lld", val); - else - printf("%05f ", ((float)val + infoarray[k].offset) - * infoarray[k].scale); - } - break; - default: - break; - } - } - printf("\n"); -} - -/* - Enablers for the gestures -*/ - -int enable_flick(char *p, int on) -{ - int ret; - printf("flick:%s\n", p); - ret = write_sysfs_int_and_verify("flick_int_on", p, on); - if (ret < 0) - return ret; - ret = write_sysfs_int_and_verify("flick_upper", p, 3147790); - if (ret < 0) - return ret; - ret = write_sysfs_int_and_verify("flick_lower", p, -3147790); - if (ret < 0) - return ret; - ret = write_sysfs_int_and_verify("flick_counter", p, 50); - if (ret < 0) - return ret; - ret = write_sysfs_int_and_verify("flick_message_on", p, 0); - if (ret < 0) - return ret; - ret = write_sysfs_int_and_verify("flick_axis", p, 0); - if (ret < 0) - return ret; - - return 0; -} - -void verify_img(char *dmp_path) -{ - FILE *fp; - int i; - char dmp_img[DMP_CODE_SIZE]; - - if ((fp = fopen(dmp_path, "rb")) < 0) { - perror("dmp fail"); - } - i = fread(dmp_img, 1, DMP_CODE_SIZE, fp); - printf("Result=%d\n", i); - fclose(fp); - fp = fopen("/dev/read_img.h", "wt"); - fprintf(fp, "char rec[]={\n"); - for(i = 0; i < DMP_CODE_SIZE; i++) { - fprintf(fp, "0x%02x, ", dmp_img[i]); - if(((i + 1) % 16) == 0) { - fprintf(fp, "\n"); - } - } - fprintf(fp, "};\n "); - fclose(fp); -} - -int setup_dmp(char *dev_path, int p_event) -{ - char dmp_path[100]; - int ret; - FILE *fd; - - printf("INFO: sysfs path=%s\n", dev_path); - - ret = write_sysfs_int_and_verify("power_state", dev_path, 1); - if (ret < 0) - return ret; - - ret = write_sysfs_int("in_accel_scale", dev_path, 0); - if (ret < 0) - return ret; - ret = write_sysfs_int("in_anglvel_scale", dev_path, 3); - if (ret < 0) - return ret; - ret = write_sysfs_int("sampling_frequency", dev_path, 200); - if (ret < 0) - return ret; - ret = write_sysfs_int_and_verify("firmware_loaded", dev_path, 0); - if (ret < 0) - return ret; - - sprintf(dmp_path, "%s/dmp_firmware", dev_path); - if ((fd = fopen(dmp_path, "wb")) < 0 ) { - perror("dmp fail"); - } - inv_load_dmp(fd); - fclose(fd); - - printf("INFO: firmware_loaded=%d\n", - read_sysfs_posint("firmware_loaded", dev_path)); - - // set accel offsets - //ret = write_sysfs_int_and_verify("in_accel_x_offset", - // dev_path, 0xabcd0000); - //if (ret < 0) - // return ret; - //ret = write_sysfs_int_and_verify("in_accel_y_offset", - // dev_path, 0xffff0000); - //if (ret < 0) - // return ret; - //ret = write_sysfs_int_and_verify("in_accel_z_offset", - // dev_path, 0xcdef0000); - //if (ret < 0) - // return ret; - - ret = write_sysfs_int_and_verify("dmp_on", dev_path, 1); - if (ret < 0) - return ret; - ret = write_sysfs_int_and_verify("dmp_int_on", dev_path, 1); - if (ret < 0) - return ret; - - /* select which event to enable and interrupt on/off here */ - if (test_flick) { - ret = enable_flick(dev_path, 1); - if (ret < 0) - return ret; - } - - /* - ret = write_sysfs_int_and_verify("tap_on", dev_path, 1); - if (ret < 0) - return ret; - */ - - ret = write_sysfs_int_and_verify("display_orientation_on", - dev_path, 1); - if (ret < 0) - return ret; - if (test_orientation) { - ret = write_sysfs_int_and_verify("orientation_on", dev_path, 1); - if (ret < 0) - return ret; - } - ret = write_sysfs_int_and_verify("dmp_output_rate", dev_path, 25); - if (ret < 0) - return ret; - ret = write_sysfs_int_and_verify("dmp_event_int_on", dev_path, p_event); - if (ret < 0) - return ret; - - //verify_img(dmp_path); - return 0; -} - -/* - Handlers for the gestures -*/ - -void handle_flick(int flick) -{ - printf("flick=%x\n", flick); -} - -void handle_display_orientation(int orient) -{ - printf("display_orientation=%x\n", orient); -} - -void handle_motion(int motion) -{ - printf("motion=%x\n", motion); -} - -void handle_orientation(int orient) -{ - printf("orientation="); - if (orient & 0x01) - printf("+X, "); - if (orient & 0x02) - printf("-X, "); - if (orient & 0x04) - printf("+Y, "); - if (orient & 0x08) - printf("-Y, "); - if (orient & 0x10) - printf("+Z, "); - if (orient & 0x20) - printf("-Z, "); - if (orient & 0x40) - printf("flip"); - printf("\n"); -} - -void handle_tap(int tap) -{ - int tap_dir = tap / 8; - int tap_num = tap % 8 + 1; - - printf("tap="); - switch (tap_dir) { - case 1: - printf("+X, "); - break; - case 2: - printf("-X, "); - break; - case 3: - printf("+Y, "); - break; - case 4: - printf("-Y, "); - break; - case 5: - printf("+Z, "); - break; - case 6: - printf("-Z, "); - break; - default: - break; - } - printf("#%d\n", tap_num); -} - -int handle_pedometer(int *got_event) -{ - static int last_pedometer_steps = -1; - static long last_pedometer_time = -1; - static unsigned long last_pedometer_poll = 0L; - static unsigned long pedometer_poll_timeout = 500L; // .5 second - - unsigned long now; - int pedometer_steps; - long pedometer_time; - -#ifdef DEBUG_PRINT - printf("GT:Pedometer Handler\n"); -#endif - - if ((now = inv_get_tick_count()) - last_pedometer_poll - < pedometer_poll_timeout) { - return 0; - } - last_pedometer_poll = now; - - pedometer_steps = read_sysfs_posint("pedometer_steps", dev_dir_name); - pedometer_time = read_sysfs_posint("pedometer_time", dev_dir_name); - - if (last_pedometer_steps == -1 && last_pedometer_time == -1) { - if (!*got_event) - printf("\n"); - printf("p> pedometer=%d, %ld ", - pedometer_steps, pedometer_time); - if (pedometer_steps > 10 - || pedometer_time > (pedometer_poll_timeout * 2)) - printf("(resumed)\n"); - else - printf("\n"); - *got_event = true; - } else if (last_pedometer_steps != pedometer_steps - || last_pedometer_time != pedometer_time) { - if (!*got_event) - printf("\n"); - printf("p> pedometer=%d, %ld\n", - pedometer_steps, pedometer_time); - *got_event = true; - } - - last_pedometer_steps = pedometer_steps; - last_pedometer_time = pedometer_time; - - return 0; -} - -/* - Main processing functions -*/ - -void dump_dmp_event_struct(void) -{ -#define VARVAL(f, v) printf("\t%s : " f "\n", #v, v); - int i; - - printf("dmp_feat structure content:\n"); - for (i = 0; i < FEAT_NUM; i++) { - printf("%d - ", i); - VARVAL("%d", dmp_feat[i].enabled); - VARVAL("%s", dmp_feat[i].sysfs_name); - VARVAL("%p", dmp_feat[i].phandler); - VARVAL("%p", dmp_feat[i].pollfd); - if (dmp_feat[i].pollfd) { - VARVAL("%d", dmp_feat[i].pollfd->events); - VARVAL("%d", dmp_feat[i].pollfd->revents); - VARVAL("%d", dmp_feat[i].pollfd->fd); - } - } - printf("dmp_feat structure content:\n"); - for (i = 0; i < FEAT_NUM; i++) { - printf("%d - ", i); - VARVAL("%d", pollfds[i].fd); - VARVAL("%d", pollfds[i].events); - VARVAL("%d", pollfds[i].revents); - } - printf("end.\n"); -} - -void init_dmp_event_fds(void) -{ - int i, j = 0; - char file_name[100]; - - for (i = 0; i < FEAT_NUM; i++) { - if (!dmp_feat[i].enabled) - continue; - sprintf(file_name, "%s/%s", dev_dir_name, dmp_feat[i].sysfs_name); - pollfds[j].fd = open(file_name, O_RDONLY | O_NONBLOCK); - if (pollfds[j].fd < 0) { - printf("Err: cannot open requested event file '%s'\n", file_name); - } else { - printf("INFO: opened event node '%s'\n", file_name); - } - pollfds[j].events = POLLPRI | POLLERR; - pollfds[j].revents = 0; - - dmp_feat[i].pollfd = &pollfds[j]; - j++; - } -} - -void close_dmp_event_fds(void) -{ - int i; - for (i = 0; i < pollfds_used; i++) - close(pollfds[i].fd); -} - -void poll_dmp_event_fds(void) -{ - int i; - char d[4]; - static int got_event = 1; - - // read the pollable fds - for (i = 0; i < pollfds_used; i++) - read(pollfds[i].fd, d, 4); - - // poll - if (got_event) - printf("e> "); - got_event = false; - poll(pollfds, pollfds_used, POLL_TIME); - - for (i = 0; i < FEAT_NUM; i++) { - if (!dmp_feat[i].enabled) - continue; - - if (dmp_feat[i].pollfd->revents != 0) { - char file_name[200]; - int data; - - sprintf(file_name, "%s/%s", - dev_dir_name, dmp_feat[i].sysfs_name); - FILE *fp = fopen(file_name, "rt"); - if (!fp) { - printf("Err:cannot open requested event file '%s'\n", - dmp_feat[i].sysfs_name); - continue; - } - fscanf(fp, "%d\n", &data); - fclose(fp); - dmp_feat[i].pollfd->revents = 0; - - dmp_feat[i].phandler(data); - got_event = true; - } - } - - if (test_pedometer) { - /* pedometer is not event based, therefore we poll using a timer every - pedometer_poll_timeout milliseconds */ - handle_pedometer(&got_event); - } -} - -/* - Main -*/ - -int main(int argc, char **argv) -{ - unsigned long num_loops = 2; - unsigned long timedelay = 100000; - unsigned long buf_len = 128; - - int ret, c, i, j, toread; - int fp; - - int num_channels; - char *trigger_name = NULL; - - int datardytrigger = 1; - char *data; - int read_size; - int dev_num, trig_num; - char *buffer_access; - int scan_size; - int noevents = 0; - int p_event = 0, nodmp = 0; - char *dummy; - char chip_name[10]; - char device_name[10]; - char sysfs[100]; - - struct iio_channel_info *infoarray; - - // all output to stdout must be delivered immediately, no buffering - setvbuf(stdout, NULL, _IONBF, 0); - - // get info about the device and driver - inv_get_sysfs_path(sysfs); - if (inv_get_chip_name(chip_name) != INV_SUCCESS) { - printf("get chip name fail\n"); - exit(0); - } - printf("INFO: chip_name=%s\n", chip_name); - - for (i = 0; i < strlen(chip_name); i++) - device_name[i] = tolower(chip_name[i]); - device_name[strlen(chip_name)] = '\0'; - printf("INFO: device name=%s\n", device_name); - - /* parse the command line parameters - -r means no DMP is enabled (raw) -> should be used for mpu3050. - -p means no print of data - when using -p, 1 means orientation, 2 means tap, 3 means flick */ - while ((c = getopt(argc, argv, "l:w:c:premavt:")) != -1) { - switch (c) { - case 't': - trigger_name = optarg; - datardytrigger = 0; - break; - case 'e': - noevents = 1; - break; - case 'p': - p_event = 1; - break; - case 'r': - nodmp = 1; - break; - case 'c': - num_loops = strtoul(optarg, &dummy, 10); - break; - case 'w': - timedelay = strtoul(optarg, &dummy, 10); - break; - case 'l': - buf_len = strtoul(optarg, &dummy, 10); - break; - case 'm': - test_motion = true; - break; - case 'a': - accel_only = true; - break; - case 'v': - verbose = true; - break; - case '?': - return -1; - } - } - - pollfds_used = 0; - - // comment out/remove/if(0) the block corresponding to the feature - // that you want to disable - - if (0) { - struct dmp_feat_t f = { - true, - NULL, - "event_tap", - handle_tap - }; - dmp_feat[pollfds_used] = f; - pollfds_used++; - } - if (test_orientation) { - struct dmp_feat_t f = { - true, - NULL, - "event_orientation", - handle_orientation - }; - dmp_feat[pollfds_used] = f; - pollfds_used++; - } - if (1) { - struct dmp_feat_t f = { - true, - NULL, - "event_display_orientation", - handle_display_orientation - }; - dmp_feat[pollfds_used] = f; - pollfds_used++; - } - if (test_motion) { - struct dmp_feat_t f = { - true, - NULL, - "event_accel_motion", - handle_motion - }; - dmp_feat[pollfds_used] = f; - pollfds_used++; - } - if (test_flick) { - struct dmp_feat_t f = { - true, - NULL, - "event_flick", - handle_flick - }; - dmp_feat[pollfds_used] = f; - pollfds_used++; - } - - // debug - printf("INFO\n"); - printf("INFO: Configured features:\n"); - for (i = 0; i < pollfds_used; i++) - printf("INFO: %d -> %s\n", i, dmp_feat[i].sysfs_name); - printf("INFO\n"); - - /* Find the device requested */ - dev_num = find_type_by_name(device_name, "iio:device"); - if (dev_num < 0) { - printf("Failed to find the %s\n", device_name); - ret = -ENODEV; - goto error_ret; - } - printf("INFO: iio device number=%d\n", dev_num); - asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num); - if (trigger_name == NULL) { - /* - * Build the trigger name. If it is device associated it's - * name is <device_name>_dev[n] where n matches the device - * number found above - */ - ret = asprintf(&trigger_name, "%s-dev%d", device_name, dev_num); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - } - ret = write_sysfs_int_and_verify("buffer/enable", dev_dir_name, 0); - if (ret < 0) - return ret; - ret = write_sysfs_int_and_verify("power_state", dev_dir_name, 1); - - // - // motion interrupt in low power accel mode - // - if (test_motion) { - ret = write_sysfs_int_and_verify("motion_lpa_on", dev_dir_name, 1); - if (ret < 0) - return ret; - // magnitude threshold - range [0, 1020] in 32 mg increments - ret = write_sysfs_int_and_verify("motion_lpa_threshold", dev_dir_name, - 3 * 32); - if (ret < 0) - return ret; - // duration in ms up to 2^16 - ret = write_sysfs_int_and_verify("motion_lpa_duration", dev_dir_name, - 200 * 1); - if (ret < 0) - return ret; - // motion_lpa_freq: 0 for 1.25, 1 for 5, 2 for 20, 3 for 40 Hz update rate - // of the low power accel mode. - // The higher the rate, the better responsiveness of the motion interrupt. - ret = write_sysfs_int("motion_lpa_freq", dev_dir_name, 2); - if (ret < 0) - return ret; - } else { - ret = write_sysfs_int_and_verify("motion_lpa_on", dev_dir_name, 0); - if (ret < 0) - return ret; - } - - /* Verify the trigger exists */ - trig_num = find_type_by_name(trigger_name, "trigger"); - if (trig_num < 0) { - printf("Failed to find the trigger %s\n", trigger_name); - ret = -ENODEV; - goto error_free_triggername; - } - printf("INFO: iio trigger number=%d\n", trig_num); - - if (!nodmp) - setup_dmp(dev_dir_name, p_event); - - /* - * Construct the directory name for the associated buffer. - * As we know that the lis3l02dq has only one buffer this may - * be built rather than found. - */ - ret = asprintf(&buf_dir_name, "%siio:device%d/buffer", iio_dir, dev_num); - if (ret < 0) { - ret = -ENOMEM; - goto error_free_triggername; - } - - /* Set the device trigger to be the data rdy trigger found above */ - ret = write_sysfs_string_and_verify("trigger/current_trigger", - dev_dir_name, - trigger_name); - if (ret < 0) { - printf("Failed to write current_trigger file\n"); - goto error_free_buf_dir_name; - } - - /* Setup ring buffer parameters - length must be even number because iio_store_to_sw_ring is expecting - half pointer to be equal to the read pointer, which is impossible - when buflen is odd number. This is actually a bug in the code */ - ret = write_sysfs_int("length", buf_dir_name, buf_len * 2); - if (ret < 0) - goto exit_here; - - // gyro - if (accel_only) { - ret = enable_anglvel_se(dev_dir_name, &infoarray, &num_channels, 0); - if (ret < 0) - return ret; - ret = write_sysfs_int_and_verify("gyro_enable", dev_dir_name, 0); - if (ret < 0) - return ret; - } else { - ret = enable_anglvel_se(dev_dir_name, &infoarray, &num_channels, 1); - if (ret < 0) - return ret; - ret = write_sysfs_int_and_verify("gyro_enable", dev_dir_name, 1); - if (ret < 0) - return ret; - } - - // accel - ret = enable_accel_se(dev_dir_name, &infoarray, &num_channels, 1); - if (ret < 0) - return ret; - ret = write_sysfs_int_and_verify("accel_enable", dev_dir_name, 1); - if (ret < 0) - return ret; - - // quaternion - if (!nodmp) { - ret = enable_quaternion_se(dev_dir_name, &infoarray, &num_channels, 1); - if (ret < 0) - return ret; - ret = write_sysfs_int_and_verify("three_axes_q_on", dev_dir_name, 1); - if (ret < 0) - return ret; - } else { - ret = enable_quaternion_se(dev_dir_name, &infoarray, &num_channels, 0); - if (ret < 0) - return ret; - ret = write_sysfs_int_and_verify("dmp_on", dev_dir_name, 0); - if (ret < 0) - return ret; - } - - //sprintf(dmp_path, "%s/dmp_firmware", dev_dir_name); - //verify_img(dmp_path); - - ret = build_channel_array(dev_dir_name, &infoarray, &num_channels); - if (ret) { - printf("Problem reading scan element information\n"); - goto exit_here; - } - - /* enable the buffer */ - ret = write_sysfs_int_and_verify("enable", buf_dir_name, 1); - if (ret < 0) - goto exit_here; - scan_size = size_from_channelarray(infoarray, num_channels); - data = malloc(scan_size * buf_len); - if (!data) { - ret = -ENOMEM; - goto exit_here; - } - - if (p_event) { - - /* polling events from the DMP */ - init_dmp_event_fds(); - while(!_kbhit()) - poll_dmp_event_fds(); - close_dmp_event_fds(); - - } else { - - /* attempt to open non blocking the access dev */ - ret = asprintf(&buffer_access, "/dev/iio:device%d", dev_num); - if (ret < 0) { - ret = -ENOMEM; - goto error_free_data; - } - fp = open(buffer_access, O_RDONLY | O_NONBLOCK); - if (fp == -1) { /*If it isn't there make the node */ - printf("Failed to open %s\n", buffer_access); - ret = -errno; - goto error_free_buffer_access; - } - /* wait for events num_loops times */ - for (j = 0; j < num_loops; j++) { - if (!noevents) { - struct pollfd pfd = { - .fd = fp, - .events = POLLIN, - }; - poll(&pfd, 1, -1); - toread = 1; - if (j % 128 == 0) - usleep(timedelay); - - } else { - usleep(timedelay); - toread = 1; - } - read_size = read(fp, data, toread * scan_size); - if (read_size == -EAGAIN) { - printf("nothing available\n"); - continue; - } - if (!p_event) { - for (i = 0; i < read_size / scan_size; i++) - process_scan(data + scan_size * i, infoarray, num_channels); - } - } - close(fp); - } - -error_free_buffer_access: - free(buffer_access); -error_free_data: - free(data); -exit_here: - /* stop the ring buffer */ - ret = write_sysfs_int_and_verify("enable", buf_dir_name, 0); - /* disable the dmp */ - if (p_event) - ret = write_sysfs_int_and_verify("dmp_on", dev_dir_name, 0); - -error_free_buf_dir_name: - free(buf_dir_name); -error_free_triggername: - if (datardytrigger) - free(trigger_name); -error_ret: - return ret; -} diff --git a/65xx/libsensors_iio/software/simple_apps/playback/linux/and_constructor.c b/65xx/libsensors_iio/software/simple_apps/playback/linux/and_constructor.c deleted file mode 100755 index c4f09a6..0000000 --- a/65xx/libsensors_iio/software/simple_apps/playback/linux/and_constructor.c +++ /dev/null @@ -1,379 +0,0 @@ -/* - $License: - Copyright (C) 2012 InvenSense Corporation, All Rights Reserved. - $ - */ - -/******************************************************************************* - * - * $Id:$ - * - ******************************************************************************/ - -/* - Includes, Defines, and Macros -*/ - -#undef MPL_LOG_NDEBUG -#define MPL_LOG_NDEBUG 0 /* turn to 0 to enable verbose logging */ - -#include "log.h" -#undef MPL_LOG_TAG -#define MPL_LOG_TAG "MPL-playback" - -#include "and_constructor.h" -#include "mlos.h" -#include "invensense.h" -#include "invensense_adv.h" - -/* - Typedef -*/ -struct inv_construct_t { - int product; /**< Gyro Product Number */ - int debug_mode; - int last_mode; - FILE *file; - int dmp_version; - int left_in_buffer; -#define FIFO_READ_SIZE 100 - unsigned char fifo_data[FIFO_READ_SIZE]; - int gyro_enable; - int accel_enable; - int compass_enable; - int quat_enable; -}; - -/* - Globals -*/ -static struct inv_construct_t inv_construct = {0}; -static void (*s_func_cb)(void); -static char playback_filename[101] = "/data/playback.bin"; -struct fifo_dmp_config fifo_dmp_cfg = {0}; - -/* - Functions -*/ -void inv_set_playback_filename(char *filename, int length) -{ - if (length > 100) { - MPL_LOGE("Error : file name and path too long, 100 characters limit\n"); - return; - } - strncpy(playback_filename, filename, length); -} - -inv_error_t inv_constructor_setup(void) -{ - unsigned short orient; - extern signed char g_gyro_orientation[9]; - extern signed char g_accel_orientation[9]; - extern signed char g_compass_orientation[9]; - float scale = 2.f; - long sens; - - // gyro setup - orient = inv_orientation_matrix_to_scalar(g_gyro_orientation); - inv_set_gyro_orientation_and_scale(orient, 2000L << 15); - - // accel setup - orient = inv_orientation_matrix_to_scalar(g_accel_orientation); - scale = 2.f; - sens = (long)(scale * (1L << 15)); - inv_set_accel_orientation_and_scale(orient, sens); - - // compass setup - orient = inv_orientation_matrix_to_scalar(g_compass_orientation); - // scale is the max value of the compass in micro Tesla. - scale = 5000.f; - sens = (long)(scale * (1L << 15)); - inv_set_compass_orientation_and_scale(orient, sens); - - return INV_SUCCESS; -} - -inv_error_t inv_set_fifo_processed_callback(void (*func_cb)(void)) -{ - s_func_cb = func_cb; - return INV_SUCCESS; -} - -void int32_to_long(int32_t in[], long out[], int length) -{ - int ii; - for (ii = 0; ii < length; ii++) - out[ii] = (long)in[ii]; -} - -inv_error_t inv_playback(void) -{ - inv_rd_dbg_states type; - inv_time_t ts; - int32_t buffer[4]; - short gyro[3]; - size_t r = 1; - int32_t orientation; - int32_t sensitivity, sample_rate_us = 0; - - // Check to make sure we were request to playback - if (inv_construct.debug_mode != RD_PLAYBACK) { - MPL_LOGE("%s|%s|%d error: debug_mode != RD_PLAYBACK\n", - __FILE__, __func__, __LINE__); - return INV_ERROR; - } - - if (inv_construct.file == NULL) { - inv_construct.file = fopen(playback_filename, "rb"); - if (!inv_construct.file) { - MPL_LOGE("Error : cannot find or open playback file '%s'\n", - playback_filename); - return INV_ERROR_FILE_OPEN; - } - } - - while (1) { - r = fread(&type, sizeof(type), 1, inv_construct.file); - if (r == 0) { - MPL_LOGV("read 0 bytes, PLAYBACK file closed\n"); - inv_construct.debug_mode = RD_NO_DEBUG; - fclose(inv_construct.file); - break; - } - //MPL_LOGV("TYPE : %d, %d\n", type); - switch (type) { - case PLAYBACK_DBG_TYPE_GYRO: - r = fread(gyro, sizeof(gyro[0]), 3, inv_construct.file); - r = fread(&ts, sizeof(ts), 1, inv_construct.file); - inv_build_gyro(gyro, ts); - MPL_LOGV("PLAYBACK_DBG_TYPE_GYRO, %+d, %+d, %+d, %+lld\n", - gyro[0], gyro[1], gyro[2], ts); - break; - case PLAYBACK_DBG_TYPE_ACCEL: - { - long accel[3]; - r = fread(buffer, sizeof(buffer[0]), 3, inv_construct.file); - r = fread(&ts, sizeof(ts), 1, inv_construct.file); - int32_to_long(buffer, accel, 3); - inv_build_accel(accel, 0, ts); - MPL_LOGV("PLAYBACK_DBG_TYPE_ACCEL, %+d, %+d, %+d, %lld\n", - buffer[0], buffer[1], buffer[2], ts); - break; - } - case PLAYBACK_DBG_TYPE_COMPASS: - { - long compass[3]; - r = fread(buffer, sizeof(buffer[0]), 3, inv_construct.file); - r = fread(&ts, sizeof(ts), 1, inv_construct.file); - int32_to_long(buffer, compass, 3); - inv_build_compass(compass, 0, ts); - MPL_LOGV("PLAYBACK_DBG_TYPE_COMPASS, %+d, %+d, %+d, %lld\n", - buffer[0], buffer[1], buffer[2], ts); - break; - } - case PLAYBACK_DBG_TYPE_TEMPERATURE: - r = fread(buffer, sizeof(buffer[0]), 1, inv_construct.file); - r = fread(&ts, sizeof(ts), 1, inv_construct.file); - inv_build_temp(buffer[0], ts); - MPL_LOGV("PLAYBACK_DBG_TYPE_TEMPERATURE, %+d, %lld\n", - buffer[0], ts); - break; - case PLAYBACK_DBG_TYPE_QUAT: - { - long quat[4]; - r = fread(buffer, sizeof(buffer[0]), 4, inv_construct.file); - r = fread(&ts, sizeof(ts), 1, inv_construct.file); - int32_to_long(buffer, quat, 4); - inv_build_quat(quat, INV_BIAS_APPLIED, ts); - MPL_LOGV("PLAYBACK_DBG_TYPE_QUAT, %+d, %+d, %+d, %+d, %lld\n", - buffer[0], buffer[1], buffer[2], buffer[3], ts); - break; - } - case PLAYBACK_DBG_TYPE_EXECUTE: - MPL_LOGV("PLAYBACK_DBG_TYPE_EXECUTE\n"); - inv_execute_on_data(); - if (s_func_cb) - s_func_cb(); - //done = 1; - break; - - case PLAYBACK_DBG_TYPE_G_ORIENT: - MPL_LOGV("PLAYBACK_DBG_TYPE_G_ORIENT\n"); - r = fread(&orientation, sizeof(orientation), 1, inv_construct.file); - r = fread(&sensitivity, sizeof(sensitivity), 1, inv_construct.file); - inv_set_gyro_orientation_and_scale(orientation, sensitivity); - break; - case PLAYBACK_DBG_TYPE_A_ORIENT: - MPL_LOGV("PLAYBACK_DBG_TYPE_A_ORIENT\n"); - r = fread(&orientation, sizeof(orientation), 1, inv_construct.file); - r = fread(&sensitivity, sizeof(sensitivity), 1, inv_construct.file); - inv_set_accel_orientation_and_scale(orientation, sensitivity); - break; - case PLAYBACK_DBG_TYPE_C_ORIENT: - MPL_LOGV("PLAYBACK_DBG_TYPE_C_ORIENT\n"); - r = fread(&orientation, sizeof(orientation), 1, inv_construct.file); - r = fread(&sensitivity, sizeof(sensitivity), 1, inv_construct.file); - inv_set_compass_orientation_and_scale(orientation, sensitivity); - break; - - case PLAYBACK_DBG_TYPE_G_SAMPLE_RATE: - r = fread(&sample_rate_us, sizeof(sample_rate_us), - 1, inv_construct.file); - inv_set_gyro_sample_rate(sample_rate_us); - MPL_LOGV("PLAYBACK_DBG_TYPE_G_SAMPLE_RATE => %d\n", - sample_rate_us); - break; - case PLAYBACK_DBG_TYPE_A_SAMPLE_RATE: - r = fread(&sample_rate_us, sizeof(sample_rate_us), - 1, inv_construct.file); - inv_set_accel_sample_rate(sample_rate_us); - MPL_LOGV("PLAYBACK_DBG_TYPE_A_SAMPLE_RATE => %d\n", - sample_rate_us); - break; - case PLAYBACK_DBG_TYPE_C_SAMPLE_RATE: - r = fread(&sample_rate_us, sizeof(sample_rate_us), - 1, inv_construct.file); - inv_set_compass_sample_rate(sample_rate_us); - MPL_LOGV("PLAYBACK_DBG_TYPE_C_SAMPLE_RATE => %d\n", - sample_rate_us); - break; - - case PLAYBACK_DBG_TYPE_GYRO_OFF: - MPL_LOGV("PLAYBACK_DBG_TYPE_GYRO_OFF\n"); - inv_gyro_was_turned_off(); - break; - case PLAYBACK_DBG_TYPE_ACCEL_OFF: - MPL_LOGV("PLAYBACK_DBG_TYPE_ACCEL_OFF\n"); - inv_accel_was_turned_off(); - break; - case PLAYBACK_DBG_TYPE_COMPASS_OFF: - MPL_LOGV("PLAYBACK_DBG_TYPE_COMPASS_OFF\n"); - inv_compass_was_turned_off(); - break; - case PLAYBACK_DBG_TYPE_QUAT_OFF: - MPL_LOGV("PLAYBACK_DBG_TYPE_QUAT_OFF\n"); - inv_quaternion_sensor_was_turned_off(); - break; - - case PLAYBACK_DBG_TYPE_Q_SAMPLE_RATE: - MPL_LOGV("PLAYBACK_DBG_TYPE_Q_SAMPLE_RATE\n"); - r = fread(&sample_rate_us, sizeof(sample_rate_us), - 1, inv_construct.file); - inv_set_quat_sample_rate(sample_rate_us); - break; - default: - //MPL_LOGV("PLAYBACK file closed\n"); - fclose(inv_construct.file); - MPL_LOGE("%s|%s|%d error: unrecognized log type '%d', " - "PLAYBACK file closed\n", - __FILE__, __func__, __LINE__, type); - return INV_ERROR; - } - } - msleep(1); - - inv_construct.debug_mode = RD_NO_DEBUG; - fclose(inv_construct.file); - - return INV_SUCCESS; -} - -/** Turns on/off playback and record modes -* @param mode Turn on recording mode with RD_RECORD and turn off recording mode with -* RD_NO_DBG. Turn on playback mode with RD_PLAYBACK. -*/ -void inv_set_debug_mode(rd_dbg_mode mode) -{ -#ifdef INV_PLAYBACK_DBG - inv_construct.debug_mode = mode; -#endif -} - -inv_error_t inv_constructor_start(void) -{ - inv_error_t result; - unsigned char divider; - //int gest_enabled = inv_get_gesture_enable(); - - // start the software - result = inv_start_mpl(); - if (result) { - LOG_RESULT_LOCATION(result); - return result; - } - - /* - if (inv_construct.dmp_version == WIN8_DMP_VERSION) { - int fifo_divider; - divider = 4; // 4 means 200Hz DMP - fifo_divider = 3; - // Set Gyro Sample Rate in MPL in micro seconds - inv_set_gyro_sample_rate(1000L*(divider+1)*(fifo_divider+1)); - - // Set Gyro Sample Rate in MPL in micro seconds - inv_set_quat_sample_rate(1000L*(divider+1)*(fifo_divider+1)); - - // Set Compass Sample Rate in MPL in micro seconds - inv_set_compass_sample_rate(1000L*(divider+1)*(fifo_divider+1)); - - // Set Accel Sample Rate in MPL in micro seconds - inv_set_accel_sample_rate(1000L*(divider+1)*(fifo_divider+1)); - } else if (gest_enabled) { - int fifo_divider; - unsigned char mpl_divider; - - inv_send_interrupt_word(); - inv_send_sensor_data(INV_ALL & INV_GYRO_ACC_MASK); - inv_send_quaternion(); - - divider = fifo_dmp_cfg.sample_divider; - mpl_divider = fifo_dmp_cfg.mpl_divider; - - // Set Gyro Sample Rate in MPL in micro seconds - inv_set_gyro_sample_rate(1000L*(mpl_divider+1)); - - // Set Gyro Sample Rate in MPL in micro seconds - inv_set_quat_sample_rate(1000L*(mpl_divider+1)); - - // Set Compass Sample Rate in MPL in micro seconds - inv_set_compass_sample_rate(1000L*(mpl_divider+1)); - - // Set Accel Sample Rate in MPL in micro seconds - inv_set_accel_sample_rate(1000L*(mpl_divider+1)); - } else - */ - { - divider = 9; - // set gyro sample sate in MPL in micro seconds - inv_set_gyro_sample_rate(1000L*(divider+1)); - // set compass sample rate in MPL in micro seconds - inv_set_compass_sample_rate(1000L*(divider+1)); - // set accel sample rate in MPL in micro seconds - inv_set_accel_sample_rate(1000L*(divider+1)); - } - - // setup the scale factors and orientations and other parameters - result = inv_constructor_setup(); - - return result; -} - -inv_error_t inv_constructor_default_enable() -{ - INV_ERROR_CHECK(inv_enable_quaternion()); - INV_ERROR_CHECK(inv_enable_fast_nomot()); - INV_ERROR_CHECK(inv_enable_heading_from_gyro()); - INV_ERROR_CHECK(inv_enable_compass_bias_w_gyro()); - INV_ERROR_CHECK(inv_enable_hal_outputs()); - INV_ERROR_CHECK(inv_enable_vector_compass_cal()); - INV_ERROR_CHECK(inv_enable_9x_sensor_fusion()); - INV_ERROR_CHECK(inv_enable_gyro_tc()); - INV_ERROR_CHECK(inv_enable_no_gyro_fusion()); - INV_ERROR_CHECK(inv_enable_in_use_auto_calibration()); - INV_ERROR_CHECK(inv_enable_magnetic_disturbance()); - return INV_SUCCESS; -} - -/** - * @} - */ diff --git a/65xx/libsensors_iio/software/simple_apps/playback/linux/and_constructor.h b/65xx/libsensors_iio/software/simple_apps/playback/linux/and_constructor.h deleted file mode 100755 index 5905037..0000000 --- a/65xx/libsensors_iio/software/simple_apps/playback/linux/and_constructor.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - $License: - Copyright (C) 2012 InvenSense Corporation, All Rights Reserved. - $ - */ - -/******************************************************************************* - * - * $Id:$ - * - ******************************************************************************/ - -#ifndef INV_CONSTRUCTOR_H__ -#define INV_CONSTRUCTOR_H__ - -#include "mltypes.h" -#include "data_builder.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define PRECISION 10000.f -#define RANGE_FLOAT_TO_FIXEDPOINT(range, x) { \ - range.mantissa = (long)x; \ - range.fraction = (long)((float)(x-(long)x)*PRECISION); \ -} -#define RANGE_FIXEDPOINT_TO_FLOAT(range, x) { \ - x = (float)(range.mantissa); \ - x += ((float)range.fraction/PRECISION); \ -} - -struct fifo_dmp_config { - unsigned char sample_divider; - unsigned char fifo_divider; - unsigned char mpl_divider; -}; - -inv_error_t inv_construct_and_push_data(); -inv_error_t inv_set_fifo_processed_callback(void (*func_cb)(void)); -inv_error_t inv_constructor_setup(); -inv_error_t inv_constructor_start(); -inv_error_t inv_constructor_init(); -inv_error_t inv_constructor_default_enable(); -void inv_set_debug_mode(rd_dbg_mode mode); -inv_error_t inv_playback(); -void inv_set_playback_filename(char *filename, int length); -inv_error_t wait_for_and_process_interrupt(); - -inv_error_t inv_set_interrupt_word(unsigned long word); -inv_error_t inv_get_interrupt_word(unsigned long *data); -inv_error_t inv_set_gesture_enable(int word); -int inv_get_gesture_enable(void); -inv_error_t inv_set_fifo_rate(unsigned long fifo_rate); -inv_error_t inv_get_dmp_sample_divider(unsigned char *data); - -#ifdef __cplusplus -} -#endif - -#endif // INVENSENSE_INV_CONSTRUCTOR_H__ - diff --git a/65xx/libsensors_iio/software/simple_apps/playback/linux/build/android/inv_playback-shared b/65xx/libsensors_iio/software/simple_apps/playback/linux/build/android/inv_playback-shared Binary files differdeleted file mode 100755 index c252a50..0000000 --- a/65xx/libsensors_iio/software/simple_apps/playback/linux/build/android/inv_playback-shared +++ /dev/null diff --git a/65xx/libsensors_iio/software/simple_apps/playback/linux/build/android/shared.mk b/65xx/libsensors_iio/software/simple_apps/playback/linux/build/android/shared.mk deleted file mode 100755 index dc33ee3..0000000 --- a/65xx/libsensors_iio/software/simple_apps/playback/linux/build/android/shared.mk +++ /dev/null @@ -1,96 +0,0 @@ -EXEC = inv_playback$(SHARED_APP_SUFFIX) - -MK_NAME = $(notdir $(CURDIR)/$(firstword $(MAKEFILE_LIST))) - -CROSS ?= $(ANDROID_ROOT)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- -COMP ?= $(CROSS)gcc -LINK ?= $(CROSS)gcc - -OBJFOLDER = $(CURDIR)/obj - -INV_ROOT = ../../../../../.. -APP_DIR = $(CURDIR)/../.. -COMMON_DIR = $(INV_ROOT)/software/simple_apps/common -MLLITE_DIR = $(INV_ROOT)/software/core/mllite -MPL_DIR = $(INV_ROOT)/software/core/mpl - -include $(INV_ROOT)/software/build/android/common.mk - -CFLAGS += $(CMDLINE_CFLAGS) -CFLAGS += $(ANDROID_COMPILE) -CFLAGS += -Wall -CFLAGS += -fpic -CFLAGS += -nostdlib -CFLAGS += -DNDEBUG -CFLAGS += -D_REENTRANT -CFLAGS += -DLINUX -CFLAGS += -DANDROID -CFLAGS += -mthumb-interwork -CFLAGS += -fno-exceptions -CFLAGS += -ffunction-sections -CFLAGS += -funwind-tables -CFLAGS += -fstack-protector -CFLAGS += -fno-short-enums -CFLAGS += -fmessage-length=0 -CFLAGS += -I$(MLLITE_DIR) -CFLAGS += -I$(MPL_DIR) -CFLAGS += -I$(COMMON_DIR) -CFLAGS += $(INV_INCLUDES) -CFLAGS += $(INV_DEFINES) - -LLINK = -lc -LLINK += -lm -LLINK += -lutils -LLINK += -lcutils -LLINK += -lgcc -LLINK += -ldl -LLINK += -lstdc++ -LLINK += -llog -LLINK += -lz - -LFLAGS += $(CMDLINE_LFLAGS) -LFLAGS += $(ANDROID_LINK_EXECUTABLE) - -LRPATH = -Wl,-rpath,$(ANDROID_ROOT)/out/target/product/$(PRODUCT)/obj/lib:$(ANDROID_ROOT)/out/target/product/$(PRODUCT)/system/lib - -#################################################################################################### -## sources - -INV_LIBS = $(MPL_DIR)/build/$(TARGET)/$(LIB_PREFIX)$(MPL_LIB_NAME).$(SHARED_LIB_EXT) -INV_LIBS += $(MLLITE_DIR)/build/$(TARGET)/$(LIB_PREFIX)$(MLLITE_LIB_NAME).$(SHARED_LIB_EXT) - -#INV_SOURCES and VPATH provided by Makefile.filelist -include ../filelist.mk - -INV_OBJS := $(addsuffix .o,$(INV_SOURCES)) -INV_OBJS_DST = $(addprefix $(OBJFOLDER)/,$(addsuffix .o, $(notdir $(INV_SOURCES)))) - -#################################################################################################### -## rules - -.PHONY: all clean cleanall install - -all: $(EXEC) $(MK_NAME) - -$(EXEC) : $(OBJFOLDER) $(INV_OBJS_DST) $(INV_LIBS) $(MK_NAME) - @$(call echo_in_colors, "\n<linking $(EXEC) with objects $(INV_OBJS_DST) $(PREBUILT_OBJS) and libraries $(INV_LIBS)\n") - $(LINK) $(INV_OBJS_DST) -o $(EXEC) $(LFLAGS) $(LLINK) $(INV_LIBS) $(LLINK) $(LRPATH) - -$(OBJFOLDER) : - @$(call echo_in_colors, "\n<creating object's folder 'obj/'>\n") - mkdir obj - -$(INV_OBJS_DST) : $(OBJFOLDER)/%.c.o : %.c $(MK_NAME) - @$(call echo_in_colors, "\n<compile $< to $(OBJFOLDER)/$(notdir $@)>\n") - $(COMP) $(ANDROID_INCLUDES) $(KERNEL_INCLUDES) $(INV_INCLUDES) $(CFLAGS) -o $@ -c $< - -clean : - rm -fR $(OBJFOLDER) - -cleanall : - rm -fR $(EXEC) $(OBJFOLDER) - -install : $(EXEC) - cp -f $(EXEC) $(INSTALL_DIR) - - diff --git a/65xx/libsensors_iio/software/simple_apps/playback/linux/build/filelist.mk b/65xx/libsensors_iio/software/simple_apps/playback/linux/build/filelist.mk deleted file mode 100755 index 1d04fea..0000000 --- a/65xx/libsensors_iio/software/simple_apps/playback/linux/build/filelist.mk +++ /dev/null @@ -1,20 +0,0 @@ -#### filelist.mk for mpu_iio #### - -# headers -HEADERS += $(APP_DIR)/iio_utils.h -HEADERS += $(APP_DIR)/and_constructor.h -HEADERS += $(APP_DIR)/datalogger_outputs.h -HEADERS += $(COMMON_DIR)/console_helper.h -HEADERS += $(COMMON_DIR)/mlerrorcode.h -HEADERS += $(COMMON_DIR)/testsupport.h - -# sources -SOURCES := $(APP_DIR)/main.c -SOURCES += $(APP_DIR)/and_constructor.c -SOURCES += $(APP_DIR)/datalogger_outputs.c -SOURCES += $(COMMON_DIR)/console_helper.c -SOURCES += $(COMMON_DIR)/mlerrorcode.c - -INV_SOURCES += $(SOURCES) - -VPATH += $(APP_DIR) $(COMMON_DIR) diff --git a/65xx/libsensors_iio/software/simple_apps/playback/linux/datalogger_outputs.c b/65xx/libsensors_iio/software/simple_apps/playback/linux/datalogger_outputs.c deleted file mode 100755 index 7c81cbb..0000000 --- a/65xx/libsensors_iio/software/simple_apps/playback/linux/datalogger_outputs.c +++ /dev/null @@ -1,384 +0,0 @@ -/** - * @defgroup HAL_Outputs - * @brief Motion Library - HAL Outputs - * Sets up common outputs for HAL - * - * @{ - * @file datalogger_outputs.c - * @brief Windows 8 HAL outputs. - */ - -#include <string.h> - -#include "datalogger_outputs.h" -#include "ml_math_func.h" -#include "mlmath.h" -#include "start_manager.h" -#include "data_builder.h" -#include "results_holder.h" - -/* - Defines -*/ -#define ACCEL_CONVERSION (0.000149637603759766f) - -/* - Types -*/ -struct datalogger_output_s { - int quat_accuracy; - inv_time_t quat_timestamp; - long quat[4]; - struct inv_sensor_cal_t sc; -}; - -/* - Globals and Statics -*/ -static struct datalogger_output_s dl_out; - -/* - Functions -*/ - -/** - * Raw (uncompensated) angular velocity (LSB) in chip frame. - * @param[out] values raw angular velocity in LSB. - * @param[out] timestamp Time when sensor was sampled. - */ -void inv_get_sensor_type_gyro_raw_short(short *values, inv_time_t *timestamp) -{ - struct inv_single_sensor_t *pg = &dl_out.sc.gyro; - - if (values) - memcpy(values, &pg->raw, sizeof(short) * 3); - if (timestamp) - *timestamp = pg->timestamp; -} - -/** - * Raw (uncompensated) angular velocity (degrees per second) in body frame. - * @param[out] values raw angular velocity in dps. - * @param[out] timestamp Time when sensor was sampled. - */ -void inv_get_sensor_type_gyro_raw_body_float(float *values, - inv_time_t *timestamp) -{ - struct inv_single_sensor_t *pg = &dl_out.sc.gyro; - long raw[3]; - long raw_body[3]; - - raw[0] = (long) pg->raw[0] * (1L << 16); - raw[1] = (long) pg->raw[1] * (1L << 16); - raw[2] = (long) pg->raw[2] * (1L << 16); - inv_convert_to_body_with_scale(pg->orientation, pg->sensitivity, - raw, raw_body); - if (values) { - values[0] = inv_q16_to_float(raw_body[0]); - values[1] = inv_q16_to_float(raw_body[1]); - values[2] = inv_q16_to_float(raw_body[2]); - } - if (timestamp) - *timestamp = pg->timestamp; -} - -/** - * Angular velocity (degrees per second) in body frame. - * @param[out] values Angular velocity in dps. - * @param[out] accuracy 0 (uncalibrated) to 3 (most accurate). - * @param[out] timestamp Time when sensor was sampled. - */ -void inv_get_sensor_type_gyro_float(float *values, int8_t *accuracy, - inv_time_t *timestamp) -{ - long gyro[3]; - inv_get_gyro_set(gyro, accuracy, timestamp); - - values[0] = (float)gyro[0] / 65536.f; - values[1] = (float)gyro[1] / 65536.f; - values[2] = (float)gyro[2] / 65536.f; -} - -/** - * Raw (uncompensated) acceleration (LSB) in chip frame. - * @param[out] values raw acceleration in LSB. - * @param[out] timestamp Time when sensor was sampled. - */ -void inv_get_sensor_type_accel_raw_short(short *values, inv_time_t *timestamp) -{ - struct inv_single_sensor_t *pa = &dl_out.sc.accel; - - if (values) - memcpy(values, &pa->raw, sizeof(short) * 3); - if (timestamp) - *timestamp = pa->timestamp; -} - -/** - * Acceleration (g's) in body frame. - * Microsoft defines gravity as positive acceleration pointing towards the - * Earth. - * @param[out] values Acceleration in g's. - * @param[out] accuracy 0 (uncalibrated) to 3 (most accurate). - * @param[out] timestamp Time when sensor was sampled. - */ -void inv_get_sensor_type_accel_float(float *values, int8_t *accuracy, - inv_time_t *timestamp) -{ - long accel[3]; - inv_get_accel_set(accel, accuracy, timestamp); - - values[0] = (float) -accel[0] / 65536.f; - values[1] = (float) -accel[1] / 65536.f; - values[2] = (float) -accel[2] / 65536.f; -} - -/** - * Raw (uncompensated) compass magnetic field (LSB) in chip frame. - * @param[out] values raw magnetic field in LSB. - * @param[out] timestamp Time when sensor was sampled. - */ -void inv_get_sensor_type_compass_raw_short(short *values, inv_time_t *timestamp) -{ - struct inv_single_sensor_t *pc = &dl_out.sc.compass; - - if (values) - memcpy(values, &pc->raw, sizeof(short) * 3); - if (timestamp) - *timestamp = pc->timestamp; -} - -/** - * Magnetic heading/field strength in body frame. - * TODO: No difference between mag_north and true_north yet. - * @param[out] mag_north Heading relative to magnetic north in degrees. - * @param[out] true_north Heading relative to true north in degrees. - * @param[out] values Field strength in milligauss. - * @param[out] accuracy 0 (uncalibrated) to 3 (most accurate). - * @param[out] timestamp Time when sensor was sampled. - */ -void inv_get_sensor_type_compass_float(float *mag_north, float *true_north, - float *values, int8_t *accuracy, inv_time_t *timestamp) -{ - long compass[3]; - long q00, q12, q22, q03, t1, t2; - - /* 1 uT = 10 milligauss. */ -#define COMPASS_CONVERSION (10 / 65536.f) - inv_get_compass_set(compass, accuracy, timestamp); - if (values) { - values[0] = (float)compass[0]*COMPASS_CONVERSION; - values[1] = (float)compass[1]*COMPASS_CONVERSION; - values[2] = (float)compass[2]*COMPASS_CONVERSION; - } - - /* TODO: Stolen from euler angle computation. Calculate this only once per - * callback. - */ - q00 = inv_q29_mult(dl_out.quat[0], dl_out.quat[0]); - q12 = inv_q29_mult(dl_out.quat[1], dl_out.quat[2]); - q22 = inv_q29_mult(dl_out.quat[2], dl_out.quat[2]); - q03 = inv_q29_mult(dl_out.quat[0], dl_out.quat[3]); - t1 = q12 - q03; - t2 = q22 + q00 - (1L << 30); - if (mag_north) { - *mag_north = atan2f((float) t1, (float) t2) * 180.f / (float) M_PI; - if (*mag_north < 0) - *mag_north += 360; - } - if (true_north) { - if (!mag_north) { - *true_north = atan2f((float) t1, (float) t2) * 180.f / (float) M_PI; - if (*true_north < 0) - *true_north += 360; - } else { - *true_north = *mag_north; - } - } -} - -#if 0 -// put it back when we handle raw temperature -/** - * Raw temperature (LSB). - * @param[out] value raw temperature in LSB (1 element). - * @param[out] timestamp Time when sensor was sampled. - */ -void inv_get_sensor_type_temp_raw_short(short *value, inv_time_t *timestamp) -{ - struct inv_single_sensor_t *pt = &dl_out.sc.temp; - if (value) { - /* no raw temperature, temperature is only handled calibrated - *value = pt->raw[0]; - */ - *value = pt->calibrated[0]; - } - if (timestamp) - *timestamp = pt->timestamp; -} -#endif - -/** - * Temperature (degree C). - * @param[out] values Temperature in degrees C. - * @param[out] timestamp Time when sensor was sampled. - */ -void inv_get_sensor_type_temperature_float(float *value, inv_time_t *timestamp) -{ - struct inv_single_sensor_t *pt = &dl_out.sc.temp; - long ltemp; - if (timestamp) - *timestamp = pt->timestamp; - if (value) { - /* no raw temperature, temperature is only handled calibrated - ltemp = pt->raw[0]; - */ - ltemp = pt->calibrated[0]; - *value = (float) ltemp / (1L << 16); - } -} - -/** - * Quaternion in body frame. - * @e inv_get_sensor_type_quaternion_float outputs the data in the following - * order: X, Y, Z, W. - * TODO: Windows expects a discontinuity at 180 degree rotations. Will our - * convention be ok? - * @param[out] values Quaternion normalized to one. - * @param[out] accuracy 0 (uncalibrated) to 3 (most accurate). - * @param[out] timestamp Time when sensor was sampled. - */ -void inv_get_sensor_type_quat_float(float *values, int *accuracy, - inv_time_t *timestamp) -{ - values[0] = dl_out.quat[0] / 1073741824.f; - values[1] = dl_out.quat[1] / 1073741824.f; - values[2] = dl_out.quat[2] / 1073741824.f; - values[3] = dl_out.quat[3] / 1073741824.f; - accuracy[0] = dl_out.quat_accuracy; - timestamp[0] = dl_out.quat_timestamp; -} - -/** Gravity vector (gee) in body frame. -* @param[out] values Gravity vector in body frame, length 3, (gee) -* @param[out] accuracy Accuracy of the measurment, 0 is least accurate, - while 3 is most accurate. -* @param[out] timestamp The timestamp for this sensor. Derived from the - timestamp sent to inv_build_accel(). -*/ -void inv_get_sensor_type_gravity_float(float *values, int *accuracy, - inv_time_t * timestamp) -{ - struct inv_single_sensor_t *pa = &dl_out.sc.accel; - - if (values) { - long lgravity[3]; - (void)inv_get_gravity(lgravity); - values[0] = (float) lgravity[0] / (1L << 16); - values[1] = (float) lgravity[1] / (1L << 16); - values[2] = (float) lgravity[2] / (1L << 16); - } - if (accuracy) - *accuracy = pa->accuracy; - if (timestamp) - *timestamp = pa->timestamp; -} - -/** -* This corresponds to Sensor.TYPE_ROTATION_VECTOR. -* The rotation vector represents the orientation of the device as a combination -* of an angle and an axis, in which the device has rotated through an angle @f$\theta@f$ -* around an axis {x, y, z}. <br> -* The three elements of the rotation vector are -* {x*sin(@f$\theta@f$/2), y*sin(@f$\theta@f$/2), z*sin(@f$\theta@f$/2)}, such that the magnitude of the rotation -* vector is equal to sin(@f$\theta@f$/2), and the direction of the rotation vector is -* equal to the direction of the axis of rotation. -* -* The three elements of the rotation vector are equal to the last three components of a unit quaternion -* {x*sin(@f$\theta@f$/2), y*sin(@f$\theta@f$/2), z*sin(@f$\theta@f$/2)>. -* -* Elements of the rotation vector are unitless. The x,y and z axis are defined in the same way as the acceleration sensor. -* The reference coordinate system is defined as a direct orthonormal basis, where: - - -X is defined as the vector product Y.Z (It is tangential to the ground at the device's current location and roughly points East). - -Y is tangential to the ground at the device's current location and points towards the magnetic North Pole. - -Z points towards the sky and is perpendicular to the ground. -* @param[out] values -* @param[out] accuracy Accuracy 0 to 3, 3 = most accurate -* @param[out] timestamp Timestamp. In (ns) for Android. -*/ -void inv_get_sensor_type_rotation_vector_float(float *values, int *accuracy, - inv_time_t * timestamp) -{ - if (accuracy) - *accuracy = dl_out.quat_accuracy; - if (timestamp) - *timestamp = dl_out.quat_timestamp; - if (values) { - if (dl_out.quat[0] >= 0) { - values[0] = dl_out.quat[1] * INV_TWO_POWER_NEG_30; - values[1] = dl_out.quat[2] * INV_TWO_POWER_NEG_30; - values[2] = dl_out.quat[3] * INV_TWO_POWER_NEG_30; - } else { - values[0] = -dl_out.quat[1] * INV_TWO_POWER_NEG_30; - values[1] = -dl_out.quat[2] * INV_TWO_POWER_NEG_30; - values[2] = -dl_out.quat[3] * INV_TWO_POWER_NEG_30; - } - } -} - -/** Main callback to generate HAL outputs. Typically not called by library users. */ -inv_error_t inv_generate_datalogger_outputs(struct inv_sensor_cal_t *sensor_cal) -{ - memcpy(&dl_out.sc, sensor_cal, sizeof(struct inv_sensor_cal_t)); - inv_get_quaternion_set(dl_out.quat, &dl_out.quat_accuracy, - &dl_out.quat_timestamp); - return INV_SUCCESS; -} - -/** Turns off generation of HAL outputs. */ -inv_error_t inv_stop_datalogger_outputs(void) -{ - return inv_unregister_data_cb(inv_generate_datalogger_outputs); -} - -/** Turns on generation of HAL outputs. This should be called after inv_stop_dl_outputs() -* to turn generation of HAL outputs back on. It is automatically called by inv_enable_dl_outputs().*/ -inv_error_t inv_start_datalogger_outputs(void) -{ - return inv_register_data_cb(inv_generate_datalogger_outputs, - INV_PRIORITY_HAL_OUTPUTS, INV_GYRO_NEW | INV_ACCEL_NEW | INV_MAG_NEW); -} - -/** Initializes hal outputs class. This is called automatically by the -* enable function. It may be called any time the feature is enabled, but -* is typically not needed to be called by outside callers. -*/ -inv_error_t inv_init_datalogger_outputs(void) -{ - memset(&dl_out, 0, sizeof(dl_out)); - return INV_SUCCESS; -} - -/** Turns on creation and storage of HAL type results. -*/ -inv_error_t inv_enable_datalogger_outputs(void) -{ - inv_error_t result; - result = inv_init_datalogger_outputs(); - if (result) - return result; - return inv_register_mpl_start_notification(inv_start_datalogger_outputs); -} - -/** Turns off creation and storage of HAL type results. -*/ -inv_error_t inv_disable_datalogger_outputs(void) -{ - inv_stop_datalogger_outputs(); - return inv_unregister_mpl_start_notification(inv_start_datalogger_outputs); -} - -/** - * @} - */ diff --git a/65xx/libsensors_iio/software/simple_apps/playback/linux/datalogger_outputs.h b/65xx/libsensors_iio/software/simple_apps/playback/linux/datalogger_outputs.h deleted file mode 100755 index 0e50faf..0000000 --- a/65xx/libsensors_iio/software/simple_apps/playback/linux/datalogger_outputs.h +++ /dev/null @@ -1,61 +0,0 @@ -/** - * @defgroup HAL_Outputs - * @brief Motion Library - HAL Outputs - * Sets up common outputs for HAL - * - * @{ - * @file datalogger_outputs.h - * @brief Windows 8 HAL outputs. - */ - -#ifndef _DATALOGGER_OUTPUTS_H_ -#define _DATALOGGER_OUTPUTS_H_ - -#include "mltypes.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* calibrated data */ -void inv_get_sensor_type_temperature_float(float *value, - inv_time_t *timestamp); -void inv_get_sensor_type_gyro_float(float *values, int8_t *accuracy, - inv_time_t *timestamp); -void inv_get_sensor_type_accel_float(float *values, int8_t *accuracy, - inv_time_t *timestamp); -void inv_get_sensor_type_compass_float(float *mag_north, float *true_north, - float *values, int8_t *accuracy, inv_time_t *timestamp); -void inv_get_sensor_type_quat_float(float *values, int *accuracy, - inv_time_t *timestamp); -void inv_get_sensor_type_gravity_float(float *values, int *accuracy, - inv_time_t * timestamp); -void inv_get_sensor_type_rotation_vector_float(float *values, int *accuracy, - inv_time_t * timestamp); - -/* uncalibrated data */ -void inv_get_sensor_type_gyro_raw_short(short *values, - inv_time_t *timestamp); -void inv_get_sensor_type_gyro_raw_body_float(float *values, - inv_time_t *timestamp); -void inv_get_sensor_type_accel_raw_short(short *values, - inv_time_t *timestamp); -void inv_get_sensor_type_compass_raw_short(short *values, - inv_time_t *timestamp); - -/* enabler/disabler APIs */ -inv_error_t inv_enable_datalogger_outputs(void); -inv_error_t inv_disable_datalogger_outputs(void); -inv_error_t inv_init_datalogger_outputs(void); -inv_error_t inv_start_datalogger_outputs(void); -inv_error_t inv_stop_datalogger_outputs(void); - -#ifdef __cplusplus -} -#endif - -#endif /* #ifndef _DATALOGGER_OUTPUTS_H_ */ - -/** - * @} - */ diff --git a/65xx/libsensors_iio/software/simple_apps/playback/linux/main.c b/65xx/libsensors_iio/software/simple_apps/playback/linux/main.c deleted file mode 100755 index 74272b0..0000000 --- a/65xx/libsensors_iio/software/simple_apps/playback/linux/main.c +++ /dev/null @@ -1,897 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 InvenSense Corporation, All Rights Reserved. - ******************************************************************************/ - -/******************************************************************************* - * - * $Id: main.c 6146 2011-10-04 18:33:51Z jcalizo $ - * - ******************************************************************************/ - -#include <stdio.h> -#include <stdlib.h> -#include <time.h> - -#include "invensense.h" -#include "invensense_adv.h" -#include "and_constructor.h" -#include "ml_math_func.h" -#include "datalogger_outputs.h" - -#include "console_helper.h" - -#include "mlos.h" -#include "mlsl.h" - -#include "testsupport.h" - -#include "log.h" -#undef MPL_LOG_TAG -#define MPL_LOG_TAG "MPL-playback" - -/* - Defines & Macros -*/ -#define UNPACK_3ELM_ARRAY(a) (a)[0], (a)[1], (a)[2] -#define UNPACK_4ELM_ARRAY(a) UNPACK_3ELM_ARRAY(a), (a)[3] -#define COMPONENT_NAME_MAX_LEN (30) -#define DEF_NAME(x) (#x) - -#define PRINT_ON_CONSOLE(...) \ - if (print_on_screen) \ - printf(__VA_ARGS__) -#define PRINT_ON_FILE(...) \ - if(stream_file) \ - fprintf(stream_file, __VA_ARGS__) - -#define PRINT(...) \ - PRINT_ON_CONSOLE(__VA_ARGS__); \ - PRINT_ON_FILE(__VA_ARGS__) -#define PRINT_FLOAT(width, prec, data) \ - PRINT_ON_CONSOLE("%+*.*f", \ - width, prec, data); \ - PRINT_ON_FILE("%+f", data) -#define PRINT_INT(width, data) \ - PRINT_ON_CONSOLE("%+*d", width, data); \ - PRINT_ON_FILE("%+d", data); -#define PRINT_LONG(width, data) \ - PRINT_ON_CONSOLE("%+*ld", width, data); \ - PRINT_ON_FILE("%+ld", data); - -#define PRINT_3ELM_ARRAY_FLOAT(w, p, data) \ - PRINT_FLOAT(w, p, data[0]); \ - PRINT(", "); \ - PRINT_FLOAT(w, p, data[1]); \ - PRINT(", "); \ - PRINT_FLOAT(w, p, data[2]); \ - PRINT(", "); -#define PRINT_4ELM_ARRAY_FLOAT(w, p, data) \ - PRINT_3ELM_ARRAY_FLOAT(w, p, data); \ - PRINT_FLOAT(w, p, data[3]); \ - PRINT(", "); - -#define PRINT_3ELM_ARRAY_LONG(w, data) \ - PRINT_LONG(w, data[0]); \ - PRINT(", "); \ - PRINT_LONG(w, data[1]); \ - PRINT(", "); \ - PRINT_LONG(w, data[2]); \ - PRINT(", "); -#define PRINT_4ELM_ARRAY_LONG(w, data) \ - PRINT_3ELM_ARRAY_LONG(w, data); \ - PRINT_LONG(w, data[3]); \ - PRINT(", "); - -#define PRINT_3ELM_ARRAY_INT(w, data) \ - PRINT_INT(w, data[0]); \ - PRINT(", "); \ - PRINT_INT(w, data[1]); \ - PRINT(", "); \ - PRINT_INT(w, data[2]); \ - PRINT(", "); -#define PRINT_4ELM_ARRAY_INT(w, data) \ - PRINT_3ELM_ARRAY_LONG(w, data); \ - PRINT_INT(w, data[3]); \ - PRINT(", "); - - -#define CASE_NAME(CODE) \ - case CODE: \ - return #CODE - -#define CALL_CHECK_N_PRINT(f) { \ - MPL_LOGI("\n"); \ - MPL_LOGI("################################################\n"); \ - MPL_LOGI("# %s\n", #f); \ - MPL_LOGI("################################################\n"); \ - MPL_LOGI("\n"); \ - CALL_N_CHECK(f); \ -} - -/* - Types -*/ -/* A badly named enum type to track state of user input for tracker menu. */ -typedef enum { - STATE_SELECT_A_TRACKER, - STATE_SET_TRACKER_STATE, /* I'm running out of ideas here. */ - STATE_COUNT -} user_state_t; - -/* bias trackers. */ -typedef enum { - BIAS_FROM_NO_MOTION, - FAST_NO_MOTION, - BIAS_FROM_GRAVITY, - BIAS_FROM_TEMPERATURE, - BIAS_FROM_LPF, - DEAD_ZONE, - NUM_TRACKERS -} bias_t; - -enum comp_ids { - TIME = 0, - CALIBRATED_GYROSCOPE, - CALIBRATED_ACCELEROMETER, - CALIBRATED_COMPASS, - RAW_GYROSCOPE, - RAW_GYROSCOPE_BODY, - RAW_ACCELEROMETER, - RAW_COMPASS, - QUATERNION_9_AXIS, - QUATERNION_6_AXIS, - GRAVITY, - HEADING, - COMPASS_BIAS_ERROR, - COMPASS_STATE, - TEMPERATURE, - TEMP_COMP_SLOPE, - LINEAR_ACCELERATION, - ROTATION_VECTOR, - MOTION_STATE, - - NUM_OF_IDS -}; - -struct component_list { - char name[COMPONENT_NAME_MAX_LEN]; - int order; -}; - -/* - Globals -*/ -static int print_on_screen = true; -static int one_time_print = true; -static FILE *stream_file = NULL; -static unsigned long sample_count = 0; -static int enabled_9x = true; - -signed char g_gyro_orientation[9] = {1, 0, 0, 0, 1, 0, 0, 0, 1}; -signed char g_accel_orientation[9] = {1, 0, 0, 0, 1, 0, 0, 0, 1}; -signed char g_compass_orientation[9] = {-1, 0, 0, 0, 1, 0, 0, 0, -1}; - -#ifdef WIN32 -static double pc_freq; -static __int64 counter_start; -#else -static inv_time_t counter_start; -#endif - -struct component_list components[NUM_OF_IDS]; - -/* - Prototypes -*/ -void print_tracker_states(bias_t tracker); - -/* - Callbacks -*/ -/*--- motion / no motion callback function ---*/ -void check_motion_event(void) -{ - long msg = inv_get_message_level_0(1); - if (msg) { - if (msg & INV_MSG_MOTION_EVENT) { - MPL_LOGI("################################################\n"); - MPL_LOGI("## Motion\n"); - MPL_LOGI("################################################\n"); - } - if (msg & INV_MSG_NO_MOTION_EVENT) { - MPL_LOGI("################################################\n"); - MPL_LOGI("## No Motion\n"); - MPL_LOGI("################################################\n"); - } - } -} - -/* number to string coversion */ -char *compass_state_name(char* out, int state) -{ - switch(state) { - CASE_NAME(SF_NORMAL); - CASE_NAME(SF_DISTURBANCE); - CASE_NAME(SF_FAST_SETTLE); - CASE_NAME(SF_SLOW_SETTLE); - CASE_NAME(SF_STARTUP_SETTLE); - CASE_NAME(SF_UNCALIBRATED); - } - - #define UNKNOWN_ERROR_CODE 1234 - return ERROR_NAME(UNKNOWN_ERROR_CODE); -} - -/* component ID to name convertion */ -char *component_name(char *out, int comp_id) -{ - switch (comp_id) { - CASE_NAME(TIME); - CASE_NAME(CALIBRATED_GYROSCOPE); - CASE_NAME(CALIBRATED_ACCELEROMETER); - CASE_NAME(CALIBRATED_COMPASS); - CASE_NAME(RAW_GYROSCOPE); - CASE_NAME(RAW_GYROSCOPE_BODY); - CASE_NAME(RAW_ACCELEROMETER); - CASE_NAME(RAW_COMPASS); - CASE_NAME(QUATERNION_9_AXIS); - CASE_NAME(QUATERNION_6_AXIS); - CASE_NAME(GRAVITY); - CASE_NAME(HEADING); - CASE_NAME(COMPASS_BIAS_ERROR); - CASE_NAME(COMPASS_STATE); - CASE_NAME(TEMPERATURE); - CASE_NAME(TEMP_COMP_SLOPE); - CASE_NAME(LINEAR_ACCELERATION); - CASE_NAME(ROTATION_VECTOR); - CASE_NAME(MOTION_STATE); - } - - return "UNKNOWN"; -} - - -#ifdef WIN32 - -/* - Karthik Implementation. - http://stackoverflow.com/questions/1739259/how-to-use-queryperformancecounter -*/ -double get_counter(__int64 *counter_start, double *pc_freq) -{ - LARGE_INTEGER li; - double x; - QueryPerformanceCounter(&li); - x = (double) (li.QuadPart - (*counter_start)); - x = x / (*pc_freq); - return(x); -} - -void start_counter(double *pc_freq, __int64 *counter_start) -{ - LARGE_INTEGER li; - double x; - if(!QueryPerformanceFrequency(&li)) - printf("QueryPerformanceFrequency failed!\n"); - x = (double)(li.QuadPart); - *pc_freq = x / 1000.0; - QueryPerformanceCounter(&li); - *counter_start = li.QuadPart; -} - -#else - -unsigned long get_counter(void) -{ - return (inv_get_tick_count() - counter_start); -} - -void start_counter(void) -{ - counter_start = inv_get_tick_count(); -} - -#endif - -/* processed data callback */ -void fifo_callback(void) -{ - int print_on_screen_saved = print_on_screen; - int i; - - /* one_time_print causes the data labels to be printed on screen */ - if (one_time_print) { - print_on_screen = true; - } - for (i = 0; i < NUM_OF_IDS; i++) { - if (components[TIME].order == i) { - if (one_time_print) { - PRINT("TIME,"); - } else { -#ifdef WIN32 - double time_ms; - static int first_value = 0; - if(first_value == 0){ - first_value = 1; - start_counter(&pc_freq, &counter_start); - time_ms = 0; - } else { - time_ms = get_counter(&counter_start, &pc_freq); - } - PRINT("%6.0f, ", time_ms); -#else - unsigned long time_ms; - static int first_value = 0; - if(first_value == 0){ - first_value = 1; - start_counter(); - time_ms = 0; - } else { - time_ms = get_counter(); - } - PRINT("%6ld, ", time_ms); -#endif - } - } else if (components[CALIBRATED_GYROSCOPE].order == i) { - if (one_time_print) { - PRINT("CALIBRATED_GYROSCOPE_X," - "CALIBRATED_GYROSCOPE_Y," - "CALIBRATED_GYROSCOPE_Z,"); - /* - PRINT("CALIBRATED_GYROSCOPE_X_AVERAGE," - "CALIBRATED_GYROSCOPE_Y_AVERAGE," - "CALIBRATED_GYROSCOPE_Z_AVERAGE,"); - */ - } else { - /* - #define window 20 - static int cnt = 0; - static int valid = 0; - static float gyro_keep[window][3]; - int kk, jj; - float avg[3]; - */ - float gyro[3]; - inv_get_gyro_float(gyro); - PRINT_3ELM_ARRAY_FLOAT(10, 5, gyro); - PRINT(" "); - /* - memcpy(gyro_keep[cnt], gyro, sizeof(float) * 3); - cnt= (cnt + 1) % window; - if (cnt == window - 1) - valid = 1; - if (valid) { - memset(avg, 0, sizeof(float) * 3); - jj = (cnt + 1) % window; - for (kk = 0; kk < window; kk++) { - avg[0] += gyro_keep[jj][0] / window; - avg[1] += gyro_keep[jj][1] / window; - avg[2] += gyro_keep[jj][2] / window; - jj = (jj + 1) % window; - } - PRINT("%+f, %+f, %+f, ", - UNPACK_3ELM_ARRAY(avg)); - PRINT_3ELM_ARRAY_FLOAT(10, 5, avg); - PRINT(" "); - } - */ - } - } else if (components[CALIBRATED_ACCELEROMETER].order == i) { - if (one_time_print) { - PRINT("CALIBRATED_ACCELEROMETER_X," - "CALIBRATED_ACCELEROMETER_Y," - "CALIBRATED_ACCELEROMETER_Z,"); - } else { - float accel[3]; - inv_get_accel_float(accel); - PRINT_3ELM_ARRAY_FLOAT(10, 5, accel); - PRINT(" "); - } - } else if (components[CALIBRATED_COMPASS].order == i) { - if (one_time_print) { - PRINT("CALIBRATED_COMPASS_X," - "CALIBRATED_COMPASS_Y," - "CALIBRATED_COMPASS_Z,"); - } else { - long lcompass[3]; - float compass[3]; - inv_get_compass_set(lcompass, 0, 0); - compass[0] = inv_q16_to_float(lcompass[0]); - compass[1] = inv_q16_to_float(lcompass[1]); - compass[2] = inv_q16_to_float(lcompass[2]); - PRINT_3ELM_ARRAY_FLOAT(10, 5, compass); - PRINT(" "); - } - } else if (components[RAW_GYROSCOPE].order == i) { - if (one_time_print) { - PRINT("RAW_GYROSCOPE_X," - "RAW_GYROSCOPE_Y," - "RAW_GYROSCOPE_Z,"); - } else { - short raw[3]; - inv_get_sensor_type_gyro_raw_short(raw, NULL); - PRINT_3ELM_ARRAY_INT(6, raw); - PRINT(" "); - } - } else if (components[RAW_GYROSCOPE_BODY].order == i) { - if (one_time_print) { - PRINT("RAW_GYROSCOPE_BODY_X," - "RAW_GYROSCOPE_BODY_Y," - "RAW_GYROSCOPE_BODY_Z,"); - } else { - float raw_body[3]; - inv_get_sensor_type_gyro_raw_body_float(raw_body, NULL); - PRINT_3ELM_ARRAY_FLOAT(10, 5, raw_body); - PRINT(" "); - } - } else if (components[RAW_ACCELEROMETER].order == i) { - if (one_time_print) { - PRINT("RAW_ACCELEROMETER_X," - "RAW_ACCELEROMETER_Y," - "RAW_ACCELEROMETER_Z,"); - } else { - short raw[3]; - inv_get_sensor_type_accel_raw_short(raw, NULL); - PRINT_3ELM_ARRAY_INT(6, raw); - PRINT(" "); - } - } else if (components[RAW_COMPASS].order == i) { - if (one_time_print) { - PRINT("RAW_COMPASS_X," - "RAW_COMPASS_Y," - "RAW_COMPASS_Z,"); - } else { - short raw[3]; - inv_get_sensor_type_compass_raw_short(raw, NULL); - PRINT_3ELM_ARRAY_INT(6, raw); - PRINT(" "); - } - } else if (components[QUATERNION_9_AXIS].order == i) { - if (one_time_print) { - PRINT("QUATERNION_9_AXIS_X," - "QUATERNION_9_AXIS_Y," - "QUATERNION_9_AXIS_Z," - "QUATERNION_9_AXIS_w,"); - } else { - float quat[4]; - inv_get_quaternion_float(quat); - PRINT_4ELM_ARRAY_FLOAT(10, 5, quat); - PRINT(" "); - } - } else if (components[QUATERNION_6_AXIS].order == i) { - if (one_time_print) { - PRINT("QUATERNION_6_AXIS_X," - "QUATERNION_6_AXIS_Y," - "QUATERNION_6_AXIS_Z," - "QUATERNION_6_AXIS_w,"); - } else { - float quat[4]; - long temp[4]; - int j; - inv_get_6axis_quaternion(temp); - for (j = 0; j < 4; j++) - quat[j] = (float)temp[j] / (1 << 30); - PRINT_4ELM_ARRAY_FLOAT(10, 5, quat); - PRINT(" "); - } - } else if (components[HEADING].order == i) { - if (one_time_print) { - PRINT("HEADING,"); - } else { - float heading[1]; - inv_get_sensor_type_compass_float(heading, NULL, NULL, - NULL, NULL); - PRINT_FLOAT(10, 5, heading[0]); - PRINT(", "); - } - } else if (components[GRAVITY].order == i) { - if (one_time_print) { - PRINT("GRAVITY_X," - "GRAVITY_Y," - "GRAVITY_Z,"); - } else { - float gravity[3]; - inv_get_sensor_type_gravity_float(gravity, NULL, NULL); - PRINT_3ELM_ARRAY_FLOAT(10, 5, gravity); - PRINT(" "); - } - } else if (components[COMPASS_STATE].order == i) { - if (one_time_print) { - PRINT("COMPASS_STATE," - "GOT_COARSE_HEADING,"); - } else { - PRINT_INT(1, inv_get_compass_state()); - PRINT(", "); - PRINT_INT(1, inv_got_compass_bias()); - PRINT(", "); - } - } else if (components[COMPASS_BIAS_ERROR].order == i) { - if (one_time_print) { - PRINT("COMPASS_BIAS_ERROR_X," - "COMPASS_BIAS_ERROR_Y," - "COMPASS_BIAS_ERROR_Z,"); - } else { - long mbe[3]; - inv_get_compass_bias_error(mbe); - PRINT_3ELM_ARRAY_LONG(6, mbe); - } - } else if (components[TEMPERATURE].order == i) { - if (one_time_print) { - PRINT("TEMPERATURE,"); - } else { - float temp; - inv_get_sensor_type_temperature_float(&temp, NULL); - PRINT_FLOAT(8, 4, temp); - PRINT(", "); - } - } else if (components[TEMP_COMP_SLOPE].order == i) { - if (one_time_print) { - PRINT("TEMP_COMP_SLOPE_X," - "TEMP_COMP_SLOPE_Y," - "TEMP_COMP_SLOPE_Z,"); - } else { - long temp_slope[3]; - float temp_slope_f[3]; - (void)inv_get_gyro_ts(temp_slope); - temp_slope_f[0] = inv_q16_to_float(temp_slope[0]); - temp_slope_f[1] = inv_q16_to_float(temp_slope[1]); - temp_slope_f[2] = inv_q16_to_float(temp_slope[2]); - PRINT_3ELM_ARRAY_FLOAT(10, 5, temp_slope_f); - PRINT(" "); - } - } else if (components[LINEAR_ACCELERATION].order == i) { - if (one_time_print) { - PRINT("LINEAR_ACCELERATION_X," - "LINEAR_ACCELERATION_Y," - "LINEAR_ACCELERATION_Z,"); - } else { - float lin_acc[3]; - inv_get_linear_accel_float(lin_acc); - PRINT_3ELM_ARRAY_FLOAT(10, 5, lin_acc); - PRINT(" "); - } - } else if (components[ROTATION_VECTOR].order == i) { - if (one_time_print) { - PRINT("ROTATION_VECTOR_X," - "ROTATION_VECTOR_Y," - "ROTATION_VECTOR_Z,"); - } else { - float rot_vec[3]; - inv_get_sensor_type_rotation_vector_float(rot_vec, NULL, NULL); - PRINT_3ELM_ARRAY_FLOAT(10, 5, rot_vec); - PRINT(" "); - } - } else if (components[MOTION_STATE].order == i) { - if (one_time_print) { - PRINT("MOTION_STATE,"); - } else { - unsigned int counter; - PRINT_INT(1, inv_get_motion_state(&counter)); - PRINT(", "); - } - } else { - ; - } - } - PRINT("\n"); - - if (one_time_print) { - one_time_print = false; - print_on_screen = print_on_screen_saved; - } - sample_count++; -} - -void print_help(char *exename) -{ - printf( - "\n" - "Usage:\n" - "\t%s [options]\n" - "\n" - "Options:\n" - " [-h|--help] = shows this help\n" - " [-o|--output PREFIX] = to dump data on csv file whose file\n" - " prefix is specified by the parameter,\n" - " e.g. '<PREFIX>-<timestamp>.csv'\n" - " [-i|--input NAME] = to read the provided playback.bin file\n" - " [-c|--comp C] = enable the following components in the\n" - " given order:\n" - " t = TIME\n" - " T = TEMPERATURE,\n" - " s = TEMP_COMP_SLOPE,\n" - " G = CALIBRATED_GYROSCOPE,\n" - " A = CALIBRATED_ACCELEROMETER,\n" - " C = CALIBRATED_COMPASS,\n" - " g = RAW_GYROSCOPE,\n" - " b = RAW_GYROSCOPE_BODY,\n" - " a = RAW_ACCELEROMETER,\n" - " c = RAW_COMPASS,\n" - " Q = QUATERNION_9_AXIS,\n" - " 6 = QUATERNION_6_AXIS,\n" - " V = GRAVITY,\n" - " L = LINEAR_ACCELERATION,\n" - " R = ROTATION_VECTOR,\n" - " H = HEADING,\n" - " E = COMPASS_BIAS_ERROR,\n" - " S = COMPASS_STATE,\n" - " M = MOTION_STATE.\n" - "\n" - "Note on compass state values:\n" - " SF_NORMAL = 0\n" - " SF_DISTURBANCE = 1\n" - " SF_FAST_SETTLE = 2\n" - " SF_SLOW_SETTLE = 3\n" - " SF_STARTUP_SETTLE = 4\n" - " SF_UNCALIBRATED = 5\n" - "\n", - exename); -} - -char *output_filename_datetimestamp(char *out) -{ - time_t t; - struct tm *now; - t = time(NULL); - now = localtime(&t); - - sprintf(out, - "%02d%02d%02d_%02d%02d%02d.csv", - now->tm_year - 100, now->tm_mon + 1, now->tm_mday, - now->tm_hour, now->tm_min, now->tm_sec); - return out; -} - -int components_parser(char pname[], char requested[], int length) -{ - int j; - - /* forcibly disable all */ - for (j = 0; j < NUM_OF_IDS; j++) - components[j].order = -1; - - /* parse each character one a time */ - for (j = 0; j < length; j++) { - switch (requested[j]) { - case 'T': - components[TEMPERATURE].order = j; - break; - case 'G': - components[CALIBRATED_GYROSCOPE].order = j; - break; - case 'A': - components[CALIBRATED_ACCELEROMETER].order = j; - break; - case 'g': - components[RAW_GYROSCOPE].order = j; - break; - case 'b': - components[RAW_GYROSCOPE_BODY].order = j; - break; - case 'a': - components[RAW_ACCELEROMETER].order = j; - break; - case 'Q': - components[QUATERNION_9_AXIS].order = j; - break; - case '6': - components[QUATERNION_6_AXIS].order = j; - break; - case 'V': - components[GRAVITY].order = j; - break; - case 'L': - components[LINEAR_ACCELERATION].order = j; - break; - case 'R': - components[ROTATION_VECTOR].order = j; - break; - - /* these components don't need to be enabled */ - case 't': - components[TIME].order = j; - break; - case 'C': - components[CALIBRATED_COMPASS].order = j; - break; - case 'c': - components[RAW_COMPASS].order = j; - break; - case 'H': - components[HEADING].order = j; - break; - case 'E': - components[COMPASS_BIAS_ERROR].order = j; - break; - case 'S': - components[COMPASS_STATE].order = j; - break; - case 'M': - components[MOTION_STATE].order = j; - break; - - default: - MPL_LOGI("Error : unrecognized component '%c'\n", - requested[j]); - print_help(pname); - return 1; - break; - } - } - return 0; -} - -int main(int argc, char *argv[]) -{ -#ifndef INV_PLAYBACK_DBG - MPL_LOGI("Error : this application was not compiled with the " - "INV_PLAYBACK_DBG define and cannot work.\n"); - MPL_LOGI(" Recompile the libmllite libraries with #define " - "INV_PLAYBACK_DBG uncommented\n"); - MPL_LOGI(" in 'software/core/mllite/data_builder.h'.\n"); - return INV_ERROR; -#endif - - inv_time_t start_time; - double total_time; - char req_component_list[50] = "tQGACH"; - char input_filename[101] = "/data/playback.bin"; - int i = 0; - char *ver_str; - /* flags */ - int use_nm_detection = true; - - /* make sure there is no buffering of the print messages */ - setvbuf(stdout, NULL, _IONBF, 0); - - /* forcibly disable all and populate the names */ - for (i = 0; i < NUM_OF_IDS; i++) { - char str_tmp[COMPONENT_NAME_MAX_LEN]; - strcpy(components[i].name, component_name(str_tmp, i)); - components[i].order = -1; - } - - CALL_N_CHECK( inv_get_version(&ver_str) ); - MPL_LOGI("\n"); - MPL_LOGI("%s\n", ver_str); - MPL_LOGI("\n"); - - for (i = 1; i < argc; i++) { - if(strcmp(argv[i], "-h") == 0 - || strcmp(argv[i], "--help") == 0) { - print_help(argv[0]); - return INV_SUCCESS; - - } else if(strcmp(argv[i], "-o") == 0 - || strcmp(argv[i], "--output") == 0) { - char output_filename[200]; - char end[50] = ""; - i++; - - snprintf(output_filename, sizeof(output_filename), "%s-%s", - argv[i], output_filename_datetimestamp(end)); - stream_file = fopen(output_filename, "w+"); - if (!stream_file) { - printf("Unable to open file '%s'\n", output_filename); - return INV_ERROR; - } - MPL_LOGI("-- Output on file '%s'\n", output_filename); - - } else if(strcmp(argv[i], "-i") == 0 - || strcmp(argv[i], "--input") == 0) { - i++; - strncpy(input_filename, argv[i], sizeof(input_filename)); - MPL_LOGI("-- Playing back file '%s'\n", input_filename); - - } else if(strcmp(argv[i], "-n") == 0 - || strcmp(argv[i], "--nm") == 0) { - i++; - if (!strcmp(argv[i], "none")) { - use_nm_detection = 0; - } else if (!strcmp(argv[i], "regular")) { - use_nm_detection = 1; - } else if (!strcmp(argv[i], "fast")) { - use_nm_detection = 2; - } else { - MPL_LOGI("Error : unrecognized no-motion type '%s'\n", - argv[i]); - return INV_ERROR_INVALID_PARAMETER; - } - MPL_LOGI("-- No motion algorithm : '%s', %d\n", - argv[i], use_nm_detection); - - } else if(strcmp(argv[i], "-9") == 0 - || strcmp(argv[i], "--nine") == 0) { - MPL_LOGI("-- using 9 axis sensor fusion by default\n"); - enabled_9x = true; - - } else if(strcmp(argv[i], "-c") == 0 - || strcmp(argv[i], "--comp") == 0) { - i++; - strcpy(req_component_list, argv[i]); - - } else { - MPL_LOGI("Unrecognized command-line parameter '%s'\n", argv[i]); - return INV_ERROR_INVALID_PARAMETER; - } - } - - CALL_CHECK_N_RETURN_ERROR( - components_parser( - argv[0], - req_component_list, strlen(req_component_list))); - - /* set up callbacks */ - CALL_N_CHECK(inv_set_fifo_processed_callback(fifo_callback)); - - /* algorithm init */ - CALL_N_CHECK(inv_enable_quaternion()); - if (use_nm_detection == 1) { - CALL_N_CHECK(inv_enable_motion_no_motion()); - } else if (use_nm_detection == 2) { - CALL_N_CHECK(inv_enable_fast_nomot()); - } - CALL_N_CHECK(inv_enable_gyro_tc()); - CALL_N_CHECK(inv_enable_in_use_auto_calibration()); - CALL_N_CHECK(inv_enable_no_gyro_fusion()); - CALL_N_CHECK(inv_enable_results_holder()); - if (enabled_9x) { - CALL_N_CHECK(inv_enable_heading_from_gyro()); - CALL_N_CHECK(inv_enable_compass_bias_w_gyro()); - CALL_N_CHECK(inv_enable_vector_compass_cal()); - CALL_N_CHECK(inv_enable_9x_sensor_fusion()); - } - - CALL_CHECK_N_RETURN_ERROR(inv_enable_datalogger_outputs()); - CALL_CHECK_N_RETURN_ERROR(inv_constructor_start()); - - /* load persistent data */ - { - FILE *fc = fopen("invcal.bin", "rb"); - if (fc != NULL) { - size_t sz, rd; - inv_error_t result = 0; - // Read amount of memory we need to hold data - rd = fread(&sz, sizeof(size_t), 1, fc); - if (rd == sizeof(size_t)) { - unsigned char *cal_data = (unsigned char *)malloc(sizeof(sz)); - unsigned char *cal_ptr; - cal_ptr = cal_data; - *(size_t *)cal_ptr = sz; - cal_ptr += sizeof(sz); - /* read rest of the file */ - fread(cal_ptr, sz - sizeof(size_t), 1, fc); - //result = inv_load_mpl_states(cal_data, sz); - if (result) { - MPL_LOGE("Cal Load error\n"); - } - MPL_LOGI("inv_load_mpl_states()\n"); - free(cal_data); - } else { - MPL_LOGE("Cal Load error with size read\n"); - } - fclose(fc); - } - } - - sample_count = 0; - start_time = inv_get_tick_count(); - - /* playback data that was recorded */ - inv_set_playback_filename(input_filename, strlen(input_filename) + 1); - inv_set_debug_mode(RD_PLAYBACK); - CALL_N_CHECK(inv_playback()); - - total_time = (1.0 * inv_get_tick_count() - start_time) / 1000; - if (total_time > 0) { - MPL_LOGI("\nPlayed back %ld samples in %.2f s (%.1f Hz)\n", - sample_count, total_time , 1.0 * sample_count / total_time); - } - - if (stream_file) - fclose(stream_file); - - return INV_SUCCESS; -} - - diff --git a/65xx/libsensors_iio/software/simple_apps/self_test/build/android/inv_self_test-shared b/65xx/libsensors_iio/software/simple_apps/self_test/build/android/inv_self_test-shared Binary files differdeleted file mode 100755 index 4d785f8..0000000 --- a/65xx/libsensors_iio/software/simple_apps/self_test/build/android/inv_self_test-shared +++ /dev/null diff --git a/65xx/libsensors_iio/software/simple_apps/self_test/build/android/shared.mk b/65xx/libsensors_iio/software/simple_apps/self_test/build/android/shared.mk deleted file mode 100755 index ed5fbf6..0000000 --- a/65xx/libsensors_iio/software/simple_apps/self_test/build/android/shared.mk +++ /dev/null @@ -1,98 +0,0 @@ -EXEC = inv_self_test$(SHARED_APP_SUFFIX) - -MK_NAME = $(notdir $(CURDIR)/$(firstword $(MAKEFILE_LIST))) - -CROSS ?= $(ANDROID_ROOT)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- -COMP ?= $(CROSS)gcc -LINK ?= $(CROSS)gcc - -OBJFOLDER = $(CURDIR)/obj - -INV_ROOT = ../../../../.. -APP_DIR = $(CURDIR)/../.. -MLLITE_DIR = $(INV_ROOT)/software/core/mllite -COMMON_DIR = $(INV_ROOT)/software/simple_apps/common -MPL_DIR = $(INV_ROOT)/software/core/mpl -HAL_DIR = $(INV_ROOT)/software/core/HAL - -include $(INV_ROOT)/software/build/android/common.mk - -CFLAGS += $(CMDLINE_CFLAGS) -CFLAGS += $(ANDROID_COMPILE) -CFLAGS += -Wall -CFLAGS += -fpic -CFLAGS += -nostdlib -CFLAGS += -DNDEBUG -CFLAGS += -D_REENTRANT -CFLAGS += -DLINUX -CFLAGS += -DANDROID -CFLAGS += -mthumb-interwork -CFLAGS += -fno-exceptions -CFLAGS += -ffunction-sections -CFLAGS += -funwind-tables -CFLAGS += -fstack-protector -CFLAGS += -fno-short-enums -CFLAGS += -fmessage-length=0 -CFLAGS += -I$(MLLITE_DIR) -CFLAGS += -I$(MPL_DIR) -CFLAGS += -I$(COMMON_DIR) -CFLAGS += -I$(HAL_DIR)/include -CFLAGS += $(INV_INCLUDES) -CFLAGS += $(INV_DEFINES) - -LLINK = -lc -LLINK += -lm -LLINK += -lutils -LLINK += -lcutils -LLINK += -lgcc -LLINK += -ldl -LLINK += -lstdc++ -LLINK += -llog -LLINK += -lz - -LFLAGS += $(CMDLINE_LFLAGS) -LFLAGS += $(ANDROID_LINK_EXECUTABLE) - -LRPATH = -Wl,-rpath,$(ANDROID_ROOT)/out/target/product/$(PRODUCT)/obj/lib:$(ANDROID_ROOT)/out/target/product/$(PRODUCT)/system/lib - -#################################################################################################### -## sources - -INV_LIBS = $(MPL_DIR)/build/$(TARGET)/$(LIB_PREFIX)$(MPL_LIB_NAME).$(SHARED_LIB_EXT) -INV_LIBS += $(MLLITE_DIR)/build/$(TARGET)/$(LIB_PREFIX)$(MLLITE_LIB_NAME).$(SHARED_LIB_EXT) - -#INV_SOURCES and VPATH provided by Makefile.filelist -include ../filelist.mk - -INV_OBJS := $(addsuffix .o,$(INV_SOURCES)) -INV_OBJS_DST = $(addprefix $(OBJFOLDER)/,$(addsuffix .o, $(notdir $(INV_SOURCES)))) - -#################################################################################################### -## rules - -.PHONY: all clean cleanall install - -all: $(EXEC) $(MK_NAME) - -$(EXEC) : $(OBJFOLDER) $(INV_OBJS_DST) $(INV_LIBS) $(MK_NAME) - @$(call echo_in_colors, "\n<linking $(EXEC) with objects $(INV_OBJS_DST) $(PREBUILT_OBJS) and libraries $(INV_LIBS)\n") - $(LINK) $(INV_OBJS_DST) -o $(EXEC) $(LFLAGS) $(LLINK) $(INV_LIBS) $(LLINK) $(LRPATH) - -$(OBJFOLDER) : - @$(call echo_in_colors, "\n<creating object's folder 'obj/'>\n") - mkdir obj - -$(INV_OBJS_DST) : $(OBJFOLDER)/%.c.o : %.c $(MK_NAME) - @$(call echo_in_colors, "\n<compile $< to $(OBJFOLDER)/$(notdir $@)>\n") - $(COMP) $(ANDROID_INCLUDES) $(KERNEL_INCLUDES) $(INV_INCLUDES) $(CFLAGS) -o $@ -c $< - -clean : - rm -fR $(OBJFOLDER) - -cleanall : - rm -fR $(EXEC) $(OBJFOLDER) - -install : $(EXEC) - cp -f $(EXEC) $(INSTALL_DIR) - - diff --git a/65xx/libsensors_iio/software/simple_apps/self_test/build/filelist.mk b/65xx/libsensors_iio/software/simple_apps/self_test/build/filelist.mk deleted file mode 100755 index 492f47e..0000000 --- a/65xx/libsensors_iio/software/simple_apps/self_test/build/filelist.mk +++ /dev/null @@ -1,11 +0,0 @@ -#### filelist.mk for console_test #### - -# headers -HEADERS += $(HAL_DIR)/include/inv_sysfs_utils.h - -# sources -SOURCES := $(APP_DIR)/inv_self_test.c - -INV_SOURCES += $(SOURCES) - -VPATH += $(APP_DIR) $(COMMON_DIR) $(HAL_DIR)/linux diff --git a/65xx/libsensors_iio/software/simple_apps/self_test/inv_self_test.c b/65xx/libsensors_iio/software/simple_apps/self_test/inv_self_test.c deleted file mode 100755 index 47abe53..0000000 --- a/65xx/libsensors_iio/software/simple_apps/self_test/inv_self_test.c +++ /dev/null @@ -1,574 +0,0 @@ -/** - * Self Test application for Invensense's MPU6xxx/MPU9xxx. - */ - -#include <unistd.h> -#include <dirent.h> -#include <fcntl.h> -#include <stdio.h> -#include <errno.h> -#include <sys/stat.h> -#include <stdlib.h> -#include <features.h> -#include <dirent.h> -#include <string.h> -#include <poll.h> -#include <stddef.h> -#include <linux/input.h> -#include <time.h> -#include <linux/time.h> - -#include "invensense.h" -#include "ml_math_func.h" -#include "storage_manager.h" -#include "ml_stored_data.h" -#include "ml_sysfs_helper.h" -#include "data_builder.h" - -#ifndef ABS -#define ABS(x)(((x) >= 0) ? (x) : -(x)) -#endif - -#define DEBUG_PRINT /* Uncomment to print Gyro & Accel read from Driver */ - -#define MAX_SYSFS_NAME_LEN (100) -#define MAX_SYSFS_ATTRB (sizeof(struct sysfs_attrbs) / sizeof(char*)) -#define IIO_SYSFS_PATH "/sys/bus/iio/devices/iio:device0" -#define IIO_HUB_NAME "inv_hub" - -#define GYRO_PASS_STATUS_BIT 0x01 -#define ACCEL_PASS_STATUS_BIT 0x02 -#define COMPASS_PASS_STATUS_BIT 0x04 - -typedef union { - long l; - int i; -} bias_dtype; - -char *sysfs_names_ptr; -struct sysfs_attrbs { - char *name; - char *enable; - int enable_value; - char *power_state; - int power_state_value; - char *dmp_on; - int dmp_on_value; - char *self_test; - char *temperature; - char *gyro_enable; - int gyro_enable_value; - char *gyro_x_bias; - char *gyro_y_bias; - char *gyro_z_bias; - char *gyro_scale; - char *accel_enable; - int accel_enable_value; - char *accel_x_bias; - char *accel_y_bias; - char *accel_z_bias; - char *accel_scale; - char *compass_enable; - int compass_enable_value; -} mpu; - -static struct inv_db_save_t save_data; - -/** This function receives the data that was stored in non-volatile memory - between power off */ -static inv_error_t inv_db_load_func(const unsigned char *data) -{ - memcpy(&save_data, data, sizeof(save_data)); - return INV_SUCCESS; -} - -/** This function returns the data to be stored in non-volatile memory between - power off */ -static inv_error_t inv_db_save_func(unsigned char *data) -{ - memcpy(data, &save_data, sizeof(save_data)); - return INV_SUCCESS; -} - -/** read a sysfs entry that represents an integer */ -int read_sysfs_int(char *filename, int *var) -{ - int res=0; - FILE *fp; - - fp = fopen(filename, "r"); - if (fp != NULL) { - fscanf(fp, "%d\n", var); - fclose(fp); - } else { - MPL_LOGE("inv_self_test: ERR open file to read"); - res= -1; - } - return res; -} - -/** write a sysfs entry that represents an integer */ -int write_sysfs_int(char *filename, int data) -{ - int res = 0; - FILE *fp; - - fp = fopen(filename, "w"); - if (fp != NULL) { - fprintf(fp, "%d\n", data); - fclose(fp); - } else { - MPL_LOGE("inv_self_test: ERR open file to write"); - res= -1; - } - return res; -} - -int android_hub(void) -{ - char dev_name[8]; - FILE *fp; - - fp = fopen(mpu.name, "r"); - fgets(dev_name, 8, fp); - fclose (fp); - - if (!strncmp(dev_name, IIO_HUB_NAME, sizeof(IIO_HUB_NAME))) - return true; - else - return false; -} - -int save_n_write_sysfs_int(char *filename, int data, int *old_value) -{ - int res; - res = read_sysfs_int(filename, old_value); - if (res < 0) { - return res; - } - printf("saved %s = %d\n", filename, *old_value); - res = write_sysfs_int(filename, data); - if (res < 0) { - return res; - } - return 0; -} - -int inv_init_sysfs_attributes(void) -{ - unsigned char i = 0; - char sysfs_path[MAX_SYSFS_NAME_LEN]; - char *sptr; - char **dptr; - - sysfs_names_ptr = - (char*)malloc(sizeof(char[MAX_SYSFS_ATTRB][MAX_SYSFS_NAME_LEN])); - sptr = sysfs_names_ptr; - if (sptr != NULL) { - dptr = (char**)&mpu; - do { - *dptr++ = sptr; - sptr += sizeof(char[MAX_SYSFS_NAME_LEN]); - } while (++i < MAX_SYSFS_ATTRB); - } else { - MPL_LOGE("inv_self_test: couldn't alloc mem for sysfs paths"); - return -1; - } - - // Setup IIO sysfs path & build MPU's sysfs paths - sprintf(sysfs_path, "%s", IIO_SYSFS_PATH); - - sprintf(mpu.name, "%s%s", sysfs_path, "/name"); - sprintf(mpu.enable, "%s%s", sysfs_path, "/buffer/enable"); - sprintf(mpu.power_state, "%s%s", sysfs_path, "/power_state"); - sprintf(mpu.dmp_on,"%s%s", sysfs_path, "/dmp_on"); - sprintf(mpu.self_test, "%s%s", sysfs_path, "/self_test"); - sprintf(mpu.temperature, "%s%s", sysfs_path, "/temperature"); - - sprintf(mpu.gyro_enable, "%s%s", sysfs_path, "/gyro_enable"); - sprintf(mpu.gyro_x_bias, "%s%s", sysfs_path, "/in_anglvel_x_calibbias"); - sprintf(mpu.gyro_y_bias, "%s%s", sysfs_path, "/in_anglvel_y_calibbias"); - sprintf(mpu.gyro_z_bias, "%s%s", sysfs_path, "/in_anglvel_z_calibbias"); - sprintf(mpu.gyro_scale, "%s%s", sysfs_path, "/in_anglvel_self_test_scale"); - - sprintf(mpu.accel_enable, "%s%s", sysfs_path, "/accel_enable"); - sprintf(mpu.accel_x_bias, "%s%s", sysfs_path, "/in_accel_x_calibbias"); - sprintf(mpu.accel_y_bias, "%s%s", sysfs_path, "/in_accel_y_calibbias"); - sprintf(mpu.accel_z_bias, "%s%s", sysfs_path, "/in_accel_z_calibbias"); - sprintf(mpu.accel_scale, "%s%s", sysfs_path, "/in_accel_self_test_scale"); - - sprintf(mpu.compass_enable, "%s%s", sysfs_path, "/compass_enable"); - -#if 0 - // test print sysfs paths - dptr = (char**)&mpu; - for (i = 0; i < MAX_SYSFS_ATTRB; i++) { - printf("inv_self_test: sysfs path: %s\n", *dptr++); - } -#endif - return 0; -} - -void print_cal_file_content(struct inv_db_save_t *data) -{ - printf("------------------------------\n"); - printf("-- Calibration file content --\n"); - printf(" compass_bias[3] = %+ld %+ld %+ld\n", - data->compass_bias[0], data->compass_bias[1], data->compass_bias[2]); - printf(" factory_gyro_bias[3] = %+ld %+ld %+ld\n", - data->factory_gyro_bias[0], data->factory_gyro_bias[1], - data->factory_gyro_bias[2]); - printf(" gyro_temp = %+ld\n", data->gyro_temp); - printf(" gyro_bias_tc_set = %+d\n", data->gyro_bias_tc_set); - printf(" accel_bias[3] = %+ld %+ld %+ld\n", - data->accel_bias[0], data->accel_bias[1], data->accel_bias[2]); - printf(" accel_temp = %+ld\n", data->accel_temp); - printf(" gyro_accuracy = %d\n", data->gyro_accuracy); - printf(" accel_accuracy = %d\n", data->accel_accuracy); - printf(" compass_accuracy = %d\n", data->compass_accuracy); - printf("------------------------------\n"); -} - -/******************************************************************************* - * M a i n - ******************************************************************************/ -int main(int argc, char **argv) -{ - FILE *fptr; - int self_test_status = 0; - inv_error_t result; - bias_dtype gyro_bias[3]; - bias_dtype gyro_scale; - bias_dtype accel_bias[3]; - bias_dtype accel_scale; - int scale_ratio; - size_t packet_sz; - int axis_sign = 1; - unsigned char *buffer; - long timestamp; - long long temperature = 0; - bool compass_present = true; - int c; - - result= inv_init_sysfs_attributes(); - if (result) - return -1; - - // Self-test for Non-Hub - inv_init_storage_manager(); - - // Register packet to be saved. - result = inv_register_load_store( - inv_db_load_func, inv_db_save_func, - sizeof(save_data), INV_DB_SAVE_KEY); - - // Self-test for Android Hub - if (android_hub() == true) { - fptr = fopen(mpu.self_test, "r"); - if (fptr) { - fscanf(fptr, "%d", &self_test_status); - printf("\nSelf-Test:Hub:Self test result - " - "Gyro passed= %x, Accel passed= %x, Compass passed= %x\n", - (self_test_status & GYRO_PASS_STATUS_BIT), - (self_test_status & ACCEL_PASS_STATUS_BIT) >> 1, - (self_test_status & COMPASS_PASS_STATUS_BIT) >> 2); - fclose(fptr); - result = 0; - } else { - printf("Hub-Self-Test:ERR-Couldn't invoke self-test\n"); - result = -1; - } - - free(sysfs_names_ptr); - return result; - } - - /* testing hook: if the command-line parameter is '-l' as in 'load', - the system will read out the MLCAL_FILE */ - while ((c = getopt(argc, argv, "l")) != -1) { - switch (c) { - case 'l': - inv_get_mpl_state_size(&packet_sz); - - buffer = (unsigned char *)malloc(packet_sz + 10); - if (buffer == NULL) { - printf("Self-Test:Can't allocate buffer\n"); - return -1; - } - - fptr= fopen(MLCAL_FILE, "rb"); - if (!fptr) { - printf("Self-Test:ERR- Can't open cal file to read - %s\n", - MLCAL_FILE); - result = -1; - } - fread(buffer, 1, packet_sz, fptr); - fclose(fptr); - - result = inv_load_mpl_states(buffer, packet_sz); - if (result) { - printf("Self-Test:ERR - " - "Cannot load MPL states from cal file - error %d\n", - result); - free(buffer); - return -1; - } - free(buffer); - - print_cal_file_content(&save_data); - return 0; - break; - case '?': - return -1; - } - } - - // Clear out data. - memset(&save_data, 0, sizeof(save_data)); - memset(gyro_bias,0, sizeof(gyro_bias)); - memset(accel_bias,0, sizeof(accel_bias)); - - // enable the device - if (save_n_write_sysfs_int(mpu.power_state, 1, - &mpu.power_state_value) < 0) { - printf("Self-Test:ERR-Failed to set power_state=1\n"); - } - if (save_n_write_sysfs_int(mpu.enable, 0, &mpu.enable_value) < 0) { - printf("Self-Test:ERR-Failed to disable master enable\n"); - } - if (save_n_write_sysfs_int(mpu.dmp_on, 0, &mpu.dmp_on_value) < 0) { - printf("Self-Test:ERR-Failed to disable DMP\n"); - } - if (save_n_write_sysfs_int(mpu.accel_enable, 1, - &mpu.accel_enable_value) < 0) { - printf("Self-Test:ERR-Failed to enable accel\n"); - } - if (save_n_write_sysfs_int(mpu.gyro_enable, 1, - &mpu.gyro_enable_value) < 0) { - printf("Self-Test:ERR-Failed to enable gyro\n"); - } - if (save_n_write_sysfs_int(mpu.compass_enable, 1, - &mpu.compass_enable_value) < 0) { -#ifdef DEBUG_PRINT - printf("Self-Test:ERR-Failed to enable compass\n"); -#endif - compass_present = false; - } - - fptr = fopen(mpu.self_test, "r"); - if (!fptr) { - printf("Self-Test:ERR-Couldn't invoke self-test\n"); - result = -1; - goto free_sysfs_storage; - } - - // Invoke self-test - fscanf(fptr, "%d", &self_test_status); - if (compass_present == true) { - printf("Self-Test:Self test result- " - "Gyro passed = %x, Accel passed = %x, Compass passed = %x\n", - (self_test_status & GYRO_PASS_STATUS_BIT), - (self_test_status & ACCEL_PASS_STATUS_BIT) >> 1, - (self_test_status & COMPASS_PASS_STATUS_BIT) >> 2); - } else { - printf("Self-Test:Self test result- " - "Gyro passed = %x, Accel passed = %x\n", - (self_test_status & GYRO_PASS_STATUS_BIT), - (self_test_status & ACCEL_PASS_STATUS_BIT) >> 1); - } - fclose(fptr); - - if (self_test_status & GYRO_PASS_STATUS_BIT) { - // Read Gyro Bias - if (read_sysfs_int(mpu.gyro_x_bias, &gyro_bias[0].i) < 0 || - read_sysfs_int(mpu.gyro_y_bias, &gyro_bias[1].i) < 0 || - read_sysfs_int(mpu.gyro_z_bias, &gyro_bias[2].i) < 0 || - read_sysfs_int(mpu.gyro_scale, &gyro_scale.i) < 0) { - memset(gyro_bias, 0, sizeof(gyro_bias)); - gyro_scale.i = 0; - printf("Self-Test:Failed to read Gyro bias\n"); - } else { - save_data.gyro_accuracy = 3; -#ifdef DEBUG_PRINT - printf("Self-Test:Gyro bias[0..2] = [%d %d %d]\n", - gyro_bias[0].i, gyro_bias[1].i, gyro_bias[2].i); -#endif - } - } else { - printf("Self-Test:Failed Gyro self-test\n"); - } - - if (self_test_status & ACCEL_PASS_STATUS_BIT) { - // Read Accel Bias - if (read_sysfs_int(mpu.accel_x_bias, &accel_bias[0].i) < 0 || - read_sysfs_int(mpu.accel_y_bias, &accel_bias[1].i) < 0 || - read_sysfs_int(mpu.accel_z_bias, &accel_bias[2].i) < 0 || - read_sysfs_int(mpu.accel_scale, &accel_scale.i) < 0) { - memset(accel_bias, 0, sizeof(accel_bias)); - accel_scale.i = 0; - printf("Self-Test:Failed to read Accel bias\n"); - } else { - save_data.accel_accuracy = 3; -#ifdef DEBUG_PRINT - printf("Self-Test:Accel bias[0..2] = [%d %d %d]\n", - accel_bias[0].i, accel_bias[1].i, accel_bias[2].i); -#endif - } - } else { - printf("Self-Test:Failed Accel self-test\n"); - } - - if (!(self_test_status & (GYRO_PASS_STATUS_BIT | ACCEL_PASS_STATUS_BIT))) { - printf("Self-Test:Failed Gyro and Accel self-test, " - "nothing left to do\n"); - result = -1; - goto restore_settings; - } - - // Read temperature - fptr = fopen(mpu.temperature, "r"); - if (fptr != NULL) { - fscanf(fptr,"%lld %ld", &temperature, ×tamp); - fclose(fptr); - } else { - printf("Self-Test:ERR-Couldn't read temperature\n"); - } - - /* - When we read gyro bias from sysfs, the bias is in the raw units scaled by - 1000 at the full scale used during self-test - (in_anglvel_self_test_scale). - We store the biases in raw units (+/- 2000 dps full scale assumed) - scaled by 2^16 therefore the gyro_bias[] have to be divided by the - ratio of 2000 / gyro_scale to comply. - */ - scale_ratio = 2000 / gyro_scale.i; - save_data.factory_gyro_bias[0] = - (long)(gyro_bias[0].l / 1000.f * 65536.f / scale_ratio); - save_data.factory_gyro_bias[1] = - (long)(gyro_bias[1].l / 1000.f * 65536.f / scale_ratio); - save_data.factory_gyro_bias[2] = - (long)(gyro_bias[2].l / 1000.f * 65536.f / scale_ratio); - - // Save temperature @ time stored. - // Temperature is in degrees Celsius scaled by 2^16 - save_data.gyro_temp = temperature * (1L << 16); - save_data.gyro_bias_tc_set = true; - save_data.accel_temp = save_data.gyro_temp; - - // When we read accel bias, the bias is in raw units scaled by 1000. - // and it contains the gravity vector. - // Find the orientation of the device, by looking for gravity - int axis = 0; - if (ABS(accel_bias[1].l) > ABS(accel_bias[0].l)) { - axis = 1; - } - if (ABS(accel_bias[2].l) > ABS(accel_bias[axis].l)) { - axis = 2; - } - if (accel_bias[axis].l < 0) { - axis_sign = -1; - } - - // Convert scaling from raw units scaled by 1000 to raw scaled by 2^16 - /* - When we read accel bias from sysfs, the bias is in the raw units scaled - by 1000 at the full scale used during self-test - (in_accel_self_test_scale). - We store the biases in raw units (+/- 2 gee full scale assumed) - scaled by 2^16 therefore the accel_bias[] have to be multipled by the - ratio of accel_scale / 2 to comply. - */ - scale_ratio = accel_scale.i / 2; - save_data.accel_bias[0] = - (long)(accel_bias[0].l / 1000.f * 65536.f * scale_ratio); - save_data.accel_bias[1] = - (long)(accel_bias[1].l / 1000.f * 65536.f * scale_ratio); - save_data.accel_bias[2] = - (long)(accel_bias[2].l / 1000.f * 65536.f * scale_ratio); - -#ifdef DEBUG_PRINT - printf("Self-Test:Saved Accel bias[0..2] = [%ld %ld %ld]\n", - save_data.accel_bias[0], save_data.accel_bias[1], - save_data.accel_bias[2]); -#endif - - /* - Remove gravity, gravity in raw units should be 16384 = 2^14 for a +/- - 2 gee setting. The data has been saved in Hw units scaled to 2^16, - so gravity needs to scale up accordingly. - */ - long gravity = axis_sign * 16384L * 65536L; -#ifdef DEBUG_PRINT - printf("Self-Test:Gravity = %ld\n", gravity); -#endif - save_data.accel_bias[axis] -= gravity; - - printf("Self-Test:Saved Accel bias (gravity removed) [0..2] = " - "[%ld %ld %ld]\n", - save_data.accel_bias[0], save_data.accel_bias[1], - save_data.accel_bias[2]); - printf("Self-Test:Saved Gyro bias[0..2] = [%ld %ld %ld]\n", - save_data.factory_gyro_bias[0], save_data.factory_gyro_bias[1], - save_data.factory_gyro_bias[2]); - printf("Self-Test:Gyro temperature @ time stored %ld\n", - save_data.gyro_temp); - printf("Self-Test:Accel temperature @ time stored %ld\n", - save_data.accel_temp); - - // Get size of packet to store. - inv_get_mpl_state_size(&packet_sz); - - // Create place to store data - buffer = (unsigned char *)malloc(packet_sz + 10); - if (buffer == NULL) { - printf("Self-Test:Can't allocate buffer\n"); - result = -1; - goto free_sysfs_storage; - } - - // Store the data - result = inv_save_mpl_states(buffer, packet_sz); - if (result) { - result = -1; - } else { - fptr = fopen(MLCAL_FILE, "wb+"); - if (fptr != NULL) { - fwrite(buffer, 1, packet_sz, fptr); - fclose(fptr); - } else { - printf("Self-Test:ERR- Can't open calibration file to write - %s\n", - MLCAL_FILE); - result= -1; - } - } - - free(buffer); - -restore_settings: - if (write_sysfs_int(mpu.dmp_on, mpu.dmp_on_value) < 0) { - printf("Self-Test:ERR-Failed to restore dmp_on\n"); - } - if (write_sysfs_int(mpu.accel_enable, mpu.accel_enable_value) < 0) { - printf("Self-Test:ERR-Failed to restore accel_enable\n"); - } - if (write_sysfs_int(mpu.gyro_enable, mpu.gyro_enable_value) < 0) { - printf("Self-Test:ERR-Failed to restore gyro_enable\n"); - } - if (compass_present) { - if (write_sysfs_int(mpu.compass_enable, mpu.compass_enable_value) < 0) { - printf("Self-Test:ERR-Failed to restore compass_enable\n"); - } - } - if (write_sysfs_int(mpu.enable, mpu.enable_value) < 0) { - printf("Self-Test:ERR-Failed to restore buffer/enable\n"); - } - if (write_sysfs_int(mpu.power_state, mpu.power_state_value) < 0) { - printf("Self-Test:ERR-Failed to restore power_state\n"); - } - -free_sysfs_storage: - free(sysfs_names_ptr); - return result; -} - diff --git a/65xx/libsensors_iio/software/simple_apps/stress_iio/README b/65xx/libsensors_iio/software/simple_apps/stress_iio/README deleted file mode 100755 index eea7588..0000000 --- a/65xx/libsensors_iio/software/simple_apps/stress_iio/README +++ /dev/null @@ -1,27 +0,0 @@ -Usage of inv_stress_iio: - -> inv_stress_iio: - this will run enable and disable sequence sequentially. - In the enable sequence, this will enable all the engines, output, and all dmp - events. - In the disable sequence, this will disable all but accel engine; all outputs - are disabled, only events are allowed. - -> inv_stress_iio -e 10 -d 1: - this set the enable sequence to 10 seconds and disable sequence for 1 seconds. - -> inv_stress_iio -c: - this includes the compass in the enable sequence when you have 9150 or other - secondary bus compass. It won't work for compasses on the primary bus. - -> inv_stress_iio -r: - this set the enable and disable sequences to last a random time. It is good - for stress test. - -> inv_stress_iio -m: - this enables motion interrupt during the disable sequence. - When this is enabled, the driver enters low power accel mode and disables all - other sensor output (including quaternion, gyro, accel, and compass.) in the - disabled sequence: - - diff --git a/65xx/libsensors_iio/software/simple_apps/stress_iio/build/android/shared.mk b/65xx/libsensors_iio/software/simple_apps/stress_iio/build/android/shared.mk deleted file mode 100755 index fe844a5..0000000 --- a/65xx/libsensors_iio/software/simple_apps/stress_iio/build/android/shared.mk +++ /dev/null @@ -1,94 +0,0 @@ -EXEC = inv_stress_iio$(SHARED_APP_SUFFIX) - -MK_NAME = $(notdir $(CURDIR)/$(firstword $(MAKEFILE_LIST))) - -CROSS ?= $(ANDROID_ROOT)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- -COMP ?= $(CROSS)gcc -LINK ?= $(CROSS)gcc - -OBJFOLDER = $(CURDIR)/obj - -INV_ROOT = ../../../../.. -APP_DIR = $(CURDIR)/../.. -MLLITE_DIR = $(INV_ROOT)/software/core/mllite -MPL_DIR = $(INV_ROOT)/software/core/mpl - -include $(INV_ROOT)/software/build/android/common.mk - -CFLAGS += $(CMDLINE_CFLAGS) -CFLAGS += $(ANDROID_COMPILE) -CFLAGS += -Wall -CFLAGS += -fpic -CFLAGS += -nostdlib -CFLAGS += -DNDEBUG -CFLAGS += -D_REENTRANT -CFLAGS += -DLINUX -CFLAGS += -DANDROID -CFLAGS += -mthumb-interwork -CFLAGS += -fno-exceptions -CFLAGS += -ffunction-sections -CFLAGS += -funwind-tables -CFLAGS += -fstack-protector -CFLAGS += -fno-short-enums -CFLAGS += -fmessage-length=0 -CFLAGS += -I$(MLLITE_DIR) -CFLAGS += -I$(MPL_DIR) -CFLAGS += $(INV_INCLUDES) -CFLAGS += $(INV_DEFINES) - -LLINK = -lc -LLINK += -lm -LLINK += -lutils -LLINK += -lcutils -LLINK += -lgcc -LLINK += -ldl -LLINK += -lstdc++ -LLINK += -llog -LLINK += -lz - -LFLAGS += $(CMDLINE_LFLAGS) -LFLAGS += $(ANDROID_LINK_EXECUTABLE) - -LRPATH = -Wl,-rpath,$(ANDROID_ROOT)/out/target/product/$(PRODUCT)/obj/lib:$(ANDROID_ROOT)/out/target/product/$(PRODUCT)/system/lib - -#################################################################################################### -## sources - -INV_LIBS = $(MPL_DIR)/build/$(TARGET)/$(LIB_PREFIX)$(MPL_LIB_NAME).$(SHARED_LIB_EXT) -INV_LIBS += $(MLLITE_DIR)/build/$(TARGET)/$(LIB_PREFIX)$(MLLITE_LIB_NAME).$(SHARED_LIB_EXT) - -#INV_SOURCES and VPATH provided by Makefile.filelist -include ../filelist.mk - -INV_OBJS := $(addsuffix .o,$(INV_SOURCES)) -INV_OBJS_DST = $(addprefix $(OBJFOLDER)/,$(addsuffix .o, $(notdir $(INV_SOURCES)))) - -#################################################################################################### -## rules - -.PHONY: all clean cleanall install - -all: $(EXEC) $(MK_NAME) - -$(EXEC) : $(OBJFOLDER) $(INV_OBJS_DST) $(INV_LIBS) $(MK_NAME) - @$(call echo_in_colors, "\n<linking $(EXEC) with objects $(INV_OBJS_DST) $(PREBUILT_OBJS) and libraries $(INV_LIBS)\n") - $(LINK) $(INV_OBJS_DST) -o $(EXEC) $(LFLAGS) $(LLINK) $(INV_LIBS) $(LLINK) $(LRPATH) - -$(OBJFOLDER) : - @$(call echo_in_colors, "\n<creating object's folder 'obj/'>\n") - mkdir obj - -$(INV_OBJS_DST) : $(OBJFOLDER)/%.c.o : %.c $(MK_NAME) - @$(call echo_in_colors, "\n<compile $< to $(OBJFOLDER)/$(notdir $@)>\n") - $(COMP) $(ANDROID_INCLUDES) $(KERNEL_INCLUDES) $(INV_INCLUDES) $(CFLAGS) -o $@ -c $< - -clean : - rm -fR $(OBJFOLDER) - -cleanall : - rm -fR $(EXEC) $(OBJFOLDER) - -install : $(EXEC) - cp -f $(EXEC) $(INSTALL_DIR) - - diff --git a/65xx/libsensors_iio/software/simple_apps/stress_iio/build/filelist.mk b/65xx/libsensors_iio/software/simple_apps/stress_iio/build/filelist.mk deleted file mode 100755 index f201fbb..0000000 --- a/65xx/libsensors_iio/software/simple_apps/stress_iio/build/filelist.mk +++ /dev/null @@ -1,12 +0,0 @@ -#### filelist.mk for stress_iio #### - -# headers -#HEADERS += $(HAL_DIR)/include/inv_sysfs_utils.h -HEADERS += $(APP_DIR)/iio_utils.h - -# sources -SOURCES := $(APP_DIR)/stress_iio.c - -INV_SOURCES += $(SOURCES) - -VPATH += $(APP_DIR) $(COMMON_DIR) $(HAL_DIR)/linux diff --git a/65xx/libsensors_iio/software/simple_apps/stress_iio/iio_utils.h b/65xx/libsensors_iio/software/simple_apps/stress_iio/iio_utils.h deleted file mode 100755 index 0d46b9f..0000000 --- a/65xx/libsensors_iio/software/simple_apps/stress_iio/iio_utils.h +++ /dev/null @@ -1,651 +0,0 @@ -/* IIO - useful set of util functionality - * - * Copyright (c) 2008 Jonathan Cameron - * - * 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. - */ - -/* Made up value to limit allocation sizes */ -#include <string.h> -#include <stdlib.h> -#include <ctype.h> -#include <stdio.h> -#include <stdint.h> -#include <dirent.h> - -#define IIO_MAX_NAME_LENGTH 30 - -#define FORMAT_SCAN_ELEMENTS_DIR "%s/scan_elements" -#define FORMAT_TYPE_FILE "%s_type" - -const char *iio_dir = "/sys/bus/iio/devices/"; - -/** - * iioutils_break_up_name() - extract generic name from full channel name - * @full_name: the full channel name - * @generic_name: the output generic channel name - **/ -static int iioutils_break_up_name(const char *full_name, - char **generic_name) -{ - char *current; - char *w, *r; - char *working; - current = strdup(full_name); - working = strtok(current, "_\0"); - w = working; - r = working; - - while (*r != '\0') { - if (!isdigit(*r)) { - *w = *r; - w++; - } - r++; - } - *w = '\0'; - *generic_name = strdup(working); - free(current); - - return 0; -} - -/** - * struct iio_channel_info - information about a given channel - * @name: channel name - * @generic_name: general name for channel type - * @scale: scale factor to be applied for conversion to si units - * @offset: offset to be applied for conversion to si units - * @index: the channel index in the buffer output - * @bytes: number of bytes occupied in buffer output - * @mask: a bit mask for the raw output - * @is_signed: is the raw value stored signed - * @enabled: is this channel enabled - **/ -struct iio_channel_info { - char *name; - char *generic_name; - float scale; - float offset; - unsigned index; - unsigned bytes; - unsigned bits_used; - unsigned shift; - uint64_t mask; - unsigned be; - unsigned is_signed; - unsigned enabled; - unsigned location; -}; - -/** - * iioutils_get_type() - find and process _type attribute data - * @is_signed: output whether channel is signed - * @bytes: output how many bytes the channel storage occupies - * @mask: output a bit mask for the raw data - * @be: big endian - * @device_dir: the iio device directory - * @name: the channel name - * @generic_name: the channel type name - **/ -inline int iioutils_get_type(unsigned *is_signed, - unsigned *bytes, - unsigned *bits_used, - unsigned *shift, - uint64_t *mask, - unsigned *be, - const char *device_dir, - const char *name, - const char *generic_name) -{ - FILE *sysfsfp; - int ret; - DIR *dp; - char *scan_el_dir, *builtname, *builtname_generic, *filename = 0; - char signchar, endianchar; - unsigned padint; - const struct dirent *ent; - - ret = asprintf(&scan_el_dir, FORMAT_SCAN_ELEMENTS_DIR, device_dir); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - ret = asprintf(&builtname, FORMAT_TYPE_FILE, name); - if (ret < 0) { - ret = -ENOMEM; - goto error_free_scan_el_dir; - } - ret = asprintf(&builtname_generic, FORMAT_TYPE_FILE, generic_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_free_builtname; - } - - dp = opendir(scan_el_dir); - if (dp == NULL) { - ret = -errno; - goto error_free_builtname_generic; - } - while (ent = readdir(dp), ent != NULL) - /* - * Do we allow devices to override a generic name with - * a specific one? - */ - if ((strcmp(builtname, ent->d_name) == 0) || - (strcmp(builtname_generic, ent->d_name) == 0)) { - ret = asprintf(&filename, - "%s/%s", scan_el_dir, ent->d_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_closedir; - } - sysfsfp = fopen(filename, "r"); - if (sysfsfp == NULL) { - printf("failed to open %s\n", filename); - ret = -errno; - goto error_free_filename; - } - - ret = fscanf(sysfsfp, - "%ce:%c%u/%u>>%u", - &endianchar, - &signchar, - bits_used, - &padint, shift); - if (ret < 0) { - printf("failed to pass scan type description\n"); - return ret; - } - *be = (endianchar == 'b'); - *bytes = padint / 8; - if (*bits_used == 64) - *mask = ~0; - else - *mask = (1 << *bits_used) - 1; - if (signchar == 's') - *is_signed = 1; - else - *is_signed = 0; - fclose(sysfsfp); - free(filename); - - filename = 0; - } -error_free_filename: - if (filename) - free(filename); -error_closedir: - closedir(dp); -error_free_builtname_generic: - free(builtname_generic); -error_free_builtname: - free(builtname); -error_free_scan_el_dir: - free(scan_el_dir); -error_ret: - return ret; -} - -inline int iioutils_get_param_float(float *output, - const char *param_name, - const char *device_dir, - const char *name, - const char *generic_name) -{ - FILE *sysfsfp; - int ret; - DIR *dp; - char *builtname, *builtname_generic; - char *filename = NULL; - const struct dirent *ent; - - ret = asprintf(&builtname, "%s_%s", name, param_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - ret = asprintf(&builtname_generic, - "%s_%s", generic_name, param_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_free_builtname; - } - dp = opendir(device_dir); - if (dp == NULL) { - ret = -errno; - goto error_free_builtname_generic; - } - while (ent = readdir(dp), ent != NULL) - if ((strcmp(builtname, ent->d_name) == 0) || - (strcmp(builtname_generic, ent->d_name) == 0)) { - ret = asprintf(&filename, - "%s/%s", device_dir, ent->d_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_closedir; - } - sysfsfp = fopen(filename, "r"); - if (!sysfsfp) { - ret = -errno; - goto error_free_filename; - } - fscanf(sysfsfp, "%f", output); - break; - } -error_free_filename: - if (filename) - free(filename); -error_closedir: - closedir(dp); -error_free_builtname_generic: - free(builtname_generic); -error_free_builtname: - free(builtname); -error_ret: - return ret; -} - -/** - * bsort_channel_array_by_index() - reorder so that the array is in index order - * - **/ - -inline void bsort_channel_array_by_index(struct iio_channel_info **ci_array, - int cnt) -{ - - struct iio_channel_info temp; - int x, y; - - for (x = 0; x < cnt; x++) - for (y = 0; y < (cnt - 1); y++) - if ((*ci_array)[y].index > (*ci_array)[y+1].index) { - temp = (*ci_array)[y + 1]; - (*ci_array)[y + 1] = (*ci_array)[y]; - (*ci_array)[y] = temp; - } -} - -/** - * build_channel_array() - function to figure out what channels are present - * @device_dir: the IIO device directory in sysfs - * @ - **/ -inline int build_channel_array(const char *device_dir, - struct iio_channel_info **ci_array, - int *counter) -{ - DIR *dp; - FILE *sysfsfp; - int count, i; - struct iio_channel_info *current; - int ret; - const struct dirent *ent; - char *scan_el_dir; - char *filename; - - *counter = 0; - ret = asprintf(&scan_el_dir, FORMAT_SCAN_ELEMENTS_DIR, device_dir); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - dp = opendir(scan_el_dir); - if (dp == NULL) { - ret = -errno; - goto error_free_name; - } - while (ent = readdir(dp), ent != NULL) - if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), - "_en") == 0) { - ret = asprintf(&filename, - "%s/%s", scan_el_dir, ent->d_name); - if (ret < 0) { - ret = -ENOMEM; - goto error_close_dir; - } - sysfsfp = fopen(filename, "r"); - if (sysfsfp == NULL) { - ret = -errno; - free(filename); - goto error_close_dir; - } - fscanf(sysfsfp, "%u", &ret); - printf("%s, %d\n", filename, ret); - if (ret == 1) - (*counter)++; - fclose(sysfsfp); - free(filename); - } - *ci_array = malloc(sizeof(**ci_array) * (*counter)); - if (*ci_array == NULL) { - ret = -ENOMEM; - goto error_close_dir; - } - closedir(dp); - dp = opendir(scan_el_dir); - //seekdir(dp, 0); - count = 0; - while (ent = readdir(dp), ent != NULL) { - if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), - "_en") == 0) { - current = &(*ci_array)[count++]; - ret = asprintf(&filename, - "%s/%s", scan_el_dir, ent->d_name); - if (ret < 0) { - ret = -ENOMEM; - /* decrement count to avoid freeing name */ - count--; - goto error_cleanup_array; - } - sysfsfp = fopen(filename, "r"); - if (sysfsfp == NULL) { - free(filename); - ret = -errno; - goto error_cleanup_array; - } - fscanf(sysfsfp, "%u", ¤t->enabled); - fclose(sysfsfp); - - if (!current->enabled) { - free(filename); - count--; - continue; - } - - current->scale = 1.0; - current->offset = 0; - current->name = strndup(ent->d_name, - strlen(ent->d_name) - - strlen("_en")); - if (current->name == NULL) { - free(filename); - ret = -ENOMEM; - goto error_cleanup_array; - } - /* Get the generic and specific name elements */ - ret = iioutils_break_up_name(current->name, - ¤t->generic_name); - if (ret) { - free(filename); - goto error_cleanup_array; - } - ret = asprintf(&filename, - "%s/%s_index", - scan_el_dir, - current->name); - if (ret < 0) { - free(filename); - ret = -ENOMEM; - goto error_cleanup_array; - } - sysfsfp = fopen(filename, "r"); - fscanf(sysfsfp, "%u", ¤t->index); - fclose(sysfsfp); - free(filename); - /* Find the scale */ - ret = iioutils_get_param_float(¤t->scale, - "scale", - device_dir, - current->name, - current->generic_name); - if (ret < 0) - goto error_cleanup_array; - ret = iioutils_get_param_float(¤t->offset, - "offset", - device_dir, - current->name, - current->generic_name); - if (ret < 0) - goto error_cleanup_array; - ret = iioutils_get_type(¤t->is_signed, - ¤t->bytes, - ¤t->bits_used, - ¤t->shift, - ¤t->mask, - ¤t->be, - device_dir, - current->name, - current->generic_name); - } - } - - closedir(dp); - /* reorder so that the array is in index order */ - bsort_channel_array_by_index(ci_array, *counter); - - return 0; - -error_cleanup_array: - for (i = count - 1; i >= 0; i--) - free((*ci_array)[i].name); - free(*ci_array); -error_close_dir: - closedir(dp); -error_free_name: - free(scan_el_dir); -error_ret: - return ret; -} - -inline int _write_sysfs_int(char *filename, char *basedir, int val, int verify) -{ - int ret; - FILE *sysfsfp; - int test; - //char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - char temp[200]; - ret = 0; - if (temp == NULL) - return -ENOMEM; - sprintf(temp, "%s/%s", basedir, filename); - sysfsfp = fopen(temp, "w"); - if (sysfsfp == NULL) { - printf("failed to open write %s\n", temp); - ret = -errno; - printf("ERROR1=%d\n", ret); - while(1); - goto error_free; - } - fprintf(sysfsfp, "%d", val); - fclose(sysfsfp); - if (verify) { - sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { - printf("failed to open read %s\n", temp); - ret = -errno; - printf("ERROR2=%d\n", ret); - while(1); - goto error_free; - } - fscanf(sysfsfp, "%d", &test); - if (test != val) { - printf("Possible failure in int write %d to %s%s\n", - val, - basedir, - filename); - ret = -1; - } - } -error_free: - fclose(sysfsfp); - //free(temp); - return ret; -} - -int write_sysfs_int(char *filename, char *basedir, int val) -{ - return _write_sysfs_int(filename, basedir, val, 0); -} - -int write_sysfs_int_and_verify(char *filename, char *basedir, int val) -{ - printf("echo %d > %s/%s\n", val, basedir, filename); - return _write_sysfs_int(filename, basedir, val, 1); -} - -int _write_sysfs_string(char *filename, char *basedir, char *val, int verify) -{ - int ret = 0; - FILE *sysfsfp; - char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) { - printf("Memory allocation failed\n"); - return -ENOMEM; - } - sprintf(temp, "%s/%s", basedir, filename); - sysfsfp = fopen(temp, "w"); - if (sysfsfp == NULL) { - printf("Could not open %s\n", temp); - ret = -errno; - goto error_free; - } - fprintf(sysfsfp, "%s", val); - fclose(sysfsfp); - if (verify) { - sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { - printf("could not open file to verify\n"); - ret = -errno; - goto error_free; - } - fscanf(sysfsfp, "%s", temp); - if (strcmp(temp, val) != 0) { - printf("Possible failure in string write of %s " - "Should be %s " - "written to %s\%s\n", - temp, - val, - basedir, - filename); - ret = -1; - } - } -error_free: - free(temp); - - return ret; -} - -/** - * write_sysfs_string_and_verify() - string write, readback and verify - * @filename: name of file to write to - * @basedir: the sysfs directory in which the file is to be found - * @val: the string to write - **/ -int write_sysfs_string_and_verify(char *filename, char *basedir, char *val) -{ - return _write_sysfs_string(filename, basedir, val, 1); -} - -int write_sysfs_string(char *filename, char *basedir, char *val) -{ - return _write_sysfs_string(filename, basedir, val, 0); -} - -int read_sysfs_posint(char *filename, char *basedir) -{ - int ret; - FILE *sysfsfp; - char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) { - printf("Memory allocation failed"); - return -ENOMEM; - } - sprintf(temp, "%s/%s", basedir, filename); - sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { - ret = -errno; - goto error_free; - } - fscanf(sysfsfp, "%d\n", &ret); - fclose(sysfsfp); -error_free: - free(temp); - return ret; -} - -int read_sysfs_float(char *filename, char *basedir, float *val) -{ - float ret = 0; - FILE *sysfsfp; - char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) { - printf("Memory allocation failed"); - return -ENOMEM; - } - sprintf(temp, "%s/%s", basedir, filename); - sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { - ret = -errno; - goto error_free; - } - fscanf(sysfsfp, "%f\n", val); - fclose(sysfsfp); -error_free: - free(temp); - return ret; -} -int enable(const char *device_dir, - struct iio_channel_info **ci_array, - int *counter) -{ - DIR *dp; - int ret; - const struct dirent *ent; - char *scan_el_dir; - - *counter = 0; - ret = asprintf(&scan_el_dir, FORMAT_SCAN_ELEMENTS_DIR, device_dir); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - dp = opendir(scan_el_dir); - if (dp == NULL) { - ret = -errno; - goto error_free_name; - } - while (ent = readdir(dp), ent != NULL) - if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), - "_en") == 0) { - write_sysfs_int_and_verify((char *)ent->d_name, scan_el_dir, 1); - } - return 0; -error_ret: -error_free_name: - return -1; -} -int disable_q_out(const char *device_dir, - struct iio_channel_info **ci_array, - int *counter) { - DIR *dp; - int ret; - const struct dirent *ent; - char *scan_el_dir; - - *counter = 0; - ret = asprintf(&scan_el_dir, FORMAT_SCAN_ELEMENTS_DIR, device_dir); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - dp = opendir(scan_el_dir); - if (dp == NULL) { - ret = -errno; - goto error_free_name; - } - while (ent = readdir(dp), ent != NULL) - if (strncmp(ent->d_name, "in_quaternion", strlen("in_quaternion")) == 0) { - write_sysfs_int_and_verify((char *)ent->d_name, scan_el_dir, 0); - } - return 0; -error_ret: -error_free_name: - return -1; - -} - diff --git a/65xx/libsensors_iio/software/simple_apps/stress_iio/stress_iio.c b/65xx/libsensors_iio/software/simple_apps/stress_iio/stress_iio.c deleted file mode 100755 index 82badc2..0000000 --- a/65xx/libsensors_iio/software/simple_apps/stress_iio/stress_iio.c +++ /dev/null @@ -1,963 +0,0 @@ -/* Industrialio buffer test code. - * - * Copyright (c) 2012 Invensense Inc. - * - * 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. - * - * Command line parameters - * stress_iio -d time1 -e time2 - */ - -#include <unistd.h> -#include <dirent.h> -#include <fcntl.h> -#include <stdio.h> -#include <errno.h> -#include <sys/stat.h> -#include <dirent.h> -#include <linux/types.h> -#include <string.h> -#include <poll.h> -#include <pthread.h> -#include "iio_utils.h" -#include "ml_load_dmp.h" -#include "ml_sysfs_helper.h" -#include "authenticate.h" - -pthread_mutex_t data_switch_lock = PTHREAD_MUTEX_INITIALIZER; - -static int has_compass = 0; -static int has_pressure = 0; -static int enable_random_delay = 0; -static int enable_delay = 10; -static int disable_delay = 10; -static int enable_motion_on = 0; -static int final_output_rate; -static int first_flag; -static char dmp_path[200]; - -static int dev_num; -static char *dev_dir_name; -static char *buf_dir_name; -static char *scan_el_dir; -static int gyro_data_is_enabled, accel_data_is_enabled, compass_data_is_enabled, quaternion_data_is_enabled; -static int accel_engine_is_on; - -struct dmp_struct { - char fname[100]; - void (*action)(struct dmp_struct *, int); -}; - -static void HandleTap(struct dmp_struct *dmp, int tap); -static void sipmle_print(struct dmp_struct *dmp, int d){ - printf("%s:%d\n", dmp->fname, d); -} - -static void handle_smd() { - printf("write wake lock for SMD\n"); - write_sysfs_string_and_verify("wake_lock", "/sys/power/", "hack"); -} - -static void pedo_print() -{ - printf("steps=%d, time=%d\n", - read_sysfs_posint("pedometer_steps", dev_dir_name), - read_sysfs_posint("pedometer_time", dev_dir_name)); -} - -struct dmp_struct event_file[] = { -#if 0 - { - .fname = "event_tap", - .action = HandleTap, - }, -#endif - { - .fname = "event_display_orientation", - .action = sipmle_print, - }, - { - .fname = "event_smd", - .action = handle_smd, - }, - { - .fname = "event_accel_motion", - .action = sipmle_print, - }, - { - .fname = "event_pedometer", - .action = pedo_print, - }, -}; - -static void HandleTap(struct dmp_struct *dmp, int tap) -{ - int tap_dir = tap/8; - int tap_num = tap%8 + 1; - - switch (tap_dir) { - case 1: - printf("INV_TAP_AXIS_X_POS\n"); - break; - case 2: - printf("INV_TAP_AXIS_X_NEG\n"); - break; - case 3: - printf("INV_TAP_AXIS_Y_POS\n"); - break; - case 4: - printf("INV_TAP_AXIS_Y_NEG\n"); - break; - case 5: - printf("INV_TAP_AXIS_Z_POS\n"); - break; - case 6: - printf("INV_TAP_AXIS_Z_NEG\n"); - break; - default: - break; - } - printf("Tap number: %d\n", tap_num); -} -#define DMP_CODE_SIZE 2799 -static char dmp_img[DMP_CODE_SIZE]; -static void verify_img(){ - FILE *fp; - int i; - char dmp_path[] = "/sys/bus/iio/devices/iio:device0/dmp_firmware"; - - printf("saving image\n"); - if ((fp = fopen(dmp_path, "rb")) < 0 ) { - perror("dmp fail"); - } - - i = fread(dmp_img, 1, DMP_CODE_SIZE, fp); - printf("Result=%d\n", i); - fclose(fp); - fp = fopen("/dev/read_img.h", "wt"); - fprintf(fp, "unsigned char rec[]={\n"); - for(i=0; i<DMP_CODE_SIZE; i++) { - fprintf(fp, "0x%02x, ", dmp_img[i]); - //printf( "0x%02x, ", dmp_img[i]); - if(((i+1)%16) == 0) { - fprintf(fp, "\n"); - //printf("\n"); - } - } - fprintf(fp, "};\n "); - fclose(fp); - printf("saving image Done\n"); -} - -static void inv_set_rate() -{ - int ret; - - printf("set rate \n"); - ret = write_sysfs_int_and_verify("accel_rate", dev_dir_name, 15); - ret = write_sysfs_int_and_verify("gyro_rate", dev_dir_name, 10); - ret = write_sysfs_int_and_verify("compass_rate", dev_dir_name, 5); - ret = write_sysfs_int_and_verify("pressure_rate", dev_dir_name, 5); - ret = write_sysfs_int_and_verify("ped_q_rate", dev_dir_name, 5); - ret = write_sysfs_int_and_verify("six_axes_q_rate", dev_dir_name, 5); - ret = write_sysfs_int_and_verify("three_axes_q_rate", dev_dir_name, 5); -} - - -static int setup_offset_and_bias() -{ - int ret; - - ret = write_sysfs_int_and_verify("in_accel_x_offset", dev_dir_name, 0); - if (ret < 0) - printf("write accel x offset failed.\n"); - ret = write_sysfs_int_and_verify("in_accel_y_offset", dev_dir_name, 0); - if (ret < 0) - printf("write accel y offset failed.\n"); - ret = write_sysfs_int_and_verify("in_accel_z_offset", dev_dir_name, 0); - if (ret < 0) - printf("write accel z offset failed.\n"); - - ret = write_sysfs_int_and_verify("in_anglvel_x_offset", dev_dir_name, 0); - if (ret < 0) - printf("write accel x offset failed.\n"); - ret = write_sysfs_int_and_verify("in_anglvel_y_offset", dev_dir_name, 0); - if (ret < 0) - printf("write accel y offset failed.\n"); - ret = write_sysfs_int_and_verify("in_anglvel_z_offset", dev_dir_name, 0); - if (ret < 0) - printf("write accel z offset failed.\n"); - - ret = write_sysfs_int_and_verify("in_accel_x_dmp_bias", dev_dir_name, 0); - if (ret < 0) - printf("write accel x offset failed.\n"); - ret = write_sysfs_int_and_verify("in_accel_y_dmp_bias", dev_dir_name, 0); - if (ret < 0) - printf("write accel y offset failed.\n"); - ret = write_sysfs_int_and_verify("in_accel_z_dmp_bias", dev_dir_name, 0); - if (ret < 0) - printf("write accel z offset failed.\n"); - - ret = write_sysfs_int_and_verify("in_anglvel_x_dmp_bias", dev_dir_name, 0); - if (ret < 0) - printf("write gyro x offset failed.\n"); - ret = write_sysfs_int_and_verify("in_anglvel_y_dmp_bias", dev_dir_name, 0); - if (ret < 0) - printf("write gyro y offset failed.\n"); - ret = write_sysfs_int_and_verify("in_anglvel_z_dmp_bias", dev_dir_name, 0); - if (ret < 0) - printf("write gyro z offset failed.\n"); - - return 0; -} - -static void setup_dmp(char *dev_path){ - char sysfs_path[200]; - int ret; - FILE *fd; - sprintf(sysfs_path, "%s", dev_path); - printf("sysfs: %s\n", sysfs_path); - ret = write_sysfs_int_and_verify("power_state", sysfs_path, 1); - if (ret < 0) - return; - - ret = write_sysfs_int("in_accel_scale", dev_path, 0); - if (ret < 0) - return; - ret = write_sysfs_int("in_anglvel_scale", dev_path, 3); - if (ret < 0) - return; - ret = write_sysfs_int("sampling_frequency", sysfs_path, 200); - if (ret < 0) - return; - ret = write_sysfs_int_and_verify("firmware_loaded", sysfs_path, 0); - if (ret < 0) - return; - sprintf(dmp_path, "%s/dmp_firmware", dev_path); - if ((fd = fopen(dmp_path, "wb")) < 0 ) { - perror("dmp fail"); - } - inv_load_dmp(fd); - fclose(fd); - printf("firmware_loaded=%d\n", read_sysfs_posint("firmware_loaded", sysfs_path)); - ret = write_sysfs_int_and_verify("dmp_on", sysfs_path, 1); - if (ret < 0) - return; - ret = write_sysfs_int_and_verify("dmp_int_on", sysfs_path, 1); - if (ret < 0) - return; - /* selelct which event to enable and interrupt on/off here */ - //enable_glu(sysfs_path, 0); - //ret = write_sysfs_int_and_verify("tap_on", sysfs_path, 0); - if (ret < 0) - return; - ret = write_sysfs_int_and_verify("display_orientation_on", sysfs_path, 1); - if (ret < 0) - return; - ret = write_sysfs_int_and_verify("pedometer_int_on", sysfs_path, 0); - ret = write_sysfs_int_and_verify("pedometer_on", sysfs_path, 1); - - ret = write_sysfs_int_and_verify("dmp_event_int_on", sysfs_path, 1); - if (ret < 0) - return; - - ret = setup_offset_and_bias(); - - return; -} - -#if 0 -static char reg_dump_arr[2000]; -static int inv_do_reg_dump(void) -{ - char reg_dump_name[100]; - int fd, i; - - sprintf(reg_dump_name, "%s/reg_dump", dev_dir_name); - printf("%s\n", reg_dump_name); - fd = open(reg_dump_name, O_RDONLY); - pread(fd, reg_dump_arr, 2000, 0); - close(fd); - for ( i = 0; i < 2000; i++) { - printf("%c", reg_dump_arr[i]); - //if((i+1)%16 == 0) - //printf("\n"); - } - return 0; -} -#endif - -static void *get_dmp_event(void *param) { - char file_name[100]; - int i; - int data; - char d[4]; - FILE *fp; - struct pollfd pfd[ARRAY_SIZE(event_file)]; - - printf("get DMP event: %s\n", dev_dir_name); - while(1) { - for (i = 0; i < ARRAY_SIZE(event_file); i++) { - sprintf(file_name, "%s/%s", dev_dir_name, event_file[i].fname); - pfd[i].fd = open(file_name, O_RDONLY | O_NONBLOCK); - pfd[i].events = POLLPRI|POLLERR; - pfd[i].revents = 0; - read(pfd[i].fd, d, 4); - } - - poll(pfd, ARRAY_SIZE(event_file), -1); - for (i = 0; i < ARRAY_SIZE(event_file); i++) { - close(pfd[i].fd); - } - - for (i=0; i< ARRAY_SIZE(pfd); i++) { - if(pfd[i].revents != 0) { - sprintf(file_name, "%s/%s", dev_dir_name, event_file[i].fname); - fp = fopen(file_name, "rt"); - fscanf(fp, "%d\n", &data); - event_file[i].action(&event_file[i], data); - } - } - } - - return 0; -} - -static int enable_gyro(int on){ - int ret; - ret = write_sysfs_int_and_verify("gyro_enable", dev_dir_name, on); - if (ret < 0) - printf("write gyro_enable failed\n"); - - return ret; -} - -static int enable_gyro_output(int on){ - int ret; - gyro_data_is_enabled = on; - ret = write_sysfs_int_and_verify("gyro_fifo_enable", dev_dir_name, on); - if (ret < 0) - printf("write gyro_fifo_enable failed\n"); - - return ret; -} - -static int enable_compass(int on){ - int ret; - - compass_data_is_enabled = on; - ret = write_sysfs_int_and_verify("compass_enable", dev_dir_name, on); - if (ret < 0) - printf("write gyro_enable failed\n"); - - return ret; -} - -static int enable_pressure(int on){ - int ret; - - ret = write_sysfs_int_and_verify("pressure_enable", dev_dir_name, on); - if (ret < 0) - printf("write pressure_enable failed\n"); - - return ret; -} - -static int enable_quaternion(int on) { - int ret; - ret = write_sysfs_int_and_verify("ped_q_on", dev_dir_name, on); - if (ret < 0) - printf("write quaternion_on failed\n"); - ret = write_sysfs_int_and_verify("six_axes_q_on", dev_dir_name, on); - if (ret < 0) - printf("write quaternion_on failed\n"); - ret = write_sysfs_int_and_verify("three_axes_q_on", dev_dir_name, on); - if (ret < 0) - printf("write quaternion_on failed\n"); - - return ret; -} -static int enable_step_detector(int on) { - int ret; - - ret = write_sysfs_int_and_verify("step_detector_on", dev_dir_name, on); - if (ret < 0) - printf("write step detector on failed\n"); -} -static int enable_step_indicator(int on) { - int ret; - - ret = write_sysfs_int_and_verify("step_indicator_on", dev_dir_name, on); - if (ret < 0) - printf("write step indicator on failed\n"); -} - -static int enable_accel(int on){ - int ret; - accel_data_is_enabled = on; - accel_engine_is_on = on; - ret = write_sysfs_int_and_verify("accel_enable", dev_dir_name, on); - if (ret < 0) - printf("write accel_enable failed\n"); - ret = write_sysfs_int_and_verify("accel_fifo_enable", dev_dir_name, on); - if (ret < 0) - printf("write accel_fifo_enable failed\n"); - - return ret; -} -static int enable_accel_output(int on) { - int ret; - accel_data_is_enabled = on; - - ret = write_sysfs_int_and_verify("accel_fifo_enable", dev_dir_name, on); - if (ret < 0) - printf("write accel_fifo_enable failed\n"); - - return ret; -} - -static int enable_enable(int on){ - int ret; - - if (0 == on) { - pthread_mutex_lock(&data_switch_lock); - } - if (on == 0) { - ret = write_sysfs_int_and_verify("power_state", dev_dir_name, 1); - - if (ret < 0) - printf("write power_state fail\n"); - ret = write_sysfs_int_and_verify("power_state", dev_dir_name, 1); - if (ret < 0) - printf("write power_state fail\n"); - } - ret = write_sysfs_int_and_verify("enable", buf_dir_name, on); - if (ret < 0) - printf("write enable failed\n"); - - if (on) { - pthread_mutex_unlock(&data_switch_lock); - } - - return 0; -} -static int write_dmp_event(int on) { - int ret; - ret = write_sysfs_int_and_verify("dmp_event_int_on", dev_dir_name, on); - if (ret < 0) - printf("write dmp_event_int_on failed\n"); - return 0; -} - -static void random_delay(){ - int i; - float bb; - - i = rand(); - bb = i * 200.0; - i = 1 + (unsigned int)(bb/(RAND_MAX + 1.0)); - if (i%2) { - printf("sleep %d ms\n", i); - usleep(i*1000); - } else { - printf("sleep %d s\n", i); - sleep(i); - } - -} -static void dmp_event_control(on){ - int ret; - - ret = 0; - - //ret = write_sysfs_int_and_verify("tap_on", dev_dir_name, on); - ret = write_sysfs_int_and_verify("display_orientation_on", dev_dir_name, 1); - if (ret < 0) - return; - ret = write_sysfs_int_and_verify("smd_enable", dev_dir_name, 1); - if (ret < 0) - return; - inv_set_rate(); - - //ret = write_sysfs_int_and_verify("batchmode_wake_fifo_full_on", dev_dir_name, 1); - ret = write_sysfs_int_and_verify("batchmode_timeout", dev_dir_name, 5000); - //ret = write_sysfs_int_and_verify("batchmode_timeout", dev_dir_name, 0); - //ret = write_sysfs_int_and_verify("smd_delay_threshold", dev_dir_name, 10); - if (ret < 0) - return; - //ret = write_sysfs_int_and_verify("smd_threshold", dev_dir_name, 5000); - if (ret < 0) - return; - //write_sysfs_int_and_verify("motion_lpa_duration", dev_dir_name, 1000); - //write_sysfs_int_and_verify("motion_lpa_threshold", dev_dir_name, 200); - write_sysfs_int_and_verify("dmp_on", dev_dir_name, 1); - //write_sysfs_int_and_verify("motion_lpa_freq", dev_dir_name, 3); - -} -void enable_motion(int on) { - - //ret = write_sysfs_int_and_verify("motion_lpa_on", dev_dir_name, on); - if (on) { - gyro_data_is_enabled = 0; - compass_data_is_enabled = 0; - quaternion_data_is_enabled = 0; - } -} -bool g, a; -static int counter = 0; -static unsigned char data_rate[] = {5, 10, 15, 50, 100, 200}; -static int run_enable_sequence() -{ - bool g, a, out; - - counter++; - g = rand()%2; - a = rand()%2; - if (!g && !a) - a = true; - - //g = true; - //a = true; - /*disable the master enable */ - enable_enable(0); - if(g) { - enable_gyro(1); - if (rand()%2) { - out = rand()%2; - enable_quaternion(out); - enable_gyro_output(!out); - } else { - enable_quaternion(1); - enable_gyro_output(1); - } - // enable_quaternion(0); - // enable_gyro_output(0); - - } else { - enable_gyro(0); - enable_quaternion(0); - } - if(a) { - enable_accel(1); - enable_accel_output(1); - // enable_accel_output(0); - } else { - enable_accel(1); - enable_accel_output(0); - } - if (has_compass) { - if(rand()%2) - enable_compass(1); - else - enable_compass(0); - enable_compass(counter%2); - //enable_compass(0); - } - if (has_pressure) { - if(rand()%2) - enable_pressure(1); - else - enable_pressure(0); - enable_pressure(counter%3); - //enable_pressure(0); - } - enable_step_detector(1); - enable_step_indicator(1); - //enable_step_detector(0); - //enable_step_indicator(0); - - write_dmp_event(0); - - //enable_motion(0); - if (accel_engine_is_on) - dmp_event_control(1); - else - dmp_event_control(0); - first_flag = 1; - /*enable the master enable */ - enable_enable(1); - //write_sysfs_string_and_verify("wake_unlock", "/sys/power/", "hack"); - if (enable_random_delay) - random_delay(); - else { - printf("sleep %ds\n", enable_delay); - sleep(enable_delay); - } - - return 0; -} - -static int run_disable_sequence() { - enable_enable(0); - - enable_gyro(0); - enable_accel(1); - enable_quaternion(0); - enable_accel_output(0); - write_dmp_event(1); - //enable_motion(enable_motion_on); - if (accel_engine_is_on) - dmp_event_control(1); - else - dmp_event_control(0); - - enable_enable(1); - if (enable_random_delay) - random_delay(); - else { - printf("sleep %ds\n", disable_delay); - sleep(disable_delay); - } - - return 0; -} -static void *control_switch(void *param) -{ - while(1) { - run_enable_sequence(); - printf("sleeping\n"); - usleep(500000); - run_disable_sequence(); - } - return 0; -} - -void get_sensor_data(char *d, short *sensor) -{ - int i; - - for (i = 0; i < 3; i++) - sensor[i] = *(short *)(d + 2 + i * 2); -} - -static void *read_data(void *param) -{ - char *buffer_access; - char data[1048], *dptr, tmp[24]; - short sensor[3]; - int q[3], i, ind, left_over_size, buf_size; - int ret, fp,read_size; - unsigned short hdr; - bool done_flag; - -#define PRESSURE_HDR 0x8000 -#define ACCEL_HDR 0x4000 -#define GYRO_HDR 0x2000 -#define COMPASS_HDR 0x1000 -#define LPQUAT_HDR 0x0800 -#define SIXQUAT_HDR 0x0400 -#define PEDQUAT_HDR 0x0200 -#define STEP_DETECTOR_HDR 0x0100 - - printf("read_data Thread: %s\n", dev_dir_name); - ret = asprintf(&scan_el_dir, FORMAT_SCAN_ELEMENTS_DIR, dev_dir_name); - if (ret < 0) - goto error_alloc_scan_el_dir; - ret = asprintf(&buffer_access, "/dev/iio:device%d", dev_num); - if (ret < 0) - goto error_alloc_buffer_access; - - fp = open(buffer_access, O_RDONLY | O_NONBLOCK); - if (fp == -1) { /*If it isn't there make the node */ - printf("Failed to open %s\n", buffer_access); - ret = -errno; - goto error_open_buffer_access; - } - ind = 0; - - while(1) { - struct pollfd pfd = { - .fd = fp, - .events = POLLIN, - }; - poll(&pfd, 1, -1); - - if (left_over_size > 0) - memcpy(data, tmp, left_over_size); - dptr = data + left_over_size; - - read_size = read(fp, dptr, 1024); - printf("readsize=%d, left_over_size=%d\n", read_size, left_over_size); - if (read_size <= 0) { - printf("Wrong size=%d\n", read_size); - pthread_mutex_unlock(&data_switch_lock); - continue; - } - ind = read_size + left_over_size; - dptr = data; - printf("ind=%d\n", ind); - buf_size = ind - (dptr - data); - done_flag = false; - while ((buf_size > 0) && (!done_flag)) { - hdr = *((short *)(dptr)); - if (hdr & 1) - printf("STEP$$$$$$$$$$$$$$$=%x\n", hdr); - - switch (hdr & (~1)) { - case PRESSURE_HDR: - if (buf_size >= 16) { - get_sensor_data(dptr, sensor); - dptr += 8; - printf("PRESSURE:%d, %lld\n", (sensor[1] << 16) + (unsigned short)sensor[2], *(long long *)dptr); - } else - done_flag = true; - break; - case ACCEL_HDR: - if (buf_size >= 16) { - get_sensor_data(dptr, sensor); - dptr += 8; - printf("A:%d, %d, %d, %lld\n", sensor[0], sensor[1], sensor[2], *(long long *)dptr); - } else - done_flag = true; - break; - case GYRO_HDR: - if (buf_size >= 16) { - get_sensor_data(dptr, sensor); - dptr += 8; - printf("G:%d, %d, %d, %lld\n", sensor[0], sensor[1], sensor[2], *(long long *)dptr); - } else - done_flag = true; - break; - case COMPASS_HDR: - if (buf_size >= 16) { - get_sensor_data(dptr, sensor); - dptr += 8; - printf("M:%d, %d, %d, %lld\n", sensor[0], sensor[1], sensor[2], *(long long *)dptr); - } else - done_flag = true; - break; - case PEDQUAT_HDR: - if (buf_size >= 16) { - get_sensor_data(dptr, sensor); - dptr += 8; - printf("PED:%d, %d, %d, %lld\n", sensor[0], sensor[1], sensor[2], *(long long *)dptr); - } else - done_flag = true; - break; - case LPQUAT_HDR: - if (buf_size >= 24) { - q[0] = *(int *)(dptr + 4); - dptr += 8; - q[1] = *(int *)(dptr); - q[2] = *(int *)(dptr + 4); - dptr += 8; - printf("LPQ:%d, %d, %d, %lld\n", q[0], q[1], q[2], *(long long *)dptr); - } else - done_flag = true; - break; - case SIXQUAT_HDR: - if (buf_size >= 24) { - q[0] = *(int *)(dptr + 4); - dptr += 8; - q[1] = *(int *)(dptr); - q[2] = *(int *)(dptr + 4); - dptr += 8; - printf("SIXQ:%d, %d, %d, %lld\n", q[0], q[1], q[2], *(long long *)dptr); - } else - done_flag = true; - break; - case STEP_DETECTOR_HDR: - if (buf_size >= 16) { - printf("STEP DETECTOR "); - dptr += 8; - printf(" %lld\n", *(long long *)dptr); - } else - done_flag = true; - - break; - default: - printf("unknown\n"); - for (i = 0; i < 8; i++) - printf("%x ", dptr[i]); - printf("\n"); - break; - } - if (!done_flag) - dptr += 8; - buf_size = ind - (dptr - data); - } - if (ind - (dptr - data) > 0) - memcpy(tmp, dptr, ind - (dptr - data)); - left_over_size = ind - (dptr - data); - } - close(fp); - -error_open_buffer_access: - free(buffer_access); -error_alloc_buffer_access: - free(scan_el_dir); -error_alloc_scan_el_dir: - - return 0; -} - -static void inv_create_thread() { - pthread_t thread_dmp_event, thread_read_data, thread_control; - - pthread_create(&thread_dmp_event, NULL, &get_dmp_event, (void *)dev_dir_name); - pthread_create(&thread_read_data, NULL, &read_data, (void *)dev_dir_name); - pthread_create(&thread_control, NULL, &control_switch, (void *)dev_dir_name); - - pthread_join(thread_dmp_event, NULL); - pthread_join(thread_read_data, NULL); - pthread_join(thread_control, NULL); -} - -static int enable_enable_main(int on){ - int ret; - - printf("enable_enable: %s=%d\n", dev_dir_name, on); - if (on == 0) { - ret = write_sysfs_int_and_verify("power_state", dev_dir_name, 1); - - if (ret < 0) - printf("write power_state fail\n"); - ret = write_sysfs_int_and_verify("power_state", dev_dir_name, 1); - if (ret < 0) - printf("write power_state fail\n"); - } - ret = write_sysfs_int_and_verify("enable", buf_dir_name, on); - if (ret < 0) - printf("write enable failed\n"); - - return 0; -} - -int main(int argc, char **argv) -{ - unsigned long buf_len = 128; - - int ret, c, i; - - char *trigger_name = NULL; - - int datardytrigger = 1; - int trig_num; - char *dummy; - char chip_name[10]; - char device_name[10]; - char sysfs[100]; - - gyro_data_is_enabled = 0; - accel_data_is_enabled = 0; - compass_data_is_enabled = 0; - quaternion_data_is_enabled = 0; - - while ((c = getopt(argc, argv, "lcd:e:rmp")) != -1) { - switch (c) { - case 'c': - has_compass = 1; - break; - case 'p': - has_pressure = 1; - break; - case 'd': - disable_delay = strtoul(optarg, &dummy, 10); - break; - case 'e': - enable_delay = strtoul(optarg, &dummy, 10); - break; - case 'r': - enable_random_delay = 1; - break; - case 'm': - enable_motion_on = 1; - break; - case '?': - return -1; - } - } - - inv_get_sysfs_path(sysfs); - printf("sss:::%s\n", sysfs); - if (inv_get_chip_name(chip_name) != INV_SUCCESS) { - printf("get chip name fail\n"); - exit(0); - } - printf("chip_name=%s\n", chip_name); - if (INV_SUCCESS != inv_check_key()) - printf("key check fail\n"); - else - printf("key authenticated\n"); - - for (i=0; i<strlen(chip_name); i++) { - device_name[i] = tolower(chip_name[i]); - } - device_name[strlen(chip_name)] = '\0'; - printf("device name: %s\n", device_name); - - /* Find the device requested */ - dev_num = find_type_by_name(device_name, "iio:device"); - if (dev_num < 0) { - printf("Failed to find the %s\n", device_name); - ret = -ENODEV; - goto error_ret; - } - printf("iio device number being used is %d\n", dev_num); - asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num); - printf("allco=%x\n", (int)dev_dir_name); - if (trigger_name == NULL) { - /* - * Build the trigger name. If it is device associated it's - * name is <device_name>_dev[n] where n matches the device - * number found above - */ - ret = asprintf(&trigger_name, - "%s-dev%d", device_name, dev_num); - if (ret < 0) { - ret = -ENOMEM; - goto error_ret; - } - } - /* Verify the trigger exists */ - trig_num = find_type_by_name(trigger_name, "trigger"); - if (trig_num < 0) { - printf("Failed to find the trigger %s\n", trigger_name); - ret = -ENODEV; - goto error_free_triggername; - } - printf("iio trigger number being used is %d\n", trig_num); - ret = asprintf(&buf_dir_name, "%siio:device%d/buffer", iio_dir, dev_num); - if (ret < 0) { - ret = -ENOMEM; - goto error_free_triggername; - } - enable_enable_main(0); - ret = write_sysfs_int_and_verify("power_state", dev_dir_name, 1); - /* - * Parse the files in scan_elements to identify what channels are - * present - */ - ret = 0; - setup_dmp(dev_dir_name); - - printf("%s %s\n", dev_dir_name, trigger_name); - - /* Set the device trigger to be the data rdy trigger found above */ - ret = write_sysfs_string_and_verify("trigger/current_trigger", - dev_dir_name, - trigger_name); - if (ret < 0) { - printf("Failed to write current_trigger file\n"); - goto error_free_buf_dir_name; - } - /* Setup ring buffer parameters */ - /* length must be even number because iio_store_to_sw_ring is expecting - half pointer to be equal to the read pointer, which is impossible - when buflen is odd number. This is actually a bug in the code */ - ret = write_sysfs_int("length", buf_dir_name, buf_len*2); - if (ret < 0) - goto exit_here; - - inv_create_thread(); -exit_here: -error_free_buf_dir_name: - free(buf_dir_name); -error_free_triggername: - if (datardytrigger) - free(trigger_name); -error_ret: - return ret; -} |
