Linux Audio
Check our new training course
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
/* * Copyright (c) 2019 Thomas Schmid <tom@lfence.de> * * SPDX-License-Identifier: Apache-2.0 */ #ifndef __SENSOR_MS5607_H__ #define __SENSOR_MS5607_H__ #include <zephyr/types.h> #include <zephyr/device.h> #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) #include <zephyr/drivers/i2c.h> #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) */ #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) #include <zephyr/drivers/spi.h> #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) */ #define MS5607_CMD_RESET 0x1E #define MS5607_CMD_CONV_P_256 0x40 #define MS5607_CMD_CONV_P_512 0x42 #define MS5607_CMD_CONV_P_1024 0x44 #define MS5607_CMD_CONV_P_2048 0x46 #define MS5607_CMD_CONV_P_4096 0x48 #define MS5607_CMD_CONV_T_256 0x50 #define MS5607_CMD_CONV_T_512 0x52 #define MS5607_CMD_CONV_T_1024 0x54 #define MS5607_CMD_CONV_T_2048 0x56 #define MS5607_CMD_CONV_T_4096 0x58 #define MS5607_CMD_CONV_READ_ADC 0x00 #define MS5607_CMD_CONV_READ_SENSE_T1 0xA2 #define MS5607_CMD_CONV_READ_OFF_T1 0xA4 #define MS5607_CMD_CONV_READ_TCS 0xA6 #define MS5607_CMD_CONV_READ_TCO 0xA8 #define MS5607_CMD_CONV_READ_T_REF 0xAA #define MS5607_CMD_CONV_READ_TEMPSENS 0xAC #define MS5607_CMD_CONV_READ_CRC 0xAE #if defined(CONFIG_MS5607_PRES_OVER_256X) #define MS5607_PRES_OVER_DEFAULT 256 #elif defined(CONFIG_MS5607_PRES_OVER_512X) #define MS5607_PRES_OVER_DEFAULT 512 #elif defined(CONFIG_MS5607_PRES_OVER_1024X) #define MS5607_PRES_OVER_DEFAULT 1024 #elif defined(CONFIG_MS5607_PRES_OVER_2048X) #define MS5607_PRES_OVER_DEFAULT 2048 #elif defined(CONFIG_MS5607_PRES_OVER_4096X) #define MS5607_PRES_OVER_DEFAULT 4096 #else #define MS5607_PRES_OVER_DEFAULT 2048 #endif #if defined(CONFIG_MS5607_TEMP_OVER_256X) #define MS5607_TEMP_OVER_DEFAULT 256 #elif defined(CONFIG_MS5607_TEMP_OVER_512X) #define MS5607_TEMP_OVER_DEFAULT 512 #elif defined(CONFIG_MS5607_TEMP_OVER_1024X) #define MS5607_TEMP_OVER_DEFAULT 1024 #elif defined(CONFIG_MS5607_TEMP_OVER_2048X) #define MS5607_TEMP_OVER_DEFAULT 2048 #elif defined(CONFIG_MS5607_TEMP_OVER_4096X) #define MS5607_TEMP_OVER_DEFAULT 4096 #else #define MS5607_TEMP_OVER_DEFAULT 2048 #endif /* Forward declaration */ struct ms5607_config; struct ms5607_transfer_function { int (*bus_check)(const struct ms5607_config *cfg); int (*reset)(const struct ms5607_config *cfg); int (*read_prom)(const struct ms5607_config *cfg, uint8_t cmd, uint16_t *val); int (*start_conversion)(const struct ms5607_config *cfg, uint8_t cmd); int (*read_adc)(const struct ms5607_config *cfg, uint32_t *val); }; #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) extern const struct ms5607_transfer_function ms5607_i2c_transfer_function; #endif #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) extern const struct ms5607_transfer_function ms5607_spi_transfer_function; #endif struct ms5607_config { const struct device *bus; const struct ms5607_transfer_function *tf; union { #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) uint16_t i2c_addr; #endif #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) struct spi_dt_spec spi_bus; #endif } bus_cfg; }; struct ms5607_data { /* Calibration values */ uint16_t sens_t1; uint16_t off_t1; uint16_t tcs; uint16_t tco; uint16_t t_ref; uint16_t tempsens; /* Measured values */ int32_t pressure; int32_t temperature; /* conversion commands */ uint8_t pressure_conv_cmd; uint8_t temperature_conv_cmd; uint8_t pressure_conv_delay; uint8_t temperature_conv_delay; }; #endif /* __SENSOR_MS607_H__*/