Da Vinci Firmware 1
Firmware for the DaVinci-M rocket avionics board.
Loading...
Searching...
No Matches
bmp3.c
Go to the documentation of this file.
1
42#include "bmp3.h"
43
44/***************** Static function declarations ******************************/
45
57static int8_t get_calib_data(struct bmp3_dev *dev);
58
67static void parse_calib_data(const uint8_t *reg_data, struct bmp3_dev *dev);
68
81static int8_t get_odr_filter_settings(struct bmp3_settings *settings, struct bmp3_dev *dev);
82
91static void parse_sensor_data(const uint8_t *reg_data, struct bmp3_uncomp_data *uncomp_data);
92
109static int8_t compensate_data(uint8_t sensor_comp,
110 const struct bmp3_uncomp_data *uncomp_data,
111 struct bmp3_data *comp_data,
112 struct bmp3_calib_data *calib_data);
113
114#ifdef BMP3_FLOAT_COMPENSATION
115
130static int8_t compensate_temperature(double *temperature,
131 const struct bmp3_uncomp_data *uncomp_data,
132 struct bmp3_calib_data *calib_data);
133
147static int8_t compensate_pressure(double *pressure,
148 const struct bmp3_uncomp_data *uncomp_data,
149 const struct bmp3_calib_data *calib_data);
150
161static float pow_bmp3(double base, uint8_t power);
162
163#else
164
178static int8_t compensate_temperature(int64_t *temperature,
179 const struct bmp3_uncomp_data *uncomp_data,
180 struct bmp3_calib_data *calib_data);
181
195static int8_t compensate_pressure(uint64_t *pressure,
196 const struct bmp3_uncomp_data *uncomp_data,
197 const struct bmp3_calib_data *calib_data);
198
208static uint32_t pow_bmp3(uint8_t base, uint8_t power);
209
210#endif /* BMP3_FLOAT_COMPENSATION */
211
225static uint8_t are_settings_changed(uint32_t sub_settings, uint32_t settings);
226
239static void interleave_reg_addr(const uint8_t *reg_addr, uint8_t *temp_buff, const uint8_t *reg_data, uint32_t len);
240
255static int8_t set_pwr_ctrl_settings(uint32_t desired_settings,
256 const struct bmp3_settings *settings,
257 struct bmp3_dev *dev);
258
273static int8_t set_odr_filter_settings(uint32_t desired_settings, struct bmp3_settings *settings, struct bmp3_dev *dev);
274
290static int8_t set_int_ctrl_settings(uint32_t desired_settings,
291 const struct bmp3_settings *settings,
292 struct bmp3_dev *dev);
293
308static int8_t set_advance_settings(uint32_t desired_settings, const struct bmp3_settings *settings,
309 struct bmp3_dev *dev);
310
323static void fill_osr_data(uint32_t desired_settings,
324 uint8_t *addr,
325 uint8_t *reg_data,
326 uint8_t *len,
327 const struct bmp3_settings *settings);
328
339static void fill_odr_data(uint8_t *addr, uint8_t *reg_data, uint8_t *len, struct bmp3_settings *settings);
340
351static void fill_filter_data(uint8_t *addr, uint8_t *reg_data, uint8_t *len, const struct bmp3_settings *settings);
352
364static int8_t null_ptr_check(const struct bmp3_dev *dev);
365
374static void parse_sett_data(const uint8_t *reg_data, struct bmp3_settings *settings);
375
384static void parse_pwr_ctrl_settings(const uint8_t *reg_data, struct bmp3_settings *settings);
385
394static void parse_odr_filter_settings(const uint8_t *reg_data, struct bmp3_odr_filter_settings *settings);
395
404static void parse_int_ctrl_settings(const uint8_t *reg_data, struct bmp3_int_ctrl_settings *settings);
405
414static void parse_advance_settings(const uint8_t *reg_data, struct bmp3_adv_settings *settings);
415
427static int8_t validate_normal_mode_settings(struct bmp3_settings *settings, struct bmp3_dev *dev);
428
439static int8_t validate_osr_and_odr_settings(const struct bmp3_settings *settings);
440
450static uint32_t calculate_press_meas_time(const struct bmp3_settings *settings);
451
461static uint32_t calculate_temp_meas_time(const struct bmp3_settings *settings);
462
475static int8_t verify_meas_time_and_odr_duration(uint32_t meas_t, uint32_t odr_duration);
476
487static int8_t put_device_to_sleep(struct bmp3_dev *dev);
488
500static int8_t set_normal_mode(struct bmp3_settings *settings, struct bmp3_dev *dev);
501
513static int8_t write_power_mode(const struct bmp3_settings *settings, struct bmp3_dev *dev);
514
525//static int8_t fill_fifo_config_1(uint16_t desired_settings,
526// const struct bmp3_fifo_settings *fifo_settings,
527// struct bmp3_dev *dev);
528//
530// * @brief This internal API fills the fifo_config_2(fifo_sub_sampling,
531// * data_select) settings in the reg_data variable so as to burst write
532// * in the sensor.
533// *
534// * @param[in] desired_settings : Variable which specifies the settings which
535// * are to be set in the sensor.
536// * @param[in] fifo_settings : Structure instance of bmp3_fifo_settings
537// * @param[in] dev : Structure instance of bmp3_dev
538// */
539//static int8_t fill_fifo_config_2(uint16_t desired_settings,
540// const struct bmp3_fifo_settings *fifo_settings,
541// struct bmp3_dev *dev);
542//
544// * @brief This internal API fills the fifo interrupt control(fwtm_en, ffull_en)
545// * settings in the reg_data variable so as to burst write in the sensor.
546// *
547// * @param[in] desired_settings : Variable which specifies the settings which
548// * are to be set in the sensor.
549// * @param[in] fifo_settings : Structure instance of bmp3_fifo_settings
550// * @param[in] dev : Structure instance of bmp3_dev
551// */
552//static int8_t fill_fifo_int_ctrl(uint16_t desired_settings,
553// const struct bmp3_fifo_settings *fifo_settings,
554// struct bmp3_dev *dev);
555//
557// * @brief This internal API is used to parse the fifo_config_1(fifo_mode,
558// * fifo_stop_on_full, fifo_time_en, fifo_press_en, fifo_temp_en),
559// * fifo_config_2(fifo_subsampling, data_select) and int_ctrl(fwtm_en, ffull_en)
560// * settings and store it in device structure
561// *
562// * @param[in] reg_data : Pointer variable which stores the fifo settings data
563// * read from the sensor.
564// * @param[out] fifo_settings : Structure instance of bmp3_fifo_settings which
565// * contains the fifo settings after parsing.
566// */
567//static void parse_fifo_settings(const uint8_t *reg_data, struct bmp3_fifo_settings *fifo_settings);
568//
570// * @brief This internal API parse the FIFO data frame from the fifo buffer and
571// * fills the byte count, uncompensated pressure and/or temperature data and no
572// * of parsed frames.
573// *
574// * @param[in] header : Pointer variable which stores the fifo settings data
575// * read from the sensor.
576// * @param[in,out] fifo : Structure instance of bmp3_fifo
577// * @param[out] byte_index : Byte count which is incremented according to the
578// * of data.
579// * @param[out] uncomp_data : Uncompensated pressure and/or temperature data
580// * which is stored after parsing fifo buffer data.
581// * @param[out] parsed_frames : Total number of parsed frames.
582// *
583// * @return Result of API execution status.
584// * @retval 0 -> Success
585// * @retval <0 -> Fail
586// */
587//static uint8_t parse_fifo_data_frame(uint8_t header,
588// struct bmp3_fifo_data *fifo,
589// uint16_t *byte_index,
590// struct bmp3_uncomp_data *uncomp_data,
591// uint8_t *parsed_frames);
592//
594// * @brief This internal API unpacks the FIFO data frame from the fifo buffer and
595// * fills the byte count, uncompensated pressure and/or temperature data.
596// *
597// * @param[out] byte_index : Byte count of fifo buffer.
598// * @param[in] fifo_buffer : FIFO buffer from where the temperature and pressure
599// * frames are unpacked.
600// * @param[out] uncomp_data : Uncompensated temperature and pressure data after
601// * unpacking from fifo buffer.
602// */
603//static void unpack_temp_press_frame(uint16_t *byte_index,
604// const uint8_t *fifo_buffer,
605// struct bmp3_uncomp_data *uncomp_data);
606//
608// * @brief This internal API unpacks the FIFO data frame from the fifo buffer and
609// * fills the byte count and uncompensated pressure data.
610// *
611// * @param[out] byte_index : Byte count of fifo buffer.
612// * @param[in] fifo_buffer : FIFO buffer from where the pressure frames are
613// * unpacked.
614// * @param[out] uncomp_data : Uncompensated pressure data after unpacking from
615// * fifo buffer.
616// */
617//static void unpack_press_frame(uint16_t *byte_index, const uint8_t *fifo_buffer, struct bmp3_uncomp_data *uncomp_data);
618//
620// * @brief This internal API unpacks the FIFO data frame from the fifo buffer and
621// * fills the byte count and uncompensated temperature data.
622// *
623// * @param[out] byte_index : Byte count of fifo buffer.
624// * @param[in] fifo_buffer : FIFO buffer from where the temperature frames
625// * are unpacked.
626// * @param[out] uncomp_data : Uncompensated temperature data after unpacking from
627// * fifo buffer.
628// */
629//static void unpack_temp_frame(uint16_t *byte_index, const uint8_t *fifo_buffer, struct bmp3_uncomp_data *uncomp_data);
630//
632// * @brief This internal API unpacks the time frame from the fifo data buffer and
633// * fills the byte count and update the sensor time variable.
634// *
635// * @param[out] byte_index : Byte count of fifo buffer.
636// * @param[in] fifo_buffer : FIFO buffer from where the sensor time frames
637// * are unpacked.
638// * @param[out] sensor_time : Variable used to store the sensor time.
639// */
640//static void unpack_time_frame(uint16_t *byte_index, const uint8_t *fifo_buffer, uint32_t *sensor_time);
641//
643// * @brief This internal API parses the FIFO buffer and gets the header info.
644// *
645// * @param[out] header : Variable used to store the fifo header data.
646// * @param[in] fifo_buffer : FIFO buffer from where the header data is retrieved.
647// * @param[out] byte_index : Byte count of fifo buffer.
648// */
649//static void get_header_info(uint8_t *header, const uint8_t *fifo_buffer, uint16_t *byte_index);
650//
652// * @brief This internal API parses the FIFO data frame from the fifo buffer and
653// * fills uncompensated temperature and/or pressure data.
654// *
655// * @param[in] sensor_comp : Variable used to select either temperature or
656// * pressure or both while parsing the fifo frames.
657// * @param[in] fifo_buffer : FIFO buffer where the temperature or pressure or
658// * both the data to be parsed.
659// * @param[out] uncomp_data : Uncompensated temperature or pressure or both the
660// * data after unpacking from fifo buffer.
661// */
662//static void parse_fifo_sensor_data(uint8_t sensor_comp, const uint8_t *fifo_buffer,
663// struct bmp3_uncomp_data *uncomp_data);
664//
666// * @brief This internal API resets the FIFO buffer, start index,
667// * parsed frame count, configuration change, configuration error and
668// * frame_not_available variables.
669// *
670// * @param[out] fifo : FIFO structure instance where the fifo related variables
671// * are reset.
672// */
673//static void reset_fifo_index(struct bmp3_fifo_data *fifo);
674
686static int8_t get_sensor_status(struct bmp3_status *status, struct bmp3_dev *dev);
687
699static int8_t get_int_status(struct bmp3_status *status, struct bmp3_dev *dev);
700
712static int8_t get_err_status(struct bmp3_status *status, struct bmp3_dev *dev);
713
727//static int8_t convert_frames_to_bytes(uint16_t *watermark_len,
728// const struct bmp3_fifo_data *fifo,
729// const struct bmp3_fifo_settings *fifo_settings);
730
731/****************** Global Function Definitions *******************************/
732
738int8_t bmp3_init(struct bmp3_dev *dev)
739{
740 int8_t rslt;
741 uint8_t chip_id = 0;
742
743 /* Check for null pointer in the device structure */
744 rslt = null_ptr_check(dev);
745
746 /* Proceed if null check is fine */
747 if (rslt == BMP3_OK)
748 {
749 /* Read mechanism according to selected interface */
750 if (dev->intf != BMP3_I2C_INTF)
751 {
752 /* If SPI interface is selected, read extra byte */
753 dev->dummy_byte = 1;
754 }
755 else
756 {
757 /* If I2C interface is selected, no need to read
758 * extra byte */
759 dev->dummy_byte = 0;
760 }
761
762 /* Read the chip-id of bmp3 sensor */
763 rslt = bmp3_get_regs(BMP3_REG_CHIP_ID, &chip_id, 1, dev);
764
765 /* Proceed if everything is fine until now */
766 if (rslt == BMP3_OK)
767 {
768 /* Check for chip id validity */
769 if ((chip_id == BMP3_CHIP_ID) || (chip_id == BMP390_CHIP_ID))
770 {
771 dev->chip_id = chip_id;
772
773 /* Reset the sensor */
774 rslt = bmp3_soft_reset(dev);
775 if (rslt == BMP3_OK)
776 {
777 /* Read the calibration data */
778 rslt = get_calib_data(dev);
779 }
780 }
781 else
782 {
784 }
785 }
786 }
787
788 return rslt;
789}
790
794int8_t bmp3_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, struct bmp3_dev *dev)
795{
796 int8_t rslt;
797 uint32_t idx;
798
799 /* Check for null pointer in the device structure */
800 rslt = null_ptr_check(dev);
801
802 /* Proceed if null check is fine */
803 if ((rslt == BMP3_OK) && (reg_data != NULL))
804 {
805 uint32_t temp_len = len + dev->dummy_byte;
806 uint8_t temp_buff[len + dev->dummy_byte];
807
808 /* If interface selected is SPI */
809 if (dev->intf != BMP3_I2C_INTF)
810 {
811 reg_addr = reg_addr | 0x80;
812
813 /* Read the data from the register */
814 dev->intf_rslt = dev->read(reg_addr, temp_buff, temp_len, dev->intf_ptr);
815 for (idx = 0; idx < len; idx++)
816 {
817 reg_data[idx] = temp_buff[idx + dev->dummy_byte];
818 }
819 }
820 else
821 {
822 /* Read the data using I2C */
823 dev->intf_rslt = dev->read(reg_addr, reg_data, len, dev->intf_ptr);
824 }
825
826 /* Check for communication error */
828 {
829 rslt = BMP3_E_COMM_FAIL;
830 }
831 }
832 else
833 {
834 rslt = BMP3_E_NULL_PTR;
835 }
836
837 return rslt;
838}
839
844int8_t bmp3_set_regs(uint8_t *reg_addr, const uint8_t *reg_data, uint32_t len, struct bmp3_dev *dev)
845{
846 int8_t rslt;
847 uint8_t temp_buff[len * 2];
848 uint32_t temp_len;
849 uint8_t reg_addr_cnt;
850
851 /* Check for null pointer in the device structure */
852 rslt = null_ptr_check(dev);
853
854 /* Check for arguments validity */
855 if ((rslt == BMP3_OK) && (reg_addr != NULL) && (reg_data != NULL))
856 {
857 if (len != 0)
858 {
859 temp_buff[0] = reg_data[0];
860
861 /* If interface selected is SPI */
862 if (dev->intf == BMP3_SPI_INTF)
863 {
864 for (reg_addr_cnt = 0; reg_addr_cnt < len; reg_addr_cnt++)
865 {
866 reg_addr[reg_addr_cnt] = reg_addr[reg_addr_cnt] & 0x7F;
867 }
868 }
869
870 /* Burst write mode */
871 if (len > 1)
872 {
873 /* Interleave register address w.r.t data for
874 * burst write*/
875 interleave_reg_addr(reg_addr, temp_buff, reg_data, len);
876 temp_len = len * 2;
877 }
878 else
879 {
880 temp_len = len;
881 }
882
883 dev->intf_rslt = dev->write(reg_addr[0], temp_buff, temp_len, dev->intf_ptr);
884
885 /* Check for communication error */
887 {
888 rslt = BMP3_E_COMM_FAIL;
889 }
890 }
891 else
892 {
893 rslt = BMP3_E_INVALID_LEN;
894 }
895 }
896 else
897 {
898 rslt = BMP3_E_NULL_PTR;
899 }
900
901 return rslt;
902}
903
909int8_t bmp3_set_sensor_settings(uint32_t desired_settings, struct bmp3_settings *settings, struct bmp3_dev *dev)
910{
911 int8_t rslt = BMP3_OK;
912
913 if (settings != NULL)
914 {
915
916 if (are_settings_changed(BMP3_POWER_CNTL, desired_settings))
917 {
918 /* Set the power control settings */
919 rslt = set_pwr_ctrl_settings(desired_settings, settings, dev);
920 }
921
922 if (are_settings_changed(BMP3_ODR_FILTER, desired_settings))
923 {
924 /* Set the over sampling, ODR and filter settings */
925 rslt = set_odr_filter_settings(desired_settings, settings, dev);
926 }
927
928 if (are_settings_changed(BMP3_INT_CTRL, desired_settings))
929 {
930 /* Set the interrupt control settings */
931 rslt = set_int_ctrl_settings(desired_settings, settings, dev);
932 }
933
934 if (are_settings_changed(BMP3_ADV_SETT, desired_settings))
935 {
936 /* Set the advance settings */
937 rslt = set_advance_settings(desired_settings, settings, dev);
938 }
939 }
940 else
941 {
942 rslt = BMP3_E_NULL_PTR;
943 }
944
945 return rslt;
946}
947
953int8_t bmp3_get_sensor_settings(struct bmp3_settings *settings, struct bmp3_dev *dev)
954{
955 int8_t rslt;
956 uint8_t settings_data[BMP3_LEN_GEN_SETT];
957
958 if (settings != NULL)
959 {
960 rslt = bmp3_get_regs(BMP3_REG_INT_CTRL, settings_data, BMP3_LEN_GEN_SETT, dev);
961
962 if (rslt == BMP3_OK)
963 {
964 /* Parse the settings data */
965 parse_sett_data(settings_data, settings);
966 }
967 }
968 else
969 {
970 rslt = BMP3_E_NULL_PTR;
971 }
972
973 return rslt;
974}
975
982//int8_t bmp3_set_fifo_settings(uint16_t desired_settings,
983// const struct bmp3_fifo_settings *fifo_settings,
984// struct bmp3_dev *dev)
985//{
986// int8_t rslt;
987//
988// /* Check for null pointer in the device structure */
989// rslt = null_ptr_check(dev);
990//
991// /* Proceed if null check is fine */
992// if ((rslt == BMP3_OK) && (fifo_settings != NULL))
993// {
994// if (are_settings_changed(BMP3_FIFO_CONFIG_1, desired_settings))
995// {
996// /* Fill the FIFO config 1 register data */
997// rslt = fill_fifo_config_1(desired_settings, fifo_settings, dev);
998// }
999//
1000// if (are_settings_changed(desired_settings, BMP3_FIFO_CONFIG_2))
1001// {
1002// /* Fill the FIFO config 2 register data */
1003// rslt = fill_fifo_config_2(desired_settings, fifo_settings, dev);
1004// }
1005//
1006// if (are_settings_changed(desired_settings, BMP3_FIFO_INT_CTRL))
1007// {
1008// /* Fill the FIFO interrupt ctrl register data */
1009// rslt = fill_fifo_int_ctrl(desired_settings, fifo_settings, dev);
1010// }
1011// }
1012// else
1013// {
1014// rslt = BMP3_E_NULL_PTR;
1015// }
1016//
1017// return rslt;
1018//}
1019//
1021// * @brief This API gets the fifo_config_1(fifo_mode,
1022// * fifo_stop_on_full, fifo_time_en, fifo_press_en, fifo_temp_en),
1023// * fifo_config_2(fifo_subsampling, data_select) and int_ctrl(fwtm_en, ffull_en)
1024// * settings from the sensor.
1025// */
1026//int8_t bmp3_get_fifo_settings(struct bmp3_fifo_settings *fifo_settings, struct bmp3_dev *dev)
1027//{
1028// int8_t rslt;
1029// uint8_t fifo_sett[3];
1030// uint8_t len = 3;
1031//
1032// /* Proceed if null check is fine */
1033// if (fifo_settings != NULL)
1034// {
1035// rslt = bmp3_get_regs(BMP3_REG_FIFO_CONFIG_1, fifo_sett, len, dev);
1036//
1037// /* Parse the fifo settings */
1038// parse_fifo_settings(fifo_sett, fifo_settings);
1039// }
1040// else
1041// {
1042// rslt = BMP3_E_NULL_PTR;
1043// }
1044//
1045// return rslt;
1046//}
1047//
1049// * @brief This API gets the fifo data from the sensor.
1050// */
1051//int8_t bmp3_get_fifo_data(struct bmp3_fifo_data *fifo,
1052// const struct bmp3_fifo_settings *fifo_settings,
1053// struct bmp3_dev *dev)
1054//{
1055// int8_t rslt;
1056// uint16_t fifo_len;
1057//
1058// if ((fifo != NULL) && (fifo_settings != NULL))
1059// {
1060// reset_fifo_index(fifo);
1061//
1062// /* Get the total number of bytes available in FIFO */
1063// rslt = bmp3_get_fifo_length(&fifo_len, dev);
1064//
1065// if (rslt == BMP3_OK)
1066// {
1067// /* For sensor time frame , add additional overhead bytes */
1068// if (fifo_settings->time_en == TRUE)
1069// {
1070// fifo_len = fifo_len + BMP3_SENSORTIME_OVERHEAD_BYTES;
1071// }
1072//
1073// /* Update the fifo length in the fifo structure */
1074// fifo->byte_count = fifo_len;
1075//
1076// /* Read the fifo data */
1077// rslt = bmp3_get_regs(BMP3_REG_FIFO_DATA, fifo->buffer, fifo_len, dev);
1078// }
1079// }
1080// else
1081// {
1082// rslt = BMP3_E_NULL_PTR;
1083// }
1084//
1085// return rslt;
1086//}
1087//
1089// * @brief This API sets the fifo watermark length according to the frames count
1090// * set by the user in the device structure. Refer below for usage.
1091// */
1092//int8_t bmp3_set_fifo_watermark(const struct bmp3_fifo_data *fifo,
1093// const struct bmp3_fifo_settings *fifo_settings,
1094// struct bmp3_dev *dev)
1095//{
1096// int8_t rslt;
1097// uint8_t reg_data[2];
1098// uint8_t reg_addr[2] = { BMP3_REG_FIFO_WM, BMP3_REG_FIFO_WM + 1 };
1099// uint16_t watermark_len;
1100//
1101// if ((fifo != NULL) && (fifo_settings != NULL))
1102// {
1103// rslt = convert_frames_to_bytes(&watermark_len, fifo, fifo_settings);
1104//
1105// if (rslt == BMP3_OK)
1106// {
1107// reg_data[0] = BMP3_GET_LSB(watermark_len);
1108// reg_data[1] = BMP3_GET_MSB(watermark_len) & 0x01;
1109// rslt = bmp3_set_regs(reg_addr, reg_data, 2, dev);
1110// }
1111// }
1112// else
1113// {
1114// rslt = BMP3_E_NULL_PTR;
1115// }
1116//
1117// return rslt;
1118//}
1119//
1121// * @brief This API sets the fifo watermark length according to the frames count
1122// * set by the user in the device structure. Refer below for usage.
1123// */
1124//int8_t bmp3_get_fifo_watermark(uint16_t *watermark_len, struct bmp3_dev *dev)
1125//{
1126// int8_t rslt;
1127// uint8_t reg_data[2];
1128// uint8_t reg_addr = BMP3_REG_FIFO_WM;
1129//
1130// if (watermark_len != NULL)
1131// {
1132// rslt = bmp3_get_regs(reg_addr, reg_data, 2, dev);
1133// if (rslt == BMP3_OK)
1134// {
1135// *watermark_len = (reg_data[0]) + (reg_data[1] << 8);
1136// }
1137// }
1138// else
1139// {
1140// rslt = BMP3_E_NULL_PTR;
1141// }
1142//
1143// return rslt;
1144//}
1145//
1147// * @brief This API extracts the temperature and/or pressure data from the FIFO
1148// * data which is already read from the fifo.
1149// */
1150//int8_t bmp3_extract_fifo_data(struct bmp3_data *data, struct bmp3_fifo_data *fifo, struct bmp3_dev *dev)
1151//{
1152// int8_t rslt;
1153// uint8_t header;
1154// uint8_t parsed_frames = 0;
1155// uint8_t t_p_frame;
1156// struct bmp3_uncomp_data uncomp_data = { 0 };
1157//
1158// rslt = null_ptr_check(dev);
1159//
1160// if ((rslt == BMP3_OK) && (fifo != NULL) && (data != NULL))
1161// {
1162// uint16_t byte_index = fifo->start_idx;
1163//
1164// while (byte_index < fifo->byte_count)
1165// {
1166// get_header_info(&header, fifo->buffer, &byte_index);
1167// t_p_frame = parse_fifo_data_frame(header, fifo, &byte_index, &uncomp_data, &parsed_frames);
1168//
1169// /* If the frame is pressure and/or temperature data */
1170// if (t_p_frame != FALSE)
1171// {
1172// /* Compensate temperature and pressure data */
1173// rslt = compensate_data(t_p_frame, &uncomp_data, &data[parsed_frames - 1], &dev->calib_data);
1174// }
1175// }
1176//
1177// /* Check if any frames are parsed in FIFO */
1178// if (parsed_frames != 0)
1179// {
1180// /* Update the bytes parsed in the device structure */
1181// fifo->start_idx = byte_index;
1182// fifo->parsed_frames += parsed_frames;
1183// }
1184// else
1185// {
1186// /* No frames are there to parse. It is time to
1187// * read the FIFO, if more frames are needed */
1188// fifo->frame_not_available = TRUE;
1189// }
1190// }
1191// else
1192// {
1193// rslt = BMP3_E_NULL_PTR;
1194// }
1195//
1196// return rslt;
1197//}
1198
1204int8_t bmp3_get_status(struct bmp3_status *status, struct bmp3_dev *dev)
1205{
1206 int8_t rslt;
1207
1208 if (status != NULL)
1209 {
1210 rslt = get_sensor_status(status, dev);
1211
1212 /* Proceed further if the earlier operation is fine */
1213 if (rslt == BMP3_OK)
1214 {
1215 rslt = get_int_status(status, dev);
1216
1217 /* Proceed further if the earlier operation is fine */
1218 if (rslt == BMP3_OK)
1219 {
1220 /* Get the error status */
1221 rslt = get_err_status(status, dev);
1222 }
1223 }
1224 }
1225 else
1226 {
1227 rslt = BMP3_E_NULL_PTR;
1228 }
1229
1230 return rslt;
1231}
1232
1236int8_t bmp3_get_fifo_length(uint16_t *fifo_length, struct bmp3_dev *dev)
1237{
1238 int8_t rslt;
1239 uint8_t reg_data[2];
1240
1241 if (fifo_length != NULL)
1242 {
1243 rslt = bmp3_get_regs(BMP3_REG_FIFO_LENGTH, reg_data, 2, dev);
1244
1245 /* Proceed if read from register is fine */
1246 if (rslt == BMP3_OK)
1247 {
1248 /* Update the fifo length */
1249 *fifo_length = BMP3_CONCAT_BYTES(reg_data[1], reg_data[0]);
1250 }
1251 }
1252 else
1253 {
1254 rslt = BMP3_E_NULL_PTR;
1255 }
1256
1257 return rslt;
1258}
1259
1263int8_t bmp3_soft_reset(struct bmp3_dev *dev)
1264{
1265 int8_t rslt;
1266 uint8_t reg_addr = BMP3_REG_CMD;
1267
1268 /* 0xB6 is the soft reset command */
1269 uint8_t soft_rst_cmd = BMP3_SOFT_RESET;
1270 uint8_t cmd_rdy_status;
1271 uint8_t cmd_err_status;
1272
1273 /* Check for command ready status */
1274 rslt = bmp3_get_regs(BMP3_REG_SENS_STATUS, &cmd_rdy_status, 1, dev);
1275
1276 /* Device is ready to accept new command */
1277 if ((cmd_rdy_status & BMP3_CMD_RDY) && (rslt == BMP3_OK))
1278 {
1279 /* Write the soft reset command in the sensor */
1280 rslt = bmp3_set_regs(&reg_addr, &soft_rst_cmd, 1, dev);
1281
1282 /* Proceed if everything is fine until now */
1283 if (rslt == BMP3_OK)
1284 {
1285 /* Wait for 2 ms */
1286 dev->delay_us(2000, dev->intf_ptr);
1287
1288 /* Read for command error status */
1289 rslt = bmp3_get_regs(BMP3_REG_ERR, &cmd_err_status, 1, dev);
1290
1291 /* check for command error status */
1292 if ((cmd_err_status & BMP3_REG_CMD) || (rslt != BMP3_OK))
1293 {
1294 /* Command not written hence return
1295 * error */
1297 }
1298 }
1299 }
1300
1301 return rslt;
1302}
1303
1307int8_t bmp3_fifo_flush(struct bmp3_dev *dev)
1308{
1309 int8_t rslt;
1310 uint8_t reg_addr = BMP3_REG_CMD;
1311
1312 uint8_t fifo_flush_cmd = BMP3_FIFO_FLUSH;
1313 uint8_t cmd_rdy_status;
1314 uint8_t cmd_err_status;
1315
1316 /* Check for command ready status */
1317 rslt = bmp3_get_regs(BMP3_REG_SENS_STATUS, &cmd_rdy_status, 1, dev);
1318
1319 /* Device is ready to accept new command */
1320 if ((cmd_rdy_status & BMP3_CMD_RDY) && (rslt == BMP3_OK))
1321 {
1322 /* Write the soft reset command in the sensor */
1323 rslt = bmp3_set_regs(&reg_addr, &fifo_flush_cmd, 1, dev);
1324
1325 /* Proceed if everything is fine until now */
1326 if (rslt == BMP3_OK)
1327 {
1328 /* Wait for 2 ms */
1329 dev->delay_us(2000, dev->intf_ptr);
1330
1331 /* Read for command error status */
1332 rslt = bmp3_get_regs(BMP3_REG_ERR, &cmd_err_status, 1, dev);
1333
1334 /* check for command error status */
1335 if ((cmd_err_status & BMP3_REG_CMD) || (rslt != BMP3_OK))
1336 {
1337 /* Command not written hence return
1338 * error */
1340 }
1341 }
1342 }
1343
1344 return rslt;
1345}
1346
1350int8_t bmp3_set_op_mode(struct bmp3_settings *settings, struct bmp3_dev *dev)
1351{
1352 int8_t rslt;
1353 uint8_t last_set_mode;
1354
1355 /* Check for null pointer in the device structure */
1356 rslt = null_ptr_check(dev);
1357
1358 if ((rslt == BMP3_OK) && (settings != NULL))
1359 {
1360 uint8_t curr_mode = settings->op_mode;
1361
1362 rslt = bmp3_get_op_mode(&last_set_mode, dev);
1363
1364 /* If the sensor is not in sleep mode put the device to sleep
1365 * mode */
1366 if ((last_set_mode != BMP3_MODE_SLEEP) && (rslt == BMP3_OK))
1367 {
1368 /* Device should be put to sleep before transiting to
1369 * forced mode or normal mode */
1370 rslt = put_device_to_sleep(dev);
1371
1372 /* Give some time for device to go into sleep mode */
1373 dev->delay_us(5000, dev->intf_ptr);
1374 }
1375
1376 /* Set the power mode */
1377 if (rslt == BMP3_OK)
1378 {
1379 if (curr_mode == BMP3_MODE_NORMAL)
1380 {
1381 /* Set normal mode and validate
1382 * necessary settings */
1383 rslt = set_normal_mode(settings, dev);
1384 }
1385 else if (curr_mode == BMP3_MODE_FORCED)
1386 {
1387 /* Set forced mode */
1388 rslt = write_power_mode(settings, dev);
1389 }
1390 }
1391 }
1392 else
1393 {
1394 rslt = BMP3_E_NULL_PTR;
1395 }
1396
1397 return rslt;
1398}
1399
1403int8_t bmp3_get_op_mode(uint8_t *op_mode, struct bmp3_dev *dev)
1404{
1405 int8_t rslt;
1406
1407 if (op_mode != NULL)
1408 {
1409 /* Read the power mode register */
1410 rslt = bmp3_get_regs(BMP3_REG_PWR_CTRL, op_mode, 1, dev);
1411
1412 /* Assign the power mode in the device structure */
1413 *op_mode = BMP3_GET_BITS(*op_mode, BMP3_OP_MODE);
1414 }
1415 else
1416 {
1417 rslt = BMP3_E_NULL_PTR;
1418 }
1419
1420 return rslt;
1421}
1422
1428int8_t bmp3_get_sensor_data(uint8_t sensor_comp, struct bmp3_data *comp_data, struct bmp3_dev *dev)
1429{
1430 int8_t rslt;
1431
1432 /* Array to store the pressure and temperature data read from
1433 * the sensor */
1434 uint8_t reg_data[BMP3_LEN_P_T_DATA] = { 0 };
1435 struct bmp3_uncomp_data uncomp_data = { 0 };
1436
1437 if (comp_data != NULL)
1438 {
1439 /* Read the pressure and temperature data from the sensor */
1440 rslt = bmp3_get_regs(BMP3_REG_DATA, reg_data, BMP3_LEN_P_T_DATA, dev);
1441
1442 if (rslt == BMP3_OK)
1443 {
1444 /* Parse the read data from the sensor */
1445 parse_sensor_data(reg_data, &uncomp_data);
1446
1447 /* Compensate the pressure/temperature/both data read
1448 * from the sensor */
1449 rslt = compensate_data(sensor_comp, &uncomp_data, comp_data, &dev->calib_data);
1450 }
1451 }
1452 else
1453 {
1454 rslt = BMP3_E_NULL_PTR;
1455 }
1456
1457 return rslt;
1458}
1459
1460/****************** Static Function Definitions *******************************/
1461
1466//static int8_t convert_frames_to_bytes(uint16_t *watermark_len,
1467// const struct bmp3_fifo_data *fifo,
1468// const struct bmp3_fifo_settings *fifo_settings)
1469//{
1470// int8_t rslt = BMP3_OK;
1471//
1472// if ((fifo->req_frames > 0) && (fifo->req_frames <= BMP3_FIFO_MAX_FRAMES))
1473// {
1474// if (fifo_settings->press_en && fifo_settings->temp_en)
1475// {
1476// /* Multiply with pressure and temperature header len */
1477// *watermark_len = fifo->req_frames * BMP3_LEN_P_AND_T_HEADER_DATA;
1478// }
1479// else if (fifo_settings->temp_en || fifo_settings->press_en)
1480// {
1481// /* Multiply with pressure or temperature header len */
1482// *watermark_len = fifo->req_frames * BMP3_LEN_P_OR_T_HEADER_DATA;
1483// }
1484// else
1485// {
1486// /* No sensor is enabled */
1487// rslt = BMP3_W_SENSOR_NOT_ENABLED;
1488// }
1489// }
1490// else
1491// {
1492// /* Required frame count is zero, which is invalid */
1493// rslt = BMP3_W_INVALID_FIFO_REQ_FRAME_CNT;
1494// }
1495//
1496// return rslt;
1497//}
1498//
1500// * @brief This internal API resets the FIFO buffer, start index,
1501// * parsed frame count, configuration change, configuration error and
1502// * frame_not_available variables.
1503// */
1579//
1581// * @brief This internal API unpacks the FIFO data frame from the fifo buffer and
1582// * fills the byte count, uncompensated pressure and/or temperature data.
1583// */
1584//static void unpack_temp_press_frame(uint16_t *byte_index,
1585// const uint8_t *fifo_buffer,
1586// struct bmp3_uncomp_data *uncomp_data)
1587//{
1588// parse_fifo_sensor_data((BMP3_PRESS_TEMP), &fifo_buffer[*byte_index], uncomp_data);
1589// *byte_index = *byte_index + BMP3_LEN_P_T_DATA;
1590//}
1591//
1593// * @brief This internal API unpacks the FIFO data frame from the fifo buffer and
1594// * fills the byte count and uncompensated temperature data.
1595// */
1596//static void unpack_temp_frame(uint16_t *byte_index, const uint8_t *fifo_buffer, struct bmp3_uncomp_data *uncomp_data)
1597//{
1598// parse_fifo_sensor_data(BMP3_TEMP, &fifo_buffer[*byte_index], uncomp_data);
1599// *byte_index = *byte_index + BMP3_LEN_T_DATA;
1600//}
1601//
1603// * @brief This internal API unpacks the FIFO data frame from the fifo buffer and
1604// * fills the byte count and uncompensated pressure data.
1605// */
1606//static void unpack_press_frame(uint16_t *byte_index, const uint8_t *fifo_buffer, struct bmp3_uncomp_data *uncomp_data)
1607//{
1608// parse_fifo_sensor_data(BMP3_PRESS, &fifo_buffer[*byte_index], uncomp_data);
1609// *byte_index = *byte_index + BMP3_LEN_P_DATA;
1610//}
1611//
1613// * @brief This internal API unpacks the time frame from the fifo data buffer and
1614// * fills the byte count and update the sensor time variable.
1615// */
1616//static void unpack_time_frame(uint16_t *byte_index, const uint8_t *fifo_buffer, uint32_t *sensor_time)
1617//{
1618// uint16_t index = *byte_index;
1619// uint32_t xlsb = fifo_buffer[index];
1620// uint32_t lsb = ((uint32_t)fifo_buffer[index + 1]) << 8;
1621// uint32_t msb = ((uint32_t)fifo_buffer[index + 2]) << 16;
1622//
1623// *sensor_time = msb | lsb | xlsb;
1624// *byte_index = *byte_index + BMP3_LEN_SENSOR_TIME;
1625//}
1626//
1628// * @brief This internal API parses the FIFO data frame from the fifo buffer and
1629// * fills uncompensated temperature and/or pressure data.
1630// */
1631//static void parse_fifo_sensor_data(uint8_t sensor_comp, const uint8_t *fifo_buffer,
1632// struct bmp3_uncomp_data *uncomp_data)
1633//{
1634// /* Temporary variables to store the sensor data */
1635// uint32_t data_xlsb;
1636// uint32_t data_lsb;
1637// uint32_t data_msb;
1638//
1639// /* Store the parsed register values for temperature data */
1640// data_xlsb = (uint32_t)fifo_buffer[0];
1641// data_lsb = (uint32_t)fifo_buffer[1] << 8;
1642// data_msb = (uint32_t)fifo_buffer[2] << 16;
1643//
1644// if (sensor_comp == BMP3_TEMP)
1645// {
1646// /* Update uncompensated temperature */
1647// uncomp_data->temperature = data_msb | data_lsb | data_xlsb;
1648// }
1649//
1650// if (sensor_comp == BMP3_PRESS)
1651// {
1652// /* Update uncompensated pressure */
1653// uncomp_data->pressure = data_msb | data_lsb | data_xlsb;
1654// }
1655//
1656// if (sensor_comp == (BMP3_PRESS_TEMP))
1657// {
1658// uncomp_data->temperature = data_msb | data_lsb | data_xlsb;
1659//
1660// /* Store the parsed register values for pressure data */
1661// data_xlsb = (uint32_t)fifo_buffer[3];
1662// data_lsb = (uint32_t)fifo_buffer[4] << 8;
1663// data_msb = (uint32_t)fifo_buffer[5] << 16;
1664// uncomp_data->pressure = data_msb | data_lsb | data_xlsb;
1665// }
1666//}
1667
1671//static void get_header_info(uint8_t *header, const uint8_t *fifo_buffer, uint16_t *byte_index)
1672//{
1673// *header = fifo_buffer[*byte_index];
1674// *byte_index = *byte_index + 1;
1675//}
1676
1680static int8_t set_normal_mode(struct bmp3_settings *settings, struct bmp3_dev *dev)
1681{
1682 int8_t rslt;
1683 uint8_t conf_err_status;
1684
1685 rslt = validate_normal_mode_settings(settings, dev);
1686
1687 /* If OSR and ODR settings are proper then write the power mode */
1688 if (rslt == BMP3_OK)
1689 {
1690 rslt = write_power_mode(settings, dev);
1691
1692 /* check for configuration error */
1693 if (rslt == BMP3_OK)
1694 {
1695 /* Read the configuration error status */
1696 rslt = bmp3_get_regs(BMP3_REG_ERR, &conf_err_status, 1, dev);
1697
1698 /* Check if conf. error flag is set */
1699 if (rslt == BMP3_OK)
1700 {
1701 if (conf_err_status & BMP3_ERR_CONF)
1702 {
1703 /* OSR and ODR configuration is not proper */
1705 }
1706 }
1707 }
1708 }
1709
1710 return rslt;
1711}
1712
1716static int8_t write_power_mode(const struct bmp3_settings *settings, struct bmp3_dev *dev)
1717{
1718 int8_t rslt;
1719 uint8_t reg_addr = BMP3_REG_PWR_CTRL;
1720 uint8_t op_mode = settings->op_mode;
1721
1722 /* Temporary variable to store the value read from op-mode register */
1723 uint8_t op_mode_reg_val;
1724
1725 /* Read the power mode register */
1726 rslt = bmp3_get_regs(reg_addr, &op_mode_reg_val, 1, dev);
1727
1728 /* Set the power mode */
1729 if (rslt == BMP3_OK)
1730 {
1731 op_mode_reg_val = BMP3_SET_BITS(op_mode_reg_val, BMP3_OP_MODE, op_mode);
1732
1733 /* Write the power mode in the register */
1734 rslt = bmp3_set_regs(&reg_addr, &op_mode_reg_val, 1, dev);
1735 }
1736
1737 return rslt;
1738}
1739
1743static int8_t put_device_to_sleep(struct bmp3_dev *dev)
1744{
1745 int8_t rslt;
1746 uint8_t reg_addr = BMP3_REG_PWR_CTRL;
1747
1748 /* Temporary variable to store the value read from op-mode register */
1749 uint8_t op_mode_reg_val;
1750
1751 rslt = bmp3_get_regs(BMP3_REG_PWR_CTRL, &op_mode_reg_val, 1, dev);
1752
1753 if (rslt == BMP3_OK)
1754 {
1755 /* Set the power mode */
1756 op_mode_reg_val = op_mode_reg_val & (~(BMP3_OP_MODE_MSK));
1757
1758 /* Write the power mode in the register */
1759 rslt = bmp3_set_regs(&reg_addr, &op_mode_reg_val, 1, dev);
1760 }
1761
1762 return rslt;
1763}
1764
1768static int8_t validate_normal_mode_settings(struct bmp3_settings *settings, struct bmp3_dev *dev)
1769{
1770 int8_t rslt;
1771
1772 rslt = get_odr_filter_settings(settings, dev);
1773
1774 if (rslt == BMP3_OK)
1775 {
1776 rslt = validate_osr_and_odr_settings(settings);
1777 }
1778
1779 return rslt;
1780}
1781
1786static int8_t get_calib_data(struct bmp3_dev *dev)
1787{
1788 int8_t rslt;
1789 uint8_t reg_addr = BMP3_REG_CALIB_DATA;
1790
1791 /* Array to store calibration data */
1792 uint8_t calib_data[BMP3_LEN_CALIB_DATA] = { 0 };
1793
1794 /* Read the calibration data from the sensor */
1795 rslt = bmp3_get_regs(reg_addr, calib_data, BMP3_LEN_CALIB_DATA, dev);
1796
1797 /* Parse calibration data and store it in device structure */
1798 parse_calib_data(calib_data, dev);
1799
1800 return rslt;
1801}
1802
1807static void interleave_reg_addr(const uint8_t *reg_addr, uint8_t *temp_buff, const uint8_t *reg_data, uint32_t len)
1808{
1809 uint32_t index;
1810
1811 for (index = 1; index < len; index++)
1812 {
1813 temp_buff[(index * 2) - 1] = reg_addr[index];
1814 temp_buff[index * 2] = reg_data[index];
1815 }
1816}
1817
1823static void parse_sett_data(const uint8_t *reg_data, struct bmp3_settings *settings)
1824{
1825 /* Parse interrupt control settings and store in device structure */
1826 parse_int_ctrl_settings(&reg_data[0], &settings->int_settings);
1827
1828 /* Parse advance settings and store in device structure */
1829 parse_advance_settings(&reg_data[1], &settings->adv_settings);
1830
1831 /* Parse power control settings and store in device structure */
1832 parse_pwr_ctrl_settings(&reg_data[2], settings);
1833
1834 /* Parse ODR and filter settings and store in device structure */
1835 parse_odr_filter_settings(&reg_data[3], &settings->odr_filter);
1836}
1837
1842static void parse_int_ctrl_settings(const uint8_t *reg_data, struct bmp3_int_ctrl_settings *settings)
1843{
1844 settings->output_mode = BMP3_GET_BITS_POS_0(*reg_data, BMP3_INT_OUTPUT_MODE);
1845 settings->level = BMP3_GET_BITS(*reg_data, BMP3_INT_LEVEL);
1846 settings->latch = BMP3_GET_BITS(*reg_data, BMP3_INT_LATCH);
1847 settings->drdy_en = BMP3_GET_BITS(*reg_data, BMP3_INT_DRDY_EN);
1848}
1849static void parse_advance_settings(const uint8_t *reg_data, struct bmp3_adv_settings *settings)
1850{
1851 settings->i2c_wdt_en = BMP3_GET_BITS(*reg_data, BMP3_I2C_WDT_EN);
1852 settings->i2c_wdt_sel = BMP3_GET_BITS(*reg_data, BMP3_I2C_WDT_SEL);
1853}
1854
1859static void parse_pwr_ctrl_settings(const uint8_t *reg_data, struct bmp3_settings *settings)
1860{
1861 settings->op_mode = BMP3_GET_BITS(*reg_data, BMP3_OP_MODE);
1862 settings->press_en = BMP3_GET_BITS_POS_0(*reg_data, BMP3_PRESS_EN);
1863 settings->temp_en = BMP3_GET_BITS(*reg_data, BMP3_TEMP_EN);
1864}
1865
1870static void parse_odr_filter_settings(const uint8_t *reg_data, struct bmp3_odr_filter_settings *settings)
1871{
1872 uint8_t index = 0;
1873
1874 /* ODR and filter settings index starts from one (0x1C register) */
1875 settings->press_os = BMP3_GET_BITS_POS_0(reg_data[index], BMP3_PRESS_OS);
1876 settings->temp_os = BMP3_GET_BITS(reg_data[index], BMP3_TEMP_OS);
1877
1878 /* Move index to 0x1D register */
1879 index++;
1880 settings->odr = BMP3_GET_BITS_POS_0(reg_data[index], BMP3_ODR);
1881
1882 /* Move index to 0x1F register */
1883 index = index + 2;
1884 settings->iir_filter = BMP3_GET_BITS(reg_data[index], BMP3_IIR_FILTER);
1885}
1886
1891static int8_t set_pwr_ctrl_settings(uint32_t desired_settings,
1892 const struct bmp3_settings *settings,
1893 struct bmp3_dev *dev)
1894{
1895 int8_t rslt;
1896 uint8_t reg_addr = BMP3_REG_PWR_CTRL;
1897 uint8_t reg_data;
1898
1899 rslt = bmp3_get_regs(reg_addr, &reg_data, 1, dev);
1900
1901 if (rslt == BMP3_OK)
1902 {
1903 if (desired_settings & BMP3_SEL_PRESS_EN)
1904 {
1905 /* Set the pressure enable settings in the
1906 * register variable */
1907 reg_data = BMP3_SET_BITS_POS_0(reg_data, BMP3_PRESS_EN, settings->press_en);
1908 }
1909
1910 if (desired_settings & BMP3_SEL_TEMP_EN)
1911 {
1912 /* Set the temperature enable settings in the
1913 * register variable */
1914 reg_data = BMP3_SET_BITS(reg_data, BMP3_TEMP_EN, settings->temp_en);
1915 }
1916
1917 /* Write the power control settings in the register */
1918 rslt = bmp3_set_regs(&reg_addr, &reg_data, 1, dev);
1919 }
1920
1921 return rslt;
1922}
1923
1928static int8_t set_odr_filter_settings(uint32_t desired_settings, struct bmp3_settings *settings, struct bmp3_dev *dev)
1929{
1930 int8_t rslt;
1931
1932 /* No of registers to be configured is 3*/
1933 uint8_t reg_addr[3] = { 0 };
1934
1935 /* No of register data to be read is 4 */
1936 uint8_t reg_data[4];
1937 uint8_t len = 0;
1938
1939 rslt = bmp3_get_regs(BMP3_REG_OSR, reg_data, 4, dev);
1940
1941 if (rslt == BMP3_OK)
1942 {
1943 if (are_settings_changed((BMP3_SEL_PRESS_OS | BMP3_SEL_TEMP_OS), desired_settings))
1944 {
1945 /* Fill the over sampling register address and
1946 * register data to be written in the sensor */
1947 fill_osr_data(desired_settings, reg_addr, reg_data, &len, settings);
1948 }
1949
1950 if (are_settings_changed(BMP3_SEL_ODR, desired_settings))
1951 {
1952 /* Fill the output data rate register address and
1953 * register data to be written in the sensor */
1954 fill_odr_data(reg_addr, reg_data, &len, settings);
1955 }
1956
1957 if (are_settings_changed(BMP3_SEL_IIR_FILTER, desired_settings))
1958 {
1959 /* Fill the iir filter register address and
1960 * register data to be written in the sensor */
1961 fill_filter_data(reg_addr, reg_data, &len, settings);
1962 }
1963
1964 if (settings->op_mode == BMP3_MODE_NORMAL)
1965 {
1966 /* For normal mode, OSR and ODR settings should
1967 * be proper */
1968 rslt = validate_osr_and_odr_settings(settings);
1969 }
1970
1971 if (rslt == BMP3_OK)
1972 {
1973 /* Burst write the over sampling, ODR and filter
1974 * settings in the register */
1975 rslt = bmp3_set_regs(reg_addr, reg_data, len, dev);
1976 }
1977 }
1978
1979 return rslt;
1980}
1981
1987static int8_t set_int_ctrl_settings(uint32_t desired_settings,
1988 const struct bmp3_settings *settings,
1989 struct bmp3_dev *dev)
1990{
1991 int8_t rslt;
1992 uint8_t reg_data;
1993 uint8_t reg_addr;
1994 struct bmp3_int_ctrl_settings int_settings;
1995
1996 reg_addr = BMP3_REG_INT_CTRL;
1997 rslt = bmp3_get_regs(reg_addr, &reg_data, 1, dev);
1998
1999 if (rslt == BMP3_OK)
2000 {
2001 int_settings = settings->int_settings;
2002
2003 if (desired_settings & BMP3_SEL_OUTPUT_MODE)
2004 {
2005 /* Set the interrupt output mode bits */
2006 reg_data = BMP3_SET_BITS_POS_0(reg_data, BMP3_INT_OUTPUT_MODE, int_settings.output_mode);
2007 }
2008
2009 if (desired_settings & BMP3_SEL_LEVEL)
2010 {
2011 /* Set the interrupt level bits */
2012 reg_data = BMP3_SET_BITS(reg_data, BMP3_INT_LEVEL, int_settings.level);
2013 }
2014
2015 if (desired_settings & BMP3_SEL_LATCH)
2016 {
2017 /* Set the interrupt latch bits */
2018 reg_data = BMP3_SET_BITS(reg_data, BMP3_INT_LATCH, int_settings.latch);
2019 }
2020
2021 if (desired_settings & BMP3_SEL_DRDY_EN)
2022 {
2023 /* Set the interrupt data ready bits */
2024 reg_data = BMP3_SET_BITS(reg_data, BMP3_INT_DRDY_EN, int_settings.drdy_en);
2025 }
2026
2027 rslt = bmp3_set_regs(&reg_addr, &reg_data, 1, dev);
2028 }
2029
2030 return rslt;
2031}
2032
2037static int8_t set_advance_settings(uint32_t desired_settings, const struct bmp3_settings *settings,
2038 struct bmp3_dev *dev)
2039{
2040 int8_t rslt;
2041 uint8_t reg_addr;
2042 uint8_t reg_data;
2043 struct bmp3_adv_settings adv_settings = settings->adv_settings;
2044
2045 reg_addr = BMP3_REG_IF_CONF;
2046 rslt = bmp3_get_regs(reg_addr, &reg_data, 1, dev);
2047
2048 if (rslt == BMP3_OK)
2049 {
2050 if (desired_settings & BMP3_SEL_I2C_WDT_EN)
2051 {
2052 /* Set the i2c watch dog enable bits */
2053 reg_data = BMP3_SET_BITS(reg_data, BMP3_I2C_WDT_EN, adv_settings.i2c_wdt_en);
2054 }
2055
2056 if (desired_settings & BMP3_SEL_I2C_WDT)
2057 {
2058 /* Set the i2c watch dog select bits */
2059 reg_data = BMP3_SET_BITS(reg_data, BMP3_I2C_WDT_SEL, adv_settings.i2c_wdt_sel);
2060 }
2061
2062 rslt = bmp3_set_regs(&reg_addr, &reg_data, 1, dev);
2063 }
2064
2065 return rslt;
2066}
2067
2072static int8_t get_odr_filter_settings(struct bmp3_settings *settings, struct bmp3_dev *dev)
2073{
2074 int8_t rslt;
2075 uint8_t reg_data[4];
2076
2077 /* Read data beginning from 0x1C register */
2078 rslt = bmp3_get_regs(BMP3_REG_OSR, reg_data, 4, dev);
2079
2080 /* Parse the read data and store it in dev structure */
2081 parse_odr_filter_settings(reg_data, &settings->odr_filter);
2082
2083 return rslt;
2084}
2085
2090static int8_t validate_osr_and_odr_settings(const struct bmp3_settings *settings)
2091{
2092 int8_t rslt;
2093
2094 /* According to BMP388 datasheet at Section 3.9.2. "Measurement rate in
2095 * forced mode and normal mode" there is also the constant of 234us also to
2096 * be considered in the sum. */
2097 uint32_t meas_t = 234;
2098 uint32_t meas_t_p = 0;
2099
2100 /* Sampling period corresponding to ODR in microseconds */
2101 uint32_t odr[18] = {
2102 5000, 10000, 20000, 40000, 80000, 160000, 320000, 640000, 1280000, 2560000, 5120000, 10240000, 20480000,
2103 40960000, 81920000, 163840000, 327680000, 655360000
2104 };
2105
2106 if (settings->press_en)
2107 {
2108 /* Calculate the pressure measurement duration */
2109 meas_t_p += calculate_press_meas_time(settings);
2110 }
2111
2112 if (settings->temp_en)
2113 {
2114 /* Calculate the temperature measurement duration */
2115 meas_t_p += calculate_temp_meas_time(settings);
2116 }
2117
2118 /* Constant 234us added to the summation of temperature and pressure measurement duration */
2119 meas_t += meas_t_p;
2120
2121 rslt = verify_meas_time_and_odr_duration(meas_t, odr[settings->odr_filter.odr]);
2122
2123 return rslt;
2124}
2125
2130static int8_t verify_meas_time_and_odr_duration(uint32_t meas_t, uint32_t odr_duration)
2131{
2132 int8_t rslt;
2133
2134 if (meas_t < odr_duration)
2135 {
2136 /* If measurement duration is less than ODR duration
2137 * then OSR and ODR settings are fine */
2138 rslt = BMP3_OK;
2139 }
2140 else
2141 {
2142 /* OSR and ODR settings are not proper */
2144 }
2145
2146 return rslt;
2147}
2148
2153static uint32_t calculate_press_meas_time(const struct bmp3_settings *settings)
2154{
2155 uint32_t press_meas_t;
2156 struct bmp3_odr_filter_settings odr_filter = settings->odr_filter;
2157
2158#ifdef BMP3_FLOAT_COMPENSATION
2159 double base = 2.0;
2160 float partial_out;
2161#else
2162 uint8_t base = 2;
2163 uint32_t partial_out;
2164#endif /* BMP3_FLOAT_COMPENSATION */
2165 partial_out = pow_bmp3(base, odr_filter.press_os);
2166 press_meas_t = (uint32_t)(BMP3_SETTLE_TIME_PRESS + partial_out * BMP3_ADC_CONV_TIME);
2167
2168 /* Output in microseconds */
2169 return press_meas_t;
2170}
2171
2176static uint32_t calculate_temp_meas_time(const struct bmp3_settings *settings)
2177{
2178 uint32_t temp_meas_t;
2179 struct bmp3_odr_filter_settings odr_filter = settings->odr_filter;
2180
2181#ifdef BMP3_FLOAT_COMPENSATION
2182 double base = 2.0;
2183 float partial_out;
2184#else
2185 uint8_t base = 2;
2186 uint32_t partial_out;
2187#endif /* BMP3_FLOAT_COMPENSATION */
2188 partial_out = pow_bmp3(base, odr_filter.temp_os);
2189 temp_meas_t = (uint32_t)(BMP3_SETTLE_TIME_TEMP + partial_out * BMP3_ADC_CONV_TIME);
2190
2191 /* Output in uint32_t */
2192 return temp_meas_t;
2193}
2194
2199static void fill_osr_data(uint32_t desired_settings,
2200 uint8_t *addr,
2201 uint8_t *reg_data,
2202 uint8_t *len,
2203 const struct bmp3_settings *settings)
2204{
2205 struct bmp3_odr_filter_settings osr_settings = settings->odr_filter;
2206
2207 if (desired_settings & (BMP3_SEL_PRESS_OS | BMP3_SEL_TEMP_OS))
2208 {
2209 /* Pressure over sampling settings check */
2210 if (desired_settings & BMP3_SEL_PRESS_OS)
2211 {
2212 /* Set the pressure over sampling settings in the
2213 * register variable */
2214 reg_data[*len] = BMP3_SET_BITS_POS_0(reg_data[0], BMP3_PRESS_OS, osr_settings.press_os);
2215 }
2216
2217 /* Temperature over sampling settings check */
2218 if (desired_settings & BMP3_SEL_TEMP_OS)
2219 {
2220 /* Set the temperature over sampling settings in the
2221 * register variable */
2222 reg_data[*len] = BMP3_SET_BITS(reg_data[0], BMP3_TEMP_OS, osr_settings.temp_os);
2223 }
2224
2225 /* 0x1C is the register address of over sampling register */
2226 addr[*len] = BMP3_REG_OSR;
2227 (*len)++;
2228 }
2229}
2230
2235static void fill_odr_data(uint8_t *addr, uint8_t *reg_data, uint8_t *len, struct bmp3_settings *settings)
2236{
2237 struct bmp3_odr_filter_settings *osr_settings = &settings->odr_filter;
2238
2239 /* Limit the ODR to 0.001525879 Hz*/
2240 if (osr_settings->odr > BMP3_ODR_0_001_HZ)
2241 {
2242 osr_settings->odr = BMP3_ODR_0_001_HZ;
2243 }
2244
2245 /* Set the ODR settings in the register variable */
2246 reg_data[*len] = BMP3_SET_BITS_POS_0(reg_data[1], BMP3_ODR, osr_settings->odr);
2247
2248 /* 0x1D is the register address of output data rate register */
2249 addr[*len] = BMP3_REG_ODR;
2250 (*len)++;
2251}
2252
2257static void fill_filter_data(uint8_t *addr, uint8_t *reg_data, uint8_t *len, const struct bmp3_settings *settings)
2258{
2259 struct bmp3_odr_filter_settings osr_settings = settings->odr_filter;
2260
2261 /* Set the iir settings in the register variable */
2262 reg_data[*len] = BMP3_SET_BITS(reg_data[3], BMP3_IIR_FILTER, osr_settings.iir_filter);
2263
2264 /* 0x1F is the register address of iir filter register */
2265 addr[*len] = BMP3_REG_CONFIG;
2266 (*len)++;
2267}
2268
2273static void parse_sensor_data(const uint8_t *reg_data, struct bmp3_uncomp_data *uncomp_data)
2274{
2275 /* Temporary variables to store the sensor data */
2276 uint32_t data_xlsb;
2277 uint32_t data_lsb;
2278 uint32_t data_msb;
2279
2280 /* Store the parsed register values for pressure data */
2281 data_xlsb = (uint32_t)reg_data[0];
2282 data_lsb = (uint32_t)reg_data[1] << 8;
2283 data_msb = (uint32_t)reg_data[2] << 16;
2284 uncomp_data->pressure = data_msb | data_lsb | data_xlsb;
2285
2286 /* Store the parsed register values for temperature data */
2287 data_xlsb = (uint32_t)reg_data[3];
2288 data_lsb = (uint32_t)reg_data[4] << 8;
2289 data_msb = (uint32_t)reg_data[5] << 16;
2290 uncomp_data->temperature = data_msb | data_lsb | data_xlsb;
2291}
2292
2297static int8_t compensate_data(uint8_t sensor_comp,
2298 const struct bmp3_uncomp_data *uncomp_data,
2299 struct bmp3_data *comp_data,
2300 struct bmp3_calib_data *calib_data)
2301{
2302 int8_t rslt = BMP3_OK;
2303
2304 if ((uncomp_data != NULL) && (comp_data != NULL) && (calib_data != NULL))
2305 {
2306 /* If pressure and temperature component is selected */
2307 if (sensor_comp == BMP3_PRESS_TEMP)
2308 {
2309 /*
2310 * NOTE : Temperature compensation must be done first.
2311 * Followed by pressure compensation
2312 * Compensated temperature updated in calib structure,
2313 * is needed for pressure calculation
2314 */
2315
2316 /* Compensate pressure and temperature data */
2317 rslt = compensate_temperature(&comp_data->temperature, uncomp_data, calib_data);
2318
2319 if (rslt == BMP3_OK)
2320 {
2321 rslt = compensate_pressure(&comp_data->pressure, uncomp_data, calib_data);
2322 }
2323 }
2324 else if (sensor_comp == BMP3_PRESS)
2325 {
2326 /*
2327 * NOTE : Temperature compensation must be done first.
2328 * Followed by pressure compensation
2329 * Compensated temperature updated in calib structure,
2330 * is needed for pressure calculation.
2331 * As only pressure is enabled in 'sensor_comp', after calculating
2332 * compensated temperature, assign it to zero.
2333 */
2334 (void)compensate_temperature(&comp_data->temperature, uncomp_data, calib_data);
2335 comp_data->temperature = 0;
2336
2337 /* Compensate the pressure data */
2338 rslt = compensate_pressure(&comp_data->pressure, uncomp_data, calib_data);
2339 }
2340 else if (sensor_comp == BMP3_TEMP)
2341 {
2342 /* Compensate the temperature data */
2343 rslt = compensate_temperature(&comp_data->temperature, uncomp_data, calib_data);
2344
2345 /*
2346 * As only temperature is enabled in 'sensor_comp'
2347 * make compensated pressure as zero
2348 */
2349 comp_data->pressure = 0;
2350 }
2351 else
2352 {
2353 comp_data->pressure = 0;
2354 comp_data->temperature = 0;
2355 }
2356 }
2357 else
2358 {
2359 rslt = BMP3_E_NULL_PTR;
2360 }
2361
2362 return rslt;
2363}
2364
2365#ifdef BMP3_FLOAT_COMPENSATION
2366
2371static void parse_calib_data(const uint8_t *reg_data, struct bmp3_dev *dev)
2372{
2373 /* Temporary variable to store the aligned trim data */
2374 struct bmp3_reg_calib_data *reg_calib_data = &dev->calib_data.reg_calib_data;
2375 struct bmp3_quantized_calib_data *quantized_calib_data = &dev->calib_data.quantized_calib_data;
2376
2377 /* Temporary variable */
2378 double temp_var;
2379
2380 /* 1 / 2^8 */
2381 temp_var = 0.00390625f;
2382 reg_calib_data->par_t1 = BMP3_CONCAT_BYTES(reg_data[1], reg_data[0]);
2383 quantized_calib_data->par_t1 = ((double)reg_calib_data->par_t1 / temp_var);
2384 reg_calib_data->par_t2 = BMP3_CONCAT_BYTES(reg_data[3], reg_data[2]);
2385 temp_var = 1073741824.0f;
2386 quantized_calib_data->par_t2 = ((double)reg_calib_data->par_t2 / temp_var);
2387 reg_calib_data->par_t3 = (int8_t)reg_data[4];
2388 temp_var = 281474976710656.0f;
2389 quantized_calib_data->par_t3 = ((double)reg_calib_data->par_t3 / temp_var);
2390 reg_calib_data->par_p1 = (int16_t)BMP3_CONCAT_BYTES(reg_data[6], reg_data[5]);
2391 temp_var = 1048576.0f;
2392 quantized_calib_data->par_p1 = ((double)(reg_calib_data->par_p1 - (16384)) / temp_var);
2393 reg_calib_data->par_p2 = (int16_t)BMP3_CONCAT_BYTES(reg_data[8], reg_data[7]);
2394 temp_var = 536870912.0f;
2395 quantized_calib_data->par_p2 = ((double)(reg_calib_data->par_p2 - (16384)) / temp_var);
2396 reg_calib_data->par_p3 = (int8_t)reg_data[9];
2397 temp_var = 4294967296.0f;
2398 quantized_calib_data->par_p3 = ((double)reg_calib_data->par_p3 / temp_var);
2399 reg_calib_data->par_p4 = (int8_t)reg_data[10];
2400 temp_var = 137438953472.0f;
2401 quantized_calib_data->par_p4 = ((double)reg_calib_data->par_p4 / temp_var);
2402 reg_calib_data->par_p5 = BMP3_CONCAT_BYTES(reg_data[12], reg_data[11]);
2403
2404 /* 1 / 2^3 */
2405 temp_var = 0.125f;
2406 quantized_calib_data->par_p5 = ((double)reg_calib_data->par_p5 / temp_var);
2407 reg_calib_data->par_p6 = BMP3_CONCAT_BYTES(reg_data[14], reg_data[13]);
2408 temp_var = 64.0f;
2409 quantized_calib_data->par_p6 = ((double)reg_calib_data->par_p6 / temp_var);
2410 reg_calib_data->par_p7 = (int8_t)reg_data[15];
2411 temp_var = 256.0f;
2412 quantized_calib_data->par_p7 = ((double)reg_calib_data->par_p7 / temp_var);
2413 reg_calib_data->par_p8 = (int8_t)reg_data[16];
2414 temp_var = 32768.0f;
2415 quantized_calib_data->par_p8 = ((double)reg_calib_data->par_p8 / temp_var);
2416 reg_calib_data->par_p9 = (int16_t)BMP3_CONCAT_BYTES(reg_data[18], reg_data[17]);
2417 temp_var = 281474976710656.0f;
2418 quantized_calib_data->par_p9 = ((double)reg_calib_data->par_p9 / temp_var);
2419 reg_calib_data->par_p10 = (int8_t)reg_data[19];
2420 temp_var = 281474976710656.0f;
2421 quantized_calib_data->par_p10 = ((double)reg_calib_data->par_p10 / temp_var);
2422 reg_calib_data->par_p11 = (int8_t)reg_data[20];
2423 temp_var = 36893488147419103232.0f;
2424 quantized_calib_data->par_p11 = ((double)reg_calib_data->par_p11 / temp_var);
2425}
2426
2433static int8_t compensate_temperature(double *temperature,
2434 const struct bmp3_uncomp_data *uncomp_data,
2435 struct bmp3_calib_data *calib_data)
2436{
2437 int8_t rslt = BMP3_OK;
2438 int64_t uncomp_temp = uncomp_data->temperature;
2439 double partial_data1;
2440 double partial_data2;
2441
2442 partial_data1 = (double)(uncomp_temp - calib_data->quantized_calib_data.par_t1);
2443 partial_data2 = (double)(partial_data1 * calib_data->quantized_calib_data.par_t2);
2444
2445 /* Update the compensated temperature in calib structure since this is
2446 * needed for pressure calculation */
2447 calib_data->quantized_calib_data.t_lin = partial_data2 + (partial_data1 * partial_data1) *
2448 calib_data->quantized_calib_data.par_t3;
2449
2450 /* Returns compensated temperature */
2452 {
2454 rslt = BMP3_W_MIN_TEMP;
2455 }
2456
2458 {
2460 rslt = BMP3_W_MAX_TEMP;
2461 }
2462
2463 (*temperature) = calib_data->quantized_calib_data.t_lin;
2464
2465 return rslt;
2466}
2467
2473static int8_t compensate_pressure(double *pressure,
2474 const struct bmp3_uncomp_data *uncomp_data,
2475 const struct bmp3_calib_data *calib_data)
2476{
2477 int8_t rslt = BMP3_OK;
2478 const struct bmp3_quantized_calib_data *quantized_calib_data = &calib_data->quantized_calib_data;
2479
2480 /* Variable to store the compensated pressure */
2481 double comp_press;
2482
2483 /* Temporary variables used for compensation */
2484 double partial_data1;
2485 double partial_data2;
2486 double partial_data3;
2487 double partial_data4;
2488 double partial_out1;
2489 double partial_out2;
2490
2491 partial_data1 = quantized_calib_data->par_p6 * quantized_calib_data->t_lin;
2492 partial_data2 = quantized_calib_data->par_p7 * pow_bmp3(quantized_calib_data->t_lin, 2);
2493 partial_data3 = quantized_calib_data->par_p8 * pow_bmp3(quantized_calib_data->t_lin, 3);
2494 partial_out1 = quantized_calib_data->par_p5 + partial_data1 + partial_data2 + partial_data3;
2495 partial_data1 = quantized_calib_data->par_p2 * quantized_calib_data->t_lin;
2496 partial_data2 = quantized_calib_data->par_p3 * pow_bmp3(quantized_calib_data->t_lin, 2);
2497 partial_data3 = quantized_calib_data->par_p4 * pow_bmp3(quantized_calib_data->t_lin, 3);
2498 partial_out2 = uncomp_data->pressure *
2499 (quantized_calib_data->par_p1 + partial_data1 + partial_data2 + partial_data3);
2500 partial_data1 = pow_bmp3((double)uncomp_data->pressure, 2);
2501 partial_data2 = quantized_calib_data->par_p9 + quantized_calib_data->par_p10 * quantized_calib_data->t_lin;
2502 partial_data3 = partial_data1 * partial_data2;
2503 partial_data4 = partial_data3 + pow_bmp3((double)uncomp_data->pressure, 3) * quantized_calib_data->par_p11;
2504 comp_press = partial_out1 + partial_out2 + partial_data4;
2505
2506 if (comp_press < BMP3_MIN_PRES_DOUBLE)
2507 {
2508 comp_press = BMP3_MIN_PRES_DOUBLE;
2509 rslt = BMP3_W_MIN_PRES;
2510 }
2511
2512 if (comp_press > BMP3_MAX_PRES_DOUBLE)
2513 {
2514 comp_press = BMP3_MAX_PRES_DOUBLE;
2515 rslt = BMP3_W_MAX_PRES;
2516 }
2517
2518 (*pressure) = comp_press;
2519
2520 return rslt;
2521}
2522
2527static float pow_bmp3(double base, uint8_t power)
2528{
2529 float pow_output = 1;
2530
2531 while (power != 0)
2532 {
2533 pow_output = (float) base * pow_output;
2534 power--;
2535 }
2536
2537 return pow_output;
2538}
2539#else
2540
2545static void parse_calib_data(const uint8_t *reg_data, struct bmp3_dev *dev)
2546{
2547 /* Temporary variable to store the aligned trim data */
2548 struct bmp3_reg_calib_data *reg_calib_data = &dev->calib_data.reg_calib_data;
2549
2550 reg_calib_data->par_t1 = BMP3_CONCAT_BYTES(reg_data[1], reg_data[0]);
2551 reg_calib_data->par_t2 = BMP3_CONCAT_BYTES(reg_data[3], reg_data[2]);
2552 reg_calib_data->par_t3 = (int8_t)reg_data[4];
2553 reg_calib_data->par_p1 = (int16_t)BMP3_CONCAT_BYTES(reg_data[6], reg_data[5]);
2554 reg_calib_data->par_p2 = (int16_t)BMP3_CONCAT_BYTES(reg_data[8], reg_data[7]);
2555 reg_calib_data->par_p3 = (int8_t)reg_data[9];
2556 reg_calib_data->par_p4 = (int8_t)reg_data[10];
2557 reg_calib_data->par_p5 = BMP3_CONCAT_BYTES(reg_data[12], reg_data[11]);
2558 reg_calib_data->par_p6 = BMP3_CONCAT_BYTES(reg_data[14], reg_data[13]);
2559 reg_calib_data->par_p7 = (int8_t)reg_data[15];
2560 reg_calib_data->par_p8 = (int8_t)reg_data[16];
2561 reg_calib_data->par_p9 = (int16_t)BMP3_CONCAT_BYTES(reg_data[18], reg_data[17]);
2562 reg_calib_data->par_p10 = (int8_t)reg_data[19];
2563 reg_calib_data->par_p11 = (int8_t)reg_data[20];
2564}
2565
2572static int8_t compensate_temperature(int64_t *temperature,
2573 const struct bmp3_uncomp_data *uncomp_data,
2574 struct bmp3_calib_data *calib_data)
2575{
2576 int8_t rslt = BMP3_OK;
2577 int64_t partial_data1;
2578 int64_t partial_data2;
2579 int64_t partial_data3;
2580 int64_t partial_data4;
2581 int64_t partial_data5;
2582 int64_t partial_data6;
2583 int64_t comp_temp;
2584
2585 partial_data1 = (int64_t)(uncomp_data->temperature - ((int64_t)256 * calib_data->reg_calib_data.par_t1));
2586 partial_data2 = (int64_t)(calib_data->reg_calib_data.par_t2 * partial_data1);
2587 partial_data3 = (int64_t)(partial_data1 * partial_data1);
2588 partial_data4 = (int64_t)partial_data3 * calib_data->reg_calib_data.par_t3;
2589 partial_data5 = (int64_t)((int64_t)(partial_data2 * 262144) + partial_data4);
2590 partial_data6 = (int64_t)(partial_data5 / 4294967296);
2591
2592 /* Store t_lin in dev. structure for pressure calculation */
2593 calib_data->reg_calib_data.t_lin = (int64_t)partial_data6;
2594 comp_temp = (int64_t)((partial_data6 * 25) / 16384);
2595
2596 if (comp_temp < BMP3_MIN_TEMP_INT)
2597 {
2598 comp_temp = BMP3_MIN_TEMP_INT;
2599 rslt = BMP3_W_MIN_TEMP;
2600 }
2601
2602 if (comp_temp > BMP3_MAX_TEMP_INT)
2603 {
2604 comp_temp = BMP3_MAX_TEMP_INT;
2605 rslt = BMP3_W_MAX_TEMP;
2606 }
2607
2608 (*temperature) = comp_temp;
2609
2610 return rslt;
2611}
2612
2618static int8_t compensate_pressure(uint64_t *pressure,
2619 const struct bmp3_uncomp_data *uncomp_data,
2620 const struct bmp3_calib_data *calib_data)
2621{
2622 int8_t rslt = BMP3_OK;
2623 const struct bmp3_reg_calib_data *reg_calib_data = &calib_data->reg_calib_data;
2624 int64_t partial_data1;
2625 int64_t partial_data2;
2626 int64_t partial_data3;
2627 int64_t partial_data4;
2628 int64_t partial_data5;
2629 int64_t partial_data6;
2630 int64_t offset;
2631 int64_t sensitivity;
2632 uint64_t comp_press;
2633
2634 partial_data1 = (int64_t)(reg_calib_data->t_lin * reg_calib_data->t_lin);
2635 partial_data2 = (int64_t)(partial_data1 / 64);
2636 partial_data3 = (int64_t)((partial_data2 * reg_calib_data->t_lin) / 256);
2637 partial_data4 = (int64_t)((reg_calib_data->par_p8 * partial_data3) / 32);
2638 partial_data5 = (int64_t)((reg_calib_data->par_p7 * partial_data1) * 16);
2639 partial_data6 = (int64_t)((reg_calib_data->par_p6 * reg_calib_data->t_lin) * 4194304);
2640 offset = (int64_t)((reg_calib_data->par_p5 * 140737488355328) + partial_data4 + partial_data5 + partial_data6);
2641 partial_data2 = (int64_t)((reg_calib_data->par_p4 * partial_data3) / 32);
2642 partial_data4 = (int64_t)((reg_calib_data->par_p3 * partial_data1) * 4);
2643 partial_data5 = (int64_t)((reg_calib_data->par_p2 - (int32_t)16384) * reg_calib_data->t_lin * 2097152);
2644 sensitivity =
2645 (int64_t)(((reg_calib_data->par_p1 - (int32_t)16384) * 70368744177664) + partial_data2 + partial_data4 +
2646 partial_data5);
2647 partial_data1 = (int64_t)((sensitivity / 16777216) * uncomp_data->pressure);
2648 partial_data2 = (int64_t)(reg_calib_data->par_p10 * reg_calib_data->t_lin);
2649 partial_data3 = (int64_t)(partial_data2 + ((int32_t)65536 * reg_calib_data->par_p9));
2650 partial_data4 = (int64_t)((partial_data3 * uncomp_data->pressure) / (int32_t)8192);
2651
2652 /* dividing by 10 followed by multiplying by 10
2653 * To avoid overflow caused by (uncomp_data->pressure * partial_data4)
2654 */
2655 partial_data5 = (int64_t)((uncomp_data->pressure * (partial_data4 / 10)) / (int32_t)512);
2656 partial_data5 = (int64_t)(partial_data5 * 10);
2657 partial_data6 = (int64_t)(uncomp_data->pressure * uncomp_data->pressure);
2658 partial_data2 = (int64_t)((reg_calib_data->par_p11 * partial_data6) / (int32_t)65536);
2659 partial_data3 = (int64_t)((int64_t)(partial_data2 * uncomp_data->pressure) / 128);
2660 partial_data4 = (int64_t)((offset / 4) + partial_data1 + partial_data5 + partial_data3);
2661 comp_press = (((uint64_t)partial_data4 * 25) / (uint64_t)1099511627776);
2662
2663 if (comp_press < BMP3_MIN_PRES_INT)
2664 {
2665 comp_press = BMP3_MIN_PRES_INT;
2666 rslt = BMP3_W_MIN_PRES;
2667 }
2668
2669 if (comp_press > BMP3_MAX_PRES_INT)
2670 {
2671 comp_press = BMP3_MAX_PRES_INT;
2672 rslt = BMP3_W_MAX_PRES;
2673 }
2674
2675 (*pressure) = comp_press;
2676
2677 return rslt;
2678}
2679
2683static uint32_t pow_bmp3(uint8_t base, uint8_t power)
2684{
2685 uint32_t pow_output = 1;
2686
2687 while (power != 0)
2688 {
2689 pow_output = base * pow_output;
2690 power--;
2691 }
2692
2693 return pow_output;
2694}
2695
2696#endif
2697
2702static uint8_t are_settings_changed(uint32_t sub_settings, uint32_t desired_settings)
2703{
2704 uint8_t settings_changed = FALSE;
2705
2706 if (sub_settings & desired_settings)
2707 {
2708 /* User wants to modify this particular settings */
2709 settings_changed = TRUE;
2710 }
2711 else
2712 {
2713 /* User don't want to modify this particular settings */
2714 settings_changed = FALSE;
2715 }
2716
2717 return settings_changed;
2718}
2719
2724static int8_t null_ptr_check(const struct bmp3_dev *dev)
2725{
2726 int8_t rslt;
2727
2728 if ((dev == NULL) || (dev->read == NULL) || (dev->write == NULL) || (dev->delay_us == NULL) ||
2729 (dev->intf_ptr == NULL))
2730 {
2731 /* Device structure pointer is not valid */
2732 rslt = BMP3_E_NULL_PTR;
2733 }
2734 else
2735 {
2736 /* Device structure is fine */
2737 rslt = BMP3_OK;
2738 }
2739
2740 return rslt;
2741}
2742
2749//static void parse_fifo_settings(const uint8_t *reg_data, struct bmp3_fifo_settings *fifo_settings)
2750//{
2751// uint8_t fifo_config_1_data = reg_data[0];
2752// uint8_t fifo_config_2_data = reg_data[1];
2753// uint8_t fifo_int_ctrl_data = reg_data[2];
2754//
2755// /* Parse fifo config 1 register data */
2756// fifo_settings->mode = BMP3_GET_BITS_POS_0(fifo_config_1_data, BMP3_FIFO_MODE);
2757// fifo_settings->stop_on_full_en = BMP3_GET_BITS(fifo_config_1_data, BMP3_FIFO_STOP_ON_FULL);
2758// fifo_settings->time_en = BMP3_GET_BITS(fifo_config_1_data, BMP3_FIFO_TIME_EN);
2759// fifo_settings->press_en = BMP3_GET_BITS(fifo_config_1_data, BMP3_FIFO_PRESS_EN);
2760// fifo_settings->temp_en = BMP3_GET_BITS(fifo_config_1_data, BMP3_FIFO_TEMP_EN);
2761//
2762// /* Parse fifo config 2 register data */
2763// fifo_settings->down_sampling = BMP3_GET_BITS_POS_0(fifo_config_2_data, BMP3_FIFO_DOWN_SAMPLING);
2764// fifo_settings->filter_en = BMP3_GET_BITS(fifo_config_2_data, BMP3_FIFO_FILTER_EN);
2765//
2766// /* Parse fifo related interrupt control data */
2767// fifo_settings->ffull_en = BMP3_GET_BITS(fifo_int_ctrl_data, BMP3_FIFO_FULL_EN);
2768// fifo_settings->fwtm_en = BMP3_GET_BITS(fifo_int_ctrl_data, BMP3_FIFO_FWTM_EN);
2769//}
2770//
2772// * @brief This internal API fills the fifo_config_1(fifo_mode,
2773// * fifo_stop_on_full, fifo_time_en, fifo_press_en, fifo_temp_en) settings in the
2774// * reg_data variable so as to burst write in the sensor.
2775// */
2776//static int8_t fill_fifo_config_1(uint16_t desired_settings,
2777// const struct bmp3_fifo_settings *fifo_settings,
2778// struct bmp3_dev *dev)
2779//{
2780// int8_t rslt;
2781// uint8_t reg_addr = BMP3_REG_FIFO_CONFIG_1;
2782// uint8_t reg_data;
2783//
2784// rslt = bmp3_get_regs(reg_addr, &reg_data, 1, dev);
2785//
2786// if (rslt == BMP3_OK)
2787// {
2788// if (desired_settings & BMP3_SEL_FIFO_MODE)
2789// {
2790// /* Fill the FIFO mode register data */
2791// reg_data = BMP3_SET_BITS_POS_0(reg_data, BMP3_FIFO_MODE, fifo_settings->mode);
2792// }
2793//
2794// if (desired_settings & BMP3_SEL_FIFO_STOP_ON_FULL_EN)
2795// {
2796// /* Fill the stop on full data */
2797// reg_data = BMP3_SET_BITS(reg_data, BMP3_FIFO_STOP_ON_FULL, fifo_settings->stop_on_full_en);
2798// }
2799//
2800// if (desired_settings & BMP3_SEL_FIFO_TIME_EN)
2801// {
2802// /* Fill the time enable data */
2803// reg_data = BMP3_SET_BITS(reg_data, BMP3_FIFO_TIME_EN, fifo_settings->time_en);
2804// }
2805//
2806// if (desired_settings & (BMP3_SEL_FIFO_PRESS_EN | BMP3_SEL_FIFO_TEMP_EN))
2807// {
2808// /* Fill the pressure enable data */
2809// reg_data = BMP3_SET_BITS(reg_data, BMP3_FIFO_PRESS_EN, fifo_settings->press_en);
2810//
2811// /* Fill the temperature enable data */
2812// reg_data = BMP3_SET_BITS(reg_data, BMP3_FIFO_TEMP_EN, fifo_settings->temp_en);
2813// }
2814//
2815// /* Write the power control settings in the register */
2816// rslt = bmp3_set_regs(&reg_addr, &reg_data, 1, dev);
2817// }
2818//
2819// return rslt;
2820//}
2821//
2823// * @brief This internal API fills the fifo_config_2(fifo_subsampling,
2824// * data_select) settings in the reg_data variable so as to burst write
2825// * in the sensor.
2826// */
2827//static int8_t fill_fifo_config_2(uint16_t desired_settings,
2828// const struct bmp3_fifo_settings *fifo_settings,
2829// struct bmp3_dev *dev)
2830//{
2831// int8_t rslt;
2832// uint8_t reg_addr = BMP3_REG_FIFO_CONFIG_2;
2833// uint8_t reg_data;
2834//
2835// rslt = bmp3_get_regs(reg_addr, &reg_data, 1, dev);
2836//
2837// if (rslt == BMP3_OK)
2838// {
2839// if (desired_settings & BMP3_SEL_FIFO_DOWN_SAMPLING)
2840// {
2841// /* To do check Normal mode */
2842// /* Fill the down-sampling data */
2843// reg_data = BMP3_SET_BITS_POS_0(reg_data, BMP3_FIFO_DOWN_SAMPLING, fifo_settings->down_sampling);
2844// }
2845//
2846// if (desired_settings & BMP3_SEL_FIFO_FILTER_EN)
2847// {
2848// /* Fill the filter enable data */
2849// reg_data = BMP3_SET_BITS(reg_data, BMP3_FIFO_FILTER_EN, fifo_settings->filter_en);
2850// }
2851//
2852// /* Write the power control settings in the register */
2853// rslt = bmp3_set_regs(&reg_addr, &reg_data, 1, dev);
2854// }
2855//
2856// return rslt;
2857//}
2858//
2860// * @brief This internal API fills the fifo interrupt control(fwtm_en, ffull_en)
2861// * settings in the reg_data variable so as to burst write in the sensor.
2862// */
2863//static int8_t fill_fifo_int_ctrl(uint16_t desired_settings,
2864// const struct bmp3_fifo_settings *fifo_settings,
2865// struct bmp3_dev *dev)
2866//{
2867// int8_t rslt;
2868// uint8_t reg_addr = BMP3_REG_INT_CTRL;
2869// uint8_t reg_data;
2870//
2871// rslt = bmp3_get_regs(reg_addr, &reg_data, 1, dev);
2872//
2873// if (rslt == BMP3_OK)
2874// {
2875// if (desired_settings & BMP3_SEL_FIFO_FWTM_EN)
2876// {
2877// /* Fill the FIFO watermark interrupt enable data */
2878// reg_data = BMP3_SET_BITS(reg_data, BMP3_FIFO_FWTM_EN, fifo_settings->fwtm_en);
2879// }
2880//
2881// if (desired_settings & BMP3_SEL_FIFO_FULL_EN)
2882// {
2883// /* Fill the FIFO full interrupt enable data */
2884// reg_data = BMP3_SET_BITS(reg_data, BMP3_FIFO_FULL_EN, fifo_settings->ffull_en);
2885// }
2886//
2887// /* Write the power control settings in the register */
2888// rslt = bmp3_set_regs(&reg_addr, &reg_data, 1, dev);
2889// }
2890//
2891// return rslt;
2892//}
2893
2898static int8_t get_sensor_status(struct bmp3_status *status, struct bmp3_dev *dev)
2899{
2900 int8_t rslt;
2901 uint8_t reg_addr;
2902 uint8_t reg_data;
2903
2904 reg_addr = BMP3_REG_SENS_STATUS;
2905 rslt = bmp3_get_regs(reg_addr, &reg_data, 1, dev);
2906
2907 if (rslt == BMP3_OK)
2908 {
2909 status->sensor.cmd_rdy = BMP3_GET_BITS(reg_data, BMP3_STATUS_CMD_RDY);
2910 status->sensor.drdy_press = BMP3_GET_BITS(reg_data, BMP3_STATUS_DRDY_PRESS);
2911 status->sensor.drdy_temp = BMP3_GET_BITS(reg_data, BMP3_STATUS_DRDY_TEMP);
2912 reg_addr = BMP3_REG_EVENT;
2913 rslt = bmp3_get_regs(reg_addr, &reg_data, 1, dev);
2914 status->pwr_on_rst = reg_data & 0x01;
2915 }
2916
2917 return rslt;
2918}
2919
2924static int8_t get_int_status(struct bmp3_status *status, struct bmp3_dev *dev)
2925{
2926 int8_t rslt;
2927 uint8_t reg_data;
2928
2929 rslt = bmp3_get_regs(BMP3_REG_INT_STATUS, &reg_data, 1, dev);
2930
2931 if (rslt == BMP3_OK)
2932 {
2933 status->intr.fifo_wm = BMP3_GET_BITS_POS_0(reg_data, BMP3_INT_STATUS_FWTM);
2934 status->intr.fifo_full = BMP3_GET_BITS(reg_data, BMP3_INT_STATUS_FFULL);
2935 status->intr.drdy = BMP3_GET_BITS(reg_data, BMP3_INT_STATUS_DRDY);
2936 }
2937
2938 return rslt;
2939}
2940
2945static int8_t get_err_status(struct bmp3_status *status, struct bmp3_dev *dev)
2946{
2947 int8_t rslt;
2948 uint8_t reg_data;
2949
2950 rslt = bmp3_get_regs(BMP3_REG_ERR, &reg_data, 1, dev);
2951
2952 if (rslt == BMP3_OK)
2953 {
2954 status->err.fatal = BMP3_GET_BITS_POS_0(reg_data, BMP3_ERR_FATAL);
2955 status->err.cmd = BMP3_GET_BITS(reg_data, BMP3_ERR_CMD);
2956 status->err.conf = BMP3_GET_BITS(reg_data, BMP3_ERR_CONF);
2957 }
2958
2959 return rslt;
2960}
static int8_t set_advance_settings(uint32_t desired_settings, const struct bmp3_settings *settings, struct bmp3_dev *dev)
This internal API sets the advance (i2c_wdt_en, i2c_wdt_sel) settings of the sensor based on the sett...
Definition bmp3.c:2037
int8_t bmp3_set_sensor_settings(uint32_t desired_settings, struct bmp3_settings *settings, struct bmp3_dev *dev)
This API sets the power control(pressure enable and temperature enable), over sampling,...
Definition bmp3.c:909
static int8_t set_pwr_ctrl_settings(uint32_t desired_settings, const struct bmp3_settings *settings, struct bmp3_dev *dev)
This internal API sets the pressure enable and temperature enable settings of the sensor.
Definition bmp3.c:1891
static int8_t write_power_mode(const struct bmp3_settings *settings, struct bmp3_dev *dev)
This internal API writes the power mode in the sensor.
Definition bmp3.c:1716
static void parse_advance_settings(const uint8_t *reg_data, struct bmp3_adv_settings *settings)
This internal API parse the advance (i2c_wdt_en, i2c_wdt_sel) settings and store in the device struct...
Definition bmp3.c:1849
static int8_t validate_osr_and_odr_settings(const struct bmp3_settings *settings)
This internal API validate the over sampling, ODR settings of the sensor.
Definition bmp3.c:2090
static int8_t get_err_status(struct bmp3_status *status, struct bmp3_dev *dev)
This API gets the fatal, command and configuration error from the sensor.
Definition bmp3.c:2945
static void parse_calib_data(const uint8_t *reg_data, struct bmp3_dev *dev)
This internal API is used to parse the calibration data, compensates it and store it in device struct...
Definition bmp3.c:2545
static void parse_sensor_data(const uint8_t *reg_data, struct bmp3_uncomp_data *uncomp_data)
This internal API is used to parse the pressure and temperature data and store it in the bmp3_uncomp_...
Definition bmp3.c:2273
static int8_t set_normal_mode(struct bmp3_settings *settings, struct bmp3_dev *dev)
This internal API sets the normal mode in the sensor.
Definition bmp3.c:1680
static int8_t get_int_status(struct bmp3_status *status, struct bmp3_dev *dev)
This API gets the interrupt (fifo watermark, fifo full, data ready) status from the sensor.
Definition bmp3.c:2924
static void fill_osr_data(uint32_t desired_settings, uint8_t *addr, uint8_t *reg_data, uint8_t *len, const struct bmp3_settings *settings)
This internal API fills the register address and register data of the the over sampling settings for ...
Definition bmp3.c:2199
static int8_t get_calib_data(struct bmp3_dev *dev)
This internal API reads the calibration data from the sensor, parse it then compensates it and store ...
Definition bmp3.c:1786
int8_t bmp3_set_op_mode(struct bmp3_settings *settings, struct bmp3_dev *dev)
This API sets the power mode of the sensor.
Definition bmp3.c:1350
static int8_t get_odr_filter_settings(struct bmp3_settings *settings, struct bmp3_dev *dev)
This internal API gets the over sampling, ODR and filter settings from the sensor.
Definition bmp3.c:2072
static void fill_filter_data(uint8_t *addr, uint8_t *reg_data, uint8_t *len, const struct bmp3_settings *settings)
This internal API fills the register address and register data of the the filter settings for burst w...
Definition bmp3.c:2257
static int8_t put_device_to_sleep(struct bmp3_dev *dev)
This internal API puts the device to sleep mode.
Definition bmp3.c:1743
static int8_t compensate_pressure(uint64_t *pressure, const struct bmp3_uncomp_data *uncomp_data, const struct bmp3_calib_data *calib_data)
This internal API is used to compensate the pressure data and return the compensated pressure data in...
Definition bmp3.c:2618
static int8_t get_sensor_status(struct bmp3_status *status, struct bmp3_dev *dev)
This internal API fills the fifo_config_1(fifo_mode, fifo_stop_on_full, fifo_time_en,...
Definition bmp3.c:2898
int8_t bmp3_get_status(struct bmp3_status *status, struct bmp3_dev *dev)
This API sets the fifo_config_1(fifo_mode, fifo_stop_on_full, fifo_time_en, fifo_press_en,...
Definition bmp3.c:1204
static void parse_pwr_ctrl_settings(const uint8_t *reg_data, struct bmp3_settings *settings)
This internal API parse the power control(power mode, pressure enable and temperature enable) setting...
Definition bmp3.c:1859
static int8_t compensate_data(uint8_t sensor_comp, const struct bmp3_uncomp_data *uncomp_data, struct bmp3_data *comp_data, struct bmp3_calib_data *calib_data)
This internal API is used to compensate the pressure or temperature or both the data according to the...
Definition bmp3.c:2297
static int8_t verify_meas_time_and_odr_duration(uint32_t meas_t, uint32_t odr_duration)
This internal API checks whether the measurement time and ODR duration of the sensor are proper.
Definition bmp3.c:2130
int8_t bmp3_get_sensor_data(uint8_t sensor_comp, struct bmp3_data *comp_data, struct bmp3_dev *dev)
This API reads the pressure, temperature or both data from the sensor, compensates the data and store...
Definition bmp3.c:1428
static void parse_int_ctrl_settings(const uint8_t *reg_data, struct bmp3_int_ctrl_settings *settings)
This internal API parse the interrupt control(output mode, level, latch and data ready) settings and ...
Definition bmp3.c:1842
static int8_t compensate_temperature(int64_t *temperature, const struct bmp3_uncomp_data *uncomp_data, struct bmp3_calib_data *calib_data)
This internal API is used to compensate the raw temperature data and return the compensated temperatu...
Definition bmp3.c:2572
static int8_t null_ptr_check(const struct bmp3_dev *dev)
This internal API is used to validate the device pointer for null conditions.
Definition bmp3.c:2724
int8_t bmp3_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, struct bmp3_dev *dev)
This API reads the data from the given register address of the sensor.
Definition bmp3.c:794
static uint8_t are_settings_changed(uint32_t sub_settings, uint32_t settings)
This internal API is used to identify the settings which the user wants to modify in the sensor.
Definition bmp3.c:2702
static void interleave_reg_addr(const uint8_t *reg_addr, uint8_t *temp_buff, const uint8_t *reg_data, uint32_t len)
This internal API interleaves the register address between the register data buffer for burst write o...
Definition bmp3.c:1807
static int8_t validate_normal_mode_settings(struct bmp3_settings *settings, struct bmp3_dev *dev)
This internal API validate the normal mode settings of the sensor.
Definition bmp3.c:1768
int8_t bmp3_get_op_mode(uint8_t *op_mode, struct bmp3_dev *dev)
This API gets the power mode of the sensor.
Definition bmp3.c:1403
static uint32_t pow_bmp3(uint8_t base, uint8_t power)
This internal API is used to calculate the power functionality.
Definition bmp3.c:2683
static int8_t set_int_ctrl_settings(uint32_t desired_settings, const struct bmp3_settings *settings, struct bmp3_dev *dev)
This internal API sets the interrupt control (output mode, level, latch and data ready) settings of t...
Definition bmp3.c:1987
int8_t bmp3_fifo_flush(struct bmp3_dev *dev)
This API performs the soft reset of the sensor.
Definition bmp3.c:1307
static int8_t set_odr_filter_settings(uint32_t desired_settings, struct bmp3_settings *settings, struct bmp3_dev *dev)
This internal API sets the over sampling, ODR and filter settings of the sensor based on the settings...
Definition bmp3.c:1928
static void fill_odr_data(uint8_t *addr, uint8_t *reg_data, uint8_t *len, struct bmp3_settings *settings)
This internal API fills the register address and register data of the the ODR settings for burst writ...
Definition bmp3.c:2235
int8_t bmp3_set_regs(uint8_t *reg_addr, const uint8_t *reg_data, uint32_t len, struct bmp3_dev *dev)
This API writes the given data to the register address of the sensor.
Definition bmp3.c:844
static uint32_t calculate_temp_meas_time(const struct bmp3_settings *settings)
This internal API calculates the temperature measurement duration of the sensor.
Definition bmp3.c:2176
int8_t bmp3_soft_reset(struct bmp3_dev *dev)
This API performs the soft reset of the sensor.
Definition bmp3.c:1263
static void parse_odr_filter_settings(const uint8_t *reg_data, struct bmp3_odr_filter_settings *settings)
This internal API parse the over sampling, ODR and filter settings and store in the device structure.
Definition bmp3.c:1870
int8_t bmp3_get_fifo_length(uint16_t *fifo_length, struct bmp3_dev *dev)
This API gets the fifo length from the sensor.
Definition bmp3.c:1236
static void parse_sett_data(const uint8_t *reg_data, struct bmp3_settings *settings)
This internal API parse the power control(power mode, pressure enable and temperature enable),...
Definition bmp3.c:1823
int8_t bmp3_get_sensor_settings(struct bmp3_settings *settings, struct bmp3_dev *dev)
This API gets the power control(power mode, pressure enable and temperature enable),...
Definition bmp3.c:953
static uint32_t calculate_press_meas_time(const struct bmp3_settings *settings)
This internal API calculates the pressure measurement duration of the sensor.
Definition bmp3.c:2153
int8_t bmp3_init(struct bmp3_dev *dev)
This internal API converts the no. of frames required by the user to bytes so as to write in the wate...
Definition bmp3.c:738
#define NULL
Definition bmp3_defs.h:88
#define BMP3_REG_PWR_CTRL
Definition bmp3_defs.h:158
#define BMP3_SEL_I2C_WDT
Definition bmp3_defs.h:292
#define BMP3_PRESS
Definition bmp3_defs.h:311
#define BMP3_MIN_TEMP_DOUBLE
Definition bmp3_defs.h:318
#define BMP3_POWER_CNTL
Definition bmp3_defs.h:450
#define BMP3_REG_CMD
Definition bmp3_defs.h:163
#define BMP3_ADV_SETT
Definition bmp3_defs.h:459
#define BMP3_REG_ODR
Definition bmp3_defs.h:160
#define BMP3_INTF_RET_SUCCESS
Definition bmp3_defs.h:124
#define BMP3_TEMP
Definition bmp3_defs.h:312
@ BMP3_SPI_INTF
Definition bmp3_defs.h:505
@ BMP3_I2C_INTF
Definition bmp3_defs.h:507
#define BMP3_MAX_TEMP_INT
Definition bmp3_defs.h:317
#define BMP3_SEL_OUTPUT_MODE
Definition bmp3_defs.h:288
#define BMP3_SETTLE_TIME_TEMP
Definition bmp3_defs.h:139
#define BMP3_GET_BITS_POS_0(reg_data, bitname)
Definition bmp3_defs.h:433
#define BMP3_SEL_LEVEL
Definition bmp3_defs.h:289
#define BMP3_SEL_DRDY_EN
Definition bmp3_defs.h:283
#define BMP3_ADC_CONV_TIME
Definition bmp3_defs.h:142
#define BMP3_REG_IF_CONF
Definition bmp3_defs.h:157
#define BMP3_MAX_PRES_INT
Definition bmp3_defs.h:323
#define BMP3_E_COMM_FAIL
Definition bmp3_defs.h:262
#define BMP3_LEN_P_T_DATA
Definition bmp3_defs.h:442
#define BMP3_MIN_PRES_INT
Definition bmp3_defs.h:322
#define BMP3_REG_SENS_STATUS
Definition bmp3_defs.h:147
#define BMP3_REG_CONFIG
Definition bmp3_defs.h:161
#define BMP3_W_MAX_TEMP
Definition bmp3_defs.h:274
#define BMP3_W_MAX_PRES
Definition bmp3_defs.h:276
#define BMP3_MAX_TEMP_DOUBLE
Definition bmp3_defs.h:319
#define BMP3_SEL_ODR
Definition bmp3_defs.h:287
#define BMP3_CMD_RDY
Definition bmp3_defs.h:171
#define BMP3_ERR_CONF
Definition bmp3_defs.h:168
#define BMP3_SEL_I2C_WDT_EN
Definition bmp3_defs.h:291
#define BMP3_REG_OSR
Definition bmp3_defs.h:159
#define BMP3_REG_FIFO_LENGTH
Definition bmp3_defs.h:151
#define BMP3_CHIP_ID
Definition bmp3_defs.h:132
#define BMP3_MIN_PRES_DOUBLE
Definition bmp3_defs.h:324
#define BMP3_FIFO_FLUSH
Definition bmp3_defs.h:255
#define TRUE
Definition bmp3_defs.h:93
#define FALSE
Definition bmp3_defs.h:97
#define BMP3_ERR_CMD
Definition bmp3_defs.h:167
#define BMP3_REG_INT_STATUS
Definition bmp3_defs.h:150
#define BMP3_REG_DATA
Definition bmp3_defs.h:148
#define BMP3_REG_EVENT
Definition bmp3_defs.h:149
#define BMP3_SOFT_RESET
Definition bmp3_defs.h:252
#define BMP3_OK
Definition bmp3_defs.h:258
#define BMP3_E_CONFIGURATION_ERR
Definition bmp3_defs.h:265
#define BMP3_PRESS_TEMP
Definition bmp3_defs.h:313
#define BMP3_MAX_PRES_DOUBLE
Definition bmp3_defs.h:325
#define BMP3_INT_CTRL
Definition bmp3_defs.h:456
#define BMP3_E_NULL_PTR
Definition bmp3_defs.h:261
#define BMP3_LEN_GEN_SETT
Definition bmp3_defs.h:443
#define BMP3_E_INVALID_ODR_OSR_SETTINGS
Definition bmp3_defs.h:263
#define BMP3_LEN_CALIB_DATA
Definition bmp3_defs.h:439
#define BMP3_SEL_PRESS_EN
Definition bmp3_defs.h:281
#define BMP3_SEL_IIR_FILTER
Definition bmp3_defs.h:286
#define BMP3_W_MIN_TEMP
Definition bmp3_defs.h:273
#define BMP3_CONCAT_BYTES(msb, lsb)
Definition bmp3_defs.h:418
#define BMP3_REG_INT_CTRL
Definition bmp3_defs.h:156
#define BMP3_GET_BITS(reg_data, bitname)
Definition bmp3_defs.h:429
#define BMP3_SETTLE_TIME_PRESS
Definition bmp3_defs.h:136
#define BMP3_MIN_TEMP_INT
Definition bmp3_defs.h:316
#define BMP3_ODR_0_001_HZ
Definition bmp3_defs.h:249
#define BMP3_E_DEV_NOT_FOUND
Definition bmp3_defs.h:267
#define BMP3_REG_CALIB_DATA
Definition bmp3_defs.h:162
#define BMP3_SEL_LATCH
Definition bmp3_defs.h:290
#define BMP3_SEL_PRESS_OS
Definition bmp3_defs.h:284
#define BMP3_MODE_FORCED
Definition bmp3_defs.h:177
#define BMP3_SEL_TEMP_EN
Definition bmp3_defs.h:282
#define BMP3_ERR_FATAL
Definition bmp3_defs.h:166
#define BMP3_MODE_SLEEP
Definition bmp3_defs.h:176
#define BMP3_REG_CHIP_ID
Definition bmp3_defs.h:145
#define BMP3_SET_BITS(reg_data, bitname, data)
Definition bmp3_defs.h:420
#define BMP3_SEL_TEMP_OS
Definition bmp3_defs.h:285
#define BMP3_W_MIN_PRES
Definition bmp3_defs.h:275
#define BMP3_ODR_FILTER
Definition bmp3_defs.h:453
#define BMP3_REG_ERR
Definition bmp3_defs.h:146
#define BMP3_SET_BITS_POS_0(reg_data, bitname, data)
Definition bmp3_defs.h:425
#define BMP390_CHIP_ID
Definition bmp3_defs.h:133
#define BMP3_E_INVALID_LEN
Definition bmp3_defs.h:266
#define BMP3_MODE_NORMAL
Definition bmp3_defs.h:178
#define BMP3_E_CMD_EXEC_FAILED
Definition bmp3_defs.h:264
#define BMP3_OP_MODE_MSK
Definition bmp3_defs.h:345
bmp3 advance settings
Definition bmp3_defs.h:589
uint8_t i2c_wdt_sel
Definition bmp3_defs.h:594
Calibration data.
Definition bmp3_defs.h:828
struct bmp3_reg_calib_data reg_calib_data
Definition bmp3_defs.h:833
struct bmp3_quantized_calib_data quantized_calib_data
Definition bmp3_defs.h:830
bmp3 sensor structure which comprises of temperature and pressure data.
Definition bmp3_defs.h:842
double pressure
Definition bmp3_defs.h:847
double temperature
Definition bmp3_defs.h:844
bmp3 device structure
Definition bmp3_defs.h:895
bmp3_read_fptr_t read
Definition bmp3_defs.h:920
BMP3_INTF_RET_TYPE intf_rslt
Definition bmp3_defs.h:914
bmp3_write_fptr_t write
Definition bmp3_defs.h:923
uint8_t chip_id
Definition bmp3_defs.h:897
enum bmp3_intf intf
Definition bmp3_defs.h:911
struct bmp3_calib_data calib_data
Definition bmp3_defs.h:929
bmp3_delay_us_fptr_t delay_us
Definition bmp3_defs.h:926
uint8_t dummy_byte
Definition bmp3_defs.h:917
void * intf_ptr
Definition bmp3_defs.h:905
bmp3 interrupt pin settings
Definition bmp3_defs.h:688
uint8_t fifo_wm
Definition bmp3_defs.h:639
uint8_t fifo_full
Definition bmp3_defs.h:642
bmp3 odr and filter settings
Definition bmp3_defs.h:602
Quantized Trim Variables.
Definition bmp3_defs.h:803
Register Trim Variables.
Definition bmp3_defs.h:564
uint8_t drdy_press
Definition bmp3_defs.h:626
uint8_t drdy_temp
Definition bmp3_defs.h:629
bmp3 device settings
Definition bmp3_defs.h:707
uint8_t op_mode
Definition bmp3_defs.h:709
uint8_t temp_en
Definition bmp3_defs.h:715
uint8_t press_en
Definition bmp3_defs.h:712
struct bmp3_int_ctrl_settings int_settings
Definition bmp3_defs.h:721
struct bmp3_adv_settings adv_settings
Definition bmp3_defs.h:724
struct bmp3_odr_filter_settings odr_filter
Definition bmp3_defs.h:718
bmp3 status flags
Definition bmp3_defs.h:669
struct bmp3_sens_status sensor
Definition bmp3_defs.h:674
struct bmp3_err_status err
Definition bmp3_defs.h:677
uint8_t pwr_on_rst
Definition bmp3_defs.h:680
struct bmp3_int_status intr
Definition bmp3_defs.h:671
bmp3 sensor structure which comprises of un-compensated temperature and pressure data.
Definition bmp3_defs.h:882
uint64_t pressure
Definition bmp3_defs.h:884
int64_t temperature
Definition bmp3_defs.h:887