X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=common.h;h=fcc202522b1a74031a41d6ab654adfbf89d621f8;hb=7c717ba09a646ee037dcbf26542209f04beecd3a;hp=012d4a27f617eb2af419b3dab69f3f8d142e35ff;hpb=5e5841987c50d6a8a0c1a4f418199996cdc31abd;p=android-x86%2Fhardware-intel-libsensors.git diff --git a/common.h b/common.h index 012d4a2..fcc2025 100644 --- a/common.h +++ b/common.h @@ -8,11 +8,11 @@ #define MAX_DEVICES 8 /* Check iio devices 0 to MAX_DEVICES-1 */ #define MAX_SENSORS 10 /* We can handle as many sensors */ #define MAX_CHANNELS 4 /* We can handle as many channels per sensor */ +#define MAX_TRIGGERS 8 /* Check for triggers 0 to MAX_TRIGGERS-1 */ -#define DEV_FILE_PATH "/dev/iio:device%d" - -#define BASE_PATH "/sys/bus/iio/devices/iio:device%d/" - +#define DEV_FILE_PATH "/dev/iio:device%d" +#define BASE_PATH "/sys/bus/iio/devices/iio:device%d/" +#define TRIGGER_FILE_PATH "/sys/bus/iio/devices/trigger%d/name" #define CHANNEL_PATH BASE_PATH "scan_elements/" #define ENABLE_PATH BASE_PATH "buffer/enable" @@ -27,14 +27,21 @@ #define PROP_BASE "ro.iio.%s.%s" /* Note: PROPERTY_KEY_MAX is small */ +#define MAX_EVENTS 1000 /* 1000 hz */ #define MAX_TYPE_SPEC_LEN 32 /* Channel type spec len; ex: "le:u10/16>>0" */ #define MAX_SENSOR_REPORT_SIZE 32 /* Sensor report buffer size */ #define MAX_NAME_SIZE 32 -#define CAP_SENSOR_MAX_FREQUENCY 1000 #define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0]) +#ifdef __LP64__ + typedef uint64_t flag_t; + typedef int64_t max_delay_t; +#else + typedef uint32_t flag_t; + typedef int32_t max_delay_t; +#endif struct channel_descriptor_t { @@ -88,19 +95,30 @@ struct sample_ops_t float (*transform)(int s, int c, unsigned char* sample_data); /* Function called once per sample */ - void (*finalize)(int s, struct sensors_event_t* data); + int (*finalize)(int s, struct sensors_event_t* data); }; struct sensor_info_t { - char friendly_name[MAX_NAME_SIZE]; /* ex: Accelerometer */ - char internal_name[MAX_NAME_SIZE]; /* ex: accel_3d */ - char vendor_name[MAX_NAME_SIZE]; /* ex: Intel */ - + char friendly_name[MAX_NAME_SIZE]; /* ex: Accelerometer */ + char internal_name[MAX_NAME_SIZE]; /* ex: accel_3d */ + char vendor_name[MAX_NAME_SIZE]; /* ex: Intel */ + char init_trigger_name[MAX_NAME_SIZE]; /* ex: accel-name-dev1 */ + char motion_trigger_name[MAX_NAME_SIZE];/* ex: accel-any-motion-dev1 */ float max_range; float resolution; float power; + /* + * Currently active trigger - either a pointer to the initial (default) + * trigger name buffer, or a pointer to the motion trigger name buffer, + * or something else (typically NULL or a pointer to some static "\n". + * This is used to determine if the conditions are met to switch from + * the default trigger to the motion trigger for a sensor, or rather for + * the interrupt-driven sensors associated to a given iio device. + */ + const char* selected_trigger; + float offset; /* (cooked = raw + offset) * scale */ float scale; /*default: 1. when set to 0, use channel specific value*/ float illumincalib; /* to set the calibration for the ALS */ @@ -139,19 +157,56 @@ struct sensor_info_t */ int64_t report_ts; + /* Buffer containing the last generated sensor report for this sensor */ unsigned char report_buffer[MAX_SENSOR_REPORT_SIZE]; - int64_t last_integration_ts; /* Last time an event was reported */ + /* Whether or not the above buffer contains data from a device report */ + int report_initialized; struct sample_ops_t ops; - int calibrated; + int cal_level; /* 0 means not calibrated */ void* cal_data; + + float prev_val; /* Previously reported value, for on-change sensors */ + + /* + * Certain sensors expose their readings through sysfs files that have + * a long response time (100-200 ms for ALS). Rather than block our + * global control loop for several hundred ms each second, offload those + * lengthy blocking reads to dedicated threads, which will then report + * their data through a fd that we can add to our poll fd set. + */ + int thread_data_fd[2]; + pthread_t acquisition_thread; + + /* For cal-uncal sensor pairs - index to the pair sensor in sensor_info */ + int pair_idx; + + uint32_t quirks; /* Bit mask expressing the need for special tweaks */ + /* Note: we may have to explicitely serialize access to some fields */ + + + /* + * If the QUIRK_FIELD_ORDERING bit is set in quirks, the contents of + * this array are used in the finalization stage to swap sample fields + * before transmitting them to Android ; they form a mapping between + * the indices of the input and output arrays: ex: 0123 is identity for + * a sample containing 4 fields. + */ + unsigned char order[MAX_CHANNELS]; + + /* A few variables used for data filtering */ + float *history; /* Working buffer containing recorded samples */ + int history_size; /* Number of recorded samples */ + int history_entries; /* How many of these are initialized */ + int history_index; /* Index of sample to evict next time */ }; /* Reference a few commonly used variables... */ extern int sensor_count; +extern struct sensor_t sensor_desc[MAX_SENSORS]; extern struct sensor_info_t sensor_info[MAX_SENSORS]; extern struct sensor_catalog_entry_t sensor_catalog[];