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