Home | History | Annotate | Download | only in linux
      1 /*
      2  $License:
      3     Copyright (C) 2014 InvenSense Corporation, All Rights Reserved.
      4  $
      5  */
      6 
      7 /**
      8  *  @brief    Provides helpful file IO wrappers for use with sysfs.
      9  *  @details  Based on Jonathan Cameron's @e iio_utils.h.
     10  */
     11 
     12 #ifndef _INV_SYSFS_UTILS_H_
     13 #define _INV_SYSFS_UTILS_H_
     14 
     15 /**
     16  *  struct inv_sysfs_names_s - Files needed by user applications.
     17  *  @buffer:		Ring buffer attached to FIFO.
     18  *  @enable:		Turns on HW-to-ring buffer flow.
     19  *  @raw_data:		Raw data from registers.
     20  *  @temperature:	Temperature data from register.
     21  *  @fifo_rate:		FIFO rate/ODR.
     22  *  @power_state:	Power state (this is a five-star comment).
     23  *  @fsr:		Full-scale range.
     24  *  @lpf:		Digital low pass filter.
     25  *  @scale:		LSBs / dps (or LSBs / Gs).
     26  *  @temp_scale:	LSBs / degrees C.
     27  *  @temp_offset:	Offset in LSBs.
     28  */
     29 struct inv_sysfs_names_s {
     30 
     31 	//Sysfs for ITG3500 & MPU6050
     32 	const char *buffer;
     33 	const char *enable;
     34 	const char *raw_data;		//Raw Gyro data
     35 	const char *temperature;
     36 	const char *fifo_rate;
     37 	const char *power_state;
     38 	const char *fsr;
     39 	const char *lpf;
     40 	const char *scale;			//Gyro scale
     41 	const char *temp_scale;
     42 	const char *temp_offset;
     43 	const char *self_test;
     44 	//Starting Sysfs available for MPU6050 only
     45 	const char *accel_en;
     46 	const char *accel_fifo_en;
     47 	const char *accel_fs;
     48 	const char *clock_source;
     49 	const char *early_suspend_en;
     50 	const char *firmware_loaded;
     51 	const char *gyro_en;
     52 	const char *gyro_fifo_en;
     53 	const char *key;
     54 	const char *raw_accel;
     55 	const char *reg_dump;
     56 	const char *tap_on;
     57 	const char *dmp_firmware;
     58 };
     59 
     60 /* File IO. Typically won't be called directly by user application, but they'll
     61  * be here for your enjoyment.
     62  */
     63 int inv_sysfs_write(char *filename, long data);
     64 int inv_sysfs_read(char *filename, long num_bytes, char *data);
     65 
     66 /* Helper APIs to extract specific data. */
     67 int inv_read_buffer(int fd, long *data, long long *timestamp);
     68 int inv_read_raw(const struct inv_sysfs_names_s *names, long *data,
     69 		 long long *timestamp);
     70 int inv_read_temperature_raw(const struct inv_sysfs_names_s *names, short *data,
     71 			     long long *timestamp);
     72 int inv_read_fifo_rate(const struct inv_sysfs_names_s *names, short *data);
     73 int inv_read_power_state(const struct inv_sysfs_names_s *names, char *data);
     74 int inv_read_scale(const struct inv_sysfs_names_s *names, float *data);
     75 int inv_read_temp_scale(const struct inv_sysfs_names_s *names, short *data);
     76 int inv_read_temp_offset(const struct inv_sysfs_names_s *names, short *data);
     77 int inv_write_fifo_rate(const struct inv_sysfs_names_s *names, short data);
     78 int inv_write_buffer_enable(const struct inv_sysfs_names_s *names, char data);
     79 int inv_write_power_state(const struct inv_sysfs_names_s *names, char data);
     80 
     81 /* Scaled data. */
     82 int inv_read_q16(const struct inv_sysfs_names_s *names, long *data,
     83                  long long *timestamp);
     84 int inv_read_temp_q16(const struct inv_sysfs_names_s *names, long *data,
     85                       long long *timestamp);
     86 
     87 
     88 #endif  /* #ifndef _INV_SYSFS_UTILS_H_ */
     89 
     90 
     91