Просмотр исходного кода

Added
- Aux FIFO support added
- Self-test issue fixed
- Support for mapping and unmapping interrupt pin for channel 1, 2 and both

Bosch Sensortec 8 лет назад
Родитель
Сommit
f506ded936
5 измененных файлов с 603 добавлено и 432 удалено
  1. 158 12
      README.md
  2. 279 410
      bmi160.c
  3. 45 4
      bmi160.h
  4. 106 3
      bmi160_defs.h
  5. 15 3
      changelog.md

+ 158 - 12
README.md

@@ -7,9 +7,9 @@ The sensor driver package includes bmi160.h, bmi160.c and bmi160_defs.h files
 ## Version
 File          | Version | Date
 --------------|---------|---------------
-bmi160.c      |   3.6.1 |   23 Aug 2017
-bmi160.h      |   3.6.1 |   23 Aug 2017
-bmi160_defs.h |   3.6.1 |   23 Aug 2017
+bmi160.c      |   3.7.2 |   16 Oct 2017
+bmi160.h      |   3.7.2 |   16 Oct 2017
+bmi160_defs.h |   3.7.2 |   16 Oct 2017
 
 ## Integration details
 * Integrate bmi160.h, bmi160_defs.h and bmi160.c file in to your project.
@@ -192,7 +192,6 @@ int_config.int_channel = BMI160_INT_CHANNEL_1;// Interrupt channel/pin 1
 
 /* Select the Interrupt type */
 int_config.int_type = BMI160_ACC_ANY_MOTION_INT;// Choosing Any motion interrupt
-
 /* Select the interrupt channel/pin settings */
 int_config.int_pin_sett.output_en = BMI160_ENABLE;// Enabling interrupt pins to act as output pin
 int_config.int_pin_sett.output_mode = BMI160_DISABLE;// Choosing push-pull mode for interrupt pin
@@ -224,7 +223,6 @@ int_config.int_channel = BMI160_INT_CHANNEL_1;// Interrupt channel/pin 1
 
 /* Select the Interrupt type */
 int_config.int_type = BMI160_ACC_FLAT_INT;// Choosing flat interrupt
-
 /* Select the interrupt channel/pin settings */
 int_config.int_pin_sett.output_en = BMI160_ENABLE;// Enabling interrupt pins to act as output pin
 int_config.int_pin_sett.output_mode = BMI160_DISABLE;// Choosing push-pull mode for interrupt pin
@@ -256,7 +254,6 @@ int_config.int_channel = BMI160_INT_CHANNEL_1;// Interrupt channel/pin 1
 
 /* Select the Interrupt type */
 int_config.int_type = BMI160_STEP_DETECT_INT;// Choosing Step Detector interrupt
-
 /* Select the interrupt channel/pin settings */
 int_config.int_pin_sett.output_en = BMI160_ENABLE;// Enabling interrupt pins to act as output pin
 int_config.int_pin_sett.output_mode = BMI160_DISABLE;// Choosing push-pull mode for interrupt pin
@@ -293,6 +290,33 @@ uint16_t step_count = 0;//stores the step counter value
 
 rslt = bmi160_read_step_counter(&step_count,  &sensor);
 ```
+
+### Unmapping Interrupt
+#### Example for unmapping Step Detector Interrupt
+``` c
+struct bmi160_intr_sett int_config;
+
+/* Deselect the Interrupt channel/pin */
+int_config.int_channel = BMI160_INT_CHANNEL_NONE;
+/* Select the Interrupt type */
+int_config.int_type = BMI160_STEP_DETECT_INT;// Choosing Step Detector interrupt
+/* Set the Step Detector interrupt */
+bmi160_set_intr_config(&int_config, &sensor); /* sensor is an instance of the structure bmi160_dev */
+```
+
+### Reading interrupt status
+#### Example for reading interrupt status for step detector
+``` c
+union bmi160_int_status interrupt;
+enum bmi160_int_status_sel int_status_sel;
+
+/* Interrupt status selection to read all interrupts */
+int_status_sel = BMI160_INT_STATUS_ALL;
+rslt = bmi160_get_int_status(int_status_sel, &interrupt, &sensor);
+if (interrupt.bit.step)
+	printf("Step detector interrupt occured\n");
+```
+
 ### Configuring the auxiliary sensor BMM150
 It is assumed that secondary interface of bmi160 has external pull-up resistor in order to access the auxiliary sensor bmm150.
 
@@ -391,7 +415,8 @@ which helps in creating less latency fusion data
 
 ```
 /* Initialize the Auxiliary BMM150 following the above code 
-   until setting the power mode and preset mode */
+ * until setting the power mode (Set the power mode as forced mode)
+ * and preset mode */
 
 	/* In BMM150 Mag data starts from register address 0x42 */
 	uint8_t aux_addr = 0x42;
@@ -400,13 +425,13 @@ which helps in creating less latency fusion data
 	
 	uint8_t index;
 		
-	/* Set the auxiliary sensor to auto mode */
-	rslt = bmi160_set_aux_auto_mode(&aux_addr, &sensor);
-	
 	/* Configure the Auxiliary sensor either in auto/manual modes and set the 
 	polling frequency for the Auxiliary interface */	
 	sensor.aux_cfg.aux_odr = 8; /* Represents polling rate in 100 Hz*/
 	rslt = bmi160_config_aux_mode(&sensor)
+	
+	/* Set the auxiliary sensor to auto mode */
+	rslt = bmi160_set_aux_auto_mode(&aux_addr, &sensor);
 
 	/* Reading data from BMI160 data registers */
 	rslt = bmi160_read_aux_data_auto_mode(mag_data, &sensor);
@@ -414,17 +439,136 @@ which helps in creating less latency fusion data
 	printf("\n RAW DATA ");
 	for(index = 0 ; index < 8 ; index++)
 	{
-		printf("\n MAG DATA[index] : %d ", index,mag_data[index]);
+		printf("\n MAG DATA[%d] : %d ", index, mag_data[index]);
 	}
 	
 	/* Compensating the raw mag data available from the BMM150 API */
-	rslt = bmm150_aux_mag_data(mag_data,&bmm150);
+	rslt = bmm150_aux_mag_data(mag_data, &bmm150);
 	
 	printf("\n COMPENSATED DATA ");
 	printf("\n MAG DATA X : %d Y : %d Z : %d", bmm150.data.x, bmm150.data.y, bmm150.data.z);
 	
 
 ```
+
+### Auxiliary FIFO data parsing
+The Auxiliary sensor data can be stored in FIFO , Here we demonstrate an example for 
+using the Bosch Magnetometer sensor BMM150 and storing its data in FIFO
+
+```
+/* Initialize the Aux BMM150 following the above 
+ * code and by creating the Wrapper functions */
+
+	int8_t rslt = 0;
+	uint8_t aux_instance = 0;
+	uint16_t fifo_cnt = 0;
+	uint8_t auto_mode_addr;
+	uint8_t i;
+
+	/* Setup and configure the FIFO buffer */
+	/* Declare memory to store the raw FIFO buffer information */
+	uint8_t fifo_buff[1000] = {0};
+
+	/* Modify the FIFO buffer instance and link to the device instance */
+	struct bmi160_fifo_frame fifo_frame;
+	fifo_frame.data = fifo_buff;
+	fifo_frame.length = 1000;
+	dev->fifo = &fifo_frame;
+
+	/* Declare instances of the sensor data structure to store the parsed FIFO data */
+	struct bmi160_aux_data aux_data[112]; //1000 / 9 bytes per frame ~ 111 data frames
+
+	rslt = bmi160_init(dev);
+	printf("\n BMI160 chip ID is : %d ",dev->chip_id);
+
+	rslt = bmi160_aux_init(dev);
+
+	rslt = bmm150_init(&bmm150);
+	printf("\n BMM150 CHIP ID : %d",bmm150.chip_id);
+
+	bmm150.settings.preset_mode = BMM150_PRESETMODE_LOWPOWER;
+	rslt = bmm150_set_presetmode(&bmm150);
+
+	bmm150.settings.pwr_mode = BMM150_FORCED_MODE;
+	rslt = bmm150_set_op_mode(&bmm150);
+
+	/* Enter the data register of BMM150 to "auto_mode_addr" here it is 0x42 */
+	auto_mode_addr = 0x42;
+	printf("\n ENTERING AUX. AUTO MODE ");
+	dev->aux_cfg.aux_odr = BMI160_AUX_ODR_25HZ;
+	rslt = bmi160_set_aux_auto_mode(&auto_mode_addr, dev);
+
+
+	/* Disable other FIFO settings */
+	rslt = bmi160_set_fifo_config(BMI160_FIFO_CONFIG_1_MASK , BMI160_DISABLE, dev);
+
+	/* Enable the required FIFO settings */
+	rslt = bmi160_set_fifo_config(BMI160_FIFO_AUX | BMI160_FIFO_HEADER, BMI160_ENABLE, dev);
+
+	/* Delay for the FIFO to get filled */
+	dev->delay_ms(400);
+
+
+	printf("\n FIFO DATA REQUESTED (in bytes): %d",dev->fifo->length);
+	rslt = bmi160_get_fifo_data(dev);
+	printf("\n FIFO DATA AVAILABLE (in bytes): %d",dev->fifo->length);
+
+	/* Print the raw FIFO data obtained */
+	for(fifo_cnt = 0; fifo_cnt < dev->fifo->length ; fifo_cnt++) {
+		printf("\n FIFO DATA [%d] IS : %x  ",fifo_cnt ,dev->fifo->data[fifo_cnt]);
+	}
+
+	printf("\n\n----------------------------------------------------\n");
+
+	/* Set the number of required sensor data instances */
+	aux_instance = 150;
+
+	/* Extract the aux data , 1frame = 8 data bytes */
+	printf("\n AUX DATA REQUESTED TO BE EXTRACTED (in frames): %d",aux_instance);
+	rslt = bmi160_extract_aux(aux_data, &aux_instance, dev);
+	printf("\n AUX DATA ACTUALLY EXTRACTED (in frames): %d",aux_instance);
+
+	/* Printing the raw aux data */
+	for (i = 0; i < aux_instance; i++) {
+		printf("\n Aux data[%d] : %x",i,aux_data[i].data[0]);
+		printf("\n Aux data[%d] : %x",i,aux_data[i].data[1]);
+		printf("\n Aux data[%d] : %x",i,aux_data[i].data[2]);
+		printf("\n Aux data[%d] : %x",i,aux_data[i].data[3]);
+		printf("\n Aux data[%d] : %x",i,aux_data[i].data[4]);
+		printf("\n Aux data[%d] : %x",i,aux_data[i].data[5]);
+		printf("\n Aux data[%d] : %x",i,aux_data[i].data[6]);
+		printf("\n Aux data[%d] : %x",i,aux_data[i].data[7]);
+	}
+
+	printf("\n\n----------------------------------------------------\n");
+
+	/* Compensate the raw mag data using BMM150 API */
+	for (i = 0; i < aux_instance; i++) {
+		printf("\n----------------------------------------------------");
+		printf("\n Aux data[%d] : %x , %x , %x , %x , %x , %x , %x , %x",i
+					,aux_data[i].data[0],aux_data[i].data[1]
+					,aux_data[i].data[2],aux_data[i].data[3]
+					,aux_data[i].data[4],aux_data[i].data[5]
+					,aux_data[i].data[6],aux_data[i].data[7]);
+
+		/* Compensated mag data using BMM150 API */
+		rslt = bmm150_aux_mag_data(&aux_data[i].data[0], &bmm150);
+
+		/* Printing the  Compensated mag data */
+		if (rslt == BMM150_OK) {
+			printf("\n MAG DATA COMPENSATION USING BMM150 APIs");
+			printf("\n COMPENSATED DATA ");
+			printf("\n MAG DATA X : %d	Y : %d      Z : %d"
+				, bmm150.data.x, bmm150.data.y, bmm150.data.z);
+
+		} else {
+			printf("\n MAG DATA COMPENSATION IN BMM150 API is FAILED ");
+		}
+		printf("\n----------------------------------------------------\n");
+	}
+
+```
+
 ## Self-test  
 #### Example for performing accel self test
 ```
@@ -644,4 +788,6 @@ int8_t write_offsets_nvm(struct bmi160_dev *dev)
 }
 ```
 
+
+
 ## Copyright (C) 2016 - 2017 Bosch Sensortec GmbH

Разница между файлами не показана из-за своего большого размера
+ 279 - 410
bmi160.c


+ 45 - 4
bmi160.h

@@ -40,8 +40,8 @@
  * patent rights of the copyright holder.
  *
  * @file    bmi160.h
- * @date    23 Aug 2017
- * @version 3.6.1
+ * @date    16 Oct 2017
+ * @version 3.7.2
  * @brief
  *
  */
@@ -121,7 +121,7 @@ int8_t bmi160_set_regs(uint8_t reg_addr, uint8_t *data, uint16_t len, const stru
  * @return Result of API execution status
  * @retval zero -> Success / -ve value -> Error.
  */
-int8_t bmi160_soft_reset(const struct bmi160_dev *dev);
+int8_t bmi160_soft_reset(struct bmi160_dev *dev);
 
 /*!
  * @brief This API configures the power mode, range and bandwidth
@@ -496,7 +496,7 @@ int8_t bmi160_extract_accel(struct bmi160_sensor_data *accel_data, uint8_t *acce
  *  FIFO data read by the "bmi160_get_fifo_data" API and stores it in
  *  the "gyro_data" structure instance.
  *
- *  @note The bmi160_extract_accel API should be called only after
+ *  @note The bmi160_extract_gyro API should be called only after
  *  reading the FIFO data by calling the bmi160_get_fifo_data() API.
  *
  *  @param[out] gyro_data    : Structure instance of bmi160_sensor_data
@@ -516,6 +516,31 @@ int8_t bmi160_extract_accel(struct bmi160_sensor_data *accel_data, uint8_t *acce
  */
 int8_t bmi160_extract_gyro(struct bmi160_sensor_data *gyro_data, uint8_t *gyro_length, struct bmi160_dev const *dev);
 
+/*!
+ *  @brief This API parses and extracts the aux frames from
+ *  FIFO data read by the "bmi160_get_fifo_data" API and stores it in
+ *  the bmi160_aux_data structure instance.
+ *
+ *  @note The bmi160_extract_aux API should be called only after
+ *  reading the FIFO data by calling the bmi160_get_fifo_data() API.
+ *
+ *  @param[out] aux_data    : Structure instance of bmi160_aux_data
+ *                            where the aux data in FIFO is stored.
+ *  @param[in,out] aux_len  : Number of valid aux frames (8bytes)
+ *                            read out from FIFO.
+ *  @param[in] dev          : Structure instance of bmi160_dev.
+ *
+ *  @note aux_len is updated with the number of valid aux
+ *  frames extracted from fifo (1 aux frame = 8 bytes) at the end of
+ *  execution of this API.
+ *
+ *  @return Result of API execution status
+ *  @retval 0 -> Success
+ *  @retval Any non zero value -> Fail
+ *
+ */
+int8_t bmi160_extract_aux(struct bmi160_aux_data *aux_data, uint8_t *aux_len, struct bmi160_dev const *dev);
+
 /*!
  *  @brief This API starts the FOC of accel and gyro
  *
@@ -609,6 +634,22 @@ int8_t bmi160_set_offsets(const struct bmi160_foc_conf *foc_conf, const struct b
  */
 int8_t bmi160_update_nvm(struct bmi160_dev const *dev);
 
+/*!
+ *  @brief This API gets the interrupt status from the sensor.
+ *
+ *  @param[in] int_status_sel		: Enum variable to select either individual or all the
+ *  interrupt status bits.
+ *	@param[in] int_status			: pointer variable to get the interrupt status
+ *	from the sensor.
+ *	param[in] dev					: Structure instance of bmi160_dev.
+ *
+ *  @return Result of API execution status
+ *  @retval 0 -> Success
+ *  @retval Any non zero value -> Fail
+ */
+int8_t bmi160_get_int_status(enum bmi160_int_status_sel int_status_sel,
+				union bmi160_int_status *int_status, struct bmi160_dev const *dev);
+
 #ifdef __cplusplus
 }
 #endif

+ 106 - 3
bmi160_defs.h

@@ -40,8 +40,8 @@
  * patent rights of the copyright holder.
  *
  * @file    bmi160_defs.h
- * @date    23 Aug 2017
- * @version 3.6.1
+ * @date    16 Oct 2017
+ * @version 3.7.2
  * @brief
  *
  */
@@ -290,6 +290,7 @@ extern "C"
 #define BMI160_GYRO_DATA_ADDR		UINT8_C(0x0C)
 #define BMI160_ACCEL_DATA_ADDR		UINT8_C(0x12)
 #define BMI160_STATUS_ADDR		UINT8_C(0x1B)
+#define BMI160_INT_STATUS_ADDR		UINT8_C(0x1C)
 #define BMI160_FIFO_LENGTH_ADDR		UINT8_C(0x22)
 #define BMI160_FIFO_DATA_ADDR		UINT8_C(0x24)
 #define BMI160_ACCEL_CONFIG_ADDR	UINT8_C(0x40)
@@ -706,6 +707,95 @@ typedef int8_t (*bmi160_com_fptr_t)(uint8_t dev_addr, uint8_t reg_addr,
 typedef void (*bmi160_delay_fptr_t)(uint32_t period);
 
 /*************************** Data structures *********************************/
+/*!
+ * @brief bmi160 interrupt status selection enum.
+ */
+enum bmi160_int_status_sel {
+	BMI160_INT_STATUS_0 = 1,
+	BMI160_INT_STATUS_1 = 2,
+	BMI160_INT_STATUS_2 = 4,
+	BMI160_INT_STATUS_3 = 8,
+	BMI160_INT_STATUS_ALL = 15
+};
+
+/*!
+ * @brief bmi160 interrupt status bits structure
+ */
+struct bmi160_int_status_bits {
+#if LITTLE_ENDIAN == 1
+	uint32_t step :1;
+	uint32_t sigmot :1;
+	uint32_t anym :1;
+	/* pmu trigger will be handled later */
+	uint32_t pmu_trigger_reserved :1;
+	uint32_t d_tap :1;
+	uint32_t s_tap :1;
+	uint32_t orient :1;
+	uint32_t flat_int :1;
+	uint32_t reserved :2;
+	uint32_t high_g :1;
+	uint32_t low_g :1;
+	uint32_t drdy :1;
+	uint32_t ffull :1;
+	uint32_t fwm :1;
+	uint32_t nomo :1;
+	uint32_t anym_first_x :1;
+	uint32_t anym_first_y :1;
+	uint32_t anym_first_z :1;
+	uint32_t anym_sign :1;
+	uint32_t tap_first_x :1;
+	uint32_t tap_first_y :1;
+	uint32_t tap_first_z :1;
+	uint32_t tap_sign :1;
+	uint32_t high_first_x :1;
+	uint32_t high_first_y :1;
+	uint32_t high_first_z :1;
+	uint32_t high_sign :1;
+	uint32_t orient_1_0 :2;
+	uint32_t orient_2 :1;
+	uint32_t flat :1;
+#elif BIG_ENDIAN == 1
+	uint32_t high_first_x :1;
+	uint32_t high_first_y :1;
+	uint32_t high_first_z :1;
+	uint32_t high_sign :1;
+	uint32_t orient_1_0 :2;
+	uint32_t orient_2 :1;
+	uint32_t flat :1;
+	uint32_t anym_first_x :1;
+	uint32_t anym_first_y :1;
+	uint32_t anym_first_z :1;
+	uint32_t anym_sign :1;
+	uint32_t tap_first_x :1;
+	uint32_t tap_first_y :1;
+	uint32_t tap_first_z :1;
+	uint32_t tap_sign :1;
+	uint32_t reserved :2;
+	uint32_t high_g :1;
+	uint32_t low_g :1;
+	uint32_t drdy :1;
+	uint32_t ffull :1;
+	uint32_t fwm :1;
+	uint32_t nomo :1;
+	uint32_t step :1;
+	uint32_t sigmot :1;
+	uint32_t anym :1;
+	/* pmu trigger will be handled later */
+	uint32_t pmu_trigger_reserved :1;
+	uint32_t d_tap :1;
+	uint32_t s_tap :1;
+	uint32_t orient :1;
+	uint32_t flat_int :1;
+#endif
+};
+
+/*!
+ * @brief bmi160 interrupt status structure
+ */
+union bmi160_int_status {
+	uint8_t data[4];
+	struct bmi160_int_status_bits bit;
+};
 
 /*!
  * @brief bmi160 sensor data structure which comprises of accel data
@@ -721,6 +811,14 @@ struct bmi160_sensor_data {
 	uint32_t sensortime;
 };
 
+/*!
+ * @brief bmi160 aux data structure which comprises of 8 bytes of accel data
+ */
+struct bmi160_aux_data {
+	/*! Auxiliary data */
+	uint8_t data[8];
+};
+
 /*!
  * @brief bmi160 FOC configuration structure
  */
@@ -856,14 +954,19 @@ struct bmi160_aux_cfg {
 	/*! i2c addr of auxiliary sensor */
 	uint8_t aux_i2c_addr;
 };
+
 /*!
  * @brief bmi160 interrupt channel selection structure
  */
 enum bmi160_int_channel {
+	/*! Un-map both channels */
+	BMI160_INT_CHANNEL_NONE,
 	/*! interrupt Channel 1 */
 	BMI160_INT_CHANNEL_1,
 	/*! interrupt Channel 2 */
-	BMI160_INT_CHANNEL_2
+	BMI160_INT_CHANNEL_2,
+	/*! Map both channels */
+	BMI160_INT_CHANNEL_BOTH
 };
 
 enum bmi160_int_types {

+ 15 - 3
changelog.md

@@ -1,13 +1,25 @@
 # Change Log
-All notable changes to bmi160 Sensor API will be documented in this file. 
+All notable changes to bmi160 Sensor API will be documented in this file.
 
-## v3.6.1, 23 Aug 2017
+## v3.7.2, 16 Oct 2017
+#### Added
+	- Aux FIFO support added
+	- Self-test issue fixed
 
+## v3.7.1, 10 Oct 2017
+#### Added
+	- Support for mapping and unmapping interrupt pin for channel 1, 2 and both
+	
+## v3.7.0, 05 Oct 2017
+#### Added
+	- Support for reading interrupt status
+	- Support for mapping and unmapping interrupt pin for channel 1 & 2
+	
+## v3.6.1, 23 Aug 2017
 #### Changed
 * SPI support for FIFO reading and parsing logic update
 
 ## v3.6.0, 04 Aug 2017
-
 #### Added
 * Added interfaces for the following features 
      - FOC

Некоторые файлы не были показаны из-за большого количества измененных файлов