#include <driver_SFM3019.h>
|
| const char * | sfm_common_get_driver_version (void) |
| |
| int16_t | sfm_common_probe (uint8_t i2c_address) |
| |
| int16_t | sfm_common_read_product_identifier (uint8_t i2c_address, uint32_t *product_number, uint8_t(*serial_number)[8]) |
| |
| int16_t | sfm_common_read_scale_factor_offset_and_unit (const SfmConfig *sfm_config, SfmCmdStartContinuousMeasurement measurement_cmd, int16_t *flow_scale, int16_t *flow_offset, uint16_t *unit) |
| |
| int16_t | sfm_common_convert_flow_float (const SfmConfig *sfm_config, int16_t flow_raw, float *flow) |
| |
| float | sfm_common_convert_temperature_float (int16_t temperature_raw) |
| |
| int16_t | sfm_common_start_continuous_measurement (SfmConfig *sfm_config, SfmCmdStartContinuousMeasurement measurement_cmd) |
| |
| int16_t | sfm_common_read_measurement_raw (const SfmConfig *sfm_config, int16_t *flow_raw, int16_t *temperature_raw, uint16_t *status) |
| |
| int16_t | sfm_common_stop_continuous_measurement (SfmConfig *sfm_config) |
| |
| uint8_t | sensirion_common_generate_crc (uint8_t *data, uint16_t count) |
| |
| int8_t | sensirion_common_check_crc (uint8_t *data, uint16_t count, uint8_t checksum) |
| |
| int16_t | sensirion_i2c_general_call_reset (void) |
| |
| uint16_t | sensirion_fill_cmd_send_buf (uint8_t *buf, uint16_t cmd, const uint16_t *args, uint8_t num_args) |
| |
| int16_t | sensirion_i2c_read_words (uint8_t address, uint16_t *data_words, uint16_t num_words) |
| |
| int16_t | sensirion_i2c_read_words_as_bytes (uint8_t address, uint8_t *data, uint16_t num_words) |
| |
| int16_t | sensirion_i2c_write_cmd (uint8_t address, uint16_t command) |
| |
| int16_t | sensirion_i2c_write_cmd_with_args (uint8_t address, uint16_t command, const uint16_t *data_words, uint16_t num_words) |
| |
| int16_t | sensirion_i2c_delayed_read_cmd (uint8_t address, uint16_t cmd, uint32_t delay_us, uint16_t *data_words, uint16_t num_words) |
| |
| int16_t | sensirion_i2c_read_cmd (uint8_t address, uint16_t cmd, uint16_t *data_words, uint16_t num_words) |
| |
| int16_t | sfm3019_probe (void) |
| |
| SfmConfig | sfm3019_create (void) |
| |
| int16_t | sensirion_i2c_select_bus (uint8_t bus_idx) |
| |
| void | sensirion_i2c_init (void) |
| |
| void | sensirion_i2c_release (void) |
| |
| int8_t | sensirion_i2c_read (uint8_t address, uint8_t *data, uint16_t count) |
| |
| int8_t | sensirion_i2c_write (uint8_t address, const uint8_t *data, uint16_t count) |
| |
| void | sensirion_sleep_usec (uint32_t useconds) |
| |
Definition at line 32 of file driver_SFM3019.h.
◆ doMeasure()
| bool SensorSFM3019::doMeasure |
( |
float * |
Flow, |
|
|
float * |
T |
|
) |
| |
Definition at line 461 of file driver_SFM3019.cpp.
464 int16_t temperature_raw;
470 &temperature_raw, &status);
◆ GetIntegral()
| float SensorSFM3019::GetIntegral |
( |
| ) |
|
◆ Init()
| bool SensorSFM3019::Init |
( |
t_i2cdevices |
device, |
|
|
void * |
hw_handle |
|
) |
| |
Definition at line 389 of file driver_SFM3019.cpp.
401 if (driver_version) {
420 uint32_t timeout = millis();
423 if (millis() - timeout > 1000)
425 hwi->__delay_blocking_ms(10);
428 uint32_t product_number = 0;
429 uint8_t serial_number[8] = {};
431 &product_number, &serial_number);
438 for (
size_t i = 0; i < 8; ++i) {
443 hwi->__delay_blocking_ms(1000);
454 hwi->__delay_blocking_ms(100);
◆ ResetIntegral()
| void SensorSFM3019::ResetIntegral |
( |
| ) |
|
◆ sensirion_common_check_crc()
| int8_t SensorSFM3019::sensirion_common_check_crc |
( |
uint8_t * |
data, |
|
|
uint16_t |
count, |
|
|
uint8_t |
checksum |
|
) |
| |
|
private |
◆ sensirion_common_generate_crc()
| uint8_t SensorSFM3019::sensirion_common_generate_crc |
( |
uint8_t * |
data, |
|
|
uint16_t |
count |
|
) |
| |
|
private |
Definition at line 79 of file driver_SFM3019.cpp.
80 uint16_t current_byte;
85 for (current_byte = 0; current_byte < count; ++current_byte) {
86 crc ^= (data[current_byte]);
87 for (crc_bit = 8; crc_bit > 0; --crc_bit) {
◆ sensirion_fill_cmd_send_buf()
| uint16_t SensorSFM3019::sensirion_fill_cmd_send_buf |
( |
uint8_t * |
buf, |
|
|
uint16_t |
cmd, |
|
|
const uint16_t * |
args, |
|
|
uint8_t |
num_args |
|
) |
| |
|
private |
sensirion_fill_cmd_send_buf() - create the i2c send buffer for a command and a set of argument words. The output buffer interleaves argument words with their checksums. @buf: The generated buffer to send over i2c. Then buffer length must be at least SENSIRION_COMMAND_LEN + num_args * (SENSIRION_WORD_SIZE + CRC8_LEN). @cmd: The i2c command to send. It already includes a checksum. @args: The arguments to the command. Can be NULL if none. @num_args: The number of word arguments in args.
- Returns
- The number of bytes written to buf
Definition at line 110 of file driver_SFM3019.cpp.
116 buf[idx++] = (uint8_t)((cmd & 0xFF00) >> 8);
117 buf[idx++] = (uint8_t)((cmd & 0x00FF) >> 0);
119 for (i = 0; i < num_args; ++i) {
120 buf[idx++] = (uint8_t)((args[i] & 0xFF00) >> 8);
121 buf[idx++] = (uint8_t)((args[i] & 0x00FF) >> 0);
◆ sensirion_i2c_delayed_read_cmd()
| int16_t SensorSFM3019::sensirion_i2c_delayed_read_cmd |
( |
uint8_t |
address, |
|
|
uint16_t |
cmd, |
|
|
uint32_t |
delay_us, |
|
|
uint16_t * |
data_words, |
|
|
uint16_t |
num_words |
|
) |
| |
|
private |
sensirion_i2c_delayed_read_cmd() - send a command, wait for the sensor to process and read data back @address: Sensor i2c address @cmd: Command @delay: Time in microseconds to delay sending the read request @data_words: Allocated buffer to store the read data @num_words: Data words to read (without CRC bytes)
- Returns
- STATUS_OK on success, an error code otherwise
Definition at line 190 of file driver_SFM3019.cpp.
◆ sensirion_i2c_general_call_reset()
| int16_t SensorSFM3019::sensirion_i2c_general_call_reset |
( |
void |
| ) |
|
|
private |
Send a general call reset.
- Warning
- This will reset all attached I2C devices on the bus which support general call reset.
- Returns
- STATUS_OK on success, an error code otherwise
Definition at line 104 of file driver_SFM3019.cpp.
105 const uint8_t data = 0x06;
◆ sensirion_i2c_init()
| void SensorSFM3019::sensirion_i2c_init |
( |
void |
| ) |
|
|
private |
Initialize all hard- and software components that are needed for the I2C communication.
◆ sensirion_i2c_read()
| int8_t SensorSFM3019::sensirion_i2c_read |
( |
uint8_t |
address, |
|
|
uint8_t * |
data, |
|
|
uint16_t |
count |
|
) |
| |
|
private |
Execute one read transaction on the I2C bus, reading a given number of bytes. If the device does not acknowledge the read command, an error shall be returned.
- Parameters
-
| address | 7-bit I2C address to read from |
| data | pointer to the buffer where the data is to be stored |
| count | number of bytes to read from I2C and store in the buffer |
- Returns
- 0 on success, error code otherwise
Definition at line 216 of file driver_SFM3019.cpp.
217 uint8_t readData[32];
218 uint8_t rxByteCount = 0;
223 memcpy(data, readData, count);
◆ sensirion_i2c_read_cmd()
| int16_t SensorSFM3019::sensirion_i2c_read_cmd |
( |
uint8_t |
address, |
|
|
uint16_t |
cmd, |
|
|
uint16_t * |
data_words, |
|
|
uint16_t |
num_words |
|
) |
| |
|
private |
sensirion_i2c_read_cmd() - reads data words from the sensor after a command is issued @address: Sensor i2c address @cmd: Command @data_words: Allocated buffer to store the read data @num_words: Data words to read (without CRC bytes)
- Returns
- STATUS_OK on success, an error code otherwise
Definition at line 207 of file driver_SFM3019.cpp.
◆ sensirion_i2c_read_words()
| int16_t SensorSFM3019::sensirion_i2c_read_words |
( |
uint8_t |
address, |
|
|
uint16_t * |
data_words, |
|
|
uint16_t |
num_words |
|
) |
| |
|
private |
sensirion_i2c_read_words() - read data words from sensor
@address: Sensor i2c address @data_words: Allocated buffer to store the read words. The buffer may also have been modified on STATUS_FAIL return. @num_words: Number of data words to read (without CRC bytes)
- Returns
- STATUS_OK on success, an error code otherwise
Definition at line 157 of file driver_SFM3019.cpp.
167 for (i = 0; i < num_words; ++i)
◆ sensirion_i2c_read_words_as_bytes()
| int16_t SensorSFM3019::sensirion_i2c_read_words_as_bytes |
( |
uint8_t |
address, |
|
|
uint8_t * |
data, |
|
|
uint16_t |
num_words |
|
) |
| |
|
private |
sensirion_i2c_read_words_as_bytes() - read data words as byte-stream from sensor
Read bytes without adjusting values to the uP's word-order.
@address: Sensor i2c address @data: Allocated buffer to store the read bytes. The buffer may also have been modified on STATUS_FAIL return. @num_words: Number of data words(!) to read (without CRC bytes) Since only word-chunks can be read from the sensor the size is still specified in sensor-words (num_words = num_bytes * SENSIRION_WORD_SIZE)
- Returns
- STATUS_OK on success, an error code otherwise
Definition at line 130 of file driver_SFM3019.cpp.
136 uint8_t*
const buf8 = (uint8_t*)word_buf;
151 data[j++] = buf8[i + 1];
◆ sensirion_i2c_release()
| void SensorSFM3019::sensirion_i2c_release |
( |
void |
| ) |
|
|
private |
◆ sensirion_i2c_select_bus()
| int16_t SensorSFM3019::sensirion_i2c_select_bus |
( |
uint8_t |
bus_idx | ) |
|
|
private |
Select the current i2c bus by index. All following i2c operations will be directed at that bus.
THE IMPLEMENTATION IS OPTIONAL ON SINGLE-BUS SETUPS (all sensors on the same bus)
- Parameters
-
| bus_idx | Bus index to select |
- Returns
- 0 on success, an error code otherwise
◆ sensirion_i2c_write()
| int8_t SensorSFM3019::sensirion_i2c_write |
( |
uint8_t |
address, |
|
|
const uint8_t * |
data, |
|
|
uint16_t |
count |
|
) |
| |
|
private |
Execute one write transaction on the I2C bus, sending a given number of bytes. The bytes in the supplied buffer must be sent to the given address. If the slave device does not acknowledge any of the bytes, an error shall be returned.
- Parameters
-
| address | 7-bit I2C address to write to |
| data | pointer to the buffer containing the data to write |
| count | number of bytes to read from the buffer and send over I2C |
- Returns
- 0 on success, error code otherwise
Definition at line 228 of file driver_SFM3019.cpp.
◆ sensirion_i2c_write_cmd()
| int16_t SensorSFM3019::sensirion_i2c_write_cmd |
( |
uint8_t |
address, |
|
|
uint16_t |
command |
|
) |
| |
|
private |
◆ sensirion_i2c_write_cmd_with_args()
| int16_t SensorSFM3019::sensirion_i2c_write_cmd_with_args |
( |
uint8_t |
address, |
|
|
uint16_t |
command, |
|
|
const uint16_t * |
data_words, |
|
|
uint16_t |
num_words |
|
) |
| |
|
private |
sensirion_i2c_write_cmd_with_args() - writes a command with arguments to the sensor @address: Sensor i2c address @command: Sensor command @data: Argument buffer with words to send @num_words: Number of data words to send (without CRC bytes)
- Returns
- STATUS_OK on success, an error code otherwise
Definition at line 180 of file driver_SFM3019.cpp.
◆ sensirion_sleep_usec()
| void SensorSFM3019::sensirion_sleep_usec |
( |
uint32_t |
useconds | ) |
|
|
private |
Sleep for a given number of microseconds. The function should delay the execution approximately, but no less than, the given time.
When using hardware i2c: Despite the unit, a <10 millisecond precision is sufficient.
When using software i2c: The precision needed depends on the desired i2c frequency, i.e. should be exact to about half a clock cycle (defined in SENSIRION_I2C_CLOCK_PERIOD_USEC in sensirion_arch_config.h).
Example with 400kHz requires a precision of 1 / (2 * 400kHz) == 1.25usec.
- Parameters
-
| useconds | the sleep time in microseconds |
Sleep for a given number of microseconds. The function should delay the execution for at least the given time, but may also sleep longer.
- Parameters
-
| useconds | the sleep time in microseconds |
Definition at line 244 of file driver_SFM3019.cpp.
245 hwi->__delay_blocking_ms((useconds / 1000) + 1);
◆ sfm3019_create()
| SfmConfig SensorSFM3019::sfm3019_create |
( |
void |
| ) |
|
|
private |
◆ sfm3019_probe()
| int16_t SensorSFM3019::sfm3019_probe |
( |
void |
| ) |
|
|
private |
Detects if a sensor is connected by reading out the ID register. If the sensor does not answer or if the answer is not the expected value, the test fails.
- Returns
- 0 if a sensor was detected
Definition at line 374 of file driver_SFM3019.cpp.
◆ sfm_common_convert_flow_float()
| int16_t SensorSFM3019::sfm_common_convert_flow_float |
( |
const SfmConfig * |
sfm_config, |
|
|
int16_t |
flow_raw, |
|
|
float * |
flow |
|
) |
| |
|
private |
Convert the raw flow ticks to slm.
- Parameters
-
| sfm_config | Pointer to the SFM object |
| flow_raw | Flow value as read by sfm_common_read_measurement_raw |
| flow | Out parameter to store the converted flow |
- Returns
- 0 on success, an error code otherwise
Definition at line 316 of file driver_SFM3019.cpp.
◆ sfm_common_convert_temperature_float()
| float SensorSFM3019::sfm_common_convert_temperature_float |
( |
int16_t |
temperature_raw | ) |
|
|
private |
Convert the raw temperature ticks to degree Celsius.
- Parameters
-
| temperature_raw | Temperature value as read by sfm_common_read_measurement_raw |
- Returns
- The temperature in degree Celsius
Definition at line 328 of file driver_SFM3019.cpp.
329 return temperature_raw / 200.0f;
◆ sfm_common_get_driver_version()
| const char * SensorSFM3019::sfm_common_get_driver_version |
( |
void |
| ) |
|
|
private |
Return the driver version
- Returns
- Driver version string
Definition at line 249 of file driver_SFM3019.cpp.
◆ sfm_common_probe()
| int16_t SensorSFM3019::sfm_common_probe |
( |
uint8_t |
i2c_address | ) |
|
|
private |
Detects if a sensor is connected by reading out the ID register. If the sensor does not answer or if the answer is not the expected value, the test fails.
- Parameters
-
| i2c_address | I2C address to probe |
- Returns
- 0 if a sensor was detected
Definition at line 253 of file driver_SFM3019.cpp.
◆ sfm_common_read_measurement_raw()
| int16_t SensorSFM3019::sfm_common_read_measurement_raw |
( |
const SfmConfig * |
sfm_config, |
|
|
int16_t * |
flow_raw, |
|
|
int16_t * |
temperature_raw, |
|
|
uint16_t * |
status |
|
) |
| |
|
private |
Read results of a continuous measurement
- Parameters
-
| sfm_config | Pointer to the SFM object |
| flow_raw | Out parameter for the raw flow value |
| temperature_raw | Out parameter for the raw temperature value |
| status | Out parameter for the status word |
- Returns
- 0 on success, an error code otherwise
Definition at line 345 of file driver_SFM3019.cpp.
349 uint16_t buf[3] = {};
355 *flow_raw = (int16_t)buf[0];
357 if (temperature_raw) {
358 *temperature_raw = (int16_t)buf[1];
◆ sfm_common_read_product_identifier()
| int16_t SensorSFM3019::sfm_common_read_product_identifier |
( |
uint8_t |
i2c_address, |
|
|
uint32_t * |
product_number, |
|
|
uint8_t(*) |
serial_number[8] |
|
) |
| |
|
private |
Read the product identifier, consisting of a product number and a serial number.
- Parameters
-
| i2c_address | I2C address to read the product identifier from |
| product_number | Out parameter to store the product number |
| serial_number | Out parameter to store the serial number in raw byte format |
- Returns
- 0 on success, an error code otherwise
Definition at line 259 of file driver_SFM3019.cpp.
272 if (product_number) {
273 *product_number = ((uint32_t)buf[0] << 24) + ((uint32_t)buf[1] << 16) +
274 ((uint32_t)buf[2] << 8) + (uint32_t)buf[3];
277 for (
size_t i = 0; i < 8; ++i) {
278 (*serial_number)[i] = buf[i + 4];
◆ sfm_common_read_scale_factor_offset_and_unit()
| int16_t SensorSFM3019::sfm_common_read_scale_factor_offset_and_unit |
( |
const SfmConfig * |
sfm_config, |
|
|
SfmCmdStartContinuousMeasurement |
measurement_cmd, |
|
|
int16_t * |
flow_scale, |
|
|
int16_t * |
flow_offset, |
|
|
uint16_t * |
unit |
|
) |
| |
|
private |
Read the scale factor, offset and unit for the given measurement type.
- Parameters
-
| sfm_config | Pointer to the SFM object |
| measurement_cmd | Measurement type to get the scale, offset and unit |
| flow_scale | Out parameter to store the flow scale |
| flow_offset | Out parameter to store the flow offset |
| unit | Out parameter to store the unit |
- Returns
- 0 on success, an error code otherwise
Definition at line 284 of file driver_SFM3019.cpp.
289 uint16_t measurement_cmd_word = (uint16_t)measurement_cmd;
294 &measurement_cmd_word, 1);
305 *flow_scale = (int16_t)buf[0];
308 *flow_offset = (int16_t)buf[1];
◆ sfm_common_start_continuous_measurement()
Starts a continuous measurement with the given gas configuration.
- Parameters
-
| sfm_config | Pointer to the SFM object |
| measurement_cmd | Select which gas or gas mix should be measured |
- Returns
- 0 on success, an error code otherwise
Definition at line 332 of file driver_SFM3019.cpp.
336 sfm_config, measurement_cmd, &sfm_config->
flow_scale,
◆ sfm_common_stop_continuous_measurement()
| int16_t SensorSFM3019::sfm_common_stop_continuous_measurement |
( |
SfmConfig * |
sfm_config | ) |
|
|
private |
Stops a continuous measurement.
- Parameters
-
| sfm_config | Pointer to the SFM object |
- Returns
- 0 on success, an error code otherwise
Definition at line 366 of file driver_SFM3019.cpp.
◆ _initialized
| bool SensorSFM3019::_initialized = false |
|
private |
◆ dbg
◆ hwi
◆ i2c_address
| uint8_t SensorSFM3019::i2c_address |
|
private |
◆ i2c_device
◆ Integral
| float SensorSFM3019::Integral |
|
private |
◆ sfm3019
The documentation for this class was generated from the following files:
#define SFM3019_CMD_START_CONTINUOUS_MEASUREMENT_AIR
int8_t sensirion_i2c_write(uint8_t address, const uint8_t *data, uint16_t count)
bool I2CRead(t_i2cdevices device, uint8_t *wbuffer, int wlength, uint8_t *rbuffer, int rlength, bool stop)
Write buffer to I2C bus and read data.
const char * sfm_common_get_driver_version(void)
const char * SFM_DRV_VERSION_STR
int8_t sensirion_common_check_crc(uint8_t *data, uint16_t count, uint8_t checksum)
float sfm_common_convert_temperature_float(int16_t temperature_raw)
int16_t sfm_common_convert_flow_float(const SfmConfig *sfm_config, int16_t flow_raw, float *flow)
int16_t sensirion_i2c_read_words_as_bytes(uint8_t address, uint8_t *data, uint16_t num_words)
bool I2CWrite(t_i2cdevices device, uint8_t *wbuffer, int wlength, bool stop)
Write buffer to I2C bus.
uint8_t sensirion_common_generate_crc(uint8_t *data, uint16_t count)
#define SFM_CMD_READ_PRODUCT_IDENTIFIER
#define SFM_CMD_STOP_CONTINUOUS_MEASUREMENT
int16_t sfm_common_start_continuous_measurement(SfmConfig *sfm_config, SfmCmdStartContinuousMeasurement measurement_cmd)
int16_t sensirion_i2c_write_cmd(uint8_t address, uint16_t command)
int16_t sensirion_i2c_general_call_reset(void)
#define SENSIRION_WORD_SIZE
int16_t sensirion_i2c_write_cmd_with_args(uint8_t address, uint16_t command, const uint16_t *data_words, uint16_t num_words)
int8_t sensirion_i2c_read(uint8_t address, uint8_t *data, uint16_t count)
int16_t sfm_common_read_product_identifier(uint8_t i2c_address, uint32_t *product_number, uint8_t(*serial_number)[8])
int16_t sfm_common_probe(uint8_t i2c_address)
uint16_t sensirion_fill_cmd_send_buf(uint8_t *buf, uint16_t cmd, const uint16_t *args, uint8_t num_args)
#define SENSIRION_MAX_BUFFER_WORDS
int16_t sfm_common_read_scale_factor_offset_and_unit(const SfmConfig *sfm_config, SfmCmdStartContinuousMeasurement measurement_cmd, int16_t *flow_scale, int16_t *flow_offset, uint16_t *unit)
#define SENSIRION_COMMAND_SIZE
int16_t sfm3019_probe(void)
Driver for the Nuclear Instruments V4 Hardware Board.
#define SFM3019_SOFT_RESET_TIME_US
SfmConfig sfm3019_create(void)
int16_t sensirion_i2c_read_words(uint8_t address, uint16_t *data_words, uint16_t num_words)
void DbgPrint(dbg_source source, verbose_level vl, String s)
Print a message on the debug console.
int16_t sensirion_i2c_read_cmd(uint8_t address, uint16_t cmd, uint16_t *data_words, uint16_t num_words)
Debug class: this class print debug message.
void sensirion_sleep_usec(uint32_t useconds)
#define SFM_CMD_READ_SCALE_FACTOR_OFFSET_AND_FLOW_UNIT
@ IIC_GENERAL_CALL_SENSIRION
int16_t sensirion_i2c_delayed_read_cmd(uint8_t address, uint16_t cmd, uint32_t delay_us, uint16_t *data_words, uint16_t num_words)
int16_t sfm_common_read_measurement_raw(const SfmConfig *sfm_config, int16_t *flow_raw, int16_t *temperature_raw, uint16_t *status)