Home | History | Annotate | Download | only in include
      1 /*
      2  $License:
      3     Copyright (C) 2011 InvenSense Corporation, All Rights Reserved.
      4  $
      5  */
      6 
      7 #ifndef __MLSL_H__
      8 #define __MLSL_H__
      9 
     10 #ifdef __cplusplus
     11 extern "C" {
     12 #endif
     13 
     14 /**
     15  *  @defgroup   MLSL
     16  *  @brief      Motion Library - Serial Layer.
     17  *              The Motion Library System Layer provides the Motion Library
     18  *              with the communication interface to the hardware.
     19  *
     20  *              The communication interface is assumed to support serial
     21  *              transfers in burst of variable length up to
     22  *              SERIAL_MAX_TRANSFER_SIZE.
     23  *              The default value for SERIAL_MAX_TRANSFER_SIZE is 128 bytes.
     24  *              Transfers of length greater than SERIAL_MAX_TRANSFER_SIZE, will
     25  *              be subdivided in smaller transfers of length <=
     26  *              SERIAL_MAX_TRANSFER_SIZE.
     27  *              The SERIAL_MAX_TRANSFER_SIZE definition can be modified to
     28  *              overcome any host processor transfer size limitation down to
     29  *              1 B, the minimum.
     30  *              An higher value for SERIAL_MAX_TRANSFER_SIZE will favor
     31  *              performance and efficiency while requiring higher resource usage
     32  *              (mostly buffering). A smaller value will increase overhead and
     33  *              decrease efficiency but allows to operate with more resource
     34  *              constrained processor and master serial controllers.
     35  *              The SERIAL_MAX_TRANSFER_SIZE definition can be found in the
     36  *              mlsl.h header file and master serial controllers.
     37  *              The SERIAL_MAX_TRANSFER_SIZE definition can be found in the
     38  *              mlsl.h header file.
     39  *
     40  *  @{
     41  *      @file   mlsl.h
     42  *      @brief  The Motion Library System Layer.
     43  *
     44  */
     45 
     46 /*
     47  * NOTE : to properly support Yamaha compass reads,
     48  *	  the max transfer size should be at least 9 B.
     49  *	  Length in bytes, typically a power of 2 >= 2
     50  */
     51 #define SERIAL_MAX_TRANSFER_SIZE 31
     52 
     53 #ifndef __KERNEL__
     54 /**
     55  *  inv_serial_open() - used to open the serial port.
     56  *  @port	The COM port specification associated with the device in use.
     57  *  @sl_handle	a pointer to the file handle to the serial device to be open
     58  *		for the communication.
     59  *	This port is used to send and receive data to the device.
     60  *
     61  *	This function is called by inv_serial_start().
     62  *	Unlike previous MPL Software releases, explicitly calling
     63  *	inv_serial_start() is mandatory to instantiate the communication
     64  *	with the device.
     65  *
     66  *  returns INV_SUCCESS if successful, a non-zero error code otherwise.
     67  */
     68 int inv_serial_open(char const *port, void **sl_handle);
     69 
     70 /**
     71  *  inv_serial_close() - used to close the serial port.
     72  *  @sl_handle	a file handle to the serial device used for the communication.
     73  *
     74  *	This port is used to send and receive data to the device.
     75  *
     76  *	This function is called by inv_serial_stop().
     77  *	Unlike previous MPL Software releases, explicitly calling
     78  *	inv_serial_stop() is mandatory to properly shut-down the
     79  *	communication with the device.
     80  *
     81  *  returns INV_SUCCESS if successful, a non-zero error code otherwise.
     82  */
     83 int inv_serial_close(void *sl_handle);
     84 
     85 /**
     86  *  inv_serial_reset() - used to reset any buffering the driver may be doing
     87  *  returns INV_SUCCESS if successful, a non-zero error code otherwise.
     88  */
     89 int inv_serial_reset(void *sl_handle);
     90 #endif
     91 
     92 /**
     93  *  inv_serial_single_write() - used to write a single byte of data.
     94  *  @sl_handle		pointer to the serial device used for the communication.
     95  *  @slave_addr		I2C slave address of device.
     96  *  @register_addr	Register address to write.
     97  *  @data		Single byte of data to write.
     98  *
     99  *	It is called by the MPL to write a single byte of data to the MPU.
    100  *
    101  *  returns INV_SUCCESS if successful, a non-zero error code otherwise.
    102  */
    103 int inv_serial_single_write(
    104 	void *sl_handle,
    105 	unsigned char slave_addr,
    106 	unsigned char register_addr,
    107 	unsigned char data);
    108 
    109 /**
    110  *  inv_serial_write() - used to write multiple bytes of data to registers.
    111  *  @sl_handle	a file handle to the serial device used for the communication.
    112  *  @slave_addr	I2C slave address of device.
    113  *  @register_addr	Register address to write.
    114  *  @length	Length of burst of data.
    115  *  @data	Pointer to block of data.
    116  *
    117  *  returns INV_SUCCESS if successful, a non-zero error code otherwise.
    118  */
    119 int inv_serial_write(
    120 	void *sl_handle,
    121 	unsigned char slave_addr,
    122 	unsigned short length,
    123 	unsigned char const *data);
    124 
    125 /**
    126  *  inv_serial_read() - used to read multiple bytes of data from registers.
    127  *  @sl_handle	a file handle to the serial device used for the communication.
    128  *  @slave_addr	I2C slave address of device.
    129  *  @register_addr	Register address to read.
    130  *  @length	Length of burst of data.
    131  *  @data	Pointer to block of data.
    132  *
    133  *  returns INV_SUCCESS == 0 if successful; a non-zero error code otherwise.
    134  */
    135 int inv_serial_read(
    136 	void *sl_handle,
    137 	unsigned char slave_addr,
    138 	unsigned char register_addr,
    139 	unsigned short length,
    140 	unsigned char *data);
    141 
    142 /**
    143  *  inv_serial_read_mem() - used to read multiple bytes of data from the memory.
    144  *	    This should be sent by I2C or SPI.
    145  *
    146  *  @sl_handle	a file handle to the serial device used for the communication.
    147  *  @slave_addr	I2C slave address of device.
    148  *  @mem_addr	The location in the memory to read from.
    149  *  @length	Length of burst data.
    150  *  @data	Pointer to block of data.
    151  *
    152  *  returns INV_SUCCESS == 0 if successful; a non-zero error code otherwise.
    153  */
    154 int inv_serial_read_mem(
    155 	void *sl_handle,
    156 	unsigned char slave_addr,
    157 	unsigned short mem_addr,
    158 	unsigned char bank_reg,
    159 	unsigned char addr_reg,
    160 	unsigned char mem_reg,
    161 	unsigned short length,
    162 	unsigned char *data);
    163 
    164 /**
    165  *  inv_serial_write_mem() - used to write multiple bytes of data to the memory.
    166  *  @sl_handle	a file handle to the serial device used for the communication.
    167  *  @slave_addr	I2C slave address of device.
    168  *  @mem_addr	The location in the memory to write to.
    169  *  @length	Length of burst data.
    170  *  @data	Pointer to block of data.
    171  *
    172  *  returns INV_SUCCESS == 0 if successful; a non-zero error code otherwise.
    173  */
    174 int inv_serial_write_mem(
    175 	void *sl_handle,
    176 	unsigned char slave_addr,
    177 	unsigned short mem_addr,
    178 	unsigned char bank_reg,
    179 	unsigned char addr_reg,
    180 	unsigned char mem_reg,
    181 	unsigned short length,
    182 	unsigned char *data);
    183 
    184 /**
    185  *  inv_serial_read_fifo() - used to read multiple bytes of data from the fifo.
    186  *  @sl_handle	a file handle to the serial device used for the communication.
    187  *  @slave_addr	I2C slave address of device.
    188  *  @length	Length of burst of data.
    189  *  @data	Pointer to block of data.
    190  *
    191  *  returns INV_SUCCESS == 0 if successful; a non-zero error code otherwise.
    192  */
    193 int inv_serial_read_fifo(
    194 	void *sl_handle,
    195 	unsigned char slave_addr,
    196 	unsigned char fifo_reg,
    197 	unsigned short length,
    198 	unsigned char *data);
    199 
    200 /**
    201  *  inv_serial_write_fifo() - used to write multiple bytes of data to the fifo.
    202  *  @sl_handle	a file handle to the serial device used for the communication.
    203  *  @slave_addr	I2C slave address of device.
    204  *  @length	Length of burst of data.
    205  *  @data	Pointer to block of data.
    206  *
    207  *  returns INV_SUCCESS == 0 if successful; a non-zero error code otherwise.
    208  */
    209 int inv_serial_write_fifo(
    210 	void *sl_handle,
    211 	unsigned char slave_addr,
    212 	unsigned char fifo_reg,
    213 	unsigned short length,
    214 	unsigned char const *data);
    215 
    216 #ifndef __KERNEL__
    217 /**
    218  *  inv_serial_read_cfg() - used to get the configuration data.
    219  *  @cfg	Pointer to the configuration data.
    220  *  @len	Length of the configuration data.
    221  *
    222  *		Is called by the MPL to get the configuration data
    223  *		used by the motion library.
    224  *		This data would typically be saved in non-volatile memory.
    225  *
    226  *  returns INV_SUCCESS if successful, a non-zero error code otherwise.
    227  */
    228 int inv_serial_read_cfg(unsigned char *cfg, unsigned int len);
    229 
    230 /**
    231  *  inv_serial_write_cfg() - used to save the configuration data.
    232  *  @cfg	Pointer to the configuration data.
    233  *  @len	Length of the configuration data.
    234  *
    235  *		Is called by the MPL to save the configuration data used by the
    236  *		motion library.
    237  *		This data would typically be saved in non-volatile memory.
    238  *
    239  *  returns INV_SUCCESS if successful, a non-zero error code otherwise.
    240  */
    241 int inv_serial_write_cfg(unsigned char *cfg, unsigned int len);
    242 
    243 /**
    244  *  inv_serial_read_cal() - used to get the calibration data.
    245  *  @cfg	Pointer to the calibration data.
    246  *  @len	Length of the calibration data.
    247  *
    248  *		It is called by the MPL to get the calibration data used by the
    249  *		motion library.
    250  *		This data is typically be saved in non-volatile memory.
    251  *
    252  *  returns INV_SUCCESS if successful, a non-zero error code otherwise.
    253  */
    254 int inv_serial_read_cal(unsigned char *cal, unsigned int len);
    255 
    256 /**
    257  *  inv_serial_write_cal() - used to save the calibration data.
    258  *
    259  *  @cfg	Pointer to the calibration data.
    260  *  @len	Length of the calibration data.
    261  *
    262  *	    It is called by the MPL to save the calibration data used by the
    263  *	    motion library.
    264  *	    This data is typically be saved in non-volatile memory.
    265  *  returns INV_SUCCESS if successful, a non-zero error code otherwise.
    266  */
    267 int inv_serial_write_cal(unsigned char *cal, unsigned int len);
    268 
    269 /**
    270  *  inv_serial_get_cal_length() - Get the calibration length from the storage.
    271  *  @len	lenght to be returned
    272  *
    273  *  returns INV_SUCCESS if successful, a non-zero error code otherwise.
    274  */
    275 int inv_serial_get_cal_length(unsigned int *len);
    276 #endif
    277 #ifdef __cplusplus
    278 }
    279 #endif
    280 /**
    281  * @}
    282  */
    283 #endif				/* __MLSL_H__ */
    284